@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
|
@@ -16,7 +16,7 @@ import { ROLE_ADMIN, ROLE_KEEPER } from './role_schema.js';
|
|
|
16
16
|
import { query_create_account_with_actor } from './account_queries.js';
|
|
17
17
|
import { query_create_role_grant } from './role_grant_queries.js';
|
|
18
18
|
import { transaction_with_post_commit_rollback } from '../http/pending_effects.js';
|
|
19
|
-
import {
|
|
19
|
+
import { sign_session_cookie } from './session_cookie.js';
|
|
20
20
|
import { create_capped_session } from './session_queries.js';
|
|
21
21
|
import { DEFAULT_MAX_SESSIONS } from './account_route_schema.js';
|
|
22
22
|
/**
|
|
@@ -102,7 +102,7 @@ export const read_bootstrap_token = async (deps) => {
|
|
|
102
102
|
* @param provided_token - the bootstrap token from the user
|
|
103
103
|
* @param input - username and password
|
|
104
104
|
* @param options - the session cookie configuration
|
|
105
|
-
* @returns the created account
|
|
105
|
+
* @returns the created account and actor, and the session's `Set-Cookie` line — or a bootstrap failure
|
|
106
106
|
* @mutates `bootstrap_lock` row - flips `bootstrapped` to `true` atomically
|
|
107
107
|
* @mutates `account` / `actor` / `role_grant` / `auth_session` / `audit_log` tables - inserts the bootstrap account, actor, keeper + admin role_grants, session, and success row
|
|
108
108
|
* @mutates `ctx.post_commit_effects` - appends the success row's listener fan-out, discarded on rollback
|
|
@@ -145,13 +145,13 @@ export const bootstrap_account = async (deps, ctx, provided_token, input, option
|
|
|
145
145
|
username: input.username,
|
|
146
146
|
password_hash
|
|
147
147
|
});
|
|
148
|
-
|
|
148
|
+
await query_create_role_grant(tx_ctx, {
|
|
149
149
|
actor_id: actor.id,
|
|
150
150
|
role: ROLE_KEEPER,
|
|
151
151
|
granted_by: null,
|
|
152
152
|
expires_at: null
|
|
153
153
|
});
|
|
154
|
-
|
|
154
|
+
await query_create_role_grant(tx_ctx, {
|
|
155
155
|
actor_id: actor.id,
|
|
156
156
|
role: ROLE_ADMIN,
|
|
157
157
|
granted_by: null,
|
|
@@ -160,16 +160,14 @@ export const bootstrap_account = async (deps, ctx, provided_token, input, option
|
|
|
160
160
|
// The account was created above, so the cap evicts nothing. Routed
|
|
161
161
|
// through the shared minter anyway: the cap is a property of session
|
|
162
162
|
// creation, not of the login route.
|
|
163
|
-
const {
|
|
164
|
-
keyring,
|
|
163
|
+
const { token: session_token } = await create_capped_session({
|
|
165
164
|
deps: tx_ctx,
|
|
166
165
|
account_id: account.id,
|
|
167
|
-
session_options: options.session_options,
|
|
168
166
|
max_sessions: DEFAULT_MAX_SESSIONS
|
|
169
167
|
});
|
|
170
|
-
//
|
|
171
|
-
//
|
|
172
|
-
const set_cookie =
|
|
168
|
+
// signed here, as login and signup sign theirs: a line the formatter
|
|
169
|
+
// refuses rolls the bootstrap back with the token unburned
|
|
170
|
+
const set_cookie = await sign_session_cookie(keyring, session_token, options.session_cookie_name);
|
|
173
171
|
// The success row, in the transaction and ahead of the burn: a refused
|
|
174
172
|
// INSERT rolls the bootstrap back with the token unburned and the
|
|
175
173
|
// window open, as a failed insert above does.
|
|
@@ -193,9 +191,9 @@ export const bootstrap_account = async (deps, ctx, provided_token, input, option
|
|
|
193
191
|
}
|
|
194
192
|
return {
|
|
195
193
|
ok: true,
|
|
194
|
+
session_token,
|
|
196
195
|
account,
|
|
197
196
|
actor,
|
|
198
|
-
role_grants: { keeper: keeper_role_grant, admin: admin_role_grant },
|
|
199
197
|
set_cookie
|
|
200
198
|
};
|
|
201
199
|
});
|
|
@@ -7,8 +7,7 @@
|
|
|
7
7
|
* @module
|
|
8
8
|
*/
|
|
9
9
|
import type { Logger } from '@fuzdev/fuz_util/log.ts';
|
|
10
|
-
import type {
|
|
11
|
-
import { type BootstrapAccountCreated } from './bootstrap_account.js';
|
|
10
|
+
import type { DaemonTokenState } from './daemon_token.js';
|
|
12
11
|
import type { BootstrapTokenStore } from './bootstrap_token_store.js';
|
|
13
12
|
import type { Db } from '../db/db.js';
|
|
14
13
|
import { type RouteSpec } from '../http/route_spec.js';
|
|
@@ -21,22 +20,15 @@ import type { RouteFactoryDeps } from './deps.js';
|
|
|
21
20
|
export interface BootstrapStatus {
|
|
22
21
|
available: boolean;
|
|
23
22
|
}
|
|
24
|
-
/**
|
|
25
|
-
* Called after a successful bootstrap has committed, with what it created.
|
|
26
|
-
* Use for app-specific post-bootstrap work like generating API tokens. It
|
|
27
|
-
* gets no request context: the response — its session cookie included — is
|
|
28
|
-
* the route's. A throw is logged and the bootstrap still succeeds, since it
|
|
29
|
-
* has already committed. Twin of the Rust `BootstrapKeeperResolved`.
|
|
30
|
-
*/
|
|
31
|
-
export type OnBootstrap = (created: BootstrapAccountCreated) => Promise<void>;
|
|
32
23
|
/**
|
|
33
24
|
* Per-factory configuration for bootstrap route specs.
|
|
34
25
|
*
|
|
35
|
-
* `bootstrap_status`
|
|
36
|
-
*
|
|
26
|
+
* `bootstrap_status` and `daemon_token_state` are runtime state (mutable refs),
|
|
27
|
+
* not deps or options values — passed through so the route handler can flip
|
|
28
|
+
* the one and set the other's keeper.
|
|
37
29
|
*/
|
|
38
30
|
export interface BootstrapRouteOptions {
|
|
39
|
-
|
|
31
|
+
session_cookie_name: string;
|
|
40
32
|
/** Shared mutable reference — flipped to false when the window closes. */
|
|
41
33
|
bootstrap_status: BootstrapStatus;
|
|
42
34
|
/**
|
|
@@ -45,8 +37,14 @@ export interface BootstrapRouteOptions {
|
|
|
45
37
|
* server does.
|
|
46
38
|
*/
|
|
47
39
|
token_store: BootstrapTokenStore | null;
|
|
48
|
-
/**
|
|
49
|
-
|
|
40
|
+
/**
|
|
41
|
+
* The daemon-token state whose `keeper_account_id` a successful bootstrap
|
|
42
|
+
* sets to the new account once it has committed, so the keeper's daemon
|
|
43
|
+
* token authenticates from the next request; `null` when the server takes
|
|
44
|
+
* no daemon token. `create_app_server` passes its own. Twin of the Rust
|
|
45
|
+
* `BootstrapOptions.on_keeper_resolved`, which the spine wires the same way.
|
|
46
|
+
*/
|
|
47
|
+
daemon_token_state: DaemonTokenState | null;
|
|
50
48
|
/**
|
|
51
49
|
* Rate limiter for bootstrap attempts, keyed by client IP. Pass `null` to
|
|
52
50
|
* disable. Its own instance, not login's: bootstrap is one-shot and its
|
|
@@ -62,15 +60,16 @@ export interface BootstrapRouteOptions {
|
|
|
62
60
|
bootstrap_ip_rate_limiter: RateLimiter | null;
|
|
63
61
|
}
|
|
64
62
|
/**
|
|
65
|
-
* Dependencies for
|
|
63
|
+
* Dependencies for `is_bootstrap_available`.
|
|
66
64
|
*/
|
|
67
|
-
export interface
|
|
65
|
+
export interface IsBootstrapAvailableDeps {
|
|
68
66
|
/** Only the single-row `bootstrap_lock` read — narrower than the full `Db`. */
|
|
69
67
|
db: Pick<Db, 'query_one'>;
|
|
70
68
|
log: Logger;
|
|
71
69
|
}
|
|
72
70
|
/**
|
|
73
|
-
*
|
|
71
|
+
* Whether bootstrap is available — read once at startup into the
|
|
72
|
+
* `BootstrapStatus` ref.
|
|
74
73
|
*
|
|
75
74
|
* Bootstrap is available when a token store is configured, the
|
|
76
75
|
* `bootstrap_lock` row shows `bootstrapped = false`, and the token file
|
|
@@ -94,11 +93,11 @@ export interface CheckBootstrapStatusDeps {
|
|
|
94
93
|
*
|
|
95
94
|
* @param deps - the lock read and a logger
|
|
96
95
|
* @param options - the token store, `null` when bootstrap is not configured
|
|
97
|
-
* @returns the
|
|
96
|
+
* @returns whether the bootstrap window is open
|
|
98
97
|
*/
|
|
99
|
-
export declare const
|
|
98
|
+
export declare const is_bootstrap_available: (deps: IsBootstrapAvailableDeps, options: {
|
|
100
99
|
token_store: BootstrapTokenStore | null;
|
|
101
|
-
}) => Promise<
|
|
100
|
+
}) => Promise<boolean>;
|
|
102
101
|
/**
|
|
103
102
|
* Create bootstrap route specs for first-time account creation.
|
|
104
103
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap_routes.d.ts","sourceRoot":"","sources":["../../src/lib/auth/bootstrap_routes.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"bootstrap_routes.d.ts","sourceRoot":"","sources":["../../src/lib/auth/bootstrap_routes.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAGtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAwB,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAG7E,OAAO,EAAoB,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAYlD;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC/B,SAAS,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,qBAAqB;IACrC,mBAAmB,EAAE,MAAM,CAAC;IAC5B,0EAA0E;IAC1E,gBAAgB,EAAE,eAAe,CAAC;IAClC;;;;OAIG;IACH,WAAW,EAAE,mBAAmB,GAAG,IAAI,CAAC;IACxC;;;;;;OAMG;IACH,kBAAkB,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAC5C;;;;;;;;;;;OAWG;IACH,yBAAyB,EAAE,WAAW,GAAG,IAAI,CAAC;CAC9C;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACxC,+EAA+E;IAC/E,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,WAAW,CAAC,CAAC;IAC1B,GAAG,EAAE,MAAM,CAAC;CACZ;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,sBAAsB,GAClC,MAAM,wBAAwB,EAC9B,SAAS;IAAE,WAAW,EAAE,mBAAmB,GAAG,IAAI,CAAA;CAAE,KAClD,OAAO,CAAC,OAAO,CA0CjB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B,GACxC,MAAM,gBAAgB,EACtB,SAAS,qBAAqB,KAC5B,KAAK,CAAC,SAAS,CA8HjB,CAAC"}
|
|
@@ -15,7 +15,8 @@ import { rate_limit_ip_key } from '../http/ip_canonical.js';
|
|
|
15
15
|
import { reserve_optional } from '../rate_limiter.js';
|
|
16
16
|
import { ERROR_ALREADY_BOOTSTRAPPED, ERROR_TOKEN_FILE_MISSING, ERROR_TOKEN_FILE_UNDELETABLE, REST_ALREADY_BOOTSTRAPPED, REST_INVALID_TOKEN, REST_RATE_LIMIT_EXCEEDED, REST_TOKEN_FILE_MISSING, REST_TOKEN_FILE_UNDELETABLE } from '../http/error_schemas.js';
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
18
|
+
* Whether bootstrap is available — read once at startup into the
|
|
19
|
+
* `BootstrapStatus` ref.
|
|
19
20
|
*
|
|
20
21
|
* Bootstrap is available when a token store is configured, the
|
|
21
22
|
* `bootstrap_lock` row shows `bootstrapped = false`, and the token file
|
|
@@ -39,17 +40,17 @@ import { ERROR_ALREADY_BOOTSTRAPPED, ERROR_TOKEN_FILE_MISSING, ERROR_TOKEN_FILE_
|
|
|
39
40
|
*
|
|
40
41
|
* @param deps - the lock read and a logger
|
|
41
42
|
* @param options - the token store, `null` when bootstrap is not configured
|
|
42
|
-
* @returns the
|
|
43
|
+
* @returns whether the bootstrap window is open
|
|
43
44
|
*/
|
|
44
|
-
export const
|
|
45
|
+
export const is_bootstrap_available = async (deps, options) => {
|
|
45
46
|
const { db, log } = deps;
|
|
46
47
|
const { token_store } = options;
|
|
47
48
|
if (!token_store)
|
|
48
|
-
return
|
|
49
|
+
return false;
|
|
49
50
|
const lock_row = await db.query_one('SELECT bootstrapped FROM bootstrap_lock WHERE id = 1');
|
|
50
51
|
if (!lock_row) {
|
|
51
52
|
log.error('Bootstrap unavailable: the bootstrap_lock row is missing — the auth migration seeds it; restore it to bootstrap');
|
|
52
|
-
return
|
|
53
|
+
return false;
|
|
53
54
|
}
|
|
54
55
|
if (lock_row.bootstrapped) {
|
|
55
56
|
let present = true;
|
|
@@ -65,17 +66,17 @@ export const check_bootstrap_status = async (deps, options) => {
|
|
|
65
66
|
else {
|
|
66
67
|
log.info('Bootstrap unavailable: already bootstrapped');
|
|
67
68
|
}
|
|
68
|
-
return
|
|
69
|
+
return false;
|
|
69
70
|
}
|
|
70
71
|
try {
|
|
71
72
|
await read_bootstrap_token({ token_store, log });
|
|
72
73
|
}
|
|
73
74
|
catch (err) {
|
|
74
75
|
log.warn(`Bootstrap unavailable: token file unreadable: ${to_error_message(err)}`);
|
|
75
|
-
return
|
|
76
|
+
return false;
|
|
76
77
|
}
|
|
77
78
|
log.info(`Bootstrap token available: ${token_store.path}`);
|
|
78
|
-
return
|
|
79
|
+
return true;
|
|
79
80
|
};
|
|
80
81
|
/**
|
|
81
82
|
* Create bootstrap route specs for first-time account creation.
|
|
@@ -85,7 +86,7 @@ export const check_bootstrap_status = async (deps, options) => {
|
|
|
85
86
|
* @returns route specs (not yet applied to Hono)
|
|
86
87
|
*/
|
|
87
88
|
export const create_bootstrap_route_specs = (deps, options) => {
|
|
88
|
-
const {
|
|
89
|
+
const { session_cookie_name, bootstrap_status, token_store, daemon_token_state, bootstrap_ip_rate_limiter } = options;
|
|
89
90
|
return [
|
|
90
91
|
attach_route_handler(bootstrap_route_shape, async (route) => {
|
|
91
92
|
// Short-circuit if bootstrap already completed or surface-only mounted.
|
|
@@ -124,7 +125,7 @@ export const create_bootstrap_route_specs = (deps, options) => {
|
|
|
124
125
|
keyring: deps.keyring,
|
|
125
126
|
audit: deps.audit,
|
|
126
127
|
log: deps.log
|
|
127
|
-
}, route, input.token, input, {
|
|
128
|
+
}, route, input.token, input, { session_cookie_name });
|
|
128
129
|
if (!result.ok) {
|
|
129
130
|
// The lock-race loser — the window open here, the lock already
|
|
130
131
|
// flipped in the database. Close the window so the next caller
|
|
@@ -138,7 +139,7 @@ export const create_bootstrap_route_specs = (deps, options) => {
|
|
|
138
139
|
return route_fail(REST_ALREADY_BOOTSTRAPPED);
|
|
139
140
|
}
|
|
140
141
|
// An unreadable token file closes the window. Bootstrap cannot
|
|
141
|
-
// succeed without one, and `
|
|
142
|
+
// succeed without one, and `is_bootstrap_available` already reads
|
|
142
143
|
// an unreadable file as unavailable at startup — so leaving the
|
|
143
144
|
// flag set means the two disagree, and every later request takes
|
|
144
145
|
// this leg and writes another audit row. A wrong token and an
|
|
@@ -168,14 +169,15 @@ export const create_bootstrap_route_specs = (deps, options) => {
|
|
|
168
169
|
bootstrap_status.available = false;
|
|
169
170
|
// the session was minted, and its cookie line formatted, in the
|
|
170
171
|
// transaction; the line rides the success
|
|
171
|
-
const { account, actor,
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
172
|
+
const { account, actor, set_cookie } = result;
|
|
173
|
+
// the new keeper, set only now that its account has committed, so
|
|
174
|
+
// the daemon leg never resolves to a row a rollback could undo
|
|
175
|
+
if (daemon_token_state) {
|
|
176
|
+
daemon_token_state.keeper_account_id = account.id;
|
|
177
|
+
// the Rust spine's `DaemonTokenKeeperResolved` line
|
|
178
|
+
deps.log.info('daemon token: keeper account set by bootstrap', {
|
|
179
|
+
account_id: account.id
|
|
180
|
+
});
|
|
179
181
|
}
|
|
180
182
|
return route_ok({
|
|
181
183
|
ok: true,
|
|
@@ -18,9 +18,8 @@ import type { BurnOutcome } from '../runtime/secure_file.js';
|
|
|
18
18
|
* the caller strips one trailing LF and compares in constant time.
|
|
19
19
|
*
|
|
20
20
|
* Twin of the Rust `BootstrapTokenStore` trait, which has no `path`: the Rust
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* log lines from here.
|
|
21
|
+
* `is_bootstrap_available` takes the path itself, while the TS one reads
|
|
22
|
+
* through this store and names the file in its log lines from here.
|
|
24
23
|
*/
|
|
25
24
|
export interface BootstrapTokenStore {
|
|
26
25
|
/** Where the token lives, named in operator log lines — never the token itself. */
|
|
@@ -49,7 +48,7 @@ export interface BootstrapTokenStore {
|
|
|
49
48
|
* burn (`burn_secure_file` — unlink, then fsync the directory). The read
|
|
50
49
|
* alone of the runtime's secure reads asks for a single link
|
|
51
50
|
* (`BOOTSTRAP_TOKEN_READ_OPTIONS`): both of bootstrap's reads, the boot check
|
|
52
|
-
* (`
|
|
51
|
+
* (`is_bootstrap_available`) and the request's, go through it. Twin of the
|
|
53
52
|
* Rust `FileBootstrapTokenStore`.
|
|
54
53
|
*
|
|
55
54
|
* @param deps - the runtime's secure read and burn (`create_node_runtime()` satisfies both)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap_token_store.d.ts","sourceRoot":"","sources":["../../src/lib/auth/bootstrap_token_store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC7E,OAAO,KAAK,EAAE,WAAW,EAAqB,MAAM,2BAA2B,CAAC;AAEhF
|
|
1
|
+
{"version":3,"file":"bootstrap_token_store.d.ts","sourceRoot":"","sources":["../../src/lib/auth/bootstrap_token_store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC7E,OAAO,KAAK,EAAE,WAAW,EAAqB,MAAM,2BAA2B,CAAC;AAEhF;;;;;;;;;GASG;AACH,MAAM,WAAW,mBAAmB;IACnC,mFAAmF;IACnF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,UAAU,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;IACtC;;;;;;;;OAQG;IACH,UAAU,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC;CACvC;AAYD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,iCAAiC,GAC7C,MAAM,gBAAgB,GAAG,gBAAgB,EACzC,MAAM,MAAM,KACV,mBAID,CAAC"}
|
|
@@ -25,7 +25,7 @@ const BOOTSTRAP_TOKEN_READ_OPTIONS = Object.freeze({
|
|
|
25
25
|
* burn (`burn_secure_file` — unlink, then fsync the directory). The read
|
|
26
26
|
* alone of the runtime's secure reads asks for a single link
|
|
27
27
|
* (`BOOTSTRAP_TOKEN_READ_OPTIONS`): both of bootstrap's reads, the boot check
|
|
28
|
-
* (`
|
|
28
|
+
* (`is_bootstrap_available`) and the request's, go through it. Twin of the
|
|
29
29
|
* Rust `FileBootstrapTokenStore`.
|
|
30
30
|
*
|
|
31
31
|
* @param deps - the runtime's secure read and burn (`create_node_runtime()` satisfies both)
|
|
@@ -38,7 +38,11 @@ export interface DaemonTokenState {
|
|
|
38
38
|
previous_token: string | null;
|
|
39
39
|
/** When the last rotation occurred. */
|
|
40
40
|
rotated_at: Date;
|
|
41
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* The account ID of the keeper: resolved by `create_app_server` at
|
|
43
|
+
* assembly when null (`resolve_keeper_account_id`), set by the bootstrap
|
|
44
|
+
* route once its account commits, never re-read per request.
|
|
45
|
+
*/
|
|
42
46
|
keeper_account_id: string | null;
|
|
43
47
|
}
|
|
44
48
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"daemon_token.d.ts","sourceRoot":"","sources":["../../src/lib/auth/daemon_token.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAgC,KAAK,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAIxF,4EAA4E;AAC5E,eAAO,MAAM,kBAAkB,QAAwB,CAAC;AAExD;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,GAAI,KAAK,MAAM,KAAG,OAAuC,CAAC;AAE7F,oFAAoF;AACpF,eAAO,MAAM,WAAW,gHAGvB,CAAC;AACF,MAAM,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAEpD,wCAAwC;AACxC,eAAO,MAAM,mBAAmB,mBAAmB,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAChC,2BAA2B;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,wFAAwF;IACxF,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,uCAAuC;IACvC,UAAU,EAAE,IAAI,CAAC;IACjB
|
|
1
|
+
{"version":3,"file":"daemon_token.d.ts","sourceRoot":"","sources":["../../src/lib/auth/daemon_token.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAgC,KAAK,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAIxF,4EAA4E;AAC5E,eAAO,MAAM,kBAAkB,QAAwB,CAAC;AAExD;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,GAAI,KAAK,MAAM,KAAG,OAAuC,CAAC;AAE7F,oFAAoF;AACpF,eAAO,MAAM,WAAW,gHAGvB,CAAC;AACF,MAAM,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAEpD,wCAAwC;AACxC,eAAO,MAAM,mBAAmB,mBAAmB,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAChC,2BAA2B;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,wFAAwF;IACxF,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,uCAAuC;IACvC,UAAU,EAAE,IAAI,CAAC;IACjB;;;;OAIG;IACH,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC;AAED;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,QAAO,MAExC,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,qBAAqB,GAAI,UAAU,MAAM,EAAE,OAAO,gBAAgB,KAAG,OAgBjF,CAAC"}
|
|
@@ -21,9 +21,12 @@ import { type DaemonTokenState } from './daemon_token.js';
|
|
|
21
21
|
* Resolve the keeper account ID by querying for the account with an active
|
|
22
22
|
* keeper role_grant.
|
|
23
23
|
*
|
|
24
|
-
* There is exactly one keeper account (the bootstrap account).
|
|
25
|
-
* at
|
|
26
|
-
* `
|
|
24
|
+
* There is exactly one keeper account (the bootstrap account). Run once by
|
|
25
|
+
* `create_app_server` at assembly for a daemon-token state with no keeper
|
|
26
|
+
* (and by `start_daemon_token_rotation`) — the result is cached in
|
|
27
|
+
* `DaemonTokenState.keeper_account_id`, which a live bootstrap sets after its
|
|
28
|
+
* commit and nothing re-reads per request (a keeper seeded by another process
|
|
29
|
+
* needs a restart, as on the Rust spine). The acting actor is resolved
|
|
27
30
|
* per-request by the dispatcher's authorization phase (which runs
|
|
28
31
|
* `resolve_acting_actor` against this account id), so multi-actor keeper
|
|
29
32
|
* accounts surface `actor_required` if a daemon caller doesn't pass an
|
|
@@ -51,12 +54,13 @@ export declare const resolve_keeper_account_id: (deps: QueryDeps) => Promise<str
|
|
|
51
54
|
* - A shaped token + `Origin` / `Referer` present: discard the credential
|
|
52
55
|
* (browser context) and pass through — daemon tokens are loopback-only and
|
|
53
56
|
* never carry an `Origin` in production, so a header-bearing request is not
|
|
54
|
-
* a legitimate daemon caller. Silent on the wire (anti-enumeration)
|
|
55
|
-
*
|
|
57
|
+
* a legitimate daemon caller. Silent on the wire (anti-enumeration), logged
|
|
58
|
+
* at debug as on the Rust spine.
|
|
56
59
|
* - Header present + invalid value (not the current/previous token): soft-fail
|
|
57
60
|
* discard (pass through, not 401) — same downstream behavior.
|
|
58
|
-
* - Header present + valid + `keeper_account_id` null (
|
|
59
|
-
*
|
|
61
|
+
* - Header present + valid + `keeper_account_id` null (pre-bootstrap — the
|
|
62
|
+
* keeper is resolved at assembly and set by the bootstrap route after its
|
|
63
|
+
* commit, never re-read per request): soft-fail discard (pass through, not 503) —
|
|
60
64
|
* mirrors the Rust spine's `resolve.rs` (`None`), so the request falls
|
|
61
65
|
* through to anonymous and a daemon-gated action returns
|
|
62
66
|
* `credential_type_required` downstream.
|
|
@@ -71,7 +75,7 @@ export declare const resolve_keeper_account_id: (deps: QueryDeps) => Promise<str
|
|
|
71
75
|
* an explicit `acting` value.
|
|
72
76
|
*
|
|
73
77
|
* @param state - the daemon token runtime state
|
|
74
|
-
* @param deps - query dependencies (pool-level db for keeper
|
|
78
|
+
* @param deps - query dependencies (pool-level db for the keeper's account row)
|
|
75
79
|
* @param log - the logger instance
|
|
76
80
|
* @mutates Hono context - clears `RESOLVED_AUTH_KEY` on entry, then sets it on a valid token
|
|
77
81
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"daemon_token_middleware.d.ts","sourceRoot":"","sources":["../../src/lib/auth/daemon_token_middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;
|
|
1
|
+
{"version":3,"file":"daemon_token_middleware.d.ts","sourceRoot":"","sources":["../../src/lib/auth/daemon_token_middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAC9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAQtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,EAGN,KAAK,gBAAgB,EACrB,MAAM,mBAAmB,CAAC;AAE3B;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,yBAAyB,GAAU,MAAM,SAAS,KAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAEtF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,eAAO,MAAM,8BAA8B,GAC1C,OAAO,gBAAgB,EACvB,MAAM,SAAS,EACf,KAAK,MAAM,KACT,iBA8EF,CAAC"}
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
*
|
|
14
14
|
* @module
|
|
15
15
|
*/
|
|
16
|
-
import { DEV } from 'esm-env';
|
|
17
16
|
import { RESOLVED_AUTH_KEY } from '../hono_context.js';
|
|
18
17
|
import { get_resolved_auth } from './resolved_auth.js';
|
|
19
18
|
import { get_header_lines } from '../http/header_lines.js';
|
|
@@ -27,9 +26,12 @@ import { DAEMON_TOKEN_HEADER, validate_daemon_token } from './daemon_token.js';
|
|
|
27
26
|
* Resolve the keeper account ID by querying for the account with an active
|
|
28
27
|
* keeper role_grant.
|
|
29
28
|
*
|
|
30
|
-
* There is exactly one keeper account (the bootstrap account).
|
|
31
|
-
* at
|
|
32
|
-
* `
|
|
29
|
+
* There is exactly one keeper account (the bootstrap account). Run once by
|
|
30
|
+
* `create_app_server` at assembly for a daemon-token state with no keeper
|
|
31
|
+
* (and by `start_daemon_token_rotation`) — the result is cached in
|
|
32
|
+
* `DaemonTokenState.keeper_account_id`, which a live bootstrap sets after its
|
|
33
|
+
* commit and nothing re-reads per request (a keeper seeded by another process
|
|
34
|
+
* needs a restart, as on the Rust spine). The acting actor is resolved
|
|
33
35
|
* per-request by the dispatcher's authorization phase (which runs
|
|
34
36
|
* `resolve_acting_actor` against this account id), so multi-actor keeper
|
|
35
37
|
* accounts surface `actor_required` if a daemon caller doesn't pass an
|
|
@@ -59,12 +61,13 @@ export const resolve_keeper_account_id = async (deps) => {
|
|
|
59
61
|
* - A shaped token + `Origin` / `Referer` present: discard the credential
|
|
60
62
|
* (browser context) and pass through — daemon tokens are loopback-only and
|
|
61
63
|
* never carry an `Origin` in production, so a header-bearing request is not
|
|
62
|
-
* a legitimate daemon caller. Silent on the wire (anti-enumeration)
|
|
63
|
-
*
|
|
64
|
+
* a legitimate daemon caller. Silent on the wire (anti-enumeration), logged
|
|
65
|
+
* at debug as on the Rust spine.
|
|
64
66
|
* - Header present + invalid value (not the current/previous token): soft-fail
|
|
65
67
|
* discard (pass through, not 401) — same downstream behavior.
|
|
66
|
-
* - Header present + valid + `keeper_account_id` null (
|
|
67
|
-
*
|
|
68
|
+
* - Header present + valid + `keeper_account_id` null (pre-bootstrap — the
|
|
69
|
+
* keeper is resolved at assembly and set by the bootstrap route after its
|
|
70
|
+
* commit, never re-read per request): soft-fail discard (pass through, not 503) —
|
|
68
71
|
* mirrors the Rust spine's `resolve.rs` (`None`), so the request falls
|
|
69
72
|
* through to anonymous and a daemon-gated action returns
|
|
70
73
|
* `credential_type_required` downstream.
|
|
@@ -79,7 +82,7 @@ export const resolve_keeper_account_id = async (deps) => {
|
|
|
79
82
|
* an explicit `acting` value.
|
|
80
83
|
*
|
|
81
84
|
* @param state - the daemon token runtime state
|
|
82
|
-
* @param deps - query dependencies (pool-level db for keeper
|
|
85
|
+
* @param deps - query dependencies (pool-level db for the keeper's account row)
|
|
83
86
|
* @param log - the logger instance
|
|
84
87
|
* @mutates Hono context - clears `RESOLVED_AUTH_KEY` on entry, then sets it on a valid token
|
|
85
88
|
*/
|
|
@@ -114,8 +117,6 @@ export const create_daemon_token_middleware = (state, deps, log) => {
|
|
|
114
117
|
// `credential_type_required` downstream rather than a hard fail.
|
|
115
118
|
if (is_browser_context(get_header_lines(c, 'origin'), get_header_lines(c, 'referer'))) {
|
|
116
119
|
log.debug('daemon token auth rejected: browser context (Origin/Referer present)');
|
|
117
|
-
if (DEV)
|
|
118
|
-
c.header('X-Fuz-Auth-Debug', 'daemon_token_discarded_browser_context');
|
|
119
120
|
await next();
|
|
120
121
|
return;
|
|
121
122
|
}
|
|
@@ -127,16 +128,9 @@ export const create_daemon_token_middleware = (state, deps, log) => {
|
|
|
127
128
|
await next();
|
|
128
129
|
return;
|
|
129
130
|
}
|
|
130
|
-
//
|
|
131
|
-
//
|
|
132
|
-
//
|
|
133
|
-
// then POST /bootstrap). Lazily refresh from the DB on the first null hit
|
|
134
|
-
// so the post-bootstrap state lands without a separate hook.
|
|
135
|
-
if (!state.keeper_account_id) {
|
|
136
|
-
state.keeper_account_id = await resolve_keeper_account_id(deps);
|
|
137
|
-
}
|
|
138
|
-
// Valid token but no keeper configured (still pre-bootstrap after the lazy
|
|
139
|
-
// refresh) — soft-fail discard (pass through), not a 503. Mirrors the Rust
|
|
131
|
+
// Valid token but no keeper configured — soft-fail discard (pass through),
|
|
132
|
+
// not a 503. The keeper is resolved at assembly and set by the
|
|
133
|
+
// bootstrap route after its commit; never re-read here. Mirrors the Rust
|
|
140
134
|
// spine's `resolve.rs`, which returns `None` when the daemon leg can't
|
|
141
135
|
// resolve a keeper: the request falls through to the next auth leg →
|
|
142
136
|
// anonymous, so a daemon-gated action returns `credential_type_required`
|
package/dist/auth/deps.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ import type { Db } from '../db/db.js';
|
|
|
16
16
|
import type { AuditEmitter } from './audit_emitter.js';
|
|
17
17
|
import type { ConnectionCloser, RealtimeCloser } from '../actions/connection_closer.js';
|
|
18
18
|
import type { RealtimeNotificationSender } from '../actions/notification_sender.js';
|
|
19
|
+
import type { RequestTracker } from '../http/pending_effects.js';
|
|
19
20
|
/**
|
|
20
21
|
* Capabilities bundle for fuz_app backends.
|
|
21
22
|
*
|
|
@@ -61,6 +62,16 @@ export interface AppDeps {
|
|
|
61
62
|
* WebSocket endpoint mounted it reaches no one.
|
|
62
63
|
*/
|
|
63
64
|
notification_sender: RealtimeNotificationSender;
|
|
65
|
+
/**
|
|
66
|
+
* Holds every request accepted — an HTTP request, a WS message — until
|
|
67
|
+
* its handler has returned and its effect flush settled, for the waits
|
|
68
|
+
* that must see them finish: `AppServer.close`'s shutdown drain and
|
|
69
|
+
* `_testing_drain_effects`. `create_app_backend` creates it;
|
|
70
|
+
* `create_app_server` holds its HTTP requests and every WS endpoint it
|
|
71
|
+
* mounts on it, and a WebSocket endpoint mounted by hand takes it through
|
|
72
|
+
* `register_action_ws`'s `request_tracker`.
|
|
73
|
+
*/
|
|
74
|
+
request_tracker: RequestTracker;
|
|
64
75
|
/**
|
|
65
76
|
* Optional content-addressed byte store. Present only on backends that
|
|
66
77
|
* serve binary content (facts) — minimal consumers leave it unset. The
|
package/dist/auth/deps.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deps.d.ts","sourceRoot":"","sources":["../../src/lib/auth/deps.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACxF,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"deps.d.ts","sourceRoot":"","sources":["../../src/lib/auth/deps.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACxF,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AACpF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAEjE;;;;;;;GAOG;AACH,MAAM,WAAW,OAAO;IACvB,0CAA0C;IAC1C,OAAO,EAAE,OAAO,CAAC;IACjB,6EAA6E;IAC7E,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,yBAAyB;IACzB,EAAE,EAAE,EAAE,CAAC;IACP,kCAAkC;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ;;;;;;;OAOG;IACH,KAAK,EAAE,YAAY,CAAC;IACpB;;;;;;;;OAQG;IACH,iBAAiB,EAAE,cAAc,CAAC;IAClC;;;;;;;OAOG;IACH,mBAAmB,EAAE,0BAA0B,CAAC;IAChD;;;;;;;;OAQG;IACH,eAAe,EAAE,cAAc,CAAC;IAChC;;;;;;;;;OASG;IACH,UAAU,CAAC,EAAE,aAAa,CAAC;CAC3B;AAED;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AAEnD;;;;;;;;GAQG;AACH,MAAM,WAAW,iBAAiB;IACjC,kCAAkC;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ,4CAA4C;IAC5C,KAAK,EAAE,YAAY,CAAC;CACpB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,yBAA0B,SAAQ,iBAAiB;IACnE;;;;;;OAMG;IACH,iBAAiB,EAAE,gBAAgB,CAAC;CACpC"}
|
|
@@ -20,12 +20,60 @@ import type { Invite, CreateInviteInput, InviteWithUsernamesJson } from './invit
|
|
|
20
20
|
*/
|
|
21
21
|
export declare const INVITE_COLUMNS: readonly ["id", "email", "username", "claimed_by", "claimed_at", "created_at", "created_by"];
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* Error thrown by `query_create_invite` when an unclaimed invite already
|
|
24
|
+
* reserves the email or the username: the partial unique index
|
|
25
|
+
* `idx_invite_email_unclaimed` or `idx_invite_username_unclaimed` refused the
|
|
26
|
+
* insert (SQLSTATE `23505`), which aborts the caller's transaction. Twin of
|
|
27
|
+
* the Rust `InviteCreateError::Duplicate`.
|
|
28
|
+
*/
|
|
29
|
+
export declare class InviteDuplicateError extends Error {
|
|
30
|
+
constructor();
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Error thrown by `query_create_invite` when the issuer is not an active
|
|
34
|
+
* account: its actor is missing or tombstoned, or its account soft-deleted — a
|
|
35
|
+
* delete that committed while the invite was in flight. Twin of the Rust
|
|
36
|
+
* `InviteCreateError::IssuerNotActive`.
|
|
37
|
+
*/
|
|
38
|
+
export declare class InviteIssuerNotActiveError extends Error {
|
|
39
|
+
constructor();
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Create an invite issued by the actor `input.created_by`.
|
|
24
43
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
44
|
+
* The issuer must be an active actor of a live account, checked here so every
|
|
45
|
+
* caller — the spine's `invite_create` handler and a consumer minting invites
|
|
46
|
+
* on its own path — gets the rule: an invite records no authority, so one
|
|
47
|
+
* minted for an issuer deleted mid-flight would outlive the delete that should
|
|
48
|
+
* have voided it. The issuer's account row is read under `FOR SHARE`
|
|
49
|
+
* (`query_account_lock_live_many`) before the insert: an account delete writes
|
|
50
|
+
* its tombstone first, so a delete that wrote its tombstone before the read is
|
|
51
|
+
* waited for if uncommitted and seen (the invite is refused), and one that
|
|
52
|
+
* reaches the row after it waits for this transaction to
|
|
53
|
+
* commit and then deletes the invite with the account's other unclaimed ones
|
|
54
|
+
* (`query_invite_delete_unclaimed_by_creators`). The actor's tombstone is read
|
|
55
|
+
* after the lock, so a delete waited on is seen there too.
|
|
56
|
+
*
|
|
57
|
+
* Run it inside the caller's transaction, which the lock spans — on the pool
|
|
58
|
+
* the lock ends with its statement and orders nothing. Lock order: account
|
|
59
|
+
* rows come before actor and `role_grant` rows, as the last-admin guard
|
|
60
|
+
* (`query_count_active_accounts_with_global_role_locked`) takes them (account,
|
|
61
|
+
* then actor, then grant). So take it before the transaction locks any actor
|
|
62
|
+
* or `role_grant` row — or lock the issuer's account row first yourself
|
|
63
|
+
* (`query_account_lock_live_many`), which this query then re-takes without
|
|
64
|
+
* waiting: a transaction holding a lock on the issuer's admin grant while it
|
|
65
|
+
* waits here on an account row a removal holds, while the removal's guard
|
|
66
|
+
* waits on that grant, deadlocks.
|
|
67
|
+
*
|
|
68
|
+
* Callers that pre-check for account collisions on `email` / `username` do so
|
|
69
|
+
* upstream. Twin of the Rust `query_create_invite`.
|
|
70
|
+
*
|
|
71
|
+
* @param deps - query dependencies (must be the caller's transaction)
|
|
72
|
+
* @param input - the invite fields and its issuing actor
|
|
27
73
|
* @returns the created invite
|
|
28
74
|
* @mutates `invite` table - inserts the new row
|
|
75
|
+
* @throws InviteIssuerNotActiveError if `created_by` names no actor, a tombstoned one, or one whose account is soft-deleted; nothing is inserted
|
|
76
|
+
* @throws InviteDuplicateError if an unclaimed invite with the same email or username already exists
|
|
29
77
|
*/
|
|
30
78
|
export declare const query_create_invite: (deps: QueryDeps, input: CreateInviteInput) => Promise<Invite>;
|
|
31
79
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invite_queries.d.ts","sourceRoot":"","sources":["../../src/lib/auth/invite_queries.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"invite_queries.d.ts","sourceRoot":"","sources":["../../src/lib/auth/invite_queries.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAIrD,OAAO,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAG7F;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,8FAQqB,CAAC;AAKjD;;;;;;GAMG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;;CAK9C;AAED;;;;;GAKG;AACH,qBAAa,0BAA2B,SAAQ,KAAK;;CAKpD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,eAAO,MAAM,mBAAmB,GAC/B,MAAM,SAAS,EACf,OAAO,iBAAiB,KACtB,OAAO,CAAC,MAAM,CAiChB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,4CAA4C,GACxD,MAAM,SAAS,EACf,OAAO,MAAM,GAAG,IAAI,EACpB,UAAU,MAAM,KACd,OAAO,CAAC,MAAM,GAAG,SAAS,CAgB5B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,2BAA2B,GACvC,MAAM,SAAS,EACf,WAAW,MAAM,EACjB,YAAY,MAAM,KAChB,OAAO,CAAC,OAAO,CAQjB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,oCAAoC,GAChD,MAAM,SAAS,KACb,OAAO,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAUxC,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,6BAA6B,GACzC,MAAM,SAAS,EACf,IAAI,MAAM,KACR,OAAO,CAAC,OAAO,CAMjB,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,yCAAyC,GACrD,MAAM,SAAS,EACf,sBAAsB,aAAa,CAAC,IAAI,CAAC,KACvC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CASrB,CAAC"}
|