@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
@@ -21,24 +21,9 @@
21
21
  import { escape_regexp } from '@fuzdev/fuz_util/regexp.ts';
22
22
  import { one_of } from '@fuzdev/fuz_schema/schema.ts';
23
23
  import { ERROR_FORBIDDEN_ORIGIN } from './error_schemas.js';
24
+ import { get_header_lines } from './header_lines.js';
25
+ import { read_origin } from './request_headers.js';
24
26
  import { middleware_applies } from './schema_helpers.js';
25
- /**
26
- * True when the request looks like it originated from a browser context — it
27
- * carries an `Origin` or `Referer` header. Browsers attach these
28
- * automatically on the state-changing surface; loopback / CLI clients don't.
29
- * Uses `!== undefined` so an empty-string header still counts as browser
30
- * context. Checks `Referer` too (not just `Origin`) because some browser
31
- * requests send only `Referer`. Twin of the Rust spine's
32
- * `bearer_auth::is_browser_context`.
33
- *
34
- * The bearer (`auth/bearer_auth.ts`) and daemon-token
35
- * (`auth/daemon_token_middleware.ts`) middleware both silently discard their
36
- * credential when this is true: a stolen bearer token can't be replayed from a
37
- * browser, and the loopback daemon token never legitimately carries an
38
- * `Origin`. Distinct from `verify_request_source` — that gates browser
39
- * requests against an allowlist; this only detects browser context.
40
- */
41
- export const is_browser_context = (c) => c.req.header('Origin') !== undefined || c.req.header('Referer') !== undefined;
42
27
  /**
43
28
  * Why one allowlist entry was refused, a `@fuzdev/fuz_schema` `one_of` whose
44
29
  * `def` is the names. The wire names both spines emit — the Rust spine's
@@ -206,11 +191,13 @@ export const should_allow_origin = (origin, allowed_patterns) => VISIBLE_ASCII.t
206
191
  *
207
192
  * Origin allowlisting (not the CSRF layer — that's `SameSite: strict` cookies
208
193
  * plus `http/simple_request.ts`):
209
- * - Checks the `Origin` header (if present) against the allowlist
194
+ * - Checks the one `Origin` line (if present) against the allowlist
210
195
  * - Allows requests without an `Origin` header (direct access, curl, etc.)
211
- * - Refuses an `Origin` that isn't visible ASCII, and a duplicated one — the
212
- * runtimes join a repeated header into one value (`a, b`), which carries a
213
- * space and so matches nothing
196
+ * - Refuses a malformed `Origin` (`read_origin` of `http/request_headers.ts`):
197
+ * an empty line, a second line, a byte that isn't visible ASCII — read from
198
+ * the lines the client sent (`get_header_lines`), so a runtime's own view of
199
+ * a repeated or empty line (`@hono/node-server` rebuilds a WebSocket
200
+ * upgrade's from Node's deduplicated one) decides nothing
214
201
  *
215
202
  * Origin-only by design — Fetch spec mandates `Origin` on every unsafe
216
203
  * method (POST / PUT / DELETE / PATCH) regardless of `Referrer-Policy`,
@@ -233,10 +220,9 @@ export const verify_request_source = (allowed_patterns, carve_outs = []) => (c,
233
220
  if (carve_outs.some((carve_out) => middleware_applies(carve_out.path, c.req.path))) {
234
221
  return next();
235
222
  }
236
- // `!== undefined` so an empty-string Origin is present (abnormal, checked
237
- // against the allowlist — the empty string never matches)
238
- const origin = c.req.header('origin');
239
- if (origin !== undefined && !should_allow_origin(origin, allowed_patterns)) {
223
+ const origin = read_origin(get_header_lines(c, 'origin'));
224
+ if (origin.kind === 'refused' ||
225
+ (origin.kind === 'one' && !should_allow_origin(origin.value, allowed_patterns))) {
240
226
  return c.json({ error: ERROR_FORBIDDEN_ORIGIN }, 403);
241
227
  }
242
228
  // no Origin — direct access (curl, CLI); token auth is the control
@@ -146,6 +146,7 @@ export declare const resolve_client_ip: (forwarded_for: string, proxies: Array<P
146
146
  *
147
147
  * @param options - trusted proxy configuration
148
148
  * @mutates `c.var.client_ip` - set to the resolved (or `'unknown'`) client IP per request
149
+ * @mutates `c.var.connection_ip` - set to the connection's peer address, `null` when the runtime gave none (`CONNECTION_IP_KEY`)
149
150
  * @throws Error if any entry in `options.trusted_proxies` is invalid (parsed eagerly via `parse_proxy_entry`)
150
151
  */
151
152
  export declare const create_proxy_middleware: (options: ProxyOptions) => MiddlewareHandler;
