@fuzdev/fuz_app 0.152.0 → 0.153.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/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/realtime/audit_log_sse.d.ts +2 -2
- package/dist/realtime/audit_log_sse.js +2 -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 +1 -1
- package/dist/server/app_server.d.ts.map +1 -1
- package/dist/server/app_server.js +6 -1
- package/dist/server/env.d.ts +8 -3
- package/dist/server/env.d.ts.map +1 -1
- package/dist/server/env.js +26 -4
- package/dist/testing/CLAUDE.md +22 -16
- 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.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 +3 -7
package/dist/http/db_routes.d.ts
CHANGED
|
@@ -99,19 +99,14 @@ export declare const NON_DELETABLE_TABLES: ReadonlyArray<string>;
|
|
|
99
99
|
*/
|
|
100
100
|
export interface DbRouteDeps {
|
|
101
101
|
/**
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
* The
|
|
107
|
-
* goes on `pending_effects`, the row's listener fan-out on
|
|
108
|
-
* `post_commit_effects`.
|
|
102
|
+
* Awaitable pool audit write. The row-`DELETE` handler calls it from an
|
|
103
|
+
* `emit_after_commit` thunk, so the success-only trail row can never
|
|
104
|
+
* claim a delete whose transaction failed at COMMIT, and the row is
|
|
105
|
+
* written on the pool because the request transaction has ended by then.
|
|
106
|
+
* The flush awaits the returned promise.
|
|
109
107
|
*/
|
|
110
108
|
audit: {
|
|
111
|
-
|
|
112
|
-
pending_effects: Array<Promise<void>>;
|
|
113
|
-
post_commit_effects: Array<() => void | Promise<void>>;
|
|
114
|
-
}, input: {
|
|
109
|
+
emit_pool: (input: {
|
|
115
110
|
event_type: 'db_admin_row_delete';
|
|
116
111
|
account_id: Uuid | null;
|
|
117
112
|
ip: string;
|
|
@@ -120,7 +115,7 @@ export interface DbRouteDeps {
|
|
|
120
115
|
pk_column: string;
|
|
121
116
|
id: string;
|
|
122
117
|
};
|
|
123
|
-
}) => void
|
|
118
|
+
}) => Promise<void>;
|
|
124
119
|
};
|
|
125
120
|
}
|
|
126
121
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db_routes.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/db_routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAqC,K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CAAC;IACxC,8EAA8E;IAC9E,WAAW,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC3D,+EAA+E;IAC/E,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,oBAAoB,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CAC7C;AA2CD;;GAEG;AACH,eAAO,MAAM,qBAAqB,GACjC,MAAM,WAAW,EACjB,SAAS,cAAc,KACrB,KAAK,CAAC,SAAS,CA4YjB,CAAC"}
|
package/dist/http/db_routes.js
CHANGED
|
@@ -375,6 +375,15 @@ export const create_db_route_specs = (deps, options) => {
|
|
|
375
375
|
return c.json({ error: ERROR_TABLE_NO_PRIMARY_KEY }, 400);
|
|
376
376
|
}
|
|
377
377
|
const pk_column = pk_columns[0];
|
|
378
|
+
// The refusals below answer from a failed DELETE, which on PostgreSQL
|
|
379
|
+
// aborts the route's transaction — its COMMIT would come back as a
|
|
380
|
+
// ROLLBACK, which the pg driver throws on (`db/db_pg.ts`). A savepoint
|
|
381
|
+
// keeps the refusal's failure out of the transaction. Guarded because
|
|
382
|
+
// a consumer may run the route with `transaction: false`, and
|
|
383
|
+
// `SAVEPOINT` outside a transaction block is an error.
|
|
384
|
+
const savepoint = route.db.in_transaction;
|
|
385
|
+
if (savepoint)
|
|
386
|
+
await route.db.query('SAVEPOINT db_admin_row_delete');
|
|
378
387
|
try {
|
|
379
388
|
// Typed PK compare, twinning the Rust spine: `$1` travels as an
|
|
380
389
|
// untyped text-format parameter, so PG infers the PK column's
|
|
@@ -397,19 +406,19 @@ export const create_db_route_specs = (deps, options) => {
|
|
|
397
406
|
// delete through this endpoint is audited. Deferred via
|
|
398
407
|
// `emit_after_commit` so the pool-routed row can never claim a
|
|
399
408
|
// delete whose transaction failed at COMMIT — the Rust twin
|
|
400
|
-
// commits before emitting for the same reason.
|
|
409
|
+
// commits before emitting for the same reason. The request
|
|
410
|
+
// transaction has ended by then, so the row goes through
|
|
411
|
+
// `emit_pool`, not the transaction-routing `emit`. Account-grain
|
|
401
412
|
// attribution — the browser is a raw storage surface, so no actor
|
|
402
413
|
// is claimed.
|
|
403
414
|
const account_id = c.var.request_context?.account.id ?? null;
|
|
404
415
|
const ip = get_client_ip(c);
|
|
405
|
-
emit_after_commit(route, () => {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
});
|
|
412
|
-
});
|
|
416
|
+
emit_after_commit(route, () => deps.audit.emit_pool({
|
|
417
|
+
event_type: 'db_admin_row_delete',
|
|
418
|
+
account_id,
|
|
419
|
+
ip,
|
|
420
|
+
metadata: { table: name, pk_column, id: deleted_id }
|
|
421
|
+
}));
|
|
413
422
|
return c.json({ success: true });
|
|
414
423
|
}
|
|
415
424
|
catch (err) {
|
|
@@ -420,21 +429,27 @@ export const create_db_route_specs = (deps, options) => {
|
|
|
420
429
|
// NUL byte, rejected by the server encoding whatever the PK
|
|
421
430
|
// type) — so no row can match; answer with the same masked 404
|
|
422
431
|
// as a typed miss.
|
|
423
|
-
|
|
424
|
-
return c.json({ error: ERROR_ROW_NOT_FOUND }, 404);
|
|
425
|
-
}
|
|
432
|
+
const uncoercible = code === '22P02' || code === '22003' || code === '22021';
|
|
426
433
|
// 23503 foreign_key_violation / 23001 restrict_violation — the
|
|
427
434
|
// same referencing-row refusal. Which one depends on the
|
|
428
435
|
// constraint: `ON DELETE RESTRICT` raises 23001 on PG 18, PGlite
|
|
429
436
|
// and pglet (23503 on PG ≤17), and `NO ACTION` — the default,
|
|
430
437
|
// when the constraint names no action — raises 23503 on all of
|
|
431
438
|
// them.
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
439
|
+
const referenced = code === '23503' || code === '23001';
|
|
440
|
+
// anything else fails the request, and the route's transaction
|
|
441
|
+
// rolls back whole
|
|
442
|
+
if (!uncoercible && !referenced)
|
|
443
|
+
throw err;
|
|
444
|
+
// the refusal answers normally, so the transaction must commit
|
|
445
|
+
if (savepoint)
|
|
446
|
+
await route.db.query('ROLLBACK TO SAVEPOINT db_admin_row_delete');
|
|
447
|
+
if (uncoercible) {
|
|
448
|
+
return c.json({ error: ERROR_ROW_NOT_FOUND }, 404);
|
|
436
449
|
}
|
|
437
|
-
|
|
450
|
+
const pg_err = err;
|
|
451
|
+
log?.warn('Foreign key violation:', pg_err.detail, pg_err.constraint);
|
|
452
|
+
return c.json({ error: ERROR_FOREIGN_KEY_VIOLATION }, 409);
|
|
438
453
|
}
|
|
439
454
|
}
|
|
440
455
|
}
|
|
@@ -21,6 +21,12 @@ export declare const ERROR_INVALID_JSON_BODY: "invalid_json_body";
|
|
|
21
21
|
export declare const ERROR_INVALID_ROUTE_PARAMS: "invalid_route_params";
|
|
22
22
|
/** URL query params failed Zod validation. */
|
|
23
23
|
export declare const ERROR_INVALID_QUERY_PARAMS: "invalid_query_params";
|
|
24
|
+
/**
|
|
25
|
+
* An RPC call's `params` hold an own `__proto__` key, at any depth — refused
|
|
26
|
+
* by the dispatcher (`invalid_params`) before the input schema runs. See
|
|
27
|
+
* `json_has_own_proto_key`.
|
|
28
|
+
*/
|
|
29
|
+
export declare const ERROR_PARAMS_PROTO_KEY: "params_proto_key";
|
|
24
30
|
/** No valid session or bearer token. */
|
|
25
31
|
export declare const ERROR_AUTHENTICATION_REQUIRED: "authentication_required";
|
|
26
32
|
/** Authenticated but missing required role. */
|
|
@@ -53,6 +59,12 @@ export declare const ERROR_RATE_LIMIT_EXCEEDED: "rate_limit_exceeded";
|
|
|
53
59
|
export declare const ERROR_INVALID_CREDENTIALS: "invalid_credentials";
|
|
54
60
|
/** Request body exceeds the maximum allowed size. */
|
|
55
61
|
export declare const ERROR_PAYLOAD_TOO_LARGE: "payload_too_large";
|
|
62
|
+
/**
|
|
63
|
+
* A pool checkout failed — the database is unavailable (503). The flat REST
|
|
64
|
+
* reason of the JSON-RPC `service_unavailable` a `DbCheckoutError` maps to;
|
|
65
|
+
* the Rust spine's `fuz_http::SERVICE_UNAVAILABLE_REASON`.
|
|
66
|
+
*/
|
|
67
|
+
export declare const ERROR_SERVICE_UNAVAILABLE: "service_unavailable";
|
|
56
68
|
/** Request `Content-Length` header is not a plain run of ASCII digits. */
|
|
57
69
|
export declare const ERROR_INVALID_CONTENT_LENGTH: "invalid_content_length";
|
|
58
70
|
/** Request origin not in allowlist. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error_schemas.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/error_schemas.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI9D,0CAA0C;AAC1C,eAAO,MAAM,0BAA0B,EAAG,sBAA+B,CAAC;AAE1E,uDAAuD;AACvD,eAAO,MAAM,uBAAuB,EAAG,mBAA4B,CAAC;AAEpE,6CAA6C;AAC7C,eAAO,MAAM,0BAA0B,EAAG,sBAA+B,CAAC;AAE1E,8CAA8C;AAC9C,eAAO,MAAM,0BAA0B,EAAG,sBAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"error_schemas.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/error_schemas.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI9D,0CAA0C;AAC1C,eAAO,MAAM,0BAA0B,EAAG,sBAA+B,CAAC;AAE1E,uDAAuD;AACvD,eAAO,MAAM,uBAAuB,EAAG,mBAA4B,CAAC;AAEpE,6CAA6C;AAC7C,eAAO,MAAM,0BAA0B,EAAG,sBAA+B,CAAC;AAE1E,8CAA8C;AAC9C,eAAO,MAA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AO,MAAM,oBAAoB,GAAI,6EAOlC,yBAAyB,KAAG,iBA8C9B,CAAC"}
|
|
@@ -22,6 +22,12 @@ export const ERROR_INVALID_JSON_BODY = 'invalid_json_body';
|
|
|
22
22
|
export const ERROR_INVALID_ROUTE_PARAMS = 'invalid_route_params';
|
|
23
23
|
/** URL query params failed Zod validation. */
|
|
24
24
|
export const ERROR_INVALID_QUERY_PARAMS = 'invalid_query_params';
|
|
25
|
+
/**
|
|
26
|
+
* An RPC call's `params` hold an own `__proto__` key, at any depth — refused
|
|
27
|
+
* by the dispatcher (`invalid_params`) before the input schema runs. See
|
|
28
|
+
* `json_has_own_proto_key`.
|
|
29
|
+
*/
|
|
30
|
+
export const ERROR_PARAMS_PROTO_KEY = 'params_proto_key';
|
|
25
31
|
// --- Core: Authentication & authorization (auto-derived by auth middleware) ---
|
|
26
32
|
/** No valid session or bearer token. */
|
|
27
33
|
export const ERROR_AUTHENTICATION_REQUIRED = 'authentication_required';
|
|
@@ -55,6 +61,12 @@ export const ERROR_RATE_LIMIT_EXCEEDED = 'rate_limit_exceeded';
|
|
|
55
61
|
export const ERROR_INVALID_CREDENTIALS = 'invalid_credentials';
|
|
56
62
|
/** Request body exceeds the maximum allowed size. */
|
|
57
63
|
export const ERROR_PAYLOAD_TOO_LARGE = 'payload_too_large';
|
|
64
|
+
/**
|
|
65
|
+
* A pool checkout failed — the database is unavailable (503). The flat REST
|
|
66
|
+
* reason of the JSON-RPC `service_unavailable` a `DbCheckoutError` maps to;
|
|
67
|
+
* the Rust spine's `fuz_http::SERVICE_UNAVAILABLE_REASON`.
|
|
68
|
+
*/
|
|
69
|
+
export const ERROR_SERVICE_UNAVAILABLE = 'service_unavailable';
|
|
58
70
|
/** Request `Content-Length` header is not a plain run of ASCII digits. */
|
|
59
71
|
export const ERROR_INVALID_CONTENT_LENGTH = 'invalid_content_length';
|
|
60
72
|
// --- Origin & bearer token verification ---
|
|
@@ -67,6 +67,11 @@ export declare const dev_only: <T>(value: T) => T | undefined;
|
|
|
67
67
|
* Frozen so tests must compose new objects rather than monkey-patch.
|
|
68
68
|
*/
|
|
69
69
|
export declare const jsonrpc_error_messages: Readonly<Record<JsonrpcErrorName, (...args: Array<any>) => JsonrpcErrorObject>>;
|
|
70
|
+
/**
|
|
71
|
+
* The message every failed pool checkout answers with, on both spines — the
|
|
72
|
+
* Rust `fuz_http::DB_UNAVAILABLE_MESSAGE`.
|
|
73
|
+
*/
|
|
74
|
+
export declare const DB_UNAVAILABLE_MESSAGE = "database unavailable";
|
|
70
75
|
/**
|
|
71
76
|
* Error class carrying a JSON-RPC error code — thrown by handlers, read by
|
|
72
77
|
* `to_thrown_jsonrpc_error`, and mapped to HTTP status + JSON-RPC error response.
|
|
@@ -87,6 +92,11 @@ export declare class ThrownJsonrpcError extends Error {
|
|
|
87
92
|
* (another library's RPC error), or a `ThrownJsonrpcError` whose `code` was
|
|
88
93
|
* cast outside the JSON-RPC set — so each caller masks it.
|
|
89
94
|
*
|
|
95
|
+
* A failed pool checkout (`DbCheckoutError`, `db/db_checkout_error.ts`) is
|
|
96
|
+
* the database unavailable: `service_unavailable` with
|
|
97
|
+
* `DB_UNAVAILABLE_MESSAGE` and no `data` (HTTP 503), the Rust spine's
|
|
98
|
+
* `fuz_http::db_unavailable`.
|
|
99
|
+
*
|
|
90
100
|
* The one thrown → wire conversion: the REST catch layer
|
|
91
101
|
* (`apply_route_specs`), the RPC dispatch core (`perform_action`),
|
|
92
102
|
* `create_jsonrpc_error_response_from_thrown`, the frontend HTTP and
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonrpc_errors.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/jsonrpc_errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;
|
|
1
|
+
{"version":3,"file":"jsonrpc_errors.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/jsonrpc_errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;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,KAAK,OAAO,KAAG,kBAAkB,GAAG,IAkB3E,CAAC;AAWF;;;;GAIG;AACH,eAAO,MAAM,cAAc;8CAXQ,kBAAkB;kDAAlB,kBAAkB;mDAAlB,kBAAkB;iDAAlB,kBAAkB;iDAAlB,kBAAkB;kDAAlB,kBAAkB;4CAAlB,kBAAkB;4CAAlB,kBAAkB;2CAAlB,kBAAkB;mDAAlB,kBAAkB;+CAAlB,kBAAkB;sDAAlB,kBAAkB;0CAAlB,kBAAkB;iDAAlB,kBAAkB;oDAAlB,kBAAkB;CA2BqC,CAAC;AAiD3F;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,2BAA2B,GAAI,MAAM,gBAAgB,EAAE,aAAa,MAAM,KAAG,IA0BzF,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,iCAAiC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAQvF,CAAC;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,iCAAiC,GAAI,MAAM,gBAAgB,KAAG,oBACC,CAAC;AAE7E;;;;GAIG;AACH,eAAO,MAAM,iCAAiC,GAAI,QAAQ,MAAM,KAAG,gBACa,CAAC;AAEjF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,0BAA0B,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAMjF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,GAAI,MAAM,gBAAgB,KAAG,gBACL,CAAC"}
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
* @module
|
|
19
19
|
*/
|
|
20
20
|
import { DEV } from 'esm-env';
|
|
21
|
+
import { is_db_checkout_error } from '../db/db_checkout_error.js';
|
|
21
22
|
import { JSONRPC_PARSE_ERROR, JSONRPC_INVALID_REQUEST, JSONRPC_METHOD_NOT_FOUND, JSONRPC_INVALID_PARAMS, JSONRPC_INTERNAL_ERROR, JSONRPC_SERVER_ERROR_START, JSONRPC_SERVER_ERROR_END, is_jsonrpc_error_code } from './jsonrpc.js';
|
|
22
23
|
/** Default message for unknown errors. */
|
|
23
24
|
export const UNKNOWN_ERROR_MESSAGE = 'unknown error';
|
|
@@ -184,6 +185,11 @@ export const jsonrpc_error_messages = Object.freeze({
|
|
|
184
185
|
data
|
|
185
186
|
})
|
|
186
187
|
});
|
|
188
|
+
/**
|
|
189
|
+
* The message every failed pool checkout answers with, on both spines — the
|
|
190
|
+
* Rust `fuz_http::DB_UNAVAILABLE_MESSAGE`.
|
|
191
|
+
*/
|
|
192
|
+
export const DB_UNAVAILABLE_MESSAGE = 'database unavailable';
|
|
187
193
|
/**
|
|
188
194
|
* Realm-global brand on `ThrownJsonrpcError.prototype`. `Symbol.for` makes
|
|
189
195
|
* every copy of this module that one process resolves mint the same key, so
|
|
@@ -216,6 +222,11 @@ Object.defineProperty(ThrownJsonrpcError.prototype, THROWN_JSONRPC_ERROR_BRAND,
|
|
|
216
222
|
* (another library's RPC error), or a `ThrownJsonrpcError` whose `code` was
|
|
217
223
|
* cast outside the JSON-RPC set — so each caller masks it.
|
|
218
224
|
*
|
|
225
|
+
* A failed pool checkout (`DbCheckoutError`, `db/db_checkout_error.ts`) is
|
|
226
|
+
* the database unavailable: `service_unavailable` with
|
|
227
|
+
* `DB_UNAVAILABLE_MESSAGE` and no `data` (HTTP 503), the Rust spine's
|
|
228
|
+
* `fuz_http::db_unavailable`.
|
|
229
|
+
*
|
|
219
230
|
* The one thrown → wire conversion: the REST catch layer
|
|
220
231
|
* (`apply_route_specs`), the RPC dispatch core (`perform_action`),
|
|
221
232
|
* `create_jsonrpc_error_response_from_thrown`, the frontend HTTP and
|
|
@@ -229,6 +240,9 @@ Object.defineProperty(ThrownJsonrpcError.prototype, THROWN_JSONRPC_ERROR_BRAND,
|
|
|
229
240
|
export const to_thrown_jsonrpc_error = (err) => {
|
|
230
241
|
if (!(err instanceof Error))
|
|
231
242
|
return null;
|
|
243
|
+
if (is_db_checkout_error(err)) {
|
|
244
|
+
return { code: JSONRPC_ERROR_CODES.service_unavailable, message: DB_UNAVAILABLE_MESSAGE };
|
|
245
|
+
}
|
|
232
246
|
const { code, data, [THROWN_JSONRPC_ERROR_BRAND]: brand } = err;
|
|
233
247
|
if (brand !== true || !is_jsonrpc_error_code(code))
|
|
234
248
|
return null;
|
|
@@ -94,6 +94,10 @@ export type ClassifiedJsonrpcMessage = {
|
|
|
94
94
|
* `method` as absent — so `{id, method: 123, result}` is a response on both
|
|
95
95
|
* sides. The `result` / `error` exclusive-or refuses a frame carrying both.
|
|
96
96
|
*
|
|
97
|
+
* A `request` carries the frame as given — validated, never re-built — so
|
|
98
|
+
* `params` reaches the action's input schema with every own key the client
|
|
99
|
+
* sent, `__proto__` included, as on the GET path and the Rust twin.
|
|
100
|
+
*
|
|
97
101
|
* Every `invalid` is `invalid_request`. Its `id` is the frame's own when the
|
|
98
102
|
* frame is an object carrying a string or number one, else `null` — a
|
|
99
103
|
* non-object frame (an array included) has none. A refused request envelope
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonrpc_helpers.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/jsonrpc_helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EACN,cAAc,EACd,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,yBAAyB,EAC9B,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,aAAa,EAElB,eAAe,EACf,MAAM,cAAc,CAAC;AAUtB,0CAA0C;AAC1C,eAAO,MAAM,sBAAsB,GAClC,QAAQ,aAAa,EACrB,QAAQ,oBAAoB,GAAG,SAAS,EACxC,IAAI,gBAAgB,KAClB,cAUF,CAAC;AAEF,mDAAmD;AACnD,eAAO,MAAM,uBAAuB,GACnC,IAAI,gBAAgB,EAC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G,oBAAoB,CAAA;CAAE,GACtE;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,EAAE,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAAC,KAAK,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,wBAAwB,GAAI,MAAM,OAAO,KAAG,wBAmCxD,CAAC"}
|
|
@@ -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,iBAAiB,EACtB,KAAK,YAAY,EAOjB,MAAM,oBAAoB,CAAC;AAW5B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAA0C,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEzF;;;;;;;;;;;;;;GA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G,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,OAAO,CAAC,CAAC,OAAO,EAAE,YAAY,OAAO,KAAG,OACA,CAAC;AAEzE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,gCAAgC,GAAI,CAAC,SAAS,CAAC,CAAC,OAAO,EACnE,QAAQ,CAAC,EACT,OAAO,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,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
|
|
@@ -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.
|
|
@@ -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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