@fuzdev/fuz_app 0.183.0 → 0.184.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 +535 -1223
- package/dist/actions/action_codegen.d.ts +1 -1
- package/dist/actions/action_codegen.d.ts.map +1 -1
- package/dist/actions/action_codegen.js +3 -2
- package/dist/actions/connection_closer.d.ts +11 -9
- package/dist/actions/connection_closer.d.ts.map +1 -1
- package/dist/actions/connection_closer.js +11 -9
- package/dist/actions/frontend_rpc_client.d.ts +1 -1
- package/dist/actions/register_action_ws.d.ts +14 -1
- package/dist/actions/register_action_ws.d.ts.map +1 -1
- package/dist/actions/register_action_ws.js +2 -1
- package/dist/actions/ws_socket_session.d.ts +9 -1
- package/dist/actions/ws_socket_session.d.ts.map +1 -1
- package/dist/actions/ws_socket_session.js +43 -19
- package/dist/auth/CLAUDE.md +430 -1048
- package/dist/auth/account_queries.d.ts +1 -1
- package/dist/auth/account_queries.js +1 -1
- package/dist/auth/account_routes.d.ts +4 -5
- package/dist/auth/account_routes.d.ts.map +1 -1
- package/dist/auth/account_routes.js +8 -10
- package/dist/auth/admin_actions.d.ts.map +1 -1
- package/dist/auth/admin_actions.js +10 -11
- package/dist/auth/api_token.d.ts +20 -3
- package/dist/auth/api_token.d.ts.map +1 -1
- package/dist/auth/api_token.js +28 -9
- package/dist/auth/api_token_queries.d.ts +2 -2
- package/dist/auth/api_token_queries.js +2 -2
- package/dist/auth/audit_log_schema.d.ts +15 -9
- package/dist/auth/audit_log_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_schema.js +1 -2
- package/dist/auth/auth_guard_resolver.d.ts +1 -1
- package/dist/auth/auth_guard_resolver.js +1 -1
- package/dist/auth/bearer_auth.d.ts +2 -5
- package/dist/auth/bearer_auth.d.ts.map +1 -1
- package/dist/auth/bearer_auth.js +4 -13
- package/dist/auth/bootstrap_account.d.ts +13 -15
- package/dist/auth/bootstrap_account.d.ts.map +1 -1
- package/dist/auth/bootstrap_account.js +9 -11
- package/dist/auth/bootstrap_routes.d.ts +20 -21
- package/dist/auth/bootstrap_routes.d.ts.map +1 -1
- package/dist/auth/bootstrap_routes.js +21 -19
- package/dist/auth/bootstrap_token_store.d.ts +3 -4
- package/dist/auth/bootstrap_token_store.d.ts.map +1 -1
- package/dist/auth/bootstrap_token_store.js +1 -1
- package/dist/auth/daemon_token.d.ts +5 -1
- package/dist/auth/daemon_token.d.ts.map +1 -1
- package/dist/auth/daemon_token_middleware.d.ts +12 -8
- package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
- package/dist/auth/daemon_token_middleware.js +15 -21
- package/dist/auth/deps.d.ts +11 -0
- package/dist/auth/deps.d.ts.map +1 -1
- package/dist/auth/invite_queries.d.ts +51 -3
- package/dist/auth/invite_queries.d.ts.map +1 -1
- package/dist/auth/invite_queries.js +81 -6
- package/dist/auth/invite_schema.d.ts +2 -1
- package/dist/auth/invite_schema.d.ts.map +1 -1
- package/dist/auth/middleware.d.ts +2 -3
- package/dist/auth/middleware.d.ts.map +1 -1
- package/dist/auth/middleware.js +3 -3
- package/dist/auth/request_context.d.ts +3 -3
- package/dist/auth/request_context.js +3 -3
- package/dist/auth/role_grant_offer_actions.d.ts +2 -2
- package/dist/auth/role_grant_offer_actions.js +2 -2
- package/dist/auth/session_cookie.d.ts +82 -174
- package/dist/auth/session_cookie.d.ts.map +1 -1
- package/dist/auth/session_cookie.js +80 -130
- package/dist/auth/session_middleware.d.ts +8 -17
- package/dist/auth/session_middleware.d.ts.map +1 -1
- package/dist/auth/session_middleware.js +14 -23
- package/dist/auth/session_queries.d.ts +9 -14
- package/dist/auth/session_queries.d.ts.map +1 -1
- package/dist/auth/session_queries.js +8 -9
- package/dist/auth/signup_routes.d.ts.map +1 -1
- package/dist/auth/signup_routes.js +4 -6
- package/dist/db/CLAUDE.md +5 -3
- package/dist/dev/setup.d.ts +3 -1
- package/dist/dev/setup.d.ts.map +1 -1
- package/dist/dev/setup.js +3 -1
- package/dist/http/CLAUDE.md +315 -768
- package/dist/http/db_routes.d.ts +1 -1
- package/dist/http/db_routes.js +1 -1
- package/dist/http/origin.d.ts +7 -8
- package/dist/http/origin.d.ts.map +1 -1
- package/dist/http/origin.js +7 -8
- package/dist/http/pending_effects.d.ts +78 -4
- package/dist/http/pending_effects.d.ts.map +1 -1
- package/dist/http/pending_effects.js +82 -4
- package/dist/http/route_result.d.ts +1 -1
- package/dist/http/route_spec.d.ts +14 -11
- package/dist/http/route_spec.d.ts.map +1 -1
- package/dist/realtime/sse.d.ts +4 -23
- package/dist/realtime/sse.d.ts.map +1 -1
- package/dist/realtime/sse.js +4 -25
- package/dist/server/app_backend.d.ts +4 -5
- package/dist/server/app_backend.d.ts.map +1 -1
- package/dist/server/app_backend.js +3 -1
- package/dist/server/app_server.d.ts +53 -30
- package/dist/server/app_server.d.ts.map +1 -1
- package/dist/server/app_server.js +81 -53
- package/dist/server/app_server_context.d.ts +1 -2
- package/dist/server/app_server_context.d.ts.map +1 -1
- package/dist/server/env.js +2 -2
- package/dist/testing/CLAUDE.md +17 -17
- package/dist/testing/admin_integration.d.ts +2 -3
- package/dist/testing/admin_integration.d.ts.map +1 -1
- package/dist/testing/admin_integration.js +3 -3
- package/dist/testing/app_server.d.ts +3 -8
- package/dist/testing/app_server.d.ts.map +1 -1
- package/dist/testing/app_server.js +10 -9
- package/dist/testing/attack_surface.d.ts +1 -1
- package/dist/testing/attack_surface.d.ts.map +1 -1
- package/dist/testing/audit_completeness.d.ts +2 -3
- package/dist/testing/audit_completeness.d.ts.map +1 -1
- package/dist/testing/audit_completeness.js +1 -1
- package/dist/testing/cross_backend/capability_mounts.d.ts.map +1 -1
- package/dist/testing/cross_backend/capability_mounts.js +16 -11
- package/dist/testing/cross_backend/conformance_table.d.ts +5 -6
- package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_table.js +4 -4
- package/dist/testing/cross_backend/cookie_attributes.js +1 -1
- package/dist/testing/cross_backend/default_backend_configs.d.ts +3 -3
- package/dist/testing/cross_backend/default_spine_surface.d.ts +0 -6
- package/dist/testing/cross_backend/default_spine_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/default_spine_surface.js +4 -9
- package/dist/testing/cross_backend/differential.d.ts +2 -3
- package/dist/testing/cross_backend/differential.d.ts.map +1 -1
- package/dist/testing/cross_backend/differential.js +1 -1
- package/dist/testing/cross_backend/full_spine_mount.d.ts +1 -42
- package/dist/testing/cross_backend/full_spine_mount.d.ts.map +1 -1
- package/dist/testing/cross_backend/full_spine_mount.js +45 -4
- package/dist/testing/cross_backend/in_process_setup.d.ts +6 -7
- package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/in_process_setup.js +9 -12
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +3 -4
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/rust_spine_consumer_surface.js +2 -2
- package/dist/testing/cross_backend/setup.d.ts +1 -1
- package/dist/testing/cross_backend/spine_suites.d.ts +2 -3
- package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_suites.js +5 -5
- package/dist/testing/cross_backend/standard.d.ts +2 -3
- package/dist/testing/cross_backend/standard.d.ts.map +1 -1
- package/dist/testing/cross_backend/standard.js +3 -3
- package/dist/testing/cross_backend/testing_credential_read.d.ts +10 -11
- package/dist/testing/cross_backend/testing_credential_read.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_credential_read.js +12 -12
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +35 -30
- package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_reset_actions.js +39 -31
- package/dist/testing/cross_backend/testing_server_core.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_server_core.js +2 -3
- package/dist/testing/daemon_token_rotation.d.ts.map +1 -1
- package/dist/testing/daemon_token_rotation.js +2 -3
- package/dist/testing/integration.d.ts +2 -3
- package/dist/testing/integration.d.ts.map +1 -1
- package/dist/testing/integration.js +4 -4
- package/dist/testing/rate_limiting.d.ts +2 -3
- package/dist/testing/rate_limiting.d.ts.map +1 -1
- package/dist/testing/rate_limiting.js +3 -3
- package/dist/testing/rpc_helpers.d.ts +1 -2
- package/dist/testing/rpc_helpers.d.ts.map +1 -1
- package/dist/testing/rpc_helpers.js +3 -3
- package/dist/testing/rpc_round_trip.d.ts +2 -3
- package/dist/testing/rpc_round_trip.d.ts.map +1 -1
- package/dist/testing/rpc_round_trip.js +1 -1
- package/dist/testing/sse_round_trip.d.ts +2 -3
- package/dist/testing/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/sse_round_trip.js +2 -2
- package/dist/testing/stubs.d.ts +5 -6
- package/dist/testing/stubs.d.ts.map +1 -1
- package/dist/testing/stubs.js +10 -8
- package/dist/testing/test_app.d.ts +5 -3
- package/dist/testing/test_app.d.ts.map +1 -1
- package/dist/testing/test_app.js +2 -3
- package/dist/testing/ws_round_trip.d.ts.map +1 -1
- package/dist/testing/ws_round_trip.js +3 -0
- package/dist/ui/ui_format.d.ts.map +1 -1
- package/dist/ui/ui_format.js +1 -2
- package/package.json +1 -1
|
@@ -11,7 +11,6 @@ import { Hono, type Context } from 'hono';
|
|
|
11
11
|
import type { UpgradeWebSocket } from 'hono/ws';
|
|
12
12
|
import type { AnySchema } from '@fuzdev/fuz_schema/schema.ts';
|
|
13
13
|
import type { Logger } from '@fuzdev/fuz_util/log.ts';
|
|
14
|
-
import { type SessionOptions } from '../auth/session_cookie.js';
|
|
15
14
|
import type { BootstrapTokenStore } from '../auth/bootstrap_token_store.js';
|
|
16
15
|
import { type EventSpec } from '../realtime/sse.js';
|
|
17
16
|
import { type AuditLogSse } from '../realtime/audit_log_sse.js';
|
|
@@ -25,8 +24,8 @@ import { type ServeStaticFactory } from './static.js';
|
|
|
25
24
|
import { type AppSurfaceSpec, type AppSurfaceDiagnostic, type RpcEndpointSpec } from '../http/surface.js';
|
|
26
25
|
import { type RouteSpec } from '../http/route_spec.js';
|
|
27
26
|
import type { MiddlewareCarveOut, MiddlewareSpec } from '../http/middleware_spec.js';
|
|
28
|
-
import { type BootstrapStatus
|
|
29
|
-
import { type EffectErrorContext } from '../http/pending_effects.js';
|
|
27
|
+
import { type BootstrapStatus } from '../auth/bootstrap_routes.js';
|
|
28
|
+
import { type EffectErrorContext, type RequestTracker } from '../http/pending_effects.js';
|
|
30
29
|
import { type WsEndpointSpec } from '../actions/ws_endpoint_spec.js';
|
|
31
30
|
import type { ConnectionRegistry } from '../actions/connection_registry.js';
|
|
32
31
|
import { type AuthCleanupScheduleOptions } from '../auth/cleanup.js';
|
|
@@ -46,7 +45,7 @@ import type { AuditEmitter } from '../auth/audit_emitter.js';
|
|
|
46
45
|
* Equivalent to omitting `bootstrap` entirely; the explicit mode is
|
|
47
46
|
* for documentation and reviewable intent at the wiring layer.
|
|
48
47
|
* - `surface_only` — route present, permanent 403 via
|
|
49
|
-
* `
|
|
48
|
+
* `is_bootstrap_available`. For tests asserting on the
|
|
50
49
|
* disabled-but-present wire shape.
|
|
51
50
|
* - `live` — route mounted, real token verification. Success path
|
|
52
51
|
* reachable. `token_store` is required.
|
|
@@ -70,8 +69,6 @@ export interface BootstrapLiveOptions {
|
|
|
70
69
|
token_store: BootstrapTokenStore;
|
|
71
70
|
/** Route prefix for bootstrap routes. Default `'/api/account'`; must sit under `/api/`. */
|
|
72
71
|
route_prefix?: string;
|
|
73
|
-
/** Called after a successful bootstrap commits (see `OnBootstrap`). */
|
|
74
|
-
on_bootstrap?: OnBootstrap;
|
|
75
72
|
}
|
|
76
73
|
/**
|
|
77
74
|
* Configuration for `create_app_server()`.
|
|
@@ -83,12 +80,11 @@ export interface AppServerOptions {
|
|
|
83
80
|
/** Pre-initialized backend from `create_app_backend()`. */
|
|
84
81
|
backend: AppBackend;
|
|
85
82
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* the `Set-Cookie` grammar cannot carry.
|
|
83
|
+
* The session cookie's name (`SESSION_COOKIE_NAME` is the spine default).
|
|
84
|
+
* Assembly throws on a name that is no RFC 6265 cookie-name, which the
|
|
85
|
+
* `Set-Cookie` grammar cannot carry.
|
|
90
86
|
*/
|
|
91
|
-
|
|
87
|
+
session_cookie_name: string;
|
|
92
88
|
/**
|
|
93
89
|
* Parsed allowed origin patterns, as `parse_allowed_origins` returns them
|
|
94
90
|
* (`validate_server_env`'s `allowed_origins`); assembly throws on a matcher
|
|
@@ -224,7 +220,14 @@ export interface AppServerOptions {
|
|
|
224
220
|
* error map declares its `413` and `400`; with `null` it is absent.
|
|
225
221
|
*/
|
|
226
222
|
max_body_size?: number | null;
|
|
227
|
-
/**
|
|
223
|
+
/**
|
|
224
|
+
* Daemon token state for keeper auth. Omit to disable. A null
|
|
225
|
+
* `keeper_account_id` is resolved from the database at assembly (an
|
|
226
|
+
* already-bootstrapped server), and a live bootstrap sets it once its
|
|
227
|
+
* account commits; the daemon leg never re-reads it per request, so a
|
|
228
|
+
* keeper seeded by another process (`seed_dev_account`) needs a restart,
|
|
229
|
+
* as on the Rust spine.
|
|
230
|
+
*/
|
|
228
231
|
daemon_token_state?: DaemonTokenState;
|
|
229
232
|
/** Bootstrap options. Omit to skip bootstrap status check and routes. */
|
|
230
233
|
bootstrap?: BootstrapServerOptions;
|
|
@@ -426,9 +429,10 @@ export interface AppServerOptions {
|
|
|
426
429
|
*/
|
|
427
430
|
await_pending_effects?: boolean;
|
|
428
431
|
/**
|
|
429
|
-
* How long `AppServer.close` waits for the
|
|
430
|
-
* request
|
|
431
|
-
*
|
|
432
|
+
* How long `AppServer.close` waits for the work still in flight — each
|
|
433
|
+
* HTTP request and WS message accepted, until its handler has returned and
|
|
434
|
+
* its effect queues (failure audit rows, API token usage, post-commit
|
|
435
|
+
* thunks) have flushed, and every pool write of `deps.audit` — before it
|
|
432
436
|
* closes the database. What is still running then is given up on and
|
|
433
437
|
* logged. Default `DEFAULT_SHUTDOWN_DRAIN_TIMEOUT_MS`; must be a positive
|
|
434
438
|
* number of ms.
|
|
@@ -485,11 +489,23 @@ export interface AppServer {
|
|
|
485
489
|
* is left closing, so an upgrade or stream that registers afterward is
|
|
486
490
|
* born closed — refused at once rather than outliving the server — and
|
|
487
491
|
* a closed registry hosts no other server
|
|
488
|
-
* 3. wait for the
|
|
489
|
-
* `
|
|
490
|
-
*
|
|
491
|
-
*
|
|
492
|
-
*
|
|
492
|
+
* 3. wait for the work still in flight on `deps.request_tracker` and
|
|
493
|
+
* `deps.audit`: every HTTP request and WS message accepted, until its
|
|
494
|
+
* handler has returned and its effect queues have flushed (failure
|
|
495
|
+
* audit rows, API token usage, post-commit thunks; production holds no
|
|
496
|
+
* HTTP response for them, and a WS reply is sent before its flush), and
|
|
497
|
+
* every pool write of the emitter — a handler still running when the
|
|
498
|
+
* close starts is waited for, then its flush. A WS handler's socket is
|
|
499
|
+
* closed in step 2, which aborts its `signal`; one that runs on is still
|
|
500
|
+
* waited for. Bounded by `shutdown_drain_timeout_ms`, logging what it
|
|
501
|
+
* gives up on. From here a request that arrives is refused — HTTP with
|
|
502
|
+
* 503 `service_unavailable`, and a WS message, on a socket step 2
|
|
503
|
+
* didn't end (a hand mount), with the `service_unavailable` JSON-RPC
|
|
504
|
+
* error — never run against the closing database. The Rust
|
|
505
|
+
* spine waits the same way for an HTTP request already dispatched, but
|
|
506
|
+
* drops a WS message's dispatch still in its handler with its socket
|
|
507
|
+
* loop, which rolls back; one whose commit has started finishes, its
|
|
508
|
+
* post-commit effects included
|
|
493
509
|
* 4. release what assembly acquired, last acquired first: remove the
|
|
494
510
|
* audit listeners `create_app_server` registered on `deps.audit` (the
|
|
495
511
|
* revocation guard, the audit-log SSE listener), the members it added
|
|
@@ -505,11 +521,14 @@ export interface AppServer {
|
|
|
505
521
|
* 5. close the database connection (`AppBackend.close`)
|
|
506
522
|
*
|
|
507
523
|
* Idempotent: a second call settles with the first one's outcome (a failed
|
|
508
|
-
* close is not retried), and concurrent calls share one shutdown.
|
|
524
|
+
* close is not retried), and concurrent calls share one shutdown. Never
|
|
525
|
+
* await it from a handler: its own request is held, so the drain waits on
|
|
526
|
+
* it until `shutdown_drain_timeout_ms`.
|
|
509
527
|
*
|
|
510
528
|
* Stop accepting new HTTP connections first — without awaiting the
|
|
511
529
|
* listener's full drain, since live WebSockets hold it open until `close`
|
|
512
|
-
* ends them — so no new request reaches a closed database.
|
|
530
|
+
* ends them — so no new request reaches a closed database. A request the
|
|
531
|
+
* app already accepted is waited for in step 3.
|
|
513
532
|
*/
|
|
514
533
|
close: () => Promise<void>;
|
|
515
534
|
}
|
|
@@ -699,22 +718,26 @@ export declare const collect_config_diagnostics: (input: ConfigDiagnosticsInput)
|
|
|
699
718
|
export declare const create_app_server: (options: AppServerOptions) => Promise<AppServer>;
|
|
700
719
|
/**
|
|
701
720
|
* What `drain_effects_on_shutdown` gave up on at its bound, each counted on
|
|
702
|
-
* its own: a request
|
|
703
|
-
*
|
|
721
|
+
* its own: a request still waiting on its audit writes has those writes
|
|
722
|
+
* counted in `audit_writes` too, so the two are not summed.
|
|
704
723
|
*/
|
|
705
724
|
export interface ShutdownDrainGivenUp {
|
|
706
|
-
/**
|
|
707
|
-
|
|
725
|
+
/**
|
|
726
|
+
* Requests still held — HTTP requests and WS messages alike, each with its
|
|
727
|
+
* handler or its effect flush still running.
|
|
728
|
+
*/
|
|
729
|
+
requests: number;
|
|
708
730
|
/** Pool writes of the audit emitter still in flight. */
|
|
709
731
|
audit_writes: number;
|
|
710
732
|
}
|
|
711
733
|
/**
|
|
712
|
-
* Wait for the
|
|
713
|
-
*
|
|
714
|
-
*
|
|
734
|
+
* Wait for the requests held (HTTP requests and WS messages, one tracker —
|
|
735
|
+
* each until its handler has returned and its flush settled) and then the
|
|
736
|
+
* audit emitter's pool writes, until none is left or `timeout_ms` passes —
|
|
737
|
+
* then log an error naming what was given up on. Never rejects.
|
|
715
738
|
*
|
|
716
739
|
* @returns what was given up on, both counts `0` when everything settled
|
|
717
740
|
*/
|
|
718
|
-
export declare const drain_effects_on_shutdown: (
|
|
741
|
+
export declare const drain_effects_on_shutdown: (requests: Pick<RequestTracker, "drain_inflight" | "inflight_count">, audit: Pick<AuditEmitter, "drain_inflight" | "inflight_count">, timeout_ms: number, log: Logger) => Promise<ShutdownDrainGivenUp>;
|
|
719
742
|
export {};
|
|
720
743
|
//# sourceMappingURL=app_server.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app_server.d.ts","sourceRoot":"","sources":["../../src/lib/server/app_server.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,IAAI,EAAE,KAAK,OAAO,EAAE,MAAM,MAAM,CAAC;AAE1C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"app_server.d.ts","sourceRoot":"","sources":["../../src/lib/server/app_server.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,IAAI,EAAE,KAAK,OAAO,EAAE,MAAM,MAAM,CAAC;AAE1C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAGtD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAqB,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAIN,KAAK,WAAW,EAChB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EACN,WAAW,EAMX,KAAK,eAAe,EACpB,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oB,CAgC5B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,eAAO,MAAM,iBAAiB,GAAU,SAAS,gBAAgB,KAAG,OAAO,CAAC,SAAS,CAQpF,CAAC;AAEF;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACpC;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB,wDAAwD;IACxD,YAAY,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,GACrC,UAAU,IAAI,CAAC,cAAc,EAAE,gBAAgB,GAAG,gBAAgB,CAAC,EACnE,OAAO,IAAI,CAAC,YAAY,EAAE,gBAAgB,GAAG,gBAAgB,CAAC,EAC9D,YAAY,MAAM,EAClB,KAAK,MAAM,KACT,OAAO,CAAC,oBAAoB,CA2B9B,CAAC"}
|
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { Hono } from 'hono';
|
|
11
11
|
import { logger } from 'hono/logger';
|
|
12
|
-
import {
|
|
13
|
-
import { generate_session_token } from '../auth/session_queries.js';
|
|
12
|
+
import { is_cookie_name } from '../auth/session_cookie.js';
|
|
14
13
|
import { create_sse_stream } from '../realtime/sse.js';
|
|
15
14
|
import { create_audit_log_sse, create_sse_connection_closer, audit_log_event_specs } from '../realtime/audit_log_sse.js';
|
|
16
15
|
import { BaseServerEnv } from './env.js';
|
|
17
16
|
import { RateLimiter, announce_rate_limiters_disabled, default_login_ip_rate_limit, default_login_account_rate_limit, default_action_account_rate_limit, default_action_ip_rate_limit } from '../rate_limiter.js';
|
|
17
|
+
import { resolve_keeper_account_id } from '../auth/daemon_token_middleware.js';
|
|
18
18
|
// Side-effect import: augments Hono's ContextVariableMap so consumers
|
|
19
19
|
// that import app_server get type-safe c.get('auth_session_id') etc.
|
|
20
20
|
import '../hono_context.js';
|
|
@@ -28,9 +28,10 @@ import { create_app_surface_spec } from '../http/surface.js';
|
|
|
28
28
|
import { create_dev_route_error_check } from '../http/dev_route_error_check.js';
|
|
29
29
|
import { create_dev_set_cookie_check } from '../http/dev_set_cookie_check.js';
|
|
30
30
|
import { apply_middleware_specs, apply_route_specs, prefix_route_specs } from '../http/route_spec.js';
|
|
31
|
-
import {
|
|
31
|
+
import { is_bootstrap_available, create_bootstrap_route_specs } from '../auth/bootstrap_routes.js';
|
|
32
32
|
import { create_surface_route_spec } from './surface_route.js';
|
|
33
|
-
import {
|
|
33
|
+
import { ERROR_SERVICE_UNAVAILABLE } from '../http/error_schemas.js';
|
|
34
|
+
import { create_request_tracker_view, flush_request_effects } from '../http/pending_effects.js';
|
|
34
35
|
import { assert_credential_routes_in_auth_scope, assert_endpoint_in_auth_scope, assert_middleware_stack_mounted, create_auth_middleware_specs } from '../auth/middleware.js';
|
|
35
36
|
import { fuz_auth_guard_resolver } from '../auth/auth_guard_resolver.js';
|
|
36
37
|
import { create_fuz_authorization_handler } from '../auth/request_context.js';
|
|
@@ -242,18 +243,21 @@ export const create_app_server = async (options) => {
|
|
|
242
243
|
}
|
|
243
244
|
};
|
|
244
245
|
/**
|
|
245
|
-
* Wait for the
|
|
246
|
-
*
|
|
247
|
-
*
|
|
246
|
+
* Wait for the requests held (HTTP requests and WS messages, one tracker —
|
|
247
|
+
* each until its handler has returned and its flush settled) and then the
|
|
248
|
+
* audit emitter's pool writes, until none is left or `timeout_ms` passes —
|
|
249
|
+
* then log an error naming what was given up on. Never rejects.
|
|
248
250
|
*
|
|
249
251
|
* @returns what was given up on, both counts `0` when everything settled
|
|
250
252
|
*/
|
|
251
|
-
export const drain_effects_on_shutdown = async (
|
|
253
|
+
export const drain_effects_on_shutdown = async (requests, audit, timeout_ms, log) => {
|
|
252
254
|
const drain = async () => {
|
|
253
|
-
//
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
255
|
+
// until both are empty: a flush's post-commit thunk can start an audit
|
|
256
|
+
// write, and a request accepted meanwhile is held too
|
|
257
|
+
do {
|
|
258
|
+
await requests.drain_inflight();
|
|
259
|
+
await audit.drain_inflight();
|
|
260
|
+
} while (requests.inflight_count() > 0 || audit.inflight_count() > 0);
|
|
257
261
|
};
|
|
258
262
|
let timer;
|
|
259
263
|
const timed_out = new Promise((resolve) => {
|
|
@@ -266,12 +270,12 @@ export const drain_effects_on_shutdown = async (inflight_flushes, audit, timeout
|
|
|
266
270
|
clearTimeout(timer);
|
|
267
271
|
}
|
|
268
272
|
const given_up = {
|
|
269
|
-
|
|
273
|
+
requests: requests.inflight_count(),
|
|
270
274
|
audit_writes: audit.inflight_count()
|
|
271
275
|
};
|
|
272
|
-
if (given_up.
|
|
276
|
+
if (given_up.requests === 0 && given_up.audit_writes === 0)
|
|
273
277
|
return given_up;
|
|
274
|
-
log.error(`create_app_server: shutdown gave up after ${timeout_ms}ms on
|
|
278
|
+
log.error(`create_app_server: shutdown gave up after ${timeout_ms}ms on work still running — ${given_up.requests} request(s) (handler or effect flush), ${given_up.audit_writes} audit row write(s)`);
|
|
275
279
|
return given_up;
|
|
276
280
|
};
|
|
277
281
|
/**
|
|
@@ -298,22 +302,11 @@ const assemble_app_server = async (options, releases) => {
|
|
|
298
302
|
const { deps } = backend;
|
|
299
303
|
const { log } = deps;
|
|
300
304
|
// option checks first, before anything is acquired
|
|
301
|
-
if (!is_cookie_name(options.
|
|
305
|
+
if (!is_cookie_name(options.session_cookie_name)) {
|
|
302
306
|
// a name the `Cookie` grammar cannot carry would be written as a header
|
|
303
|
-
// that reads back differently — refused here rather than at the first
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
// Mint a sample cookie the way a login does. Options that cannot write one
|
|
307
|
-
// — an `encode_identity` emitting a character outside the cookie grammar, a
|
|
308
|
-
// `max_age` that is no whole number of seconds — would otherwise throw at
|
|
309
|
-
// the first mint, which for bootstrap comes after its one-shot token is
|
|
310
|
-
// spent.
|
|
311
|
-
try {
|
|
312
|
-
format_session_set_cookie(options.session_options.cookie_name, await create_session_cookie_value(deps.keyring, generate_session_token(), options.session_options), options.session_options.max_age ?? SESSION_AGE_MAX);
|
|
313
|
-
}
|
|
314
|
-
catch (error) {
|
|
315
|
-
throw new Error('create_app_server: session_options cannot mint a session cookie — ' +
|
|
316
|
-
(error instanceof Error ? error.message : String(error)), { cause: error });
|
|
307
|
+
// that reads back differently — refused here rather than at the first
|
|
308
|
+
// mint, which for bootstrap comes after its one-shot token is spent
|
|
309
|
+
throw new Error(`create_app_server: session cookie name ${JSON.stringify(options.session_cookie_name)} is not an RFC 6265 cookie-name`);
|
|
317
310
|
}
|
|
318
311
|
if (options.allowed_origins.length === 0) {
|
|
319
312
|
throw new Error('create_app_server: allowed_origins is empty — list at least one origin pattern ' +
|
|
@@ -371,7 +364,7 @@ const assemble_app_server = async (options, releases) => {
|
|
|
371
364
|
// Auth middleware
|
|
372
365
|
const auth_middleware = await create_auth_middleware_specs(deps, {
|
|
373
366
|
allowed_origins: options.allowed_origins,
|
|
374
|
-
|
|
367
|
+
session_cookie_name: options.session_cookie_name,
|
|
375
368
|
daemon_token_state: options.daemon_token_state,
|
|
376
369
|
origin_carve_outs: options.origin_carve_outs
|
|
377
370
|
});
|
|
@@ -387,12 +380,35 @@ const assemble_app_server = async (options, releases) => {
|
|
|
387
380
|
middleware_specs = options.transform_middleware(stack_specs.map((spec) => ({ ...spec })));
|
|
388
381
|
assert_middleware_stack_mounted(stack_specs, middleware_specs);
|
|
389
382
|
}
|
|
383
|
+
// The daemon-token keeper, after the migrations and before the bootstrap
|
|
384
|
+
// check, as the Rust spine's boot runs `resolve_keeper_into`: a live
|
|
385
|
+
// bootstrap sets it on a fresh database once it commits, and this covers
|
|
386
|
+
// one already bootstrapped. Best-effort, as there: a failed read leaves it
|
|
387
|
+
// unset, and a keeper-less state authenticates no daemon token (the warn
|
|
388
|
+
// below has no twin; the Rust spine's failed read is silent).
|
|
389
|
+
const daemon_token_state = options.daemon_token_state;
|
|
390
|
+
if (daemon_token_state && daemon_token_state.keeper_account_id === null) {
|
|
391
|
+
try {
|
|
392
|
+
const keeper_account_id = await resolve_keeper_account_id(deps);
|
|
393
|
+
if (keeper_account_id !== null) {
|
|
394
|
+
daemon_token_state.keeper_account_id = keeper_account_id;
|
|
395
|
+
log.info('daemon token: keeper account resolved', { account_id: keeper_account_id });
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
catch (error) {
|
|
399
|
+
log.warn('daemon token: resolving the keeper account failed', error);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
390
402
|
// Bootstrap status
|
|
391
403
|
// - undefined / 'disabled': no route mounted; placeholder status.
|
|
392
404
|
// - 'surface_only': route mounted but permanently unavailable; status placeholder.
|
|
393
|
-
// - 'live': real disk + lock check via `
|
|
405
|
+
// - 'live': real disk + lock check via `is_bootstrap_available`.
|
|
394
406
|
const bootstrap_status = options.bootstrap?.mode === 'live'
|
|
395
|
-
?
|
|
407
|
+
? {
|
|
408
|
+
available: await is_bootstrap_available(deps, {
|
|
409
|
+
token_store: options.bootstrap.token_store
|
|
410
|
+
})
|
|
411
|
+
}
|
|
396
412
|
: { available: false };
|
|
397
413
|
// Surface route ref — factory manages the circular ref
|
|
398
414
|
const surface_ref = {
|
|
@@ -411,7 +427,7 @@ const assemble_app_server = async (options, releases) => {
|
|
|
411
427
|
deps,
|
|
412
428
|
backend,
|
|
413
429
|
bootstrap_status,
|
|
414
|
-
|
|
430
|
+
session_cookie_name: options.session_cookie_name,
|
|
415
431
|
...rate_limiters,
|
|
416
432
|
audit_sse
|
|
417
433
|
};
|
|
@@ -424,10 +440,11 @@ const assemble_app_server = async (options, releases) => {
|
|
|
424
440
|
// 'surface_only' and the post-bootstrap state for 'live'.
|
|
425
441
|
if (options.bootstrap && options.bootstrap.mode !== 'disabled') {
|
|
426
442
|
const bootstrap_routes = create_bootstrap_route_specs(deps, {
|
|
427
|
-
|
|
443
|
+
session_cookie_name: options.session_cookie_name,
|
|
428
444
|
bootstrap_status,
|
|
429
445
|
token_store: options.bootstrap.mode === 'live' ? options.bootstrap.token_store : null,
|
|
430
|
-
|
|
446
|
+
// a successful bootstrap sets its keeper here, after its commit
|
|
447
|
+
daemon_token_state: options.daemon_token_state ?? null,
|
|
431
448
|
bootstrap_ip_rate_limiter
|
|
432
449
|
});
|
|
433
450
|
const prefix = options.bootstrap.route_prefix ?? '/api/account';
|
|
@@ -602,13 +619,22 @@ const assemble_app_server = async (options, releases) => {
|
|
|
602
619
|
// writes to settle — a revocation's connection close must not sit behind
|
|
603
620
|
// a slow audit INSERT.
|
|
604
621
|
const on_effect_error = options.on_effect_error;
|
|
605
|
-
//
|
|
606
|
-
//
|
|
607
|
-
//
|
|
608
|
-
|
|
622
|
+
// Every request, HTTP and WS, is held on the backend's tracker from
|
|
623
|
+
// acceptance until its handler has returned and its flush settled — what
|
|
624
|
+
// shutdown waits on before the database closes. The WS endpoints mounted
|
|
625
|
+
// below hold their messages there too. Through this server's own view, so
|
|
626
|
+
// its shutdown refuses what arrives after it starts draining and leaves
|
|
627
|
+
// the backend's tracker open for a later server.
|
|
628
|
+
const request_tracker = create_request_tracker_view(deps.request_tracker);
|
|
609
629
|
app.use('*', async (c, next) => {
|
|
630
|
+
const accepted = request_tracker.accept();
|
|
631
|
+
// the server is shutting down: refused, never run against a closing
|
|
632
|
+
// database — the shape of a failed pool checkout (`app_error_handler.ts`)
|
|
633
|
+
if (!accepted)
|
|
634
|
+
return c.json({ error: ERROR_SERVICE_UNAVAILABLE }, 503);
|
|
610
635
|
c.set('pending_effects', []);
|
|
611
636
|
c.set('post_commit_effects', []);
|
|
637
|
+
let flushed = null;
|
|
612
638
|
try {
|
|
613
639
|
await next();
|
|
614
640
|
}
|
|
@@ -621,16 +647,13 @@ const assemble_app_server = async (options, releases) => {
|
|
|
621
647
|
method: c.req.method,
|
|
622
648
|
path: c.req.path
|
|
623
649
|
};
|
|
624
|
-
|
|
625
|
-
if (options.await_pending_effects) {
|
|
626
|
-
await flushed;
|
|
627
|
-
}
|
|
628
|
-
else {
|
|
629
|
-
inflight_flushes.add(flushed);
|
|
630
|
-
void flushed.then(() => inflight_flushes.delete(flushed));
|
|
631
|
-
}
|
|
650
|
+
flushed = flush_request_effects(eager, deferred, log, on_effect_error ? (reason) => on_effect_error(reason, error_ctx) : undefined);
|
|
632
651
|
}
|
|
652
|
+
accepted.finish(flushed);
|
|
653
|
+
if (flushed && options.await_pending_effects)
|
|
654
|
+
await flushed;
|
|
633
655
|
}
|
|
656
|
+
return;
|
|
634
657
|
});
|
|
635
658
|
if (log.level !== 'off') {
|
|
636
659
|
app.use(logger((msg) => log.info(msg)));
|
|
@@ -676,7 +699,8 @@ const assemble_app_server = async (options, releases) => {
|
|
|
676
699
|
action_ip_rate_limiter,
|
|
677
700
|
action_account_rate_limiter,
|
|
678
701
|
notification_sender: deps.notification_sender,
|
|
679
|
-
on_effect_error
|
|
702
|
+
on_effect_error,
|
|
703
|
+
request_tracker
|
|
680
704
|
});
|
|
681
705
|
mounted_ws_endpoints[endpoint.path] = endpoint_registry;
|
|
682
706
|
// every revocation's close — the handlers' and the guard's — reaches
|
|
@@ -725,10 +749,14 @@ const assemble_app_server = async (options, releases) => {
|
|
|
725
749
|
catch (error) {
|
|
726
750
|
log.error('create_app_server: closing live connections on shutdown failed:', error);
|
|
727
751
|
}
|
|
728
|
-
// then the
|
|
729
|
-
//
|
|
730
|
-
//
|
|
731
|
-
|
|
752
|
+
// then the work still in flight, refusing any request that arrives from
|
|
753
|
+
// here, so a handler still running, and the failure row, token-usage
|
|
754
|
+
// touch or post-commit thunk a request or WS message started, is not cut
|
|
755
|
+
// off by the closing pool — bounded. The Rust spine's drain waits for an
|
|
756
|
+
// HTTP request already dispatched too, but drops a WS message's dispatch
|
|
757
|
+
// still in its handler (`http/CLAUDE.md` §Pending Effects)
|
|
758
|
+
request_tracker.close();
|
|
759
|
+
await drain_effects_on_shutdown(request_tracker, deps.audit, shutdown_drain_timeout_ms, log);
|
|
732
760
|
// then what assembly acquired — the audit listeners and closer members
|
|
733
761
|
// this server added, and the limiters it built
|
|
734
762
|
run_releases(releases, log, 'shutdown');
|
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
import type { AppDeps } from '../auth/deps.js';
|
|
17
17
|
import type { AppBackend } from './app_backend.js';
|
|
18
18
|
import type { BootstrapStatus } from '../auth/bootstrap_routes.js';
|
|
19
|
-
import type { SessionOptions } from '../auth/session_cookie.js';
|
|
20
19
|
import type { RateLimiter } from '../rate_limiter.js';
|
|
21
20
|
import type { AuditLogSse } from '../realtime/audit_log_sse.js';
|
|
22
21
|
/** Context passed to `create_route_specs`. */
|
|
@@ -24,7 +23,7 @@ export interface AppServerContext {
|
|
|
24
23
|
deps: AppDeps;
|
|
25
24
|
backend: AppBackend;
|
|
26
25
|
bootstrap_status: BootstrapStatus;
|
|
27
|
-
|
|
26
|
+
session_cookie_name: string;
|
|
28
27
|
/**
|
|
29
28
|
* Per-IP login + password-change rate limiter. One instance per auth
|
|
30
29
|
* surface — see `AppServerOptions.login_ip_rate_limiter` for why these
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app_server_context.d.ts","sourceRoot":"","sources":["../../src/lib/server/app_server_context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"app_server_context.d.ts","sourceRoot":"","sources":["../../src/lib/server/app_server_context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAEhE,8CAA8C;AAC9C,MAAM,WAAW,gBAAgB;IAChC,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,UAAU,CAAC;IACpB,gBAAgB,EAAE,eAAe,CAAC;IAClC,mBAAmB,EAAE,MAAM,CAAC;IAC5B;;;;;;;;;OASG;IACH,qBAAqB,EAAE,WAAW,GAAG,IAAI,CAAC;IAC1C,wDAAwD;IACxD,sBAAsB,EAAE,WAAW,GAAG,IAAI,CAAC;IAC3C,2DAA2D;IAC3D,yBAAyB,EAAE,WAAW,GAAG,IAAI,CAAC;IAC9C,4DAA4D;IAC5D,0BAA0B,EAAE,WAAW,GAAG,IAAI,CAAC;IAC/C,6DAA6D;IAC7D,2BAA2B,EAAE,WAAW,GAAG,IAAI,CAAC;IAChD,iGAAiG;IACjG,sBAAsB,EAAE,WAAW,GAAG,IAAI,CAAC;IAC3C;;;OAGG;IACH,2BAA2B,EAAE,WAAW,GAAG,IAAI,CAAC;IAChD;;;;OAIG;IACH,SAAS,EAAE,WAAW,GAAG,IAAI,CAAC;CAC9B"}
|
package/dist/server/env.js
CHANGED
|
@@ -61,10 +61,10 @@ export const BaseServerEnv = object({
|
|
|
61
61
|
sensitivity: 'secret'
|
|
62
62
|
}),
|
|
63
63
|
FUZ_DB_CHECKOUT_TIMEOUT_MS: meta(optional(env_integer({ min: 1, max: DB_CHECKOUT_TIMEOUT_MAX_MS })), {
|
|
64
|
-
description: 'Bound on the pool checkouts a request makes, in ms (default 5000); a failed checkout answers 503. Audit writes use FUZ_DB_AUDIT_CHECKOUT_TIMEOUT_MS instead
|
|
64
|
+
description: 'Bound on the pool checkouts a request makes, in ms (default 5000); a failed checkout answers 503. Audit pool writes (failure rows) use FUZ_DB_AUDIT_CHECKOUT_TIMEOUT_MS instead. Postgres only — PGlite and pglet have no pool'
|
|
65
65
|
}),
|
|
66
66
|
FUZ_DB_AUDIT_CHECKOUT_TIMEOUT_MS: meta(optional(env_integer({ min: 1, max: DB_CHECKOUT_TIMEOUT_MAX_MS })), {
|
|
67
|
-
description: 'Bound on the checkout behind each audit pool write, in ms (default 30000);
|
|
67
|
+
description: 'Bound on the checkout behind each audit pool write (a failure row), in ms (default 30000); no response waits on one, and shutdown drains them within its own bound. Postgres only'
|
|
68
68
|
})
|
|
69
69
|
});
|
|
70
70
|
/**
|