cursedbelt-server 4.78.0 → 4.79.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/dist/server/analytics/injectedScripts.d.ts +1 -1
  2. package/dist/server/analytics/injectedScripts.js +1 -1
  3. package/dist/server/analytics/webAnalytics.d.ts +2 -2
  4. package/dist/server/analytics/webAnalytics.js +2 -2
  5. package/dist/server/clientIssues/d1.d.ts +1 -1
  6. package/dist/server/engagement/visits.d.ts +1 -1
  7. package/dist/server/incidents/channels.d.ts +2 -2
  8. package/dist/server/incidents/channels.js +2 -2
  9. package/dist/server/incidents/index.d.ts +2 -2
  10. package/dist/server/incidents/index.js +2 -2
  11. package/dist/server/incidents/notifier.d.ts +6 -6
  12. package/dist/server/incidents/notifier.js +6 -6
  13. package/dist/server/incidents/reporter.d.ts +1 -1
  14. package/dist/server/incidents/types.d.ts +5 -5
  15. package/dist/server/incidents/types.js +2 -2
  16. package/dist/server/maps-budget/mapsBudget.d.ts +37 -0
  17. package/dist/server/maps-budget/mapsBudget.js +52 -0
  18. package/dist/server/maps-static/staticMap.d.ts +30 -3
  19. package/dist/server/maps-static/staticMap.js +35 -3
  20. package/dist/server/master-lock/accountsPage.js +2 -2
  21. package/dist/server/master-lock/attempts.js +1 -1
  22. package/dist/server/master-lock/masterLock.d.ts +2 -2
  23. package/dist/server/master-lock/masterLock.js +3 -3
  24. package/dist/server/master-lock/principals.js +1 -1
  25. package/dist/server/presence/index.d.ts +3 -2
  26. package/dist/server/presence/index.js +35 -2
  27. package/dist/server/requestScope.d.ts +8 -0
  28. package/dist/server/requestScope.js +33 -0
  29. package/dist/server/resume/store.d.ts +1 -1
  30. package/dist/server/storage/binaryStoreFake.d.ts +1 -1
  31. package/dist/server/sync/status.d.ts +1 -1
  32. package/dist/server/youtube/ytdlp.d.ts +1 -1
  33. package/package.json +3 -3
  34. package/src/cursedopsRange.spec.ts +5 -3
  35. package/src/noTimerDialsAPeer.spec.ts +3 -3
  36. package/src/server/analytics/injectedScripts.spec.ts +1 -1
  37. package/src/server/analytics/injectedScripts.ts +1 -1
  38. package/src/server/analytics/webAnalytics.ts +2 -2
  39. package/src/server/clientIssues/d1.ts +1 -1
  40. package/src/server/engagement/engagement.spec.ts +1 -1
  41. package/src/server/engagement/visits.ts +1 -1
  42. package/src/server/incidents/channels.ts +2 -2
  43. package/src/server/incidents/index.ts +2 -2
  44. package/src/server/incidents/notifier.ts +9 -9
  45. package/src/server/incidents/reporter.ts +1 -1
  46. package/src/server/incidents/types.ts +5 -5
  47. package/src/server/maps-budget/mapsBudget.ts +73 -0
  48. package/src/server/maps-static/renderStaticMap.spec.ts +79 -0
  49. package/src/server/maps-static/staticMap.ts +47 -3
  50. package/src/server/master-lock/accounts.spec.ts +4 -4
  51. package/src/server/master-lock/accountsPage.spec.ts +1 -1
  52. package/src/server/master-lock/accountsPage.ts +2 -2
  53. package/src/server/master-lock/attempts.ts +1 -1
  54. package/src/server/master-lock/beaconNeverReachesTheWall.spec.ts +3 -3
  55. package/src/server/master-lock/guard.spec.ts +1 -1
  56. package/src/server/master-lock/masterLock.ts +3 -3
  57. package/src/server/master-lock/principals.spec.ts +2 -2
  58. package/src/server/master-lock/principals.ts +1 -1
  59. package/src/server/presence/index.ts +3 -2
  60. package/src/server/requestScope.spec.ts +15 -1
  61. package/src/server/requestScope.ts +35 -0
  62. package/src/server/resume/store.ts +1 -1
  63. package/src/server/storage/binaryStoreFake.ts +1 -1
  64. package/src/server/sync/status.ts +1 -1
  65. package/src/server/youtube/ytdlp.ts +1 -1
@@ -10,7 +10,7 @@
10
10
  * the foreign scripts disappear — green. Decide a third-party script is wanted and allow its
11
11
  * host — green. Harden a page with `script-src 'self'` while something is still injecting into
12
12
  * it — RED, and it names the origin, which is the console line the owner would otherwise find
13
- * himself during an incident.
13
+ * themselves during an incident.
14
14
  *
15
15
  * ## 🔴 Why it lives in this package
16
16
  *
@@ -10,7 +10,7 @@
10
10
  * the foreign scripts disappear — green. Decide a third-party script is wanted and allow its
