@fuzdev/fuz_app 0.184.0 → 0.186.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/dist/actions/CLAUDE.md +18 -3
  2. package/dist/actions/perform_action.d.ts.map +1 -1
  3. package/dist/actions/perform_action.js +36 -5
  4. package/dist/actions/register_action_ws.d.ts +14 -7
  5. package/dist/actions/register_action_ws.d.ts.map +1 -1
  6. package/dist/actions/ws_socket_session.d.ts +17 -4
  7. package/dist/actions/ws_socket_session.d.ts.map +1 -1
  8. package/dist/actions/ws_socket_session.js +41 -7
  9. package/dist/auth/CLAUDE.md +18 -9
  10. package/dist/auth/account_queries.d.ts +53 -40
  11. package/dist/auth/account_queries.d.ts.map +1 -1
  12. package/dist/auth/account_queries.js +57 -50
  13. package/dist/auth/account_routes.d.ts.map +1 -1
  14. package/dist/auth/account_routes.js +59 -25
  15. package/dist/auth/admin_actions.d.ts.map +1 -1
  16. package/dist/auth/admin_actions.js +26 -9
  17. package/dist/auth/audit_emitter.js +2 -2
  18. package/dist/auth/audit_log_queries.d.ts +11 -3
  19. package/dist/auth/audit_log_queries.d.ts.map +1 -1
  20. package/dist/auth/audit_log_queries.js +4 -4
  21. package/dist/auth/audit_log_routes.d.ts +1 -1
  22. package/dist/auth/audit_log_routes.d.ts.map +1 -1
  23. package/dist/auth/audit_log_routes.js +3 -2
  24. package/dist/auth/audit_log_schema.js +1 -1
  25. package/dist/auth/auth_ddl.d.ts.map +1 -1
  26. package/dist/auth/auth_ddl.js +4 -0
  27. package/dist/auth/cleanup.d.ts +34 -3
  28. package/dist/auth/cleanup.d.ts.map +1 -1
  29. package/dist/auth/cleanup.js +12 -4
  30. package/dist/auth/migrations.d.ts.map +1 -1
  31. package/dist/auth/migrations.js +35 -0
  32. package/dist/auth/role_grant_offer_queries.d.ts +13 -13
  33. package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
  34. package/dist/auth/role_grant_offer_queries.js +12 -13
  35. package/dist/auth/role_grant_queries.d.ts +16 -9
  36. package/dist/auth/role_grant_queries.d.ts.map +1 -1
  37. package/dist/auth/role_grant_queries.js +16 -9
  38. package/dist/auth/self_service_role_actions.d.ts.map +1 -1
  39. package/dist/auth/self_service_role_actions.js +15 -0
  40. package/dist/auth/session_queries.d.ts +24 -0
  41. package/dist/auth/session_queries.d.ts.map +1 -1
  42. package/dist/auth/session_queries.js +28 -0
  43. package/dist/db/CLAUDE.md +3 -3
  44. package/dist/db/cell_ddl.d.ts +8 -3
  45. package/dist/db/cell_ddl.d.ts.map +1 -1
  46. package/dist/db/cell_ddl.js +10 -5
  47. package/dist/http/CLAUDE.md +1 -1
  48. package/dist/http/body_limit.d.ts +4 -4
  49. package/dist/http/body_limit.js +4 -4
  50. package/dist/http/pending_effects.d.ts +8 -4
  51. package/dist/http/pending_effects.d.ts.map +1 -1
  52. package/dist/http/route_spec.d.ts +3 -3
  53. package/dist/http/route_spec.d.ts.map +1 -1
  54. package/dist/realtime/audit_log_sse.d.ts +1 -1
  55. package/dist/realtime/sse.d.ts +2 -2
  56. package/dist/realtime/sse.d.ts.map +1 -1
  57. package/dist/realtime/sse_constants.d.ts +1 -1
  58. package/dist/realtime/sse_constants.js +1 -1
  59. package/dist/server/app_server.d.ts +59 -71
  60. package/dist/server/app_server.d.ts.map +1 -1
  61. package/dist/server/app_server.js +52 -60
  62. package/dist/server/shutdown_drain.d.ts +69 -0
  63. package/dist/server/shutdown_drain.d.ts.map +1 -0
  64. package/dist/server/shutdown_drain.js +77 -0
  65. package/dist/testing/CLAUDE.md +197 -66
  66. package/dist/testing/admin_integration.d.ts +2 -2
  67. package/dist/testing/admin_integration.d.ts.map +1 -1
  68. package/dist/testing/admin_integration.js +36 -20
  69. package/dist/testing/app_server.d.ts +5 -7
  70. package/dist/testing/app_server.d.ts.map +1 -1
  71. package/dist/testing/app_server.js +5 -7
  72. package/dist/testing/auth_apps.d.ts +3 -1
  73. package/dist/testing/auth_apps.d.ts.map +1 -1
  74. package/dist/testing/auth_apps.js +22 -5
  75. package/dist/testing/cross_backend/backend_config.d.ts +8 -0
  76. package/dist/testing/cross_backend/backend_config.d.ts.map +1 -1
  77. package/dist/testing/cross_backend/backend_log.d.ts +71 -0
  78. package/dist/testing/cross_backend/backend_log.d.ts.map +1 -0
  79. package/dist/testing/cross_backend/backend_log.js +134 -0
  80. package/dist/testing/cross_backend/backend_swap.d.ts +41 -0
  81. package/dist/testing/cross_backend/backend_swap.d.ts.map +1 -0
  82. package/dist/testing/cross_backend/backend_swap.js +431 -0
  83. package/dist/testing/cross_backend/body_size_smuggling.js +3 -3
  84. package/dist/testing/cross_backend/bootstrap_backend.d.ts +3 -1
  85. package/dist/testing/cross_backend/bootstrap_backend.d.ts.map +1 -1
  86. package/dist/testing/cross_backend/bootstrap_backend.js +9 -5
  87. package/dist/testing/cross_backend/conformance_case.d.ts +11 -6
  88. package/dist/testing/cross_backend/conformance_case.d.ts.map +1 -1
  89. package/dist/testing/cross_backend/conformance_case.js +4 -0
  90. package/dist/testing/cross_backend/conformance_principal.d.ts +2 -2
  91. package/dist/testing/cross_backend/conformance_principal.d.ts.map +1 -1
  92. package/dist/testing/cross_backend/conformance_principal.js +27 -10
  93. package/dist/testing/cross_backend/create_dual_spawn_global_setup.d.ts +10 -1
  94. package/dist/testing/cross_backend/create_dual_spawn_global_setup.d.ts.map +1 -1
  95. package/dist/testing/cross_backend/create_dual_spawn_global_setup.js +33 -7
  96. package/dist/testing/cross_backend/default_backend_configs.d.ts +38 -5
  97. package/dist/testing/cross_backend/default_backend_configs.d.ts.map +1 -1
  98. package/dist/testing/cross_backend/default_backend_configs.js +50 -15
  99. package/dist/testing/cross_backend/in_process_setup.d.ts +1 -1
  100. package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
  101. package/dist/testing/cross_backend/in_process_setup.js +53 -31
  102. package/dist/testing/cross_backend/revocation_drivers.d.ts +14 -2
  103. package/dist/testing/cross_backend/revocation_drivers.d.ts.map +1 -1
  104. package/dist/testing/cross_backend/revocation_drivers.js +36 -8
  105. package/dist/testing/cross_backend/rpc_success_fixtures.d.ts.map +1 -1
  106. package/dist/testing/cross_backend/rpc_success_fixtures.js +2 -1
  107. package/dist/testing/cross_backend/rust_spine_stub_backend_config.d.ts +7 -0
  108. package/dist/testing/cross_backend/rust_spine_stub_backend_config.d.ts.map +1 -1
  109. package/dist/testing/cross_backend/rust_spine_stub_backend_config.js +4 -2
  110. package/dist/testing/cross_backend/setup.d.ts +44 -43
  111. package/dist/testing/cross_backend/setup.d.ts.map +1 -1
  112. package/dist/testing/cross_backend/setup.js +64 -62
  113. package/dist/testing/cross_backend/spawn_backend.d.ts +19 -1
  114. package/dist/testing/cross_backend/spawn_backend.d.ts.map +1 -1
  115. package/dist/testing/cross_backend/spawn_backend.js +138 -11
  116. package/dist/testing/cross_backend/spine_suites.d.ts +17 -14
  117. package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
  118. package/dist/testing/cross_backend/spine_suites.js +37 -15
  119. package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
  120. package/dist/testing/cross_backend/sse_round_trip.js +4 -2
  121. package/dist/testing/cross_backend/standard.d.ts +18 -82
  122. package/dist/testing/cross_backend/standard.d.ts.map +1 -1
  123. package/dist/testing/cross_backend/standard.js +6 -21
  124. package/dist/testing/cross_backend/standard_auth.d.ts +74 -0
  125. package/dist/testing/cross_backend/standard_auth.d.ts.map +1 -0
  126. package/dist/testing/cross_backend/standard_auth.js +28 -0
  127. package/dist/testing/cross_backend/standard_bundle.d.ts +48 -0
  128. package/dist/testing/cross_backend/standard_bundle.d.ts.map +1 -0
  129. package/dist/testing/cross_backend/standard_bundle.js +43 -0
  130. package/dist/testing/cross_backend/testing_reset_actions.d.ts +18 -6
  131. package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
  132. package/dist/testing/cross_backend/testing_reset_actions.js +23 -8
  133. package/dist/testing/cross_backend/testing_server_bun.d.ts.map +1 -1
  134. package/dist/testing/cross_backend/testing_server_bun.js +7 -30
  135. package/dist/testing/cross_backend/testing_server_core.d.ts +16 -3
  136. package/dist/testing/cross_backend/testing_server_core.d.ts.map +1 -1
  137. package/dist/testing/cross_backend/testing_server_core.js +20 -4
  138. package/dist/testing/cross_backend/ts_spine_backend_config.d.ts +6 -2
  139. package/dist/testing/cross_backend/ts_spine_backend_config.d.ts.map +1 -1
  140. package/dist/testing/cross_backend/ts_spine_backend_config.js +7 -3
  141. package/dist/testing/cross_backend/ws_round_trip.d.ts.map +1 -1
  142. package/dist/testing/cross_backend/ws_round_trip.js +4 -3
  143. package/dist/testing/data_exposure.d.ts +4 -1
  144. package/dist/testing/data_exposure.d.ts.map +1 -1
  145. package/dist/testing/data_exposure.js +93 -25
  146. package/dist/testing/db_invariants.d.ts +5 -5
  147. package/dist/testing/db_invariants.js +5 -5
  148. package/dist/testing/error_coverage.d.ts +5 -0
  149. package/dist/testing/error_coverage.d.ts.map +1 -1
  150. package/dist/testing/error_coverage.js +2 -1
  151. package/dist/testing/integration.d.ts +4 -20
  152. package/dist/testing/integration.d.ts.map +1 -1
  153. package/dist/testing/integration.js +49 -79
  154. package/dist/testing/integration_helpers.d.ts +16 -0
  155. package/dist/testing/integration_helpers.d.ts.map +1 -1
  156. package/dist/testing/integration_helpers.js +29 -1
  157. package/dist/testing/logged_errors.d.ts +61 -0
  158. package/dist/testing/logged_errors.d.ts.map +1 -0
  159. package/dist/testing/logged_errors.js +285 -0
  160. package/dist/testing/middleware_gate_probes.d.ts +55 -1
  161. package/dist/testing/middleware_gate_probes.d.ts.map +1 -1
  162. package/dist/testing/middleware_gate_probes.js +76 -3
  163. package/dist/testing/rpc_attack_surface.d.ts.map +1 -1
  164. package/dist/testing/rpc_attack_surface.js +41 -16
  165. package/dist/testing/stubs.d.ts +5 -1
  166. package/dist/testing/stubs.d.ts.map +1 -1
  167. package/dist/testing/stubs.js +6 -3
  168. package/dist/testing/test_app.d.ts +39 -9
  169. package/dist/testing/test_app.d.ts.map +1 -1
  170. package/dist/testing/test_app.js +70 -12
  171. package/dist/testing/transports/fetch_transport.d.ts +10 -0
  172. package/dist/testing/transports/fetch_transport.d.ts.map +1 -1
  173. package/dist/testing/transports/fetch_transport.js +13 -0
  174. package/package.json +4 -3
