@fuzdev/fuz_app 0.152.0 → 0.154.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 (177) 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/env/env_schemas.d.ts +41 -0
  87. package/dist/env/env_schemas.d.ts.map +1 -0
  88. package/dist/env/env_schemas.js +55 -0
  89. package/dist/env/load.d.ts +23 -15
  90. package/dist/env/load.d.ts.map +1 -1
  91. package/dist/env/load.js +38 -22
  92. package/dist/hono_context.d.ts +36 -6
  93. package/dist/hono_context.d.ts.map +1 -1
  94. package/dist/hono_context.js +29 -2
  95. package/dist/http/CLAUDE.md +11 -10
  96. package/dist/http/db_routes.d.ts +7 -12
  97. package/dist/http/db_routes.d.ts.map +1 -1
  98. package/dist/http/db_routes.js +32 -17
  99. package/dist/http/error_schemas.d.ts +12 -0
  100. package/dist/http/error_schemas.d.ts.map +1 -1
  101. package/dist/http/error_schemas.js +12 -0
  102. package/dist/http/jsonrpc_errors.d.ts +10 -0
  103. package/dist/http/jsonrpc_errors.d.ts.map +1 -1
  104. package/dist/http/jsonrpc_errors.js +14 -0
  105. package/dist/http/jsonrpc_helpers.d.ts +4 -0
  106. package/dist/http/jsonrpc_helpers.d.ts.map +1 -1
  107. package/dist/http/jsonrpc_helpers.js +8 -1
  108. package/dist/http/route_spec.d.ts +4 -4
  109. package/dist/http/route_spec.d.ts.map +1 -1
  110. package/dist/http/route_spec.js +20 -3
  111. package/dist/http/schema_helpers.d.ts +21 -0
  112. package/dist/http/schema_helpers.d.ts.map +1 -1
  113. package/dist/http/schema_helpers.js +38 -0
  114. package/dist/http/surface.d.ts +13 -9
  115. package/dist/http/surface.d.ts.map +1 -1
  116. package/dist/http/surface.js +22 -18
  117. package/dist/realtime/audit_log_sse.d.ts +2 -2
  118. package/dist/realtime/audit_log_sse.js +2 -2
  119. package/dist/schema_meta.d.ts +4 -2
  120. package/dist/schema_meta.d.ts.map +1 -1
  121. package/dist/schema_meta.js +4 -2
  122. package/dist/sensitivity.d.ts +34 -1
  123. package/dist/sensitivity.d.ts.map +1 -1
  124. package/dist/sensitivity.js +32 -2
  125. package/dist/server/app_backend.d.ts +25 -1
  126. package/dist/server/app_backend.d.ts.map +1 -1
  127. package/dist/server/app_backend.js +16 -3
  128. package/dist/server/app_error_handler.d.ts +30 -0
  129. package/dist/server/app_error_handler.d.ts.map +1 -0
  130. package/dist/server/app_error_handler.js +41 -0
  131. package/dist/server/app_server.d.ts +7 -6
  132. package/dist/server/app_server.d.ts.map +1 -1
  133. package/dist/server/app_server.js +6 -2
  134. package/dist/server/env.d.ts +55 -28
  135. package/dist/server/env.d.ts.map +1 -1
  136. package/dist/server/env.js +46 -29
  137. package/dist/testing/CLAUDE.md +23 -17
  138. package/dist/testing/app_server.js +2 -2
  139. package/dist/testing/audit_drift_guard.d.ts.map +1 -1
  140. package/dist/testing/audit_drift_guard.js +2 -0
  141. package/dist/testing/auth_apps.d.ts.map +1 -1
  142. package/dist/testing/auth_apps.js +2 -2
  143. package/dist/testing/cross_backend/conformance_case.d.ts +2 -0
  144. package/dist/testing/cross_backend/conformance_case.d.ts.map +1 -1
  145. package/dist/testing/cross_backend/conformance_case.js +8 -0
  146. package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
  147. package/dist/testing/cross_backend/conformance_table.js +24 -7
  148. package/dist/testing/cross_backend/default_backend_configs.d.ts +4 -0
  149. package/dist/testing/cross_backend/default_backend_configs.d.ts.map +1 -1
  150. package/dist/testing/cross_backend/default_backend_configs.js +7 -0
  151. package/dist/testing/cross_backend/rust_spine_stub_backend_config.d.ts +11 -0
  152. package/dist/testing/cross_backend/rust_spine_stub_backend_config.d.ts.map +1 -1
  153. package/dist/testing/cross_backend/testing_server_core.d.ts +1 -1
  154. package/dist/testing/cross_backend/ts_spine_backend_config.d.ts +15 -11
  155. package/dist/testing/cross_backend/ts_spine_backend_config.d.ts.map +1 -1
  156. package/dist/testing/cross_backend/ts_spine_backend_config.js +3 -12
  157. package/dist/testing/daemon_token_rotation.d.ts +4 -14
  158. package/dist/testing/daemon_token_rotation.d.ts.map +1 -1
  159. package/dist/testing/daemon_token_rotation.js +0 -12
  160. package/dist/testing/db.d.ts.map +1 -1
  161. package/dist/testing/db.js +7 -3
  162. package/dist/testing/middleware.d.ts.map +1 -1
  163. package/dist/testing/middleware.js +2 -2
  164. package/dist/testing/rpc_helpers.d.ts +19 -0
  165. package/dist/testing/rpc_helpers.d.ts.map +1 -1
  166. package/dist/testing/rpc_helpers.js +25 -2
  167. package/dist/testing/schema_parity.d.ts +1 -1
  168. package/dist/testing/stubs.d.ts +2 -2
  169. package/dist/testing/stubs.d.ts.map +1 -1
  170. package/dist/testing/stubs.js +2 -2
  171. package/dist/testing/surface_invariants.js +1 -1
  172. package/dist/testing/ws_round_trip.d.ts.map +1 -1
  173. package/dist/testing/ws_round_trip.js +3 -3
  174. package/dist/zod.d.ts +9 -0
  175. package/dist/zod.d.ts.map +1 -1
  176. package/dist/zod.js +1 -1
  177. package/package.json +6 -10
@@ -197,7 +197,7 @@ Shim responsibilities (per-request):
197
197
  1. Parse envelope (POST body / GET query string); parse errors → `parse_error` 400. GET reads `method` / `id` / `params` via Hono's `c.req.query()` — first occurrence wins on a duplicated key, unknown keys are ignored, and an empty value counts as missing. This is the cross-impl contract (the Rust GET dispatch mirrors it via `fuz_http`'s `query_first`, including the id numeric-vs-string normalization), pinned by the `query_shape` cross suite.
198
198
  2. Lookup method in the `compile_action_registry`-built map; unknown → `method_not_found`.
