cursedauth 0.5.1 → 0.8.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 CHANGED
@@ -38,19 +38,37 @@ logins and nothing else. The provider is a separate service reached over HTTPS a
38
38
  |---|---|---|
39
39
  | `cursedauth` | server | the barrel: consumer, sessions, gate, census |
40
40
  | `cursedauth/sso-consumer` | server | the six routes and `requireUser` |
41
- | `cursedauth/user-sessions` | server | signed cookies + a sessions table, per app |
41
+ | `cursedauth/user-sessions` | server | signed cookies + a sessions table, per app — the `bun:sqlite` half |
42
+ | `cursedauth/user-sessions-core` | server | the same store over a `SessionRows` seam, plus `SESSIONS_DDL`. **Worker-safe** |
43
+ | `cursedauth/sso-user-store` | server | the `sso_users` snapshot behind `SsoUserStore`, plus `SSO_USERS_DDL`. **Worker-safe** |
44
+ | `cursedauth/d1-stores` | server | both seams on Cloudflare D1: one snapshot per invocation, writes settled before the response. **Worker-only** |
42
45
  | `cursedauth/mount-gated` | server | mount public routes before the gate, gated ones after |
43
46
  | `cursedauth/content-census` | server | answer "what has this account made here?" by COUNT |
44
47
  | `cursedauth/account-slots` | both | several accounts signed in on one browser |
45
48
  | `cursedauth/sso` | both | the grant: its wire shape, its claims, its verification |
49
+ | `cursedauth/session-claims` | server | the bearer-token half: `SESSION_CLAIMS_KEY`, `SessionClaims`, `createRequireSession`. **Worker-safe** — reaches no `bun:sqlite` |
46
50
  | `cursedauth/constant-time` | both | `constantTimeEqual` — compare two secrets without leaking where they differ |
51
+ | `cursedauth/offline-grant` | both | the bounded offline window: how long a device with no network may keep using cached content |
47
52
  | `cursedauth/auth` | browser | `startSsoSignIn`, `useSsoAutoSignIn`, session hooks |
48
53
  | `cursedauth/account-ui` | browser | the account menu |
49
54
  | `cursedauth/account-slot-client` | browser | slot switching in the page |
50
55
  | `cursedauth/testing` | server | the grant→callback→cookie harness, for a consumer's own suite |
51
56
 
52
57
  🔴 The barrel reaches `bun:sqlite`. A browser bundle imports the three browser
53
- subpaths and never the root.
58
+ subpaths and never the root — **and so does a Cloudflare Worker**, which is why
59
+ `cursedauth/session-claims` exists. `apps/patterns` could not `wrangler deploy` at
60
+ all on 2026-09-18 (`Could not resolve "bun:sqlite"`, naming `dist/userSessions.js`)
61
+ because one string constant was reachable only through the barrel. Which subpaths
62
+ may reach `bun:sqlite` is now a CHECK — `src/subpathsReachNoBunBuiltin.test.ts` —
63
+ and that allowlist may only shrink.
64
+
65
+ 🔴 **Two different things are called a "grant" here, and only one is a
66
+ credential.** `cursedauth/sso` has *the* grant: signed by the accounts service,
67
+ single-use, and it authorizes a sign-in. `cursedauth/offline-grant` has an
68
+ `OfflineGrant`: a local stamp saying "this device completed a verified session
69
+ for account X at time T", which authorizes nothing, is never sent anywhere, and
70
+ only bounds how long already-cached bytes may be replayed while there is no
71
+ network to re-check. Separate subpaths, no import between them.
54
72
 
55
73
  🔴 **This table is a CHECK, not prose** — `src/publishShape.test.ts` fails if an
56
74
  export subpath is missing a row. A subpath nobody can find is a subpath every app
