@fuzdev/fuz_app 0.182.0 → 0.184.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 (295) hide show
  1. package/README.md +2 -0
  2. package/dist/actions/CLAUDE.md +535 -1223
  3. package/dist/actions/action_codegen.d.ts +1 -1
  4. package/dist/actions/action_codegen.d.ts.map +1 -1
  5. package/dist/actions/action_codegen.js +3 -2
  6. package/dist/actions/connection_closer.d.ts +11 -9
  7. package/dist/actions/connection_closer.d.ts.map +1 -1
  8. package/dist/actions/connection_closer.js +11 -9
  9. package/dist/actions/frontend_rpc_client.d.ts +1 -1
  10. package/dist/actions/register_action_ws.d.ts +14 -1
  11. package/dist/actions/register_action_ws.d.ts.map +1 -1
  12. package/dist/actions/register_action_ws.js +2 -1
  13. package/dist/actions/ws_socket_session.d.ts +9 -1
  14. package/dist/actions/ws_socket_session.d.ts.map +1 -1
  15. package/dist/actions/ws_socket_session.js +43 -19
  16. package/dist/auth/CLAUDE.md +430 -1024
  17. package/dist/auth/account_queries.d.ts +1 -1
  18. package/dist/auth/account_queries.js +1 -1
  19. package/dist/auth/account_routes.d.ts +9 -8
  20. package/dist/auth/account_routes.d.ts.map +1 -1
  21. package/dist/auth/account_routes.js +78 -75
  22. package/dist/auth/admin_actions.d.ts.map +1 -1
  23. package/dist/auth/admin_actions.js +32 -28
  24. package/dist/auth/api_token.d.ts +20 -3
  25. package/dist/auth/api_token.d.ts.map +1 -1
  26. package/dist/auth/api_token.js +28 -9
  27. package/dist/auth/api_token_queries.d.ts +2 -2
  28. package/dist/auth/api_token_queries.js +2 -2
  29. package/dist/auth/audit_emitter.d.ts +75 -84
  30. package/dist/auth/audit_emitter.d.ts.map +1 -1
  31. package/dist/auth/audit_emitter.js +83 -71
  32. package/dist/auth/audit_log_schema.d.ts +25 -14
  33. package/dist/auth/audit_log_schema.d.ts.map +1 -1
  34. package/dist/auth/audit_log_schema.js +23 -8
  35. package/dist/auth/auth_guard_resolver.d.ts +1 -1
  36. package/dist/auth/auth_guard_resolver.js +1 -1
  37. package/dist/auth/bearer_auth.d.ts +2 -5
  38. package/dist/auth/bearer_auth.d.ts.map +1 -1
  39. package/dist/auth/bearer_auth.js +4 -13
  40. package/dist/auth/bootstrap_account.d.ts +42 -26
  41. package/dist/auth/bootstrap_account.d.ts.map +1 -1
  42. package/dist/auth/bootstrap_account.js +36 -19
  43. package/dist/auth/bootstrap_routes.d.ts +20 -21
  44. package/dist/auth/bootstrap_routes.d.ts.map +1 -1
  45. package/dist/auth/bootstrap_routes.js +26 -31
  46. package/dist/auth/bootstrap_token_store.d.ts +3 -4
  47. package/dist/auth/bootstrap_token_store.d.ts.map +1 -1
  48. package/dist/auth/bootstrap_token_store.js +1 -1
  49. package/dist/auth/daemon_token.d.ts +5 -1
  50. package/dist/auth/daemon_token.d.ts.map +1 -1
  51. package/dist/auth/daemon_token_middleware.d.ts +12 -8
  52. package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
  53. package/dist/auth/daemon_token_middleware.js +15 -21
  54. package/dist/auth/deps.d.ts +19 -5
  55. package/dist/auth/deps.d.ts.map +1 -1
  56. package/dist/auth/deps.js +3 -2
  57. package/dist/auth/invite_queries.d.ts +51 -3
  58. package/dist/auth/invite_queries.d.ts.map +1 -1
  59. package/dist/auth/invite_queries.js +81 -6
  60. package/dist/auth/invite_schema.d.ts +2 -1
  61. package/dist/auth/invite_schema.d.ts.map +1 -1
  62. package/dist/auth/middleware.d.ts +2 -3
  63. package/dist/auth/middleware.d.ts.map +1 -1
  64. package/dist/auth/middleware.js +3 -3
  65. package/dist/auth/request_context.d.ts +3 -3
  66. package/dist/auth/request_context.js +3 -3
  67. package/dist/auth/resolved_auth.d.ts +7 -7
  68. package/dist/auth/resolved_auth.d.ts.map +1 -1
  69. package/dist/auth/resolved_auth.js +4 -4
  70. package/dist/auth/role_grant_offer_actions.d.ts +27 -3
  71. package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
  72. package/dist/auth/role_grant_offer_actions.js +42 -35
  73. package/dist/auth/role_grant_offer_queries.d.ts +60 -4
  74. package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
  75. package/dist/auth/role_grant_offer_queries.js +79 -5
  76. package/dist/auth/role_grant_queries.d.ts +3 -52
  77. package/dist/auth/role_grant_queries.d.ts.map +1 -1
  78. package/dist/auth/role_grant_queries.js +5 -80
  79. package/dist/auth/self_service_role_actions.d.ts.map +1 -1
  80. package/dist/auth/self_service_role_actions.js +11 -22
  81. package/dist/auth/session_cookie.d.ts +82 -174
  82. package/dist/auth/session_cookie.d.ts.map +1 -1
  83. package/dist/auth/session_cookie.js +80 -130
  84. package/dist/auth/session_middleware.d.ts +8 -17
  85. package/dist/auth/session_middleware.d.ts.map +1 -1
  86. package/dist/auth/session_middleware.js +14 -23
  87. package/dist/auth/session_queries.d.ts +15 -17
  88. package/dist/auth/session_queries.d.ts.map +1 -1
  89. package/dist/auth/session_queries.js +28 -20
  90. package/dist/auth/signup_routes.d.ts.map +1 -1
  91. package/dist/auth/signup_routes.js +93 -43
  92. package/dist/db/CLAUDE.md +5 -3
  93. package/dist/db/sql_columns.d.ts +1 -1
  94. package/dist/db/sql_columns.js +1 -1
  95. package/dist/dev/setup.d.ts +3 -1
  96. package/dist/dev/setup.d.ts.map +1 -1
  97. package/dist/dev/setup.js +3 -1
  98. package/dist/http/CLAUDE.md +315 -763
  99. package/dist/http/db_routes.d.ts +8 -23
  100. package/dist/http/db_routes.d.ts.map +1 -1
  101. package/dist/http/db_routes.js +73 -73
  102. package/dist/http/origin.d.ts +7 -8
  103. package/dist/http/origin.d.ts.map +1 -1
  104. package/dist/http/origin.js +7 -8
  105. package/dist/http/pending_effects.d.ts +118 -6
  106. package/dist/http/pending_effects.d.ts.map +1 -1
  107. package/dist/http/pending_effects.js +114 -6
  108. package/dist/http/route_result.d.ts +1 -1
  109. package/dist/http/route_spec.d.ts +14 -11
  110. package/dist/http/route_spec.d.ts.map +1 -1
  111. package/dist/realtime/sse.d.ts +4 -23
  112. package/dist/realtime/sse.d.ts.map +1 -1
  113. package/dist/realtime/sse.js +4 -25
  114. package/dist/server/app_backend.d.ts +4 -5
  115. package/dist/server/app_backend.d.ts.map +1 -1
  116. package/dist/server/app_backend.js +3 -1
  117. package/dist/server/app_server.d.ts +80 -16
  118. package/dist/server/app_server.d.ts.map +1 -1
  119. package/dist/server/app_server.js +113 -31
  120. package/dist/server/app_server_context.d.ts +1 -2
  121. package/dist/server/app_server_context.d.ts.map +1 -1
  122. package/dist/server/env.js +2 -2
  123. package/dist/testing/CLAUDE.md +265 -796
  124. package/dist/testing/admin_integration.d.ts +2 -3
  125. package/dist/testing/admin_integration.d.ts.map +1 -1
  126. package/dist/testing/admin_integration.js +3 -3
  127. package/dist/testing/adversarial_404.d.ts +6 -1
  128. package/dist/testing/adversarial_404.d.ts.map +1 -1
  129. package/dist/testing/adversarial_404.js +38 -17
  130. package/dist/testing/app_server.d.ts +23 -148
  131. package/dist/testing/app_server.d.ts.map +1 -1
  132. package/dist/testing/app_server.js +53 -131
  133. package/dist/testing/attack_surface.d.ts +1 -1
  134. package/dist/testing/attack_surface.d.ts.map +1 -1
  135. package/dist/testing/audit_completeness.d.ts +2 -3
  136. package/dist/testing/audit_completeness.d.ts.map +1 -1
  137. package/dist/testing/audit_completeness.js +1 -1
  138. package/dist/testing/audit_drift_guard.d.ts +11 -6
  139. package/dist/testing/audit_drift_guard.d.ts.map +1 -1
  140. package/dist/testing/audit_drift_guard.js +15 -8
  141. package/dist/testing/cross_backend/audit_cross_helpers.d.ts +12 -9
  142. package/dist/testing/cross_backend/audit_cross_helpers.d.ts.map +1 -1
  143. package/dist/testing/cross_backend/audit_cross_helpers.js +13 -14
  144. package/dist/testing/cross_backend/capabilities.d.ts +9 -6
  145. package/dist/testing/cross_backend/capabilities.d.ts.map +1 -1
  146. package/dist/testing/cross_backend/capabilities.js +11 -7
  147. package/dist/testing/cross_backend/capability_mounts.d.ts +103 -0
  148. package/dist/testing/cross_backend/capability_mounts.d.ts.map +1 -0
  149. package/dist/testing/cross_backend/capability_mounts.js +428 -0
  150. package/dist/testing/cross_backend/cell_moderate.js +2 -2
  151. package/dist/testing/cross_backend/cell_relations.d.ts.map +1 -1
  152. package/dist/testing/cross_backend/cell_relations.js +12 -11
  153. package/dist/testing/cross_backend/conformance_principal.d.ts +54 -0
  154. package/dist/testing/cross_backend/conformance_principal.d.ts.map +1 -0
  155. package/dist/testing/cross_backend/conformance_principal.js +283 -0
  156. package/dist/testing/cross_backend/conformance_table.d.ts +7 -56
  157. package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
  158. package/dist/testing/cross_backend/conformance_table.js +6 -274
  159. package/dist/testing/cross_backend/cookie_attributes.js +1 -1
  160. package/dist/testing/cross_backend/credential_deadline.d.ts.map +1 -1
  161. package/dist/testing/cross_backend/credential_deadline.js +2 -0
  162. package/dist/testing/cross_backend/credential_wire.d.ts +1 -1
  163. package/dist/testing/cross_backend/credential_wire.d.ts.map +1 -1
  164. package/dist/testing/cross_backend/db_state_diff.d.ts +72 -0
  165. package/dist/testing/cross_backend/db_state_diff.d.ts.map +1 -0
  166. package/dist/testing/cross_backend/db_state_diff.js +444 -0
  167. package/dist/testing/cross_backend/declared_skips.d.ts +68 -0
  168. package/dist/testing/cross_backend/declared_skips.d.ts.map +1 -0
  169. package/dist/testing/cross_backend/declared_skips.js +132 -0
  170. package/dist/testing/cross_backend/default_backend_configs.d.ts +3 -3
  171. package/dist/testing/cross_backend/default_spine_surface.d.ts +0 -6
  172. package/dist/testing/cross_backend/default_spine_surface.d.ts.map +1 -1
  173. package/dist/testing/cross_backend/default_spine_surface.js +4 -9
  174. package/dist/testing/cross_backend/differential.d.ts +13 -5
  175. package/dist/testing/cross_backend/differential.d.ts.map +1 -1
  176. package/dist/testing/cross_backend/differential.js +35 -11
  177. package/dist/testing/cross_backend/differential_normalize.d.ts +12 -0
  178. package/dist/testing/cross_backend/differential_normalize.d.ts.map +1 -1
  179. package/dist/testing/cross_backend/differential_normalize.js +16 -0
  180. package/dist/testing/cross_backend/full_spine_mount.d.ts +1 -42
  181. package/dist/testing/cross_backend/full_spine_mount.d.ts.map +1 -1
  182. package/dist/testing/cross_backend/full_spine_mount.js +45 -4
  183. package/dist/testing/cross_backend/in_process_setup.d.ts +28 -19
  184. package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
  185. package/dist/testing/cross_backend/in_process_setup.js +156 -142
  186. package/dist/testing/cross_backend/login_security.d.ts +12 -0
  187. package/dist/testing/cross_backend/login_security.d.ts.map +1 -1
  188. package/dist/testing/cross_backend/login_security.js +21 -4
  189. package/dist/testing/cross_backend/request_target_conformance_wire.d.ts +0 -2
  190. package/dist/testing/cross_backend/request_target_conformance_wire.d.ts.map +1 -1
  191. package/dist/testing/cross_backend/request_target_conformance_wire.js +3 -1
  192. package/dist/testing/cross_backend/revocation_drivers.d.ts +18 -5
  193. package/dist/testing/cross_backend/revocation_drivers.d.ts.map +1 -1
  194. package/dist/testing/cross_backend/revocation_drivers.js +18 -10
  195. package/dist/testing/cross_backend/role_grant_cross_helpers.d.ts +1 -1
  196. package/dist/testing/cross_backend/role_grant_cross_helpers.d.ts.map +1 -1
  197. package/dist/testing/cross_backend/role_grant_offer_lifecycle.d.ts.map +1 -1
  198. package/dist/testing/cross_backend/role_grant_offer_lifecycle.js +33 -1
  199. package/dist/testing/cross_backend/role_grant_participation.js +4 -4
  200. package/dist/testing/cross_backend/rpc_adversarial.js +1 -1
  201. package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +3 -4
  202. package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
  203. package/dist/testing/cross_backend/rust_spine_consumer_surface.js +2 -2
  204. package/dist/testing/cross_backend/session_cap.d.ts +2 -2
  205. package/dist/testing/cross_backend/session_cap.d.ts.map +1 -1
  206. package/dist/testing/cross_backend/session_cap.js +22 -11
  207. package/dist/testing/cross_backend/setup.d.ts +32 -2
  208. package/dist/testing/cross_backend/setup.d.ts.map +1 -1
  209. package/dist/testing/cross_backend/setup.js +32 -1
  210. package/dist/testing/cross_backend/spine_suites.d.ts +125 -15
  211. package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
  212. package/dist/testing/cross_backend/spine_suites.js +459 -62
  213. package/dist/testing/cross_backend/spine_surface_constants.d.ts +1 -1
  214. package/dist/testing/cross_backend/spine_surface_constants.d.ts.map +1 -1
  215. package/dist/testing/cross_backend/spine_surface_constants.js +1 -0
  216. package/dist/testing/cross_backend/sse_round_trip.d.ts +9 -1
  217. package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
  218. package/dist/testing/cross_backend/sse_round_trip.js +123 -27
  219. package/dist/testing/cross_backend/standard.d.ts +2 -3
  220. package/dist/testing/cross_backend/standard.d.ts.map +1 -1
  221. package/dist/testing/cross_backend/standard.js +3 -3
  222. package/dist/testing/cross_backend/testing_backdoor.d.ts.map +1 -1
  223. package/dist/testing/cross_backend/testing_backdoor.js +4 -2
  224. package/dist/testing/cross_backend/testing_credential_read.d.ts +10 -11
  225. package/dist/testing/cross_backend/testing_credential_read.d.ts.map +1 -1
  226. package/dist/testing/cross_backend/testing_credential_read.js +12 -12
  227. package/dist/testing/cross_backend/testing_reset_actions.d.ts +84 -47
  228. package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
  229. package/dist/testing/cross_backend/testing_reset_actions.js +95 -63
  230. package/dist/testing/cross_backend/testing_server_core.d.ts.map +1 -1
  231. package/dist/testing/cross_backend/testing_server_core.js +2 -3
  232. package/dist/testing/cross_backend/transport_composition.d.ts +1 -1
  233. package/dist/testing/cross_backend/transport_composition.d.ts.map +1 -1
  234. package/dist/testing/cross_backend/transport_composition.js +7 -3
  235. package/dist/testing/cross_backend/ws_round_trip.d.ts +5 -0
  236. package/dist/testing/cross_backend/ws_round_trip.d.ts.map +1 -1
  237. package/dist/testing/cross_backend/ws_round_trip.js +54 -8
  238. package/dist/testing/daemon_token_rotation.d.ts.map +1 -1
  239. package/dist/testing/daemon_token_rotation.js +2 -3
  240. package/dist/testing/data_exposure.d.ts.map +1 -1
  241. package/dist/testing/data_exposure.js +3 -0
  242. package/dist/testing/db.d.ts +0 -32
  243. package/dist/testing/db.d.ts.map +1 -1
  244. package/dist/testing/db.js +0 -86
  245. package/dist/testing/db_entities.d.ts +14 -0
  246. package/dist/testing/db_entities.d.ts.map +1 -1
  247. package/dist/testing/db_entities.js +17 -0
  248. package/dist/testing/db_invariant_queries.d.ts +259 -0
  249. package/dist/testing/db_invariant_queries.d.ts.map +1 -0
  250. package/dist/testing/db_invariant_queries.js +400 -0
  251. package/dist/testing/db_invariants.d.ts +106 -0
  252. package/dist/testing/db_invariants.d.ts.map +1 -0
  253. package/dist/testing/db_invariants.gen.sql.d.ts +11 -0
  254. package/dist/testing/db_invariants.gen.sql.d.ts.map +1 -0
  255. package/dist/testing/db_invariants.gen.sql.js +13 -0
  256. package/dist/testing/db_invariants.js +141 -0
  257. package/dist/testing/db_invariants.sql +152 -0
  258. package/dist/testing/describe_db.d.ts +36 -0
  259. package/dist/testing/describe_db.d.ts.map +1 -0
  260. package/dist/testing/describe_db.js +71 -0
  261. package/dist/testing/integration.d.ts +8 -12
  262. package/dist/testing/integration.d.ts.map +1 -1
  263. package/dist/testing/integration.js +13 -17
  264. package/dist/testing/integration_helpers.d.ts +1 -1
  265. package/dist/testing/integration_helpers.d.ts.map +1 -1
  266. package/dist/testing/rate_limiting.d.ts +3 -4
  267. package/dist/testing/rate_limiting.d.ts.map +1 -1
  268. package/dist/testing/rate_limiting.js +6 -5
  269. package/dist/testing/role_grant_helpers.d.ts +1 -1
  270. package/dist/testing/role_grant_helpers.d.ts.map +1 -1
  271. package/dist/testing/round_trip.d.ts.map +1 -1
  272. package/dist/testing/round_trip.js +3 -0
  273. package/dist/testing/rpc_attack_surface.d.ts +8 -6
  274. package/dist/testing/rpc_attack_surface.d.ts.map +1 -1
  275. package/dist/testing/rpc_attack_surface.js +69 -6
  276. package/dist/testing/rpc_helpers.d.ts +1 -2
  277. package/dist/testing/rpc_helpers.d.ts.map +1 -1
  278. package/dist/testing/rpc_helpers.js +3 -3
  279. package/dist/testing/rpc_round_trip.d.ts +3 -4
  280. package/dist/testing/rpc_round_trip.d.ts.map +1 -1
  281. package/dist/testing/rpc_round_trip.js +4 -1
  282. package/dist/testing/sse_round_trip.d.ts +3 -4
  283. package/dist/testing/sse_round_trip.d.ts.map +1 -1
  284. package/dist/testing/sse_round_trip.js +15 -6
  285. package/dist/testing/stubs.d.ts +9 -8
  286. package/dist/testing/stubs.d.ts.map +1 -1
  287. package/dist/testing/stubs.js +20 -13
  288. package/dist/testing/test_app.d.ts +168 -0
  289. package/dist/testing/test_app.d.ts.map +1 -0
  290. package/dist/testing/test_app.js +123 -0
  291. package/dist/testing/ws_round_trip.d.ts.map +1 -1
  292. package/dist/testing/ws_round_trip.js +3 -0
  293. package/dist/ui/ui_format.d.ts.map +1 -1
  294. package/dist/ui/ui_format.js +1 -2
  295. package/package.json +1 -1
