@fuzdev/fuz_app 0.181.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 (267) hide show
  1. package/README.md +2 -0
  2. package/dist/actions/CLAUDE.md +28 -10
  3. package/dist/actions/action_rpc.d.ts +11 -1
  4. package/dist/actions/action_rpc.d.ts.map +1 -1
  5. package/dist/actions/action_rpc.js +3 -2
  6. package/dist/actions/action_types.d.ts +16 -1
  7. package/dist/actions/action_types.d.ts.map +1 -1
  8. package/dist/actions/action_types.js +1 -1
  9. package/dist/actions/notification_sender.d.ts +83 -0
  10. package/dist/actions/notification_sender.d.ts.map +1 -0
  11. package/dist/actions/notification_sender.js +85 -0
  12. package/dist/actions/perform_action.d.ts +9 -0
  13. package/dist/actions/perform_action.d.ts.map +1 -1
  14. package/dist/actions/perform_action.js +22 -13
  15. package/dist/actions/register_action_ws.d.ts +14 -0
  16. package/dist/actions/register_action_ws.d.ts.map +1 -1
  17. package/dist/actions/register_action_ws.js +3 -2
  18. package/dist/actions/ws_socket_session.d.ts +3 -0
  19. package/dist/actions/ws_socket_session.d.ts.map +1 -1
  20. package/dist/actions/ws_socket_session.js +2 -1
  21. package/dist/auth/CLAUDE.md +113 -70
  22. package/dist/auth/account_actions.d.ts.map +1 -1
  23. package/dist/auth/account_actions.js +13 -3
  24. package/dist/auth/account_queries.d.ts +158 -16
  25. package/dist/auth/account_queries.d.ts.map +1 -1
  26. package/dist/auth/account_queries.js +189 -18
  27. package/dist/auth/account_routes.d.ts +6 -4
  28. package/dist/auth/account_routes.d.ts.map +1 -1
  29. package/dist/auth/account_routes.js +98 -92
  30. package/dist/auth/admin_actions.d.ts.map +1 -1
  31. package/dist/auth/admin_actions.js +93 -45
  32. package/dist/auth/api_token_queries.d.ts +13 -5
  33. package/dist/auth/api_token_queries.d.ts.map +1 -1
  34. package/dist/auth/api_token_queries.js +24 -9
  35. package/dist/auth/audit_emitter.d.ts +75 -84
  36. package/dist/auth/audit_emitter.d.ts.map +1 -1
  37. package/dist/auth/audit_emitter.js +83 -71
  38. package/dist/auth/audit_log_schema.d.ts +10 -5
  39. package/dist/auth/audit_log_schema.d.ts.map +1 -1
  40. package/dist/auth/audit_log_schema.js +22 -6
  41. package/dist/auth/bearer_auth.d.ts.map +1 -1
  42. package/dist/auth/bearer_auth.js +3 -2
  43. package/dist/auth/bootstrap_account.d.ts +31 -13
  44. package/dist/auth/bootstrap_account.d.ts.map +1 -1
  45. package/dist/auth/bootstrap_account.js +34 -15
  46. package/dist/auth/bootstrap_routes.d.ts +1 -1
  47. package/dist/auth/bootstrap_routes.d.ts.map +1 -1
  48. package/dist/auth/bootstrap_routes.js +7 -14
  49. package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
  50. package/dist/auth/daemon_token_middleware.js +12 -1
  51. package/dist/auth/deps.d.ts +18 -5
  52. package/dist/auth/deps.d.ts.map +1 -1
  53. package/dist/auth/deps.js +3 -2
  54. package/dist/auth/request_context.d.ts +73 -73
  55. package/dist/auth/request_context.d.ts.map +1 -1
  56. package/dist/auth/request_context.js +78 -96
  57. package/dist/auth/resolved_auth.d.ts +16 -11
  58. package/dist/auth/resolved_auth.d.ts.map +1 -1
  59. package/dist/auth/resolved_auth.js +6 -6
  60. package/dist/auth/role_grant_offer_action_specs.d.ts +1 -1
  61. package/dist/auth/role_grant_offer_action_specs.d.ts.map +1 -1
  62. package/dist/auth/role_grant_offer_action_specs.js +2 -1
  63. package/dist/auth/role_grant_offer_actions.d.ts +32 -12
  64. package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
  65. package/dist/auth/role_grant_offer_actions.js +91 -116
  66. package/dist/auth/role_grant_offer_notifications.d.ts +87 -38
  67. package/dist/auth/role_grant_offer_notifications.d.ts.map +1 -1
  68. package/dist/auth/role_grant_offer_notifications.js +75 -22
  69. package/dist/auth/role_grant_offer_queries.d.ts +155 -18
  70. package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
  71. package/dist/auth/role_grant_offer_queries.js +262 -73
  72. package/dist/auth/role_grant_offer_schema.js +1 -1
  73. package/dist/auth/role_grant_queries.d.ts +43 -52
  74. package/dist/auth/role_grant_queries.d.ts.map +1 -1
  75. package/dist/auth/role_grant_queries.js +50 -74
  76. package/dist/auth/role_grant_sql.d.ts +21 -0
  77. package/dist/auth/role_grant_sql.d.ts.map +1 -1
  78. package/dist/auth/role_grant_sql.js +21 -0
  79. package/dist/auth/self_service_role_actions.d.ts.map +1 -1
  80. package/dist/auth/self_service_role_actions.js +17 -21
  81. package/dist/auth/session_queries.d.ts +40 -16
  82. package/dist/auth/session_queries.d.ts.map +1 -1
  83. package/dist/auth/session_queries.js +68 -29
  84. package/dist/auth/signup_routes.d.ts.map +1 -1
  85. package/dist/auth/signup_routes.js +90 -38
  86. package/dist/auth/standard_rpc_actions.d.ts +6 -19
  87. package/dist/auth/standard_rpc_actions.d.ts.map +1 -1
  88. package/dist/auth/standard_rpc_actions.js +5 -6
  89. package/dist/auth/token_scope.d.ts +1 -1
  90. package/dist/auth/token_scope.js +1 -1
  91. package/dist/db/sql_columns.d.ts +1 -1
  92. package/dist/db/sql_columns.js +1 -1
  93. package/dist/http/CLAUDE.md +22 -16
  94. package/dist/http/auth_shape.d.ts +1 -1
  95. package/dist/http/db_routes.d.ts +7 -22
  96. package/dist/http/db_routes.d.ts.map +1 -1
  97. package/dist/http/db_routes.js +72 -72
  98. package/dist/http/error_schemas.d.ts +9 -21
  99. package/dist/http/error_schemas.d.ts.map +1 -1
  100. package/dist/http/error_schemas.js +14 -24
  101. package/dist/http/pending_effects.d.ts +42 -4
  102. package/dist/http/pending_effects.d.ts.map +1 -1
  103. package/dist/http/pending_effects.js +34 -4
  104. package/dist/http/route_spec.d.ts +2 -2
  105. package/dist/server/app_backend.d.ts.map +1 -1
  106. package/dist/server/app_backend.js +3 -1
  107. package/dist/server/app_server.d.ts +69 -18
  108. package/dist/server/app_server.d.ts.map +1 -1
  109. package/dist/server/app_server.js +74 -10
  110. package/dist/server/serve_fact_route.d.ts +3 -3
  111. package/dist/server/serve_fact_route.js +12 -12
  112. package/dist/testing/CLAUDE.md +259 -790
  113. package/dist/testing/adversarial_404.d.ts +6 -1
  114. package/dist/testing/adversarial_404.d.ts.map +1 -1
  115. package/dist/testing/adversarial_404.js +38 -17
  116. package/dist/testing/app_server.d.ts +20 -140
  117. package/dist/testing/app_server.d.ts.map +1 -1
  118. package/dist/testing/app_server.js +48 -125
  119. package/dist/testing/audit_drift_guard.d.ts +11 -6
  120. package/dist/testing/audit_drift_guard.d.ts.map +1 -1
  121. package/dist/testing/audit_drift_guard.js +15 -8
  122. package/dist/testing/auth_apps.js +1 -1
  123. package/dist/testing/cross_backend/account_lifecycle.d.ts.map +1 -1
  124. package/dist/testing/cross_backend/account_lifecycle.js +43 -0
  125. package/dist/testing/cross_backend/audit_cross_helpers.d.ts +12 -9
  126. package/dist/testing/cross_backend/audit_cross_helpers.d.ts.map +1 -1
  127. package/dist/testing/cross_backend/audit_cross_helpers.js +13 -14
  128. package/dist/testing/cross_backend/capabilities.d.ts +9 -6
  129. package/dist/testing/cross_backend/capabilities.d.ts.map +1 -1
  130. package/dist/testing/cross_backend/capabilities.js +11 -7
  131. package/dist/testing/cross_backend/capability_mounts.d.ts +103 -0
  132. package/dist/testing/cross_backend/capability_mounts.d.ts.map +1 -0
  133. package/dist/testing/cross_backend/capability_mounts.js +423 -0
  134. package/dist/testing/cross_backend/cell_moderate.js +2 -2
  135. package/dist/testing/cross_backend/cell_relations.d.ts.map +1 -1
  136. package/dist/testing/cross_backend/cell_relations.js +12 -11
  137. package/dist/testing/cross_backend/conformance_principal.d.ts +54 -0
  138. package/dist/testing/cross_backend/conformance_principal.d.ts.map +1 -0
  139. package/dist/testing/cross_backend/conformance_principal.js +283 -0
  140. package/dist/testing/cross_backend/conformance_table.d.ts +2 -50
  141. package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
  142. package/dist/testing/cross_backend/conformance_table.js +2 -270
  143. package/dist/testing/cross_backend/credential_deadline.d.ts.map +1 -1
  144. package/dist/testing/cross_backend/credential_deadline.js +2 -0
  145. package/dist/testing/cross_backend/credential_wire.d.ts +1 -1
  146. package/dist/testing/cross_backend/credential_wire.d.ts.map +1 -1
  147. package/dist/testing/cross_backend/db_state_diff.d.ts +72 -0
  148. package/dist/testing/cross_backend/db_state_diff.d.ts.map +1 -0
  149. package/dist/testing/cross_backend/db_state_diff.js +444 -0
  150. package/dist/testing/cross_backend/declared_skips.d.ts +68 -0
  151. package/dist/testing/cross_backend/declared_skips.d.ts.map +1 -0
  152. package/dist/testing/cross_backend/declared_skips.js +132 -0
  153. package/dist/testing/cross_backend/default_spine_surface.d.ts +1 -26
  154. package/dist/testing/cross_backend/default_spine_surface.d.ts.map +1 -1
  155. package/dist/testing/cross_backend/default_spine_surface.js +2 -6
  156. package/dist/testing/cross_backend/differential.d.ts +11 -2
  157. package/dist/testing/cross_backend/differential.d.ts.map +1 -1
  158. package/dist/testing/cross_backend/differential.js +35 -11
  159. package/dist/testing/cross_backend/differential_normalize.d.ts +12 -0
  160. package/dist/testing/cross_backend/differential_normalize.d.ts.map +1 -1
  161. package/dist/testing/cross_backend/differential_normalize.js +16 -0
  162. package/dist/testing/cross_backend/full_spine_mount.d.ts +3 -10
  163. package/dist/testing/cross_backend/full_spine_mount.d.ts.map +1 -1
  164. package/dist/testing/cross_backend/full_spine_mount.js +4 -4
  165. package/dist/testing/cross_backend/in_process_setup.d.ts +22 -12
  166. package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
  167. package/dist/testing/cross_backend/in_process_setup.js +151 -134
  168. package/dist/testing/cross_backend/login_security.d.ts +12 -0
  169. package/dist/testing/cross_backend/login_security.d.ts.map +1 -1
  170. package/dist/testing/cross_backend/login_security.js +21 -4
  171. package/dist/testing/cross_backend/request_target_conformance_wire.d.ts +0 -2
  172. package/dist/testing/cross_backend/request_target_conformance_wire.d.ts.map +1 -1
  173. package/dist/testing/cross_backend/request_target_conformance_wire.js +3 -1
  174. package/dist/testing/cross_backend/revocation_drivers.d.ts +18 -5
  175. package/dist/testing/cross_backend/revocation_drivers.d.ts.map +1 -1
  176. package/dist/testing/cross_backend/revocation_drivers.js +18 -10
  177. package/dist/testing/cross_backend/role_grant_cross_helpers.d.ts +1 -1
  178. package/dist/testing/cross_backend/role_grant_cross_helpers.d.ts.map +1 -1
  179. package/dist/testing/cross_backend/role_grant_offer_lifecycle.d.ts.map +1 -1
  180. package/dist/testing/cross_backend/role_grant_offer_lifecycle.js +33 -1
  181. package/dist/testing/cross_backend/role_grant_offer_notification_ws.d.ts +5 -4
  182. package/dist/testing/cross_backend/role_grant_offer_notification_ws.d.ts.map +1 -1
  183. package/dist/testing/cross_backend/role_grant_offer_notification_ws.js +183 -30
  184. package/dist/testing/cross_backend/role_grant_participation.js +4 -4
  185. package/dist/testing/cross_backend/rpc_adversarial.js +1 -1
  186. package/dist/testing/cross_backend/session_cap.d.ts +2 -2
  187. package/dist/testing/cross_backend/session_cap.d.ts.map +1 -1
  188. package/dist/testing/cross_backend/session_cap.js +48 -16
  189. package/dist/testing/cross_backend/setup.d.ts +31 -1
  190. package/dist/testing/cross_backend/setup.d.ts.map +1 -1
  191. package/dist/testing/cross_backend/setup.js +32 -1
  192. package/dist/testing/cross_backend/spine_suites.d.ts +123 -12
  193. package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
  194. package/dist/testing/cross_backend/spine_suites.js +454 -57
  195. package/dist/testing/cross_backend/spine_surface_constants.d.ts +1 -1
  196. package/dist/testing/cross_backend/spine_surface_constants.d.ts.map +1 -1
  197. package/dist/testing/cross_backend/spine_surface_constants.js +1 -0
  198. package/dist/testing/cross_backend/sse_round_trip.d.ts +9 -1
  199. package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
  200. package/dist/testing/cross_backend/sse_round_trip.js +123 -27
  201. package/dist/testing/cross_backend/testing_backdoor.d.ts.map +1 -1
  202. package/dist/testing/cross_backend/testing_backdoor.js +4 -2
  203. package/dist/testing/cross_backend/testing_reset_actions.d.ts +59 -27
  204. package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
  205. package/dist/testing/cross_backend/testing_reset_actions.js +66 -42
  206. package/dist/testing/cross_backend/transport_composition.d.ts +1 -1
  207. package/dist/testing/cross_backend/transport_composition.d.ts.map +1 -1
  208. package/dist/testing/cross_backend/transport_composition.js +7 -3
  209. package/dist/testing/cross_backend/ws_round_trip.d.ts +5 -0
  210. package/dist/testing/cross_backend/ws_round_trip.d.ts.map +1 -1
  211. package/dist/testing/cross_backend/ws_round_trip.js +54 -8
  212. package/dist/testing/data_exposure.d.ts.map +1 -1
  213. package/dist/testing/data_exposure.js +3 -0
  214. package/dist/testing/db.d.ts +0 -32
  215. package/dist/testing/db.d.ts.map +1 -1
  216. package/dist/testing/db.js +0 -86
  217. package/dist/testing/db_entities.d.ts +14 -0
  218. package/dist/testing/db_entities.d.ts.map +1 -1
  219. package/dist/testing/db_entities.js +17 -0
  220. package/dist/testing/db_invariant_queries.d.ts +259 -0
  221. package/dist/testing/db_invariant_queries.d.ts.map +1 -0
  222. package/dist/testing/db_invariant_queries.js +400 -0
  223. package/dist/testing/db_invariants.d.ts +106 -0
  224. package/dist/testing/db_invariants.d.ts.map +1 -0
  225. package/dist/testing/db_invariants.gen.sql.d.ts +11 -0
  226. package/dist/testing/db_invariants.gen.sql.d.ts.map +1 -0
  227. package/dist/testing/db_invariants.gen.sql.js +13 -0
  228. package/dist/testing/db_invariants.js +141 -0
  229. package/dist/testing/db_invariants.sql +152 -0
  230. package/dist/testing/describe_db.d.ts +36 -0
  231. package/dist/testing/describe_db.d.ts.map +1 -0
  232. package/dist/testing/describe_db.js +71 -0
  233. package/dist/testing/integration.d.ts +6 -9
  234. package/dist/testing/integration.d.ts.map +1 -1
  235. package/dist/testing/integration.js +9 -13
  236. package/dist/testing/integration_helpers.d.ts +1 -1
  237. package/dist/testing/integration_helpers.d.ts.map +1 -1
  238. package/dist/testing/middleware.d.ts +1 -1
  239. package/dist/testing/middleware.js +5 -5
  240. package/dist/testing/rate_limiting.d.ts +1 -1
  241. package/dist/testing/rate_limiting.d.ts.map +1 -1
  242. package/dist/testing/rate_limiting.js +3 -2
  243. package/dist/testing/resolved_auth.d.ts +3 -1
  244. package/dist/testing/resolved_auth.d.ts.map +1 -1
  245. package/dist/testing/resolved_auth.js +4 -4
  246. package/dist/testing/role_grant_helpers.d.ts +1 -1
  247. package/dist/testing/role_grant_helpers.d.ts.map +1 -1
  248. package/dist/testing/round_trip.d.ts.map +1 -1
  249. package/dist/testing/round_trip.js +3 -0
  250. package/dist/testing/rpc_attack_surface.d.ts +8 -6
  251. package/dist/testing/rpc_attack_surface.d.ts.map +1 -1
  252. package/dist/testing/rpc_attack_surface.js +69 -6
  253. package/dist/testing/rpc_round_trip.d.ts +1 -1
  254. package/dist/testing/rpc_round_trip.d.ts.map +1 -1
  255. package/dist/testing/rpc_round_trip.js +3 -0
  256. package/dist/testing/sse_round_trip.d.ts +1 -1
  257. package/dist/testing/sse_round_trip.d.ts.map +1 -1
  258. package/dist/testing/sse_round_trip.js +13 -4
  259. package/dist/testing/stubs.d.ts +4 -2
  260. package/dist/testing/stubs.d.ts.map +1 -1
  261. package/dist/testing/stubs.js +15 -7
  262. package/dist/testing/test_app.d.ts +166 -0
  263. package/dist/testing/test_app.d.ts.map +1 -0
  264. package/dist/testing/test_app.js +124 -0
  265. package/dist/testing/ws_round_trip.d.ts.map +1 -1
  266. package/dist/testing/ws_round_trip.js +8 -4
  267. package/package.json +1 -1