@@ -0,0 +1,161 @@
1
+ /**
2
+ * `cursedauth` on Cloudflare D1 — the two stores an app's DOOR needs, snapshot-and-settle.
3
+ *
4
+ * ## 🔴 The problem this solves, stated once
5
+ *
6
+ * `createUserSessionStore` and `createSsoConsumer` are synchronous **by publication**:
7
+ * nineteen members and five statements, every one of them called in the middle of
8
+ * resolving a cookie, by six apps that have not ported. Cloudflare's only database is
9
+ * async. Neither side can move — making the stores async breaks the six, and `workerd`
10
+ * will never have `bun:sqlite` — so an app ported to a Worker could serve its catalogue
11
+ * and refuse its own front door. Measured 2026-09-19: `apps/collections` shipped exactly
12
+ * that, a `503` on every `/api/*` naming this gap.
13
+ *
14
+ * The answer, which is the fleet's established one (`tasks/Procedures/move-an-app-to-cloudflare.md`
15
+ * §3, and the two working examples in `apps/patterns/worker/stores.ts` and
16
+ * `apps/collections/worker/stores.ts`):
17
+ *
18
+ * 1. before `app.fetch`, ONE D1 read fills an in-memory snapshot;
19
+ * 2. every synchronous call during the request answers from that snapshot;
20
+ * 3. writes are collected as pending promises, and the entry point **awaits them before
21
+ * it returns the response** — so nothing is acknowledged before it is durable.
22
+ *
23
+ * Two extra queries per invocation, against a 1,000-query budget.
24
+ *
25
+ * ## 🔴 What this must never become: an in-memory store with no read-back
26
+ *
27
+ * A Worker isolate is per-colo and short-lived. A revocation kept only in one isolate's
28
+ * memory means **signing out works until the next request lands somewhere else** — which
29
+ * reads to the person as the feature being broken rather than absent, and leaves a
30
+ * credential live that a human believes they ended. That is the worst outcome this file
31
+ * has, it is invisible in any single-process test, and `d1Stores.lostWrite.test.ts` is
32
+ * what holds the line: it drives two separate store instances standing for two isolates
33
+ * over one database, and it carries a test of its own failure path — a collector that
34
+ * DROPS writes, proving the harness can tell a durable store from a memory-only one.
35
+ *
36
+ * ## What is honest about the staleness
37
+ *
38
+ * A write made by request A is not visible to request B until B takes its own snapshot.
39
+ * For a sign-out that is milliseconds. Within ONE invocation a read-after-write is exact,
40
+ * because every mutation below updates the snapshot as well as queueing the statement —
41
+ * the property `bun:sqlite` has for free and whose absence would make `revoke()` followed
42
+ * by a session check disagree with itself inside one request.
43
+ *
44
+ * ## Where the SCHEMA comes from
45
+ *
46
+ * D1 has no migration story inside a request and DDL per invocation would spend the query
47
+ * budget on statements that can only ever matter once. So `ensureSchema()` here is a
48
+ * documented no-op and the tables come from the app's `db/schema.sql`, applied by
49
+ * `wrangler d1 execute --file db/schema.sql`. Paste {@link SESSIONS_DDL} and
50
+ * {@link SSO_USERS_DDL} into it — both are exported for that purpose and both are driven
51
+ * by the sameShape specs, so they are schemas that have been PROVED to answer identically
52
+ * to the `bun:sqlite` ones rather than transcribed by hand. A missing table is not silent:
53
+ * the snapshot read below is the first thing that happens and D1 fails it by name.
54
+ */
55
+ import { type SsoUserStore } from "./ssoUsers";
56
+ import type { SessionRows } from "./userSessions.core";
57
+ export { SESSIONS_DDL } from "./userSessions.core";
58
+ export { SSO_USERS_DDL } from "./ssoUsers";
59
+ /**
60
+ * The slice of a D1 handle these stores use.
61
+ *
62
+ * 🔴 Declared HERE rather than imported from `cursedbelt-server/d1`, deliberately. This
63
+ * package sits UNDER that one — every app installs `cursedauth` and not all of them
64
+ * install the belt — so a type-only import would put a required peer on a package that
65
+ * needs nothing else from it, and would couple two independently-published majors in one
66
+ * `node_modules`. It is structural: `cursedbelt-server/d1`'s `D1LikeDatabase` and
67
+ * Cloudflare's own `D1Database` both satisfy it as they are, and
68
+ * `d1Stores.handleShape.test.ts` asserts the first of those at compile time so that a
69
+ * change on the other side of the seam is a red here rather than a surprise in somebody's
70
+ * `wrangler deploy`.
71
+ */
72
+ export interface D1HandleStatement {
73
+ bind(...values: (string | number | null)[]): D1HandleStatement;
74
+ all<T>(): Promise<{
75
+ results: T[];
76
+ }>;
77
+ run(): Promise<unknown>;
78
+ }
79
+ export interface D1Handle {
80
+ prepare(sql: string): D1HandleStatement;
81
+ /**
82
+ * Several statements, atomically, in ORDER, as one round trip.
83
+ *
84
+ * 🔴 Required rather than convenient. {@link WriteCollector} fires what it is given
85
+ * immediately and awaits the set at the end, so two separately-collected statements
86
+ * race — and `upsert` below is a DELETE that MUST land before its INSERT or the
87
+ * unique index on `lower(email)` refuses a legitimate sign-in. Ordering that matters
88
+ * goes in one `batch`, never in two `add`s.
89
+ */
90
+ batch(statements: D1HandleStatement[]): Promise<unknown>;
91
+ }
92
+ /**
93
+ * Where a durable write goes on its way out.
94
+ *
95
+ * Two members is deliberately fewer than the `PendingWrites` interface `apps/patterns` and
96
+ * `apps/collections` already carry — this needs only `add`, so both of those objects
97
+ * satisfy it verbatim and neither app has to change anything to adopt these stores.
98
+ */
99
+ export interface WriteCollector {
100
+ add(promise: Promise<unknown>): void;
101
+ }
102
+ /** A write that must land before the response is returned. See the header. */
103
+ export interface PendingWrites extends WriteCollector {
104
+ /** Await every collected write. Called BEFORE the response is returned, never after. */
105
+ settle(): Promise<void>;
106
+ }
107
+ export declare function createPendingWrites(): PendingWrites;
108
+ /**
109
+ * How many rows either snapshot may hold before this refuses to take one.
110
+ *
111
+ * 🔴 It REFUSES rather than truncating, and the difference is the whole point. A silently
112
+ * truncated snapshot of a credential table answers "no such session" for everybody past
113
+ * the cut — so signing in appears to work, the cookie is real, and every subsequent
114
+ * request is anonymous. A throw is a 500 naming the table and the number, which somebody
115
+ * can act on.
116
+ *
117
+ * The default suits a household: `sessions` is bounded by people × devices and swept on
118
+ * every write, `sso_users` by how many accounts have ever signed in here. An app with
119
+ * thousands of principals must move these reads into SQL — a per-request snapshot keyed on
120
+ * the cookie the request actually carries — rather than raising this number.
121
+ */
122
+ export declare const SNAPSHOT_MAX_ROWS = 5000;
123
+ export declare class D1SnapshotTooLargeError extends RangeError {
124
+ readonly table: string;
125
+ constructor(table: string, max: number);
126
+ }
127
+ export interface D1StoreOptions {
128
+ /** The invocation's clock, in ms. One value for the whole request. */
129
+ now: number;
130
+ /** Override {@link SNAPSHOT_MAX_ROWS} — lower it in a test that proves the refusal. */
131
+ maxRows?: number;
132
+ }
133
+ /**
134
+ * The `sessions` table for one invocation. Hand the result to
135
+ * `createUserSessionStoreOver` from `cursedauth/user-sessions-core`.
136
+ *
137
+ * ## 🔴 What the snapshot is, and what it deliberately is not
138
+ *
139
+ * It is every row that is still LIVE at `now` — not the whole table. Expired rows are
140
+ * excluded because every reader discards them anyway (`byId`'s call sites re-check
141
+ * `expires_at > now()`; `forUser` takes the cutoff), and because including them would let
142
+ * a table nobody has swept push a working app past {@link SNAPSHOT_MAX_ROWS}. The one way
143
+ * the two implementations could then disagree is a clock that runs BACKWARDS inside a
144
+ * single invocation, which `options.now` makes possible in a test and nothing makes
145
+ * possible in production — which is why the sameShape spec drives both sides from one
146
+ * non-decreasing fake clock rather than pretending the question does not exist.
147
+ *
148
+ * The store sweeps on every write, so the live set is also very nearly the whole table.
149
+ */
150
+ export declare function createD1SessionRows(db: D1Handle, writes: WriteCollector, options: D1StoreOptions): Promise<SessionRows>;
151
+ /**
152
+ * The `sso_users` snapshot for one invocation. Pass the result as `users` to
153
+ * `createSsoConsumer`.
154
+ *
155
+ * The whole table, because it IS the household: one row per account that has ever signed
156
+ * in to this app. The consumer reads it by id for the request's own user and once per
157
+ * occupied account slot, so a snapshot costs one query where per-key reads would cost one
158
+ * per slot — up to `MAX_ACCOUNT_SLOTS` of them on the account switcher's own route.
159
+ */
160
+ export declare function createD1SsoUserStore(db: D1Handle, writes: WriteCollector, options: D1StoreOptions): Promise<SsoUserStore>;
161
+ //# sourceMappingURL=d1Stores.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"d1Stores.d.ts","sourceRoot":"","sources":["../src/d1Stores.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,OAAO,EAIN,KAAK,YAAY,EACjB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAc,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEnE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,iBAAiB;IACjC,IAAI,CAAC,GAAG,MAAM,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC,EAAE,GAAG,iBAAiB,CAAC;IAC/D,GAAG,CAAC,CAAC,KAAK,OAAO,CAAC;QAAE,OAAO,EAAE,CAAC,EAAE,CAAA;KAAE,CAAC,CAAC;IACpC,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CACxB;AAED,MAAM,WAAW,QAAQ;IACxB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,iBAAiB,CAAC;IACxC;;;;;;;;OAQG;IACH,KAAK,CAAC,UAAU,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACzD;AAED;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC9B,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;CACrC;AAED,8EAA8E;AAC9E,MAAM,WAAW,aAAc,SAAQ,cAAc;IACpD,wFAAwF;IACxF,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED,wBAAgB,mBAAmB,IAAI,aAAa,CAWnD;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,iBAAiB,OAAQ,CAAC;AAEvC,qBAAa,uBAAwB,SAAQ,UAAU;IACtD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;gBACX,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;CAUtC;AA0CD,MAAM,WAAW,cAAc;IAC9B,sEAAsE;IACtE,GAAG,EAAE,MAAM,CAAC;IACZ,uFAAuF;IACvF,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,mBAAmB,CACxC,EAAE,EAAE,QAAQ,EACZ,MAAM,EAAE,cAAc,EACtB,OAAO,EAAE,cAAc,GACrB,OAAO,CAAC,WAAW,CAAC,CAkFtB;AAKD;;;;;;;;GAQG;AACH,wBAAsB,oBAAoB,CACzC,EAAE,EAAE,QAAQ,EACZ,MAAM,EAAE,cAAc,EACtB,OAAO,EAAE,cAAc,GACrB,OAAO,CAAC,YAAY,CAAC,CAqHvB"}
@@ -0,0 +1,295 @@
1
+ /**
2
+ * `cursedauth` on Cloudflare D1 — the two stores an app's DOOR needs, snapshot-and-settle.
3
+ *
4
+ * ## 🔴 The problem this solves, stated once
5
+ *
6
+ * `createUserSessionStore` and `createSsoConsumer` are synchronous **by publication**:
7
+ * nineteen members and five statements, every one of them called in the middle of
8
+ * resolving a cookie, by six apps that have not ported. Cloudflare's only database is
9
+ * async. Neither side can move — making the stores async breaks the six, and `workerd`
10
+ * will never have `bun:sqlite` — so an app ported to a Worker could serve its catalogue
11
+ * and refuse its own front door. Measured 2026-09-19: `apps/collections` shipped exactly
12
+ * that, a `503` on every `/api/*` naming this gap.
13
+ *
14
+ * The answer, which is the fleet's established one (`tasks/Procedures/move-an-app-to-cloudflare.md`
15
+ * §3, and the two working examples in `apps/patterns/worker/stores.ts` and
16
+ * `apps/collections/worker/stores.ts`):
17
+ *
18
+ * 1. before `app.fetch`, ONE D1 read fills an in-memory snapshot;
19
+ * 2. every synchronous call during the request answers from that snapshot;
20
+ * 3. writes are collected as pending promises, and the entry point **awaits them before
21
+ * it returns the response** — so nothing is acknowledged before it is durable.
22
+ *
23
+ * Two extra queries per invocation, against a 1,000-query budget.
24
+ *
25
+ * ## 🔴 What this must never become: an in-memory store with no read-back
26
+ *
27
+ * A Worker isolate is per-colo and short-lived. A revocation kept only in one isolate's
28
+ * memory means **signing out works until the next request lands somewhere else** — which
29
+ * reads to the person as the feature being broken rather than absent, and leaves a
30
+ * credential live that a human believes they ended. That is the worst outcome this file
31
+ * has, it is invisible in any single-process test, and `d1Stores.lostWrite.test.ts` is
32
+ * what holds the line: it drives two separate store instances standing for two isolates
33
+ * over one database, and it carries a test of its own failure path — a collector that
34
+ * DROPS writes, proving the harness can tell a durable store from a memory-only one.
35
+ *
36
+ * ## What is honest about the staleness
37
+ *
38
+ * A write made by request A is not visible to request B until B takes its own snapshot.
39
+ * For a sign-out that is milliseconds. Within ONE invocation a read-after-write is exact,
40
+ * because every mutation below updates the snapshot as well as queueing the statement —
41
+ * the property `bun:sqlite` has for free and whose absence would make `revoke()` followed
42
+ * by a session check disagree with itself inside one request.
43
+ *
44
+ * ## Where the SCHEMA comes from
45
+ *
46
+ * D1 has no migration story inside a request and DDL per invocation would spend the query
47
+ * budget on statements that can only ever matter once. So `ensureSchema()` here is a
48
+ * documented no-op and the tables come from the app's `db/schema.sql`, applied by
49
+ * `wrangler d1 execute --file db/schema.sql`. Paste {@link SESSIONS_DDL} and
50
+ * {@link SSO_USERS_DDL} into it — both are exported for that purpose and both are driven
51
+ * by the sameShape specs, so they are schemas that have been PROVED to answer identically
52
+ * to the `bun:sqlite` ones rather than transcribed by hand. A missing table is not silent:
53
+ * the snapshot read below is the first thing that happens and D1 fails it by name.
54
+ */
55
+ import { normalizeSsoUserRow, } from "./ssoUsers";
56
+ export { SESSIONS_DDL } from "./userSessions.core";
57
+ export { SSO_USERS_DDL } from "./ssoUsers";
58
+ export function createPendingWrites() {
59
+ const pending = [];
60
+ return {
61
+ add: (promise) => void pending.push(promise),
62
+ async settle() {
63
+ // `all`, not `allSettled`: a failed durable write must not be reported as a
64
+ // success. It surfaces as a 500 from the entry point, which is the honest answer
65
+ // to "did my sign-out take".
66
+ await Promise.all(pending);
67
+ },
68
+ };
69
+ }
70
+ /**
71
+ * How many rows either snapshot may hold before this refuses to take one.
72
+ *
73
+ * 🔴 It REFUSES rather than truncating, and the difference is the whole point. A silently
74
+ * truncated snapshot of a credential table answers "no such session" for everybody past
75
+ * the cut — so signing in appears to work, the cookie is real, and every subsequent
76
+ * request is anonymous. A throw is a 500 naming the table and the number, which somebody
77
+ * can act on.
78
+ *
79
+ * The default suits a household: `sessions` is bounded by people × devices and swept on
80
+ * every write, `sso_users` by how many accounts have ever signed in here. An app with
81
+ * thousands of principals must move these reads into SQL — a per-request snapshot keyed on
82
+ * the cookie the request actually carries — rather than raising this number.
83
+ */
84
+ export const SNAPSHOT_MAX_ROWS = 5_000;
85
+ export class D1SnapshotTooLargeError extends RangeError {
86
+ table;
87
+ constructor(table, max) {
88
+ super(`cursedauth's D1 ${table} snapshot would exceed ${max} rows. These stores read the ` +
89
+ `live table once per invocation and serve the request from it, which is only honest ` +
90
+ `while the table is small. Do NOT raise the limit: move this read into SQL, keyed on ` +
91
+ `the session the request actually carries.`);
92
+ this.name = "D1SnapshotTooLargeError";
93
+ this.table = table;
94
+ }
95
+ }
96
+ /** One read, bounded, that refuses rather than truncates. */
97
+ async function snapshot(db, table, sql, binds, max) {
98
+ // `max + 1` is what turns "we got exactly the limit" from ambiguous into decisive: a
99
+ // full page could mean a full table or a cut one, and one extra row says which.
100
+ const rows = (await db.prepare(`${sql} LIMIT ?`).bind(...binds, max + 1).all()).results;
101
+ if (rows.length > max)
102
+ throw new D1SnapshotTooLargeError(table, max);
103
+ return rows;
104
+ }
105
+ const SESSION_COLUMNS = "id, user_id, expires_at, user_agent, ip, created_at, last_seen_at, place";
106
+ /** The same fail-closed normalization the `bun:sqlite` implementation performs. */
107
+ const normalizeSessionRow = (row) => ({
108
+ id: row.id,
109
+ user_id: row.user_id,
110
+ expires_at: row.expires_at,
111
+ user_agent: row.user_agent ?? "",
112
+ ip: row.ip ?? "",
113
+ created_at: row.created_at ?? 0,
114
+ last_seen_at: row.last_seen_at ?? 0,
115
+ place: row.place ?? "",
116
+ });
117
+ /**
118
+ * The `sessions` table for one invocation. Hand the result to
119
+ * `createUserSessionStoreOver` from `cursedauth/user-sessions-core`.
120
+ *
121
+ * ## 🔴 What the snapshot is, and what it deliberately is not
122
+ *
123
+ * It is every row that is still LIVE at `now` — not the whole table. Expired rows are
124
+ * excluded because every reader discards them anyway (`byId`'s call sites re-check
125
+ * `expires_at > now()`; `forUser` takes the cutoff), and because including them would let
126
+ * a table nobody has swept push a working app past {@link SNAPSHOT_MAX_ROWS}. The one way
127
+ * the two implementations could then disagree is a clock that runs BACKWARDS inside a
128
+ * single invocation, which `options.now` makes possible in a test and nothing makes
129
+ * possible in production — which is why the sameShape spec drives both sides from one
130
+ * non-decreasing fake clock rather than pretending the question does not exist.
131
+ *
132
+ * The store sweeps on every write, so the live set is also very nearly the whole table.
133
+ */
134
+ export async function createD1SessionRows(db, writes, options) {
135
+ const max = options.maxRows ?? SNAPSHOT_MAX_ROWS;
136
+ const rows = await snapshot(db, "sessions", `SELECT ${SESSION_COLUMNS} FROM sessions WHERE expires_at > ?`, [options.now], max);
137
+ const live = new Map();
138
+ for (const row of rows)
139
+ live.set(row.id, normalizeSessionRow(row));
140
+ return {
141
+ byId: (id) => live.get(id) ?? null,
142
+ forUser: (userId, liveAfter) => [...live.values()]
143
+ .filter((row) => row.user_id === userId && row.expires_at > liveAfter)
144
+ // The ORDER is part of the seam's contract — `SessionRows.forUser` says why.
145
+ // `bun:sqlite` gets it from `ORDER BY last_seen_at DESC, expires_at DESC`;
146
+ // here it is the same two keys, same direction, applied to the snapshot.
147
+ .sort((a, b) => b.last_seen_at - a.last_seen_at || b.expires_at - a.expires_at),
148
+ insert(row) {
149
+ live.set(row.id, row);
150
+ writes.add(db
151
+ .prepare(`INSERT INTO sessions (${SESSION_COLUMNS}) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`)
152
+ .bind(row.id, row.user_id, row.expires_at, row.user_agent, row.ip, row.created_at, row.last_seen_at, row.place)
153
+ .run());
154
+ },
155
+ touch(id, at) {
156
+ const row = live.get(id);
157
+ if (row)
158
+ live.set(id, { ...row, last_seen_at: at });
159
+ writes.add(db.prepare("UPDATE sessions SET last_seen_at = ? WHERE id = ?").bind(at, id).run());
160
+ },
161
+ deleteById(id) {
162
+ live.delete(id);
163
+ writes.add(db.prepare("DELETE FROM sessions WHERE id = ?").bind(id).run());
164
+ },
165
+ deleteByIdForUser(id, userId) {
166
+ // Scoped in the snapshot exactly as it is scoped in SQL: a handle that names
167
+ // somebody else's session must delete nothing on either side.
168
+ if (live.get(id)?.user_id === userId)
169
+ live.delete(id);
170
+ writes.add(db.prepare("DELETE FROM sessions WHERE id = ? AND user_id = ?").bind(id, userId).run());
171
+ },
172
+ deleteForUser(userId) {
173
+ for (const [id, row] of live)
174
+ if (row.user_id === userId)
175
+ live.delete(id);
176
+ writes.add(db.prepare("DELETE FROM sessions WHERE user_id = ?").bind(userId).run());
177
+ },
178
+ deleteOthersForUser(userId, keepId) {
179
+ for (const [id, row] of live)
180
+ if (row.user_id === userId && id !== keepId)
181
+ live.delete(id);
182
+ writes.add(db
183
+ .prepare("DELETE FROM sessions WHERE user_id = ? AND id != ?")
184
+ .bind(userId, keepId)
185
+ .run());
186
+ },
187
+ deleteExpired(at) {
188
+ for (const [id, row] of live)
189
+ if (row.expires_at <= at)
190
+ live.delete(id);
191
+ writes.add(db.prepare("DELETE FROM sessions WHERE expires_at <= ?").bind(at).run());
192
+ },
193
+ };
194
+ }
195
+ const SSO_USER_COLUMNS = "id, email, name, is_admin, is_owner, is_granted, last_login_at, created_at, updated_at";
196
+ /**
197
+ * The `sso_users` snapshot for one invocation. Pass the result as `users` to
198
+ * `createSsoConsumer`.
199
+ *
200
+ * The whole table, because it IS the household: one row per account that has ever signed
201
+ * in to this app. The consumer reads it by id for the request's own user and once per
202
+ * occupied account slot, so a snapshot costs one query where per-key reads would cost one
203
+ * per slot — up to `MAX_ACCOUNT_SLOTS` of them on the account switcher's own route.
204
+ */
205
+ export async function createD1SsoUserStore(db, writes, options) {
206
+ const max = options.maxRows ?? SNAPSHOT_MAX_ROWS;
207
+ const rows = await snapshot(db, "sso_users", `SELECT ${SSO_USER_COLUMNS} FROM sso_users`, [], max);
208
+ const users = new Map();
209
+ for (const row of rows)
210
+ users.set(row.id, normalizeSsoUserRow(row));
211
+ const sameAddress = (a, b) => a.toLowerCase() === b.toLowerCase();
212
+ return {
213
+ ensureSchema() {
214
+ // 🔴 Deliberately nothing. D1's schema is applied out of band by
215
+ // `wrangler d1 execute --file db/schema.sql` — paste `SSO_USERS_DDL` into it —
216
+ // and a per-invocation `CREATE TABLE IF NOT EXISTS` would spend the request's
217
+ // query budget on DDL that can only ever matter once. It is not a silent
218
+ // no-op: the snapshot above runs BEFORE any of this and D1 fails it by name if
219
+ // the table is absent, so a forgotten migration is a loud 500 on the first
220
+ // request rather than a door that refuses everybody.
221
+ },
222
+ byId: (id) => users.get(id) ?? null,
223
+ upsert(row) {
224
+ // The snapshot first, so the rest of THIS invocation sees the account it just
225
+ // wrote — the callback mints a session and reads the user back within one
226
+ // request.
227
+ for (const [id, existing] of users) {
228
+ if (id !== row.id && sameAddress(existing.email, row.email))
229
+ users.delete(id);
230
+ }
231
+ const previous = users.get(row.id);
232
+ users.set(row.id, {
233
+ ...row,
234
+ // `created_at` belongs to the row's first write. The SQL below says the same
235
+ // thing by leaving it out of the `DO UPDATE SET` list; saying it here too is
236
+ // what keeps the snapshot from disagreeing with what was durably stored.
237
+ created_at: previous?.created_at ?? row.created_at,
238
+ });
239
+ // 🔴 ONE batch, not two `add`s. The DELETE must land before the INSERT or the
240
+ // unique index on `lower(email)` refuses a legitimate re-issued account id —
241
+ // and a collector fires what it is given immediately, so two adds race. See
242
+ // `D1Handle.batch`.
243
+ writes.add(db.batch([
244
+ db
245
+ .prepare("DELETE FROM sso_users WHERE lower(email) = lower(?) AND id <> ?")
246
+ .bind(row.email, row.id),
247
+ db
248
+ .prepare(`INSERT INTO sso_users (${SSO_USER_COLUMNS})
249
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
250
+ ON CONFLICT(id) DO UPDATE SET
251
+ email = excluded.email, name = excluded.name, is_admin = excluded.is_admin,
252
+ is_owner = excluded.is_owner, is_granted = excluded.is_granted,
253
+ last_login_at = excluded.last_login_at, updated_at = excluded.updated_at`)
254
+ .bind(row.id, row.email, row.name, row.is_admin, row.is_owner, row.is_granted, row.last_login_at, row.created_at, row.updated_at),
255
+ ]));
256
+ },
257
+ deleteById(id) {
258
+ users.delete(id);
259
+ writes.add(db.prepare("DELETE FROM sso_users WHERE id = ?").bind(id).run());
260
+ },
261
+ dropDuplicates() {
262
+ // Unreachable from `ensureSchema` here — a database that starts behind the unique
263
+ // index cannot grow a duplicate — but implemented rather than thrown, because a
264
+ // one-off import script that copies a Mac's table into D1 CAN, and a member that
265
+ // silently did nothing would be a repair somebody believed had run.
266
+ const keep = new Map();
267
+ for (const row of users.values()) {
268
+ const key = row.email.toLowerCase();
269
+ const winner = keep.get(key);
270
+ if (!winner ||
271
+ row.last_login_at > winner.last_login_at ||
272
+ (row.last_login_at === winner.last_login_at && row.updated_at > winner.updated_at)) {
273
+ keep.set(key, row);
274
+ }
275
+ }
276
+ const survivors = new Set([...keep.values()].map((row) => row.id));
277
+ for (const id of [...users.keys()])
278
+ if (!survivors.has(id))
279
+ users.delete(id);
280
+ writes.add(db
281
+ .prepare(`DELETE FROM sso_users WHERE rowid NOT IN (
282
+ SELECT rowid FROM (
283
+ SELECT rowid,
284
+ ROW_NUMBER() OVER (
285
+ PARTITION BY lower(email)
286
+ ORDER BY last_login_at DESC, updated_at DESC, rowid DESC
287
+ ) AS rn
288
+ FROM sso_users
289
+ ) WHERE rn = 1
290
+ )`)
291
+ .run());
292
+ },
293
+ };
294
+ }
295
+ //# sourceMappingURL=d1Stores.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"d1Stores.js","sourceRoot":"","sources":["../src/d1Stores.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,OAAO,EACN,mBAAmB,GAInB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAoD3C,MAAM,UAAU,mBAAmB;IAClC,MAAM,OAAO,GAAuB,EAAE,CAAC;IACvC,OAAO;QACN,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC;QAC5C,KAAK,CAAC,MAAM;YACX,4EAA4E;YAC5E,iFAAiF;YACjF,6BAA6B;YAC7B,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC5B,CAAC;KACD,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,CAAC;AAEvC,MAAM,OAAO,uBAAwB,SAAQ,UAAU;IAC7C,KAAK,CAAS;IACvB,YAAY,KAAa,EAAE,GAAW;QACrC,KAAK,CACJ,mBAAmB,KAAK,0BAA0B,GAAG,+BAA+B;YACnF,qFAAqF;YACrF,sFAAsF;YACtF,2CAA2C,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,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;YACnE,KAAK,MAAM,EAAE,IAAI,CAAC,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;gBAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;oBAAE,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YAC7E,MAAM,CAAC,GAAG,CACT,EAAE;iBACA,OAAO,CACP;;;;;;;;;QASE,CACF;iBACA,GAAG,EAAE,CACP,CAAC;QACH,CAAC;KACD,CAAC;AACH,CAAC"}
package/dist/index.d.ts CHANGED
@@ -16,7 +16,8 @@
16
16
  * knowledge of it is that URL and its public key.