@@ -12,7 +12,6 @@ import { to_admin_account } from './account_schema.js';
12
12
  import { ADMIN_ACCOUNT_LIST_DEFAULT_LIMIT } from './admin_action_specs.js';
13
13
  import { ROLE_GRANT_COLUMNS } from './role_grant_queries.js';
14
14
  import { offer_pending_predicate, role_grant_active_sql } from './role_grant_sql.js';
15
- import { ROLE_ADMIN } from './role_schema.js';
16
15
  /**
17
16
  * The full `account` column set, named explicitly so a row read fails loud
18
17
  * on schema drift.
@@ -147,15 +146,21 @@ export const query_account_by_username_or_email = async (deps, input) => {
147
146
  * Pass the same hash the verify ran against — typically
148
147
  * `ctx.account.password_hash` from the request context.
149
148
  *
149
+ * A tombstoned account matches nothing either: a delete can commit between
150
+ * the authorization and the UPDATE, and a waiting UPDATE rereads the row the
151
+ * delete committed, so the change never lands on a deleted account. Twin of
152
+ * the Rust `query_update_account_password`.
153
+ *
150
154
  * @returns `true` if the row was updated, `false` if `expected_hash` no
151
155
  * longer matched (concurrent change won — caller should treat as a
152
- * stale-credential failure).
156
+ * stale-credential failure) or the account is deleted.
153
157
  * @mutates `account` row - updates `password_hash`, `updated_at`, and
154
- * `updated_by` only when the stored hash equals `expected_hash`
158
+ * `updated_by` only when the account is live and its stored hash equals
159
+ * `expected_hash`
155
160
  */
