cursedauth 0.1.0

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 (108) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +87 -0
  3. package/dist/account/AccountMenu.d.ts +153 -0
  4. package/dist/account/AccountMenu.d.ts.map +1 -0
  5. package/dist/account/AccountMenu.js +388 -0
  6. package/dist/account/AccountMenu.js.map +1 -0
  7. package/dist/account/AccountNotice.d.ts +35 -0
  8. package/dist/account/AccountNotice.d.ts.map +1 -0
  9. package/dist/account/AccountNotice.js +133 -0
  10. package/dist/account/AccountNotice.js.map +1 -0
  11. package/dist/account/accountNotice.state.d.ts +20 -0
  12. package/dist/account/accountNotice.state.d.ts.map +1 -0
  13. package/dist/account/accountNotice.state.js +55 -0
  14. package/dist/account/accountNotice.state.js.map +1 -0
  15. package/dist/account/avatar.d.ts +37 -0
  16. package/dist/account/avatar.d.ts.map +1 -0
  17. package/dist/account/avatar.js +47 -0
  18. package/dist/account/avatar.js.map +1 -0
  19. package/dist/accountSlot.client.d.ts +113 -0
  20. package/dist/accountSlot.client.d.ts.map +1 -0
  21. package/dist/accountSlot.client.js +330 -0
  22. package/dist/accountSlot.client.js.map +1 -0
  23. package/dist/accountSlots.d.ts +192 -0
  24. package/dist/accountSlots.d.ts.map +1 -0
  25. package/dist/accountSlots.js +274 -0
  26. package/dist/accountSlots.js.map +1 -0
  27. package/dist/auth.d.ts +167 -0
  28. package/dist/auth.d.ts.map +1 -0
  29. package/dist/auth.js +310 -0
  30. package/dist/auth.js.map +1 -0
  31. package/dist/auth.server.d.ts +35 -0
  32. package/dist/auth.server.d.ts.map +1 -0
  33. package/dist/auth.server.js +67 -0
  34. package/dist/auth.server.js.map +1 -0
  35. package/dist/clientDescription.d.ts +186 -0
  36. package/dist/clientDescription.d.ts.map +1 -0
  37. package/dist/clientDescription.js +278 -0
  38. package/dist/clientDescription.js.map +1 -0
  39. package/dist/constantTime.d.ts +35 -0
  40. package/dist/constantTime.d.ts.map +1 -0
  41. package/dist/constantTime.js +46 -0
  42. package/dist/constantTime.js.map +1 -0
  43. package/dist/contentCensus.d.ts +59 -0
  44. package/dist/contentCensus.d.ts.map +1 -0
  45. package/dist/contentCensus.js +55 -0
  46. package/dist/contentCensus.js.map +1 -0
  47. package/dist/index.d.ts +25 -0
  48. package/dist/index.d.ts.map +1 -0
  49. package/dist/index.js +24 -0
  50. package/dist/index.js.map +1 -0
  51. package/dist/mountGatedApp.d.ts +128 -0
  52. package/dist/mountGatedApp.d.ts.map +1 -0
  53. package/dist/mountGatedApp.js +107 -0
  54. package/dist/mountGatedApp.js.map +1 -0
  55. package/dist/runtimeMode.d.ts +28 -0
  56. package/dist/runtimeMode.d.ts.map +1 -0
  57. package/dist/runtimeMode.js +37 -0
  58. package/dist/runtimeMode.js.map +1 -0
  59. package/dist/secureRequest.d.ts +22 -0
  60. package/dist/secureRequest.d.ts.map +1 -0
  61. package/dist/secureRequest.js +27 -0
  62. package/dist/secureRequest.js.map +1 -0
  63. package/dist/sso.d.ts +373 -0
  64. package/dist/sso.d.ts.map +1 -0
  65. package/dist/sso.js +420 -0
  66. package/dist/sso.js.map +1 -0
  67. package/dist/ssoAutoSignIn.d.ts +272 -0
  68. package/dist/ssoAutoSignIn.d.ts.map +1 -0
  69. package/dist/ssoAutoSignIn.js +431 -0
  70. package/dist/ssoAutoSignIn.js.map +1 -0
  71. package/dist/ssoConsumer.server.d.ts +295 -0
  72. package/dist/ssoConsumer.server.d.ts.map +1 -0
  73. package/dist/ssoConsumer.server.js +972 -0
  74. package/dist/ssoConsumer.server.js.map +1 -0
  75. package/dist/stageIdentity.d.ts +72 -0
  76. package/dist/stageIdentity.d.ts.map +1 -0
  77. package/dist/stageIdentity.js +74 -0
  78. package/dist/stageIdentity.js.map +1 -0
  79. package/dist/ui/popover.d.ts +190 -0
  80. package/dist/ui/popover.d.ts.map +1 -0
  81. package/dist/ui/popover.js +351 -0
  82. package/dist/ui/popover.js.map +1 -0
  83. package/dist/userSessions.d.ts +205 -0
  84. package/dist/userSessions.d.ts.map +1 -0
  85. package/dist/userSessions.js +419 -0
  86. package/dist/userSessions.js.map +1 -0
  87. package/package.json +115 -0
  88. package/src/account/AccountMenu.tsx +729 -0
  89. package/src/account/AccountNotice.tsx +223 -0
  90. package/src/account/accountNotice.state.ts +66 -0
  91. package/src/account/avatar.ts +50 -0
  92. package/src/accountSlot.client.ts +362 -0
  93. package/src/accountSlots.ts +305 -0
  94. package/src/auth.server.ts +89 -0
  95. package/src/auth.ts +515 -0
  96. package/src/clientDescription.ts +366 -0
  97. package/src/constantTime.ts +45 -0
  98. package/src/contentCensus.ts +106 -0
  99. package/src/index.ts +58 -0
  100. package/src/mountGatedApp.ts +240 -0
  101. package/src/runtimeMode.ts +37 -0
  102. package/src/secureRequest.ts +25 -0
  103. package/src/sso.ts +767 -0
  104. package/src/ssoAutoSignIn.ts +544 -0
  105. package/src/ssoConsumer.server.ts +1260 -0
  106. package/src/stageIdentity.ts +76 -0
  107. package/src/ui/popover.ts +390 -0
  108. package/src/userSessions.ts +678 -0
