Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ v41 Iris turns the current design, the Interactive Tour, or the Before / After c
- **One function for all share routes.** The Vercel Hobby plan allows 12 serverless functions per deployment and every non-underscore file in `api/` is one (10 today). So `api/share.js` is the only deployed share function: `vercel.json` rewrites `/api/share-<op>` and `/s/<id>` to it with `?op=`, and it dispatches to the route modules `api/_share-<op>.js` (underscore files are not deployed on their own). **Add new server routes the same way, not as new `api/` files**, or the deployment fails with `exceeded_serverless_functions_per_deployment`.
- **Tests and local runs.** `SHARE_STORE=memory` swaps Blob for an in-process store (still minting real client tokens), so `scripts/regression-tests.mjs` runs every route. Under plain `npm run dev` there is no `/api`, so `shareStatus()` is false and the Share panel says links are not set up; downloads still work.

### Glint Pro waitlist and usage analytics
Not a versioned release; groundwork for a paid plan (Glint Pro: hosted AI, lasting share links, sync). The studio itself stays free, and site copy must keep saying so.

- **Waitlist.** The pricing page's Pro card (`pricing/index.html`, `#pro`) has a `form[data-waitlist]` that `public/site.js` (0a) posts to `/api/waitlist`. `api/_waitlist.js` holds both routes as ops of the one share function (`vercel.json` rewrites `/api/waitlist` and `/api/waitlist-export` to `api/share.js`). The Blob store is public, so entries are stored unreadable: the file name is an HMAC of the email (which also de-duplicates) and the body is AES-256-GCM encrypted, both keyed from `SHARE_SIGNING_SECRET`. Changing that secret orphans the list. The join route answers the same whether or not the email was already there. Read the list with `curl -H "Authorization: Bearer $CRON_SECRET" https://<site>/api/waitlist-export?format=csv`.
- **Analytics.** Vercel Web Analytics, no cookies. Marketing pages load it from `public/site.js` (0) (skipped on localhost) and send `open_studio` and `waitlist_join`. The editor uses `src/features/analytics.js` (`bindAnalytics()`, `track(name, data)`): `section_used` once per sidebar section per visit (a capture listener, so new sections are covered for free), `export`, `share_link`, `roll_develop`. **Events carry feature names and choices only, never images, file names, colors or typed text;** if you add an event, list it on the privacy page.

### Persistence
User data (templates, brand kits, projects, onboarding flags) is stored in `localStorage` under `glint_*` keys, each feature managing its own. `src/state/serialize.js` handles project save/load (`SERIALIZED_FIELDS` for the lean payload, `PROJECT_FIELDS` for heavier fields like dataURLs). Cloud sync (optional) goes through Supabase. The Campaign folder lives in its own `glint_campaigns_v1` localStorage store (optional Supabase mirror ships but is unwired) and is never snapshotted. Projects (`glint_projects_v12`) are stored in IndexedDB (`src/state/project-db.js`, db `glint`, store `kv`) with a localStorage fallback (used when IndexedDB is unavailable or does not load within 8s); any project store found in localStorage is merged into IndexedDB on every healthy load (not one-time) and then removed, and the `glint_projects_idb` flag records that IndexedDB was used before, so a later load failure retries once and warns the user. The projects status line shows "Saved" only after the IndexedDB write commits. Share links (v41) keep each link's record and owner key in `glint_shares` (newest first, max 50, thumbnails dropped first on quota errors); the shares themselves live in Vercel Blob, not in the project. Since v40 the Projects panel's "History" button (whole-project versions) is labeled "Project timeline", so it is not confused with the History panel.

Expand Down
126 changes: 126 additions & 0 deletions api/_waitlist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// Glint Pro waitlist: POST /api/waitlist adds an email, GET /api/waitlist-export
// lists them for the site owner. Both are ops of the one share function
// (vercel.json rewrites them to /api/share?op=...), so they cost no extra
// serverless function.
//
// Entries live in the share Blob store under `waitlist/`. That store is public,
// so nothing readable is put there: the file name is an HMAC of the email (no
// one can guess it, and the same email always lands on the same file, which is
// the de-duplication), and the content is AES-256-GCM encrypted with a key
// derived from SHARE_SIGNING_SECRET.

import { createCipheriv, createDecipheriv, randomBytes } from 'node:crypto';
import { ApiError, parseBody } from './_shared.js';
import { shareConfig, store, sendError, hmacNode } from './_share.js';
import { base64url } from '../src/share/share-core.js';

export const WAITLIST_PREFIX = 'waitlist/';
const SOURCES = ['pricing', 'editor', 'home'];
const EMAIL = /^[^\s@<>"',;]+@[^\s@<>"',;]+\.[^\s@<>"',;]{2,}$/;

// Best-effort throttle. Serverless instances come and go, so this only slows a
// burst from one address; the honeypot and the validation do the rest.
const WINDOW_MS = 10 * 60 * 1000;
const MAX_PER_WINDOW = 8;
const hits = new Map();
function throttled(ip) {
const now = Date.now();
if (hits.size > 5000) hits.clear();
const recent = (hits.get(ip) || []).filter((t) => now - t < WINDOW_MS);
recent.push(now);
hits.set(ip, recent);
return recent.length > MAX_PER_WINDOW;
}

function requireOpen() {
const cfg = shareConfig();
if (!cfg.enabled) throw new ApiError(501, 'The waitlist is not open on this copy of Glint.');
return cfg;
}

export function cleanEmail(value) {
const email = typeof value === 'string' ? value.trim().toLowerCase() : '';
if (!email || email.length > 254 || !EMAIL.test(email)) return '';
return email;
}