17
17
  */
18
18
  export { createSsoConsumer, resolveSsoAudience, sanitizeReturnPath, SSO_CALLBACK_PATH, SSO_CENSUS_PATH, SSO_RETURN_COOKIE, SSO_REVOKE_PATH, SSO_SESSIONS_PATH, SSO_SIGNOUT_PATH, SSO_SLOT_COOKIE, SSO_START_PATH, type SsoConsumer, type SsoConsumerOptions, type SsoUser, } from "./ssoConsumer.server";
19
- export { createUserSessionStore, type SessionRecord, type SignedIn, type SignInOptions, type SlotOccupant, type UserSessionStore, type UserSessionStoreOptions, } from "./userSessions";
19
+ export { createSqliteSessionRows, createUserSessionStore, createUserSessionStoreOver, SESSIONS_DDL, type SessionRecord, type SessionRow, type SessionRows, type SignedIn, type SignInOptions, type SlotOccupant, type UserSessionStore, type UserSessionStoreCoreOptions, type UserSessionStoreOptions, } from "./userSessions";
20
+ export { createSqliteSsoUserStore, normalizeSsoUserRow, type RawSsoUserRow, SSO_USERS_DDL, type SsoUserRow, type SsoUserStore, } from "./ssoUsers";
20
21
  export { DEFAULT_GATE_PATH, type GatedMountPlan, gatedMountReport, type Mounter, mountGatedApp, type SessionGate, } from "./mountGatedApp";