11
11
  * host — green. Harden a page with `script-src 'self'` while something is still injecting into
12
12
  * it — RED, and it names the origin, which is the console line the owner would otherwise find
13
- * himself during an incident.
13
+ * themselves during an incident.
14
14
  *
15
15
  * ## 🔴 Why it lives in this package
16
16
  *
@@ -11,7 +11,7 @@
11
11
  * line was that tag being refused; it broke nothing and cost an agent the first minutes of
12
12
  * the incident.
13
13
  *
14
- * His decision, 2026-09-18, in his words: *"do your recommendation with option c but not on
14
+ * The owner's decision, 2026-09-18, in their words: *"do your recommendation with option c but not on
15
15
  * the wall. If we can stop the console error that would be good since we are purposely
16
16
  * blocking on that page and it makes it look like there is a mistake when it shows."* — and,
17
17
  * on why the wall's CSP may not simply be loosened: *"I don't want to trust cloudflare with
@@ -105,7 +105,7 @@ export declare const WEB_ANALYTICS_PUBLIC_HOST = "cursedalchemy.com";
105
105
  * `apps/desk` lost 24, both asserting the console is empty, and the owner's own local console
106
106
  * would have gained a red line on every page.
107
107
  *
108
- * That is the exact cost he asked to be rid of, one environment over. So the guard: the beacon
108
+ * That is the exact cost the owner asked to be rid of, one environment over. So the guard: the beacon
109
109
  * is appended only when the page is being served from {@link WEB_ANALYTICS_PUBLIC_HOST}, which
110
110
  * is the only place it can report anyway.
111
111
  *
@@ -11,7 +11,7 @@
11
11
  * line was that tag being refused; it broke nothing and cost an agent the first minutes of
12
12
  * the incident.
13
13
  *
14
- * His decision, 2026-09-18, in his words: *"do your recommendation with option c but not on
14
+ * The owner's decision, 2026-09-18, in their words: *"do your recommendation with option c but not on
15
15
  * the wall. If we can stop the console error that would be good since we are purposely
16
16
  * blocking on that page and it makes it look like there is a mistake when it shows."* — and,
17
17
  * on why the wall's CSP may not simply be loosened: *"I don't want to trust cloudflare with
@@ -112,7 +112,7 @@ export const WEB_ANALYTICS_PUBLIC_HOST = "cursedalchemy.com";
112
112
  * `apps/desk` lost 24, both asserting the console is empty, and the owner's own local console
113
113
  * would have gained a red line on every page.
114
114
  *
115
- * That is the exact cost he asked to be rid of, one environment over. So the guard: the beacon
115
+ * That is the exact cost the owner asked to be rid of, one environment over. So the guard: the beacon
116
116
  * is appended only when the page is being served from {@link WEB_ANALYTICS_PUBLIC_HOST}, which
117
117
  * is the only place it can report anyway.
118
118
  *
@@ -5,7 +5,7 @@
5
5
  * problem a page sees (a stuck video, a failing API, an uncaught error) to {@link CLIENT_ISSUES_PATH};
6
6
  * this door writes one row per report into the app's own D1 `client_issues`, and autopilot's watch
7
7
  * reads that table to file the work. Before it, a problem reached a fix only when the owner copied
8
- * a report off his phone by hand.
8
+ * a report off the owner's phone by hand.
9
9
  *
