@fuzdev/fuz_app 0.180.0 → 0.182.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (389) hide show
  1. package/dist/actions/CLAUDE.md +38 -20
  2. package/dist/actions/action_rpc.d.ts +25 -6
  3. package/dist/actions/action_rpc.d.ts.map +1 -1
  4. package/dist/actions/action_rpc.js +56 -48
  5. package/dist/actions/action_types.d.ts +31 -13
  6. package/dist/actions/action_types.d.ts.map +1 -1
  7. package/dist/actions/action_types.js +1 -1
  8. package/dist/actions/notification_sender.d.ts +83 -0
  9. package/dist/actions/notification_sender.d.ts.map +1 -0
  10. package/dist/actions/notification_sender.js +85 -0
  11. package/dist/actions/perform_action.d.ts +13 -4
  12. package/dist/actions/perform_action.d.ts.map +1 -1
  13. package/dist/actions/perform_action.js +27 -18
  14. package/dist/actions/register_action_ws.d.ts +20 -2
  15. package/dist/actions/register_action_ws.d.ts.map +1 -1
  16. package/dist/actions/register_action_ws.js +17 -5
  17. package/dist/actions/ws_socket_session.d.ts +3 -0
  18. package/dist/actions/ws_socket_session.d.ts.map +1 -1
  19. package/dist/actions/ws_socket_session.js +3 -2
  20. package/dist/auth/CLAUDE.md +84 -59
  21. package/dist/auth/account_actions.d.ts.map +1 -1
  22. package/dist/auth/account_actions.js +30 -3
  23. package/dist/auth/account_queries.d.ts +213 -2
  24. package/dist/auth/account_queries.d.ts.map +1 -1
  25. package/dist/auth/account_queries.js +255 -2
  26. package/dist/auth/account_route_schema.d.ts +26 -16
  27. package/dist/auth/account_route_schema.d.ts.map +1 -1
  28. package/dist/auth/account_route_schema.js +10 -24
  29. package/dist/auth/account_routes.d.ts +5 -7
  30. package/dist/auth/account_routes.d.ts.map +1 -1
  31. package/dist/auth/account_routes.js +110 -89
  32. package/dist/auth/admin_actions.d.ts.map +1 -1
  33. package/dist/auth/admin_actions.js +117 -25
  34. package/dist/auth/api_token_queries.d.ts +29 -12
  35. package/dist/auth/api_token_queries.d.ts.map +1 -1
  36. package/dist/auth/api_token_queries.js +42 -27
  37. package/dist/auth/audit_log_route_schema.d.ts +1 -1
  38. package/dist/auth/audit_log_route_schema.d.ts.map +1 -1
  39. package/dist/auth/audit_log_routes.d.ts +1 -1
  40. package/dist/auth/audit_log_routes.d.ts.map +1 -1
  41. package/dist/auth/audit_log_routes.js +10 -12
  42. package/dist/auth/audit_log_schema.js +4 -4
  43. package/dist/auth/bearer_auth.d.ts +4 -3
  44. package/dist/auth/bearer_auth.d.ts.map +1 -1
  45. package/dist/auth/bearer_auth.js +37 -32
  46. package/dist/auth/bootstrap_account.d.ts +65 -37
  47. package/dist/auth/bootstrap_account.d.ts.map +1 -1
  48. package/dist/auth/bootstrap_account.js +115 -66
  49. package/dist/auth/bootstrap_route_schema.d.ts +6 -2
  50. package/dist/auth/bootstrap_route_schema.d.ts.map +1 -1
  51. package/dist/auth/bootstrap_route_schema.js +7 -2
  52. package/dist/auth/bootstrap_routes.d.ts +50 -33
  53. package/dist/auth/bootstrap_routes.d.ts.map +1 -1
  54. package/dist/auth/bootstrap_routes.js +109 -87
  55. package/dist/auth/bootstrap_token_store.d.ts +60 -0
  56. package/dist/auth/bootstrap_token_store.d.ts.map +1 -0
  57. package/dist/auth/bootstrap_token_store.js +39 -0
  58. package/dist/auth/credential_headers.d.ts +71 -0
  59. package/dist/auth/credential_headers.d.ts.map +1 -0
  60. package/dist/auth/credential_headers.js +100 -0
  61. package/dist/auth/daemon_token.d.ts +13 -1
  62. package/dist/auth/daemon_token.d.ts.map +1 -1
  63. package/dist/auth/daemon_token.js +14 -2
  64. package/dist/auth/daemon_token_middleware.d.ts +10 -11
  65. package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
  66. package/dist/auth/daemon_token_middleware.js +39 -30
  67. package/dist/auth/deps.d.ts +10 -11
  68. package/dist/auth/deps.d.ts.map +1 -1
  69. package/dist/auth/invite_queries.d.ts +18 -0
  70. package/dist/auth/invite_queries.d.ts.map +1 -1
  71. package/dist/auth/invite_queries.js +24 -0
  72. package/dist/auth/request_context.d.ts +97 -76
  73. package/dist/auth/request_context.d.ts.map +1 -1
  74. package/dist/auth/request_context.js +93 -104
  75. package/dist/auth/resolved_auth.d.ts +10 -5
  76. package/dist/auth/resolved_auth.d.ts.map +1 -1
  77. package/dist/auth/resolved_auth.js +2 -2
  78. package/dist/auth/role_grant_offer_action_specs.d.ts +2 -2
  79. package/dist/auth/role_grant_offer_action_specs.d.ts.map +1 -1
  80. package/dist/auth/role_grant_offer_action_specs.js +5 -3
  81. package/dist/auth/role_grant_offer_actions.d.ts +7 -11
  82. package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
  83. package/dist/auth/role_grant_offer_actions.js +97 -106
  84. package/dist/auth/role_grant_offer_ddl.d.ts +7 -1
  85. package/dist/auth/role_grant_offer_ddl.d.ts.map +1 -1
  86. package/dist/auth/role_grant_offer_ddl.js +9 -2
  87. package/dist/auth/role_grant_offer_notifications.d.ts +87 -38
  88. package/dist/auth/role_grant_offer_notifications.d.ts.map +1 -1
  89. package/dist/auth/role_grant_offer_notifications.js +75 -22
  90. package/dist/auth/role_grant_offer_queries.d.ts +143 -9
  91. package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
  92. package/dist/auth/role_grant_offer_queries.js +266 -66
  93. package/dist/auth/role_grant_offer_schema.js +1 -1
  94. package/dist/auth/role_grant_queries.d.ts +57 -10
  95. package/dist/auth/role_grant_queries.d.ts.map +1 -1
  96. package/dist/auth/role_grant_queries.js +81 -22
  97. package/dist/auth/role_grant_sql.d.ts +21 -0
  98. package/dist/auth/role_grant_sql.d.ts.map +1 -1
  99. package/dist/auth/role_grant_sql.js +21 -0
  100. package/dist/auth/self_service_role_actions.d.ts.map +1 -1
  101. package/dist/auth/self_service_role_actions.js +9 -2
  102. package/dist/auth/session_cookie.d.ts +105 -25
  103. package/dist/auth/session_cookie.d.ts.map +1 -1
  104. package/dist/auth/session_cookie.js +124 -15
  105. package/dist/auth/session_middleware.d.ts +83 -54
  106. package/dist/auth/session_middleware.d.ts.map +1 -1
  107. package/dist/auth/session_middleware.js +92 -66
  108. package/dist/auth/session_queries.d.ts +95 -14
  109. package/dist/auth/session_queries.d.ts.map +1 -1
  110. package/dist/auth/session_queries.js +98 -19
  111. package/dist/auth/signup_route_schema.d.ts +5 -5
  112. package/dist/auth/signup_route_schema.d.ts.map +1 -1
  113. package/dist/auth/signup_route_schema.js +4 -4
  114. package/dist/auth/signup_routes.d.ts.map +1 -1
  115. package/dist/auth/signup_routes.js +17 -14
  116. package/dist/auth/standard_rpc_actions.d.ts +6 -19
  117. package/dist/auth/standard_rpc_actions.d.ts.map +1 -1
  118. package/dist/auth/standard_rpc_actions.js +5 -6
  119. package/dist/auth/token_scope.d.ts +6 -8
  120. package/dist/auth/token_scope.d.ts.map +1 -1
  121. package/dist/auth/token_scope.js +6 -9
  122. package/dist/dev/setup.d.ts +6 -1
  123. package/dist/dev/setup.d.ts.map +1 -1
  124. package/dist/dev/setup.js +42 -34
  125. package/dist/hono_context.d.ts +21 -0
  126. package/dist/hono_context.d.ts.map +1 -1
  127. package/dist/hono_context.js +17 -0
  128. package/dist/http/CLAUDE.md +156 -48
  129. package/dist/http/auth_shape.d.ts +4 -4
  130. package/dist/http/common_routes.js +1 -1
  131. package/dist/http/db_routes.d.ts +4 -3
  132. package/dist/http/db_routes.d.ts.map +1 -1
  133. package/dist/http/db_routes.js +14 -14
  134. package/dist/http/dev_route_error_check.d.ts +6 -3
  135. package/dist/http/dev_route_error_check.d.ts.map +1 -1
  136. package/dist/http/dev_route_error_check.js +6 -3
  137. package/dist/http/dev_set_cookie_check.d.ts +53 -0
  138. package/dist/http/dev_set_cookie_check.d.ts.map +1 -0
  139. package/dist/http/dev_set_cookie_check.js +80 -0
  140. package/dist/http/error_schemas.d.ts +45 -22
  141. package/dist/http/error_schemas.d.ts.map +1 -1
  142. package/dist/http/error_schemas.js +53 -26
  143. package/dist/http/header_lines.d.ts +42 -0
  144. package/dist/http/header_lines.d.ts.map +1 -0
  145. package/dist/http/header_lines.js +80 -0
  146. package/dist/http/host.d.ts +12 -9
  147. package/dist/http/host.d.ts.map +1 -1
  148. package/dist/http/host.js +25 -20
  149. package/dist/http/origin.d.ts +7 -22
  150. package/dist/http/origin.d.ts.map +1 -1
  151. package/dist/http/origin.js +11 -25
  152. package/dist/http/proxy.d.ts +1 -0
  153. package/dist/http/proxy.d.ts.map +1 -1
  154. package/dist/http/proxy.js +3 -0
  155. package/dist/http/request_headers.d.ts +95 -0
  156. package/dist/http/request_headers.d.ts.map +1 -0
  157. package/dist/http/request_headers.js +110 -0
  158. package/dist/http/request_target.d.ts +134 -0
  159. package/dist/http/request_target.d.ts.map +1 -0
  160. package/dist/http/request_target.js +193 -0
  161. package/dist/http/route_error_check.d.ts +4 -11
  162. package/dist/http/route_error_check.d.ts.map +1 -1
  163. package/dist/http/route_error_check.js +4 -21
  164. package/dist/http/route_result.d.ts +127 -23
  165. package/dist/http/route_result.d.ts.map +1 -1
  166. package/dist/http/route_result.js +97 -19
  167. package/dist/http/route_spec.d.ts +299 -83
  168. package/dist/http/route_spec.d.ts.map +1 -1
  169. package/dist/http/route_spec.js +548 -71
  170. package/dist/http/simple_request.d.ts +19 -14
  171. package/dist/http/simple_request.d.ts.map +1 -1
  172. package/dist/http/simple_request.js +17 -29
  173. package/dist/http/surface.d.ts +2 -0
  174. package/dist/http/surface.d.ts.map +1 -1
  175. package/dist/http/surface.js +4 -1
  176. package/dist/realtime/outbound_budget.d.ts +1 -2
  177. package/dist/realtime/outbound_budget.d.ts.map +1 -1
  178. package/dist/realtime/outbound_budget.js +1 -2
  179. package/dist/realtime/sse.d.ts +47 -17
  180. package/dist/realtime/sse.d.ts.map +1 -1
  181. package/dist/realtime/sse.js +115 -93
  182. package/dist/realtime/sse_constants.d.ts +7 -1
  183. package/dist/realtime/sse_constants.d.ts.map +1 -1
  184. package/dist/realtime/sse_constants.js +12 -1
  185. package/dist/realtime/sse_registry.d.ts +3 -3
  186. package/dist/realtime/sse_registry.js +3 -3
  187. package/dist/runtime/deps.d.ts +20 -4
  188. package/dist/runtime/deps.d.ts.map +1 -1
  189. package/dist/runtime/mock.d.ts +7 -1
  190. package/dist/runtime/mock.d.ts.map +1 -1
  191. package/dist/runtime/mock.js +33 -3
  192. package/dist/runtime/node.d.ts.map +1 -1
  193. package/dist/runtime/node.js +2 -1
  194. package/dist/runtime/secure_file.d.ts +71 -10
  195. package/dist/runtime/secure_file.d.ts.map +1 -1
  196. package/dist/runtime/secure_file.js +91 -11
  197. package/dist/server/app_backend.d.ts +0 -8
  198. package/dist/server/app_backend.d.ts.map +1 -1
  199. package/dist/server/app_backend.js +4 -4
  200. package/dist/server/app_server.d.ts +54 -33
  201. package/dist/server/app_server.d.ts.map +1 -1
  202. package/dist/server/app_server.js +69 -41
  203. package/dist/server/serve_fact_route.d.ts +3 -3
  204. package/dist/server/serve_fact_route.d.ts.map +1 -1
  205. package/dist/server/serve_fact_route.js +59 -55
  206. package/dist/server/static.d.ts +20 -0
  207. package/dist/server/static.d.ts.map +1 -1
  208. package/dist/server/static.js +56 -8
  209. package/dist/server/unmatched_route.d.ts +42 -0
  210. package/dist/server/unmatched_route.d.ts.map +1 -0
  211. package/dist/server/unmatched_route.js +64 -0
  212. package/dist/testing/CLAUDE.md +406 -1202
  213. package/dist/testing/app_server.d.ts +3 -1
  214. package/dist/testing/app_server.d.ts.map +1 -1
  215. package/dist/testing/app_server.js +5 -9
  216. package/dist/testing/auth_apps.d.ts.map +1 -1
  217. package/dist/testing/auth_apps.js +3 -2
  218. package/dist/testing/cross_backend/account_lifecycle.d.ts +11 -4
  219. package/dist/testing/cross_backend/account_lifecycle.d.ts.map +1 -1
  220. package/dist/testing/cross_backend/account_lifecycle.js +320 -6
  221. package/dist/testing/cross_backend/build_test_backend_paths.d.ts +4 -1
  222. package/dist/testing/cross_backend/build_test_backend_paths.d.ts.map +1 -1
  223. package/dist/testing/cross_backend/build_test_backend_paths.js +1 -1
  224. package/dist/testing/cross_backend/capabilities.d.ts +68 -5
  225. package/dist/testing/cross_backend/capabilities.d.ts.map +1 -1
  226. package/dist/testing/cross_backend/capabilities.js +20 -4
  227. package/dist/testing/cross_backend/cell_gated_create.js +1 -1
  228. package/dist/testing/cross_backend/conformance_case.d.ts +63 -21
  229. package/dist/testing/cross_backend/conformance_case.d.ts.map +1 -1
  230. package/dist/testing/cross_backend/conformance_table.d.ts +54 -12
  231. package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
  232. package/dist/testing/cross_backend/conformance_table.js +179 -23
  233. package/dist/testing/cross_backend/cookie_attributes.js +1 -1
  234. package/dist/testing/cross_backend/create_dual_spawn_global_setup.d.ts +7 -1
  235. package/dist/testing/cross_backend/create_dual_spawn_global_setup.d.ts.map +1 -1
  236. package/dist/testing/cross_backend/create_dual_spawn_global_setup.js +3 -3
  237. package/dist/testing/cross_backend/credential_conformance.d.ts +196 -0
  238. package/dist/testing/cross_backend/credential_conformance.d.ts.map +1 -0
  239. package/dist/testing/cross_backend/credential_conformance.js +296 -0
  240. package/dist/testing/cross_backend/credential_conformance.json +1284 -0
  241. package/dist/testing/cross_backend/credential_conformance_wire.d.ts +40 -0
  242. package/dist/testing/cross_backend/credential_conformance_wire.d.ts.map +1 -0
  243. package/dist/testing/cross_backend/credential_conformance_wire.js +293 -0
  244. package/dist/testing/cross_backend/credential_header_robustness.d.ts +1 -3
  245. package/dist/testing/cross_backend/credential_header_robustness.d.ts.map +1 -1
  246. package/dist/testing/cross_backend/credential_header_robustness.js +24 -55
  247. package/dist/testing/cross_backend/credential_wire.d.ts +112 -0
  248. package/dist/testing/cross_backend/credential_wire.d.ts.map +1 -0
  249. package/dist/testing/cross_backend/credential_wire.js +188 -0
  250. package/dist/testing/cross_backend/default_backend_configs.d.ts.map +1 -1
  251. package/dist/testing/cross_backend/default_backend_configs.js +22 -2
  252. package/dist/testing/cross_backend/default_spine_surface.d.ts +1 -26
  253. package/dist/testing/cross_backend/default_spine_surface.d.ts.map +1 -1
  254. package/dist/testing/cross_backend/default_spine_surface.js +3 -7
  255. package/dist/testing/cross_backend/differential.d.ts +1 -1
  256. package/dist/testing/cross_backend/differential.d.ts.map +1 -1
  257. package/dist/testing/cross_backend/differential.js +3 -2
  258. package/dist/testing/cross_backend/differential_normalize.d.ts +23 -6
  259. package/dist/testing/cross_backend/differential_normalize.d.ts.map +1 -1
  260. package/dist/testing/cross_backend/differential_normalize.js +11 -5
  261. package/dist/testing/cross_backend/full_spine_mount.d.ts +4 -10
  262. package/dist/testing/cross_backend/full_spine_mount.d.ts.map +1 -1
  263. package/dist/testing/cross_backend/full_spine_mount.js +11 -4
  264. package/dist/testing/cross_backend/identity_parity.d.ts.map +1 -1
  265. package/dist/testing/cross_backend/identity_parity.js +4 -0
  266. package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
  267. package/dist/testing/cross_backend/in_process_setup.js +78 -4
  268. package/dist/testing/cross_backend/login_security.d.ts.map +1 -1
  269. package/dist/testing/cross_backend/login_security.js +13 -10
  270. package/dist/testing/cross_backend/peer_ping_ws.d.ts +1 -1
  271. package/dist/testing/cross_backend/peer_ping_ws.js +2 -2
  272. package/dist/testing/cross_backend/request_header_conformance.d.ts +174 -0
  273. package/dist/testing/cross_backend/request_header_conformance.d.ts.map +1 -0
  274. package/dist/testing/cross_backend/request_header_conformance.js +196 -0
  275. package/dist/testing/cross_backend/request_header_conformance.json +1158 -0
  276. package/dist/testing/cross_backend/request_header_conformance_wire.d.ts +39 -0
  277. package/dist/testing/cross_backend/request_header_conformance_wire.d.ts.map +1 -0
  278. package/dist/testing/cross_backend/request_header_conformance_wire.js +284 -0
  279. package/dist/testing/cross_backend/request_target_conformance.d.ts +298 -0
  280. package/dist/testing/cross_backend/request_target_conformance.d.ts.map +1 -0
  281. package/dist/testing/cross_backend/request_target_conformance.js +186 -0
  282. package/dist/testing/cross_backend/request_target_conformance.json +3765 -0
  283. package/dist/testing/cross_backend/request_target_conformance_wire.d.ts +32 -0
  284. package/dist/testing/cross_backend/request_target_conformance_wire.d.ts.map +1 -0
  285. package/dist/testing/cross_backend/request_target_conformance_wire.js +278 -0
  286. package/dist/testing/cross_backend/role_grant_offer_lifecycle.d.ts.map +1 -1
  287. package/dist/testing/cross_backend/role_grant_offer_lifecycle.js +173 -1
  288. package/dist/testing/cross_backend/role_grant_offer_notification_ws.d.ts +5 -4
  289. package/dist/testing/cross_backend/role_grant_offer_notification_ws.d.ts.map +1 -1
  290. package/dist/testing/cross_backend/role_grant_offer_notification_ws.js +185 -31
  291. package/dist/testing/cross_backend/rpc_adversarial.d.ts +6 -4
  292. package/dist/testing/cross_backend/rpc_adversarial.d.ts.map +1 -1
  293. package/dist/testing/cross_backend/rpc_adversarial.js +5 -2
  294. package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +6 -7
  295. package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
  296. package/dist/testing/cross_backend/rust_spine_consumer_surface.js +4 -5
  297. package/dist/testing/cross_backend/session_cap.d.ts.map +1 -1
  298. package/dist/testing/cross_backend/session_cap.js +82 -34
  299. package/dist/testing/cross_backend/session_cookie_effect.d.ts +43 -0
  300. package/dist/testing/cross_backend/session_cookie_effect.d.ts.map +1 -0
  301. package/dist/testing/cross_backend/session_cookie_effect.js +103 -0
  302. package/dist/testing/cross_backend/session_login.d.ts +24 -0
  303. package/dist/testing/cross_backend/session_login.d.ts.map +1 -0
  304. package/dist/testing/cross_backend/session_login.js +31 -0
  305. package/dist/testing/cross_backend/setup.d.ts +117 -0
  306. package/dist/testing/cross_backend/setup.d.ts.map +1 -1
  307. package/dist/testing/cross_backend/setup.js +193 -9
  308. package/dist/testing/cross_backend/simple_request.d.ts.map +1 -1
  309. package/dist/testing/cross_backend/simple_request.js +5 -0
  310. package/dist/testing/cross_backend/spine_suites.d.ts +9 -1
  311. package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
  312. package/dist/testing/cross_backend/spine_suites.js +88 -5
  313. package/dist/testing/cross_backend/spine_surface_constants.d.ts +1 -1
  314. package/dist/testing/cross_backend/spine_surface_constants.d.ts.map +1 -1
  315. package/dist/testing/cross_backend/spine_surface_constants.js +1 -0
  316. package/dist/testing/cross_backend/sse_round_trip.d.ts +8 -5
  317. package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
  318. package/dist/testing/cross_backend/sse_round_trip.js +205 -64
  319. package/dist/testing/cross_backend/testing_backdoor.d.ts.map +1 -1
  320. package/dist/testing/cross_backend/testing_backdoor.js +5 -2
  321. package/dist/testing/cross_backend/testing_credential_read.d.ts +165 -0
  322. package/dist/testing/cross_backend/testing_credential_read.d.ts.map +1 -0
  323. package/dist/testing/cross_backend/testing_credential_read.js +175 -0
  324. package/dist/testing/cross_backend/testing_reset_actions.d.ts +19 -0
  325. package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
  326. package/dist/testing/cross_backend/testing_reset_actions.js +22 -6
  327. package/dist/testing/cross_backend/token_lifetime.d.ts.map +1 -1
  328. package/dist/testing/cross_backend/token_lifetime.js +58 -2
  329. package/dist/testing/cross_backend/transport_composition.d.ts +2 -4
  330. package/dist/testing/cross_backend/transport_composition.d.ts.map +1 -1
  331. package/dist/testing/cross_backend/transport_composition.js +13 -10
  332. package/dist/testing/cross_backend/ts_spine_backend_config.d.ts.map +1 -1
  333. package/dist/testing/cross_backend/ts_spine_backend_config.js +5 -3
  334. package/dist/testing/cross_backend/ws_endpoint.d.ts +11 -1
  335. package/dist/testing/cross_backend/ws_endpoint.d.ts.map +1 -1
  336. package/dist/testing/cross_backend/ws_endpoint.js +19 -2
  337. package/dist/testing/cross_backend/ws_role_gated.d.ts.map +1 -1
  338. package/dist/testing/cross_backend/ws_role_gated.js +2 -3
  339. package/dist/testing/cross_backend/ws_round_trip.d.ts.map +1 -1
  340. package/dist/testing/cross_backend/ws_round_trip.js +28 -12
  341. package/dist/testing/cross_backend/xfail.d.ts +44 -11
  342. package/dist/testing/cross_backend/xfail.d.ts.map +1 -1
  343. package/dist/testing/cross_backend/xfail.js +68 -23
  344. package/dist/testing/data_exposure.d.ts.map +1 -1
  345. package/dist/testing/data_exposure.js +4 -3
  346. package/dist/testing/integration.d.ts +1 -2
  347. package/dist/testing/integration.d.ts.map +1 -1
  348. package/dist/testing/integration.js +14 -8
  349. package/dist/testing/integration_helpers.d.ts +50 -3
  350. package/dist/testing/integration_helpers.d.ts.map +1 -1
  351. package/dist/testing/integration_helpers.js +87 -9
  352. package/dist/testing/middleware.d.ts +3 -1
  353. package/dist/testing/middleware.d.ts.map +1 -1
  354. package/dist/testing/middleware.js +14 -7
  355. package/dist/testing/resolved_auth.d.ts +3 -1
  356. package/dist/testing/resolved_auth.d.ts.map +1 -1
  357. package/dist/testing/resolved_auth.js +4 -4
  358. package/dist/testing/round_trip.d.ts +6 -2
  359. package/dist/testing/round_trip.d.ts.map +1 -1
  360. package/dist/testing/round_trip.js +17 -6
  361. package/dist/testing/rpc_envelope_cases.d.ts.map +1 -1
  362. package/dist/testing/rpc_envelope_cases.js +7 -0
  363. package/dist/testing/rpc_helpers.d.ts +4 -2
  364. package/dist/testing/rpc_helpers.d.ts.map +1 -1
  365. package/dist/testing/rpc_helpers.js +6 -1
  366. package/dist/testing/rpc_round_trip.d.ts +13 -2
  367. package/dist/testing/rpc_round_trip.d.ts.map +1 -1
  368. package/dist/testing/rpc_round_trip.js +25 -6
  369. package/dist/testing/schema_generators.d.ts +2 -2
  370. package/dist/testing/schema_generators.d.ts.map +1 -1
  371. package/dist/testing/schema_generators.js +4 -4
  372. package/dist/testing/stubs.d.ts +2 -2
  373. package/dist/testing/stubs.d.ts.map +1 -1
  374. package/dist/testing/stubs.js +13 -10
  375. package/dist/testing/transports/fetch_transport.d.ts +6 -3
  376. package/dist/testing/transports/fetch_transport.d.ts.map +1 -1
  377. package/dist/testing/transports/fetch_transport.js +31 -19
  378. package/dist/testing/transports/raw_http.d.ts +61 -1
  379. package/dist/testing/transports/raw_http.d.ts.map +1 -1
  380. package/dist/testing/transports/raw_http.js +61 -1
  381. package/dist/testing/transports/ws_raw_client.d.ts +20 -0
  382. package/dist/testing/transports/ws_raw_client.d.ts.map +1 -1
  383. package/dist/testing/transports/ws_raw_client.js +10 -4
  384. package/dist/testing/transports/ws_transport.d.ts +21 -1
  385. package/dist/testing/transports/ws_transport.d.ts.map +1 -1
  386. package/dist/testing/transports/ws_transport.js +58 -20
  387. package/dist/testing/ws_round_trip.d.ts.map +1 -1
  388. package/dist/testing/ws_round_trip.js +8 -4
  389. package/package.json +1 -1