199
199
  3. GET read restriction — GET rejected for `side_effects: true` actions. Every response the GET handler writes, its refusals included, carries `Cache-Control: no-store` (`RPC_GET_CACHE_CONTROL`; a pre-handler middleware refusal, like the origin 403, does not): a read answers one caller at one moment.
200
- 4. Build `PerformActionInput` from `get_resolved_auth(c)` + `get_client_ip` + `c.req.raw.signal`. Test-preset escape hatch reads `TEST_CONTEXT_PRESET_KEY` + `REQUEST_CONTEXT_KEY`.
200
+ 4. Build `PerformActionInput` from `get_resolved_auth(c)` + `get_client_ip` + `c.req.raw.signal`. Test-preset escape hatch reads `has_test_context_preset(c)` + `REQUEST_CONTEXT_KEY`.
201
201
  5. Call `perform_action` (shared core).
202
202
  6. Bind result via `serialize_action_result(id, result, method, log)` (`actions/perform_action.ts`, shared with WS) → `{body, status}`, written with `c.json`'s content type.
203
203
 
@@ -281,7 +281,7 @@ Pipeline (401 → authz → 403 → 429 → 400 → handler):
281
281
  2. Authorization phase — `apply_authorization_phase` against `account_id` + `read_acting(auth, raw_params)`, which takes the selector off the raw params (malformed reads as omitted) since validation runs later. Test escape hatch via `preset.request_context`
282
282
  3. Post-authorization auth (403) — credential-type gate, then token scope, then role
283
283
  4. Rate limit (429) — throttle-requests semantics, ahead of validation so malformed params charge the budget and a throttled caller pays no schema work
284
- 5. Validate params (400) — `spec.input.safeParse` with `z.void()` / `?? {}` rules; a `z.void()` input reads absent, `null` (GET `?params=null`), and `{}` alike as the no-arg call (`to_input_params` in `http/schema_helpers.ts`, via `to_void_params`, the twin of the Rust `require_void_params`; the peer receive path in `ActionDispatcher` runs the same normalizer) and refuses any other shape. A refusal is `to_invalid_params_error`: the generic `invalid params`, `data.reason` when the first issue's field declares an `invalid_reason` in its `.meta()` and no issue sits on the input itself, such as an unknown key (`resolve_issues_invalid_reason`, `schema_meta.ts` — see ../../../docs/architecture.md §Error Schema System), and the Zod issues DEV-only
284
+ 5. Validate params (400) — first, object params holding an own `__proto__` key at any depth are refused on every input with `data.reason` `params_proto_key` (`json_has_own_proto_key` in `http/schema_helpers.ts`, an iterative walk; `ERROR_PARAMS_PROTO_KEY`; the Rust twin walks after its params-shape check, so a non-object `params` stays the schema's reasonless refusal); then `spec.input.safeParse` with `z.void()` / `?? {}` rules; a `z.void()` input reads absent, `null` (GET `?params=null`), and `{}` alike as the no-arg call (`to_input_params` in `http/schema_helpers.ts`, via `to_void_params`, the twin of the Rust `require_void_params`; the peer receive path in `ActionDispatcher` runs the same normalizer) and refuses any other shape. A refusal is `to_invalid_params_error`: the generic `invalid params`, `data.reason` when the first issue's field declares an `invalid_reason` in its `.meta()` and no issue sits on the input itself, such as an unknown key (`resolve_issues_invalid_reason`, `schema_meta.ts` — see ../../../docs/architecture.md §Error Schema System), and the Zod issues DEV-only
285
285
  6. Dispatch + DEV output validation + error normalization — `spec.side_effects` picks transaction vs pool. `ThrownJsonrpcError` preserves code + data; generic throws become `internal_error`
286
286
 
287
287
  `PerformActionInput` carries `auth` (the request's `ResolvedAuth`, `null` for
@@ -632,8 +632,9 @@ type ConnectionCloseTarget =
632
632
  `create_sse_connection_closer(registry, required_role)` (`realtime/audit_log_sse.ts`) adapts
633
633
  an `SseRegistry` (`close_all_connections` is `SseRegistry.close_all`;
634
634
  a `role` target closes the account's streams when `role` is the
635
- registry's gating role). No handler closes for a role: a role revocation's
636
- closes come from the revocation guard alone (below).
635
+ registry's gating role). The role revokes (`role_grant_revoke` of a global
636
+ grant, a self-service disable) queue that close themselves, and the revocation
637
+ guard (below) repeats it.
637
638
  Closing is idempotent and synchronous. `close_all_connections` is the one method no
638
639
  revocation calls: `AppServer.close` runs it on `deps.connection_closer` to end
639
640
  every live connection of the backend at shutdown, and it has no
@@ -662,8 +663,8 @@ its credential, so a close that missed the registration must belong to a
662
663
  revocation the re-read can see — true only if the close came after the commit
663
664
  (../../../docs/security.md §Closing on Revocation).
664
665
 
665
- The close does not depend on the audit write, which is pool-routed and
666
- fail-open. Failure outcomes (`revoked: false`, a 404) queue no close — they
666
+ The close does not depend on the audit row's announcement (a row written
667
+ outside a transaction — `/login`, `/password` — is fail-open). Failure outcomes (`revoked: false`, a 404) queue no close — they
667
668
  carry caller-supplied ids.
668
669
 
669
670
  **One closer for every transport.** `create_realtime_closer()` returns a
@@ -687,7 +688,8 @@ live-connection surface.
687
688
 
688
689
  It is required where it is read, so it can't be forgotten:
689
690
  `RevokingActionFactoryDeps.connection_closer` (`create_account_actions`,
690
- `create_admin_actions`, `create_standard_rpc_actions`), `AppDeps` /
691
+ `create_admin_actions`, `create_role_grant_offer_actions`,
692
+ `create_self_service_role_actions`, `create_standard_rpc_actions`), `AppDeps` /
691
693
  `RouteFactoryDeps` (`create_account_route_specs`),
692
694
  `AuthCleanupDeps.connection_closer` (the auth cleanup's session sweep closes
693
695
  the connections of each expired session it deletes — `auth/CLAUDE.md`
@@ -733,8 +735,8 @@ included) maps to nothing:
733
735
  dispatch re-authorizes each request against its own action, but nothing
734
736
  re-checks what a connection admitted by a role gate receives — every push its
735
737
  endpoint sends, every row the stream sends — so a socket closes with
736
- `WS_CLOSE_PERMISSION_REVOKED` and a stream gated on the role ends. No handler
737
- closes for a role, so this guard is the one closer.
738
+ `WS_CLOSE_PERMISSION_REVOKED` and a stream gated on the role ends. The role
739
+ revokes queue the same close themselves; this is its repeat.
738
740
  - `none` → nothing — every other event, and any event type fuz_app doesn't
