@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
|
@@ -4,8 +4,8 @@ import './assert_dev_env.js';
|
|
|
4
4
|
*
|
|
5
5
|
* Two categories:
|
|
6
6
|
* - **Structural** — validate internal consistency (error schema presence,
|
|
7
|
-
* descriptions, duplicates, middleware propagation, error
|
|
8
|
-
* error code consistency). No options needed.
|
|
7
|
+
* descriptions, duplicates, middleware propagation, every error naming a
|
|
8
|
+
* code, error code consistency). No options needed.
|
|
9
9
|
* - **Policy** — enforce security policy (sensitive routes rate-limited,
|
|
10
10
|
* no public mutations, mutation method conventions). Configurable with
|
|
11
11
|
* sensible defaults.
|
|
@@ -20,6 +20,7 @@ import { assert } from 'vitest';
|
|
|
20
20
|
import { middleware_spec_applies } from '../http/schema_helpers.js';
|
|
21
21
|
import { filter_protected_routes, filter_role_routes, filter_keeper_routes, filter_credential_gated_routes, filter_routes_with_input, filter_routes_with_params, filter_routes_with_query, filter_public_routes, format_route_key } from '../http/surface_query.js';
|
|
22
22
|
import { PROTOCOL_ACTION_METHODS } from '../actions/action_codegen.js';
|
|
23
|
+
import { ERROR_INVALID_QUERY_PARAMS, ERROR_INVALID_REQUEST_BODY, ERROR_INVALID_ROUTE_PARAMS, REST_ERROR_CODE_PATTERN, is_rest_error_code } from '../http/error_schemas.js';
|
|
23
24
|
// --- Structural invariants ---
|
|
24
25
|
/**
|
|
25
26
|
* Every protected route has 401 in `error_schemas`.
|
|
@@ -47,31 +48,34 @@ export const assert_role_routes_declare_403 = (surface) => {
|
|
|
47
48
|
}
|
|
48
49
|
};
|
|
49
50
|
/**
|
|
50
|
-
*
|
|
51
|
+
* Assert each route declares a 400 naming `code` among its branches — the
|
|
52
|
+
* code its input middleware answers when it refuses the slot.
|
|
51
53
|
*/
|
|
52
|
-
|
|
53
|
-
const routes = filter_routes_with_input(surface);
|
|
54
|
+
const assert_routes_declare_400_code = (routes, code, slot) => {
|
|
54
55
|
for (const route of routes) {
|
|
55
|
-
|
|
56
|
+
const declared = route.error_schemas?.['400'];
|
|
57
|
+
assert.ok(declared, `${format_route_key(route)} has ${slot} but missing 400 error schema`);
|
|
58
|
+
assert.ok(extract_error_consts(declared).includes(code), `${format_route_key(route)} has ${slot} but its 400 error schema does not name ${code}`);
|
|
56
59
|
}
|
|
57
60
|
};
|
|
58
61
|
/**
|
|
59
|
-
* Every route with non-null `
|
|
62
|
+
* Every route with a body — a non-null `input_schema` on a method other than
|
|
63
|
+
* `GET`, which reads no body — declares a 400 naming `invalid_request_body`.
|
|
64
|
+
*/
|
|
65
|
+
export const assert_input_routes_declare_400 = (surface) => {
|
|
66
|
+
assert_routes_declare_400_code(filter_routes_with_input(surface).filter((route) => route.method !== 'GET'), ERROR_INVALID_REQUEST_BODY, 'input');
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Every route with non-null `params_schema` declares a 400 naming `invalid_route_params`.
|
|
60
70
|
*/
|
|
61
71
|
export const assert_params_routes_declare_400 = (surface) => {
|
|
62
|
-
|
|
63
|
-
for (const route of routes) {
|
|
64
|
-
assert.ok(route.error_schemas && '400' in route.error_schemas, `${format_route_key(route)} has params but missing 400 error schema`);
|
|
65
|
-
}
|
|
72
|
+
assert_routes_declare_400_code(filter_routes_with_params(surface), ERROR_INVALID_ROUTE_PARAMS, 'params');
|
|
66
73
|
};
|
|
67
74
|
/**
|
|
68
|
-
* Every route with non-null `query_schema`
|
|
75
|
+
* Every route with non-null `query_schema` declares a 400 naming `invalid_query_params`.
|
|
69
76
|
*/
|
|
70
77
|
export const assert_query_routes_declare_400 = (surface) => {
|
|
71
|
-
|
|
72
|
-
for (const route of routes) {
|
|
73
|
-
assert.ok(route.error_schemas && '400' in route.error_schemas, `${format_route_key(route)} has query schema but missing 400 error schema`);
|
|
74
|
-
}
|
|
78
|
+
assert_routes_declare_400_code(filter_routes_with_query(surface), ERROR_INVALID_QUERY_PARAMS, 'query schema');
|
|
75
79
|
};
|
|
76
80
|
/**
|
|
77
81
|
* Every route has a non-empty description.
|
|
@@ -95,6 +99,11 @@ export const assert_no_duplicate_routes = (surface) => {
|
|
|
95
99
|
/**
|
|
96
100
|
* Every applicable middleware that declares errors must have those status codes
|
|
97
101
|
* present in the route's `error_schemas`.
|
|
102
|
+
*
|
|
103
|
+
* Holds by construction for a surface `generate_app_surface` builds: each
|
|
104
|
+
* route's error map (`resolve_route_error_map`) already unions every applying
|
|
105
|
+
* layer's definitions. It earns its place only on a surface built another
|
|
106
|
+
* way — a committed snapshot read back, or one written by hand.
|
|
98
107
|
*/
|
|
99
108
|
export const assert_middleware_errors_propagated = (surface) => {
|
|
100
109
|
const middleware_with_errors = surface.middleware.filter((m) => m.error_schemas !== null);
|
|
@@ -109,55 +118,84 @@ export const assert_middleware_errors_propagated = (surface) => {
|
|
|
109
118
|
}
|
|
110
119
|
};
|
|
111
120
|
/**
|
|
112
|
-
* Every
|
|
113
|
-
* (
|
|
121
|
+
* Every error a route or middleware layer declares names its code exactly:
|
|
122
|
+
* each body at each status (each branch of an `anyOf` or `oneOf`) is an
|
|
123
|
+
* object whose `error` is a `const` or an `enum` — what a definition built by
|
|
124
|
+
* `rest_error` writes. A bare string `error`, or a body with no `error`, is a
|
|
125
|
+
* contract a client can't key on.
|
|
114
126
|
*
|
|
115
|
-
*
|
|
116
|
-
|
|
117
|
-
|
|
127
|
+
* @throws AssertionError naming the route or layer, the status, and the body
|
|
128
|
+
*/
|
|
129
|
+
export const assert_error_codes_specific = (surface) => {
|
|
130
|
+
for (const { label, status, branch } of each_error_branch(surface)) {
|
|
131
|
+
const error_prop = get_error_property(branch);
|
|
132
|
+
assert.ok(error_prop && (typeof error_prop.const === 'string' || Array.isArray(error_prop.enum)), `${label} error schema for status ${status} does not name its code — ` +
|
|
133
|
+
`declare it with rest_error: ${JSON.stringify(branch)}`);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* Every declared `error` code is a code — `REST_ERROR_CODE_PATTERN`, a
|
|
138
|
+
* lowercase letter then lowercase letters, digits, and `_` — never prose,
|
|
139
|
+
* which belongs in `message`. `rest_error` refuses one off the pattern; this
|
|
140
|
+
* holds a surface built another way (a snapshot, a hand-written layer) to the
|
|
141
|
+
* same rule.
|
|
118
142
|
*
|
|
119
|
-
*
|
|
120
|
-
* read `.error` from error responses.
|
|
143
|
+
* @throws AssertionError naming the route or layer, the status, and the code
|
|
121
144
|
*/
|
|
122
|
-
export const
|
|
145
|
+
export const assert_error_codes_well_formed = (surface) => {
|
|
146
|
+
for (const { label, status, branch } of each_error_branch(surface)) {
|
|
147
|
+
const error_prop = get_error_property(branch);
|
|
148
|
+
if (!error_prop)
|
|
149
|
+
continue;
|
|
150
|
+
const codes = error_prop.const !== undefined
|
|
151
|
+
? [error_prop.const]
|
|
152
|
+
: Array.isArray(error_prop.enum)
|
|
153
|
+
? error_prop.enum
|
|
154
|
+
: [];
|
|
155
|
+
for (const code of codes) {
|
|
156
|
+
assert.ok(is_rest_error_code(code), `${label} error code ${JSON.stringify(code)} at status ${status} is not a code ` +
|
|
157
|
+
`(${REST_ERROR_CODE_PATTERN.source}) — put prose in \`message\``);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
/** Every body every route and middleware layer declares, one per union branch. */
|
|
162
|
+
const each_error_branch = (surface) => {
|
|
163
|
+
const out = [];
|
|
164
|
+
const visit = (label, status, schema) => {
|
|
165
|
+
const branches = get_union_branches(schema);
|
|
166
|
+
if (branches) {
|
|
167
|
+
for (const branch of branches)
|
|
168
|
+
visit(label, status, branch);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
out.push({ label, status, branch: schema });
|
|
172
|
+
};
|
|
123
173
|
for (const route of surface.routes) {
|
|
124
174
|
if (!route.error_schemas)
|
|
125
175
|
continue;
|
|
126
176
|
for (const [status, schema] of Object.entries(route.error_schemas)) {
|
|
127
|
-
|
|
177
|
+
visit(format_route_key(route), status, schema);
|
|
128
178
|
}
|
|
129
179
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
assert_branch_has_error_property(branch, route_key, status);
|
|
180
|
+
for (const mw of surface.middleware) {
|
|
181
|
+
if (!mw.error_schemas)
|
|
182
|
+
continue;
|
|
183
|
+
for (const [status, schema] of Object.entries(mw.error_schemas)) {
|
|
184
|
+
visit(`middleware '${mw.name}'`, status, schema);
|
|
136
185
|
}
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
if (typeof schema !== 'object' || schema === null)
|
|
140
|
-
return;
|
|
141
|
-
const s = schema;
|
|
142
|
-
if (s.type === 'object' && s.properties && typeof s.properties === 'object') {
|
|
143
|
-
const props = s.properties;
|
|
144
|
-
assert.ok('error' in props, `${route_key} error schema for status ${status} missing 'error' property`);
|
|
145
186
|
}
|
|
187
|
+
return out;
|
|
146
188
|
};
|
|
147
189
|
/**
|
|
148
|
-
*
|
|
149
|
-
* across routes.
|
|
150
|
-
*
|
|
151
|
-
* Extracts `const` values from error schema `error` properties (which correspond to
|
|
152
|
-
* `z.literal()` in the Zod source). Walks union branches (`anyOf` from `z.union`,
|
|
153
|
-
* `oneOf` from `z.discriminatedUnion`) so literal codes nested inside merged unions
|
|
154
|
-
* (e.g. validation 400 + actor-resolution 400) are still tracked. Flags when the
|
|
155
|
-
* same literal appears at different status codes — e.g., `ERROR_INVALID_CREDENTIALS`
|
|
156
|
-
* at both 401 and 403 would be a bug.
|
|
190
|
+
* One error code at one HTTP status: the same code declared at two statuses
|
|
191
|
+
* across the surface's routes and middleware layers fails — e.g.
|
|
192
|
+
* `invalid_credentials` at both 401 and 403 would be a bug.
|
|
157
193
|
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
194
|
+
* Reads each body's `error` `const` (what `rest_error` writes), through every
|
|
195
|
+
* branch of an `anyOf` or `oneOf` — the surface writes a status with several
|
|
196
|
+
* definitions as an `anyOf` — and nested unions within them. An `error` with
|
|
197
|
+
* no `const` (an `enum`, a bare string) is not read; `assert_error_codes_specific`
|
|
198
|
+
* refuses the bare string.
|
|
161
199
|
*/
|
|
162
200
|
export const assert_error_code_status_consistency = (surface) => {
|
|
163
201
|
// Map from error code literal → Set of status codes where it appears
|
|
@@ -194,8 +232,8 @@ export const assert_error_code_status_consistency = (surface) => {
|
|
|
194
232
|
/**
|
|
195
233
|
* Extract the `error` property's JSON Schema from a route error schema.
|
|
196
234
|
*
|
|
197
|
-
* Navigates `schema.properties.error` —
|
|
198
|
-
* `
|
|
235
|
+
* Navigates `schema.properties.error` — every error body is an object with
|
|
236
|
+
* an `error` code. Returns `null` if the schema doesn't conform.
|
|
199
237
|
*/
|
|
200
238
|
const get_error_property = (schema) => {
|
|
201
239
|
if (typeof schema !== 'object' || schema === null)
|
|
@@ -211,11 +249,11 @@ const get_error_property = (schema) => {
|
|
|
211
249
|
/**
|
|
212
250
|
* Read the branch array off a JSON Schema union, if present.
|
|
213
251
|
*
|
|
214
|
-
*
|
|
215
|
-
* `
|
|
216
|
-
* for
|
|
217
|
-
*
|
|
218
|
-
*
|
|
252
|
+
* The surface writes a status with several definitions as an `anyOf`, and a
|
|
253
|
+
* `oneOf` from a JSON Schema written another way is read the same; both are
|
|
254
|
+
* union-shaped for code extraction. Nested unions are not flattened, so
|
|
255
|
+
* every caller must recurse through the returned branches. Returns the
|
|
256
|
+
* branch array or `null` for non-union schemas.
|
|
219
257
|
*/
|
|
220
258
|
const get_union_branches = (schema) => {
|
|
221
259
|
if (typeof schema !== 'object' || schema === null)
|
|
@@ -231,11 +269,11 @@ const get_union_branches = (schema) => {
|
|
|
231
269
|
* Extract every `const` value from a JSON Schema error property, walking
|
|
232
270
|
* union branches.
|
|
233
271
|
*
|
|
234
|
-
* Looks for `schema.properties.error.const` —
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
272
|
+
* Looks for `schema.properties.error.const` — what a definition's
|
|
273
|
+
* `literal(code)` writes — and recurses into `anyOf` / `oneOf` branches, so
|
|
274
|
+
* a code in a status of several definitions is still tracked. Returns an
|
|
275
|
+
* empty array for schemas with no `const` code (an `enum`, a bare string,
|
|
276
|
+
* a non-object schema).
|
|
239
277
|
*/
|
|
240
278
|
const extract_error_consts = (schema) => {
|
|
241
279
|
const branches = get_union_branches(schema);
|
|
@@ -253,134 +291,6 @@ const extract_error_consts = (schema) => {
|
|
|
253
291
|
return [error_prop.const];
|
|
254
292
|
return [];
|
|
255
293
|
};
|
|
256
|
-
/**
|
|
257
|
-
* Check if a JSON Schema error property uses specific error codes (`const` or `enum`),
|
|
258
|
-
* not just generic `z.string()` (`{type: 'string'}`).
|
|
259
|
-
*
|
|
260
|
-
* Returns `true` for `z.literal()` (`{const: '...'}`) and `z.enum()` (`{enum: [...]}`),
|
|
261
|
-
* and for union schemas where every branch is specific. Defers to
|
|
262
|
-
* `classify_error_specificity` so the union walk stays in one place.
|
|
263
|
-
*/
|
|
264
|
-
const has_specific_error_schema = (schema) => classify_error_specificity(schema) !== 'generic';
|
|
265
|
-
/**
|
|
266
|
-
* Routes declaring 404 error schemas should use specific `z.literal()` or `z.enum()`
|
|
267
|
-
* error codes, not generic `z.string()`.
|
|
268
|
-
*
|
|
269
|
-
* A generic 404 schema (`ApiError` with `z.string()`) means the error code is
|
|
270
|
-
* unconstrained — the handler could return any string, making client error handling
|
|
271
|
-
* fragile. Routes with params (`:id`) are the primary 404 producers; their error
|
|
272
|
-
* schemas should use specific constants like `ERROR_ACCOUNT_NOT_FOUND`.
|
|
273
|
-
*
|
|
274
|
-
* Only flags routes that have `params_schema` (param-driven resource lookup) — routes
|
|
275
|
-
* declaring 404 for other reasons (e.g., bootstrap not configured) may legitimately
|
|
276
|
-
* use generic schemas.
|
|
277
|
-
*/
|
|
278
|
-
export const assert_404_schemas_use_specific_errors = (surface) => {
|
|
279
|
-
for (const route of surface.routes) {
|
|
280
|
-
if (!route.error_schemas || !('404' in route.error_schemas))
|
|
281
|
-
continue;
|
|
282
|
-
if (route.params_schema === null)
|
|
283
|
-
continue;
|
|
284
|
-
assert.ok(has_specific_error_schema(route.error_schemas['404']), `${format_route_key(route)} declares 404 with params but uses generic error schema — ` +
|
|
285
|
-
`use a specific z.literal() or z.enum() error code`);
|
|
286
|
-
}
|
|
287
|
-
};
|
|
288
|
-
/**
|
|
289
|
-
* Classify the specificity of a JSON Schema error property.
|
|
290
|
-
*
|
|
291
|
-
* - `'literal'` — `z.literal()` (`{const: '...'}`)
|
|
292
|
-
* - `'enum'` — `z.enum()` (`{enum: [...]}`)
|
|
293
|
-
* - `'generic'` — `z.string()` or unrecognized
|
|
294
|
-
*
|
|
295
|
-
* Walks union branches (`anyOf` from `z.union`, `oneOf` from
|
|
296
|
-
* `z.discriminatedUnion`) — `derive_error_schemas` emits `anyOf` when it
|
|
297
|
-
* merges multiple shapes at one status (e.g. validation 400 +
|
|
298
|
-
* actor-resolution 400), and a consumer that explicitly declares a
|
|
299
|
-
* discriminated-union error schema emits `oneOf`. Reports the **minimum**
|
|
300
|
-
* specificity across branches — a union's contract is only as tight as
|
|
301
|
-
* its loosest member.
|
|
302
|
-
*/
|
|
303
|
-
const classify_error_specificity = (schema) => {
|
|
304
|
-
const branches = get_union_branches(schema);
|
|
305
|
-
if (branches) {
|
|
306
|
-
if (branches.length === 0)
|
|
307
|
-
return 'generic';
|
|
308
|
-
let min = 'literal';
|
|
309
|
-
for (const branch of branches) {
|
|
310
|
-
const branch_specificity = classify_error_specificity(branch);
|
|
311
|
-
if (SPECIFICITY_ORDER[branch_specificity] < SPECIFICITY_ORDER[min]) {
|
|
312
|
-
min = branch_specificity;
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
return min;
|
|
316
|
-
}
|
|
317
|
-
const error_prop = get_error_property(schema);
|
|
318
|
-
if (!error_prop)
|
|
319
|
-
return 'generic';
|
|
320
|
-
if (typeof error_prop.const === 'string')
|
|
321
|
-
return 'literal';
|
|
322
|
-
if (Array.isArray(error_prop.enum))
|
|
323
|
-
return 'enum';
|
|
324
|
-
return 'generic';
|
|
325
|
-
};
|
|
326
|
-
/**
|
|
327
|
-
* Extract error code values from a JSON Schema error property.
|
|
328
|
-
*
|
|
329
|
-
* Returns the literal value or enum array, or `null` for generic schemas.
|
|
330
|
-
*
|
|
331
|
-
* For union schemas (`anyOf` / `oneOf`), collects codes from every branch
|
|
332
|
-
* (deduped). If any branch is generic, returns `null` because the union
|
|
333
|
-
* admits arbitrary strings on that branch.
|
|
334
|
-
*/
|
|
335
|
-
const extract_error_codes = (schema) => {
|
|
336
|
-
const branches = get_union_branches(schema);
|
|
337
|
-
if (branches) {
|
|
338
|
-
const codes = new Set();
|
|
339
|
-
for (const branch of branches) {
|
|
340
|
-
const branch_codes = extract_error_codes(branch);
|
|
341
|
-
if (branch_codes === null)
|
|
342
|
-
return null;
|
|
343
|
-
for (const code of branch_codes)
|
|
344
|
-
codes.add(code);
|
|
345
|
-
}
|
|
346
|
-
return [...codes];
|
|
347
|
-
}
|
|
348
|
-
const error_prop = get_error_property(schema);
|
|
349
|
-
if (!error_prop)
|
|
350
|
-
return null;
|
|
351
|
-
if (typeof error_prop.const === 'string')
|
|
352
|
-
return [error_prop.const];
|
|
353
|
-
if (Array.isArray(error_prop.enum))
|
|
354
|
-
return error_prop.enum.filter((v) => typeof v === 'string');
|
|
355
|
-
return null;
|
|
356
|
-
};
|
|
357
|
-
/**
|
|
358
|
-
* Audit error schema tightness across all routes in a surface.
|
|
359
|
-
*
|
|
360
|
-
* Reports which route x status code combinations use generic `ApiError`
|
|
361
|
-
* (`z.string()`) vs specific `z.literal()` or `z.enum()` error codes.
|
|
362
|
-
* Use the output to prioritize progressive tightening of error schemas.
|
|
363
|
-
*
|
|
364
|
-
* @returns audit entries for every route x status combination
|
|
365
|
-
*/
|
|
366
|
-
export const audit_error_schema_tightness = (surface) => {
|
|
367
|
-
const entries = [];
|
|
368
|
-
for (const route of surface.routes) {
|
|
369
|
-
if (!route.error_schemas)
|
|
370
|
-
continue;
|
|
371
|
-
for (const [status, schema] of Object.entries(route.error_schemas)) {
|
|
372
|
-
const specificity = classify_error_specificity(schema);
|
|
373
|
-
entries.push({
|
|
374
|
-
method: route.method,
|
|
375
|
-
route_path: route.path,
|
|
376
|
-
status,
|
|
377
|
-
specificity,
|
|
378
|
-
error_codes: extract_error_codes(schema)
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
return entries;
|
|
383
|
-
};
|
|
384
294
|
// --- RPC / WS structural invariants ---
|
|
385
295
|
/**
|
|
386
296
|
* Every RPC method on every endpoint has a non-empty `description`.
|
|
@@ -579,88 +489,15 @@ export const assert_keeper_routes_under_prefix = (surface, prefixes = DEFAULT_KE
|
|
|
579
489
|
assert.ok(under_prefix, `${format_route_key(route)} is keeper-protected but not under any expected prefix: ${prefixes.join(', ')}`);
|
|
580
490
|
}
|
|
581
491
|
};
|
|
582
|
-
// --- Error schema tightness assertion ---
|
|
583
|
-
/** Numeric specificity ranking for threshold comparisons. */
|
|
584
|
-
const SPECIFICITY_ORDER = {
|
|
585
|
-
literal: 2,
|
|
586
|
-
enum: 1,
|
|
587
|
-
generic: 0
|
|
588
|
-
};
|
|
589
|
-
/**
|
|
590
|
-
* Routes shipped by fuz_app whose error schemas require a tightness exemption.
|
|
591
|
-
*
|
|
592
|
-
* Currently empty — every fuz_app-shipped route (account login/password/
|
|
593
|
-
* bootstrap/signup, db health/tables/:name/tables/:name/rows/:id) was tightened
|
|
594
|
-
* in place to `z.enum([...])` / `z.literal(...)` against every emit-site error
|
|
595
|
-
* code.
|
|
596
|
-
*
|
|
597
|
-
* Kept as a forward-compatibility hook: when new stock routes ship with
|
|
598
|
-
* heterogeneous error surfaces that need an interim generic schema, add
|
|
599
|
-
* them here instead of forcing every consumer to hand-maintain the entry.
|
|
600
|
-
*
|
|
601
|
-
* Paths assume the standard `/api/account` + `/api/db` prefixes used by every
|
|
602
|
-
* fuz_app consumer. Merged into `default_error_schema_tightness.allowlist` so
|
|
603
|
-
* consumers calling `assert_error_schema_tightness` directly inherit the
|
|
604
|
-
* exemptions; the standard attack-surface suite also prepends these entries
|
|
605
|
-
* underneath any consumer-supplied allowlist so project-specific entries are
|
|
606
|
-
* additive.
|
|
607
|
-
*/
|
|
608
|
-
export const fuz_app_stock_route_tightness_allowlist = [];
|
|
609
|
-
/**
|
|
610
|
-
* Baseline error schema tightness applied by
|
|
611
|
-
* `describe_standard_attack_surface_tests` when no config is passed.
|
|
612
|
-
*
|
|
613
|
-
* Uses `min_specificity: 'enum'` (the assertion default) with `ignore_statuses`
|
|
614
|
-
* for middleware-derived status codes that are commonly generic (auth middleware
|
|
615
|
-
* produces multiple error codes at 401/403, and 429 comes from rate limiters),
|
|
616
|
-
* and `allowlist` seeded with `fuz_app_stock_route_tightness_allowlist` so
|
|
617
|
-
* fuz_app-shipped routes with heterogeneous generic schemas don't force every
|
|
618
|
-
* consumer to hand-maintain an identical allowlist. Consumers can pass a
|
|
619
|
-
* narrower config with project-specific `allowlist` entries, or pass `null`
|
|
620
|
-
* to skip the assertion entirely.
|
|
621
|
-
*/
|
|
622
|
-
export const default_error_schema_tightness = {
|
|
623
|
-
ignore_statuses: [401, 403, 429],
|
|
624
|
-
allowlist: [...fuz_app_stock_route_tightness_allowlist]
|
|
625
|
-
};
|
|
626
|
-
/**
|
|
627
|
-
* Assert that all error schemas meet a minimum specificity threshold.
|
|
628
|
-
*
|
|
629
|
-
* Calls `audit_error_schema_tightness` and fails on any entry below
|
|
630
|
-
* the configured threshold. Use `allowlist` and `ignore_statuses` to exclude
|
|
631
|
-
* known exceptions during progressive tightening.
|
|
632
|
-
*
|
|
633
|
-
* @throws AssertionError listing every route × status combination whose error
|
|
634
|
-
* schema specificity is below `min_specificity` (default `'enum'`) and is
|
|
635
|
-
* not in `allowlist` or `ignore_statuses`.
|
|
636
|
-
*/
|
|
637
|
-
export const assert_error_schema_tightness = (surface, options) => {
|
|
638
|
-
const min_specificity = options?.min_specificity ?? 'enum';
|
|
639
|
-
const ignore_statuses = new Set(options?.ignore_statuses?.map(String));
|
|
640
|
-
const allowlist = new Set(options?.allowlist);
|
|
641
|
-
const threshold = SPECIFICITY_ORDER[min_specificity];
|
|
642
|
-
const entries = audit_error_schema_tightness(surface);
|
|
643
|
-
const failures = [];
|
|
644
|
-
for (const entry of entries) {
|
|
645
|
-
if (ignore_statuses.has(entry.status))
|
|
646
|
-
continue;
|
|
647
|
-
const key = `${entry.method} ${entry.route_path}`;
|
|
648
|
-
if (allowlist.has(key))
|
|
649
|
-
continue;
|
|
650
|
-
if (SPECIFICITY_ORDER[entry.specificity] < threshold) {
|
|
651
|
-
failures.push(`${key} → ${entry.status} (${entry.specificity})`);
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
assert.ok(failures.length === 0, `Error schemas below '${min_specificity}' threshold:\n ${failures.join('\n ')}`);
|
|
655
|
-
};
|
|
656
492
|
// --- Aggregate runners ---
|
|
657
493
|
/**
|
|
658
494
|
* Run all structural invariants. Options-free — applies universally.
|
|
659
495
|
*
|
|
660
496
|
* Catches schema/surface generation bugs: missing 401/403/400 declarations,
|
|
661
497
|
* empty descriptions, duplicate routes, middleware-injected error codes
|
|
662
|
-
* unpropagated to routes
|
|
663
|
-
*
|
|
498
|
+
* unpropagated to routes (by construction on a generated surface, so a
|
|
499
|
+
* snapshot's check), an error that doesn't name its code or whose code is
|
|
500
|
+
* not one, and error codes appearing at multiple statuses.
|
|
664
501
|
*
|
|
665
502
|
* @throws AssertionError on the first invariant violation; the message names
|
|
666
503
|
* the offending route and the missing/inconsistent field.
|
|
@@ -674,9 +511,9 @@ export const assert_surface_invariants = (surface) => {
|
|
|
674
511
|
assert_descriptions_present(surface);
|
|
675
512
|
assert_no_duplicate_routes(surface);
|
|
676
513
|
assert_middleware_errors_propagated(surface);
|
|
677
|
-
|
|
514
|
+
assert_error_codes_specific(surface);
|
|
515
|
+
assert_error_codes_well_formed(surface);
|
|
678
516
|
assert_error_code_status_consistency(surface);
|
|
679
|
-
assert_404_schemas_use_specific_errors(surface);
|
|
680
517
|
};
|
|
681
518
|
/**
|
|
682
519
|
* Run all RPC / WS structural invariants. Options-free — applies
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import './assert_dev_env.js';
|
|
2
|
+
/**
|
|
3
|
+
* The UTF-8 byte length of the compact JSON of a `methods` scope over
|
|
4
|
+
* `methods`, the unit `MAX_TOKEN_SCOPE_BYTES` counts. Method order changes the
|
|
5
|
+
* document, not its length.
|
|
6
|
+
*
|
|
7
|
+
* @param methods - the scope's method names
|
|
8
|
+
* @returns the byte length of `JSON.stringify(token_scope_methods(methods))`
|
|
9
|
+
*/
|
|
10
|
+
export declare const token_scope_methods_bytes: (methods: Array<string>) => number;
|
|
11
|
+
/**
|
|
12
|
+
* Method names whose `methods` scope document is exactly `bytes` compact UTF-8
|
|
13
|
+
* bytes: `account_token_list` (so a token over it can list its own account's
|
|
14
|
+
* tokens), names `scope_cap_<i>_<filler>` while they fit, and an ASCII pad of
|
|
15
|
+
* `x`s. A multibyte `filler` makes a document far under `bytes` in UTF-16 code
|
|
16
|
+
* units. The names hold no `:` or `,`, so the printed `jsonb` text has exactly
|
|
17
|
+
* one more byte per separator.
|
|
18
|
+
*
|
|
19
|
+
* @param bytes - the compact document's size; at least that of the first name alone
|
|
20
|
+
* @param filler - the tail of every name but the first and the pad
|
|
21
|
+
* @returns distinct method names, sorted, as the Rust spine stores them
|
|
22
|
+
*/
|
|
23
|
+
export declare const token_scope_methods_at_bytes: (bytes: number, filler: string) => Array<string>;
|
|
24
|
+
//# sourceMappingURL=token_scope_fixtures.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token_scope_fixtures.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/token_scope_fixtures.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAkB7B;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,GAAI,SAAS,KAAK,CAAC,MAAM,CAAC,KAAG,MACL,CAAC;AAE/D;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,4BAA4B,GAAI,OAAO,MAAM,EAAE,QAAQ,MAAM,KAAG,KAAK,CAAC,MAAM,CAWxF,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import './assert_dev_env.js';
|
|
2
|
+
/**
|
|
3
|
+
* Token-scope documents built to a size, for the tests of
|
|
4
|
+
* `MAX_TOKEN_SCOPE_BYTES` — hono-free, so the cross-process suites import it.
|
|
5
|
+
*
|
|
6
|
+
* The cap counts UTF-8 bytes of a document's compact JSON on both spines.
|
|
7
|
+
* `token_scope_methods_at_bytes` builds the method list whose `methods`
|
|
8
|
+
* document is exactly a given size, the same list the Rust spine's tests
|
|
9
|
+
* build, so a boundary pinned on one spine is the boundary on the other.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
import { to_bytes } from '@fuzdev/fuz_util/bytes.ts';
|
|
14
|
+
import { token_scope_methods } from '../auth/token_scope.js';
|
|
15
|
+
/**
|
|
16
|
+
* The UTF-8 byte length of the compact JSON of a `methods` scope over
|
|
17
|
+
* `methods`, the unit `MAX_TOKEN_SCOPE_BYTES` counts. Method order changes the
|
|
18
|
+
* document, not its length.
|
|
19
|
+
*
|
|
20
|
+
* @param methods - the scope's method names
|
|
21
|
+
* @returns the byte length of `JSON.stringify(token_scope_methods(methods))`
|
|
22
|
+
*/
|
|
23
|
+
export const token_scope_methods_bytes = (methods) => to_bytes(JSON.stringify(token_scope_methods(methods))).length;
|
|
24
|
+
/**
|
|
25
|
+
* Method names whose `methods` scope document is exactly `bytes` compact UTF-8
|
|
26
|
+
* bytes: `account_token_list` (so a token over it can list its own account's
|
|
27
|
+
* tokens), names `scope_cap_<i>_<filler>` while they fit, and an ASCII pad of
|
|
28
|
+
* `x`s. A multibyte `filler` makes a document far under `bytes` in UTF-16 code
|
|
29
|
+
* units. The names hold no `:` or `,`, so the printed `jsonb` text has exactly
|
|
30
|
+
* one more byte per separator.
|
|
31
|
+
*
|
|
32
|
+
* @param bytes - the compact document's size; at least that of the first name alone
|
|
33
|
+
* @param filler - the tail of every name but the first and the pad
|
|
34
|
+
* @returns distinct method names, sorted, as the Rust spine stores them
|
|
35
|
+
*/
|
|
36
|
+
export const token_scope_methods_at_bytes = (bytes, filler) => {
|
|
37
|
+
const methods = ['account_token_list'];
|
|
38
|
+
for (let i = 0;; i++) {
|
|
39
|
+
const next = `scope_cap_${String(i).padStart(3, '0')}_${filler}`;
|
|
40
|
+
if (token_scope_methods_bytes([...methods, next, '']) > bytes)
|
|
41
|
+
break;
|
|
42
|
+
methods.push(next);
|
|
43
|
+
}
|
|
44
|
+
const pad = bytes - token_scope_methods_bytes([...methods, '']);
|
|
45
|
+
if (pad < 0)
|
|
46
|
+
throw new Error(`no methods document is ${bytes} bytes`);
|
|
47
|
+
methods.push('x'.repeat(pad));
|
|
48
|
+
return methods;
|
|
49
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import '../assert_dev_env.js';
|
|
2
|
-
import { Uuid } from '../../
|
|
2
|
+
import { Uuid } from '../../primitive_schemas_fuz.js';
|
|
3
3
|
import type { BackendConfig } from '../cross_backend/backend_config.js';
|
|
4
4
|
import type { FetchTransport } from './fetch_transport.js';
|
|
5
5
|
/** Input for `bootstrap()`. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"../src/lib/","sources":["../../../src/lib/testing/transports/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"../src/lib/","sources":["../../../src/lib/testing/transports/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAwB9B,OAAO,EAAE,IAAI,EAAE,MAAM,gCAAgC,CAAC;AAGtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAe3D,+BAA+B;AAC/B,MAAM,WAAW,gBAAgB;IAChC;;;;OAIG;IACH,QAAQ,CAAC,SAAS,EAAE,cAAc,CAAC;IACnC;;;;;;OAMG;IACH,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;CAC/B;AAED,0EAA0E;AAC1E,MAAM,WAAW,eAAe;IAC/B;;;;OAIG;IACH,QAAQ,CAAC,SAAS,EAAE,cAAc,CAAC;IACnC,kDAAkD;IAClD,QAAQ,CAAC,OAAO,EAAE;QAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;QAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IACnE,gDAAgD;IAChD,QAAQ,CAAC,KAAK,EAAE;QAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAA;KAAE,CAAC;IACtC,iEAAiE;IACjE,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CACxC;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,GAAU,SAAS,gBAAgB,KAAG,OAAO,CAAC,eAAe,CA8BlF,CAAC"}
|
|
@@ -18,19 +18,20 @@ import '../assert_dev_env.js';
|
|
|
18
18
|
*
|
|
19
19
|
* @module
|
|
20
20
|
*/
|
|
21
|
-
import {
|
|
22
|
-
import { Uuid } from '../../
|
|
21
|
+
import { parse, string, strip_object } from '@fuzdev/fuz_schema/schema.ts';
|
|
22
|
+
import { Uuid } from '../../primitive_schemas_fuz.js';
|
|
23
|
+
import { format_issues } from '../../schema_issues.js';
|
|
23
24
|
/**
|
|
24
25
|
* The `BootstrapOutput` envelope shape the cross-process bootstrap call
|
|
25
|
-
* cares about. Looser than the full `BootstrapOutput`
|
|
26
|
-
* `auth/
|
|
26
|
+
* cares about. Looser than the full `BootstrapOutput` schema in
|
|
27
|
+
* `auth/bootstrap_route_schema.ts` — that schema is the canonical wire shape
|
|
27
28
|
* on the server side, and this one is a structural subset the runner
|
|
28
29
|
* uses to extract the keeper identity. Kept local so cross-process
|
|
29
30
|
* testing doesn't pull the full auth-domain schema into its dep graph.
|
|
30
31
|
*/
|
|
31
|
-
const BootstrapResponse =
|
|
32
|
-
account:
|
|
33
|
-
actor:
|
|
32
|
+
const BootstrapResponse = strip_object({
|
|
33
|
+
account: strip_object({ id: Uuid, username: string }),
|
|
34
|
+
actor: strip_object({ id: Uuid })
|
|
34
35
|
});
|
|
35
36
|
/**
|
|
36
37
|
* Fire `POST {config.bootstrap_path}` and capture the keeper session.
|
|
@@ -57,14 +58,14 @@ export const bootstrap = async (options) => {
|
|
|
57
58
|
throw new Error(`bootstrap(${config.name}) failed: status=${response.status} body=${body}`);
|
|
58
59
|
}
|
|
59
60
|
const raw = await response.json();
|
|
60
|
-
const parsed = BootstrapResponse
|
|
61
|
-
if (!parsed.
|
|
62
|
-
throw new Error(`bootstrap(${config.name}) returned unexpected body: ${JSON.stringify(raw)} (${parsed.
|
|
61
|
+
const parsed = parse(BootstrapResponse, raw);
|
|
62
|
+
if (!parsed.ok) {
|
|
63
|
+
throw new Error(`bootstrap(${config.name}) returned unexpected body: ${JSON.stringify(raw)} (${format_issues(parsed.issues)})`);
|
|
63
64
|
}
|
|
64
65
|
return {
|
|
65
66
|
transport,
|
|
66
|
-
account: parsed.
|
|
67
|
-
actor: parsed.
|
|
67
|
+
account: parsed.value.account,
|
|
68
|
+
actor: parsed.value.actor,
|
|
68
69
|
cookies: transport.cookies()
|
|
69
70
|
};
|
|
70
71
|
};
|
|
@@ -16,8 +16,10 @@
|
|
|
16
16
|
import { resolve } from '$app/paths';
|
|
17
17
|
import PendingButton from '@fuzdev/fuz_ui/PendingButton.svelte';
|
|
18
18
|
import { autofocus } from '@fuzdev/fuz_ui/autofocus.svelte.ts';
|
|
19
|
+
import { is } from '@fuzdev/fuz_schema/schema.ts';
|
|
19
20
|
|
|
20
|
-
import {
|
|
21
|
+
import { USERNAME_LENGTH_MAX, USERNAME_LENGTH_MIN } from '../primitive_schemas.js';
|
|
22
|
+
import { Username } from '../primitive_schemas_fuz.js';
|
|
21
23
|
import { PASSWORD_LENGTH_MIN } from '../auth/password.js';
|
|
22
24
|
import { auth_state_context } from './auth_state.svelte.js';
|
|
23
25
|
import { FormState } from './form_state.svelte.js';
|
|
@@ -40,7 +42,7 @@
|
|
|
40
42
|
let password = $state.raw('');
|
|
41
43
|
let password_confirm = $state.raw('');
|
|
42
44
|
|
|
43
|
-
const username_valid = $derived(Username
|
|
45
|
+
const username_valid = $derived(is(Username, username));
|
|
44
46
|
const passwords_match = $derived(password === password_confirm);
|
|
45
47
|
const can_submit = $derived(
|
|
46
48
|
token.trim() &&
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BootstrapForm.svelte.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/ui/BootstrapForm.svelte"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BootstrapForm.svelte.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/ui/BootstrapForm.svelte"],"names":[],"mappings":"AA2BC,KAAK,gBAAgB,GAAI;IACxB;;;OAGG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAC/B,CAAC;AA4GH,QAAA,MAAM,aAAa,sDAAwC,CAAC;AAC5D,KAAK,aAAa,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AACtD,eAAe,aAAa,CAAC"}
|