@fuzdev/fuz_app 0.182.0 → 0.183.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 (191) hide show
  1. package/README.md +2 -0
  2. package/dist/actions/CLAUDE.md +4 -4
  3. package/dist/auth/CLAUDE.md +58 -34
  4. package/dist/auth/account_routes.d.ts +5 -3
  5. package/dist/auth/account_routes.d.ts.map +1 -1
  6. package/dist/auth/account_routes.js +71 -66
  7. package/dist/auth/admin_actions.d.ts.map +1 -1
  8. package/dist/auth/admin_actions.js +22 -17
  9. package/dist/auth/audit_emitter.d.ts +75 -84
  10. package/dist/auth/audit_emitter.d.ts.map +1 -1
  11. package/dist/auth/audit_emitter.js +83 -71
  12. package/dist/auth/audit_log_schema.d.ts +10 -5
  13. package/dist/auth/audit_log_schema.d.ts.map +1 -1
  14. package/dist/auth/audit_log_schema.js +22 -6
  15. package/dist/auth/bootstrap_account.d.ts +31 -13
  16. package/dist/auth/bootstrap_account.d.ts.map +1 -1
  17. package/dist/auth/bootstrap_account.js +34 -15
  18. package/dist/auth/bootstrap_routes.d.ts +1 -1
  19. package/dist/auth/bootstrap_routes.d.ts.map +1 -1
  20. package/dist/auth/bootstrap_routes.js +7 -14
  21. package/dist/auth/deps.d.ts +8 -5
  22. package/dist/auth/deps.d.ts.map +1 -1
  23. package/dist/auth/deps.js +3 -2
  24. package/dist/auth/resolved_auth.d.ts +7 -7
  25. package/dist/auth/resolved_auth.d.ts.map +1 -1
  26. package/dist/auth/resolved_auth.js +4 -4
  27. package/dist/auth/role_grant_offer_actions.d.ts +25 -1
  28. package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
  29. package/dist/auth/role_grant_offer_actions.js +40 -33
  30. package/dist/auth/role_grant_offer_queries.d.ts +60 -4
  31. package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
  32. package/dist/auth/role_grant_offer_queries.js +79 -5
  33. package/dist/auth/role_grant_queries.d.ts +3 -52
  34. package/dist/auth/role_grant_queries.d.ts.map +1 -1
  35. package/dist/auth/role_grant_queries.js +5 -80
  36. package/dist/auth/self_service_role_actions.d.ts.map +1 -1
  37. package/dist/auth/self_service_role_actions.js +11 -22
  38. package/dist/auth/session_queries.d.ts +6 -3
  39. package/dist/auth/session_queries.d.ts.map +1 -1
  40. package/dist/auth/session_queries.js +20 -11
  41. package/dist/auth/signup_routes.d.ts.map +1 -1
  42. package/dist/auth/signup_routes.js +90 -38
  43. package/dist/db/sql_columns.d.ts +1 -1
  44. package/dist/db/sql_columns.js +1 -1
  45. package/dist/http/CLAUDE.md +15 -10
  46. package/dist/http/db_routes.d.ts +7 -22
  47. package/dist/http/db_routes.d.ts.map +1 -1
  48. package/dist/http/db_routes.js +72 -72
  49. package/dist/http/pending_effects.d.ts +42 -4
  50. package/dist/http/pending_effects.d.ts.map +1 -1
  51. package/dist/http/pending_effects.js +34 -4
  52. package/dist/server/app_server.d.ts +43 -2
  53. package/dist/server/app_server.d.ts.map +1 -1
  54. package/dist/server/app_server.js +57 -3
  55. package/dist/testing/CLAUDE.md +255 -786
  56. package/dist/testing/adversarial_404.d.ts +6 -1
  57. package/dist/testing/adversarial_404.d.ts.map +1 -1
  58. package/dist/testing/adversarial_404.js +38 -17
  59. package/dist/testing/app_server.d.ts +20 -140
  60. package/dist/testing/app_server.d.ts.map +1 -1
  61. package/dist/testing/app_server.js +45 -124
  62. package/dist/testing/audit_drift_guard.d.ts +11 -6
  63. package/dist/testing/audit_drift_guard.d.ts.map +1 -1
  64. package/dist/testing/audit_drift_guard.js +15 -8
  65. package/dist/testing/cross_backend/audit_cross_helpers.d.ts +12 -9
  66. package/dist/testing/cross_backend/audit_cross_helpers.d.ts.map +1 -1
  67. package/dist/testing/cross_backend/audit_cross_helpers.js +13 -14
  68. package/dist/testing/cross_backend/capabilities.d.ts +9 -6
  69. package/dist/testing/cross_backend/capabilities.d.ts.map +1 -1
  70. package/dist/testing/cross_backend/capabilities.js +11 -7
  71. package/dist/testing/cross_backend/capability_mounts.d.ts +103 -0
  72. package/dist/testing/cross_backend/capability_mounts.d.ts.map +1 -0
  73. package/dist/testing/cross_backend/capability_mounts.js +423 -0
  74. package/dist/testing/cross_backend/cell_moderate.js +2 -2
  75. package/dist/testing/cross_backend/cell_relations.d.ts.map +1 -1
  76. package/dist/testing/cross_backend/cell_relations.js +12 -11
  77. package/dist/testing/cross_backend/conformance_principal.d.ts +54 -0
  78. package/dist/testing/cross_backend/conformance_principal.d.ts.map +1 -0
  79. package/dist/testing/cross_backend/conformance_principal.js +283 -0
  80. package/dist/testing/cross_backend/conformance_table.d.ts +2 -50
  81. package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
  82. package/dist/testing/cross_backend/conformance_table.js +2 -270
  83. package/dist/testing/cross_backend/credential_deadline.d.ts.map +1 -1
  84. package/dist/testing/cross_backend/credential_deadline.js +2 -0
  85. package/dist/testing/cross_backend/credential_wire.d.ts +1 -1
  86. package/dist/testing/cross_backend/credential_wire.d.ts.map +1 -1
  87. package/dist/testing/cross_backend/db_state_diff.d.ts +72 -0
  88. package/dist/testing/cross_backend/db_state_diff.d.ts.map +1 -0
  89. package/dist/testing/cross_backend/db_state_diff.js +444 -0
  90. package/dist/testing/cross_backend/declared_skips.d.ts +68 -0
  91. package/dist/testing/cross_backend/declared_skips.d.ts.map +1 -0
  92. package/dist/testing/cross_backend/declared_skips.js +132 -0
  93. package/dist/testing/cross_backend/differential.d.ts +11 -2
  94. package/dist/testing/cross_backend/differential.d.ts.map +1 -1
  95. package/dist/testing/cross_backend/differential.js +35 -11
  96. package/dist/testing/cross_backend/differential_normalize.d.ts +12 -0
  97. package/dist/testing/cross_backend/differential_normalize.d.ts.map +1 -1
  98. package/dist/testing/cross_backend/differential_normalize.js +16 -0
  99. package/dist/testing/cross_backend/in_process_setup.d.ts +22 -12
  100. package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
  101. package/dist/testing/cross_backend/in_process_setup.js +151 -134
  102. package/dist/testing/cross_backend/login_security.d.ts +12 -0
  103. package/dist/testing/cross_backend/login_security.d.ts.map +1 -1
  104. package/dist/testing/cross_backend/login_security.js +21 -4
  105. package/dist/testing/cross_backend/request_target_conformance_wire.d.ts +0 -2
  106. package/dist/testing/cross_backend/request_target_conformance_wire.d.ts.map +1 -1
  107. package/dist/testing/cross_backend/request_target_conformance_wire.js +3 -1
  108. package/dist/testing/cross_backend/revocation_drivers.d.ts +18 -5
  109. package/dist/testing/cross_backend/revocation_drivers.d.ts.map +1 -1
  110. package/dist/testing/cross_backend/revocation_drivers.js +18 -10
  111. package/dist/testing/cross_backend/role_grant_cross_helpers.d.ts +1 -1
  112. package/dist/testing/cross_backend/role_grant_cross_helpers.d.ts.map +1 -1
  113. package/dist/testing/cross_backend/role_grant_offer_lifecycle.d.ts.map +1 -1
  114. package/dist/testing/cross_backend/role_grant_offer_lifecycle.js +33 -1
  115. package/dist/testing/cross_backend/role_grant_participation.js +4 -4
  116. package/dist/testing/cross_backend/rpc_adversarial.js +1 -1
  117. package/dist/testing/cross_backend/session_cap.d.ts +2 -2
  118. package/dist/testing/cross_backend/session_cap.d.ts.map +1 -1
  119. package/dist/testing/cross_backend/session_cap.js +22 -11
  120. package/dist/testing/cross_backend/setup.d.ts +31 -1
  121. package/dist/testing/cross_backend/setup.d.ts.map +1 -1
  122. package/dist/testing/cross_backend/setup.js +32 -1
  123. package/dist/testing/cross_backend/spine_suites.d.ts +123 -12
  124. package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
  125. package/dist/testing/cross_backend/spine_suites.js +454 -57
  126. package/dist/testing/cross_backend/spine_surface_constants.d.ts +1 -1
  127. package/dist/testing/cross_backend/spine_surface_constants.d.ts.map +1 -1
  128. package/dist/testing/cross_backend/spine_surface_constants.js +1 -0
  129. package/dist/testing/cross_backend/sse_round_trip.d.ts +9 -1
  130. package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
  131. package/dist/testing/cross_backend/sse_round_trip.js +123 -27
  132. package/dist/testing/cross_backend/testing_backdoor.d.ts.map +1 -1
  133. package/dist/testing/cross_backend/testing_backdoor.js +4 -2
  134. package/dist/testing/cross_backend/testing_reset_actions.d.ts +59 -27
  135. package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
  136. package/dist/testing/cross_backend/testing_reset_actions.js +66 -42
  137. package/dist/testing/cross_backend/transport_composition.d.ts +1 -1
  138. package/dist/testing/cross_backend/transport_composition.d.ts.map +1 -1
  139. package/dist/testing/cross_backend/transport_composition.js +7 -3
  140. package/dist/testing/cross_backend/ws_round_trip.d.ts +5 -0
  141. package/dist/testing/cross_backend/ws_round_trip.d.ts.map +1 -1
  142. package/dist/testing/cross_backend/ws_round_trip.js +54 -8
  143. package/dist/testing/data_exposure.d.ts.map +1 -1
  144. package/dist/testing/data_exposure.js +3 -0
  145. package/dist/testing/db.d.ts +0 -32
  146. package/dist/testing/db.d.ts.map +1 -1
  147. package/dist/testing/db.js +0 -86
  148. package/dist/testing/db_entities.d.ts +14 -0
  149. package/dist/testing/db_entities.d.ts.map +1 -1
  150. package/dist/testing/db_entities.js +17 -0
  151. package/dist/testing/db_invariant_queries.d.ts +259 -0
  152. package/dist/testing/db_invariant_queries.d.ts.map +1 -0
  153. package/dist/testing/db_invariant_queries.js +400 -0
  154. package/dist/testing/db_invariants.d.ts +106 -0
  155. package/dist/testing/db_invariants.d.ts.map +1 -0
  156. package/dist/testing/db_invariants.gen.sql.d.ts +11 -0
  157. package/dist/testing/db_invariants.gen.sql.d.ts.map +1 -0
  158. package/dist/testing/db_invariants.gen.sql.js +13 -0
  159. package/dist/testing/db_invariants.js +141 -0
  160. package/dist/testing/db_invariants.sql +152 -0
  161. package/dist/testing/describe_db.d.ts +36 -0
  162. package/dist/testing/describe_db.d.ts.map +1 -0
  163. package/dist/testing/describe_db.js +71 -0
  164. package/dist/testing/integration.d.ts +6 -9
  165. package/dist/testing/integration.d.ts.map +1 -1
  166. package/dist/testing/integration.js +9 -13
  167. package/dist/testing/integration_helpers.d.ts +1 -1
  168. package/dist/testing/integration_helpers.d.ts.map +1 -1
  169. package/dist/testing/rate_limiting.d.ts +1 -1
  170. package/dist/testing/rate_limiting.d.ts.map +1 -1
  171. package/dist/testing/rate_limiting.js +3 -2
  172. package/dist/testing/role_grant_helpers.d.ts +1 -1
  173. package/dist/testing/role_grant_helpers.d.ts.map +1 -1
  174. package/dist/testing/round_trip.d.ts.map +1 -1
  175. package/dist/testing/round_trip.js +3 -0
  176. package/dist/testing/rpc_attack_surface.d.ts +8 -6
  177. package/dist/testing/rpc_attack_surface.d.ts.map +1 -1
  178. package/dist/testing/rpc_attack_surface.js +69 -6
  179. package/dist/testing/rpc_round_trip.d.ts +1 -1
  180. package/dist/testing/rpc_round_trip.d.ts.map +1 -1
  181. package/dist/testing/rpc_round_trip.js +3 -0
  182. package/dist/testing/sse_round_trip.d.ts +1 -1
  183. package/dist/testing/sse_round_trip.d.ts.map +1 -1
  184. package/dist/testing/sse_round_trip.js +13 -4
  185. package/dist/testing/stubs.d.ts +4 -2
  186. package/dist/testing/stubs.d.ts.map +1 -1
  187. package/dist/testing/stubs.js +10 -5
  188. package/dist/testing/test_app.d.ts +166 -0
  189. package/dist/testing/test_app.d.ts.map +1 -0
  190. package/dist/testing/test_app.js +124 -0
  191. package/package.json +1 -1