21
22
  export { type CensusCounter, countingCensus, sharedCensus } from "./contentCensus";
22
23
  export { LOCAL_AUTH_URL, STAGE_IDENTITY_ENV, stageIdentityIsLocal, } from "./stageIdentity";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EACN,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,OAAO,GACZ,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,sBAAsB,EACtB,KAAK,aAAa,EAClB,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,GAC5B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACN,iBAAiB,EACjB,KAAK,cAAc,EACnB,gBAAgB,EAChB,KAAK,OAAO,EACZ,aAAa,EACb,KAAK,WAAW,GAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,KAAK,aAAa,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACnF,OAAO,EACN,cAAc,EACd,kBAAkB,EAClB,oBAAoB,GACpB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAa9D,OAAO,EACN,WAAW,EACX,uBAAuB,EACvB,oBAAoB,EACpB,iCAAiC,EACjC,kBAAkB,EAClB,gBAAgB,EAChB,KAAK,cAAc,EACnB,kBAAkB,EAClB,KAAK,aAAa,EAClB,KAAK,eAAe,GACpB,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EACN,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,OAAO,GACZ,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,uBAAuB,EACvB,sBAAsB,EACtB,0BAA0B,EAC1B,YAAY,EACZ,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,2BAA2B,EAChC,KAAK,uBAAuB,GAC5B,MAAM,gBAAgB,CAAC;AAOxB,OAAO,EACN,wBAAwB,EACxB,mBAAmB,EACnB,KAAK,aAAa,EAClB,aAAa,EACb,KAAK,UAAU,EACf,KAAK,YAAY,GACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EACN,iBAAiB,EACjB,KAAK,cAAc,EACnB,gBAAgB,EAChB,KAAK,OAAO,EACZ,aAAa,EACb,KAAK,WAAW,GAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,KAAK,aAAa,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACnF,OAAO,EACN,cAAc,EACd,kBAAkB,EAClB,oBAAoB,GACpB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAa9D,OAAO,EACN,WAAW,EACX,uBAAuB,EACvB,oBAAoB,EACpB,iCAAiC,EACjC,kBAAkB,EAClB,gBAAgB,EAChB,KAAK,cAAc,EACnB,kBAAkB,EAClB,KAAK,aAAa,EAClB,KAAK,eAAe,GACpB,MAAM,eAAe,CAAC"}
