@fuzdev/fuz_app 0.54.0 → 0.55.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 (142) hide show
  1. package/dist/actions/CLAUDE.md +68 -13
  2. package/dist/actions/action_codegen.d.ts +13 -0
  3. package/dist/actions/action_codegen.d.ts.map +1 -1
  4. package/dist/actions/action_codegen.js +15 -1
  5. package/dist/actions/action_rpc.d.ts +60 -7
  6. package/dist/actions/action_rpc.d.ts.map +1 -1
  7. package/dist/actions/action_rpc.js +158 -44
  8. package/dist/actions/register_action_ws.d.ts +4 -4
  9. package/dist/actions/register_action_ws.js +6 -6
  10. package/dist/actions/register_ws_endpoint.d.ts +20 -7
  11. package/dist/actions/register_ws_endpoint.d.ts.map +1 -1
  12. package/dist/actions/register_ws_endpoint.js +30 -5
  13. package/dist/actions/transports.d.ts.map +1 -1
  14. package/dist/actions/transports.js +0 -4
  15. package/dist/auth/CLAUDE.md +219 -66
  16. package/dist/auth/account_actions.d.ts +6 -6
  17. package/dist/auth/account_actions.d.ts.map +1 -1
  18. package/dist/auth/account_actions.js +8 -11
  19. package/dist/auth/account_queries.d.ts +6 -3
  20. package/dist/auth/account_queries.d.ts.map +1 -1
  21. package/dist/auth/account_queries.js +14 -5
  22. package/dist/auth/account_routes.d.ts +7 -10
  23. package/dist/auth/account_routes.d.ts.map +1 -1
  24. package/dist/auth/account_routes.js +70 -23
  25. package/dist/auth/account_schema.d.ts +19 -0
  26. package/dist/auth/account_schema.d.ts.map +1 -1
  27. package/dist/auth/account_schema.js +20 -0
  28. package/dist/auth/admin_action_specs.d.ts +45 -11
  29. package/dist/auth/admin_action_specs.d.ts.map +1 -1
  30. package/dist/auth/admin_action_specs.js +23 -8
  31. package/dist/auth/admin_actions.d.ts +8 -7
  32. package/dist/auth/admin_actions.d.ts.map +1 -1
  33. package/dist/auth/admin_actions.js +11 -18
  34. package/dist/auth/audit_log_queries.d.ts +53 -14
  35. package/dist/auth/audit_log_queries.d.ts.map +1 -1
  36. package/dist/auth/audit_log_queries.js +45 -2
  37. package/dist/auth/audit_log_schema.d.ts +55 -1
  38. package/dist/auth/audit_log_schema.d.ts.map +1 -1
  39. package/dist/auth/audit_log_schema.js +19 -3
  40. package/dist/auth/bearer_auth.d.ts +9 -7
  41. package/dist/auth/bearer_auth.d.ts.map +1 -1
  42. package/dist/auth/bearer_auth.js +13 -21
  43. package/dist/auth/cleanup.d.ts.map +1 -1
  44. package/dist/auth/cleanup.js +5 -0
  45. package/dist/auth/daemon_token_middleware.d.ts +23 -11
  46. package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
  47. package/dist/auth/daemon_token_middleware.js +26 -20
  48. package/dist/auth/deps.d.ts +14 -0
  49. package/dist/auth/deps.d.ts.map +1 -1
  50. package/dist/auth/middleware.d.ts.map +1 -1
  51. package/dist/auth/middleware.js +4 -2
  52. package/dist/auth/migrations.d.ts +15 -7
  53. package/dist/auth/migrations.d.ts.map +1 -1
  54. package/dist/auth/migrations.js +15 -7
  55. package/dist/auth/permit_offer_action_specs.d.ts +45 -6
  56. package/dist/auth/permit_offer_action_specs.d.ts.map +1 -1
  57. package/dist/auth/permit_offer_action_specs.js +38 -7
  58. package/dist/auth/permit_offer_actions.d.ts +2 -2
  59. package/dist/auth/permit_offer_actions.d.ts.map +1 -1
  60. package/dist/auth/permit_offer_actions.js +98 -90
  61. package/dist/auth/permit_offer_notifications.d.ts +10 -0
  62. package/dist/auth/permit_offer_notifications.d.ts.map +1 -1
  63. package/dist/auth/permit_offer_queries.d.ts +68 -9
  64. package/dist/auth/permit_offer_queries.d.ts.map +1 -1
  65. package/dist/auth/permit_offer_queries.js +147 -35
  66. package/dist/auth/permit_offer_schema.d.ts +23 -1
  67. package/dist/auth/permit_offer_schema.d.ts.map +1 -1
  68. package/dist/auth/permit_offer_schema.js +5 -0
  69. package/dist/auth/permit_queries.d.ts +17 -5
  70. package/dist/auth/permit_queries.d.ts.map +1 -1
  71. package/dist/auth/permit_queries.js +19 -8
  72. package/dist/auth/request_context.d.ts +321 -38
  73. package/dist/auth/request_context.d.ts.map +1 -1
  74. package/dist/auth/request_context.js +393 -66
  75. package/dist/auth/route_guards.d.ts +10 -4
  76. package/dist/auth/route_guards.d.ts.map +1 -1
  77. package/dist/auth/route_guards.js +14 -8
  78. package/dist/auth/self_service_role_action_specs.d.ts +2 -0
  79. package/dist/auth/self_service_role_action_specs.d.ts.map +1 -1
  80. package/dist/auth/self_service_role_action_specs.js +2 -0
  81. package/dist/auth/self_service_role_actions.d.ts +6 -5
  82. package/dist/auth/self_service_role_actions.d.ts.map +1 -1
  83. package/dist/auth/self_service_role_actions.js +18 -8
  84. package/dist/db/migrate.d.ts +11 -7
  85. package/dist/db/migrate.d.ts.map +1 -1
  86. package/dist/db/migrate.js +9 -6
  87. package/dist/dev/setup.d.ts.map +1 -1
  88. package/dist/dev/setup.js +5 -3
  89. package/dist/hono_context.d.ts +77 -0
  90. package/dist/hono_context.d.ts.map +1 -1
  91. package/dist/hono_context.js +50 -0
  92. package/dist/http/CLAUDE.md +80 -17
  93. package/dist/http/error_schemas.d.ts +92 -1
  94. package/dist/http/error_schemas.d.ts.map +1 -1
  95. package/dist/http/error_schemas.js +73 -16
  96. package/dist/http/jsonrpc_errors.d.ts +27 -2
  97. package/dist/http/jsonrpc_errors.d.ts.map +1 -1
  98. package/dist/http/jsonrpc_errors.js +26 -2
  99. package/dist/http/route_spec.d.ts +62 -4
  100. package/dist/http/route_spec.d.ts.map +1 -1
  101. package/dist/http/route_spec.js +117 -21
  102. package/dist/http/schema_helpers.d.ts +13 -1
  103. package/dist/http/schema_helpers.d.ts.map +1 -1
  104. package/dist/http/schema_helpers.js +21 -2
  105. package/dist/http/surface.d.ts +10 -1
  106. package/dist/http/surface.d.ts.map +1 -1
  107. package/dist/http/surface.js +2 -2
  108. package/dist/server/app_server.d.ts.map +1 -1
  109. package/dist/server/app_server.js +11 -1
  110. package/dist/testing/CLAUDE.md +23 -17
  111. package/dist/testing/admin_integration.d.ts.map +1 -1
  112. package/dist/testing/admin_integration.js +15 -13
  113. package/dist/testing/adversarial_headers.js +1 -1
  114. package/dist/testing/app_server.js +2 -2
  115. package/dist/testing/audit_completeness.d.ts.map +1 -1
  116. package/dist/testing/audit_completeness.js +21 -7
  117. package/dist/testing/auth_apps.d.ts.map +1 -1
  118. package/dist/testing/auth_apps.js +6 -3
  119. package/dist/testing/entities.d.ts +2 -1
  120. package/dist/testing/entities.d.ts.map +1 -1
  121. package/dist/testing/entities.js +1 -0
  122. package/dist/testing/integration_helpers.d.ts +4 -2
  123. package/dist/testing/integration_helpers.d.ts.map +1 -1
  124. package/dist/testing/integration_helpers.js +9 -5
  125. package/dist/testing/middleware.d.ts +12 -8
  126. package/dist/testing/middleware.d.ts.map +1 -1
  127. package/dist/testing/middleware.js +67 -25
  128. package/dist/testing/rpc_helpers.d.ts.map +1 -1
  129. package/dist/testing/rpc_helpers.js +3 -1
  130. package/dist/testing/ws_round_trip.d.ts.map +1 -1
  131. package/dist/testing/ws_round_trip.js +5 -1
  132. package/dist/ui/CLAUDE.md +16 -10
  133. package/dist/ui/PermitOfferForm.svelte +14 -0
  134. package/dist/ui/PermitOfferForm.svelte.d.ts +6 -0
  135. package/dist/ui/PermitOfferForm.svelte.d.ts.map +1 -1
  136. package/dist/ui/admin_accounts_state.svelte.d.ts +8 -1
  137. package/dist/ui/admin_accounts_state.svelte.d.ts.map +1 -1
  138. package/dist/ui/admin_accounts_state.svelte.js +14 -3
  139. package/dist/ui/permit_offers_state.svelte.d.ts +9 -1
  140. package/dist/ui/permit_offers_state.svelte.d.ts.map +1 -1
  141. package/dist/ui/permit_offers_state.svelte.js +7 -1
  142. package/package.json +1 -1