@@ -62,13 +62,44 @@ import { queue_connection_close } from '../actions/connection_closer.js';
62
62
  import { builtin_role_specs, is_builtin_role, ROLE_ADMIN, ROLE_KEEPER, role_has_grant_path } from './role_schema.js';
63
63
  import { GRANT_PATH_ADMIN } from './grant_path_schema.js';
64
64
  import { ROLE_GRANT_OFFER_DEFAULT_TTL_MS, to_role_grant_offer_json } from './role_grant_offer_schema.js';
65
- import { query_role_grant_offer_create, query_role_grant_offer_decline, query_role_grant_offer_retract, query_role_grant_offer_list, query_role_grant_offer_history_for_account, query_accept_offer, RoleGrantOfferActorAccountMismatchError, RoleGrantOfferActorMismatchError, RoleGrantOfferGrantorNotActiveError, RoleGrantOfferRecipientNotActiveError, RoleGrantOfferAlreadyTerminalError, RoleGrantOfferBuiltinRefusedError, RoleGrantOfferExpiredError, RoleGrantOfferNotFoundError, RoleGrantOfferSelfTargetError, query_role_grant_offer_lock_for_revoke, query_role_grant_offer_supersede_outgoing } from './role_grant_offer_queries.js';
66
- import { query_account_has_active_global_role, query_account_has_global_role, query_count_active_accounts_with_global_role_locked, query_create_role_grant, query_role_grant_find_active_role_for_actor, query_revoke_role_grant } from './role_grant_queries.js';
67
- import { query_account_lock_for_revoke, query_active_actors_by_account } from './account_queries.js';
65
+ import { query_role_grant_offer_create, query_role_grant_offer_decline, query_role_grant_offer_retract, query_role_grant_offer_list, query_role_grant_offer_history_for_account, query_accept_offer, RoleGrantOfferActorAccountMismatchError, RoleGrantOfferActorMismatchError, RoleGrantOfferGrantorNotActiveError, RoleGrantOfferRecipientNotActiveError, RoleGrantOfferAlreadyTerminalError, RoleGrantOfferBuiltinRefusedError, RoleGrantOfferExpiredError, RoleGrantOfferNotFoundError, RoleGrantOfferSelfTargetError, query_revoke_role_grant } from './role_grant_offer_queries.js';
66
+ import { query_account_has_active_global_role, query_account_has_global_role, query_count_active_accounts_with_global_role_locked, query_create_role_grant, query_role_grant_find_active_role_for_actor } from './role_grant_queries.js';
67
+ import { query_active_actors_by_account } from './account_queries.js';
68
68
  import { has_scoped_role } from './request_context.js';