const encKey = (secret) => hmacNode(secret, 'waitlist:enc');
export const waitlistPath = (secret, email) => `${WAITLIST_PREFIX}${base64url(hmacNode(secret, 'waitlist:id:' + email))}.json`;

function seal(secret, entry) {
const iv = randomBytes(12);
const cipher = createCipheriv('aes-256-gcm', encKey(secret), iv);
const data = Buffer.concat([cipher.update(JSON.stringify(entry), 'utf8'), cipher.final()]);
return { v: 1, iv: iv.toString('base64'), tag: cipher.getAuthTag().toString('base64'), data: data.toString('base64') };
}

function open(secret, box) {
const decipher = createDecipheriv('aes-256-gcm', encKey(secret), Buffer.from(String(box.iv), 'base64'));
decipher.setAuthTag(Buffer.from(String(box.tag), 'base64'));
const text = Buffer.concat([decipher.update(Buffer.from(String(box.data), 'base64')), decipher.final()]).toString('utf8');
return JSON.parse(text);
}

export async function join(req, res) {
res.setHeader('Cache-Control', 'no-store');
try {
if (req.method !== 'POST') throw new ApiError(405, 'Method not allowed');
const cfg = requireOpen();
const body = parseBody(req);
// Bots fill every field; people never see this one.
if (body.website) { res.status(200).json({ ok: true }); return; }
const email = cleanEmail(body.email);
if (!email) throw new ApiError(400, 'That does not look like an email address.');
const ip = String((req.headers && req.headers['x-forwarded-for']) || 'unknown').split(',')[0].trim();
if (throttled(ip)) throw new ApiError(429, 'Too many tries. Give it a few minutes.');
const source = SOURCES.includes(body.source) ? body.source : 'other';
const st = store(cfg);
const path = waitlistPath(cfg.secret, email);
// The answer is the same whether or not the email was already there, so
// the form cannot be used to check who is on the list.
if (!(await st.getJson(path))) {
const entry = seal(cfg.secret, { email, at: new Date().toISOString(), source });
try {
await st.put(path, JSON.stringify(entry), { contentType: 'application/json' });
} catch (e) {
// Two requests for the same email at once: the other one won.
if (!(await st.getJson(path))) throw e;
}
}
res.status(200).json({ ok: true });
} catch (e) {
sendError(res, e);
}
}

const csvCell = (v) => `"${String(v == null ? '' : v).replace(/"/g, '""')}"`;

export async function exportList(req, res) {
res.setHeader('Cache-Control', 'no-store');
try {
if (req.method !== 'GET') throw new ApiError(405, 'Method not allowed');
const secret = process.env.CRON_SECRET;
const auth = (req.headers && req.headers.authorization) || '';
if (!secret || auth !== `Bearer ${secret}`) throw new ApiError(401, 'Unauthorized');
const cfg = requireOpen();
const st = store(cfg);
const files = await st.list(WAITLIST_PREFIX);
const entries = [];
for (const f of files) {
const got = await st.getJson(f.pathname).catch(() => null);
if (!got) continue;
try { entries.push(open(cfg.secret, got.data)); } catch (e) { /* written with another secret */ }
}
entries.sort((a, b) => String(a.at).localeCompare(String(b.at)));
const format = Array.isArray(req.query && req.query.format) ? req.query.format[0] : req.query && req.query.format;
if (format === 'csv') {
const rows = ['email,joined,source', ...entries.map((e) => [e.email, e.at, e.source].map(csvCell).join(','))];
res.setHeader('Content-Type', 'text/csv; charset=utf-8');
res.status(200).send(rows.join('\n') + '\n');
return;
}
res.status(200).json({ count: entries.length, entries });
} catch (e) {
sendError(res, e);
}
}
4 changes: 3 additions & 1 deletion api/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import remove from './_share-delete.js';
import page from './_share-page.js';
import sweep from './_share-sweep.js';
import upload from './_share-upload.js';
import { join as waitlist, exportList as waitlistExport } from './_waitlist.js';

const ROUTES = { status, create, upload, commit, manifest, delete: remove, page, sweep };
// The Glint Pro waitlist rides along here too (/api/waitlist, /api/waitlist-export).
const ROUTES = { status, create, upload, commit, manifest, delete: remove, page, sweep, waitlist, 'waitlist-export': waitlistExport };

export default async function handler(req, res) {
const raw = req.query && req.query.op;
Expand Down
2 changes: 2 additions & 0 deletions docs/BACKEND.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ the Vite frontend.
| `POST /api/share-delete` | Deletes a share. Needs the owner key. |
| `GET /s/<id>` | Serves the share viewer with link-preview tags (rewritten to `/api/share?op=page`). |
| `GET /api/share-sweep` | Daily cron. Removes uploads that were never published. |
| `POST /api/waitlist` | Glint Pro waitlist. Stores `{ email, at, source }` encrypted under `waitlist/` in the share Blob store. Always answers `{ ok: true }` for a valid email. |
| `GET /api/waitlist-export` | The waitlist for the site owner, as JSON or `?format=csv`. Needs `Authorization: Bearer <CRON_SECRET>`. |

All share routes run in one function, `api/share.js`: `vercel.json` rewrites
`/api/share-<op>` to `/api/share?op=<op>`, and the route code lives in
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ <h2 class="sec-title">Everything included.</h2>
<div class="facts">
<article class="fact free reveal">
<div class="big">$0</div>
<p><strong>Free, forever.</strong> Glint is open source, with no paid tier and nothing to unlock.</p>
<p><strong>Free, forever.</strong> Glint is open source, and every tool in the studio is free to use.</p>
</article>
<article class="fact acct reveal">
<div class="big">0</div>
Expand Down
Loading
Loading