@@ -91,10 +91,10 @@ export const get_resolved_auth = (c) => c.get(RESOLVED_AUTH_KEY) ?? null;
91
91
  * - **Every credential** — the account row still exists and is not
92
92
  * soft-deleted.
93
93
  *
94
- * It re-checks the **credential**, not what a revocation chose to close: a
95
- * `logout` closes every connection of the account but deletes only its own
96
- * session, so another session's connection opening concurrently passes this
97
- * check and is refused only if that account-wide close found its pending
94
+ * It re-checks the **credential**, not what a revocation chose to close: an
95
+ * `admin_token_revoke_all` closes every connection of the account but deletes
96
+ * only its API tokens, so a session's connection opening concurrently passes
97
+ * this check and is refused only if that account-wide close found its pending
98
98
  * registration — the same two outcomes an already-open connection has.
99
99
  *
100
100
  * **No side effects.** Unlike the bearer middleware this never touches
@@ -4,7 +4,7 @@
4
4
  * The offer-lifecycle methods (create / accept / decline / retract / list /
5
5
  * history) plus `role_grant_revoke` and `role_grant_assign` (both
6
6
  * admin-only). All mount
7
- * on a consumer's JSON-RPC endpoint via `create_rpc_endpoint`. The action
7
+ * on a consumer's JSON-RPC endpoint through `rpc_endpoints`. The action
8
8
  * specs themselves live in `auth/role_grant_offer_action_specs.ts`. Mutations
