@fuzdev/fuz_app 0.152.0 → 0.154.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/CLAUDE.md +14 -11
- package/dist/actions/action_rpc.js +3 -3
- package/dist/actions/action_types.d.ts +3 -3
- package/dist/actions/broadcast_api.d.ts +0 -6
- package/dist/actions/broadcast_api.d.ts.map +1 -1
- package/dist/actions/connection_closer.d.ts +14 -15
- package/dist/actions/connection_closer.d.ts.map +1 -1
- package/dist/actions/connection_closer.js +13 -13
- package/dist/actions/perform_action.d.ts +5 -1
- package/dist/actions/perform_action.d.ts.map +1 -1
- package/dist/actions/perform_action.js +57 -19
- package/dist/actions/register_action_ws.d.ts +6 -5
- package/dist/actions/register_action_ws.d.ts.map +1 -1
- package/dist/actions/register_action_ws.js +5 -6
- package/dist/auth/CLAUDE.md +44 -14
- package/dist/auth/account_actions.d.ts +2 -2
- package/dist/auth/account_actions.js +6 -6
- package/dist/auth/account_routes.js +9 -9
- package/dist/auth/admin_actions.d.ts +2 -1
- package/dist/auth/admin_actions.d.ts.map +1 -1
- package/dist/auth/admin_actions.js +21 -20
- package/dist/auth/audit_emitter.d.ts +111 -64
- package/dist/auth/audit_emitter.d.ts.map +1 -1
- package/dist/auth/audit_emitter.js +130 -55
- package/dist/auth/audit_log_queries.d.ts +9 -10
- package/dist/auth/audit_log_queries.d.ts.map +1 -1
- package/dist/auth/audit_log_queries.js +13 -10
- package/dist/auth/audit_log_routes.js +2 -2
- package/dist/auth/audit_log_schema.d.ts +6 -1
- package/dist/auth/audit_log_schema.d.ts.map +1 -1
- package/dist/auth/bootstrap_account.d.ts +4 -3
- package/dist/auth/bootstrap_account.d.ts.map +1 -1
- package/dist/auth/bootstrap_account.js +4 -3
- package/dist/auth/bootstrap_routes.js +2 -2
- package/dist/auth/cell_action_helpers.d.ts +3 -2
- package/dist/auth/cell_action_helpers.d.ts.map +1 -1
- package/dist/auth/cell_action_helpers.js +9 -10
- package/dist/auth/cell_actions.js +6 -6
- package/dist/auth/cell_data_schema.d.ts +5 -0
- package/dist/auth/cell_data_schema.d.ts.map +1 -1
- package/dist/auth/cell_data_schema.js +5 -0
- package/dist/auth/cell_field_actions.js +2 -2
- package/dist/auth/cell_grant_actions.js +2 -2
- package/dist/auth/cell_item_actions.js +3 -3
- package/dist/auth/deps.d.ts +12 -10
- package/dist/auth/deps.d.ts.map +1 -1
- package/dist/auth/middleware.js +1 -1
- package/dist/auth/request_context.d.ts +5 -10
- package/dist/auth/request_context.d.ts.map +1 -1
- package/dist/auth/request_context.js +10 -9
- package/dist/auth/role_grant_offer_actions.d.ts +11 -8
- package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_actions.js +57 -41
- package/dist/auth/self_service_role_actions.d.ts +6 -5
- package/dist/auth/self_service_role_actions.d.ts.map +1 -1
- package/dist/auth/self_service_role_actions.js +17 -6
- package/dist/auth/session_cookie.d.ts +4 -4
- package/dist/auth/session_cookie.d.ts.map +1 -1
- package/dist/auth/session_cookie.js +0 -1
- package/dist/auth/session_middleware.d.ts +8 -5
- package/dist/auth/session_middleware.d.ts.map +1 -1
- package/dist/auth/session_middleware.js +10 -7
- package/dist/auth/signup_routes.js +6 -6
- package/dist/auth/standard_rpc_actions.d.ts +3 -2
- package/dist/auth/standard_rpc_actions.d.ts.map +1 -1
- package/dist/auth/standard_rpc_actions.js +3 -2
- package/dist/db/CLAUDE.md +10 -1
- package/dist/db/create_db.d.ts +18 -1
- package/dist/db/create_db.d.ts.map +1 -1
- package/dist/db/create_db.js +15 -4
- package/dist/db/db.d.ts +27 -0
- package/dist/db/db.d.ts.map +1 -1
- package/dist/db/db.js +26 -0
- package/dist/db/db_checkout_error.d.ts +36 -0
- package/dist/db/db_checkout_error.d.ts.map +1 -0
- package/dist/db/db_checkout_error.js +48 -0
- package/dist/db/db_pg.d.ts +83 -5
- package/dist/db/db_pg.d.ts.map +1 -1
- package/dist/db/db_pg.js +119 -9
- package/dist/db/pg_error.d.ts +4 -0
- package/dist/db/pg_error.d.ts.map +1 -1
- package/dist/db/pg_error.js +13 -3
- package/dist/dev/setup.d.ts +4 -2
- package/dist/dev/setup.d.ts.map +1 -1
- package/dist/dev/setup.js +12 -5
- package/dist/env/env_schemas.d.ts +41 -0
- package/dist/env/env_schemas.d.ts.map +1 -0
- package/dist/env/env_schemas.js +55 -0
- package/dist/env/load.d.ts +23 -15
- package/dist/env/load.d.ts.map +1 -1
- package/dist/env/load.js +38 -22
- package/dist/hono_context.d.ts +36 -6
- package/dist/hono_context.d.ts.map +1 -1
- package/dist/hono_context.js +29 -2
- package/dist/http/CLAUDE.md +11 -10
- package/dist/http/db_routes.d.ts +7 -12
- package/dist/http/db_routes.d.ts.map +1 -1
- package/dist/http/db_routes.js +32 -17
- package/dist/http/error_schemas.d.ts +12 -0
- package/dist/http/error_schemas.d.ts.map +1 -1
- package/dist/http/error_schemas.js +12 -0
- package/dist/http/jsonrpc_errors.d.ts +10 -0
- package/dist/http/jsonrpc_errors.d.ts.map +1 -1
- package/dist/http/jsonrpc_errors.js +14 -0
- package/dist/http/jsonrpc_helpers.d.ts +4 -0
- package/dist/http/jsonrpc_helpers.d.ts.map +1 -1
- package/dist/http/jsonrpc_helpers.js +8 -1
- package/dist/http/route_spec.d.ts +4 -4
- package/dist/http/route_spec.d.ts.map +1 -1
- package/dist/http/route_spec.js +20 -3
- package/dist/http/schema_helpers.d.ts +21 -0
- package/dist/http/schema_helpers.d.ts.map +1 -1
- package/dist/http/schema_helpers.js +38 -0
- package/dist/http/surface.d.ts +13 -9
- package/dist/http/surface.d.ts.map +1 -1
- package/dist/http/surface.js +22 -18
- package/dist/realtime/audit_log_sse.d.ts +2 -2
- package/dist/realtime/audit_log_sse.js +2 -2
- package/dist/schema_meta.d.ts +4 -2
- package/dist/schema_meta.d.ts.map +1 -1
- package/dist/schema_meta.js +4 -2
- package/dist/sensitivity.d.ts +34 -1
- package/dist/sensitivity.d.ts.map +1 -1
- package/dist/sensitivity.js +32 -2
- package/dist/server/app_backend.d.ts +25 -1
- package/dist/server/app_backend.d.ts.map +1 -1
- package/dist/server/app_backend.js +16 -3
- package/dist/server/app_error_handler.d.ts +30 -0
- package/dist/server/app_error_handler.d.ts.map +1 -0
- package/dist/server/app_error_handler.js +41 -0
- package/dist/server/app_server.d.ts +7 -6
- package/dist/server/app_server.d.ts.map +1 -1
- package/dist/server/app_server.js +6 -2
- package/dist/server/env.d.ts +55 -28
- package/dist/server/env.d.ts.map +1 -1
- package/dist/server/env.js +46 -29
- package/dist/testing/CLAUDE.md +23 -17
- package/dist/testing/app_server.js +2 -2
- package/dist/testing/audit_drift_guard.d.ts.map +1 -1
- package/dist/testing/audit_drift_guard.js +2 -0
- package/dist/testing/auth_apps.d.ts.map +1 -1
- package/dist/testing/auth_apps.js +2 -2
- package/dist/testing/cross_backend/conformance_case.d.ts +2 -0
- package/dist/testing/cross_backend/conformance_case.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_case.js +8 -0
- package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_table.js +24 -7
- package/dist/testing/cross_backend/default_backend_configs.d.ts +4 -0
- package/dist/testing/cross_backend/default_backend_configs.d.ts.map +1 -1
- package/dist/testing/cross_backend/default_backend_configs.js +7 -0
- package/dist/testing/cross_backend/rust_spine_stub_backend_config.d.ts +11 -0
- package/dist/testing/cross_backend/rust_spine_stub_backend_config.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_server_core.d.ts +1 -1
- package/dist/testing/cross_backend/ts_spine_backend_config.d.ts +15 -11
- package/dist/testing/cross_backend/ts_spine_backend_config.d.ts.map +1 -1
- package/dist/testing/cross_backend/ts_spine_backend_config.js +3 -12
- package/dist/testing/daemon_token_rotation.d.ts +4 -14
- package/dist/testing/daemon_token_rotation.d.ts.map +1 -1
- package/dist/testing/daemon_token_rotation.js +0 -12
- package/dist/testing/db.d.ts.map +1 -1
- package/dist/testing/db.js +7 -3
- package/dist/testing/middleware.d.ts.map +1 -1
- package/dist/testing/middleware.js +2 -2
- package/dist/testing/rpc_helpers.d.ts +19 -0
- package/dist/testing/rpc_helpers.d.ts.map +1 -1
- package/dist/testing/rpc_helpers.js +25 -2
- package/dist/testing/schema_parity.d.ts +1 -1
- package/dist/testing/stubs.d.ts +2 -2
- package/dist/testing/stubs.d.ts.map +1 -1
- package/dist/testing/stubs.js +2 -2
- package/dist/testing/surface_invariants.js +1 -1
- package/dist/testing/ws_round_trip.d.ts.map +1 -1
- package/dist/testing/ws_round_trip.js +3 -3
- package/dist/zod.d.ts +9 -0
- package/dist/zod.d.ts.map +1 -1
- package/dist/zod.js +1 -1
- package/package.json +6 -10
|
@@ -135,6 +135,10 @@ export const to_jsonrpc_params = (input) => {
|
|
|
135
135
|
* `method` as absent — so `{id, method: 123, result}` is a response on both
|
|
136
136
|
* sides. The `result` / `error` exclusive-or refuses a frame carrying both.
|
|
137
137
|
*
|
|
138
|
+
* A `request` carries the frame as given — validated, never re-built — so
|
|
139
|
+
* `params` reaches the action's input schema with every own key the client
|
|
140
|
+
* sent, `__proto__` included, as on the GET path and the Rust twin.
|
|
141
|
+
*
|
|
138
142
|
* Every `invalid` is `invalid_request`. Its `id` is the frame's own when the
|
|
139
143
|
* frame is an object carrying a string or number one, else `null` — a
|
|
140
144
|
* non-object frame (an array included) has none. A refused request envelope
|
|
@@ -176,5 +180,8 @@ export const classify_jsonrpc_message = (json) => {
|
|
|
176
180
|
error: jsonrpc_error_messages.invalid_request(dev_only({ issues: parsed.error.issues }))
|
|
177
181
|
};
|
|
178
182
|
}
|
|
179
|
-
|
|
183
|
+
// the frame itself, validated — not Zod's rebuilt copy, which drops an own
|
|
184
|
+
// `__proto__` key from `params`, so `{"__proto__": …}` would reach the
|
|
185
|
+
// action as `{}` and pass a void or strict input the Rust twin refuses
|
|
186
|
+
return { kind: 'request', request: frame };
|
|
180
187
|
};
|
|
@@ -67,10 +67,10 @@ export type RouteMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
|
67
67
|
/**
|
|
68
68
|
* Per-request deps provided by the framework to route handlers.
|
|
69
69
|
*
|
|
70
|
-
* Audit writes
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
70
|
+
* Audit writes run through `AppDeps.audit.emit(ctx, input)` (see
|
|
71
|
+
* `auth/audit_emitter.ts`). It writes a success row in the route's
|
|
72
|
+
* transaction when one is open and a failure row on the pool it closes over,
|
|
73
|
+
* so a refused attempt's row survives the rollback.
|
|
74
74
|
*
|
|
75
75
|
* Routes whose body manages its own transaction (signup, bootstrap)
|
|
76
76
|
* declare `transaction: false` on the spec, which makes `route.db` the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route_spec.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/route_spec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAW,IAAI,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AACtE,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"route_spec.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/route_spec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAW,IAAI,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AACtE,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAEtC,OAAO,EACN,KAAK,iBAAi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G;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACxF,wBAAgB,eAAe,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC;AA6L5D;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GAAI,KAAK,IAAI,EAAE,OAAO,KAAK,CAAC,cAAc,CAAC,KAAG,IAIhF,CAAC;AAsGF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,eAAO,MAAM,iBAAiB,GAC7B,KAAK,IAAI,EACT,OAAO,KAAK,CAAC,SAAS,CAAC,EACvB,qBAAqB,iBAAiB,EACtC,KAAK,MAAM,EACX,IAAI,EAAE,EACN,YAAY,oBAAoB,KAC9B,IAsEF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAI,QAAQ,MAAM,EAAE,OAAO,KAAK,CAAC,SAAS,CAAC,KAAG,KAAK,CAAC,SAAS,CAK3F,CAAC"}
|
package/dist/http/route_spec.js
CHANGED
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
* @module
|
|
14
14
|
*/
|
|
15
15
|
import { DEV } from 'esm-env';
|
|
16
|
-
import {
|
|
16
|
+
import { is_db_checkout_error } from '../db/db_checkout_error.js';
|
|
17
|
+
import { ERROR_INVALID_JSON_BODY, ERROR_INVALID_REQUEST_BODY, ERROR_INVALID_ROUTE_PARAMS, ERROR_INVALID_QUERY_PARAMS, ERROR_SERVICE_UNAVAILABLE, ERROR_UNSUPPORTED_CONTENT_TYPE } from './error_schemas.js';
|
|
17
18
|
import { is_post_content_type_refused } from './simple_request.js';
|
|
18
19
|
import { jsonrpc_error_code_to_http_status, jsonrpc_error_code_to_name, dev_only, to_thrown_jsonrpc_error } from './jsonrpc_errors.js';
|
|
19
20
|
import { is_null_schema, merge_error_schemas } from './schema_helpers.js';
|
|
@@ -140,14 +141,18 @@ const create_query_validation = (query_schema) => {
|
|
|
140
141
|
const is_internal_error_body = (body) => body !== null &&
|
|
141
142
|
typeof body === 'object' &&
|
|
142
143
|
body.error === 'internal_error';
|
|
144
|
+
/** Whether a JSON body is the catch layer's failed-checkout `{error: 'service_unavailable'}`. */
|
|
145
|
+
const is_service_unavailable_body = (body) => body !== null &&
|
|
146
|
+
typeof body === 'object' &&
|
|
147
|
+
body.error === ERROR_SERVICE_UNAVAILABLE;
|
|
143
148
|
/**
|
|
144
149
|
* Wrap a handler with DEV-only output and error validation.
|
|
145
150
|
*
|
|
146
151
|
* In development, validates 2xx JSON responses against the output schema
|
|
147
152
|
* and non-2xx responses against declared error schemas. Wraps the error
|
|
148
153
|
* catch layer, so the body built from a thrown error is validated too — except
|
|
149
|
-
* a 500 `internal_error
|
|
150
|
-
*
|
|
154
|
+
* a 500 `internal_error` and a failed checkout's 503 `service_unavailable`,
|
|
155
|
+
* which the catch layer can answer on any route and so are always accepted.
|
|
151
156
|
* Logs an error for mismatches and returns the response unchanged —
|
|
152
157
|
* does not throw. Non-JSON responses (SSE, binary) are skipped. In
|
|
153
158
|
* production, returns the handler unchanged.
|
|
@@ -179,6 +184,9 @@ const wrap_output_validation = (handler, output_schema, error_schemas, log) => {
|
|
|
179
184
|
// misreport a schema problem the route can't fix
|
|
180
185
|
if (response.status === 500 && is_internal_error_body(body))
|
|
181
186
|
return response;
|
|
187
|
+
// the same for a failed pool checkout's 503, which any route can answer
|
|
188
|
+
if (response.status === 503 && is_service_unavailable_body(body))
|
|
189
|
+
return response;
|
|
182
190
|
const result = schema.safeParse(body);
|
|
183
191
|
if (!result.success) {
|
|
184
192
|
const label = response.ok
|
|
@@ -206,6 +214,9 @@ export const apply_middleware_specs = (app, specs) => {
|
|
|
206
214
|
* fuz_app, recognized by its brand (`to_thrown_jsonrpc_error`) — and maps it
|
|
207
215
|
* to a flat REST `ApiError` body (`{error: <reason>, message?, ...rest_data}`)
|
|
208
216
|
* at the matching HTTP status.
|
|
217
|
+
* A failed pool checkout (`DbCheckoutError`) answers the flat 503
|
|
218
|
+
* `{error: 'service_unavailable'}` with no `message`, byte for byte the Rust
|
|
219
|
+
* spine's `db_unavailable_response`.
|
|
209
220
|
* Catches anything else, a foreign error class carrying a JSON-RPC `code`
|
|
210
221
|
* included, and maps to `{error: 'internal_error', message?}`
|
|
211
222
|
* at 500 (`message` populated only in DEV). Existing handlers that return
|
|
@@ -235,6 +246,12 @@ const wrap_error_catch = (handler, log) => {
|
|
|
235
246
|
return await handler(c, next);
|
|
236
247
|
}
|
|
237
248
|
catch (err) {
|
|
249
|
+
// a failed pool checkout is the database unavailable: the flat 503 the
|
|
250
|
+
// Rust spine's `db_unavailable_response` answers, no message
|
|
251
|
+
if (is_db_checkout_error(err)) {
|
|
252
|
+
log.error('pool checkout failed:', err);
|
|
253
|
+
return c.json({ error: ERROR_SERVICE_UNAVAILABLE }, 503);
|
|
254
|
+
}
|
|
238
255
|
// recognized by brand, so a second fuz_app copy's error maps too
|
|
239
256
|
const thrown = to_thrown_jsonrpc_error(err);
|
|
240
257
|
if (thrown) {
|
|
@@ -59,6 +59,27 @@ export declare const to_void_params: (raw_params: unknown) => unknown;
|
|
|
59
59
|
* @returns the value to run `input.safeParse` on
|
|
60
60
|
*/
|
|
61
61
|
export declare const to_input_params: (input: z.ZodType, raw_params: unknown) => unknown;
|
|
62
|
+
/**
|
|
63
|
+
* Check whether a parsed JSON value holds an own `__proto__` key in any
|
|
64
|
+
* object, at any depth — what the dispatcher refuses in a request's `params`
|
|
65
|
+
* (`ERROR_PARAMS_PROTO_KEY`).
|
|
66
|
+
*
|
|
67
|
+
* `JSON.parse` defines `"__proto__"` as an ordinary own key, but the first
|
|
68
|
+
* plain assignment that copies it (`target[key] = value`, as any shallow copy
|
|
69
|
+
* or merge loop does) hits the prototype setter instead, so stored JSON
|
|
70
|
+
* carrying one is a prototype-pollution sink for whoever reads it back. An
|
|
71
|
+
* own `constructor` or `prototype` key is inert on a plain object and is not
|
|
72
|
+
* checked.
|
|
73
|
+
*
|
|
74
|
+
* Walks with an explicit stack rather than recursion: `JSON.parse` accepts
|
|
75
|
+
* nesting deep enough to overflow the call stack, and the walk is linear in
|
|
76
|
+
* the value's nodes, which the request body limit bounds. The Rust spine's
|
|
77
|
+
* `fuz_http::json_has_own_proto_key` is the twin.
|
|
78
|
+
*
|
|
79
|
+
* @param value - a value as `JSON.parse` produced it
|
|
80
|
+
* @returns whether any object in `value` has an own `__proto__` key
|
|
81
|
+
*/
|
|
82
|
+
export declare const json_has_own_proto_key: (value: unknown) => boolean;
|
|
62
83
|
/**
|
|
63
84
|
* `schema.safeParse(value)`, except that keys the schema doesn't declare are
|
|
64
85
|
* dropped rather than refused — the forward-compatible read of a payload a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema_helpers.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/schema_helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAEN,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,MAAM,oBAAoB,CAAC;AAE5B;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,OAAsC,CAAC;AAE1F;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,OAAsC,CAAC;AAE1F;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,cAAc,GAAI,YAAY,OAAO,KAAG,OAUpD,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,eAAe,GAAI,O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OAAO,KAAG,OACe,CAAC;AAE5E;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,OAQrD,CAAC;AAoBF;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,EAAE,YAAY,MAAM,KAAG,OAQxE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,GAAI,GAAG,MAAM,EAAE,GAAG,MAAM,KAAG,OAM/D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,GACnC,MAAM;IACL,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,CAAC,EAAE,aAAa,CAAC;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,IAAI,CAAC;CACtE,EACD,YAAY,MAAM,KAChB,OAE0F,CAAC;AAE9F;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,GAC/B,MAAM;IACL,MAAM,EAAE,WAAW,CAAC;IACpB,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC;IACrB,KAAK,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC;IACpB,UAAU,CAAC,EAAE,YAAY,CAAC;IAC1B,MAAM,CAAC,EAAE,iBAAiB,CAAC;CAC3B,EACD,oBAAoB,iBAAiB,GAAG,IAAI,KAC1C,iBAAiB,GAAG,IAWtB,CAAC"}
|
|
@@ -66,6 +66,44 @@ export const to_void_params = (raw_params) => {
|
|
|
66
66
|
* @returns the value to run `input.safeParse` on
|
|
67
67
|
*/
|
|
68
68
|
export const to_input_params = (input, raw_params) => is_void_schema(input) ? to_void_params(raw_params) : (raw_params ?? {});
|
|
69
|
+
/**
|
|
70
|
+
* Check whether a parsed JSON value holds an own `__proto__` key in any
|
|
71
|
+
* object, at any depth — what the dispatcher refuses in a request's `params`
|
|
72
|
+
* (`ERROR_PARAMS_PROTO_KEY`).
|
|
73
|
+
*
|
|
74
|
+
* `JSON.parse` defines `"__proto__"` as an ordinary own key, but the first
|
|
75
|
+
* plain assignment that copies it (`target[key] = value`, as any shallow copy
|
|
76
|
+
* or merge loop does) hits the prototype setter instead, so stored JSON
|
|
77
|
+
* carrying one is a prototype-pollution sink for whoever reads it back. An
|
|
78
|
+
* own `constructor` or `prototype` key is inert on a plain object and is not
|
|
79
|
+
* checked.
|
|
80
|
+
*
|
|
81
|
+
* Walks with an explicit stack rather than recursion: `JSON.parse` accepts
|
|
82
|
+
* nesting deep enough to overflow the call stack, and the walk is linear in
|
|
83
|
+
* the value's nodes, which the request body limit bounds. The Rust spine's
|
|
84
|
+
* `fuz_http::json_has_own_proto_key` is the twin.
|
|
85
|
+
*
|
|
86
|
+
* @param value - a value as `JSON.parse` produced it
|
|
87
|
+
* @returns whether any object in `value` has an own `__proto__` key
|
|
88
|
+
*/
|
|
89
|
+
export const json_has_own_proto_key = (value) => {
|
|
90
|
+
const stack = [value];
|
|
91
|
+
while (stack.length > 0) {
|
|
92
|
+
const current = stack.pop();
|
|
93
|
+
if (typeof current !== 'object' || current === null)
|
|
94
|
+
continue;
|
|
95
|
+
if (Array.isArray(current)) {
|
|
96
|
+
for (const item of current)
|
|
97
|
+
stack.push(item);
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
if (Object.hasOwn(current, '__proto__'))
|
|
101
|
+
return true;
|
|
102
|
+
for (const item of Object.values(current))
|
|
103
|
+
stack.push(item);
|
|
104
|
+
}
|
|
105
|
+
return false;
|
|
106
|
+
};
|
|
69
107
|
/**
|
|
70
108
|
* `schema.safeParse(value)`, except that keys the schema doesn't declare are
|
|
71
109
|
* dropped rather than refused — the forward-compatible read of a payload a
|
package/dist/http/surface.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @module
|
|
8
8
|
*/
|
|
9
|
-
import {
|
|
9
|
+
import { type AnySchema } from '@fuzdev/fuz_schema/schema.ts';
|
|
10
10
|
import type { EventSpec } from '../realtime/sse.js';
|
|
11
11
|
import type { MiddlewareSpec } from './middleware_spec.js';
|
|
12
12
|
import type { RouteSpec } from './route_spec.js';
|
|
@@ -15,7 +15,7 @@ import type { RateLimitKey, RouteErrorSchemas } from './error_schemas.js';
|
|
|
15
15
|
import type { RpcAction } from '../actions/action_types.js';
|
|
16
16
|
import type { ActionKind } from '../actions/action_spec.js';
|
|
17
17
|
import type { ResolvedWsEndpointSpec } from '../actions/ws_endpoint_spec.js';
|
|
18
|
-
import type
|
|
18
|
+
import { type Sensitivity } from '../sensitivity.js';
|
|
19
19
|
/** A route in the generated attack surface (JSON-serializable). */
|
|
20
20
|
export interface AppSurfaceRoute {
|
|
21
21
|
method: string;
|
|
@@ -62,7 +62,7 @@ export interface AppSurfaceMiddleware {
|
|
|
62
62
|
export interface AppSurfaceEnv {
|
|
63
63
|
name: string;
|
|
64
64
|
description: string;
|
|
65
|
-
/** Sensitivity level from
|
|
65
|
+
/** Sensitivity level from `meta(schema, {sensitivity})`. `null` when not sensitive. */
|
|
66
66
|
sensitivity: Sensitivity | null;
|
|
67
67
|
has_default: boolean;
|
|
68
68
|
optional: boolean;
|
|
@@ -178,7 +178,8 @@ export interface RpcEndpointSpec {
|
|
|
178
178
|
export interface GenerateAppSurfaceOptions {
|
|
179
179
|
route_specs: Array<RouteSpec>;
|
|
180
180
|
middleware_specs: Array<MiddlewareSpec>;
|
|
181
|
-
|
|
181
|
+
/** A `@fuzdev/fuz_schema` object schema of the app's env vars, such as `BaseServerEnv`. */
|
|
182
|
+
env_schema?: AnySchema;
|
|
182
183
|
event_specs?: Array<EventSpec>;
|
|
183
184
|
rpc_endpoints?: Array<RpcEndpointSpec>;
|
|
184
185
|
/**
|
|
@@ -198,13 +199,16 @@ export interface GenerateAppSurfaceOptions {
|
|
|
198
199
|
*/
|
|
199
200
|
export declare const collect_middleware_errors: (middleware: Array<MiddlewareSpec>, route_path: string) => RouteErrorSchemas | null;
|
|
200
201
|
/**
|
|
201
|
-
* Convert env schema to surface entries
|
|
202
|
-
*
|
|
203
|
-
* the
|
|
202
|
+
* Convert a `@fuzdev/fuz_schema` env schema to surface entries, one per
|
|
203
|
+
* entry in order, reading each field's `meta`: the description from its
|
|
204
|
+
* layers (`get_schema_fields`), and the fail-safe `find_schema_sensitivity`
|
|
205
|
+
* for secrets. `optional` and `has_default` are what a parse of `undefined`
|
|
206
|
+
* does: accepted, and accepted with a value other than `undefined`.
|
|
204
207
|
*
|
|
205
|
-
* @param schema -
|
|
208
|
+
* @param schema - an object schema (under any wrappers) with `meta` on its fields
|
|
209
|
+
* @throws TypeError if `schema` is not an object schema
|
|
206
210
|
*/
|
|
207
|
-
export declare const env_schema_to_surface: (schema:
|
|
211
|
+
export declare const env_schema_to_surface: (schema: AnySchema) => Array<AppSurfaceEnv>;
|
|
208
212
|
/**
|
|
209
213
|
* Convert SSE event specs to surface entries.
|
|
210
214
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"surface.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/surface.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"surface.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/surface.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAS,KAAK,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAGrE,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;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE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AC,CAAC;CAC1B;AAED,0CAA0C;AAC1C,MAAM,WAAW,yBAAyB;IACzC,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;IAC9B,gBAAgB,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;IACxC,2FAA2F;IAC3F,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;IAC/B,aAAa,CAAC,EAAE,KAAK,CAAC,eAAe,CAAC,CAAC;IACvC;;;;;;;OAOG;IACH,YAAY,CAAC,EAAE,aAAa,CAAC,sBAAsB,CAAC,CAAC;CACrD;AAID;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,GACrC,YAAY,KAAK,CAAC,cAAc,CAAC,EACjC,YAAY,MAAM,KAChB,iBAAiB,GAAG,IAQtB,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,qBAAqB,GAAI,QAAQ,SAAS,KAAG,KAAK,CAAC,aAAa,CAc5E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,aAAa,KAAK,CAAC,SAAS,CAAC,KAAG,KAAK,CAAC,eAAe,CAOtF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,oBAAoB,GAAI,SAAS,yBAAyB,KAAG,UA4HzE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,uBAAuB,GAAI,SAAS,yBAAyB,KAAG,cAS5E,CAAC"}
|
package/dist/http/surface.js
CHANGED
|
@@ -6,9 +6,11 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @module
|
|
8
8
|
*/
|
|
9
|
+
import { get_schema_entries, get_schema_fields } from '@fuzdev/fuz_schema/introspect.ts';
|
|
10
|
+
import { parse } from '@fuzdev/fuz_schema/schema.ts';
|
|
9
11
|
import { z } from 'zod';
|
|
10
12
|
import { schema_to_surface, middleware_spec_applies, merge_error_schemas, is_null_schema, is_strict_object_schema } from './schema_helpers.js';
|
|
11
|
-
import {
|
|
13
|
+
import { find_schema_sensitivity } from '../sensitivity.js';
|
|
12
14
|
// --- Surface generation ---
|
|
13
15
|
/**
|
|
14
16
|
* Collect error schemas from all middleware that applies to a route path.
|
|
@@ -25,27 +27,29 @@ export const collect_middleware_errors = (middleware, route_path) => {
|
|
|
25
27
|
return Object.keys(errors).length > 0 ? errors : null;
|
|
26
28
|
};
|
|
27
29
|
/**
|
|
28
|
-
* Convert env schema to surface entries
|
|
29
|
-
*
|
|
30
|
-
* the
|
|
30
|
+
* Convert a `@fuzdev/fuz_schema` env schema to surface entries, one per
|
|
31
|
+
* entry in order, reading each field's `meta`: the description from its
|
|
32
|
+
* layers (`get_schema_fields`), and the fail-safe `find_schema_sensitivity`
|
|
33
|
+
* for secrets. `optional` and `has_default` are what a parse of `undefined`
|
|
34
|
+
* does: accepted, and accepted with a value other than `undefined`.
|
|
31
35
|
*
|
|
32
|
-
* @param schema -
|
|
36
|
+
* @param schema - an object schema (under any wrappers) with `meta` on its fields
|
|
37
|
+
* @throws TypeError if `schema` is not an object schema
|
|
33
38
|
*/
|
|
34
39
|
export const env_schema_to_surface = (schema) => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const field = field_schema;
|
|
38
|
-
const undef_result = field.safeParse(undefined);
|
|
39
|
-
entries.push({
|
|
40
|
-
name,
|
|
41
|
-
// read through wrappers — a `.meta()` under `.optional()` is not on the outer schema
|
|
42
|
-
description: schema_meta_value(field, 'description') ?? '',
|
|
43
|
-
sensitivity: schema_sensitivity(field) ?? null,
|
|
44
|
-
has_default: undef_result.success && undef_result.data !== undefined,
|
|
45
|
-
optional: undef_result.success
|
|
46
|
-
});
|
|
40
|
+
if (!get_schema_entries(schema)) {
|
|
41
|
+
throw new TypeError(`env_schema must be an object schema, got '${schema.kind}'`);
|
|
47
42
|
}
|
|
48
|
-
return
|
|
43
|
+
return get_schema_fields(schema).map((field) => {
|
|
44
|
+
const undef_result = parse(field.schema, undefined);
|
|
45
|
+
return {
|
|
46
|
+
name: field.name,
|
|
47
|
+
description: field.description ?? '',
|
|
48
|
+
sensitivity: find_schema_sensitivity(field.schema) ?? null,
|
|
49
|
+
has_default: undef_result.ok && undef_result.value !== undefined,
|
|
50
|
+
optional: undef_result.ok
|
|
51
|
+
};
|
|
52
|
+
});
|
|
49
53
|
};
|
|
50
54
|
/**
|
|
51
55
|
* Convert SSE event specs to surface entries.
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* `SseRegistry` to `ConnectionCloser`, and a registry added to the
|
|
8
8
|
* backend's `deps.connection_closer` is closed by every revocation: the
|
|
9
9
|
* handlers' own post-commit closes (`queue_connection_close`), and the one
|
|
10
|
-
* audit listener on that closer (`create_revocation_guard`), which
|
|
11
|
-
*
|
|
10
|
+
* audit listener on that closer (`create_revocation_guard`), which repeats
|
|
11
|
+
* them.
|
|
12
12
|
*
|
|
13
13
|
* `create_audit_log_sse` builds the registry and its broadcaster and adds the
|
|
14
14
|
* registry to the closer — making the secure path the easy path for consumers.
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* `SseRegistry` to `ConnectionCloser`, and a registry added to the
|
|
8
8
|
* backend's `deps.connection_closer` is closed by every revocation: the
|
|
9
9
|
* handlers' own post-commit closes (`queue_connection_close`), and the one
|
|
10
|
-
* audit listener on that closer (`create_revocation_guard`), which
|
|
11
|
-
*
|
|
10
|
+
* audit listener on that closer (`create_revocation_guard`), which repeats
|
|
11
|
+
* them.
|
|
12
12
|
*
|
|
13
13
|
* `create_audit_log_sse` builds the registry and its broadcaster and adds the
|
|
14
14
|
* registry to the closer — making the secure path the easy path for consumers.
|
package/dist/schema_meta.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shared Zod `.meta()` conventions for fuz_app schemas.
|
|
3
3
|
*
|
|
4
|
-
* Cross-cutting metadata shape used by
|
|
5
|
-
* surface generation, and test helpers.
|
|
4
|
+
* Cross-cutting metadata shape used by auth and action input schemas,
|
|
5
|
+
* surface generation, and test helpers. The env schemas are
|
|
6
|
+
* `@fuzdev/fuz_schema` and carry the same keys in its `meta`
|
|
7
|
+
* (`sensitivity.ts`, `find_schema_sensitivity`).
|
|
6
8
|
*
|
|
7
9
|
* @module
|
|
8
10
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema_meta.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/schema_meta.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"schema_meta.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/schema_meta.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGpD,mEAAmE;AACnE,MAAM,WAAW,eAAe;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B;;;;;;;;;;OAUG;IACH,2BAA2B,CAAC,EAAE,OAAO,CAAC;IACtC;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;GAKG;AACH,eAAO,MAAM,8BAA8B,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,OACkB,CAAC;AAEtF;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,GAAI,IAAI,SAAS,MAAM,eAAe,EACnE,QAAQ,CAAC,CAAC,OAAO,EACjB,KAAK,IAAI,KACP,eAAe,CAAC,IAAI,CAAC,GAAG,SAM1B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,MAAM,GAAG,SACvB,CAAC;AA4D7C;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,kBAAkB,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,WAAW,GAAG,SACrC,CAAC;AAEjC;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,0BAA0B,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,OAClB,CAAC;AAE9C;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,sBAAsB,GAClC,cAAc,CAAC,CAAC,OAAO,EACvB,MAAM,aAAa,CAAC,WAAW,CAAC,KAC9B,MAAM,GAAG,SAYX,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,6BAA6B,GACzC,cAAc,CAAC,CAAC,OAAO,EACvB,QAAQ,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KACrC,MAAM,GAAG,SAIX,CAAC"}
|
package/dist/schema_meta.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shared Zod `.meta()` conventions for fuz_app schemas.
|
|
3
3
|
*
|
|
4
|
-
* Cross-cutting metadata shape used by
|
|
5
|
-
* surface generation, and test helpers.
|
|
4
|
+
* Cross-cutting metadata shape used by auth and action input schemas,
|
|
5
|
+
* surface generation, and test helpers. The env schemas are
|
|
6
|
+
* `@fuzdev/fuz_schema` and carry the same keys in its `meta`
|
|
7
|
+
* (`sensitivity.ts`, `find_schema_sensitivity`).
|
|
6
8
|
*
|
|
7
9
|
* @module
|
|
8
10
|
*/
|
package/dist/sensitivity.d.ts
CHANGED
|
@@ -3,10 +3,19 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Used by env schemas and action input schemas to control masking/redaction
|
|
5
5
|
* in startup logs, surface explorers, and test output, and to keep values
|
|
6
|
-
* out of URLs.
|
|
6
|
+
* out of URLs. A Zod schema declares it with `.meta({sensitivity})`
|
|
7
|
+
* (`SchemaFieldMeta`, read by `schema_sensitivity`); a `@fuzdev/fuz_schema`
|
|
8
|
+
* schema with `meta(schema, {sensitivity})`, the key this module adds to
|
|
9
|
+
* fuz_schema's `SchemaMeta` by declaration merging, read by
|
|
10
|
+
* `find_schema_sensitivity`. `server/env.ts` and `env/env_schemas.ts` import
|
|
11
|
+
* this module for the declaration, so a consumer of either has the key; a
|
|
12
|
+
* module that imports neither and marks a fuz_schema field adds
|
|
13
|
+
* `import type {} from '@fuzdev/fuz_app/sensitivity.ts';`, which brings the
|
|
14
|
+
* declaration in without an unused binding.
|
|
7
15
|
*
|
|
8
16
|
* @module
|
|
9
17
|
*/
|
|
18
|
+
import type { AnySchema } from '@fuzdev/fuz_schema/schema.ts';
|
|
10
19
|
/**
|
|
11
20
|
* Sensitivity level for a schema field.
|
|
12
21
|
*
|
|
@@ -18,4 +27,28 @@
|
|
|
18
27
|
* logs or UI
|
|
19
28
|
*/
|
|
20
29
|
export type Sensitivity = 'secret' | 'personal';
|
|
30
|
+
declare module '@fuzdev/fuz_schema/meta.ts' {
|
|
31
|
+
interface SchemaMeta {
|
|
32
|
+
/**
|
|
33
|
+
* Sensitivity level (`Sensitivity`): `'secret'` masks the value,
|
|
34
|
+
* `'personal'` only keeps it out of URLs. Read fail-safe from every
|
|
35
|
+
* schema the field reaches (`find_schema_sensitivity`).
|
|
36
|
+
*/
|
|
37
|
+
sensitivity?: Sensitivity;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The strongest `sensitivity` declared on any schema a `@fuzdev/fuz_schema`
|
|
42
|
+
* field reaches — `'secret'` over `'personal'` — the fuz_schema twin of
|
|
43
|
+
* `schema_sensitivity`. Fail-safe: `find_schema_meta` reads every wrapper,
|
|
44
|
+
* every schema and action of a `pipe` (not only its first), every option of a
|
|
45
|
+
* union, and a `lazy`'s schema, so a secret stays masked however the field is
|
|
46
|
+
* wrapped, `message` included, which carries the metadata of the schema it
|
|
47
|
+
* was given over. It stops at structural schemas — an object's entries and an
|
|
48
|
+
* array's items carry their own.
|
|
49
|
+
*
|
|
50
|
+
* @param schema - a field schema, possibly wrapped
|
|
51
|
+
* @returns the strongest level any reachable schema declares, else `undefined`
|
|
52
|
+
*/
|
|
53
|
+
export declare const find_schema_sensitivity: (schema: AnySchema) => Sensitivity | undefined;
|
|
21
54
|
//# sourceMappingURL=sensitivity.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sensitivity.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/sensitivity.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"sensitivity.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/sensitivity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAI9D;;;;;;;;;GASG;AACH,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,UAAU,CAAC;AAEhD,OAAO,QAAQ,4BAA4B,CAAC;IAC3C,UAAU,UAAU;QACnB;;;;WAIG;QACH,WAAW,CAAC,EAAE,WAAW,CAAC;KAC1B;CACD;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,uBAAuB,GAAI,QAAQ,SAAS,KAAG,WAAW,GAAG,SAOzE,CAAC"}
|
package/dist/sensitivity.js
CHANGED
|
@@ -3,8 +3,38 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Used by env schemas and action input schemas to control masking/redaction
|
|
5
5
|
* in startup logs, surface explorers, and test output, and to keep values
|
|
6
|
-
* out of URLs.
|
|
6
|
+
* out of URLs. A Zod schema declares it with `.meta({sensitivity})`
|
|
7
|
+
* (`SchemaFieldMeta`, read by `schema_sensitivity`); a `@fuzdev/fuz_schema`
|
|
8
|
+
* schema with `meta(schema, {sensitivity})`, the key this module adds to
|
|
9
|
+
* fuz_schema's `SchemaMeta` by declaration merging, read by
|
|
10
|
+
* `find_schema_sensitivity`. `server/env.ts` and `env/env_schemas.ts` import
|
|
11
|
+
* this module for the declaration, so a consumer of either has the key; a
|
|
12
|
+
* module that imports neither and marks a fuz_schema field adds
|
|
13
|
+
* `import type {} from '@fuzdev/fuz_app/sensitivity.ts';`, which brings the
|
|
14
|
+
* declaration in without an unused binding.
|
|
7
15
|
*
|
|
8
16
|
* @module
|
|
9
17
|
*/
|
|
10
|
-
|
|
18
|
+
import { find_schema_meta } from '@fuzdev/fuz_schema/introspect.ts';
|
|
19
|
+
/**
|
|
20
|
+
* The strongest `sensitivity` declared on any schema a `@fuzdev/fuz_schema`
|
|
21
|
+
* field reaches — `'secret'` over `'personal'` — the fuz_schema twin of
|
|
22
|
+
* `schema_sensitivity`. Fail-safe: `find_schema_meta` reads every wrapper,
|
|
23
|
+
* every schema and action of a `pipe` (not only its first), every option of a
|
|
24
|
+
* union, and a `lazy`'s schema, so a secret stays masked however the field is
|
|
25
|
+
* wrapped, `message` included, which carries the metadata of the schema it
|
|
26
|
+
* was given over. It stops at structural schemas — an object's entries and an
|
|
27
|
+
* array's items carry their own.
|
|
28
|
+
*
|
|
29
|
+
* @param schema - a field schema, possibly wrapped
|
|
30
|
+
* @returns the strongest level any reachable schema declares, else `undefined`
|
|
31
|
+
*/
|
|
32
|
+
export const find_schema_sensitivity = (schema) => {
|
|
33
|
+
let found;
|
|
34
|
+
for (const sensitivity of find_schema_meta(schema, 'sensitivity')) {
|
|
35
|
+
if (sensitivity === 'secret')
|
|
36
|
+
return 'secret';
|
|
37
|
+
found = sensitivity;
|
|
38
|
+
}
|
|
39
|
+
return found;
|
|
40
|
+
};
|
|
@@ -35,7 +35,10 @@ export interface AppBackend {
|
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
* Callback that builds the bound `AuditEmitter` after the backend's pool
|
|
38
|
-
* `Db` and `Logger` exist.
|
|
38
|
+
* `Db` and `Logger` exist. The `db` it is handed is the backend's pool with
|
|
39
|
+
* the audit checkout bound (`db_audit_checkout_timeout_ms`,
|
|
40
|
+
* `Db.with_checkout_timeout`), so the emitter's pool writes wait longer than a
|
|
41
|
+
* request's checkout. Required on `CreateAppBackendOptions` so the
|
|
39
42
|
* consumer owns subscriber-chain composition and `AuditLogConfig`
|
|
40
43
|
* selection without the factory holding a default.
|
|
41
44
|
*
|
|
@@ -143,12 +146,33 @@ export interface CreateAppBackendOptions {
|
|
|
143
146
|
* lifecycle, not server assembly.
|
|
144
147
|
*/
|
|
145
148
|
migration_namespaces?: ReadonlyArray<MigrationNamespace>;
|
|
149
|
+
/**
|
|
150
|
+
* Bound on the pool checkouts a request makes, in ms — the server env's
|
|
151
|
+
* `FUZ_DB_CHECKOUT_TIMEOUT_MS`. Default `DEFAULT_DB_CHECKOUT_TIMEOUT_MS`
|
|
152
|
+
* (5 s). A failed checkout answers 503 on every surface. Audit writes use
|
|
153
|
+
* `db_audit_checkout_timeout_ms` instead — the failed-login row a request
|
|
154
|
+
* waits on included. A checkout that waits and then connects can take about
|
|
155
|
+
* twice the bound (`db/db_pg.ts`, "Checkout timeout"). Postgres only:
|
|
156
|
+
* PGlite and pglet have no pool, and a value passed with one is warned of
|
|
157
|
+
* at boot. Twin of the Rust `BaseServerEnv::db_checkout_timeout`.
|
|
158
|
+
*/
|
|
159
|
+
db_checkout_timeout_ms?: number;
|
|
160
|
+
/**
|
|
161
|
+
* Bound on the checkout behind each audit pool write, in ms — the server
|
|
162
|
+
* env's `FUZ_DB_AUDIT_CHECKOUT_TIMEOUT_MS`. Default
|
|
163
|
+
* `DEFAULT_DB_AUDIT_CHECKOUT_TIMEOUT_MS` (30 s). A failed login awaits its
|
|
164
|
+
* row, so it can wait up to this bound. Postgres only, like
|
|
165
|
+
* `db_checkout_timeout_ms`. Twin of the Rust
|
|
166
|
+
* `BaseServerEnv::db_audit_checkout_timeout`.
|
|
167
|
+
*/
|
|
168
|
+
db_audit_checkout_timeout_ms?: number;
|
|
146
169
|
}
|
|
147
170
|
/**
|
|
148
171
|
* Initialize the backend: database + auth migrations + deps.
|
|
149
172
|
*
|
|
150
173
|
* Calls `create_db` → `run_migrations` (auth namespace, then any
|
|
151
174
|
* `migration_namespaces` from options in order) → `audit_factory({db, log})`
|
|
175
|
+
* (`db` with the audit checkout bound)
|
|
152
176
|
* and bundles the result with the provided keyring and password deps and a
|
|
153
177
|
* `connection_closer` (empty until `create_app_server` adds its transports).
|
|
154
178
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app_backend.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/server/app_backend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEjD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAwB,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACnF,OAAO,EAA0B,KAAK,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAC9F,OAAO,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAkB,KAAK,kBAAkB,EAAE,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"app_backend.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/server/app_backend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEjD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAwB,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACnF,OAAO,EAA0B,KAAK,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAC9F,OAAO,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,gBAAgB,E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a,CAAC,kBAAkB,CAAC,CAAC;IACzD;;;;;;;;;OASG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC;;;;;;;OAOG;IACH,4BAA4B,CAAC,EAAE,MAAM,CAAC;CACtC;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,kBAAkB,GAAU,SAAS,uBAAuB,KAAG,OAAO,CAAC,UAAU,CAyD7F,CAAC"}
|
|
@@ -15,7 +15,8 @@ import { create_audit_emitter } from '../auth/audit_emitter.js';
|
|
|
15
15
|
import { create_realtime_closer } from '../actions/connection_closer.js';
|
|
16
16
|
import { run_migrations } from '../db/migrate.js';
|
|
17
17
|
import { AUTH_MIGRATION_NS } from '../auth/migrations.js';
|
|
18
|
-
import { create_db } from '../db/create_db.js';
|
|
18
|
+
import { create_db, is_pg_database_url } from '../db/create_db.js';
|
|
19
|
+
import { DEFAULT_DB_AUDIT_CHECKOUT_TIMEOUT_MS } from '../db/db_pg.js';
|
|
19
20
|
/**
|
|
20
21
|
* Trivial `AuditFactory` for consumers that don't compose `on_audit_event`
|
|
21
22
|
* or `audit_log_config`. Equivalent to
|
|
@@ -33,6 +34,7 @@ export const default_audit_factory = ({ db, log }) => create_audit_emitter({ db,
|
|
|
33
34
|
*
|
|
34
35
|
* Calls `create_db` → `run_migrations` (auth namespace, then any
|
|
35
36
|
* `migration_namespaces` from options in order) → `audit_factory({db, log})`
|
|
37
|
+
* (`db` with the audit checkout bound)
|
|
36
38
|
* and bundles the result with the provided keyring and password deps and a
|
|
37
39
|
* `connection_closer` (empty until `create_app_server` adds its transports).
|
|
38
40
|
*
|
|
@@ -43,7 +45,15 @@ export const default_audit_factory = ({ db, log }) => create_audit_emitter({ db,
|
|
|
43
45
|
export const create_app_backend = async (options) => {
|
|
44
46
|
const { database_url, keyring, password, read_secure_file, delete_file, audit_factory } = options;
|
|
45
47
|
const log = options.log ?? new Logger('server');
|
|
46
|
-
const { db, close, db_type, db_name } = await create_db(database_url
|
|
48
|
+
const { db, close, db_type, db_name } = await create_db(database_url, {
|
|
49
|
+
checkout_timeout_ms: options.db_checkout_timeout_ms
|
|
50
|
+
});
|
|
51
|
+
// set but inert: fail loud rather than let an operator believe it applies
|
|
52
|
+
if (!is_pg_database_url(database_url) &&
|
|
53
|
+
(options.db_checkout_timeout_ms !== undefined ||
|
|
54
|
+
options.db_audit_checkout_timeout_ms !== undefined)) {
|
|
55
|
+
log.warn(`${db_type} has no connection pool; FUZ_DB_CHECKOUT_TIMEOUT_MS and FUZ_DB_AUDIT_CHECKOUT_TIMEOUT_MS have no effect`);
|
|
56
|
+
}
|
|
47
57
|
// Everything after `create_db` can throw — `run_migrations` (its
|
|
48
58
|
// `MigrationError` kinds include the reserved-namespace refusal),
|
|
49
59
|
// `audit_factory`.
|
|
@@ -55,7 +65,10 @@ export const create_app_backend = async (options) => {
|
|
|
55
65
|
AUTH_MIGRATION_NS,
|
|
56
66
|
...(options.migration_namespaces ?? [])
|
|
57
67
|
]);
|
|
58
|
-
const audit = audit_factory({
|
|
68
|
+
const audit = audit_factory({
|
|
69
|
+
db: db.with_checkout_timeout(options.db_audit_checkout_timeout_ms ?? DEFAULT_DB_AUDIT_CHECKOUT_TIMEOUT_MS),
|
|
70
|
+
log
|
|
71
|
+
});
|
|
59
72
|
return {
|
|
60
73
|
db_type,
|
|
61
74
|
db_name,
|