@@ -1 +1 @@
1
- {"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../src/lib/http/proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAEvD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAG3D;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,YAAY,GAAI,IAAI,MAAM,KAAG,MAA6B,CAAC;AAExE;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B,sFAAsF;IACtF,eAAe,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC/B,+DAA+D;IAC/D,iBAAiB,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,MAAM,GAAG,SAAS,CAAC;IACtD,wDAAwD;IACxD,GAAG,CAAC,EAAE,MAAM,CAAC;CACb;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GACpB;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAC/B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAC;AAEpF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,iBAAiB,GAAI,OAAO,MAAM,KAAG,WAgDjD,CAAC;AAiBF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,kBAAkB,GAAI,IAAI,MAAM,KAAG,MAAM,GAAG,MAAM,GAAG,SAWjE,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,GAAI,IAAI,MAAM,EAAE,SAAS,KAAK,CAAC,WAAW,CAAC,KAAG,OAqBvE,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,iBAAiB,GAC7B,eAAe,MAAM,EACrB,SAAS,KAAK,CAAC,WAAW,CAAC,KACzB,MAAM,GAAG,SAqBX,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,uBAAuB,GAAI,SAAS,YAAY,KAAG,iBAyC/D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B,GAAI,SAAS,YAAY,KAAG,cAInE,CAAC"}
1
+ {"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../src/lib/http/proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAEvD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAI3D;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,YAAY,GAAI,IAAI,MAAM,KAAG,MAA6B,CAAC;AAExE;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B,sFAAsF;IACtF,eAAe,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC/B,+DAA+D;IAC/D,iBAAiB,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,MAAM,GAAG,SAAS,CAAC;IACtD,wDAAwD;IACxD,GAAG,CAAC,EAAE,MAAM,CAAC;CACb;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GACpB;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAC/B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAC;AAEpF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,iBAAiB,GAAI,OAAO,MAAM,KAAG,WAgDjD,CAAC;AAiBF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,kBAAkB,GAAI,IAAI,MAAM,KAAG,MAAM,GAAG,MAAM,GAAG,SAWjE,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,GAAI,IAAI,MAAM,EAAE,SAAS,KAAK,CAAC,WAAW,CAAC,KAAG,OAqBvE,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,iBAAiB,GAC7B,eAAe,MAAM,EACrB,SAAS,KAAK,CAAC,WAAW,CAAC,KACzB,MAAM,GAAG,SAqBX,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,uBAAuB,GAAI,SAAS,YAAY,KAAG,iBA0C/D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B,GAAI,SAAS,YAAY,KAAG,cAInE,CAAC"}
@@ -9,6 +9,7 @@
9
9
  */
10
10
  import { convertIPv4ToBinary, convertIPv6ToBinary, distinctRemoteAddr } from 'hono/utils/ipaddr';
11
11
  import { canonicalize_ip, IP_LITERAL_CHARS } from './ip_canonical.js';
12
+ import { CONNECTION_IP_KEY } from '../hono_context.js';
12
13
  /**
13
14
  * Normalize an IP address for consistent matching and storage.
14
15
  *
@@ -242,6 +243,7 @@ export const resolve_client_ip = (forwarded_for, proxies) => {
242
243
  *
243
244
  * @param options - trusted proxy configuration
244
245
  * @mutates `c.var.client_ip` - set to the resolved (or `'unknown'`) client IP per request
246
+ * @mutates `c.var.connection_ip` - set to the connection's peer address, `null` when the runtime gave none (`CONNECTION_IP_KEY`)
245
247
  * @throws Error if any entry in `options.trusted_proxies` is invalid (parsed eagerly via `parse_proxy_entry`)
246
248
  */
247
249
  export const create_proxy_middleware = (options) => {
@@ -283,6 +285,7 @@ export const create_proxy_middleware = (options) => {
283
285
  }
284
286
  }
285
287
  c.set('client_ip', client_ip);
288
+ c.set(CONNECTION_IP_KEY, connection_ip ?? null);
286
289
  await next();
287
290
  };
288
291
  };