@@ -85,47 +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
88
  /**
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
- * @param deps - query dependencies
119
- * @param role_grant_id - the role_grant to revoke
120
- * @param actor_id - the actor that must own the role_grant
121
- * @param revoked_by - the actor who revoked it (for audit trail)
122
- * @param reason - optional free-form reason, stamped on `role_grant.revoked_reason` and surfaced to the revokee notification.
123
- * @mutates `role_grant` row - sets `revoked_at`, `revoked_by`, and `revoked_reason`
124
- * @mutates `role_grant_offer` rows - stamps `superseded_at` on every pending sibling for the same `(account, role, scope)`
125
- */
126
- 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>;
127
- /**
128
- * 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.
129
92
  */
130
93
  export declare const query_role_grant_find_active_for_actor: (deps: QueryDeps, actor_id: string) => Promise<Array<RoleGrant>>;
131
94
  /**
@@ -159,7 +122,7 @@ export declare const query_account_has_global_role: (deps: QueryDeps, account_id
159
122
  * Like `query_account_has_global_role`, but only counts the grant when the
160
123
  * **account and the granting actor are both active** (`deleted_at IS NULL`).
161
124
  * Used by the last-admin branch of the removability guard: a soft-deleted admin
162
- * can't log in and is excluded from `query_count_active_accounts_with_global_role_for_update`,
125
+ * can't log in and is excluded from `query_count_active_accounts_with_global_role_locked`,
163
126
  * so the guard must use the same active predicate when testing whether the
164
127
  * *target* is an admin — otherwise removing an already-tombstoned admin is
165
128
  * falsely blocked as `cannot_delete_last_admin`. Soft-delete does **not** revoke
@@ -205,16 +168,37 @@ export declare const query_actor_has_active_global_role: (deps: QueryDeps, actor
205
168
  * guard could fail-open and let the last usable admin be removed).
206
169
  *
207
170
  * **Locks** every counted `role_grant`, `actor`, and `account` row
208
- * (`FOR UPDATE`) until the caller's transaction ends, so two guards racing to
209
- * remove the last two admins serialize: the second waits for the first to
210
- * commit, re-reads the rows it changed, and counts one. Run it inside the
211
- * transaction that does the removal. Twin of the Rust
212
- * `query_count_active_accounts_with_global_role_for_update`.
171
+ * `FOR NO KEY UPDATE` until the caller's transaction ends. That conflicts with
172
+ * another guard, so two guards racing to remove the last two admins serialize:
173
+ * the second waits for the first to commit, re-reads the rows it changed, and
174
+ * counts one. It conflicts with every write that lowers the count — a revoke's
175
+ * or a soft delete's `UPDATE` of a counted row, a purge's `DELETE` — and with
176
+ * the locks a credential mint, an offer, an invite and an offer accept (its
177
+ * recipient's row and its grantor's, `query_account_lock_for_offer_accept`)
178
+ * take on the account row. Run it inside the transaction that does the
179
+ * removal.
180
+ *
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
184
+ * lowers the count, so the guard fails closed — what it counted is at most what
185
+ * will stand, and a removal it allows leaves an admin. A purge that deletes a
186
+ * row such a write names still takes `FOR UPDATE` and waits for it.
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.
195
+ * Twin of the Rust `query_count_active_accounts_with_global_role_locked`.
213
196
  *
214
197
  * The rows are locked in id order — account, then actor, then grant — as the
215
198
  * sort returns them: each account's row, its actors' and its grants' before
216
- * the next account's. `query_account_lock_live_many` takes account rows in the
217
- * same order, so an offer between two admins and an admin's removal never
199
+ * the next account's. `query_account_lock_live_many` and
200
+ * `query_account_lock_for_offer_accept` take account rows in the same order,
201
+ * so an offer or an accept between two admins and an admin's removal never
218
202
  * wait on each other's rows in opposite orders. Ids never change, so no
219
203
  * concurrent update can move a row the sort has placed.
220
204
  *
@@ -230,7 +214,7 @@ export declare const query_actor_has_active_global_role: (deps: QueryDeps, actor
230
214
  * @returns the number of distinct active accounts with an active global `role` grant
231
215
  * @mutates `role_grant` / `actor` / `account` rows - row-locks the counted rows for the transaction
232
216
  */
