feat(waitlist): save signups to a Google Sheet via Apps Script

Server-side validation, email dedupe under a script lock, formula-injection
guard, honeypot field. The page posts text/plain so no CORS preflight is
needed. tools/waitlist-check.mjs runs the script against stub services.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
kirukib 2026-10-17 01:33:46 +03:00
parent 829469896f
commit 629403da0b
4 changed files with 92 additions and 6 deletions

View File

@ -8,7 +8,7 @@ Video courses for makeup artists in Amharic, Afaan Oromoo, Tigrinya and English.
- **Design:** [`design/inspo/README.md`](design/inspo/README.md) (Logosmental reference), [`design/tokens.json`](design/tokens.json), [`design/audit-2026-10-06.md`](design/audit-2026-10-06.md).
- **Live demo (Phase 0, Claude-hosted):** https://claude.ai/artifact/Rv2YqqccDs9GtAWbzHUCHE. It's private, so ask the owner for access. Payments, SMS and email are simulated.
**Waitlist page:** `apps/demo/public/waitlist/index.html` is a standalone page (name, email, phone) served at `/waitlist/` on Vercel. Set `ENDPOINT` in it before sharing it publicly. Until then, signups stay in the visitor's browser.
**Waitlist page:** `apps/demo/public/waitlist/index.html` (name, email, phone) is served at `/waitlist/` on Vercel. Signups go to a Google Sheet through `tools/waitlist-apps-script.gs`, which has the setup steps in its header. Paste the web app URL into `ENDPOINT` in the page before sharing it. While `ENDPOINT` is empty, signups stay in the visitor's browser.
## Layout
@ -28,6 +28,7 @@ npx -y pnpm@9 install
npx -y pnpm@9 run demo:build # next build → dist/demo.html → offline network check
npx -y pnpm@9 test # domain rules (payments, entitlement, progress, dashboard)
npx -y pnpm@9 run i18n:check # every locale has every key
node tools/waitlist-check.mjs # waitlist Apps Script: validation, dedupe, formula-injection guard
```
**Vercel (standalone demo):** `vercel.json` builds the static export, then `tools/vercel-build.mjs` injects the runtime mock and the seed. Outside Claude, all data lives in memory in each visitor's browser and resets on reload. Deploy with `npx vercel deploy --prod`.

View File

@ -177,6 +177,7 @@
<div class="join rise" id="join">
<form id="form" novalidate>
<div class="fields">
<label class="sr-only" aria-hidden="true">Company<input id="company" name="company" tabindex="-1" autocomplete="off" /></label>
<label class="full">Full name<input id="name" name="name" autocomplete="name" placeholder="Selam Tesfaye" required maxlength="80" /></label>
<label>Email<input id="email" name="email" type="email" autocomplete="email" placeholder="you@example.com" required maxlength="120" /></label>
<label>Phone<input id="phone" name="phone" type="tel" autocomplete="tel" inputmode="tel" placeholder="+251 9XX XXX XXX" required maxlength="20" /></label>
@ -231,9 +232,8 @@
</footer>
<script>
// ponytail: no waitlist backend yet. Set ENDPOINT to a URL that accepts a JSON POST
// ({ name, email, phone, locale, createdAt }) before sharing this page publicly.
// Until then, signups are kept only in this browser's localStorage (demo only).
// Google Apps Script web app URL (…/exec) from tools/waitlist-apps-script.gs. Each signup becomes a row in the sheet.
// While it's empty, signups are kept only in this browser's localStorage, so don't share the page until it's set.
const ENDPOINT = '';
const pans = ['#F3D5C4', '#E9B8A7', '#C98B6B', '#8E4B45', '#FAD7DA', '#F5AFB5', '#E63946', '#A8DADC'];
@ -272,8 +272,10 @@
btn.disabled = true;
try {
if (ENDPOINT) {
const res = await fetch(ENDPOINT, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(r.data) });
if (!res.ok) throw new Error(res.status);
// text/plain keeps this a "simple" request: Apps Script can't answer a CORS preflight.
const res = await fetch(ENDPOINT, { method: 'POST', headers: { 'Content-Type': 'text/plain;charset=utf-8' }, body: JSON.stringify({ ...r.data, page: location.href, company: $('company').value }) });
const out = await res.json().catch(() => ({}));
if (!res.ok || !out.ok) throw new Error(out.error || res.status);
} else {
let list = []; try { list = JSON.parse(localStorage.getItem('waitlist') || '[]'); } catch {}
if (!list.some((x) => x.email === r.data.email)) list.push(r.data);

View File

@ -0,0 +1,58 @@
/**
* Waitlist receiver for apps/demo/public/waitlist/index.html → one row per signup in a Google Sheet.
*
* Setup (once, in the Google account that should own the list):
* 1. Create a Google Sheet, e.g. "MakeUp Academy waitlist".
* 2. Extensions → Apps Script. Replace Code.gs with this file and save.
* 3. Deploy → New deployment → type "Web app". Execute as: Me. Who has access: Anyone.
* 4. Authorize, then copy the Web app URL (ends in /exec).
* 5. Paste it into ENDPOINT in apps/demo/public/waitlist/index.html, then commit and deploy.
* After editing this script, use Deploy → Manage deployments → Edit → New version (the URL stays the same).
*/
const SHEET_NAME = 'Signups';
const HEADER = ['Signed up (UTC)', 'Name', 'Email', 'Phone', 'Language', 'Page'];
function doPost(e) {
let data;
try { data = JSON.parse((e && e.postData && e.postData.contents) || '{}'); } catch (_) { return reply({ ok: false, error: 'bad_json' }); }
if (data.company) return reply({ ok: true }); // honeypot filled → bot; pretend success
const row = clean(data);
if (row.error) return reply({ ok: false, error: row.error });
const lock = LockService.getScriptLock();
lock.waitLock(10000);
try {
const sheet = getSheet();
const last = sheet.getLastRow();
const emails = last > 1 ? sheet.getRange(2, 3, last - 1, 1).getValues().map((r) => String(r[0]).toLowerCase()) : [];
if (emails.indexOf(row.email) === -1) {
sheet.appendRow([new Date().toISOString(), safe(row.name), safe(row.email), "'" + row.phone, safe(row.locale), safe(row.page)]);
}
} finally { lock.releaseLock(); }
return reply({ ok: true });
}
/** Server-side check: the page validates too, but anyone can POST here. */
function clean(d) {
const name = String(d.name || '').trim().slice(0, 80);
const email = String(d.email || '').trim().toLowerCase().slice(0, 120);
const phone = String(d.phone || '').replace(/[\s()-]/g, '');
if (name.length < 2) return { error: 'name' };
if (!/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(email)) return { error: 'email' };
if (!/^\+\d{8,15}$/.test(phone)) return { error: 'phone' };
return { name, email, phone, locale: String(d.locale || '').slice(0, 20), page: String(d.page || '').slice(0, 200) };
}
/** Cells starting with = + - @ would run as formulas when someone opens the sheet. */
function safe(v) { return /^[=+\-@]/.test(v) ? "'" + v : v; }
function getSheet() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
let sheet = ss.getSheetByName(SHEET_NAME);
if (!sheet) { sheet = ss.insertSheet(SHEET_NAME); sheet.appendRow(HEADER); sheet.setFrozenRows(1); }
return sheet;
}
function reply(obj) {
return ContentService.createTextOutput(JSON.stringify(obj)).setMimeType(ContentService.MimeType.JSON);
}

25
tools/waitlist-check.mjs Normal file
View File

@ -0,0 +1,25 @@
// Runs tools/waitlist-apps-script.gs against stub Google services. Usage: node tools/waitlist-check.mjs
import fs from 'fs'; import vm from 'vm'; import assert from 'assert';
const rows = [];
const sheet = { appendRow: (r) => rows.push(r), getLastRow: () => rows.length, setFrozenRows() {},
getRange: (r, c, n) => ({ getValues: () => rows.slice(r - 1, r - 1 + n).map((row) => [row[c - 1]]) }) };
const ctx = {
SpreadsheetApp: { getActiveSpreadsheet: () => ({ getSheetByName: () => (rows.length ? sheet : null), insertSheet: () => sheet }) },
LockService: { getScriptLock: () => ({ waitLock() {}, releaseLock() {} }) },
ContentService: { MimeType: { JSON: 'json' }, createTextOutput: (t) => ({ setMimeType: () => JSON.parse(t) }) },
};
vm.runInNewContext(fs.readFileSync(new URL('./waitlist-apps-script.gs', import.meta.url), 'utf8') + '\nthis.doPost = doPost;', ctx);
const post = (d) => ctx.doPost({ postData: { contents: JSON.stringify(d) } });
const ok = { name: 'Selam Tesfaye', email: 'Selam@Example.com', phone: '+251911234567', locale: 'en' };
assert.deepEqual(post(ok), { ok: true });
assert.equal(rows.length, 2, 'header + one signup');
assert.equal(rows[1][2], 'selam@example.com'); assert.equal(rows[1][3], "'+251911234567", 'phone kept as text');
assert.deepEqual(post({ ...ok, email: 'selam@example.com' }), { ok: true }); assert.equal(rows.length, 2, 'duplicate email skipped');
assert.deepEqual(post({ ...ok, email: 'x@y.co', phone: '0911' }), { ok: false, error: 'phone' });
assert.deepEqual(post({ ...ok, email: 'nope' }), { ok: false, error: 'email' });
assert.deepEqual(post({ ...ok, name: ' ' }), { ok: false, error: 'name' });
post({ ...ok, email: 'f@y.co', name: '=HYPERLINK("x")' }); assert.equal(rows.at(-1)[1], '\'=HYPERLINK("x")', 'formula neutralised');
const n = rows.length; assert.deepEqual(post({ ...ok, email: 'bot@y.co', company: 'spam' }), { ok: true }); assert.equal(rows.length, n, 'honeypot dropped');
assert.deepEqual(ctx.doPost({ postData: { contents: '{bad' } }), { ok: false, error: 'bad_json' });
console.log('waitlist checks: all passed');