@fuzdev/fuz_app 0.180.0 → 0.181.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 (358) hide show
  1. package/dist/actions/CLAUDE.md +14 -14
  2. package/dist/actions/action_rpc.d.ts +14 -5
  3. package/dist/actions/action_rpc.d.ts.map +1 -1
  4. package/dist/actions/action_rpc.js +53 -46
  5. package/dist/actions/action_types.d.ts +15 -12
  6. package/dist/actions/action_types.d.ts.map +1 -1
  7. package/dist/actions/perform_action.d.ts +4 -4
  8. package/dist/actions/perform_action.d.ts.map +1 -1
  9. package/dist/actions/perform_action.js +6 -6
  10. package/dist/actions/register_action_ws.d.ts +6 -2
  11. package/dist/actions/register_action_ws.d.ts.map +1 -1
  12. package/dist/actions/register_action_ws.js +14 -3
  13. package/dist/actions/ws_socket_session.js +1 -1
  14. package/dist/auth/CLAUDE.md +36 -30
  15. package/dist/auth/account_actions.d.ts.map +1 -1
  16. package/dist/auth/account_actions.js +18 -1
  17. package/dist/auth/account_queries.d.ts +69 -0
  18. package/dist/auth/account_queries.d.ts.map +1 -1
  19. package/dist/auth/account_queries.js +82 -0
  20. package/dist/auth/account_route_schema.d.ts +26 -16
  21. package/dist/auth/account_route_schema.d.ts.map +1 -1
  22. package/dist/auth/account_route_schema.js +10 -24
  23. package/dist/auth/account_routes.d.ts +4 -6
  24. package/dist/auth/account_routes.d.ts.map +1 -1
  25. package/dist/auth/account_routes.js +86 -66
  26. package/dist/auth/admin_actions.d.ts.map +1 -1
  27. package/dist/auth/admin_actions.js +63 -14
  28. package/dist/auth/api_token_queries.d.ts +16 -7
  29. package/dist/auth/api_token_queries.d.ts.map +1 -1
  30. package/dist/auth/api_token_queries.js +18 -18
  31. package/dist/auth/audit_log_route_schema.d.ts +1 -1
  32. package/dist/auth/audit_log_route_schema.d.ts.map +1 -1
  33. package/dist/auth/audit_log_routes.d.ts +1 -1
  34. package/dist/auth/audit_log_routes.d.ts.map +1 -1
  35. package/dist/auth/audit_log_routes.js +10 -12
  36. package/dist/auth/audit_log_schema.js +4 -4
  37. package/dist/auth/bearer_auth.d.ts +4 -3
  38. package/dist/auth/bearer_auth.d.ts.map +1 -1
  39. package/dist/auth/bearer_auth.js +35 -31
  40. package/dist/auth/bootstrap_account.d.ts +65 -37
  41. package/dist/auth/bootstrap_account.d.ts.map +1 -1
  42. package/dist/auth/bootstrap_account.js +115 -66
  43. package/dist/auth/bootstrap_route_schema.d.ts +6 -2
  44. package/dist/auth/bootstrap_route_schema.d.ts.map +1 -1
  45. package/dist/auth/bootstrap_route_schema.js +7 -2
  46. package/dist/auth/bootstrap_routes.d.ts +50 -33
  47. package/dist/auth/bootstrap_routes.d.ts.map +1 -1
  48. package/dist/auth/bootstrap_routes.js +109 -87
  49. package/dist/auth/bootstrap_token_store.d.ts +60 -0
  50. package/dist/auth/bootstrap_token_store.d.ts.map +1 -0
  51. package/dist/auth/bootstrap_token_store.js +39 -0
  52. package/dist/auth/credential_headers.d.ts +71 -0
  53. package/dist/auth/credential_headers.d.ts.map +1 -0
  54. package/dist/auth/credential_headers.js +100 -0
  55. package/dist/auth/daemon_token.d.ts +13 -1
  56. package/dist/auth/daemon_token.d.ts.map +1 -1
  57. package/dist/auth/daemon_token.js +14 -2
  58. package/dist/auth/daemon_token_middleware.d.ts +10 -11
  59. package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
  60. package/dist/auth/daemon_token_middleware.js +27 -29
  61. package/dist/auth/deps.d.ts +0 -11
  62. package/dist/auth/deps.d.ts.map +1 -1
  63. package/dist/auth/invite_queries.d.ts +18 -0
  64. package/dist/auth/invite_queries.d.ts.map +1 -1
  65. package/dist/auth/invite_queries.js +24 -0
  66. package/dist/auth/request_context.d.ts +26 -5
  67. package/dist/auth/request_context.d.ts.map +1 -1
  68. package/dist/auth/request_context.js +17 -10
  69. package/dist/auth/role_grant_offer_action_specs.d.ts +1 -1
  70. package/dist/auth/role_grant_offer_action_specs.d.ts.map +1 -1
  71. package/dist/auth/role_grant_offer_action_specs.js +3 -2
  72. package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
  73. package/dist/auth/role_grant_offer_actions.js +37 -14
  74. package/dist/auth/role_grant_offer_ddl.d.ts +7 -1
  75. package/dist/auth/role_grant_offer_ddl.d.ts.map +1 -1
  76. package/dist/auth/role_grant_offer_ddl.js +9 -2
  77. package/dist/auth/role_grant_offer_queries.d.ts +56 -3
  78. package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
  79. package/dist/auth/role_grant_offer_queries.js +93 -8
  80. package/dist/auth/role_grant_queries.d.ts +7 -0
  81. package/dist/auth/role_grant_queries.d.ts.map +1 -1
  82. package/dist/auth/role_grant_queries.js +8 -0
  83. package/dist/auth/session_cookie.d.ts +105 -25
  84. package/dist/auth/session_cookie.d.ts.map +1 -1
  85. package/dist/auth/session_cookie.js +124 -15
  86. package/dist/auth/session_middleware.d.ts +83 -54
  87. package/dist/auth/session_middleware.d.ts.map +1 -1
  88. package/dist/auth/session_middleware.js +92 -66
  89. package/dist/auth/session_queries.d.ts +64 -4
  90. package/dist/auth/session_queries.d.ts.map +1 -1
  91. package/dist/auth/session_queries.js +53 -4
  92. package/dist/auth/signup_route_schema.d.ts +5 -5
  93. package/dist/auth/signup_route_schema.d.ts.map +1 -1
  94. package/dist/auth/signup_route_schema.js +4 -4
  95. package/dist/auth/signup_routes.d.ts.map +1 -1
  96. package/dist/auth/signup_routes.js +17 -14
  97. package/dist/auth/token_scope.d.ts +5 -7
  98. package/dist/auth/token_scope.d.ts.map +1 -1
  99. package/dist/auth/token_scope.js +5 -8
  100. package/dist/dev/setup.d.ts +6 -1
  101. package/dist/dev/setup.d.ts.map +1 -1
  102. package/dist/dev/setup.js +42 -34
  103. package/dist/hono_context.d.ts +21 -0
  104. package/dist/hono_context.d.ts.map +1 -1
  105. package/dist/hono_context.js +17 -0
  106. package/dist/http/CLAUDE.md +150 -43
  107. package/dist/http/auth_shape.d.ts +3 -3
  108. package/dist/http/common_routes.js +1 -1
  109. package/dist/http/db_routes.d.ts +4 -3
  110. package/dist/http/db_routes.d.ts.map +1 -1
  111. package/dist/http/db_routes.js +14 -14
  112. package/dist/http/dev_route_error_check.d.ts +6 -3
  113. package/dist/http/dev_route_error_check.d.ts.map +1 -1
  114. package/dist/http/dev_route_error_check.js +6 -3
  115. package/dist/http/dev_set_cookie_check.d.ts +53 -0
  116. package/dist/http/dev_set_cookie_check.d.ts.map +1 -0
  117. package/dist/http/dev_set_cookie_check.js +80 -0
  118. package/dist/http/error_schemas.d.ts +36 -1
  119. package/dist/http/error_schemas.d.ts.map +1 -1
  120. package/dist/http/error_schemas.js +39 -2
  121. package/dist/http/header_lines.d.ts +42 -0
  122. package/dist/http/header_lines.d.ts.map +1 -0
  123. package/dist/http/header_lines.js +80 -0
  124. package/dist/http/host.d.ts +12 -9
  125. package/dist/http/host.d.ts.map +1 -1
  126. package/dist/http/host.js +25 -20
  127. package/dist/http/origin.d.ts +7 -22
  128. package/dist/http/origin.d.ts.map +1 -1
  129. package/dist/http/origin.js +11 -25
  130. package/dist/http/proxy.d.ts +1 -0
  131. package/dist/http/proxy.d.ts.map +1 -1
  132. package/dist/http/proxy.js +3 -0
  133. package/dist/http/request_headers.d.ts +95 -0
  134. package/dist/http/request_headers.d.ts.map +1 -0
  135. package/dist/http/request_headers.js +110 -0
  136. package/dist/http/request_target.d.ts +134 -0
  137. package/dist/http/request_target.d.ts.map +1 -0
  138. package/dist/http/request_target.js +193 -0
  139. package/dist/http/route_error_check.d.ts +4 -11
  140. package/dist/http/route_error_check.d.ts.map +1 -1
  141. package/dist/http/route_error_check.js +4 -21
  142. package/dist/http/route_result.d.ts +127 -23
  143. package/dist/http/route_result.d.ts.map +1 -1
  144. package/dist/http/route_result.js +97 -19
  145. package/dist/http/route_spec.d.ts +298 -82
  146. package/dist/http/route_spec.d.ts.map +1 -1
  147. package/dist/http/route_spec.js +548 -71
  148. package/dist/http/simple_request.d.ts +19 -14
  149. package/dist/http/simple_request.d.ts.map +1 -1
  150. package/dist/http/simple_request.js +17 -29
  151. package/dist/http/surface.d.ts +2 -0
  152. package/dist/http/surface.d.ts.map +1 -1
  153. package/dist/http/surface.js +4 -1
  154. package/dist/realtime/outbound_budget.d.ts +1 -2
  155. package/dist/realtime/outbound_budget.d.ts.map +1 -1
  156. package/dist/realtime/outbound_budget.js +1 -2
  157. package/dist/realtime/sse.d.ts +47 -17
  158. package/dist/realtime/sse.d.ts.map +1 -1
  159. package/dist/realtime/sse.js +115 -93
  160. package/dist/realtime/sse_constants.d.ts +7 -1
  161. package/dist/realtime/sse_constants.d.ts.map +1 -1
  162. package/dist/realtime/sse_constants.js +12 -1
  163. package/dist/realtime/sse_registry.d.ts +3 -3
  164. package/dist/realtime/sse_registry.js +3 -3
  165. package/dist/runtime/deps.d.ts +20 -4
  166. package/dist/runtime/deps.d.ts.map +1 -1
  167. package/dist/runtime/mock.d.ts +7 -1
  168. package/dist/runtime/mock.d.ts.map +1 -1
  169. package/dist/runtime/mock.js +33 -3
  170. package/dist/runtime/node.d.ts.map +1 -1
  171. package/dist/runtime/node.js +2 -1
  172. package/dist/runtime/secure_file.d.ts +71 -10
  173. package/dist/runtime/secure_file.d.ts.map +1 -1
  174. package/dist/runtime/secure_file.js +91 -11
  175. package/dist/server/app_backend.d.ts +0 -8
  176. package/dist/server/app_backend.d.ts.map +1 -1
  177. package/dist/server/app_backend.js +1 -3
  178. package/dist/server/app_server.d.ts +28 -17
  179. package/dist/server/app_server.d.ts.map +1 -1
  180. package/dist/server/app_server.js +52 -34
  181. package/dist/server/serve_fact_route.d.ts.map +1 -1
  182. package/dist/server/serve_fact_route.js +49 -45
  183. package/dist/server/static.d.ts +20 -0
  184. package/dist/server/static.d.ts.map +1 -1
  185. package/dist/server/static.js +56 -8
  186. package/dist/server/unmatched_route.d.ts +42 -0
  187. package/dist/server/unmatched_route.d.ts.map +1 -0
  188. package/dist/server/unmatched_route.js +64 -0
  189. package/dist/testing/CLAUDE.md +404 -1200
  190. package/dist/testing/app_server.d.ts +3 -1
  191. package/dist/testing/app_server.d.ts.map +1 -1
  192. package/dist/testing/app_server.js +4 -10
  193. package/dist/testing/auth_apps.d.ts.map +1 -1
  194. package/dist/testing/auth_apps.js +2 -1
  195. package/dist/testing/cross_backend/account_lifecycle.d.ts +11 -4
  196. package/dist/testing/cross_backend/account_lifecycle.d.ts.map +1 -1
  197. package/dist/testing/cross_backend/account_lifecycle.js +277 -6
  198. package/dist/testing/cross_backend/build_test_backend_paths.d.ts +4 -1
  199. package/dist/testing/cross_backend/build_test_backend_paths.d.ts.map +1 -1
  200. package/dist/testing/cross_backend/build_test_backend_paths.js +1 -1
  201. package/dist/testing/cross_backend/capabilities.d.ts +68 -5
  202. package/dist/testing/cross_backend/capabilities.d.ts.map +1 -1
  203. package/dist/testing/cross_backend/capabilities.js +20 -4
  204. package/dist/testing/cross_backend/cell_gated_create.js +1 -1
  205. package/dist/testing/cross_backend/conformance_case.d.ts +63 -21
  206. package/dist/testing/cross_backend/conformance_case.d.ts.map +1 -1
  207. package/dist/testing/cross_backend/conformance_table.d.ts +54 -12
  208. package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
  209. package/dist/testing/cross_backend/conformance_table.js +179 -23
  210. package/dist/testing/cross_backend/cookie_attributes.js +1 -1
  211. package/dist/testing/cross_backend/create_dual_spawn_global_setup.d.ts +7 -1
  212. package/dist/testing/cross_backend/create_dual_spawn_global_setup.d.ts.map +1 -1
  213. package/dist/testing/cross_backend/create_dual_spawn_global_setup.js +3 -3
  214. package/dist/testing/cross_backend/credential_conformance.d.ts +196 -0
  215. package/dist/testing/cross_backend/credential_conformance.d.ts.map +1 -0
  216. package/dist/testing/cross_backend/credential_conformance.js +296 -0
  217. package/dist/testing/cross_backend/credential_conformance.json +1284 -0
  218. package/dist/testing/cross_backend/credential_conformance_wire.d.ts +40 -0
  219. package/dist/testing/cross_backend/credential_conformance_wire.d.ts.map +1 -0
  220. package/dist/testing/cross_backend/credential_conformance_wire.js +293 -0
  221. package/dist/testing/cross_backend/credential_header_robustness.d.ts +1 -3
  222. package/dist/testing/cross_backend/credential_header_robustness.d.ts.map +1 -1
  223. package/dist/testing/cross_backend/credential_header_robustness.js +24 -55
  224. package/dist/testing/cross_backend/credential_wire.d.ts +112 -0
  225. package/dist/testing/cross_backend/credential_wire.d.ts.map +1 -0
  226. package/dist/testing/cross_backend/credential_wire.js +188 -0
  227. package/dist/testing/cross_backend/default_backend_configs.d.ts.map +1 -1
  228. package/dist/testing/cross_backend/default_backend_configs.js +22 -2
  229. package/dist/testing/cross_backend/default_spine_surface.js +1 -1
  230. package/dist/testing/cross_backend/differential.d.ts +1 -1
  231. package/dist/testing/cross_backend/differential.d.ts.map +1 -1
  232. package/dist/testing/cross_backend/differential.js +3 -2
  233. package/dist/testing/cross_backend/differential_normalize.d.ts +23 -6
  234. package/dist/testing/cross_backend/differential_normalize.d.ts.map +1 -1
  235. package/dist/testing/cross_backend/differential_normalize.js +11 -5
  236. package/dist/testing/cross_backend/full_spine_mount.d.ts +1 -0
  237. package/dist/testing/cross_backend/full_spine_mount.d.ts.map +1 -1
  238. package/dist/testing/cross_backend/full_spine_mount.js +7 -0
  239. package/dist/testing/cross_backend/identity_parity.d.ts.map +1 -1
  240. package/dist/testing/cross_backend/identity_parity.js +4 -0
  241. package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
  242. package/dist/testing/cross_backend/in_process_setup.js +78 -4
  243. package/dist/testing/cross_backend/login_security.d.ts.map +1 -1
  244. package/dist/testing/cross_backend/login_security.js +13 -10
  245. package/dist/testing/cross_backend/peer_ping_ws.d.ts +1 -1
  246. package/dist/testing/cross_backend/peer_ping_ws.js +2 -2
  247. package/dist/testing/cross_backend/request_header_conformance.d.ts +174 -0
  248. package/dist/testing/cross_backend/request_header_conformance.d.ts.map +1 -0
  249. package/dist/testing/cross_backend/request_header_conformance.js +196 -0
  250. package/dist/testing/cross_backend/request_header_conformance.json +1158 -0
  251. package/dist/testing/cross_backend/request_header_conformance_wire.d.ts +39 -0
  252. package/dist/testing/cross_backend/request_header_conformance_wire.d.ts.map +1 -0
  253. package/dist/testing/cross_backend/request_header_conformance_wire.js +284 -0
  254. package/dist/testing/cross_backend/request_target_conformance.d.ts +298 -0
  255. package/dist/testing/cross_backend/request_target_conformance.d.ts.map +1 -0
  256. package/dist/testing/cross_backend/request_target_conformance.js +186 -0
  257. package/dist/testing/cross_backend/request_target_conformance.json +3765 -0
  258. package/dist/testing/cross_backend/request_target_conformance_wire.d.ts +32 -0
  259. package/dist/testing/cross_backend/request_target_conformance_wire.d.ts.map +1 -0
  260. package/dist/testing/cross_backend/request_target_conformance_wire.js +278 -0
  261. package/dist/testing/cross_backend/role_grant_offer_lifecycle.d.ts.map +1 -1
  262. package/dist/testing/cross_backend/role_grant_offer_lifecycle.js +173 -1
  263. package/dist/testing/cross_backend/role_grant_offer_notification_ws.d.ts.map +1 -1
  264. package/dist/testing/cross_backend/role_grant_offer_notification_ws.js +2 -1
  265. package/dist/testing/cross_backend/rpc_adversarial.d.ts +6 -4
  266. package/dist/testing/cross_backend/rpc_adversarial.d.ts.map +1 -1
  267. package/dist/testing/cross_backend/rpc_adversarial.js +5 -2
  268. package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +6 -7
  269. package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
  270. package/dist/testing/cross_backend/rust_spine_consumer_surface.js +4 -5
  271. package/dist/testing/cross_backend/session_cap.d.ts.map +1 -1
  272. package/dist/testing/cross_backend/session_cap.js +56 -29
  273. package/dist/testing/cross_backend/session_cookie_effect.d.ts +43 -0
  274. package/dist/testing/cross_backend/session_cookie_effect.d.ts.map +1 -0
  275. package/dist/testing/cross_backend/session_cookie_effect.js +103 -0
  276. package/dist/testing/cross_backend/session_login.d.ts +24 -0
  277. package/dist/testing/cross_backend/session_login.d.ts.map +1 -0
  278. package/dist/testing/cross_backend/session_login.js +31 -0
  279. package/dist/testing/cross_backend/setup.d.ts +117 -0
  280. package/dist/testing/cross_backend/setup.d.ts.map +1 -1
  281. package/dist/testing/cross_backend/setup.js +193 -9
  282. package/dist/testing/cross_backend/simple_request.d.ts.map +1 -1
  283. package/dist/testing/cross_backend/simple_request.js +5 -0
  284. package/dist/testing/cross_backend/spine_suites.d.ts +9 -1
  285. package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
  286. package/dist/testing/cross_backend/spine_suites.js +88 -5
  287. package/dist/testing/cross_backend/spine_surface_constants.d.ts +1 -1
  288. package/dist/testing/cross_backend/spine_surface_constants.d.ts.map +1 -1
  289. package/dist/testing/cross_backend/spine_surface_constants.js +1 -0
  290. package/dist/testing/cross_backend/sse_round_trip.d.ts +8 -5
  291. package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
  292. package/dist/testing/cross_backend/sse_round_trip.js +205 -64
  293. package/dist/testing/cross_backend/testing_backdoor.d.ts.map +1 -1
  294. package/dist/testing/cross_backend/testing_backdoor.js +5 -2
  295. package/dist/testing/cross_backend/testing_credential_read.d.ts +165 -0
  296. package/dist/testing/cross_backend/testing_credential_read.d.ts.map +1 -0
  297. package/dist/testing/cross_backend/testing_credential_read.js +175 -0
  298. package/dist/testing/cross_backend/testing_reset_actions.d.ts +19 -0
  299. package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
  300. package/dist/testing/cross_backend/testing_reset_actions.js +22 -6
  301. package/dist/testing/cross_backend/token_lifetime.d.ts.map +1 -1
  302. package/dist/testing/cross_backend/token_lifetime.js +58 -2
  303. package/dist/testing/cross_backend/transport_composition.d.ts +2 -4
  304. package/dist/testing/cross_backend/transport_composition.d.ts.map +1 -1
  305. package/dist/testing/cross_backend/transport_composition.js +13 -10
  306. package/dist/testing/cross_backend/ts_spine_backend_config.d.ts.map +1 -1
  307. package/dist/testing/cross_backend/ts_spine_backend_config.js +5 -3
  308. package/dist/testing/cross_backend/ws_endpoint.d.ts +11 -1
  309. package/dist/testing/cross_backend/ws_endpoint.d.ts.map +1 -1
  310. package/dist/testing/cross_backend/ws_endpoint.js +19 -2
  311. package/dist/testing/cross_backend/ws_role_gated.d.ts.map +1 -1
  312. package/dist/testing/cross_backend/ws_role_gated.js +2 -3
  313. package/dist/testing/cross_backend/ws_round_trip.d.ts.map +1 -1
  314. package/dist/testing/cross_backend/ws_round_trip.js +28 -12
  315. package/dist/testing/cross_backend/xfail.d.ts +44 -11
  316. package/dist/testing/cross_backend/xfail.d.ts.map +1 -1
  317. package/dist/testing/cross_backend/xfail.js +68 -23
  318. package/dist/testing/data_exposure.d.ts.map +1 -1
  319. package/dist/testing/data_exposure.js +4 -3
  320. package/dist/testing/integration.d.ts +1 -2
  321. package/dist/testing/integration.d.ts.map +1 -1
  322. package/dist/testing/integration.js +14 -8
  323. package/dist/testing/integration_helpers.d.ts +50 -3
  324. package/dist/testing/integration_helpers.d.ts.map +1 -1
  325. package/dist/testing/integration_helpers.js +87 -9
  326. package/dist/testing/middleware.d.ts +2 -0
  327. package/dist/testing/middleware.d.ts.map +1 -1
  328. package/dist/testing/middleware.js +9 -2
  329. package/dist/testing/round_trip.d.ts +6 -2
  330. package/dist/testing/round_trip.d.ts.map +1 -1
  331. package/dist/testing/round_trip.js +17 -6
  332. package/dist/testing/rpc_envelope_cases.d.ts.map +1 -1
  333. package/dist/testing/rpc_envelope_cases.js +7 -0
  334. package/dist/testing/rpc_helpers.d.ts +4 -2
  335. package/dist/testing/rpc_helpers.d.ts.map +1 -1
  336. package/dist/testing/rpc_helpers.js +6 -1
  337. package/dist/testing/rpc_round_trip.d.ts +13 -2
  338. package/dist/testing/rpc_round_trip.d.ts.map +1 -1
  339. package/dist/testing/rpc_round_trip.js +25 -6
  340. package/dist/testing/schema_generators.d.ts +2 -2
  341. package/dist/testing/schema_generators.d.ts.map +1 -1
  342. package/dist/testing/schema_generators.js +4 -4
  343. package/dist/testing/stubs.d.ts +2 -2
  344. package/dist/testing/stubs.d.ts.map +1 -1
  345. package/dist/testing/stubs.js +8 -8
  346. package/dist/testing/transports/fetch_transport.d.ts +6 -3
  347. package/dist/testing/transports/fetch_transport.d.ts.map +1 -1
  348. package/dist/testing/transports/fetch_transport.js +31 -19
  349. package/dist/testing/transports/raw_http.d.ts +61 -1
  350. package/dist/testing/transports/raw_http.d.ts.map +1 -1
  351. package/dist/testing/transports/raw_http.js +61 -1
  352. package/dist/testing/transports/ws_raw_client.d.ts +20 -0
  353. package/dist/testing/transports/ws_raw_client.d.ts.map +1 -1
  354. package/dist/testing/transports/ws_raw_client.js +10 -4
  355. package/dist/testing/transports/ws_transport.d.ts +21 -1
  356. package/dist/testing/transports/ws_transport.d.ts.map +1 -1
  357. package/dist/testing/transports/ws_transport.js +58 -20
  358. package/package.json +1 -1