@@ -41,6 +41,39 @@ export declare const ERROR_BEARER_REJECTED_BROWSER: "bearer_token_rejected_in_br
41
41
  export declare const ERROR_INVALID_TOKEN: "invalid_token";
42
42
  /** Token references a deleted account. */
43
43
  export declare const ERROR_ACCOUNT_NOT_FOUND: "account_not_found";
44
+ /**
45
+ * Multi-actor account requires the request to carry an explicit `acting`
46
+ * field naming the actor the request is acting as, so the dispatcher's
47
+ * authorization phase doesn't pick a default actor silently. Returned
48
+ * with the available actors so the client can prompt.
49
+ */
50
+ export declare const ERROR_ACTOR_REQUIRED: "actor_required";
51
+ /**
52
+ * Supplied `acting` field does not name an actor on the authenticated
53
+ * account.
54
+ */
55
+ export declare const ERROR_ACTOR_NOT_ON_ACCOUNT: "actor_not_on_account";
56
+ /**
57
+ * Authenticated account exists but has no actors. Server invariant
58
+ * violation — signup / bootstrap always create an actor in the same
59
+ * transaction. Surfaced from the dispatcher's authorization phase as a
60
+ * 500 so the operator sees the corruption signal rather than a confusing
61
+ * 4xx. Distinct from `ERROR_ACCOUNT_VANISHED`: the actor list was
62
+ * enumerated successfully and came back empty.
63
+ */
64
+ export declare const ERROR_NO_ACTORS_ON_ACCOUNT: "no_actors_on_account";
65
+ /**
66
+ * Authentication validated an account, but a follow-up read in the
67
+ * authorization phase came back null — the account or its named actor
68
+ * row was deleted between the credential check and the dispatcher's
69
+ * `build_request_context` / `build_account_context` step. Torn read,
70
+ * not a missing-actor invariant violation. Surfaced as 500 so the
71
+ * operator sees the race signal; clients can retry. Distinct from
72
+ * `ERROR_ACCOUNT_NOT_FOUND` (stale token referencing a long-deleted
73
+ * account, raised at credential validation) and
74
+ * `ERROR_NO_ACTORS_ON_ACCOUNT` (the actor list enumerated empty).
75
+ */
76
+ export declare const ERROR_ACCOUNT_VANISHED: "account_vanished";
44
77
  /** Keeper routes require daemon_token credential type. */