10
10
  * ```ts
11
11
  * import { CLIENT_ISSUES_DDL, createD1ClientIssuesRecorder } from "cursedbelt-server/client-issues/d1";
@@ -8,7 +8,7 @@
8
8
  * ── What it may hold, and why this much ─────────────────────────────────────
9
9
  * `store.ts`'s header refuses a timeline of a household's private apps, and that still holds for
10
10
  * everything with a PLACE in it. A row here has no place: a visit's start, end, view count and
11
- * attention, the least that answers his question, and only for {@link ENGAGEMENT_VISIT_RETENTION_DAYS}.
11
+ * attention, the least that answers the owner's question, and only for {@link ENGAGEMENT_VISIT_RETENTION_DAYS}.
12
12
  * One row per VISIT (the same cut as the sessions count, `policy.ts:foldView`), not per beacon: 264
13
13
  * visits across the fleet in the 30 days to 2026-10-30, against "a few thousand a month" as the line.
14
14
  *
@@ -4,8 +4,8 @@
4
4
  *
5
5
  * ── The severity split is the feature ───────────────────────────────────────
6
6
  * The owner asked for "an email and a text message about blocking issues like
7
- * these (can't deploy, can't ingest files)". A warning that texts him is a
8
- * warning that gets the channel muted, and a muted channel puts him back where
7
+ * these (can't deploy, can't ingest files)". A warning that texts the owner is a
8
+ * warning that gets the channel muted, and a muted channel puts the owner back where
9
9
  * this whole unit started — finding out days later, by accident. So: in-app for
10
10
  * everything, email + text for `blocking` only, and `notifier.ts` is the only
11
11
  * place that decision is made.
@@ -4,8 +4,8 @@
4
4
  *
5
5
  * ── The severity split is the feature ───────────────────────────────────────
6
6
  * The owner asked for "an email and a text message about blocking issues like
7
- * these (can't deploy, can't ingest files)". A warning that texts him is a
8
- * warning that gets the channel muted, and a muted channel puts him back where
7
+ * these (can't deploy, can't ingest files)". A warning that texts the owner is a
8
+ * warning that gets the channel muted, and a muted channel puts the owner back where
9
9
  * this whole unit started — finding out days later, by accident. So: in-app for
10
10
  * everything, email + text for `blocking` only, and `notifier.ts` is the only
11
11
  * place that decision is made.
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * `cursedbelt-server/incidents` — the fleet's ONE owner-alert primitive: a
3
3
  * condition that is true for a while, told to the owner exactly once, and told
4
- * to him again when it clears.
4
+ * to the owner again when it clears.
5
5
  *
6
6
  * ── Why it exists (the owner, 2026-08-13) ───────────────────────────────────
7
7
  * *"I found out from an agent my collection uploads were stuck … there are
@@ -10,7 +10,7 @@
10
10
  * The incident behind it: 42 videos / 35 GB sat in the collections dropzone and
11
11
  * every scheduled ingest failed all 42 with EPIPE against binary-server, while
12
12
  * binary-server logged that it was under its 12 GB disk reserve — and the
13
- * dropzone deletes originals once they reach the catalog. Nothing told him. Two
13
+ * dropzone deletes originals once they reach the catalog. Nothing told the owner. Two
14
14
  * separate deterministic checks would each have caught it on the first run.
15
15
  *
16
16
  * ── Why it is HERE and not in `satellite-kit` ───────────────────────────────
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * `cursedbelt-server/incidents` — the fleet's ONE owner-alert primitive: a
3
3
  * condition that is true for a while, told to the owner exactly once, and told
4
- * to him again when it clears.
4
+ * to the owner again when it clears.
5
5
  *
6
6
  * ── Why it exists (the owner, 2026-08-13) ───────────────────────────────────
7
7
  * *"I found out from an agent my collection uploads were stuck … there are
@@ -10,7 +10,7 @@
10
10
  * The incident behind it: 42 videos / 35 GB sat in the collections dropzone and
11
11
  * every scheduled ingest failed all 42 with EPIPE against binary-server, while
12
12
  * binary-server logged that it was under its 12 GB disk reserve — and the
13
- * dropzone deletes originals once they reach the catalog. Nothing told him. Two
13
+ * dropzone deletes originals once they reach the catalog. Nothing told the owner. Two
14
14
  * separate deterministic checks would each have caught it on the first run.
15
15
  *
16
16
  * ── Why it is HERE and not in `satellite-kit` ───────────────────────────────
@@ -13,12 +13,12 @@
13
13
  * symptom, a command and a credential without saying what any of them are. So
14
14
  * an incident message is three sentences with fixed jobs, in this order:
15
15
  *
16
- * WHAT BROKE — in words, naming the app. Assume he does not know what
16
+ * WHAT BROKE — in words, naming the app. Assume the owner does not know what
17
17
  * your daemon, flag, tab or port is.
18
- * WHAT IT BLOCKS — what he cannot do until it is fixed. This is the sentence
18
+ * WHAT IT BLOCKS — what the owner cannot do until it is fixed. This is the sentence
19
19
  * that earns a text message at 2am; if you cannot write it,
20
20
  * the incident is a `warning`.
21
- * WHAT TO DO — a next step. A command carries its own `cd`, because he
21
+ * WHAT TO DO — a next step. A command carries its own `cd`, because the owner
22
22
  * opens terminals anywhere (`fleet/rules/