package/dist/index.js CHANGED
@@ -16,7 +16,14 @@
16
16
  * knowledge of it is that URL and its public key.
17
17
  */
18
18
  export { createSsoConsumer, resolveSsoAudience, sanitizeReturnPath, SSO_CALLBACK_PATH, SSO_CENSUS_PATH, SSO_RETURN_COOKIE, SSO_REVOKE_PATH, SSO_SESSIONS_PATH, SSO_SIGNOUT_PATH, SSO_SLOT_COOKIE, SSO_START_PATH, } from "./ssoConsumer.server";
19
- export { createUserSessionStore, } from "./userSessions";
19
+ export { createSqliteSessionRows, createUserSessionStore, createUserSessionStoreOver, SESSIONS_DDL, } from "./userSessions";
20
+ /*
21
+ * The `sso_users` seam. 🔴 `cursedauth/d1-stores` is deliberately NOT re-exported from
22
+ * this barrel: it has no reason to be here (a Worker cannot import this file at all —
23
+ * the barrel reaches `bun:sqlite` through `./userSessions`), and re-exporting it would
24
+ * put a second, Bun-only route to a Worker-only module in front of every reader.
25
+ */
26
+ export { createSqliteSsoUserStore, normalizeSsoUserRow, SSO_USERS_DDL, } from "./ssoUsers";
20
27
  export { DEFAULT_GATE_PATH, gatedMountReport, mountGatedApp, } from "./mountGatedApp";
21
28
  export { countingCensus, sharedCensus } from "./contentCensus";
22
29
  export { LOCAL_AUTH_URL, STAGE_IDENTITY_ENV, stageIdentityIsLocal, } from "./stageIdentity";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EACN,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,cAAc,GAId,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,sBAAsB,GAOtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACN,iBAAiB,EAEjB,gBAAgB,EAEhB,aAAa,GAEb,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAsB,cAAc,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACnF,OAAO,EACN,cAAc,EACd,kBAAkB,EAClB,oBA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