45
78
  export declare const ERROR_KEEPER_REQUIRES_DAEMON_TOKEN: "keeper_requires_daemon_token";
46
79
  /** Daemon token header present but malformed or not matching current/previous token. */
@@ -132,6 +165,44 @@ export declare const ForeignKeyError: z.ZodObject<{
132
165
  error: z.ZodLiteral<"foreign_key_violation">;
133
166
  }, z.core.$loose>;
134
167
  export type ForeignKeyError = z.infer<typeof ForeignKeyError>;
168
+ /**
169
+ * Authorization-phase failure shapes. Surfaced when the dispatcher's
170
+ * `apply_authorization_phase` rejects a request before the handler runs —
171
+ * the route is acting-aware (input declares `acting?: ActingActor` or
172
+ * auth requires permits), but actor resolution failed.
173
+ *
174
+ * 400: `actor_required` (with `available[]`) for unspecified-actor on
175
+ * a multi-actor account; `actor_not_on_account` for a supplied actor
176
+ * id that doesn't belong to the authenticated account.
177
+ *
178
+ * 500: `no_actors_on_account` for a signup-invariant violation (the
179
+ * actor list enumerated empty); `account_vanished` for a torn-read
180
+ * race (account/actor row deleted between credential validation and
181
+ * the dispatcher's follow-up read).
182
+ *
183
+ * Used by `derive_error_schemas` when `acting_aware` is true so the
184
+ * merged error surface matches what the dispatcher actually emits.
185
+ */
186
+ export declare const ActorRequiredError: z.ZodObject<{
187
+ error: z.ZodLiteral<"actor_required">;
188
+ available: z.ZodArray<z.ZodObject<{
189
+ id: z.ZodString;
190
+ name: z.ZodString;
191
+ }, z.core.$loose>>;
192
+ }, z.core.$loose>;
193
+ export type ActorRequiredError = z.infer<typeof ActorRequiredError>;
194
+ export declare const ActorNotOnAccountError: z.ZodObject<{
195
+ error: z.ZodLiteral<"actor_not_on_account">;
196
+ }, z.core.$loose>;
197
+ export type ActorNotOnAccountError = z.infer<typeof ActorNotOnAccountError>;
198
+ export declare const NoActorsOnAccountError: z.ZodObject<{
199
+ error: z.ZodLiteral<"no_actors_on_account">;
200
+ }, z.core.$loose>;
201
+ export type NoActorsOnAccountError = z.infer<typeof NoActorsOnAccountError>;
202
+ export declare const AccountVanishedError: z.ZodObject<{
203
+ error: z.ZodLiteral<"account_vanished">;
204
+ }, z.core.$loose>;
205
+ export type AccountVanishedError = z.infer<typeof AccountVanishedError>;
135
206
  /**
136
207
  * Error schema map — maps HTTP status codes to Zod schemas.
137
208
  *
@@ -167,6 +238,26 @@ export type RateLimitKey = z.infer<typeof RateLimitKey>;
167
238
  * - **auth: role**: 401 + 403 (with `required_role`)
168
239
  * - **auth: keeper**: 401 + 403 (keeper-specific)
169
240
  * - **rate_limit**: 429 (rate limit exceeded with `retry_after`)
241
+ * - **acting_aware**: extends 400 with `ActorRequiredError` / `ActorNotOnAccountError`
242
+ * and adds 500 union of `NoActorsOnAccountError` / `AccountVanishedError`. The
243
+ * dispatcher's authorization phase emits these on routes whose input declares
244
+ * `acting?: ActingActor` or whose auth requires permits (`role` / `keeper`); the
245
+ * route's surface must reflect them so DEV-mode error-schema validation in
246
+ * `wrap_output_validation` doesn't fail when the auth phase fires before the
247
+ * handler. See `http/CLAUDE.md` § Three-layer error-schema merge.
248
+ *
249
+ * `acting_aware` is computed at the merge call site (it requires inspecting
250
+ * the input schema for `acting?: ActingActor`, which lives in `auth/`). This
251
+ * keeps `http/` auth-agnostic — the per-route flag flows in via the optional
252
+ * `is_acting_aware` callback on `apply_route_specs` / `generate_app_surface`.
170
253
  */