@@ -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"}
@@ -0,0 +1,100 @@
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
+ import { trim_optional_whitespace } from '../http/header_lines.js';
24
+ import { is_api_token_shaped } from './api_token.js';
25
+ import { is_daemon_token_shaped } from './daemon_token.js';
26
+ /** The `Authorization` scheme of an API token, with the one SP that follows it. */
27
+ const BEARER_PREFIX = 'bearer ';
28
+ /**
29
+ * Read the session cookie's value out of the request's `Cookie` lines.
30
+ *
31
+ * Several `Cookie` lines read as one value joined with `; ` — what Node and
32
+ * Bun hand a handler, and RFC 9113's rule for HTTP/2 cookie crumbs. The value
33
+ * is split on `;`, each pair is stripped of SP and HTAB at both ends (no other
34
+ * byte — not the U+00A0 a `0xA0` arrives as), and the first pair that begins
35
+ * with exactly `<cookie_name>=` wins. Its value is the rest of the pair,
36
+ * verbatim: not percent-decoded, not unquoted, whitespace after the `=` kept.
37
+ * A first pair that will not verify is not skipped for a later one.
38
+ *
39
+ * A pair with an empty value (`name=`) is present, and reads `''` — an
40
+ * invalid cookie to whatever verifies it, not an absent one.
41
+ *
42
+ * @param cookie_lines - the `Cookie` header's lines
43
+ * @param cookie_name - the session cookie's name
44
+ * @returns the cookie's value as sent, or `null` when no pair names it
45
+ */
46
+ export const read_session_cookie_value = (cookie_lines, cookie_name) => {
47
+ const prefix = `${cookie_name}=`;
48
+ // walking the lines in order is reading their `; ` join: the separator
49
+ // holds the `;` the split is on
50
+ for (const line of cookie_lines) {
51
+ for (const part of line.split(';')) {
52
+ const pair = trim_optional_whitespace(part);
53
+ if (pair.startsWith(prefix))
54
+ return pair.slice(prefix.length);
55
+ }
56
+ }
57
+ return null;
58
+ };
59
+ /**
60
+ * Read the API token out of the request's `Authorization` lines.
61
+ *
62
+ * The header must be exactly one line: the scheme `Bearer` in any ASCII case,
63
+ * one SP, and a value `is_api_token_shaped` accepts — nothing before, between,
64
+ * or after. A header sent twice is discarded whatever its lines hold, never
65
+ * resolved to one of them.
66
+ *
67
+ * A runtime that shows no per-line view (`get_header_lines`) hands repeated
68
+ * lines over as one, joined with `, `. No token holds a comma, so the join
69
+ * fails the shape and is discarded as the repeat it is; a lone line that
70
+ * happens to hold `, ` reads the same on both spines.
71
+ *
72
+ * @param authorization_lines - the `Authorization` header's lines
73
+ * @returns the token to look up, or `null` when the header carries none
74
+ */
75
+ export const read_bearer_token = (authorization_lines) => {
76
+ if (authorization_lines.length !== 1)
77
+ return null;
78
+ const value = authorization_lines[0];
79
+ if (value.slice(0, BEARER_PREFIX.length).toLowerCase() !== BEARER_PREFIX)
80
+ return null;
81
+ const token = value.slice(BEARER_PREFIX.length);
82
+ return is_api_token_shaped(token) ? token : null;
83
+ };
84
+ /**
85
+ * Read the daemon token out of the request's `X-Daemon-Token` lines.
86
+ *
87
+ * The header must be exactly one line holding a value
88
+ * `is_daemon_token_shaped` accepts. A header sent twice is discarded — an
89
+ * empty second line included — and, as for `read_bearer_token`, a join with
90
+ * `, ` fails the shape.
91
+ *
92
+ * @param daemon_token_lines - the `X-Daemon-Token` header's lines
93
+ * @returns the token to compare, or `null` when the header carries none
94
+ */
95
+ export const read_daemon_token = (daemon_token_lines) => {
96
+ if (daemon_token_lines.length !== 1)
97
+ return null;
98
+ const value = daemon_token_lines[0];
99
+ return is_daemon_token_shaped(value) ? value : null;
100
+ };
@@ -8,7 +8,19 @@
8
8
  * @module
