/** * cottondb.com/delete: deleting a Cotton account without the app (the stores * ask for a web way; owner, 22 Nov 2026). Drawn by the door, as the OAuth * phone page is, with no script: a form for the number, a form for the code * that number was sent, the same warning the apps show, then done. The code is * bound to this one form's own id (a fresh `browser_id` per number asked), so * a code asked here is good here only, and a sign-in code never deletes * (src/account_delete.ts, `deleteCode`/`deleteConfirm`). A number with no * account is answered as one that was sent a code, so the page never says who * is on Cotton. Every word is the kit's (`kits/shell/lines/signin.json` * `delete.*`). It says the account goes thirty days after asking, and the date * (src/account_delete.ts). * * GET /delete the number * POST /delete step=phone phone a code sent; the code asked * POST /delete step=code phone challenge_id browser_id code confirm=delete deleted */import LINES from"../../../crates/cotton-core/kits/shell/lines/signin.json";import { Refused } from"./http.ts";import { esc, page } from"./oauth.ts";exportconst DELETE_PAGE = "/delete";const words = (LINES as { delete: Record<string, string> }).delete;const say = (key: string): string => words[key] ?? "";/** Asks the web routes' own logic (src/open.ts `webDelete`), as a JSON caller would. */exporttypeWebDelete = (path: "code" | "confirm", body: Record<string, unknown>) => Promise<Response>;exportasyncfunction deletePage(request: Request, ask: WebDelete): Promise<Response> {if (request.method === "GET" || request.method === "HEAD") return numberPage();const form = await request.formData().catch(() => null);const field = (name: string): string => String(form?.get(name) ?? "").trim();if (!form) return numberPage(undefined, 400);const phone = field("phone");if (field("step") === "phone") {const browserId = freshId();const asked = await call(() => ask("code", { phone, browser_id: browserId }));if ("problem"in asked) return numberPage(asked.problem, asked.status, phone);return codePage(phone, String(asked.body.challenge_id ?? ""), browserId); }if (field("step") === "code") {const challenge = field("challenge_id");const browserId = field("browser_id");if (field("confirm") !== "delete") return codePage(phone, challenge, browserId, say("wrong"), 400);const done = await call(() => ask("confirm", { phone, challenge_id: challenge, browser_id: browserId, code: field("code"), confirm: "delete" }));if ("problem"in done) return codePage(phone, challenge, browserId, done.problem, done.status);// The date the account goes, as the apps say it (a day and a month); asked again, the first date stands.return page(say("done_heading"), `<p>${esc(say("web_done").replaceAll("{date}", dayAndMonth(String(done.body.erase_at ?? ""))))}</p>`, 200); }return numberPage(undefined, 400);}/** * What goes and when. Not `what_stays`, which names the app the person is in ("{app}", since ff8d3a8a78): the web has * none, and `what_goes` already says it is everything in any Cotton app. A line here never carries a `{…}` unfilled * (walked in Chrome on dev, 24 Nov 2026: the page said "in {app}"). */function warning(): string {return ["what_goes", "when"].map((key) => `<p>${esc(say(key))}</p>`).join("\n");}function numberPage(problem?: string, status = 200, phone = ""): Response {return page( say("heading"),`<p>${esc(say("web_intro"))}</p>${warning()}${problem ? `<p role="alert">${esc(problem)}</p>` : ""}<form method="post" action="${DELETE_PAGE}"><input type="hidden" name="step" value="phone"><p><label>${esc(say("web_number"))}<br><input type="tel" name="phone" autocomplete="tel" placeholder="+91…" value="${esc(phone)}" required autofocus></label></p><p><button type="submit">${esc(say("send"))}</button></p></form>`, problem ? status : 200, );}function codePage(phone: string, challenge: string, browserId: string, problem?: string, status = 200): Response {return page( say("heading"),`<p>${esc(say("web_sent"))}</p>${warning()}${problem ? `<p role="alert">${esc(problem)}</p>` : ""}<form method="post" action="${DELETE_PAGE}"><input type="hidden" name="step" value="code"><input type="hidden" name="phone" value="${esc(phone)}"><input type="hidden" name="challenge_id" value="${esc(challenge)}"><input type="hidden" name="browser_id" value="${esc(browserId)}"><input type="hidden" name="confirm" value="delete"><p><label>${esc(say("code_label"))}<br><input type="text" name="code" inputmode="numeric" autocomplete="one-time-code" required autofocus></label></p><p><button type="submit">${esc(say("confirm"))}</button></p></form><form method="get" action="${DELETE_PAGE}"><p><button type="submit">${esc(say("cancel"))}</button></p></form>`, problem ? status : 200, );}/** The web route's answer, or the words to show for its refusal: a wrong or old code in the kit's words. */asyncfunction call(asked: () => Promise<Response>): Promise<{ body: Record<string, unknown> } | { problem: string; status: number }> {try {const answer = await asked();return { body: (await answer.json()) asRecord<string, unknown> }; } catch (error) {if (!(error instanceofRefused)) throw error;if (error.code === "bad_phone") return { problem: error.message, status: 400 };if (error.code === "too_many_codes" || error.code === "rate_limited") return { problem: error.message, status: 429 };return { problem: say("wrong"), status: error.status }; }}const MONTHS = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];/** "22 December" from an ISO time (UTC): the day the account goes. */exportfunction dayAndMonth(iso: string): string {const at = newDate(iso);returnNumber.isNaN(at.getTime()) ? iso : `${at.getUTCDate()} ${MONTHS[at.getUTCMonth()]}`;}function freshId(): string {const bytes = crypto.getRandomValues(newUint8Array(24));return btoa(String.fromCharCode(...bytes)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");}