@fuzdev/fuz_app 0.152.0 → 0.153.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 (159) hide show
  1. package/dist/actions/CLAUDE.md +14 -11
  2. package/dist/actions/action_rpc.js +3 -3
  3. package/dist/actions/action_types.d.ts +3 -3
  4. package/dist/actions/broadcast_api.d.ts +0 -6
  5. package/dist/actions/broadcast_api.d.ts.map +1 -1
  6. package/dist/actions/connection_closer.d.ts +14 -15
  7. package/dist/actions/connection_closer.d.ts.map +1 -1
  8. package/dist/actions/connection_closer.js +13 -13
  9. package/dist/actions/perform_action.d.ts +5 -1
  10. package/dist/actions/perform_action.d.ts.map +1 -1
  11. package/dist/actions/perform_action.js +57 -19
  12. package/dist/actions/register_action_ws.d.ts +6 -5
  13. package/dist/actions/register_action_ws.d.ts.map +1 -1
  14. package/dist/actions/register_action_ws.js +5 -6
  15. package/dist/auth/CLAUDE.md +44 -14
  16. package/dist/auth/account_actions.d.ts +2 -2
  17. package/dist/auth/account_actions.js +6 -6
  18. package/dist/auth/account_routes.js +9 -9
  19. package/dist/auth/admin_actions.d.ts +2 -1
  20. package/dist/auth/admin_actions.d.ts.map +1 -1
  21. package/dist/auth/admin_actions.js +21 -20
  22. package/dist/auth/audit_emitter.d.ts +111 -64
  23. package/dist/auth/audit_emitter.d.ts.map +1 -1
  24. package/dist/auth/audit_emitter.js +130 -55
  25. package/dist/auth/audit_log_queries.d.ts +9 -10
  26. package/dist/auth/audit_log_queries.d.ts.map +1 -1
  27. package/dist/auth/audit_log_queries.js +13 -10
  28. package/dist/auth/audit_log_routes.js +2 -2
  29. package/dist/auth/audit_log_schema.d.ts +6 -1
  30. package/dist/auth/audit_log_schema.d.ts.map +1 -1
  31. package/dist/auth/bootstrap_account.d.ts +4 -3
  32. package/dist/auth/bootstrap_account.d.ts.map +1 -1
  33. package/dist/auth/bootstrap_account.js +4 -3
  34. package/dist/auth/bootstrap_routes.js +2 -2
  35. package/dist/auth/cell_action_helpers.d.ts +3 -2
  36. package/dist/auth/cell_action_helpers.d.ts.map +1 -1
  37. package/dist/auth/cell_action_helpers.js +9 -10
  38. package/dist/auth/cell_actions.js +6 -6
  39. package/dist/auth/cell_data_schema.d.ts +5 -0
  40. package/dist/auth/cell_data_schema.d.ts.map +1 -1
  41. package/dist/auth/cell_data_schema.js +5 -0
  42. package/dist/auth/cell_field_actions.js +2 -2
  43. package/dist/auth/cell_grant_actions.js +2 -2
  44. package/dist/auth/cell_item_actions.js +3 -3
  45. package/dist/auth/deps.d.ts +12 -10
  46. package/dist/auth/deps.d.ts.map +1 -1
  47. package/dist/auth/middleware.js +1 -1
  48. package/dist/auth/request_context.d.ts +5 -10
  49. package/dist/auth/request_context.d.ts.map +1 -1
  50. package/dist/auth/request_context.js +10 -9
  51. package/dist/auth/role_grant_offer_actions.d.ts +11 -8
  52. package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
  53. package/dist/auth/role_grant_offer_actions.js +57 -41
  54. package/dist/auth/self_service_role_actions.d.ts +6 -5
  55. package/dist/auth/self_service_role_actions.d.ts.map +1 -1
  56. package/dist/auth/self_service_role_actions.js +17 -6
  57. package/dist/auth/session_cookie.d.ts +4 -4
  58. package/dist/auth/session_cookie.d.ts.map +1 -1
  59. package/dist/auth/session_cookie.js +0 -1
  60. package/dist/auth/session_middleware.d.ts +8 -5
  61. package/dist/auth/session_middleware.d.ts.map +1 -1
  62. package/dist/auth/session_middleware.js +10 -7
  63. package/dist/auth/signup_routes.js +6 -6
  64. package/dist/auth/standard_rpc_actions.d.ts +3 -2
  65. package/dist/auth/standard_rpc_actions.d.ts.map +1 -1
  66. package/dist/auth/standard_rpc_actions.js +3 -2
  67. package/dist/db/CLAUDE.md +10 -1
  68. package/dist/db/create_db.d.ts +18 -1
  69. package/dist/db/create_db.d.ts.map +1 -1
  70. package/dist/db/create_db.js +15 -4
  71. package/dist/db/db.d.ts +27 -0
  72. package/dist/db/db.d.ts.map +1 -1
  73. package/dist/db/db.js +26 -0
  74. package/dist/db/db_checkout_error.d.ts +36 -0
  75. package/dist/db/db_checkout_error.d.ts.map +1 -0
  76. package/dist/db/db_checkout_error.js +48 -0
  77. package/dist/db/db_pg.d.ts +83 -5
  78. package/dist/db/db_pg.d.ts.map +1 -1
  79. package/dist/db/db_pg.js +119 -9
  80. package/dist/db/pg_error.d.ts +4 -0
  81. package/dist/db/pg_error.d.ts.map +1 -1
  82. package/dist/db/pg_error.js +13 -3
  83. package/dist/dev/setup.d.ts +4 -2
  84. package/dist/dev/setup.d.ts.map +1 -1
  85. package/dist/dev/setup.js +12 -5
  86. package/dist/hono_context.d.ts +36 -6
  87. package/dist/hono_context.d.ts.map +1 -1
  88. package/dist/hono_context.js +29 -2
  89. package/dist/http/CLAUDE.md +11 -10
  90. package/dist/http/db_routes.d.ts +7 -12
  91. package/dist/http/db_routes.d.ts.map +1 -1
  92. package/dist/http/db_routes.js +32 -17
  93. package/dist/http/error_schemas.d.ts +12 -0
  94. package/dist/http/error_schemas.d.ts.map +1 -1
  95. package/dist/http/error_schemas.js +12 -0
  96. package/dist/http/jsonrpc_errors.d.ts +10 -0
  97. package/dist/http/jsonrpc_errors.d.ts.map +1 -1
  98. package/dist/http/jsonrpc_errors.js +14 -0
  99. package/dist/http/jsonrpc_helpers.d.ts +4 -0
  100. package/dist/http/jsonrpc_helpers.d.ts.map +1 -1
  101. package/dist/http/jsonrpc_helpers.js +8 -1
  102. package/dist/http/route_spec.d.ts +4 -4
  103. package/dist/http/route_spec.d.ts.map +1 -1
  104. package/dist/http/route_spec.js +20 -3
  105. package/dist/http/schema_helpers.d.ts +21 -0
  106. package/dist/http/schema_helpers.d.ts.map +1 -1
  107. package/dist/http/schema_helpers.js +38 -0
  108. package/dist/realtime/audit_log_sse.d.ts +2 -2
  109. package/dist/realtime/audit_log_sse.js +2 -2
  110. package/dist/server/app_backend.d.ts +25 -1
  111. package/dist/server/app_backend.d.ts.map +1 -1
  112. package/dist/server/app_backend.js +16 -3
  113. package/dist/server/app_error_handler.d.ts +30 -0
  114. package/dist/server/app_error_handler.d.ts.map +1 -0
  115. package/dist/server/app_error_handler.js +41 -0
  116. package/dist/server/app_server.d.ts +1 -1
  117. package/dist/server/app_server.d.ts.map +1 -1
  118. package/dist/server/app_server.js +6 -1
  119. package/dist/server/env.d.ts +8 -3
  120. package/dist/server/env.d.ts.map +1 -1
  121. package/dist/server/env.js +26 -4
  122. package/dist/testing/CLAUDE.md +22 -16
  123. package/dist/testing/audit_drift_guard.d.ts.map +1 -1
  124. package/dist/testing/audit_drift_guard.js +2 -0
  125. package/dist/testing/auth_apps.d.ts.map +1 -1
  126. package/dist/testing/auth_apps.js +2 -2
  127. package/dist/testing/cross_backend/conformance_case.d.ts +2 -0
  128. package/dist/testing/cross_backend/conformance_case.d.ts.map +1 -1
  129. package/dist/testing/cross_backend/conformance_case.js +8 -0
  130. package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
  131. package/dist/testing/cross_backend/conformance_table.js +24 -7
  132. package/dist/testing/cross_backend/default_backend_configs.d.ts +4 -0
  133. package/dist/testing/cross_backend/default_backend_configs.d.ts.map +1 -1
  134. package/dist/testing/cross_backend/default_backend_configs.js +7 -0
  135. package/dist/testing/cross_backend/rust_spine_stub_backend_config.d.ts +11 -0
  136. package/dist/testing/cross_backend/rust_spine_stub_backend_config.d.ts.map +1 -1
  137. package/dist/testing/cross_backend/testing_server_core.d.ts +1 -1
  138. package/dist/testing/cross_backend/ts_spine_backend_config.d.ts +15 -11
  139. package/dist/testing/cross_backend/ts_spine_backend_config.d.ts.map +1 -1
  140. package/dist/testing/cross_backend/ts_spine_backend_config.js +3 -12
  141. package/dist/testing/daemon_token_rotation.d.ts +4 -14
  142. package/dist/testing/daemon_token_rotation.d.ts.map +1 -1
  143. package/dist/testing/daemon_token_rotation.js +0 -12
  144. package/dist/testing/db.d.ts.map +1 -1
  145. package/dist/testing/db.js +7 -3
  146. package/dist/testing/middleware.d.ts.map +1 -1
  147. package/dist/testing/middleware.js +2 -2
  148. package/dist/testing/rpc_helpers.d.ts +19 -0
  149. package/dist/testing/rpc_helpers.d.ts.map +1 -1
  150. package/dist/testing/rpc_helpers.js +25 -2
  151. package/dist/testing/schema_parity.d.ts +1 -1
  152. package/dist/testing/stubs.js +2 -2
  153. package/dist/testing/surface_invariants.js +1 -1
  154. package/dist/testing/ws_round_trip.d.ts.map +1 -1
  155. package/dist/testing/ws_round_trip.js +3 -3
  156. package/dist/zod.d.ts +9 -0
  157. package/dist/zod.d.ts.map +1 -1
  158. package/dist/zod.js +1 -1
  159. package/package.json +3 -7
