@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
@@ -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,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,8BAA8B,EACnC,KAAK,yBAAyB,EAC9B,MAAM,uBAAuB,CAAC;AAE/B;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,mJAYyB,CAAC;AAExD;;;;GAIG;AACH,eAAO,MAAM,cAAc,8DAA4D,CAAC;AAaxF,iFAAiF;AACjF,eAAO,MAAM,sCAAsC,QAAO,MACvB,CAAC;AAEpC,0CAA0C;AAC1C,eAAO,MAAM,wCAAwC,QAAO,IAE3D,CAAC;AAYF,gFAAgF;AAChF,eAAO,MAAM,qCAAqC,QAAO,MACvB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;AAExD;;;;GAIG;AACH,eAAO,MAAM,cAAc,8DAA4D,CAAC;AAaxF,iFAAiF;AACjF,eAAO,MAAM,sCAAsC,QAAO,MACvB,CAAC;AAEpC,0CAA0C;AAC1C,eAAO,MAAM,wCAAwC,QAAO,IAE3D,CAAC;AAYF,gFAAgF;AAChF,eAAO,MAAM,qCAAqC,QAAO,MACvB,CAAC;AAEnC,0CAA0C;AAC1C,eAAO,MAAM,uCAAuC,QAAO,IAE1D,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,iBAAkB,SAAQ,SAAS;IACnD,GAAG,EAAE,MAAM,CAAC;CACZ;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,eAAe,GAAU,CAAC,SAAS,MAAM,EACrD,MAAM,iBAAiB,EACvB,OAAO,aAAa,CAAC,CAAC,CAAC,EACvB,SAAQ,cAAyC,KAC/C,OAAO,CAAC,aAAa,CAmCvB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAChC,MAAM,SAAS,EACf,UAAU,mBAAmB,KAC3B,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,CA0C9B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,mCAAmC,GAC/C,MAAM,SAAS,EACf,UAAU,mBAAmB,KAC3B,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
  }