@@ -9,7 +9,7 @@
9
9
  import { assert_row } from '../db/assert_row.js';
10
10
  import { columns_sql, iso8601_timestamp_expr, qualify_columns } from '../db/sql_columns.js';
11
11
  import { ROLE_GRANT_OFFER_COLUMNS, ROLE_GRANT_OFFER_SCOPE_KIND_GLOBAL_TOKEN, ROLE_GRANT_OFFER_SCOPE_SENTINEL_UUID, ROLE_GRANT_OFFER_WITH_GRANTOR_SELECT } from './role_grant_offer_ddl.js';
12
- import { offer_pending_predicate, role_grant_active_sql } from './role_grant_sql.js';
12
+ import { offer_pending_predicate, offer_rows_locked_in_id_order, role_grant_active_sql } from './role_grant_sql.js';
13
13
  /**
14
14
  * The full `role_grant` column set, named explicitly so a row read fails loud
15
15
  * on schema drift (see `ACCOUNT_COLUMNS` in `auth/account_queries.ts` for the
@@ -162,6 +162,18 @@ export const query_role_grant_find_active_role_for_actor = async (deps, role_gra
162
162
  * offer becomes terminal at revoke time. A fresh post-revoke grant
163
163
  * requires the grantor to call `query_role_grant_offer_create` again.
164
164
  *
165
+ * The revokee's account row is locked first (`FOR NO KEY UPDATE`, the lock
166
+ * `query_account_lock_for_revoke` takes), so no offer to or from the account is
167
+ * made, and none accepted, while the revoke runs: the offers it locks are the
168
+ * offers it writes. Then those offers, in id order, before the grant is
169
+ * updated: an accept claims its offers before it inserts its grant, and that
170
+ * insert waits on an uncommitted update of the same grant, so the grant first
171
+ * and the offers second would close a cycle with it. A caller that supersedes
172
+ * the revokee's outgoing offers too (`role_grant_revoke`) takes the account row
173
+ * and then every offer it writes in one statement first
174
+ * (`query_role_grant_offer_lock_for_revoke`); the locks here then find rows
175
+ * the transaction already holds.
176
+ *
165
177
  * @param deps - query dependencies
166
178
  * @param role_grant_id - the role_grant to revoke
167
179
  * @param actor_id - the actor that must own the role_grant
@@ -171,6 +183,21 @@ export const query_role_grant_find_active_role_for_actor = async (deps, role_gra
171
183
  * @mutates `role_grant_offer` rows - stamps `superseded_at` on every pending sibling for the same `(account, role, scope)`
172
184
  */