9
9
  */
10
10
  import { type Infer } from '@fuzdev/fuz_schema/schema.ts';
11
- /** Daemon token format, a `@fuzdev/fuz_schema` schema: 43 base64url characters (256 bits). */
11
+ /** Regex for a daemon token: exactly 43 base64url characters (256 bits). */
12
+ export declare const DAEMON_TOKEN_REGEX: RegExp;
13
+ /**
14
+ * Whether `raw` has the shape of a daemon token — the daemon leg's precheck,
15
+ * ahead of the constant-time compare, so an off-form value is discarded
16
+ * without one. A `true` says nothing about whether the token is the current
17
+ * one. Twin of the Rust spine's `is_daemon_token_shaped`.
18
+ *
19
+ * @param raw - the value of an `X-Daemon-Token` line
20
+ * @returns `true` when `raw` matches `DAEMON_TOKEN_REGEX`
21
+ */
22
+ export declare const is_daemon_token_shaped: (raw: string) => boolean;
23
+ /** Daemon token format, a `@fuzdev/fuz_schema` schema over `DAEMON_TOKEN_REGEX`. */
12
24
  export declare const DaemonToken: import("@fuzdev/fuz_schema/schema.ts").PipeSchema<string, import("@fuzdev/fuz_schema/schema.ts").StringSchema>;