@@ -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(),
@@ -225,7 +225,7 @@ export const cleanup_expired_role_grant_offers = async (deps) => {
225
225
  // Account-grain offers (no `to_actor_id`) never bound to a
226
226
  // specific actor and leave the field null. No request is behind a
227
227
  // sweep, so `ip` stays null.
228
- written.push(await query_audit_log({ db: tx }, {
228
+ written.push(await query_audit_log({ db: tx, log: deps.log }, {
229
229
  event_type: 'role_grant_offer_expire',
230
230
  actor_id: offer.from_actor_id,
231
231
  target_account_id: offer.to_account_id,
@@ -1 +1 @@
1
- {"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../src/lib/auth/migrations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AA+BH,OAAO,EAGN,KAAK,kBAAkB,EACvB,MAAM,kBAAkB,CAAC;AAkQ1B;;;GAGG;AACH,eAAO,MAAM,iBAAiB,EAAE,kBAG/B,CAAC"}
1
+ {"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../src/lib/auth/migrations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AA+BH,OAAO,EAGN,KAAK,kBAAkB,EACvB,MAAM,kBAAkB,CAAC;AAsS1B;;;GAGG;AACH,eAAO,MAAM,iBAAiB,EAAE,kBAG/B,CAAC"}
@@ -52,6 +52,19 @@ import { ROLE_GRANT_OFFER_SCHEMA, ROLE_GRANT_OFFER_PENDING_UNIQUE_INDEX, ROLE_GR
52
52
  import { create_spine_migration_namespace } from '../db/migrate.js';
53
53
  /** Namespace identifier for fuz_app auth migrations. */
54
54
  const AUTH_MIGRATION_NAMESPACE = 'fuz_auth';
55
+ /**
56
+ * The statements of the `drop_provenance_stamp_foreign_keys` migration: the
57
+ * foreign keys of the provenance stamps, by their default names
58
+ * (`<table>_<column>_fkey`, the same on both spines). Statement for statement
59
+ * the Rust spine's `drop_provenance_stamp_foreign_keys.sql`.
60
+ */
61
+ const DROP_PROVENANCE_STAMP_FOREIGN_KEYS = [
62
+ 'ALTER TABLE actor DROP CONSTRAINT IF EXISTS actor_updated_by_fkey',
63
+ 'ALTER TABLE actor DROP CONSTRAINT IF EXISTS actor_deleted_by_fkey',
64
+ 'ALTER TABLE role_grant DROP CONSTRAINT IF EXISTS role_grant_granted_by_fkey',
65
+ 'ALTER TABLE role_grant DROP CONSTRAINT IF EXISTS role_grant_revoked_by_fkey',
66
+ 'ALTER TABLE role_grant DROP CONSTRAINT IF EXISTS role_grant_source_offer_id_fkey'
67
+ ];
55
68
  /**
56
69
  * Auth schema migrations in order.
57
70
  *
@@ -284,6 +297,28 @@ const AUTH_MIGRATIONS = [
284
297
  CHECK (username = lower(username))`);
285
298
  }
286
299
  }
300
+ },
301
+ // The provenance stamps carry no foreign key: `actor.updated_by` /
302
+ // `deleted_by`, `role_grant.granted_by` / `revoked_by` and
303
+ // `role_grant.source_offer_id`.
304
+ //
305
+ // A stamp records who did a thing; nothing authorizes on it, so it keeps the
306
+ // id it was written with after its actor (or offer) is purged, as
307
+ // `audit_log`'s identity columns and `account`'s stamps do. With the foreign
308
+ // key, a purge's cascade wrote other accounts' rows (`ON DELETE SET NULL`)
309
+ // in whatever order its plan walked them, and a write stamping an actor
310
+ // being purged waited on that actor's row while holding the row the cascade
311
+ // needed next: a deadlock. Without it, the cascade never writes a stamp and
312
+ // a stamp write takes no lock on its actor. The references that carry
313
+ // meaning keep theirs: every `actor_id` and `account_id`, an offer's
314
+ // parties, an invite's issuer. `IF EXISTS`, so a re-run is a no-op.
315
+ {
316
+ name: 'drop_provenance_stamp_foreign_keys',
317
+ up: async (db) => {
318
+ for (const sql of DROP_PROVENANCE_STAMP_FOREIGN_KEYS) {
319
+ await db.query(sql);
320
+ }
321
+ }
287
322
  }
288
323
  ];
289
324
  /**
@@ -15,6 +15,7 @@ import type { Uuid } from '../primitive_schemas.js';
15
15
  import type { QueryDeps } from '../db/query_deps.js';
16
16
  import type { RoleGrant } from './account_schema.js';
17
17
  import type { CreateRoleGrantOfferInput, RoleGrantOffer, SupersededOffer } from './role_grant_offer_schema.js';
18
+ import { type AuditLogQueryDeps } from './audit_log_queries.js';
18
19
  import type { AuditLogEvent } from './audit_log_schema.js';
19
20
  /**
20
21
  * Error thrown by offer-lifecycle queries when the offer is in a non-pending
@@ -304,18 +305,17 @@ export interface AcceptOfferResult {
304
305
  * (`query_account_lock_for_offer_accept`), then the offer and the pending
305
306
  * siblings it supersedes in one id-ordered claim, then the grant insert. The
306
307
  * accounts first, as every removal of either account takes them first, so a
307
- * removal and an accept never meet at the offers, the actor, or a grant a
308
- * purge's cascade reaches; two accepts by one recipient take turns. The
309
- * offers in id order, as every transaction that writes several offer rows
310
- * locks them all first in one id-ordered statement (a delete, a purge, a
311
- * revoke, the expiry sweep). The grantor's authority is read unlocked after
312
- * the grantor's account lock — the invariant it rests on: every write that
313
- * ends a grantor's global `admin` takes the grantor's account row first (a
314
- * revoke of the grant through `query_account_lock_for_revoke`, whether or not
315
- * its last-admin guard ran; a delete through its write of the row; a purge
316
- * through `query_account_lock_admins_for_purge` and
317
- * `query_account_lock_for_purge`; the DB browser's delete, which takes none of
318
- * them, excepted).
308
+ * removal and an accept never meet at the offers or the actor; two accepts
309
+ * by one recipient take turns. The offers in id order, as every transaction
310
+ * that writes several offer rows locks them all first in one id-ordered
311
+ * statement (a delete, a purge, a revoke, the expiry sweep). The grantor's
312
+ * authority is read unlocked after the grantor's account lock — the invariant
313
+ * it rests on: every write that ends a grantor's global `admin` takes the
314
+ * grantor's account row first (a revoke of the grant through
315
+ * `query_account_lock_for_revoke`, whether or not its last-admin guard ran; a
316
+ * delete through its write of the row; a purge through its last-admin guard
317
+ * and `query_account_lock_for_purge`; the DB browser's delete, which takes
318
+ * none of them, excepted).
319
319
  *
320
320
  * Error map:
321
321
  * - `RoleGrantOfferNotFoundError` — offer does not exist, or belongs to a
@@ -348,7 +348,7 @@ export interface AcceptOfferResult {
348
348
  * @throws RoleGrantOfferBuiltinRefusedError if a builtin-role offer must not mint (see `BuiltinOfferRefusal`)
349
349
  * @throws Error if the accepting `actor_id` does not belong to `to_account_id`, or invariant assertions fail
350
350
  */
351
- export declare const query_accept_offer: (deps: QueryDeps, input: AcceptOfferInput) => Promise<AcceptOfferResult>;
351
+ export declare const query_accept_offer: (deps: AuditLogQueryDeps, input: AcceptOfferInput) => Promise<AcceptOfferResult>;
352
352
  /**
353
353
  * Supersede every pending offer **made by** one of `from_actor_ids` — the
354
354
  * grantor-side cascade.
@@ -1 +1 @@
1
- {"version":3,"file":"role_grant_offer_queries.d.ts","sourceRoot":"","sources":["../../src/lib/auth/role_grant_offer_queries.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAcrD,OAAO,KAAK,EACX,yBAAyB,EACzB,cAAc,EACd,eAAe,EACf,MAAM,8BAA8B,CAAC;AAOtC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAG3D;;;;;GAKG;AACH,qBAAa,kCAAmC,SAAQ,KAAK;gBAChD,QAAQ,EAAE,MAAM;CAI5B;AAED;;;;;GAKG;AACH,qBAAa,0BAA2B,SAAQ,KAAK;gBACxC,QAAQ,EAAE,MAAM;CAI5B;AAED;;;;;GAKG;AACH,qBAAa,2BAA4B,SAAQ,KAAK;gBACzC,QAAQ,EAAE,MAAM;CAI5B;AAED;;;;;;;;GAQG;AACH,qBAAa,6BAA8B,SAAQ,KAAK;;CAKvD;AAED;;;;;;;GAOG;AACH,qBAAa,gCAAiC,SAAQ,KAAK;gBAC9C,QAAQ,EAAE,MAAM;CAI5B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,mBAAmB,GAAG,gBAAgB,GAAG,QAAQ,GAAG,wBAAwB,CAAC;AAEzF;;;;;GAKG;AACH,qBAAa,iCAAkC,SAAQ,KAAK;IAC3D,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;IAC/B,QAAQ,CAAC,OAAO,EAAE,mBAAmB,CAAC;gBAC1B,KAAK,EAAE,cAAc,EAAE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,IAAI,CASd,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,sCAAsC,GAClD,MAAM,SAAS,EACf,UAAU,IAAI,EACd,MAAM,MAAM,EACZ,UAAU,IAAI,GAAG,IAAI,KACnB,OAAO,CAAC,IAAI,CAWd,CAAC;AAEF,mHAAmH;AACnH,MAAM,WAAW,qBAAqB;IACrC,EAAE,EAAE,IAAI,CAAC;IACT,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAC;IACtB;;;;;;;;;OASG;IACH,iBAAiB,EAAE,KAAK,CAAC,eAAe,CAAC,CAAC;CAC1C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,eAAO,MAAM,uBAAuB,GACnC,MAAM,SAAS,EACf,eAAe,IAAI,EACnB,UAAU,IAAI,EACd,YAAY,IAAI,GAAG,IAAI,EACvB,SAAS,MAAM,GAAG,IAAI,KACpB,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAmDtC,CAAC"}
1
+ {"version":3,"file":"role_grant_offer_queries.d.ts","sourceRoot":"","sources":["../../src/lib/auth/role_grant_offer_queries.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAcrD,OAAO,KAAK,EACX,yBAAyB,EACzB,cAAc,EACd,eAAe,EACf,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAmB,KAAK,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAMjF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAG3D;;;;;GAKG;AACH,qBAAa,kCAAm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I,EACd,YAAY,IAAI,GAAG,IAAI,EACvB,SAAS,MAAM,GAAG,IAAI,KACpB,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAmDtC,CAAC"}
@@ -387,7 +387,7 @@ export const query_role_grant_offer_sweep_expired = async (deps) => {
387
387
  * the grantor's account row `FOR SHARE` in the accept's transaction: every
388
388
  * write that ends a grantor's global `admin` takes that row first — a revoke of
389
389
  * the grant through `query_account_lock_for_revoke`, a delete through its write
390
- * of the row, a purge through `query_account_lock_admins_for_purge` and
390
+ * of the row, a purge through its last-admin guard and
391
391
  * `query_account_lock_for_purge` — so one that committed first is
392
392
  * seen here (each statement reads afresh), and one that came later waits for
393
393
  * the accept to commit. Twin of the Rust `grantor_holds_global_admin`.
@@ -423,18 +423,17 @@ const query_grantor_holds_global_admin = async (deps, grantor_actor_id) => {
423
423
  * (`query_account_lock_for_offer_accept`), then the offer and the pending
424
424
  * siblings it supersedes in one id-ordered claim, then the grant insert. The
425
425
  * accounts first, as every removal of either account takes them first, so a
426
- * removal and an accept never meet at the offers, the actor, or a grant a
427
- * purge's cascade reaches; two accepts by one recipient take turns. The
428
- * offers in id order, as every transaction that writes several offer rows
429
- * locks them all first in one id-ordered statement (a delete, a purge, a
430
- * revoke, the expiry sweep). The grantor's authority is read unlocked after
431
- * the grantor's account lock — the invariant it rests on: every write that
432
- * ends a grantor's global `admin` takes the grantor's account row first (a
433
- * revoke of the grant through `query_account_lock_for_revoke`, whether or not
434
- * its last-admin guard ran; a delete through its write of the row; a purge
435
- * through `query_account_lock_admins_for_purge` and
436
- * `query_account_lock_for_purge`; the DB browser's delete, which takes none of
437
- * them, excepted).
426
+ * removal and an accept never meet at the offers or the actor; two accepts
427
+ * by one recipient take turns. The offers in id order, as every transaction
428
+ * that writes several offer rows locks them all first in one id-ordered
429
+ * statement (a delete, a purge, a revoke, the expiry sweep). The grantor's
430
+ * authority is read unlocked after the grantor's account lock — the invariant
431
+ * it rests on: every write that ends a grantor's global `admin` takes the
432
+ * grantor's account row first (a revoke of the grant through
433
+ * `query_account_lock_for_revoke`, whether or not its last-admin guard ran; a
434
+ * delete through its write of the row; a purge through its last-admin guard
435
+ * and `query_account_lock_for_purge`; the DB browser's delete, which takes
436
+ * none of them, excepted).
438
437
  *
439
438
  * Error map:
440
439
  * - `RoleGrantOfferNotFoundError` — offer does not exist, or belongs to a
@@ -179,19 +179,26 @@ export declare const query_actor_has_active_global_role: (deps: QueryDeps, actor
179
179
  * removal.
180
180
  *
181
181
  * It does not conflict with a foreign key's `FOR KEY SHARE` — the lock an
182
- * insert or update naming a counted row takes (an accept's new grant naming its
183
- * grantor, a cell's `created_by`). Such a write only adds a reference: it never
182
+ * insert or update naming a counted row takes (a new grant to a counted actor,
183
+ * a cell's `created_by`). Such a write only adds a reference: it never
184
184
  * lowers the count, so the guard fails closed — what it counted is at most what
185
185
  * will stand, and a removal it allows leaves an admin. A purge that deletes a
186
186
  * row such a write names still takes `FOR UPDATE` and waits for it.
187
187
  *
188
- * A purge's cascade writes admin rows too — it sets null the `granted_by` of
189
- * every grant the purged account's actors granted, admins' grants among them,
190
- * in the order its plan walks them — so a purge takes every admin's account
191
- * row first, with its own, in one id-ordered statement
192
- * (`query_account_lock_admins_for_purge`), and runs this count after it only
193
- * when its target is an admin: another guard then waits at its first account
194
- * holding nothing.
188
+ * Both removals, a purge and a delete, run this count when their target is an
189
+ * admin, before any row of the target's (a purge after its advisory lock,
190
+ * `query_account_purge_advisory_lock`), and again once they hold the target's
191
+ * row (a purge's `query_account_lock_for_purge`, a delete's
192
+ * `query_account_lock_live`): whether the target is an admin is read
193
+ * unlocked, and an accept making it one can commit in between, with a revoke
194
+ * it let pass ending every other admin. The second count re-locks only rows
195
+ * the first holds, unless an admin was made in between — the target or
196
+ * another — whose rows it then takes out of id order. A deadlock error then
197
+ * rolls one of the two transactions back whole, removing nothing: the
198
+ * removal, or the other — which may be a removal that would have committed,
199
+ * and answers 500. A purge's cascade writes no other account's admin rows —
200
+ * the provenance stamps a grant names its granter by carry no foreign key —
201
+ * so another guard meets it only at these counts.
195
202
  * Twin of the Rust `query_count_active_accounts_with_global_role_locked`.
196
203
  *
197
204
  * The rows are locked in id order — account, then actor, then grant — as the
@@ -1 +1 @@
1
- {"version":3,"file":"role_grant_queries.d.ts","sourceRoot":"","sources":["../../src/lib/auth/role_grant_queries.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAS3E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAGpE;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,0KAaoB,CAAC;AAcpD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,uBAAuB,GACnC,MAAM,SAAS,EACf,OAAO,oBAAoB,KACzB,OAAO,CAAC,SAAS,CA8CnB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,GAClC,MAAM,SAAS,EACf,IAAI,IAAI,KACN,OAAO,CAAC,SAAS,GAAG,SAAS,CAI9B,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,2CAA2C,GACvD,MAAM,SAAS,EACf,eAAe,MAAM,EACrB,UAAU,MAAM,KACd,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAC;IAAC,UAAU,EAAE,IAAI,CAAA;CAAE,GAAG,IAAI,CAS1E,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,sCAAsC,GAClD,MAAM,SAAS,EACf,UAAU,MAAM,KACd,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAQ1B,CAAC;AAEF;;;;;;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;;;;;;GA4BG;AACH,eAAO,MAAM,iCAAiC,GAC7C,MAAM,SAAS,EACf,UAAU,IAAI,EACd,YAAY,IAAI,GAAG,IAAI,EACvB,SAAS,MAAM,GAAG,IAAI,KACpB,OAAO,CAAC,oBAAoB,CAkD9B,CAAC"}
@@ -283,19 +283,26 @@ export const query_actor_has_active_global_role = async (deps, actor_id, role) =
283
283
  * removal.
284
284
  *
285
285
  * It does not conflict with a foreign key's `FOR KEY SHARE` — the lock an
286
- * insert or update naming a counted row takes (an accept's new grant naming its
287
- * grantor, a cell's `created_by`). Such a write only adds a reference: it never
286
+ * insert or update naming a counted row takes (a new grant to a counted actor,
287
+ * a cell's `created_by`). Such a write only adds a reference: it never
288
288
  * lowers the count, so the guard fails closed — what it counted is at most what
289
289
  * will stand, and a removal it allows leaves an admin. A purge that deletes a
290
290
  * row such a write names still takes `FOR UPDATE` and waits for it.
291
291
  *
292
- * A purge's cascade writes admin rows too — it sets null the `granted_by` of
293
- * every grant the purged account's actors granted, admins' grants among them,
294
- * in the order its plan walks them — so a purge takes every admin's account
295
- * row first, with its own, in one id-ordered statement
296
- * (`query_account_lock_admins_for_purge`), and runs this count after it only
297
- * when its target is an admin: another guard then waits at its first account
298
- * holding nothing.
292
+ * Both removals, a purge and a delete, run this count when their target is an
293
+ * admin, before any row of the target's (a purge after its advisory lock,
294
+ * `query_account_purge_advisory_lock`), and again once they hold the target's
295
+ * row (a purge's `query_account_lock_for_purge`, a delete's
296
+ * `query_account_lock_live`): whether the target is an admin is read
297
+ * unlocked, and an accept making it one can commit in between, with a revoke
298
+ * it let pass ending every other admin. The second count re-locks only rows
299
+ * the first holds, unless an admin was made in between — the target or
300
+ * another — whose rows it then takes out of id order. A deadlock error then
301
+ * rolls one of the two transactions back whole, removing nothing: the
302
+ * removal, or the other — which may be a removal that would have committed,
303
+ * and answers 500. A purge's cascade writes no other account's admin rows —
304
+ * the provenance stamps a grant names its granter by carry no foreign key —
305
+ * so another guard meets it only at these counts.
299
306
  * Twin of the Rust `query_count_active_accounts_with_global_role_locked`.
300
307
  *
301
308
  * The rows are locked in id order — account, then actor, then grant — as the
@@ -1 +1 @@
1
- {"version":3,"file":"self_service_role_actions.d.ts","sourceRoot":"","sources":["../../src/lib/auth/self_service_role_actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAIH,OAAO,EAAuC,KAAK,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAGjG,OAAO,EAKN,KAAK,YAAY,EACjB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AAiB3D;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,oCAAoC,GAAI,OAAO,QAAQ,CAAC,MAAM,CAAC,KAAG,IAW9E,CAAC;AAEF,sDAAsD;AACtD,MAAM,WAAW,6BAA6B;IAC7C;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACvC;;;;OAIG;IACH,KAAK,CAAC,EAAE,YAAY,CAAC;CACrB;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,gCAAgC,GAC5C,MAAM,yBAAyB,EAC/B,UAAS,6BAAkC,KACzC,KAAK,CAAC,SAAS,CAyJjB,CAAC"}
1
+ {"version":3,"file":"self_service_role_actions.d.ts","sourceRoot":"","sources":["../../src/lib/auth/self_service_role_actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAIH,OAAO,EAAuC,KAAK,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAGjG,OAAO,EAKN,KAAK,YAAY,EACjB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AAmB3D;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,oCAAoC,GAAI,OAAO,QAAQ,CAAC,MAAM,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