23
23
  * commands-must-run-from-anywhere.md`).
24
24
  *
@@ -50,9 +50,9 @@ export interface AnnounceResult {
50
50
  * overdue backup opened as blocking while the email channel was still
51
51
  * misconfigured, both channels failed, and — because `notifiedAt` was stamped —
52
52
  * nothing would ever have tried again. The owner would have had a blocking
53
- * incident on a board he had no reason to open. The dedupe promise is "you are
53
+ * incident on a board the owner had no reason to open. The dedupe promise is "you are
54
54
  * told ONCE", not "we attempt once": an attempt that reached nobody has not told
55
- * him anything.
55
+ * the owner anything.
56
56
  *
57
57
  * It retries at most hourly, and it STOPS the moment any channel reports
58
58
  * `delivered` — so a permanently broken channel costs one send an hour, and a
@@ -63,7 +63,7 @@ export declare const UNDELIVERED_RETRY_MS: number;
63
63
  export declare function composeOpened(incident: Incident): ChannelMessage;
64
64
  /**
65
65
  * The message for a resolve. It exists so "is it fixed?" is answered without
66
- * him having to go and look — the same reason the open message exists.
66
+ * the owner having to go and look — the same reason the open message exists.
67
67
  */
68
68
  export declare function composeResolved(incident: Incident): ChannelMessage;
69
69
  export interface CreateNotifierOptions {
@@ -6,9 +6,9 @@
6
6
  * overdue backup opened as blocking while the email channel was still
7
7
  * misconfigured, both channels failed, and — because `notifiedAt` was stamped —
8
8
  * nothing would ever have tried again. The owner would have had a blocking
9
- * incident on a board he had no reason to open. The dedupe promise is "you are
9
+ * incident on a board the owner had no reason to open. The dedupe promise is "you are
10
10
  * told ONCE", not "we attempt once": an attempt that reached nobody has not told
11
- * him anything.
11
+ * the owner anything.
12
12
  *
13
13
  * It retries at most hourly, and it STOPS the moment any channel reports
14
14
  * `delivered` — so a permanently broken channel costs one send an hour, and a
@@ -39,7 +39,7 @@ export function composeOpened(incident) {
39
39
  }
40
40
  /**
41
41
  * The message for a resolve. It exists so "is it fixed?" is answered without
42
- * him having to go and look — the same reason the open message exists.
42
+ * the owner having to go and look — the same reason the open message exists.
43
43
  */
44
44
  export function composeResolved(incident) {
45
45
  const minutes = Math.max(1, Math.round(((incident.resolvedAt ?? 0) - incident.firstSeen) / 60000));
@@ -99,8 +99,8 @@ export function createIncidentNotifier(options) {
99
99
  const result = await dispatch(incident, composeOpened(incident), transition);
100
100
  // 🔴 Only stamp `notifiedAt` when there was actually a channel to try.
101
101
  // A host with none (a prod deployment that only stores what the Mac
102
- // pushes it) has not told him anything, and stamping it there is what
103
- // made the resolve message below fire for an open he never saw.
102
+ // pushes it) has not told the owner anything, and stamping it there is what
103
+ // made the resolve message below fire for an open the owner never saw.
104
104
  if (result.results.length > 0) {
105
105
  store.markNotified([incident.fingerprint], summarise(result.results));
106
106
  }
@@ -125,7 +125,7 @@ export function createIncidentNotifier(options) {
125
125
  }
126
126
  for (const incident of t.resolved) {
127
127
  // Never announce a resolve for something whose OPEN was never
128
- // announced — the owner would get "cleared: X" for an X he has never
128
+ // announced — the owner would get "cleared: X" for an X they have never
129
129
  // heard of, which reads as a bug in the alerting rather than as good
130
130
  // news. This happens for real: an incident opened, acknowledged and
131
131
  // resolved between two sweeps of a host that had no channels.
@@ -19,7 +19,7 @@
19
19
  * which is the same uselessness as a permanently green one.
20
20
  *
21
21
  * The dedupe is entirely the console's: post the same thing every five minutes
22
- * for a week and he is told once. So a reporter needs no state, no "have I said
22
+ * for a week and the owner is told once. So a reporter needs no state, no "have I said
23
23
  * this?" flag, and no backoff — which is why this file is forty lines and not
24
24
  * four hundred.
25
25
  *
@@ -5,7 +5,7 @@
5
5
  * "auto notifying me once per incident (it needs to avoid sending me the same
6
6
  * problem over and over in duplicated notifications if it's polling for
7
7
  * problems)". A poller that re-sends every five minutes is the failure mode
8
- * that gets the whole feature muted, which puts him back where he started but
8
+ * that gets the whole feature muted, which puts the owner back where they started but
9
9
  * with more noise. So the unit of this module is a *condition that is true for
10
10
  * a while*, identified by a stable {@link fingerprint}, with a lifecycle —
11
11
  * and a notification is attached to a TRANSITION of that lifecycle, never to
@@ -26,7 +26,7 @@
26
26
  export type IncidentSeverity =
27
27
  /** The owner's own examples: "can't deploy, can't ingest files". Email AND text. */
28
28
  "blocking"
29
- /** Worth knowing, in-app only. A warning that texts him is a warning that mutes the channel. */
29
+ /** Worth knowing, in-app only. A warning that texts the owner is a warning that mutes the channel. */
30
30
  | "warning";
31
31
  /** Where an incident is in its life. */
32
32
  export type IncidentState =
@@ -56,9 +56,9 @@ export interface IncidentReport {
56
56
  severity: IncidentSeverity;
57
57
  /** One line, for a notification subject and a table row. Names the app. */
58
58
  title: string;
59
- /** ELI5: what actually broke. Assume he does not know what your daemon is. */
59
+ /** ELI5: what actually broke. Assume the owner does not know what your daemon is. */
60
60
  whatBroke: string;
61
- /** ELI5: what it stops him doing. This is the sentence that earns the text message. */
61
+ /** ELI5: what it stops the owner doing. This is the sentence that earns the text message. */
62
62
  whatItBlocks: string;
63
63
  /** ELI5: what to do about it. A runnable command carries its own `cd` (fleet rule). */
64
64
  whatToDo: string;
@@ -102,6 +102,6 @@ export interface IncidentTransitions {
102
102
  /**
103
103
  * A stable identity for a condition. Deliberately NOT a hash of the message:
104
104
  * an author who improves the wording of `whatToDo` must not thereby re-alert
105
- * the owner about a problem he already knows about.
105
+ * the owner about a problem they already know about.
106
106
  */
107
107
  export declare function fingerprint(report: Pick<IncidentReport, "source" | "kind" | "subject">): string;
@@ -5,7 +5,7 @@
5
5
  * "auto notifying me once per incident (it needs to avoid sending me the same
6
6
  * problem over and over in duplicated notifications if it's polling for
7
7
  * problems)". A poller that re-sends every five minutes is the failure mode
8
- * that gets the whole feature muted, which puts him back where he started but
8
+ * that gets the whole feature muted, which puts the owner back where they started but
9
9
  * with more noise. So the unit of this module is a *condition that is true for
10
10
  * a while*, identified by a stable {@link fingerprint}, with a lifecycle —
11
11
  * and a notification is attached to a TRANSITION of that lifecycle, never to
@@ -25,7 +25,7 @@
25
25
  /**
26
26
  * A stable identity for a condition. Deliberately NOT a hash of the message:
27
27
  * an author who improves the wording of `whatToDo` must not thereby re-alert
28
- * the owner about a problem he already knows about.
28
+ * the owner about a problem they already know about.
29
29
  */
30
30
  export function fingerprint(report) {
31
31
  return `${report.source}:${report.kind}:${report.subject}`;
@@ -212,3 +212,40 @@ export interface AsyncMapsBudget<Api extends string> {
212
212
  * under load is the one kind that cannot be trusted.
213
213
  */
214
214
  export declare function createMetaTableBudget<Api extends string>(db: Pick<D1LikeDatabase, 'prepare' | 'batch'>, options: Omit<MapsBudgetOptions<Api>, 'store'>): AsyncMapsBudget<Api>;
215
+ /**
216
+ * A Maps key Google REFUSED, remembered in the app's `meta (key, value)` table so the app stops asking
217
+ * (forge tasks 5592, 5764).
218
+ *
219
+ * 🔴 On 2026-11-18 every Places viewport in photos spent a count of the ceiling on a key Google called
220
+ * "invalid", and the 404's reason said only "answered 403". A new key is the owner's hands, never minutes
221
+ * away, so a 401/403 is written down for an hour: until then the door answers with the refusal's own words
222
+ * and touches neither the ceiling nor the network. photos, trivia and family each held a copy of this; a
223
+ * fix to it (a new status Google uses to refuse) now reaches all three.
224
+ *
225
+ * One row per API (`maps-refused.<api>`), because a key restricted away from ONE API is still good for
226
+ * the rest.
227
+ */
228
+ /** How long an app stops asking after Google refused its key. */
229
+ export declare const KEY_REFUSED_HOLD_MS: number;
230
+ /** The `meta` row a refusal of `api` is remembered under: `{ at: ISO, reason }`. */
231
+ export declare const keyRefusedRow: (api: string) => string;
232
+ /** The HTTP statuses that mean Google refuses the KEY, not the request. */
233
+ export declare const isKeyRefusal: (status: number) => boolean;
234
+ export interface KeyRefusalOptions {
235
+ /** The app's own name, as a reader sees it in the reason ("photos", "trivia", "family"). */
236
+ app: string;
237
+ /** Defaults to the wall clock; a spec passes its own. */
238
+ now?: () => number;
239
+ /** Defaults to {@link KEY_REFUSED_HOLD_MS}. */
240
+ holdMs?: number;
241
+ }
242
+ export interface KeyRefusalMemory {
243
+ /** The refusal of `api` still holding now, in words a reader sees — or null. A malformed row is null. */
244
+ held(api: string): Promise<string | null>;
245
+ /**
246
+ * When `response` is Google refusing the key, remember it and return the reason; otherwise null.
247
+ * Reads the body (Google's one line of plain text, "The provided API key is invalid.") only then.
248
+ */
249
+ record(api: string, response: Response): Promise<string | null>;
250
+ }
251
+ export declare function createKeyRefusalMemory(db: Pick<D1LikeDatabase, 'prepare'>, options: KeyRefusalOptions): KeyRefusalMemory;
@@ -248,3 +248,55 @@ export function createMetaTableBudget(db, options) {
248
248
  },
249
249
  };
250
250
  }
251
+ // ───────────────────────────── a refused key ─────────────────────────────
252
+ /**
253
+ * A Maps key Google REFUSED, remembered in the app's `meta (key, value)` table so the app stops asking
254
+ * (forge tasks 5592, 5764).
255
+ *
256
+ * 🔴 On 2026-11-18 every Places viewport in photos spent a count of the ceiling on a key Google called
257
+ * "invalid", and the 404's reason said only "answered 403". A new key is the owner's hands, never minutes
258
+ * away, so a 401/403 is written down for an hour: until then the door answers with the refusal's own words
259
+ * and touches neither the ceiling nor the network. photos, trivia and family each held a copy of this; a
260
+ * fix to it (a new status Google uses to refuse) now reaches all three.
261
+ *
262
+ * One row per API (`maps-refused.<api>`), because a key restricted away from ONE API is still good for
263
+ * the rest.
264
+ */
265
+ /** How long an app stops asking after Google refused its key. */
266
+ export const KEY_REFUSED_HOLD_MS = 60 * 60 * 1000;
267
+ /** The `meta` row a refusal of `api` is remembered under: `{ at: ISO, reason }`. */
268
+ export const keyRefusedRow = (api) => `maps-refused.${api}`;
269
+ /** The HTTP statuses that mean Google refuses the KEY, not the request. */
270
+ export const isKeyRefusal = (status) => status === 401 || status === 403;
271
+ export function createKeyRefusalMemory(db, options) {
272
+ const now = options.now ?? Date.now;
273
+ const holdMs = options.holdMs ?? KEY_REFUSED_HOLD_MS;
274
+ return {
275
+ async held(api) {
276
+ const row = await db.prepare('SELECT value FROM meta WHERE key = ?').bind(keyRefusedRow(api)).first();
277
+ if (!row)
278
+ return null;
279
+ try {
280
+ const mark = JSON.parse(row.value);
281
+ const at = typeof mark.at === 'string' ? Date.parse(mark.at) : Number.NaN;
282
+ if (!Number.isFinite(at) || now() - at >= holdMs || typeof mark.reason !== 'string')
283
+ return null;
284
+ return `${mark.reason} ${options.app} stopped asking at ${mark.at} and asks again an hour after.`;
285
+ }
286
+ catch {
287
+ return null;
288
+ }
289
+ },
290
+ async record(api, response) {
291
+ if (!isKeyRefusal(response.status))
292
+ return null;
293
+ const said = (await response.text().catch(() => '')).trim().slice(0, 200);
294
+ const reason = `Google refuses the Maps key ${options.app} holds, for ${api} (${response.status}${said ? `: ${said}` : ''}) — a new GOOGLE_MAPS_API_KEY is needed; the map draws every pin meanwhile.`;
295
+ await db
296
+ .prepare('INSERT INTO meta (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value')
297
+ .bind(keyRefusedRow(api), JSON.stringify({ at: new Date(now()).toISOString(), reason }))
298
+ .run();
299
+ return reason;
300
+ },
301
+ };
302
+ }
@@ -7,13 +7,15 @@
7
7
  * request a query string may ask for (clamped, so the cache key space stays tiny), the URL with
8
8
  * the fleet's map styling, the cache key, and an LRU for the bytes.
9
9
  *
10
- * 🔴 The FETCH is not here, on purpose. Each app keeps its own ONE DOOR to Google — the place
11
- * its `cursedbelt-server/maps-budget` ceiling is consumed immediately before the request — so
12
- * the ceiling and the call can never be separated. Build the URL here; spend it there.
10
+ * 🔴 The FETCH is here only inside {@link renderStaticMap}, THE door: a key Google refused, then the
11
+ * app's `cursedbelt-server/maps-budget` ceiling consumed immediately before the one request, so the
12
+ * ceiling and the call can never be separated. photos and trivia each held a copy of it until forge
13
+ * task 5764; a fix to the refusal or the timeout now reaches every app that draws a map.
13
14
  *
14
15
  * 🔴 The key NEVER reaches a browser: `GOOGLE_MAPS_API_KEY` is restricted by API and not by
15
16
  * HTTP referrer, so the imagery is proxied and the frame's overlay is our own SVG.
16
17
  */
18
+ import type { AsyncMapsBudget, KeyRefusalMemory } from '../maps-budget/mapsBudget.js';
17
19
  /** The one Static Maps endpoint. An app's door checks a URL starts with it. */
18
20
  export declare const STATIC_MAP_HOST = "https://maps.googleapis.com/maps/api/staticmap";
19
21
  /** A lat/lng. Structural, so the server tier needs nothing from the React package. */
@@ -101,3 +103,28 @@ export declare function createImageCache(max?: number): {
101
103
  set(key: string, value: Uint8Array): void;
102
104
  readonly size: number;
103
105
  };
106
+ /** The app's seam to Google: its key and its fetch (a spec passes a fake). */
107
+ export interface StaticMapSeam {
108
+ apiKey: string;
109
+ fetch: (url: string, init?: RequestInit) => Promise<Response>;
110
+ }
111
+ export type RenderedStaticMap = {
112
+ ok: true;
113
+ bytes: Uint8Array;
114
+ } | {
115
+ ok: false;
116
+ reason: string;
117
+ };
118
+ /** How long the door waits on Google before it gives up and the frame draws its graticule. */
119
+ export declare const STATIC_MAP_TIMEOUT_MS = 8000;
120
+ /**
121
+ * THE door to Google Static Maps: a refused key and the ceiling first, then the one request, with a
122
+ * timeout. A refusal touches no network, and a 401/403 is remembered so the next viewport does not ask.
123
+ */
124
+ export declare function renderStaticMap(input: {
125
+ request: StaticMapRequest;
126
+ maps: StaticMapSeam;
127
+ budget: Pick<AsyncMapsBudget<'staticmap'>, 'consume'>;
128
+ refusals: KeyRefusalMemory;
129
+ timeoutMs?: number;
130
+ }): Promise<RenderedStaticMap>;
@@ -7,9 +7,10 @@
7
7
  * request a query string may ask for (clamped, so the cache key space stays tiny), the URL with
8
8
  * the fleet's map styling, the cache key, and an LRU for the bytes.
9
9
  *
10
- * 🔴 The FETCH is not here, on purpose. Each app keeps its own ONE DOOR to Google — the place
11
- * its `cursedbelt-server/maps-budget` ceiling is consumed immediately before the request — so
12
- * the ceiling and the call can never be separated. Build the URL here; spend it there.
10
+ * 🔴 The FETCH is here only inside {@link renderStaticMap}, THE door: a key Google refused, then the
11
+ * app's `cursedbelt-server/maps-budget` ceiling consumed immediately before the one request, so the
12
+ * ceiling and the call can never be separated. photos and trivia each held a copy of it until forge
13
+ * task 5764; a fix to the refusal or the timeout now reaches every app that draws a map.
13
14
  *
14
15
  * 🔴 The key NEVER reaches a browser: `GOOGLE_MAPS_API_KEY` is restricted by API and not by
15
16
  * HTTP referrer, so the imagery is proxied and the frame's overlay is our own SVG.
@@ -169,3 +170,34 @@ export function createImageCache(max = 160) {
169
170
  },
170
171
  };
171
172
  }
173
+ /** How long the door waits on Google before it gives up and the frame draws its graticule. */
174
+ export const STATIC_MAP_TIMEOUT_MS = 8000;
175
+ /**
176
+ * THE door to Google Static Maps: a refused key and the ceiling first, then the one request, with a
177
+ * timeout. A refusal touches no network, and a 401/403 is remembered so the next viewport does not ask.
178
+ */
179
+ export async function renderStaticMap(input) {
180
+ const held = await input.refusals.held('staticmap');
181
+ if (held)
182
+ return { ok: false, reason: held };
183
+ const verdict = await input.budget.consume('staticmap');
184
+ if (!verdict.allowed)
185
+ return { ok: false, reason: verdict.reason };
186
+ const controller = new AbortController();
187
+ const timer = setTimeout(() => controller.abort(), input.timeoutMs ?? STATIC_MAP_TIMEOUT_MS);
188
+ try {
189
+ const response = await input.maps.fetch(staticMapUrl(input.request, input.maps.apiKey), { signal: controller.signal });
190
+ const refused = await input.refusals.record('staticmap', response);
191
+ if (refused)
192
+ return { ok: false, reason: refused };
193
+ if (!response.ok)
194
+ return { ok: false, reason: `Google staticmap answered ${response.status}` };
195
+ return { ok: true, bytes: new Uint8Array(await response.arrayBuffer()) };
196
+ }
197
+ catch (error) {
198
+ return { ok: false, reason: `Google staticmap did not answer (${error instanceof Error ? error.message : 'unknown'})` };
199
+ }
200
+ finally {
201
+ clearTimeout(timer);
202
+ }
203
+ }
@@ -1,11 +1,11 @@
1
1
  /**
2
- * The ACCOUNTS page — where the owner changes his master password.
2
+ * The ACCOUNTS page — where the owner changes their master password.
3
3
  *
4
4
  * ── Why it is here and not in the app ───────────────────────────────────────
5
5
  * `cursedbelt@2.5.1`'s React `MasterLockMenuItems` dialog minted a FRESH `kdf` salt on every
6
6
  * rotation, which is what the wire looked like before accounts existed. Every account on an
7
7
  * app now derives under ONE shared descriptor, so honoring that salt would store a verifier
8
- * hash nothing could ever match: the owner sets a new password, the rotation logs him out,
8
+ * hash nothing could ever match: the owner sets a new password, the rotation logs them out,
9
9
  * and neither the old nor the new one opens the app. `guard.ts` therefore answers that shape
10
10
  * `409 {"error":"stale-client"}`. That is the safe failure; this page is the fix.
11
11
  *
@@ -8,7 +8,7 @@
8
8
  * six before the first wait. On `collections`' Worker it was worse: the count lived in a JSON
9
9
  * blob snapshotted per request, so the twelve each wrote `failures + 1` over one another and
10
10
  * the burst was RECORDED as one guess. The same blob holds the open unlocks, so a failed guess
11
- * settling after the owner's unlock could also drop his fresh session.
11
+ * settling after the owner's unlock could also drop their fresh session.
12
12
  *
13
13
  * `charge` is the one operation that closes it: check the window AND, when it is open, charge
14
14
  * a failure in the same step, before anything slow happens. A correct verifier then `clear`s
@@ -204,7 +204,7 @@ export declare class MasterLock {
204
204
  * App-wide, one unlock was right: one person, one site, and the owner's *"entering it
205
205
  * in one site will only apply it to that site"*. Per person it is wrong twice over.
206
206
  * The owner asked to *"put in prompts for the orch and monitor it from our phones and
207
- * other devices"* — so the desk and the phone are both his, both open at once, and a
207
+ * other devices"* — so the desk and the phone are both the owner's, both open at once, and a
208
208
  * single-token model would have each unlock silently evict the other. And the guard
209
209
  * now demands a PRESENTED token rather than reading `unlocked` (see the guard's own
210
210
  * note), which is only possible if every device that typed the password holds one.
@@ -375,7 +375,7 @@ export declare class MasterLock {
375
375
  /**
376
376
  * Add ANOTHER master password, and with it another tenant.
377
377
  *
378
- * The owner's model, in his words: *"The master passwords represent their own tenants
378
+ * The owner's model, in their words: *"The master passwords represent their own tenants
379
379
  * or you can think of it as a fully separate account even though I am the user in both
380
380
  * cases … If I login with a master password I only see the files I added or removed
381
381
  * with that login."*
@@ -79,7 +79,7 @@ export class MasterLock {
79
79
  * App-wide, one unlock was right: one person, one site, and the owner's *"entering it
80
80
  * in one site will only apply it to that site"*. Per person it is wrong twice over.
81
81
  * The owner asked to *"put in prompts for the orch and monitor it from our phones and
82
- * other devices"* — so the desk and the phone are both his, both open at once, and a
82
+ * other devices"* — so the desk and the phone are both the owner's, both open at once, and a
83
83
  * single-token model would have each unlock silently evict the other. And the guard
84
84
  * now demands a PRESENTED token rather than reading `unlocked` (see the guard's own
85
85
  * note), which is only possible if every device that typed the password holds one.
@@ -443,7 +443,7 @@ export class MasterLock {
443
443
  /**
444
444
  * Add ANOTHER master password, and with it another tenant.
445
445
  *
446
- * The owner's model, in his words: *"The master passwords represent their own tenants
446
+ * The owner's model, in their words: *"The master passwords represent their own tenants
447
447
  * or you can think of it as a fully separate account even though I am the user in both
448
448
  * cases … If I login with a master password I only see the files I added or removed
449
449
  * with that login."*
@@ -851,7 +851,7 @@ function readAccount(value) {
851
851
  };
852
852
  }
853
853
  /** `acct-1`, `acct-2`, … — the lowest number no live account already holds. Sequential
854
- * because the owner reads these ids out of his own vault and types them into a terminal;
854
+ * because the owner reads these ids out of their own vault and types them into a terminal;
855
855
  * a random id would be one more thing to write down. */
856
856
  function nextAccountId(accounts) {
857
857
  const taken = new Set(accounts.map((account) => account.id));
@@ -11,7 +11,7 @@
11
11
  * *"I would pick one that only I know and use and she could pick one for only she knows
12
12
  * just like we did for the vault app."* Two people cannot share one record — the first to
13
13
  * rotate it locks the second out of an app they were granted — and they must not share one
14
- * unlock either, or her phone opens his desk.
14
+ * unlock either, or her phone opens the owner's desk.
15
15
  *
16
16
  * So the unit here is the PERSON. Each principal gets its own {@link MasterLock}: its own
17
17
  * KDF salt, its own `argon2id(verifier)`, its own idle clock, its own guess throttle and
@@ -30,13 +30,14 @@
30
30
  *
31
31
  * 🔴 Worker-safe: nothing here imports `bun:*`.
32
32
  */
33
+ import { IDLE_AFTER_MS } from "cursedops/idle-window";
33
34
  import type { D1LikeDatabase } from "../d1/types.js";
34
35
  /** One row per name: a presence mark (`reader:<tenant>`) or a tick's last run (`tick:<name>`). */
35
36
  export declare const PRESENCE_DDL: string[];
36
37
  /** How often one isolate writes the same presence mark. Presence is an hours-scale question. */
37
38
  export declare const PRESENCE_THROTTLE_MS: number;
38
- /** The default "nobody is here" line: no use for this long and scheduled work stands down. */
39
- export declare const IDLE_AFTER_MS: number;
39
+ /** The default "nobody is here" line: no use for this long and scheduled work stands down. cursedops' one home (forge task 5853). */
40
+ export { IDLE_AFTER_MS };
40
41
  /**
41
42
  * Note that someone used `name` now. At most one D1 write per isolate per `throttleMs`, and the row only
42
43
  * moves when it is older than that, so many isolates add up to a handful of writes an hour while anyone is