// The editor's cookie alerts, stubbed (umtool redesign L4, needs-you.spec.ts): `GET /api/ops/services` answers // what a spec put there (`POST /__stub/services {alerts, x}`, the stub's own door, no token; `{}` resets to no // alerts) -- the payload editor/app/lib/cookieAlerts.ts serves, so the Inbox's X jar row (lib/inbox/xJar.ts) // reads the same shape it reads from the real editor. Nothing here asks X anything. // `down: true`: the services route answers 503, as an editor that is not up does (readiness.spec.ts: the X jar pill // is "—" then, never ✓). const state = { alerts: [], pending: [], x: null, down: false }; /** The spec's door. True when it answered. */ export function servicesControl(req, res, url, { json, readBody }) { if (req.method !== "POST" || url.pathname !== "/__stub/services") return false; readBody(req, (body) => { state.alerts = Array.isArray(body?.alerts) ? body.alerts : []; state.pending = Array.isArray(body?.pending) ? body.pending : []; state.x = body?.x && typeof body.x === "object" ? body.x : null; state.down = body?.down === true; json(res, 200, { ok: true, alerts: state.alerts.length }); }); return true; } /** `GET /api/ops/services`, behind the token. True when it answered. */ export function servicesRoute(req, res, url, { json }) { if (req.method !== "GET" || url.pathname !== "/api/ops/services") return false; req.resume(); if (state.down) return json(res, 503, { error: "the editor is down (stub)" }), true; json(res, 200, { ok: true, alerts: state.alerts, pending: state.pending, ...(state.x ? { x: state.x } : {}) }); return true; }