69
69
  import { build_role_grant_offer_accepted_notification, build_role_grant_offer_declined_notification, build_role_grant_offer_received_notification, build_role_grant_offer_retracted_notification, build_role_grant_revoked_notification, queue_offer_notification, queue_supersede_notifications } from './role_grant_offer_notifications.js';
70
70
  import { ERROR_AUTHENTICATION_REQUIRED, ERROR_INSUFFICIENT_PERMISSIONS, ERROR_ROLE_GRANT_NOT_FOUND, ERROR_ROLE_NOT_WEB_GRANTABLE } from '../http/error_schemas.js';
71
71
  import { ERROR_CANNOT_REVOKE_KEEPER_ADMIN, ERROR_CANNOT_REVOKE_LAST_ADMIN, ERROR_ROLE_GRANT_BUILTIN_SCOPED, ERROR_ROLE_GRANT_OFFER_ACTOR_ACCOUNT_MISMATCH, ERROR_ROLE_GRANT_OFFER_ACTOR_MISMATCH, ERROR_ROLE_GRANT_OFFER_EXPIRED, ERROR_ROLE_GRANT_OFFER_NOT_AUTHORIZED, ERROR_ROLE_GRANT_OFFER_NOT_FOUND, ERROR_ROLE_GRANT_OFFER_ROLE_NOT_GRANTABLE, ERROR_ROLE_GRANT_OFFER_SELF_TARGET, ERROR_ROLE_GRANT_OFFER_TERMINAL, role_grant_offer_create_action_spec, role_grant_offer_accept_action_spec, role_grant_offer_decline_action_spec, role_grant_offer_retract_action_spec, role_grant_offer_list_action_spec, role_grant_offer_history_action_spec, role_grant_revoke_action_spec, role_grant_assign_action_spec } from './role_grant_offer_action_specs.js';
72
+ /**
73
+ * Emit one `role_grant_offer_supersede` audit row per offer a cascade ended —
74
+ * the revokes (`role_grant_revoke` and the self-service disable, both
75
+ * `'role_grant_revoked'` with the revoked grant as `cause_id`) and account
76
+ * removal (`'account_deleted'`, the removed account). The acting pair is the
77
+ * caller's; the target pair is the offer's recipient (`to_account_id`, and
78
+ * `to_actor_id` when the offer named an actor). Twin of the Rust
79
+ * `emit_supersede_audits`.
80
+ *
81
+ * @param ctx - the handler context; the rows are the caller's
82
+ * @param audit - the emitter
83
+ * @param superseded - the offers the cascade ended
84
+ * @param reason - why they were superseded
85
+ * @param cause_id - the row that caused it
86
+ */
87
+ export const emit_supersede_audits = async (ctx, audit, superseded, reason, cause_id) => {
88
+ for (const offer of superseded) {
89
+ await audit.emit_role_grant_target(ctx, ctx.auth, {
90
+ event_type: 'role_grant_offer_supersede',
91
+ target_account_id: offer.to_account_id,
92
+ target_actor_id: offer.to_actor_id,
93
+ metadata: {
94
+ offer_id: offer.id,
95
+ role: offer.role,
96
+ scope_id: offer.scope_id,
97
+ reason,
98
+ cause_id
99
+ }
100
+ });
101
+ }
102
+ };
72
103
  // -- Helpers ----------------------------------------------------------------