156
161
  export const query_update_account_password = async (deps, id, password_hash, updated_by, expected_hash) => {
157
162
  const rows = await deps.db.query(`UPDATE account SET password_hash = $1, updated_at = NOW(), updated_by = $2
158
- WHERE id = $3 AND password_hash = $4
163
+ WHERE id = $3 AND password_hash = $4 AND deleted_at IS NULL
159
164
  RETURNING id`, [password_hash, updated_by ?? null, id, expected_hash]);
160
165
  return rows.length > 0;
161
166
  };
@@ -218,11 +223,15 @@ export const query_account_lock_verified = async (deps, id, password_hash) => {
218
223
  * cap — `query_account_lock_verified` has why, and what it conflicts with; a
219
224
  * token mint and a login of one account take turns too. A write that only
220
225
  * needs ordering against a delete takes `query_account_lock_live_many`, which
221
- * lets such writes run together. Twin of the Rust
226
+ * lets such writes run together. A delete takes it too, after its last-admin
227
+ * guard and before the guards' second pass (`account_delete` in
228
+ * `admin_actions.ts`): the guard reads whether the target is an admin
229
+ * unlocked. And `self_service_role_set` takes it first, so a toggle is refused
230
+ * on a removed account, or a removal waits for it. Twin of the Rust
222
231
  * `fuz_auth::query_account_lock_live`.
223
232
  *
