@fuzdev/fuz_app 0.180.0 → 0.182.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 (389) hide show
  1. package/dist/actions/CLAUDE.md +38 -20
  2. package/dist/actions/action_rpc.d.ts +25 -6
  3. package/dist/actions/action_rpc.d.ts.map +1 -1
  4. package/dist/actions/action_rpc.js +56 -48
  5. package/dist/actions/action_types.d.ts +31 -13
  6. package/dist/actions/action_types.d.ts.map +1 -1
  7. package/dist/actions/action_types.js +1 -1
  8. package/dist/actions/notification_sender.d.ts +83 -0
  9. package/dist/actions/notification_sender.d.ts.map +1 -0
  10. package/dist/actions/notification_sender.js +85 -0
  11. package/dist/actions/perform_action.d.ts +13 -4
  12. package/dist/actions/perform_action.d.ts.map +1 -1
  13. package/dist/actions/perform_action.js +27 -18
  14. package/dist/actions/register_action_ws.d.ts +20 -2
  15. package/dist/actions/register_action_ws.d.ts.map +1 -1
  16. package/dist/actions/register_action_ws.js +17 -5
  17. package/dist/actions/ws_socket_session.d.ts +3 -0
  18. package/dist/actions/ws_socket_session.d.ts.map +1 -1
  19. package/dist/actions/ws_socket_session.js +3 -2
  20. package/dist/auth/CLAUDE.md +84 -59
  21. package/dist/auth/account_actions.d.ts.map +1 -1
  22. package/dist/auth/account_actions.js +30 -3
  23. package/dist/auth/account_queries.d.ts +213 -2
  24. package/dist/auth/account_queries.d.ts.map +1 -1
  25. package/dist/auth/account_queries.js +255 -2
  26. package/dist/auth/account_route_schema.d.ts +26 -16
  27. package/dist/auth/account_route_schema.d.ts.map +1 -1
  28. package/dist/auth/account_route_schema.js +10 -24
  29. package/dist/auth/account_routes.d.ts +5 -7
  30. package/dist/auth/account_routes.d.ts.map +1 -1
  31. package/dist/auth/account_routes.js +110 -89
  32. package/dist/auth/admin_actions.d.ts.map +1 -1
  33. package/dist/auth/admin_actions.js +117 -25
  34. package/dist/auth/api_token_queries.d.ts +29 -12
  35. package/dist/auth/api_token_queries.d.ts.map +1 -1
  36. package/dist/auth/api_token_queries.js +42 -27
  37. package/dist/auth/audit_log_route_schema.d.ts +1 -1
  38. package/dist/auth/audit_log_route_schema.d.ts.map +1 -1
  39. package/dist/auth/audit_log_routes.d.ts +1 -1
  40. package/dist/auth/audit_log_routes.d.ts.map +1 -1
  41. package/dist/auth/audit_log_routes.js +10 -12
  42. package/dist/auth/audit_log_schema.js +4 -4
  43. package/dist/auth/bearer_auth.d.ts +4 -3
  44. package/dist/auth/bearer_auth.d.ts.map +1 -1
  45. package/dist/auth/bearer_auth.js +37 -32
  46. package/dist/auth/bootstrap_account.d.ts +65 -37
  47. package/dist/auth/bootstrap_account.d.ts.map +1 -1
  48. package/dist/auth/bootstrap_account.js +115 -66
  49. package/dist/auth/bootstrap_route_schema.d.ts +6 -2
  50. package/dist/auth/bootstrap_route_schema.d.ts.map +1 -1
  51. package/dist/auth/bootstrap_route_schema.js +7 -2
  52. package/dist/auth/bootstrap_routes.d.ts +50 -33
  53. package/dist/auth/bootstrap_routes.d.ts.map +1 -1
  54. package/dist/auth/bootstrap_routes.js +109 -87
  55. package/dist/auth/bootstrap_token_store.d.ts +60 -0
  56. package/dist/auth/bootstrap_token_store.d.ts.map +1 -0
  57. package/dist/auth/bootstrap_token_store.js +39 -0
  58. package/dist/auth/credential_headers.d.ts +71 -0
  59. package/dist/auth/credential_headers.d.ts.map +1 -0
  60. package/dist/auth/credential_headers.js +100 -0
  61. package/dist/auth/daemon_token.d.ts +13 -1
  62. package/dist/auth/daemon_token.d.ts.map +1 -1
  63. package/dist/auth/daemon_token.js +14 -2
  64. package/dist/auth/daemon_token_middleware.d.ts +10 -11
  65. package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
  66. package/dist/auth/daemon_token_middleware.js +39 -30
  67. package/dist/auth/deps.d.ts +10 -11
  68. package/dist/auth/deps.d.ts.map +1 -1
  69. package/dist/auth/invite_queries.d.ts +18 -0
  70. package/dist/auth/invite_queries.d.ts.map +1 -1
  71. package/dist/auth/invite_queries.js +24 -0
  72. package/dist/auth/request_context.d.ts +97 -76
  73. package/dist/auth/request_context.d.ts.map +1 -1
  74. package/dist/auth/request_context.js +93 -104
  75. package/dist/auth/resolved_auth.d.ts +10 -5
  76. package/dist/auth/resolved_auth.d.ts.map +1 -1
  77. package/dist/auth/resolved_auth.js +2 -2
  78. package/dist/auth/role_grant_offer_action_specs.d.ts +2 -2
  79. package/dist/auth/role_grant_offer_action_specs.d.ts.map +1 -1
  80. package/dist/auth/role_grant_offer_action_specs.js +5 -3
  81. package/dist/auth/role_grant_offer_actions.d.ts +7 -11
  82. package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
  83. package/dist/auth/role_grant_offer_actions.js +97 -106
  84. package/dist/auth/role_grant_offer_ddl.d.ts +7 -1
  85. package/dist/auth/role_grant_offer_ddl.d.ts.map +1 -1
  86. package/dist/auth/role_grant_offer_ddl.js +9 -2
  87. package/dist/auth/role_grant_offer_notifications.d.ts +87 -38
  88. package/dist/auth/role_grant_offer_notifications.d.ts.map +1 -1
  89. package/dist/auth/role_grant_offer_notifications.js +75 -22
  90. package/dist/auth/role_grant_offer_queries.d.ts +143 -9
  91. package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
  92. package/dist/auth/role_grant_offer_queries.js +266 -66
  93. package/dist/auth/role_grant_offer_schema.js +1 -1
  94. package/dist/auth/role_grant_queries.d.ts +57 -10
  95. package/dist/auth/role_grant_queries.d.ts.map +1 -1
  96. package/dist/auth/role_grant_queries.js +81 -22
  97. package/dist/auth/role_grant_sql.d.ts +21 -0
  98. package/dist/auth/role_grant_sql.d.ts.map +1 -1
  99. package/dist/auth/role_grant_sql.js +21 -0
  100. package/dist/auth/self_service_role_actions.d.ts.map +1 -1
  101. package/dist/auth/self_service_role_actions.js +9 -2
  102. package/dist/auth/session_cookie.d.ts +105 -25
  103. package/dist/auth/session_cookie.d.ts.map +1 -1
  104. package/dist/auth/session_cookie.js +124 -15
  105. package/dist/auth/session_middleware.d.ts +83 -54
  106. package/dist/auth/session_middleware.d.ts.map +1 -1
  107. package/dist/auth/session_middleware.js +92 -66
  108. package/dist/auth/session_queries.d.ts +95 -14
  109. package/dist/auth/session_queries.d.ts.map +1 -1
  110. package/dist/auth/session_queries.js +98 -19
  111. package/dist/auth/signup_route_schema.d.ts +5 -5
  112. package/dist/auth/signup_route_schema.d.ts.map +1 -1
  113. package/dist/auth/signup_route_schema.js +4 -4
  114. package/dist/auth/signup_routes.d.ts.map +1 -1
  115. package/dist/auth/signup_routes.js +17 -14
  116. package/dist/auth/standard_rpc_actions.d.ts +6 -19
  117. package/dist/auth/standard_rpc_actions.d.ts.map +1 -1
  118. package/dist/auth/standard_rpc_actions.js +5 -6
  119. package/dist/auth/token_scope.d.ts +6 -8
  120. package/dist/auth/token_scope.d.ts.map +1 -1
  121. package/dist/auth/token_scope.js +6 -9
  122. package/dist/dev/setup.d.ts +6 -1
  123. package/dist/dev/setup.d.ts.map +1 -1
  124. package/dist/dev/setup.js +42 -34
  125. package/dist/hono_context.d.ts +21 -0
  126. package/dist/hono_context.d.ts.map +1 -1
  127. package/dist/hono_context.js +17 -0
  128. package/dist/http/CLAUDE.md +156 -48
  129. package/dist/http/auth_shape.d.ts +4 -4
  130. package/dist/http/common_routes.js +1 -1
  131. package/dist/http/db_routes.d.ts +4 -3
  132. package/dist/http/db_routes.d.ts.map +1 -1
  133. package/dist/http/db_routes.js +14 -14
  134. package/dist/http/dev_route_error_check.d.ts +6 -3
  135. package/dist/http/dev_route_error_check.d.ts.map +1 -1
  136. package/dist/http/dev_route_error_check.js +6 -3
  137. package/dist/http/dev_set_cookie_check.d.ts +53 -0
  138. package/dist/http/dev_set_cookie_check.d.ts.map +1 -0
  139. package/dist/http/dev_set_cookie_check.js +80 -0
  140. package/dist/http/error_schemas.d.ts +45 -22
  141. package/dist/http/error_schemas.d.ts.map +1 -1
  142. package/dist/http/error_schemas.js +53 -26
  143. package/dist/http/header_lines.d.ts +42 -0
  144. package/dist/http/header_lines.d.ts.map +1 -0
  145. package/dist/http/header_lines.js +80 -0
  146. package/dist/http/host.d.ts +12 -9
  147. package/dist/http/host.d.ts.map +1 -1
  148. package/dist/http/host.js +25 -20
  149. package/dist/http/origin.d.ts +7 -22
  150. package/dist/http/origin.d.ts.map +1 -1
  151. package/dist/http/origin.js +11 -25
  152. package/dist/http/proxy.d.ts +1 -0
  153. package/dist/http/proxy.d.ts.map +1 -1
  154. package/dist/http/proxy.js +3 -0
  155. package/dist/http/request_headers.d.ts +95 -0
  156. package/dist/http/request_headers.d.ts.map +1 -0
  157. package/dist/http/request_headers.js +110 -0
  158. package/dist/http/request_target.d.ts +134 -0
  159. package/dist/http/request_target.d.ts.map +1 -0
  160. package/dist/http/request_target.js +193 -0
  161. package/dist/http/route_error_check.d.ts +4 -11
  162. package/dist/http/route_error_check.d.ts.map +1 -1
  163. package/dist/http/route_error_check.js +4 -21
  164. package/dist/http/route_result.d.ts +127 -23
  165. package/dist/http/route_result.d.ts.map +1 -1
  166. package/dist/http/route_result.js +97 -19
  167. package/dist/http/route_spec.d.ts +299 -83
  168. package/dist/http/route_spec.d.ts.map +1 -1
  169. package/dist/http/route_spec.js +548 -71
  170. package/dist/http/simple_request.d.ts +19 -14
  171. package/dist/http/simple_request.d.ts.map +1 -1
  172. package/dist/http/simple_request.js +17 -29
  173. package/dist/http/surface.d.ts +2 -0
  174. package/dist/http/surface.d.ts.map +1 -1
  175. package/dist/http/surface.js +4 -1
  176. package/dist/realtime/outbound_budget.d.ts +1 -2
  177. package/dist/realtime/outbound_budget.d.ts.map +1 -1
  178. package/dist/realtime/outbound_budget.js +1 -2
  179. package/dist/realtime/sse.d.ts +47 -17
  180. package/dist/realtime/sse.d.ts.map +1 -1
  181. package/dist/realtime/sse.js +115 -93
  182. package/dist/realtime/sse_constants.d.ts +7 -1
  183. package/dist/realtime/sse_constants.d.ts.map +1 -1
  184. package/dist/realtime/sse_constants.js +12 -1
  185. package/dist/realtime/sse_registry.d.ts +3 -3
  186. package/dist/realtime/sse_registry.js +3 -3
  187. package/dist/runtime/deps.d.ts +20 -4
  188. package/dist/runtime/deps.d.ts.map +1 -1
  189. package/dist/runtime/mock.d.ts +7 -1
  190. package/dist/runtime/mock.d.ts.map +1 -1
  191. package/dist/runtime/mock.js +33 -3
  192. package/dist/runtime/node.d.ts.map +1 -1
  193. package/dist/runtime/node.js +2 -1
  194. package/dist/runtime/secure_file.d.ts +71 -10
  195. package/dist/runtime/secure_file.d.ts.map +1 -1
  196. package/dist/runtime/secure_file.js +91 -11
  197. package/dist/server/app_backend.d.ts +0 -8
  198. package/dist/server/app_backend.d.ts.map +1 -1
  199. package/dist/server/app_backend.js +4 -4
  200. package/dist/server/app_server.d.ts +54 -33
  201. package/dist/server/app_server.d.ts.map +1 -1
  202. package/dist/server/app_server.js +69 -41
  203. package/dist/server/serve_fact_route.d.ts +3 -3
  204. package/dist/server/serve_fact_route.d.ts.map +1 -1
  205. package/dist/server/serve_fact_route.js +59 -55
  206. package/dist/server/static.d.ts +20 -0
  207. package/dist/server/static.d.ts.map +1 -1
  208. package/dist/server/static.js +56 -8
  209. package/dist/server/unmatched_route.d.ts +42 -0
  210. package/dist/server/unmatched_route.d.ts.map +1 -0
  211. package/dist/server/unmatched_route.js +64 -0
  212. package/dist/testing/CLAUDE.md +406 -1202
  213. package/dist/testing/app_server.d.ts +3 -1
  214. package/dist/testing/app_server.d.ts.map +1 -1
  215. package/dist/testing/app_server.js +5 -9
  216. package/dist/testing/auth_apps.d.ts.map +1 -1
  217. package/dist/testing/auth_apps.js +3 -2
  218. package/dist/testing/cross_backend/account_lifecycle.d.ts +11 -4
  219. package/dist/testing/cross_backend/account_lifecycle.d.ts.map +1 -1
  220. package/dist/testing/cross_backend/account_lifecycle.js +320 -6
  221. package/dist/testing/cross_backend/build_test_backend_paths.d.ts +4 -1
  222. package/dist/testing/cross_backend/build_test_backend_paths.d.ts.map +1 -1
  223. package/dist/testing/cross_backend/build_test_backend_paths.js +1 -1
  224. package/dist/testing/cross_backend/capabilities.d.ts +68 -5
  225. package/dist/testing/cross_backend/capabilities.d.ts.map +1 -1
  226. package/dist/testing/cross_backend/capabilities.js +20 -4
  227. package/dist/testing/cross_backend/cell_gated_create.js +1 -1
  228. package/dist/testing/cross_backend/conformance_case.d.ts +63 -21
  229. package/dist/testing/cross_backend/conformance_case.d.ts.map +1 -1
  230. package/dist/testing/cross_backend/conformance_table.d.ts +54 -12
  231. package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
  232. package/dist/testing/cross_backend/conformance_table.js +179 -23
  233. package/dist/testing/cross_backend/cookie_attributes.js +1 -1
  234. package/dist/testing/cross_backend/create_dual_spawn_global_setup.d.ts +7 -1
  235. package/dist/testing/cross_backend/create_dual_spawn_global_setup.d.ts.map +1 -1
  236. package/dist/testing/cross_backend/create_dual_spawn_global_setup.js +3 -3
  237. package/dist/testing/cross_backend/credential_conformance.d.ts +196 -0
  238. package/dist/testing/cross_backend/credential_conformance.d.ts.map +1 -0
  239. package/dist/testing/cross_backend/credential_conformance.js +296 -0
  240. package/dist/testing/cross_backend/credential_conformance.json +1284 -0
  241. package/dist/testing/cross_backend/credential_conformance_wire.d.ts +40 -0
  242. package/dist/testing/cross_backend/credential_conformance_wire.d.ts.map +1 -0
  243. package/dist/testing/cross_backend/credential_conformance_wire.js +293 -0
  244. package/dist/testing/cross_backend/credential_header_robustness.d.ts +1 -3
  245. package/dist/testing/cross_backend/credential_header_robustness.d.ts.map +1 -1
  246. package/dist/testing/cross_backend/credential_header_robustness.js +24 -55
  247. package/dist/testing/cross_backend/credential_wire.d.ts +112 -0
  248. package/dist/testing/cross_backend/credential_wire.d.ts.map +1 -0
  249. package/dist/testing/cross_backend/credential_wire.js +188 -0
  250. package/dist/testing/cross_backend/default_backend_configs.d.ts.map +1 -1
  251. package/dist/testing/cross_backend/default_backend_configs.js +22 -2
  252. package/dist/testing/cross_backend/default_spine_surface.d.ts +1 -26
  253. package/dist/testing/cross_backend/default_spine_surface.d.ts.map +1 -1
  254. package/dist/testing/cross_backend/default_spine_surface.js +3 -7
  255. package/dist/testing/cross_backend/differential.d.ts +1 -1
  256. package/dist/testing/cross_backend/differential.d.ts.map +1 -1
  257. package/dist/testing/cross_backend/differential.js +3 -2
  258. package/dist/testing/cross_backend/differential_normalize.d.ts +23 -6
  259. package/dist/testing/cross_backend/differential_normalize.d.ts.map +1 -1
  260. package/dist/testing/cross_backend/differential_normalize.js +11 -5
  261. package/dist/testing/cross_backend/full_spine_mount.d.ts +4 -10
  262. package/dist/testing/cross_backend/full_spine_mount.d.ts.map +1 -1
  263. package/dist/testing/cross_backend/full_spine_mount.js +11 -4
  264. package/dist/testing/cross_backend/identity_parity.d.ts.map +1 -1
  265. package/dist/testing/cross_backend/identity_parity.js +4 -0
  266. package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
  267. package/dist/testing/cross_backend/in_process_setup.js +78 -4
  268. package/dist/testing/cross_backend/login_security.d.ts.map +1 -1
  269. package/dist/testing/cross_backend/login_security.js +13 -10
  270. package/dist/testing/cross_backend/peer_ping_ws.d.ts +1 -1
  271. package/dist/testing/cross_backend/peer_ping_ws.js +2 -2
  272. package/dist/testing/cross_backend/request_header_conformance.d.ts +174 -0
  273. package/dist/testing/cross_backend/request_header_conformance.d.ts.map +1 -0
  274. package/dist/testing/cross_backend/request_header_conformance.js +196 -0
  275. package/dist/testing/cross_backend/request_header_conformance.json +1158 -0
  276. package/dist/testing/cross_backend/request_header_conformance_wire.d.ts +39 -0
  277. package/dist/testing/cross_backend/request_header_conformance_wire.d.ts.map +1 -0
  278. package/dist/testing/cross_backend/request_header_conformance_wire.js +284 -0
  279. package/dist/testing/cross_backend/request_target_conformance.d.ts +298 -0
  280. package/dist/testing/cross_backend/request_target_conformance.d.ts.map +1 -0
  281. package/dist/testing/cross_backend/request_target_conformance.js +186 -0
  282. package/dist/testing/cross_backend/request_target_conformance.json +3765 -0
  283. package/dist/testing/cross_backend/request_target_conformance_wire.d.ts +32 -0
  284. package/dist/testing/cross_backend/request_target_conformance_wire.d.ts.map +1 -0
  285. package/dist/testing/cross_backend/request_target_conformance_wire.js +278 -0
  286. package/dist/testing/cross_backend/role_grant_offer_lifecycle.d.ts.map +1 -1
  287. package/dist/testing/cross_backend/role_grant_offer_lifecycle.js +173 -1
  288. package/dist/testing/cross_backend/role_grant_offer_notification_ws.d.ts +5 -4
  289. package/dist/testing/cross_backend/role_grant_offer_notification_ws.d.ts.map +1 -1
  290. package/dist/testing/cross_backend/role_grant_offer_notification_ws.js +185 -31
  291. package/dist/testing/cross_backend/rpc_adversarial.d.ts +6 -4
  292. package/dist/testing/cross_backend/rpc_adversarial.d.ts.map +1 -1
  293. package/dist/testing/cross_backend/rpc_adversarial.js +5 -2
  294. package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +6 -7
  295. package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
  296. package/dist/testing/cross_backend/rust_spine_consumer_surface.js +4 -5
  297. package/dist/testing/cross_backend/session_cap.d.ts.map +1 -1
  298. package/dist/testing/cross_backend/session_cap.js +82 -34
  299. package/dist/testing/cross_backend/session_cookie_effect.d.ts +43 -0
  300. package/dist/testing/cross_backend/session_cookie_effect.d.ts.map +1 -0
  301. package/dist/testing/cross_backend/session_cookie_effect.js +103 -0
  302. package/dist/testing/cross_backend/session_login.d.ts +24 -0
  303. package/dist/testing/cross_backend/session_login.d.ts.map +1 -0
  304. package/dist/testing/cross_backend/session_login.js +31 -0
  305. package/dist/testing/cross_backend/setup.d.ts +117 -0
  306. package/dist/testing/cross_backend/setup.d.ts.map +1 -1
  307. package/dist/testing/cross_backend/setup.js +193 -9
  308. package/dist/testing/cross_backend/simple_request.d.ts.map +1 -1
  309. package/dist/testing/cross_backend/simple_request.js +5 -0
  310. package/dist/testing/cross_backend/spine_suites.d.ts +9 -1
  311. package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
  312. package/dist/testing/cross_backend/spine_suites.js +88 -5
  313. package/dist/testing/cross_backend/spine_surface_constants.d.ts +1 -1
  314. package/dist/testing/cross_backend/spine_surface_constants.d.ts.map +1 -1
  315. package/dist/testing/cross_backend/spine_surface_constants.js +1 -0
  316. package/dist/testing/cross_backend/sse_round_trip.d.ts +8 -5
  317. package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
  318. package/dist/testing/cross_backend/sse_round_trip.js +205 -64
  319. package/dist/testing/cross_backend/testing_backdoor.d.ts.map +1 -1
  320. package/dist/testing/cross_backend/testing_backdoor.js +5 -2
  321. package/dist/testing/cross_backend/testing_credential_read.d.ts +165 -0
  322. package/dist/testing/cross_backend/testing_credential_read.d.ts.map +1 -0
  323. package/dist/testing/cross_backend/testing_credential_read.js +175 -0
  324. package/dist/testing/cross_backend/testing_reset_actions.d.ts +19 -0
  325. package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
  326. package/dist/testing/cross_backend/testing_reset_actions.js +22 -6
  327. package/dist/testing/cross_backend/token_lifetime.d.ts.map +1 -1
  328. package/dist/testing/cross_backend/token_lifetime.js +58 -2
  329. package/dist/testing/cross_backend/transport_composition.d.ts +2 -4
  330. package/dist/testing/cross_backend/transport_composition.d.ts.map +1 -1
  331. package/dist/testing/cross_backend/transport_composition.js +13 -10
  332. package/dist/testing/cross_backend/ts_spine_backend_config.d.ts.map +1 -1
  333. package/dist/testing/cross_backend/ts_spine_backend_config.js +5 -3
  334. package/dist/testing/cross_backend/ws_endpoint.d.ts +11 -1
  335. package/dist/testing/cross_backend/ws_endpoint.d.ts.map +1 -1
  336. package/dist/testing/cross_backend/ws_endpoint.js +19 -2
  337. package/dist/testing/cross_backend/ws_role_gated.d.ts.map +1 -1
  338. package/dist/testing/cross_backend/ws_role_gated.js +2 -3
  339. package/dist/testing/cross_backend/ws_round_trip.d.ts.map +1 -1
  340. package/dist/testing/cross_backend/ws_round_trip.js +28 -12
  341. package/dist/testing/cross_backend/xfail.d.ts +44 -11
  342. package/dist/testing/cross_backend/xfail.d.ts.map +1 -1
  343. package/dist/testing/cross_backend/xfail.js +68 -23
  344. package/dist/testing/data_exposure.d.ts.map +1 -1
  345. package/dist/testing/data_exposure.js +4 -3
  346. package/dist/testing/integration.d.ts +1 -2
  347. package/dist/testing/integration.d.ts.map +1 -1
  348. package/dist/testing/integration.js +14 -8
  349. package/dist/testing/integration_helpers.d.ts +50 -3
  350. package/dist/testing/integration_helpers.d.ts.map +1 -1
  351. package/dist/testing/integration_helpers.js +87 -9
  352. package/dist/testing/middleware.d.ts +3 -1
  353. package/dist/testing/middleware.d.ts.map +1 -1
  354. package/dist/testing/middleware.js +14 -7
  355. package/dist/testing/resolved_auth.d.ts +3 -1
  356. package/dist/testing/resolved_auth.d.ts.map +1 -1
  357. package/dist/testing/resolved_auth.js +4 -4
  358. package/dist/testing/round_trip.d.ts +6 -2
  359. package/dist/testing/round_trip.d.ts.map +1 -1
  360. package/dist/testing/round_trip.js +17 -6
  361. package/dist/testing/rpc_envelope_cases.d.ts.map +1 -1
  362. package/dist/testing/rpc_envelope_cases.js +7 -0
  363. package/dist/testing/rpc_helpers.d.ts +4 -2
  364. package/dist/testing/rpc_helpers.d.ts.map +1 -1
  365. package/dist/testing/rpc_helpers.js +6 -1
  366. package/dist/testing/rpc_round_trip.d.ts +13 -2
  367. package/dist/testing/rpc_round_trip.d.ts.map +1 -1
  368. package/dist/testing/rpc_round_trip.js +25 -6
  369. package/dist/testing/schema_generators.d.ts +2 -2
  370. package/dist/testing/schema_generators.d.ts.map +1 -1
  371. package/dist/testing/schema_generators.js +4 -4
  372. package/dist/testing/stubs.d.ts +2 -2
  373. package/dist/testing/stubs.d.ts.map +1 -1
  374. package/dist/testing/stubs.js +13 -10
  375. package/dist/testing/transports/fetch_transport.d.ts +6 -3
  376. package/dist/testing/transports/fetch_transport.d.ts.map +1 -1
  377. package/dist/testing/transports/fetch_transport.js +31 -19
  378. package/dist/testing/transports/raw_http.d.ts +61 -1
  379. package/dist/testing/transports/raw_http.d.ts.map +1 -1
  380. package/dist/testing/transports/raw_http.js +61 -1
  381. package/dist/testing/transports/ws_raw_client.d.ts +20 -0
  382. package/dist/testing/transports/ws_raw_client.d.ts.map +1 -1
  383. package/dist/testing/transports/ws_raw_client.js +10 -4
  384. package/dist/testing/transports/ws_transport.d.ts +21 -1
  385. package/dist/testing/transports/ws_transport.d.ts.map +1 -1
  386. package/dist/testing/transports/ws_transport.js +58 -20
  387. package/dist/testing/ws_round_trip.d.ts.map +1 -1
  388. package/dist/testing/ws_round_trip.js +8 -4
  389. package/package.json +1 -1