171
- export declare const derive_error_schemas: (auth: RouteAuth, has_input: boolean, has_params?: boolean, has_query?: boolean, rate_limit?: RateLimitKey) => RouteErrorSchemas;
254
+ export interface DeriveErrorSchemasOptions {
255
+ auth: RouteAuth;
256
+ has_input?: boolean;
257
+ has_params?: boolean;
258
+ has_query?: boolean;
259
+ rate_limit?: RateLimitKey;
260
+ acting_aware?: boolean;
261
+ }
262
+ export declare const derive_error_schemas: ({ auth, has_input, has_params, has_query, rate_limit, acting_aware, }: DeriveErrorSchemasOptions) => RouteErrorSchemas;
172
263
  //# sourceMappingURL=error_schemas.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"error_schemas.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/error_schemas.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAEtB,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAI/C,0CAA0C;AAC1C,eAAO,MAAM,0BAA0B,EAAG,sBAA+B,CAAC;AAE1E,uDAAuD;AACvD,eAAO,MAAM,uBAAuB,EAAG,mBA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;iBAEjC,CAAC;AACH,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAE5E,eAAO,MAAM,sBAAsB;;iBAEjC,CAAC;AACH,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAE5E,eAAO,MAAM,oBAAoB;;iBAE/B,CAAC;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAExE;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;AAEnE;;;;;;;;;GASG;AACH,eAAO,MAAM,YAAY;;;;EAAoC,CAAC;AAC9D,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAExD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,WAAW,yBAAyB;IACzC,IAAI,EAAE,SAAS,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,YAAY,CAAC;IAC1B,YAAY,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,eAAO,MAAM,oBAAoB,GAAI,uEAOlC,yBAAyB,KAAG,iBAkC9B,CAAC"}
@@ -43,6 +43,39 @@ export const ERROR_BEARER_REJECTED_BROWSER = 'bearer_token_rejected_in_browser_c
43
43
  export const ERROR_INVALID_TOKEN = 'invalid_token';
44
44
  /** Token references a deleted account. */
45
45
  export const ERROR_ACCOUNT_NOT_FOUND = 'account_not_found';
