/** * 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"; export const DELETE_PAGE = "/delete"; const words = (LINES as { delete: Record }).delete; const say = (key: string): string => words[key] ?? ""; /** Asks the web routes' own logic (src/open.ts `webDelete`), as a JSON caller would. */ export type WebDelete = (path: "code" | "confirm", body: Record) => Promise; export async function deletePage(request: Request, ask: WebDelete): Promise { 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"), `

${esc(say("web_done").replaceAll("{date}", dayAndMonth(String(done.body.erase_at ?? ""))))}

`, 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) => `

${esc(say(key))}

`).join("\n"); } function numberPage(problem?: string, status = 200, phone = ""): Response { return page( say("heading"), `

${esc(say("web_intro"))}

${warning()} ${problem ? `

${esc(problem)}

` : ""}

`, problem ? status : 200, ); } function codePage(phone: string, challenge: string, browserId: string, problem?: string, status = 200): Response { return page( say("heading"), `

${esc(say("web_sent"))}

${warning()} ${problem ? `

${esc(problem)}

` : ""}

`, 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. */ async function call(asked: () => Promise): Promise<{ body: Record } | { problem: string; status: number }> { try { const answer = await asked(); return { body: (await answer.json()) as Record }; } catch (error) { if (!(error instanceof Refused)) 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. */ export function dayAndMonth(iso: string): string { const at = new Date(iso); return Number.isNaN(at.getTime()) ? iso : `${at.getUTCDate()} ${MONTHS[at.getUTCMonth()]}`; } function freshId(): string { const bytes = crypto.getRandomValues(new Uint8Array(24)); return btoa(String.fromCharCode(...bytes)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""); }