@@ -6,46 +6,58 @@
6
6
  *
7
7
  * @module
8
8
  */
9
- import type { Context } from 'hono';
10
9
  import type { Logger } from '@fuzdev/fuz_util/log.ts';
11
- import type { SessionOptions } from './session_cookie.js';
12
- import { type BootstrapAccountSuccess } from './bootstrap_account.js';
10
+ import { type SessionOptions } from './session_cookie.js';
11
+ import { type BootstrapAccountCreated } from './bootstrap_account.js';
12
+ import type { BootstrapTokenStore } from './bootstrap_token_store.js';
13
13
  import type { Db } from '../db/db.js';
14
14
  import { type RouteSpec } from '../http/route_spec.js';
15
15
  import { type RateLimiter } from '../rate_limiter.js';
16
16
  import type { RouteFactoryDeps } from './deps.js';
17
17
  /**
18
- * Bootstrap status — runtime state computed once at startup.
18
+ * Bootstrap status — runtime state computed once at startup, flipped to
19
+ * unavailable when the window closes.
19
20
  */
20
21
  export interface BootstrapStatus {
21
22
  available: boolean;
22
- token_path: string | null;
23
23
  }
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>;
24
32
  /**
25
33
  * Per-factory configuration for bootstrap route specs.
26
34
  *
27
35
  * `bootstrap_status` is runtime state (a mutable ref), not a dep or options value —
28
- * it is passed through so the route handler can flip it on success.
36
+ * it is passed through so the route handler can flip it.
29
37
  */