233
- export declare const query_count_active_accounts_with_global_role_for_update: (deps: QueryDeps, role: string, exclude_role_grant_id?: Uuid | null) => Promise<number>;
217
+ export declare const query_count_active_accounts_with_global_role_locked: (deps: QueryDeps, role: string, exclude_role_grant_id?: Uuid | null) => Promise<number>;
234
218
  /**
235
219
  * Find the account ID of an account that holds an active **global** role_grant
236
220
  * for a given role.
@@ -273,7 +257,9 @@ export interface RevokeForScopeResult {
273
257
  /**
274
258
  * Every pending offer at the scope — tuple-matched and orphan, undifferentiated
275
259
  * — superseded in the same cascade. Each entry carries its grantor's
276
- * `from_account_id` for `role_grant_offer_supersede` notification fan-out.
260
+ * `from_account_id`, as every supersede cascade's does; no
261
+ * `role_grant_offer_supersede` notification carries `scope_destroyed`, so a
262
+ * scope teardown tells no one.
277
263
  *
278
264
  * The caller is responsible for emitting `role_grant_offer_supersede` audit
279
265
  * events with `reason: 'scope_destroyed'` and `cause_id: <destroyed scope row id>`
@@ -294,7 +280,12 @@ export interface RevokeForScopeResult {
294
280
  * attached to the destroyed scope is cleaned up.
295
281
  *
296
282
  * Both updates run as separate statements inside the caller's transaction,
297
- * the `role_grant` revoke first. The two halves are
283
+ * the scope's pending offers locked in id order first, then the `role_grant`
284
+ * revoke, then the supersede of the offers that lock returned — offers before
285
+ * grants, as `query_revoke_role_grant` takes them. No account row keeps a new
286
+ * offer at the scope out (the scope's offers span accounts), so the supersede
287
+ * writes only the rows it locked: an offer made at the scope after the lock is
288
+ * left pending rather than taken out of order. The two halves are
298
289
  * independent — orphan pending offers can exist at a scope with no active
299
290
  * role_grants, so the supersede half always runs even when no role_grant was
300
291
  * revoked.
@@ -305,7 +296,7 @@ export interface RevokeForScopeResult {
305
296
  * @param reason - optional free-form reason, stamped on `role_grant.revoked_reason`.
306
297
  * @returns the revoked role_grants (with `account_id` for fan-out) and superseded offers (with `from_account_id` for fan-out)
307
298
  * @mutates `role_grant` table - sets `revoked_at`/`revoked_by`/`revoked_reason` on every active row at `scope_id`
308
- * @mutates `role_grant_offer` table - stamps `superseded_at` on every pending row at `scope_id`
299
+ * @mutates `role_grant_offer` table - stamps `superseded_at` on every pending row at `scope_id` its lock took
309
300
  */
