2026-11-19 10:31:03 +00:00
|
|
|
// web/view-claim.mjs -- the invite claim and the token paste: the
|
|
|
|
|
// only public screen. A single-use invite code is exchanged for a
|
|
|
|
|
// persistent token; the display name is a freeform label, collisions
|
|
|
|
|
// allowed. The paste path takes a token straight into the store --
|
|
|
|
|
// the debug token's way in, and the only browser-migration path for
|
|
|
|
|
// a saved token (tokens are returned once, never listed).
|
2026-11-14 23:48:27 +00:00
|
|
|
|
|
|
|
|
import { $ } from './dom.mjs';
|
2026-11-19 10:31:03 +00:00
|
|
|
import { api, setToken, clearToken } from './client.mjs';
|
2026-11-14 23:48:27 +00:00
|
|
|
import { state } from './state.mjs';
|
|
|
|
|
import { banner } from './chrome.mjs';
|
|
|
|
|
import { logEvent } from './log.mjs';
|
|
|
|
|
import { navigate } from './router.mjs';
|
|
|
|
|
|
jsdoc typing round, phases 3-4: the clerk (tool/memory.mjs) and the SPA (web/) typed under strict -- row shapes local to their owners (the clerk's five tables in its header; the SPA's response envelopes in the new web/shapes.mjs, the server's shared shapes imported at their use sites: User, LogEvent, JobState, HttpError); the db boundary cast at every .get()/.all(), fail as @returns {never} so guard-narrowing works; web via a second tsconfig (tsconfig.web.json: DOM libs in their own program, node types riding along because shapes.mjs's Provider typedef pulls provider.mjs in), npm run typecheck runs both; every non-annotation delta audited onto a small intended list (COUNT(*) Number() wraps, impossible-path guards, ?? ''/?? undefined null-absorbers, the RewordOp reason fix -- the validator demands it, the reminder-find naming its tag); smoke 110/110 + restart + reminder + repo checks + a zero-console-error browser pass green; the typing round is complete
2026-11-15 19:57:07 +00:00
|
|
|
/** @param {?string} arg @param {number} seq @returns {Promise<void>} */
|
2026-11-14 23:48:27 +00:00
|
|
|
export async function enter(arg, seq) {
|
jsdoc typing round, phases 3-4: the clerk (tool/memory.mjs) and the SPA (web/) typed under strict -- row shapes local to their owners (the clerk's five tables in its header; the SPA's response envelopes in the new web/shapes.mjs, the server's shared shapes imported at their use sites: User, LogEvent, JobState, HttpError); the db boundary cast at every .get()/.all(), fail as @returns {never} so guard-narrowing works; web via a second tsconfig (tsconfig.web.json: DOM libs in their own program, node types riding along because shapes.mjs's Provider typedef pulls provider.mjs in), npm run typecheck runs both; every non-annotation delta audited onto a small intended list (COUNT(*) Number() wraps, impossible-path guards, ?? ''/?? undefined null-absorbers, the RewordOp reason fix -- the validator demands it, the reminder-find naming its tag); smoke 110/110 + restart + reminder + repo checks + a zero-console-error browser pass green; the typing round is complete
2026-11-15 19:57:07 +00:00
|
|
|
/** @type {HTMLInputElement} */ ($('claim-code')).value = '';
|
|
|
|
|
/** @type {HTMLInputElement} */ ($('claim-name')).value = '';
|
2026-11-19 10:31:03 +00:00
|
|
|
/** @type {HTMLInputElement} */ ($('token-paste')).value = '';
|
2026-11-14 23:48:27 +00:00
|
|
|
let fresh = false;
|
2026-11-19 10:31:03 +00:00
|
|
|
let debug = false;
|
|
|
|
|
try { ({ fresh = false, debug = false } = await api('/session')); } catch { /* public: works signed out; a dead server shows the plain hint */ }
|
2026-11-14 23:48:27 +00:00
|
|
|
if (seq !== state.seq) return;
|
2026-11-19 10:31:03 +00:00
|
|
|
/** @type {string} */
|
|
|
|
|
let hint;
|
|
|
|
|
if (debug) hint = 'debug server -- paste the token the server printed at boot';
|
|
|
|
|
else hint = fresh
|
variant round: roll retired, chance is variant literature (strict parse, crypto pick on reception, picked-only rendering, /story variance metric); entity round: /story the whole deliverable, /table the play projection, the slidwin carry (smart contwin cutoff, whole exchanges, housekeeper reads session-minus-tail); dormant-session rework: universal session lifecycle (dormant->live->finished, sessions/<n> storage), move-at-stop, start lint + auto-send rule, rebaseable housekeeping, turn-0 -> carryover.jsonl, seed -> memory.json, draft-only save-package; format house rules enforced by the nine-rule check-repo (ascii bytes, no text-mutating css); smoke 105/105 + restart + reminder + browser pass green, irene hand-migrated to the new layout
2026-11-15 14:35:00 +00:00
|
|
|
? 'this deployment has no users yet -- the superuser invite is in state/bootstrap-invite.txt on the server'
|
2026-11-14 23:48:27 +00:00
|
|
|
: 'a single-use invite code, from the operator';
|
2026-11-19 10:31:03 +00:00
|
|
|
$('claim-hint').textContent = hint;
|
jsdoc typing round, phases 3-4: the clerk (tool/memory.mjs) and the SPA (web/) typed under strict -- row shapes local to their owners (the clerk's five tables in its header; the SPA's response envelopes in the new web/shapes.mjs, the server's shared shapes imported at their use sites: User, LogEvent, JobState, HttpError); the db boundary cast at every .get()/.all(), fail as @returns {never} so guard-narrowing works; web via a second tsconfig (tsconfig.web.json: DOM libs in their own program, node types riding along because shapes.mjs's Provider typedef pulls provider.mjs in), npm run typecheck runs both; every non-annotation delta audited onto a small intended list (COUNT(*) Number() wraps, impossible-path guards, ?? ''/?? undefined null-absorbers, the RewordOp reason fix -- the validator demands it, the reminder-find naming its tag); smoke 110/110 + restart + reminder + repo checks + a zero-console-error browser pass green; the typing round is complete
2026-11-15 19:57:07 +00:00
|
|
|
/** @type {HTMLInputElement} */ ($('claim-code')).focus();
|
2026-11-14 23:48:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$('claim-form').addEventListener('submit', async (e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
try {
|
jsdoc typing round, phases 3-4: the clerk (tool/memory.mjs) and the SPA (web/) typed under strict -- row shapes local to their owners (the clerk's five tables in its header; the SPA's response envelopes in the new web/shapes.mjs, the server's shared shapes imported at their use sites: User, LogEvent, JobState, HttpError); the db boundary cast at every .get()/.all(), fail as @returns {never} so guard-narrowing works; web via a second tsconfig (tsconfig.web.json: DOM libs in their own program, node types riding along because shapes.mjs's Provider typedef pulls provider.mjs in), npm run typecheck runs both; every non-annotation delta audited onto a small intended list (COUNT(*) Number() wraps, impossible-path guards, ?? ''/?? undefined null-absorbers, the RewordOp reason fix -- the validator demands it, the reminder-find naming its tag); smoke 110/110 + restart + reminder + repo checks + a zero-console-error browser pass green; the typing round is complete
2026-11-15 19:57:07 +00:00
|
|
|
const r = await api('/claim', { method: 'POST', body: { code: /** @type {HTMLInputElement} */ ($('claim-code')).value.trim(), name: /** @type {HTMLInputElement} */ ($('claim-name')).value.trim() } });
|
2026-11-14 23:48:27 +00:00
|
|
|
setToken(r.token);
|
|
|
|
|
state.me = r.user;
|
|
|
|
|
logEvent('nav', `claimed: ${r.user.name}${r.user.superuser ? ' (op)' : ''}`);
|
|
|
|
|
navigate('/');
|
|
|
|
|
} catch (err) {
|
|
|
|
|
banner(err.message);
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-11-19 10:31:03 +00:00
|
|
|
|
|
|
|
|
// the paste path: store the token, then verify it the same way the
|
|
|
|
|
// app boot does -- the public /session resolves it to a user or null
|
|
|
|
|
$('token-form').addEventListener('submit', async (e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
const t = /** @type {HTMLInputElement} */ ($('token-paste')).value.trim();
|
|
|
|
|
if (!t) return;
|
|
|
|
|
try {
|
|
|
|
|
setToken(t);
|
|
|
|
|
const r = await api('/session');
|
|
|
|
|
if (!r.user) { clearToken(); banner('token rejected'); return; }
|
|
|
|
|
state.me = r.user;
|
|
|
|
|
logEvent('nav', `signed in: ${r.user.name}${r.user.superuser ? ' (op)' : ''}`);
|
|
|
|
|
navigate('/');
|
|
|
|
|
} catch (err) {
|
|
|
|
|
clearToken();
|
|
|
|
|
banner(err.message);
|
|
|
|
|
}
|
|
|
|
|
});
|