224
- * @param deps - query dependencies (must be the mint's transaction)
225
- * @param id - the account the credential is for
233
+ * @param deps - query dependencies (must be the mint's, the delete's, or the toggle's transaction)
234
+ * @param id - the account the credential is for, or the account the delete removes
226
235
  * @returns `true` when the row is locked and not tombstoned, `false` when it was deleted or tombstoned
227
236
  */
228
237
  export const query_account_lock_live = async (deps, id) => {
@@ -230,42 +239,38 @@ export const query_account_lock_live = async (deps, id) => {
230
239
  return row !== undefined;
231
240
  };
232
241
  /**
233
- * Lock, for a purge, the account rows of every holder of an unrevoked global
234
- * `admin` grant and the purged account's own, in one statement, in id order,
235
- * `FOR NO KEY UPDATE`.
242
+ * The key of the advisory lock every purge takes
243
+ * (`query_account_purge_advisory_lock`): the ASCII of `fuz_` and `purg`.
236
244
  *
237
- * A purge's cascade writes rows of other accounts: it sets null the
238
- * `granted_by` and `revoked_by` of every grant the purged account's actors
239
- * named, admins' grants among them, in whatever order the plan walks them. A
240
- * last-admin guard of another removal takes admin accounts, actors and grants
241
- * in account-id order. A purge reaching an admin's grant before the guard does
242
- * and waiting on one the guard took could hold a row the guard waits on.
243
- * Holding every admin's account first, in the order the guard and
244
- * `query_account_lock_live_many` take account rows, another guard waits at its
245
- * first account holding nothing, and two purges take turns. The purged
246
- * account's row is taken in the same statement, so an offer create holding one
247
- * of these rows `FOR SHARE` and waiting on another meets them in the same order.
248
- * No `deleted_at` filter on either: a tombstoned admin's grant is written by
249
- * the cascade as well, and a purge removes a tombstoned account. The admins
250
- * are those the statement's snapshot sees; one made by a transaction that
251
- * commits after it starts is not among them. Cost: a purge waits behind
252
- * admins' logins, token creates and offers. Run first in the purge's
253
- * transaction, before the last-admin guard (an admin target's only) and
254
- * `query_account_lock_for_purge`.
255
- * Twin of the Rust `fuz_auth::account_queries::query_account_lock_admins_for_purge`.
245
+ * The two-`int4` form, `pg_advisory_xact_lock(int4, int4)`, a key space apart
246
+ * from the single-key form the migration runner's per-namespace
247
+ * `pg_advisory_lock(int4)` takes, so no namespace's hash can collide with it.
248
+ * Twin of the Rust `fuz_auth::account_queries::ACCOUNT_PURGE_ADVISORY_LOCK_KEY`.
249
+ */
250
+ export const ACCOUNT_PURGE_ADVISORY_LOCK_KEY = [
251
+ 0x6675_7a5f, 0x7075_7267
252
+ ];
253
+ /**
254
+ * Take, for a purge, the transaction-scoped advisory lock every purge takes,
255
+ * so two purges take turns.
256
+ *
257
+ * Two purges' cascades write rows both reach — the offers each account made to
258
+ * the other, accepted and declined as well as pending, and the invites each
259
+ * issued and the other claimed — in whatever order their plans walk them, and
260
+ * no row lock a purge takes ahead of its cascade covers every such row. Held
261
+ * from the purge's first statement, the lock makes a second purge wait before
262
+ * it holds any row. Only purges take it, and a purge takes it holding nothing,
263
+ * so it orders purges against each other and nothing else: every other writer
264
+ * meets a purge at the rows it locks after this — the last-admin guard's (an
265
+ * admin target's only), its account row (`query_account_lock_for_purge`), its
266
+ * offers. Released when the transaction ends. Run first in the purge's
267
+ * transaction. Twin of the Rust
268
+ * `fuz_auth::account_queries::query_account_purge_advisory_lock`.
256
269
  *
257
270
  * @param deps - query dependencies (must be the purge's transaction)
258
- * @param id - the account to purge
259
271
  */
260
- export const query_account_lock_admins_for_purge = async (deps, id) => {
261
- await deps.db.query(`SELECT a.id FROM account a
262
- WHERE a.id = $1
263
- OR a.id IN (
264
- SELECT act.account_id FROM actor act
265
- JOIN role_grant rg ON rg.actor_id = act.id
266
- WHERE rg.role = $2 AND rg.scope_id IS NULL AND rg.revoked_at IS NULL)
267
- ORDER BY a.id
268
- FOR NO KEY UPDATE`, [id, ROLE_ADMIN]);
272
+ export const query_account_purge_advisory_lock = async (deps) => {
273
+ await deps.db.query('SELECT pg_advisory_xact_lock($1, $2)', [...ACCOUNT_PURGE_ADVISORY_LOCK_KEY]);
269
274
  };
270
275
  /**
271
276
  * Lock the account row of a revoke's revokee, by its actor, tombstoned or not,
@@ -306,10 +311,13 @@ export const query_account_lock_for_revoke = async (deps, actor_id) => {
306
311
  * takes anyway: it conflicts with every other lock on the row, so a writer
307
312
  * holding one is waited out, and a writer arriving later waits for the purge
308
313
  * and then finds no row. No `deleted_at` filter — a purge removes a tombstoned
309
- * account too. Run after `query_account_lock_admins_for_purge`, which takes the
310
- * row `FOR NO KEY UPDATE` among every admin's in id order, and, for an admin
311
- * target, the last-admin guard, so this only strengthens a lock the purge
312
- * already holds. Twin of the Rust
314
+ * account too. Run after `query_account_purge_advisory_lock` and, for an admin
315
+ * target, the last-admin guard, which takes the row `FOR NO KEY UPDATE` among
316
+ * every admin's in id order, so for an admin this only strengthens a lock the
317
+ * purge already holds. The guards run again after it: they read whether the
318
+ * target is an admin unlocked, and a non-admin target's row is the first the
319
+ * purge holds of it, so an accept making it an admin commits before this lock
320
+ * is granted. Twin of the Rust
313
321
  * `fuz_auth::account_queries::query_account_lock_for_purge`.
314
322
  *
315
323
  * @param deps - query dependencies (must be the purge's transaction)
@@ -365,7 +373,7 @@ export const query_account_lock_live_many = async (deps, ids) => {
365
373
  * by one recipient take turns, and the second claims after the first has
366
374
  * superseded its siblings. It conflicts with a delete's or a purge's first
367
375
  * write of the account (the soft-delete `UPDATE`,
368
- * `query_account_lock_admins_for_purge`, the last-admin guard), so a removal of
376
+ * `query_account_lock_for_purge`, the last-admin guard), so a removal of
369
377
  * the recipient waits here or is waited for whole, and never meets the accept
370
378
  * at its offers or its actor; with a revoke's `query_account_lock_for_revoke`,
371
379
  * so a revoke of the recipient's grant and the accept take turns; and with
@@ -377,12 +385,11 @@ export const query_account_lock_live_many = async (deps, ids) => {
377
385
  * unlocked read after this one): every write that ends a grantor's global
378
386
  * `admin` takes the grantor's account row first — a revoke of the grant through
379
387
  * `query_account_lock_for_revoke` (whether or not its last-admin guard ran), a
380
- * delete through its write of the row, a purge through
381
- * `query_account_lock_admins_for_purge` and `query_account_lock_for_purge` — so
382
- * it either commits before the read, which sees it, or waits for the accept to
383
- * commit. A share lock on the account,
384
- * not on the grant, so a purge's cascade reaching the grant (its `granted_by`
385
- * naming an actor of the purged account) never waits on the accept.
388
+ * delete through its write of the row, a purge through the last-admin guard
389
+ * and `query_account_lock_for_purge` — so it either commits before the read,
390
+ * which sees it, or waits for the accept to commit. A share lock on the
391
+ * account, not on the grant: every removal takes the account first, so it
392
+ * waits there holding nothing the accept needs.
386
393
  *
387
394
  * Two statements, as the two strengths can't share one locking clause, the
388
395
  * lower id first — the order the last-admin guard
@@ -1 +1 @@
1
- {"version":3,"file":"account_routes.d.ts","sourceRoot":"","sources":["../../src/lib/auth/account_routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AA2BH,OAAO,EAAwB,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAK7E,OAAO,EAAoB,KAAK,WAAW,EAA6B,MAAM,oBAAoB,CAAC;AACnG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAclD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,gCAAgC,GAAI,UAAU,oBAAoB,KAAG,SAiFjF,CAAC;AAEF,iDAAiD;AACjD,MAAM,WAAW,oBAAoB;IACpC,yDAAyD;IACzD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,8FAA8F;IAC9F,gBAAgB,CAAC,EAAE;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC;CAC1C;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,2BAA2B,M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CAAC;IACd,8FAA8F;IAC9F,gBAAgB,CAAC,EAAE;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC;CAC1C;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,2BAA2B,MAAM,CAAC;AAE/C;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B,KAAK,CAAC;AAE/C;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,uBAAuB;IACvC,mBAAmB,EAAE,MAAM,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,mBAAoB,SAAQ,uBAAuB;IACnE;;;;;;;OAOG;IACH,qBAAqB,EAAE,WAAW,GAAG,IAAI,CAAC;IAC1C,4FAA4F;IAC5F,0BAA0B,EAAE,WAAW,GAAG,IAAI,CAAC;IAC/C,2FAA2F;IAC3F,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;;;;OAOG;IACH,gBAAgB,CAAC,EAAE;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC;CAC1C;AAID;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,0BAA0B,GACtC,MAAM,gBAAgB,EACtB,SAAS,mBAAmB,KAC1B,KAAK,CAAC,SAAS,CA4ZjB,CAAC"}
@@ -22,8 +22,8 @@
22
22
  import { format_session_clear_cookie, sign_session_cookie } from './session_cookie.js';
23
23
  import { RoleGrantSummaryJson, to_session_account } from './account_schema.js';
24
24
  import { account_status_route_shape, create_account_route_shapes, DEFAULT_MAX_SESSIONS } from './account_route_schema.js';
25
- import { create_capped_session, query_session_revoke_all_for_account, query_session_revoke_by_hash_unscoped } from './session_queries.js';
26
- import { query_account_by_id, query_account_by_username_or_email, query_account_lock_verified, query_update_account_password } from './account_queries.js';
25
+ import { create_capped_session, query_session_is_live, query_session_live_password_hash, query_session_revoke_all_for_account, query_session_revoke_by_hash_unscoped } from './session_queries.js';
26
+ import { query_account_by_id, query_account_by_username_or_email, query_account_lock_live, query_account_lock_verified, query_update_account_password } from './account_queries.js';
27
27
  import { query_revoke_all_api_tokens_for_account } from './api_token_queries.js';
28
28
  import { build_request_context, get_public_account, resolve_acting_actor } from './request_context.js';
29
29
  import { resolved_auth_session_hash } from './resolved_auth.js';
@@ -398,7 +398,40 @@ export const create_account_route_specs = (deps, options) => {
398
398
  });
399
399
  }
400
400
  account_reservation = account_reserved.reservation;
401
- const valid = await password.verify_password(current_password, ctx.account.password_hash);
401
+ // Lost to a concurrent change, a delete or a purge: the caller's
402
+ // `current_password` may have been right when the request was
403
+ // authorized, so the row says so rather than "user typoed".
404
+ // Sessions and tokens were already revoked by the winner; no
405
+ // cookie clear here either.
406
+ const lost_race = async () => {
407
+ ip_reserved.reservation.record();
408
+ account_reservation?.record();
409
+ await deps.audit.emit(route, {
410
+ event_type: 'password_change',
411
+ outcome: 'failure',
412
+ account_id: ctx.account.id,
413
+ ip: route.client_ip,
414
+ metadata: { reason: 'concurrent_change', credential_type }
415
+ });
416
+ return route_fail(REST_INVALID_CREDENTIALS);
417
+ };
418
+ // the shape admits only a session credential, so this is its hash
419
+ // (the Rust `account_password` reads the same value)
420
+ const change_session_hash = resolved_auth_session_hash(route.credential);
421
+ if (change_session_hash === null) {
422
+ // a 500 with nothing changed, as the Rust handler answers
423
+ throw new Error('password: the session gate admitted a caller with no session hash');
424
+ }
425
+ // The hash to verify against, read through the session that
426
+ // authorized the request: a change committed since the credential
427
+ // leg revoked it, so a dead session has no hash to verify — the
428
+ // race was lost before the verify — and a live one names the hash
429
+ // the session was resolved under, never a later change's. Twin of
430
+ // the Rust spine's read at the same step.
431
+ const verified_hash = await query_session_live_password_hash(route, change_session_hash, ctx.account.id);
432
+ if (verified_hash === undefined)
433
+ return await lost_race();
434
+ const valid = await password.verify_password(current_password, verified_hash);
402
435
  if (!valid) {
403
436
  ip_reserved.reservation.record();
404
437
  account_reservation?.record();
@@ -418,7 +451,7 @@ export const create_account_route_specs = (deps, options) => {
418
451
  const new_hash = await password.hash_password(new_password);
419
452
  // Conditional UPDATE keyed on the verified hash: closes the
420
453
  // verify-write race with a concurrent password change that
421
- // already committed against the same starting hash. Account-grain
454
+ // commits after the hash was read. Account-grain
422
455
  // operation — `updated_by` stays null (the per-request actor is
423
456
  // incidental; password is account-level state).
424
457
  //
@@ -429,9 +462,23 @@ export const create_account_route_specs = (deps, options) => {
429
462
  // Argon2 verify and hash held no connection). Twin of the Rust
430
463
  // spine's `change_password`. The audit row is written last, so a
431
464
  // refused row changes no password and revokes nothing. `null` when
432
- // the UPDATE matched nothing — a concurrent change committed first.
465
+ // the account or the session died since the hash read, or the
466
+ // UPDATE matched nothing — a concurrent change committed first.
433
467
  const change = await transaction_with_post_commit_rollback(route, async (tx_ctx) => {
434
- const updated = await query_update_account_password(tx_ctx, ctx.account.id, new_hash, null, ctx.account.password_hash);
468
+ // The account row first, then the session again under it. The
469
+ // session died between the hash read and here when a delete
470
+ // (an undelete since makes the row live again, with the
471
+ // verified hash) or a logout or a session revoke committed —
472
+ // before the lock was granted, so this read sees it. A change
473
+ // by a revoked session would otherwise land. A logout or a
474
+ // session revoke takes no account row: one after this read
475
+ // meets the revoke-all at the session row, which ends that
476
+ // session with the rest. The same pair the token mint takes.
477
+ if (!(await query_account_lock_live(tx_ctx, ctx.account.id)) ||
478
+ !(await query_session_is_live(tx_ctx, change_session_hash, ctx.account.id))) {
479
+ return null;
480
+ }
481
+ const updated = await query_update_account_password(tx_ctx, ctx.account.id, new_hash, null, verified_hash);
435
482
  if (!updated)
436
483
  return null;
437
484
  // revoke all sessions and API tokens (force re-auth everywhere)
@@ -463,25 +510,12 @@ export const create_account_route_specs = (deps, options) => {
463
510
  // rather than netting out, which is the intent.
464
511
  if (login_account_rate_limiter)
465
512
  login_account_rate_limiter.reset(ctx.account.id);
466
- if (!change) {
467
- // A concurrent password change committed first — our
468
- // `current_password` was correct at read-time but the row's
469
- // `password_hash` no longer matches. Mirrors the wrong-password
470
- // 401 shape; tag the failure metadata so admins reading the
471
- // audit log can distinguish "user typoed" from "two clients
472
- // raced." Sessions/tokens were already revoked by the winner;
473
- // no cookie clear here either.
474
- ip_reserved.reservation.record();
475
- account_reservation?.record();
476
- await deps.audit.emit(route, {
477
- event_type: 'password_change',
478
- outcome: 'failure',
479
- account_id: ctx.account.id,
480
- ip: route.client_ip,
481
- metadata: { reason: 'concurrent_change', credential_type }
482
- });
483
- return route_fail(REST_INVALID_CREDENTIALS);
484
- }
513
+ // A concurrent password change committed after the hash was read —
514
+ // our `current_password` was correct then, but the row's
515
+ // `password_hash` no longer matches — or a delete or a purge did,
516
+ // and the row is a tombstone or gone.
517
+ if (!change)
518
+ return await lost_race();
485
519
  const { sessions_revoked, tokens_revoked } = change;
486
520
  // Close every live connection of this account now the password
487
521
  // update, the revoke-all cascade, and its audit row have committed
@@ -1 +1 @@
1
- {"version":3,"file":"admin_actions.d.ts","sourceRoot":"","sources":["../../src/lib/auth/admin_actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAuC,KAAK,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAIjG,OAAO,EAKN,KAAK,YAAY,EACjB,MAAM,kBAAkB,CAAC;AA0D1B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AA0D3D,0CAA0C;AAC1C,MAAM,WAAW,kBAAkB;IAClC;;;;;OAKG;IACH,KAAK,CAAC,EAAE,YAAY,CAAC;CACrB;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,oBAAoB,GAChC,MAAM,yBAAyB,EAC/B,UAAS,kBAAuB,KAC9B,KAAK,CAAC,SAAS,CAupBjB,CAAC"}
1
+ {"version":3,"file":"admin_actions.d.ts","sourceRoot":"","sources":["../../src/lib/auth/admin_actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAuC,KAAK,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAIjG,OAAO,EAKN,KAAK,YAAY,EACjB,MAAM,kBAAkB,CAAC;AA2D1B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AA0D3D,0CAA0C;AAC1C,MAAM,WAAW,kBAAkB;IAClC;;;;;OAKG;IACH,KAAK,CAAC,EAAE,YAAY,CAAC;CACrB;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,oBAAoB,GAChC,MAAM,yBAAyB,EAC/B,UAAS,kBAAuB,KAC9B,KAAK,CAAC,SAAS,CAwqBjB,CAAC"}
@@ -39,7 +39,7 @@ import { GRANT_PATH_ADMIN } from './grant_path_schema.js';
39
39
  import { query_role_grant_offer_lock_for_account_removal, query_role_grant_offer_supersede_incoming, query_role_grant_offer_supersede_outgoing } from './role_grant_offer_queries.js';
40
40
  import { emit_supersede_audits } from './role_grant_offer_actions.js';
41
41
  import { queue_supersede_notifications } from './role_grant_offer_notifications.js';
42
- import { query_account_by_email, query_account_by_id, query_account_by_username, query_account_lock_admins_for_purge, query_account_lock_for_purge, query_account_soft_delete, query_account_undelete, query_actor_soft_delete, query_actor_undelete, query_actors_by_account, query_admin_account_list, query_purge_account } from './account_queries.js';
42
+ import { query_account_by_email, query_account_by_id, query_account_by_username, query_account_purge_advisory_lock, query_account_lock_for_purge, query_account_lock_live, query_account_soft_delete, query_account_undelete, query_actor_soft_delete, query_actor_undelete, query_actors_by_account, query_admin_account_list, query_purge_account } from './account_queries.js';
43
43
  import { query_session_list_all_active, query_session_revoke_all_for_account } from './session_queries.js';
44
44
  import { query_revoke_all_api_tokens_for_account } from './api_token_queries.js';
45
45
  import { query_audit_log_list_role_grant_history, query_audit_log_list_with_usernames } from './audit_log_queries.js';
@@ -367,6 +367,14 @@ export const create_admin_actions = (deps, options = {}) => {
367
367
  }
368
368
  // Keeper + last-admin guards (fail-loud, before the tombstone).
369
369
  await assert_account_removable(ctx, target_account_id, 'account_delete');
370
+ // The target's row, then the guards again under it — as a purge does
371
+ // (`account_purge_handler` has why): the guard's read of whether the
372
+ // target is an admin took no lock, and an accept making it one can commit
373
+ // before the tombstone takes the row. A row already gone or tombstoned
374
+ // skips the second pass; the tombstone then finds nothing.
375
+ if (await query_account_lock_live(ctx, target_account_id)) {
376
+ await assert_account_removable(ctx, target_account_id, 'account_delete');
377
+ }
370
378
  // Snapshot actor names before the tombstone.
371
379
  const actors = await query_actors_by_account(ctx, target_account_id);
372
380
  const snapshot = await query_account_soft_delete(ctx, target_account_id, auth.actor.id);
@@ -436,14 +444,11 @@ export const create_admin_actions = (deps, options = {}) => {
436
444
  reason: ERROR_PURGE_NOT_CONFIRMED
437
445
  });
438
446
  }
439
- // Every admin's account row and the target's, in one id-ordered statement:
440
- // the cascade writes admin rows (the grants the target's actors granted).
441
- // Every other removal's guard and every other purge take those accounts
442
- // first, and no other writer of an admin's grant waits on an account row
443
- // while holding one, so holding the accounts orders the purge before any of
444
- // them (`query_account_lock_admins_for_purge` has why). The last-admin guard
445
- // then runs only for an admin target, in `assert_account_removable`.
446
- await query_account_lock_admins_for_purge(ctx, input.account_id);
447
+ // The purge lock first, holding nothing: two purges' cascades cross at
448
+ // rows no row lock ahead of them covers, so purges take turns
449
+ // (`query_account_purge_advisory_lock` has why). The last-admin guard then
450
+ // runs only for an admin target, in `assert_account_removable`.
451
+ await query_account_purge_advisory_lock(ctx);
447
452
  // Keeper + last-admin guards (fail-loud, before the cascade).
448
453
  await assert_account_removable(ctx, input.account_id, 'account_purge');
449
454
  const refuse_not_found = async () => {
@@ -461,6 +466,18 @@ export const create_admin_actions = (deps, options = {}) => {
461
466
  // it — `query_account_lock_for_purge` has why.
462
467
  if (!(await query_account_lock_for_purge(ctx, input.account_id)))
463
468
  await refuse_not_found();
469
+ // The guards again, under the row lock. The first read of whether the
470
+ // target is an admin took no lock, and a purge holds no row of a
471
+ // non-admin target before its own: an accept making it an admin, in
472
+ // flight then, has committed by now (it holds the row this lock waited
473
+ // on), and a revoke the accept's grant let pass may have ended every
474
+ // other admin. For a target that was an admin, this count re-locks the
475
+ // rows the first one holds; it reaches past them only for an admin made
476
+ // in the window, the target or another — out of the guards' id order. A
477
+ // deadlock error then rolls one of the two transactions back whole,
478
+ // removing nothing: this purge, or the other, which may be a removal
479
+ // that would have committed (it answers 500).
480
+ await assert_account_removable(ctx, input.account_id, 'account_purge');
464
481
  // Snapshot actors before the cascade removes them.
465
482
  const actors = await query_actors_by_account(ctx, input.account_id);
466
483
  // Before the cascade, whose `ON DELETE CASCADE` would take the offers
@@ -223,7 +223,7 @@ export const create_audit_emitter = (options) => {
223
223
  // the whole row, and resolves `null`, so there is no row to announce.
224
224
  const write = async (input) => {
225
225
  try {
226
- return await query_audit_log({ db }, input, audit_log_config);
226
+ return await query_audit_log({ db, log }, input, audit_log_config);
227
227
  }
228
228
  catch (err) {
229
229
  audit_write_failures++;
@@ -282,7 +282,7 @@ export const create_audit_emitter = (options) => {
282
282
  // Written in the request's transaction, so it commits or rolls back
283
283
  // with the change it reports; a throw here fails the handler. The
284
284
  // fan-out waits for the commit and is discarded on rollback.
285
- const event = await query_audit_log({ db: ctx.db }, input, audit_log_config);
285
+ const event = await query_audit_log({ db: ctx.db, log }, input, audit_log_config);
286
286
  emit_after_commit(ctx, () => notify(event));
287
287
  };
288
288
  // The decorated `emit` is what `emit_role_grant_target` captures below
@@ -1,3 +1,4 @@
1
+ import type { Logger } from '@fuzdev/fuz_util/log.ts';
1
2
  import type { QueryDeps } from '../db/query_deps.js';
2
3
  import { type AuditLogConfig, type AuditLogEvent, type AuditLogInput, type AuditLogListOptions, type AuditLogEventWithUsernamesJson, type RoleGrantHistoryEventJson } from './audit_log_schema.js';
3
4
  /**
@@ -25,13 +26,20 @@ export declare const reset_audit_metadata_validation_failures: () => void;
25
26
  export declare const get_audit_unknown_event_type_failures: () => number;
26
27
  /** Reset the counter — for tests only. */
27
28
  export declare const reset_audit_unknown_event_type_failures: () => void;
29
+ /**
30
+ * Deps for `query_audit_log`, which logs the drift it counts (an unknown
31
+ * `event_type`, a metadata mismatch) on `log`.
32
+ */
33
+ export interface AuditLogQueryDeps extends QueryDeps {
34
+ log: Logger;
35
+ }
28
36
  /**
29
37
  * Insert an audit log entry.
30
38
  *
31
39
  * Returns the full row (`AUDIT_LOG_COLUMNS`) so callers receive DB-assigned
32
40
  * fields (`id`, `seq`, `created_at`). Validates `metadata` against
33
41
  * `config.metadata_schemas`; unknown `event_type` and metadata mismatches
34
- * log + bump their counters
42
+ * log an error on `deps.log` and bump their counters
35
43
  * but write the row anyway. Consumers extend the recognized set via
36
44
  * `create_audit_log_config({extra_events})`.
37
45
  *
@@ -40,14 +48,14 @@ export declare const reset_audit_unknown_event_type_failures: () => void;
40
48
  * reach for `AppDeps.audit.emit` instead, which picks the transaction or the
41
49
  * pool by outcome.
42
50
  *
43
- * @param deps - query dependencies
51
+ * @param deps - query dependencies and the logger the drift is reported on
44
52
  * @param input - the audit event to record
45
53
  * @param config - audit-log config. Defaults to `builtin_audit_log_config`.
46
54
  * @returns the inserted audit log row
47
55
  * @mutates `audit_log` table - inserts the new row
48
56
  * @mutates drift counters - bumps `audit_unknown_event_type_failures` and/or `audit_metadata_validation_failures` on mismatch
49
57
  */
50
- export declare const query_audit_log: <T extends string>(deps: QueryDeps, input: AuditLogInput<T>, config?: AuditLogConfig) => Promise<AuditLogEvent>;
58
+ export declare const query_audit_log: <T extends string>(deps: AuditLogQueryDeps, input: AuditLogInput<T>, config?: AuditLogConfig) => Promise<AuditLogEvent>;
51
59
  /**
52
60
  * List audit log entries, newest first.
53
61
  *
@@ -1 +1 @@
1
- {"version":3,"file":"audit_log_queries.d.ts","sourceRoot":"","sources":["../../src/lib/auth/audit_log_queries.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,EAGN,KAAK,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B,OAAO,CAAC,KAAK,CAAC,8BAA8B,CAAC,CA4D/C,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,uCAAuC,GACnD,MAAM,SAAS,EACf,cAA+B,EAC/B,eAAU,KACR,OAAO,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAmB1C,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,8BAA8B,GAC1C,MAAM,SAAS,EACf,QAAQ,IAAI,KACV,OAAO,CAAC,MAAM,CAMhB,CAAC"}
@@ -81,7 +81,7 @@ export const reset_audit_unknown_event_type_failures = () => {
81
81
  * Returns the full row (`AUDIT_LOG_COLUMNS`) so callers receive DB-assigned
82
82
  * fields (`id`, `seq`, `created_at`). Validates `metadata` against
83
83
  * `config.metadata_schemas`; unknown `event_type` and metadata mismatches
84
- * log + bump their counters
84
+ * log an error on `deps.log` and bump their counters
85
85
  * but write the row anyway. Consumers extend the recognized set via
86
86
  * `create_audit_log_config({extra_events})`.
87
87
  *
@@ -90,7 +90,7 @@ export const reset_audit_unknown_event_type_failures = () => {
90
90
  * reach for `AppDeps.audit.emit` instead, which picks the transaction or the
91
91
  * pool by outcome.
92
92
  *
93
- * @param deps - query dependencies
93
+ * @param deps - query dependencies and the logger the drift is reported on
94
94
  * @param input - the audit event to record
95
95
  * @param config - audit-log config. Defaults to `builtin_audit_log_config`.
96
96
  * @returns the inserted audit log row
@@ -100,7 +100,7 @@ export const reset_audit_unknown_event_type_failures = () => {
100
100
  export const query_audit_log = async (deps, input, config = builtin_audit_log_config) => {
101
101
  if (!config.event_types.includes(input.event_type)) {
102
102
  audit_unknown_event_type_failures++;
103
- console.error(`[audit_log] unknown event_type '${input.event_type}' — register via create_audit_log_config({extra_events})`);
103
+ deps.log.error(`[audit_log] unknown event_type '${input.event_type}' — register via create_audit_log_config({extra_events})`);
104
104
  }
105
105
  if (input.metadata != null) {
106
106
  const schema = config.metadata_schemas[input.event_type];
@@ -108,7 +108,7 @@ export const query_audit_log = async (deps, input, config = builtin_audit_log_co
108
108
  const result = parse(schema, input.metadata);
109
109
  if (!result.ok) {
110
110
  audit_metadata_validation_failures++;
111
- console.error(`[audit_log] metadata mismatch for '${input.event_type}':`, result.issues);
111
+ deps.log.error(`[audit_log] metadata mismatch for '${input.event_type}':`, result.issues);
112
112
  }
113
113
  }
114
114
  }
@@ -31,7 +31,7 @@ export interface AuditLogRouteOptions {
31
31
  registry: SseRegistry<SseNotification>;
32
32
  log: Logger;
33
33
  /**
34
- * Each stream's keep-alive interval (`SseResponseOptions.keep_alive_ms`)
34
+ * Each stream's keep-alive interval (`SseStreamOptions.keep_alive_ms`)
35
35
  * — a test server shortens it. Validated here, at route creation.
36
36
  *
37
37
  * @default SSE_KEEP_ALIVE_INTERVAL_MS
@@ -1 +1 @@
1
- {"version":3,"file":"audit_log_routes.d.ts","sourceRoot":"","sources":["../../src/lib/auth/audit_log_routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAGtD,OAAO,EAAwB,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAU7E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAS/D,yCAAyC;AACzC,MAAM,WAAW,oBAAoB;IACpC,+DAA+D;IAC/D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE;QACR,QAAQ,EAAE,WAAW,CAAC,eAAe,CAAC,CAAC;QACvC,GAAG,EAAE,MAAM,CAAC;QACZ;;;;;WAKG;QACH,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KAC9B,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,4BAA4B,GAAI,UAAU,oBAAoB,KAAG,KAAK,CAAC,SAAS,CA6H5F,CAAC"}
1
+ {"version":3,"file":"audit_log_routes.d.ts","sourceRoot":"","sources":["../../src/lib/auth/audit_log_routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAGtD,OAAO,EAAwB,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAU7E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAS/D,yCAAyC;AACzC,MAAM,WAAW,oBAAoB;IACpC,+DAA+D;IAC/D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE;QACR,QAAQ,EAAE,WAAW,CAAC,eAAe,CAAC,CAAC;QACvC,GAAG,EAAE,MAAM,CAAC;QACZ;;;;;WAKG;QACH,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KAC9B,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,4BAA4B,GAAI,UAAU,oBAAoB,KAAG,KAAK,CAAC,SAAS,CA8H5F,CAAC"}
@@ -141,8 +141,9 @@ export const create_audit_log_route_specs = (options) => {
141
141
  }
142
142
  };
143
143
  const refusal = await reread().catch((error) => {
144
- // the shutdown closed the registration and then the database
145
- // under the re-read: the answer is the shutdown's — admission
144
+ // a shutdown that gave up on this request at its drain bound may
145
+ // have closed the database under the re-read: the answer is the
146
+ // shutdown's — admission
146
147
  // below refuses, since a closing registry admits nothing —
147
148
  // not a failure
148
149
  if (registry.closing) {
@@ -217,7 +217,7 @@ export const audit_metadata_schemas = Object.freeze({
217
217
  description: 'Number of API tokens revoked as a side effect of the password change. Present on `outcome=success`.'
218
218
  }),
219
219
  reason: meta(optional(literal('concurrent_change')), {
220
- description: 'Failure category. `concurrent_change` indicates another password change committed first against the same starting hash (verify-write race loser). Absent for typed-wrong-password failures.'
220
+ description: 'Failure category. `concurrent_change` indicates the conditional write matched nothing: another password change committed first against the same starting hash, or a delete tombstoned the account (verify-write race loser). Absent for typed-wrong-password failures.'
221
221
  }),
222
222
  credential_type: credential_type_meta
223
223
  })),
@@ -1 +1 @@
1
- {"version":3,"file":"auth_ddl.d.ts","sourceRoot":"","sources":["../../src/lib/auth/auth_ddl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAMH,eAAO,MAAM,cAAc,6ZAazB,CAAC;AAEH,eAAO,MAAM,YAAY,0ZAUvB,CAAC;AAEH,eAAO,MAAM,WAAW,wEAC0C,CAAC;AAEnE;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,8FACqD,CAAC;AAEzF,eAAO,MAAM,iBAAiB,2ZAU5B,CAAC;AAEH,eAAO,MAAM,kBAAkB,UAI9B,CAAC;AAKF,eAAO,MAAM,mBAAmB,0RAO9B,CAAC;AAEH,eAAO,MAAM,oBAAoB,UAGhC,CAAC;AAEF,eAAO,MAAM,gBAAgB,iUAU3B,CAAC;AAEH,eAAO,MAAM,mBAAmB,4GACsE,CAAC;AAEvG,eAAO,MAAM,yBAAyB,6FACiD,CAAC;AAExF,eAAO,MAAM,eAAe,gFAC8C,CAAC;AAE3E,eAAO,MAAM,qBAAqB,wJAIhC,CAAC;AAEH,6FAA6F;AAC7F,eAAO,MAAM,mBAAmB,yHAGP,CAAC;AAE1B,eAAO,MAAM,aAAa,6ZAUxB,CAAC;AAEH,eAAO,MAAM,cAAc,UAI1B,CAAC;AAEF,eAAO,MAAM,mBAAmB,oMAM9B,CAAC;AAEH,eAAO,MAAM,iBAAiB,sEACkC,CAAC"}
1
+ {"version":3,"file":"auth_ddl.d.ts","sourceRoot":"","sources":["../../src/lib/auth/auth_ddl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAMH,eAAO,MAAM,cAAc,6ZAazB,CAAC;AAMH,eAAO,MAAM,YAAY,0ZAUvB,CAAC;AAEH,eAAO,MAAM,WAAW,wEAC0C,CAAC;AAEnE;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,8FACqD,CAAC;AAEzF,eAAO,MAAM,iBAAiB,2ZAU5B,CAAC;AAEH,eAAO,MAAM,kBAAkB,UAI9B,CAAC;AAKF,eAAO,MAAM,mBAAmB,0RAO9B,CAAC;AAEH,eAAO,MAAM,oBAAoB,UAGhC,CAAC;AAEF,eAAO,MAAM,gBAAgB,iUAU3B,CAAC;AAEH,eAAO,MAAM,mBAAmB,4GACsE,CAAC;AAEvG,eAAO,MAAM,yBAAyB,6FACiD,CAAC;AAExF,eAAO,MAAM,eAAe,gFAC8C,CAAC;AAE3E,eAAO,MAAM,qBAAqB,wJAIhC,CAAC;AAEH,6FAA6F;AAC7F,eAAO,MAAM,mBAAmB,yHAGP,CAAC;AAE1B,eAAO,MAAM,aAAa,6ZAUxB,CAAC;AAEH,eAAO,MAAM,cAAc,UAI1B,CAAC;AAEF,eAAO,MAAM,mBAAmB,oMAM9B,CAAC;AAEH,eAAO,MAAM,iBAAiB,sEACkC,CAAC"}
@@ -33,6 +33,10 @@ CREATE TABLE IF NOT EXISTS account (
33
33
  deleted_at TIMESTAMPTZ,
34
34
  deleted_by UUID
35
35
  )`;
36
+ // The `updated_by` / `deleted_by` foreign keys stay in this frozen v0 body —
37
+ // the appended `drop_provenance_stamp_foreign_keys` migration drops them, as
38
+ // it drops `role_grant`'s `granted_by` / `revoked_by` / `source_offer_id`
39
+ // (`auth/migrations.ts` has why).
36
40
  export const ACTOR_SCHEMA = `
37
41
  CREATE TABLE IF NOT EXISTS actor (
38
42
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
@@ -83,7 +83,11 @@
83
83
  * that, so the standard assembly is one option:
84
84
  *
85
85
  * ```ts
86
- * const server = await create_app_server({backend, auth_cleanup: true, ...});
86
+ * const server = await create_app_server({
87
+ * backend,
88
+ * auth_cleanup: {every_ms: DEFAULT_AUTH_CLEANUP_INTERVAL_MS},
89
+ * ...
90
+ * });
87
91
  * // on shutdown: stops the schedule, then closes the database
88
92
  * await server.close();
89
93
  * ```
@@ -103,7 +107,10 @@
103
107
  * token is cancelled; a promise cannot be dropped, so `stop` ends the schedule
104
108
  * at once and its promise resolves when the pass in progress — if there is
105
109
  * one — has finished. Awaiting it before closing the database lets that pass
106
- * end on a live pool rather than fail on a closed one.
110
+ * end on a live pool rather than fail on a closed one. `AppServer.close`
111
+ * waits for it within its drain bound, as the Rust shutdown joins its upkeep,
112
+ * and counts a pass still running at the bound as given up on
113
+ * (`ShutdownDrainGivenUp.upkeep`).
107
114
  *
108
115
  * @module
109
116
  */
@@ -221,6 +228,29 @@ export declare const cleanup_expired_role_grant_offers: (deps: AuthCleanupDeps)
221
228
  * @throws Error re-thrown from the first sweep that fails (no per-sweep isolation here)
222
229
  */
223
230
  export declare const run_auth_cleanup: (deps: AuthCleanupDeps) => Promise<AuthCleanupResult>;
231
+ /**
232
+ * Whether a server runs the auth cleanup beside itself, and how often —
233
+ * `create_app_server`'s `auth_cleanup` option.
234
+ *
235
+ * A required choice, with no default: every server names it, so none gets or
236
+ * loses the sweeps without writing it out.
237
+ *
238
+ * - `{every_ms}` — `start_auth_cleanup` on that interval: a pass as the
239
+ * server finishes assembly, then one per `every_ms`
240
+ * (`DEFAULT_AUTH_CLEANUP_INTERVAL_MS` unless the server has a reason to
241
+ * differ) — what a production server runs. Must be a positive finite
242
+ * number no greater than `PERIODIC_INTERVAL_MS_MAX`.
243
+ * - `'off'` — no cleanup: an in-process test harness (a background pass
244
+ * deletes rows and writes audit rows mid-test), a test server held to a
245
+ * spine that schedules none, or a process whose sweeps run elsewhere
246
+ * (`run_auth_cleanup` on a schedule of its own).
247
+ *
248
+ * Twin of the Rust `fuz_auth::AuthCleanupSchedule` (`Every(Duration)` /
249
+ * `Off`).
250
+ */
251
+ export type AuthCleanupSchedule = {
252
+ every_ms: number;
253
+ } | 'off';
224
254
  /** Options for `start_auth_cleanup`. */
225
255
  export interface AuthCleanupScheduleOptions {
226
256
  /**
@@ -236,7 +266,8 @@ export interface AuthCleanupScheduleOptions {
236
266
  *
237
267
  * The auth surface's upkeep in one call — start it once migrations have run
238
268
  * and stop it before the database closes (see the module doc's § Scheduling).
239
- * `create_app_server`'s `auth_cleanup` option does both.
269
+ * `create_app_server`'s `auth_cleanup` option (an `AuthCleanupSchedule`)
270
+ * does both.
240
271
  *
241
272
  * Built on `start_periodic`, which fixes the loop's rules: the startup pass
242
273
  * starts before this returns, passes never overlap, a slow pass delays the
@@ -1 +1 @@
1
- {"version":3,"file":"cleanup.d.ts","sourceRoot":"","sources":["../../src/lib/auth/cleanup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4GG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAGxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAIvD;;;;;;;;;GASG;AACH,eAAO,MAAM,gCAAgC,QAAiB,CAAC;AAE/D;;;GAGG;AACH,MAAM,WAAW,eAAgB,SAAQ,SAAS;IACjD,GAAG,EAAE,MAAM,CAAC;IACZ;;;;;;;OAOG;IACH,KAAK,EAAE,YAAY,CAAC;IACpB;;;;;;;;;OASG;IACH,iBAAiB,EAAE,gBAAgB,CAAC;CACpC;AAED,+FAA+F;AAC/F,MAAM,WAAW,iBAAiB;IACjC,8EAA8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