cursedauth 0.15.1 → 0.16.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.
- package/README.md +2 -0
- package/dist/clientDescription.d.ts +13 -0
- package/dist/clientDescription.d.ts.map +1 -1
- package/dist/clientDescription.js +36 -0
- package/dist/clientDescription.js.map +1 -1
- package/dist/offlineGrant.browser.d.ts +81 -0
- package/dist/offlineGrant.browser.d.ts.map +1 -0
- package/dist/offlineGrant.browser.js +183 -0
- package/dist/offlineGrant.browser.js.map +1 -0
- package/package.json +15 -3
- package/src/clientDescription.ts +37 -0
- package/src/offlineGrant.browser.ts +242 -0
package/README.md
CHANGED
|
@@ -46,11 +46,13 @@ logins and nothing else. The provider is a separate service reached over HTTPS a
|
|
|
46
46
|
| `cursedauth/content-census` | server | answer "what has this account made here?" by COUNT |
|
|
47
47
|
| `cursedauth/account-slots` | both | several accounts signed in on one browser |
|
|
48
48
|
| `cursedauth/sso` | both | the grant: its wire shape, its claims, its verification |
|
|
49
|
+
| `cursedauth/client-description` | server | what a request says about its device and place — `describeClient`, `clientFactsOf`, `describePlace`, and `withEdgePlace` (a Worker's `request.cf` into the place headers, client-sent ones dropped). **Worker-safe** |
|
|
49
50
|
| `cursedauth/session-claims` | server | the bearer-token half: `SESSION_CLAIMS_KEY`, `SessionClaims`, `createRequireSession`. **Worker-safe** — reaches no `bun:sqlite` |
|
|
50
51
|
| `cursedauth/constant-time` | both | `constantTimeEqual` — compare two secrets without leaking where they differ |
|
|
51
52
|
| `cursedauth/fleet-call` | both | `parseFleetUser`, `fleetBearerMatches`, `fleetCallHeaders` — one fleet app asking another over a Service Binding as the signed-in account (`x-fleet-user`) |
|
|
52
53
|
| `cursedauth/secure-request` | both | `isSecureRequest` — whether a request arrived over HTTPS (reading `x-forwarded-proto` behind the tunnel), the one question the cookie `Secure` attribute turns on. Published 0.9.3 because `patterns` and `auth` each carried a copy (task 2106) |
|
|
53
54
|
| `cursedauth/offline-grant` | both | the bounded offline window: how long a device with no network may keep using cached content |
|
|
55
|
+
| `cursedauth/offline-grant/browser` | browser | where a device keeps its grant (per app key, per account slot), and `resolveSession` — the session probe the grant stands in for offline, with each app's purge as `onPurge` / `onExpiredOffline`. Lifted from roms, music and flix in 0.16.0 |
|
|
54
56
|
| `cursedauth/relay-door` | server | a relay app's door on its Worker (`cursedops/relay`): the SSO consumer over D1, the account signed into `<app>_as` for the Mac, the browser's session cookies stripped, the door's schema and the cutover's session import. Lifted from `apps/roms` in 0.10.0. **Worker-safe** |
|
|
55
57
|
| `cursedauth/relay-identity` | server | the Mac's half: believe `<app>_as` only on a request that came down the link, under the link key's digest, and gate on it like the consumer would. `node:crypto`, Mac only |
|
|
56
58
|
| `cursedauth/auth` | browser | `startSsoSignIn`, `useSsoAutoSignIn`, session hooks |
|
|
@@ -126,6 +126,19 @@ export declare function describeDevice(userAgent: string | null | undefined): st
|
|
|
126
126
|
* and why `clientFactsOf` takes an origin-side lookup as the second source.
|
|
127
127
|
*/
|
|
128
128
|
export declare function clientPlaceOf(request: Request | undefined): ClientPlace;
|
|
129
|
+
/**
|
|
130
|
+
* A Worker request with its place headers REPLACED by what Cloudflare put on `request.cf` (task
|
|
131
|
+
* 2152). On a Worker the edge's own answer arrives as an object, not as headers, so without this
|
|
132
|
+
* `clientPlaceOf` sees only `cf-ipcountry` — and the Mac's IP→city snapshot (`ipGeo.ts`) is a
|
|
133
|
+
* file a Worker cannot open.
|
|
134
|
+
*
|
|
135
|
+
* 🔴 Every place header is DELETED first, and only then set from `cf`. A client may send its own
|
|
136
|
+
* `cf-ipcity`, and `clientFactsOf` lets headers win — so passing them through would let whoever
|
|
137
|
+
* signs in choose the city their own security alert names. `request.cf` is not client-writable.
|
|
138
|
+
* City and region are URI-encoded because a header is bytes and "São Paulo" is not; `decodedFact`
|
|
139
|
+
* undoes it.
|
|
140
|
+
*/
|
|
141
|
+
export declare function withEdgePlace(request: Request, cf: Record<string, unknown> | undefined): Request;
|
|
129
142
|
/** An empty place — the honest answer for a request nothing is known about. */
|
|
130
143
|
export declare const UNKNOWN_PLACE: ClientPlace;
|
|
131
144
|
/** Is anything at all known about where this came from? */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientDescription.d.ts","sourceRoot":"","sources":["../src/clientDescription.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,mFAAmF;AACnF,MAAM,WAAW,iBAAiB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;CACf;AAED;;kEAEkE;AAClE,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAMxC;;;;;;;;GAQG;AACH,MAAM,WAAW,WAAW;IAC3B,0EAA0E;IAC1E,OAAO,EAAE,MAAM,CAAC;IAChB,+DAA+D;IAC/D,QAAQ,EAAE,MAAM,CAAC;IACjB,yDAAyD;IACzD,IAAI,EAAE,OAAO,GAAG,QAAQ,GAAG,UAAU,GAAG,KAAK,GAAG,SAAS,CAAC;CAC1D;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,WAAW;IAC3B,mCAAmC;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,4BAA4B;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,yCAAyC;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,oBAAoB;IACpB,SAAS,EAAE,MAAM,CAAC;CAClB;AAED,+EAA+E;AAC/E,MAAM,WAAW,WAAY,SAAQ,WAAW,EAAE,WAAW;IAC5D,qDAAqD;IACrD,EAAE,EAAE,MAAM,CAAC;IACX;;;;;;;OAOG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB,wDAAwD;IACxD,SAAS,EAAE,MAAM,CAAC;IAClB,gEAAgE;IAChE,MAAM,EAAE,MAAM,CAAC;CACf;AA0BD;;;;;;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E,EAAE,MAAM,KAAK,WAAW,GAAG,IAAI,CAAC;AAE7D;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC5B,OAAO,EAAE,OAAO,GAAG,SAAS,EAC5B,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,WAAW,CAAA;CAAO,GACpC,WAAW,CAsBb;AAED,iEAAiE;AACjE,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAG9D;AAED,+EAA+E;AAC/E,eAAO,MAAM,iBAAiB,GAAI,SAAS,OAAO,KAAG,MACoB,CAAC;AAE1E,yCAAyC;AACzC,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,iBAAiB,CAKlE"}
|
|
@@ -159,6 +159,42 @@ export function clientPlaceOf(request) {
|
|
|
159
159
|
continent: fact(header("cf-ipcontinent")).slice(0, 4).toUpperCase(),
|
|
160
160
|
};
|
|
161
161
|
}
|
|
162
|
+
/** The place fields of a Worker request's `request.cf`, and the header `clientPlaceOf` reads each from. */
|
|
163
|
+
const EDGE_PLACE_HEADERS = {
|
|
164
|
+
country: "cf-ipcountry",
|
|
165
|
+
region: "cf-region",
|
|
166
|
+
city: "cf-ipcity",
|
|
167
|
+
postalCode: "cf-postal-code",
|
|
168
|
+
timezone: "cf-timezone",
|
|
169
|
+
continent: "cf-ipcontinent",
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* A Worker request with its place headers REPLACED by what Cloudflare put on `request.cf` (task
|
|
173
|
+
* 2152). On a Worker the edge's own answer arrives as an object, not as headers, so without this
|
|
174
|
+
* `clientPlaceOf` sees only `cf-ipcountry` — and the Mac's IP→city snapshot (`ipGeo.ts`) is a
|
|
175
|
+
* file a Worker cannot open.
|
|
176
|
+
*
|
|
177
|
+
* 🔴 Every place header is DELETED first, and only then set from `cf`. A client may send its own
|
|
178
|
+
* `cf-ipcity`, and `clientFactsOf` lets headers win — so passing them through would let whoever
|
|
179
|
+
* signs in choose the city their own security alert names. `request.cf` is not client-writable.
|
|
180
|
+
* City and region are URI-encoded because a header is bytes and "São Paulo" is not; `decodedFact`
|
|
181
|
+
* undoes it.
|
|
182
|
+
*/
|
|
183
|
+
export function withEdgePlace(request, cf) {
|
|
184
|
+
// Not a Worker request (a test, a Bun server): nothing more trustworthy to replace them with.
|
|
185
|
+
if (!cf)
|
|
186
|
+
return request;
|
|
187
|
+
const headers = new Headers(request.headers);
|
|
188
|
+
for (const [field, name] of Object.entries(EDGE_PLACE_HEADERS)) {
|
|
189
|
+
headers.delete(name);
|
|
190
|
+
const value = cf[field];
|
|
191
|
+
if (typeof value !== "string" || value === "")
|
|
192
|
+
continue;
|
|
193
|
+
// The two `clientPlaceOf` decodes; the rest are codes, and an encoded "America/Chicago" is not one.
|
|
194
|
+
headers.set(name, field === "city" || field === "region" ? encodeURIComponent(value) : value);
|
|
195
|
+
}
|
|
196
|
+
return new Request(request, { headers });
|
|
197
|
+
}
|
|
162
198
|
/** An empty place — the honest answer for a request nothing is known about. */
|
|
163
199
|
export const UNKNOWN_PLACE = {
|
|
164
200
|
country: "",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientDescription.js","sourceRoot":"","sources":["../src/clientDescription.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAQH;;kEAEkE;AAClE,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,CAAC;AAExC;gEACgE;AAChE,MAAM,cAAc,GAAG,EAAE,CAAC;AA+D1B;mCACmC;AACnC,8HAA8H;AAC9H,MAAM,kBAAkB,GAAG,wBAAwB,CAAC;AAEpD,kFAAkF;AAClF,MAAM,IAAI,GAAG,CAAC,KAAgC,EAAU,EAAE,CACzD,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC;AAE/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QAAQ,IAAI,KAAK,CAAC,QAAQ;QACzC,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,KAAK,CAAC,SAAS;KAC5C,CAAC;IACF,OAAO;QACN,EAAE;QACF,OAAO,EAAE,WAAW,CAAC,EAAE,CAAC;QACxB,SAAS;QACT,MAAM,EAAE,mBAAmB,CAAC,KAAK,EAAE,SAAS,CAAC;QAC7C,GAAG,KAAK;QACR,GAAG,KAAK;KACR,CAAC;AACH,CAAC;AAED,iEAAiE;AACjE,MAAM,UAAU,mBAAmB,CAAC,KAAkB;IACrD,MAAM,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IACnC,OAAO,CAAC,KAAK,CAAC,EAAE,IAAI,oBAAoB,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC5F,CAAC;AAED,+EAA+E;AAC/E,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,OAAgB,EAAU,EAAE,CAC7D,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,oBAAoB,CAAC,CAAC;AAE1E,yCAAyC;AACzC,MAAM,UAAU,cAAc,CAAC,OAAgB;IAC9C,OAAO;QACN,EAAE,EAAE,eAAe,CAAC,OAAO,CAAC,IAAI,oBAAoB;QACpD,MAAM,EAAE,cAAc,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;KACzD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { type OfflineGrant } from "./offlineGrant";
|
|
2
|
+
export type { OfflineGrant } from "./offlineGrant";
|
|
3
|
+
/** The slice of `Storage` this needs — so a spec can hand in a `Map`. */
|
|
4
|
+
export interface KeyValueStore {
|
|
5
|
+
getItem(key: string): string | null;
|
|
6
|
+
setItem(key: string, value: string): void;
|
|
7
|
+
removeItem(key: string): void;
|
|
8
|
+
}
|
|
9
|
+
/** `localStorage`, or an in-memory fallback where it is absent or throws (sandboxed frames). */
|
|
10
|
+
export declare function browserKeyValue(): KeyValueStore;
|
|
11
|
+
export declare function memoryKeyValue(): KeyValueStore;
|
|
12
|
+
/** The slot this tab is signed in as; 0 where the slot client cannot say. */
|
|
13
|
+
export declare function activeSlot(): number;
|
|
14
|
+
/** `base` scoped to one account slot — see the header for why. */
|
|
15
|
+
export declare function slotKey(base: string, slot: number): string;
|
|
16
|
+
/** Where one grant lives: the app's own key (`"music.offline.grant.v1"`), the store, the slot. */
|
|
17
|
+
export interface GrantPlace {
|
|
18
|
+
base: string;
|
|
19
|
+
store: KeyValueStore;
|
|
20
|
+
slot: number;
|
|
21
|
+
}
|
|
22
|
+
/** The persisted grant, or null when there is none or it does not parse as one. */
|
|
23
|
+
export declare function readGrant(place: GrantPlace): OfflineGrant | null;
|
|
24
|
+
/** Persist the grant, or with `null` clear it. */
|
|
25
|
+
export declare function writeGrant(grant: OfflineGrant | null, place: GrantPlace): void;
|
|
26
|
+
/** What `/api/auth/session` answers, plus whether the grant answered for it. */
|
|
27
|
+
export interface OfflineSessionPayload {
|
|
28
|
+
authenticated: boolean;
|
|
29
|
+
user?: {
|
|
30
|
+
id: string;
|
|
31
|
+
email?: string;
|
|
32
|
+
name?: string;
|
|
33
|
+
};
|
|
34
|
+
/** The accounts satellite's origin, as the SERVER advertises it. */
|
|
35
|
+
accountsUrl?: string;
|
|
36
|
+
/**
|
|
37
|
+
* The server could not be reached. With `authenticated: true` the device's offline grant is
|
|
38
|
+
* standing in for the session; with `false` there was no valid grant to do so.
|
|
39
|
+
*/
|
|
40
|
+
offline?: true;
|
|
41
|
+
}
|
|
42
|
+
/** The grant's place plus the clock. An app extends it with whatever its purge needs. */
|
|
43
|
+
export interface OfflineSessionDeps extends GrantPlace {
|
|
44
|
+
now: () => number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* What an app does with its kept bytes when the grant rule says they must go. Handed the same
|
|
48
|
+
* deps the probe was, so an app's policy is one constant object.
|
|
49
|
+
*/
|
|
50
|
+
export interface OfflinePurge<D extends OfflineSessionDeps = OfflineSessionDeps> {
|
|
51
|
+
/**
|
|
52
|
+
* ONLINE only: the server answered anonymous while a grant was on file (a sign-out or a
|
|
53
|
+
* revocation), or a DIFFERENT account signed in than the one whose bytes are on this device.
|
|
54
|
+
* Delete everything the slot keeps. The grant itself is cleared or re-stamped here.
|
|
55
|
+
*/
|
|
56
|
+
onPurge(deps: D): void;
|
|
57
|
+
/**
|
|
58
|
+
* OFFLINE, with a grant that EXISTS but is past the window. Absent, the expired grant only
|
|
59
|
+
* LOCKS: the session answers anonymous, nothing is deleted, and the next online answer for the
|
|
60
|
+
* same account re-validates what is kept. Never called with no grant at all.
|
|
61
|
+
*/
|
|
62
|
+
onExpiredOffline?(deps: D): void;
|
|
63
|
+
}
|
|
64
|
+
/** A rejected `fetch` — no route to the server — as opposed to an abort, which is a choice. */
|
|
65
|
+
export declare function isUnreachable(error: unknown): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Fold an ONLINE session answer into the grant. `reconcileGrant` is the only way a grant is
|
|
68
|
+
* created or refreshed, and its `null` means purge: the account changed or was revoked.
|
|
69
|
+
*/
|
|
70
|
+
export declare function reconcileSession<D extends OfflineSessionDeps>(session: OfflineSessionPayload, deps: D, policy: OfflinePurge<D>): void;
|
|
71
|
+
/** The grant for this slot, only while it is inside the window. */
|
|
72
|
+
export declare function validGrant(deps: OfflineSessionDeps): OfflineGrant | null;
|
|
73
|
+
/**
|
|
74
|
+
* Who is signed in — the server's answer when there is one, the grant's when there is not.
|
|
75
|
+
*
|
|
76
|
+
* A 401/403 is a verdict (anonymous, reconciled). Any other failure status is the server having a
|
|
77
|
+
* bad moment, not a verdict on the account: anonymous, and the grant untouched. An aborted probe
|
|
78
|
+
* rethrows — an abort is a choice, never "offline".
|
|
79
|
+
*/
|
|
80
|
+
export declare function resolveSession<D extends OfflineSessionDeps>(probe: () => Promise<Response>, deps: D, policy: OfflinePurge<D>): Promise<OfflineSessionPayload>;
|
|
81
|
+
//# sourceMappingURL=offlineGrant.browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"offlineGrant.browser.d.ts","sourceRoot":"","sources":["../src/offlineGrant.browser.ts"],"names":[],"mappings":"AAqCA,OAAO,EAAuB,KAAK,YAAY,EAAkB,MAAM,gBAAgB,CAAC;AAExF,YAAY,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD,yEAAyE;AACzE,MAAM,WAAW,aAAa;IAC7B,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IACpC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1C,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED,gGAAgG;AAChG,wBAAgB,eAAe,IAAI,aAAa,CAO/C;AAED,wBAAgB,cAAc,IAAI,aAAa,CAO9C;AAED,6EAA6E;AAC7E,wBAAgB,UAAU,IAAI,MAAM,CAMnC;AAED,kEAAkE;AAClE,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED,kGAAkG;AAClG,MAAM,WAAW,UAAU;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,aAAa,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;CACb;AAED,mFAAmF;AACnF,wBAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,YAAY,GAAG,IAAI,CAqBhE;AAED,kDAAkD;AAClD,wBAAgB,UAAU,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CAQ9E;AAED,gFAAgF;AAChF,MAAM,WA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ser half of `cursedauth/offline-grant`: where a device keeps its grant, and the session
|
|
3
|
+
* probe that lets the grant stand in for the session when there is no network (forge task 5718).
|
|
4
|
+
*
|
|
5
|
+
* `./offlineGrant.ts` is pure and never touches storage; persisting the stamp and acting on it is
|
|
6
|
+
* this file. roms, music and flix (task 5716) each carried a copy of both halves that differed
|
|
7
|
+
* only by a storage key, until they moved here and the copies were deleted — a fix to the grant
|
|
8
|
+
* rule had to be found and made three times.
|
|
9
|
+
*
|
|
10
|
+
* ── The bug the session probe closes ────────────────────────────────────────
|
|
11
|
+
* Found by roms' offline browser smoke on 2026-08-05: a cold OFFLINE load probes the session, no
|
|
12
|
+
* cache serves it, the app concludes "anonymous" — correctly, it has no evidence — and draws the
|
|
13
|
+
* sign-in card over a library sitting on the device.
|
|
14
|
+
*
|
|
15
|
+
* ── The rule ────────────────────────────────────────────────────────────────
|
|
16
|
+
* The grant stands in for the session ONLY when the probe could not reach the server at all (the
|
|
17
|
+
* `fetch` rejected) AND a grant for this slot is inside `OFFLINE_MAX_WINDOW_MS`. It never
|
|
18
|
+
* overrides an answer the server gave: online, an anonymous verdict is a sign-out or a revocation,
|
|
19
|
+
* and a DIFFERENT account than the grant's means the device holds another account's bytes — both
|
|
20
|
+
* are {@link OfflinePurge.onPurge}. 🔴 The window is `./offlineGrant.ts`', unchanged: there is no
|
|
21
|
+
* second, longer one here (the exposure a disabled account keeps IS the window).
|
|
22
|
+
*
|
|
23
|
+
* ── What each app decides for itself ────────────────────────────────────────
|
|
24
|
+
* WHAT a purge deletes, and whether a grant that has run out OFFLINE deletes anything at all, are
|
|
25
|
+
* the app's ({@link OfflinePurge}). They genuinely differ, on purpose: music forgets its kept audio
|
|
26
|
+
* the moment it finds an expired grant offline; flix only LOCKS its saved films (the session
|
|
27
|
+
* answers anonymous, so nothing plays) and lets the next online answer for the same account
|
|
28
|
+
* re-validate them. Never flatten the two.
|
|
29
|
+
*
|
|
30
|
+
* 🔴 **Every key carries the ACCOUNT SLOT** ({@link slotKey}). This browser may hold up to five
|
|
31
|
+
* accounts at once (`./accountSlot.client.ts`), one per tab, and `localStorage` is shared by all of
|
|
32
|
+
* them. A single device-wide grant would be reconciled by tab A as account A and by tab B as
|
|
33
|
+
* account B — and `reconcileGrant` returns `null` on an account change, which is the PURGE signal:
|
|
34
|
+
* two tabs would scrub each other's kept bytes on every session check. Slot 0 keeps the bare key,
|
|
35
|
+
* so the one-account case reads exactly the name it always had.
|
|
36
|
+
*/
|
|
37
|
+
import { currentAccountSlot } from "./accountSlot.client";
|
|
38
|
+
import { isOfflineGrantValid, reconcileGrant } from "./offlineGrant";
|
|
39
|
+
/** `localStorage`, or an in-memory fallback where it is absent or throws (sandboxed frames). */
|
|
40
|
+
export function browserKeyValue() {
|
|
41
|
+
try {
|
|
42
|
+
if (typeof localStorage !== "undefined")
|
|
43
|
+
return localStorage;
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
// Fall through to memory — offline is an enhancement, never a crash.
|
|
47
|
+
}
|
|
48
|
+
return memoryKeyValue();
|
|
49
|
+
}
|
|
50
|
+
export function memoryKeyValue() {
|
|
51
|
+
const m = new Map();
|
|
52
|
+
return {
|
|
53
|
+
getItem: (k) => m.get(k) ?? null,
|
|
54
|
+
setItem: (k, v) => void m.set(k, v),
|
|
55
|
+
removeItem: (k) => void m.delete(k),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** The slot this tab is signed in as; 0 where the slot client cannot say. */
|
|
59
|
+
export function activeSlot() {
|
|
60
|
+
try {
|
|
61
|
+
return currentAccountSlot();
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return 0;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** `base` scoped to one account slot — see the header for why. */
|
|
68
|
+
export function slotKey(base, slot) {
|
|
69
|
+
return slot === 0 ? base : `${base}.slot${slot}`;
|
|
70
|
+
}
|
|
71
|
+
/** The persisted grant, or null when there is none or it does not parse as one. */
|
|
72
|
+
export function readGrant(place) {
|
|
73
|
+
const raw = place.store.getItem(slotKey(place.base, place.slot));
|
|
74
|
+
if (!raw)
|
|
75
|
+
return null;
|
|
76
|
+
try {
|
|
77
|
+
const parsed = JSON.parse(raw);
|
|
78
|
+
if (parsed &&
|
|
79
|
+
typeof parsed.accountId === "string" &&
|
|
80
|
+
typeof parsed.lastVerifiedAt === "number" &&
|
|
81
|
+
Number.isFinite(parsed.lastVerifiedAt)) {
|
|
82
|
+
return {
|
|
83
|
+
accountId: parsed.accountId,
|
|
84
|
+
lastVerifiedAt: parsed.lastVerifiedAt,
|
|
85
|
+
...(typeof parsed.email === "string" ? { email: parsed.email } : {}),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
// A corrupt grant is no grant.
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
/** Persist the grant, or with `null` clear it. */
|
|
95
|
+
export function writeGrant(grant, place) {
|
|
96
|
+
const key = slotKey(place.base, place.slot);
|
|
97
|
+
try {
|
|
98
|
+
if (grant)
|
|
99
|
+
place.store.setItem(key, JSON.stringify(grant));
|
|
100
|
+
else
|
|
101
|
+
place.store.removeItem(key);
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// A full store costs offline use, never the online path.
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/** A rejected `fetch` — no route to the server — as opposed to an abort, which is a choice. */
|
|
108
|
+
export function isUnreachable(error) {
|
|
109
|
+
return !(error instanceof DOMException && error.name === "AbortError");
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Fold an ONLINE session answer into the grant. `reconcileGrant` is the only way a grant is
|
|
113
|
+
* created or refreshed, and its `null` means purge: the account changed or was revoked.
|
|
114
|
+
*/
|
|
115
|
+
export function reconcileSession(session, deps, policy) {
|
|
116
|
+
const previous = readGrant(deps);
|
|
117
|
+
const accountId = session.authenticated ? session.user?.id : undefined;
|
|
118
|
+
if (accountId) {
|
|
119
|
+
const at = deps.now();
|
|
120
|
+
const next = reconcileGrant(previous, { verified: true, accountId, at });
|
|
121
|
+
// The email rides along as a LABEL for the offline header — never an identity check.
|
|
122
|
+
const email = session.user?.email;
|
|
123
|
+
const label = email ? { email } : {};
|
|
124
|
+
if (next === null) {
|
|
125
|
+
// A different account than the one whose bytes are on this device.
|
|
126
|
+
policy.onPurge(deps);
|
|
127
|
+
writeGrant({ accountId, lastVerifiedAt: at, ...label }, deps);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
writeGrant({ ...next, ...label }, deps);
|
|
131
|
+
}
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (!session.authenticated && previous) {
|
|
135
|
+
// Reachable and DEFINITIVELY signed out while a grant existed → revoked. Scrub.
|
|
136
|
+
policy.onPurge(deps);
|
|
137
|
+
writeGrant(null, deps);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/** The grant for this slot, only while it is inside the window. */
|
|
141
|
+
export function validGrant(deps) {
|
|
142
|
+
const grant = readGrant(deps);
|
|
143
|
+
return grant && isOfflineGrantValid(grant, deps.now()) ? grant : null;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Who is signed in — the server's answer when there is one, the grant's when there is not.
|
|
147
|
+
*
|
|
148
|
+
* A 401/403 is a verdict (anonymous, reconciled). Any other failure status is the server having a
|
|
149
|
+
* bad moment, not a verdict on the account: anonymous, and the grant untouched. An aborted probe
|
|
150
|
+
* rethrows — an abort is a choice, never "offline".
|
|
151
|
+
*/
|
|
152
|
+
export async function resolveSession(probe, deps, policy) {
|
|
153
|
+
let response;
|
|
154
|
+
try {
|
|
155
|
+
response = await probe();
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
if (!isUnreachable(error))
|
|
159
|
+
throw error;
|
|
160
|
+
const grant = validGrant(deps);
|
|
161
|
+
if (!grant) {
|
|
162
|
+
if (policy.onExpiredOffline && readGrant(deps))
|
|
163
|
+
policy.onExpiredOffline(deps);
|
|
164
|
+
return { authenticated: false, offline: true };
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
authenticated: true,
|
|
168
|
+
offline: true,
|
|
169
|
+
user: { id: grant.accountId, ...(grant.email ? { email: grant.email } : {}) },
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
if (response.status === 401 || response.status === 403) {
|
|
173
|
+
const anonymous = { authenticated: false };
|
|
174
|
+
reconcileSession(anonymous, deps, policy);
|
|
175
|
+
return anonymous;
|
|
176
|
+
}
|
|
177
|
+
if (!response.ok)
|
|
178
|
+
return { authenticated: false };
|
|
179
|
+
const session = (await response.json());
|
|
180
|
+
reconcileSession(session, deps, policy);
|
|
181
|
+
return session;
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=offlineGrant.browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"offlineGrant.browser.js","sourceRoot":"","sources":["../src/offlineGrant.browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAqB,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAWxF,gGAAgG;AAChG,MAAM,UAAU,eAAe;IAC9B,IAAI,CAAC;QACJ,IAAI,OAAO,YAAY,KAAK,WAAW;YAAE,OAAO,YAAY,CAAC;IAC9D,CAAC;IAAC,MAAM,CAAC;QACR,qEAAqE;IACtE,CAAC;IACD,OAAO,cAAc,EAAE,CAAC;AACzB,CAAC;AAED,MAAM,UAAU,cAAc;IAC7B,MAAM,CAAC,GAAG,IAAI,GAAG,EAAkB,CAAC;IACpC,OAAO;QACN,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,IAAI;QAChC,OAAO,EAAE,CAAC,C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U,CAAC,IAAI,CAAC,CAAC;QAC/B,IAAI,CAAC,KAAK,EAAE,CAAC;YACZ,IAAI,MAAM,CAAC,gBAAgB,IAAI,SAAS,CAAC,IAAI,CAAC;gBAAE,MAAM,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;YAC9E,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAChD,CAAC;QACD,OAAO;YACN,aAAa,EAAE,IAAI;YACnB,OAAO,EAAE,IAAI;YACb,IAAI,EAAE,EAAE,EAAE,EAAE,KAAK,CAAC,SAAS,EAAE,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE;SAC7E,CAAC;IACH,CAAC;IACD,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;QACxD,MAAM,SAAS,GAA0B,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;QAClE,gBAAgB,CAAC,SAAS,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QAC1C,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,IAAI,CAAC,QAAQ,CAAC,EAAE;QAAE,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;IAClD,MAAM,OAAO,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAA0B,CAAC;IACjE,gBAAgB,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IACxC,OAAO,OAAO,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cursedauth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "The app side of fleet SSO — sign in through the accounts service, keep a local snapshot of who signed in, and gate the app on it. Bun + Hono + React, one SQLite file per app.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -83,6 +83,12 @@
|
|
|
83
83
|
"source": "./src/sso.ts",
|
|
84
84
|
"import": "./dist/sso.js"
|
|
85
85
|
},
|
|
86
|
+
"./client-description": {
|
|
87
|
+
"types": "./dist/clientDescription.d.ts",
|
|
88
|
+
"bun": "./src/clientDescription.ts",
|
|
89
|
+
"source": "./src/clientDescription.ts",
|
|
90
|
+
"import": "./dist/clientDescription.js"
|
|
91
|
+
},
|
|
86
92
|
"./testing": {
|
|
87
93
|
"types": "./dist/ssoTestHarness.d.ts",
|
|
88
94
|
"bun": "./src/ssoTestHarness.ts",
|
|
@@ -119,6 +125,12 @@
|
|
|
119
125
|
"source": "./src/offlineGrant.ts",
|
|
120
126
|
"import": "./dist/offlineGrant.js"
|
|
121
127
|
},
|
|
128
|
+
"./offline-grant/browser": {
|
|
129
|
+
"types": "./dist/offlineGrant.browser.d.ts",
|
|
130
|
+
"bun": "./src/offlineGrant.browser.ts",
|
|
131
|
+
"source": "./src/offlineGrant.browser.ts",
|
|
132
|
+
"import": "./dist/offlineGrant.browser.js"
|
|
133
|
+
},
|
|
122
134
|
"./relay-door": {
|
|
123
135
|
"types": "./dist/relayDoor.d.ts",
|
|
124
136
|
"bun": "./src/relayDoor.ts",
|
|
@@ -179,8 +191,8 @@
|
|
|
179
191
|
"@types/bun": "latest",
|
|
180
192
|
"@types/react": "^19.2.18",
|
|
181
193
|
"@types/react-dom": "^19.2.5",
|
|
182
|
-
"cursedbelt-core": "^2.
|
|
183
|
-
"cursedbelt-server": "^4.
|
|
194
|
+
"cursedbelt-core": "^2.26.0",
|
|
195
|
+
"cursedbelt-server": "^4.77.0",
|
|
184
196
|
"hono": "^4.13.5",
|
|
185
197
|
"react": "^19.2.8",
|
|
186
198
|
"react-dom": "^19.2.8",
|
package/src/clientDescription.ts
CHANGED
|
@@ -230,6 +230,43 @@ export function clientPlaceOf(request: Request | undefined): ClientPlace {
|
|
|
230
230
|
};
|
|
231
231
|
}
|
|
232
232
|
|
|
233
|
+
/** The place fields of a Worker request's `request.cf`, and the header `clientPlaceOf` reads each from. */
|
|
234
|
+
const EDGE_PLACE_HEADERS = {
|
|
235
|
+
country: "cf-ipcountry",
|
|
236
|
+
region: "cf-region",
|
|
237
|
+
city: "cf-ipcity",
|
|
238
|
+
postalCode: "cf-postal-code",
|
|
239
|
+
timezone: "cf-timezone",
|
|
240
|
+
continent: "cf-ipcontinent",
|
|
241
|
+
} as const;
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* A Worker request with its place headers REPLACED by what Cloudflare put on `request.cf` (task
|
|
245
|
+
* 2152). On a Worker the edge's own answer arrives as an object, not as headers, so without this
|
|
246
|
+
* `clientPlaceOf` sees only `cf-ipcountry` — and the Mac's IP→city snapshot (`ipGeo.ts`) is a
|
|
247
|
+
* file a Worker cannot open.
|
|
248
|
+
*
|
|
249
|
+
* 🔴 Every place header is DELETED first, and only then set from `cf`. A client may send its own
|
|
250
|
+
* `cf-ipcity`, and `clientFactsOf` lets headers win — so passing them through would let whoever
|
|
251
|
+
* signs in choose the city their own security alert names. `request.cf` is not client-writable.
|
|
252
|
+
* City and region are URI-encoded because a header is bytes and "São Paulo" is not; `decodedFact`
|
|
253
|
+
* undoes it.
|
|
254
|
+
*/
|
|
255
|
+
export function withEdgePlace(request: Request, cf: Record<string, unknown> | undefined): Request {
|
|
256
|
+
// Not a Worker request (a test, a Bun server): nothing more trustworthy to replace them with.
|
|
257
|
+
if (!cf) return request;
|
|
258
|
+
const headers = new Headers(request.headers);
|
|
259
|
+
for (const [field, name] of Object.entries(EDGE_PLACE_HEADERS)) {
|
|
260
|
+
headers.delete(name);
|
|
261
|
+
const value = cf[field];
|
|
262
|
+
if (typeof value !== "string" || value === "") continue;
|
|
263
|
+
// The two `clientPlaceOf` decodes; the rest are codes, and an encoded "America/Chicago" is not one.
|
|
264
|
+
headers.set(name, field === "city" || field === "region" ? encodeURIComponent(value) : value);
|
|
265
|
+
}
|
|
266
|
+
return new Request(request, { headers });
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
|
|
233
270
|
/** An empty place — the honest answer for a request nothing is known about. */
|
|
234
271
|
export const UNKNOWN_PLACE: ClientPlace = {
|
|
235
272
|
country: "",
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The browser half of `cursedauth/offline-grant`: where a device keeps its grant, and the session
|
|
3
|
+
* probe that lets the grant stand in for the session when there is no network (forge task 5718).
|
|
4
|
+
*
|
|
5
|
+
* `./offlineGrant.ts` is pure and never touches storage; persisting the stamp and acting on it is
|
|
6
|
+
* this file. roms, music and flix (task 5716) each carried a copy of both halves that differed
|
|
7
|
+
* only by a storage key, until they moved here and the copies were deleted — a fix to the grant
|
|
8
|
+
* rule had to be found and made three times.
|
|
9
|
+
*
|
|
10
|
+
* ── The bug the session probe closes ────────────────────────────────────────
|
|
11
|
+
* Found by roms' offline browser smoke on 2026-08-05: a cold OFFLINE load probes the session, no
|
|
12
|
+
* cache serves it, the app concludes "anonymous" — correctly, it has no evidence — and draws the
|
|
13
|
+
* sign-in card over a library sitting on the device.
|
|
14
|
+
*
|
|
15
|
+
* ── The rule ────────────────────────────────────────────────────────────────
|
|
16
|
+
* The grant stands in for the session ONLY when the probe could not reach the server at all (the
|
|
17
|
+
* `fetch` rejected) AND a grant for this slot is inside `OFFLINE_MAX_WINDOW_MS`. It never
|
|
18
|
+
* overrides an answer the server gave: online, an anonymous verdict is a sign-out or a revocation,
|
|
19
|
+
* and a DIFFERENT account than the grant's means the device holds another account's bytes — both
|
|
20
|
+
* are {@link OfflinePurge.onPurge}. 🔴 The window is `./offlineGrant.ts`', unchanged: there is no
|
|
21
|
+
* second, longer one here (the exposure a disabled account keeps IS the window).
|
|
22
|
+
*
|
|
23
|
+
* ── What each app decides for itself ────────────────────────────────────────
|
|
24
|
+
* WHAT a purge deletes, and whether a grant that has run out OFFLINE deletes anything at all, are
|
|
25
|
+
* the app's ({@link OfflinePurge}). They genuinely differ, on purpose: music forgets its kept audio
|
|
26
|
+
* the moment it finds an expired grant offline; flix only LOCKS its saved films (the session
|
|
27
|
+
* answers anonymous, so nothing plays) and lets the next online answer for the same account
|
|
28
|
+
* re-validate them. Never flatten the two.
|
|
29
|
+
*
|
|
30
|
+
* 🔴 **Every key carries the ACCOUNT SLOT** ({@link slotKey}). This browser may hold up to five
|
|
31
|
+
* accounts at once (`./accountSlot.client.ts`), one per tab, and `localStorage` is shared by all of
|
|
32
|
+
* them. A single device-wide grant would be reconciled by tab A as account A and by tab B as
|
|
33
|
+
* account B — and `reconcileGrant` returns `null` on an account change, which is the PURGE signal:
|
|
34
|
+
* two tabs would scrub each other's kept bytes on every session check. Slot 0 keeps the bare key,
|
|
35
|
+
* so the one-account case reads exactly the name it always had.
|
|
36
|
+
*/
|
|
37
|
+
import { currentAccountSlot } from "./accountSlot.client";
|
|
38
|
+
import { isOfflineGrantValid, type OfflineGrant, reconcileGrant } from "./offlineGrant";
|
|
39
|
+
|
|
40
|
+
export type { OfflineGrant } from "./offlineGrant";
|
|
41
|
+
|
|
42
|
+
/** The slice of `Storage` this needs — so a spec can hand in a `Map`. */
|
|
43
|
+
export interface KeyValueStore {
|
|
44
|
+
getItem(key: string): string | null;
|
|
45
|
+
setItem(key: string, value: string): void;
|
|
46
|
+
removeItem(key: string): void;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** `localStorage`, or an in-memory fallback where it is absent or throws (sandboxed frames). */
|
|
50
|
+
export function browserKeyValue(): KeyValueStore {
|
|
51
|
+
try {
|
|
52
|
+
if (typeof localStorage !== "undefined") return localStorage;
|
|
53
|
+
} catch {
|
|
54
|
+
// Fall through to memory — offline is an enhancement, never a crash.
|
|
55
|
+
}
|
|
56
|
+
return memoryKeyValue();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function memoryKeyValue(): KeyValueStore {
|
|
60
|
+
const m = new Map<string, string>();
|
|
61
|
+
return {
|
|
62
|
+
getItem: (k) => m.get(k) ?? null,
|
|
63
|
+
setItem: (k, v) => void m.set(k, v),
|
|
64
|
+
removeItem: (k) => void m.delete(k),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** The slot this tab is signed in as; 0 where the slot client cannot say. */
|
|
69
|
+
export function activeSlot(): number {
|
|
70
|
+
try {
|
|
71
|
+
return currentAccountSlot();
|
|
72
|
+
} catch {
|
|
73
|
+
return 0;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** `base` scoped to one account slot — see the header for why. */
|
|
78
|
+
export function slotKey(base: string, slot: number): string {
|
|
79
|
+
return slot === 0 ? base : `${base}.slot${slot}`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Where one grant lives: the app's own key (`"music.offline.grant.v1"`), the store, the slot. */
|
|
83
|
+
export interface GrantPlace {
|
|
84
|
+
base: string;
|
|
85
|
+
store: KeyValueStore;
|
|
86
|
+
slot: number;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** The persisted grant, or null when there is none or it does not parse as one. */
|
|
90
|
+
export function readGrant(place: GrantPlace): OfflineGrant | null {
|
|
91
|
+
const raw = place.store.getItem(slotKey(place.base, place.slot));
|
|
92
|
+
if (!raw) return null;
|
|
93
|
+
try {
|
|
94
|
+
const parsed = JSON.parse(raw) as Partial<OfflineGrant> | null;
|
|
95
|
+
if (
|
|
96
|
+
parsed &&
|
|
97
|
+
typeof parsed.accountId === "string" &&
|
|
98
|
+
typeof parsed.lastVerifiedAt === "number" &&
|
|
99
|
+
Number.isFinite(parsed.lastVerifiedAt)
|
|
100
|
+
) {
|
|
101
|
+
return {
|
|
102
|
+
accountId: parsed.accountId,
|
|
103
|
+
lastVerifiedAt: parsed.lastVerifiedAt,
|
|
104
|
+
...(typeof parsed.email === "string" ? { email: parsed.email } : {}),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
} catch {
|
|
108
|
+
// A corrupt grant is no grant.
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Persist the grant, or with `null` clear it. */
|
|
114
|
+
export function writeGrant(grant: OfflineGrant | null, place: GrantPlace): void {
|
|
115
|
+
const key = slotKey(place.base, place.slot);
|
|
116
|
+
try {
|
|
117
|
+
if (grant) place.store.setItem(key, JSON.stringify(grant));
|
|
118
|
+
else place.store.removeItem(key);
|
|
119
|
+
} catch {
|
|
120
|
+
// A full store costs offline use, never the online path.
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** What `/api/auth/session` answers, plus whether the grant answered for it. */
|
|
125
|
+
export interface OfflineSessionPayload {
|
|
126
|
+
authenticated: boolean;
|
|
127
|
+
user?: { id: string; email?: string; name?: string };
|
|
128
|
+
/** The accounts satellite's origin, as the SERVER advertises it. */
|
|
129
|
+
accountsUrl?: string;
|
|
130
|
+
/**
|
|
131
|
+
* The server could not be reached. With `authenticated: true` the device's offline grant is
|
|
132
|
+
* standing in for the session; with `false` there was no valid grant to do so.
|
|
133
|
+
*/
|
|
134
|
+
offline?: true;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** The grant's place plus the clock. An app extends it with whatever its purge needs. */
|
|
138
|
+
export interface OfflineSessionDeps extends GrantPlace {
|
|
139
|
+
now: () => number;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* What an app does with its kept bytes when the grant rule says they must go. Handed the same
|
|
144
|
+
* deps the probe was, so an app's policy is one constant object.
|
|
145
|
+
*/
|
|
146
|
+
export interface OfflinePurge<D extends OfflineSessionDeps = OfflineSessionDeps> {
|
|
147
|
+
/**
|
|
148
|
+
* ONLINE only: the server answered anonymous while a grant was on file (a sign-out or a
|
|
149
|
+
* revocation), or a DIFFERENT account signed in than the one whose bytes are on this device.
|
|
150
|
+
* Delete everything the slot keeps. The grant itself is cleared or re-stamped here.
|
|
151
|
+
*/
|
|
152
|
+
onPurge(deps: D): void;
|
|
153
|
+
/**
|
|
154
|
+
* OFFLINE, with a grant that EXISTS but is past the window. Absent, the expired grant only
|
|
155
|
+
* LOCKS: the session answers anonymous, nothing is deleted, and the next online answer for the
|
|
156
|
+
* same account re-validates what is kept. Never called with no grant at all.
|
|
157
|
+
*/
|
|
158
|
+
onExpiredOffline?(deps: D): void;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** A rejected `fetch` — no route to the server — as opposed to an abort, which is a choice. */
|
|
162
|
+
export function isUnreachable(error: unknown): boolean {
|
|
163
|
+
return !(error instanceof DOMException && error.name === "AbortError");
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Fold an ONLINE session answer into the grant. `reconcileGrant` is the only way a grant is
|
|
168
|
+
* created or refreshed, and its `null` means purge: the account changed or was revoked.
|
|
169
|
+
*/
|
|
170
|
+
export function reconcileSession<D extends OfflineSessionDeps>(
|
|
171
|
+
session: OfflineSessionPayload,
|
|
172
|
+
deps: D,
|
|
173
|
+
policy: OfflinePurge<D>,
|
|
174
|
+
): void {
|
|
175
|
+
const previous = readGrant(deps);
|
|
176
|
+
const accountId = session.authenticated ? session.user?.id : undefined;
|
|
177
|
+
if (accountId) {
|
|
178
|
+
const at = deps.now();
|
|
179
|
+
const next = reconcileGrant(previous, { verified: true, accountId, at });
|
|
180
|
+
// The email rides along as a LABEL for the offline header — never an identity check.
|
|
181
|
+
const email = session.user?.email;
|
|
182
|
+
const label = email ? { email } : {};
|
|
183
|
+
if (next === null) {
|
|
184
|
+
// A different account than the one whose bytes are on this device.
|
|
185
|
+
policy.onPurge(deps);
|
|
186
|
+
writeGrant({ accountId, lastVerifiedAt: at, ...label }, deps);
|
|
187
|
+
} else {
|
|
188
|
+
writeGrant({ ...next, ...label }, deps);
|
|
189
|
+
}
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (!session.authenticated && previous) {
|
|
193
|
+
// Reachable and DEFINITIVELY signed out while a grant existed → revoked. Scrub.
|
|
194
|
+
policy.onPurge(deps);
|
|
195
|
+
writeGrant(null, deps);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** The grant for this slot, only while it is inside the window. */
|
|
200
|
+
export function validGrant(deps: OfflineSessionDeps): OfflineGrant | null {
|
|
201
|
+
const grant = readGrant(deps);
|
|
202
|
+
return grant && isOfflineGrantValid(grant, deps.now()) ? grant : null;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Who is signed in — the server's answer when there is one, the grant's when there is not.
|
|
207
|
+
*
|
|
208
|
+
* A 401/403 is a verdict (anonymous, reconciled). Any other failure status is the server having a
|
|
209
|
+
* bad moment, not a verdict on the account: anonymous, and the grant untouched. An aborted probe
|
|
210
|
+
* rethrows — an abort is a choice, never "offline".
|
|
211
|
+
*/
|
|
212
|
+
export async function resolveSession<D extends OfflineSessionDeps>(
|
|
213
|
+
probe: () => Promise<Response>,
|
|
214
|
+
deps: D,
|
|
215
|
+
policy: OfflinePurge<D>,
|
|
216
|
+
): Promise<OfflineSessionPayload> {
|
|
217
|
+
let response: Response;
|
|
218
|
+
try {
|
|
219
|
+
response = await probe();
|
|
220
|
+
} catch (error) {
|
|
221
|
+
if (!isUnreachable(error)) throw error;
|
|
222
|
+
const grant = validGrant(deps);
|
|
223
|
+
if (!grant) {
|
|
224
|
+
if (policy.onExpiredOffline && readGrant(deps)) policy.onExpiredOffline(deps);
|
|
225
|
+
return { authenticated: false, offline: true };
|
|
226
|
+
}
|
|
227
|
+
return {
|
|
228
|
+
authenticated: true,
|
|
229
|
+
offline: true,
|
|
230
|
+
user: { id: grant.accountId, ...(grant.email ? { email: grant.email } : {}) },
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
if (response.status === 401 || response.status === 403) {
|
|
234
|
+
const anonymous: OfflineSessionPayload = { authenticated: false };
|
|
235
|
+
reconcileSession(anonymous, deps, policy);
|
|
236
|
+
return anonymous;
|
|
237
|
+
}
|
|
238
|
+
if (!response.ok) return { authenticated: false };
|
|
239
|
+
const session = (await response.json()) as OfflineSessionPayload;
|
|
240
|
+
reconcileSession(session, deps, policy);
|
|
241
|
+
return session;
|
|
242
|
+
}
|