30
38
  export interface BootstrapRouteOptions {
31
39
  session_options: SessionOptions<string>;
32
- /** Shared mutable reference — flipped to false after successful bootstrap. */
40
+ /** Shared mutable reference — flipped to false when the window closes. */
33
41
  bootstrap_status: BootstrapStatus;
34
42
  /**
35
- * Called after successful bootstrap (account + session created).
36
- * Use for app-specific post-bootstrap work like generating API tokens.
43
+ * The one-shot token. `null` mounts the route permanently closed
44
+ * (`'surface_only'`), answering `already_bootstrapped` as a bootstrapped
45
+ * server does.
37
46
  */
38
- on_bootstrap?: (result: BootstrapAccountSuccess, c: Context) => Promise<void>;
47
+ token_store: BootstrapTokenStore | null;
48
+ /** Called after a successful bootstrap commits. */
49
+ on_bootstrap?: OnBootstrap;
39
50
  /**
40
51
  * Rate limiter for bootstrap attempts, keyed by client IP. Pass `null` to
41
52
  * disable. Its own instance, not login's: bootstrap is one-shot and its
42
53
  * bucket is never refunded on success (see `RateLimiter.reset`), so a
43
54
  * fumbled token would otherwise leave the operator's *login* budget nearly
44
55
  * spent on a deployment where their new account is the only one that
45
- * exists. The Rust spine rate-limits bootstrap not at all (the token is
46
- * 32 bytes of CSPRNG compared in constant time); this is the tighter side
47
- * of that divergence, kept because the token also sits in a file whose
48
- * read path an operator can misconfigure.
56
+ * exists. The token is 32 bytes of CSPRNG compared in constant time, so
57
+ * guessing is not what it bounds: the `invalid_token` and
58
+ * `token_file_undeletable` legs write an unauthenticated audit row each and
59
+ * leave the window open, and the limiter bounds them. Twin of the Rust
60
+ * `BootstrapOptions.bootstrap_ip_rate_limiter`.
49
61
  */
50
62
  bootstrap_ip_rate_limiter: RateLimiter | null;
51
63
  }