310
301
  export declare const query_role_grant_revoke_for_scope: (deps: QueryDeps, scope_id: Uuid, revoked_by: Uuid | null, reason?: string | null) => Promise<RevokeForScopeResult>;
311
302
  //# sourceMappingURL=role_grant_queries.d.ts.map
@@ -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,qB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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"}
@@ -150,68 +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
- * @param deps - query dependencies
166
- * @param role_grant_id - the role_grant to revoke
167
- * @param actor_id - the actor that must own the role_grant
168
- * @param revoked_by - the actor who revoked it (for audit trail)
169
- * @param reason - optional free-form reason, stamped on `role_grant.revoked_reason` and surfaced to the revokee notification.
170
- * @mutates `role_grant` row - sets `revoked_at`, `revoked_by`, and `revoked_reason`
171
- * @mutates `role_grant_offer` rows - stamps `superseded_at` on every pending sibling for the same `(account, role, scope)`
172
- */
173
- export const query_revoke_role_grant = async (deps, role_grant_id, actor_id, revoked_by, reason) => {
174
- const rows = await deps.db.query(`UPDATE role_grant SET revoked_at = NOW(), revoked_by = $3, revoked_reason = $4
175
- WHERE id = $1 AND actor_id = $2 AND revoked_at IS NULL
176
- RETURNING id, role, scope_kind, scope_id`, [role_grant_id, actor_id, revoked_by ?? null, reason ?? null]);
177
- const revoked = rows[0];
178
- if (!revoked)
179
- return null;
180
- // CTE joins `actor` after the UPDATE so each superseded row carries the
181
- // grantor's `account_id` — callers fan out `role_grant_offer_supersede`
182
- // notifications to that account without a second round-trip. The match
183
- // keys on `scope_id` only because the (scope_kind, scope_id) pair-CHECK
184
- // makes scope_kind a function of scope_id; matching on both adds no
185
- // new selectivity in v1.
186
- const superseded_offers = await deps.db.query(`WITH updated AS (
187
- UPDATE role_grant_offer o
188
- SET superseded_at = NOW()
189
- FROM actor a
190
- WHERE a.id = $1
191
- AND o.to_account_id = a.account_id
192
- AND o.role = $2
193
- AND o.scope_id IS NOT DISTINCT FROM $3
194
- AND ${offer_pending_predicate('o')}
195
- -- raw columns; the outer grantor select formats them
196
- RETURNING ${qualify_columns(ROLE_GRANT_OFFER_COLUMNS, 'o')}
197
- )
198
- ${ROLE_GRANT_OFFER_WITH_GRANTOR_SELECT}`, [actor_id, revoked.role, revoked.scope_id]);
199
- return {
200
- id: revoked.id,
201
- role: revoked.role,
202
- scope_kind: revoked.scope_kind,
203
- scope_id: revoked.scope_id,
204
- superseded_offers
205
- };
206
- };
207
- /**
208
- * 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.
209
156
  */