@@ -167,7 +167,7 @@ export const create_cell_grant_actions = (deps) => {
167
167
  principal,
168
168
  granted_by: auth.actor.id
169
169
  });
170
- emit_cell_audit(ctx, deps.audit, auth, 'cell_grant_create', {
170
+ await emit_cell_audit(ctx, deps.audit, auth, 'cell_grant_create', {
171
171
  cell_id: row.cell_id,
172
172
  grant_id: row.id,
173
173
  level: row.level,
@@ -227,7 +227,7 @@ export const create_cell_grant_actions = (deps) => {
227
227
  ...(is_self_actor_grant ? { self: true } : {}),
228
228
  ...(is_steward ? { steward: true } : {})
229
229
  };
230
- emit_cell_audit(ctx, deps.audit, auth, 'cell_grant_revoke', audit_metadata);
230
+ await emit_cell_audit(ctx, deps.audit, auth, 'cell_grant_revoke', audit_metadata);
231
231
  return { ok: true, still_admitted };
232
232
  };
233
233
  const list_handler = async (input, ctx) => {
@@ -69,7 +69,7 @@ export const create_cell_item_actions = (deps) => {
69
69
  throw position_taken_error();
70
70
  throw err;
71
71
  }
72
- emit_cell_audit(ctx, deps.audit, auth, 'cell_item_insert', {
72
+ await emit_cell_audit(ctx, deps.audit, auth, 'cell_item_insert', {
73
73
  parent_id: row.parent_id,
74
74
  position: row.position,
75
75
  child_id: row.child_id
@@ -92,7 +92,7 @@ export const create_cell_item_actions = (deps) => {
92
92
  // Source row missing — raced with deleter. 404 covers the gap.
93
93
  throw jsonrpc_errors.not_found('cell_item', { reason: ERROR_CELL_NOT_FOUND });
94
94
  }
95
- emit_cell_audit(ctx, deps.audit, auth, 'cell_item_move', {
95
+ await emit_cell_audit(ctx, deps.audit, auth, 'cell_item_move', {
96
96
  parent_id: row.parent_id,
97
97
  position_old: input.position,
98
98
  position_new: row.position
@@ -104,7 +104,7 @@ export const create_cell_item_actions = (deps) => {
104
104
  await require_editable_cell(ctx, auth, input.parent_id);
105
105
  const deleted = await query_cell_item_delete(ctx, input.parent_id, input.position);
106
106
  if (deleted) {
107
- emit_cell_audit(ctx, deps.audit, auth, 'cell_item_delete', {
107
+ await emit_cell_audit(ctx, deps.audit, auth, 'cell_item_delete', {
108
108
  parent_id: deleted.parent_id,
109
109
  position: deleted.position,
110
110
  child_id: deleted.child_id
@@ -43,9 +43,10 @@ export interface AppDeps {
43
43
  /**
44
44
  * Bound audit emitter. Closes over the pool, its registered listeners,
45
45
  * and the optional `AuditLogConfig`. Built once at backend assembly via
46
- * `create_audit_emitter` so handlers can never accidentally write audits
47
- * against the request transaction — there is no pool slot on the handler
48
- * context.
46
+ * `create_audit_emitter`. `emit` writes a success row in the request
47
+ * transaction when one is open and every other row on the captured pool
48
+ * (`auth/audit_emitter.ts`, "Where a row is written"). There is no pool
49
+ * slot on the handler context.
49
50
  */
50
51
  audit: AuditEmitter;
51
52
  /**
@@ -82,22 +83,23 @@ export type RouteFactoryDeps = Omit<AppDeps, 'db'>;
82
83
  *
83
84
  * The minimal slice every `create_*_actions` factory needs: a `log` for
84
85
  * RPC-internal error logging and the bound `audit` emitter for
85
- * fire-and-forget audit writes. `RouteFactoryDeps` (and `AppDeps`)
86
+ * audit writes. `RouteFactoryDeps` (and `AppDeps`)
86
87
  * satisfy it structurally, so consumers pass their fuller deps bundle
87
88
  * straight through.
88
89
  */
89
90
  export interface ActionFactoryDeps {
90
91
  /** Structured logger instance. */
91
92
  log: Logger;
92
- /** Bound audit emitter for fire-and-forget audit writes. */
93
+ /** Bound audit emitter for audit writes. */
93
94
  audit: AuditEmitter;
94
95
  }
95
96
  /**
96
- * Capabilities for the action factories whose handlers end credentials —
97
- * `create_account_actions`, `create_admin_actions`, and the
98
- * `create_standard_rpc_actions` bundle over them. `ActionFactoryDeps` plus
99
- * the closer their revocations close live connections through. `AppDeps`
100
- * and `RouteFactoryDeps` satisfy it structurally.
97
+ * Capabilities for the action factories whose handlers end credentials or
98
+ * revoke roles — `create_account_actions`, `create_admin_actions`,
99
+ * `create_role_grant_offer_actions`, `create_self_service_role_actions`, and
100
+ * the `create_standard_rpc_actions` bundle. `ActionFactoryDeps` plus the
101
+ * closer their revocations close live connections through. `AppDeps` and
102
+ * `RouteFactoryDeps` satisfy it structurally.
101
103
  */
102
104
  export interface RevokingActionFactoryDeps extends ActionFactoryDeps {
103
105
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"deps.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/auth/deps.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAExF;;;;;GAKG;AACH,MAAM,WAAW,OAAO;IACvB;;;;;;;OAOG;IACH,gBAAgB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IACxD,qBAAqB;IACrB,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7C,0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,OAAO;IACvB;;;;;;;OAOG;IACH,gBAAgB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IACxD,qBAAqB;IACrB,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7C,0CAA0C;IAC1C,OAAO,EAAE,OAAO,CAAC;IACjB,6EAA6E;IAC7E,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,yBAAyB;IACzB,EAAE,EAAE,EAAE,CAAC;IACP,kCAAkC;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ;;;;;;;OAOG;IACH,KAAK,EAAE,YAAY,CAAC;IACpB;;;;;;;;OAQG;IACH,iBAAiB,EAAE,cAAc,CAAC;IAClC;;;;;;;;;OASG;IACH,UAAU,CAAC,EAAE,aAAa,CAAC;CAC3B;AAED;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AAEnD;;;;;;;;GAQG;AACH,MAAM,WAAW,iBAAiB;IACjC,kCAAkC;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ,4CAA4C;IAC5C,KAAK,EAAE,YAAY,CAAC;CACpB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,yBAA0B,SAAQ,iBAAiB;IACnE;;;;;;OAMG;IACH,iBAAiB,EAAE,gBAAgB,CAAC;CACpC"}
@@ -226,7 +226,7 @@ export const create_auth_middleware_specs = async (deps, options) => {
226
226
  // Dynamic imports preserve the bundle-split for type-only consumers of
227
227
  // this module (`MiddlewareSpec`, `AuthMiddlewareOptions`, etc.). The
228
228
  // runtime chain pulls session_queries + blake3 transitively via
229
- // session_middleware.js, but type-only imports are erased at compile
229
+ // session_middleware.ts, but type-only imports are erased at compile
230
230
  // time and stay free.
231
231
  const [{ verify_request_source }, { create_session_middleware }, { create_request_context_middleware }, { create_bearer_auth_middleware }] = await Promise.all([
232
232
  import('../http/origin.js'),
@@ -194,12 +194,6 @@ export type ResolveActingActorResult = {
194
194
  export declare const resolve_acting_actor: (deps: QueryDeps, account_id: string, acting_actor_id: string | undefined) => Promise<ResolveActingActorResult>;
195
195
  /** Options for `create_request_context_middleware`. */
196
196
  export interface RequestContextMiddlewareOptions {
197
- /**
198
- * The Hono context key where session middleware stored the session token.
199
- *
200
- * @default 'auth_session_id'
201
- */
202
- session_context_key?: string;
203
197
  /**
204
198
  * Whether this leg starts the credential chain, clearing `RESOLVED_AUTH_KEY`
205
199
  * on entry so a layer mounted before the legs cannot pre-set an identity
@@ -223,7 +217,8 @@ export interface RequestContextMiddlewareOptions {
223
217
  *
224
218
  * When it starts the chain (`starts_chain`, the default) it first clears
225
219
  * `RESOLVED_AUTH_KEY`. It then skips when an earlier leg (the daemon token)
226
- * already resolved the request. Otherwise reads the session identity (set by session middleware), looks up
220
+ * already resolved the request. Otherwise reads the session token the session middleware set
221
+ * (`SESSION_TOKEN_KEY`), looks up
227
222
  * the `auth_session`, and on a valid session sets the `session` arm of
228
223
  * `ResolvedAuth` (`RESOLVED_AUTH_KEY`): the account, the session hash, and the
229
224
  * credential deadline — the earlier of the cookie's signed expiry
@@ -237,7 +232,7 @@ export interface RequestContextMiddlewareOptions {
237
232
  * `require_role` enforce.
238
233
  *
239
234
  * @param deps - query dependencies (pool-level db for middleware)
240
- * @param options - the session token's context key, whether this leg starts the chain, and the logger for a start that clears a credential
235
+ * @param options - whether this leg starts the chain, and the logger for a start that clears a credential
241
236
  * @mutates Hono context - resets `REQUEST_CONTEXT_KEY` (and `RESOLVED_AUTH_KEY` when it starts the chain), then on a valid session (and no credential already resolved) sets `RESOLVED_AUTH_KEY`
242
237
  */
243
238
  export declare const create_request_context_middleware: (deps: QueryDeps, options?: RequestContextMiddlewareOptions) => MiddlewareHandler;
@@ -518,8 +513,8 @@ export declare const apply_authorization_phase: (deps: QueryDeps, account_id: st
518
513
  * directly instead.
519
514
  *
520
515
  * Skipped for a public `auth` shape, and under the test-preset escape hatch:
521
- * harnesses that pre-populate `REQUEST_CONTEXT_KEY` flag
522
- * `TEST_CONTEXT_PRESET_KEY = true` so the phase trusts the supplied context
516
+ * harnesses that pre-populate `REQUEST_CONTEXT_KEY` set
517
+ * `TEST_CONTEXT_PRESET_KEY` to `TEST_CONTEXT_PRESET` so the phase trusts the supplied context
523
518
  * instead of running DB-backed resolution. Production middleware never sets
524
519
  * that flag.
525
520
  *
@@ -1 +1 @@
1
- {"version":3,"file":"request_context.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/auth/request_context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AACvD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,EACN,KAAK,OAAO,EACZ,KAAK,KAAK,EAEV,KAAK,SAAS,EACd,MAAM,qBAAqB,CAAC;AAQ7B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAarD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAA6C,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElG,OAAO,EAIN,oBAAoB,EACpB,0BAA0B,EAC1B,0BAA0B,EAC1B,sBAAsB,EACtB,MAAM,0BAA0B,CAAC;AAElC;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,cAAc;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;CAC9B;AAED,0DAA0D;AAC1D,eAAO,MAAM,mBAAmB,oBAAoB,CAAC;AAErD;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAAI,GAAG,OAAO,KAAG,cAAc,GAAG,IAEjE,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{ hash_session_token, query_session_get_valid } from './session_queries.js';
40
40
  import { query_account_by_id, query_actor_by_id, query_active_actors_by_account } from './account_queries.js';
41
41
  import { query_role_grant_find_active_for_actor } from './role_grant_queries.js';
42
- import { RESOLVED_AUTH_KEY, SESSION_COOKIE_EXPIRES_AT_KEY, TEST_CONTEXT_PRESET_KEY } from '../hono_context.js';
42
+ import { has_test_context_preset, RESOLVED_AUTH_KEY, SESSION_COOKIE_EXPIRES_AT_KEY, SESSION_TOKEN_KEY } from '../hono_context.js';
43
43
  import { credential_deadline_after } from './credential_deadline.js';
44
44
  import { get_resolved_auth, resolved_auth_scope } from './resolved_auth.js';
45
45
  import { is_route_scope_capability, token_scope_admits_non_rpc, token_scope_denied_body } from './token_scope.js';
@@ -185,7 +185,8 @@ export const resolve_acting_actor = async (deps, account_id, acting_actor_id) =>
185
185
  *
186
186
  * When it starts the chain (`starts_chain`, the default) it first clears
187
187
  * `RESOLVED_AUTH_KEY`. It then skips when an earlier leg (the daemon token)
188
- * already resolved the request. Otherwise reads the session identity (set by session middleware), looks up
188
+ * already resolved the request. Otherwise reads the session token the session middleware set
189
+ * (`SESSION_TOKEN_KEY`), looks up
189
190
  * the `auth_session`, and on a valid session sets the `session` arm of
190
191
  * `ResolvedAuth` (`RESOLVED_AUTH_KEY`): the account, the session hash, and the
191
192
  * credential deadline — the earlier of the cookie's signed expiry
@@ -199,11 +200,11 @@ export const resolve_acting_actor = async (deps, account_id, acting_actor_id) =>
199
200
  * `require_role` enforce.
200
201
  *
201
202
  * @param deps - query dependencies (pool-level db for middleware)
202
- * @param options - the session token's context key, whether this leg starts the chain, and the logger for a start that clears a credential
203
+ * @param options - whether this leg starts the chain, and the logger for a start that clears a credential
203
204
  * @mutates Hono context - resets `REQUEST_CONTEXT_KEY` (and `RESOLVED_AUTH_KEY` when it starts the chain), then on a valid session (and no credential already resolved) sets `RESOLVED_AUTH_KEY`
204
205
  */
205
206
  export const create_request_context_middleware = (deps, options = {}) => {
206
- const { session_context_key = 'auth_session_id', starts_chain = true, log } = options;
207
+ const { starts_chain = true, log } = options;
207
208
  return async (c, next) => {
208
209
  c.set(REQUEST_CONTEXT_KEY, null);
209
210
  if (starts_chain) {
@@ -218,7 +219,7 @@ export const create_request_context_middleware = (deps, options = {}) => {
218
219
  await next();
219
220
  return;
220
221
  }
221
- const session_token = c.get(session_context_key) ?? null;
222
+ const session_token = c.get(SESSION_TOKEN_KEY) ?? null;
222
223
  if (!session_token) {
223
224
  await next();
224
225
  return;
@@ -588,8 +589,8 @@ export const apply_authorization_phase = async (deps, account_id, auth, acting_v
588
589
  * directly instead.
589
590
  *
590
591
  * Skipped for a public `auth` shape, and under the test-preset escape hatch:
591
- * harnesses that pre-populate `REQUEST_CONTEXT_KEY` flag
592
- * `TEST_CONTEXT_PRESET_KEY = true` so the phase trusts the supplied context
592
+ * harnesses that pre-populate `REQUEST_CONTEXT_KEY` set
593
+ * `TEST_CONTEXT_PRESET_KEY` to `TEST_CONTEXT_PRESET` so the phase trusts the supplied context
593
594
  * instead of running DB-backed resolution. Production middleware never sets
594
595
  * that flag.
595
596
  *
@@ -601,7 +602,7 @@ export const apply_authorization_phase = async (deps, account_id, auth, acting_v
601
602
  * account), or nothing when the request may proceed
602
603
  */
603
604
  export const run_authorization_phase = async (c, deps, auth, acting) => {
604
- if (c.get(TEST_CONTEXT_PRESET_KEY))
605
+ if (has_test_context_preset(c))
605
606
  return;
606
607
  if (is_public_auth(auth))
607
608
  return;
@@ -638,7 +639,7 @@ export const run_authorization_phase = async (c, deps, auth, acting) => {
638
639
  export const create_fuz_authorization_handler = (deps) => {
639
640
  return async (c, spec) => {
640
641
  // the same skips `run_authorization_phase` makes, ahead of reading a body
641
- if (c.get(TEST_CONTEXT_PRESET_KEY) || is_public_auth(spec.auth))
642
+ if (has_test_context_preset(c) || is_public_auth(spec.auth))
642
643
  return;
643
644
  const acting_value = needs_actor(spec.auth) ? await read_route_acting(c, spec) : undefined;
644
645
  return run_authorization_phase(c, deps, spec.auth, acting_value);
@@ -38,15 +38,18 @@
38
38
  * no power to assign it.
39
39
  *
40
40
  * Audit events are emitted in-transaction by the query layer (atomic with
41
- * the role_grant write on accept/revoke) or by the handler via the bound
42
- * `deps.audit.emit_role_grant_target` helper for single-event lifecycle
43
- * transitions. `audit.notify` (SSE/WS broadcast) fires post-commit in both
44
- * paths.
41
+ * the role_grant write on accept) or by the handler via the bound
42
+ * `deps.audit.emit_role_grant_target` helper (revoke, assign, and the
43
+ * single-event lifecycle transitions — a success row written in the request
44
+ * transaction, a failure row on the pool). `audit.notify` (SSE/WS broadcast)
45
+ * fires post-commit in both paths.
45
46
  *
46
47
  * WS notifications fan out post-commit via `emit_after_commit` when a
47
48
  * `notification_sender` is wired: offer lifecycle transitions notify the
48
49
  * counterparty, `role_grant_revoke` notifies the revokee plus each superseded
49
- * pending offer's grantor.
50
+ * pending offer's grantor. `role_grant_revoke` of a global grant also closes
51
+ * the revokee's connections gated on the role through
52
+ * `deps.connection_closer`, after the commit.
50
53
  *
51
54
  * @module
52
55
  */
@@ -54,7 +57,7 @@ import type { Logger } from '@fuzdev/fuz_util/log.ts';
54
57
  import { type ActionContext, type RpcAction } from '../actions/action_types.js';
55
58
  import { type RoleSchemaResult } from './role_schema.js';
56
59
  import { type RequestContext } from './request_context.js';
57
- import type { ActionFactoryDeps } from './deps.js';
60
+ import type { RevokingActionFactoryDeps } from './deps.js';
58
61
  import { type NotificationSender } from './role_grant_offer_notifications.js';
59
62
  /**
60
63
  * Authorization callback for `role_grant_offer_create` and `role_grant_assign`.
@@ -109,11 +112,11 @@ export interface RoleGrantOfferActionOptions {
109
112
  * Create the role-grant-offer RPC actions: the offer-lifecycle methods plus
110
113
  * `role_grant_revoke` and the immediate `role_grant_assign`.
111
114
  *
112
- * @param deps - `ActionFactoryDeps` (`log`, `audit`) plus optional `notification_sender` for WS fan-out — when absent, WS fan-out is silently skipped (DB-only side effects still happen). Consumers wiring `ConnectionRegistry` assign its instance directly (the registry's `send_to_account` signature accepts the broader `JsonrpcMessageFromServerToClient`, which is contravariantly compatible)
115
+ * @param deps - `RevokingActionFactoryDeps` (`log`, `audit`, and the `connection_closer` a revoked global grant closes the revokee's role-gated connections through) plus optional `notification_sender` for WS fan-out — when absent, WS fan-out is silently skipped (DB-only side effects still happen). Consumers wiring `ConnectionRegistry` assign its instance directly (the registry's `send_to_account` signature accepts the broader `JsonrpcMessageFromServerToClient`, which is contravariantly compatible)
113
116
  * @param options - role schema, default TTL, authorization override
114
117
  * @returns the `RpcAction` array to spread into a `create_rpc_endpoint` call
115
118
  */
116
- export declare const create_role_grant_offer_actions: (deps: ActionFactoryDeps & {
119
+ export declare const create_role_grant_offer_actions: (deps: RevokingActionFactoryDeps & {
117
120
  notification_sender?: NotificationSender | null;
118
121
  }, options?: RoleGrantOfferActionOptions) => Array<RpcAction>;
119
122
  //# sourceMappingURL=role_grant_offer_actions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"role_grant_offer_actions.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/auth/role_grant_offer_actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,EAGN,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAMN,KAAK,gBAAgB,EACrB,MAAM,kBAAkB,CAAC;AAgC1B,OAAO,EAGN,KAAK,cAAc,EACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAEnD,OAAO,EAON,KAAK,kBAAkB,EACvB,MAAM,qCAAqC,CAAC;AA4C7C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,6BAA6B,GAAG,CAC3C,IAAI,EAAE,cAAc,EACpB,KAAK,EAAE;IACN,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB,EACD,IAAI,EAAE;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,EACrB,GAAG,EAAE,aAAa,KACd,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAEhC,qDAAqD;AACrD,MAAM,WAAW,2BAA2B;IAC3C;;;;;OAKG;IACH,KAAK,CAAC,EAAE,gBAAgB,CAAC;IACzB,0FAA0F;IAC1F,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;;;;OAQG;IACH,SAAS,CAAC,EAAE,6BAA6B,CAAC;CAC1C;AA6CD;;;;;;;GAOG;AACH,eAAO,MAAM,+BAA+B,GAC3C,MAAM,iBAAiB,GAAG;IACzB,mBAAmB,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAC;CAChD,EACD,UAAS,2BAAgC,KACvC,KAAK,CAAC,SAAS,CAksBjB,CAAC"}
1
+ {"version":3,"file":"role_grant_offer_actions.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/auth/role_grant_offer_actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;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,gBAAgB,EACrB,MAAM,kBAAkB,CAAC;AAgC1B,OAAO,EAGN,KAAK,cAAc,EACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AAE3D,OAAO,EAON,KAAK,kBAAkB,EACvB,MAAM,qCAAqC,CAAC;AA4C7C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,6BAA6B,GAAG,CAC3C,IAAI,EAAE,cAAc,EACpB,KAAK,EAAE;IACN,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB,EACD,IAAI,EAAE;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,EACrB,GAAG,EAAE,aAAa,KACd,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAEhC,qDAAqD;AACrD,MAAM,WAAW,2BAA2B;IAC3C;;;;;OAKG;IACH,KAAK,CAAC,EAAE,gBAAgB,CAAC;IACzB,0FAA0F;IAC1F,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;;;;OAQG;IACH,SAAS,CAAC,EAAE,6BAA6B,CAAC;CAC1C;AA6CD;;;;;;;GAOG;AACH,eAAO,MAAM,+BAA+B,GAC3C,MAAM,yBAAyB,GAAG;IACjC,mBAAmB,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAC;CAChD,EACD,UAAS,2BAAgC,KACvC,KAAK,CAAC,SAAS,CAitBjB,CAAC"}
@@ -38,21 +38,25 @@
38
38
  * no power to assign it.
39
39
  *
40
40
  * Audit events are emitted in-transaction by the query layer (atomic with
41
- * the role_grant write on accept/revoke) or by the handler via the bound
42
- * `deps.audit.emit_role_grant_target` helper for single-event lifecycle
43
- * transitions. `audit.notify` (SSE/WS broadcast) fires post-commit in both
44
- * paths.
41
+ * the role_grant write on accept) or by the handler via the bound
42
+ * `deps.audit.emit_role_grant_target` helper (revoke, assign, and the
43
+ * single-event lifecycle transitions — a success row written in the request
44
+ * transaction, a failure row on the pool). `audit.notify` (SSE/WS broadcast)
45
+ * fires post-commit in both paths.
45
46
  *
46
47
  * WS notifications fan out post-commit via `emit_after_commit` when a
47
48
  * `notification_sender` is wired: offer lifecycle transitions notify the
48
49
  * counterparty, `role_grant_revoke` notifies the revokee plus each superseded
49
- * pending offer's grantor.
50
+ * pending offer's grantor. `role_grant_revoke` of a global grant also closes
51
+ * the revokee's connections gated on the role through
52
+ * `deps.connection_closer`, after the commit.
50
53
  *
51
54
  * @module
52
55
  */
53
56
  import { rpc_action } from '../actions/action_types.js';
54
57
  import { jsonrpc_errors } from '../http/jsonrpc_errors.js';
55
58
  import { emit_after_commit } from '../http/pending_effects.js';
59
+ import { queue_connection_close } from '../actions/connection_closer.js';
56
60
  import { builtin_role_specs_by_name, is_builtin_role, ROLE_ADMIN, ROLE_KEEPER, role_has_grant_path } from './role_schema.js';
57
61
  import { GRANT_PATH_ADMIN } from './grant_path_schema.js';
58
62
  import { ROLE_GRANT_OFFER_DEFAULT_TTL_MS, to_role_grant_offer_json } from './role_grant_offer_schema.js';
@@ -102,12 +106,12 @@ const default_authorize = async (auth, _input, _deps, _ctx) => {
102
106
  * Create the role-grant-offer RPC actions: the offer-lifecycle methods plus
103
107
  * `role_grant_revoke` and the immediate `role_grant_assign`.
104
108
  *
105
- * @param deps - `ActionFactoryDeps` (`log`, `audit`) plus optional `notification_sender` for WS fan-out — when absent, WS fan-out is silently skipped (DB-only side effects still happen). Consumers wiring `ConnectionRegistry` assign its instance directly (the registry's `send_to_account` signature accepts the broader `JsonrpcMessageFromServerToClient`, which is contravariantly compatible)
109
+ * @param deps - `RevokingActionFactoryDeps` (`log`, `audit`, and the `connection_closer` a revoked global grant closes the revokee's role-gated connections through) plus optional `notification_sender` for WS fan-out — when absent, WS fan-out is silently skipped (DB-only side effects still happen). Consumers wiring `ConnectionRegistry` assign its instance directly (the registry's `send_to_account` signature accepts the broader `JsonrpcMessageFromServerToClient`, which is contravariantly compatible)
106
110
  * @param options - role schema, default TTL, authorization override
107
111
  * @returns the `RpcAction` array to spread into a `create_rpc_endpoint` call
108
112
  */
109
113
  export const create_role_grant_offer_actions = (deps, options = {}) => {
110
- const { log, audit, notification_sender = null } = deps;
114
+ const { log, audit, connection_closer, notification_sender = null } = deps;
111
115
  const role_specs = options.roles?.role_specs ?? builtin_role_specs_by_name;
112
116
  const default_ttl_ms = options.default_ttl_ms ?? ROLE_GRANT_OFFER_DEFAULT_TTL_MS;
113
117
  const authorize = options.authorize ?? default_authorize;
@@ -116,8 +120,8 @@ export const create_role_grant_offer_actions = (deps, options = {}) => {
116
120
  // same failure-outcome audit event. `target_actor_id` is populated when the
117
121
  // caller supplied a `to_actor_id` so failure rows match the success-shape
118
122
  // envelope of actor-targeted offers.
119
- const emit_create_failure_audit = (ctx, auth, input) => {
120
- audit.emit_role_grant_target(ctx, auth, {
123
+ const emit_create_failure_audit = async (ctx, auth, input) => {
124
+ await audit.emit_role_grant_target(ctx, auth, {
121
125
  event_type: 'role_grant_offer_create',
122
126
  outcome: 'failure',
123
127
  target_account_id: input.to_account_id,
@@ -136,26 +140,26 @@ export const create_role_grant_offer_actions = (deps, options = {}) => {
136
140
  // offer-create refusals. Metadata is the success row's shape minus
137
141
  // `role_grant_id` (no grant was minted), plus the wire `reason`. The offer
138
142
  // stays pending. Returns the error the verb answers.
139
- const refuse_builtin_accept = (ctx, auth, err) => {
143
+ const refuse_builtin_accept = async (ctx, auth, err) => {
140
144
  let error;
145
+ let data;
141
146
  switch (err.refusal) {
142
147
  case 'bootstrap_only':
143
148
  // `keeper`'s grant path is bootstrap-only — the offer-create answer
144
149
  // for a role no offer may confer
145
- error = jsonrpc_errors.forbidden('role not grantable', {
146
- reason: ERROR_ROLE_GRANT_OFFER_ROLE_NOT_GRANTABLE
147
- });
150
+ data = { reason: ERROR_ROLE_GRANT_OFFER_ROLE_NOT_GRANTABLE };
151
+ error = jsonrpc_errors.forbidden('role not grantable', data);
148
152
  break;
149
153
  case 'scoped':
150
- error = jsonrpc_errors.invalid_request({ reason: ERROR_ROLE_GRANT_BUILTIN_SCOPED });
154
+ data = { reason: ERROR_ROLE_GRANT_BUILTIN_SCOPED };
155
+ error = jsonrpc_errors.invalid_request(data);
151
156
  break;
152
157
  case 'grantor_not_authorized':
153
- error = jsonrpc_errors.forbidden("the offer's grantor can no longer confer this role", {
154
- reason: ERROR_ROLE_GRANT_OFFER_NOT_AUTHORIZED
155
- });
158
+ data = { reason: ERROR_ROLE_GRANT_OFFER_NOT_AUTHORIZED };
159
+ error = jsonrpc_errors.forbidden("the offer's grantor can no longer confer this role", data);
156
160
  break;
157
161
  }
158
- audit.emit_role_grant_target(ctx, auth, {
162
+ await audit.emit_role_grant_target(ctx, auth, {
159
163
  event_type: 'role_grant_offer_accept',
160
164
  outcome: 'failure',
161
165
  target_account_id: auth.account.id,
@@ -164,7 +168,7 @@ export const create_role_grant_offer_actions = (deps, options = {}) => {
164
168
  offer_id: err.offer.id,
165
169
  role: err.offer.role,
166
170
  scope_id: err.offer.scope_id,
167
- reason: error.data.reason
171
+ reason: data.reason
168
172
  }
169
173
  });
170
174
  return error;
@@ -178,7 +182,7 @@ export const create_role_grant_offer_actions = (deps, options = {}) => {
178
182
  const auth = ctx.auth;
179
183
  // Role must include the admin grant path — same gate as admin direct-grant.
180
184
  if (!role_has_grant_path(role_specs, input.role, GRANT_PATH_ADMIN)) {
181
- emit_create_failure_audit(ctx, auth, input);
185
+ await emit_create_failure_audit(ctx, auth, input);
182
186
  throw jsonrpc_errors.forbidden('role not grantable', {
183
187
  reason: ERROR_ROLE_GRANT_OFFER_ROLE_NOT_GRANTABLE
184
188
  });
@@ -186,7 +190,7 @@ export const create_role_grant_offer_actions = (deps, options = {}) => {
186
190
  // Builtin roles are global-only — refused before the injected callback,
187
191
  // so no consumer authorizer can admit a scoped `admin` / `keeper` offer.
188
192
  if (is_scoped_builtin(input.role, input.scope_id)) {
189
- emit_create_failure_audit(ctx, auth, input);
193
+ await emit_create_failure_audit(ctx, auth, input);
190
194
  throw builtin_scoped_error();
191
195
  }
192
196
  // Offering a builtin role is global-admin authority, decided here rather
@@ -195,7 +199,7 @@ export const create_role_grant_offer_actions = (deps, options = {}) => {
195
199
  // row offer a global `admin` to a second account it controls. Same denial
196
200
  // the default callback gives.
197
201
  if (is_builtin_role(input.role) && !has_scoped_role(auth, ROLE_ADMIN, null)) {
198
- emit_create_failure_audit(ctx, auth, input);
202
+ await emit_create_failure_audit(ctx, auth, input);
199
203
  throw jsonrpc_errors.forbidden('not authorized to offer this role', {
200
204
  reason: ERROR_ROLE_GRANT_OFFER_NOT_AUTHORIZED
201
205
  });
@@ -207,7 +211,7 @@ export const create_role_grant_offer_actions = (deps, options = {}) => {
207
211
  scope_id: input.scope_id ?? null
208
212
  }, { log }, ctx);
209
213
  if (!authorized) {
210
- emit_create_failure_audit(ctx, auth, input);
214
+ await emit_create_failure_audit(ctx, auth, input);
211
215
  throw jsonrpc_errors.forbidden('not authorized to offer this role', {
212
216
  reason: ERROR_ROLE_GRANT_OFFER_NOT_AUTHORIZED
213
217
  });
@@ -227,13 +231,13 @@ export const create_role_grant_offer_actions = (deps, options = {}) => {
227
231
  }
228
232
  catch (err) {
229
233
  if (err instanceof RoleGrantOfferSelfTargetError) {
230
- emit_create_failure_audit(ctx, auth, input);
234
+ await emit_create_failure_audit(ctx, auth, input);
231
235
  throw jsonrpc_errors.invalid_params('cannot offer to self', {
232
236
  reason: ERROR_ROLE_GRANT_OFFER_SELF_TARGET
233
237
  });
234
238
  }
235
239
  if (err instanceof RoleGrantOfferActorAccountMismatchError) {
236
- emit_create_failure_audit(ctx, auth, input);
240
+ await emit_create_failure_audit(ctx, auth, input);
237
241
  throw jsonrpc_errors.invalid_params('to_actor_id does not belong to to_account_id', {
238
242
  reason: ERROR_ROLE_GRANT_OFFER_ACTOR_ACCOUNT_MISMATCH
239
243
  });
@@ -244,7 +248,7 @@ export const create_role_grant_offer_actions = (deps, options = {}) => {
244
248
  // (per the offer's `to_actor_id`), null for account-grain offers
245
249
  // — closes the audit hole where offer-shape events used to leave
246
250
  // actor-grain forensics blank even when the binding was known.
247
- audit.emit_role_grant_target(ctx, auth, {
251
+ await audit.emit_role_grant_target(ctx, auth, {
248
252
  event_type: 'role_grant_offer_create',
249
253
  target_account_id: input.to_account_id,
250
254
  target_actor_id: offer.to_actor_id,
@@ -290,7 +294,7 @@ export const create_role_grant_offer_actions = (deps, options = {}) => {
290
294
  });
291
295
  }
292
296
  if (err instanceof RoleGrantOfferBuiltinRefusedError) {
293
- throw refuse_builtin_accept(ctx, auth, err);
297
+ throw await refuse_builtin_accept(ctx, auth, err);
294
298
  }
295
299
  throw err;
296
300
  }
@@ -361,7 +365,7 @@ export const create_role_grant_offer_actions = (deps, options = {}) => {
361
365
  // (the grantor account, joined in the decline RETURNING via CTE).
362
366
  // The "both populated → same account" invariant holds: the
363
367
  // grantor's actor↔account binding is 1:1 by definition of `actor`.
364
- audit.emit_role_grant_target(ctx, auth, {
368
+ await audit.emit_role_grant_target(ctx, auth, {
365
369
  event_type: 'role_grant_offer_decline',
366
370
  target_account_id: declined.from_account_id,
367
371
  target_actor_id: declined.from_actor_id,
@@ -404,7 +408,7 @@ export const create_role_grant_offer_actions = (deps, options = {}) => {
404
408
  // `target_account_id` is the recipient account; `target_actor_id`
405
409
  // inherits the offer's `to_actor_id` (set on actor-targeted
406
410
  // offers, null on account-grain offers).
407
- audit.emit_role_grant_target(ctx, auth, {
411
+ await audit.emit_role_grant_target(ctx, auth, {
408
412
  event_type: 'role_grant_offer_retract',
409
413
  target_account_id: retracted.to_account_id,
410
414
  target_actor_id: retracted.to_actor_id,
@@ -462,8 +466,8 @@ export const create_role_grant_offer_actions = (deps, options = {}) => {
462
466
  const target_actor_id = input.actor_id;
463
467
  // Admin-grant-path gate — keeper / daemon-scoped roles stay CLI-only
464
468
  // (their `grant_paths` does not include `'admin'`).
465
- const emit_revoke_failure = () => {
466
- audit.emit_role_grant_target(ctx, auth, {
469
+ const emit_revoke_failure = async () => {
470
+ await audit.emit_role_grant_target(ctx, auth, {
467
471
  event_type: 'role_grant_revoke',
468
472
  outcome: 'failure',
469
473
  target_account_id,
@@ -472,7 +476,7 @@ export const create_role_grant_offer_actions = (deps, options = {}) => {
472
476
  });
473
477
  };
474
478
  if (!role_has_grant_path(role_specs, role_grant_row.role, GRANT_PATH_ADMIN)) {
475
- emit_revoke_failure();
479
+ await emit_revoke_failure();
476
480
  throw jsonrpc_errors.forbidden('role not web-grantable', {
477
481
  reason: ERROR_ROLE_NOT_WEB_GRANTABLE
478
482
  });
@@ -486,14 +490,14 @@ export const create_role_grant_offer_actions = (deps, options = {}) => {
486
490
  // revoke or account removal can't pass the same guard.
487
491
  if (role_grant_row.role === ROLE_ADMIN && role_grant_row.scope_id === null) {
488
492
  if (await query_account_has_global_role(ctx, target_account_id, ROLE_KEEPER)) {
489
- emit_revoke_failure();
493
+ await emit_revoke_failure();
490
494
  throw jsonrpc_errors.forbidden("cannot revoke the keeper account's admin grant", {
491
495
  reason: ERROR_CANNOT_REVOKE_KEEPER_ADMIN
492
496
  });
493
497
  }
494
498
  if ((await query_account_has_active_global_role(ctx, target_account_id, ROLE_ADMIN)) &&
495
499
  (await query_count_active_accounts_with_global_role_for_update(ctx, ROLE_ADMIN, input.role_grant_id)) === 0) {
496
- emit_revoke_failure();
500
+ await emit_revoke_failure();
497
501
  throw jsonrpc_errors.forbidden("cannot revoke the last admin's admin grant", {
498
502
  reason: ERROR_CANNOT_REVOKE_LAST_ADMIN
499
503
  });
@@ -510,7 +514,19 @@ export const create_role_grant_offer_actions = (deps, options = {}) => {
510
514
  // accept. Every outgoing offer of the actor goes, superseded like the
511
515
  // revokee's incoming siblings (same reason, same cause, same fan-out).
512
516
  result.superseded_offers.push(...(await query_role_grant_offer_supersede_outgoing(ctx, [input.actor_id])));
513
- audit.emit_role_grant_target(ctx, auth, {
517
+ // Close the revokee's connections gated on the role once the revoke has
518
+ // committed — queued, so never before the commit or on rollback, and not
519
+ // riding on the audit row's announcement below (the revocation guard
520
+ // repeats it when the row is announced). Global grants only: a role gate admits on global grants
521
+ // alone, so a scoped revoke has nothing to close.
522
+ if (result.scope_id === null) {
523
+ queue_connection_close(ctx, connection_closer, {
524
+ kind: 'role',
525
+ account_id: target_account_id,
526
+ role: result.role
527
+ });
528
+ }
529
+ await audit.emit_role_grant_target(ctx, auth, {
514
530
  event_type: 'role_grant_revoke',
515
531
  target_account_id,
516
532
  target_actor_id,
@@ -526,7 +542,7 @@ export const create_role_grant_offer_actions = (deps, options = {}) => {
526
542
  // `target_actor_id` inherits the offer's `to_actor_id` (actor-grain
527
543
  // when the superseded offer was actor-targeted, null otherwise).
528
544
  for (const offer of result.superseded_offers) {
529
- audit.emit_role_grant_target(ctx, auth, {
545
+ await audit.emit_role_grant_target(ctx, auth, {
530
546
  event_type: 'role_grant_offer_supersede',
531
547
  target_account_id: offer.to_account_id,
532
548
  target_actor_id: offer.to_actor_id,
@@ -589,8 +605,8 @@ export const create_role_grant_offer_actions = (deps, options = {}) => {
589
605
  // omitted — no grant was created).
590
606
  const admin_grantable = role_has_grant_path(role_specs, input.role, GRANT_PATH_ADMIN);
591
607
  const builtin_scoped = is_scoped_builtin(input.role, input.scope_id);
592
- const emit_assign_failure_audit = () => {
593
- audit.emit_role_grant_target(ctx, auth, {
608
+ const emit_assign_failure_audit = async () => {
609
+ await audit.emit_role_grant_target(ctx, auth, {
594
610
  event_type: 'role_grant_create',
595
611
  outcome: 'failure',
596
612
  target_account_id: input.to_account_id,
@@ -603,7 +619,7 @@ export const create_role_grant_offer_actions = (deps, options = {}) => {
603
619
  });
604
620
  };
605
621
  if (builtin_scoped || !admin_grantable) {
606
- emit_assign_failure_audit();
622
+ await emit_assign_failure_audit();
607
623
  if (builtin_scoped && admin_grantable)
608
624
  throw builtin_scoped_error();
609
625
  throw jsonrpc_errors.forbidden('role not web-grantable', {
@@ -621,7 +637,7 @@ export const create_role_grant_offer_actions = (deps, options = {}) => {
621
637
  scope_id: input.scope_id ?? null
622
638
  }, { log }, ctx);
623
639
  if (!authorized) {
624
- emit_assign_failure_audit();
640
+ await emit_assign_failure_audit();
625
641
  throw jsonrpc_errors.forbidden('not authorized to grant this role', {
626
642
  reason: ERROR_ROLE_GRANT_OFFER_NOT_AUTHORIZED
627
643
  });
@@ -659,7 +675,7 @@ export const create_role_grant_offer_actions = (deps, options = {}) => {
659
675
  scope_id: input.scope_id ?? null,
660
676
  granted_by: auth.actor.id
661
677
  });
662
- audit.emit_role_grant_target(ctx, auth, {
678
+ await audit.emit_role_grant_target(ctx, auth, {
663
679
  event_type: 'role_grant_create',
664
680
  target_account_id: input.to_account_id,
665
681
  target_actor_id,
@@ -38,7 +38,7 @@
38
38
  */
39
39
  import { type RpcAction } from '../actions/action_types.js';
40
40
  import { type RoleSchemaResult } from './role_schema.js';
41
- import type { ActionFactoryDeps } from './deps.js';
41
+ import type { RevokingActionFactoryDeps } from './deps.js';
42
42
  /**
43
43
  * Validate a deployment's self-service eligible-role set at construction.
44
44
  *
@@ -77,13 +77,14 @@ export interface SelfServiceRoleActionsOptions {
77
77
  /**
78
78
  * Build the unified self-service role toggle RPC action.
79
79
  *
80
- * @param deps - `ActionFactoryDeps` (`log`, `audit`); `audit.emit` writes
81
- * audit rows via the captured pool. The bound emitter encapsulates
82
- * `on_audit_event` fan-out and the optional `AuditLogConfig`.
80
+ * @param deps - `RevokingActionFactoryDeps` (`log`, `audit`,
81
+ * `connection_closer`); `audit.emit` writes a success row in the request
82
+ * transaction and a failure row via the captured pool, and a disable closes the caller's connections gated on the role
83
+ * through `connection_closer`.
83
84
  * @param options - optional eligible-role override plus optional role schema for default-eligibility derivation
84
85
  * @returns the `RpcAction` array to spread into a `create_rpc_endpoint` call
85
86
  * @throws Error at factory time if any `eligible_roles` entry is missing from `options.roles.role_specs`
86
87
  * @throws Error at factory time if the eligible set names a builtin role or an invalid role name
87
88
  */
88
- export declare const create_self_service_role_actions: (deps: ActionFactoryDeps, options?: SelfServiceRoleActionsOptions) => Array<RpcAction>;
89
+ export declare const create_self_service_role_actions: (deps: RevokingActionFactoryDeps, options?: SelfServiceRoleActionsOptions) => Array<RpcAction>;
89
90
  //# sourceMappingURL=self_service_role_actions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"self_service_role_actions.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/auth/self_service_role_actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,EAAuC,KAAK,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAEjG,OAAO,EAKN,KAAK,gBAAgB,EACrB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAWnD;;;;;;;;;;;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,gBAAgB,CAAC;CACzB;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,gCAAgC,GAC5C,MAAM,iBAAiB,EACvB,UAAS,6BAAkC,KACzC,KAAK,CAAC,SAAS,CAiJjB,CAAC"}
1
+ {"version":3,"file":"self_service_role_actions.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/auth/self_service_role_actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,EAAuC,KAAK,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAGjG,OAAO,EAKN,KAAK,gBAAgB,EACrB,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,gBAAgB,CAAC;CACzB;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,gCAAgC,GAC5C,MAAM,yBAAyB,EAC/B,UAAS,6BAAkC,KACzC,KAAK,CAAC,SAAS,CA0JjB,CAAC"}