@@ -0,0 +1,95 @@
1
+ /**
2
+ * The readers of the request headers the gates decide on — `Origin` (the
3
+ * origin check), `Origin` and `Referer` (browser context), `Host` (the host
4
+ * gate) and `Content-Type` (the CORS simple-request refusal) — as pure
5
+ * functions over header lines.
6
+ *
7
+ * One rule per reader, the Rust spine's `fuz_http::request_headers` reading
8
+ * the same one, and the shared table
9
+ * `testing/cross_backend/request_header_conformance.json` holding both to the
10
+ * same rows. Each reader takes the header's lines — one field value per
11
+ * header line, in the order sent, outer SP and HTAB already stripped
12
+ * (`get_header_lines` of `http/header_lines.ts` on a request) — so a header
13
+ * sent twice is something it can see.
14
+ *
15
+ * A malformed `Origin`, `Host` or `Content-Type` — an empty line, more than
16
+ * one line, a byte the grammar doesn't hold — reads `refused`, never
17
+ * `absent`: reading a malformed browser signal as no signal at all would fail
18
+ * open past the gate it feeds.
19
+ *
20
+ * **Join-invariance.** A runtime without a per-line view (Bun, an in-process
21
+ * `app.request`) hands the spine one line holding the repeated lines joined
22
+ * with `, `. No origin, host or media type holds a comma, so each reader
23
+ * refuses one anywhere in its value: the join of a repeat is then refused as
24
+ * the repeat itself is, and every reading is the same over the lines and over
25
+ * their join.
26
+ *
27
+ * Hono-free: lines in, a reading out.
28
+ *
29
+ * @module
30
+ */
31
+ /**
32
+ * One header's reading: none sent, exactly one well-formed line, or refused.
33
+ * Twin of the Rust `fuz_http::HeaderRead`.
34
+ */
35
+ export type HeaderRead<T> = {
36
+ readonly kind: 'absent';
37
+ } | {
38
+ readonly kind: 'one';
39
+ readonly value: T;
40
+ } | {
41
+ readonly kind: 'refused';
42
+ };
43
+ /**
44
+ * Read the `Origin` lines: `absent` when there are none, `one` for exactly one
45
+ * line of printable ASCII with no space or comma, `refused` otherwise — an
46
+ * empty line, a second line, a byte outside that set.
47
+ *
48
+ * The opaque origin `null` reads `one`: it is a value a browser sends, and the
49
+ * allowlist refuses it.
50
+ *
51
+ * @param origin_lines - the `Origin` header's lines
52
+ */
53
+ export declare const read_origin: (origin_lines: ReadonlyArray<string>) => HeaderRead<string>;
54
+ /**
55
+ * Read the `Host` lines, by `read_origin`'s rule: `absent`, `one` well-formed
56
+ * line, or `refused` — an empty `Host` names nothing, and more than one is
57
+ * refused (RFC 9112 §3.2).
58
+ *
59
+ * @param host_lines - the `Host` header's lines
60
+ */
61
+ export declare const read_host: (host_lines: ReadonlyArray<string>) => HeaderRead<string>;
62
+ /**
63
+ * Read the `Content-Type` lines to the MIME essence: `absent` when there are
64
+ * none, `one` with the essence (the part before any `;`, stripped of SP and
65
+ * HTAB, lowercased) when there is exactly one line of header text with no
66
+ * comma whose essence is `token "/" token`, `refused` otherwise.
67
+ *
68
+ * A comma is refused anywhere in the value, a quoted parameter's included: a
69
+ * joined repeat whose first line carries a parameter
70
+ * (`application/json; charset=utf-8, text/plain`) has a well-formed essence,
71
+ * and only refusing the comma reads it as the repeat it is.
72
+ *
73
+ * @param content_type_lines - the `Content-Type` header's lines
74
+ */
75
+ export declare const read_content_type: (content_type_lines: ReadonlyArray<string>) => HeaderRead<string>;
76
+ /**
77
+ * True when the request carries a browser-context header — any `Origin` or
78
+ * `Referer` line, an empty or repeated one included. A presence test: a
79
+ * malformed browser signal is still a browser signal.
80
+ *
81
+ * The bearer (`auth/bearer_auth.ts`) and daemon-token
82
+ * (`auth/daemon_token_middleware.ts`) legs discard their credential when this
83
+ * is true, and the request continues without it: a stolen bearer token can't
84
+ * be replayed from a cross-origin page, and the loopback daemon token never
85
+ * legitimately carries an `Origin`. It is not a proof that the caller is no
86
+ * browser — a same-origin `GET` sends no `Origin`, and with
87
+ * `referrerPolicy: 'no-referrer'` no `Referer` either. Distinct from the
88
+ * origin check (`verify_request_source`), which gates a browser request
89
+ * against the allowlist.
90
+ *
91
+ * @param origin_lines - the `Origin` header's lines
92
+ * @param referer_lines - the `Referer` header's lines
93
+ */
94
+ export declare const is_browser_context: (origin_lines: ReadonlyArray<string>, referer_lines: ReadonlyArray<string>) => boolean;
95
+ //# sourceMappingURL=request_headers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request_headers.d.ts","sourceRoot":"","sources":["../../src/lib/http/request_headers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAIH;;;GAGG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,IACrB;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,GAC3B;IAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GAC3C;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC;AAchC;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW,GAAI,cAAc,aAAa,CAAC,MAAM,CAAC,KAAG,UAAU,CAAC,MAAM,CACjD,CAAC;AAEnC;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAI,YAAY,aAAa,CAAC,MAAM,CAAC,KAAG,UAAU,CAAC,MAAM,CAC/C,CAAC;AASjC;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,iBAAiB,GAC7B,oBAAoB,aAAa,CAAC,MAAM,CAAC,KACvC,UAAU,CAAC,MAAM,CAQnB,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,kBAAkB,GAC9B,cAAc,aAAa,CAAC,MAAM,CAAC,EACnC,eAAe,aAAa,CAAC,MAAM,CAAC,KAClC,OAA8D,CAAC"}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * The readers of the request headers the gates decide on — `Origin` (the
3
+ * origin check), `Origin` and `Referer` (browser context), `Host` (the host
4
+ * gate) and `Content-Type` (the CORS simple-request refusal) — as pure
5
+ * functions over header lines.
6
+ *
7
+ * One rule per reader, the Rust spine's `fuz_http::request_headers` reading
8
+ * the same one, and the shared table
9
+ * `testing/cross_backend/request_header_conformance.json` holding both to the
10
+ * same rows. Each reader takes the header's lines — one field value per
11
+ * header line, in the order sent, outer SP and HTAB already stripped
12
+ * (`get_header_lines` of `http/header_lines.ts` on a request) — so a header
13
+ * sent twice is something it can see.
14
+ *
15
+ * A malformed `Origin`, `Host` or `Content-Type` — an empty line, more than
16
+ * one line, a byte the grammar doesn't hold — reads `refused`, never
17
+ * `absent`: reading a malformed browser signal as no signal at all would fail
18
+ * open past the gate it feeds.
19
+ *
20
+ * **Join-invariance.** A runtime without a per-line view (Bun, an in-process
21
+ * `app.request`) hands the spine one line holding the repeated lines joined
22
+ * with `, `. No origin, host or media type holds a comma, so each reader
23
+ * refuses one anywhere in its value: the join of a repeat is then refused as
24
+ * the repeat itself is, and every reading is the same over the lines and over
25
+ * their join.
26
+ *
27
+ * Hono-free: lines in, a reading out.
28
+ *
29
+ * @module
30
+ */
31
+ import { trim_optional_whitespace } from './header_lines.js';
32
+ const ABSENT = Object.freeze({ kind: 'absent' });
33
+ const REFUSED = Object.freeze({ kind: 'refused' });
34
+ /** Printable ASCII without the space or a comma — every byte of an origin or a host. */
35
+ const ORIGIN_OR_HOST_TEXT = /^[\x21-\x2b\x2d-\x7e]+$/;
36
+ /** Visible ASCII, the space and a tab, without a comma — what a `Content-Type` value may hold. */
37
+ const CONTENT_TYPE_TEXT = /^[\t\x20-\x2b\x2d-\x7e]*$/;
38
+ /** A MIME essence: `token "/" token` (RFC 9110 §8.3.1, §5.6.2). */
39
+ const MEDIA_TYPE_ESSENCE = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+\/[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
40
+ /**
41
+ * Read the `Origin` lines: `absent` when there are none, `one` for exactly one
42
+ * line of printable ASCII with no space or comma, `refused` otherwise — an
43
+ * empty line, a second line, a byte outside that set.
44
+ *
45
+ * The opaque origin `null` reads `one`: it is a value a browser sends, and the
46
+ * allowlist refuses it.
47
+ *
48
+ * @param origin_lines - the `Origin` header's lines
49
+ */
50
+ export const read_origin = (origin_lines) => read_origin_or_host(origin_lines);
51
+ /**
52
+ * Read the `Host` lines, by `read_origin`'s rule: `absent`, `one` well-formed
53
+ * line, or `refused` — an empty `Host` names nothing, and more than one is
54
+ * refused (RFC 9112 §3.2).
55
+ *
56
+ * @param host_lines - the `Host` header's lines
57
+ */
58
+ export const read_host = (host_lines) => read_origin_or_host(host_lines);
59
+ const read_origin_or_host = (lines) => {
60
+ if (lines.length === 0)
61
+ return ABSENT;
62
+ if (lines.length > 1)
63
+ return REFUSED;
64
+ const value = lines[0];
65
+ return ORIGIN_OR_HOST_TEXT.test(value) ? { kind: 'one', value } : REFUSED;
66
+ };
67
+ /**
68
+ * Read the `Content-Type` lines to the MIME essence: `absent` when there are
69
+ * none, `one` with the essence (the part before any `;`, stripped of SP and
70
+ * HTAB, lowercased) when there is exactly one line of header text with no
71
+ * comma whose essence is `token "/" token`, `refused` otherwise.
72
+ *
73
+ * A comma is refused anywhere in the value, a quoted parameter's included: a
74
+ * joined repeat whose first line carries a parameter
75
+ * (`application/json; charset=utf-8, text/plain`) has a well-formed essence,
76
+ * and only refusing the comma reads it as the repeat it is.
77
+ *
78
+ * @param content_type_lines - the `Content-Type` header's lines
79
+ */
80
+ export const read_content_type = (content_type_lines) => {
81
+ if (content_type_lines.length === 0)
82
+ return ABSENT;
83
+ if (content_type_lines.length > 1)
84
+ return REFUSED;
85
+ const value = content_type_lines[0];
86
+ if (!CONTENT_TYPE_TEXT.test(value))
87
+ return REFUSED;
88
+ const semicolon = value.indexOf(';');
89
+ const essence = trim_optional_whitespace(semicolon === -1 ? value : value.slice(0, semicolon));
90
+ return MEDIA_TYPE_ESSENCE.test(essence) ? { kind: 'one', value: essence.toLowerCase() } : REFUSED;
91
+ };
92
+ /**
93
+ * True when the request carries a browser-context header — any `Origin` or
94
+ * `Referer` line, an empty or repeated one included. A presence test: a
95
+ * malformed browser signal is still a browser signal.
96
+ *
97
+ * The bearer (`auth/bearer_auth.ts`) and daemon-token
98
+ * (`auth/daemon_token_middleware.ts`) legs discard their credential when this
99
+ * is true, and the request continues without it: a stolen bearer token can't
100
+ * be replayed from a cross-origin page, and the loopback daemon token never
101
+ * legitimately carries an `Origin`. It is not a proof that the caller is no
102
+ * browser — a same-origin `GET` sends no `Origin`, and with
103
+ * `referrerPolicy: 'no-referrer'` no `Referer` either. Distinct from the
104
+ * origin check (`verify_request_source`), which gates a browser request
105
+ * against the allowlist.
106
+ *
107
+ * @param origin_lines - the `Origin` header's lines
108
+ * @param referer_lines - the `Referer` header's lines
109
+ */
110
+ export const is_browser_context = (origin_lines, referer_lines) => origin_lines.length > 0 || referer_lines.length > 0;
@@ -0,0 +1,134 @@
1
+ /**
2
+ * The strict readers of the request target: the query string to its pairs,
3
+ * and one path segment to its text — each percent-decoded, or refused.
4
+ *
5
+ * An escape that doesn't decode is refused, never left literal and never
6
+ * replaced with U+FFFD: a `%` not followed by two hex digits is a
7
+ * `malformed_escape`, and decoded bytes that are not UTF-8 are
8
+ * `invalid_utf8`. A literal spelling would make `%FF` and `%25FF` one value,
9
+ * and a lossy one would make every invalid sequence the same U+FFFD — either
10
+ * way a handler reads a value the client never sent. The Rust spine's
11
+ * `fuz_http::request_target` reads by the same rule, and the shared table
12
+ * `testing/cross_backend/request_target_conformance.json` holds both to the
13
+ * same rows.
14
+ *
15
+ * The pure readers take text and are Hono-free. `read_request_query_pairs`
16
+ * and `read_request_route_params` apply them to a request (a type-only import
17
+ * of the Hono context): every read of the query or the path params in the
18
+ * spine goes through one of the two.
19
+ *
20
+ * @module
21
+ */
22
+ import type { Context } from 'hono';
23
+ import type { Result } from '@fuzdev/fuz_util/result.ts';
24
+ /** Why a query string or a path segment doesn't decode. */
25
+ export declare const PERCENT_DECODE_ERRORS: readonly ["malformed_escape", "invalid_utf8"];
26
+ /**
27
+ * Why a query string or a path segment doesn't decode: a `%` not followed by
28
+ * two hex digits, or decoded bytes that are not UTF-8. Twin of the Rust
29
+ * `fuz_http::PercentDecodeError`.
30
+ */
31
+ export type PercentDecodeError = (typeof PERCENT_DECODE_ERRORS)[number];
32
+ /** One query pair, decoded: its name and its value. */
33
+ export type QueryPair = readonly [name: string, value: string];
34
+ /** A decoded query string, or why it doesn't decode. */
35
+ export type QueryPairsRead = Result<{
36
+ readonly value: ReadonlyArray<QueryPair>;
37
+ }, {
38
+ readonly error: PercentDecodeError;
39
+ }>;
40
+ /** A decoded path segment, or why it doesn't decode. */
41
+ export type PathSegmentRead = Result<{
42
+ readonly value: string;
43
+ }, {
44
+ readonly error: PercentDecodeError;
45
+ }>;
46
+ /**
47
+ * Read one raw path segment to its text: percent-decoded strictly, `+` left a
48
+ * plus (a path is no form encoding).
49
+ *
50
+ * @param segment - a segment of the raw request path, between two `/`
51
+ */
52
+ export declare const read_path_segment: (segment: string) => PathSegmentRead;
53
+ /**
54
+ * Read a raw query string to its pairs, in order: split on `&` (an empty
55
+ * piece is no pair), each piece split at its first `=` (none reads an empty
56
+ * value), `+` read as a space, then name and value percent-decoded strictly.
57
+ * Every pair is read, a repeated key's and a nameless one's included, and the
58
+ * first component that doesn't decode refuses the whole string — a key no
59
+ * handler reads included, so no reader of one key sees a query another reader
60
+ * would refuse.
61
+ *
62
+ * What a pair means is the caller's: `query_first` takes a key's first
63
+ * occurrence, and `to_query_record` builds the record a route's query schema
64
+ * parses.
65
+ *
66
+ * @param query - the text after `?`, or `null` for a target with none
67
+ */
68
+ export declare const read_query_pairs: (query: string | null) => QueryPairsRead;
69
+ /**
70
+ * The first value of `key` among `pairs` — a repeated key's later values are
71
+ * ignored. Twin of the Rust `fuz_http::query_first`.
72
+ *
73
+ * @returns the value, `''` for a key with no value, `undefined` when absent
74
+ */
75
+ export declare const query_first: (pairs: ReadonlyArray<QueryPair>, key: string) => string | undefined;
76
+ /**
77
+ * The record a route's query schema parses: each name's first value, a
78
+ * nameless pair skipped — what Hono's `c.req.query()` builds, on a
79
+ * null-prototype object.
80
+ */
81
+ export declare const to_query_record: (pairs: ReadonlyArray<QueryPair>) => Record<string, string>;
82
+ /**
83
+ * The path and the query of an absolute request URL, both as sent: the path
84
+ * from the first `/` after the authority, the query the text after the first
85
+ * `?` (`null` without one), a fragment dropped.
86
+ *
87
+ * @param url - the request URL, as the runtime serialized it
88
+ */
89
+ export declare const split_request_url: (url: string) => {
90
+ path: string;
91
+ query: string | null;
92
+ };
93
+ /**
94
+ * A request's path as sent — nothing percent-decoded — which the assembled
95
+ * server routes on (`new Hono({getPath})`), as the Rust spine's router
96
+ * matches the raw `Uri::path`. So `/%61pi/x` is its own path, not `/api/x`,
97
+ * on both spines, and every path-keyed layer (the auth and origin scopes,
98
+ * the origin carve-outs, the session-cookie clear, the unmatched-route
99
+ * handler) reads the spelling the router matched. Dot segments are the
100
+ * runtime's: Node and Bun resolve them while building the request's URL,
101
+ * before this runs.
102
+ *
103
+ * @param request - the request, its `url` as the runtime serialized it
104
+ */
105
+ export declare const get_request_path: (request: Request) => string;
106
+ /**
107
+ * Read a request's query string strictly (`read_query_pairs`) — the one read
108
+ * of the query in the spine: the route context's `query_pairs`, a route's
109
+ * query schema, and the WebSocket upgrade's `acting`.
110
+ *
111
+ * @param c - the Hono context
112
+ */
113
+ export declare const read_request_query_pairs: (c: Context) => QueryPairsRead;
114
+ /**
115
+ * Read the matched route's path params, every escape in the request path
116
+ * decoded strictly first — the one read of the path params in the spine.
117
+ *
118
+ * The whole path is read rather than each param's own segments: the router
119
+ * matches the raw path (`get_request_path`), so a literal segment matches
120
+ * only as the template spells it — no escape at all — and on a matched route
121
+ * every escape is inside a param. Once every segment decodes, Hono's own
122
+ * reading of each param — the raw matched text by `decodeURIComponent` — is
123
+ * exactly its strict decoding, so the values are taken from Hono's match,
124
+ * which knows which segments each param spans.
125
+ *
126
+ * @param c - the Hono context
127
+ * @returns the params by name, or why the path doesn't decode
128
+ */
129
+ export declare const read_request_route_params: (c: Context) => Result<{
130
+ readonly value: Record<string, string>;
131
+ }, {
132
+ readonly error: PercentDecodeError;
133
+ }>;
134
+ //# sourceMappingURL=request_target.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request_target.d.ts","sourceRoot":"","sources":["../../src/lib/http/request_target.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEzD,2DAA2D;AAC3D,eAAO,MAAM,qBAAqB,+CAAgD,CAAC;AAEnF;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC;AAExE,uDAAuD;AACvD,MAAM,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAE/D,wDAAwD;AACxD,MAAM,MAAM,cAAc,GAAG,MAAM,CAClC;IAAE,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,SAAS,CAAC,CAAA;CAAE,EAC5C;IAAE,QAAQ,CAAC,KAAK,EAAE,kBAAkB,CAAA;CAAE,CACtC,CAAC;AAEF,wDAAwD;AACxD,MAAM,MAAM,eAAe,GAAG,MAAM,CACnC;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EAC1B;IAAE,QAAQ,CAAC,KAAK,EAAE,kBAAkB,CAAA;CAAE,CACtC,CAAC;AA8CF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAI,SAAS,MAAM,KAAG,eACrB,CAAC;AAEhC;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,gBAAgB,GAAI,OAAO,MAAM,GAAG,IAAI,KAAG,cAevD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,aAAa,CAAC,SAAS,CAAC,EAAE,KAAK,MAAM,KAAG,MAAM,GAAG,SAC1C,CAAC;AAE3C;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,aAAa,CAAC,SAAS,CAAC,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAOtF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAAI,KAAK,MAAM,KAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;CAWnF,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,gBAAgB,GAAI,SAAS,OAAO,KAAG,MAA6C,CAAC;AAElG;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,GAAI,GAAG,OAAO,KAAG,cACD,CAAC;AAEtD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,yBAAyB,GACrC,GAAG,OAAO,KACR,MAAM,CAAC;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,kBAAkB,CAAA;CAAE,CAM3F,CAAC"}
@@ -0,0 +1,193 @@
1
+ /**
2
+ * The strict readers of the request target: the query string to its pairs,
3
+ * and one path segment to its text — each percent-decoded, or refused.
4
+ *
5
+ * An escape that doesn't decode is refused, never left literal and never
6
+ * replaced with U+FFFD: a `%` not followed by two hex digits is a
7
+ * `malformed_escape`, and decoded bytes that are not UTF-8 are
8
+ * `invalid_utf8`. A literal spelling would make `%FF` and `%25FF` one value,
9
+ * and a lossy one would make every invalid sequence the same U+FFFD — either
10
+ * way a handler reads a value the client never sent. The Rust spine's
11
+ * `fuz_http::request_target` reads by the same rule, and the shared table
12
+ * `testing/cross_backend/request_target_conformance.json` holds both to the
13
+ * same rows.
14
+ *
15
+ * The pure readers take text and are Hono-free. `read_request_query_pairs`
16
+ * and `read_request_route_params` apply them to a request (a type-only import
17
+ * of the Hono context): every read of the query or the path params in the
18
+ * spine goes through one of the two.
19
+ *
20
+ * @module
21
+ */
22
+ /** Why a query string or a path segment doesn't decode. */
23
+ export const PERCENT_DECODE_ERRORS = ['malformed_escape', 'invalid_utf8'];
24
+ const HEX_DIGIT = /^[0-9A-Fa-f]$/;
25
+ const UTF8 = new TextEncoder();
26
+ const UTF8_STRICT = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true });
27
+ /**
28
+ * Percent-decode `text` strictly: every `%` must start an escape of two hex
29
+ * digits, and the decoded bytes must be UTF-8. A malformed escape anywhere is
30
+ * reported ahead of invalid bytes, since it is found in the scan and the bytes
31
+ * are judged after it.
32
+ */
33
+ const percent_decode_strict = (text) => {
34
+ if (!text.includes('%'))
35
+ return { ok: true, value: text };
36
+ const bytes = [];
37
+ for (let i = 0; i < text.length;) {
38
+ const char = text[i];
39
+ if (char === '%') {
40
+ const high = text[i + 1];
41
+ const low = text[i + 2];
42
+ if (high === undefined ||
43
+ low === undefined ||
44
+ !HEX_DIGIT.test(high) ||
45
+ !HEX_DIGIT.test(low)) {
46
+ return { ok: false, error: 'malformed_escape' };
47
+ }
48
+ bytes.push(Number.parseInt(high + low, 16));
49
+ i += 3;
50
+ }
51
+ else {
52
+ // a run of literal text, as its UTF-8 bytes
53
+ const next = text.indexOf('%', i);
54
+ const end = next === -1 ? text.length : next;
55
+ for (const byte of UTF8.encode(text.slice(i, end)))
56
+ bytes.push(byte);
57
+ i = end;
58
+ }
59
+ }
60
+ try {
61
+ return { ok: true, value: UTF8_STRICT.decode(new Uint8Array(bytes)) };
62
+ }
63
+ catch {
64
+ return { ok: false, error: 'invalid_utf8' };
65
+ }
66
+ };
67
+ /**
68
+ * Read one raw path segment to its text: percent-decoded strictly, `+` left a
69
+ * plus (a path is no form encoding).
70
+ *
71
+ * @param segment - a segment of the raw request path, between two `/`
72
+ */
73
+ export const read_path_segment = (segment) => percent_decode_strict(segment);
74
+ /**
75
+ * Read a raw query string to its pairs, in order: split on `&` (an empty
76
+ * piece is no pair), each piece split at its first `=` (none reads an empty
77
+ * value), `+` read as a space, then name and value percent-decoded strictly.
78
+ * Every pair is read, a repeated key's and a nameless one's included, and the
79
+ * first component that doesn't decode refuses the whole string — a key no
80
+ * handler reads included, so no reader of one key sees a query another reader
81
+ * would refuse.
82
+ *
83
+ * What a pair means is the caller's: `query_first` takes a key's first
84
+ * occurrence, and `to_query_record` builds the record a route's query schema
85
+ * parses.
86
+ *
87
+ * @param query - the text after `?`, or `null` for a target with none
88
+ */
89
+ export const read_query_pairs = (query) => {
90
+ const pairs = [];
91
+ if (query === null || query === '')
92
+ return { ok: true, value: pairs };
93
+ for (const piece of query.split('&')) {
94
+ if (piece === '')
95
+ continue;
96
+ const equals = piece.indexOf('=');
97
+ const raw_name = equals === -1 ? piece : piece.slice(0, equals);
98
+ const raw_value = equals === -1 ? '' : piece.slice(equals + 1);
99
+ const name = percent_decode_strict(raw_name.replaceAll('+', ' '));
100
+ if (!name.ok)
101
+ return name;
102
+ const value = percent_decode_strict(raw_value.replaceAll('+', ' '));
103
+ if (!value.ok)
104
+ return value;
105
+ pairs.push([name.value, value.value]);
106
+ }
107
+ return { ok: true, value: pairs };
108
+ };
109
+ /**
110
+ * The first value of `key` among `pairs` — a repeated key's later values are
111
+ * ignored. Twin of the Rust `fuz_http::query_first`.
112
+ *
113
+ * @returns the value, `''` for a key with no value, `undefined` when absent
114
+ */
115
+ export const query_first = (pairs, key) => pairs.find(([name]) => name === key)?.[1];
116
+ /**
117
+ * The record a route's query schema parses: each name's first value, a
118
+ * nameless pair skipped — what Hono's `c.req.query()` builds, on a
119
+ * null-prototype object.
120
+ */
121
+ export const to_query_record = (pairs) => {
122
+ const record = Object.create(null);
123
+ for (const [name, value] of pairs) {
124
+ if (name === '' || Object.hasOwn(record, name))
125
+ continue;
126
+ record[name] = value;
127
+ }
128
+ return record;
129
+ };
130
+ /**
131
+ * The path and the query of an absolute request URL, both as sent: the path
132
+ * from the first `/` after the authority, the query the text after the first
133
+ * `?` (`null` without one), a fragment dropped.
134
+ *
135
+ * @param url - the request URL, as the runtime serialized it
136
+ */
137
+ export const split_request_url = (url) => {
138
+ const hash = url.indexOf('#');
139
+ const without_fragment = hash === -1 ? url : url.slice(0, hash);
140
+ const scheme_end = without_fragment.indexOf('://');
141
+ const path_start = without_fragment.indexOf('/', scheme_end === -1 ? 0 : scheme_end + 3);
142
+ if (path_start === -1)
143
+ return { path: '/', query: null };
144
+ const rest = without_fragment.slice(path_start);
145
+ const question = rest.indexOf('?');
146
+ return question === -1
147
+ ? { path: rest, query: null }
148
+ : { path: rest.slice(0, question), query: rest.slice(question + 1) };
149
+ };
150
+ /**
151
+ * A request's path as sent — nothing percent-decoded — which the assembled
152
+ * server routes on (`new Hono({getPath})`), as the Rust spine's router
153
+ * matches the raw `Uri::path`. So `/%61pi/x` is its own path, not `/api/x`,
154
+ * on both spines, and every path-keyed layer (the auth and origin scopes,
155
+ * the origin carve-outs, the session-cookie clear, the unmatched-route
156
+ * handler) reads the spelling the router matched. Dot segments are the
157
+ * runtime's: Node and Bun resolve them while building the request's URL,
158
+ * before this runs.
159
+ *
160
+ * @param request - the request, its `url` as the runtime serialized it
161
+ */
162
+ export const get_request_path = (request) => split_request_url(request.url).path;
163
+ /**
164
+ * Read a request's query string strictly (`read_query_pairs`) — the one read
165
+ * of the query in the spine: the route context's `query_pairs`, a route's
166
+ * query schema, and the WebSocket upgrade's `acting`.
167
+ *
168
+ * @param c - the Hono context
169
+ */
170
+ export const read_request_query_pairs = (c) => read_query_pairs(split_request_url(c.req.url).query);
171
+ /**
172
+ * Read the matched route's path params, every escape in the request path
173
+ * decoded strictly first — the one read of the path params in the spine.
174
+ *
175
+ * The whole path is read rather than each param's own segments: the router
176
+ * matches the raw path (`get_request_path`), so a literal segment matches
177
+ * only as the template spells it — no escape at all — and on a matched route
178
+ * every escape is inside a param. Once every segment decodes, Hono's own
179
+ * reading of each param — the raw matched text by `decodeURIComponent` — is
180
+ * exactly its strict decoding, so the values are taken from Hono's match,
181
+ * which knows which segments each param spans.
182
+ *
183
+ * @param c - the Hono context
184
+ * @returns the params by name, or why the path doesn't decode
185
+ */
186
+ export const read_request_route_params = (c) => {
187
+ for (const segment of split_request_url(c.req.url).path.split('/')) {
188
+ const read = read_path_segment(segment);
189
+ if (!read.ok)
190
+ return read;
191
+ }
192
+ return { ok: true, value: c.req.param() };
193
+ };