@fuzdev/fuz_app 0.162.0 → 0.164.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/README.md +2 -1
- package/dist/actions/action_event_data.d.ts +1 -1
- package/dist/actions/action_rpc.d.ts.map +1 -1
- package/dist/actions/action_rpc.js +4 -0
- package/dist/actions/action_spec.d.ts +3 -3
- package/dist/actions/action_spec.d.ts.map +1 -1
- package/dist/auth/CLAUDE.md +39 -36
- package/dist/auth/account_action_specs.d.ts +441 -115
- package/dist/auth/account_action_specs.d.ts.map +1 -1
- package/dist/auth/account_action_specs.js +47 -46
- package/dist/auth/account_route_schema.d.ts +98 -62
- package/dist/auth/account_route_schema.d.ts.map +1 -1
- package/dist/auth/account_route_schema.js +45 -45
- package/dist/auth/account_routes.js +1 -1
- package/dist/auth/account_schema.d.ts +54 -27
- package/dist/auth/account_schema.d.ts.map +1 -1
- package/dist/auth/account_schema.js +16 -18
- package/dist/auth/admin_action_specs.d.ts +76 -76
- package/dist/auth/admin_action_specs.js +2 -4
- package/dist/auth/admin_actions.d.ts +4 -4
- package/dist/auth/admin_actions.d.ts.map +1 -1
- package/dist/auth/admin_actions.js +3 -3
- package/dist/auth/all_cell_actions.d.ts +3 -3
- package/dist/auth/all_cell_actions.d.ts.map +1 -1
- package/dist/auth/all_cell_actions.js +1 -1
- package/dist/auth/api_token.d.ts +4 -4
- package/dist/auth/api_token.d.ts.map +1 -1
- package/dist/auth/api_token.js +3 -3
- package/dist/auth/audit_log_route_schema.d.ts +1 -1
- package/dist/auth/audit_log_route_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_route_schema.js +4 -5
- package/dist/auth/audit_log_schema.d.ts +46 -66
- package/dist/auth/audit_log_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_schema.js +34 -30
- package/dist/auth/bootstrap_route_schema.d.ts +146 -52
- package/dist/auth/bootstrap_route_schema.d.ts.map +1 -1
- package/dist/auth/bootstrap_route_schema.js +33 -19
- package/dist/auth/cell_grant_action_specs.d.ts +1 -1
- package/dist/auth/cell_grant_action_specs.js +1 -1
- package/dist/auth/cell_grant_actions.d.ts +4 -4
- package/dist/auth/cell_grant_actions.d.ts.map +1 -1
- package/dist/auth/cell_grant_actions.js +1 -1
- package/dist/auth/credential_type_schema.d.ts +16 -29
- package/dist/auth/credential_type_schema.d.ts.map +1 -1
- package/dist/auth/credential_type_schema.js +14 -18
- package/dist/auth/daemon_token.d.ts +4 -4
- package/dist/auth/daemon_token.d.ts.map +1 -1
- package/dist/auth/daemon_token.js +3 -3
- package/dist/auth/daemon_token_middleware.d.ts +1 -1
- package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
- package/dist/auth/daemon_token_middleware.js +5 -5
- package/dist/auth/grant_path_schema.d.ts +15 -29
- package/dist/auth/grant_path_schema.d.ts.map +1 -1
- package/dist/auth/grant_path_schema.js +13 -17
- package/dist/auth/middleware.js +4 -4
- package/dist/auth/migrations.js +1 -1
- package/dist/auth/name_schema.d.ts +7 -6
- package/dist/auth/name_schema.d.ts.map +1 -1
- package/dist/auth/name_schema.js +8 -9
- package/dist/auth/password.d.ts +15 -7
- package/dist/auth/password.d.ts.map +1 -1
- package/dist/auth/password.js +16 -9
- package/dist/auth/role_grant_offer_action_specs.d.ts +2 -2
- package/dist/auth/role_grant_offer_action_specs.js +2 -2
- package/dist/auth/role_grant_offer_actions.d.ts +4 -4
- package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_actions.js +3 -3
- package/dist/auth/role_grant_offer_notifications.js +2 -2
- package/dist/auth/role_grant_offer_schema.d.ts +2 -2
- package/dist/auth/role_grant_offer_schema.js +2 -2
- package/dist/auth/role_schema.d.ts +47 -55
- package/dist/auth/role_schema.d.ts.map +1 -1
- package/dist/auth/role_schema.js +29 -35
- package/dist/auth/scope_kind_schema.d.ts +22 -26
- package/dist/auth/scope_kind_schema.d.ts.map +1 -1
- package/dist/auth/scope_kind_schema.js +19 -19
- package/dist/auth/self_service_role_action_specs.js +1 -1
- package/dist/auth/self_service_role_actions.d.ts +6 -6
- package/dist/auth/self_service_role_actions.d.ts.map +1 -1
- package/dist/auth/self_service_role_actions.js +7 -6
- package/dist/auth/signup_route_schema.d.ts +71 -21
- package/dist/auth/signup_route_schema.d.ts.map +1 -1
- package/dist/auth/signup_route_schema.js +17 -19
- package/dist/auth/standard_rpc_actions.d.ts +1 -1
- package/dist/auth/standard_rpc_actions.js +1 -1
- package/dist/auth/token_lifetime.d.ts +33 -9
- package/dist/auth/token_lifetime.d.ts.map +1 -1
- package/dist/auth/token_lifetime.js +8 -7
- package/dist/auth/token_scope.d.ts +99 -25
- package/dist/auth/token_scope.d.ts.map +1 -1
- package/dist/auth/token_scope.js +57 -35
- package/dist/db/CLAUDE.md +2 -1
- package/dist/db/file_fact_url.d.ts +11 -6
- package/dist/db/file_fact_url.d.ts.map +1 -1
- package/dist/db/file_fact_url.js +5 -5
- package/dist/db/schema_ready.d.ts +0 -5
- package/dist/db/schema_ready.d.ts.map +1 -1
- package/dist/db/schema_ready.js +0 -5
- package/dist/http/CLAUDE.md +104 -71
- package/dist/http/auth_shape.d.ts +48 -29
- package/dist/http/auth_shape.d.ts.map +1 -1
- package/dist/http/auth_shape.js +12 -85
- package/dist/http/body_limit.d.ts +12 -0
- package/dist/http/body_limit.d.ts.map +1 -1
- package/dist/http/body_limit.js +15 -0
- package/dist/http/body_limit_schema.d.ts +20 -0
- package/dist/http/body_limit_schema.d.ts.map +1 -0
- package/dist/http/body_limit_schema.js +20 -0
- package/dist/http/common_routes.d.ts +1 -1
- package/dist/http/common_routes.d.ts.map +1 -1
- package/dist/http/common_routes.js +11 -14
- package/dist/http/db_routes.d.ts.map +1 -1
- package/dist/http/db_routes.js +59 -69
- package/dist/http/dev_route_error_check.d.ts +70 -0
- package/dist/http/dev_route_error_check.d.ts.map +1 -0
- package/dist/http/dev_route_error_check.js +119 -0
- package/dist/http/error_schemas.d.ts +365 -189
- package/dist/http/error_schemas.d.ts.map +1 -1
- package/dist/http/error_schemas.js +256 -149
- package/dist/http/health_schema.d.ts +10 -6
- package/dist/http/health_schema.d.ts.map +1 -1
- package/dist/http/health_schema.js +3 -3
- package/dist/http/middleware_spec.d.ts +8 -3
- package/dist/http/middleware_spec.d.ts.map +1 -1
- package/dist/http/origin.d.ts +12 -43
- package/dist/http/origin.d.ts.map +1 -1
- package/dist/http/origin.js +10 -6
- package/dist/http/route_error_check.d.ts +158 -0
- package/dist/http/route_error_check.d.ts.map +1 -0
- package/dist/http/route_error_check.js +247 -0
- package/dist/http/route_errors.d.ts +80 -0
- package/dist/http/route_errors.d.ts.map +1 -0
- package/dist/http/route_errors.js +83 -0
- package/dist/http/route_spec.d.ts +33 -17
- package/dist/http/route_spec.d.ts.map +1 -1
- package/dist/http/route_spec.js +48 -62
- package/dist/http/schema_helpers.d.ts +0 -33
- package/dist/http/schema_helpers.d.ts.map +1 -1
- package/dist/http/schema_helpers.js +0 -45
- package/dist/http/surface.d.ts +19 -12
- package/dist/http/surface.d.ts.map +1 -1
- package/dist/http/surface.js +25 -38
- package/dist/http/surface_query.d.ts +11 -2
- package/dist/http/surface_query.d.ts.map +1 -1
- package/dist/http/surface_query.js +7 -1
- package/dist/primitive_schemas.d.ts +2 -19
- package/dist/primitive_schemas.d.ts.map +1 -1
- package/dist/primitive_schemas.js +2 -20
- package/dist/primitive_schemas_fuz.d.ts +39 -5
- package/dist/primitive_schemas_fuz.d.ts.map +1 -1
- package/dist/primitive_schemas_fuz.js +36 -7
- package/dist/rate_limiter.d.ts +13 -0
- package/dist/rate_limiter.d.ts.map +1 -1
- package/dist/rate_limiter.js +20 -2
- package/dist/schema_issues.d.ts +29 -11
- package/dist/schema_issues.d.ts.map +1 -1
- package/dist/schema_issues.js +11 -10
- package/dist/schema_meta.d.ts +8 -1
- package/dist/schema_meta.d.ts.map +1 -1
- package/dist/schema_meta.js +2 -1
- package/dist/server/app_server.d.ts +3 -1
- package/dist/server/app_server.d.ts.map +1 -1
- package/dist/server/app_server.js +24 -10
- package/dist/server/serve_fact_route.d.ts.map +1 -1
- package/dist/server/serve_fact_route.js +8 -31
- package/dist/server/surface_route.d.ts.map +1 -1
- package/dist/server/surface_route.js +5 -6
- package/dist/server/x_accel.d.ts +12 -7
- package/dist/server/x_accel.d.ts.map +1 -1
- package/dist/server/x_accel.js +7 -9
- package/dist/testing/CLAUDE.md +55 -44
- package/dist/testing/admin_integration.d.ts +3 -3
- package/dist/testing/admin_integration.d.ts.map +1 -1
- package/dist/testing/admin_integration.js +2 -2
- package/dist/testing/adversarial_404.d.ts +4 -18
- package/dist/testing/adversarial_404.d.ts.map +1 -1
- package/dist/testing/adversarial_404.js +19 -51
- package/dist/testing/adversarial_headers.d.ts +3 -4
- package/dist/testing/adversarial_headers.d.ts.map +1 -1
- package/dist/testing/adversarial_headers.js +8 -6
- package/dist/testing/adversarial_input.d.ts.map +1 -1
- package/dist/testing/adversarial_input.js +18 -17
- package/dist/testing/assertions.d.ts +33 -11
- package/dist/testing/assertions.d.ts.map +1 -1
- package/dist/testing/assertions.js +52 -12
- package/dist/testing/attack_surface.d.ts +5 -35
- package/dist/testing/attack_surface.d.ts.map +1 -1
- package/dist/testing/attack_surface.js +29 -91
- package/dist/testing/auth_apps.d.ts.map +1 -1
- package/dist/testing/auth_apps.js +2 -1
- package/dist/testing/cross_backend/action_manifest.d.ts +126 -56
- package/dist/testing/cross_backend/action_manifest.d.ts.map +1 -1
- package/dist/testing/cross_backend/action_manifest.js +11 -11
- package/dist/testing/cross_backend/action_manifest_parity.d.ts +1 -1
- package/dist/testing/cross_backend/action_manifest_parity.d.ts.map +1 -1
- package/dist/testing/cross_backend/cell_crud.d.ts.map +1 -1
- package/dist/testing/cross_backend/cell_crud.js +2 -1
- package/dist/testing/cross_backend/conformance_table.js +1 -1
- package/dist/testing/cross_backend/default_spine_surface.d.ts +2 -2
- package/dist/testing/cross_backend/default_spine_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/default_spine_surface.js +2 -2
- package/dist/testing/cross_backend/fact_serving.js +3 -3
- package/dist/testing/cross_backend/identity_parity.d.ts.map +1 -1
- package/dist/testing/cross_backend/identity_parity.js +39 -6
- package/dist/testing/cross_backend/origin_conformance.d.ts +278 -102
- package/dist/testing/cross_backend/origin_conformance.d.ts.map +1 -1
- package/dist/testing/cross_backend/origin_conformance.js +21 -21
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +3 -3
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/rust_spine_consumer_surface.js +7 -1
- package/dist/testing/cross_backend/setup.d.ts +14 -1
- package/dist/testing/cross_backend/setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/setup.js +68 -48
- package/dist/testing/cross_backend/spine_suites.d.ts +3 -3
- package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
- package/dist/testing/cross_backend/standard.d.ts +4 -4
- package/dist/testing/cross_backend/standard.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_origin_check.d.ts +147 -71
- package/dist/testing/cross_backend/testing_origin_check.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_origin_check.js +16 -13
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +70 -27
- package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
- package/dist/testing/cross_backend/token_lifetime.d.ts.map +1 -1
- package/dist/testing/cross_backend/token_lifetime.js +34 -1
- package/dist/testing/data_exposure.d.ts.map +1 -1
- package/dist/testing/data_exposure.js +5 -4
- package/dist/testing/error_coverage.d.ts +24 -34
- package/dist/testing/error_coverage.d.ts.map +1 -1
- package/dist/testing/error_coverage.js +46 -89
- package/dist/testing/integration.d.ts.map +1 -1
- package/dist/testing/integration.js +6 -14
- package/dist/testing/integration_helpers.d.ts +37 -9
- package/dist/testing/integration_helpers.d.ts.map +1 -1
- package/dist/testing/integration_helpers.js +86 -40
- package/dist/testing/middleware.d.ts +3 -5
- package/dist/testing/middleware.d.ts.map +1 -1
- package/dist/testing/middleware.js +5 -4
- package/dist/testing/rate_limiting.d.ts +1 -1
- package/dist/testing/rate_limiting.d.ts.map +1 -1
- package/dist/testing/rate_limiting.js +5 -4
- package/dist/testing/round_trip.d.ts.map +1 -1
- package/dist/testing/round_trip.js +5 -3
- package/dist/testing/schema_generators.d.ts +10 -3
- package/dist/testing/schema_generators.d.ts.map +1 -1
- package/dist/testing/schema_generators.js +23 -11
- package/dist/testing/stubs.d.ts +10 -1
- package/dist/testing/stubs.d.ts.map +1 -1
- package/dist/testing/stubs.js +15 -5
- package/dist/testing/surface_invariants.d.ts +36 -115
- package/dist/testing/surface_invariants.d.ts.map +1 -1
- package/dist/testing/surface_invariants.js +106 -269
- package/dist/testing/token_scope_fixtures.d.ts +24 -0
- package/dist/testing/token_scope_fixtures.d.ts.map +1 -0
- package/dist/testing/token_scope_fixtures.js +49 -0
- 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 +13 -12
- package/dist/ui/BootstrapForm.svelte +4 -2
- package/dist/ui/BootstrapForm.svelte.d.ts.map +1 -1
- package/dist/ui/CLAUDE.md +4 -2
- package/dist/ui/SignupForm.svelte +4 -2
- package/dist/ui/SignupForm.svelte.d.ts.map +1 -1
- package/dist/ui/auth_state.svelte.d.ts.map +1 -1
- package/dist/ui/auth_state.svelte.js +2 -8
- package/dist/ui/backend_probe.svelte.js +3 -3
- package/dist/ui/table_state.svelte.d.ts.map +1 -1
- package/dist/ui/table_state.svelte.js +1 -8
- package/dist/ui/ui_fetch.d.ts +12 -2
- package/dist/ui/ui_fetch.d.ts.map +1 -1
- package/dist/ui/ui_fetch.js +22 -4
- package/package.json +1 -1
- package/dist/auth/audit_log_schema_fuz.d.ts +0 -53
- package/dist/auth/audit_log_schema_fuz.d.ts.map +0 -1
- package/dist/auth/audit_log_schema_fuz.js +0 -50
- package/dist/auth/role_schema_fuz.d.ts +0 -30
- package/dist/auth/role_schema_fuz.d.ts.map +0 -1
- package/dist/auth/role_schema_fuz.js +0 -30
- package/dist/auth/scope_kind_schema_fuz.d.ts +0 -31
- package/dist/auth/scope_kind_schema_fuz.d.ts.map +0 -1
- package/dist/auth/scope_kind_schema_fuz.js +0 -31
package/dist/auth/token_scope.js
CHANGED
|
@@ -28,17 +28,21 @@
|
|
|
28
28
|
*
|
|
29
29
|
* @module
|
|
30
30
|
*/
|
|
31
|
-
import {
|
|
31
|
+
import { array, boolean, literal, object, optional, parse, string, variant } from '@fuzdev/fuz_schema/schema.ts';
|
|
32
|
+
import { to_bytes } from '@fuzdev/fuz_util/bytes.ts';
|
|
32
33
|
import { is_valid_name } from './name_schema.js';
|
|
33
34
|
/** Current `TokenScope` document version. Must match the Rust `TOKEN_SCOPE_VERSION`. */
|
|
34
35
|
export const TOKEN_SCOPE_VERSION = 1;
|
|
35
36
|
/**
|
|
36
|
-
* Serialized-document cap
|
|
37
|
+
* Serialized-document cap, in UTF-8 bytes of the document's compact JSON (no
|
|
38
|
+
* whitespace, what `JSON.stringify` writes) — never the text a driver or
|
|
39
|
+
* Postgres prints it as, which for `jsonb` adds a space after every `:` and
|
|
40
|
+
* `,`. Matches the Rust `MAX_TOKEN_SCOPE_BYTES`, which measures the same, and
|
|
37
41
|
* fuz_forge's `MAX_POLICY_BYTES`.
|
|
38
42
|
*/
|
|
39
43
|
export const MAX_TOKEN_SCOPE_BYTES = 4 * 1024;
|
|
40
44
|
/**
|
|
41
|
-
* The stored `api_token.scope` document.
|
|
45
|
+
* The stored `api_token.scope` document, a `@fuzdev/fuz_schema` schema.
|
|
42
46
|
*
|
|
43
47
|
* `grandfathered` is a fact about the *row* — the `api_token_scope` migration
|
|
44
48
|
* wrote it; no minter chose it — that only the token list cares about. The
|
|
@@ -50,31 +54,31 @@ export const MAX_TOKEN_SCOPE_BYTES = 4 * 1024;
|
|
|
50
54
|
* The discriminated union also refuses the contradiction
|
|
51
55
|
* `{kind: 'full', methods: [...]}`.
|
|
52
56
|
*/
|
|
53
|
-
export const TokenScope =
|
|
54
|
-
|
|
55
|
-
version:
|
|
56
|
-
kind:
|
|
57
|
-
grandfathered:
|
|
57
|
+
export const TokenScope = variant('kind', [
|
|
58
|
+
object({
|
|
59
|
+
version: literal(TOKEN_SCOPE_VERSION),
|
|
60
|
+
kind: literal('full'),
|
|
61
|
+
grandfathered: optional(boolean)
|
|
58
62
|
}),
|
|
59
|
-
|
|
60
|
-
version:
|
|
61
|
-
kind:
|
|
62
|
-
methods:
|
|
63
|
-
grandfathered:
|
|
63
|
+
object({
|
|
64
|
+
version: literal(TOKEN_SCOPE_VERSION),
|
|
65
|
+
kind: literal('methods'),
|
|
66
|
+
methods: array(string),
|
|
67
|
+
grandfathered: optional(boolean)
|
|
64
68
|
})
|
|
65
69
|
]);
|
|
66
70
|
/**
|
|
67
71
|
* The `scope` input accepted by `account_token_create` — the stored shape minus
|
|
68
|
-
* the row-owned fields.
|
|
72
|
+
* the row-owned fields, a `@fuzdev/fuz_schema` schema.
|
|
69
73
|
*
|
|
70
74
|
* A minter cannot set `version` or `grandfathered`: the first is stamped by
|
|
71
75
|
* `token_scope_full` / `token_scope_methods`, and the second is the migration's
|
|
72
76
|
* mark for tokens that predate scoping. Letting a caller forge `grandfathered`
|
|
73
77
|
* would turn a tracked debt into a laundered one.
|
|
74
78
|
*/
|
|
75
|
-
export const TokenScopeInput =
|
|
76
|
-
|
|
77
|
-
|
|
79
|
+
export const TokenScopeInput = variant('kind', [
|
|
80
|
+
object({ kind: literal('full') }),
|
|
81
|
+
object({ kind: literal('methods'), methods: array(string) })
|
|
78
82
|
]);
|
|
79
83
|
/** A deliberately-minted full-authority scope. */
|
|
80
84
|
export const token_scope_full = () => ({
|
|
@@ -219,8 +223,33 @@ export const token_scope_label = (scope) => {
|
|
|
219
223
|
return scope.grandfathered ? 'full (grandfathered)' : 'full';
|
|
220
224
|
return `${scope.methods.length} methods`;
|
|
221
225
|
};
|
|
226
|
+
/** The UTF-8 byte length of `json`, the unit `MAX_TOKEN_SCOPE_BYTES` counts. */
|
|
227
|
+
const token_scope_json_bytes = (json) => to_bytes(json).length;
|
|
222
228
|
/**
|
|
223
|
-
*
|
|
229
|
+
* Read a document's parsed JSON value, enforcing the size cap on its compact
|
|
230
|
+
* serialization and the schema; `null` when it is unreadable.
|
|
231
|
+
*/
|
|
232
|
+
const token_scope_from_value = (value) => {
|
|
233
|
+
// `JSON.stringify(undefined)` returns `undefined`, not a string — so a row
|
|
234
|
+
// missing the column entirely must be caught here rather than measured.
|
|
235
|
+
// Absent is *unreadable*, which is fail-closed: the caller refuses the
|
|
236
|
+
// credential.
|
|
237
|
+
const json = JSON.stringify(value);
|
|
238
|
+
if (json === undefined || token_scope_json_bytes(json) > MAX_TOKEN_SCOPE_BYTES)
|
|
239
|
+
return null;
|
|
240
|
+
const parsed = parse(TokenScope, value);
|
|
241
|
+
return parsed.ok ? parsed.value : null;
|
|
242
|
+
};
|
|
243
|
+
/**
|
|
244
|
+
* Parse a stored document, enforcing the size cap and the schema. The cap is
|
|
245
|
+
* measured on the document's compact serialization, not on `raw`, so the
|
|
246
|
+
* spaced text Postgres prints a `jsonb` as reads as the document it is.
|
|
247
|
+
*
|
|
248
|
+
* A `raw` past twice the cap is refused before it is parsed. Postgres prints a
|
|
249
|
+
* `jsonb` as its compact form plus one space after each `:` and `,` outside
|
|
250
|
+
* strings, each of which is a byte of that form beside its braces, so the
|
|
251
|
+
* printed text of a document either spine can write is under twice the cap and
|
|
252
|
+
* never refused here.
|
|
224
253
|
*
|
|
225
254
|
* **Fail-closed**: returns `null` on an unreadable document, and every caller on
|
|
226
255
|
* the enforcement path treats `null` as "refuse the credential" rather than
|
|
@@ -230,7 +259,8 @@ export const token_scope_label = (scope) => {
|
|
|
230
259
|
* authority exactly when something is already wrong.
|
|
231
260
|
*/
|
|
232
261
|
export const parse_token_scope = (raw) => {
|
|
233
|
-
|
|
262
|
+
// code units, which never exceed UTF-8 bytes, so this refuses no text the byte cap reads
|
|
263
|
+
if (raw.length > 2 * MAX_TOKEN_SCOPE_BYTES)
|
|
234
264
|
return null;
|
|
235
265
|
let value;
|
|
236
266
|
try {
|
|
@@ -239,19 +269,19 @@ export const parse_token_scope = (raw) => {
|
|
|
239
269
|
catch {
|
|
240
270
|
return null;
|
|
241
271
|
}
|
|
242
|
-
|
|
243
|
-
return parsed.success ? parsed.data : null;
|
|
272
|
+
return token_scope_from_value(value);
|
|
244
273
|
};
|
|
245
274
|
/**
|
|
246
|
-
* Serialize for storage, enforcing the size cap.
|
|
275
|
+
* Serialize for storage, enforcing the size cap in UTF-8 bytes.
|
|
247
276
|
*
|
|
248
277
|
* Throws on an over-cap document — the mint path maps that to a 400, matching
|
|
249
278
|
* the Rust side's `TokenScopeError::TooLarge`.
|
|
250
279
|
*/
|
|
251
280
|
export const serialize_token_scope = (scope) => {
|
|
252
281
|
const json = JSON.stringify(scope);
|
|
253
|
-
|
|
254
|
-
|
|
282
|
+
const bytes = token_scope_json_bytes(json);
|
|
283
|
+
if (bytes > MAX_TOKEN_SCOPE_BYTES) {
|
|
284
|
+
throw new Error(`token scope document is ${bytes} bytes, exceeding the ${MAX_TOKEN_SCOPE_BYTES} byte cap`);
|
|
255
285
|
}
|
|
256
286
|
return json;
|
|
257
287
|
};
|
|
@@ -261,16 +291,8 @@ export const serialize_token_scope = (scope) => {
|
|
|
261
291
|
*
|
|
262
292
|
* The DB driver may hand `scope` back already-parsed (JSONB → object) or as
|
|
263
293
|
* text depending on backend, so both are normalized here rather than at each
|
|
264
|
-
* call site
|
|
294
|
+
* call site, and either is held to the cap by its compact serialization, as
|
|
295
|
+
* the Rust spine holds the spaced `scope::text` it reads. Lives here rather than beside the queries so the pure scope module
|
|
265
296
|
* owns every parse — and so mocking the query module doesn't drag this along.
|
|
266
297
|
*/
|
|
267
|
-
export const parse_stored_token_scope = (value) =>
|
|
268
|
-
if (typeof value === 'string')
|
|
269
|
-
return parse_token_scope(value);
|
|
270
|
-
// `JSON.stringify(undefined)` returns `undefined`, not a string — so a row
|
|
271
|
-
// missing the column entirely must be caught here rather than reaching
|
|
272
|
-
// `parse_token_scope` and throwing on `.length`. Absent is *unreadable*,
|
|
273
|
-
// which is fail-closed: the caller refuses the credential.
|
|
274
|
-
const json = JSON.stringify(value);
|
|
275
|
-
return json === undefined ? null : parse_token_scope(json);
|
|
276
|
-
};
|
|
298
|
+
export const parse_stored_token_scope = (value) => typeof value === 'string' ? parse_token_scope(value) : token_scope_from_value(value);
|
package/dist/db/CLAUDE.md
CHANGED
|
@@ -75,7 +75,8 @@ the code.
|
|
|
75
75
|
`fuz_db` twin's; `src/test/db/status.test.ts` pins the shared fixture.
|
|
76
76
|
- `schema_ready.ts` — `/ready` deploy-gate core: `query_public_columns`
|
|
77
77
|
(keeps `schema_version`, unlike `query_schema_snapshot`), pure
|
|
78
|
-
`check_schema_drift` / `format_schema_drift
|
|
78
|
+
`check_schema_drift` / `format_schema_drift` (the `/ready` 503 codes are
|
|
79
|
+
`ERROR_SCHEMA_DRIFT` / `ERROR_DB_UNREACHABLE` in `http/error_schemas.ts`). Column-presence
|
|
79
80
|
drift detection only (engine-portable); the HTTP route + fixture loader live
|
|
80
81
|
in `http/common_routes.ts`, the gen-time regen helper in
|
|
81
82
|
`testing/schema_ready_fixture.ts`.
|
|
@@ -25,16 +25,21 @@
|
|
|
25
25
|
* @module
|
|
26
26
|
*/
|
|
27
27
|
import { type FactHash } from '@fuzdev/fuz_util/hash_schemas.ts';
|
|
28
|
-
import {
|
|
28
|
+
import { type Infer } from '@fuzdev/fuz_schema/schema.ts';
|
|
29
29
|
/** Anchored, capture-group form: `^file:(<shard>)/(<rest>)$`. */
|
|
30
30
|
export declare const FILE_FACT_URL_PATTERN: RegExp;
|
|
31
31
|
/**
|
|
32
|
-
* Branded URL form. Construct only via
|
|
33
|
-
* `mint_file_fact_url` — those are the validated
|
|
34
|
-
* string literals don't satisfy the brand.
|
|
32
|
+
* Branded URL form, a `@fuzdev/fuz_schema` schema. Construct only via
|
|
33
|
+
* `parse_file_fact_url` or `mint_file_fact_url` — those are the validated
|
|
34
|
+
* boundaries. Direct string literals don't satisfy the brand.
|
|
35
35
|
*/
|
|
36
|
-
export declare const FileFactUrl:
|
|
37
|
-
|
|
36
|
+
export declare const FileFactUrl: import("@fuzdev/fuz_schema/schema.ts").Schema<import("@fuzdev/fuz_schema/schema.ts").Branded<string, "FileFactUrl">, string, "pipe", readonly (import("@fuzdev/fuz_schema/schema.ts").SchemaOfKind<"string"> | import("@fuzdev/fuz_schema/schema.ts").SchemaOfKind<"number"> | import("@fuzdev/fuz_schema/schema.ts").SchemaOfKind<"bigint"> | import("@fuzdev/fuz_schema/schema.ts").SchemaOfKind<"boolean"> | import("@fuzdev/fuz_schema/schema.ts").SchemaOfKind<"object"> | import("@fuzdev/fuz_schema/schema.ts").SchemaOfKind<"check"> | import("@fuzdev/fuz_schema/schema.ts").SchemaOfKind<"uuid"> | import("@fuzdev/fuz_schema/schema.ts").SchemaOfKind<"unknown"> | import("@fuzdev/fuz_schema/schema.ts").SchemaOfKind<"record"> | import("@fuzdev/fuz_schema/schema.ts").SchemaOfKind<"array"> | import("@fuzdev/fuz_schema/schema.ts").SchemaOfKind<"union"> | import("@fuzdev/fuz_schema/schema.ts").SchemaOfKind<"literal"> | import("@fuzdev/fuz_schema/schema.ts").SchemaOfKind<"nullable"> | import("@fuzdev/fuz_schema/schema.ts").SchemaOfKind<"optional"> | import("@fuzdev/fuz_schema/schema.ts").SchemaOfKind<"transform"> | import("@fuzdev/fuz_schema/schema.ts").SchemaOfKind<"pipe"> | import("@fuzdev/fuz_schema/schema.ts").SchemaOfKind<"lazy"> | import("@fuzdev/fuz_schema/schema.ts").SchemaOfKind<"regex"> | import("@fuzdev/fuz_schema/schema.ts").SchemaOfKind<"one_of"> | import("@fuzdev/fuz_schema/schema.ts").SchemaOfKind<"with_default"> | import("@fuzdev/fuz_schema/schema.ts").SchemaOfKind<"with_default_fn"> | import("@fuzdev/fuz_schema/schema.ts").SchemaOfKind<"loose_object"> | import("@fuzdev/fuz_schema/schema.ts").SchemaOfKind<"strip_object"> | import("@fuzdev/fuz_schema/schema.ts").SchemaOfKind<"object_with_rest"> | import("@fuzdev/fuz_schema/schema.ts").SchemaOfKind<"variant"> | import("@fuzdev/fuz_schema/schema.ts").SchemaOfKind<"min_length"> | import("@fuzdev/fuz_schema/schema.ts").SchemaOfKind<"max_length"> | import("@fuzdev/fuz_schema/schema.ts").SchemaOfKind<"min_value"> | import("@fuzdev/fuz_schema/schema.ts").SchemaOfKind<"max_value"> | import("@fuzdev/fuz_schema/schema.ts").SchemaOfKind<"integer"> | import("@fuzdev/fuz_schema/schema.ts").SchemaOfKind<"safe_integer"> | import("@fuzdev/fuz_schema/schema.ts").SchemaOfKind<"iso_datetime"> | import("@fuzdev/fuz_schema/schema.ts").SchemaOfKind<"to_lower_case">)[]> & {
|
|
37
|
+
readonly '~types'?: {
|
|
38
|
+
readonly input: string;
|
|
39
|
+
readonly first: import("@fuzdev/fuz_schema/schema.ts").Schema<string, string, "string", undefined>;
|
|
40
|
+
} | undefined;
|
|
41
|
+
};
|
|
42
|
+
export type FileFactUrl = Infer<typeof FileFactUrl>;
|
|
38
43
|
/**
|
|
39
44
|
* Split a `FactHash` into its on-disk `<shard>/<rest>` parts — the first 2
|
|
40
45
|
* hex chars of the digest (shard subdir) + the remaining 62. The single
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file_fact_url.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/db/file_fact_url.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAoB,KAAK,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AACnF,OAAO,
|
|
1
|
+
{"version":3,"file":"file_fact_url.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/db/file_fact_url.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAoB,KAAK,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AACnF,OAAO,EAA8B,KAAK,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAEtF,iEAAiE;AACjE,eAAO,MAAM,qBAAqB,QAAyC,CAAC;AAE5E;;;;GAIG;AACH,eAAO,MAAM,WAAW;;;;;CAAmE,CAAC;AAC5F,MAAM,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAEpD;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,GAAI,MAAM,QAAQ,KAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAG5E,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAC/B,KAAK,MAAM,KACT;IAAE,GAAG,EAAE,WAAW,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,IAItD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,uBAAuB,GACnC,QAAQ;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EACvC,MAAM,QAAQ,KACZ,OAGF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAI,OAAO,MAAM,EAAE,MAAM,MAAM,KAAG,WAC1B,CAAC"}
|
package/dist/db/file_fact_url.js
CHANGED
|
@@ -25,15 +25,15 @@
|
|
|
25
25
|
* @module
|
|
26
26
|
*/
|
|
27
27
|
import { FACT_HASH_PREFIX } from '@fuzdev/fuz_util/hash_schemas.ts';
|
|
28
|
-
import {
|
|
28
|
+
import { brand, pipe, regex, string } from '@fuzdev/fuz_schema/schema.ts';
|
|
29
29
|
/** Anchored, capture-group form: `^file:(<shard>)/(<rest>)$`. */
|
|
30
30
|
export const FILE_FACT_URL_PATTERN = /^file:([0-9a-f]{2})\/([0-9a-f]{62})$/;
|
|
31
31
|
/**
|
|
32
|
-
* Branded URL form. Construct only via
|
|
33
|
-
* `mint_file_fact_url` — those are the validated
|
|
34
|
-
* string literals don't satisfy the brand.
|
|
32
|
+
* Branded URL form, a `@fuzdev/fuz_schema` schema. Construct only via
|
|
33
|
+
* `parse_file_fact_url` or `mint_file_fact_url` — those are the validated
|
|
34
|
+
* boundaries. Direct string literals don't satisfy the brand.
|
|
35
35
|
*/
|
|
36
|
-
export const FileFactUrl =
|
|
36
|
+
export const FileFactUrl = brand(pipe(string, regex(FILE_FACT_URL_PATTERN)), 'FileFactUrl');
|
|
37
37
|
/**
|
|
38
38
|
* Split a `FactHash` into its on-disk `<shard>/<rest>` parts — the first 2
|
|
39
39
|
* hex chars of the digest (shard subdir) + the remaining 62. The single
|
|
@@ -80,9 +80,4 @@ export interface SchemaDriftResult {
|
|
|
80
80
|
export declare const check_schema_drift: (db: Db, expected: ExpectedSchema) => Promise<SchemaDriftResult>;
|
|
81
81
|
/** Render a drift result as a one-issue-per-line operator string. */
|
|
82
82
|
export declare const format_schema_drift: (drift: SchemaDriftResult) => string;
|
|
83
|
-
/** Error codes a readiness check returns at `503` (conforms to `{error: string}`). */
|
|
84
|
-
export declare const READY_ERROR: {
|
|
85
|
-
readonly schema_drift: "schema_drift";
|
|
86
|
-
readonly db_unreachable: "db_unreachable";
|
|
87
|
-
};
|
|
88
83
|
//# sourceMappingURL=schema_ready.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema_ready.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/db/schema_ready.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAElC,iFAAiF;AACjF,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;AAOnE;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,oBAAoB,GAChC,IAAI,EAAE,EACN,UAAU;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,KAC1B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAavC,CAAC;AAEF,+EAA+E;AAC/E,MAAM,WAAW,cAAc;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CACvB;AAED,uCAAuC;AACvC,MAAM,WAAW,iBAAiB;IACjC,EAAE,EAAE,OAAO,CAAC;IACZ,+CAA+C;IAC/C,cAAc,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC9B,6EAA6E;IAC7E,eAAe,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;CACvC;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,GAC9B,IAAI,EAAE,EACN,UAAU,cAAc,KACtB,OAAO,CAAC,iBAAiB,CAmB3B,CAAC;AAEF,qEAAqE;AACrE,eAAO,MAAM,mBAAmB,GAAI,OAAO,iBAAiB,KAAG,MAO9D,CAAC
|
|
1
|
+
{"version":3,"file":"schema_ready.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/db/schema_ready.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAElC,iFAAiF;AACjF,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;AAOnE;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,oBAAoB,GAChC,IAAI,EAAE,EACN,UAAU;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,KAC1B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAavC,CAAC;AAEF,+EAA+E;AAC/E,MAAM,WAAW,cAAc;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CACvB;AAED,uCAAuC;AACvC,MAAM,WAAW,iBAAiB;IACjC,EAAE,EAAE,OAAO,CAAC;IACZ,+CAA+C;IAC/C,cAAc,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC9B,6EAA6E;IAC7E,eAAe,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;CACvC;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,GAC9B,IAAI,EAAE,EACN,UAAU,cAAc,KACtB,OAAO,CAAC,iBAAiB,CAmB3B,CAAC;AAEF,qEAAqE;AACrE,eAAO,MAAM,mBAAmB,GAAI,OAAO,iBAAiB,KAAG,MAO9D,CAAC"}
|
package/dist/db/schema_ready.js
CHANGED
|
@@ -100,8 +100,3 @@ export const format_schema_drift = (drift) => {
|
|
|
100
100
|
}
|
|
101
101
|
return lines.join('\n');
|
|
102
102
|
};
|
|
103
|
-
/** Error codes a readiness check returns at `503` (conforms to `{error: string}`). */
|
|
104
|
-
export const READY_ERROR = {
|
|
105
|
-
schema_drift: 'schema_drift',
|
|
106
|
-
db_unreachable: 'db_unreachable'
|
|
107
|
-
};
|
package/dist/http/CLAUDE.md
CHANGED
|
@@ -9,17 +9,20 @@ guards live in `auth/` and consume these primitives. Routes and actions in
|
|
|
9
9
|
other domains should do the same — extend, don't special-case.
|
|
10
10
|
|
|
11
11
|
For the design rationale behind declarative routes, DEV-only output
|
|
12
|
-
validation, the
|
|
12
|
+
validation, the route error map, and fire-and-forget
|
|
13
13
|
effects, see ../../../docs/architecture.md.
|
|
14
14
|
|
|
15
15
|
## Module Map
|
|
16
16
|
|
|
17
17
|
- `http/route_spec.ts` — `RouteSpec` + `apply_route_specs`, validation pipeline, transactions.
|
|
18
|
-
- `http/auth_shape.ts` — canonical `RouteAuth`
|
|
19
|
-
- `http/error_schemas.ts` — `ERROR_*` constants,
|
|
20
|
-
- `http/
|
|
18
|
+
- `http/auth_shape.ts` — canonical `RouteAuth` type + `AuthAxisState` + predicates + the registration-time checks: `assert_route_auth_invariants` (the cross-axis invariants 1, 3, 4) and `assert_route_auth_acting_biconditional` (invariant 2), both run by `apply_route_specs` and `compile_action_registry` on every spec.
|
|
19
|
+
- `http/error_schemas.ts` — `ERROR_*` constants, the per-code REST error definitions (`rest_error`, `REST_*`), `derive_route_errors`, `to_error_schemas`.
|
|
20
|
+
- `http/route_errors.ts` — the route error map: `RouteErrorMap`, `resolve_route_error_map`, `resolve_app_route_error_maps`, `get_route_error_map`.
|
|
21
|
+
- `http/route_error_check.ts` — `check_route_error` (whether an error response is one its route's map declares, the rule the DEV error check and `assert_response_matches_spec` share; `ALWAYS_ACCEPTED_ERRORS`, `is_error_status`, `format_route_error_check`) `is_json_response`, and the test helpers' hono-free route lookup (`split_route_template` and `parse_route_param`, a template read segment by segment as Hono's `getPattern` reads it; `compile_route_path`; `to_mounted_routes`; `find_mounted_route`), whose reading `resolve_valid_path` also fills params by. Hono-free and `esm-env`-free.
|
|
22
|
+
- `http/dev_route_error_check.ts` — `create_dev_route_error_check({route_specs, route_error_maps, log})`: the DEV-only outer error check, `null` outside DEV; `create_route_lookup`, its lookup by Hono's own router.
|
|
23
|
+
- `http/schema_helpers.ts` — shared schema introspection (null/void/strict/surface/middleware-applies), and `to_void_params` / `to_input_params` / `json_has_own_proto_key` / `safe_parse_dropping_unknown_keys`.
|
|
21
24
|
- `http/middleware_spec.ts` — `MiddlewareSpec` interface.
|
|
22
|
-
- `http/body_limit.ts` — `create_body_limit_middleware(max_size)`: the `413` body cap `create_app_server` mounts. Refuses on `Content-Length` without reading `c.req.raw.body` and answers `Connection: close` — `413` past the cap, `400` `ERROR_INVALID_CONTENT_LENGTH` when the value is not a plain run of ASCII digits (a length the cap cannot read, which Hono's `bodyLimit` would pass uncounted) — else falls through to Hono's `bodyLimit` (no `Content-Length`, or one beside `Transfer-Encoding`), which reads the body into memory up to the cap before the next middleware runs, so its `413` — no `Connection: close` — also precedes origin and auth.
|
|
25
|
+
- `http/body_limit.ts` — `create_body_limit_middleware(max_size)`: the `413` body cap `create_app_server` mounts, as `create_body_limit_middleware_spec(max_size)`, a `MiddlewareSpec` at `'*'` ahead of the other middleware, absent with `max_body_size: null`. Its hono-free shape, `body_limit_middleware_shape` (`http/body_limit_schema.ts`), declares its `413` `payload_too_large` and `400` `invalid_content_length`, so every route's error map carries both; `create_test_app_surface_spec` lists the same shape with a stub handler. Refuses on `Content-Length` without reading `c.req.raw.body` and answers `Connection: close` — `413` past the cap, `400` `ERROR_INVALID_CONTENT_LENGTH` when the value is not a plain run of ASCII digits (a length the cap cannot read, which Hono's `bodyLimit` would pass uncounted) — else falls through to Hono's `bodyLimit` (no `Content-Length`, or one beside `Transfer-Encoding`), which reads the body into memory up to the cap before the next middleware runs, so its `413` — no `Connection: close` — also precedes origin and auth. After the header `413` Node and Bun close at once (the header is what makes them — Bun 1.4.3 is the tested floor, an older Bun kept the connection and served the next request) and Deno closes once the declared body has arrived (../../../docs/security.md §Body Size Limiting).
|
|
23
26
|
- `http/surface.ts` — `AppSurface`, `AppSurfaceSpec`, `generate_app_surface`, diagnostics.
|
|
24
27
|
- `http/surface_query.ts` — pure filters/groupings over `AppSurface`.
|
|
25
28
|
- `http/proxy.ts` — trusted-proxy middleware, CIDR parsing, rightmost-first XFF resolution. Pulls `hono/utils/ipaddr` for CIDR matching.
|
|
@@ -29,7 +32,7 @@ effects, see ../../../docs/architecture.md.
|
|
|
29
32
|
- `http/jsonrpc.ts` — JSON-RPC 2.0 envelope schemas (MCP superset), `JsonrpcErrorCode`, `_meta`.
|
|
30
33
|
- `http/jsonrpc_errors.ts` — `ThrownJsonrpcError`, `jsonrpc_errors` throwers, HTTP-status mappings.
|
|
31
34
|
- `http/jsonrpc_helpers.ts` — message builders, type guards, input/result normalizers, and `classify_jsonrpc_message`, the one envelope classifier both transports run.
|
|
32
|
-
- `http/health_schema.ts` — `HEALTH_PATH` + the `HealthResponse` schema, browser-safe, shared by the health route spec and the client probe (`ui/backend_probe.svelte.ts`).
|
|
35
|
+
- `http/health_schema.ts` — `HEALTH_PATH` + the `HealthResponse` schema (a fuz_schema `object`), browser-safe, shared by the health route spec and the client probe (`ui/backend_probe.svelte.ts`).
|
|
33
36
|
- `http/common_routes.ts` — health check + readiness probe (`/ready` schema-drift deploy gate) + authenticated server-status route specs (the surface explorer route lives in `server/surface_route.ts`).
|
|
34
37
|
- `http/db_routes.ts` — allowlist-gated keeper-only table browser route specs (`public` schema, minus the `NON_BROWSABLE_TABLES` credential floor).
|
|
35
38
|
- `http/pending_effects.ts` — `emit_after_commit` + `dispatch_with_post_commit_rollback` (the shared rollback-discard wrapper both dispatch sites use) + `flush_request_effects` (the one two-queue flush HTTP and WS share, over `flush_pending_effects` + `flush_post_commit_effects`) + `EffectErrorContext` + `EmitAfterCommitContext`.
|
|
@@ -55,7 +58,8 @@ consumers.
|
|
|
55
58
|
- `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`)
|
|
56
59
|
- `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
|
|
57
60
|
- `rate_limit?: RateLimitKey` — metadata only (`'ip' | 'account' | 'both'`); auto-derives 429
|
|
58
|
-
- `errors?:
|
|
61
|
+
- `errors?: ReadonlyArray<RestErrorDef>` — the handler's own error definitions (`rest_error`); joins the route error map beside the derived and middleware ones
|
|
62
|
+
- `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`
|
|
59
63
|
- `transaction?: boolean` — declarative transaction wrapping (see below)
|
|
60
64
|
|
|
61
65
|
Every schema field takes a Zod or a `@fuzdev/fuz_schema` schema
|
|
@@ -115,10 +119,10 @@ wrapper). See `auth/signup_routes.ts`.
|
|
|
115
119
|
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>`.
|
|
116
120
|
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.
|
|
117
121
|
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)`.
|
|
118
|
-
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 `z.null()`
|
|
122
|
+
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`: `z.null()` or `literal(null)`). The validated input lands on `c.var.validated_input`.
|
|
119
123
|
7. **Handler** — wrapped in transaction when `use_transaction` (see above), receives `RouteContext`
|
|
120
|
-
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
|
|
121
|
-
9. **DEV-only output
|
|
124
|
+
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.
|
|
125
|
+
9. **DEV-only output validation** — a 2xx JSON body against `spec.output` (see below); error responses are the outer DEV error check's
|
|
122
126
|
|
|
123
127
|
**Ordering: 401 → authz → 403 → 400 → handler.** Mirrors the RPC dispatcher
|
|
124
128
|
(`actions/action_rpc.ts`) so HTTP RPC and REST fail with the same priority, and
|
|
@@ -146,17 +150,17 @@ schema in scope.
|
|
|
146
150
|
are the contract with external callers.
|
|
147
151
|
|
|
148
152
|
**Output and error schemas are validated DEV-only** via `DEV` from
|
|
149
|
-
`esm-env
|
|
153
|
+
`esm-env`, each in one place:
|
|
150
154
|
|
|
151
|
-
-
|
|
152
|
-
- On
|
|
153
|
-
-
|
|
154
|
-
- Always accepts a 500 `{error: 'internal_error'}`: the error catch answers it for any generic throw, so no route declares it
|
|
155
|
-
- **Logs on mismatch, returns the response unchanged** — never throws, never mutates the body
|
|
155
|
+
- **Output** — `wrap_output_validation`, per route: a 2xx JSON body against `spec.output`. Skips non-`application/json` responses so SSE doesn't hang on `.json()`.
|
|
156
|
+
- **Errors** — `create_dev_route_error_check` (`http/dev_route_error_check.ts`), one outer middleware `create_app_server` mounts outermost (`app.use('*')`, first after `onError`), so it sees what every layer answers — a middleware's refusal (body limit, origin, auth guards) as much as a handler's or the error catch's. After the request it finds the route with Hono's own router (`create_route_lookup`: the `SmartRouter` over a `RegExpRouter` and a `TrieRouter` that `new Hono()` builds, the route specs added in mount order, the first match the route, `HEAD` read as `GET`) and checks a JSON body at 400 and up against the route's error map (`check_route_error`, `http/route_error_check.ts`): a status the map lacks logs `Undeclared error status (S): METHOD path`, a body off the status's schema `Error schema mismatch (S): METHOD path`. Always accepted: a 500 `internal_error` and a 503 `service_unavailable` (`ALWAYS_ACCEPTED_ERRORS`, which the catch layers answer on any route). On a `jsonrpc` route (the pair `create_rpc_endpoint` builds) a JSON-RPC error envelope is skipped (`is_jsonrpc_error_response`): the endpoint answers its refusals as envelopes, which no REST error definition describes, and the dispatch core checks its own outputs. On any other route an envelope-shaped body is checked. Skipped: non-JSON responses (`is_json_response`, the gate both checks run), and a request no route spec matches — an unmatched path's 404 is Hono's plain text, with no JSON convention to hold it to. `assert_response_matches_spec` runs the same `check_route_error`.
|
|
157
|
+
- **Logs on mismatch, returns the response unchanged** — never throws (a throw inside the error check, its logger's included, is swallowed), never mutates the body
|
|
156
158
|
|
|
157
|
-
Production short-circuits
|
|
158
|
-
|
|
159
|
-
|
|
159
|
+
Production short-circuits: `wrap_output_validation` returns the handler
|
|
160
|
+
unwrapped and `create_dev_route_error_check` returns `null`, so nothing is
|
|
161
|
+
mounted — no parse work on the hot path. Uniform across all three
|
|
162
|
+
action-handler surfaces (REST, RPC, WS); see ../../../docs/architecture.md
|
|
163
|
+
§DEV-only Output Validation.
|
|
160
164
|
|
|
161
165
|
### Helpers
|
|
162
166
|
|
|
@@ -167,39 +171,63 @@ WS); see ../../../docs/architecture.md §DEV-only Output Validation.
|
|
|
167
171
|
|
|
168
172
|
`http/error_schemas.ts` is the **declarative** error surface:
|
|
169
173
|
|
|
170
|
-
- `ERROR_*` `snake_case` string constants — single source of truth;
|
|
171
|
-
- `
|
|
172
|
-
- `
|
|
173
|
-
- `
|
|
174
|
+
- `ERROR_*` `snake_case` string constants (`ERROR_FORBIDDEN_HOST` / `REST_FORBIDDEN_HOST` the Rust spine's host gate, which the TS spine lacks) — single source of truth for codes; they double as JSON-RPC `data.reason`s, so they carry no HTTP status
|
|
175
|
+
- `rest_error(status, code, fields?, headers?)` → `RestErrorDef<S, C, F>` — one code at one status; the code must be a code, `REST_ERROR_CODE_PATTERN` (`^[a-z][a-z0-9_]*$`, `is_rest_error_code`) — a throw at definition, and a literal plainly off it (prose, uppercase, a leading digit) a type error — so prose goes in `message`; its body `loose_object({error: literal(code), ...fields})` as `.schema`; `headers` derives response headers from a body (`Retry-After`). Status and code must be literals. One `REST_*` definition per code a route or middleware answers (`REST_TABLE_NOT_FOUND`, `REST_RATE_LIMIT_EXCEEDED`, …); a code with a second body shape gets a second definition (`REST_AUTHENTICATION_REQUIRED_BOOTSTRAP`, `/account/status`'s 401 with `bootstrap_available`)
|
|
176
|
+
- `to_error_schemas(defs)` — a status map from definitions: one schema at a status maps to it, more to a `union` in list order
|
|
177
|
+
- `ErrorSchemas = Record<number, AnySchema>` — a status map, what `to_error_schemas` groups definitions into: one schema at a status, or a `union` of them
|
|
178
|
+
- `same_rest_error(a, b)` / `dedupe_rest_errors(defs)` — a definition is the same as another when it is the same object, or the same status, code, `headers`, and field schemas; a list keeps the first of each
|
|
179
|
+
- `RateLimitKey` (`rate_limiter.ts`) — `'ip' | 'account' | 'both'`
|
|
174
180
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
(`required_roles`, `required_credential_types`, `retry_after`, `detail`) are diagnostic.
|
|
179
|
-
|
|
180
|
-
Pair every schema with the `z.infer` type export.
|
|
181
|
-
|
|
182
|
-
### Three-layer error-schema merge
|
|
183
|
-
|
|
184
|
-
`merge_error_schemas(spec, middleware_errors?)` (in `http/schema_helpers.ts`)
|
|
185
|
-
merges three layers, later overrides earlier at the same status code; an
|
|
186
|
-
entry left `undefined` is absent (`strip_undefined_error_schemas`), so it
|
|
187
|
-
overrides nothing:
|
|
181
|
+
`RouteSpec.errors` and `MiddlewareSpec.errors` are lists of definitions
|
|
182
|
+
(`ReadonlyArray<RestErrorDef>`), so a Zod error entry is impossible by type,
|
|
183
|
+
and `apply_route_specs` refuses anything else at registration.
|
|
188
184
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
185
|
+
All error bodies are loose objects — intentional because multiple
|
|
186
|
+
producers (middleware + handler) can emit different extra fields at the
|
|
187
|
+
same status code, and a thrown error flattens its `data` into the body. The
|
|
188
|
+
`error` code is the contract; extra keys (`required_roles`,
|
|
189
|
+
`required_credential_types`, `retry_after`, `message`) are diagnostic.
|
|
190
|
+
|
|
191
|
+
A body's type is its definition's: `Infer<typeof REST_X.schema>`, or `RestErrorBody<C, F>`.
|
|
192
|
+
|
|
193
|
+
### The route error map
|
|
194
|
+
|
|
195
|
+
A route's declared errors are **one map**, built by
|
|
196
|
+
`resolve_route_error_map(spec, middleware_specs?)` (in `http/route_errors.ts`):
|
|
197
|
+
the union of three layers, in order, where nothing replaces anything — a
|
|
198
|
+
definition at a status another layer declares is one more branch there, and a
|
|
199
|
+
repeat (`same_rest_error`) counts once. Two shapes of one code at one status
|
|
200
|
+
(`REST_AUTHENTICATION_REQUIRED` and `REST_AUTHENTICATION_REQUIRED_BOOTSTRAP`)
|
|
201
|
+
are both kept, a union of their bodies. The result, `RouteErrorMap`, holds the
|
|
202
|
+
definitions (`defs`) and the status map they group into (`schemas`):
|
|
203
|
+
|
|
204
|
+
1. **Derived** — `derive_route_errors({method, auth, has_input?, has_params?, has_query?, rate_limit?})`, narrowed to the slots the route has:
|
|
205
|
+
- a body — `input` not null, `method` not `GET` (the input middleware skips a `GET`) → 400 `invalid_request_body`, `invalid_json_body`
|
|
206
|
+
- `params` → 400 `invalid_route_params`; `query` → 400 `invalid_query_params`
|
|
207
|
+
- `auth.actor !== 'none'` → 400 `actor_required`, `actor_not_on_account`, 500 `no_actors_on_account`, `account_vanished` — what the dispatcher's authorization phase emits on routes whose input declares `acting?: ActingActor` (per registry-time invariant 2)
|
|
208
|
+
- `auth.account === 'required'` or `auth.actor === 'required'` → 401 `authentication_required` (`REST_AUTHENTICATION_REQUIRED`), the only body the pre-authorization gate answers
|
|
209
|
+
- `auth.required_scope` → 403 `token_scope_required`; `auth.credential_types?.length` → 403 `credential_type_required`; `auth.roles?.length` → 403 `insufficient_permissions` — in the order the gates fire, each carrying what the route demanded
|
|
210
|
+
- `rate_limit` → 429 `rate_limit_exceeded` (`retry_after`, a non-negative integer of seconds)
|
|
211
|
+
- every `POST` → 415 `unsupported_content_type`
|
|
212
|
+
2. **Middleware** — the definitions of each `MiddlewareSpec` that runs on the route (`middleware_spec_applies`: its path, less its carve-outs), in list order — the body limit's 413 and 400, the origin check's 403 `forbidden_origin`, a consumer layer's own
|
|
213
|
+
3. **Explicit** — `RouteSpec.errors`, the handler's own codes (a 404, a 409, a second 401)
|
|
214
|
+
|
|
215
|
+
`resolve_app_route_error_maps(route_specs, middleware_specs)` builds every
|
|
216
|
+
route's map keyed `METHOD path` (`format_route_key`); `create_app_surface_spec`
|
|
217
|
+
builds it once and carries it as `AppSurfaceSpec.route_error_maps`, and
|
|
218
|
+
`create_app_server` hands the same maps to the DEV error check. Every reader
|
|
219
|
+
reads it: the surface (status-keyed, a status's definitions an `anyOf`), the
|
|
220
|
+
DEV error check, `assert_response_matches_spec`, error coverage
|
|
221
|
+
(`ErrorCoverageCollector`, which reads codes from `defs`), `describe_adversarial_auth`,
|
|
222
|
+
`describe_adversarial_404`, and `assert_error_schema_valid`.
|
|
223
|
+
`get_route_error_map(route_error_maps, spec)` reads a map, or without one resolves the
|
|
224
|
+
route alone; given a map with no entry for the route, it throws naming the key.
|
|
225
|
+
|
|
226
|
+
Routes typically only declare `errors` for handler-specific codes (404, 409,
|
|
227
|
+
422): what the framework answers is derived, and what a middleware layer
|
|
228
|
+
answers is the layer's.
|
|
229
|
+
|
|
230
|
+
The derived actor codes read `spec.auth.actor !== 'none'` directly — per
|
|
203
231
|
registry-time invariant 2 (`actor !== 'none' ⟺ input declares acting?: ActingActor`),
|
|
204
232
|
the auth-shape axis is the single source of truth.
|
|
205
233
|
|
|
@@ -207,9 +235,10 @@ the auth-shape axis is the single source of truth.
|
|
|
207
235
|
above is sound because the framework authors the errors at fixed
|
|
208
236
|
middleware sites — 401 from `require_auth`, 400 from
|
|
209
237
|
`create_input_validation`, 403 from `require_role` /
|
|
210
|
-
`require_credential_types`, 429 from rate limiters
|
|
211
|
-
documents the framework's
|
|
212
|
-
|
|
238
|
+
`require_credential_types`, 429 from rate limiters — and narrows each to
|
|
239
|
+
the slots that reach those sites. Auto-derivation documents the framework's
|
|
240
|
+
own emissions; consumers add their handler's codes in `RouteSpec.errors`,
|
|
241
|
+
beside them.
|
|
213
242
|
|
|
214
243
|
The same auto-derivation pattern is **not** appropriate for
|
|
215
244
|
consumer-authored inputs (or handler outputs). A consumer's spec declares
|
|
@@ -242,9 +271,9 @@ confirmation.
|
|
|
242
271
|
(input validation) and `http/surface.ts` (surface generation).
|
|
243
272
|
|
|
244
273
|
**Import `is_null_schema`, `is_void_schema`, `to_void_params`, `to_input_params`, `is_strict_object_schema`, `schema_to_surface`,
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
274
|
+
and `middleware_applies` from `http/schema_helpers.ts`, and the route error map from
|
|
275
|
+
`http/route_errors.ts`.** `http/surface.ts` only imports and re-uses them for
|
|
276
|
+
generation logic.
|
|
248
277
|
|
|
249
278
|
Key helpers:
|
|
250
279
|
|
|
@@ -257,9 +286,7 @@ Key helpers:
|
|
|
257
286
|
- `is_strict_object_schema(schema)` — detects `z.strictObject()` by checking `schema.def.catchall instanceof z.ZodNever`, or a fuz_schema `object` (not `strip_object` / `loose_object`); a fuz_schema `pipe` is read through to its first schema when no stage is a `transform` (so a refined `object` reads strict), while any Zod `ZodPipe` — even `O.pipe(O)` with no transform — reads not strict
|
|
258
287
|
- `schema_to_surface(schema, {io?, source?, on_unrepresentable?}?)` — throws first on a value of neither library (`assert_validation_schema`, naming `source`, so an assembled app's slot of neither library fails boot as registration would refuse it, not as an unwritable JSON Schema); Zod or fuz_schema → JSON Schema (`z.toJSONSchema` or fuz_schema's `to_json_schema`, by `is_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 `z.custom()`, a fuz_schema `check`) is left out or written as `{}` (`unrepresentable: 'any'`) and reported to `on_unrepresentable`; a schema with nothing describable (`{}` from a schema other than `z.unknown()` / `z.any()`) or one an emitter refuses outright throws, prefixed with `source` — so a root-level transform output (`z.unknown().transform(f)` included), `z.custom()` or `z.date()` 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
|
|
259
288
|
- `middleware_applies(mw_path, route_path)` — Hono pattern matching: `'*'`, exact, `'/api/*'` prefix (handles `prefix.slice(0, -1)` so `/api/*` also matches the bare `/api`)
|
|
260
|
-
- `middleware_spec_applies(spec, route_path)` — the layer runs on the route: its `path` applies and none of its `carve_outs` does; what
|
|
261
|
-
- `merge_error_schemas(spec, middleware_errors?)` — the three-layer merge described above
|
|
262
|
-
- `strip_undefined_error_schemas(errors)` — an error-schema map without its `undefined` entries, what the merge and `collect_middleware_errors` read each layer through
|
|
289
|
+
- `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
|
|
263
290
|
|
|
264
291
|
## Surface Generation
|
|
265
292
|
|
|
@@ -285,7 +312,7 @@ params and query on the input side (what the server accepts, so a
|
|
|
285
312
|
event params on the output side — with an `info` diagnostic (category
|
|
286
313
|
`schema`, `source` naming the route or method and side) for each schema
|
|
287
314
|
part of which is left out or written as `{}`, throws naming the same source for one
|
|
288
|
-
that can't be written,
|
|
315
|
+
that can't be written, writes each route's error map (`route_error_maps`) status by status, derives `is_mutation`
|
|
289
316
|
and `transaction` from method/spec, and surfaces RPC methods with their
|
|
290
317
|
`RouteAuth` directly (same shape on both `ActionSpec.auth` and
|
|
291
318
|
`RouteSpec.auth`, no translation step).
|
|
@@ -300,16 +327,16 @@ No side effects, no state — filters and groupings over `AppSurface`:
|
|
|
300
327
|
- `filter_protected_routes` / `filter_public_routes`
|
|
301
328
|
- `filter_role_routes` / `filter_keeper_routes` / `filter_credential_gated_routes` (any `auth.credential_types` gate — superset of keeper)
|
|
302
329
|
- `filter_routes_with_input` / `filter_routes_with_params` / `filter_routes_with_query`
|
|
303
|
-
- `format_route_key(route)` → `'METHOD /path'`
|
|
330
|
+
- `format_route_key(route)` → `'METHOD /path'`, of a surface route or a route spec — the key of the route error maps, and every `METHOD path` label
|
|
304
331
|
- `surface_auth_summary(surface)` — counts per auth bucket (`none`, `keeper`, `role`, `credential`, `authenticated`, `optional`, `other`), roles and credential channels broken out by name; multi-role / multi-channel specs count once per name. One private categorizer decides the bucket: keeper is tested before the role bucket and the general credential bucket after it — keeper is an authority _level_ and names the route, a session gate is a _channel_ restriction over the authority the route already declares (so the audit SSE stream counts under `role`)
|
|
305
332
|
|
|
306
333
|
The per-route auth predicates these filters compose over (`is_public_auth`,
|
|
307
334
|
`is_role_auth`, `is_credential_gated_auth`, `is_keeper_auth`,
|
|
308
335
|
`is_plain_authenticated_auth`, plus `needs_actor`) live
|
|
309
|
-
in `http/auth_shape.ts` next to the canonical `RouteAuth`
|
|
336
|
+
in `http/auth_shape.ts` next to the canonical `RouteAuth` type — import
|
|
310
337
|
them from there, not from this module. Same predicates back the
|
|
311
338
|
dispatcher's authorization phase, the route-spec auth-guard resolver,
|
|
312
|
-
`
|
|
339
|
+
`derive_route_errors`'s actor codes, and the testing harnesses.
|
|
313
340
|
|
|
314
341
|
Consumer code (tests, attack-surface helpers, `SurfaceExplorer.svelte`)
|
|
315
342
|
should reach for these rather than inlining `.filter` chains.
|
|
@@ -323,7 +350,7 @@ interface MiddlewareSpec {
|
|
|
323
350
|
name: string;
|
|
324
351
|
path: string; // Hono pattern — '*', exact, or '/api/*'
|
|
325
352
|
handler: MiddlewareHandler;
|
|
326
|
-
errors?:
|
|
353
|
+
errors?: ReadonlyArray<RestErrorDef>; // definitions this layer may answer with
|
|
327
354
|
}
|
|
328
355
|
```
|
|
329
356
|
|
|
@@ -355,7 +382,7 @@ Origin allowlisting for locally-running services — **not** the CSRF layer.
|
|
|
355
382
|
CSRF is handled by `SameSite: strict` on session cookies (`auth/session_middleware.ts`).
|
|
356
383
|
|
|
357
384
|
- `parse_allowed_origins(raw)` — comma-separated entries → `Result<{origins: Array<RegExp>}, {errors: Array<AllowedOriginsError>}>`; every refused entry is reported (`{kind, index, entry}`, 1-based), a blank value is `{kind: 'no_origins'}`
|
|
358
|
-
- `OriginPatternErrorKind` / `AllowedOriginsErrorKind` — the refusal kinds, wire names shared with the Rust spine; `ALLOWED_ORIGINS_ERROR_MESSAGES` the reason per kind, `format_allowed_origins_error` one refusal as a boot-error line (entry quoted and escaped)
|
|
385
|
+
- `OriginPatternErrorKind` / `AllowedOriginsErrorKind` — the refusal kinds, fuz_schema `one_of`s whose `def` is the names, wire names shared with the Rust spine; `ALLOWED_ORIGINS_ERROR_MESSAGES` the reason per kind, `format_allowed_origins_error` one refusal as a boot-error line (entry quoted and escaped)
|
|
359
386
|
- `should_allow_origin(origin, patterns)` — case-insensitive match; a value that isn't visible ASCII matches nothing
|
|
360
387
|
- `verify_request_source(allowed_patterns, carve_outs?)` — Hono handler: `Origin` present → must match allowlist or 403 `ERROR_FORBIDDEN_ORIGIN`; no `Origin` → allow through (curl, CLI, token auth is primary control). A repeated `Origin` reaches it joined (`a, b`) and is refused. A request whose path a `carve_outs` entry (`MiddlewareCarveOut`, `{path, reason}`) matches passes unchecked
|
|
361
388
|
- `is_browser_context(c)` — true when `Origin` or `Referer` is present (`!== undefined`, so empty-string counts). The bearer + daemon-token middleware discard their credential when true; twin of the Rust spine's `bearer_auth::is_browser_context`. Distinct from `verify_request_source` (allowlist gate) — this only detects browser context
|
|
@@ -567,7 +594,7 @@ auth-domain dependencies:
|
|
|
567
594
|
|
|
568
595
|
- `create_health_route_spec()` — `GET /health` (`HEALTH_PATH`), public, returns `{status: 'ok'}` (`HealthResponse`, both from `http/health_schema.ts`). Infrastructure endpoint for uptime monitors, and what `ui/backend_probe.svelte.ts` reads
|
|
569
596
|
- `create_ready_route_spec({expected, log})` — `GET /ready`, public, the deploy gate. Introspects the live DB's columns (`db/schema_ready.ts`) and compares against the committed `expected` column map: `200 {ready: true}` on match, else `503 {error: 'schema_drift' | 'db_unreachable'}`. Detailed drift logs server-side only (minimal body — no schema leak, mirrors why `/api/surface` is admin-only). Throws at assembly on an empty `expected` (fail-loud). Opt-in like `/health`; pair with `load_expected_schema(url)` — loads + URL-caches a consumer's committed `expected_schema.json` and throws on an empty map
|
|
570
|
-
- `create_server_status_route_spec({version, get_uptime_ms})` — `GET /api/server/status`, authenticated, returns `{version, uptime_ms}`
|
|
597
|
+
- `create_server_status_route_spec({version, get_uptime_ms})` — `GET /api/server/status`, authenticated, returns `{version, uptime_ms}` (`uptime_ms` a non-negative integer)
|
|
571
598
|
|
|
572
599
|
Auth-aware variants (account status, bootstrap status) live in `auth/` —
|
|
573
600
|
`http/common_routes.ts` stays generic.
|
|
@@ -588,10 +615,16 @@ table browser; the factory is domain-agnostic.
|
|
|
588
615
|
- `DELETE /tables/:name/rows/:id` — delete by PK, compared typed as `"<pk>" = $1` (twinning the Rust spine — the untyped text-format param makes PG coerce the id with the PK type's input function, so the delete index-scans and follows the column type's semantics; an uncoercible id — 22P02/22003 — is the same clean 404 as a typed miss). `RETURNING "<pk>"::text` feeds the audit trail the row's canonical PK rendering. Returns 400 if the table is excluded by policy (`ERROR_TABLE_NOT_DELETABLE`) or has no single-column PK (`ERROR_TABLE_NO_PRIMARY_KEY`), 404 if row missing (`ERROR_ROW_NOT_FOUND`) or table missing/unbrowsable (`ERROR_TABLE_NOT_FOUND`), 409 on a referencing-row refusal (pg error `23503` foreign_key_violation, or `23001` restrict_violation — PG 18+ raises the latter for `ON DELETE RESTRICT`)
|
|
589
616
|
|
|
590
617
|
Every route declares `acting?: ActingActor` on its `query` (registry-time
|
|
591
|
-
invariant 2). The
|
|
592
|
-
|
|
593
|
-
`
|
|
594
|
-
`
|
|
618
|
+
invariant 2). The routes' schemas are `@fuzdev/fuz_schema`: the queries
|
|
619
|
+
`object`s over the twin `ActingActor`, and the counts and positions they
|
|
620
|
+
answer with (`row_count`, `total`, `offset`, `limit`) non-negative integers.
|
|
621
|
+
`GET /tables/:name`'s paging params are each a `query_int`:
|
|
622
|
+
`pipe(string, regex(/^[+-]?\d+$/), transform(Number))`, then `safe_integer`
|
|
623
|
+
and its bounds, under a default — the spellings the Rust twin's
|
|
624
|
+
`str::parse::<i64>` reads, so `""`, `" 5"`, `"1e2"`, `"5.0"` and `"0x10"` are
|
|
625
|
+
refused on both. The surface writes each as a string with that `pattern`,
|
|
626
|
+
its bounds in the `description`, and notes the steps it can't say as an
|
|
627
|
+
`info` diagnostic.
|
|
595
628
|
|
|
596
629
|
**The allowlist gates everything.** `DbRouteOptions.browsable_tables` is
|
|
597
630
|
required with no "all" escape hatch — the table list shows only listed tables,
|
|
@@ -674,4 +707,4 @@ Interfaces exported for consumer use: `TableInfo`, `TableWithCount`,
|
|
|
674
707
|
- **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
|
|
675
708
|
- **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`
|
|
676
709
|
- **Input/output schemas align with SAES.** When wiring RPC via `actions/action_rpc.ts`, the same Zod types flow through unchanged (see `actions/CLAUDE.md` §Single JSON-RPC 2.0 endpoint)
|
|
677
|
-
- **Error modules are complementary, not redundant.** `http/error_schemas.ts` is
|
|
710
|
+
- **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
|