@@ -0,0 +1,55 @@
1
+ /**
2
+ * The LISTENER half of `AccountNotice` β€” deliberately tiny, and deliberately the
3
+ * only half that is eager.
4
+ *
5
+ * ── Why the split exists ────────────────────────────────────────────────────
6
+ * The banner renders nothing at all until an account goes wrong, which is almost
7
+ * never β€” and it carries a ~4 KB scoped stylesheet to be styleable in nineteen
8
+ * apps that each keep their own Tailwind `@source` list. Shipping that in every
9
+ * app's ENTRY chunk to display nothing is exactly the cost `test:gates:artifacts`
10
+ * exists to catch, and it caught it: `notes` went 581.07 KB against a 578 KB
11
+ * budget the moment `AccountMenu` imported the banner directly.
12
+ *
13
+ * πŸ”΄ Raising the budget was the wrong fix and the repo has already ruled on it
14
+ * once (unit 26: station's entry chunk was SPLIT, 783 β†’ 468 KB, and the ceiling
15
+ * LOWERED). `notes` is *"an inbox, a search box and lists β€” a triage tool, often
16
+ * on a phone"*, which is the reader least able to pay for a banner they will
17
+ * probably never see.
18
+ *
19
+ * So the subscription stays eager β€” it MUST, because a lazily-loaded component is
20
+ * not mounted and therefore cannot hear the event that would make it appear β€” and
21
+ * the banner is fetched only once there is something to say.
22
+ */
23
+ import { useEffect, useState } from "react";
24
+ import { ACCOUNT_DRIFT_EVENT } from "../accountSlot.client";
25
+ import { takeSsoError } from "../ssoAutoSignIn";
26
+ /**
27
+ * Watch for the two ways an account goes wrong. Returns null almost always.
28
+ *
29
+ * A hook rather than a component so the cost of watching is a `useState` and one
30
+ * listener β€” no styles, no markup, nothing in the entry chunk but this file.
31
+ */
32
+ export function useAccountNotice() {
33
+ const [notice, setNotice] = useState(null);
34
+ useEffect(() => {
35
+ // A refused hop, taken OFF the URL as it is read β€” the owner's complaint was
36
+ // that the address bar kept claiming he had no access while he used the app
37
+ // perfectly well. `takeSsoError` is one-shot by design, so whoever reads it
38
+ // owns reporting it; this is now that reader for every app in the fleet.
39
+ const message = takeSsoError();
40
+ if (message)
41
+ setNotice({ kind: "sso-error", message });
42
+ const onDrift = (event) => {
43
+ const detail = event.detail;
44
+ // Drift outranks a stale hop error: it is live, and it is about the
45
+ // request the person just made rather than one navigation ago.
46
+ if (detail && typeof detail.actual?.id === "string") {
47
+ setNotice({ kind: "drift", detail });
48
+ }
49
+ };
50
+ globalThis.addEventListener?.(ACCOUNT_DRIFT_EVENT, onDrift);
51
+ return () => globalThis.removeEventListener?.(ACCOUNT_DRIFT_EVENT, onDrift);
52
+ }, []);
53
+ return [notice, setNotice];
54
+ }
55
+ //# sourceMappingURL=accountNotice.state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accountNotice.state.js","sourceRoot":"","sources":["../../src/account/accountNotice.state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAOhD;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB;IAI/B,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAA4B,IAAI,CAAC,CAAC;IAEtE,SAAS,CAAC,GAAG,EAAE;QACd,6EAA6E;QAC7E,4EAA4E;QAC5E,4EAA4E;QAC5E,yEAAyE;QACzE,MAAM,OAAO,GAAG,YAAY,EAAE,CAAC;QAC/B,IAAI,OAAO;YAAE,SAAS,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC,CAAC;QAEvD,MAAM,OAAO,GAAG,CAAC,KAAY,EAAE,EAAE;YAChC,MAAM,MAAM,GAAI,KAAuC,CAAC,MAAM,CAAC;YAC/D,oEAAoE;YACpE,+DAA+D;YAC/D,IAAI,MAAM,IAAI,OAAO,MAAM,CAAC,MAAM,EAAE,EAAE,KAAK,QAAQ,EAAE,CAAC;gBACrD,SAAS,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;YACtC,CAAC;QACF,CAAC,CAAC;QACF,UAAU,CAAC,gBAAgB,EAAE,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC;QAC5D,OAAO,GAAG,EAAE,CAAC,UAAU,CAAC,mBAAmB,EAAE,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC;IAC7E,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Where the fleet's ONE profile picture lives, as a URL.
3
+ *
4
+ * The owner asked for a picture set once and shown everywhere
5
+ * (`___Todo-Ready/life-app-issues.md`), so the image belongs to the ACCOUNT and is served
6
+ * by the accounts satellite: `https://auth…/avatar/<user id>`. Every app renders that URL;
7
+ * no app stores a copy, so there is no such thing as a stale one.
8
+ *
9
+ * πŸ”΄ This helper exists so the path shape is written ONCE. Eighteen headers each
10
+ * concatenating `${accountsUrl}/avatar/${id}` is eighteen chances to disagree about the
11
+ * trailing slash β€” the same drift that put three copies of the breadcrumb markup in the
12
+ * fleet before unit 16.
13
+ */
14
+ /** The route `apps/auth` mounts, open, outside its gates. */
15
+ export declare const ACCOUNT_AVATAR_PATH = "/avatar";
16
+ /**
17
+ * The account's picture, or `undefined` when there is nothing to point at.
18
+ *
19
+ * `undefined` rather than a placeholder URL: the initials fallback is the CLIENT's
20
+ * (cursedbelt's `Avatar`), so a missing accounts origin has to read as "no src", not as a
21
+ * broken image. An app that is not an SSO door β€” the local vault daemon, the
22
+ * owner-password apps β€” passes no `accountsUrl` and correctly gets initials.
23
+ */
24
+ export declare function accountAvatarUrl(accountsUrl: string | null | undefined, userId: string | null | undefined): string | undefined;
25
+ /**
26
+ * The initials drawn in the circle when there is no picture.
27
+ *
28
+ * Deliberately the same rule as cursedbelt's `Avatar` β€” two initials from a two-word name,
29
+ * otherwise the first two characters of the name or the local part of the address. It is
30
+ * duplicated here for one reason and it is a real one: `AccountMenu` renders into apps with
31
+ * per-app Tailwind `@source` lists and therefore ships its own scoped stylesheet rather
32
+ * than utility classes (see that file's header), so it cannot mount a Tailwind component.
33
+ * The RULE is what has to match, and this test-covered function is what makes that provable
34
+ * rather than hopeful.
35
+ */
36
+ export declare function accountInitials(name?: string, email?: string): string;
37
+ //# sourceMappingURL=avatar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"avatar.d.ts","sourceRoot":"","sources":["../../src/account/avatar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,6DAA6D;AAC7D,eAAO,MAAM,mBAAmB,YAAY,CAAC;AAE7C;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC/B,WAAW,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACtC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAC/B,MAAM,GAAG,SAAS,CAGpB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAKrE"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Where the fleet's ONE profile picture lives, as a URL.
3
+ *
4
+ * The owner asked for a picture set once and shown everywhere
5
+ * (`___Todo-Ready/life-app-issues.md`), so the image belongs to the ACCOUNT and is served
6
+ * by the accounts satellite: `https://auth…/avatar/<user id>`. Every app renders that URL;
7
+ * no app stores a copy, so there is no such thing as a stale one.
8
+ *
9
+ * πŸ”΄ This helper exists so the path shape is written ONCE. Eighteen headers each
10
+ * concatenating `${accountsUrl}/avatar/${id}` is eighteen chances to disagree about the
11
+ * trailing slash β€” the same drift that put three copies of the breadcrumb markup in the
12
+ * fleet before unit 16.
13
+ */
14
+ /** The route `apps/auth` mounts, open, outside its gates. */
15
+ export const ACCOUNT_AVATAR_PATH = "/avatar";
16
+ /**
17
+ * The account's picture, or `undefined` when there is nothing to point at.
18
+ *
19
+ * `undefined` rather than a placeholder URL: the initials fallback is the CLIENT's
20
+ * (cursedbelt's `Avatar`), so a missing accounts origin has to read as "no src", not as a
21
+ * broken image. An app that is not an SSO door β€” the local vault daemon, the
22
+ * owner-password apps β€” passes no `accountsUrl` and correctly gets initials.
23
+ */
24
+ export function accountAvatarUrl(accountsUrl, userId) {
25
+ if (!accountsUrl || !userId)
26
+ return undefined;
27
+ return `${accountsUrl.replace(/\/$/, "")}${ACCOUNT_AVATAR_PATH}/${encodeURIComponent(userId)}`;
28
+ }
29
+ /**
30
+ * The initials drawn in the circle when there is no picture.
31
+ *
32
+ * Deliberately the same rule as cursedbelt's `Avatar` β€” two initials from a two-word name,
33
+ * otherwise the first two characters of the name or the local part of the address. It is
34
+ * duplicated here for one reason and it is a real one: `AccountMenu` renders into apps with
35
+ * per-app Tailwind `@source` lists and therefore ships its own scoped stylesheet rather
36
+ * than utility classes (see that file's header), so it cannot mount a Tailwind component.
37
+ * The RULE is what has to match, and this test-covered function is what makes that provable
38
+ * rather than hopeful.
39
+ */
40
+ export function accountInitials(name, email) {
41
+ const base = (name?.trim() || email?.split("@")[0] || "?").trim();
42
+ const parts = base.split(/\s+/).filter(Boolean);
43
+ if (parts.length >= 2)
44
+ return `${parts[0]?.[0] ?? ""}${parts[1]?.[0] ?? ""}`.toUpperCase();
45
+ return base.slice(0, 2).toUpperCase();
46
+ }
47
+ //# sourceMappingURL=avatar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"avatar.js","sourceRoot":"","sources":["../../src/account/avatar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,6DAA6D;AAC7D,MAAM,CAAC,MAAM,mBAAmB,GAAG,SAAS,CAAC;AAE7C;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAC/B,WAAsC,EACtC,MAAiC;IAEjC,IAAI,CAAC,WAAW,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAC9C,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,mBAAmB,IAAI,kBAAkB,CAAC,MAAM,CAAC,EAAE,CAAC;AAChG,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,eAAe,CAAC,IAAa,EAAE,KAAc;IAC5D,MAAM,IAAI,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IAClE,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAChD,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC;QAAE,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,WAAW,EAAE,CAAC;IAC3F,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;AACvC,CAAC"}
@@ -0,0 +1,113 @@
1
+ /**
2
+ * The browser half of account slots: which account THIS TAB is, and how every
3
+ * request it makes says so (2026-08-12).
4
+ *
5
+ * ── Why a tab can have its own account at all ───────────────────────────────
6
+ * Cookies are per-origin, so two tabs of one app share one cookie jar and
7
+ * cannot each hold a different session. What they CAN each hold is a different
8
+ * `sessionStorage` β€” that storage is per-tab by definition, survives reloads
9
+ * and in-app navigation, and dies with the tab. So the jar holds every account
10
+ * (see `accountSlots.ts`), and the tab remembers WHICH of them it is.
11
+ *
12
+ * ── Two channels, and why both ──────────────────────────────────────────────
13
+ * - **`sessionStorage`** is the tab's memory. It is what makes the choice
14
+ * survive a reload and every click inside the app.
15
+ * - **The `?authuser=` URL param** is how a slot ENTERS a tab: the SSO
16
+ * callback lands on it, "open this account in a new window" links to it, and
17
+ * a bookmark restores it. It is read once, at boot, and then re-asserted on
18
+ * the URL so what the address bar says is true.
19
+ *
20
+ * The URL wins at boot when both are present, because the URL is what the
21
+ * person just navigated to.
22
+ *
23
+ * ── What the fetch patch is for, and its one limit ──────────────────────────
24
+ * These apps are SPAs: the document is static HTML that needs no session, and
25
+ * everything that does comes back through `fetch`. So attaching one header to
26
+ * same-origin `fetch` covers the authenticated surface completely, without
27
+ * every route constant in eighteen apps growing a query parameter β€” which is
28
+ * the change nobody would apply consistently, and one missed call site is a
29
+ * request that silently acts as the wrong account.
30
+ *
31
+ * πŸ”΄ The limit: a same-origin SUBRESOURCE that needs the session β€” an `<img>`,
32
+ * a `<video>`, a download, an EventSource β€” is not a `fetch` and carries no
33
+ * header. Those must be built with `slotUrl()`. In this fleet almost nothing is
34
+ * affected, because media is served by binary-server against signed tokens
35
+ * rather than a session cookie, but an app that adds a session-gated `<img>`
36
+ * has to say so in the URL.
37
+ *
38
+ * ── Slot 0 costs nothing ────────────────────────────────────────────────────
39
+ * Every function here short-circuits at slot 0: no storage write, no URL
40
+ * rewrite, no patched `fetch`, no header. The overwhelmingly common case β€” one
41
+ * account β€” behaves exactly as it did before this file existed, which is also
42
+ * why nothing in the fleet had to change to adopt it.
43
+ */
44
+ import { ACCOUNT_SLOT_HEADER, ACCOUNT_SLOT_PARAM, ACCOUNT_USER_HEADER } from "./accountSlots";
45
+ /** Per-tab, like the SSO auto-sign-in guards next door and for the same
46
+ * reason: it must never be a reason a DIFFERENT tab acts as somebody else. */
47
+ export declare const ACCOUNT_SLOT_KEY = "satellite.account.slot.v1";
48
+ /**
49
+ * Which account this tab is acting as.
50
+ *
51
+ * URL first (that is how a slot arrives), then the tab's memory, then 0. Safe
52
+ * to call before `installAccountSlot`, and safe to call on a server (no
53
+ * `location`, no storage β†’ 0).
54
+ */
55
+ export declare function currentAccountSlot(): number;
56
+ /**
57
+ * `url` with this tab's account on it.
58
+ *
59
+ * For the things a header cannot reach: a session-gated `<img src>`, an
60
+ * `EventSource`, a download link, an `<a>` to another page of this app. Slot 0
61
+ * returns the URL untouched.
62
+ */
63
+ export declare function slotUrl(url: string, slot?: number): string;
64
+ /**
65
+ * A URL that opens `slot` β€” in this app, in another tab or window.
66
+ *
67
+ * The owner-facing point of the whole feature: "open my test account beside my
68
+ * own". Always absolute, because the caller is about to hand it to
69
+ * `window.open` or an `<a target="_blank">`.
70
+ */
71
+ export declare function accountWindowUrl(slot: number, path?: string): string;
72
+ /** The event a drift refusal raises. One name, so the shared banner and any app
73
+ * that wants its own reaction listen to the same thing. */
74
+ export declare const ACCOUNT_DRIFT_EVENT = "satellite:account-drift";
75
+ /**
76
+ * Declare who this page rendered for.
77
+ *
78
+ * Called once from the shared session surfaces β€” `useSatelliteAuth`'s SSO
79
+ * adapter and `AccountMenu` β€” so no app wires this up for itself. Passing an
80
+ * empty string or null clears it (signed out).
81
+ *
82
+ * πŸ”΄ Calling this INSTALLS the fetch patch even at slot 0, which is the whole
83
+ * point: slot 0 is where the eviction happens, because it is the slot every
84
+ * ordinary sign-in takes. Everything else about "slot 0 costs nothing" is
85
+ * unchanged β€” an app that never declares an expectation never gets a patch.
86
+ */
87
+ export declare function setExpectedAccount(userId: string | null): void;
88
+ /** Who this page said it was. */
89
+ export declare function currentExpectedAccount(): string | null;
90
+ /** Tests only β€” forget the page's expectation and let a drift be announced again. */
91
+ export declare function resetExpectedAccountForTests(): void;
92
+ export interface InstallAccountSlotOptions {
93
+ /**
94
+ * Rewrite the address bar so it names the slot. On by default: a URL that
95
+ * silently means "account 2" is one the person cannot copy, bookmark or
96
+ * reopen, and cannot tell apart from the other window.
97
+ */
98
+ syncUrl?: boolean;
99
+ }
100
+ /**
101
+ * Resolve this tab's slot, remember it, put it on the URL, and make every
102
+ * same-origin `fetch` carry it. Returns the slot.
103
+ *
104
+ * Call once, as early as the app can β€” before the first data fetch, or that
105
+ * request answers as the wrong account. Idempotent.
106
+ */
107
+ export declare function installAccountSlot(options?: InstallAccountSlotOptions): number;
108
+ export declare function fetchWithoutAccountSlot(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
109
+ /** Undo the patch and forget the tab's slot. Tests only β€” an app that wanted
110
+ * this would be asking for a tab whose account changes underneath it. */
111
+ export declare function resetAccountSlotForTests(originalFetch?: typeof fetch): void;
112
+ export { ACCOUNT_SLOT_HEADER, ACCOUNT_SLOT_PARAM, ACCOUNT_USER_HEADER };
113
+ //# sourceMappingURL=accountSlot.client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accountSlot.client.d.ts","sourceRoot":"","sources":["../src/accountSlot.client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,OAAO,EAEN,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EAMnB,MAAM,gBAAgB,CAAC;AAExB;+EAC+E;AAC/E,eAAO,MAAM,gBAAgB,8BAA8B,CAAC;AA4B5D;;;;;;GAMG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAQ3C;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE,MAA6B,GAAG,MAAM,CAEhF;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,SAAM,GAAG,MAAM,CAGjE;AAcD;4DAC4D;AAC5D,eAAO,MAAM,mBAAmB,4BAA4B,CAAC;AAE7D;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAK9D;AAED,iCAAiC;AACjC,wBAAgB,sBAAsB,IAAI,MAAM,GAAG,IAAI,CAEtD;AAgDD,qFAAqF;AACrF,wBAAgB,4BAA4B,IAAI,IAAI,CAGnD;AAED,MAAM,WAAW,yBAAyB;IACzC;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,GAAE,yBAA8B,GAAG,MAAM,CA0ElF;AA6BD,wBAAgB,uBAAuB,CACtC,KAAK,EAAE,WAAW,GAAG,GAAG,EACxB,IAAI,CAAC,EAAE,WAAW,GAChB,OAAO,CAAC,QAAQ,CAAC,CAKnB;AAED;0EAC0E;AAC1E,wBAAgB,wBAAwB,CAAC,aAAa,CAAC,EAAE,OAAO,KAAK,GAAG,IAAI,CAW3E;AAED,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,CAAC"}
@@ -0,0 +1,330 @@
1
+ /**
2
+ * The browser half of account slots: which account THIS TAB is, and how every
3
+ * request it makes says so (2026-08-12).
4
+ *
5
+ * ── Why a tab can have its own account at all ───────────────────────────────
6
+ * Cookies are per-origin, so two tabs of one app share one cookie jar and
7
+ * cannot each hold a different session. What they CAN each hold is a different
8
+ * `sessionStorage` β€” that storage is per-tab by definition, survives reloads
9
+ * and in-app navigation, and dies with the tab. So the jar holds every account
10
+ * (see `accountSlots.ts`), and the tab remembers WHICH of them it is.
11
+ *
12
+ * ── Two channels, and why both ──────────────────────────────────────────────
13
+ * - **`sessionStorage`** is the tab's memory. It is what makes the choice
14
+ * survive a reload and every click inside the app.
15
+ * - **The `?authuser=` URL param** is how a slot ENTERS a tab: the SSO
16
+ * callback lands on it, "open this account in a new window" links to it, and
17
+ * a bookmark restores it. It is read once, at boot, and then re-asserted on
18
+ * the URL so what the address bar says is true.
19
+ *
20
+ * The URL wins at boot when both are present, because the URL is what the
21
+ * person just navigated to.
22
+ *
23
+ * ── What the fetch patch is for, and its one limit ──────────────────────────
24
+ * These apps are SPAs: the document is static HTML that needs no session, and
25
+ * everything that does comes back through `fetch`. So attaching one header to
26
+ * same-origin `fetch` covers the authenticated surface completely, without
27
+ * every route constant in eighteen apps growing a query parameter β€” which is
28
+ * the change nobody would apply consistently, and one missed call site is a
29
+ * request that silently acts as the wrong account.
30
+ *
31
+ * πŸ”΄ The limit: a same-origin SUBRESOURCE that needs the session β€” an `<img>`,
32
+ * a `<video>`, a download, an EventSource β€” is not a `fetch` and carries no
33
+ * header. Those must be built with `slotUrl()`. In this fleet almost nothing is
34
+ * affected, because media is served by binary-server against signed tokens
35
+ * rather than a session cookie, but an app that adds a session-gated `<img>`
36
+ * has to say so in the URL.
37
+ *
38
+ * ── Slot 0 costs nothing ────────────────────────────────────────────────────
39
+ * Every function here short-circuits at slot 0: no storage write, no URL
40
+ * rewrite, no patched `fetch`, no header. The overwhelmingly common case β€” one
41
+ * account β€” behaves exactly as it did before this file existed, which is also
42
+ * why nothing in the fleet had to change to adopt it.
43
+ */
44
+ import { ACCOUNT_DRIFT_STATUS, ACCOUNT_SLOT_HEADER, ACCOUNT_SLOT_PARAM, ACCOUNT_USER_HEADER, isAccountDriftBody, normalizeSlot, slotFromUrl, withSlot, } from "./accountSlots";
45
+ /** Per-tab, like the SSO auto-sign-in guards next door and for the same
46
+ * reason: it must never be a reason a DIFFERENT tab acts as somebody else. */
47
+ export const ACCOUNT_SLOT_KEY = "satellite.account.slot.v1";
48
+ /** Set once `installAccountSlot` has run, so a second call is a no-op rather
49
+ * than a second layer of patched `fetch` wrapping the first. */
50
+ const INSTALLED = Symbol.for("satellite.accountSlot.installed");
51
+ /**
52
+ * Every storage access is wrapped. Safari's private mode throws on ACCESS, not
53
+ * on write, and a tab that cannot remember its slot must degrade to the primary
54
+ * account β€” never to an exception on the way to first paint.
55
+ */
56
+ function readStoredSlot() {
57
+ try {
58
+ const raw = globalThis.sessionStorage?.getItem(ACCOUNT_SLOT_KEY);
59
+ return raw === null || raw === undefined ? null : normalizeSlot(raw);
60
+ }
61
+ catch {
62
+ return null;
63
+ }
64
+ }
65
+ function storeSlot(slot) {
66
+ try {
67
+ globalThis.sessionStorage?.setItem(ACCOUNT_SLOT_KEY, String(slot));
68
+ }
69
+ catch {
70
+ // See above. A tab that cannot remember is still a tab that works.
71
+ }
72
+ }
73
+ /**
74
+ * Which account this tab is acting as.
75
+ *
76
+ * URL first (that is how a slot arrives), then the tab's memory, then 0. Safe
77
+ * to call before `installAccountSlot`, and safe to call on a server (no
78
+ * `location`, no storage β†’ 0).
79
+ */
80
+ export function currentAccountSlot() {
81
+ try {
82
+ const fromUrl = slotFromUrl(globalThis.location?.href ?? "");
83
+ if (fromUrl !== null)
84
+ return fromUrl;
85
+ }
86
+ catch {
87
+ // A location that cannot be read is not a slot.
88
+ }
89
+ return readStoredSlot() ?? 0;
90
+ }
91
+ /**
92
+ * `url` with this tab's account on it.
93
+ *
94
+ * For the things a header cannot reach: a session-gated `<img src>`, an
95
+ * `EventSource`, a download link, an `<a>` to another page of this app. Slot 0
96
+ * returns the URL untouched.
97
+ */
98
+ export function slotUrl(url, slot = currentAccountSlot()) {
99
+ return withSlot(url, slot);
100
+ }
101
+ /**
102
+ * A URL that opens `slot` β€” in this app, in another tab or window.
103
+ *
104
+ * The owner-facing point of the whole feature: "open my test account beside my
105
+ * own". Always absolute, because the caller is about to hand it to
106
+ * `window.open` or an `<a target="_blank">`.
107
+ */
108
+ export function accountWindowUrl(slot, path = "/") {
109
+ const origin = globalThis.location?.origin ?? "";
110
+ return `${origin}${withSlot(path, slot)}`;
111
+ }
112
+ /* ── The expected account ────────────────────────────────────────────────────
113
+ *
114
+ * See `accountSlots.ts` for the failure this closes. In short: another tab can
115
+ * replace this slot's occupant while this tab is still showing a page it drew
116
+ * for the previous one, and nothing tells it. The page states who it rendered
117
+ * for; the server compares and answers 409.
118
+ */
119
+ /** Who this PAGE believes it is. Module scope, not storage: it is a property of
120
+ * the rendered document, and a reload re-derives it from the session. */
121
+ let expectedAccount = null;
122
+ /** The event a drift refusal raises. One name, so the shared banner and any app
123
+ * that wants its own reaction listen to the same thing. */
124
+ export const ACCOUNT_DRIFT_EVENT = "satellite:account-drift";
125
+ /**
126
+ * Declare who this page rendered for.
127
+ *
128
+ * Called once from the shared session surfaces β€” `useSatelliteAuth`'s SSO
129
+ * adapter and `AccountMenu` β€” so no app wires this up for itself. Passing an
130
+ * empty string or null clears it (signed out).
131
+ *
132
+ * πŸ”΄ Calling this INSTALLS the fetch patch even at slot 0, which is the whole
133
+ * point: slot 0 is where the eviction happens, because it is the slot every
134
+ * ordinary sign-in takes. Everything else about "slot 0 costs nothing" is
135
+ * unchanged β€” an app that never declares an expectation never gets a patch.
136
+ */
137
+ export function setExpectedAccount(userId) {
138
+ const next = userId && userId.length > 0 ? userId : null;
139
+ if (next === expectedAccount)
140
+ return;
141
+ expectedAccount = next;
142
+ if (next !== null)
143
+ installAccountSlot();
144
+ }
145
+ /** Who this page said it was. */
146
+ export function currentExpectedAccount() {
147
+ return expectedAccount;
148
+ }
149
+ /**
150
+ * Announce a drift, at most once per page.
151
+ *
152
+ * Once is deliberate and load-bearing: a dashboard fires a dozen requests at
153
+ * mount and every one of them will be refused with the same body, so an
154
+ * un-latched event would stack a dozen identical banners. The page is now
155
+ * lying about who it is and the only cure is a navigation, so a second telling
156
+ * adds nothing.
157
+ */
158
+ let driftAnnounced = false;
159
+ function announceDrift(detail) {
160
+ if (driftAnnounced)
161
+ return;
162
+ driftAnnounced = true;
163
+ try {
164
+ globalThis.dispatchEvent?.(new CustomEvent(ACCOUNT_DRIFT_EVENT, { detail }));
165
+ }
166
+ catch {
167
+ // No DOM (a test, a server render). The response still returns unchanged
168
+ // to its caller, which is the half that must never depend on this.
169
+ }
170
+ }
171
+ /**
172
+ * Read one response for a drift refusal, without consuming it.
173
+ *
174
+ * πŸ”΄ `res.clone()` is not optional. The caller owns this body and will read it;
175
+ * reading it here first would hand them a locked stream β€” a fetch wrapper that
176
+ * breaks every JSON parse in the app is a far worse bug than the one being
177
+ * detected. A clone that cannot be made or parsed is simply not a drift.
178
+ */
179
+ function watchForDrift(res) {
180
+ if (res.status !== ACCOUNT_DRIFT_STATUS || driftAnnounced)
181
+ return res;
182
+ try {
183
+ void res
184
+ .clone()
185
+ .json()
186
+ .then((body) => {
187
+ if (isAccountDriftBody(body))
188
+ announceDrift(body);
189
+ })
190
+ .catch(() => { });
191
+ }
192
+ catch {
193
+ // An opaque or already-consumed response is not something to inspect.
194
+ }
195
+ return res;
196
+ }
197
+ /** Tests only β€” forget the page's expectation and let a drift be announced again. */
198
+ export function resetExpectedAccountForTests() {
199
+ expectedAccount = null;
200
+ driftAnnounced = false;
201
+ }
202
+ /**
203
+ * Resolve this tab's slot, remember it, put it on the URL, and make every
204
+ * same-origin `fetch` carry it. Returns the slot.
205
+ *
206
+ * Call once, as early as the app can β€” before the first data fetch, or that
207
+ * request answers as the wrong account. Idempotent.
208
+ */
209
+ export function installAccountSlot(options = {}) {
210
+ const slot = currentAccountSlot();
211
+ storeSlot(slot);
212
+ if (options.syncUrl !== false && slot !== 0) {
213
+ try {
214
+ const href = globalThis.location?.href ?? "";
215
+ if (href && slotFromUrl(href) === null) {
216
+ globalThis.history?.replaceState(null, "", withSlot(href, slot));
217
+ }
218
+ }
219
+ catch {
220
+ // A history API that refuses is cosmetic here β€” the tab still knows.
221
+ }
222
+ }
223
+ const scope = globalThis;
224
+ // πŸ”΄ Slot 0 installs nothing UNLESS the page has declared who it rendered for.
225
+ // The original rule β€” "slot 0 costs nothing" β€” is what makes this module free
226
+ // for the fleet's ordinary single-account use, and it still holds for any app
227
+ // that never calls `setExpectedAccount`. But slot 0 is precisely where an
228
+ // account gets replaced underneath an open tab (it is the slot every ordinary
229
+ // sign-in takes), so refusing to install there would exempt the common case
230
+ // from the guard written for it.
231
+ if ((slot === 0 && expectedAccount === null) || scope[INSTALLED])
232
+ return slot;
233
+ scope[INSTALLED] = true;
234
+ const original = globalThis.fetch;
235
+ if (typeof original !== "function")
236
+ return slot;
237
+ unpatched = original;
238
+ function withAccountSlot(input, init) {
239
+ let sameOrigin = false;
240
+ try {
241
+ const href = typeof input === "string"
242
+ ? input
243
+ : input instanceof URL
244
+ ? input.href
245
+ : input.url;
246
+ sameOrigin = new URL(href, globalThis.location?.href).origin === globalThis.location?.origin;
247
+ }
248
+ catch {
249
+ sameOrigin = false;
250
+ }
251
+ // πŸ”΄ Same-origin ONLY. A custom header on a cross-origin request forces a
252
+ // CORS preflight the other end never agreed to, which would break every
253
+ // third-party call an app makes β€” and the slot means nothing there anyway,
254
+ // since it selects among cookies of THIS origin.
255
+ if (!sameOrigin)
256
+ return original(input, init);
257
+ const inherited = init?.headers ?? (input instanceof Request ? input.headers : undefined);
258
+ const headers = new Headers(inherited);
259
+ // Never override a caller that set it deliberately β€” an app asking on
260
+ // behalf of a specific account knows better than the tab's default.
261
+ if (!headers.has(ACCOUNT_SLOT_HEADER))
262
+ headers.set(ACCOUNT_SLOT_HEADER, String(slot));
263
+ // Read at REQUEST time, not at install time: the expectation is declared
264
+ // once the session resolves, which is after the first fetch has already
265
+ // gone out. A value closed over at install would be null forever.
266
+ if (expectedAccount !== null && !headers.has(ACCOUNT_USER_HEADER)) {
267
+ headers.set(ACCOUNT_USER_HEADER, expectedAccount);
268
+ }
269
+ if (input instanceof Request && !init) {
270
+ return original(new Request(input, { headers })).then(watchForDrift);
271
+ }
272
+ return original(input, { ...init, headers }).then(watchForDrift);
273
+ }
274
+ // πŸ”΄ `Object.assign` rather than a bare replacement: `fetch` carries side
275
+ // properties (React 19 puts `preconnect` on it) and a wrapper that drops
276
+ // them breaks whatever reads them β€” silently, and far from here.
277
+ globalThis.fetch = Object.assign(withAccountSlot, original);
278
+ return slot;
279
+ }
280
+ /**
281
+ * The `fetch` this module replaced, for the ONE request shape the patch cannot serve.
282
+ *
283
+ * πŸ”΄ Why this exists (2026-09-07). The patch attaches its header to same-origin requests
284
+ * only, and the comment above says why: a custom header on a cross-origin request forces a
285
+ * preflight the other end never agreed to. That reasoning has a hole, and it cost the ROM
286
+ * player. A **same-origin request that REDIRECTS cross-origin** is same-origin when the
287
+ * patch sees it and cross-origin by the time the browser acts, and the browser replays the
288
+ * headers at the new host β€” so it preflights after all:
289
+ *
290
+ * Access to fetch at 'https://binary-server…/media/roms/rom/…' (redirected from
291
+ * 'https://roms…/_nes-roms/…') has been blocked by CORS policy: Request header field
292
+ * x-account-slot is not allowed by Access-Control-Allow-Headers in preflight response.
293
+ *
294
+ * That is the fleet's whole media pattern β€” app URL β†’ signed redirect β†’ binary-server β€” so
295
+ * every app reading bytes that way was affected, not only roms. binary-server now answers
296
+ * the preflight (`src/server.ts::preflight`), which is the fix that covers callers this
297
+ * module has never heard of. This export is the other half: a caller that KNOWS its URL
298
+ * redirects to a foreign origin can keep its request a simple GET and skip the preflight
299
+ * round-trip entirely, which is what `apps/roms`' `fetchRomResponse` documented needing
300
+ * since 2026-07-30 β€” a paragraph that could not enforce itself.
301
+ *
302
+ * The slot is not lost by using this: these URLs authorize with a signed token in the URL,
303
+ * not with a session, so there is nothing for the header to select. Do NOT reach for it to
304
+ * silence an ordinary preflight β€” for a real API call the header is the point.
305
+ */
306
+ let unpatched = null;
307
+ export function fetchWithoutAccountSlot(input, init) {
308
+ // Before `installAccountSlot` runs, `globalThis.fetch` IS the original β€” so the
309
+ // fallback is correct rather than merely convenient, and this is safe to call from a
310
+ // module that loads in either order.
311
+ return (unpatched ?? globalThis.fetch)(input, init);
312
+ }
313
+ /** Undo the patch and forget the tab's slot. Tests only β€” an app that wanted
314
+ * this would be asking for a tab whose account changes underneath it. */
315
+ export function resetAccountSlotForTests(originalFetch) {
316
+ const scope = globalThis;
317
+ scope[INSTALLED] = false;
318
+ unpatched = null;
319
+ resetExpectedAccountForTests();
320
+ if (originalFetch)
321
+ globalThis.fetch = originalFetch;
322
+ try {
323
+ globalThis.sessionStorage?.removeItem(ACCOUNT_SLOT_KEY);
324
+ }
325
+ catch {
326
+ // Nothing stored is nothing to clear.
327
+ }
328
+ }
329
+ export { ACCOUNT_SLOT_HEADER, ACCOUNT_SLOT_PARAM, ACCOUNT_USER_HEADER };
330
+ //# sourceMappingURL=accountSlot.client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accountSlot.client.js","sourceRoot":"","sources":["../src/accountSlot.client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,OAAO,EACN,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EAEnB,kBAAkB,EAClB,aAAa,EACb,WAAW,EACX,QAAQ,GACR,MAAM,gBAAgB,CAAC;AAExB;+EAC+E;AAC/E,MAAM,CAAC,MAAM,gBAAgB,GAAG,2BAA2B,CAAC;AAE5D;iEACiE;AACjE,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;AAEhE;;;;GAIG;AACH,SAAS,cAAc;IACtB,IAAI,CAAC;QACJ,MAAM,GAAG,GAAG,UAAU,CAAC,cAAc,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC;QACjE,OAAO,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,IA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