@fuzdev/fuz_app 0.183.0 → 0.185.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.
Files changed (223) hide show
  1. package/dist/actions/CLAUDE.md +538 -1223
  2. package/dist/actions/action_codegen.d.ts +1 -1
  3. package/dist/actions/action_codegen.d.ts.map +1 -1
  4. package/dist/actions/action_codegen.js +3 -2
  5. package/dist/actions/connection_closer.d.ts +11 -9
  6. package/dist/actions/connection_closer.d.ts.map +1 -1
  7. package/dist/actions/connection_closer.js +11 -9
  8. package/dist/actions/frontend_rpc_client.d.ts +1 -1
  9. package/dist/actions/register_action_ws.d.ts +21 -1
  10. package/dist/actions/register_action_ws.d.ts.map +1 -1
  11. package/dist/actions/register_action_ws.js +2 -1
  12. package/dist/actions/ws_socket_session.d.ts +25 -4
  13. package/dist/actions/ws_socket_session.d.ts.map +1 -1
  14. package/dist/actions/ws_socket_session.js +81 -25
  15. package/dist/auth/CLAUDE.md +433 -1048
  16. package/dist/auth/account_queries.d.ts +1 -1
  17. package/dist/auth/account_queries.js +1 -1
  18. package/dist/auth/account_routes.d.ts +4 -5
  19. package/dist/auth/account_routes.d.ts.map +1 -1
  20. package/dist/auth/account_routes.js +8 -10
  21. package/dist/auth/admin_actions.d.ts.map +1 -1
  22. package/dist/auth/admin_actions.js +10 -11
  23. package/dist/auth/api_token.d.ts +20 -3
  24. package/dist/auth/api_token.d.ts.map +1 -1
  25. package/dist/auth/api_token.js +28 -9
  26. package/dist/auth/api_token_queries.d.ts +2 -2
  27. package/dist/auth/api_token_queries.js +2 -2
  28. package/dist/auth/audit_log_routes.d.ts +1 -1
  29. package/dist/auth/audit_log_routes.d.ts.map +1 -1
  30. package/dist/auth/audit_log_routes.js +3 -2
  31. package/dist/auth/audit_log_schema.d.ts +15 -9
  32. package/dist/auth/audit_log_schema.d.ts.map +1 -1
  33. package/dist/auth/audit_log_schema.js +1 -2
  34. package/dist/auth/auth_guard_resolver.d.ts +1 -1
  35. package/dist/auth/auth_guard_resolver.js +1 -1
  36. package/dist/auth/bearer_auth.d.ts +2 -5
  37. package/dist/auth/bearer_auth.d.ts.map +1 -1
  38. package/dist/auth/bearer_auth.js +4 -13
  39. package/dist/auth/bootstrap_account.d.ts +13 -15
  40. package/dist/auth/bootstrap_account.d.ts.map +1 -1
  41. package/dist/auth/bootstrap_account.js +9 -11
  42. package/dist/auth/bootstrap_routes.d.ts +20 -21
  43. package/dist/auth/bootstrap_routes.d.ts.map +1 -1
  44. package/dist/auth/bootstrap_routes.js +21 -19
  45. package/dist/auth/bootstrap_token_store.d.ts +3 -4
  46. package/dist/auth/bootstrap_token_store.d.ts.map +1 -1
  47. package/dist/auth/bootstrap_token_store.js +1 -1
  48. package/dist/auth/cleanup.d.ts +34 -3
  49. package/dist/auth/cleanup.d.ts.map +1 -1
  50. package/dist/auth/cleanup.js +11 -3
  51. package/dist/auth/daemon_token.d.ts +5 -1
  52. package/dist/auth/daemon_token.d.ts.map +1 -1
  53. package/dist/auth/daemon_token_middleware.d.ts +12 -8
  54. package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
  55. package/dist/auth/daemon_token_middleware.js +15 -21
  56. package/dist/auth/deps.d.ts +11 -0
  57. package/dist/auth/deps.d.ts.map +1 -1
  58. package/dist/auth/invite_queries.d.ts +51 -3
  59. package/dist/auth/invite_queries.d.ts.map +1 -1
  60. package/dist/auth/invite_queries.js +81 -6
  61. package/dist/auth/invite_schema.d.ts +2 -1
  62. package/dist/auth/invite_schema.d.ts.map +1 -1
  63. package/dist/auth/middleware.d.ts +2 -3
  64. package/dist/auth/middleware.d.ts.map +1 -1
  65. package/dist/auth/middleware.js +3 -3
  66. package/dist/auth/request_context.d.ts +3 -3
  67. package/dist/auth/request_context.js +3 -3
  68. package/dist/auth/role_grant_offer_actions.d.ts +2 -2
  69. package/dist/auth/role_grant_offer_actions.js +2 -2
  70. package/dist/auth/session_cookie.d.ts +82 -174
  71. package/dist/auth/session_cookie.d.ts.map +1 -1
  72. package/dist/auth/session_cookie.js +80 -130
  73. package/dist/auth/session_middleware.d.ts +8 -17
  74. package/dist/auth/session_middleware.d.ts.map +1 -1
  75. package/dist/auth/session_middleware.js +14 -23
  76. package/dist/auth/session_queries.d.ts +9 -14
  77. package/dist/auth/session_queries.d.ts.map +1 -1
  78. package/dist/auth/session_queries.js +8 -9
  79. package/dist/auth/signup_routes.d.ts.map +1 -1
  80. package/dist/auth/signup_routes.js +4 -6
  81. package/dist/db/CLAUDE.md +5 -3
  82. package/dist/dev/setup.d.ts +3 -1
  83. package/dist/dev/setup.d.ts.map +1 -1
  84. package/dist/dev/setup.js +3 -1
  85. package/dist/http/CLAUDE.md +315 -768
  86. package/dist/http/db_routes.d.ts +1 -1
  87. package/dist/http/db_routes.js +1 -1
  88. package/dist/http/origin.d.ts +7 -8
  89. package/dist/http/origin.d.ts.map +1 -1
  90. package/dist/http/origin.js +7 -8
  91. package/dist/http/pending_effects.d.ts +82 -4
  92. package/dist/http/pending_effects.d.ts.map +1 -1
  93. package/dist/http/pending_effects.js +82 -4
  94. package/dist/http/route_result.d.ts +1 -1
  95. package/dist/http/route_spec.d.ts +17 -14
  96. package/dist/http/route_spec.d.ts.map +1 -1
  97. package/dist/realtime/audit_log_sse.d.ts +1 -1
  98. package/dist/realtime/sse.d.ts +6 -25
  99. package/dist/realtime/sse.d.ts.map +1 -1
  100. package/dist/realtime/sse.js +4 -25
  101. package/dist/realtime/sse_constants.d.ts +1 -1
  102. package/dist/realtime/sse_constants.js +1 -1
  103. package/dist/server/app_backend.d.ts +4 -5
  104. package/dist/server/app_backend.d.ts.map +1 -1
  105. package/dist/server/app_backend.js +3 -1
  106. package/dist/server/app_server.d.ts +87 -76
  107. package/dist/server/app_server.d.ts.map +1 -1
  108. package/dist/server/app_server.js +111 -91
  109. package/dist/server/app_server_context.d.ts +1 -2
  110. package/dist/server/app_server_context.d.ts.map +1 -1
  111. package/dist/server/env.js +2 -2
  112. package/dist/server/shutdown_drain.d.ts +69 -0
  113. package/dist/server/shutdown_drain.d.ts.map +1 -0
  114. package/dist/server/shutdown_drain.js +77 -0
  115. package/dist/testing/CLAUDE.md +89 -57
  116. package/dist/testing/admin_integration.d.ts +4 -5
  117. package/dist/testing/admin_integration.d.ts.map +1 -1
  118. package/dist/testing/admin_integration.js +39 -23
  119. package/dist/testing/app_server.d.ts +3 -8
  120. package/dist/testing/app_server.d.ts.map +1 -1
  121. package/dist/testing/app_server.js +10 -9
  122. package/dist/testing/attack_surface.d.ts +1 -1
  123. package/dist/testing/attack_surface.d.ts.map +1 -1
  124. package/dist/testing/audit_completeness.d.ts +2 -3
  125. package/dist/testing/audit_completeness.d.ts.map +1 -1
  126. package/dist/testing/audit_completeness.js +1 -1
  127. package/dist/testing/cross_backend/bootstrap_backend.d.ts +3 -1
  128. package/dist/testing/cross_backend/bootstrap_backend.d.ts.map +1 -1
  129. package/dist/testing/cross_backend/bootstrap_backend.js +5 -1
  130. package/dist/testing/cross_backend/capability_mounts.d.ts.map +1 -1
  131. package/dist/testing/cross_backend/capability_mounts.js +16 -11
  132. package/dist/testing/cross_backend/conformance_table.d.ts +5 -6
  133. package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
  134. package/dist/testing/cross_backend/conformance_table.js +4 -4
  135. package/dist/testing/cross_backend/cookie_attributes.js +1 -1
  136. package/dist/testing/cross_backend/create_dual_spawn_global_setup.d.ts +10 -1
  137. package/dist/testing/cross_backend/create_dual_spawn_global_setup.d.ts.map +1 -1
  138. package/dist/testing/cross_backend/create_dual_spawn_global_setup.js +33 -7
  139. package/dist/testing/cross_backend/default_backend_configs.d.ts +3 -3
  140. package/dist/testing/cross_backend/default_spine_surface.d.ts +0 -6
  141. package/dist/testing/cross_backend/default_spine_surface.d.ts.map +1 -1
  142. package/dist/testing/cross_backend/default_spine_surface.js +4 -9
  143. package/dist/testing/cross_backend/differential.d.ts +2 -3
  144. package/dist/testing/cross_backend/differential.d.ts.map +1 -1
  145. package/dist/testing/cross_backend/differential.js +1 -1
  146. package/dist/testing/cross_backend/full_spine_mount.d.ts +1 -42
  147. package/dist/testing/cross_backend/full_spine_mount.d.ts.map +1 -1
  148. package/dist/testing/cross_backend/full_spine_mount.js +45 -4
  149. package/dist/testing/cross_backend/in_process_setup.d.ts +7 -8
  150. package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
  151. package/dist/testing/cross_backend/in_process_setup.js +10 -13
  152. package/dist/testing/cross_backend/rpc_success_fixtures.d.ts.map +1 -1
  153. package/dist/testing/cross_backend/rpc_success_fixtures.js +2 -1
  154. package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +3 -4
  155. package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
  156. package/dist/testing/cross_backend/rust_spine_consumer_surface.js +2 -2
  157. package/dist/testing/cross_backend/setup.d.ts +1 -1
  158. package/dist/testing/cross_backend/spawn_backend.d.ts +14 -0
  159. package/dist/testing/cross_backend/spawn_backend.d.ts.map +1 -1
  160. package/dist/testing/cross_backend/spawn_backend.js +56 -8
  161. package/dist/testing/cross_backend/spine_suites.d.ts +18 -16
  162. package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
  163. package/dist/testing/cross_backend/spine_suites.js +38 -18
  164. package/dist/testing/cross_backend/standard.d.ts +19 -84
  165. package/dist/testing/cross_backend/standard.d.ts.map +1 -1
  166. package/dist/testing/cross_backend/standard.js +8 -23
  167. package/dist/testing/cross_backend/standard_auth.d.ts +74 -0
  168. package/dist/testing/cross_backend/standard_auth.d.ts.map +1 -0
  169. package/dist/testing/cross_backend/standard_auth.js +28 -0
  170. package/dist/testing/cross_backend/standard_bundle.d.ts +48 -0
  171. package/dist/testing/cross_backend/standard_bundle.d.ts.map +1 -0
  172. package/dist/testing/cross_backend/standard_bundle.js +43 -0
  173. package/dist/testing/cross_backend/testing_credential_read.d.ts +10 -11
  174. package/dist/testing/cross_backend/testing_credential_read.d.ts.map +1 -1
  175. package/dist/testing/cross_backend/testing_credential_read.js +12 -12
  176. package/dist/testing/cross_backend/testing_reset_actions.d.ts +46 -30
  177. package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
  178. package/dist/testing/cross_backend/testing_reset_actions.js +52 -31
  179. package/dist/testing/cross_backend/testing_server_bun.d.ts.map +1 -1
  180. package/dist/testing/cross_backend/testing_server_bun.js +5 -4
  181. package/dist/testing/cross_backend/testing_server_core.d.ts +16 -3
  182. package/dist/testing/cross_backend/testing_server_core.d.ts.map +1 -1
  183. package/dist/testing/cross_backend/testing_server_core.js +22 -7
  184. package/dist/testing/cross_backend/ts_spine_backend_config.d.ts +6 -2
  185. package/dist/testing/cross_backend/ts_spine_backend_config.d.ts.map +1 -1
  186. package/dist/testing/cross_backend/ts_spine_backend_config.js +7 -3
  187. package/dist/testing/daemon_token_rotation.d.ts.map +1 -1
  188. package/dist/testing/daemon_token_rotation.js +2 -3
  189. package/dist/testing/error_coverage.d.ts +5 -0
  190. package/dist/testing/error_coverage.d.ts.map +1 -1
  191. package/dist/testing/error_coverage.js +2 -1
  192. package/dist/testing/integration.d.ts +6 -23
  193. package/dist/testing/integration.d.ts.map +1 -1
  194. package/dist/testing/integration.js +53 -83
  195. package/dist/testing/integration_helpers.d.ts +16 -0
  196. package/dist/testing/integration_helpers.d.ts.map +1 -1
  197. package/dist/testing/integration_helpers.js +29 -1
  198. package/dist/testing/middleware_gate_probes.d.ts +55 -1
  199. package/dist/testing/middleware_gate_probes.d.ts.map +1 -1
  200. package/dist/testing/middleware_gate_probes.js +69 -3
  201. package/dist/testing/rate_limiting.d.ts +2 -3
  202. package/dist/testing/rate_limiting.d.ts.map +1 -1
  203. package/dist/testing/rate_limiting.js +3 -3
  204. package/dist/testing/rpc_helpers.d.ts +1 -2
  205. package/dist/testing/rpc_helpers.d.ts.map +1 -1
  206. package/dist/testing/rpc_helpers.js +3 -3
  207. package/dist/testing/rpc_round_trip.d.ts +2 -3
  208. package/dist/testing/rpc_round_trip.d.ts.map +1 -1
  209. package/dist/testing/rpc_round_trip.js +1 -1
  210. package/dist/testing/sse_round_trip.d.ts +2 -3
  211. package/dist/testing/sse_round_trip.d.ts.map +1 -1
  212. package/dist/testing/sse_round_trip.js +2 -2
  213. package/dist/testing/stubs.d.ts +5 -6
  214. package/dist/testing/stubs.d.ts.map +1 -1
  215. package/dist/testing/stubs.js +10 -8
  216. package/dist/testing/test_app.d.ts +8 -5
  217. package/dist/testing/test_app.d.ts.map +1 -1
  218. package/dist/testing/test_app.js +7 -7
  219. package/dist/testing/ws_round_trip.d.ts.map +1 -1
  220. package/dist/testing/ws_round_trip.js +3 -0
  221. package/dist/ui/ui_format.d.ts.map +1 -1
  222. package/dist/ui/ui_format.js +1 -2
  223. 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 { session_cookie_header } from './session_cookie.js';
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, actor, role_grants, and the session's `Set-Cookie` line — or a bootstrap failure
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
- const keeper_role_grant = await query_create_role_grant(tx_ctx, {
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
- const admin_role_grant = await query_create_role_grant(tx_ctx, {
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 { cookie_value } = await create_capped_session({
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
- // formatted here, as login and signup format theirs: a value the
171
- // formatter refuses rolls the bootstrap back with the token unburned
172
- const set_cookie = session_cookie_header(cookie_value, options.session_options);
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 { SessionOptions } from './session_cookie.js';
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` is runtime state (a mutable ref), not a dep or options value —
36
- * it is passed through so the route handler can flip it.
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
- session_options: SessionOptions<string>;
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
- /** Called after a successful bootstrap commits. */
49
- on_bootstrap?: OnBootstrap;
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 checking bootstrap status at startup.
63
+ * Dependencies for `is_bootstrap_available`.
66
64
  */
67
- export interface CheckBootstrapStatusDeps {
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
- * Check bootstrap availability at startup.
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 initial `BootstrapStatus`
96
+ * @returns whether the bootstrap window is open
98
97
  */
99
- export declare const check_bootstrap_status: (deps: CheckBootstrapStatusDeps, options: {
98
+ export declare const is_bootstrap_available: (deps: IsBootstrapAvailableDeps, options: {
100
99
  token_store: BootstrapTokenStore | null;
101
- }) => Promise<BootstrapStatus>;
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;AAEtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAGN,KAAK,uBAAuB,EAC5B,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,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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
- * Check bootstrap availability at startup.
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 initial `BootstrapStatus`
43
+ * @returns whether the bootstrap window is open
43
44
  */
44
- export const check_bootstrap_status = async (deps, options) => {
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 { available: false };
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 { available: false };
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 { available: false };
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 { available: false };
76
+ return false;
76
77
  }
77
78
  log.info(`Bootstrap token available: ${token_store.path}`);
78
- return { available: true };
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 { session_options, bootstrap_status, token_store, on_bootstrap, bootstrap_ip_rate_limiter } = options;
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, { session_options });
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 `check_bootstrap_status` already reads
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, role_grants, set_cookie } = result;
172
- if (on_bootstrap) {
173
- try {
174
- await on_bootstrap({ account, actor, role_grants });
175
- }
176
- catch (err) {
177
- deps.log.error(`on_bootstrap callback failed: ${to_error_message(err)}`);
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
- * boot check (`is_bootstrap_available`) takes the path itself, while
22
- * `check_bootstrap_status` reads through this store and names the file in its
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
- * (`check_bootstrap_status`) and the request's, go through it. Twin of the
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;;;;;;;;;;GAUG;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"}
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
- * (`check_bootstrap_status`) and the request's, go through it. Twin of the
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)
@@ -83,7 +83,11 @@
83
83
  * that, so the standard assembly is one option:
84
84
  *
85
85
  * ```ts
86
- * const server = await create_app_server({backend, auth_cleanup: true, ...});
86
+ * const server = await create_app_server({
87
+ * backend,
88
+ * auth_cleanup: {every_ms: DEFAULT_AUTH_CLEANUP_INTERVAL_MS},
89
+ * ...
90
+ * });
87
91
  * // on shutdown: stops the schedule, then closes the database
88
92
  * await server.close();
89
93
  * ```
@@ -103,7 +107,10 @@
103
107
  * token is cancelled; a promise cannot be dropped, so `stop` ends the schedule
104
108
  * at once and its promise resolves when the pass in progress — if there is
105
109
  * one — has finished. Awaiting it before closing the database lets that pass
106
- * end on a live pool rather than fail on a closed one.
110
+ * end on a live pool rather than fail on a closed one. `AppServer.close`
111
+ * waits for it within its drain bound, as the Rust shutdown joins its upkeep,
112
+ * and counts a pass still running at the bound as given up on
113
+ * (`ShutdownDrainGivenUp.upkeep`).
107
114
  *
108
115
  * @module
109
116
  */
@@ -221,6 +228,29 @@ export declare const cleanup_expired_role_grant_offers: (deps: AuthCleanupDeps)
221
228
  * @throws Error re-thrown from the first sweep that fails (no per-sweep isolation here)
222
229
  */
223
230
  export declare const run_auth_cleanup: (deps: AuthCleanupDeps) => Promise<AuthCleanupResult>;
231
+ /**
232
+ * Whether a server runs the auth cleanup beside itself, and how often —
233
+ * `create_app_server`'s `auth_cleanup` option.
234
+ *
235
+ * A required choice, with no default: every server names it, so none gets or
236
+ * loses the sweeps without writing it out.
237
+ *
238
+ * - `{every_ms}` — `start_auth_cleanup` on that interval: a pass as the
239
+ * server finishes assembly, then one per `every_ms`
240
+ * (`DEFAULT_AUTH_CLEANUP_INTERVAL_MS` unless the server has a reason to
241
+ * differ) — what a production server runs. Must be a positive finite
242
+ * number no greater than `PERIODIC_INTERVAL_MS_MAX`.
243
+ * - `'off'` — no cleanup: an in-process test harness (a background pass
244
+ * deletes rows and writes audit rows mid-test), a test server held to a
245
+ * spine that schedules none, or a process whose sweeps run elsewhere
246
+ * (`run_auth_cleanup` on a schedule of its own).
247
+ *
248
+ * Twin of the Rust `fuz_auth::AuthCleanupSchedule` (`Every(Duration)` /
249
+ * `Off`).
250
+ */
251
+ export type AuthCleanupSchedule = {
252
+ every_ms: number;
253
+ } | 'off';
224
254
  /** Options for `start_auth_cleanup`. */
225
255
  export interface AuthCleanupScheduleOptions {
226
256
  /**
@@ -236,7 +266,8 @@ export interface AuthCleanupScheduleOptions {
236
266
  *
237
267
  * The auth surface's upkeep in one call — start it once migrations have run
238
268
  * and stop it before the database closes (see the module doc's § Scheduling).
239
- * `create_app_server`'s `auth_cleanup` option does both.
269
+ * `create_app_server`'s `auth_cleanup` option (an `AuthCleanupSchedule`)
270
+ * does both.
240
271
  *
241
272
  * Built on `start_periodic`, which fixes the loop's rules: the startup pass
242
273
  * starts before this returns, passes never overlap, a slow pass delays the
@@ -1 +1 @@
1
- {"version":3,"file":"cleanup.d.ts","sourceRoot":"","sources":["../../src/lib/auth/cleanup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4GG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,KAAK,EAAE,gBA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MAAM,WAAW,0BAA0B;IAC1C;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,kBAAkB,GAC9B,MAAM,eAAe,EACrB,UAAS,0BAA+B,KACtC,YAWD,CAAC"}
@@ -83,7 +83,11 @@
83
83
  * that, so the standard assembly is one option:
84
84
  *
85
85
  * ```ts
86
- * const server = await create_app_server({backend, auth_cleanup: true, ...});
86
+ * const server = await create_app_server({
87
+ * backend,
88
+ * auth_cleanup: {every_ms: DEFAULT_AUTH_CLEANUP_INTERVAL_MS},
89
+ * ...
90
+ * });
87
91
  * // on shutdown: stops the schedule, then closes the database
88
92
  * await server.close();
89
93
  * ```
@@ -103,7 +107,10 @@
103
107
  * token is cancelled; a promise cannot be dropped, so `stop` ends the schedule
104
108
  * at once and its promise resolves when the pass in progress — if there is
105
109
  * one — has finished. Awaiting it before closing the database lets that pass
106
- * end on a live pool rather than fail on a closed one.
110
+ * end on a live pool rather than fail on a closed one. `AppServer.close`
111
+ * waits for it within its drain bound, as the Rust shutdown joins its upkeep,
112
+ * and counts a pass still running at the bound as given up on
113
+ * (`ShutdownDrainGivenUp.upkeep`).
107
114
  *
108
115
  * @module
109
116
  */
@@ -267,7 +274,8 @@ export const run_auth_cleanup = async (deps) => {
267
274
  *
268
275
  * The auth surface's upkeep in one call — start it once migrations have run
269
276
  * and stop it before the database closes (see the module doc's § Scheduling).
270
- * `create_app_server`'s `auth_cleanup` option does both.
277
+ * `create_app_server`'s `auth_cleanup` option (an `AuthCleanupSchedule`)
278
+ * does both.
271
279
  *
272
280
  * Built on `start_periodic`, which fixes the loop's rules: the startup pass
273
281
  * starts before this returns, passes never overlap, a slow pass delays the
@@ -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
- /** The account ID of the keeper (resolved at startup, set by `on_bootstrap`). */
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,iFAAiF;IACjF,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"}
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). Runs once
25
- * at server startup — the result is cached in
26
- * `DaemonTokenState.keeper_account_id`. The acting actor is resolved
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); in
55
- * `DEV` only, sets `X-Fuz-Auth-Debug: daemon_token_discarded_browser_context`.
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 (still pre-bootstrap
59
- * after the lazy refresh): soft-fail discard (pass through, not 503) —
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-account resolution)
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;AAGH,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;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,yBAAyB,GAAU,MAAM,SAAS,KAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAEtF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,eAAO,MAAM,8BAA8B,GAC1C,OAAO,gBAAgB,EACvB,MAAM,SAAS,EACf,KAAK,MAAM,KACT,iBAsFF,CAAC"}
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). Runs once
31
- * at server startup — the result is cached in
32
- * `DaemonTokenState.keeper_account_id`. The acting actor is resolved
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); in
63
- * `DEV` only, sets `X-Fuz-Auth-Debug: daemon_token_discarded_browser_context`.
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 (still pre-bootstrap
67
- * after the lazy refresh): soft-fail discard (pass through, not 503) —
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-account resolution)
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
- // daemon token valid — resolve keeper account. `start_daemon_token_rotation`
131
- // resolves the keeper once at startup, but rotation often starts before the
132
- // keeper account exists (e.g. cross-process test harnesses spawn the binary
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`
@@ -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
@@ -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;AAEpF;;;;;;;GAOG;AACH,MAAM,WAAW,OAAO;IACvB,0CAA0C;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