173
185
  export const query_revoke_role_grant = async (deps, role_grant_id, actor_id, revoked_by, reason) => {
186
+ // the revokee's account row first, as `query_account_lock_for_revoke` takes it
187
+ await deps.db.query(`SELECT a.id FROM actor act JOIN account a ON a.id = act.account_id
188
+ WHERE act.id = $1
189
+ FOR NO KEY UPDATE OF a`, [actor_id]);
190
+ // the role and scope name the offers to lock; written once with the grant
191
+ const target = await deps.db.query_one(`SELECT role, scope_id FROM role_grant WHERE id = $1 AND actor_id = $2 AND revoked_at IS NULL`, [role_grant_id, actor_id]);
192
+ if (!target)
193
+ return null;
194
+ const incoming = `to_account_id = (SELECT account_id FROM actor WHERE id = $1)
195
+ AND role = $2 AND scope_id IS NOT DISTINCT FROM $3 AND ${offer_pending_predicate('')}`;
196
+ await deps.db.query(`SELECT id FROM role_grant_offer WHERE ${incoming} ORDER BY id FOR UPDATE`, [
197
+ actor_id,
198
+ target.role,
199
+ target.scope_id
200
+ ]);
174
201
  const rows = await deps.db.query(`UPDATE role_grant SET revoked_at = NOW(), revoked_by = $3, revoked_reason = $4
175
202
  WHERE id = $1 AND actor_id = $2 AND revoked_at IS NULL
176
203
  RETURNING id, role, scope_kind, scope_id`, [role_grant_id, actor_id, revoked_by ?? null, reason ?? null]);
@@ -186,12 +213,7 @@ export const query_revoke_role_grant = async (deps, role_grant_id, actor_id, rev
186
213
  const superseded_offers = await deps.db.query(`WITH updated AS (
187
214
  UPDATE role_grant_offer o
188
215
  SET superseded_at = NOW()
189
- FROM actor a
190
- WHERE a.id = $1
191
- AND o.to_account_id = a.account_id
192
- AND o.role = $2
193
- AND o.scope_id IS NOT DISTINCT FROM $3
194
- AND ${offer_pending_predicate('o')}
216
+ WHERE ${offer_rows_locked_in_id_order('o', incoming)}
195
217
  -- raw columns; the outer grantor select formats them
196
218
  RETURNING ${qualify_columns(ROLE_GRANT_OFFER_COLUMNS, 'o')}
197
219
  )
@@ -253,7 +275,7 @@ export const query_account_has_global_role = async (deps, account_id, role) => {
253
275
  * Like `query_account_has_global_role`, but only counts the grant when the
254
276
  * **account and the granting actor are both active** (`deleted_at IS NULL`).
255
277
  * Used by the last-admin branch of the removability guard: a soft-deleted admin
256
- * can't log in and is excluded from `query_count_active_accounts_with_global_role_for_update`,
278
+ * can't log in and is excluded from `query_count_active_accounts_with_global_role_locked`,
257
279
  * so the guard must use the same active predicate when testing whether the
258
280
  * *target* is an admin — otherwise removing an already-tombstoned admin is
259
281
  * falsely blocked as `cannot_delete_last_admin`. Soft-delete does **not** revoke
@@ -325,11 +347,39 @@ export const query_actor_has_active_global_role = async (deps, actor_id, role) =
325
347
  * guard could fail-open and let the last usable admin be removed).
326
348
  *
327
349
  * **Locks** every counted `role_grant`, `actor`, and `account` row
328
- * (`FOR UPDATE`) until the caller's transaction ends, so two guards racing to
329
- * remove the last two admins serialize: the second waits for the first to
330
- * commit, re-reads the rows it changed, and counts one. Run it inside the
331
- * transaction that does the removal. Twin of the Rust
332
- * `query_count_active_accounts_with_global_role_for_update`.
350
+ * `FOR NO KEY UPDATE` until the caller's transaction ends. That conflicts with
351
+ * another guard, so two guards racing to remove the last two admins serialize:
352
+ * the second waits for the first to commit, re-reads the rows it changed, and
353
+ * counts one. It conflicts with every write that lowers the count — a revoke's
354
+ * or a soft delete's `UPDATE` of a counted row, a purge's `DELETE` — and with
355
+ * the locks a credential mint, an offer, an invite and an offer accept (its
356
+ * recipient's row and its grantor's, `query_account_lock_for_offer_accept`)
357
+ * take on the account row. Run it inside the transaction that does the
358
+ * removal.
359
+ *
360
+ * It does not conflict with a foreign key's `FOR KEY SHARE` — the lock an
361
+ * insert or update naming a counted row takes (an accept's new grant naming its
362
+ * grantor, a cell's `created_by`). Such a write only adds a reference: it never
363
+ * lowers the count, so the guard fails closed — what it counted is at most what
364
+ * will stand, and a removal it allows leaves an admin. A purge that deletes a
365
+ * row such a write names still takes `FOR UPDATE` and waits for it.
366
+ *
367
+ * A purge's cascade writes admin rows too — it sets null the `granted_by` of
368
+ * every grant the purged account's actors granted, admins' grants among them,
369
+ * in the order its plan walks them — so a purge takes every admin's account
370
+ * row first, with its own, in one id-ordered statement
371
+ * (`query_account_lock_admins_for_purge`), and runs this count after it only
372
+ * when its target is an admin: another guard then waits at its first account
373
+ * holding nothing.
374
+ * Twin of the Rust `query_count_active_accounts_with_global_role_locked`.
375
+ *
376
+ * The rows are locked in id order — account, then actor, then grant — as the
377
+ * sort returns them: each account's row, its actors' and its grants' before
378
+ * the next account's. `query_account_lock_live_many` and
379
+ * `query_account_lock_for_offer_accept` take account rows in the same order,
380
+ * so an offer or an accept between two admins and an admin's removal never
381
+ * wait on each other's rows in opposite orders. Ids never change, so no
382
+ * concurrent update can move a row the sort has placed.
333
383
  *
334
384
  * `exclude_role_grant_id` leaves one grant out of the count, so a revoke asks
335
385
  * whether any active admin account would remain without that grant — an
@@ -343,9 +393,9 @@ export const query_actor_has_active_global_role = async (deps, actor_id, role) =
343
393
  * @returns the number of distinct active accounts with an active global `role` grant
344
394
  * @mutates `role_grant` / `actor` / `account` rows - row-locks the counted rows for the transaction
345
395
  */
346
- export const query_count_active_accounts_with_global_role_for_update = async (deps, role, exclude_role_grant_id = null) => {
347
- // `FOR UPDATE` refuses an aggregate, so the rows come back and are counted
348
- // here. The excluded grant is dropped in code, not SQL: filtering it in the
396
+ export const query_count_active_accounts_with_global_role_locked = async (deps, role, exclude_role_grant_id = null) => {
397
+ // A locking clause refuses an aggregate, so the rows come back and are
398
+ // counted here. The excluded grant is dropped in code, not SQL: filtering it in the
349
399
  // WHERE would leave it unlocked, and two cross-revokes (each locking only the
350
400
  // other's grant, then updating it) would deadlock instead of serializing
351
401
  const rows = await deps.db.query(`SELECT a.id AS account_id, rg.id AS role_grant_id
@@ -357,7 +407,8 @@ export const query_count_active_accounts_with_global_role_for_update = async (de
357
407
  AND rg.role = $1
358
408
  AND rg.scope_id IS NULL
359
409
  AND ${role_grant_active_sql('rg')}
360
- FOR UPDATE`, [role]);
410
+ ORDER BY a.id, act.id, rg.id
411
+ FOR NO KEY UPDATE`, [role]);
361
412
  const account_ids = new Set();
362
413
  for (const row of rows) {
363
414
  if (row.role_grant_id !== exclude_role_grant_id)
@@ -409,7 +460,12 @@ export const query_role_grant_find_account_id_for_role = async (deps, role) => {
409
460
  * attached to the destroyed scope is cleaned up.
410
461
  *
411
462
  * Both updates run as separate statements inside the caller's transaction,
412
- * the `role_grant` revoke first. The two halves are
463
+ * the scope's pending offers locked in id order first, then the `role_grant`
464
+ * revoke, then the supersede of the offers that lock returned — offers before
465
+ * grants, as `query_revoke_role_grant` takes them. No account row keeps a new
466
+ * offer at the scope out (the scope's offers span accounts), so the supersede
467
+ * writes only the rows it locked: an offer made at the scope after the lock is
468
+ * left pending rather than taken out of order. The two halves are
413
469
  * independent — orphan pending offers can exist at a scope with no active
414
470
  * role_grants, so the supersede half always runs even when no role_grant was
415
471
  * revoked.
@@ -420,13 +476,17 @@ export const query_role_grant_find_account_id_for_role = async (deps, role) => {
420
476
  * @param reason - optional free-form reason, stamped on `role_grant.revoked_reason`.
421
477
  * @returns the revoked role_grants (with `account_id` for fan-out) and superseded offers (with `from_account_id` for fan-out)
422
478
  * @mutates `role_grant` table - sets `revoked_at`/`revoked_by`/`revoked_reason` on every active row at `scope_id`
423
- * @mutates `role_grant_offer` table - stamps `superseded_at` on every pending row at `scope_id`
479
+ * @mutates `role_grant_offer` table - stamps `superseded_at` on every pending row at `scope_id` its lock took
424
480
  */
425
481
  export const query_role_grant_revoke_for_scope = async (deps, scope_id, revoked_by, reason) => {
426
482
  // Revoke every active role_grant at the scope. CTE returns `actor_id` directly
427
483
  // from the role_grant row (drives `target_actor_id` audit envelopes); a join
428
484
  // against `actor` resolves `account_id` for `target_account_id`
429
485
  // + WS/SSE socket-close fan-out, all in one round-trip.
486
+ // The scope's pending offers first, in id order — before the grants, for
487
+ // the reason `query_revoke_role_grant` locks its offers before its grant
488
+ const at_scope = `scope_id = $1 AND ${offer_pending_predicate('')}`;
489
+ const locked_ids = (await deps.db.query(`SELECT id FROM role_grant_offer WHERE ${at_scope} ORDER BY id FOR UPDATE`, [scope_id])).map((row) => row.id);
430
490
  const revoked = await deps.db.query(`WITH updated AS (
431
491
  UPDATE role_grant
432
492
  SET revoked_at = NOW(), revoked_by = $2, revoked_reason = $3
@@ -444,11 +504,10 @@ export const query_role_grant_revoke_for_scope = async (deps, scope_id, revoked_
444
504
  const superseded_offers = await deps.db.query(`WITH updated AS (
445
505
  UPDATE role_grant_offer o
446
506
  SET superseded_at = NOW()
447
- WHERE o.scope_id = $1
448
- AND ${offer_pending_predicate('o')}
507
+ WHERE o.id = ANY($2) AND o.scope_id = $1 AND ${offer_pending_predicate('o')}
449
508
  -- raw columns; the outer grantor select formats them
450
509
  RETURNING ${qualify_columns(ROLE_GRANT_OFFER_COLUMNS, 'o')}
451
510
  )
452
- ${ROLE_GRANT_OFFER_WITH_GRANTOR_SELECT}`, [scope_id]);
511
+ ${ROLE_GRANT_OFFER_WITH_GRANTOR_SELECT}`, [scope_id, locked_ids]);
453
512
  return { revoked, superseded_offers };
454
513
  };
@@ -39,4 +39,25 @@ export declare const OFFER_TERMINAL_COLUMNS: readonly ["accepted_at", "declined_
39
39
  * @returns the predicate, with no surrounding parentheses
40
40
  */
41
41
  export declare const offer_pending_predicate: (alias: string) => string;
42
+ /**
43
+ * The predicate a multi-row write of `role_grant_offer` takes its rows
44
+ * through: `id` in an id-ordered locking subselect over `where`.
45
+ *
46
+ * Every transaction that writes several offer rows locks them in id order —
47
+ * in one statement like this, or, when it writes them across statements or
48
+ * after another table's row, all of them first in one id-ordered lock, and
49
+ * then writes only rows that lock took: it either holds the account rows that
50
+ * keep a new offer out (an offer create takes both parties' rows — a removal
51
+ * holds its account's, a revoke its revokee's, an accept its recipient's), or
52
+ * names the locked ids (a scope teardown) — so two such transactions never
53
+ * hold rows the other waits on, whatever plan the database picks. A row
54
+ * changed by a transaction it waited on is re-checked against `where` and
55
+ * drops out when it no longer matches. Twin of the Rust
56
+ * `offer_rows_locked_in_id_order`.
57
+ *
58
+ * @param alias - the alias qualifying the written table's `id`, or `''`
59
+ * @param where - the rows' condition, over unqualified `role_grant_offer` columns
60
+ * @returns the predicate, with no surrounding parentheses
61
+ */
62
+ export declare const offer_rows_locked_in_id_order: (alias: string, where: string) => string;
42
63
  //# sourceMappingURL=role_grant_sql.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"role_grant_sql.d.ts","sourceRoot":"","sources":["../../src/lib/auth/role_grant_sql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAQH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,qBAAqB,GAAI,OAAO,MAAM,KAAG,MAIrD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,sBAAsB,0EAKzB,CAAC;AAEX;;;;;;;;;;GAUG;AACH,eAAO,MAAM,uBAAuB,GAAI,OAAO,MAAM,KAAG,MACkC,CAAC"}
1
+ {"version":3,"file":"role_grant_sql.d.ts","sourceRoot":"","sources":["../../src/lib/auth/role_grant_sql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAQH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,qBAAqB,GAAI,OAAO,MAAM,KAAG,MAIrD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,sBAAsB,0EAKzB,CAAC;AAEX;;;;;;;;;;GAUG;AACH,eAAO,MAAM,uBAAuB,GAAI,OAAO,MAAM,KAAG,MACkC,CAAC;AAE3F;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,6BAA6B,GAAI,OAAO,MAAM,EAAE,OAAO,MAAM,KAAG,MACwB,CAAC"}
@@ -52,3 +52,24 @@ export const OFFER_TERMINAL_COLUMNS = [
52
52
  * @returns the predicate, with no surrounding parentheses
53
53
  */
54
54
  export const offer_pending_predicate = (alias) => OFFER_TERMINAL_COLUMNS.map((column) => `${qualify(alias, column)} IS NULL`).join(' AND ');
55
+ /**
56
+ * The predicate a multi-row write of `role_grant_offer` takes its rows
57
+ * through: `id` in an id-ordered locking subselect over `where`.
58
+ *
59
+ * Every transaction that writes several offer rows locks them in id order —
60
+ * in one statement like this, or, when it writes them across statements or
61
+ * after another table's row, all of them first in one id-ordered lock, and
62
+ * then writes only rows that lock took: it either holds the account rows that
63
+ * keep a new offer out (an offer create takes both parties' rows — a removal
64
+ * holds its account's, a revoke its revokee's, an accept its recipient's), or
65
+ * names the locked ids (a scope teardown) — so two such transactions never
66
+ * hold rows the other waits on, whatever plan the database picks. A row
67
+ * changed by a transaction it waited on is re-checked against `where` and
68
+ * drops out when it no longer matches. Twin of the Rust
69
+ * `offer_rows_locked_in_id_order`.
70
+ *
71
+ * @param alias - the alias qualifying the written table's `id`, or `''`
72
+ * @param where - the rows' condition, over unqualified `role_grant_offer` columns
73
+ * @returns the predicate, with no surrounding parentheses
74
+ */
75
+ export const offer_rows_locked_in_id_order = (alias, where) => `${qualify(alias, 'id')} IN (SELECT id FROM role_grant_offer WHERE ${where} ORDER BY id FOR UPDATE)`;
@@ -1 +1 @@
1
- {"version":3,"file":"self_service_role_actions.d.ts","sourceRoot":"","sources":["../../src/lib/auth/self_service_role_actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAIH,OAAO,EAAuC,KAAK,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAGjG,OAAO,EAKN,KAAK,YAAY,EACjB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AAW3D;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,oCAAoC,GAAI,OAAO,QAAQ,CAAC,MAAM,CAAC,KAAG,IAW9E,CAAC;AAEF,sDAAsD;AACtD,MAAM,WAAW,6BAA6B;IAC7C;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACvC;;;;OAIG;IACH,KAAK,CAAC,EAAE,YAAY,CAAC;CACrB;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,gCAAgC,GAC5C,MAAM,yBAAyB,EAC/B,UAAS,6BAAkC,KACzC,KAAK,CAAC,SAAS,CA0JjB,CAAC"}
1
+ {"version":3,"file":"self_service_role_actions.d.ts","sourceRoot":"","sources":["../../src/lib/auth/self_service_role_actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAIH,OAAO,EAAuC,KAAK,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAGjG,OAAO,EAKN,KAAK,YAAY,EACjB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AAe3D;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,oCAAoC,GAAI,OAAO,QAAQ,CAAC,MAAM,CAAC,KAAG,IAW9E,CAAC;AAEF,sDAAsD;AACtD,MAAM,WAAW,6BAA6B;IAC7C;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACvC;;;;OAIG;IACH,KAAK,CAAC,EAAE,YAAY,CAAC;CACrB;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,gCAAgC,GAC5C,MAAM,yBAAyB,EAC/B,UAAS,6BAAkC,KACzC,KAAK,CAAC,SAAS,CAgKjB,CAAC"}
@@ -45,6 +45,7 @@ import { GRANT_PATH_SELF_SERVICE } from './grant_path_schema.js';
45
45
  import { query_create_role_grant, query_revoke_role_grant } from './role_grant_queries.js';
46
46
  import { is_role_grant_active } from './account_schema.js';
47
47
  import { has_scoped_role } from './request_context.js';
48
+ import { queue_supersede_notifications } from './role_grant_offer_notifications.js';
48
49
  import { ERROR_ROLE_NOT_SELF_SERVICE_ELIGIBLE, self_service_role_set_action_spec } from './self_service_role_action_specs.js';
49
50
  /**
50
51
  * Validate a deployment's self-service eligible-role set at construction.
@@ -192,8 +193,9 @@ export const create_self_service_role_actions = (deps, options = {}) => {
192
193
  // for the same `(account, role, scope)` superseded as a side effect, and
193
194
  // each gets its forensic row like the admin revoke's (empty in practice:
194
195
  // offer creation gates on the role's `grant_paths`, so only a role that is
195
- // both offerable and self-service-eligible has siblings). The WS supersede
196
- // notification to each grantor is not sent (twin of the Rust path).
196
+ // both offerable and self-service-eligible has siblings). Both parties are
197
+ // told, as the admin revoke tells them: the recipient is the caller, but
198
+ // its answer lists no offers, so its other connections learn of them here.
197
199
  for (const offer of result.superseded_offers) {
198
200
  await deps.audit.emit_role_grant_target(ctx, auth, {
199
201
  event_type: 'role_grant_offer_supersede',
@@ -208,6 +210,11 @@ export const create_self_service_role_actions = (deps, options = {}) => {
208
210
  }
209
211
  });
210
212
  }
213
+ const revoked_grant = { kind: 'id', id: result.id };
214
+ queue_supersede_notifications(ctx, result.superseded_offers, 'role_grant_revoked', {
215
+ grantor: revoked_grant,
216
+ recipient: revoked_grant
217
+ });
211
218
  return { ok: true, enabled: false, changed: true };
212
219
  };
213
220
  return [rpc_action(self_service_role_set_action_spec, handler)];
@@ -20,24 +20,66 @@ import type { Keyring } from './keyring.js';
20
20
  */
21
21
  export declare const SESSION_AGE_MAX: number;
22
22
  /**
23
- * Cookie options for session cookies.
24
- */
25
- export interface SessionCookieOptions {
26
- path: string;
27
- httpOnly: boolean;
28
- secure: boolean;
29
- sameSite: 'strict' | 'lax' | 'none';
30
- maxAge: number;
31
- }
23
+ * The attributes every session `Set-Cookie` carries, in the order written —
24
+ * the Rust spine's `SESSION_COOKIE_ATTRIBUTES`, byte for byte. Fixed: the
25
+ * spine writes one cookie.
26
+ *
27
+ * - `Path=/` - sent to every path of the origin
28
+ * - `HttpOnly` - out of reach of page script
29
+ * - `Secure` - HTTPS only (Chrome and Firefox treat `localhost` as secure)
30
+ * - `SameSite=Strict` - never sent on a cross-site request
31
+ */
32
+ export declare const SESSION_COOKIE_ATTRIBUTES = "Path=/; HttpOnly; Secure; SameSite=Strict";
33
+ /**
34
+ * Whether `name` is an RFC 6265 `cookie-name` — an HTTP `token`: visible
35
+ * ASCII less the separators (`=`, `;`, `,`, space, quotes, brackets and the
36
+ * rest). Twin of the Rust spine's `is_cookie_name`.
37
+ *
38
+ * Anything but a string is refused, whatever its type says: the name is a
39
+ * consumer's option, and a regex alone would read `undefined` as the text
40
+ * `undefined`.
41
+ *
42
+ * @param name - a cookie name
43
+ */
44
+ export declare const is_cookie_name: (name: string) => boolean;
45
+ /**
46
+ * Whether `value` is an RFC 6265 `cookie-value` in its unquoted form — only
47
+ * `cookie-octet`s: visible ASCII less `"`, `,`, `;` and `\`. Such a value
48
+ * reads back out of a `Cookie` header exactly as it was written, which is
49
+ * what a reader that decodes nothing needs. Twin of the Rust spine's
50
+ * `is_cookie_value`.
51
+ *
52
+ * Anything but a string is refused, whatever its type says: the value comes
53
+ * out of a consumer's `encode_identity` and keyring, and a regex alone would
54
+ * read `undefined` as the text `undefined`.
55
+ *
56
+ * @param value - a cookie value
57
+ */
58
+ export declare const is_cookie_value: (value: string) => boolean;
59
+ /**
60
+ * Build the `Set-Cookie` header value that sets the session cookie:
61
+ * `<name>=<value>; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=<max_age>`,
62
+ * the Rust spine's string. The value is written as given — never
63
+ * percent-encoded or quoted — so the cookie either spine mints verifies on
64
+ * both.
65
+ *
66
+ * @param cookie_name - the session cookie's name
67
+ * @param value - the signed cookie value (`create_session_cookie_value`)
68
+ * @param max_age - the cookie's lifetime in seconds
69
+ * @returns the `Set-Cookie` header value
70
+ * @throws Error when the name is not an RFC 6265 `cookie-name`, the value holds anything but `cookie-octet`s (an `encode_identity` that emits a space, a `;`, or a non-ASCII character), or `max_age` is not a non-negative safe integer — a header that would read back differently is never written
71
+ */
72
+ export declare const format_session_set_cookie: (cookie_name: string, value: string, max_age: number) => string;
32
73
  /**
33
- * Default cookie options for session cookies.
74
+ * Build the `Set-Cookie` header value that clears the session cookie:
75
+ * `<name>=; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=0`, the Rust
76
+ * spine's string.
34
77
  *
35
- * Uses strict security settings:
36
- * - `secure: true` - Works on localhost in Chrome/Firefox (treated as secure context)
37
- * - `sameSite: 'strict'` - Prevents CSRF
38
- * - `httpOnly: true` - Prevents XSS access to cookie
78
+ * @param cookie_name - the session cookie's name
79
+ * @returns the `Set-Cookie` header value
80
+ * @throws Error when the name is not an RFC 6265 `cookie-name`
39
81
  */
40
- export declare const session_cookie_options: SessionCookieOptions;
82
+ export declare const format_session_clear_cookie: (cookie_name: string) => string;
41
83
  /**
42
84
  * Configuration for a session cookie format.
43
85
  *
@@ -85,17 +127,45 @@ export interface SessionOptions<TIdentity> {
85
127
  /**
86
128
  * Cookie lifetime in seconds. Single source of truth for both the embedded
87
129
  * `expires_at` (via `create_session_cookie_value`) and the cookie's HTTP
88
- * `Max-Age` attribute (via `set_session_cookie`). Defaults to
89
- * `SESSION_AGE_MAX` (30 days). The `cookie_options` slot intentionally
90
- * cannot carry `maxAge` so the two values can't drift.
130
+ * `Max-Age` attribute (via `session_cookie_header`). Defaults to
131
+ * `SESSION_AGE_MAX` (30 days). Every other attribute is fixed
132
+ * (`SESSION_COOKIE_ATTRIBUTES`).
91
133
  */
92
134
  max_age?: number;
93
- cookie_options?: Partial<Omit<SessionCookieOptions, 'maxAge'>>;
94
- /** Encode identity into the cookie payload (before the `:expires_at` suffix). */
135
+ /**
136
+ * Encode identity into the cookie payload (before the `:expires_at` suffix).
137
+ * The payload goes into the cookie as written, so it must hold only RFC
138
+ * 6265 `cookie-octet`s (`is_cookie_value`) — `session_cookie_header` throws
139
+ * on anything else.
140
+ */
95
141
  encode_identity: (identity: TIdentity) => string;
96
142
  /** Decode identity from cookie payload. Return null if invalid. */
97
143
  decode_identity: (payload: string) => TIdentity | null;
98
144
  }
145
+ /**
146
+ * The `Set-Cookie` value that sets the session cookie to `value`, a signed
147
+ * cookie value (`create_session_cookie_value`, or the `cookie_value` of
148
+ * `create_capped_session`) — what a success carries
149
+ * (`route_ok(value, {set_cookie: [...]})`). `options.max_age` sets `Max-Age`,
150
+ * as it set the value's embedded expiry; `SESSION_AGE_MAX` when unset. Twin of
151
+ * the Rust `session_cookie_header`, which signs the token itself.
152
+ *
153
+ * @param value - the signed cookie value
154
+ * @param options - the cookie name and lifetime
155
+ * @returns the `Set-Cookie` header value (`format_session_set_cookie`)
156
+ * @throws Error when the cookie name or the value is outside the RFC 6265 grammar
157
+ */
158
+ export declare const session_cookie_header: <T>(value: string, options: SessionOptions<T>) => string;
159
+ /**
160
+ * The `Set-Cookie` value that clears the session cookie — what a logout or a
161
+ * password change carries on its success. Twin of the Rust
162
+ * `clear_session_cookie_header`.
163
+ *
164
+ * @param options - the cookie name
165
+ * @returns the `Set-Cookie` header value (`format_session_clear_cookie`)
166
+ * @throws Error when the cookie name is outside the RFC 6265 grammar
167
+ */
168
+ export declare const clear_session_cookie_header: <T>(options: SessionOptions<T>) => string;
99
169
  /**
100
170
  * Result of parsing a signed session cookie.
101
171
  */
@@ -113,13 +183,17 @@ export interface ParsedSession<TIdentity> {
113
183
  * The signed value format is `${encode(identity)}:${expires_at}`.
114
184
  * Tries all keys in order to support key rotation.
115
185
  *
116
- * @param signed_value - the raw cookie value (signed)
186
+ * An empty string is a cookie that was sent with no value (`name=`): present
187
+ * and invalid, like any other value that fails verification. Only a nullish
188
+ * `signed_value` is "no cookie".
189
+ *
190
+ * @param signed_value - the raw cookie value (signed), nullish when the request carries no session cookie
117
191
  * @param keyring - key ring for verification
118
192
  * @param options - session configuration with decode logic
119
193
  * @param now_seconds - current time in seconds (for testing)
120
- * @returns `ParsedSession` if valid, null if invalid/expired, undefined if empty/missing
194
+ * @returns `ParsedSession` if valid, null if invalid/expired (the empty string included), undefined if missing
121
195
  */
122
- export declare const parse_session: <TIdentity>(signed_value: string | undefined, keyring: Keyring, options: SessionOptions<TIdentity>, now_seconds?: number) => Promise<ParsedSession<TIdentity> | null | undefined>;
196
+ export declare const parse_session: <TIdentity>(signed_value: string | null | undefined, keyring: Keyring, options: SessionOptions<TIdentity>, now_seconds?: number) => Promise<ParsedSession<TIdentity> | null | undefined>;
123
197
  /**
124
198
  * Create a signed session cookie value.
125
199
  *
@@ -171,11 +245,17 @@ export declare const fuz_session_config: SessionOptions<string>;
171
245
  * retired keys are safe to drop after `SESSION_AGE_MAX` (see
172
246
  * `docs/security.md` §Cookie Key Rotation).
173
247
  *
174
- * @param signed_value - the raw cookie value (may be undefined)
248
+ * The three outcomes are what the cookie alone shows: no cookie (`action:
249
+ * 'none'`), a cookie that fails verification — unreadable, a bad MAC, a signed
250
+ * expiry that has passed, an empty identity, an empty value — (`action:
251
+ * 'clear'`), and a valid one. A valid cookie whose `auth_session` row is gone
252
+ * is still valid here; nothing clears it.
253
+ *
254
+ * @param signed_value - the raw cookie value, nullish when the request carries no session cookie
175
255
  * @param keyring - key ring for verification and signing
176
256
  * @param options - session configuration
177
257
  * @param now_seconds - current time in seconds (for testing)
178
258
  * @returns result with validity and action to take
179
259
  */
180
- export declare const process_session_cookie: <TIdentity>(signed_value: string | undefined, keyring: Keyring, options: SessionOptions<TIdentity>, now_seconds?: number) => Promise<ProcessSessionResult<TIdentity>>;
260
+ export declare const process_session_cookie: <TIdentity>(signed_value: string | null | undefined, keyring: Keyring, options: SessionOptions<TIdentity>, now_seconds?: number) => Promise<ProcessSessionResult<TIdentity>>;
181
261
  //# sourceMappingURL=session_cookie.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"session_cookie.d.ts","sourceRoot":"","sources":["../../src/lib/auth/session_cookie.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,QAAoB,CAAC;AAWjD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;IACpC,MAAM,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,EAAE,oBAMpC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,MAAM,WAAW,cAAc,CAAC,SAAS;IACxC,WAAW,EAAE,MAAM,CAAC;IACpB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,oBAAoB,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC/D,iFAAiF;IACjF,eAAe,EAAE,CAAC,QAAQ,EAAE,SAAS,KAAK,MAAM,CAAC;IACjD,mEAAmE;IACnE,eAAe,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,SAAS,GAAG,IAAI,CAAC;CACvD;AAED;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,SAAS;IACvC,4BAA4B;IAC5B,QAAQ,EAAE,SAAS,CAAC;IACpB,kEAAkE;IAClE,SAAS,EAAE,MAAM,CAAC;IAClB,iFAAiF;IACjF,UAAU,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,aAAa,GAAU,SAAS,EAC5C,cAAc,MAAM,GAAG,SAAS,EAChC,SAAS,OAAO,EAChB,SAAS,cAAc,CAAC,SAAS,CAAC,EAClC,cAAc,MAAM,KAClB,OAAO,CAAC,aAAa,CAAC,SAAS,CAAC,GAAG,IAAI,GAAG,SAAS,CAiCrD,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,2BAA2B,GAAU,SAAS,EAC1D,SAAS,OAAO,EAChB,UAAU,SAAS,EACnB,SAAS,cAAc,CAAC,SAAS,CAAC,EAClC,cAAc,MAAM,KAClB,OAAO,CAAC,MAAM,CAMhB,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,oBAAoB,CAAC,SAAS;IAC9C,oCAAoC;IACpC,KAAK,EAAE,OAAO,CAAC;IACf,sCAAsC;IACtC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;IACzB,oDAAoD;IACpD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,0EAA0E;IAC1E,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,qBAAqB,GAAI,aAAa,MAAM,KAAG,cAAc,CAAC,MAAM,CAI/E,CAAC;AAEH,iDAAiD;AACjD,eAAO,MAAM,kBAAkB,EAAE,cAAc,CAAC,MAAM,CAAwC,CAAC;AAE/F;;;;;;;;;;;;;;;;;GAiBG;AAEH,eAAO,MAAM,sBAAsB,GAAU,SAAS,EACrD,cAAc,MAAM,GAAG,SAAS,EAChC,SAAS,OAAO,EAChB,SAAS,cAAc,CAAC,SAAS,CAAC,EAClC,cAAc,MAAM,KAClB,OAAO,CAAC,oBAAoB,CAAC,SAAS,CAAC,CAgBzC,CAAC"}
1
+ {"version":3,"file":"session_cookie.d.ts","sourceRoot":"","sources":["../../src/lib/auth/session_cookie.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,QAAoB,CAAC;AAWjD;;;;;;;;;GASG;AACH,eAAO,MAAM,yBAAyB,8CAA8C,CAAC;AAQrF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,KAAG,OACW,CAAC;AAE1D;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,MAAM,KAAG,OACY,CAAC;AAgB7D;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,yBAAyB,GACrC,aAAa,MAAM,EACnB,OAAO,MAAM,EACb,SAAS,MAAM,KACb,MAeF,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,2BAA2B,GAAI,aAAa,MAAM,KAAG,MAGjE,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,MAAM,WAAW,cAAc,CAAC,SAAS;IACxC,WAAW,EAAE,MAAM,CAAC;IACpB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,eAAe,EAAE,CAAC,QAAQ,EAAE,SAAS,KAAK,MAAM,CAAC;IACjD,mEAAmE;IACnE,eAAe,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,SAAS,GAAG,IAAI,CAAC;CACvD;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,qBAAqB,GAAI,CAAC,EAAE,OAAO,MAAM,EAAE,SAAS,cAAc,CAAC,CAAC,CAAC,KAAG,MACK,CAAC;AAE3F;;;;;;;;GAQG;AACH,eAAO,MAAM,2BAA2B,GAAI,CAAC,EAAE,SAAS,cAAc,CAAC,CAAC,CAAC,KAAG,MAC3B,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,SAAS;IACvC,4BAA4B;IAC5B,QAAQ,EAAE,SAAS,CAAC;IACpB,kEAAkE;IAClE,SAAS,EAAE,MAAM,CAAC;IAClB,iFAAiF;IACjF,UAAU,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,aAAa,GAAU,SAAS,EAC5C,cAAc,MAAM,GAAG,IAAI,GAAG,SAAS,EACvC,SAAS,OAAO,EAChB,SAAS,cAAc,CAAC,SAAS,CAAC,EAClC,cAAc,MAAM,KAClB,OAAO,CAAC,aAAa,CAAC,SAAS,CAAC,GAAG,IAAI,GAAG,SAAS,CAiCrD,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,2BAA2B,GAAU,SAAS,EAC1D,SAAS,OAAO,EAChB,UAAU,SAAS,EACnB,SAAS,cAAc,CAAC,SAAS,CAAC,EAClC,cAAc,MAAM,KAClB,OAAO,CAAC,MAAM,CAMhB,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,oBAAoB,CAAC,SAAS;IAC9C,oCAAoC;IACpC,KAAK,EAAE,OAAO,CAAC;IACf,sCAAsC;IACtC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;IACzB,oDAAoD;IACpD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,0EAA0E;IAC1E,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,qBAAqB,GAAI,aAAa,MAAM,KAAG,cAAc,CAAC,MAAM,CAI/E,CAAC;AAEH,iDAAiD;AACjD,eAAO,MAAM,kBAAkB,EAAE,cAAc,CAAC,MAAM,CAAwC,CAAC;AAE/F;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,eAAO,MAAM,sBAAsB,GAAU,SAAS,EACrD,cAAc,MAAM,GAAG,IAAI,GAAG,SAAS,EACvC,SAAS,OAAO,EAChB,SAAS,cAAc,CAAC,SAAS,CAAC,EAClC,cAAc,MAAM,KAClB,OAAO,CAAC,oBAAoB,CAAC,SAAS,CAAC,CAgBzC,CAAC"}
@@ -25,34 +25,137 @@ const EXPIRES_AT_INTEGER_RE = /^\d+$/;
25
25
  /** The largest `expires_at` the Rust spine's `u64` parse accepts. */
26
26
  const EXPIRES_AT_MAX = 18446744073709551615n;
27
27
  /**
28
- * Default cookie options for session cookies.
28
+ * The attributes every session `Set-Cookie` carries, in the order written —
29
+ * the Rust spine's `SESSION_COOKIE_ATTRIBUTES`, byte for byte. Fixed: the
30
+ * spine writes one cookie.
29
31
  *
30
- * Uses strict security settings:
31
- * - `secure: true` - Works on localhost in Chrome/Firefox (treated as secure context)
32
- * - `sameSite: 'strict'` - Prevents CSRF
33
- * - `httpOnly: true` - Prevents XSS access to cookie
32
+ * - `Path=/` - sent to every path of the origin
33
+ * - `HttpOnly` - out of reach of page script
34
+ * - `Secure` - HTTPS only (Chrome and Firefox treat `localhost` as secure)
35
+ * - `SameSite=Strict` - never sent on a cross-site request
34
36
  */
35
- export const session_cookie_options = {
36
- path: '/',
37
- httpOnly: true,
38
- secure: true,
39
- sameSite: 'strict',
40
- maxAge: SESSION_AGE_MAX
37
+ export const SESSION_COOKIE_ATTRIBUTES = 'Path=/; HttpOnly; Secure; SameSite=Strict';
38
+ /** RFC 6265's `cookie-name`: an RFC 2616 `token`, one or more characters. */
39
+ const COOKIE_NAME_REGEX = /^[!#$%&'*+\-.0-9A-Z^_`a-z|~]+$/;
40
+ /** RFC 6265's unquoted `cookie-value`: zero or more `cookie-octet`s. */
41
+ const COOKIE_VALUE_REGEX = /^[\x21\x23-\x2B\x2D-\x3A\x3C-\x5B\x5D-\x7E]*$/;
42
+ /**
43
+ * Whether `name` is an RFC 6265 `cookie-name` — an HTTP `token`: visible
44
+ * ASCII less the separators (`=`, `;`, `,`, space, quotes, brackets and the
45
+ * rest). Twin of the Rust spine's `is_cookie_name`.
46
+ *
47
+ * Anything but a string is refused, whatever its type says: the name is a
48
+ * consumer's option, and a regex alone would read `undefined` as the text
49
+ * `undefined`.
50
+ *
51
+ * @param name - a cookie name
52
+ */
53
+ export const is_cookie_name = (name) => typeof name === 'string' && COOKIE_NAME_REGEX.test(name);
54
+ /**
55
+ * Whether `value` is an RFC 6265 `cookie-value` in its unquoted form — only
56
+ * `cookie-octet`s: visible ASCII less `"`, `,`, `;` and `\`. Such a value
57
+ * reads back out of a `Cookie` header exactly as it was written, which is
58
+ * what a reader that decodes nothing needs. Twin of the Rust spine's
59
+ * `is_cookie_value`.
60
+ *
61
+ * Anything but a string is refused, whatever its type says: the value comes
62
+ * out of a consumer's `encode_identity` and keyring, and a regex alone would
63
+ * read `undefined` as the text `undefined`.
64
+ *
65
+ * @param value - a cookie value
66
+ */
67
+ export const is_cookie_value = (value) => typeof value === 'string' && COOKIE_VALUE_REGEX.test(value);
68
+ /**
69
+ * Refuse a session cookie name the `Cookie` grammar cannot carry.
70
+ *
71
+ * @param cookie_name - the session cookie's name
72
+ * @throws Error when `cookie_name` is not an RFC 6265 `cookie-name`
73
+ */
74
+ const assert_cookie_name = (cookie_name) => {
75
+ if (!is_cookie_name(cookie_name)) {
76
+ throw new Error(`session cookie name ${JSON.stringify(cookie_name)} is not an RFC 6265 cookie-name`);
77
+ }
78
+ };
79
+ /**
80
+ * Build the `Set-Cookie` header value that sets the session cookie:
81
+ * `<name>=<value>; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=<max_age>`,
82
+ * the Rust spine's string. The value is written as given — never
83
+ * percent-encoded or quoted — so the cookie either spine mints verifies on
84
+ * both.
85
+ *
86
+ * @param cookie_name - the session cookie's name
87
+ * @param value - the signed cookie value (`create_session_cookie_value`)
88
+ * @param max_age - the cookie's lifetime in seconds
89
+ * @returns the `Set-Cookie` header value
90
+ * @throws Error when the name is not an RFC 6265 `cookie-name`, the value holds anything but `cookie-octet`s (an `encode_identity` that emits a space, a `;`, or a non-ASCII character), or `max_age` is not a non-negative safe integer — a header that would read back differently is never written
91
+ */
92
+ export const format_session_set_cookie = (cookie_name, value, max_age) => {
93
+ assert_cookie_name(cookie_name);
94
+ if (!is_cookie_value(value)) {
95
+ // the value is a credential: say what is wrong with it, never what it is
96
+ throw new Error(`session cookie '${cookie_name}': the signed value holds a character outside RFC 6265's ` +
97
+ 'cookie-octets — `encode_identity` must emit only visible ASCII without `"`, `,`, `;` or `\\`');
98
+ }
99
+ if (!Number.isSafeInteger(max_age) || max_age < 0) {
100
+ throw new Error(`session cookie '${cookie_name}': max_age ${max_age} is not a whole number of seconds`);
101
+ }
102
+ return `${cookie_name}=${value}; ${SESSION_COOKIE_ATTRIBUTES}; Max-Age=${max_age}`;
103
+ };
104
+ /**
105
+ * Build the `Set-Cookie` header value that clears the session cookie:
106
+ * `<name>=; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=0`, the Rust
107
+ * spine's string.
108
+ *
109
+ * @param cookie_name - the session cookie's name
110
+ * @returns the `Set-Cookie` header value
111
+ * @throws Error when the name is not an RFC 6265 `cookie-name`
112
+ */
113
+ export const format_session_clear_cookie = (cookie_name) => {
114
+ assert_cookie_name(cookie_name);
115
+ return `${cookie_name}=; ${SESSION_COOKIE_ATTRIBUTES}; Max-Age=0`;
41
116
  };
117
+ /**
118
+ * The `Set-Cookie` value that sets the session cookie to `value`, a signed
119
+ * cookie value (`create_session_cookie_value`, or the `cookie_value` of
120
+ * `create_capped_session`) — what a success carries
121
+ * (`route_ok(value, {set_cookie: [...]})`). `options.max_age` sets `Max-Age`,
122
+ * as it set the value's embedded expiry; `SESSION_AGE_MAX` when unset. Twin of
123
+ * the Rust `session_cookie_header`, which signs the token itself.
124
+ *
125
+ * @param value - the signed cookie value
126
+ * @param options - the cookie name and lifetime
127
+ * @returns the `Set-Cookie` header value (`format_session_set_cookie`)
128
+ * @throws Error when the cookie name or the value is outside the RFC 6265 grammar
129
+ */
130
+ export const session_cookie_header = (value, options) => format_session_set_cookie(options.cookie_name, value, options.max_age ?? SESSION_AGE_MAX);
131
+ /**
132
+ * The `Set-Cookie` value that clears the session cookie — what a logout or a
133
+ * password change carries on its success. Twin of the Rust
134
+ * `clear_session_cookie_header`.
135
+ *
136
+ * @param options - the cookie name
137
+ * @returns the `Set-Cookie` header value (`format_session_clear_cookie`)
138
+ * @throws Error when the cookie name is outside the RFC 6265 grammar
139
+ */
140
+ export const clear_session_cookie_header = (options) => format_session_clear_cookie(options.cookie_name);
42
141
  /**
43
142
  * Parse a signed session cookie value.
44
143
  *
45
144
  * The signed value format is `${encode(identity)}:${expires_at}`.
46
145
  * Tries all keys in order to support key rotation.
47
146
  *
48
- * @param signed_value - the raw cookie value (signed)
147
+ * An empty string is a cookie that was sent with no value (`name=`): present
148
+ * and invalid, like any other value that fails verification. Only a nullish
149
+ * `signed_value` is "no cookie".
150
+ *
151
+ * @param signed_value - the raw cookie value (signed), nullish when the request carries no session cookie
49
152
  * @param keyring - key ring for verification
50
153
  * @param options - session configuration with decode logic
51
154
  * @param now_seconds - current time in seconds (for testing)
52
- * @returns `ParsedSession` if valid, null if invalid/expired, undefined if empty/missing
155
+ * @returns `ParsedSession` if valid, null if invalid/expired (the empty string included), undefined if missing
53
156
  */
54
157
  export const parse_session = async (signed_value, keyring, options, now_seconds) => {
55
- if (!signed_value)
158
+ if (signed_value == null)
56
159
  return undefined;
57
160
  const result = await keyring.verify(signed_value);
58
161
  if (!result)
@@ -133,7 +236,13 @@ export const fuz_session_config = create_session_config('fuz_session');
133
236
  * retired keys are safe to drop after `SESSION_AGE_MAX` (see
134
237
  * `docs/security.md` §Cookie Key Rotation).
135
238
  *
136
- * @param signed_value - the raw cookie value (may be undefined)
239
+ * The three outcomes are what the cookie alone shows: no cookie (`action:
240
+ * 'none'`), a cookie that fails verification — unreadable, a bad MAC, a signed
241
+ * expiry that has passed, an empty identity, an empty value — (`action:
242
+ * 'clear'`), and a valid one. A valid cookie whose `auth_session` row is gone
243
+ * is still valid here; nothing clears it.
244
+ *
245
+ * @param signed_value - the raw cookie value, nullish when the request carries no session cookie
137
246
  * @param keyring - key ring for verification and signing
138
247
  * @param options - session configuration
139
248
  * @param now_seconds - current time in seconds (for testing)