@fuzdev/fuz_app 0.185.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 (114) hide show
  1. package/dist/actions/CLAUDE.md +14 -2
  2. package/dist/actions/perform_action.d.ts.map +1 -1
  3. package/dist/actions/perform_action.js +36 -5
  4. package/dist/actions/ws_socket_session.d.ts.map +1 -1
  5. package/dist/actions/ws_socket_session.js +3 -1
  6. package/dist/auth/CLAUDE.md +11 -5
  7. package/dist/auth/account_queries.d.ts +53 -40
  8. package/dist/auth/account_queries.d.ts.map +1 -1
  9. package/dist/auth/account_queries.js +57 -50
  10. package/dist/auth/account_routes.d.ts.map +1 -1
  11. package/dist/auth/account_routes.js +59 -25
  12. package/dist/auth/admin_actions.d.ts.map +1 -1
  13. package/dist/auth/admin_actions.js +26 -9
  14. package/dist/auth/audit_emitter.js +2 -2
  15. package/dist/auth/audit_log_queries.d.ts +11 -3
  16. package/dist/auth/audit_log_queries.d.ts.map +1 -1
  17. package/dist/auth/audit_log_queries.js +4 -4
  18. package/dist/auth/audit_log_schema.js +1 -1
  19. package/dist/auth/auth_ddl.d.ts.map +1 -1
  20. package/dist/auth/auth_ddl.js +4 -0
  21. package/dist/auth/cleanup.js +1 -1
  22. package/dist/auth/migrations.d.ts.map +1 -1
  23. package/dist/auth/migrations.js +35 -0
  24. package/dist/auth/role_grant_offer_queries.d.ts +13 -13
  25. package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
  26. package/dist/auth/role_grant_offer_queries.js +12 -13
  27. package/dist/auth/role_grant_queries.d.ts +16 -9
  28. package/dist/auth/role_grant_queries.d.ts.map +1 -1
  29. package/dist/auth/role_grant_queries.js +16 -9
  30. package/dist/auth/self_service_role_actions.d.ts.map +1 -1
  31. package/dist/auth/self_service_role_actions.js +15 -0
  32. package/dist/auth/session_queries.d.ts +24 -0
  33. package/dist/auth/session_queries.d.ts.map +1 -1
  34. package/dist/auth/session_queries.js +28 -0
  35. package/dist/db/CLAUDE.md +3 -3
  36. package/dist/db/cell_ddl.d.ts +8 -3
  37. package/dist/db/cell_ddl.d.ts.map +1 -1
  38. package/dist/db/cell_ddl.js +10 -5
  39. package/dist/http/body_limit.d.ts +4 -4
  40. package/dist/http/body_limit.js +4 -4
  41. package/dist/testing/CLAUDE.md +126 -27
  42. package/dist/testing/app_server.d.ts +5 -7
  43. package/dist/testing/app_server.d.ts.map +1 -1
  44. package/dist/testing/app_server.js +5 -7
  45. package/dist/testing/auth_apps.d.ts +3 -1
  46. package/dist/testing/auth_apps.d.ts.map +1 -1
  47. package/dist/testing/auth_apps.js +22 -5
  48. package/dist/testing/cross_backend/backend_config.d.ts +8 -0
  49. package/dist/testing/cross_backend/backend_config.d.ts.map +1 -1
  50. package/dist/testing/cross_backend/backend_log.d.ts +71 -0
  51. package/dist/testing/cross_backend/backend_log.d.ts.map +1 -0
  52. package/dist/testing/cross_backend/backend_log.js +134 -0
  53. package/dist/testing/cross_backend/backend_swap.d.ts +41 -0
  54. package/dist/testing/cross_backend/backend_swap.d.ts.map +1 -0
  55. package/dist/testing/cross_backend/backend_swap.js +431 -0
  56. package/dist/testing/cross_backend/body_size_smuggling.js +3 -3
  57. package/dist/testing/cross_backend/bootstrap_backend.js +4 -4
  58. package/dist/testing/cross_backend/conformance_case.d.ts +11 -6
  59. package/dist/testing/cross_backend/conformance_case.d.ts.map +1 -1
  60. package/dist/testing/cross_backend/conformance_case.js +4 -0
  61. package/dist/testing/cross_backend/conformance_principal.d.ts +2 -2
  62. package/dist/testing/cross_backend/conformance_principal.d.ts.map +1 -1
  63. package/dist/testing/cross_backend/conformance_principal.js +27 -10
  64. package/dist/testing/cross_backend/default_backend_configs.d.ts +38 -5
  65. package/dist/testing/cross_backend/default_backend_configs.d.ts.map +1 -1
  66. package/dist/testing/cross_backend/default_backend_configs.js +50 -15
  67. package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
  68. package/dist/testing/cross_backend/in_process_setup.js +52 -30
  69. package/dist/testing/cross_backend/revocation_drivers.d.ts +14 -2
  70. package/dist/testing/cross_backend/revocation_drivers.d.ts.map +1 -1
  71. package/dist/testing/cross_backend/revocation_drivers.js +36 -8
  72. package/dist/testing/cross_backend/rust_spine_stub_backend_config.d.ts +7 -0
  73. package/dist/testing/cross_backend/rust_spine_stub_backend_config.d.ts.map +1 -1
  74. package/dist/testing/cross_backend/rust_spine_stub_backend_config.js +4 -2
  75. package/dist/testing/cross_backend/setup.d.ts +44 -43
  76. package/dist/testing/cross_backend/setup.d.ts.map +1 -1
  77. package/dist/testing/cross_backend/setup.js +64 -62
  78. package/dist/testing/cross_backend/spawn_backend.d.ts +7 -3
  79. package/dist/testing/cross_backend/spawn_backend.d.ts.map +1 -1
  80. package/dist/testing/cross_backend/spawn_backend.js +86 -7
  81. package/dist/testing/cross_backend/spine_suites.d.ts +1 -1
  82. package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
  83. package/dist/testing/cross_backend/spine_suites.js +4 -2
  84. package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
  85. package/dist/testing/cross_backend/sse_round_trip.js +4 -2
  86. package/dist/testing/cross_backend/testing_reset_actions.d.ts +7 -6
  87. package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
  88. package/dist/testing/cross_backend/testing_reset_actions.js +10 -8
  89. package/dist/testing/cross_backend/testing_server_bun.d.ts.map +1 -1
  90. package/dist/testing/cross_backend/testing_server_bun.js +7 -31
  91. package/dist/testing/cross_backend/ws_round_trip.d.ts.map +1 -1
  92. package/dist/testing/cross_backend/ws_round_trip.js +4 -3
  93. package/dist/testing/data_exposure.d.ts +4 -1
  94. package/dist/testing/data_exposure.d.ts.map +1 -1
  95. package/dist/testing/data_exposure.js +93 -25
  96. package/dist/testing/db_invariants.d.ts +5 -5
  97. package/dist/testing/db_invariants.js +5 -5
  98. package/dist/testing/logged_errors.d.ts +61 -0
  99. package/dist/testing/logged_errors.d.ts.map +1 -0
  100. package/dist/testing/logged_errors.js +285 -0
  101. package/dist/testing/middleware_gate_probes.d.ts.map +1 -1
  102. package/dist/testing/middleware_gate_probes.js +15 -8
  103. package/dist/testing/rpc_attack_surface.d.ts.map +1 -1
  104. package/dist/testing/rpc_attack_surface.js +41 -16
  105. package/dist/testing/stubs.d.ts +5 -1
  106. package/dist/testing/stubs.d.ts.map +1 -1
  107. package/dist/testing/stubs.js +6 -3
  108. package/dist/testing/test_app.d.ts +40 -11
  109. package/dist/testing/test_app.d.ts.map +1 -1
  110. package/dist/testing/test_app.js +66 -9
  111. package/dist/testing/transports/fetch_transport.d.ts +10 -0
  112. package/dist/testing/transports/fetch_transport.d.ts.map +1 -1
  113. package/dist/testing/transports/fetch_transport.js +13 -0
  114. package/package.json +4 -3