73
104
  /**
74
105
  * Fan out a batch of pre-written audit rows to the bound emitter's
@@ -512,24 +543,16 @@ export const create_role_grant_offer_actions = (deps, options = {}) => {
512
543
  });
513
544
  }
514
545
  }
515
- // The revokee's account row, then every offer the revoke supersedes — the
516
- // revokee's incoming siblings and its outgoing offers — in one statement in
517
- // id order, before the grant is touched (`query_account_lock_for_revoke`
518
- // and `query_role_grant_offer_lock_for_revoke` have why). After the guard,
519
- // which holds an admin revokee's row already.
520
- await query_account_lock_for_revoke(ctx, input.actor_id);
521
- await query_role_grant_offer_lock_for_revoke(ctx, input.actor_id, role_grant_row.role, role_grant_row.scope_id);
546
+ // The revoke ends the revokee's incoming siblings and every offer its
547
+ // actor made, taking the revokee's account row and then those offers
548
+ // before the grant (`query_revoke_role_grant` has the order). After the
549
+ // guard, which holds an admin revokee's row already.
522
550
  const result = await query_revoke_role_grant(ctx, input.role_grant_id, input.actor_id, auth.actor.id, input.reason ?? null);
523
551
  if (!result) {
524
552
  // Raced with another revoker or the role_grant was revoked between
525
553
  // the IDOR check and the UPDATE.
526
554
  throw jsonrpc_errors.not_found('role_grant', { reason: ERROR_ROLE_GRANT_NOT_FOUND });
527
555
  }
528
- // The revokee's own pending offers end with the grant: an offer records
529
- // no authority, so one made under this grant would still confer on
530
- // accept. Every outgoing offer of the actor goes, superseded like the
531
- // revokee's incoming siblings (same reason, same cause, same fan-out).
532
- result.superseded_offers.push(...(await query_role_grant_offer_supersede_outgoing(ctx, [input.actor_id])));
533
556
  // Close the revokee's connections gated on the role once the revoke has
534
557
  // committed — queued, so never before the commit or on rollback, and not
535
558
  // riding on the audit row's announcement below (the revocation guard
@@ -553,24 +576,8 @@ export const create_role_grant_offer_actions = (deps, options = {}) => {
553
576
  reason: input.reason ?? undefined
554
577
  }
555
578
  });
556
- // Supersede cascade — the recipient is known (`offer.to_account_id`),
557
- // so populate `target_account_id` rather than leaving it null;
558
- // `target_actor_id` inherits the offer's `to_actor_id` (actor-grain
559
- // when the superseded offer was actor-targeted, null otherwise).
560
- for (const offer of result.superseded_offers) {
561
- await audit.emit_role_grant_target(ctx, auth, {
562
- event_type: 'role_grant_offer_supersede',
563
- target_account_id: offer.to_account_id,
564
- target_actor_id: offer.to_actor_id,
565
- metadata: {
566
- offer_id: offer.id,
567
- role: offer.role,
568
- scope_id: offer.scope_id,
569
- reason: 'role_grant_revoked',
570
- cause_id: result.id
571
- }
572
- });
573
- }
579
+ // Supersede cascade — one row per offer the revoke ended.
580
+ await emit_supersede_audits(ctx, audit, result.superseded_offers, 'role_grant_revoked', result.id);
574
581
  queue_offer_notification(ctx, target_account_id, build_role_grant_revoked_notification({
575
582
  role_grant_id: result.id,
576
583
  role: result.role,
@@ -355,9 +355,9 @@ export declare const query_accept_offer: (deps: QueryDeps, input: AcceptOfferInp
355
355
  *
356
356
  * An offer carries no record of the authority it was made under, so one
357
357
  * outliving that authority would still confer its role on accept. Revoking a
358
- * grant (`role_grant_revoke`, the revokee's actor) and removing an account
359
- * (`account_delete` / `account_purge`, every actor of the account) end the
360
- * grantor's outgoing pending offers in the same transaction. Each row carries
358
+ * grant (`query_revoke_role_grant`, the revokee's actor) and removing an
359
+ * account (`account_delete` / `account_purge`, every actor of the account) end
360
+ * the grantor's outgoing pending offers in the same transaction. Each row carries
361
361
  * the grantor's `from_account_id`, as every supersede cascade's does; the
362
362
  * caller emits a `role_grant_offer_supersede` audit event per entry and
363
363
  * queues its notifications (`queue_supersede_notifications`). The rows are
@@ -415,7 +415,7 @@ export declare const query_role_grant_offer_supersede_incoming: (deps: QueryDeps
415
415
  */
416
416
  export declare const query_role_grant_offer_lock_for_account_removal: (deps: QueryDeps, to_account_id: Uuid, from_actor_ids: ReadonlyArray<Uuid>) => Promise<void>;
417
417
  /**
418
- * Lock every pending offer `role_grant_revoke` supersedes — the revokee
418
+ * Lock every pending offer a revoke supersedes (`query_revoke_role_grant`) — the revokee
419
419
  * account's incoming offers of the revoked grant's role and scope, and every
420
420
  * offer the revokee's actor made — in one statement, in id order.
421
421
  *
@@ -435,4 +435,60 @@ export declare const query_role_grant_offer_lock_for_account_removal: (deps: Que
435
435
  * @mutates `role_grant_offer` rows - row-locks the pending offers the revoke supersedes
436
436
  */
437
437
  export declare const query_role_grant_offer_lock_for_revoke: (deps: QueryDeps, actor_id: Uuid, role: string, scope_id: Uuid | null) => Promise<void>;