13
25
  export type DaemonToken = Infer<typeof DaemonToken>;
14
26
  /** The `X-Daemon-Token` header name. */
@@ -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,8FAA8F;AAC9F,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,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"}
@@ -10,8 +10,20 @@
10
10
  import { timingSafeEqual } from 'node:crypto';
11
11
  import { message, pipe, regex, string } from '@fuzdev/fuz_schema/schema.ts';
12
12
  import { generate_random_base64url } from '../crypto.js';
13
- /** Daemon token format, a `@fuzdev/fuz_schema` schema: 43 base64url characters (256 bits). */
14
- export const DaemonToken = pipe(string, message(regex(/^[A-Za-z0-9_-]{43}$/), 'Invalid daemon token format'));
13
+ /** Regex for a daemon token: exactly 43 base64url characters (256 bits). */
14
+ export const DAEMON_TOKEN_REGEX = /^[A-Za-z0-9_-]{43}$/;
15
+ /**
16
+ * Whether `raw` has the shape of a daemon token — the daemon leg's precheck,
17
+ * ahead of the constant-time compare, so an off-form value is discarded
18
+ * without one. A `true` says nothing about whether the token is the current
19
+ * one. Twin of the Rust spine's `is_daemon_token_shaped`.
20
+ *
21
+ * @param raw - the value of an `X-Daemon-Token` line
22
+ * @returns `true` when `raw` matches `DAEMON_TOKEN_REGEX`
23
+ */
24
+ export const is_daemon_token_shaped = (raw) => DAEMON_TOKEN_REGEX.test(raw);
25
+ /** Daemon token format, a `@fuzdev/fuz_schema` schema over `DAEMON_TOKEN_REGEX`. */
26
+ export const DaemonToken = pipe(string, message(regex(DAEMON_TOKEN_REGEX), 'Invalid daemon token format'));
15
27
  /** The `X-Daemon-Token` header name. */
