@fuzdev/fuz_app 0.168.1 → 0.170.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.
- package/dist/actions/CLAUDE.md +17 -19
- package/dist/actions/action_codegen.d.ts +32 -23
- package/dist/actions/action_codegen.d.ts.map +1 -1
- package/dist/actions/action_codegen.js +101 -80
- package/dist/actions/action_event.d.ts +0 -8
- package/dist/actions/action_event.d.ts.map +1 -1
- package/dist/actions/action_event.js +7 -6
- package/dist/actions/action_event_data.d.ts +18 -18
- package/dist/actions/action_rpc.d.ts +1 -1
- package/dist/actions/action_rpc.js +1 -1
- package/dist/actions/action_spec.d.ts +8 -10
- package/dist/actions/action_spec.d.ts.map +1 -1
- package/dist/actions/action_spec.js +1 -1
- package/dist/actions/action_types.d.ts +4 -4
- package/dist/actions/action_types.d.ts.map +1 -1
- package/dist/actions/action_types.js +2 -2
- package/dist/actions/broadcast_api.d.ts +2 -2
- package/dist/actions/broadcast_api.js +4 -4
- package/dist/actions/compile_action_registry.d.ts +6 -7
- package/dist/actions/compile_action_registry.d.ts.map +1 -1
- package/dist/actions/compile_action_registry.js +8 -9
- package/dist/actions/perform_action.d.ts +6 -6
- package/dist/actions/perform_action.d.ts.map +1 -1
- package/dist/actions/perform_action.js +11 -10
- package/dist/actions/socket.svelte.d.ts +1 -1
- package/dist/actions/socket.svelte.js +2 -2
- package/dist/auth/CLAUDE.md +11 -11
- package/dist/auth/account_action_specs.d.ts +11 -11
- package/dist/auth/account_action_specs.js +1 -1
- package/dist/auth/account_route_schema.d.ts +18 -18
- package/dist/auth/account_route_schema.js +1 -1
- package/dist/auth/account_routes.js +1 -1
- package/dist/auth/account_schema.d.ts +38 -40
- package/dist/auth/account_schema.d.ts.map +1 -1
- package/dist/auth/account_schema.js +7 -8
- package/dist/auth/actor_lookup_action_specs.d.ts +7 -7
- package/dist/auth/actor_lookup_action_specs.js +1 -1
- package/dist/auth/actor_search_action_specs.d.ts +6 -6
- package/dist/auth/actor_search_action_specs.js +1 -1
- package/dist/auth/admin_action_specs.d.ts +166 -166
- package/dist/auth/admin_action_specs.js +1 -1
- package/dist/auth/app_settings_schema.d.ts +3 -3
- package/dist/auth/app_settings_schema.d.ts.map +1 -1
- package/dist/auth/app_settings_schema.js +1 -1
- package/dist/auth/audit_emitter.d.ts +6 -7
- package/dist/auth/audit_emitter.d.ts.map +1 -1
- package/dist/auth/audit_emitter.js +11 -22
- package/dist/auth/audit_log_ddl.d.ts +1 -1
- package/dist/auth/audit_log_ddl.js +1 -1
- package/dist/auth/audit_log_queries.d.ts +0 -13
- package/dist/auth/audit_log_queries.d.ts.map +1 -1
- package/dist/auth/audit_log_queries.js +3 -3
- package/dist/auth/audit_log_route_schema.d.ts +1 -1
- package/dist/auth/audit_log_route_schema.js +1 -1
- package/dist/auth/audit_log_schema.d.ts +69 -70
- package/dist/auth/audit_log_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_schema.js +2 -2
- package/dist/auth/auth_ddl.d.ts +1 -1
- package/dist/auth/auth_ddl.js +1 -1
- package/dist/auth/bootstrap_route_schema.d.ts +4 -4
- package/dist/auth/bootstrap_route_schema.js +1 -1
- package/dist/auth/cell_action_specs.d.ts +466 -466
- package/dist/auth/cell_action_specs.js +1 -1
- package/dist/auth/cell_actions.d.ts +2 -2
- package/dist/auth/cell_actions.js +5 -5
- package/dist/auth/cell_audit_action_specs.d.ts +14 -14
- package/dist/auth/cell_audit_action_specs.js +1 -1
- package/dist/auth/cell_audit_metadata.d.ts +8 -8
- package/dist/auth/cell_audit_metadata.js +1 -1
- package/dist/auth/cell_field_action_specs.d.ts +55 -55
- package/dist/auth/cell_field_action_specs.js +1 -1
- package/dist/auth/cell_field_audit_metadata.d.ts +4 -4
- package/dist/auth/cell_field_audit_metadata.js +1 -1
- package/dist/auth/cell_grant_action_specs.d.ts +61 -61
- package/dist/auth/cell_grant_action_specs.js +1 -1
- package/dist/auth/cell_grant_audit_metadata.d.ts +10 -10
- package/dist/auth/cell_grant_audit_metadata.js +1 -1
- package/dist/auth/cell_item_action_specs.d.ts +76 -76
- package/dist/auth/cell_item_action_specs.js +1 -1
- package/dist/auth/cell_item_audit_metadata.d.ts +5 -5
- package/dist/auth/cell_item_audit_metadata.js +1 -1
- package/dist/auth/invite_schema.d.ts +11 -11
- package/dist/auth/invite_schema.d.ts.map +1 -1
- package/dist/auth/invite_schema.js +1 -1
- package/dist/auth/name_schema.js +1 -1
- package/dist/auth/password.js +1 -1
- package/dist/auth/request_context.js +2 -2
- package/dist/auth/role_grant_offer_action_specs.d.ts +182 -182
- package/dist/auth/role_grant_offer_action_specs.js +1 -1
- package/dist/auth/role_grant_offer_ddl.d.ts +1 -1
- package/dist/auth/role_grant_offer_ddl.js +1 -1
- package/dist/auth/role_grant_offer_notifications.d.ts +107 -107
- package/dist/auth/role_grant_offer_notifications.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_notifications.js +3 -4
- package/dist/auth/role_grant_offer_schema.d.ts +9 -9
- package/dist/auth/role_grant_offer_schema.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_schema.js +1 -1
- package/dist/auth/self_service_role_action_specs.d.ts +2 -2
- package/dist/auth/self_service_role_action_specs.js +1 -1
- package/dist/auth/self_service_role_actions.d.ts +1 -1
- package/dist/auth/self_service_role_actions.js +1 -1
- package/dist/auth/signup_route_schema.d.ts +2 -2
- package/dist/auth/signup_route_schema.js +1 -1
- package/dist/auth/token_scope.d.ts +8 -8
- package/dist/db/file_fact_url.d.ts +1 -1
- package/dist/env/env_schemas.d.ts +1 -2
- package/dist/env/env_schemas.d.ts.map +1 -1
- package/dist/env/env_schemas.js +3 -4
- package/dist/http/CLAUDE.md +30 -32
- package/dist/http/auth_shape.d.ts +17 -52
- package/dist/http/auth_shape.d.ts.map +1 -1
- package/dist/http/auth_shape.js +19 -61
- package/dist/http/db_routes.d.ts +1 -1
- package/dist/http/db_routes.d.ts.map +1 -1
- package/dist/http/db_routes.js +1 -1
- package/dist/http/error_schemas.d.ts +36 -36
- package/dist/http/jsonrpc.d.ts +11 -11
- package/dist/http/jsonrpc_helpers.js +1 -1
- package/dist/http/route_error_check.d.ts +2 -2
- package/dist/http/route_error_check.d.ts.map +1 -1
- package/dist/http/route_error_check.js +2 -3
- package/dist/http/route_errors.d.ts +4 -4
- package/dist/http/route_errors.d.ts.map +1 -1
- package/dist/http/route_errors.js +0 -13
- package/dist/http/route_spec.d.ts +33 -36
- package/dist/http/route_spec.d.ts.map +1 -1
- package/dist/http/route_spec.js +21 -22
- package/dist/http/schema_helpers.d.ts +75 -67
- package/dist/http/schema_helpers.d.ts.map +1 -1
- package/dist/http/schema_helpers.js +54 -76
- package/dist/http/surface.d.ts.map +1 -1
- package/dist/http/surface.js +6 -8
- package/dist/primitive_schemas.d.ts +162 -112
- package/dist/primitive_schemas.d.ts.map +1 -1
- package/dist/primitive_schemas.js +129 -161
- package/dist/realtime/sse.d.ts +3 -3
- package/dist/realtime/sse.d.ts.map +1 -1
- package/dist/realtime/sse.js +2 -2
- package/dist/schema_issues.d.ts +41 -146
- package/dist/schema_issues.d.ts.map +1 -1
- package/dist/schema_issues.js +39 -322
- package/dist/schema_meta.d.ts +63 -136
- package/dist/schema_meta.d.ts.map +1 -1
- package/dist/schema_meta.js +37 -184
- package/dist/sensitivity.d.ts +3 -5
- package/dist/sensitivity.d.ts.map +1 -1
- package/dist/sensitivity.js +3 -5
- package/dist/server/serve_fact_route.js +1 -1
- package/dist/server/surface_route.js +1 -1
- package/dist/testing/CLAUDE.md +23 -25
- package/dist/testing/adversarial_headers.js +2 -2
- package/dist/testing/adversarial_input_cases.d.ts +19 -18
- package/dist/testing/adversarial_input_cases.d.ts.map +1 -1
- package/dist/testing/adversarial_input_cases.js +29 -42
- package/dist/testing/assertions.d.ts +2 -2
- package/dist/testing/assertions.d.ts.map +1 -1
- package/dist/testing/assertions.js +3 -3
- package/dist/testing/cross_backend/account_lifecycle.js +2 -2
- package/dist/testing/cross_backend/action_manifest.d.ts +10 -9
- package/dist/testing/cross_backend/action_manifest.d.ts.map +1 -1
- package/dist/testing/cross_backend/action_manifest.js +4 -3
- package/dist/testing/cross_backend/cell_crud.js +1 -1
- package/dist/testing/cross_backend/conformance_case.d.ts +96 -114
- package/dist/testing/cross_backend/conformance_case.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_case.js +0 -256
- package/dist/testing/cross_backend/conformance_rpc_auth.d.ts +0 -62
- package/dist/testing/cross_backend/conformance_rpc_auth.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_table.js +3 -3
- package/dist/testing/cross_backend/cross_rpc.d.ts +3 -4
- package/dist/testing/cross_backend/cross_rpc.d.ts.map +1 -1
- package/dist/testing/cross_backend/cross_rpc.js +4 -4
- package/dist/testing/cross_backend/differential.js +2 -2
- package/dist/testing/cross_backend/fact_serving.js +1 -1
- package/dist/testing/cross_backend/identity_parity.js +9 -9
- package/dist/testing/cross_backend/origin_conformance.d.ts +9 -9
- package/dist/testing/cross_backend/query_shape.js +1 -1
- package/dist/testing/cross_backend/rpc_success_fixtures.d.ts.map +1 -1
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +1 -1
- package/dist/testing/cross_backend/setup.d.ts +26 -4
- package/dist/testing/cross_backend/setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/setup.js +7 -8
- package/dist/testing/cross_backend/sse_round_trip.js +2 -2
- package/dist/testing/cross_backend/testing_origin_check.d.ts +12 -12
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +608 -201
- package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_reset_actions.js +46 -55
- package/dist/testing/cross_backend/token_lifetime.js +3 -3
- package/dist/testing/cross_backend/wire_shapes.js +1 -1
- package/dist/testing/cross_backend/ws_outbound_overflow.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_outbound_overflow.js +35 -0
- package/dist/testing/cross_backend/ws_round_trip.js +1 -1
- package/dist/testing/data_exposure.d.ts.map +1 -1
- package/dist/testing/data_exposure.js +1 -1
- package/dist/testing/integration.js +2 -2
- package/dist/testing/integration_helpers.d.ts.map +1 -1
- package/dist/testing/integration_helpers.js +2 -2
- package/dist/testing/middleware.d.ts.map +1 -1
- package/dist/testing/middleware.js +2 -2
- package/dist/testing/rpc_attack_surface.js +1 -1
- package/dist/testing/rpc_envelope_cases.d.ts +3 -3
- package/dist/testing/rpc_envelope_cases.d.ts.map +1 -1
- package/dist/testing/rpc_envelope_cases.js +1 -1
- package/dist/testing/rpc_helpers.d.ts +12 -14
- package/dist/testing/rpc_helpers.d.ts.map +1 -1
- package/dist/testing/rpc_helpers.js +9 -11
- package/dist/testing/schema_generators.d.ts +67 -60
- package/dist/testing/schema_generators.d.ts.map +1 -1
- package/dist/testing/schema_generators.js +144 -151
- package/dist/testing/schema_introspect.d.ts +438 -78
- package/dist/testing/schema_introspect.d.ts.map +1 -1
- package/dist/testing/schema_introspect.js +26 -26
- package/dist/testing/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/sse_round_trip.js +2 -2
- package/dist/testing/surface_invariants.d.ts +1 -1
- package/dist/testing/surface_invariants.js +1 -1
- package/dist/testing/transports/bootstrap.d.ts +1 -1
- package/dist/testing/transports/bootstrap.d.ts.map +1 -1
- package/dist/testing/transports/bootstrap.js +1 -1
- package/dist/ui/BootstrapForm.svelte +1 -2
- package/dist/ui/BootstrapForm.svelte.d.ts.map +1 -1
- package/dist/ui/SignupForm.svelte +1 -2
- package/dist/ui/SignupForm.svelte.d.ts.map +1 -1
- package/dist/ui/admin_accounts_state.svelte.d.ts +5 -5
- package/dist/ui/admin_accounts_state.svelte.d.ts.map +1 -1
- package/dist/ui/admin_invites_state.svelte.d.ts +1 -1
- package/dist/ui/admin_invites_state.svelte.d.ts.map +1 -1
- package/dist/ui/admin_sessions_state.svelte.d.ts +2 -2
- package/dist/ui/admin_sessions_state.svelte.d.ts.map +1 -1
- package/dist/ui/form_state.svelte.d.ts +1 -1
- package/dist/ui/form_state.svelte.js +1 -1
- package/dist/ui/role_grant_offers_state.svelte.d.ts +1 -1
- package/package.json +7 -9
- package/dist/primitive_schemas_fuz.d.ts +0 -178
- package/dist/primitive_schemas_fuz.d.ts.map +0 -1
- package/dist/primitive_schemas_fuz.js +0 -149
- package/dist/zod.d.ts +0 -101
- package/dist/zod.d.ts.map +0 -1
- package/dist/zod.js +0 -195
package/dist/http/CLAUDE.md
CHANGED
|
@@ -52,10 +52,10 @@ consumers.
|
|
|
52
52
|
- `auth: RouteAuth` — flat record `{account, actor, roles?, credential_types?, required_scope?}` from `http/auth_shape.ts`. `account` / `actor` are `'none' | 'optional' | 'required'`. `required_scope` names the capability a narrowed api token's scope must admit — `surface:<name>`, a non-RPC surface refused to every narrowed token (an `rpc:<method>` capability throws at registration: it is the dispatcher's per-method gate, which a route never reaches) — and is route-spec-only: `compile_action_registry` rejects it on an `ActionSpec`, where the dispatcher derives `rpc:<method>` from `spec.method`. Otherwise the same shape governs `ActionSpec.auth` (see `actions/CLAUDE.md`).
|
|
53
53
|
- `handler: RouteHandler` — `(c: Context, route: RouteContext) => RouteResult | Promise<RouteResult>`, a result the framework answers with (§Handlers and results)
|
|
54
54
|
- `description` — free-text, surfaced in `AppSurface`
|
|
55
|
-
- `params?:
|
|
56
|
-
- `query?:
|
|
57
|
-
- `input:
|
|
58
|
-
- `output:
|
|
55
|
+
- `params?: AnySchema` — strict-object schema for URL path params
|
|
56
|
+
- `query?: AnySchema` — strict-object schema for URL query string
|
|
57
|
+
- `input: AnySchema` — request body schema; `literal(null)` for no-body (GET/DELETE)
|
|
58
|
+
- `output: AnySchema` — success response schema
|
|
59
59
|
- `mints_credential?: boolean` — the route issues a session cookie while declaring no auth (login, signup, bootstrap); assembly refuses it outside `AUTH_MIDDLEWARE_PATH`, as it does any route whose `auth.account` is not `'none'` (`assert_credential_routes_in_auth_scope` in `auth/middleware.ts`)
|
|
60
60
|
- `reads_credential?: boolean` — the handler reads the resolved account while the route declares no auth gate, answering an anonymous caller itself (account status, the cell-scoped fact read, `create_rpc_endpoint`'s pair, whose dispatcher gates per action); held inside `AUTH_MIDDLEWARE_PATH` by the same assertion. Such a handler reads the account through `get_public_account_id` (`auth/request_context.ts`), which answers a scope-narrowed token as anonymous — the RPC pair excepted, its dispatcher gating each method
|
|
61
61
|
- `rate_limit?: RateLimitKey` — metadata only (`'ip' | 'account' | 'both'`); auto-derives 429
|
|
@@ -63,20 +63,18 @@ consumers.
|
|
|
63
63
|
- `jsonrpc?: boolean` — the route answers JSON-RPC envelopes, not REST bodies; set by `create_rpc_endpoint`, read by the DEV error check and `assert_response_matches_spec`
|
|
64
64
|
- `transaction?: boolean` — declarative transaction wrapping (see below)
|
|
65
65
|
|
|
66
|
-
Every schema field takes a
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
holding a value of neither library throws at registration, naming the route
|
|
66
|
+
Every schema field takes a `@fuzdev/fuz_schema` schema (`AnySchema`),
|
|
67
|
+
validated through `parse`, its refusals answered with `to_wire_issues`'s
|
|
68
|
+
`WireIssue`s. A slot holding a value that is no schema throws at registration, naming the route
|
|
70
69
|
and the slot (`assert_validation_schema`) — in an assembled app, surface
|
|
71
70
|
generation (`schema_to_surface`) reads most slots first and throws the same
|
|
72
71
|
refusal; `params`, `query` and an `errors` entry
|
|
73
|
-
may be absent. A
|
|
72
|
+
may be absent. A `params` or `query` must be an object schema
|
|
74
73
|
under any wrappers (`get_schema_entries`); `apply_route_specs` throws naming
|
|
75
74
|
the route on one that isn't. Input/output naming mirrors SAES `ActionSpec`. Use a strict object for
|
|
76
|
-
inputs —
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
`loose_object`); the warning names the library's strict form.
|
|
75
|
+
inputs — fuz_schema's `object` — the surface diagnostic warns on non-strict
|
|
76
|
+
objects because unknown keys are silently stripped by `strip_object` and
|
|
77
|
+
kept by `loose_object`.
|
|
80
78
|
|
|
81
79
|
### Handlers and results
|
|
82
80
|
|
|
@@ -164,7 +162,7 @@ wrapper). See `auth/signup_routes.ts`.
|
|
|
164
162
|
3. **Pre-authorization auth guards** — every gate that reads only what the auth middleware set, in coarse-to-fine order: `require_auth` (401 `ERROR_AUTHENTICATION_REQUIRED`) when `auth.account === 'required'` or `auth.actor === 'required'`; `require_credential_types(types)` (403 `ERROR_CREDENTIAL_TYPE_REQUIRED` with `required_credential_types: ReadonlyArray<string>`) when `auth.credential_types?.length`; `require_token_scope(capability)` (403 `ERROR_TOKEN_SCOPE_REQUIRED` with `required_scope`, the token-scope refusal) when `auth.required_scope` names a capability. All fire before any body parsing — so a caller they refuse never sees route-shape information from input parse failures — and before actor resolution, so a wrong channel costs no DB work and never learns account state (e.g. that the account is multi-actor). The `AuthGuardResolver` (e.g. `fuz_auth_guard_resolver` from `auth/auth_guard_resolver.ts`) returns this set as `pre_authorization: Array<MiddlewareHandler>`.
|
|
165
163
|
4. **Authorization phase** — when `spec.auth.actor !== 'none'`, resolves the acting actor against the resolved credential's account (`get_resolved_auth`, set by the auth middleware) plus the `acting` selector (`validated_query.acting` on GETs; read off the raw body on mutations, since body validation now runs after the gates), builds `RequestContext` via `build_request_context`, and sets `REQUEST_CONTEXT_KEY`. When `auth.account !== 'none' && auth.actor === 'none'`, an account-only context is built. Resolution failures return 400 `ERROR_ACTOR_REQUIRED` (with `available[]`) or `ERROR_ACTOR_NOT_ON_ACCOUNT` (or 500 `ERROR_NO_ACTORS_ON_ACCOUNT` on signup-invariant violation, 500 `ERROR_ACCOUNT_VANISHED` on torn account/actor reads after a successful resolve). Public routes (`account: 'none' && actor: 'none'`) skip this phase entirely.
|
|
166
164
|
5. **Post-authorization auth guards** — `require_role(roles)` (403 `ERROR_INSUFFICIENT_PERMISSIONS` with `required_roles: ReadonlyArray<string>`) when `auth.roles?.length`. The only gate in this phase, because it is the only one that reads `REQUEST_CONTEXT_KEY` (populated by step 4) rather than the auth middleware's own context vars. Multi-role specs admit any-of via `has_any_scoped_role(ctx, roles, null)`.
|
|
167
|
-
6. **Input validation** — JSON body parsed + validated; mismatch returns 400 `ERROR_INVALID_JSON_BODY` (not JSON) or `ERROR_INVALID_REQUEST_BODY` (schema failure with `issues`). Every schema refusal's `issues` are `WireIssue`s (`to_wire_issues`, `schema_issues.ts`), sent under DEV only (`dev_only`). Skipped on GET and on a null input (`is_null_schema`: `
|
|
165
|
+
6. **Input validation** — JSON body parsed + validated; mismatch returns 400 `ERROR_INVALID_JSON_BODY` (not JSON) or `ERROR_INVALID_REQUEST_BODY` (schema failure with `issues`). Every schema refusal's `issues` are `WireIssue`s (`to_wire_issues`, `schema_issues.ts`), sent under DEV only (`dev_only`). Skipped on GET and on a null input (`is_null_schema`: `literal(null)`). The validated input lands on `c.var.validated_input`.
|
|
168
166
|
7. **Handler** — wrapped in transaction when `use_transaction` (see above), receives `RouteContext`; its result becomes the response (`to_route_response`)
|
|
169
167
|
8. **Error catch** — catches a thrown JSON-RPC error (`ThrownJsonrpcError`, recognized by brand through `to_thrown_jsonrpc_error`, so one from a second fuz_app copy maps too; a foreign error class carrying a JSON-RPC `code` falls to the generic path) → maps to HTTP status + the flat REST error body (`{error: <reason>, message?, ...rest_data}`); catches generic `Error` → 500 `{error: 'internal_error', message?}` (message only in DEV). The reason string comes from `err.data.reason` when set (consumer-supplied canonical reason override) or from `jsonrpc_error_code_to_name(err.code)` (e.g. `-32003 → 'not_found'`). The flat shape matches what middleware and direct handlers emit — REST callers see one envelope across every emit site, while the JSON-RPC dispatcher keeps its own `{jsonrpc, id, error: {code, message, data}}` envelope on the RPC mount.
|
|
170
168
|
9. **DEV-only output validation** — a 2xx JSON body against `spec.output` (see below); error responses are the outer DEV error check's
|
|
@@ -184,8 +182,7 @@ Duplicate `method path` pairs throw at registration.
|
|
|
184
182
|
|
|
185
183
|
Validated values are accessed via `get_route_input(c, schema)`,
|
|
186
184
|
`get_route_params(c, schema)`, `get_route_query(c, schema)` — pass the
|
|
187
|
-
matching schema,
|
|
188
|
-
`ValidationOutput<typeof schema>`.
|
|
185
|
+
matching schema, and the return type infers as `Infer<typeof schema>`.
|
|
189
186
|
Each helper has a `<T>(c)` overload (no schema arg) for callers without the
|
|
190
187
|
schema in scope.
|
|
191
188
|
|
|
@@ -224,8 +221,8 @@ action-handler surfaces (REST, RPC, WS); see ../../../docs/architecture.md
|
|
|
224
221
|
- `RateLimitKey` (`rate_limiter.ts`) — `'ip' | 'account' | 'both'`
|
|
225
222
|
|
|
226
223
|
`RouteSpec.errors` and `MiddlewareSpec.errors` are lists of definitions
|
|
227
|
-
(`ReadonlyArray<RestErrorDef>`), so a
|
|
228
|
-
|
|
224
|
+
(`ReadonlyArray<RestErrorDef>`), so a bare schema is impossible by type, and
|
|
225
|
+
`apply_route_specs` refuses anything else at registration.
|
|
229
226
|
|
|
230
227
|
All error bodies are loose objects — intentional because multiple
|
|
231
228
|
producers (middleware + handler) can emit different extra fields at the
|
|
@@ -287,8 +284,8 @@ beside them.
|
|
|
287
284
|
|
|
288
285
|
The same auto-derivation pattern is **not** appropriate for
|
|
289
286
|
consumer-authored inputs (or handler outputs). A consumer's spec declares
|
|
290
|
-
the exact `acting?: ActingActor` slot (
|
|
291
|
-
|
|
287
|
+
the exact `acting?: ActingActor` slot (`ActingActor` of `primitive_schemas.ts`),
|
|
288
|
+
and the framework
|
|
292
289
|
reads it back via reference-equality to drive the authorization phase — auto-extending
|
|
293
290
|
schemas at registration time would obscure the source of truth ("did the
|
|
294
291
|
spec declare this, or did the framework graft it on?") and quietly shadow
|
|
@@ -311,7 +308,7 @@ confirmation.
|
|
|
311
308
|
|
|
312
309
|
## Schema Helpers
|
|
313
310
|
|
|
314
|
-
`http/schema_helpers.ts` is the canonical home for shared schema introspection
|
|
311
|
+
`http/schema_helpers.ts` is the canonical home for shared schema introspection
|
|
315
312
|
— extracted to break a circular dependency between `http/route_spec.ts`
|
|
316
313
|
(input validation) and `http/surface.ts` (surface generation).
|
|
317
314
|
|
|
@@ -322,14 +319,15 @@ generation logic.
|
|
|
322
319
|
|
|
323
320
|
Key helpers:
|
|
324
321
|
|
|
325
|
-
- `is_null_schema(schema)` —
|
|
326
|
-
- `is_void_schema(schema)` —
|
|
322
|
+
- `is_null_schema(schema)` — a `literal(null)` (a kind check, not parse-null, to avoid false positives from `nullable(string)`)
|
|
323
|
+
- `is_void_schema(schema)` — a `literal(undefined)` (what `s.void` is, a `meta` copy included; a kind check like `is_null_schema`, so an optional schema is not void); a void input declares a parameterless RPC method
|
|
327
324
|
- `to_void_params(raw_params)` — reads absent, `null`, and `{}` params of a void input as the no-arg call (`undefined`), passing any other shape through for the void schema to refuse — the twin of the Rust spine's `require_void_params`
|
|
328
|
-
- `to_input_params(input, raw_params)` — the one params normalizer every receiving end runs before the input parse (`
|
|
325
|
+
- `to_input_params(input, raw_params)` — the one params normalizer every receiving end runs before the input parse (`parse`): `to_void_params` for a void input, else absent/`null` → `{}`; used by both the server dispatch core (`perform_action`) and the peer receive path (`ActionDispatcher`)
|
|
329
326
|
- `json_has_own_proto_key(value)` — whether any object in a parsed JSON value has an own `__proto__` key, by an iterative walk (no recursion — `JSON.parse` nests deeper than the call stack); the dispatcher refuses such params with `ERROR_PARAMS_PROTO_KEY`. Twin of the Rust `fuz_http::json_has_own_proto_key`
|
|
330
|
-
- `safe_parse_dropping_unknown_keys(schema, value)` — the forward-compatible read of a remote-authored payload,
|
|
331
|
-
- `is_strict_object_schema(schema)` — detects
|
|
332
|
-
- `schema_to_surface(schema, {io?, source?, on_unrepresentable?}?)` — throws first on a value
|
|
327
|
+
- `safe_parse_dropping_unknown_keys(schema, value)` — the forward-compatible read of a remote-authored payload, returning `parse`'s `{ok, value}` / `{ok: false, issues}`: while every issue is an unknown key (`unknown_key_targets`), strips them from a copy and reparses — after the first parse that reports unknown keys, one schema-guided pass deletes every key a strict `object` doesn't name anywhere the schema reaches (entries, array items, record values, the `variant` option), as a parse reports at most a hundred issues; a key under a `union` is never stripped (the union fails as one issue of its own), and a later `pipe` stage is stripped only as reported — until nothing is left to strip, capped at `UNKNOWN_KEY_PASSES_MAX` passes (the last failure returned past it); any other issue still fails. Used for response `result`s (`ActionEvent`) and peer replies (`peer/ping`); matches serde's ignore-unknown-fields default on the Rust spine
|
|
328
|
+
- `is_strict_object_schema(schema)` — detects an `object` (not `strip_object` / `loose_object`); a `pipe` is read through to its first schema when no stage is a `transform` (so a refined `object` reads strict)
|
|
329
|
+
- `schema_to_surface(schema, {io?, source?, on_unrepresentable?}?)` — throws first on a value that is no schema (`assert_validation_schema`, naming `source`, so an assembled app's slot holding none fails boot as registration would refuse it, not as an unwritable JSON Schema); a schema → JSON Schema (`to_json_schema`), on the side `io` names (`'output'` by default), with `$schema` and `default` keys stripped recursively (defaults may be non-deterministic; `$schema` is snapshot noise). `null` for a null or void schema. A part JSON Schema can't say (an output-side transform, a `check`) is left out or written as `{}` (`unrepresentable: 'any'`) and reported to `on_unrepresentable`; a schema with nothing describable (`{}` from a schema other than `unknown`) or one the emitter refuses outright throws, prefixed with `source` — so a root-level transform output fails server assembly. It never answers `null` for a failure, which would read as "no input" and drop the schema from every suite that reads the surface
|
|
330
|
+
- `SchemaFieldInfo` — one field of an object schema (`name`, `base_type`, `required`, `has_default`, `nullable`), what the testing generators' `to_object_schema_view` produces
|
|
333
331
|
- `middleware_applies(mw_path, route_path)` — Hono pattern matching: `'*'`, exact, `'/api/*'` prefix (handles `prefix.slice(0, -1)` so `/api/*` also matches the bare `/api`)
|
|
334
332
|
- `middleware_carves_out(spec, route_path)` — one of the layer's `carve_outs` applies to the route; the carve-out half of `middleware_spec_applies`, which `assert_full_middleware_stack` reads to relax a carved-out route's expected stack
|
|
335
333
|
- `middleware_spec_applies(spec, route_path)` — the layer runs on the route: its `path` applies and none of its `carve_outs` does; what the route error map takes middleware definitions by
|
|
@@ -352,7 +350,7 @@ policy invariants.
|
|
|
352
350
|
|
|
353
351
|
`generate_app_surface(options)` emits a `warning` diagnostic for every
|
|
354
352
|
input schema that's not strict (unknown keys silently strip under
|
|
355
|
-
`
|
|
353
|
+
`strip_object`), writes every schema through `schema_to_surface` — inputs,
|
|
356
354
|
params and query on the input side (what the server accepts, so a
|
|
357
355
|
`Username` transform keeps its bounds and pattern), outputs, error bodies and
|
|
358
356
|
event params on the output side — with an `info` diagnostic (category
|
|
@@ -524,7 +522,7 @@ own by casting `as JsonrpcErrorCode`, and declare each one's HTTP status with
|
|
|
524
522
|
- `request_cancelled` (-32010, HTTP 499) — caller-initiated cancellation (nginx "client closed").
|
|
525
523
|
|
|
526
524
|
**`invalid_params` vs `validation_error`** — use `invalid_params` (standard
|
|
527
|
-
code) for
|
|
525
|
+
code) for schema parse failures; reserve `validation_error` (app code) for
|
|
528
526
|
business rules.
|
|
529
527
|
|
|
530
528
|
**`rate_limited` vs `queue_overflow`** — both 429; reverse map
|
|
@@ -630,7 +628,7 @@ must run only after the transaction commits.
|
|
|
630
628
|
- Structurally satisfied by both `RouteContext` (HTTP) and `ActionContext` (RPC + WS) — they share the `{log, post_commit_effects}` shape, which is why this helper lives in `http/` rather than `actions/` or `auth/`.
|
|
631
629
|
|
|
632
630
|
WS sends are **not** wrapped by `create_validated_broadcaster` (that only
|
|
633
|
-
guards SSE `broadcast(channel, data)`).
|
|
631
|
+
guards SSE `broadcast(channel, data)`). The input schemas of
|
|
634
632
|
`RemoteNotificationActionSpec`s are contracts for consumers, not enforced
|
|
635
633
|
at send time.
|
|
636
634
|
|
|
@@ -663,7 +661,7 @@ table browser; the factory is domain-agnostic.
|
|
|
663
661
|
|
|
664
662
|
Every route declares `acting?: ActingActor` on its `query` (registry-time
|
|
665
663
|
invariant 2). The routes' schemas are `@fuzdev/fuz_schema`: the queries
|
|
666
|
-
`object`s over
|
|
664
|
+
`object`s over `ActingActor`, and the counts and positions they
|
|
667
665
|
answer with (`row_count`, `total`, `offset`, `limit`) non-negative integers.
|
|
668
666
|
`GET /tables/:name`'s paging params are each a `query_int`:
|
|
669
667
|
`pipe(string, regex(/^[+-]?\d+$/), transform(Number))`, then `safe_integer`
|
|
@@ -753,5 +751,5 @@ Interfaces exported for consumer use: `TableInfo`, `TableWithCount`,
|
|
|
753
751
|
|
|
754
752
|
- **Middleware ordering** is assembled by `create_app_server` — see the root ../../../CLAUDE.md §Middleware Ordering. The invariants `http/` needs consumers to uphold: trusted-proxy runs before auth/rate-limit; origin verification runs before session parsing; `client_ip` must be set before any handler or rate limiter reads it
|
|
755
753
|
- **No re-exports.** Import every symbol from its canonical source module. `http/surface.ts` no longer re-exports schema helpers — go through `http/schema_helpers.ts`
|
|
756
|
-
- **Input/output schemas align with SAES.** When wiring RPC via `actions/action_rpc.ts`, the same
|
|
754
|
+
- **Input/output schemas align with SAES.** When wiring RPC via `actions/action_rpc.ts`, the same schemas flow through unchanged (see `actions/CLAUDE.md` §Single JSON-RPC 2.0 endpoint)
|
|
757
755
|
- **Error modules are complementary, not redundant.** `http/error_schemas.ts` is declaration-first (for routes and surface); `http/jsonrpc_errors.ts` is throw-first (for handlers and the catch layer). A single `ERROR_*` code can be raised either way depending on whether the handler needs to also attach diagnostic fields
|
|
@@ -33,34 +33,7 @@
|
|
|
33
33
|
*
|
|
34
34
|
* @module
|
|
35
35
|
*/
|
|
36
|
-
import {
|
|
37
|
-
import { type Infer } from '@fuzdev/fuz_schema/schema.ts';
|
|
38
|
-
import type { ValidationSchema } from '../schema_issues.js';
|
|
39
|
-
/**
|
|
40
|
-
* `acting` field shared by every input that needs the caller's acting actor.
|
|
41
|
-
* Declaring `acting: ActingActor` on a route or action input signals to the
|
|
42
|
-
* dispatcher's authorization phase to resolve an actor against the
|
|
43
|
-
* authenticated account: it runs `resolve_acting_actor`, builds the
|
|
44
|
-
* actor-bound `RequestContext`, and loads role_grants before auth guards fire.
|
|
45
|
-
*
|
|
46
|
-
* Resolution rules: omitted + 1 actor → use it; omitted + multiple actors →
|
|
47
|
-
* `actor_required` with the available list; supplied + on the account → use
|
|
48
|
-
* it; supplied + foreign actor → `actor_not_on_account`.
|
|
49
|
-
*
|
|
50
|
-
* Account-grain routes — input doesn't declare `acting` and auth doesn't
|
|
51
|
-
* require role_grants — skip resolution entirely; their `RequestContext.actor`
|
|
52
|
-
* is `null` and the audit envelope's `actor_id` stays null.
|
|
53
|
-
*
|
|
54
|
-
* Lives next to `RouteAuth` because the two are paired by registry-time
|
|
55
|
-
* invariant 2: `auth.actor !== 'none'` ⟺ input (or query, on REST GETs)
|
|
56
|
-
* declares `acting?: ActingActor`. Keeping the contract in one module
|
|
57
|
-
* removes the http/ → auth/ import that an earlier split forced.
|
|
58
|
-
*
|
|
59
|
-
* A fuz_schema input declares the twin in `primitive_schemas_fuz.ts`, which
|
|
60
|
-
* the dispatcher finds the same way.
|
|
61
|
-
*/
|
|
62
|
-
export declare const ActingActor: z.ZodOptional<z.ZodUUID & z.ZodType<import("@fuzdev/fuz_schema/schema.ts").Branded<string, "Uuid">, string, z.core.$ZodTypeInternals<import("@fuzdev/fuz_schema/schema.ts").Branded<string, "Uuid">, string>>>;
|
|
63
|
-
export type ActingActor = z.infer<typeof ActingActor>;
|
|
36
|
+
import { type AnySchema, type Infer } from '@fuzdev/fuz_schema/schema.ts';
|
|
64
37
|
/**
|
|
65
38
|
* Read an `acting` selector out of an unvalidated value.
|
|
66
39
|
*
|
|
@@ -81,11 +54,11 @@ export type ActingActor = z.infer<typeof ActingActor>;
|
|
|
81
54
|
* an input schema behind it, so there a malformed selector is final (the
|
|
82
55
|
* status route answers account-only).
|
|
83
56
|
*
|
|
84
|
-
* The grammar is
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
57
|
+
* The grammar is `ActingActor`'s, which is the Rust spine's, so every value
|
|
58
|
+
* reads as either would, the max UUID in any case
|
|
59
|
+
* included. The id comes back lowercased. A route declaring `acting` on its
|
|
60
|
+
* `query` schema doesn't read it here: that schema runs ahead of the
|
|
61
|
+
* authorization phase, with the same grammar.
|
|
89
62
|
*
|
|
90
63
|
* @param value - the raw `acting` field, from params / query / body
|
|
91
64
|
* @returns the actor id, or `undefined` when absent or malformed
|
|
@@ -231,24 +204,16 @@ export declare const is_plain_authenticated_auth: (auth: RouteAuth) => boolean;
|
|
|
231
204
|
export declare const assert_route_auth_invariants: (auth: RouteAuth, context: string) => void;
|
|
232
205
|
/**
|
|
233
206
|
* Whether a schema declares the canonical `acting?: ActingActor` field.
|
|
234
|
-
* Reference-equality on the exported `ActingActor`
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
* authored as `z.optional(z.strictObject({acting: ActingActor}))` or
|
|
243
|
-
* `z.strictObject({acting: ActingActor}).default({})` still trips the
|
|
244
|
-
* predicate.
|
|
245
|
-
*
|
|
246
|
-
* A `@fuzdev/fuz_schema` schema is read by `get_schema_entries`, which sees
|
|
247
|
-
* through its wrappers (`optional`, `nullable`, the defaults) and a `pipe` to
|
|
248
|
-
* the schema it starts with; a schema that isn't an object under them (a void
|
|
249
|
-
* input, say) answers `false`.
|
|
207
|
+
* Reference-equality on the exported `ActingActor` (`primitive_schemas.ts`),
|
|
208
|
+
* so consumer schemas with unrelated `acting` fields don't trip this check.
|
|
209
|
+
*
|
|
210
|
+
* The schema is read by `get_schema_entries`, which sees through its wrappers
|
|
211
|
+
* (`optional`, `nullable`, the defaults) and a `pipe` to the schema it starts
|
|
212
|
+
* with, so `optional(object({acting: ActingActor}))` still trips the
|
|
213
|
+
* predicate; a schema that isn't an object under them (a void input, say)
|
|
214
|
+
* answers `false`.
|
|
250
215
|
*/
|
|
251
|
-
export declare const input_schema_declares_acting: (schema:
|
|
216
|
+
export declare const input_schema_declares_acting: (schema: AnySchema) => boolean;
|
|
252
217
|
/**
|
|
253
218
|
* Slots where a spec may declare the `acting?: ActingActor` field —
|
|
254
219
|
* input for both REST + actions; query for REST GETs that bi-locate
|
|
@@ -256,8 +221,8 @@ export declare const input_schema_declares_acting: (schema: ValidationSchema) =>
|
|
|
256
221
|
* field is omitted on action call sites).
|
|
257
222
|
*/
|
|
258
223
|
export interface ActingSlots {
|
|
259
|
-
input:
|
|
260
|
-
query?:
|
|
224
|
+
input: AnySchema;
|
|
225
|
+
query?: AnySchema;
|
|
261
226
|
}
|
|
262
227
|
/**
|
|
263
228
|
* Registry-time biconditional check: `auth.actor !== 'none' ⟺ some
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth_shape.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/auth_shape.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"auth_shape.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/auth_shape.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EAAiB,KAAK,SAAS,EAAE,KAAK,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAKzF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,OAAO,KAAG,MAAM,GAAG,SAGtD,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,aAAa,wKAA2C,CAAC;AACtE,MAAM,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAuDxD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,WAAW,SAAS;IACzB,OAAO,EAAE,aAAa,CAAC;IACvB,KAAK,EAAE,aAAa,CAAC;IACrB,KAAK,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IAC1C,gBAAgB,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IACrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IACH,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACpC;AAUD;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,MAAM,SAAS,KAAG,OACA,CAAC;AAElD;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,SAAS,KAAG,OAAgC,CAAC;AAE/E,wEAAwE;AACxE,eAAO,MAAM,YAAY,GAAI,MAAM,SAAS,KAAG,OAA+B,CAAC;AAE/E,8FAA8F;AAC9F,eAAO,MAAM,wBAAwB,GAAI,MAAM,SAAS,KAAG,OAC3B,CAAC;AAEjC;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,cAAc,GAAI,MAAM,SAAS,KAAG,OACQ,CAAC;AAE1D;;;;;;;;;;GAUG;AACH,eAAO,MAAM,2BAA2B,GAAI,MAAM,SAAS,KAAG,OACwB,CAAC;AAEvF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,4BAA4B,GAAI,MAAM,SAAS,EAAE,SAAS,MAAM,KAAG,IAM/E,CAAC;AAYF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,4BAA4B,GAAI,QAAQ,SAAS,KAAG,OACd,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC3B,KAAK,EAAE,SAAS,CAAC;IACjB,KAAK,CAAC,EAAE,SAAS,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,sCAAsC,GAClD,MAAM,SAAS,EACf,OAAO,WAAW,EAClB,SAAS,MAAM,KACb,IAmBF,CAAC"}
|
package/dist/http/auth_shape.js
CHANGED
|
@@ -33,36 +33,9 @@
|
|
|
33
33
|
*
|
|
34
34
|
* @module
|
|
35
35
|
*/
|
|
36
|
-
import {
|
|
37
|
-
import { is_schema, one_of, parse } from '@fuzdev/fuz_schema/schema.ts';
|
|
36
|
+
import { one_of, parse } from '@fuzdev/fuz_schema/schema.ts';
|
|
38
37
|
import { get_schema_entries } from '@fuzdev/fuz_schema/introspect.ts';
|
|
39
|
-
import {
|
|
40
|
-
import { ACTING_ACTOR_DESCRIPTION, ActingActor as ActingActorFuz } from '../primitive_schemas_fuz.js';
|
|
41
|
-
import { zod_unwrap_to_object } from '../zod.js';
|
|
42
|
-
/**
|
|
43
|
-
* `acting` field shared by every input that needs the caller's acting actor.
|
|
44
|
-
* Declaring `acting: ActingActor` on a route or action input signals to the
|
|
45
|
-
* dispatcher's authorization phase to resolve an actor against the
|
|
46
|
-
* authenticated account: it runs `resolve_acting_actor`, builds the
|
|
47
|
-
* actor-bound `RequestContext`, and loads role_grants before auth guards fire.
|
|
48
|
-
*
|
|
49
|
-
* Resolution rules: omitted + 1 actor → use it; omitted + multiple actors →
|
|
50
|
-
* `actor_required` with the available list; supplied + on the account → use
|
|
51
|
-
* it; supplied + foreign actor → `actor_not_on_account`.
|
|
52
|
-
*
|
|
53
|
-
* Account-grain routes — input doesn't declare `acting` and auth doesn't
|
|
54
|
-
* require role_grants — skip resolution entirely; their `RequestContext.actor`
|
|
55
|
-
* is `null` and the audit envelope's `actor_id` stays null.
|
|
56
|
-
*
|
|
57
|
-
* Lives next to `RouteAuth` because the two are paired by registry-time
|
|
58
|
-
* invariant 2: `auth.actor !== 'none'` ⟺ input (or query, on REST GETs)
|
|
59
|
-
* declares `acting?: ActingActor`. Keeping the contract in one module
|
|
60
|
-
* removes the http/ → auth/ import that an earlier split forced.
|
|
61
|
-
*
|
|
62
|
-
* A fuz_schema input declares the twin in `primitive_schemas_fuz.ts`, which
|
|
63
|
-
* the dispatcher finds the same way.
|
|
64
|
-
*/
|
|
65
|
-
export const ActingActor = Uuid.optional().meta({ description: ACTING_ACTOR_DESCRIPTION });
|
|
38
|
+
import { ActingActor } from '../primitive_schemas.js';
|
|
66
39
|
/**
|
|
67
40
|
* Read an `acting` selector out of an unvalidated value.
|
|
68
41
|
*
|
|
@@ -83,17 +56,17 @@ export const ActingActor = Uuid.optional().meta({ description: ACTING_ACTOR_DESC
|
|
|
83
56
|
* an input schema behind it, so there a malformed selector is final (the
|
|
84
57
|
* status route answers account-only).
|
|
85
58
|
*
|
|
86
|
-
* The grammar is
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
59
|
+
* The grammar is `ActingActor`'s, which is the Rust spine's, so every value
|
|
60
|
+
* reads as either would, the max UUID in any case
|
|
61
|
+
* included. The id comes back lowercased. A route declaring `acting` on its
|
|
62
|
+
* `query` schema doesn't read it here: that schema runs ahead of the
|
|
63
|
+
* authorization phase, with the same grammar.
|
|
91
64
|
*
|
|
92
65
|
* @param value - the raw `acting` field, from params / query / body
|
|
93
66
|
* @returns the actor id, or `undefined` when absent or malformed
|
|
94
67
|
*/
|
|
95
68
|
export const parse_acting = (value) => {
|
|
96
|
-
const parsed = parse(
|
|
69
|
+
const parsed = parse(ActingActor, value);
|
|
97
70
|
return parsed.ok ? parsed.value : undefined;
|
|
98
71
|
};
|
|
99
72
|
/**
|
|
@@ -229,31 +202,16 @@ export const assert_route_auth_invariants = (auth, context) => {
|
|
|
229
202
|
// + `register_action_ws`).
|
|
230
203
|
/**
|
|
231
204
|
* Whether a schema declares the canonical `acting?: ActingActor` field.
|
|
232
|
-
* Reference-equality on the exported `ActingActor`
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
* authored as `z.optional(z.strictObject({acting: ActingActor}))` or
|
|
241
|
-
* `z.strictObject({acting: ActingActor}).default({})` still trips the
|
|
242
|
-
* predicate.
|
|
243
|
-
*
|
|
244
|
-
* A `@fuzdev/fuz_schema` schema is read by `get_schema_entries`, which sees
|
|
245
|
-
* through its wrappers (`optional`, `nullable`, the defaults) and a `pipe` to
|
|
246
|
-
* the schema it starts with; a schema that isn't an object under them (a void
|
|
247
|
-
* input, say) answers `false`.
|
|
205
|
+
* Reference-equality on the exported `ActingActor` (`primitive_schemas.ts`),
|
|
206
|
+
* so consumer schemas with unrelated `acting` fields don't trip this check.
|
|
207
|
+
*
|
|
208
|
+
* The schema is read by `get_schema_entries`, which sees through its wrappers
|
|
209
|
+
* (`optional`, `nullable`, the defaults) and a `pipe` to the schema it starts
|
|
210
|
+
* with, so `optional(object({acting: ActingActor}))` still trips the
|
|
211
|
+
* predicate; a schema that isn't an object under them (a void input, say)
|
|
212
|
+
* answers `false`.
|
|
248
213
|
*/
|
|
249
|
-
export const input_schema_declares_acting = (schema) =>
|
|
250
|
-
if (is_schema(schema))
|
|
251
|
-
return get_schema_entries(schema)?.acting === ActingActorFuz;
|
|
252
|
-
const obj = zod_unwrap_to_object(schema);
|
|
253
|
-
if (!obj)
|
|
254
|
-
return false;
|
|
255
|
-
return obj.shape.acting === ActingActor;
|
|
256
|
-
};
|
|
214
|
+
export const input_schema_declares_acting = (schema) => get_schema_entries(schema)?.acting === ActingActor;
|
|
257
215
|
/**
|
|
258
216
|
* Registry-time biconditional check: `auth.actor !== 'none' ⟺ some
|
|
259
217
|
* supplied slot declares acting?: ActingActor`. Throws on violation.
|
|
@@ -281,7 +239,7 @@ export const assert_route_auth_acting_biconditional = (auth, slots, context) =>
|
|
|
281
239
|
return;
|
|
282
240
|
const slot_phrase = slots.query !== undefined ? 'input or query schema' : 'input schema';
|
|
283
241
|
if (wants_actor) {
|
|
284
|
-
throw new Error(`${context}: auth.actor === '${auth.actor}' requires the ${slot_phrase} to declare 'acting?: ActingActor'
|
|
242
|
+
throw new Error(`${context}: auth.actor === '${auth.actor}' requires the ${slot_phrase} to declare 'acting?: ActingActor' (registry-time invariant 2)`);
|
|
285
243
|
}
|
|
286
|
-
throw new Error(`${context}: ${slot_phrase} declares 'acting?: ActingActor'
|
|
244
|
+
throw new Error(`${context}: ${slot_phrase} declares 'acting?: ActingActor' but auth.actor === 'none' (registry-time invariant 2)`);
|
|
287
245
|
};
|
package/dist/http/db_routes.d.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* @module
|
|
11
11
|
*/
|
|
12
12
|
import type { Logger } from '@fuzdev/fuz_util/log.ts';
|
|
13
|
-
import type
|
|
13
|
+
import { type Uuid } from '../primitive_schemas.js';
|
|
14
14
|
import type { Db, DbType } from '../db/db.js';
|
|
15
15
|
import { type RouteSpec } from './route_spec.js';
|
|
16
16
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db_routes.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/db_routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAsBtD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"db_routes.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/db_routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAsBtD,OAAO,EAAe,KAAK,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAEjE,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAmD,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAelG;;GAEG;AACH,MAAM,WAAW,SAAS;IACzB,UAAU,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,WAAW,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACpB;AAwCD,sDAAsD;AACtD,eAAO,MAAM,2BAA2B,MAAM,CAAC;AAC/C,sDAAsD;AACtD,eAAO,MAAM,uBAAuB,OAAO,CAAC;AAE5C;;;;;;GAMG;AACH,eAAO,MAAM,6BAA6B,OAAO,CAAC;AAElD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,oBAAoB,EAAE,aAAa,CAAC,MAAM,CAKrD,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,oBAAoB,EAAE,aAAa,CAAC,MAAM,CAKrD,CAAC;AAEH;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC3B;;;;;;OAMG;IACH,KAAK,EAAE;QACN,SAAS,EAAE,CAAC,KAAK,EAAE;YAClB,UAAU,EAAE,qBAAqB,CAAC;YAClC,UAAU,EAAE,IAAI,GAAG,IAAI,CAAC;YACxB,EAAE,EAAE,MAAM,CAAC;YACX,QAAQ,EAAE;gBAAE,KAAK,EAAE,MAAM,CAAC;gBAAC,SAAS,EAAE,MAAM,CAAC;gBAAC,EAAE,EAAE,MAAM,CAAA;aAAE,CAAC;SAC3D,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;KACpB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;;;OAOG;IACH,gBAAgB,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACxC,8EAA8E;IAC9E,WAAW,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC3D,+EAA+E;IAC/E,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,oBAAoB,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CAC7C;AA2CD;;GAEG;AACH,eAAO,MAAM,qBAAqB,GACjC,MAAM,WAAW,EACjB,SAAS,cAAc,KACrB,KAAK,CAAC,SAAS,CA8VjB,CAAC"}
|
package/dist/http/db_routes.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { meta } from '@fuzdev/fuz_schema/meta.ts';
|
|
13
13
|
import { array, boolean, integer, literal, loose_object, max_value, min_value, nullable, number, object, pipe, record, regex, safe_integer, string, transform, unknown, with_default } from '@fuzdev/fuz_schema/schema.ts';
|
|
14
|
-
import { ActingActor } from '../
|
|
14
|
+
import { ActingActor } from '../primitive_schemas.js';
|
|
15
15
|
import { define_route, get_route_params, get_route_query } from './route_spec.js';
|
|
16
16
|
import { route_fail, route_ok } from './route_result.js';
|
|
17
17
|
import { REST_DATABASE_CONNECTION_FAILED, REST_FOREIGN_KEY_VIOLATION, REST_ROW_NOT_FOUND, REST_TABLE_NO_PRIMARY_KEY, REST_TABLE_NOT_DELETABLE, REST_TABLE_NOT_FOUND } from './error_schemas.js';
|
|
@@ -279,41 +279,41 @@ export declare const dedupe_rest_errors: (defs: Iterable<RestErrorDef>) => Array
|
|
|
279
279
|
export declare const to_error_schemas: (defs: Iterable<RestErrorDef>) => ErrorSchemas;
|
|
280
280
|
export declare const REST_INVALID_REQUEST_BODY: RestErrorDef<400, "invalid_request_body", {
|
|
281
281
|
readonly issues: Schema<({
|
|
282
|
-
|
|
282
|
+
kind: string;
|
|
283
283
|
path: (string | number)[];
|
|
284
284
|
expected: string;
|
|
285
|
-
kind: string;
|
|
286
285
|
received: string;
|
|
287
|
-
} & Record<string, unknown>)[] | undefined, ({
|
|
288
286
|
message: string;
|
|
287
|
+
} & Record<string, unknown>)[] | undefined, ({
|
|
288
|
+
kind: string;
|
|
289
289
|
path: (string | number)[];
|
|
290
290
|
expected: string;
|
|
291
|
-
kind: string;
|
|
292
291
|
received: string;
|
|
293
|
-
} & Record<string, unknown>)[] | undefined, "optional", import("@fuzdev/fuz_schema/schema.ts").SchemaWrapperDef<Schema<({
|
|
294
292
|
message: string;
|
|
293
|
+
} & Record<string, unknown>)[] | undefined, "optional", import("@fuzdev/fuz_schema/schema.ts").SchemaWrapperDef<Schema<({
|
|
294
|
+
kind: string;
|
|
295
295
|
path: (string | number)[];
|
|
296
296
|
expected: string;
|
|
297
|
-
kind: string;
|
|
298
297
|
received: string;
|
|
299
|
-
} & Record<string, unknown>)[], ({
|
|
300
298
|
message: string;
|
|
299
|
+
} & Record<string, unknown>)[], ({
|
|
300
|
+
kind: string;
|
|
301
301
|
path: (string | number)[];
|
|
302
302
|
expected: string;
|
|
303
|
-
kind: string;
|
|
304
303
|
received: string;
|
|
305
|
-
} & Record<string, unknown>)[], "array", Schema<{
|
|
306
304
|
message: string;
|
|
305
|
+
} & Record<string, unknown>)[], "array", Schema<{
|
|
306
|
+
kind: string;
|
|
307
307
|
path: (string | number)[];
|
|
308
308
|
expected: string;
|
|
309
|
-
kind: string;
|
|
310
309
|
received: string;
|
|
311
|
-
} & Record<string, unknown>, {
|
|
312
310
|
message: string;
|
|
311
|
+
} & Record<string, unknown>, {
|
|
312
|
+
kind: string;
|
|
313
313
|
path: (string | number)[];
|
|
314
314
|
expected: string;
|
|
315
|
-
kind: string;
|
|
316
315
|
received: string;
|
|
316
|
+
message: string;
|
|
317
317
|
} & Record<string, unknown>, "loose_object", {
|
|
318
318
|
kind: Schema<string, string, "string", undefined>;
|
|
319
319
|
path: Schema<(string | number)[], (string | number)[], "array", Schema<string | number, string | number, "union", readonly [Schema<string, string, "string", undefined>, Schema<number, number, "number", undefined>]>>;
|
|
@@ -325,41 +325,41 @@ export declare const REST_INVALID_REQUEST_BODY: RestErrorDef<400, "invalid_reque
|
|
|
325
325
|
export declare const REST_INVALID_JSON_BODY: RestErrorDef<400, "invalid_json_body", Record<never, never>>;
|
|
326
326
|
export declare const REST_INVALID_ROUTE_PARAMS: RestErrorDef<400, "invalid_route_params", {
|
|
327
327
|
readonly issues: Schema<({
|
|
328
|
-
|
|
328
|
+
kind: string;
|
|
329
329
|
path: (string | number)[];
|
|
330
330
|
expected: string;
|
|
331
|
-
kind: string;
|
|
332
331
|
received: string;
|
|
333
|
-
} & Record<string, unknown>)[] | undefined, ({
|
|
334
332
|
message: string;
|
|
333
|
+
} & Record<string, unknown>)[] | undefined, ({
|
|
334
|
+
kind: string;
|
|
335
335
|
path: (string | number)[];
|
|
336
336
|
expected: string;
|
|
337
|
-
kind: string;
|
|
338
337
|
received: string;
|
|
339
|
-
} & Record<string, unknown>)[] | undefined, "optional", import("@fuzdev/fuz_schema/schema.ts").SchemaWrapperDef<Schema<({
|
|
340
338
|
message: string;
|
|
339
|
+
} & Record<string, unknown>)[] | undefined, "optional", import("@fuzdev/fuz_schema/schema.ts").SchemaWrapperDef<Schema<({
|
|
340
|
+
kind: string;
|
|
341
341
|
path: (string | number)[];
|
|
342
342
|
expected: string;
|
|
343
|
-
kind: string;
|
|
344
343
|
received: string;
|
|
345
|
-
} & Record<string, unknown>)[], ({
|
|
346
344
|
message: string;
|
|
345
|
+
} & Record<string, unknown>)[], ({
|
|
346
|
+
kind: string;
|
|
347
347
|
path: (string | number)[];
|
|
348
348
|
expected: string;
|
|
349
|
-
kind: string;
|
|
350
349
|
received: string;
|
|
351
|
-
} & Record<string, unknown>)[], "array", Schema<{
|
|
352
350
|
message: string;
|
|
351
|
+
} & Record<string, unknown>)[], "array", Schema<{
|
|
352
|
+
kind: string;
|
|
353
353
|
path: (string | number)[];
|
|
354
354
|
expected: string;
|
|
355
|
-
kind: string;
|
|
356
355
|
received: string;
|
|
357
|
-
} & Record<string, unknown>, {
|
|
358
356
|
message: string;
|
|
357
|
+
} & Record<string, unknown>, {
|
|
358
|
+
kind: string;
|
|
359
359
|
path: (string | number)[];
|
|
360
360
|
expected: string;
|
|
361
|
-
kind: string;
|
|
362
361
|
received: string;
|
|
362
|
+
message: string;
|
|
363
363
|
} & Record<string, unknown>, "loose_object", {
|
|
364
364
|
kind: Schema<string, string, "string", undefined>;
|
|
365
365
|
path: Schema<(string | number)[], (string | number)[], "array", Schema<string | number, string | number, "union", readonly [Schema<string, string, "string", undefined>, Schema<number, number, "number", undefined>]>>;
|
|
@@ -370,41 +370,41 @@ export declare const REST_INVALID_ROUTE_PARAMS: RestErrorDef<400, "invalid_route
|
|
|
370
370
|
}>;
|
|
371
371
|
export declare const REST_INVALID_QUERY_PARAMS: RestErrorDef<400, "invalid_query_params", {
|
|
372
372
|
readonly issues: Schema<({
|
|
373
|
-
|
|
373
|
+
kind: string;
|
|
374
374
|
path: (string | number)[];
|
|
375
375
|
expected: string;
|
|
376
|
-
kind: string;
|
|
377
376
|
received: string;
|
|
378
|
-
} & Record<string, unknown>)[] | undefined, ({
|
|
379
377
|
message: string;
|
|
378
|
+
} & Record<string, unknown>)[] | undefined, ({
|
|
379
|
+
kind: string;
|
|
380
380
|
path: (string | number)[];
|
|
381
381
|
expected: string;
|
|
382
|
-
kind: string;
|
|
383
382
|
received: string;
|
|
384
|
-
} & Record<string, unknown>)[] | undefined, "optional", import("@fuzdev/fuz_schema/schema.ts").SchemaWrapperDef<Schema<({
|
|
385
383
|
message: string;
|
|
384
|
+
} & Record<string, unknown>)[] | undefined, "optional", import("@fuzdev/fuz_schema/schema.ts").SchemaWrapperDef<Schema<({
|
|
385
|
+
kind: string;
|
|
386
386
|
path: (string | number)[];
|
|
387
387
|
expected: string;
|
|
388
|
-
kind: string;
|
|
389
388
|
received: string;
|
|
390
|
-
} & Record<string, unknown>)[], ({
|
|
391
389
|
message: string;
|
|
390
|
+
} & Record<string, unknown>)[], ({
|
|
391
|
+
kind: string;
|
|
392
392
|
path: (string | number)[];
|
|
393
393
|
expected: string;
|
|
394
|
-
kind: string;
|
|
395
394
|
received: string;
|
|
396
|
-
} & Record<string, unknown>)[], "array", Schema<{
|
|
397
395
|
message: string;
|
|
396
|
+
} & Record<string, unknown>)[], "array", Schema<{
|
|
397
|
+
kind: string;
|
|
398
398
|
path: (string | number)[];
|
|
399
399
|
expected: string;
|
|
400
|
-
kind: string;
|
|
401
400
|
received: string;
|
|
402
|
-
} & Record<string, unknown>, {
|
|
403
401
|
message: string;
|
|
402
|
+
} & Record<string, unknown>, {
|
|
403
|
+
kind: string;
|
|
404
404
|
path: (string | number)[];
|
|
405
405
|
expected: string;
|
|
406
|
-
kind: string;
|
|
407
406
|
received: string;
|
|
407
|
+
message: string;
|
|
408
408
|
} & Record<string, unknown>, "loose_object", {
|
|
409
409
|
kind: Schema<string, string, "string", undefined>;
|
|
410
410
|
path: Schema<(string | number)[], (string | number)[], "array", Schema<string | number, string | number, "union", readonly [Schema<string, string, "string", undefined>, Schema<number, number, "number", undefined>]>>;
|