438
+ /** Result of `query_revoke_role_grant` — the revoked role_grant plus every pending offer the revoke superseded. */
439
+ export interface RevokeRoleGrantResult {
440
+ id: Uuid;
441
+ role: string;
442
+ scope_kind: string | null;
443
+ scope_id: Uuid | null;
444
+ /**
445
+ * The pending offers the revoke ended: the revokee account's incoming
446
+ * offers of the revoked grant's `(role, scope)`, then every offer the
447
+ * revokee's actor made. Each entry carries its grantor's `from_account_id`
448
+ * so callers can fan out `role_grant_offer_supersede` notifications without
449
+ * a second round-trip. The caller emits a `role_grant_offer_supersede`
450
+ * audit event per entry (with `reason: 'role_grant_revoked'` and
451
+ * `cause_id: <revoked role_grant id>`) and queues its notifications
452
+ * (`queue_supersede_notifications`).
453
+ */
454
+ superseded_offers: Array<SupersededOffer>;
455
+ }
456
+ /**
457
+ * Revoke a role_grant by id, constrained to a specific actor, and end the
458
+ * pending offers the grant stood behind — the one supersede rule every revoke
459
+ * follows, the admin `role_grant_revoke`, a self-service disable, and a
460
+ * consumer's direct call alike.
461
+ *
462
+ * Requires `actor_id` to prevent cross-account revocation (IDOR guard).
463
+ * Returns `null` if the role_grant is not found, already revoked, or belongs
464
+ * to a different actor.
465
+ *
466
+ * Two sets of offers end with the grant, in the same transaction:
467
+ *
468
+ * - the revokee account's pending offers of the grant's `(role, scope)` — an
469
+ * offer accepted after the revoke would hand the role straight back;
470
+ * - every pending offer the revokee's actor made, whatever its role — an
471
+ * offer records no authority, so one made under this grant would still
472
+ * confer on accept.
473
+ *
474
+ * Locks follow the class order (accounts, then offers, then grants): the
475
+ * revokee's account row (`query_account_lock_for_revoke`), which keeps any new
476
+ * offer to or from the account out and any accept by it waiting, then both
477
+ * sets of offers in one id-ordered statement
478
+ * (`query_role_grant_offer_lock_for_revoke`), then the grant's update — an
479
+ * accept claims its offers before it inserts its grant, and that insert waits
480
+ * on an uncommitted update of the same grant, so the grant first and the
481
+ * offers second would close a cycle. The two supersedes then write only rows
482
+ * the transaction holds. Twin of the Rust
483
+ * `fuz_auth::role_grant_offer_queries::query_revoke_role_grant`.
484
+ *
485
+ * @param deps - query dependencies (must be the revoke's transaction)
486
+ * @param role_grant_id - the role_grant to revoke
487
+ * @param actor_id - the actor that must own the role_grant
488
+ * @param revoked_by - the actor who revoked it (for audit trail)
489
+ * @param reason - optional free-form reason, stamped on `role_grant.revoked_reason` and surfaced to the revokee notification.
490
+ * @mutates `role_grant` row - sets `revoked_at`, `revoked_by`, and `revoked_reason`
491
+ * @mutates `role_grant_offer` rows - stamps `superseded_at` on every pending incoming sibling for the same `(account, role, scope)` and every pending offer from `actor_id`
492
+ */
493
+ export declare const query_revoke_role_grant: (deps: QueryDeps, role_grant_id: Uuid, actor_id: Uuid, revoked_by: Uuid | null, reason?: string | null) => Promise<RevokeRoleGrantResult | null>;
438
494
  //# sourceMappingURL=role_grant_offer_queries.d.ts.map
