@fuzdev/fuz_app 0.163.0 → 0.165.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 +1 -1
- package/dist/auth/account_route_schema.d.ts +3 -27
- package/dist/auth/account_route_schema.d.ts.map +1 -1
- package/dist/auth/account_route_schema.js +6 -20
- package/dist/auth/admin_action_specs.d.ts +56 -56
- 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 +18 -18
- package/dist/auth/bootstrap_route_schema.d.ts +1 -30
- package/dist/auth/bootstrap_route_schema.d.ts.map +1 -1
- package/dist/auth/bootstrap_route_schema.js +3 -8
- 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/middleware.js +4 -4
- package/dist/auth/role_grant_offer_action_specs.d.ts +2 -2
- package/dist/auth/signup_route_schema.d.ts.map +1 -1
- package/dist/auth/signup_route_schema.js +3 -7
- 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 +105 -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 +179 -0
- package/dist/http/route_error_check.d.ts.map +1 -0
- package/dist/http/route_error_check.js +283 -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 +15 -34
- package/dist/http/schema_helpers.d.ts.map +1 -1
- package/dist/http/schema_helpers.js +11 -47
- 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_fuz.d.ts +17 -3
- package/dist/primitive_schemas_fuz.d.ts.map +1 -1
- package/dist/primitive_schemas_fuz.js +13 -3
- 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 +105 -61
- 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 +20 -52
- 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 +20 -19
- package/dist/testing/assertions.d.ts +46 -14
- package/dist/testing/assertions.d.ts.map +1 -1
- package/dist/testing/assertions.js +73 -16
- package/dist/testing/attack_surface.d.ts +17 -35
- package/dist/testing/attack_surface.d.ts.map +1 -1
- package/dist/testing/attack_surface.js +36 -95
- 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/fact_serving.js +3 -3
- package/dist/testing/cross_backend/in_process_setup.d.ts +7 -3
- package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/in_process_setup.js +11 -4
- 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.map +1 -1
- package/dist/testing/cross_backend/rust_spine_consumer_surface.js +7 -1
- package/dist/testing/cross_backend/setup.d.ts +13 -0
- package/dist/testing/cross_backend/setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/setup.js +24 -7
- package/dist/testing/cross_backend/spine_suites.d.ts +3 -2
- package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_suites.js +5 -2
- package/dist/testing/cross_backend/standard.d.ts +31 -0
- package/dist/testing/cross_backend/standard.d.ts.map +1 -1
- package/dist/testing/cross_backend/standard.js +9 -3
- 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/data_exposure.d.ts +7 -0
- package/dist/testing/data_exposure.d.ts.map +1 -1
- package/dist/testing/data_exposure.js +8 -7
- package/dist/testing/error_coverage.d.ts +53 -61
- package/dist/testing/error_coverage.d.ts.map +1 -1
- package/dist/testing/error_coverage.js +86 -119
- package/dist/testing/integration.d.ts +28 -1
- package/dist/testing/integration.d.ts.map +1 -1
- package/dist/testing/integration.js +54 -29
- 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 +75 -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/middleware_gate_probes.d.ts +90 -0
- package/dist/testing/middleware_gate_probes.d.ts.map +1 -0
- package/dist/testing/middleware_gate_probes.js +179 -0
- 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 +7 -0
- package/dist/testing/round_trip.d.ts.map +1 -1
- package/dist/testing/round_trip.js +8 -5
- package/dist/testing/schema_generators.d.ts +40 -11
- package/dist/testing/schema_generators.d.ts.map +1 -1
- package/dist/testing/schema_generators.js +71 -17
- 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/transports/raw_http.d.ts +10 -2
- package/dist/testing/transports/raw_http.d.ts.map +1 -1
- package/dist/testing/transports/raw_http.js +10 -4
- package/dist/ui/CLAUDE.md +4 -2
- 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
|
@@ -12,7 +12,6 @@ import { to_error_message } from '@fuzdev/fuz_util/error.ts';
|
|
|
12
12
|
import { is_schema } from '@fuzdev/fuz_schema/schema.ts';
|
|
13
13
|
import { unwrap_schema } from '@fuzdev/fuz_schema/introspect.ts';
|
|
14
14
|
import { to_json_schema } from '@fuzdev/fuz_schema/json_schema.ts';
|
|
15
|
-
import { derive_error_schemas } from './error_schemas.js';
|
|
16
15
|
import { assert_validation_schema, parse_any, unknown_key_targets } from '../schema_issues.js';
|
|
17
16
|
/**
|
|
18
17
|
* Check if a schema is exactly `z.null()`, or a `@fuzdev/fuz_schema`
|
|
@@ -449,55 +448,20 @@ export const middleware_paths_overlap = (a, b) => {
|
|
|
449
448
|
return middleware_applies(a, base(b)) || middleware_applies(b, base(a));
|
|
450
449
|
};
|
|
451
450
|
/**
|
|
452
|
-
* Check if a middleware layer
|
|
453
|
-
* applies (`middleware_applies`)
|
|
451
|
+
* Check if a middleware layer carves a route path out: one of its
|
|
452
|
+
* `carve_outs` applies to it (`middleware_applies`), whether or not its own
|
|
453
|
+
* `path` does.
|
|
454
454
|
*
|
|
455
|
-
* @param spec - the layer's
|
|
455
|
+
* @param spec - the layer's optional `carve_outs`
|
|
456
456
|
* @param route_path - the route path to check
|
|
457
457
|
*/
|
|
458
|
-
export const
|
|
459
|
-
!(spec.carve_outs ?? []).some((carve_out) => middleware_applies(carve_out.path, route_path));
|
|
460
|
-
/**
|
|
461
|
-
* Copy an error-schema map without its entries left `undefined`, so a
|
|
462
|
-
* status declared `undefined` reads as absent: it overrides nothing beneath
|
|
463
|
-
* it in a merge.
|
|
464
|
-
*
|
|
465
|
-
* @param errors - a route's or middleware's error schemas, keyed by status
|
|
466
|
-
* @returns the entries that hold a schema
|
|
467
|
-
*/
|
|
468
|
-
export const strip_undefined_error_schemas = (errors) => {
|
|
469
|
-
const defined = {};
|
|
470
|
-
for (const [status, schema] of Object.entries(errors)) {
|
|
471
|
-
if (schema !== undefined)
|
|
472
|
-
defined[Number(status)] = schema;
|
|
473
|
-
}
|
|
474
|
-
return defined;
|
|
475
|
-
};
|
|
458
|
+
export const middleware_carves_out = (spec, route_path) => (spec.carve_outs ?? []).some((carve_out) => middleware_applies(carve_out.path, route_path));
|
|
476
459
|
/**
|
|
477
|
-
*
|
|
478
|
-
*
|
|
479
|
-
*
|
|
480
|
-
* Later layers override earlier ones for the same status code; an entry left
|
|
481
|
-
* `undefined` is absent (`strip_undefined_error_schemas`), so it leaves the
|
|
482
|
-
* layer beneath it in place.
|
|
460
|
+
* Check if a middleware layer runs on a route path: its `path` pattern
|
|
461
|
+
* applies (`middleware_applies`) and none of its `carve_outs` does
|
|
462
|
+
* (`middleware_carves_out`).
|
|
483
463
|
*
|
|
484
|
-
* @param spec - the
|
|
485
|
-
* @param
|
|
486
|
-
* @returns merged error schemas, or `null` if empty
|
|
464
|
+
* @param spec - the layer's `path` and optional `carve_outs`
|
|
465
|
+
* @param route_path - the route path to check
|
|
487
466
|
*/
|
|
488
|
-
export const
|
|
489
|
-
const derived = derive_error_schemas({
|
|
490
|
-
auth: spec.auth,
|
|
491
|
-
has_input: !is_null_schema(spec.input),
|
|
492
|
-
has_params: !!spec.params,
|
|
493
|
-
has_query: !!spec.query,
|
|
494
|
-
rate_limit: spec.rate_limit,
|
|
495
|
-
checks_content_type: spec.method === 'POST'
|
|
496
|
-
});
|
|
497
|
-
const merged = {
|
|
498
|
-
...derived,
|
|
499
|
-
...(middleware_errors && strip_undefined_error_schemas(middleware_errors)),
|
|
500
|
-
...(spec.errors && strip_undefined_error_schemas(spec.errors))
|
|
501
|
-
};
|
|
502
|
-
return Object.keys(merged).length > 0 ? merged : null;
|
|
503
|
-
};
|
|
467
|
+
export const middleware_spec_applies = (spec, route_path) => middleware_applies(spec.path, route_path) && !middleware_carves_out(spec, route_path);
|
package/dist/http/surface.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* App surface generation — JSON-serializable attack surface from route and middleware specs.
|
|
3
3
|
*
|
|
4
|
-
* Pure schema helpers (`is_null_schema`, `schema_to_surface`, `middleware_applies`,
|
|
5
|
-
* `
|
|
4
|
+
* Pure schema helpers (`is_null_schema`, `schema_to_surface`, `middleware_applies`,
|
|
5
|
+
* `middleware_spec_applies`) live in `http/schema_helpers.ts`, and each route's
|
|
6
|
+
* error map (`resolve_route_error_map`) in `http/route_errors.ts`.
|
|
6
7
|
*
|
|
7
8
|
* @module
|
|
8
9
|
*/
|
|
@@ -11,10 +12,11 @@ import type { EventSpec } from '../realtime/sse.js';
|
|
|
11
12
|
import type { MiddlewareSpec } from './middleware_spec.js';
|
|
12
13
|
import type { RouteSpec } from './route_spec.js';
|
|
13
14
|
import type { RouteAuth } from './auth_shape.js';
|
|
14
|
-
import type { RateLimitKey
|
|
15
|
+
import type { RateLimitKey } from '../rate_limiter.js';
|
|
15
16
|
import type { RpcAction } from '../actions/action_types.js';
|
|
16
17
|
import type { ActionKind } from '../actions/action_spec.js';
|
|
17
18
|
import type { ResolvedWsEndpointSpec } from '../actions/ws_endpoint_spec.js';
|
|
19
|
+
import { type RouteErrorMap } from './route_errors.js';
|
|
18
20
|
import { type Sensitivity } from '../sensitivity.js';
|
|
19
21
|
/** A route in the generated attack surface (JSON-serializable). */
|
|
20
22
|
export interface AppSurfaceRoute {
|
|
@@ -166,6 +168,12 @@ export interface AppSurfaceSpec {
|
|
|
166
168
|
surface: AppSurface;
|
|
167
169
|
route_specs: Array<RouteSpec>;
|
|
168
170
|
middleware_specs: Array<MiddlewareSpec>;
|
|
171
|
+
/**
|
|
172
|
+
* Each route's error map (`resolve_route_error_map` against `middleware_specs`),
|
|
173
|
+
* keyed `METHOD path` (`format_route_key`) — the one the surface writes, and
|
|
174
|
+
* the one the DEV error check and the test helpers read.
|
|
175
|
+
*/
|
|
176
|
+
route_error_maps: ReadonlyMap<string, RouteErrorMap>;
|
|
169
177
|
rpc_endpoints: Array<RpcEndpointSpec>;
|
|
170
178
|
ws_endpoints: Array<ResolvedWsEndpointSpec>;
|
|
171
179
|
}
|
|
@@ -191,15 +199,13 @@ export interface GenerateAppSurfaceOptions {
|
|
|
191
199
|
* it — so the surface records the exact patterns the upgrade gate matches.
|
|
192
200
|
*/
|
|
193
201
|
ws_endpoints?: ReadonlyArray<ResolvedWsEndpointSpec>;
|
|
202
|
+
/**
|
|
203
|
+
* Each route's error map, keyed `METHOD path`, when the caller has built
|
|
204
|
+
* it (`resolve_app_route_error_maps` over the same routes and middleware);
|
|
205
|
+
* resolved here otherwise.
|
|
206
|
+
*/
|
|
207
|
+
route_error_maps?: ReadonlyMap<string, RouteErrorMap>;
|
|
194
208
|
}
|
|
195
|
-
/**
|
|
196
|
-
* Collect error schemas from all middleware that applies to a route path.
|
|
197
|
-
* An entry left `undefined` is absent (`strip_undefined_error_schemas`),
|
|
198
|
-
* so it leaves an earlier layer's schema for that status in place.
|
|
199
|
-
*
|
|
200
|
-
* @returns merged middleware error schemas, or `null` if none
|
|
201
|
-
*/
|
|
202
|
-
export declare const collect_middleware_errors: (middleware: Array<MiddlewareSpec>, route_path: string) => RouteErrorSchemas | null;
|
|
203
209
|
/**
|
|
204
210
|
* Convert a `@fuzdev/fuz_schema` env schema to surface entries, one per
|
|
205
211
|
* entry in order, reading each field's `meta`: the description from its
|
|
@@ -226,7 +232,8 @@ export declare const events_to_surface: (event_specs: Array<EventSpec>, diagnost
|
|
|
226
232
|
*/
|
|
227
233
|
export declare const generate_app_surface: (options: GenerateAppSurfaceOptions) => AppSurface;
|
|
228
234
|
/**
|
|
229
|
-
* Create an `AppSurfaceSpec` — the surface bundled with its source specs
|
|
235
|
+
* Create an `AppSurfaceSpec` — the surface bundled with its source specs and
|
|
236
|
+
* each route's error map, built once and read by both.
|
|
230
237
|
*/
|
|
231
238
|
export declare const create_app_surface_spec: (options: GenerateAppSurfaceOptions) => AppSurfaceSpec;
|
|
232
239
|
//# sourceMappingURL=surface.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"surface.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/surface.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"surface.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/surface.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAoB,KAAK,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAEhF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAO7E,OAAO,EAGN,KAAK,aAAa,EAClB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAA2B,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAK9E,mEAAmE;AACnE,MAAM,WAAW,eAAe;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,SAAS,CAAC;IAChB,qBAAqB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB,mEAAmE;IACnE,WAAW,EAAE,OAAO,CAAC;IACrB,uEAAuE;IACvE,WAAW,EAAE,OAAO,CAAC;IACrB;;;;OAIG;IACH,QAAQ,EAAE,OAAO,CAAC;IAClB,oFAAoF;IACpF,cAAc,EAAE,YAAY,G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aAAa,CAc5E,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,GAC7B,aAAa,KAAK,CAAC,SAAS,CAAC,EAC7B,cAAc,KAAK,CAAC,oBAAoB,CAAC,KACvC,KAAK,CAAC,eAAe,CAQvB,CAAC;AA2BF;;;GAGG;AACH,eAAO,MAAM,oBAAoB,GAAI,SAAS,yBAAyB,KAAG,UAyIzE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,uBAAuB,GAAI,SAAS,yBAAyB,KAAG,cAa5E,CAAC"}
|
package/dist/http/surface.js
CHANGED
|
@@ -1,32 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* App surface generation — JSON-serializable attack surface from route and middleware specs.
|
|
3
3
|
*
|
|
4
|
-
* Pure schema helpers (`is_null_schema`, `schema_to_surface`, `middleware_applies`,
|
|
5
|
-
* `
|
|
4
|
+
* Pure schema helpers (`is_null_schema`, `schema_to_surface`, `middleware_applies`,
|
|
5
|
+
* `middleware_spec_applies`) live in `http/schema_helpers.ts`, and each route's
|
|
6
|
+
* error map (`resolve_route_error_map`) in `http/route_errors.ts`.
|
|
6
7
|
*
|
|
7
8
|
* @module
|
|
8
9
|
*/
|
|
9
10
|
import { get_schema_entries, get_schema_fields } from '@fuzdev/fuz_schema/introspect.ts';
|
|
10
11
|
import { is_schema, parse } from '@fuzdev/fuz_schema/schema.ts';
|
|
11
|
-
import {
|
|
12
|
+
import { to_error_schemas } from './error_schemas.js';
|
|
13
|
+
import { schema_to_surface, middleware_spec_applies, is_null_schema, is_strict_object_schema } from './schema_helpers.js';
|
|
14
|
+
import { get_route_error_map, resolve_app_route_error_maps } from './route_errors.js';
|
|
15
|
+
import { format_route_key } from './surface_query.js';
|
|
12
16
|
import { find_schema_sensitivity } from '../sensitivity.js';
|
|
13
17
|
// --- Surface generation ---
|
|
14
|
-
/**
|
|
15
|
-
* Collect error schemas from all middleware that applies to a route path.
|
|
16
|
-
* An entry left `undefined` is absent (`strip_undefined_error_schemas`),
|
|
17
|
-
* so it leaves an earlier layer's schema for that status in place.
|
|
18
|
-
*
|
|
19
|
-
* @returns merged middleware error schemas, or `null` if none
|
|
20
|
-
*/
|
|
21
|
-
export const collect_middleware_errors = (middleware, route_path) => {
|
|
22
|
-
const errors = {};
|
|
23
|
-
for (const mw of middleware) {
|
|
24
|
-
if (mw.errors && middleware_spec_applies(mw, route_path)) {
|
|
25
|
-
Object.assign(errors, strip_undefined_error_schemas(mw.errors));
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return Object.keys(errors).length > 0 ? errors : null;
|
|
29
|
-
};
|
|
30
18
|
/**
|
|
31
19
|
* Convert a `@fuzdev/fuz_schema` env schema to surface entries, one per
|
|
32
20
|
* entry in order, reading each field's `meta`: the description from its
|
|
@@ -93,6 +81,7 @@ const FUZ_SCHEMA_NOT_STRICT_INPUT_MESSAGE = 'Input schema is not a strict object
|
|
|
93
81
|
*/
|
|
94
82
|
export const generate_app_surface = (options) => {
|
|
95
83
|
const { route_specs, middleware_specs, env_schema, event_specs, rpc_endpoints, ws_endpoints } = options;
|
|
84
|
+
const route_error_maps = options.route_error_maps ?? resolve_app_route_error_maps(route_specs, middleware_specs);
|
|
96
85
|
const diagnostics = [];
|
|
97
86
|
const to_surface = create_to_surface(diagnostics);
|
|
98
87
|
// Spec-level diagnostics: check for non-strict input schemas
|
|
@@ -114,9 +103,7 @@ export const generate_app_surface = (options) => {
|
|
|
114
103
|
let mw_error_schemas = null;
|
|
115
104
|
if (m.errors) {
|
|
116
105
|
const schemas = {};
|
|
117
|
-
for (const [status, schema] of Object.entries(m.errors)) {
|
|
118
|
-
if (schema === undefined)
|
|
119
|
-
continue;
|
|
106
|
+
for (const [status, schema] of Object.entries(to_error_schemas(m.errors))) {
|
|
120
107
|
const json_schema = to_surface(schema, 'output', `middleware ${m.name} errors.${status}`);
|
|
121
108
|
if (json_schema !== null) {
|
|
122
109
|
schemas[status] = json_schema;
|
|
@@ -139,23 +126,19 @@ export const generate_app_surface = (options) => {
|
|
|
139
126
|
const applicable_middleware = middleware_specs
|
|
140
127
|
.filter((m) => middleware_spec_applies(m, r.path))
|
|
141
128
|
.map((m) => m.name);
|
|
142
|
-
const route =
|
|
143
|
-
//
|
|
144
|
-
const mw_errors = collect_middleware_errors(middleware_specs, r.path);
|
|
145
|
-
const merged_errors = merge_error_schemas(r, mw_errors);
|
|
129
|
+
const route = format_route_key(r);
|
|
130
|
+
// the route's error map: derived, middleware, and explicit, unioned
|
|
146
131
|
let error_schemas = null;
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
schemas[status] = json_schema;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
if (Object.keys(schemas).length > 0) {
|
|
156
|
-
error_schemas = schemas;
|
|
132
|
+
const schemas = {};
|
|
133
|
+
for (const [status, schema] of Object.entries(get_route_error_map(route_error_maps, r).schemas)) {
|
|
134
|
+
const json_schema = to_surface(schema, 'output', `${route} errors.${status}`);
|
|
135
|
+
if (json_schema !== null) {
|
|
136
|
+
schemas[status] = json_schema;
|
|
157
137
|
}
|
|
158
138
|
}
|
|
139
|
+
if (Object.keys(schemas).length > 0) {
|
|
140
|
+
error_schemas = schemas;
|
|
141
|
+
}
|
|
159
142
|
return {
|
|
160
143
|
method: r.method,
|
|
161
144
|
path: r.path,
|
|
@@ -217,14 +200,18 @@ export const generate_app_surface = (options) => {
|
|
|
217
200
|
};
|
|
218
201
|
};
|
|
219
202
|
/**
|
|
220
|
-
* Create an `AppSurfaceSpec` — the surface bundled with its source specs
|
|
203
|
+
* Create an `AppSurfaceSpec` — the surface bundled with its source specs and
|
|
204
|
+
* each route's error map, built once and read by both.
|
|
221
205
|
*/
|
|
222
206
|
export const create_app_surface_spec = (options) => {
|
|
223
|
-
const
|
|
207
|
+
const route_error_maps = options.route_error_maps ??
|
|
208
|
+
resolve_app_route_error_maps(options.route_specs, options.middleware_specs);
|
|
209
|
+
const surface = generate_app_surface({ ...options, route_error_maps });
|
|
224
210
|
return {
|
|
225
211
|
surface,
|
|
226
212
|
route_specs: options.route_specs,
|
|
227
213
|
middleware_specs: options.middleware_specs,
|
|
214
|
+
route_error_maps,
|
|
228
215
|
rpc_endpoints: options.rpc_endpoints ?? [],
|
|
229
216
|
ws_endpoints: options.ws_endpoints ? [...options.ws_endpoints] : []
|
|
230
217
|
};
|
|
@@ -39,8 +39,17 @@ export declare const filter_routes_with_input: (surface: AppSurface) => Array<Ap
|
|
|
39
39
|
export declare const filter_routes_with_params: (surface: AppSurface) => Array<AppSurfaceRoute>;
|
|
40
40
|
/** Filter routes that have a non-null query schema. */
|
|
41
41
|
export declare const filter_routes_with_query: (surface: AppSurface) => Array<AppSurfaceRoute>;
|
|
42
|
-
/**
|
|
43
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Format a route as `'METHOD /path'` (e.g. `'GET /health'`): a surface route or
|
|
44
|
+
* a route spec, its path the template. The key of a route in a map of route
|
|
45
|
+
* error maps (`resolve_app_route_error_maps`).
|
|
46
|
+
*
|
|
47
|
+
* @param route - the route's method and path template
|
|
48
|
+
*/
|
|
49
|
+
export declare const format_route_key: (route: {
|
|
50
|
+
readonly method: string;
|
|
51
|
+
readonly path: string;
|
|
52
|
+
}) => string;
|
|
44
53
|
/**
|
|
45
54
|
* Summarize route auth distribution across the surface.
|
|
46
55
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"surface_query.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/surface_query.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAUhE,6DAA6D;AAC7D,eAAO,MAAM,uBAAuB,GAAI,SAAS,UAAU,KAAG,KAAK,CAAC,eAAe,CAC7B,CAAC;AAEvD,2EAA2E;AAC3E,eAAO,MAAM,oBAAoB,GAAI,SAAS,UAAU,KAAG,KA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,eAAO,MAAM,8BAA8B,GAAI,SAAS,UAAU,KAAG,KAAK,CAAC,eAAe,CAC3B,CAAC;AAsChE,uDAAuD;AACvD,eAAO,MAAM,wBAAwB,GAAI,SAAS,UAAU,KAAG,KAAK,CAAC,eAAe,CAC9B,CAAC;AAEvD,wDAAwD;AACxD,eAAO,MAAM,yBAAyB,GAAI,SAAS,UAAU,KAAG,KAAK,CAAC,eAAe,CAC9B,CAAC;AAExD,uDAAuD;AACvD,eAAO,MAAM,wBAAwB,GAAI,SAAS,UAAU,KAAG,KAAK,CAAC,eAAe,CAC9B,CAAC;AAEvD;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,GAAI,OAAO;IACvC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACtB,KAAG,MAAyC,CAAC;AAE9C;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,oBAAoB,GAChC,SAAS,UAAU,KACjB;IACF,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1B,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CAsCd,CAAC"}
|
|
@@ -54,7 +54,13 @@ export const filter_routes_with_input = (surface) => surface.routes.filter((r) =
|
|
|
54
54
|
export const filter_routes_with_params = (surface) => surface.routes.filter((r) => r.params_schema !== null);
|
|
55
55
|
/** Filter routes that have a non-null query schema. */
|
|
56
56
|
export const filter_routes_with_query = (surface) => surface.routes.filter((r) => r.query_schema !== null);
|
|
57
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* Format a route as `'METHOD /path'` (e.g. `'GET /health'`): a surface route or
|
|
59
|
+
* a route spec, its path the template. The key of a route in a map of route
|
|
60
|
+
* error maps (`resolve_app_route_error_maps`).
|
|
61
|
+
*
|
|
62
|
+
* @param route - the route's method and path template
|
|
63
|
+
*/
|
|
58
64
|
export const format_route_key = (route) => `${route.method} ${route.path}`;
|
|
59
65
|
/**
|
|
60
66
|
* Summarize route auth distribution across the surface.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `@fuzdev/fuz_schema` twins of the Zod `bounded_string`, `Username`,
|
|
3
|
-
* `Email`, `Uuid`, `UuidWithDefault` (`primitive_schemas.ts`), and
|
|
3
|
+
* `Email`, `Uuid`, `UuidWithDefault`, `FactHashSchema` (`primitive_schemas.ts`), and
|
|
4
4
|
* `ActingActor` (`http/auth_shape.ts`), under the same names, for schemas
|
|
5
5
|
* written in fuz_schema; `UsernameCanonical`, the username an output carries;
|
|
6
6
|
* `UsernameProvided`, the username login and lookup take; `Timestamp`, a
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
* have no Zod twin.
|
|
9
9
|
*
|
|
10
10
|
* The output type is shared: the Zod `Uuid` outputs fuz_schema's
|
|
11
|
-
* `Branded<string, 'Uuid'>` too,
|
|
12
|
-
* the other's is taken.
|
|
11
|
+
* `Branded<string, 'Uuid'>` too, and both `FactHashSchema`s output fuz_util's
|
|
12
|
+
* `FactHash`, so a value parsed by either twin goes where the other's is taken.
|
|
13
13
|
*
|
|
14
14
|
* Both twins have one grammar, RFC 9562's read case-insensitively as its §4
|
|
15
15
|
* says, the max UUID included, and the Rust spine's: every input gets the same
|
|
@@ -133,6 +133,20 @@ export type UuidWithDefault = Infer<typeof UuidWithDefault>;
|
|
|
133
133
|
*/
|
|
134
134
|
export declare const Timestamp: PipeSchema<string, import("@fuzdev/fuz_schema/schema.ts").Schema<string, string, "string", undefined>>;
|
|
135
135
|
export type Timestamp = Infer<typeof Timestamp>;
|
|
136
|
+
/**
|
|
137
|
+
* A `blake3:`-prefixed fact hash on the wire, the twin of the Zod
|
|
138
|
+
* `FactHashSchema`: `FACT_HASH_EXACT`, its output fuz_util's `FactHash`, which
|
|
139
|
+
* `fact_hash_bytes`, `fact_hash_stream`, and `FactStore` take. The twins agree
|
|
140
|
+
* on every input, and their JSON Schema is the same `pattern`.
|
|
141
|
+
*
|
|
142
|
+
* @nodocs
|
|
143
|
+
*/
|
|
144
|
+
export declare const FactHashSchema: import("@fuzdev/fuz_schema/schema.ts").Schema<import("@fuzdev/fuz_schema/schema.ts").Branded<string, "FactHash">, 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">)[]> & {
|
|
145
|
+
readonly '~types'?: {
|
|
146
|
+
readonly input: string;
|
|
147
|
+
readonly first: import("@fuzdev/fuz_schema/schema.ts").Schema<string, string, "string", undefined>;
|
|
148
|
+
} | undefined;
|
|
149
|
+
};
|
|
136
150
|
/** A BLAKE3 hex hash's grammar: 64 lowercase hex characters (256-bit output). */
|
|
137
151
|
export declare const BLAKE3_HASH_REGEX: RegExp;
|
|
138
152
|
/** The message of a string off `BLAKE3_HASH_REGEX`. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"primitive_schemas_fuz.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/primitive_schemas_fuz.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,EAUN,MAAM,EAKN,KAAK,KAAK,EACV,KAAK,UAAU,EACf,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"primitive_schemas_fuz.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/primitive_schemas_fuz.ts"],"names":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AA6B,CAAC;AACpD,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,SAAS,CAAC,CAAC;AAEhD;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc;;;;;CAA0D,CAAC;AAEtF,iFAAiF;AACjF,eAAO,MAAM,iBAAiB,QAAmB,CAAC;AAElD,uDAAuD;AACvD,eAAO,MAAM,mBAAmB,sDAAsD,CAAC;AAEvF;;;GAGG;AACH,eAAO,MAAM,UAAU,wGAAuE,CAAC;AAC/F,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AAElD,wDAAwD;AACxD,eAAO,MAAM,wBAAwB,0HACmF,CAAC;AAEzH;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW;;;;;GAAkE,CAAC;AAC3F,cAAc;AACd,MAAM,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `@fuzdev/fuz_schema` twins of the Zod `bounded_string`, `Username`,
|
|
3
|
-
* `Email`, `Uuid`, `UuidWithDefault` (`primitive_schemas.ts`), and
|
|
3
|
+
* `Email`, `Uuid`, `UuidWithDefault`, `FactHashSchema` (`primitive_schemas.ts`), and
|
|
4
4
|
* `ActingActor` (`http/auth_shape.ts`), under the same names, for schemas
|
|
5
5
|
* written in fuz_schema; `UsernameCanonical`, the username an output carries;
|
|
6
6
|
* `UsernameProvided`, the username login and lookup take; `Timestamp`, a
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
* have no Zod twin.
|
|
9
9
|
*
|
|
10
10
|
* The output type is shared: the Zod `Uuid` outputs fuz_schema's
|
|
11
|
-
* `Branded<string, 'Uuid'>` too,
|
|
12
|
-
* the other's is taken.
|
|
11
|
+
* `Branded<string, 'Uuid'>` too, and both `FactHashSchema`s output fuz_util's
|
|
12
|
+
* `FactHash`, so a value parsed by either twin goes where the other's is taken.
|
|
13
13
|
*
|
|
14
14
|
* Both twins have one grammar, RFC 9562's read case-insensitively as its §4
|
|
15
15
|
* says, the max UUID included, and the Rust spine's: every input gets the same
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
*/
|
|
23
23
|
import { meta } from '@fuzdev/fuz_schema/meta.ts';
|
|
24
24
|
import { brand, check, iso_datetime, max_length, message, min_length, optional, pipe, regex, string, to_lower_case, transform, uuid, with_default_fn } from '@fuzdev/fuz_schema/schema.ts';
|
|
25
|
+
import { FACT_HASH_EXACT } from '@fuzdev/fuz_util/hash_schemas.ts';
|
|
25
26
|
import { create_uuid, EMAIL_LENGTH_MAX, EMAIL_LENGTH_MESSAGE, EMAIL_REGEX, is_email_within_length_max, USERNAME_LENGTH_MAX, USERNAME_LENGTH_MIN, USERNAME_PROVIDED_LENGTH_MAX, USERNAME_REGEX } from './primitive_schemas.js';
|
|
26
27
|
/**
|
|
27
28
|
* A string schema whose length is bounded in UTF-16 code units, the twin of
|
|
@@ -117,6 +118,15 @@ export const UuidWithDefault = with_default_fn(Uuid, create_uuid);
|
|
|
117
118
|
* branded, unlike the Zod `Datetime`.
|
|
118
119
|
*/
|
|
119
120
|
export const Timestamp = pipe(string, iso_datetime);
|
|
121
|
+
/**
|
|
122
|
+
* A `blake3:`-prefixed fact hash on the wire, the twin of the Zod
|
|
123
|
+
* `FactHashSchema`: `FACT_HASH_EXACT`, its output fuz_util's `FactHash`, which
|
|
124
|
+
* `fact_hash_bytes`, `fact_hash_stream`, and `FactStore` take. The twins agree
|
|
125
|
+
* on every input, and their JSON Schema is the same `pattern`.
|
|
126
|
+
*
|
|
127
|
+
* @nodocs
|
|
128
|
+
*/
|
|
129
|
+
export const FactHashSchema = brand(pipe(string, regex(FACT_HASH_EXACT)), 'FactHash');
|
|
120
130
|
/** A BLAKE3 hex hash's grammar: 64 lowercase hex characters (256-bit output). */
|
|
121
131
|
export const BLAKE3_HASH_REGEX = /^[0-9a-f]{64}$/;
|
|
122
132
|
/** The message of a string off `BLAKE3_HASH_REGEX`. */
|
package/dist/rate_limiter.d.ts
CHANGED
|
@@ -24,6 +24,19 @@
|
|
|
24
24
|
* @module
|
|
25
25
|
*/
|
|
26
26
|
import type { Context } from 'hono';
|
|
27
|
+
import { type Infer } from '@fuzdev/fuz_schema/schema.ts';
|
|
28
|
+
/**
|
|
29
|
+
* Rate limit key type — declares what a route or RPC action's rate limiter
|
|
30
|
+
* is keyed on.
|
|
31
|
+
*
|
|
32
|
+
* - `'ip'` — per-IP rate limiting (login, bootstrap, password change, signup)
|
|
33
|
+
* - `'account'` — per-account rate limiting. On REST auth routes the key is
|
|
34
|
+
* the submitted identifier (login). On RPC actions (post-auth) the key is
|
|
35
|
+
* the resolved actor id (`request_context.actor.id`) — separate namespace.
|
|
36
|
+
* - `'both'` — both keys.
|
|
37
|
+
*/
|
|
38
|
+
export declare const RateLimitKey: import("@fuzdev/fuz_schema/schema.ts").Schema<"account" | "ip" | "both", "account" | "ip" | "both", "one_of", readonly ["ip", "account", "both"]>;
|
|
39
|
+
export type RateLimitKey = Infer<typeof RateLimitKey>;
|
|
27
40
|
/**
|
|
28
41
|
* Default tracked-key cap: bounds worst-case memory under key-enumeration
|
|
29
42
|
* attacks (an attacker rotating source IPs cannot grow the backing map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rate_limiter.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/rate_limiter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"rate_limiter.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/rate_limiter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,EAAU,KAAK,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAK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G;IACH,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAUxB;;;;;;OAMG;IACH,OAAO,CAAC,GAAG,GAAE,MAAmB,GAAG,IAAI;IAcvC;;;;OAIG;IACH,OAAO,IAAI,IAAI;CAMf;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,oBAAoB,GAChC,SAAS,WAAW,GAAG,IAAI,EAC3B,KAAK,MAAM,GAAG,IAAI,EAClB,MAAK,MAAmB,KACtB,sBAGF,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,GAC5B,SAAS,WAAW,GAAG,IAAI,EAC3B,KAAK,MAAM,GAAG,IAAI,EAClB,UAAU,uBAAuB,KAC/B,OAAO,CAAC,sBAAsB,CAGhC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAAI,UAAU,OAAO,CAAC,kBAAkB,CAAC,KAAG,WAE3E,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B,GAAI,GAAG,OAAO,EAAE,aAAa,MAAM,KAAG,QAM9E,CAAC"}
|
package/dist/rate_limiter.js
CHANGED
|
@@ -24,8 +24,20 @@
|
|
|
24
24
|
* @module
|
|
25
25
|
*/
|
|
26
26
|
import { LruMap } from '@fuzdev/fuz_util/lru_map.ts';
|
|
27
|
-
import {
|
|
27
|
+
import { one_of } from '@fuzdev/fuz_schema/schema.ts';
|
|
28
|
+
import { REST_RATE_LIMIT_EXCEEDED } from './http/error_schemas.js';
|
|
28
29
|
import { PERIODIC_INTERVAL_MS_MAX } from './periodic.js';
|
|
30
|
+
/**
|
|
31
|
+
* Rate limit key type — declares what a route or RPC action's rate limiter
|
|
32
|
+
* is keyed on.
|
|
33
|
+
*
|
|
34
|
+
* - `'ip'` — per-IP rate limiting (login, bootstrap, password change, signup)
|
|
35
|
+
* - `'account'` — per-account rate limiting. On REST auth routes the key is
|
|
36
|
+
* the submitted identifier (login). On RPC actions (post-auth) the key is
|
|
37
|
+
* the resolved actor id (`request_context.actor.id`) — separate namespace.
|
|
38
|
+
* - `'both'` — both keys.
|
|
39
|
+
*/
|
|
40
|
+
export const RateLimitKey = one_of(['ip', 'account', 'both']);
|
|
29
41
|
/**
|
|
30
42
|
* Default tracked-key cap: bounds worst-case memory under key-enumeration
|
|
31
43
|
* attacks (an attacker rotating source IPs cannot grow the backing map
|
|
@@ -593,4 +605,10 @@ export const create_rate_limiter = (options) => {
|
|
|
593
605
|
* @param retry_after - seconds until the client should retry
|
|
594
606
|
* @returns a 429 Response
|
|
595
607
|
*/
|
|
596
|
-
export const rate_limit_exceeded_response = (c, retry_after) =>
|
|
608
|
+
export const rate_limit_exceeded_response = (c, retry_after) => {
|
|
609
|
+
const body = { error: REST_RATE_LIMIT_EXCEEDED.code, retry_after };
|
|
610
|
+
return c.json(body, {
|
|
611
|
+
status: REST_RATE_LIMIT_EXCEEDED.status,
|
|
612
|
+
headers: REST_RATE_LIMIT_EXCEEDED.headers(body)
|
|
613
|
+
});
|
|
614
|
+
};
|
package/dist/schema_issues.d.ts
CHANGED
|
@@ -131,20 +131,38 @@ export declare const format_issues: (issues: ReadonlyArray<AnyIssue>) => string;
|
|
|
131
131
|
*/
|
|
132
132
|
export declare const is_schema_validation_error: (err: unknown) => err is z.ZodError | SchemaError;
|
|
133
133
|
/**
|
|
134
|
-
* A validation issue as an error
|
|
135
|
-
* library
|
|
136
|
-
* text of the issue. `to_wire_issues` builds it
|
|
134
|
+
* A `@fuzdev/fuz_schema` `loose_object`: a validation issue as an error
|
|
135
|
+
* response carries it, for either schema library — fuz_schema's `SchemaIssue`
|
|
136
|
+
* as JSON, with `message` the text of the issue. `to_wire_issues` builds it
|
|
137
|
+
* from either library's issues.
|
|
137
138
|
*
|
|
138
139
|
* Loose: a client reads it, and a newer server may add fields.
|
|
139
140
|
*/
|
|
140
|
-
export declare const WireIssue:
|
|
141
|
-
|
|
142
|
-
path:
|
|
143
|
-
expected:
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
},
|
|
147
|
-
|
|
141
|
+
export declare const WireIssue: Schema<{
|
|
142
|
+
message: string;
|
|
143
|
+
path: (string | number)[];
|
|
144
|
+
expected: string;
|
|
145
|
+
kind: string;
|
|
146
|
+
received: string;
|
|
147
|
+
} & Record<string, unknown>, {
|
|
148
|
+
message: string;
|
|
149
|
+
path: (string | number)[];
|
|
150
|
+
expected: string;
|
|
151
|
+
kind: string;
|
|
152
|
+
received: string;
|
|
153
|
+
} & Record<string, unknown>, "loose_object", {
|
|
154
|
+
/** The fuz_schema kind of the check that failed, or `unknown_key` / `missing_key`. */
|
|
155
|
+
kind: Schema<string, string, "string", undefined>;
|
|
156
|
+
/** Keys from the root value to the one that failed, outermost first. */
|
|
157
|
+
path: Schema<(string | number)[], (string | number)[], "array", Schema<string | number, string | number, "union", readonly [Schema<string, string, "string", undefined>, Schema<number, number, "number", undefined>]>>;
|
|
158
|
+
/** Describes what was expected, as fuz_schema writes it. */
|
|
159
|
+
expected: Schema<string, string, "string", undefined>;
|
|
160
|
+
/** The type of the value that failed: `'null'`, `'array'`, `'NaN'`, `'Infinity'`, `'-Infinity'`, or its `typeof`. */
|
|
161
|
+
received: Schema<string, string, "string", undefined>;
|
|
162
|
+
/** The issue as text: `format_issue` for a fuz_schema issue, Zod's own message for a Zod one. */
|
|
163
|
+
message: Schema<string, string, "string", undefined>;
|
|
164
|
+
}>;
|
|
165
|
+
export type WireIssue = Infer<typeof WireIssue>;
|
|
148
166
|
/**
|
|
149
167
|
* A failed parse's issues as `WireIssue`s, whichever library made them.
|
|
150
168
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema_issues.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/schema_issues.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,
|
|
1
|
+
{"version":3,"file":"schema_issues.d.ts","sourceRoot":"../src/lib/","sources":["../src/l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D;;IAE5D,qHAAqH;;IAErH,iGAAiG;;EAEhG,CAAC;AACH,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,SAAS,CAAC,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,eAAO,MAAM,cAAc,GAC1B,QAAQ,aAAa,CAAC,QAAQ,CAAC,EAC/B,OAAO,OAAO,KACZ,KAAK,CAAC,SAAS,CAgBjB,CAAC"}
|
package/dist/schema_issues.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* @module
|
|
11
11
|
*/
|
|
12
12
|
import { z } from 'zod';
|
|
13
|
-
import { format_issue, is_schema, parse, SchemaError } from '@fuzdev/fuz_schema/schema.ts';
|
|
13
|
+
import { array, format_issue, is_schema, loose_object, number, parse, SchemaError, string, union } from '@fuzdev/fuz_schema/schema.ts';
|
|
14
14
|
/**
|
|
15
15
|
* Whether `value` is a Zod schema. Zod's `instanceof` reads the schema's
|
|
16
16
|
* traits, so a schema made by another copy of Zod is one too.
|
|
@@ -149,23 +149,24 @@ export const format_issues = (issues) => {
|
|
|
149
149
|
*/
|
|
150
150
|
export const is_schema_validation_error = (err) => err instanceof z.ZodError || err instanceof SchemaError;
|
|
151
151
|
/**
|
|
152
|
-
* A validation issue as an error
|
|
153
|
-
* library
|
|
154
|
-
* text of the issue. `to_wire_issues` builds it
|
|
152
|
+
* A `@fuzdev/fuz_schema` `loose_object`: a validation issue as an error
|
|
153
|
+
* response carries it, for either schema library — fuz_schema's `SchemaIssue`
|
|
154
|
+
* as JSON, with `message` the text of the issue. `to_wire_issues` builds it
|
|
155
|
+
* from either library's issues.
|
|
155
156
|
*
|
|
156
157
|
* Loose: a client reads it, and a newer server may add fields.
|
|
157
158
|
*/
|
|
158
|
-
export const WireIssue =
|
|
159
|
+
export const WireIssue = loose_object({
|
|
159
160
|
/** The fuz_schema kind of the check that failed, or `unknown_key` / `missing_key`. */
|
|
160
|
-
kind:
|
|
161
|
+
kind: string,
|
|
161
162
|
/** Keys from the root value to the one that failed, outermost first. */
|
|
162
|
-
path:
|
|
163
|
+
path: array(union([string, number])),
|
|
163
164
|
/** Describes what was expected, as fuz_schema writes it. */
|
|
164
|
-
expected:
|
|
165
|
+
expected: string,
|
|
165
166
|
/** The type of the value that failed: `'null'`, `'array'`, `'NaN'`, `'Infinity'`, `'-Infinity'`, or its `typeof`. */
|
|
166
|
-
received:
|
|
167
|
+
received: string,
|
|
167
168
|
/** The issue as text: `format_issue` for a fuz_schema issue, Zod's own message for a Zod one. */
|
|
168
|
-
message:
|
|
169
|
+
message: string
|
|
169
170
|
});
|
|
170
171
|
/**
|
|
171
172
|
* A failed parse's issues as `WireIssue`s, whichever library made them.
|