@@ -196,8 +196,20 @@ module's TSDoc and pinned by the `query_shape` cross suite.
196
196
  `GET` with `?params=42` is a 401 on both spines and an authorized one is
197
197
  `invalid_params`.
198
198
  - **Errors.** A `ThrownJsonrpcError` (recognized by its realm-global brand,
199
- `http/CLAUDE.md` §JSON-RPC) keeps its code and data; any other throw is
200
- `internal_error` 500, its message the raw error only under `DEV`. A result
199
+ `http/CLAUDE.md` §JSON-RPC) keeps its code and data. Any other throw is
200
+ `internal_error` 500, its message the raw error only under `DEV`, unless
201
+ the request's `signal` has aborted (a WS `cancel`, the socket closing, an
202
+ HTTP client gone): then it is `request_cancelled`, in the authorization
203
+ phase and the handler alike, logged at debug when the throw is the
204
+ cancellation itself (the signal's reason or an `AbortError`) and at warn
205
+ when it is anything else — a fault that landed after the cancel.
206
+ **Twin difference:** the Rust dispatcher answers a handler's `Err` as
207
+ returned, so over WS, with a per-request `cancel` and the socket still open,
208
+ a Rust handler that bails with `internal_error` answers `internal_error` and
209
+ logs at error where the error is built (`internal_error_with_source`); the
210
+ twin's answer is `request_cancelled`. Rust can't twin the log, which is
211
+ written at construction, before the dispatcher sees the error; a Rust
212
+ handler bails with `request_cancelled`. A result
201
213
  that can't be serialized answers the same 500 rather than throwing: the
202
214
  action has committed by then, and a throw would discard the handler's
203
215
  `post_commit_effects` — the connection closes of a revocation that landed.
@@ -1 +1 @@
1
- {"version":3,"file":"perform_action.d.ts","sourceRoot":"","sources":["../../src/lib/actions/perform_action.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAS,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACvF,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAGN,KAAK,cAAc,EACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAGN,KAAK,YAAY,EACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAOtC,OAAO,EACN,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EAGvB,MAAM,oBAAoB,CAAC;AAkB5B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,KAAK,EAAgC,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACjF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAInE;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IAClC,kEAAkE;IAClE,MAAM,EAAE,SAAS,CAAC;IAClB,qGAAqG;IACrG,UAAU,EAAE,OAAO,CAAC;IACpB,sDAAsD;IACtD,UAAU,EAAE,gBAAgB,CAAC;IAC7B;;;;;;OAMG;IACH,UAAU,EAAE,YAAY,GAAG,IAAI,CAAC;IAChC,qEAAqE;IACrE,SAAS,EAAE,MAAM,CAAC;IAClB,uGAAuG;IACvG,MAAM,EA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AAI,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,kBAAkB,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhG;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,GAC1B,OAAO,kBAAkB,EACzB,MAAM,iBAAiB,KACrB,OAAO,CAAC,mBAAmB,CAgM7B,CAAC;AAyDF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,uBAAuB,GACnC,OAAO,SAAS,EAChB,QAAQ,aAAa,CAAC,WAAW,CAAC,EAClC,QAAQ,OAAO,KACb,kBAOF,CAAC;AA2EF;;;;;;;;GAQG;AACH,eAAO,MAAM,8BAA8B,GAC1C,2BAA2B,aAAa,CAAC,MAAM,CAAC,KAC9C,kBAIA,CAAC;AAqEJ,0FAA0F;AAC1F,MAAM,WAAW,sBAAsB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,uEAAuE;IACvE,MAAM,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,uBAAuB,GACnC,IAAI,gBAAgB,EACpB,QAAQ,mBAAmB,EAC3B,QAAQ,MAAM,EACd,KAAK,MAAM,KACT,sBAkBF,CAAC"}
@@ -118,7 +118,7 @@ export const perform_action = async (input, deps) => {
118
118
  result = await apply_authorization_phase({ db }, account, action_auth, read_acting(action_auth, raw_params));
119
119
  }
120
120
  catch (err) {
121
- return thrown_error_result(err, `authorization phase error: ${spec.method}`, log);
121
+ return thrown_error_result(err, `authorization phase error: ${spec.method}`, log, signal);
122
122
  }
123
123
  if (!result.ok) {
124
124
  // an account removed since its credential was read: the dead
@@ -240,16 +240,30 @@ export const perform_action = async (input, deps) => {
240
240
  return await dispatch_with_post_commit_rollback(post_commit_effects, () => use_transaction ? db.transaction((tx) => execute(tx)) : execute(db));
241
241
  }
242
242
  catch (err) {
243
- return thrown_error_result(err, `unhandled action handler error: ${spec.method}`, log);
243
+ return thrown_error_result(err, `unhandled action handler error: ${spec.method}`, log, signal);
244
244
  }
245
245
  };
246
246
  /**
247
247
  * The dispatcher's answer to a thrown value: the JSON-RPC error it carries
248
248
  * (`to_thrown_jsonrpc_error` — a `ThrownJsonrpcError` from any copy of
249
- * fuz_app, or a failed pool checkout's `service_unavailable`), else a logged,
250
- * masked `internal_error`.
249
+ * fuz_app, or a failed pool checkout's `service_unavailable`); else, once the
250
+ * request's `signal` has aborted, `request_cancelled`, since nobody is waiting
251
+ * on the answer; else a logged, masked `internal_error`.
252
+ *
253
+ * A throw after the abort is logged by what it is. The cancellation itself
254
+ * (`is_cancellation`: the signal's own reason, or an `AbortError`) is the
255
+ * handler bailing as it should, at debug. Any other throw may be a genuine
256
+ * fault that happened to land after the cancel, so it is logged at warn:
257
+ * visible, but not an error line, since its caller has gone. A handler that
258
+ * bails on a cancel throws the cancellation (`ctx.signal.throwIfAborted()`) or
259
+ * `jsonrpc_errors.request_cancelled`.
260
+ *
261
+ * **Twin difference:** the Rust dispatcher answers a handler's `Err` as it is,
262
+ * so a Rust handler that returns `internal_error` after its cancel answers
263
+ * `internal_error`, logged at error where it was built (`actions/CLAUDE.md`
264
+ * §Errors).
251
265
  */
252
- const thrown_error_result = (err, context, log) => {
266
+ const thrown_error_result = (err, context, log, signal) => {
253
267
  const thrown = to_thrown_jsonrpc_error(err);
254
268
  if (thrown) {
255
269
  // a failed checkout is the server's to see, though the caller gets the 503
@@ -261,6 +275,15 @@ const thrown_error_result = (err, context, log) => {
261
275
  error: thrown
262
276
  };
263
277
  }
278
+ if (signal.aborted) {
279
+ if (is_cancellation(err, signal)) {
280
+ log.debug(`${context}: the request was cancelled`, err);
281
+ }
282
+ else {
283
+ log.warn(`${context} after its request was cancelled`, err);
284
+ }
285
+ return error_result(jsonrpc_error_messages.request_cancelled());
286
+ }
264
287
  log.error(context, err);
265
288
  // Raw exception messages can leak internals (paths, SQL, secrets in a
266
289
  // message) — surface them only in development; production falls back to
@@ -285,6 +308,14 @@ export const to_invalid_params_error = (input, issues, params) => {
285
308
  const issues_data = dev_only(() => ({ issues: to_wire_issues(issues) }));
286
309
  return jsonrpc_error_messages.invalid_params('invalid params', reason === undefined ? issues_data : { reason, ...issues_data });
287
310
  };
311
+ /**
312
+ * Whether a throw is the request's cancellation itself: the aborted signal's
313
+ * own reason (what `signal.throwIfAborted()` and a `fetch` given the signal
314
+ * reject with), or any `AbortError` (a `DOMException` from an API that names
315
+ * no reason).
316
+ */
317
+ const is_cancellation = (err, signal) => err === signal.reason ||
318
+ (typeof err === 'object' && err !== null && err.name === 'AbortError');
288
319
  const error_result = (error) => ({
289
320
  kind: 'error',
290
321
  error,
@@ -1 +1 @@
1
- {"version":3,"file":"ws_socket_session.d.ts","sourceRoot":"","sources":["../../src/lib/actions/ws_socket_session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyHG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAGpE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAKN,KAAK,YAAY,EACjB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAEN,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EA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;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,uBAAuB,GACnC,UAAU,gBAAgB,EAC1B,SAAS,eAAe,KACtB,QAwrBF,CAAC"}
@@ -543,7 +543,9 @@ export const create_ws_socket_events = (endpoint, upgrade) => {
543
543
  json = parse_json_text(String(data));
544
544
  }
545
545
  catch (error) {
546
- log.error('JSON parse error:', error);
546
+ // a client's malformed frame is its own fault, answered `parse_error`: debug, as the
547
+ // HTTP RPC endpoint and the Rust spine log nothing for it
548
+ log.debug('JSON parse error:', error);
547
549
  send_error(null, jsonrpc_error_messages.parse_error());
548
550
  return;
549
551
  }
@@ -252,8 +252,10 @@ cannot disagree.
252
252
 
253
253
  One class order in every transaction — accounts, then offers, then grants and
254
254
  actors — and id order within a class. Every writer of an account takes its row
255
- first (two mints of one account take turns there, so the caps hold); a
256
- multi-row write locks its rows in one id-ordered statement before writing.
255
+ first (two mints of one account take turns there, so the caps hold) — a
256
+ delete and a purge after their last-admin guard, which an admin target's row
257
+ is locked within, then the guards again; a multi-row write locks its rows in
258
+ one id-ordered statement before writing.
257
259
  Each lock's strength and reason is on its query's TSDoc; the rule set:
258
260
  ../../../docs/security.md §Row Locks. `lock_pins.cross.test.ts` pins them on
259
261
  both spines (../../test/CLAUDE.md).
@@ -409,9 +411,13 @@ a mounting surface; protocol specs excluded.
409
411
  notified), deletes the unclaimed invites it issued, revokes its sessions and
410
412
  tokens, and writes the account row plus one per actor. Delete keeps the role
411
413
  grants, inert; purge is the keeper-only cascading delete with
412
- `confirm: true`. The target guards (never a keeper account, never the last
413
- active admin) and what an undelete restores are ../../../docs/security.md
414
- §Authorization.
414
+ `confirm: true`, taking the purge advisory lock first
415
+ (`query_account_purge_advisory_lock`) and running its guards again under
416
+ its row lock (`query_account_lock_for_purge`), and its cascade leaves the
417
+ provenance stamps (`granted_by`, `revoked_by`, `source_offer_id`, the
418
+ actor's) naming the purged ids. The target guards (never a keeper account,
419
+ never the last active admin) and what an undelete restores are
420
+ ../../../docs/security.md §Authorization.
415
421
  - **Failure rows on a miss.** `admin_session_revoke_all`,
416
422
  `admin_token_revoke_all`, account delete / purge and `invite_delete` write
417
423
  a failure row on a missing target, the probed id in metadata
@@ -89,11 +89,17 @@ export declare const query_account_by_username_or_email: (deps: QueryDeps, input
89
89
  * Pass the same hash the verify ran against — typically
90
90
  * `ctx.account.password_hash` from the request context.
91
91
  *
92
+ * A tombstoned account matches nothing either: a delete can commit between
93
+ * the authorization and the UPDATE, and a waiting UPDATE rereads the row the
94
+ * delete committed, so the change never lands on a deleted account. Twin of
95
+ * the Rust `query_update_account_password`.
96
+ *
92
97
  * @returns `true` if the row was updated, `false` if `expected_hash` no
93
98
  * longer matched (concurrent change won — caller should treat as a
94
- * stale-credential failure).
99
+ * stale-credential failure) or the account is deleted.
95
100
  * @mutates `account` row - updates `password_hash`, `updated_at`, and
96
- * `updated_by` only when the stored hash equals `expected_hash`
101
+ * `updated_by` only when the account is live and its stored hash equals
102
+ * `expected_hash`
97
103
  */
98
104
  export declare const query_update_account_password: (deps: QueryDeps, id: string, password_hash: string, updated_by: string | null, expected_hash: string) => Promise<boolean>;
99
105
  /**
@@ -150,43 +156,48 @@ export declare const query_account_lock_verified: (deps: QueryDeps, id: string,
150
156
  * cap — `query_account_lock_verified` has why, and what it conflicts with; a
151
157
  * token mint and a login of one account take turns too. A write that only
152
158
  * needs ordering against a delete takes `query_account_lock_live_many`, which
153
- * lets such writes run together. Twin of the Rust
159
+ * lets such writes run together. A delete takes it too, after its last-admin
160
+ * guard and before the guards' second pass (`account_delete` in
161
+ * `admin_actions.ts`): the guard reads whether the target is an admin
162
+ * unlocked. And `self_service_role_set` takes it first, so a toggle is refused
163
+ * on a removed account, or a removal waits for it. Twin of the Rust
154
164
  * `fuz_auth::query_account_lock_live`.
155
165
  *
156
- * @param deps - query dependencies (must be the mint's transaction)
157
- * @param id - the account the credential is for
166
+ * @param deps - query dependencies (must be the mint's, the delete's, or the toggle's transaction)
167
+ * @param id - the account the credential is for, or the account the delete removes
158
168
  * @returns `true` when the row is locked and not tombstoned, `false` when it was deleted or tombstoned
159
169
  */
160
170
  export declare const query_account_lock_live: (deps: QueryDeps, id: string) => Promise<boolean>;
161
171
  /**
162
- * Lock, for a purge, the account rows of every holder of an unrevoked global
163
- * `admin` grant and the purged account's own, in one statement, in id order,
164
- * `FOR NO KEY UPDATE`.
172
+ * The key of the advisory lock every purge takes
173
+ * (`query_account_purge_advisory_lock`): the ASCII of `fuz_` and `purg`.
165
174
  *
166
- * A purge's cascade writes rows of other accounts: it sets null the
167
- * `granted_by` and `revoked_by` of every grant the purged account's actors
168
- * named, admins' grants among them, in whatever order the plan walks them. A
169
- * last-admin guard of another removal takes admin accounts, actors and grants
170
- * in account-id order. A purge reaching an admin's grant before the guard does
171
- * and waiting on one the guard took could hold a row the guard waits on.
172
- * Holding every admin's account first, in the order the guard and
173
- * `query_account_lock_live_many` take account rows, another guard waits at its
174
- * first account holding nothing, and two purges take turns. The purged
175
- * account's row is taken in the same statement, so an offer create holding one
176
- * of these rows `FOR SHARE` and waiting on another meets them in the same order.
177
- * No `deleted_at` filter on either: a tombstoned admin's grant is written by
178
- * the cascade as well, and a purge removes a tombstoned account. The admins
179
- * are those the statement's snapshot sees; one made by a transaction that
180
- * commits after it starts is not among them. Cost: a purge waits behind
181
- * admins' logins, token creates and offers. Run first in the purge's
182
- * transaction, before the last-admin guard (an admin target's only) and
183
- * `query_account_lock_for_purge`.
184
- * Twin of the Rust `fuz_auth::account_queries::query_account_lock_admins_for_purge`.
175
+ * The two-`int4` form, `pg_advisory_xact_lock(int4, int4)`, a key space apart
176
+ * from the single-key form the migration runner's per-namespace
177
+ * `pg_advisory_lock(int4)` takes, so no namespace's hash can collide with it.
178
+ * Twin of the Rust `fuz_auth::account_queries::ACCOUNT_PURGE_ADVISORY_LOCK_KEY`.
179
+ */
180
+ export declare const ACCOUNT_PURGE_ADVISORY_LOCK_KEY: readonly [number, number];
181
+ /**
182
+ * Take, for a purge, the transaction-scoped advisory lock every purge takes,
183
+ * so two purges take turns.
184
+ *
185
+ * Two purges' cascades write rows both reach — the offers each account made to
186
+ * the other, accepted and declined as well as pending, and the invites each
187
+ * issued and the other claimed — in whatever order their plans walk them, and
188
+ * no row lock a purge takes ahead of its cascade covers every such row. Held
189
+ * from the purge's first statement, the lock makes a second purge wait before
190
+ * it holds any row. Only purges take it, and a purge takes it holding nothing,
191
+ * so it orders purges against each other and nothing else: every other writer
192
+ * meets a purge at the rows it locks after this — the last-admin guard's (an
193
+ * admin target's only), its account row (`query_account_lock_for_purge`), its
194
+ * offers. Released when the transaction ends. Run first in the purge's
195
+ * transaction. Twin of the Rust
196
+ * `fuz_auth::account_queries::query_account_purge_advisory_lock`.
185
197
  *
186
198
  * @param deps - query dependencies (must be the purge's transaction)
187
- * @param id - the account to purge
188
199
  */
189
- export declare const query_account_lock_admins_for_purge: (deps: QueryDeps, id: string) => Promise<void>;
200
+ export declare const query_account_purge_advisory_lock: (deps: QueryDeps) => Promise<void>;
190
201
  /**
191
202
  * Lock the account row of a revoke's revokee, by its actor, tombstoned or not,
192
203
  * `FOR NO KEY UPDATE`.
@@ -222,10 +233,13 @@ export declare const query_account_lock_for_revoke: (deps: QueryDeps, actor_id:
222
233
  * takes anyway: it conflicts with every other lock on the row, so a writer
223
234
  * holding one is waited out, and a writer arriving later waits for the purge
224
235
  * and then finds no row. No `deleted_at` filter — a purge removes a tombstoned
225
- * account too. Run after `query_account_lock_admins_for_purge`, which takes the
226
- * row `FOR NO KEY UPDATE` among every admin's in id order, and, for an admin
227
- * target, the last-admin guard, so this only strengthens a lock the purge
228
- * already holds. Twin of the Rust
236
+ * account too. Run after `query_account_purge_advisory_lock` and, for an admin
237
+ * target, the last-admin guard, which takes the row `FOR NO KEY UPDATE` among
238
+ * every admin's in id order, so for an admin this only strengthens a lock the
239
+ * purge already holds. The guards run again after it: they read whether the
240
+ * target is an admin unlocked, and a non-admin target's row is the first the
241
+ * purge holds of it, so an accept making it an admin commits before this lock
242
+ * is granted. Twin of the Rust
229
243
  * `fuz_auth::account_queries::query_account_lock_for_purge`.
230
244
  *
231
245
  * @param deps - query dependencies (must be the purge's transaction)
@@ -273,7 +287,7 @@ export declare const query_account_lock_live_many: (deps: QueryDeps, ids: Readon
273
287
  * by one recipient take turns, and the second claims after the first has
274
288
  * superseded its siblings. It conflicts with a delete's or a purge's first
275
289
  * write of the account (the soft-delete `UPDATE`,
276
- * `query_account_lock_admins_for_purge`, the last-admin guard), so a removal of
290
+ * `query_account_lock_for_purge`, the last-admin guard), so a removal of
277
291
  * the recipient waits here or is waited for whole, and never meets the accept
278
292
  * at its offers or its actor; with a revoke's `query_account_lock_for_revoke`,
279
293
  * so a revoke of the recipient's grant and the accept take turns; and with
@@ -285,12 +299,11 @@ export declare const query_account_lock_live_many: (deps: QueryDeps, ids: Readon
285
299
  * unlocked read after this one): every write that ends a grantor's global
286
300
  * `admin` takes the grantor's account row first — a revoke of the grant through
287
301
  * `query_account_lock_for_revoke` (whether or not its last-admin guard ran), a
288
- * delete through its write of the row, a purge through
289
- * `query_account_lock_admins_for_purge` and `query_account_lock_for_purge` — so
290
- * it either commits before the read, which sees it, or waits for the accept to
291
- * commit. A share lock on the account,
292
- * not on the grant, so a purge's cascade reaching the grant (its `granted_by`
293
- * naming an actor of the purged account) never waits on the accept.
302
+ * delete through its write of the row, a purge through the last-admin guard
303
+ * and `query_account_lock_for_purge` — so it either commits before the read,
304
+ * which sees it, or waits for the accept to commit. A share lock on the
305
+ * account, not on the grant: every removal takes the account first, so it
306
+ * waits there holding nothing the accept needs.
294
307
  *
295
308
  * Two statements, as the two strengths can't share one locking clause, the
296
309
  * lower id first — the order the last-admin guard
@@ -1 +1 @@
1
- {"version":3,"file":"account_queries.d.ts","sourceRoot":"","sources":["../../src/lib/auth/account_queries.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAQrD,OAAO,EAEN,KAAK,OAAO,EACZ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
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,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;IACn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