@@ -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;AAMtC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAG3D;;;;;GAKG;AACH,qBAAa,kCAAmC,SAAQ,KAAK;gBAChD,QAAQ,EAAE,MAAM;CAI5B;AAED;;;;;GAKG;AACH,qB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MAAM,kBAAkB,GAC9B,MAAM,SAAS,EACf,OAAO,gBAAgB,KACrB,OAAO,CAAC,iBAAiB,CA8R3B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,yCAAyC,GACrD,MAAM,SAAS,EACf,gBAAgB,aAAa,CAAC,IAAI,CAAC,KACjC,OAAO,CAAC,KAAK,CAAC,eAAe,CAAC,CAgBhC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,yCAAyC,GACrD,MAAM,SAAS,EACf,eAAe,IAAI,KACjB,OAAO,CAAC,KAAK,CAAC,eAAe,CAAC,CAehC,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,+CAA+C,GAC3D,MAAM,SAAS,EACf,eAAe,IAAI,EACnB,gBAAgB,aAAa,CAAC,IAAI,CAAC,KACjC,OAAO,CAAC,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"}
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,kCA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I,EACd,YAAY,IAAI,GAAG,IAAI,EACvB,SAAS,MAAM,GAAG,IAAI,KACpB,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAmDtC,CAAC"}
@@ -17,7 +17,7 @@ import { ROLE_GRANT_OFFER_COLUMNS, role_grant_offer_expr, ROLE_GRANT_OFFER_SCOPE
17
17
  import { query_create_role_grant, query_role_grant_by_id } from './role_grant_queries.js';
18
18
  import { offer_pending_predicate, offer_rows_locked_in_id_order, role_grant_active_sql } from './role_grant_sql.js';
19
19
  import { query_audit_log } from './audit_log_queries.js';
20
- import { query_account_lock_for_offer_accept, query_account_lock_live_many } from './account_queries.js';
20
+ import { query_account_lock_for_offer_accept, query_account_lock_for_revoke, query_account_lock_live_many } from './account_queries.js';
21
21
  import { is_builtin_role, ROLE_ADMIN, ROLE_KEEPER } from './role_schema.js';
22
22
  /**
23
23
  * Error thrown by offer-lifecycle queries when the offer is in a non-pending
@@ -717,9 +717,9 @@ export const query_accept_offer = async (deps, input) => {
717
717
  *
718
718
  * An offer carries no record of the authority it was made under, so one
719
719
  * outliving that authority would still confer its role on accept. Revoking a
720
- * grant (`role_grant_revoke`, the revokee's actor) and removing an account
721
- * (`account_delete` / `account_purge`, every actor of the account) end the
722
- * grantor's outgoing pending offers in the same transaction. Each row carries
720
+ * grant (`query_revoke_role_grant`, the revokee's actor) and removing an
721
+ * account (`account_delete` / `account_purge`, every actor of the account) end
722
+ * the grantor's outgoing pending offers in the same transaction. Each row carries
723
723
  * the grantor's `from_account_id`, as every supersede cascade's does; the
724
724
  * caller emits a `role_grant_offer_supersede` audit event per entry and
725
725
  * queues its notifications (`queue_supersede_notifications`). The rows are
@@ -803,7 +803,7 @@ export const query_role_grant_offer_lock_for_account_removal = async (deps, to_a
803
803
  FOR UPDATE`, [to_account_id, from_actor_ids]);
804
804
  };
805
805
  /**
806
- * Lock every pending offer `role_grant_revoke` supersedes — the revokee
806
+ * Lock every pending offer a revoke supersedes (`query_revoke_role_grant`) — the revokee
807
807
  * account's incoming offers of the revoked grant's role and scope, and every
808
808
  * offer the revokee's actor made — in one statement, in id order.
809
809
  *
@@ -831,3 +831,77 @@ export const query_role_grant_offer_lock_for_revoke = async (deps, actor_id, rol
831
831
  ORDER BY id
832
832
  FOR UPDATE`, [actor_id, role, scope_id]);
833
833
  };
834
+ /**
835
+ * Revoke a role_grant by id, constrained to a specific actor, and end the
836
+ * pending offers the grant stood behind — the one supersede rule every revoke
837
+ * follows, the admin `role_grant_revoke`, a self-service disable, and a
838
+ * consumer's direct call alike.
839
+ *
840
+ * Requires `actor_id` to prevent cross-account revocation (IDOR guard).
841
+ * Returns `null` if the role_grant is not found, already revoked, or belongs
842
+ * to a different actor.
843
+ *
844
+ * Two sets of offers end with the grant, in the same transaction:
845
+ *
846
+ * - the revokee account's pending offers of the grant's `(role, scope)` — an
847
+ * offer accepted after the revoke would hand the role straight back;
848
+ * - every pending offer the revokee's actor made, whatever its role — an
849
+ * offer records no authority, so one made under this grant would still
850
+ * confer on accept.
851
+ *
852
+ * Locks follow the class order (accounts, then offers, then grants): the
853
+ * revokee's account row (`query_account_lock_for_revoke`), which keeps any new
854
+ * offer to or from the account out and any accept by it waiting, then both
855
+ * sets of offers in one id-ordered statement
856
+ * (`query_role_grant_offer_lock_for_revoke`), then the grant's update — an
857
+ * accept claims its offers before it inserts its grant, and that insert waits
858
+ * on an uncommitted update of the same grant, so the grant first and the
859
+ * offers second would close a cycle. The two supersedes then write only rows
860
+ * the transaction holds. Twin of the Rust
861
+ * `fuz_auth::role_grant_offer_queries::query_revoke_role_grant`.
862
+ *
863
+ * @param deps - query dependencies (must be the revoke's transaction)
864
+ * @param role_grant_id - the role_grant to revoke
865
+ * @param actor_id - the actor that must own the role_grant
866
+ * @param revoked_by - the actor who revoked it (for audit trail)
867
+ * @param reason - optional free-form reason, stamped on `role_grant.revoked_reason` and surfaced to the revokee notification.
868
+ * @mutates `role_grant` row - sets `revoked_at`, `revoked_by`, and `revoked_reason`
869
+ * @mutates `role_grant_offer` rows - stamps `superseded_at` on every pending incoming sibling for the same `(account, role, scope)` and every pending offer from `actor_id`
870
+ */
871
+ export const query_revoke_role_grant = async (deps, role_grant_id, actor_id, revoked_by, reason) => {
872
+ await query_account_lock_for_revoke(deps, actor_id);
873
+ // the role and scope name the offers to lock; written once with the grant
874
+ const target = await deps.db.query_one(`SELECT role, scope_id FROM role_grant WHERE id = $1 AND actor_id = $2 AND revoked_at IS NULL`, [role_grant_id, actor_id]);
875
+ if (!target)
876
+ return null;
877
+ await query_role_grant_offer_lock_for_revoke(deps, actor_id, target.role, target.scope_id);
878
+ const rows = await deps.db.query(`UPDATE role_grant SET revoked_at = NOW(), revoked_by = $3, revoked_reason = $4
879
+ WHERE id = $1 AND actor_id = $2 AND revoked_at IS NULL
880
+ RETURNING id, role, scope_kind, scope_id`, [role_grant_id, actor_id, revoked_by ?? null, reason ?? null]);
881
+ const revoked = rows[0];
882
+ if (!revoked)
883
+ return null;
884
+ // CTE joins `actor` after the UPDATE so each superseded row carries the
885
+ // grantor's `account_id` — callers fan out `role_grant_offer_supersede`
886
+ // notifications to that account without a second round-trip. The match
887
+ // keys on `scope_id` only because the (scope_kind, scope_id) pair-CHECK
888
+ // makes scope_kind a function of scope_id; matching on both adds no
889
+ // new selectivity in v1.
890
+ const incoming = await deps.db.query(`WITH updated AS (
891
+ UPDATE role_grant_offer o
892
+ SET superseded_at = NOW()
893
+ WHERE ${offer_rows_locked_in_id_order('o', `to_account_id = (SELECT account_id FROM actor WHERE id = $1)
894
+ AND role = $2 AND scope_id IS NOT DISTINCT FROM $3 AND ${offer_pending_predicate('')}`)}
895
+ -- raw columns; the outer grantor select formats them
896
+ RETURNING ${qualify_columns(ROLE_GRANT_OFFER_COLUMNS, 'o')}
897
+ )
898
+ ${ROLE_GRANT_OFFER_WITH_GRANTOR_SELECT}`, [actor_id, revoked.role, revoked.scope_id]);
899
+ const outgoing = await query_role_grant_offer_supersede_outgoing(deps, [actor_id]);
900
+ return {
901
+ id: revoked.id,
902
+ role: revoked.role,
903
+ scope_kind: revoked.scope_kind,
904
+ scope_id: revoked.scope_id,
905
+ superseded_offers: [...incoming, ...outgoing]
906
+ };
907
+ };
@@ -85,59 +85,10 @@ export declare const query_role_grant_find_active_role_for_actor: (deps: QueryDe
85
85
  scope_id: Uuid | null;
86
86
  account_id: Uuid;
87
87
  } | null>;
88
- /** Result of `query_revoke_role_grant` — the revoked role_grant plus any pending offers superseded by the revoke. */
89
- export interface RevokeRoleGrantResult {
90
- id: Uuid;
91
- role: string;
92
- scope_kind: string | null;
93
- scope_id: Uuid | null;
94
- /**
95
- * Pending offers for the revoked role_grant's `(account, role, scope)` that
96
- * were marked superseded as a side effect. Each entry carries its
97
- * grantor's `from_account_id` so callers can fan out
98
- * `role_grant_offer_supersede` notifications without a second round-trip.
99
- * The caller is responsible for emitting a `role_grant_offer_supersede`
100
- * audit event per entry (with `reason: 'role_grant_revoked'` and
101
- * `cause_id: <revoked role_grant id>`).
102
- */
103
- superseded_offers: Array<SupersededOffer>;
104
- }
105
- /**
106
- * Revoke a role_grant by id, constrained to a specific actor.
107
- *
108
- * Requires `actor_id` to prevent cross-account revocation (IDOR guard).
109
- * Returns `null` if the role_grant is not found, already revoked, or belongs
110
- * to a different actor.
111
- *
112
- * Supersedes any pending offers for the revoked role_grant's
113
- * `(to_account, role, scope)` in the same transaction. Prevents the
114
- * "accept a pre-revoke offer to bypass the revoke" path — any stale
115
- * offer becomes terminal at revoke time. A fresh post-revoke grant
116
- * requires the grantor to call `query_role_grant_offer_create` again.
117
- *
118
- * The revokee's account row is locked first (`FOR NO KEY UPDATE`, the lock
119
- * `query_account_lock_for_revoke` takes), so no offer to or from the account is
120
- * made, and none accepted, while the revoke runs: the offers it locks are the
121
- * offers it writes. Then those offers, in id order, before the grant is
122
- * updated: an accept claims its offers before it inserts its grant, and that
123
- * insert waits on an uncommitted update of the same grant, so the grant first
124
- * and the offers second would close a cycle with it. A caller that supersedes
125
- * the revokee's outgoing offers too (`role_grant_revoke`) takes the account row
126
- * and then every offer it writes in one statement first
127
- * (`query_role_grant_offer_lock_for_revoke`); the locks here then find rows
128
- * the transaction already holds.
129
- *
130
- * @param deps - query dependencies
131
- * @param role_grant_id - the role_grant to revoke
132
- * @param actor_id - the actor that must own the role_grant
133
- * @param revoked_by - the actor who revoked it (for audit trail)
134
- * @param reason - optional free-form reason, stamped on `role_grant.revoked_reason` and surfaced to the revokee notification.
135
- * @mutates `role_grant` row - sets `revoked_at`, `revoked_by`, and `revoked_reason`
136
- * @mutates `role_grant_offer` rows - stamps `superseded_at` on every pending sibling for the same `(account, role, scope)`
137
- */
138
- export declare const query_revoke_role_grant: (deps: QueryDeps, role_grant_id: Uuid, actor_id: Uuid, revoked_by: Uuid | null, reason?: string | null) => Promise<RevokeRoleGrantResult | null>;
139
88
  /**
140
- * Find all active (non-revoked, non-expired) role_grants for an actor.
89
+ * Find all active (non-revoked, non-expired) role_grants for an actor, oldest
90
+ * first, grants of one instant (bootstrap's keeper and admin) by role, scope
91
+ * and id — the admin account list's order, and the Rust twin's.
141
92
  */
142
93
  export declare const query_role_grant_find_active_for_actor: (deps: QueryDeps, actor_id: string) => Promise<Array<RoleGrant>>;
143
94
  /**
@@ -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;AAOpE;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,0KAaoB,CAAC;AAcpD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,uBAAuB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GAAG,IAAI,KACpB,OAAO,CAAC,oBAAoB,CAkD9B,CAAC"}
@@ -9,7 +9,7 @@
9
9
  import { assert_row } from '../db/assert_row.js';
10
10
  import { columns_sql, iso8601_timestamp_expr, qualify_columns } from '../db/sql_columns.js';
11
11
  import { ROLE_GRANT_OFFER_COLUMNS, ROLE_GRANT_OFFER_SCOPE_KIND_GLOBAL_TOKEN, ROLE_GRANT_OFFER_SCOPE_SENTINEL_UUID, ROLE_GRANT_OFFER_WITH_GRANTOR_SELECT } from './role_grant_offer_ddl.js';
12
- import { offer_pending_predicate, offer_rows_locked_in_id_order, role_grant_active_sql } from './role_grant_sql.js';
12
+ import { offer_pending_predicate, role_grant_active_sql } from './role_grant_sql.js';
13
13
  /**
14
14
  * The full `role_grant` column set, named explicitly so a row read fails loud
15
15
  * on schema drift (see `ACCOUNT_COLUMNS` in `auth/account_queries.ts` for the
@@ -150,90 +150,15 @@ export const query_role_grant_find_active_role_for_actor = async (deps, role_gra
150
150
  return row ?? null;
151
151
  };
152
152
  /**
153
- * Revoke a role_grant by id, constrained to a specific actor.
154
- *
155
- * Requires `actor_id` to prevent cross-account revocation (IDOR guard).
156
- * Returns `null` if the role_grant is not found, already revoked, or belongs
157
- * to a different actor.
158
- *
159
- * Supersedes any pending offers for the revoked role_grant's
160
- * `(to_account, role, scope)` in the same transaction. Prevents the
161
- * "accept a pre-revoke offer to bypass the revoke" path — any stale
162
- * offer becomes terminal at revoke time. A fresh post-revoke grant
163
- * requires the grantor to call `query_role_grant_offer_create` again.
164
- *
165
- * The revokee's account row is locked first (`FOR NO KEY UPDATE`, the lock
166
- * `query_account_lock_for_revoke` takes), so no offer to or from the account is
167
- * made, and none accepted, while the revoke runs: the offers it locks are the
168
- * offers it writes. Then those offers, in id order, before the grant is
169
- * updated: an accept claims its offers before it inserts its grant, and that
170
- * insert waits on an uncommitted update of the same grant, so the grant first
171
- * and the offers second would close a cycle with it. A caller that supersedes
172
- * the revokee's outgoing offers too (`role_grant_revoke`) takes the account row
173
- * and then every offer it writes in one statement first
174
- * (`query_role_grant_offer_lock_for_revoke`); the locks here then find rows
175
- * the transaction already holds.
176
- *
177
- * @param deps - query dependencies
178
- * @param role_grant_id - the role_grant to revoke
179
- * @param actor_id - the actor that must own the role_grant
180
- * @param revoked_by - the actor who revoked it (for audit trail)
181
- * @param reason - optional free-form reason, stamped on `role_grant.revoked_reason` and surfaced to the revokee notification.
182
- * @mutates `role_grant` row - sets `revoked_at`, `revoked_by`, and `revoked_reason`
183
- * @mutates `role_grant_offer` rows - stamps `superseded_at` on every pending sibling for the same `(account, role, scope)`
184
- */
185
- export const query_revoke_role_grant = async (deps, role_grant_id, actor_id, revoked_by, reason) => {
186
- // the revokee's account row first, as `query_account_lock_for_revoke` takes it
187
- await deps.db.query(`SELECT a.id FROM actor act JOIN account a ON a.id = act.account_id
188
- WHERE act.id = $1
189
- FOR NO KEY UPDATE OF a`, [actor_id]);
190
- // the role and scope name the offers to lock; written once with the grant
191
- const target = await deps.db.query_one(`SELECT role, scope_id FROM role_grant WHERE id = $1 AND actor_id = $2 AND revoked_at IS NULL`, [role_grant_id, actor_id]);
192
- if (!target)
193
- return null;
194
- const incoming = `to_account_id = (SELECT account_id FROM actor WHERE id = $1)
195
- AND role = $2 AND scope_id IS NOT DISTINCT FROM $3 AND ${offer_pending_predicate('')}`;
196
- await deps.db.query(`SELECT id FROM role_grant_offer WHERE ${incoming} ORDER BY id FOR UPDATE`, [
197
- actor_id,
198
- target.role,
199
- target.scope_id
200
- ]);
201
- const rows = await deps.db.query(`UPDATE role_grant SET revoked_at = NOW(), revoked_by = $3, revoked_reason = $4
202
- WHERE id = $1 AND actor_id = $2 AND revoked_at IS NULL
203
- RETURNING id, role, scope_kind, scope_id`, [role_grant_id, actor_id, revoked_by ?? null, reason ?? null]);
204
- const revoked = rows[0];
205
- if (!revoked)
206
- return null;
207
- // CTE joins `actor` after the UPDATE so each superseded row carries the
208
- // grantor's `account_id` — callers fan out `role_grant_offer_supersede`
209
- // notifications to that account without a second round-trip. The match
210
- // keys on `scope_id` only because the (scope_kind, scope_id) pair-CHECK
211
- // makes scope_kind a function of scope_id; matching on both adds no
212
- // new selectivity in v1.
213
- const superseded_offers = await deps.db.query(`WITH updated AS (
214
- UPDATE role_grant_offer o
215
- SET superseded_at = NOW()
216
- WHERE ${offer_rows_locked_in_id_order('o', incoming)}
217
- -- raw columns; the outer grantor select formats them
218
- RETURNING ${qualify_columns(ROLE_GRANT_OFFER_COLUMNS, 'o')}
219
- )
220
- ${ROLE_GRANT_OFFER_WITH_GRANTOR_SELECT}`, [actor_id, revoked.role, revoked.scope_id]);
221
- return {
222
- id: revoked.id,
223
- role: revoked.role,
224
- scope_kind: revoked.scope_kind,
225
- scope_id: revoked.scope_id,
226
- superseded_offers
227
- };
228
- };
229
- /**
230
- * Find all active (non-revoked, non-expired) role_grants for an actor.
153
+ * Find all active (non-revoked, non-expired) role_grants for an actor, oldest
154
+ * first, grants of one instant (bootstrap's keeper and admin) by role, scope
155
+ * and id — the admin account list's order, and the Rust twin's.
231
156
  */
232
157
  export const query_role_grant_find_active_for_actor = async (deps, actor_id) => {
233
158
  return deps.db.query(`SELECT ${columns_sql(ROLE_GRANT_COLUMNS, role_grant_expr)} FROM role_grant
234
159
  WHERE actor_id = $1
235
160
  AND ${role_grant_active_sql('')}
236
- ORDER BY role_grant.created_at`, [actor_id]);
161
+ ORDER BY role_grant.created_at, role_grant.role, role_grant.scope_id, role_grant.id`, [actor_id]);
237
162
  };
238
163
  /**
239
164
  * Account-grain check: does any actor on `account_id` hold an active
@@ -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,kBAAk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 @@ import { queue_connection_close } from '../actions/connection_closer.js';
42
42
  import { jsonrpc_errors } from '../http/jsonrpc_errors.js';
43
43
  import { builtin_role_specs, is_builtin_role, list_roles_with_grant_path, RoleName } from './role_schema.js';
44
44
  import { GRANT_PATH_SELF_SERVICE } from './grant_path_schema.js';
45
- import { query_create_role_grant, query_revoke_role_grant } from './role_grant_queries.js';
45
+ import { query_create_role_grant } from './role_grant_queries.js';
46
+ import { query_revoke_role_grant } from './role_grant_offer_queries.js';
47
+ import { emit_supersede_audits } from './role_grant_offer_actions.js';
46
48
  import { is_role_grant_active } from './account_schema.js';
47
49
  import { has_scoped_role } from './request_context.js';
48
50
  import { queue_supersede_notifications } from './role_grant_offer_notifications.js';
@@ -189,27 +191,14 @@ export const create_self_service_role_actions = (deps, options = {}) => {
189
191
  self_service: true
190
192
  }
191
193
  });
192
- // Supersede cascade — `query_revoke_role_grant` marks any pending offers
193
- // for the same `(account, role, scope)` superseded as a side effect, and
194
- // each gets its forensic row like the admin revoke's (empty in practice:
195
- // offer creation gates on the role's `grant_paths`, so only a role that is
196
- // both offerable and self-service-eligible has siblings). Both parties are
197
- // told, as the admin revoke tells them: the recipient is the caller, but
198
- // its answer lists no offers, so its other connections learn of them here.
199
- for (const offer of result.superseded_offers) {
200
- await deps.audit.emit_role_grant_target(ctx, auth, {
201
- event_type: 'role_grant_offer_supersede',
202
- target_account_id: offer.to_account_id,
203
- target_actor_id: offer.to_actor_id,
204
- metadata: {
205
- offer_id: offer.id,
206
- role: offer.role,
207
- scope_id: offer.scope_id,
208
- reason: 'role_grant_revoked',
209
- cause_id: result.id
210
- }
211
- });
212
- }
194
+ // Supersede cascade — the revoke ended the caller's pending offers of the
195
+ // role (only a role both offerable and self-service-eligible has any) and
196
+ // every offer the caller's actor made, whatever its role, as the admin
197
+ // revoke ends them (`query_revoke_role_grant`). Each gets its forensic row
198
+ // like the admin revoke's, and both parties of each are told: the caller
199
+ // is one party of every offer, but its answer lists none, so its other
200
+ // connections learn of them here.
201
+ await emit_supersede_audits(ctx, deps.audit, result.superseded_offers, 'role_grant_revoked', result.id);
213
202
  const revoked_grant = { kind: 'id', id: result.id };
214
203
  queue_supersede_notifications(ctx, result.superseded_offers, 'role_grant_revoked', {
215
204
  grantor: revoked_grant,
@@ -36,15 +36,18 @@ export declare const hash_session_token: (token: string) => SessionId;
36
36
  */
37
37
  export declare const generate_session_token: () => string;
38
38
  /**
39
- * Create a new auth session.
39
+ * Create a new auth session, expiring `AUTH_SESSION_LIFETIME_MS` after the
40
+ * database's `NOW()` — the clock the validity check (`expires_at > NOW()`)
41
+ * reads, and the one `created_at` takes, so the expiry sits a whole lifetime
42
+ * past the row's creation and every session one transaction creates shares
43
+ * it. Twin of the Rust `query_create_session`, same statement.
40
44
  *
41
45
  * @param deps - query dependencies
42
46
  * @param token_hash - blake3 hash of the session token (use `hash_session_token`)
43
47
  * @param account_id - the account this session belongs to
44
- * @param expires_at - when the session expires
45
48
  * @mutates `auth_session` table - inserts a row keyed by `token_hash`
46
49
  */
47
- export declare const query_create_session: (deps: QueryDeps, token_hash: string, account_id: string, expires_at: Date) => Promise<void>;
50
+ export declare const query_create_session: (deps: QueryDeps, token_hash: string, account_id: string) => Promise<void>;
48
51
  /**
49
52
  * The full `auth_session` column set, named explicitly so a row read fails
50
53
  * loud on schema drift — `SELECT *` would silently carry a dropped or
@@ -1 +1 @@
1
- {"version":3,"file":"session_queries.d.ts","sourceRoot":"","sources":["../../src/lib/auth/session_queries.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAA+B,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAEvF,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGlE;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB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