739
741
  define
740
742
 
@@ -941,8 +943,9 @@ heartbeat activity.
941
943
  `apply_authorization_phase` per-message (HTTP and WS uniformly). Role grant
942
944
  changes during a connection lifetime are picked up on the next message —
943
945
  no in-place refresh. A revoked global grant of a role the endpoint's
944
- `required_roles` lists closes the socket (`WS_CLOSE_PERMISSION_REVOKED`,
945
- through the revocation guard), since nothing else re-checks what it
946
+ `required_roles` lists closes the socket (`WS_CLOSE_PERMISSION_REVOKED` —
947
+ the revoking handler through `connection_closer`, the revocation guard
948
+ repeating it), since nothing else re-checks what it
946
949
  receives. Authentication
947
950
  invalidation (a session or token revoke, `password_change`, a logout, an
948
951
  account delete, a cap eviction) still closes the socket — the revoking
@@ -19,7 +19,7 @@ import {} from '../http/route_spec.js';
19
19
  import { get_client_ip } from '../http/client_ip.js';
20
20
  import { get_request_context } from '../auth/request_context.js';
21
21
  import { get_resolved_auth } from '../auth/resolved_auth.js';
22
- import { TEST_CONTEXT_PRESET_KEY } from '../hono_context.js';
22
+ import { has_test_context_preset } from '../hono_context.js';
23
23
  import { compile_action_registry } from './compile_action_registry.js';
24
24
  import { jsonrpc_error_messages, jsonrpc_error_code_to_http_status, JSONRPC_ERROR_CODES } from '../http/jsonrpc_errors.js';
25
25
  import { classify_jsonrpc_message, create_jsonrpc_error_response } from '../http/jsonrpc_helpers.js';
@@ -108,10 +108,10 @@ export const create_rpc_endpoint = (options) => {
108
108
  }
109
109
  };
110
110
  // Test escape hatch: harnesses pre-populate `REQUEST_CONTEXT_KEY` and
111
- // flag `TEST_CONTEXT_PRESET_KEY = true`. Production middleware never
111
+ // set `TEST_CONTEXT_PRESET_KEY` to `TEST_CONTEXT_PRESET`. Production middleware never
112
112
  // sets the flag; the shim honors it and `perform_action` trusts the
113
113
  // pre-baked context instead of running the live authorization phase.
114
- const preset = c.get(TEST_CONTEXT_PRESET_KEY)
114
+ const preset = has_test_context_preset(c)
115
115
  ? { request_context: get_request_context(c) }
116
116
  : undefined;