16
28
  export const DAEMON_TOKEN_HEADER = 'X-Daemon-Token';
17
29
  /**
@@ -41,19 +41,18 @@ export declare const resolve_keeper_account_id: (deps: QueryDeps) => Promise<str
41
41
  * `RESOLVED_AUTH_KEY` on entry, so a layer mounted before the credential legs
42
42
  * cannot pre-set an identity that every leg would then skip past.
43
43
  *
44
- * Checks the `X-Daemon-Token` header. Behavior:
45
- * - No header: pass through.
46
- * - Header present + `Origin` / `Referer` present: discard the credential
44
+ * Reads the `X-Daemon-Token` header's lines through `read_daemon_token`.
45
+ * Behavior:
46
+ * - No header, a malformed value (fails `is_daemon_token_shaped`), or the
47
+ * header sent as more than one line: soft-fail discard (pass through, not
48
+ * 401) — mirrors the bearer guard and the Rust spine's `resolve.rs`
49
+ * (`None`). Downstream a daemon-gated action returns
50
+ * `credential_type_required`; a public action proceeds anonymous.
51
+ * - A shaped token + `Origin` / `Referer` present: discard the credential
47
52
  * (browser context) and pass through — daemon tokens are loopback-only and
48
53
  * never carry an `Origin` in production, so a header-bearing request is not
49
- * a legitimate daemon caller. Mirrors the bearer guard: `next()` rather than
50
- * 401, so downstream auth enforcement returns `credential_type_required`
51
- * (not a hard fail). Silent on the wire (anti-enumeration); in `DEV` only,
52
- * sets `X-Fuz-Auth-Debug: daemon_token_discarded_browser_context`.
53
- * - Header present + malformed (fails `DaemonToken`): soft-fail discard (pass through,
54
- * not 401) — mirrors the bearer guard and the Rust spine's `resolve.rs`
55
- * (`None`). Downstream a daemon-gated action returns `credential_type_required`;
56
- * a public action proceeds anonymous.
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
56
  * - Header present + invalid value (not the current/previous token): soft-fail
58
57
  * discard (pass through, not 401) — same downstream behavior.
59
58
  * - Header present + valid + `keeper_account_id` null (still pre-bootstrap