9
9
  * declare `side_effects: true` so the RPC dispatcher wraps the handler in
10
10
  * a DB transaction; `role_grant_offer_list` and `role_grant_offer_history` declare
@@ -55,11 +55,31 @@
55
55
  *
56
56
  * @module
57
57
  */
58
+ import type { Uuid } from '../primitive_schemas.js';
58
59
  import type { Logger } from '@fuzdev/fuz_util/log.ts';
59
- import { type ActionContext, type RpcAction } from '../actions/action_types.js';
60
+ import { type ActionActorContext, type ActionContext, type RpcAction } from '../actions/action_types.js';
60
61
  import { type RoleRegistry } from './role_schema.js';
62
+ import { type SupersededOffer } from './role_grant_offer_schema.js';
61
63
  import { type RequestContext } from './request_context.js';
62
64
  import type { RevokingActionFactoryDeps } from './deps.js';
65
+ import type { AuditEmitter } from './audit_emitter.js';
66
+ import { type RoleGrantOfferSupersedeParams } from './role_grant_offer_notifications.js';
67
+ /**
68
+ * Emit one `role_grant_offer_supersede` audit row per offer a cascade ended —
69
+ * the revokes (`role_grant_revoke` and the self-service disable, both
70
+ * `'role_grant_revoked'` with the revoked grant as `cause_id`) and account
71
+ * removal (`'account_deleted'`, the removed account). The acting pair is the
72
+ * caller's; the target pair is the offer's recipient (`to_account_id`, and
73
+ * `to_actor_id` when the offer named an actor). Twin of the Rust
74
+ * `emit_supersede_audits`.
75
+ *
76
+ * @param ctx - the handler context; the rows are the caller's
77
+ * @param audit - the emitter
78
+ * @param superseded - the offers the cascade ended
79
+ * @param reason - why they were superseded
80
+ * @param cause_id - the row that caused it
81
+ */
82
+ export declare const emit_supersede_audits: (ctx: ActionActorContext, audit: AuditEmitter, superseded: ReadonlyArray<SupersededOffer>, reason: RoleGrantOfferSupersedeParams["reason"], cause_id: Uuid) => Promise<void>;
63
83
  /**
64
84
  * Authorization callback for `role_grant_offer_create` and `role_grant_assign`.
65
85
  * Returns `true` to allow, `false` to reject (handler converts to `forbidden`
@@ -73,6 +93,10 @@ import type { RevokingActionFactoryDeps } from './deps.js';
73
93
  * role that must be scoped, a scope that must be real) holds on both paths.
74
94
  * Twin of the Rust `OfferCreateAuthorize`.
75
95
  *
96
+ * An offer authorized by a scoped grant must stay at that grant's scope: a
97
+ * scope teardown (`query_role_grant_revoke_for_scope`) supersedes only that
98
+ * scope's offers, so a revokee's offers elsewhere survive it.
99
+ *
76
100
  * `ctx` is the request's: both verbs have side effects, so `ctx.db` is the
77
101
  * request transaction, and a callback needing the database (a scope-existence
78
102
  * check, say) reads through it. **Read-only** — the callback decides, it never
@@ -115,7 +139,7 @@ export interface RoleGrantOfferActionOptions {
115
139
  *
116
140
  * @param deps - `RevokingActionFactoryDeps`: `log`, `audit`, and the `connection_closer` a revoked global grant closes the revokee's role-gated connections through. WS notifications go through the handler context's `notification_sender`, not a dep
117
141
  * @param options - role registry, default TTL, authorization override
118
- * @returns the `RpcAction` array to spread into a `create_rpc_endpoint` call
142
+ * @returns the `RpcAction` array to spread into an `RpcEndpointSpec`'s `actions`
119
143
  */