46
+ /**
47
+ * Multi-actor account requires the request to carry an explicit `acting`
48
+ * field naming the actor the request is acting as, so the dispatcher's
49
+ * authorization phase doesn't pick a default actor silently. Returned
50
+ * with the available actors so the client can prompt.
51
+ */
52
+ export const ERROR_ACTOR_REQUIRED = 'actor_required';
53
+ /**
54
+ * Supplied `acting` field does not name an actor on the authenticated
55
+ * account.
56
+ */
57
+ export const ERROR_ACTOR_NOT_ON_ACCOUNT = 'actor_not_on_account';
58
+ /**
59
+ * Authenticated account exists but has no actors. Server invariant
60
+ * violation — signup / bootstrap always create an actor in the same
61
+ * transaction. Surfaced from the dispatcher's authorization phase as a
62
+ * 500 so the operator sees the corruption signal rather than a confusing
63
+ * 4xx. Distinct from `ERROR_ACCOUNT_VANISHED`: the actor list was
64
+ * enumerated successfully and came back empty.
65
+ */
66
+ export const ERROR_NO_ACTORS_ON_ACCOUNT = 'no_actors_on_account';
67
+ /**
68
+ * Authentication validated an account, but a follow-up read in the
69
+ * authorization phase came back null — the account or its named actor
70
+ * row was deleted between the credential check and the dispatcher's
71
+ * `build_request_context` / `build_account_context` step. Torn read,
72
+ * not a missing-actor invariant violation. Surfaced as 500 so the
73
+ * operator sees the race signal; clients can retry. Distinct from
74
+ * `ERROR_ACCOUNT_NOT_FOUND` (stale token referencing a long-deleted
75
+ * account, raised at credential validation) and
76
+ * `ERROR_NO_ACTORS_ON_ACCOUNT` (the actor list enumerated empty).
77
+ */
78
+ export const ERROR_ACCOUNT_VANISHED = 'account_vanished';
46
79
  // --- Keeper / daemon token ---
47
80
  /** Keeper routes require daemon_token credential type. */
48
81
  export const ERROR_KEEPER_REQUIRES_DAEMON_TOKEN = 'keeper_requires_daemon_token';
