cursedauth 0.7.0 → 0.9.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,7 +38,10 @@ 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 |
@@ -0,0 +1,172 @@
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
+ /**
108
+ * 🔴 The SHARED home of this primitive is `cursedbelt-server/d1` — it is a D1-invocation
109
+ * concern, it sits beside `perInvocation` there, and its header carries the full argument.
110
+ * This copy stays because the dependency edge may not: every app installs `cursedauth` and
111
+ * not all of them install the belt, so a belt-less consumer needs a door here. One
112
+ * implementation's worth of BEHAVIOUR behind two doors is not two implementations — but it
113
+ * is still two bodies, so **a change to either one belongs in both**, and the belt's is the
114
+ * one that decides. The contract that must not drift is `Promise.all` over `allSettled`, and
115
+ * both sides hold it under test: `d1Stores.lostWrite.test.ts:254` here, and
116
+ * `d1/invocation.spec.ts`'s "a failed write REJECTS settle()" there.
117
+ */
118
+ export declare function createPendingWrites(): PendingWrites;
119
+ /**
120
+ * How many rows either snapshot may hold before this refuses to take one.
121
+ *
122
+ * 🔴 It REFUSES rather than truncating, and the difference is the whole point. A silently
123
+ * truncated snapshot of a credential table answers "no such session" for everybody past
124
+ * the cut — so signing in appears to work, the cookie is real, and every subsequent
125
+ * request is anonymous. A throw is a 500 naming the table and the number, which somebody
126
+ * can act on.
127
+ *
128
+ * The default suits a household: `sessions` is bounded by people × devices and swept on
129
+ * every write, `sso_users` by how many accounts have ever signed in here. An app with
130
+ * thousands of principals must move these reads into SQL — a per-request snapshot keyed on
131
+ * the cookie the request actually carries — rather than raising this number.
132
+ */
133
+ export declare const SNAPSHOT_MAX_ROWS = 5000;
134
+ export declare class D1SnapshotTooLargeError extends RangeError {
135
+ readonly table: string;
136
+ constructor(table: string, max: number);
137
+ }
138
+ export interface D1StoreOptions {
139
+ /** The invocation's clock, in ms. One value for the whole request. */
140
+ now: number;
141
+ /** Override {@link SNAPSHOT_MAX_ROWS} — lower it in a test that proves the refusal. */
142
+ maxRows?: number;
143
+ }
144
+ /**
145
+ * The `sessions` table for one invocation. Hand the result to
146
+ * `createUserSessionStoreOver` from `cursedauth/user-sessions-core`.
147
+ *
148
+ * ## 🔴 What the snapshot is, and what it deliberately is not
149
+ *
150
+ * It is every row that is still LIVE at `now` — not the whole table. Expired rows are
151
+ * excluded because every reader discards them anyway (`byId`'s call sites re-check
152
+ * `expires_at > now()`; `forUser` takes the cutoff), and because including them would let
153
+ * a table nobody has swept push a working app past {@link SNAPSHOT_MAX_ROWS}. The one way
154
+ * the two implementations could then disagree is a clock that runs BACKWARDS inside a
155
+ * single invocation, which `options.now` makes possible in a test and nothing makes
156
+ * possible in production — which is why the sameShape spec drives both sides from one
157
+ * non-decreasing fake clock rather than pretending the question does not exist.
158
+ *
159
+ * The store sweeps on every write, so the live set is also very nearly the whole table.
160
+ */
161
+ export declare function createD1SessionRows(db: D1Handle, writes: WriteCollector, options: D1StoreOptions): Promise<SessionRows>;
162
+ /**
163
+ * The `sso_users` snapshot for one invocation. Pass the result as `users` to
164
+ * `createSsoConsumer`.
165
+ *
166
+ * The whole table, because it IS the household: one row per account that has ever signed
167
+ * in to this app. The consumer reads it by id for the request's own user and once per
168
+ * occupied account slot, so a snapshot costs one query where per-key reads would cost one
169
+ * per slot — up to `MAX_ACCOUNT_SLOTS` of them on the account switcher's own route.
170
+ */
171
+ export declare function createD1SsoUserStore(db: D1Handle, writes: WriteCollector, options: D1StoreOptions): Promise<SsoUserStore>;
172
+ //# 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;A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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,306 @@
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
+ /**
59
+ * 🔴 The SHARED home of this primitive is `cursedbelt-server/d1` — it is a D1-invocation
60
+ * concern, it sits beside `perInvocation` there, and its header carries the full argument.
61
+ * This copy stays because the dependency edge may not: every app installs `cursedauth` and
62
+ * not all of them install the belt, so a belt-less consumer needs a door here. One
63
+ * implementation's worth of BEHAVIOUR behind two doors is not two implementations — but it
64
+ * is still two bodies, so **a change to either one belongs in both**, and the belt's is the
65
+ * one that decides. The contract that must not drift is `Promise.all` over `allSettled`, and
66
+ * both sides hold it under test: `d1Stores.lostWrite.test.ts:254` here, and
67
+ * `d1/invocation.spec.ts`'s "a failed write REJECTS settle()" there.
68
+ */
69
+ export function createPendingWrites() {
70
+ const pending = [];
71
+ return {
72
+ add: (promise) => void pending.push(promise),
73
+ async settle() {
74
+ // `all`, not `allSettled`: a failed durable write must not be reported as a
75
+ // success. It surfaces as a 500 from the entry point, which is the honest answer
76
+ // to "did my sign-out take".
77
+ await Promise.all(pending);
78
+ },
79
+ };
80
+ }
81
+ /**
82
+ * How many rows either snapshot may hold before this refuses to take one.
83
+ *
84
+ * 🔴 It REFUSES rather than truncating, and the difference is the whole point. A silently
85
+ * truncated snapshot of a credential table answers "no such session" for everybody past
86
+ * the cut — so signing in appears to work, the cookie is real, and every subsequent
87
+ * request is anonymous. A throw is a 500 naming the table and the number, which somebody
88
+ * can act on.
89
+ *
90
+ * The default suits a household: `sessions` is bounded by people × devices and swept on
91
+ * every write, `sso_users` by how many accounts have ever signed in here. An app with
92
+ * thousands of principals must move these reads into SQL — a per-request snapshot keyed on
93
+ * the cookie the request actually carries — rather than raising this number.
94
+ */
95
+ export const SNAPSHOT_MAX_ROWS = 5_000;
96
+ export class D1SnapshotTooLargeError extends RangeError {
97
+ table;
98
+ constructor(table, max) {
99
+ super(`cursedauth's D1 ${table} snapshot would exceed ${max} rows. These stores read the ` +
100
+ `live table once per invocation and serve the request from it, which is only honest ` +
101
+ `while the table is small. Do NOT raise the limit: move this read into SQL, keyed on ` +
102
+ `the session the request actually carries.`);
103
+ this.name = "D1SnapshotTooLargeError";
104
+ this.table = table;
105
+ }
106
+ }
107
+ /** One read, bounded, that refuses rather than truncates. */
108
+ async function snapshot(db, table, sql, binds, max) {
109
+ // `max + 1` is what turns "we got exactly the limit" from ambiguous into decisive: a
110
+ // full page could mean a full table or a cut one, and one extra row says which.
111
+ const rows = (await db.prepare(`${sql} LIMIT ?`).bind(...binds, max + 1).all()).results;
112
+ if (rows.length > max)
113
+ throw new D1SnapshotTooLargeError(table, max);
114
+ return rows;
115
+ }
116
+ const SESSION_COLUMNS = "id, user_id, expires_at, user_agent, ip, created_at, last_seen_at, place";
117
+ /** The same fail-closed normalization the `bun:sqlite` implementation performs. */
118
+ const normalizeSessionRow = (row) => ({
119
+ id: row.id,
120
+ user_id: row.user_id,
121
+ expires_at: row.expires_at,
122
+ user_agent: row.user_agent ?? "",
123
+ ip: row.ip ?? "",
124
+ created_at: row.created_at ?? 0,
125
+ last_seen_at: row.last_seen_at ?? 0,
126
+ place: row.place ?? "",
127
+ });
128
+ /**
129
+ * The `sessions` table for one invocation. Hand the result to
130
+ * `createUserSessionStoreOver` from `cursedauth/user-sessions-core`.
131
+ *
132
+ * ## 🔴 What the snapshot is, and what it deliberately is not
133
+ *
134
+ * It is every row that is still LIVE at `now` — not the whole table. Expired rows are
135
+ * excluded because every reader discards them anyway (`byId`'s call sites re-check
136
+ * `expires_at > now()`; `forUser` takes the cutoff), and because including them would let
137
+ * a table nobody has swept push a working app past {@link SNAPSHOT_MAX_ROWS}. The one way
138
+ * the two implementations could then disagree is a clock that runs BACKWARDS inside a
139
+ * single invocation, which `options.now` makes possible in a test and nothing makes
140
+ * possible in production — which is why the sameShape spec drives both sides from one
141
+ * non-decreasing fake clock rather than pretending the question does not exist.
142
+ *
143
+ * The store sweeps on every write, so the live set is also very nearly the whole table.
144
+ */
145
+ export async function createD1SessionRows(db, writes, options) {
146
+ const max = options.maxRows ?? SNAPSHOT_MAX_ROWS;
147
+ const rows = await snapshot(db, "sessions", `SELECT ${SESSION_COLUMNS} FROM sessions WHERE expires_at > ?`, [options.now], max);
148
+ const live = new Map();
149
+ for (const row of rows)
150
+ live.set(row.id, normalizeSessionRow(row));
151
+ return {
152
+ byId: (id) => live.get(id) ?? null,
153
+ forUser: (userId, liveAfter) => [...live.values()]
154
+ .filter((row) => row.user_id === userId && row.expires_at > liveAfter)
155
+ // The ORDER is part of the seam's contract — `SessionRows.forUser` says why.
156
+ // `bun:sqlite` gets it from `ORDER BY last_seen_at DESC, expires_at DESC`;
157
+ // here it is the same two keys, same direction, applied to the snapshot.
158
+ .sort((a, b) => b.last_seen_at - a.last_seen_at || b.expires_at - a.expires_at),
159
+ insert(row) {
160
+ live.set(row.id, row);
161
+ writes.add(db
162
+ .prepare(`INSERT INTO sessions (${SESSION_COLUMNS}) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`)
163
+ .bind(row.id, row.user_id, row.expires_at, row.user_agent, row.ip, row.created_at, row.last_seen_at, row.place)
164
+ .run());
165
+ },
166
+ touch(id, at) {
167
+ const row = live.get(id);
168
+ if (row)
169
+ live.set(id, { ...row, last_seen_at: at });
170
+ writes.add(db.prepare("UPDATE sessions SET last_seen_at = ? WHERE id = ?").bind(at, id).run());
171
+ },
172
+ deleteById(id) {
173
+ live.delete(id);
174
+ writes.add(db.prepare("DELETE FROM sessions WHERE id = ?").bind(id).run());
175
+ },
176
+ deleteByIdForUser(id, userId) {
177
+ // Scoped in the snapshot exactly as it is scoped in SQL: a handle that names
178
+ // somebody else's session must delete nothing on either side.
179
+ if (live.get(id)?.user_id === userId)
180
+ live.delete(id);
181
+ writes.add(db.prepare("DELETE FROM sessions WHERE id = ? AND user_id = ?").bind(id, userId).run());
182
+ },
183
+ deleteForUser(userId) {
184
+ for (const [id, row] of live)
185
+ if (row.user_id === userId)
186
+ live.delete(id);
187
+ writes.add(db.prepare("DELETE FROM sessions WHERE user_id = ?").bind(userId).run());
188
+ },
189
+ deleteOthersForUser(userId, keepId) {
190
+ for (const [id, row] of live)
191
+ if (row.user_id === userId && id !== keepId)
192
+ live.delete(id);
193
+ writes.add(db
194
+ .prepare("DELETE FROM sessions WHERE user_id = ? AND id != ?")
195
+ .bind(userId, keepId)
196
+ .run());
197
+ },
198
+ deleteExpired(at) {
199
+ for (const [id, row] of live)
200
+ if (row.expires_at <= at)
201
+ live.delete(id);
202
+ writes.add(db.prepare("DELETE FROM sessions WHERE expires_at <= ?").bind(at).run());
203
+ },
204
+ };
205
+ }
206
+ const SSO_USER_COLUMNS = "id, email, name, is_admin, is_owner, is_granted, last_login_at, created_at, updated_at";
207
+ /**
208
+ * The `sso_users` snapshot for one invocation. Pass the result as `users` to
209
+ * `createSsoConsumer`.
210
+ *
211
+ * The whole table, because it IS the household: one row per account that has ever signed
212
+ * in to this app. The consumer reads it by id for the request's own user and once per
213
+ * occupied account slot, so a snapshot costs one query where per-key reads would cost one
214
+ * per slot — up to `MAX_ACCOUNT_SLOTS` of them on the account switcher's own route.
215
+ */
216
+ export async function createD1SsoUserStore(db, writes, options) {
217
+ const max = options.maxRows ?? SNAPSHOT_MAX_ROWS;
218
+ const rows = await snapshot(db, "sso_users", `SELECT ${SSO_USER_COLUMNS} FROM sso_users`, [], max);
219
+ const users = new Map();
220
+ for (const row of rows)
221
+ users.set(row.id, normalizeSsoUserRow(row));
222
+ const sameAddress = (a, b) => a.toLowerCase() === b.toLowerCase();
223
+ return {
224
+ ensureSchema() {
225
+ // 🔴 Deliberately nothing. D1's schema is applied out of band by
226
+ // `wrangler d1 execute --file db/schema.sql` — paste `SSO_USERS_DDL` into it —
227
+ // and a per-invocation `CREATE TABLE IF NOT EXISTS` would spend the request's
228
+ // query budget on DDL that can only ever matter once. It is not a silent
229
+ // no-op: the snapshot above runs BEFORE any of this and D1 fails it by name if
230
+ // the table is absent, so a forgotten migration is a loud 500 on the first
231
+ // request rather than a door that refuses everybody.
232
+ },
233
+ byId: (id) => users.get(id) ?? null,
234
+ upsert(row) {
235
+ // The snapshot first, so the rest of THIS invocation sees the account it just
236
+ // wrote — the callback mints a session and reads the user back within one
237
+ // request.
238
+ for (const [id, existing] of users) {
239
+ if (id !== row.id && sameAddress(existing.email, row.email))
240
+ users.delete(id);
241
+ }
242
+ const previous = users.get(row.id);
243
+ users.set(row.id, {
244
+ ...row,
245
+ // `created_at` belongs to the row's first write. The SQL below says the same
246
+ // thing by leaving it out of the `DO UPDATE SET` list; saying it here too is
247
+ // what keeps the snapshot from disagreeing with what was durably stored.
248
+ created_at: previous?.created_at ?? row.created_at,
249
+ });
250
+ // 🔴 ONE batch, not two `add`s. The DELETE must land before the INSERT or the
251
+ // unique index on `lower(email)` refuses a legitimate re-issued account id —
252
+ // and a collector fires what it is given immediately, so two adds race. See
253
+ // `D1Handle.batch`.
254
+ writes.add(db.batch([
255
+ db
256
+ .prepare("DELETE FROM sso_users WHERE lower(email) = lower(?) AND id <> ?")
257
+ .bind(row.email, row.id),
258
+ db
259
+ .prepare(`INSERT INTO sso_users (${SSO_USER_COLUMNS})
260
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
261
+ ON CONFLICT(id) DO UPDATE SET
262
+ email = excluded.email, name = excluded.name, is_admin = excluded.is_admin,
263
+ is_owner = excluded.is_owner, is_granted = excluded.is_granted,
264
+ last_login_at = excluded.last_login_at, updated_at = excluded.updated_at`)
265
+ .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),
266
+ ]));
267
+ },
268
+ deleteById(id) {
269
+ users.delete(id);
270
+ writes.add(db.prepare("DELETE FROM sso_users WHERE id = ?").bind(id).run());
271
+ },
272
+ dropDuplicates() {
273
+ // Unreachable from `ensureSchema` here — a database that starts behind the unique
274
+ // index cannot grow a duplicate — but implemented rather than thrown, because a
275
+ // one-off import script that copies a Mac's table into D1 CAN, and a member that
276
+ // silently did nothing would be a repair somebody believed had run.
277
+ const keep = new Map();
278
+ for (const row of users.values()) {
279
+ const key = row.email.toLowerCase();
280
+ const winner = keep.get(key);
281
+ if (!winner ||
282
+ row.last_login_at > winner.last_login_at ||
283
+ (row.last_login_at === winner.last_login_at && row.updated_at > winner.updated_at)) {
284
+ keep.set(key, row);
285
+ }
286
+ }
287
+ const survivors = new Set([...keep.values()].map((row) => row.id));
288
+ for (const id of [...users.keys()])
289
+ if (!survivors.has(id))
290
+ users.delete(id);
291
+ writes.add(db
292
+ .prepare(`DELETE FROM sso_users WHERE rowid NOT IN (
293
+ SELECT rowid FROM (
294
+ SELECT rowid,
295
+ ROW_NUMBER() OVER (
296
+ PARTITION BY lower(email)
297
+ ORDER BY last_login_at DESC, updated_at DESC, rowid DESC
298
+ ) AS rn
299
+ FROM sso_users
300
+ ) WHERE rn = 1
301
+ )`)
302
+ .run());
303
+ },
304
+ };
305
+ }
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,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,oBAAoB,GACpB,MAAM,iBAAiB,CAAC;AAEzB;;;;;;;;;;;GAWG;AACH,OAAO,EACN,WAAW,EACX,uBAAuB,EACvB,oBAAoB,EACpB,iCAAiC,EACjC,kBAAkB,EAClB,gBAAgB,EAEhB,kBAAkB,GAGlB,MAAM,eAAe,CAAC"}
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,uBAAuB,EACvB,sBAAsB,EACtB,0BAA0B,EAC1B,YAAY,GAUZ,MAAM,gBAAgB,CAAC;AACxB;;;;;GAKG;AACH,OAAO,EACN,wBAAwB,EACxB,mBAAmB,EAEnB,aAAa,GAGb,MAAM,YAAY,CAAC;AACpB,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,oBAAoB,GACpB,MAAM,iBAAiB,CAAC;AAEzB;;;;;;;;;;;GAWG;AACH,OAAO,EACN,WAAW,EACX,uBAAuB,EACvB,oBAAoB,EACpB,iCAAiC,EACjC,kBAAkB,EAClB,gBAAgB,EAEhB,kBAAkB,GAGlB,MAAM,eAAe,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import type { Database } from "bun:sqlite";
2
2
  import type { Context, Hono, MiddlewareHandler } from "hono";