120
144
  export declare const create_role_grant_offer_actions: (deps: RevokingActionFactoryDeps, options?: RoleGrantOfferActionOptions) => Array<RpcAction>;
121
145
  //# sourceMappingURL=role_grant_offer_actions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"role_grant_offer_actions.d.ts","sourceRoot":"","sources":["../../src/lib/auth/role_grant_offer_actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,EAGN,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,MAAM,4BAA4B,CAAC;AAIpC,OAAO,EAMN,KAAK,YAAY,EACjB,MAAM,kBAAkB,CAAC;AAuC1B,OAAO,EAGN,KAAK,cAAc,EACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,yBAAyB,E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The offer-lifecycle methods (create / accept / decline / retract / list /
5
5
  * history) plus `role_grant_revoke` and `role_grant_assign` (both
6
6
  * admin-only). All mount
7
- * on a consumer's JSON-RPC endpoint via `create_rpc_endpoint`. The action
7
+ * on a consumer's JSON-RPC endpoint through `rpc_endpoints`. The action
8
8
  * specs themselves live in `auth/role_grant_offer_action_specs.ts`. Mutations
9
9
  * declare `side_effects: true` so the RPC dispatcher wraps the handler in
10
10
  * a DB transaction; `role_grant_offer_list` and `role_grant_offer_history` declare
@@ -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
@@ -110,7 +141,7 @@ const default_authorize = async (auth, _input, _deps, _ctx) => {
110
141
  *
111
142
  * @param deps - `RevokingActionFactoryDeps`: `log`, `audit`, and the `connection_closer` a revoked global grant closes the revokee's role-gated connections through. WS notifications go through the handler context's `notification_sender`, not a dep
112
143
  * @param options - role registry, default TTL, authorization override
113
- * @returns the `RpcAction` array to spread into a `create_rpc_endpoint` call
144
+ * @returns the `RpcAction` array to spread into an `RpcEndpointSpec`'s `actions`
114
145
  */
115
146
  export const create_role_grant_offer_actions = (deps, options = {}) => {
116
147
  const { log, audit, connection_closer } = deps;
@@ -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,qBAAa,0BAA2B,SAAQ,KAAK;gBACxC,QAAQ,EAAE,MAAM;CAI5B;AAED;;;;;GAKG;AACH,qBAAa,2BAA4B,SAAQ,KAAK;gBACzC,Q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@ -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,GACnC,MAAM,SAAS,EACf,OAAO,oBAAoB,KACzB,OAAO,CAAC,SAAS,CA8CnB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,sBAA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ql, 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,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AAe3D;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,oCAAoC,G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