@@ -132,6 +165,37 @@ export const PayloadTooLargeError = z.looseObject({
132
165
  export const ForeignKeyError = z.looseObject({
133
166
  error: z.literal(ERROR_FOREIGN_KEY_VIOLATION),
134
167
  });
168
+ /**
169
+ * Authorization-phase failure shapes. Surfaced when the dispatcher's
170
+ * `apply_authorization_phase` rejects a request before the handler runs —
171
+ * the route is acting-aware (input declares `acting?: ActingActor` or
172
+ * auth requires permits), but actor resolution failed.
173
+ *
174
+ * 400: `actor_required` (with `available[]`) for unspecified-actor on
175
+ * a multi-actor account; `actor_not_on_account` for a supplied actor
176
+ * id that doesn't belong to the authenticated account.
177
+ *
178
+ * 500: `no_actors_on_account` for a signup-invariant violation (the
179
+ * actor list enumerated empty); `account_vanished` for a torn-read
180
+ * race (account/actor row deleted between credential validation and
181
+ * the dispatcher's follow-up read).
182
+ *
183
+ * Used by `derive_error_schemas` when `acting_aware` is true so the
184
+ * merged error surface matches what the dispatcher actually emits.
185
+ */
186
+ export const ActorRequiredError = z.looseObject({
187
+ error: z.literal(ERROR_ACTOR_REQUIRED),
188
+ available: z.array(z.looseObject({ id: z.string(), name: z.string() })),
189
+ });
190
+ export const ActorNotOnAccountError = z.looseObject({
191
+ error: z.literal(ERROR_ACTOR_NOT_ON_ACCOUNT),
192
+ });
193
+ export const NoActorsOnAccountError = z.looseObject({
194
+ error: z.literal(ERROR_NO_ACTORS_ON_ACCOUNT),
195
+ });
196
+ export const AccountVanishedError = z.looseObject({
197
+ error: z.literal(ERROR_ACCOUNT_VANISHED),
198
+ });
135
199
  /**
136
200
  * Rate limit key type — declares what a route or RPC action's rate limiter
137
201
  * is keyed on.
@@ -143,23 +207,16 @@ export const ForeignKeyError = z.looseObject({
143
207
  * - `'both'` — both keys.
144
208
  */
145
209
  export const RateLimitKey = z.enum(['ip', 'account', 'both']);
146
- /**
147
- * Derive error schemas from a route's auth requirement, input schema, and rate limit config.
148
- *
149
- * Returns the error schemas that middleware will auto-produce for this route.
150
- * Route handlers can declare additional error schemas via `RouteSpec.errors`;
151
- * explicit entries override auto-derived ones for the same status code.
152
- *
153
- * Derivation rules:
154
- * - **Has input schema** (non-null) or **has params schema** or **has query schema**: 400 (validation error with issues)
155
- * - **auth: authenticated**: 401
156
- * - **auth: role**: 401 + 403 (with `required_role`)
157
- * - **auth: keeper**: 401 + 403 (keeper-specific)
158
- * - **rate_limit**: 429 (rate limit exceeded with `retry_after`)
159
- */
160
- export const derive_error_schemas = (auth, has_input, has_params = false, has_query = false, rate_limit) => {
210
+ export const derive_error_schemas = ({ auth, has_input = false, has_params = false, has_query = false, rate_limit, acting_aware = false, }) => {
161
211
  const errors = {};
162
- if (has_input || has_params || has_query) {
212
+ const has_validation = has_input || has_params || has_query;
213
+ if (acting_aware) {
214
+ errors[400] = has_validation
215
+ ? z.union([ValidationError, ActorRequiredError, ActorNotOnAccountError])
216
+ : z.union([ActorRequiredError, ActorNotOnAccountError]);
217
+ errors[500] = z.union([NoActorsOnAccountError, AccountVanishedError]);
218
+ }
219
+ else if (has_validation) {
163
220
  errors[400] = ValidationError;
164
221
  }
165
222
  switch (auth.type) {
@@ -16,6 +16,7 @@
16
16
  *
17
17
  * @module
18
18
  */
19
+ import type { ContentfulStatusCode } from 'hono/utils/http-status';
19
20
  import { type JsonrpcErrorCode, type JsonrpcErrorObject } from './jsonrpc.js';
20
21
  /** Default message for unknown errors. */
21
22
  export declare const UNKNOWN_ERROR_MESSAGE = "unknown error";
@@ -97,13 +98,37 @@ export declare const HTTP_STATUS_TO_JSONRPC_ERROR_CODE: Record<number, JsonrpcEr
97
98
  * Map a JSON-RPC error code to an HTTP status code.
98
99
  *
99
100
  * Returns 500 for unrecognized codes (consumer-defined codes
100
- * without a mapping default to internal server error).
101
+ * without a mapping default to internal server error). The return
102
+ * is narrowed to Hono's `ContentfulStatusCode` so call sites can
103
+ * pass the result to `c.json(body, status)` without `as any` —
104
+ * 499 (nginx "client closed request") is non-standard and gets
105
+ * absorbed by the cast here rather than at every dispatcher branch.
101
106
  */
102
- export declare const jsonrpc_error_code_to_http_status: (code: JsonrpcErrorCode) => number;
107
+ export declare const jsonrpc_error_code_to_http_status: (code: JsonrpcErrorCode) => ContentfulStatusCode;
103
108
  /**
104
109
  * Map an HTTP status code to a JSON-RPC error code.
105
110
  *
106
111
  * Returns `internal_error` (-32603) for unrecognized status codes.
107
112
  */
108
113
  export declare const http_status_to_jsonrpc_error_code: (status: number) => JsonrpcErrorCode;
114
+ /**
115
+ * Reverse map of `JSONRPC_ERROR_CODES` — JSON-RPC error code → name.
116
+ *
117
+ * Used by REST emitters that need a stable string identifier for the
118
+ * code in their flat-shape error body (`{error: '<name>', ...}`)
119
+ * without inventing a separate vocabulary. Built once at module load
120
+ * from the canonical `JSONRPC_ERROR_CODES` map so the two cannot drift.
121
+ *
122
+ * Consumer-defined codes outside the standard taxonomy are not present;
123
+ * `jsonrpc_error_code_to_name` falls back to `'internal_error'` so the
124
+ * REST shape always carries some reason rather than `undefined`.
125
+ */
126
+ export declare const JSONRPC_ERROR_CODE_TO_NAME: Readonly<Record<number, JsonrpcErrorName>>;
127
+ /**
128
+ * Map a JSON-RPC error code to its canonical name (`'not_found'`,
129
+ * `'forbidden'`, etc.). Falls back to `'internal_error'` for codes
130
+ * outside the standard taxonomy so REST emitters that read this for
131
+ * their `error` field always have a stable string to emit.
132
+ */
133
+ export declare const jsonrpc_error_code_to_name: (code: JsonrpcErrorCode) => JsonrpcErrorName;
109
134
  //# sourceMappingURL=jsonrpc_errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"jsonrpc_errors.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/jsonrpc_errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAMN,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,MAAM,cAAc,CAAC;AAEtB,0CAA0C;AAC1C,eAAO,MAAM,qBAAqB,kBAAkB,CAAC;AAErD,sEAAsE;AACtE,MAAM,MAAM,gBAAgB,GACzB,aAAa,GACb,iBAAiB,GACjB,kBAAkB,GAClB,gBAAgB,GAChB,gBAAgB,GAChB,iBAAiB,GACjB,WAAW,GACX,WAAW,GACX,UAAU,GACV,kBAAkB,GAClB,cAAc,GACd,qBAAqB,GACrB,SAAS,GACT,gBAAgB,GAChB,mBAAmB,CAAC;AAEvB;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,EA0C1B,QAAQ,CAAC,MAAM,CAAC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kB;0CAAlB,kBAAkB;iDAAlB,kBAAkB;oDAAlB,kBAAkB;CA2BqC,CAAC;AAI3F;;;;;;;GAOG;AACH,eAAO,MAAM,iCAAiC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAkBpE,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,iCAAiC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAMzC,CAAC;AAEvC;;;;;;;;;GASG;AACH,eAAO,MAAM,iCAAiC,GAAI,MAAM,gBAAgB,KAAG,oBACQ,CAAC;AAEpF;;;;GAIG;AACH,eAAO,MAAM,iCAAiC,GAAI,QAAQ,MAAM,KAAG,gBACa,CAAC;AAEjF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,0BAA0B,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAMjF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,GAAI,MAAM,gBAAgB,KAAG,gBACL,CAAC"}
@@ -242,12 +242,36 @@ export const HTTP_STATUS_TO_JSONRPC_ERROR_CODE = Object.fromEntries(Object.entri
242
242
  * Map a JSON-RPC error code to an HTTP status code.
243
243
  *
244
244
  * Returns 500 for unrecognized codes (consumer-defined codes
245
- * without a mapping default to internal server error).
245
+ * without a mapping default to internal server error). The return
246
+ * is narrowed to Hono's `ContentfulStatusCode` so call sites can
247
+ * pass the result to `c.json(body, status)` without `as any` —
248
+ * 499 (nginx "client closed request") is non-standard and gets
249
+ * absorbed by the cast here rather than at every dispatcher branch.
246
250
  */
247
- export const jsonrpc_error_code_to_http_status = (code) => JSONRPC_ERROR_CODE_TO_HTTP_STATUS[code] ?? 500;
251
+ export const jsonrpc_error_code_to_http_status = (code) => (JSONRPC_ERROR_CODE_TO_HTTP_STATUS[code] ?? 500);
248
252
  /**
249
253
  * Map an HTTP status code to a JSON-RPC error code.
250
254
  *
251
255
  * Returns `internal_error` (-32603) for unrecognized status codes.
252
256
  */
253
257
  export const http_status_to_jsonrpc_error_code = (status) => HTTP_STATUS_TO_JSONRPC_ERROR_CODE[status] ?? JSONRPC_ERROR_CODES.internal_error;
258
+ /**
259
+ * Reverse map of `JSONRPC_ERROR_CODES` — JSON-RPC error code → name.
260
+ *
261
+ * Used by REST emitters that need a stable string identifier for the
262
+ * code in their flat-shape error body (`{error: '<name>', ...}`)
263
+ * without inventing a separate vocabulary. Built once at module load
264
+ * from the canonical `JSONRPC_ERROR_CODES` map so the two cannot drift.
265
+ *
266
+ * Consumer-defined codes outside the standard taxonomy are not present;
267
+ * `jsonrpc_error_code_to_name` falls back to `'internal_error'` so the
268
+ * REST shape always carries some reason rather than `undefined`.
269
+ */
270
+ export const JSONRPC_ERROR_CODE_TO_NAME = Object.freeze(Object.fromEntries(Object.entries(JSONRPC_ERROR_CODES).map(([name, code]) => [code, name])));
271
+ /**
272
+ * Map a JSON-RPC error code to its canonical name (`'not_found'`,
273
+ * `'forbidden'`, etc.). Falls back to `'internal_error'` for codes
274
+ * outside the standard taxonomy so REST emitters that read this for
275
+ * their `error` field always have a stable string to emit.
276
+ */
277
+ export const jsonrpc_error_code_to_name = (code) => JSONRPC_ERROR_CODE_TO_NAME[code] ?? 'internal_error';
@@ -34,6 +34,19 @@ export type RouteAuth = {
34
34
  } | {
35
35
  type: 'keeper';
36
36
  };
37
+ /**
38
+ * Two-phase auth guard set returned by `AuthGuardResolver`.
39
+ *
40
+ * `pre_validation` runs before input validation — 401 checks live here
41
+ * so unauthenticated callers never see route-shape information from
42
+ * input parsing failures. `post_authorization` runs after the
43
+ * authorization phase has populated `RequestContext` — role / keeper
44
+ * checks live here because they read `c.var.request_context.permits`.
45
+ */
46
+ export interface AuthGuards {
47
+ pre_validation: Array<MiddlewareHandler>;
48
+ post_authorization: Array<MiddlewareHandler>;
49
+ }
37
50
  /**
38
51
  * Resolves a `RouteAuth` to middleware guard handlers.
39
52
  *
@@ -41,7 +54,37 @@ export type RouteAuth = {
41
54
  * from auth-specific middleware. See `fuz_auth_guard_resolver` in
42
55
  * `auth/route_guards.ts` for the standard implementation.
43
56
  */
44
- export type AuthGuardResolver = (auth: RouteAuth) => Array<MiddlewareHandler>;
57
+ export type AuthGuardResolver = (auth: RouteAuth) => AuthGuards;
58
+ /**
59
+ * Per-route authorization phase. Runs after the pre-validation auth guards
60
+ * and before input validation; resolves the acting actor (when the route's
61
+ * input declares `acting?: ActingActor` or auth requires permits) and sets
62
+ * the request context on the Hono context. Per-route order in
63
+ * `apply_route_specs`: params → query → pre-validation auth (401) →
64
+ * authorization → post-authorization auth (403) → input validation →
65
+ * handler.
66
+ *
67
+ * Returns a `Response` to short-circuit (resolution failure → 400 / 500),
68
+ * or `void` to continue. The http framework stays auth-agnostic — fuz_app
69
+ * provides the implementation via `create_fuz_authorization_handler` in
70
+ * `auth/request_context.ts`.
71
+ */
72
+ export type AuthorizationHandler = (c: Context, spec: RouteSpec) => Promise<Response | void>;
73
+ /**
74
+ * Predicate that decides whether a route is "acting-aware" — i.e. whether
75
+ * the dispatcher's authorization phase may emit `actor_required` /
76
+ * `actor_not_on_account` (400) or `no_actors_on_account` /
77
+ * `account_vanished` (500) on this spec. When the predicate returns true
78
+ * the merged error schema is widened to accept those shapes so DEV-mode
79
+ * `wrap_output_validation` doesn't reject them.
80
+ *
81
+ * Computed at the call site because the canonical "input declares
82
+ * `acting?: ActingActor`" check lives in `auth/request_context.ts` (it
83
+ * uses reference equality with the canonical `ActingActor` schema). The
84
+ * `http/` framework receives the predicate via this callback so it stays
85
+ * auth-agnostic. See `http/CLAUDE.md` § Three-layer error-schema merge.
86
+ */
87
+ export type IsActingAware = (spec: Pick<RouteSpec, 'auth' | 'input'>) => boolean;
45
88
  /** HTTP methods supported by route specs. */
46
89
  export type RouteMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
47
90
  /**
@@ -153,8 +196,22 @@ export declare const apply_middleware_specs: (app: Hono, specs: Array<Middleware
153
196
  *
154
197
  * For each spec: resolves auth to guards via the provided resolver,
155
198
  * adds input validation middleware (for routes with non-null input schemas),
156
- * wraps handler with DEV-only output and error validation, wraps with error
157
- * catch layer (catches `ThrownJsonrpcError` and generic errors), and registers the route.
199
+ * runs the optional authorization phase to resolve the acting actor + build
200
+ * the request context, wraps handler with DEV-only output and error
201
+ * validation, wraps with error catch layer (catches `ThrownJsonrpcError`
202
+ * and generic errors), and registers the route.
203
+ *
204
+ * Per-route middleware order: params → query → pre-validation auth
205
+ * guards (401) → authorization phase → post-authorization auth guards
206
+ * (403) → input validation → handler. The 401 check runs before any
207
+ * body parsing so unauthenticated callers never see route-shape
208
+ * information from parse failures. The authorization phase runs before
209
+ * input validation (matches the RPC dispatcher's order) so role /
210
+ * keeper denials surface 403 before 400 invalid_params; it extracts
211
+ * `acting` from raw query (GET) or pre-parsed JSON body (POST/PUT/...)
212
+ * — Hono caches the parsed body internally so the subsequent input-
213
+ * validation step does not re-parse. The role / keeper guards consume
214
+ * the `RequestContext` populated by the authorization phase.
158
215
  *
159
216
  * Each handler receives a `RouteContext` with:
160
217
  * - `db`: transaction-scoped (for non-GET) or pool-level (for GET)
@@ -162,11 +219,12 @@ export declare const apply_middleware_specs: (app: Hono, specs: Array<Middleware
162
219
  * - `pending_effects`: fire-and-forget effect queue
163
220
  *
164
221
  * @param resolve_auth_guards - maps `RouteAuth` to middleware — use `fuz_auth_guard_resolver` from `auth/route_guards.ts`
222
+ * @param authorize - optional authorization phase; runs between guards and input validation
165
223
  * @param db - used for transaction wrapping and `RouteContext`
166
224
  * @mutates `app`
167
225
  * @throws Error if two specs share the same `method` + `path` (each combination must be unique)
168
226
  */
169
- export declare const apply_route_specs: (app: Hono, specs: Array<RouteSpec>, resolve_auth_guards: AuthGuardResolver, log: Logger, db: Db) => void;
227
+ export declare const apply_route_specs: (app: Hono, specs: Array<RouteSpec>, resolve_auth_guards: AuthGuardResolver, log: Logger, db: Db, authorize?: AuthorizationHandler, is_acting_aware?: IsActingAware) => void;
170
228
  /**
171
229
  * Prepend a prefix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