3
+ import { type SsoUserStore } from "./ssoUsers";
3
4
  import { type ContentCensus } from "./sso";
4
5
  import type { UserSessionStore } from "./userSessions";
5
6
  export declare const SSO_CALLBACK_PATH = "/api/auth/sso/callback";
@@ -142,9 +143,24 @@ export interface SsoConsumerOptions {
142
143
  * a credential gets redirected. */
143
144
  publicUrl: string;
144
145
  sessions: UserSessionStore;
145
- /** The app's own database — the `sso_users` snapshot lives here so app
146
- * tables can foreign-key the user id. */
147
- db: Database;
146
+ /**
147
+ * The app's own database — the `sso_users` snapshot lives here so app
148
+ * tables can foreign-key the user id.
149
+ *
150
+ * 🔴 Optional since 0.8.0, and still what every Bun-hosted app passes. Give
151
+ * {@link users} instead on a host with no synchronous database; exactly one of the
152
+ * two is required and passing neither throws at construction rather than at the
153
+ * first request. See `ssoUsers.ts` for why the seam is at the rows.
154
+ */
155
+ db?: Database;
156
+ /**
157
+ * The `sso_users` snapshot behind a seam, for a host that is not Bun.
158
+ *
159
+ * `cursedauth/d1-stores`' `createD1SsoUserStore` is the Cloudflare Workers
160
+ * implementation: one read per invocation, writes collected and awaited before the
161
+ * response leaves. Wins over {@link db} when both are given.
162
+ */
163
+ users?: SsoUserStore;
148
164
  /** Static verification key (SPKI PEM). Set → JWKS is never fetched. */
149
165
  publicKeyPem?: string;
150
166
  /**
@@ -290,6 +306,26 @@ export interface SsoConsumer {
290
306
  * app code that has no idea it is on a stage, and a scope string that changed shape
291
307
  * under the app would be a permissions bug wearing a stage costume.
292
308
  */
293
- export declare function resolveSsoAudience(appKey: string, authUrl: string, env?: NodeJS.ProcessEnv, registered?: readonly string[]): string;
309
+ export declare function resolveSsoAudience(appKey: string, authUrl: string, env?: NodeJS.ProcessEnv, registered?: readonly string[], publicUrl?: string): string;
310
+ /**
311
+ * 🔴 The HOSTED stage — `<app>-stage.<zone>` signing in at `auth-stage.<zone>` — which is
312
+ * `apps/auth` deployed a second time and mints grants for `<app>-stage` (its roster,
313
+ * `apps/auth/src/server/stageDoor.ts`). Added 2026-09-22, the day auth-stage stopped being a
314
+ * fork: until then only the LOCAL stage had a twin audience, and a hosted stage consumer asked
315
+ * for `<app>` and refused every grant the stage door minted — measured on `collections-stage`,
316
+ * *"grant is for "collections-stage", not "collections""*.
317
+ *
318
+ * Three conditions, all required, the same shape as the local branch and for the same reasons:
319
+ *
320
+ * 1. **this consumer's OWN origin is `<app>-stage.<zone>`** — a name in the fleet's zone that
321
+ * only a stage deploy creates. A production release cannot acquire it without the DNS record.
322
+ * 2. **the accounts door is `auth-stage.<zone>`, the same zone** — a stage origin talking to the
323
+ * REAL door keeps its real audience, so a stage can never mint itself production access.
324
+ * 3. **`<app>-stage` is registered** — an app that has not declared its stage twin keeps its own
325
+ * key and fails visibly at the roster rather than asking for an audience nobody knows.
326
+ *
327
+ * It moves the AUDIENCE only, exactly as the local branch does.
328
+ */
329
+ export declare function hostedStageAudience(appKey: string, authUrl: string, publicUrl: string, registered: readonly string[]): string | null;
294
330
  export declare function createSsoConsumer(options: SsoConsumerOptions): SsoConsumer;
295
331
  //# sourceMappingURL=ssoConsumer.server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ssoConsumer.server.d.ts","sourceRoot":"","sources":["../src/ssoConsumer.server.ts"],"names":[],"mappings":"AA+BA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAQ,MAAM,MAAM,CAAC;AAInE,OAAO,EAEN,KAAK,aAAa,EAUlB,MAAM,OAAO,CAAC;AASf,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,eAAO,MAAM,iBAAiB,2BAA2B,CAAC;AAC1D,eAAO,MAAM,cAAc,wBAAwB,CAAC;AACpD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,gBAAgB,0BAA0B,CAAC;AACxD;;;;GAIG;AACH,eAAO,MAAM,eAAe,yBAAyB,CAAC;AACtD;;;;;GAKG;AACH,eAAO,MAAM,eAAe,yBAAyB,CAAC;AACtD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,iBAAiB,2BAA2B,CAAC;AAC1D;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,eAAe,CAAC;AAK9C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,eAAe,aAAa,CAAC;AAI1C;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAoBhF;AAq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