210
157
  export const query_role_grant_find_active_for_actor = async (deps, actor_id) => {
211
158
  return deps.db.query(`SELECT ${columns_sql(ROLE_GRANT_COLUMNS, role_grant_expr)} FROM role_grant
212
159
  WHERE actor_id = $1
213
160
  AND ${role_grant_active_sql('')}
214
- 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]);
215
162
  };
216
163
  /**
217
164
  * Account-grain check: does any actor on `account_id` hold an active
@@ -253,7 +200,7 @@ export const query_account_has_global_role = async (deps, account_id, role) => {
253
200
  * Like `query_account_has_global_role`, but only counts the grant when the
254
201
  * **account and the granting actor are both active** (`deleted_at IS NULL`).
255
202
  * Used by the last-admin branch of the removability guard: a soft-deleted admin
256
- * can't log in and is excluded from `query_count_active_accounts_with_global_role_for_update`,
203
+ * can't log in and is excluded from `query_count_active_accounts_with_global_role_locked`,
257
204
  * so the guard must use the same active predicate when testing whether the
258
205
  * *target* is an admin — otherwise removing an already-tombstoned admin is
259
206
  * falsely blocked as `cannot_delete_last_admin`. Soft-delete does **not** revoke
@@ -325,16 +272,37 @@ export const query_actor_has_active_global_role = async (deps, actor_id, role) =
325
272
  * guard could fail-open and let the last usable admin be removed).
326
273
  *
327
274
  * **Locks** every counted `role_grant`, `actor`, and `account` row
328
- * (`FOR UPDATE`) until the caller's transaction ends, so two guards racing to
329
- * remove the last two admins serialize: the second waits for the first to
330
- * commit, re-reads the rows it changed, and counts one. Run it inside the
331
- * transaction that does the removal. Twin of the Rust
332
- * `query_count_active_accounts_with_global_role_for_update`.
275
+ * `FOR NO KEY UPDATE` until the caller's transaction ends. That conflicts with
276
+ * another guard, so two guards racing to remove the last two admins serialize:
277
+ * the second waits for the first to commit, re-reads the rows it changed, and
278
+ * counts one. It conflicts with every write that lowers the count — a revoke's
279
+ * or a soft delete's `UPDATE` of a counted row, a purge's `DELETE` — and with
280
+ * the locks a credential mint, an offer, an invite and an offer accept (its
281
+ * recipient's row and its grantor's, `query_account_lock_for_offer_accept`)
282
+ * take on the account row. Run it inside the transaction that does the
283
+ * removal.
284
+ *
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
288
+ * lowers the count, so the guard fails closed — what it counted is at most what
289
+ * will stand, and a removal it allows leaves an admin. A purge that deletes a
290
+ * row such a write names still takes `FOR UPDATE` and waits for it.
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.
299
+ * Twin of the Rust `query_count_active_accounts_with_global_role_locked`.
333
300
  *
334
301
  * The rows are locked in id order — account, then actor, then grant — as the
335
302
  * sort returns them: each account's row, its actors' and its grants' before
336
- * the next account's. `query_account_lock_live_many` takes account rows in the
337
- * same order, so an offer between two admins and an admin's removal never
303
+ * the next account's. `query_account_lock_live_many` and
304
+ * `query_account_lock_for_offer_accept` take account rows in the same order,
305
+ * so an offer or an accept between two admins and an admin's removal never
338
306
  * wait on each other's rows in opposite orders. Ids never change, so no
339
307
  * concurrent update can move a row the sort has placed.
340
308
  *
@@ -350,9 +318,9 @@ export const query_actor_has_active_global_role = async (deps, actor_id, role) =
350
318
  * @returns the number of distinct active accounts with an active global `role` grant
351
319
  * @mutates `role_grant` / `actor` / `account` rows - row-locks the counted rows for the transaction
352
320
  */
353
- export const query_count_active_accounts_with_global_role_for_update = async (deps, role, exclude_role_grant_id = null) => {
354
- // `FOR UPDATE` refuses an aggregate, so the rows come back and are counted
355
- // here. The excluded grant is dropped in code, not SQL: filtering it in the
321
+ export const query_count_active_accounts_with_global_role_locked = async (deps, role, exclude_role_grant_id = null) => {
322
+ // A locking clause refuses an aggregate, so the rows come back and are
323
+ // counted here. The excluded grant is dropped in code, not SQL: filtering it in the
356
324
  // WHERE would leave it unlocked, and two cross-revokes (each locking only the
357
325
  // other's grant, then updating it) would deadlock instead of serializing
358
326
  const rows = await deps.db.query(`SELECT a.id AS account_id, rg.id AS role_grant_id
@@ -365,7 +333,7 @@ export const query_count_active_accounts_with_global_role_for_update = async (de
365
333
  AND rg.scope_id IS NULL
366
334
  AND ${role_grant_active_sql('rg')}
367
335
  ORDER BY a.id, act.id, rg.id
368
- FOR UPDATE`, [role]);
336
+ FOR NO KEY UPDATE`, [role]);
369
337
  const account_ids = new Set();
370
338
  for (const row of rows) {
371
339
  if (row.role_grant_id !== exclude_role_grant_id)
@@ -417,7 +385,12 @@ export const query_role_grant_find_account_id_for_role = async (deps, role) => {
417
385
  * attached to the destroyed scope is cleaned up.
418
386
  *
419
387
  * Both updates run as separate statements inside the caller's transaction,
420
- * the `role_grant` revoke first. The two halves are
388
+ * the scope's pending offers locked in id order first, then the `role_grant`
389
+ * revoke, then the supersede of the offers that lock returned — offers before
390
+ * grants, as `query_revoke_role_grant` takes them. No account row keeps a new
391
+ * offer at the scope out (the scope's offers span accounts), so the supersede
392
+ * writes only the rows it locked: an offer made at the scope after the lock is
393
+ * left pending rather than taken out of order. The two halves are
421
394
  * independent — orphan pending offers can exist at a scope with no active
422
395
  * role_grants, so the supersede half always runs even when no role_grant was
423
396
  * revoked.
@@ -428,13 +401,17 @@ export const query_role_grant_find_account_id_for_role = async (deps, role) => {
428
401
  * @param reason - optional free-form reason, stamped on `role_grant.revoked_reason`.
429
402
  * @returns the revoked role_grants (with `account_id` for fan-out) and superseded offers (with `from_account_id` for fan-out)
430
403
  * @mutates `role_grant` table - sets `revoked_at`/`revoked_by`/`revoked_reason` on every active row at `scope_id`
431
- * @mutates `role_grant_offer` table - stamps `superseded_at` on every pending row at `scope_id`
404
+ * @mutates `role_grant_offer` table - stamps `superseded_at` on every pending row at `scope_id` its lock took
432
405
  */
433
406
  export const query_role_grant_revoke_for_scope = async (deps, scope_id, revoked_by, reason) => {
434
407
  // Revoke every active role_grant at the scope. CTE returns `actor_id` directly
435
408
  // from the role_grant row (drives `target_actor_id` audit envelopes); a join
436
409
  // against `actor` resolves `account_id` for `target_account_id`
437
410
  // + WS/SSE socket-close fan-out, all in one round-trip.
411
+ // The scope's pending offers first, in id order — before the grants, for
412
+ // the reason `query_revoke_role_grant` locks its offers before its grant
413
+ const at_scope = `scope_id = $1 AND ${offer_pending_predicate('')}`;
414
+ const locked_ids = (await deps.db.query(`SELECT id FROM role_grant_offer WHERE ${at_scope} ORDER BY id FOR UPDATE`, [scope_id])).map((row) => row.id);
438
415
  const revoked = await deps.db.query(`WITH updated AS (
439
416
  UPDATE role_grant
440
417
  SET revoked_at = NOW(), revoked_by = $2, revoked_reason = $3
@@ -452,11 +429,10 @@ export const query_role_grant_revoke_for_scope = async (deps, scope_id, revoked_
452
429
  const superseded_offers = await deps.db.query(`WITH updated AS (
453
430
  UPDATE role_grant_offer o
454
431
  SET superseded_at = NOW()
455
- WHERE o.scope_id = $1
456
- AND ${offer_pending_predicate('o')}
432
+ WHERE o.id = ANY($2) AND o.scope_id = $1 AND ${offer_pending_predicate('o')}
457
433
  -- raw columns; the outer grantor select formats them
458
434
  RETURNING ${qualify_columns(ROLE_GRANT_OFFER_COLUMNS, 'o')}
459
435
  )
460
- ${ROLE_GRANT_OFFER_WITH_GRANTOR_SELECT}`, [scope_id]);
436
+ ${ROLE_GRANT_OFFER_WITH_GRANTOR_SELECT}`, [scope_id, locked_ids]);
461
437
  return { revoked, superseded_offers };
462
438
  };
@@ -39,4 +39,25 @@ export declare const OFFER_TERMINAL_COLUMNS: readonly ["accepted_at", "declined_
39
39
  * @returns the predicate, with no surrounding parentheses
40
40
  */
41
41
  export declare const offer_pending_predicate: (alias: string) => string;
42
+ /**
43
+ * The predicate a multi-row write of `role_grant_offer` takes its rows
44
+ * through: `id` in an id-ordered locking subselect over `where`.
45
+ *
46
+ * Every transaction that writes several offer rows locks them in id order —
47
+ * in one statement like this, or, when it writes them across statements or
48
+ * after another table's row, all of them first in one id-ordered lock, and
49
+ * then writes only rows that lock took: it either holds the account rows that
50
+ * keep a new offer out (an offer create takes both parties' rows — a removal
51
+ * holds its account's, a revoke its revokee's, an accept its recipient's), or
52
+ * names the locked ids (a scope teardown) — so two such transactions never
53
+ * hold rows the other waits on, whatever plan the database picks. A row
54
+ * changed by a transaction it waited on is re-checked against `where` and
55
+ * drops out when it no longer matches. Twin of the Rust
56
+ * `offer_rows_locked_in_id_order`.
57
+ *
58
+ * @param alias - the alias qualifying the written table's `id`, or `''`
59
+ * @param where - the rows' condition, over unqualified `role_grant_offer` columns
60
+ * @returns the predicate, with no surrounding parentheses
61
+ */
62
+ export declare const offer_rows_locked_in_id_order: (alias: string, where: string) => string;
42
63
  //# sourceMappingURL=role_grant_sql.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"role_grant_sql.d.ts","sourceRoot":"","sources":["../../src/lib/auth/role_grant_sql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAQH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,qBAAqB,GAAI,OAAO,MAAM,KAAG,MAIrD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,sBAAsB,0EAKzB,CAAC;AAEX;;;;;;;;;;GAUG;AACH,eAAO,MAAM,uBAAuB,GAAI,OAAO,MAAM,KAAG,MACkC,CAAC"}
1
+ {"version":3,"file":"role_grant_sql.d.ts","sourceRoot":"","sources":["../../src/lib/auth/role_grant_sql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAQH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,qBAAqB,GAAI,OAAO,MAAM,KAAG,MAIrD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,sBAAsB,0EAKzB,CAAC;AAEX;;;;;;;;;;GAUG;AACH,eAAO,MAAM,uBAAuB,GAAI,OAAO,MAAM,KAAG,MACkC,CAAC;AAE3F;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,6BAA6B,GAAI,OAAO,MAAM,EAAE,OAAO,MAAM,KAAG,MACwB,CAAC"}
@@ -52,3 +52,24 @@ export const OFFER_TERMINAL_COLUMNS = [
52
52
  * @returns the predicate, with no surrounding parentheses
53
53
  */
54
54
  export const offer_pending_predicate = (alias) => OFFER_TERMINAL_COLUMNS.map((column) => `${qualify(alias, column)} IS NULL`).join(' AND ');
55
+ /**
56
+ * The predicate a multi-row write of `role_grant_offer` takes its rows
57
+ * through: `id` in an id-ordered locking subselect over `where`.
58
+ *
59
+ * Every transaction that writes several offer rows locks them in id order —
60
+ * in one statement like this, or, when it writes them across statements or
61
+ * after another table's row, all of them first in one id-ordered lock, and
62
+ * then writes only rows that lock took: it either holds the account rows that
63
+ * keep a new offer out (an offer create takes both parties' rows — a removal
64
+ * holds its account's, a revoke its revokee's, an accept its recipient's), or
65
+ * names the locked ids (a scope teardown) — so two such transactions never
66
+ * hold rows the other waits on, whatever plan the database picks. A row
67
+ * changed by a transaction it waited on is re-checked against `where` and
68
+ * drops out when it no longer matches. Twin of the Rust
69
+ * `offer_rows_locked_in_id_order`.
70
+ *
71
+ * @param alias - the alias qualifying the written table's `id`, or `''`
72
+ * @param where - the rows' condition, over unqualified `role_grant_offer` columns
73
+ * @returns the predicate, with no surrounding parentheses
74
+ */
75
+ export const offer_rows_locked_in_id_order = (alias, where) => `${qualify(alias, 'id')} IN (SELECT id FROM role_grant_offer WHERE ${where} ORDER BY id FOR UPDATE)`;
@@ -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;AAW3D;;;;;;;;;;;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,CA0JjB,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;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"}
@@ -42,9 +42,12 @@ 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';
50
+ import { queue_supersede_notifications } from './role_grant_offer_notifications.js';
48
51
  import { ERROR_ROLE_NOT_SELF_SERVICE_ELIGIBLE, self_service_role_set_action_spec } from './self_service_role_action_specs.js';
49
52
  /**
50
53
  * Validate a deployment's self-service eligible-role set at construction.
@@ -188,26 +191,19 @@ export const create_self_service_role_actions = (deps, options = {}) => {
188
191
  self_service: true
189
192
  }
190
193
  });
191
- // Supersede cascade — `query_revoke_role_grant` marks any pending offers
192
- // for the same `(account, role, scope)` superseded as a side effect, and
193
- // each gets its forensic row like the admin revoke's (empty in practice:
194
- // offer creation gates on the role's `grant_paths`, so only a role that is
195
- // both offerable and self-service-eligible has siblings). The WS supersede
196
- // notification to each grantor is not sent (twin of the Rust path).
197
- for (const offer of result.superseded_offers) {
198
- await deps.audit.emit_role_grant_target(ctx, auth, {
199
- event_type: 'role_grant_offer_supersede',
200
- target_account_id: offer.to_account_id,
201
- target_actor_id: offer.to_actor_id,
202
- metadata: {
203
- offer_id: offer.id,
204
- role: offer.role,
205
- scope_id: offer.scope_id,
206
- reason: 'role_grant_revoked',
207
- cause_id: result.id
208
- }
209
- });
210
- }
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);
202
+ const revoked_grant = { kind: 'id', id: result.id };
203
+ queue_supersede_notifications(ctx, result.superseded_offers, 'role_grant_revoked', {
204
+ grantor: revoked_grant,
205
+ recipient: revoked_grant
206
+ });
211
207
  return { ok: true, enabled: false, changed: true };
212
208
  };
213
209
  return [rpc_action(self_service_role_set_action_spec, handler)];
@@ -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
@@ -128,6 +131,13 @@ export declare const query_session_revoke_for_account: (deps: QueryDeps, token_h
128
131
  /**
129
132
  * Revoke all sessions for an account.
130
133
  *
134
+ * Locks its rows in id order before it deletes them (`ORDER BY id FOR
135
+ * UPDATE`), as every multi-row delete of `auth_session` rows does — the cap's
136
+ * eviction, the expiry sweep, the revoke-all — so two of them reaching the
137
+ * same rows wait one on the other instead of deadlocking in the opposite
138
+ * orders their plans would otherwise walk. Twin of the Rust
139
+ * `fuz_auth::query_session_revoke_all_for_account`.
140
+ *
131
141
  * @returns the number of sessions revoked
132
142
  * @mutates `auth_session` table - deletes every row for `account_id`
133
143
  */
@@ -142,21 +152,21 @@ export declare const query_session_list_for_account: (deps: QueryDeps, account_i
142
152
  * Keeps the newest `max_sessions` sessions and deletes the rest.
143
153
  *
144
154
  * Race safety: this function must run inside a transaction alongside the
145
- * INSERT that created the new session. All callers satisfy this requirement:
146
- * - The `account_token_create` RPC handler runs under the dispatcher's
147
- * transaction path because its spec declares `side_effects: true`
148
- * - `POST /login`, `POST /bootstrap` and `POST /signup` manage their own
149
- * transactions and pass the transaction-scoped `deps` to
150
- * `create_capped_session`
155
+ * INSERT that created the new session. Its one caller is
156
+ * `create_capped_session`, which `POST /login`, `POST /bootstrap` and
157
+ * `POST /signup` each run in a transaction of their own.
151
158
  *
152
159
  * The transaction makes one creator's INSERT + enforce_limit pair atomic, but it
153
160
  * does **not** serialize concurrent creators. Under Read Committed, two
154
161
  * transactions can't see each other's uncommitted session row, so each computes
155
162
  * its `OFFSET` eviction against a stale count, each preserves its own row, and
156
- * both commit above `max_sessions`. A transaction is necessary here but not
157
- * sufficient. Closing this needs one serialization point per
158
- * `(account_id, credential_kind)` — a locked parent row or a transaction-scoped
159
- * advisory lock — taken before count/evict/insert.
163
+ * both commit above `max_sessions` — and their two `DELETE`s lock the same old
164
+ * rows in orders the plan picks, so they can deadlock. A transaction is
165
+ * necessary here but not sufficient: a creator for an existing account first
166
+ * takes its account row `FOR NO KEY UPDATE` (`query_account_lock_verified`),
167
+ * which makes the creators of one account take turns, each counting the rows
168
+ * the one before committed. A creator for an account its own transaction just
169
+ * made needs none — no other can reach the account.
160
170
  *
161
171
  * Ordering is `created_at DESC, id DESC`. The `id` leg is a **stability**
162
172
  * tie-breaker, not a recency one: `created_at` defaults to `NOW()`, the
@@ -165,11 +175,17 @@ export declare const query_session_list_for_account: (deps: QueryDeps, account_i
165
175
  * `OFFSET` may keep a different set on two evaluations of the same rows. `id` is
166
176
  * the blake3 token hash, so the tie-break is arbitrary but deterministic; it
167
177
  * makes the survivors reproducible, it does not make the row just inserted a
168
- * guaranteed survivor. Only the serialization point above does that.
178
+ * guaranteed survivor. Only the account lock above does that.
169
179
  *
170
180
  * Expired-but-unreaped rows count toward the cap (the predicate is `account_id`
171
181
  * alone). Matches the Rust twin `query_session_enforce_limit`.
172
182
  *
183
+ * The victims are locked in id order before the delete (`ORDER BY id FOR
184
+ * UPDATE`), as every multi-row delete of `auth_session` rows locks them: a
185
+ * revoke-all or the expiry sweep reaching the same rows waits on the eviction,
186
+ * or the eviction on it, instead of the two deadlocking in whatever orders
187
+ * their plans walk (`query_session_revoke_all_for_account`).
188
+ *
173
189
  * Deleting a session row does not end the connections it opened: a WebSocket
174
190
  * keeps the authority it resolved at upgrade and an SSE stream never rechecks.
175
191
  * The returned ids are the token hashes those connections are registered
@@ -215,8 +231,10 @@ export declare const query_session_list_all_active: (deps: QueryDeps, limit?: nu
215
231
  * a concurrent pass gets a disjoint set. Run it in a transaction, as the
216
232
  * caller above does, so the ids are in hand before the delete commits — on a
217
233
  * pool-level `Db` a connection lost on the response leaves the rows deleted
218
- * and their ids unread. Served by `idx_auth_session_expires`. Twin of the
219
- * Rust `query_session_cleanup_expired`.
234
+ * and their ids unread. Served by `idx_auth_session_expires`. The rows are
235
+ * locked in id order before the delete, as every multi-row delete of
236
+ * `auth_session` rows locks them (`query_session_revoke_all_for_account`). Twin
237
+ * of the Rust `query_session_cleanup_expired`.
220
238
  *
221
239
  * @param deps - query dependencies (transaction-scoped, see above)
222
240
  * @returns the deleted sessions' ids (their token hashes), empty when nothing had expired
@@ -258,6 +276,12 @@ export interface CappedSession {
258
276
  * `session` target, as `POST /login` does. A caller that mints for an account
259
277
  * created in the same transaction (signup, bootstrap) evicts nothing.
260
278
  *
279
+ * A caller minting for an existing account first takes its row lock in the
280
+ * same transaction (`query_account_lock_verified`) and refuses on `false`: a
281
+ * password change or a delete in flight is ordered against the mint, and the
282
+ * account's mints take turns, which the cap counts on
283
+ * (`query_session_enforce_limit`).
284
+ *
261
285
  * @returns the signed cookie value and the evicted sessions' token hashes
262
286
  * @mutates `auth_session` table - inserts the new session row (and evicts older rows when `max_sessions` is set)
263
287
  */
@@ -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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