@@ -53,8 +65,6 @@ export interface BootstrapRouteOptions {
53
65
  * Dependencies for checking bootstrap status at startup.
54
66
  */
55
67
  export interface CheckBootstrapStatusDeps {
56
- /** Hardened secret-file read — the same capability the request-time read uses. */
57
- read_secure_file: (path: string) => Promise<Uint8Array>;
58
68
  /** Only the single-row `bootstrap_lock` read — narrower than the full `Db`. */
59
69
  db: Pick<Db, 'query_one'>;
60
70
  log: Logger;
@@ -62,31 +72,38 @@ export interface CheckBootstrapStatusDeps {
62
72
  /**
63
73
  * Check bootstrap availability at startup.
64
74
  *
65
- * Bootstrap is available when:
66
- * 1. A token path is configured
67
- * 2. The token file passes the secure read (exists, not a symlink, mode
68
- * `0600`/`0400`, within the size cap) and holds at least
69
- * `BOOTSTRAP_TOKEN_MIN_BYTES` (a shorter one logs an error)
70
- * 3. The `bootstrap_lock` table shows `bootstrapped = false`
75
+ * Bootstrap is available when a token store is configured, the
76
+ * `bootstrap_lock` row shows `bootstrapped = false`, and the token file
77
+ * passes the same `read_bootstrap_token` the request makes — so "bootstrap
78
+ * is available" and "the token file can actually be read" can't drift apart.
79
+ *
80
+ * The lock is read first, so the report fits the state:
81
+ *
82
+ * - a missing `bootstrap_lock` row is unavailable, logged as an `error` — the
83
+ * migration seeds it, and without it every bootstrap would be refused in
84
+ * its transaction while `/status` advertised an open window
85
+ * - bootstrapped, no readable token file: `info`, the steady state
86
+ * - bootstrapped with a readable token file: a `warn` naming it — it would
87
+ * reopen bootstrap on an empty database, so the operator should delete it
88
+ * - not bootstrapped and the file unreadable: a `warn` with the reason (and
89
+ * the `error` a short token logs)
71
90
  *
72
- * The probe **reads through the same `read_bootstrap_token` the request-time
73
- * read uses**, so "bootstrap is available" and "the token file can actually
74
- * be read" can't drift apart — an availability check laxer than the read it
75
- * gates is the misconfiguration that reports green at boot and fails at
76
- * request time. Twin of the Rust spine's `is_bootstrap_available`.
91
+ * Twin of the Rust spine's `is_bootstrap_available`, which logs the same
92
+ * states at the same levels. A failed lock read throws here (boot fails)
93
+ * where the Rust twin reads it as unavailable.
77
94
  *
78
- * @param deps - filesystem and database access for the check
79
- * @param options - static configuration including `token_path`
80
- * @returns an object with `available` (boolean) and `token_path` (string | null)
95
+ * @param deps - the lock read and a logger
96
+ * @param options - the token store, `null` when bootstrap is not configured
97
+ * @returns the initial `BootstrapStatus`
81
98
  */
82
99
  export declare const check_bootstrap_status: (deps: CheckBootstrapStatusDeps, options: {
83
- token_path: string | null;
100
+ token_store: BootstrapTokenStore | null;
84
101
  }) => Promise<BootstrapStatus>;
85
102
  /**
86
103
  * Create bootstrap route specs for first-time account creation.
87
104
  *
88
- * @param deps - stateless capabilities including filesystem access
89
- * @param options - per-factory configuration (session, token path, bootstrap status)
105
+ * @param deps - stateless capabilities (keyring, password, audit, log)
106
+ * @param options - per-factory configuration (session, token store, bootstrap status, limiter)
90
107
  * @returns route specs (not yet applied to Hono)
91
108
  */
92
109
  export declare const create_bootstrap_route_specs: (deps: RouteFactoryDeps, options: BootstrapRouteOptions) => Array<RouteSpec>;
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrap_routes.d.ts","sourceRoot":"","sources":["../../src/lib/auth/bootstrap_routes.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D,OAAO,EAGN,KAAK,uBAAuB,EAC5B,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAyC,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAI9F,OAAO,EAAoB,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAUlD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB;IACrC,eAAe,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC;IACxC,8EAA8E;IAC9E,gBAAgB,EAAE,eAAe,CAAC;IAClC;;;OAGG;IACH,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,uBAAuB,EAAE,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9E;;;;;;;;;;OAUG;IACH,yBAAyB,EAAE,WAAW,GAAG,IAAI,CAAC;CAC9C;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACxC,kFAAkF;IAClF,gBAAgB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IACxD,+EAA+E;IAC/E,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,WAAW,CAAC,CAAC;IAC1B,GAAG,EAAE,MAAM,CAAC;CACZ;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,sBAAsB,GAClC,MAAM,wBAAwB,EAC9B,SAAS;IAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,KACpC,OAAO,CAAC,eAAe,CAyBzB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B,GACxC,MAAM,gBAAgB,EACtB,SAAS,qBAAqB,KAC5B,KAAK,CAAC,SAAS,CA6HjB,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;AAEtD,OAAO,EAAyB,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAGN,KAAK,uBAAuB,EAC5B,MAAM,wBAAwB,CAAC;AAChC,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,MAAM,WAAW,GAAG,CAAC,OAAO,EAAE,uBAAuB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAE9E;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB;IACrC,eAAe,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC;IACxC,0EAA0E;IAC1E,gBAAgB,EAAE,eAAe,CAAC;IAClC;;;;OAIG;IACH,WAAW,EAAE,mBAAmB,GAAG,IAAI,CAAC;IACxC,mDAAmD;IACnD,YAAY,CAAC,EAAE,WAAW,CAAC;IAC3B;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,sBAAsB,GAClC,MAAM,wBAAwB,EAC9B,SAAS;IAAE,WAAW,EAAE,mBAAmB,GAAG,IAAI,CAAA;CAAE,KAClD,OAAO,CAAC,eAAe,CA0CzB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B,GACxC,MAAM,gBAAgB,EACtB,SAAS,qBAAqB,KAC5B,KAAK,CAAC,SAAS,CAmIjB,CAAC"}
@@ -7,144 +7,172 @@
7
7
  * @module
8
8
  */
9
9
  import { to_error_message } from '@fuzdev/fuz_util/error.ts';
10
- import { create_session_and_set_cookie } from './session_middleware.js';
10
+ import { session_cookie_header } from './session_cookie.js';
11
11
  import { bootstrap_account, read_bootstrap_token } from './bootstrap_account.js';
12
12
  import { bootstrap_route_shape } from './bootstrap_route_schema.js';
13
- import { attach_route_handler, get_route_input } from '../http/route_spec.js';
13
+ import { attach_route_handler } from '../http/route_spec.js';
14
14
  import { route_fail, route_ok } from '../http/route_result.js';
15
- import { get_client_ip } from '../http/client_ip.js';
16
15
  import { rate_limit_ip_key } from '../http/ip_canonical.js';
17
16
  import { reserve_optional } from '../rate_limiter.js';
18
- import { ERROR_ALREADY_BOOTSTRAPPED, ERROR_TOKEN_FILE_MISSING, REST_ALREADY_BOOTSTRAPPED, REST_INVALID_TOKEN, REST_RATE_LIMIT_EXCEEDED, REST_TOKEN_FILE_MISSING } from '../http/error_schemas.js';
17
+ 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';
19
18
  /**
20
19
  * Check bootstrap availability at startup.
21
20
  *
22
- * Bootstrap is available when:
23
- * 1. A token path is configured
24
- * 2. The token file passes the secure read (exists, not a symlink, mode
25
- * `0600`/`0400`, within the size cap) and holds at least
26
- * `BOOTSTRAP_TOKEN_MIN_BYTES` (a shorter one logs an error)
27
- * 3. The `bootstrap_lock` table shows `bootstrapped = false`
21
+ * Bootstrap is available when a token store is configured, the
22
+ * `bootstrap_lock` row shows `bootstrapped = false`, and the token file
23
+ * passes the same `read_bootstrap_token` the request makes — so "bootstrap
24
+ * is available" and "the token file can actually be read" can't drift apart.
28
25
  *
29
- * The probe **reads through the same `read_bootstrap_token` the request-time
30
- * read uses**, so "bootstrap is available" and "the token file can actually
31
- * be read" can't drift apart — an availability check laxer than the read it
32
- * gates is the misconfiguration that reports green at boot and fails at
33
- * request time. Twin of the Rust spine's `is_bootstrap_available`.
26
+ * The lock is read first, so the report fits the state:
34
27
  *
35
- * @param deps - filesystem and database access for the check
36
- * @param options - static configuration including `token_path`
37
- * @returns an object with `available` (boolean) and `token_path` (string | null)
28
+ * - a missing `bootstrap_lock` row is unavailable, logged as an `error` — the
29
+ * migration seeds it, and without it every bootstrap would be refused in
30
+ * its transaction while `/status` advertised an open window
31
+ * - bootstrapped, no readable token file: `info`, the steady state
32
+ * - bootstrapped with a readable token file: a `warn` naming it — it would
33
+ * reopen bootstrap on an empty database, so the operator should delete it
34
+ * - not bootstrapped and the file unreadable: a `warn` with the reason (and
35
+ * the `error` a short token logs)
36
+ *
37
+ * Twin of the Rust spine's `is_bootstrap_available`, which logs the same
38
+ * states at the same levels. A failed lock read throws here (boot fails)
39
+ * where the Rust twin reads it as unavailable.
40
+ *
41
+ * @param deps - the lock read and a logger
42
+ * @param options - the token store, `null` when bootstrap is not configured
43
+ * @returns the initial `BootstrapStatus`
38
44
  */
39
45
  export const check_bootstrap_status = async (deps, options) => {
40
- const { read_secure_file, db, log } = deps;
41
- const { token_path } = options;
42
- if (!token_path) {
43
- return { available: false, token_path: null };
46
+ const { db, log } = deps;
47
+ const { token_store } = options;
48
+ if (!token_store)
49
+ return { available: false };
50
+ const lock_row = await db.query_one('SELECT bootstrapped FROM bootstrap_lock WHERE id = 1');
51
+ if (!lock_row) {
52
+ log.error('Bootstrap unavailable: the bootstrap_lock row is missing — the auth migration seeds it; restore it to bootstrap');
53
+ return { available: false };
54
+ }
55
+ if (lock_row.bootstrapped) {
56
+ let present = true;
57
+ try {
58
+ await token_store.read_token();
59
+ }
60
+ catch {
61
+ present = false;
62
+ }
63
+ if (present) {
64
+ log.warn(`Bootstrap token file present on a bootstrapped server at ${token_store.path} — it would reopen bootstrap on an empty database; delete it`);
65
+ }
66
+ else {
67
+ log.info('Bootstrap unavailable: already bootstrapped');
68
+ }
69
+ return { available: false };
44
70
  }
45
71
  try {
46
- await read_bootstrap_token({ read_secure_file, log }, token_path);
72
+ await read_bootstrap_token({ token_store, log });
47
73
  }
48
74
  catch (err) {
49
- log.info(`Bootstrap unavailable: ${to_error_message(err)}`);
50
- return { available: false, token_path };
51
- }
52
- const lock_row = await db.query_one('SELECT bootstrapped FROM bootstrap_lock WHERE id = 1');
53
- if (lock_row?.bootstrapped) {
54
- log.info('Bootstrap unavailable: already bootstrapped');
55
- return { available: false, token_path };
75
+ log.warn(`Bootstrap unavailable: token file unreadable: ${to_error_message(err)}`);
76
+ return { available: false };
56
77
  }
57
- log.info(`Bootstrap token available: ${token_path}`);
58
- return { available: true, token_path };
78
+ log.info(`Bootstrap token available: ${token_store.path}`);
79
+ return { available: true };
59
80
  };
60
81
  /**
61
82
  * Create bootstrap route specs for first-time account creation.
62
83
  *
63
- * @param deps - stateless capabilities including filesystem access
64
- * @param options - per-factory configuration (session, token path, bootstrap status)
84
+ * @param deps - stateless capabilities (keyring, password, audit, log)
85
+ * @param options - per-factory configuration (session, token store, bootstrap status, limiter)
65
86
  * @returns route specs (not yet applied to Hono)
66
87
  */
67
88
  export const create_bootstrap_route_specs = (deps, options) => {
68
- const { keyring } = deps;
69
- const { session_options, bootstrap_status, on_bootstrap, bootstrap_ip_rate_limiter } = options;
70
- const { token_path } = bootstrap_status;
89
+ const { session_options, bootstrap_status, token_store, on_bootstrap, bootstrap_ip_rate_limiter } = options;
71
90
  return [
72
- attach_route_handler(bootstrap_route_shape, async (c, route) => {
91
+ attach_route_handler(bootstrap_route_shape, async (route) => {
73
92
  // Short-circuit if bootstrap already completed or surface-only mounted.
74
- // In 'surface_only' mode `bootstrap_status.token_path === null` and
75
- // `available === false`; in 'live' mode after success `available` flips
76
- // to `false`. Either way the wire shape is 403 ALREADY_BOOTSTRAPPED.
77
- if (!bootstrap_status.available || token_path === null) {
93
+ // In 'surface_only' mode `token_store === null`; in 'live' mode after
94
+ // the window closes `available` is `false`. Either way the wire shape
95
+ // is 403 ALREADY_BOOTSTRAPPED, and no audit row is written: the route
96
+ // stays mounted for the life of the process, so an emit here would be
97
+ // an unauthenticated, unbounded write channel.
98
+ if (!bootstrap_status.available || token_store === null) {
78
99
  return route_fail(REST_ALREADY_BOOTSTRAPPED);
79
100
  }
80
101
  // Per-IP rate limit (before any token/DB work). Reserved, not
81
102
  // checked: the attempt counts against the cap until it settles, so
82
103
  // a concurrent burst of token guesses can't all pass before any of
83
- // it records. The `finally` releases it unless a failure recorded it.
84
- // keyed by the address's rate-limit key (an IPv6 client's /64)
85
- const ip_key = bootstrap_ip_rate_limiter ? rate_limit_ip_key(get_client_ip(c)) : null;
104
+ // it records. A refusal records it; the race loser, a success, and
105
+ // a throw release it in the `finally`.
106
+ // keyed by the address's rate-limit key (an IPv6 client's /64). With
107
+ // no resolved client IP that is one shared `'unknown'` bucket, where
108
+ // the Rust twin skips the limiter — the difference signup has too, and
109
+ // one only an app mounted without the proxy middleware can show.
110
+ const ip_key = bootstrap_ip_rate_limiter ? rate_limit_ip_key(route.client_ip) : null;
86
111
  const ip_reserved = await reserve_optional(bootstrap_ip_rate_limiter, ip_key, {
87
- signal: c.req.raw.signal
112
+ signal: route.signal
88
113
  });
89
114
  if (!ip_reserved.ok) {
90
115
  return route_fail(REST_RATE_LIMIT_EXCEEDED, { retry_after: ip_reserved.retry_after });
91
116
  }
92
117
  try {
93
- const input = get_route_input(c);
118
+ const input = route.input;
94
119
  // `transaction: false` makes `route.db` the pool. `bootstrap_account`
95
120
  // manages its own transaction internally.
96
121
  const result = await bootstrap_account({
97
122
  db: route.db,
98
- token_path,
99
- read_secure_file: deps.read_secure_file,
100
- delete_file: deps.delete_file,
123
+ token_store,
101
124
  password: deps.password,
125
+ keyring: deps.keyring,
102
126
  log: deps.log
103
- }, input.token, input);
127
+ }, input.token, input, { session_options });
104
128
  if (!result.ok) {
129
+ // The lock-race loser — the window open here, the lock already
130
+ // flipped in the database. Close the window so the next caller
131
+ // takes the short-circuit, and write nothing and charge nothing:
132
+ // it is reachable only by a concurrent legitimate attempt, and
133
+ // folding it into the silent closed-window refusal keeps the
134
+ // post-bootstrap probe channel write-free. Twin of the Rust
135
+ // spine's `bootstrap_handler`.
136
+ if (result.error === ERROR_ALREADY_BOOTSTRAPPED) {
137
+ bootstrap_status.available = false;
138
+ return route_fail(REST_ALREADY_BOOTSTRAPPED);
139
+ }
105
140
  // An unreadable token file closes the window. Bootstrap cannot
106
141
  // succeed without one, and `check_bootstrap_status` already reads
107
142
  // an unreadable file as unavailable at startup — so leaving the
108
143
  // flag set means the two disagree, and every later request takes
109
- // this leg and writes another audit row. The limiter would bound
110
- // that channel; closing it ends it, and stops `/status`
111
- // advertising a window that can't be walked through. Twin of the
112
- // Rust spine's `bootstrap_handler`, which does the same.
144
+ // this leg and writes another audit row. A wrong token and an
145
+ // undeletable file leave it open (the operator retries); the
146
+ // limiter bounds those.
113
147
  if (result.error === ERROR_TOKEN_FILE_MISSING)
114
148
  bootstrap_status.available = false;
115
149
  ip_reserved.reservation.record();
116
150
  await deps.audit.emit(route, {
117
151
  event_type: 'bootstrap',
118
152
  outcome: 'failure',
119
- ip: get_client_ip(c),
153
+ ip: route.client_ip,
120
154
  metadata: { error: result.error }
121
155
  });
122
- return route_fail(result.error === ERROR_ALREADY_BOOTSTRAPPED
123
- ? REST_ALREADY_BOOTSTRAPPED
124
- : result.error === ERROR_TOKEN_FILE_MISSING
125
- ? REST_TOKEN_FILE_MISSING
156
+ return route_fail(result.error === ERROR_TOKEN_FILE_MISSING
157
+ ? REST_TOKEN_FILE_MISSING
158
+ : result.error === ERROR_TOKEN_FILE_UNDELETABLE
159
+ ? REST_TOKEN_FILE_UNDELETABLE
126
160
  : REST_INVALID_TOKEN);
127
161
  }
128
- // Successful bootstrap — update state immediately. Nothing is
162
+ // Successful bootstrap — committed, its token burned. Nothing is
129
163
  // reset: bootstrap has no account-grain bucket to forgive (it
130
164
  // predates any account), and the IP bucket is never refunded on
131
- // success (see `RateLimiter.reset`). So this is the one auth
132
- // surface where a success clears nothing at all. Bootstrap is
133
- // one-shot, so at most `max_attempts - 1` residual entries
134
- // survive — and they sit on this route's own limiter, not
135
- // login's, so a fumbled token can't spend the operator's login
136
- // budget on a deployment where their account is the only one.
165
+ // success (see `RateLimiter.reset`). Bootstrap is one-shot, so at
166
+ // most `max_attempts - 1` residual entries survive — and they sit
167
+ // on this route's own limiter, not login's.
137
168
  bootstrap_status.available = false;
138
- await create_session_and_set_cookie({
139
- keyring,
140
- deps: { db: route.db },
141
- c,
142
- account_id: result.account.id,
143
- session_options
144
- });
169
+ // the session was minted in the transaction; its cookie rides the
170
+ // success
171
+ const set_cookie = session_cookie_header(result.session_cookie_value, session_options);
172
+ const { account, actor, role_grants } = result;
145
173
  if (on_bootstrap) {
146
174
  try {
147
- await on_bootstrap(result, c);
175
+ await on_bootstrap({ account, actor, role_grants });
148
176
  }
149
177
  catch (err) {
150
178
  deps.log.error(`on_bootstrap callback failed: ${to_error_message(err)}`);
@@ -152,21 +180,15 @@ export const create_bootstrap_route_specs = (deps, options) => {
152
180
  }
153
181
  await deps.audit.emit(route, {
154
182
  event_type: 'bootstrap',
155
- actor_id: result.actor.id,
156
- account_id: result.account.id,
157
- ip: get_client_ip(c)
183
+ actor_id: actor.id,
184
+ account_id: account.id,
185
+ ip: route.client_ip
158
186
  });
159
- // CRITICAL: If token file deletion failed, throw to force operator attention.
160
- // All success work (session, on_bootstrap, audit) has completed above.
161
- // The error response alerts the operator to delete the token file manually.
162
- if (!result.token_file_deleted) {
163
- throw new Error(`Bootstrap succeeded but token file was not deleted at ${token_path}. Delete it manually and log in.`);
164
- }
165
187
  return route_ok({
166
188
  ok: true,
167
- account: { id: result.account.id, username: result.account.username },
168
- actor: { id: result.actor.id }
169
- });
189
+ account: { id: account.id, username: account.username },
190
+ actor: { id: actor.id }
191
+ }, { set_cookie: [set_cookie] });
170
192
  }
171
193
  finally {
172
194
  ip_reserved.reservation.release();
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Narrow filesystem seam for bootstrap token I/O.
3
+ *
4
+ * Bootstrap reads a one-shot token file on each request and burns it inside
5
+ * the transaction the token authorized, just before the commit. The store
6
+ * scopes to exactly those two operations so tests can swap in an in-memory
7
+ * one without reaching for a general filesystem abstraction. Twin of the Rust
8
+ * spine's `fuz_auth::BootstrapTokenStore`.
9
+ *
10
+ * @module
11
+ */
12
+ import type { FsSecureBurnDeps, FsSecureReadDeps } from '../runtime/deps.js';
13
+ import type { BurnOutcome } from '../runtime/secure_file.js';
14
+ /**
15
+ * Two-operation seam for the one-shot bootstrap token file.
16
+ *
17
+ * Implementations must not trim or normalize the bytes `read_token` returns —
18
+ * the caller strips one trailing LF and compares in constant time.
19
+ *
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.
24
+ */
25
+ export interface BootstrapTokenStore {
26
+ /** Where the token lives, named in operator log lines — never the token itself. */
27
+ readonly path: string;
28
+ /**
29
+ * Read the raw token bytes.
30
+ *
31
+ * @throws Error when the file is missing or refused
32
+ */
33
+ read_token: () => Promise<Uint8Array>;
34
+ /**
35
+ * Burn the token so it can never be presented again. Required, not
36
+ * best-effort: `bootstrap_account` calls it last inside the bootstrap
37
+ * transaction, and a throw rolls the bootstrap back
38
+ * (`token_file_undeletable`). `'already_gone'` — nothing was there — is a
39
+ * burn: the token can't be presented either way.
40
+ *
41
+ * @throws Error when the token can't be durably removed
42
+ */
43
+ burn_token: () => Promise<BurnOutcome>;
44
+ }
45
+ /**
46
+ * The production `BootstrapTokenStore`: the hardened secret read
47
+ * (`read_secure_file` — a symlinked, non-regular, group/other-readable,
48
+ * multiply-linked, or oversized file is refused, never read) and the durable
49
+ * burn (`burn_secure_file` — unlink, then fsync the directory). The read
50
+ * alone of the runtime's secure reads asks for a single link
51
+ * (`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
53
+ * Rust `FileBootstrapTokenStore`.
54
+ *
55
+ * @param deps - the runtime's secure read and burn (`create_node_runtime()` satisfies both)
56
+ * @param path - the bootstrap token file, `FUZ_BOOTSTRAP_TOKEN_PATH`
57
+ * @returns a store over the file at `path`
58
+ */
59
+ export declare const create_file_bootstrap_token_store: (deps: FsSecureReadDeps & FsSecureBurnDeps, path: string) => BootstrapTokenStore;
60
+ //# sourceMappingURL=bootstrap_token_store.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Narrow filesystem seam for bootstrap token I/O.
3
+ *
4
+ * Bootstrap reads a one-shot token file on each request and burns it inside
5
+ * the transaction the token authorized, just before the commit. The store
6
+ * scopes to exactly those two operations so tests can swap in an in-memory
7
+ * one without reaching for a general filesystem abstraction. Twin of the Rust
8
+ * spine's `fuz_auth::BootstrapTokenStore`.
9
+ *
10
+ * @module
11
+ */
12
+ /**
13
+ * The secure read's strictness for the bootstrap token: a link count of 1,
14
+ * beside the default checks, so the burn's unlink leaves no other name the
15
+ * token can still be read under. Twin of the Rust
16
+ * `BOOTSTRAP_TOKEN_READ_OPTIONS`.
17
+ */
18
+ const BOOTSTRAP_TOKEN_READ_OPTIONS = Object.freeze({
19
+ require_single_link: true
20
+ });
21
+ /**
22
+ * The production `BootstrapTokenStore`: the hardened secret read
23
+ * (`read_secure_file` — a symlinked, non-regular, group/other-readable,
24
+ * multiply-linked, or oversized file is refused, never read) and the durable
25
+ * burn (`burn_secure_file` — unlink, then fsync the directory). The read
26
+ * alone of the runtime's secure reads asks for a single link
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
29
+ * Rust `FileBootstrapTokenStore`.
30
+ *
31
+ * @param deps - the runtime's secure read and burn (`create_node_runtime()` satisfies both)
32
+ * @param path - the bootstrap token file, `FUZ_BOOTSTRAP_TOKEN_PATH`
33
+ * @returns a store over the file at `path`
34
+ */
35
+ export const create_file_bootstrap_token_store = (deps, path) => ({
36
+ path,
37
+ read_token: () => deps.read_secure_file(path, BOOTSTRAP_TOKEN_READ_OPTIONS),
38
+ burn_token: () => deps.burn_secure_file(path)
39
+ });
@@ -0,0 +1,71 @@
1
+ /**
2
+ * The grammar of the three credential headers — the session cookie in
3
+ * `Cookie`, the API token in `Authorization: Bearer`, the daemon token in
4
+ * `X-Daemon-Token` — as pure readers over header lines.
5
+ *
6
+ * One spelling per credential, the Rust spine's `fuz_auth::credential_headers`
7
+ * reading the same one: a value either reads exactly, or it is not that
8
+ * credential. Nothing is decoded, unquoted, or repaired — a lenient side
9
+ * would authenticate a request the other refuses. The shared table
10
+ * `testing/cross_backend/credential_conformance.json` holds both to the same
11
+ * rows.
12
+ *
13
+ * Each reader takes the header's lines — one field value per header line, in
14
+ * the order sent, outer SP and HTAB already stripped (`get_header_lines` of
15
+ * `http/header_lines.ts` on a request) — so "sent twice" is something a reader
16
+ * can see and decide on.
17
+ *
18
+ * Hono-free: the middleware legs call these, and so does the
19
+ * `_testing_credential_read` action.
20
+ *
21
+ * @module
22
+ */
23
+ /**
24
+ * Read the session cookie's value out of the request's `Cookie` lines.
25
+ *
26
+ * Several `Cookie` lines read as one value joined with `; ` — what Node and
27
+ * Bun hand a handler, and RFC 9113's rule for HTTP/2 cookie crumbs. The value
28
+ * is split on `;`, each pair is stripped of SP and HTAB at both ends (no other
29
+ * byte — not the U+00A0 a `0xA0` arrives as), and the first pair that begins
30
+ * with exactly `<cookie_name>=` wins. Its value is the rest of the pair,
31
+ * verbatim: not percent-decoded, not unquoted, whitespace after the `=` kept.
32
+ * A first pair that will not verify is not skipped for a later one.
33
+ *
34
+ * A pair with an empty value (`name=`) is present, and reads `''` — an
35
+ * invalid cookie to whatever verifies it, not an absent one.
36
+ *
37
+ * @param cookie_lines - the `Cookie` header's lines
38
+ * @param cookie_name - the session cookie's name
39
+ * @returns the cookie's value as sent, or `null` when no pair names it
40
+ */
41
+ export declare const read_session_cookie_value: (cookie_lines: ReadonlyArray<string>, cookie_name: string) => string | null;
42
+ /**
43
+ * Read the API token out of the request's `Authorization` lines.
44
+ *
45
+ * The header must be exactly one line: the scheme `Bearer` in any ASCII case,
46
+ * one SP, and a value `is_api_token_shaped` accepts — nothing before, between,
47
+ * or after. A header sent twice is discarded whatever its lines hold, never
48
+ * resolved to one of them.
49
+ *
50
+ * A runtime that shows no per-line view (`get_header_lines`) hands repeated
51
+ * lines over as one, joined with `, `. No token holds a comma, so the join
52
+ * fails the shape and is discarded as the repeat it is; a lone line that
53
+ * happens to hold `, ` reads the same on both spines.
54
+ *
55
+ * @param authorization_lines - the `Authorization` header's lines
56
+ * @returns the token to look up, or `null` when the header carries none
57
+ */
58
+ export declare const read_bearer_token: (authorization_lines: ReadonlyArray<string>) => string | null;
59
+ /**
60
+ * Read the daemon token out of the request's `X-Daemon-Token` lines.
61
+ *
62
+ * The header must be exactly one line holding a value
63
+ * `is_daemon_token_shaped` accepts. A header sent twice is discarded — an
64
+ * empty second line included — and, as for `read_bearer_token`, a join with
65
+ * `, ` fails the shape.
66
+ *
67
+ * @param daemon_token_lines - the `X-Daemon-Token` header's lines
68
+ * @returns the token to compare, or `null` when the header carries none
69
+ */
70
+ export declare const read_daemon_token: (daemon_token_lines: ReadonlyArray<string>) => string | null;
71
+ //# sourceMappingURL=credential_headers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credential_headers.d.ts","sourceRoot":"","sources":["../../src/lib/auth/credential_headers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AASH;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,yBAAyB,GACrC,cAAc,aAAa,CAAC,MAAM,CAAC,EACnC,aAAa,MAAM,KACjB,MAAM,GAAG,IAWX,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,iBAAiB,GAAI,qBAAqB,aAAa,CAAC,MAAM,CAAC,KAAG,MAAM,GAAG,IAMvF,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,GAAI,oBAAoB,aAAa,CAAC,MAAM,CAAC,KAAG,MAAM,GAAG,IAItF,CAAC"}