117
117
  const result = await perform_action({
@@ -78,9 +78,9 @@ export interface ActionContext {
78
78
  request_client?: RequestClient;
79
79
  /**
80
80
  * Transaction-scoped when `spec.side_effects` is true (the dispatcher
81
- * wraps in `db.transaction`); pool-level otherwise. Handlers that
82
- * need rollback-resilient writes call `deps.audit.emit(ctx, input)`,
83
- * which captures the pool inside its closure.
81
+ * wraps in `db.transaction`); pool-level otherwise.
82
+ * `deps.audit.emit(ctx, input)` writes a success row in this transaction
83
+ * and a failure row on the pool the emitter closes over.
84
84
  */
85
85
  db: Db;
86
86
  /**
@@ -61,12 +61,6 @@ export interface CreateBroadcastApiOptions {
61
61
  */
62
62
  should_deliver?: ShouldDeliverFn;
63
63
  }
64
- /**
65
- * Loose base shape for a broadcast API. Consumers typically declare a
66
- * stricter per-method interface (e.g. `BackendActionsApi`) and pin it via
67
- * the type parameter on `create_broadcast_api`.
68
- */
69
- export type BroadcastApi = Record<string, (input: never) => Promise<void>>;
70
64
  /**
71
65
  * Builds a typed broadcast API from a set of action specs.
72
66
  *
@@ -1 +1 @@
1
- {"version":3,"file":"broadcast_api.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/actions/broadcast_api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAU,KAAK,MAAM,IAAI,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAG5E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAEvF;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,kBAAkB,EAAE,WAAW,GAAG,oBAAoB,CAAC,CAAC;AAE3F;;;;;;;;GAQG;AACH,MAAM,MAAM,eAAe,GAAG,CAC7B,UAAU,EAAE,QAAQ,CAAC,kBAAkB,CAAC,EACxC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,OAAO,KACV,OAAO,CAAC;AAEb,0CAA0C;AAC1C,MAAM,WAAW,yBAAyB;IACzC;;;;OAIG;IACH,QAAQ,EAAE,eAAe,CAAC;IAC1B;;;;;OAKG;IACH,KAAK,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;IACtC,gFAAgF;IAChF,GAAG,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IACxB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,eAAe,CAAC;CACjC;AAED;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AAE3E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,oBAAoB,GAAI,IAAI,SAAS,MAAM,EACvD,SAAS,yBAAyB,KAChC,IAsCF,CAAC"}
1
+ {"version":3,"file":"broadcast_api.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/actions/broadcast_api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAU,KAAK,MAAM,IAAI,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAG5E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAEvF;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,kBAAkB,EAAE,WAAW,GAAG,oBAAoB,CAAC,CAAC;AAE3F;;;;;;;;GAQG;AACH,MAAM,MAAM,eAAe,GAAG,CAC7B,UAAU,EAAE,QAAQ,CAAC,kBAAkB,CAAC,EACxC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,OAAO,KACV,OAAO,CAAC;AAEb,0CAA0C;AAC1C,MAAM,WAAW,yBAAyB;IACzC;;;;OAIG;IACH,QAAQ,EAAE,eAAe,CAAC;IAC1B;;;;;OAKG;IACH,KAAK,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;IACtC,gFAAgF;IAChF,GAAG,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IACxB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,eAAe,CAAC;CACjC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,oBAAoB,GAAI,IAAI,SAAS,MAAM,EACvD,SAAS,yBAAyB,KAChC,IAsCF,CAAC"}
@@ -8,11 +8,10 @@
8
8
  * nothing. So a revocation takes effect on an open connection only when
9
9
  * something closes it. `ConnectionCloser` is that capability, and every
10
10
  * revocation handler holds one: the session and token revokes, the revoke-alls,
11
- * account delete and purge, `/logout`, `/password`, and the session and token
12
- * caps for what they evict. A role revocation is the exception: it closes
13
- * only the connections an endpoint gated on that role, and only through the
14
- * audit listener (`create_revocation_guard`) — no handler holds a closer for
15
- * it. The auth cleanup holds one too
11
+ * account delete and purge, `/logout`, `/password`, the session and token
12
+ * caps for what they evict, and the role revokes (`role_grant_revoke` and a
13
+ * self-service disable), which close only the connections an endpoint gated
14
+ * on the revoked role. The auth cleanup holds one too
16
15
  * (`AuthCleanupDeps.connection_closer`): its session sweep closes the
17
16
  * connections of each expired session it deletes, after that delete commits.
18
17
  *
@@ -34,17 +33,17 @@
34
33
  * ## Why the handlers close directly
35
34
  *
36
35
  * The audit listener (`create_revocation_guard`) closes connections too, but
37
- * only once the audit row is written, and that write is pool-routed and
38
- * fail-open. The handler's own close is the one that runs
39
- * whatever happens to the audit write, so the closer it holds must reach every
36
+ * only once the audit row is announced, and a row written outside a
37
+ * transaction (`/login`, `/password`) is fail-open. The handler's own close
38
+ * is the one that runs whatever happens to the audit row, so the closer it holds must reach every
40
39
  * transport whose connections outlive their credential. `RealtimeCloser` is
41
40
  * that fan-out, and `create_app_backend` puts one on `AppDeps`.
42
41
  *
43
42
  * ## The audit listener
44
43
  *
45
44
  * `create_revocation_guard` repeats a revocation's close when its audit row is
46
- * announced, which covers a revocation emitted by code that holds no closer,
47
- * and is the one closer of a role revocation. `create_app_server` registers one
45
+ * announced, which covers a revocation emitted by code that holds no closer.
46
+ * `create_app_server` registers one
48
47
  * on `deps.connection_closer` when it mounts a WebSocket endpoint or the audit
49
48
  * stream, so it reaches every member — each WebSocket connection registry and the audit
50
49
  * stream registry — through the one fan-out.
@@ -113,8 +112,7 @@ export interface ConnectionCloser {
113
112
  * still good. It **over-closes an any-of gate**: a connection whose
114
113
  * endpoint listed several roles closes on the loss of any of them, whether
115
114
  * or not the account still holds another; the client reconnects into the
116
- * gate if it still qualifies. No handler queues `role`: the audit listener
117
- * is a role's only closer.
115
+ * gate if it still qualifies.
118
116
  */
119
117
  export type ConnectionCloseTarget = {
120
118
  kind: 'session';
@@ -268,9 +266,10 @@ export type AuditEventHandler = (event: AuditLogEvent) => void;
268
266
  * own action, but an endpoint's role gate is the only check on what its
269
267
  * connections *receive* — WebSocket broadcasts and notifications, the audit
270
268
  * stream's rows — with no per-recipient filter, so a connection left open past
271
- * the revocation would keep receiving what the gate exists to withhold. No
272
- * handler closes for a role, so this listener is its one closer: a WebSocket
273
- * closes with `WS_CLOSE_PERMISSION_REVOKED`, a stream gated on the role ends.
269
+ * the revocation would keep receiving what the gate exists to withhold. The
270
+ * role revokes close for it directly, and this listener repeats the close: a
271
+ * WebSocket closes with `WS_CLOSE_PERMISSION_REVOKED`, a stream gated on the
272
+ * role ends.
274
273
  *
275
274
  * Twin of the Rust spine's `register_revocation_guard`.
276
275
  *
@@ -1 +1 @@
1
- {"version":3,"file":"connection_closer.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/actions/connection_closer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,EAAqB,KAAK,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAC5F,OAAO,EAGN,KAAK,aAAa,EAClB,MAAM,6BAA6B,CAAC;AAErC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,gBAAgB;IAChC;;;;;OAKG;IACH,iBAAiB,EAAE,CAAC,MAAM,EAAE,qBAAqB,KAAK,MAAM,CAAC;IAC7D;;;;;;;OAOG;IACH,qBAAqB,EAAE,MAAM,MAAM,CAAC;CACpC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,MAAM,qBAAqB,GAC9B;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,G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AAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,sBAAsB,GAClC,KAAK,sBAAsB,EAC3B,QAAQ,gBAAgB,EACxB,QAAQ,qBAAqB,KAC3B,IAIF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,sBAAsB,EAAE,gBAGnC,CAAC;AAEH;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,cAAe,SAAQ,gBAAgB;IACvD;;;;;;;;;;;;;;;OAeG;IACH,GAAG,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,MAAM,IAAI,CAAC;IAC9C,2EAA2E;IAC3E,YAAY,EAAE,MAAM,MAAM,CAAC;CAC3B;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB,QAAO,cAwCzC,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,uBAAuB,GACnC,QAAQ,gBAAgB,EACxB,KAAK,MAAM,KACT,iBAWF,CAAC"}
@@ -8,11 +8,10 @@
8
8
  * nothing. So a revocation takes effect on an open connection only when
9
9
  * something closes it. `ConnectionCloser` is that capability, and every
10
10
  * revocation handler holds one: the session and token revokes, the revoke-alls,
11
- * account delete and purge, `/logout`, `/password`, and the session and token
12
- * caps for what they evict. A role revocation is the exception: it closes
13
- * only the connections an endpoint gated on that role, and only through the
14
- * audit listener (`create_revocation_guard`) — no handler holds a closer for
15
- * it. The auth cleanup holds one too
11
+ * account delete and purge, `/logout`, `/password`, the session and token
12
+ * caps for what they evict, and the role revokes (`role_grant_revoke` and a
13
+ * self-service disable), which close only the connections an endpoint gated
14
+ * on the revoked role. The auth cleanup holds one too
16
15
  * (`AuthCleanupDeps.connection_closer`): its session sweep closes the
17
16
  * connections of each expired session it deletes, after that delete commits.
18
17
  *
@@ -34,17 +33,17 @@
34
33
  * ## Why the handlers close directly
35
34
  *
36
35
  * The audit listener (`create_revocation_guard`) closes connections too, but
37
- * only once the audit row is written, and that write is pool-routed and
38
- * fail-open. The handler's own close is the one that runs
39
- * whatever happens to the audit write, so the closer it holds must reach every
36
+ * only once the audit row is announced, and a row written outside a
37
+ * transaction (`/login`, `/password`) is fail-open. The handler's own close
38
+ * is the one that runs whatever happens to the audit row, so the closer it holds must reach every
40
39
  * transport whose connections outlive their credential. `RealtimeCloser` is
41
40
  * that fan-out, and `create_app_backend` puts one on `AppDeps`.
42
41
  *
43
42
  * ## The audit listener
44
43
  *
45
44
  * `create_revocation_guard` repeats a revocation's close when its audit row is
46
- * announced, which covers a revocation emitted by code that holds no closer,
47
- * and is the one closer of a role revocation. `create_app_server` registers one
45
+ * announced, which covers a revocation emitted by code that holds no closer.
46
+ * `create_app_server` registers one
48
47
  * on `deps.connection_closer` when it mounts a WebSocket endpoint or the audit
49
48
  * stream, so it reaches every member — each WebSocket connection registry and the audit
50
49
  * stream registry — through the one fan-out.
@@ -268,9 +267,10 @@ export const create_realtime_closer = () => {
268
267
  * own action, but an endpoint's role gate is the only check on what its
269
268
  * connections *receive* — WebSocket broadcasts and notifications, the audit
270
269
  * stream's rows — with no per-recipient filter, so a connection left open past
271
- * the revocation would keep receiving what the gate exists to withhold. No
272
- * handler closes for a role, so this listener is its one closer: a WebSocket
273
- * closes with `WS_CLOSE_PERMISSION_REVOKED`, a stream gated on the role ends.
270
+ * the revocation would keep receiving what the gate exists to withhold. The
271
+ * role revokes close for it directly, and this listener repeats the close: a
272
+ * WebSocket closes with `WS_CLOSE_PERMISSION_REVOKED`, a stream gated on the
273
+ * role ends.
274
274
  *
275
275
  * Twin of the Rust spine's `register_revocation_guard`.
276
276
  *
@@ -27,7 +27,11 @@
27
27
  * (`request_context.account.id`), settled by authentication, so the gate
28
28
  * sits behind the authority gates by choice rather than necessity: a
29
29
  * caller those gates refuse is answered 403, not 429.
30
- * 5. **Validate params (400)** — `spec.input.safeParse(raw_params)` with
30
+ * 5. **Validate params (400)** — first, object `params` holding an own
31
+ * `__proto__` key at any depth (`json_has_own_proto_key`) are refused
32
+ * with `data.reason` `params_proto_key` (`ERROR_PARAMS_PROTO_KEY`), on
33
+ * every input schema, before it runs; then
34
+ * `spec.input.safeParse(raw_params)` with
31
35
  * `z.void()` / `?? {}` rules (`to_input_params`). A refusal is the generic
32
36
  * `invalid params`, with `data.reason` when the first issue's field
33
37
  * declares an `invalid_reason` (`to_invalid_params_error`) and the Zod
@@ -1 +1 @@
1
- {"version":3,"file":"perform_action.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/actions/perform_action.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAGN,KAAK,cAAc,EACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAGN,KAAK,YAAY,EACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAKtC,OAAO,EACN,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EAGvB,MAAM,oBAAoB,CAAC;AAgB5B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,KAAK,EAAgC,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACjF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGvD;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IAClC,kEAAkE;IAClE,MAAM,EAAE,SAAS,CAAC;IAClB,mGAAmG;IACnG,UAAU,EAAE,OAAO,CAAC;IACpB,sDAAsD;IAC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E,IAAI,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,kBAAkB,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhG;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,GAC1B,OAAO,kBAAkB,EACzB,MAAM,iBAAiB,KACrB,OAAO,CAAC,mBAAmB,CAuL7B,CAAC;AA4BF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,uBAAuB,GACnC,OAAO,CAAC,CAAC,OAAO,EAChB,QAAQ,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KACrC,kBAOF,CAAC;AA6DF;;;;;;;;GAQG;AACH,eAAO,MAAM,8BAA8B,GAC1C,2BAA2B,aAAa,CAAC,MAAM,CAAC,KAC9C,kBAIA,CAAC;AAqEJ,0FAA0F;AAC1F,MAAM,WAAW,sBAAsB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,uEAAuE;IACvE,MAAM,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,uBAAuB,GACnC,IAAI,gBAAgB,EACpB,QAAQ,mBAAmB,EAC3B,QAAQ,MAAM,EACd,KAAK,MAAM,KACT,sBAkBF,CAAC"}
@@ -27,7 +27,11 @@
27
27
  * (`request_context.account.id`), settled by authentication, so the gate
28
28
  * sits behind the authority gates by choice rather than necessity: a
29
29
  * caller those gates refuse is answered 403, not 429.
30
- * 5. **Validate params (400)** — `spec.input.safeParse(raw_params)` with
30
+ * 5. **Validate params (400)** — first, object `params` holding an own
31
+ * `__proto__` key at any depth (`json_has_own_proto_key`) are refused
32
+ * with `data.reason` `params_proto_key` (`ERROR_PARAMS_PROTO_KEY`), on
33
+ * every input schema, before it runs; then
34
+ * `spec.input.safeParse(raw_params)` with
31
35
  * `z.void()` / `?? {}` rules (`to_input_params`). A refusal is the generic
32
36
  * `invalid params`, with `data.reason` when the first issue's field
33
37
  * declares an `invalid_reason` (`to_invalid_params_error`) and the Zod
@@ -59,14 +63,15 @@
59
63
  import { DEV } from 'esm-env';
60
64
  import { apply_authorization_phase, has_any_scoped_role } from '../auth/request_context.js';
61
65
  import { resolved_auth_scope, resolved_auth_session_hash } from '../auth/resolved_auth.js';
66
+ import { is_db_checkout_error } from '../db/db_checkout_error.js';
62
67
  import { resolve_issues_invalid_reason } from '../schema_meta.js';
63
- import { to_input_params } from '../http/schema_helpers.js';
68
+ import { json_has_own_proto_key, to_input_params } from '../http/schema_helpers.js';
64
69
  import { rate_limit_ip_key } from '../http/ip_canonical.js';
65
70
  import { dispatch_with_post_commit_rollback } from '../http/pending_effects.js';
66
71
  import {} from '../http/jsonrpc.js';
67
72
  import { create_jsonrpc_error_response, create_jsonrpc_response } from '../http/jsonrpc_helpers.js';
68
73
  import { jsonrpc_error_messages, jsonrpc_error_code_to_http_status, http_status_to_jsonrpc_error_code, JSONRPC_ERROR_CODES, dev_only, to_thrown_jsonrpc_error } from '../http/jsonrpc_errors.js';
69
- import { ERROR_AUTHENTICATION_REQUIRED, ERROR_INSUFFICIENT_PERMISSIONS, ERROR_CREDENTIAL_TYPE_REQUIRED, ERROR_TOKEN_SCOPE_REQUIRED } from '../http/error_schemas.js';
74
+ import { ERROR_AUTHENTICATION_REQUIRED, ERROR_INSUFFICIENT_PERMISSIONS, ERROR_CREDENTIAL_TYPE_REQUIRED, ERROR_PARAMS_PROTO_KEY, ERROR_TOKEN_SCOPE_REQUIRED } from '../http/error_schemas.js';
70
75
  import { is_public_auth, needs_actor, parse_acting } from '../http/auth_shape.js';
71
76
  import { token_scope_admits_method, token_scope_method_capability } from '../auth/token_scope.js';
72
77
  /**
@@ -100,7 +105,17 @@ export const perform_action = async (input, deps) => {
100
105
  request_context = preset.request_context;
101
106
  }
102
107
  else if (!is_public_auth(action_auth)) {
103
- const result = await apply_authorization_phase({ db }, account_id, action_auth, read_acting(action_auth, raw_params));
108
+ // A throw here (a failed checkout or read) answers the JSON-RPC envelope
109
+ // like a handler throw does — never escaping to the transport's REST
110
+ // catch — so the RPC endpoint answers in its own shape, as the Rust
111
+ // dispatcher does.
112
+ let result;
113
+ try {
114
+ result = await apply_authorization_phase({ db }, account_id, action_auth, read_acting(action_auth, raw_params));
115
+ }
116
+ catch (err) {
117
+ return thrown_error_result(err, `authorization phase error: ${spec.method}`, log);
118
+ }
104
119
  if (!result.ok) {
105
120
  const { error: reason, ...rest } = result.body;
106
121
  const code = http_status_to_jsonrpc_error_code(result.status);
@@ -155,6 +170,19 @@ export const perform_action = async (input, deps) => {
155
170
  // (`raw_params ?? {}`) lets all-optional-object methods omit `params`;
156
171
  // a `z.void()` input reads every empty shape as the no-arg call — see
157
172
  // `to_input_params`.
173
+ //
174
+ // An own `__proto__` key anywhere in object params is refused first, on
175
+ // every input: Zod drops a top-level one from a loose object and keeps a
176
+ // nested one by reference, so a schema alone would store it — a sink for
177
+ // any client that copies the value back with plain assignment. Only an
178
+ // object is walked, so a non-object `params` is the schema's refusal, as
179
+ // the Rust twin's shape check answers it ahead of its walk.
180
+ if (typeof raw_params === 'object' &&
181
+ raw_params !== null &&
182
+ !Array.isArray(raw_params) &&
183
+ json_has_own_proto_key(raw_params)) {
184
+ return error_result(jsonrpc_error_messages.invalid_params('invalid params', { reason: ERROR_PARAMS_PROTO_KEY }));
185
+ }
158
186
  const params = to_input_params(spec.input, raw_params);
159
187
  const parse_result = spec.input.safeParse(params);
160
188
  if (!parse_result.success) {
@@ -199,22 +227,32 @@ export const perform_action = async (input, deps) => {
199
227
  return await dispatch_with_post_commit_rollback(post_commit_effects, () => use_transaction ? db.transaction((tx) => execute(tx)) : execute(db));
200
228
  }
201
229
  catch (err) {
202
- // a JSON-RPC error recognized by brand, a second fuz_app copy's included;
203
- // anything else is an internal error, logged and masked
204
- const thrown = to_thrown_jsonrpc_error(err);
205
- if (thrown) {
206
- return {
207
- kind: 'error',
208
- status: jsonrpc_error_code_to_http_status(thrown.code),
209
- error: thrown
210
- };
211
- }
212
- log.error(`unhandled action handler error: ${spec.method}`, err);
213
- // Raw exception messages can leak internals (paths, SQL, secrets in a
214
- // message) — surface them only in development; production falls back to
215
- // the generic `internal_error` default. Same gate as the Zod-issue redaction.
216
- return error_result(jsonrpc_error_messages.internal_error(dev_only(err instanceof Error ? err.message : undefined)));
230
+ return thrown_error_result(err, `unhandled action handler error: ${spec.method}`, log);
231
+ }
232
+ };
233
+ /**
234
+ * The dispatcher's answer to a thrown value: the JSON-RPC error it carries
235
+ * (`to_thrown_jsonrpc_error` — a `ThrownJsonrpcError` from any copy of
236
+ * fuz_app, or a failed pool checkout's `service_unavailable`), else a logged,
237
+ * masked `internal_error`.
238
+ */
239
+ const thrown_error_result = (err, context, log) => {
240
+ const thrown = to_thrown_jsonrpc_error(err);
241
+ if (thrown) {
242
+ // a failed checkout is the server's to see, though the caller gets the 503
243
+ if (is_db_checkout_error(err))
244
+ log.error(context, err);
245
+ return {
246
+ kind: 'error',
247
+ status: jsonrpc_error_code_to_http_status(thrown.code),
248
+ error: thrown
249
+ };
217
250
  }
251
+ log.error(context, err);
252
+ // Raw exception messages can leak internals (paths, SQL, secrets in a
253
+ // message) — surface them only in development; production falls back to
254
+ // the generic `internal_error` default. Same gate as the Zod-issue redaction.
255
+ return error_result(jsonrpc_error_messages.internal_error(dev_only(err instanceof Error ? err.message : undefined)));
218
256
  };
219
257
  /**
220
258
  * The `invalid_params` error an input validation failure answers: the generic
@@ -110,9 +110,9 @@ export interface RegisterActionWsOptions {
110
110
  * `side_effects: true` actions, the same way HTTP RPC does. Per-message
111
111
  * authorization phase reads through this pool.
112
112
  *
113
- * Audit writes and other rollback-resilient fire-and-forget calls run
114
- * through `AppDeps.audit.emit` from the action factory's closure —
115
- * the dispatcher never holds an audit-side pool reference; the bound
113
+ * Audit writes run through `AppDeps.audit.emit` from the action factory's
114
+ * closure (a success row in the dispatch transaction, a failure row on the
115
+ * pool) — the dispatcher never holds an audit-side pool reference; the bound
116
116
  * emitter owns the pool.
117
117
  */
118
118
  db: Db;
@@ -292,8 +292,9 @@ export interface RegisterActionWsResult {
292
292
  * with `WS_CLOSE_PERMISSION_REVOKED`, and one whose re-check failed with
293
293
  * `WS_CLOSE_INTERNAL_ERROR`. Frames sent before admission wait for it.
294
294
  * - A revoked global grant of a role `required_roles` lists closes the
295
- * account's sockets on this endpoint with `WS_CLOSE_PERMISSION_REVOKED`,
296
- * through the revocation guard; nothing more is sent on them.
295
+ * account's sockets on this endpoint with `WS_CLOSE_PERMISSION_REVOKED` —
296
+ * the revoking handler through `connection_closer`, the revocation guard
297
+ * again on the audit row; nothing more is sent on them.
297
298
  * - A socket the server has closed dispatches nothing more, whether or not
298
299
  * its client answers the close.
299
300
  * - Every frame sent — responses, error frames, notifications — goes through
@@ -1 +1 @@
1
- {"version":3,"file":"register_action_ws.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/actions/register_action_ws.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAU,KAAK,MAAM,IAAI,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAS5E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAKvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAE7D,OAAO,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ACH,cAAc,CAAC,EAAE,CAAC,GAAG,EAAE,iBAAiB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClE;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,CAAC,GAAG,EAAE,kBAAkB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpE;;;;;;;;OAQG;IACH,sBAAsB,EAAE,WAAW,GAAG,IAAI,CAAC;IAC3C;;;;;;OAMG;IACH,2BAA2B,EAAE,WAAW,GAAG,IAAI,CAAC;IAChD;;;;;OAKG;IACH,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,kBAAkB,KAAK,IAAI,CAAC;CACxE;AAED,sCAAsC;AACtC,MAAM,WAAW,sBAAsB;IACtC,wEAAwE;IACxE,QAAQ,EAAE,kBAAkB,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,uBAAuB,KAAG,sBAiLrE,CAAC"}
@@ -62,7 +62,7 @@ import { get_resolved_auth } from '../auth/resolved_auth.js';
62
62
  import { verify_request_source } from '../http/origin.js';
63
63
  import { parse_acting } from '../http/auth_shape.js';
64
64
  import { get_client_ip } from '../http/client_ip.js';
65
- import { TEST_CONTEXT_PRESET_KEY } from '../hono_context.js';
65
+ import { has_test_context_preset } from '../hono_context.js';
66
66
  import {} from './action_types.js';
67
67
  import { compile_action_registry } from './compile_action_registry.js';
68
68
  import { DEFAULT_WS_MAX_MESSAGE_BYTES } from './transports.js';
@@ -114,8 +114,9 @@ export const WS_RECEIVE_TIMEOUT_MAX = 2_147_483_647;
114
114
  * with `WS_CLOSE_PERMISSION_REVOKED`, and one whose re-check failed with
115
115
  * `WS_CLOSE_INTERNAL_ERROR`. Frames sent before admission wait for it.
116
116
  * - A revoked global grant of a role `required_roles` lists closes the
117
- * account's sockets on this endpoint with `WS_CLOSE_PERMISSION_REVOKED`,
118
- * through the revocation guard; nothing more is sent on them.
117
+ * account's sockets on this endpoint with `WS_CLOSE_PERMISSION_REVOKED` —
118
+ * the revoking handler through `connection_closer`, the revocation guard
119
+ * again on the audit row; nothing more is sent on them.
119
120
  * - A socket the server has closed dispatches nothing more, whether or not
120
121
  * its client answers the close.
121
122
  * - Every frame sent — responses, error frames, notifications — goes through
@@ -245,9 +246,7 @@ export const register_action_ws = (options) => {
245
246
  // `RequestContext` skip the live authorization phase. It skips the
246
247
  // admission re-read for the same reason: a pre-baked credential has
247
248
  // no session, token, or account row to re-read.
248
- const upgrade_preset = c.get(TEST_CONTEXT_PRESET_KEY)
249
- ? { request_context: get_request_context(c) }
250
- : undefined;
249
+ const upgrade_preset = has_test_context_preset(c) ? { request_context: get_request_context(c) } : undefined;
251
250
  // Captured at upgrade and passed per message, its scope consulted
252
251
  // there. Rule 3 rejects a narrowed token at the upgrade's guards
253
252
  // above, so in practice the scope is always `full` on a live socket —
@@ -18,7 +18,7 @@ documents the cross-cutting invariants that don't fit on any single symbol.
18
18
 
19
19
  - **Capabilities** — `AppDeps` — stateless, injectable per env: `read_secure_file` (hardened bootstrap-token read), `delete_file`, `keyring`, `password`, `db`, `log`, `audit`, `connection_closer` (the `RealtimeCloser` every revocation handler closes live connections through — `actions/CLAUDE.md` §Connection closer).
20
20
  - **Route caps** — `RouteFactoryDeps` — `Omit<AppDeps, 'db'>`; handlers get `db` via `RouteContext`.
21
- - **Action caps** — `ActionFactoryDeps` (`auth/deps.ts`) — the `{log, audit}` shape action factories take; `RouteFactoryDeps`/`AppDeps` satisfy it structurally (role-grant-offer adds `notification_sender?`). The factories whose handlers end credentials (`create_account_actions`, `create_admin_actions`, and the standard bundle) take `RevokingActionFactoryDeps` — `ActionFactoryDeps` plus a required `connection_closer`. The two pure-read actor factories (`actor_lookup`/`actor_search`) take only `{log: Logger}`.
21
+ - **Action caps** — `ActionFactoryDeps` (`auth/deps.ts`) — the `{log, audit}` shape action factories take; `RouteFactoryDeps`/`AppDeps` satisfy it structurally (role-grant-offer adds `notification_sender?`). The factories whose handlers end credentials or revoke roles (`create_account_actions`, `create_admin_actions`, `create_role_grant_offer_actions`, `create_self_service_role_actions`, and the standard bundle) take `RevokingActionFactoryDeps` — `ActionFactoryDeps` plus a required `connection_closer`. The two pure-read actor factories (`actor_lookup`/`actor_search`) take only `{log: Logger}`.
22
22
  - **Parameters** — `*Options` — static startup values, per-factory.
23
23
  - **Runtime state** — inline ref — mutable values: `bootstrap_status`, `DaemonTokenState`. NOT in deps or options.
24
24
 
@@ -124,9 +124,9 @@ upstream in `auth/signup_routes.ts` via `query_invite_find_unclaimed_match_for_u
124
124
  `audit_factory` callback over `create_audit_emitter`; closes over the pool +
125
125
  its registered listeners + optional `AuditLogConfig`. Its methods:
126
126
 
127
- - `emit(ctx, input)` — fire-and-forget pool write, pushes to `ctx.pending_effects`; a success row's listener fan-out goes on `ctx.post_commit_effects`
127
+ - `emit(ctx, input)` — async, always awaited: a success row inside a request transaction is written in it (a failed INSERT rejects); any other row is a fire-and-forget pool write pushed to `ctx.pending_effects`; a success row's listener fan-out goes on `ctx.post_commit_effects`
128
128
  - `emit_role_grant_target(ctx, auth, input)` — lifts `actor_id` / `account_id` / `ip` boilerplate for role-grant-shape events; `input` is an `AuditEmitRoleGrantInput`
129
- - `emit_pool(input)` — awaitable pool write for code paths without a request context (ad-hoc maintenance scripts; not for success audits paired with a mutation — those write in-tx and `notify` post-commit). Writes, then notifies, whatever the outcome
129
+ - `emit_pool(input)` — awaitable pool write for code paths without a request transaction (ad-hoc maintenance scripts, a post-commit thunk; not for success audits paired with a mutation — those write in-tx and `notify` post-commit). Writes, then notifies, whatever the outcome
130
130
  - `notify(event)` — fan out an already-written row to listeners (used by in-tx audit batches like `query_accept_offer.audit_events`)
131
131
  - `add_listener(listener)` — listener registration, returning a remover for that registration (idempotent; the same function registered twice is two registrations, each with its own remover). Twin of Rust `fuz_auth` `AuditEmitter::add_listener` in firing order and snapshot-at-notify
132
132
  - `listener_count()` — registered-listener count, for tests / diagnostics
@@ -143,13 +143,26 @@ without shallow-copying `AppDeps`, and removes them when its assembly fails or
143
143
  the next event, and one removed mid-fan-out still hears the in-flight event
144
144
  (converges with the Rust twin's cloned vec).
145
145
 
146
- **When listeners hear about a row.** `emit` always writes at once, on the pool
147
- (the row survives a rollback). The fan-out depends on the outcome: a
146
+ **Where a row is written.** `emit` is async — always `await` it. A **success**
147
+ row emitted inside a request transaction (`ctx.db.in_transaction`: an action
148
+ with `side_effects`, a route with `transaction: true`) is written in that
149
+ transaction, so the change and its row commit together; a failed INSERT
150
+ rejects `emit` and the handler's transaction rolls back. A **failure** row, and
151
+ a success row with no request transaction open (`/login`, `/password`,
152
+ signup, bootstrap — which emit after their own transaction commits), is a
153
+ fire-and-forget pool write, fail-open (logged, counted by
154
+ `get_audit_write_failures`). The Rust spine's split is the same
155
+ (`route_audit_emit`: `emit_in_tx` for an action's success row, `emit` on the
156
+ pool otherwise); the TS `/logout` runs in a route transaction, so its row is
157
+ in-transaction where Rust's is pooled. `db_admin_row_delete` is written on the
158
+ pool after its commit on both twins (TS: `emit_pool` from a post-commit
159
+ thunk).
160
+
161
+ **When listeners hear about a row.** The fan-out depends on the outcome: a
148
162
  **failure** row is announced as soon as it is written — the attempt happened
149
163
  whatever the transaction does; a **success** row is announced only after the
150
- request's transaction commits (a thunk on `ctx.post_commit_effects` that awaits
151
- the write; after the handler returns, on a route without one) and never when
152
- the handler throws. The listeners act on a success row — the revocation guards
164
+ request's transaction commits (a thunk on `ctx.post_commit_effects`; after the
165
+ handler returns, on a route without one) and never when the handler throws. The listeners act on a success row — the revocation guards
153
166
  close connections, the audit stream broadcasts it — so announcing one before
154
167
  its commit would close while the revoked credential still reads as valid, and
155
168
  a rolled-back revocation would close anyway. A route that runs without a
@@ -158,7 +171,7 @@ request transaction and opens its own around just its writes (`/login`,
158
171
  spine follows the same order: a success row emitted inside a request
159
172
  transaction is written in it with its fan-out queued behind the commit, and
160
173
  `/login` and `/password` emit after their own commit. `AuditEmitterContext` is therefore
161
- `{pending_effects, post_commit_effects}` — `RouteContext` and `ActionContext`
174
+ `{db, pending_effects, post_commit_effects}` — `RouteContext` and `ActionContext`
162
175
  both satisfy it.
163
176
 
164
177
  **Revocation scopes** (`auth/audit_log_schema.ts`) —
@@ -437,9 +450,16 @@ stay distinct: `no_actors_on_account` (signup invariant violation),
437
450
 
438
451
  **Production-middleware invariant.** No production middleware on the auth
439
452
  path populates `REQUEST_CONTEXT_KEY`; it sets only `RESOLVED_AUTH_KEY`. Test
440
- harnesses pre-populate `REQUEST_CONTEXT_KEY` +
441
- `TEST_CONTEXT_PRESET_KEY` to bypass DB-backed actor resolution; production
442
- code that reads `REQUEST_CONTEXT_KEY` is reading test escape-hatch state.
453
+ harnesses pre-populate `REQUEST_CONTEXT_KEY` and set `TEST_CONTEXT_PRESET_KEY`
454
+ to the `TEST_CONTEXT_PRESET` symbol to bypass DB-backed actor resolution
455
+ (`has_test_context_preset` reads it; any other value, `true` or a string
456
+ included, is unset); production code that reads `REQUEST_CONTEXT_KEY` is
457
+ reading test escape-hatch state.
458
+
459
+ **The session token key is fixed.** The session middleware writes the token
460
+ under `SESSION_TOKEN_KEY` (`hono_context.ts`, `'auth_session_id'`) and the
461
+ session leg reads it there; `SessionOptions` carries no context key, so the two
462
+ cannot disagree and the token cannot land on another spine key.
443
463
 
444
464
  ### Wire timestamp shape
445
465
 
@@ -850,7 +870,12 @@ builders, plus `role_grant_offer_notification_specs: Array<EventSpec>` for
850
870
  `create_app_server`'s `event_specs` (drives surface generation and
851
871
  DEV-mode `create_validated_broadcaster` payload validation).
852
872
 
853
- Deps: `ActionFactoryDeps & {notification_sender?: NotificationSender | null}`.
873
+ Deps: `RevokingActionFactoryDeps & {notification_sender?: NotificationSender | null}`.
874
+ `role_grant_revoke` of a global grant queues a close of the revokee account's
875
+ connections gated on the role (`queue_connection_close`, `{kind: 'role'}`),
876
+ run after the transaction commits and independent of the audit row's
877
+ announcement; the revocation guard repeats it on the announced row. A scoped revoke
878
+ closes nothing — a role gate admits on global grants alone.
854
879
  `NotificationSender` is the narrow structural capability
855
880
  (`send_to_account(account_id, message): number`); `ConnectionRegistry`
856
881
  satisfies it structurally. Target account travels via the send argument, not
@@ -911,7 +936,8 @@ app-settings methods are always wired). Frontend mirror is
911
936
  Option routing — `roles` is shared between admin + role-grant-offer;
912
937
  `default_ttl_ms` + `authorize` → role-grant-offer
913
938
  only; `max_tokens` → account only. On `deps`: `notification_sender` →
914
- role-grant-offer only; `connection_closer` (required) → admin + account.
939
+ role-grant-offer only; `connection_closer` (required) → admin, account, and
940
+ role-grant-offer (the role revoke's close).
915
941
 
916
942
  Pair with `create_app_server`'s `rpc_endpoints` factory form
917
943
  `(ctx) => Array<RpcEndpointSpec>` so the combined action list gets
@@ -943,6 +969,10 @@ construction (`validate_self_service_eligible_roles`): a builtin role or a name
943
969
  outside the `RoleName` grammar throws — self-toggling a builtin would hand any
944
970
  account instance-wide authority.
945
971
 
972
+ Deps are `RevokingActionFactoryDeps`: a disable that revokes queues a close of
973
+ the caller's connections gated on the role (`queue_connection_close`,
974
+ `{kind: 'role'}`), after the commit and independent of the audit write.
975
+
946
976
  Method name is static (`role` lives in input, not method) — per-role
947
977
  parameterized methods would break the `satisfies RequestResponseActionSpec`
948
978
  codegen invariant.