@fuzdev/fuz_app 0.149.0 → 0.151.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 (650) hide show
  1. package/README.md +1 -1
  2. package/dist/actions/CLAUDE.md +327 -300
  3. package/dist/actions/action_bridge.d.ts +5 -79
  4. package/dist/actions/action_bridge.d.ts.map +1 -1
  5. package/dist/actions/action_bridge.js +4 -74
  6. package/dist/actions/action_codegen.d.ts +8 -166
  7. package/dist/actions/action_codegen.d.ts.map +1 -1
  8. package/dist/actions/action_codegen.js +19 -95
  9. package/dist/actions/action_dispatcher.d.ts +10 -0
  10. package/dist/actions/action_dispatcher.d.ts.map +1 -1
  11. package/dist/actions/action_dispatcher.js +9 -6
  12. package/dist/actions/action_event.d.ts +1 -2
  13. package/dist/actions/action_event.d.ts.map +1 -1
  14. package/dist/actions/action_event.js +7 -13
  15. package/dist/actions/action_event_helpers.d.ts +1 -40
  16. package/dist/actions/action_event_helpers.d.ts.map +1 -1
  17. package/dist/actions/action_event_helpers.js +1 -25
  18. package/dist/actions/action_event_types.d.ts +1 -1
  19. package/dist/actions/action_event_types.d.ts.map +1 -1
  20. package/dist/actions/action_rpc.d.ts +10 -215
  21. package/dist/actions/action_rpc.d.ts.map +1 -1
  22. package/dist/actions/action_rpc.js +56 -111
  23. package/dist/actions/action_spec.d.ts +2 -2
  24. package/dist/actions/action_spec.js +2 -2
  25. package/dist/actions/action_types.d.ts +229 -8
  26. package/dist/actions/action_types.d.ts.map +1 -1
  27. package/dist/actions/action_types.js +56 -5
  28. package/dist/actions/broadcast_api.d.ts +22 -17
  29. package/dist/actions/broadcast_api.d.ts.map +1 -1
  30. package/dist/actions/broadcast_api.js +16 -27
  31. package/dist/actions/cancel.d.ts +4 -13
  32. package/dist/actions/cancel.d.ts.map +1 -1
  33. package/dist/actions/cancel.js +5 -17
  34. package/dist/actions/compile_action_registry.d.ts +1 -2
  35. package/dist/actions/compile_action_registry.d.ts.map +1 -1
  36. package/dist/actions/connection_closer.d.ts +120 -50
  37. package/dist/actions/connection_closer.d.ts.map +1 -1
  38. package/dist/actions/connection_closer.js +139 -31
  39. package/dist/actions/{transports_ws_backend.d.ts → connection_registry.d.ts} +120 -132
  40. package/dist/actions/connection_registry.d.ts.map +1 -0
  41. package/dist/actions/{transports_ws_backend.js → connection_registry.js} +149 -152
  42. package/dist/actions/frontend_rpc_client.d.ts +52 -2
  43. package/dist/actions/frontend_rpc_client.d.ts.map +1 -1
  44. package/dist/actions/frontend_rpc_client.js +42 -4
  45. package/dist/actions/peer_ping.d.ts +7 -9
  46. package/dist/actions/peer_ping.d.ts.map +1 -1
  47. package/dist/actions/peer_ping.js +6 -8
  48. package/dist/actions/peer_request.d.ts +6 -5
  49. package/dist/actions/peer_request.d.ts.map +1 -1
  50. package/dist/actions/peer_request.js +6 -5
  51. package/dist/actions/perform_action.d.ts +36 -28
  52. package/dist/actions/perform_action.d.ts.map +1 -1
  53. package/dist/actions/perform_action.js +60 -31
  54. package/dist/actions/protocol.d.ts +14 -0
  55. package/dist/actions/protocol.d.ts.map +1 -1
  56. package/dist/actions/protocol.js +18 -0
  57. package/dist/actions/register_action_ws.d.ts +137 -292
  58. package/dist/actions/register_action_ws.d.ts.map +1 -1
  59. package/dist/actions/register_action_ws.js +155 -903
  60. package/dist/actions/socket.svelte.d.ts +9 -0
  61. package/dist/actions/socket.svelte.d.ts.map +1 -1
  62. package/dist/actions/socket.svelte.js +16 -5
  63. package/dist/actions/transports.d.ts +88 -34
  64. package/dist/actions/transports.d.ts.map +1 -1
  65. package/dist/actions/transports.js +76 -76
  66. package/dist/actions/transports_http.d.ts +48 -12
  67. package/dist/actions/transports_http.d.ts.map +1 -1
  68. package/dist/actions/transports_http.js +75 -44
  69. package/dist/actions/transports_ws.d.ts +29 -0
  70. package/dist/actions/transports_ws.d.ts.map +1 -1
  71. package/dist/actions/transports_ws.js +34 -8
  72. package/dist/actions/ws_endpoint_spec.d.ts +53 -76
  73. package/dist/actions/ws_endpoint_spec.d.ts.map +1 -1
  74. package/dist/actions/ws_endpoint_spec.js +27 -10
  75. package/dist/actions/ws_outbound_writer.d.ts +3 -3
  76. package/dist/actions/ws_outbound_writer.js +3 -3
  77. package/dist/actions/ws_socket_session.d.ts +321 -0
  78. package/dist/actions/ws_socket_session.d.ts.map +1 -0
  79. package/dist/actions/ws_socket_session.js +783 -0
  80. package/dist/auth/CLAUDE.md +132 -68
  81. package/dist/auth/account_action_specs.d.ts +2 -0
  82. package/dist/auth/account_action_specs.d.ts.map +1 -1
  83. package/dist/auth/account_actions.d.ts +1 -1
  84. package/dist/auth/account_actions.d.ts.map +1 -1
  85. package/dist/auth/account_actions.js +9 -3
  86. package/dist/auth/account_queries.d.ts +10 -0
  87. package/dist/auth/account_queries.d.ts.map +1 -1
  88. package/dist/auth/account_queries.js +27 -17
  89. package/dist/auth/account_routes.d.ts +2 -1
  90. package/dist/auth/account_routes.d.ts.map +1 -1
  91. package/dist/auth/account_routes.js +14 -17
  92. package/dist/auth/account_schema.d.ts +5 -5
  93. package/dist/auth/account_schema.d.ts.map +1 -1
  94. package/dist/auth/account_schema.js +5 -2
  95. package/dist/auth/actor_lookup_actions.d.ts +1 -1
  96. package/dist/auth/actor_lookup_actions.d.ts.map +1 -1
  97. package/dist/auth/actor_lookup_actions.js +1 -1
  98. package/dist/auth/actor_lookup_queries.d.ts +3 -2
  99. package/dist/auth/actor_lookup_queries.d.ts.map +1 -1
  100. package/dist/auth/actor_lookup_queries.js +6 -3
  101. package/dist/auth/actor_search_action_specs.d.ts.map +1 -1
  102. package/dist/auth/actor_search_action_specs.js +2 -1
  103. package/dist/auth/actor_search_actions.d.ts +1 -1
  104. package/dist/auth/actor_search_actions.d.ts.map +1 -1
  105. package/dist/auth/actor_search_actions.js +1 -1
  106. package/dist/auth/actor_search_queries.d.ts +10 -7
  107. package/dist/auth/actor_search_queries.d.ts.map +1 -1
  108. package/dist/auth/actor_search_queries.js +18 -11
  109. package/dist/auth/admin_action_specs.d.ts +4 -4
  110. package/dist/auth/admin_action_specs.d.ts.map +1 -1
  111. package/dist/auth/admin_action_specs.js +7 -5
  112. package/dist/auth/admin_actions.d.ts +1 -1
  113. package/dist/auth/admin_actions.d.ts.map +1 -1
  114. package/dist/auth/admin_actions.js +47 -48
  115. package/dist/auth/all_cell_actions.d.ts +14 -3
  116. package/dist/auth/all_cell_actions.d.ts.map +1 -1
  117. package/dist/auth/all_cell_actions.js +2 -1
  118. package/dist/auth/api_token_queries.d.ts +1 -0
  119. package/dist/auth/api_token_queries.d.ts.map +1 -1
  120. package/dist/auth/api_token_queries.js +1 -0
  121. package/dist/auth/audit_emitter.d.ts +12 -6
  122. package/dist/auth/audit_emitter.d.ts.map +1 -1
  123. package/dist/auth/audit_emitter.js +11 -5
  124. package/dist/auth/audit_log_route_schema.d.ts.map +1 -1
  125. package/dist/auth/audit_log_route_schema.js +3 -2
  126. package/dist/auth/audit_log_routes.d.ts +20 -11
  127. package/dist/auth/audit_log_routes.d.ts.map +1 -1
  128. package/dist/auth/audit_log_routes.js +49 -29
  129. package/dist/auth/audit_log_schema.d.ts +14 -21
  130. package/dist/auth/audit_log_schema.d.ts.map +1 -1
  131. package/dist/auth/audit_log_schema.js +19 -23
  132. package/dist/auth/bearer_auth.d.ts +7 -4
  133. package/dist/auth/bearer_auth.d.ts.map +1 -1
  134. package/dist/auth/bearer_auth.js +21 -15
  135. package/dist/auth/bootstrap_account.d.ts +25 -1
  136. package/dist/auth/bootstrap_account.d.ts.map +1 -1
  137. package/dist/auth/bootstrap_account.js +37 -4
  138. package/dist/auth/bootstrap_routes.d.ts +3 -2
  139. package/dist/auth/bootstrap_routes.d.ts.map +1 -1
  140. package/dist/auth/bootstrap_routes.js +5 -4
  141. package/dist/auth/cell_action_helpers.d.ts +89 -0
  142. package/dist/auth/cell_action_helpers.d.ts.map +1 -0
  143. package/dist/auth/cell_action_helpers.js +113 -0
  144. package/dist/auth/cell_action_specs.d.ts +215 -15
  145. package/dist/auth/cell_action_specs.d.ts.map +1 -1
  146. package/dist/auth/cell_action_specs.js +103 -16
  147. package/dist/auth/cell_actions.d.ts +58 -27
  148. package/dist/auth/cell_actions.d.ts.map +1 -1
  149. package/dist/auth/cell_actions.js +206 -161
  150. package/dist/auth/cell_audit_actions.d.ts +1 -1
  151. package/dist/auth/cell_audit_actions.d.ts.map +1 -1
  152. package/dist/auth/cell_audit_actions.js +3 -12
  153. package/dist/auth/cell_audit_events.d.ts +1 -1
  154. package/dist/auth/cell_audit_events.d.ts.map +1 -1
  155. package/dist/auth/cell_audit_events.js +3 -2
  156. package/dist/auth/cell_audit_metadata.d.ts +12 -1
  157. package/dist/auth/cell_audit_metadata.d.ts.map +1 -1
  158. package/dist/auth/cell_audit_metadata.js +11 -1
  159. package/dist/auth/cell_field_actions.d.ts +1 -1
  160. package/dist/auth/cell_field_actions.d.ts.map +1 -1
  161. package/dist/auth/cell_field_actions.js +16 -66
  162. package/dist/auth/cell_grant_action_specs.d.ts +9 -2
  163. package/dist/auth/cell_grant_action_specs.d.ts.map +1 -1
  164. package/dist/auth/cell_grant_action_specs.js +10 -3
  165. package/dist/auth/cell_grant_actions.d.ts +105 -11
  166. package/dist/auth/cell_grant_actions.d.ts.map +1 -1
  167. package/dist/auth/cell_grant_actions.js +81 -56
  168. package/dist/auth/cell_grant_audit_metadata.d.ts +6 -3
  169. package/dist/auth/cell_grant_audit_metadata.d.ts.map +1 -1
  170. package/dist/auth/cell_grant_audit_metadata.js +7 -4
  171. package/dist/auth/cell_item_actions.d.ts +1 -1
  172. package/dist/auth/cell_item_actions.d.ts.map +1 -1
  173. package/dist/auth/cell_item_actions.js +21 -82
  174. package/dist/auth/cleanup.d.ts +1 -1
  175. package/dist/auth/cleanup.d.ts.map +1 -1
  176. package/dist/auth/cleanup.js +6 -3
  177. package/dist/auth/credential_deadline.d.ts +3 -3
  178. package/dist/auth/credential_deadline.js +3 -3
  179. package/dist/auth/credential_type_schema.d.ts +8 -7
  180. package/dist/auth/credential_type_schema.d.ts.map +1 -1
  181. package/dist/auth/credential_type_schema.js +8 -7
  182. package/dist/auth/daemon_token_middleware.d.ts +12 -6
  183. package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
  184. package/dist/auth/daemon_token_middleware.js +28 -17
  185. package/dist/auth/deps.d.ts +4 -4
  186. package/dist/auth/fail_floor.d.ts +55 -0
  187. package/dist/auth/fail_floor.d.ts.map +1 -0
  188. package/dist/auth/fail_floor.js +63 -0
  189. package/dist/auth/invite_queries.d.ts +3 -15
  190. package/dist/auth/invite_queries.d.ts.map +1 -1
  191. package/dist/auth/invite_queries.js +3 -21
  192. package/dist/auth/middleware.d.ts +12 -7
  193. package/dist/auth/middleware.d.ts.map +1 -1
  194. package/dist/auth/middleware.js +42 -29
  195. package/dist/auth/migrations.d.ts +5 -33
  196. package/dist/auth/migrations.d.ts.map +1 -1
  197. package/dist/auth/migrations.js +9 -16
  198. package/dist/auth/request_context.d.ts +101 -71
  199. package/dist/auth/request_context.d.ts.map +1 -1
  200. package/dist/auth/request_context.js +137 -140
  201. package/dist/auth/resolved_auth.d.ts +122 -36
  202. package/dist/auth/resolved_auth.d.ts.map +1 -1
  203. package/dist/auth/resolved_auth.js +89 -38
  204. package/dist/auth/role_grant_offer_action_specs.d.ts +117 -16
  205. package/dist/auth/role_grant_offer_action_specs.d.ts.map +1 -1
  206. package/dist/auth/role_grant_offer_action_specs.js +51 -16
  207. package/dist/auth/role_grant_offer_actions.d.ts +22 -11
  208. package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
  209. package/dist/auth/role_grant_offer_actions.js +72 -19
  210. package/dist/auth/role_grant_offer_notifications.d.ts +6 -5
  211. package/dist/auth/role_grant_offer_notifications.d.ts.map +1 -1
  212. package/dist/auth/role_grant_offer_notifications.js +4 -3
  213. package/dist/auth/role_grant_offer_queries.d.ts +20 -5
  214. package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
  215. package/dist/auth/role_grant_offer_queries.js +40 -37
  216. package/dist/auth/role_grant_queries.d.ts +44 -76
  217. package/dist/auth/role_grant_queries.d.ts.map +1 -1
  218. package/dist/auth/role_grant_queries.js +73 -118
  219. package/dist/auth/role_grant_sql.d.ts +42 -0
  220. package/dist/auth/role_grant_sql.d.ts.map +1 -0
  221. package/dist/auth/role_grant_sql.js +54 -0
  222. package/dist/auth/role_schema.d.ts +14 -8
  223. package/dist/auth/role_schema.d.ts.map +1 -1
  224. package/dist/auth/role_schema.js +6 -3
  225. package/dist/auth/scope_kind_schema.d.ts +1 -1
  226. package/dist/auth/scope_kind_schema.js +1 -1
  227. package/dist/auth/self_service_role_actions.d.ts +1 -1
  228. package/dist/auth/self_service_role_actions.d.ts.map +1 -1
  229. package/dist/auth/self_service_role_actions.js +21 -1
  230. package/dist/auth/session_queries.d.ts +2 -1
  231. package/dist/auth/session_queries.d.ts.map +1 -1
  232. package/dist/auth/session_queries.js +2 -1
  233. package/dist/auth/signup_routes.d.ts +2 -1
  234. package/dist/auth/signup_routes.d.ts.map +1 -1
  235. package/dist/auth/signup_routes.js +14 -13
  236. package/dist/auth/standard_rpc_actions.d.ts +1 -1
  237. package/dist/auth/standard_rpc_actions.d.ts.map +1 -1
  238. package/dist/auth/token_scope.d.ts +19 -46
  239. package/dist/auth/token_scope.d.ts.map +1 -1
  240. package/dist/auth/token_scope.js +23 -41
  241. package/dist/db/CLAUDE.md +18 -6
  242. package/dist/db/cell_ddl.d.ts +5 -134
  243. package/dist/db/cell_ddl.d.ts.map +1 -1
  244. package/dist/db/cell_ddl.js +28 -17
  245. package/dist/db/cell_field_queries.d.ts +0 -13
  246. package/dist/db/cell_field_queries.d.ts.map +1 -1
  247. package/dist/db/cell_field_queries.js +0 -16
  248. package/dist/db/cell_grant_queries.d.ts +10 -5
  249. package/dist/db/cell_grant_queries.d.ts.map +1 -1
  250. package/dist/db/cell_grant_queries.js +13 -7
  251. package/dist/db/cell_item_queries.d.ts +0 -7
  252. package/dist/db/cell_item_queries.d.ts.map +1 -1
  253. package/dist/db/cell_item_queries.js +0 -10
  254. package/dist/db/cell_queries.d.ts +65 -55
  255. package/dist/db/cell_queries.d.ts.map +1 -1
  256. package/dist/db/cell_queries.js +85 -62
  257. package/dist/db/cell_view_sql.d.ts +1 -6
  258. package/dist/db/cell_view_sql.d.ts.map +1 -1
  259. package/dist/db/cell_view_sql.js +1 -2
  260. package/dist/db/fact_ddl.d.ts +5 -30
  261. package/dist/db/fact_ddl.d.ts.map +1 -1
  262. package/dist/db/fact_ddl.js +14 -13
  263. package/dist/db/fact_store.d.ts +11 -0
  264. package/dist/db/fact_store.d.ts.map +1 -1
  265. package/dist/db/fact_store.js +4 -1
  266. package/dist/db/migrate.d.ts +44 -6
  267. package/dist/db/migrate.d.ts.map +1 -1
  268. package/dist/db/migrate.js +63 -4
  269. package/dist/dev/setup.d.ts +18 -14
  270. package/dist/dev/setup.d.ts.map +1 -1
  271. package/dist/dev/setup.js +42 -39
  272. package/dist/env/dotenv.d.ts +2 -2
  273. package/dist/env/dotenv.js +2 -2
  274. package/dist/env/update_env_variable.d.ts +33 -21
  275. package/dist/env/update_env_variable.d.ts.map +1 -1
  276. package/dist/env/update_env_variable.js +54 -35
  277. package/dist/hono_context.d.ts +15 -90
  278. package/dist/hono_context.d.ts.map +1 -1
  279. package/dist/hono_context.js +9 -56
  280. package/dist/http/CLAUDE.md +35 -20
  281. package/dist/http/auth_shape.d.ts +1 -8
  282. package/dist/http/auth_shape.d.ts.map +1 -1
  283. package/dist/http/auth_shape.js +6 -12
  284. package/dist/http/body_limit.d.ts +3 -1
  285. package/dist/http/body_limit.d.ts.map +1 -1
  286. package/dist/http/body_limit.js +6 -1
  287. package/dist/http/common_routes.d.ts.map +1 -1
  288. package/dist/http/common_routes.js +3 -2
  289. package/dist/http/db_routes.d.ts +3 -3
  290. package/dist/http/db_routes.js +3 -3
  291. package/dist/http/error_schemas.d.ts +1 -2
  292. package/dist/http/error_schemas.d.ts.map +1 -1
  293. package/dist/http/error_schemas.js +1 -2
  294. package/dist/http/health_schema.d.ts +16 -0
  295. package/dist/http/health_schema.d.ts.map +1 -0
  296. package/dist/http/health_schema.js +12 -0
  297. package/dist/http/jsonrpc.d.ts +9 -0
  298. package/dist/http/jsonrpc.d.ts.map +1 -1
  299. package/dist/http/jsonrpc.js +17 -0
  300. package/dist/http/jsonrpc_errors.d.ts +22 -2
  301. package/dist/http/jsonrpc_errors.d.ts.map +1 -1
  302. package/dist/http/jsonrpc_errors.js +70 -23
  303. package/dist/http/jsonrpc_helpers.d.ts +60 -17
  304. package/dist/http/jsonrpc_helpers.d.ts.map +1 -1
  305. package/dist/http/jsonrpc_helpers.js +67 -25
  306. package/dist/http/origin.d.ts +30 -1
  307. package/dist/http/origin.d.ts.map +1 -1
  308. package/dist/http/origin.js +46 -9
  309. package/dist/http/origin_wildcard.d.ts +97 -0
  310. package/dist/http/origin_wildcard.d.ts.map +1 -0
  311. package/dist/http/origin_wildcard.js +142 -0
  312. package/dist/http/pending_effects.d.ts +28 -0
  313. package/dist/http/pending_effects.d.ts.map +1 -1
  314. package/dist/http/pending_effects.js +32 -1
  315. package/dist/http/proxy.d.ts +4 -2
  316. package/dist/http/proxy.d.ts.map +1 -1
  317. package/dist/http/proxy.js +7 -2
  318. package/dist/http/route_spec.d.ts +4 -3
  319. package/dist/http/route_spec.d.ts.map +1 -1
  320. package/dist/http/route_spec.js +54 -45
  321. package/dist/http/surface.d.ts +4 -2
  322. package/dist/http/surface.d.ts.map +1 -1
  323. package/dist/http/surface.js +7 -4
  324. package/dist/http/surface_query.d.ts +9 -50
  325. package/dist/http/surface_query.d.ts.map +1 -1
  326. package/dist/http/surface_query.js +48 -94
  327. package/dist/realtime/audit_log_sse.d.ts +180 -0
  328. package/dist/realtime/audit_log_sse.d.ts.map +1 -0
  329. package/dist/realtime/audit_log_sse.js +154 -0
  330. package/dist/realtime/sse.d.ts +21 -6
  331. package/dist/realtime/sse.d.ts.map +1 -1
  332. package/dist/realtime/sse.js +33 -10
  333. package/dist/realtime/sse_constants.d.ts +29 -2
  334. package/dist/realtime/sse_constants.d.ts.map +1 -1
  335. package/dist/realtime/sse_constants.js +35 -2
  336. package/dist/realtime/{subscriber_registry.d.ts → sse_registry.d.ts} +12 -12
  337. package/dist/realtime/sse_registry.d.ts.map +1 -0
  338. package/dist/realtime/{subscriber_registry.js → sse_registry.js} +4 -4
  339. package/dist/schema_meta.d.ts +52 -1
  340. package/dist/schema_meta.d.ts.map +1 -1
  341. package/dist/schema_meta.js +123 -6
  342. package/dist/sensitivity.d.ts +9 -3
  343. package/dist/sensitivity.d.ts.map +1 -1
  344. package/dist/sensitivity.js +3 -2
  345. package/dist/server/app_backend.d.ts +8 -5
  346. package/dist/server/app_backend.d.ts.map +1 -1
  347. package/dist/server/app_backend.js +6 -12
  348. package/dist/server/app_server.d.ts +73 -54
  349. package/dist/server/app_server.d.ts.map +1 -1
  350. package/dist/server/app_server.js +115 -78
  351. package/dist/server/app_server_context.d.ts +1 -1
  352. package/dist/server/app_server_context.d.ts.map +1 -1
  353. package/dist/server/env.d.ts +24 -20
  354. package/dist/server/env.d.ts.map +1 -1
  355. package/dist/server/env.js +24 -34
  356. package/dist/server/serve_fact_route.d.ts +12 -16
  357. package/dist/server/serve_fact_route.d.ts.map +1 -1
  358. package/dist/server/serve_fact_route.js +59 -34
  359. package/dist/server/static.d.ts.map +1 -1
  360. package/dist/server/static.js +2 -2
  361. package/dist/testing/CLAUDE.md +213 -179
  362. package/dist/testing/admin_integration.d.ts.map +1 -1
  363. package/dist/testing/admin_integration.js +10 -19
  364. package/dist/testing/adversarial_headers.d.ts.map +1 -1
  365. package/dist/testing/adversarial_headers.js +8 -0
  366. package/dist/testing/app_server.d.ts +9 -75
  367. package/dist/testing/app_server.d.ts.map +1 -1
  368. package/dist/testing/app_server.js +31 -112
  369. package/dist/testing/attack_surface.d.ts.map +1 -1
  370. package/dist/testing/attack_surface.js +3 -4
  371. package/dist/testing/audit_completeness.d.ts.map +1 -1
  372. package/dist/testing/audit_completeness.js +4 -5
  373. package/dist/testing/auth_apps.d.ts +3 -3
  374. package/dist/testing/auth_apps.d.ts.map +1 -1
  375. package/dist/testing/auth_apps.js +9 -6
  376. package/dist/testing/connection_closer_helpers.d.ts +8 -16
  377. package/dist/testing/connection_closer_helpers.d.ts.map +1 -1
  378. package/dist/testing/connection_closer_helpers.js +7 -20
  379. package/dist/testing/cross_backend/action_manifest.d.ts +15 -4
  380. package/dist/testing/cross_backend/action_manifest.d.ts.map +1 -1
  381. package/dist/testing/cross_backend/action_manifest.js +13 -3
  382. package/dist/testing/cross_backend/action_manifest_parity.d.ts +15 -7
  383. package/dist/testing/cross_backend/action_manifest_parity.d.ts.map +1 -1
  384. package/dist/testing/cross_backend/action_manifest_parity.js +8 -1
  385. package/dist/testing/cross_backend/actor_lookup.d.ts.map +1 -1
  386. package/dist/testing/cross_backend/actor_lookup.js +27 -0
  387. package/dist/testing/cross_backend/body_size.d.ts.map +1 -1
  388. package/dist/testing/cross_backend/body_size.js +25 -22
  389. package/dist/testing/cross_backend/build_test_backend_paths.d.ts +22 -3
  390. package/dist/testing/cross_backend/build_test_backend_paths.d.ts.map +1 -1
  391. package/dist/testing/cross_backend/build_test_backend_paths.js +34 -11
  392. package/dist/testing/cross_backend/capabilities.d.ts +15 -8
  393. package/dist/testing/cross_backend/capabilities.d.ts.map +1 -1
  394. package/dist/testing/cross_backend/cell_gated_create.d.ts.map +1 -1
  395. package/dist/testing/cross_backend/cell_gated_create.js +109 -13
  396. package/dist/testing/cross_backend/cell_grant_role.js +2 -2
  397. package/dist/testing/cross_backend/cell_grant_steward.d.ts +4 -0
  398. package/dist/testing/cross_backend/cell_grant_steward.d.ts.map +1 -0
  399. package/dist/testing/cross_backend/cell_grant_steward.js +120 -0
  400. package/dist/testing/cross_backend/cell_moderate.d.ts +7 -1
  401. package/dist/testing/cross_backend/cell_moderate.d.ts.map +1 -1
  402. package/dist/testing/cross_backend/cell_moderate.js +68 -4
  403. package/dist/testing/cross_backend/cell_ref_admission.d.ts.map +1 -1
  404. package/dist/testing/cross_backend/cell_ref_admission.js +18 -9
  405. package/dist/testing/cross_backend/cell_relations.d.ts.map +1 -1
  406. package/dist/testing/cross_backend/cell_relations.js +21 -0
  407. package/dist/testing/cross_backend/conformance_table.d.ts +6 -1
  408. package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
  409. package/dist/testing/cross_backend/conformance_table.js +12 -10
  410. package/dist/testing/cross_backend/default_backend_configs.d.ts +18 -4
  411. package/dist/testing/cross_backend/default_backend_configs.d.ts.map +1 -1
  412. package/dist/testing/cross_backend/default_backend_configs.js +29 -9
  413. package/dist/testing/cross_backend/default_spine_surface.d.ts +7 -7
  414. package/dist/testing/cross_backend/default_spine_surface.js +2 -2
  415. package/dist/testing/cross_backend/differential.d.ts +7 -0
  416. package/dist/testing/cross_backend/differential.d.ts.map +1 -1
  417. package/dist/testing/cross_backend/differential.js +17 -0
  418. package/dist/testing/cross_backend/expected_schema.json +1 -0
  419. package/dist/testing/cross_backend/fact_serving.d.ts.map +1 -1
  420. package/dist/testing/cross_backend/fact_serving.js +48 -0
  421. package/dist/testing/cross_backend/full_spine_mount.d.ts +3 -4
  422. package/dist/testing/cross_backend/full_spine_mount.d.ts.map +1 -1
  423. package/dist/testing/cross_backend/full_spine_mount.js +13 -5
  424. package/dist/testing/cross_backend/origin_scope.d.ts.map +1 -1
  425. package/dist/testing/cross_backend/origin_scope.js +5 -13
  426. package/dist/testing/cross_backend/peer_ping_ws.d.ts.map +1 -1
  427. package/dist/testing/cross_backend/peer_ping_ws.js +29 -4
  428. package/dist/testing/cross_backend/postgres_database.d.ts +32 -0
  429. package/dist/testing/cross_backend/postgres_database.d.ts.map +1 -1
  430. package/dist/testing/cross_backend/postgres_database.js +56 -1
  431. package/dist/testing/cross_backend/query_shape.d.ts.map +1 -1
  432. package/dist/testing/cross_backend/query_shape.js +18 -1
  433. package/dist/testing/cross_backend/role_grant_offer_lifecycle.d.ts.map +1 -1
  434. package/dist/testing/cross_backend/role_grant_offer_lifecycle.js +96 -2
  435. package/dist/testing/cross_backend/rpc_success_fixtures.js +2 -2
  436. package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +1 -1
  437. package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
  438. package/dist/testing/cross_backend/rust_spine_stub_backend_config.d.ts +17 -5
  439. package/dist/testing/cross_backend/rust_spine_stub_backend_config.d.ts.map +1 -1
  440. package/dist/testing/cross_backend/rust_spine_stub_backend_config.js +5 -4
  441. package/dist/testing/cross_backend/session_cap.d.ts +8 -0
  442. package/dist/testing/cross_backend/session_cap.d.ts.map +1 -1
  443. package/dist/testing/cross_backend/session_cap.js +66 -2
  444. package/dist/testing/cross_backend/setup.d.ts.map +1 -1
  445. package/dist/testing/cross_backend/setup.js +5 -4
  446. package/dist/testing/cross_backend/spine_suites.d.ts +4 -1
  447. package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
  448. package/dist/testing/cross_backend/spine_suites.js +21 -0
  449. package/dist/testing/cross_backend/spine_surface_constants.d.ts +22 -7
  450. package/dist/testing/cross_backend/spine_surface_constants.d.ts.map +1 -1
  451. package/dist/testing/cross_backend/spine_surface_constants.js +22 -7
  452. package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
  453. package/dist/testing/cross_backend/sse_round_trip.js +4 -3
  454. package/dist/testing/cross_backend/standard.d.ts +6 -12
  455. package/dist/testing/cross_backend/standard.d.ts.map +1 -1
  456. package/dist/testing/cross_backend/test_cell_gated_create_authorize.d.ts +18 -19
  457. package/dist/testing/cross_backend/test_cell_gated_create_authorize.d.ts.map +1 -1
  458. package/dist/testing/cross_backend/test_cell_gated_create_authorize.js +66 -42
  459. package/dist/testing/cross_backend/test_cell_grant_steward_revoke_authorize.d.ts +8 -0
  460. package/dist/testing/cross_backend/test_cell_grant_steward_revoke_authorize.d.ts.map +1 -0
  461. package/dist/testing/cross_backend/test_cell_grant_steward_revoke_authorize.js +22 -0
  462. package/dist/testing/cross_backend/testing_backdoor.d.ts.map +1 -1
  463. package/dist/testing/cross_backend/testing_backdoor.js +4 -6
  464. package/dist/testing/cross_backend/testing_origin_check.d.ts +1 -1
  465. package/dist/testing/cross_backend/testing_origin_check.d.ts.map +1 -1
  466. package/dist/testing/cross_backend/testing_origin_check.js +1 -1
  467. package/dist/testing/cross_backend/testing_reset_actions.d.ts +10 -5
  468. package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
  469. package/dist/testing/cross_backend/testing_reset_actions.js +7 -6
  470. package/dist/testing/cross_backend/testing_server_bun.d.ts.map +1 -1
  471. package/dist/testing/cross_backend/testing_server_bun.js +5 -4
  472. package/dist/testing/cross_backend/testing_server_core.d.ts +6 -7
  473. package/dist/testing/cross_backend/testing_server_core.d.ts.map +1 -1
  474. package/dist/testing/cross_backend/testing_server_core.js +1 -1
  475. package/dist/testing/cross_backend/testing_server_node.d.ts.map +1 -1
  476. package/dist/testing/cross_backend/testing_server_node.js +13 -2
  477. package/dist/testing/cross_backend/token_lifetime.d.ts.map +1 -1
  478. package/dist/testing/cross_backend/token_lifetime.js +68 -0
  479. package/dist/testing/cross_backend/transport_composition.d.ts +1 -1
  480. package/dist/testing/cross_backend/transport_composition.d.ts.map +1 -1
  481. package/dist/testing/cross_backend/transport_composition.js +48 -6
  482. package/dist/testing/cross_backend/ts_spine_backend_config.d.ts +16 -2
  483. package/dist/testing/cross_backend/ts_spine_backend_config.d.ts.map +1 -1
  484. package/dist/testing/cross_backend/ts_spine_backend_config.js +11 -8
  485. package/dist/testing/cross_backend/ws_action_rate_limit.d.ts.map +1 -1
  486. package/dist/testing/cross_backend/ws_action_rate_limit.js +30 -12
  487. package/dist/testing/cross_backend/ws_connection_cap.d.ts.map +1 -1
  488. package/dist/testing/cross_backend/ws_connection_cap.js +5 -7
  489. package/dist/testing/cross_backend/ws_endpoint.d.ts +2 -3
  490. package/dist/testing/cross_backend/ws_endpoint.d.ts.map +1 -1
  491. package/dist/testing/cross_backend/ws_envelope.d.ts +17 -0
  492. package/dist/testing/cross_backend/ws_envelope.d.ts.map +1 -0
  493. package/dist/testing/cross_backend/ws_envelope.js +172 -0
  494. package/dist/testing/cross_backend/ws_inbound_dispatch.d.ts +16 -0
  495. package/dist/testing/cross_backend/ws_inbound_dispatch.d.ts.map +1 -1
  496. package/dist/testing/cross_backend/ws_inbound_dispatch.js +8 -4
  497. package/dist/testing/cross_backend/ws_outbound_overflow.d.ts.map +1 -1
  498. package/dist/testing/cross_backend/ws_outbound_overflow.js +5 -8
  499. package/dist/testing/cross_backend/ws_role_gated.js +2 -2
  500. package/dist/testing/cross_backend/ws_round_trip.d.ts.map +1 -1
  501. package/dist/testing/cross_backend/ws_round_trip.js +6 -4
  502. package/dist/{cli/daemon.d.ts → testing/daemon_info.d.ts} +15 -47
  503. package/dist/testing/daemon_info.d.ts.map +1 -0
  504. package/dist/testing/daemon_info.js +108 -0
  505. package/dist/testing/daemon_token_rotation.js +1 -1
  506. package/dist/testing/data_exposure.d.ts.map +1 -1
  507. package/dist/testing/data_exposure.js +3 -4
  508. package/dist/testing/db.js +2 -2
  509. package/dist/testing/integration.d.ts.map +1 -1
  510. package/dist/testing/integration.js +35 -65
  511. package/dist/testing/integration_helpers.d.ts +0 -15
  512. package/dist/testing/integration_helpers.d.ts.map +1 -1
  513. package/dist/testing/integration_helpers.js +2 -42
  514. package/dist/testing/middleware.d.ts +20 -12
  515. package/dist/testing/middleware.d.ts.map +1 -1
  516. package/dist/testing/middleware.js +49 -40
  517. package/dist/testing/rate_limiting.d.ts.map +1 -1
  518. package/dist/testing/rate_limiting.js +13 -22
  519. package/dist/testing/resolved_auth.d.ts +30 -0
  520. package/dist/testing/resolved_auth.d.ts.map +1 -0
  521. package/dist/testing/resolved_auth.js +41 -0
  522. package/dist/testing/rpc_envelope_cases.d.ts.map +1 -1
  523. package/dist/testing/rpc_envelope_cases.js +3 -0
  524. package/dist/testing/rpc_helpers.d.ts +1 -1
  525. package/dist/testing/rpc_helpers.d.ts.map +1 -1
  526. package/dist/testing/rpc_helpers.js +2 -1
  527. package/dist/testing/sse_round_trip.d.ts +5 -4
  528. package/dist/testing/sse_round_trip.d.ts.map +1 -1
  529. package/dist/testing/sse_round_trip.js +2 -2
  530. package/dist/testing/stubs.d.ts +2 -2
  531. package/dist/testing/stubs.d.ts.map +1 -1
  532. package/dist/testing/stubs.js +24 -21
  533. package/dist/testing/test_origin.d.ts +25 -0
  534. package/dist/testing/test_origin.d.ts.map +1 -0
  535. package/dist/testing/test_origin.js +28 -0
  536. package/dist/testing/transports/raw_http.d.ts +54 -0
  537. package/dist/testing/transports/raw_http.d.ts.map +1 -1
  538. package/dist/testing/transports/raw_http.js +58 -0
  539. package/dist/testing/transports/ws_raw_client.d.ts +8 -0
  540. package/dist/testing/transports/ws_raw_client.d.ts.map +1 -1
  541. package/dist/testing/transports/ws_raw_client.js +13 -0
  542. package/dist/testing/transports/ws_transport.d.ts +15 -2
  543. package/dist/testing/transports/ws_transport.d.ts.map +1 -1
  544. package/dist/testing/transports/ws_transport.js +4 -2
  545. package/dist/testing/ws_round_trip.d.ts +27 -25
  546. package/dist/testing/ws_round_trip.d.ts.map +1 -1
  547. package/dist/testing/ws_round_trip.js +34 -26
  548. package/dist/ui/AccountSessions.svelte +48 -19
  549. package/dist/ui/AccountSessions.svelte.d.ts +2 -17
  550. package/dist/ui/AccountSessions.svelte.d.ts.map +1 -1
  551. package/dist/ui/AdminAccounts.svelte +6 -1
  552. package/dist/ui/AdminAuditLog.svelte +61 -22
  553. package/dist/ui/AdminAuditLog.svelte.d.ts.map +1 -1
  554. package/dist/ui/AdminInvites.svelte +1 -1
  555. package/dist/ui/AdminOverview.svelte +76 -37
  556. package/dist/ui/AdminOverview.svelte.d.ts.map +1 -1
  557. package/dist/ui/AdminRoleGrantHistory.svelte +6 -1
  558. package/dist/ui/AdminSessions.svelte +1 -1
  559. package/dist/ui/AppShell.svelte +3 -2
  560. package/dist/ui/AppShell.svelte.d.ts +3 -2
  561. package/dist/ui/AppShell.svelte.d.ts.map +1 -1
  562. package/dist/ui/CLAUDE.md +121 -35
  563. package/dist/ui/Datatable.svelte +33 -18
  564. package/dist/ui/Datatable.svelte.d.ts +2 -14
  565. package/dist/ui/Datatable.svelte.d.ts.map +1 -1
  566. package/dist/ui/OpenSignupToggle.svelte +10 -1
  567. package/dist/ui/OpenSignupToggle.svelte.d.ts.map +1 -1
  568. package/dist/ui/PopoverButton.svelte +13 -8
  569. package/dist/ui/PopoverButton.svelte.d.ts.map +1 -1
  570. package/dist/ui/RoleGrantOfferForm.svelte +3 -2
  571. package/dist/ui/RoleGrantOfferForm.svelte.d.ts +3 -2
  572. package/dist/ui/RoleGrantOfferForm.svelte.d.ts.map +1 -1
  573. package/dist/ui/RoleGrantOfferHistory.svelte +3 -3
  574. package/dist/ui/RoleGrantOfferInbox.svelte +19 -15
  575. package/dist/ui/RoleGrantOfferInbox.svelte.d.ts.map +1 -1
  576. package/dist/ui/SurfaceExplorer.svelte +66 -27
  577. package/dist/ui/SurfaceExplorer.svelte.d.ts.map +1 -1
  578. package/dist/ui/account_sessions_state.svelte.d.ts +7 -14
  579. package/dist/ui/account_sessions_state.svelte.d.ts.map +1 -1
  580. package/dist/ui/admin_accounts_state.svelte.d.ts +14 -9
  581. package/dist/ui/admin_accounts_state.svelte.d.ts.map +1 -1
  582. package/dist/ui/admin_accounts_state.svelte.js +6 -4
  583. package/dist/ui/admin_invites_state.svelte.d.ts +2 -2
  584. package/dist/ui/admin_invites_state.svelte.d.ts.map +1 -1
  585. package/dist/ui/admin_rpc_adapters.d.ts +9 -9
  586. package/dist/ui/admin_rpc_adapters.d.ts.map +1 -1
  587. package/dist/ui/admin_rpc_adapters.js +9 -9
  588. package/dist/ui/app_settings_state.svelte.d.ts +2 -2
  589. package/dist/ui/app_settings_state.svelte.d.ts.map +1 -1
  590. package/dist/ui/audit_log_state.svelte.d.ts +70 -13
  591. package/dist/ui/audit_log_state.svelte.d.ts.map +1 -1
  592. package/dist/ui/audit_log_state.svelte.js +239 -47
  593. package/dist/ui/backend_probe.svelte.d.ts +93 -0
  594. package/dist/ui/backend_probe.svelte.d.ts.map +1 -0
  595. package/dist/ui/backend_probe.svelte.js +140 -0
  596. package/dist/ui/format_scope.d.ts +7 -7
  597. package/dist/ui/format_scope.d.ts.map +1 -1
  598. package/dist/ui/format_scope.js +4 -4
  599. package/dist/ui/keyed_async_slot.svelte.d.ts +2 -2
  600. package/dist/ui/keyed_async_slot.svelte.js +2 -2
  601. package/dist/ui/popover.svelte.d.ts +18 -19
  602. package/dist/ui/popover.svelte.d.ts.map +1 -1
  603. package/dist/ui/popover.svelte.js +103 -16
  604. package/dist/ui/role_grant_offers_state.svelte.d.ts +41 -46
  605. package/dist/ui/role_grant_offers_state.svelte.d.ts.map +1 -1
  606. package/dist/ui/role_grant_offers_state.svelte.js +37 -19
  607. package/dist/ui/ui_format.d.ts +17 -0
  608. package/dist/ui/ui_format.d.ts.map +1 -1
  609. package/dist/ui/ui_format.js +20 -0
  610. package/package.json +2 -1
  611. package/dist/actions/register_ws_endpoint.d.ts +0 -79
  612. package/dist/actions/register_ws_endpoint.d.ts.map +0 -1
  613. package/dist/actions/register_ws_endpoint.js +0 -109
  614. package/dist/actions/transports_ws_auth_guard.d.ts +0 -94
  615. package/dist/actions/transports_ws_auth_guard.d.ts.map +0 -1
  616. package/dist/actions/transports_ws_auth_guard.js +0 -138
  617. package/dist/actions/transports_ws_backend.d.ts.map +0 -1
  618. package/dist/cli/args.d.ts +0 -55
  619. package/dist/cli/args.d.ts.map +0 -1
  620. package/dist/cli/args.js +0 -100
  621. package/dist/cli/config.d.ts +0 -47
  622. package/dist/cli/config.d.ts.map +0 -1
  623. package/dist/cli/config.js +0 -77
  624. package/dist/cli/daemon.d.ts.map +0 -1
  625. package/dist/cli/daemon.js +0 -181
  626. package/dist/cli/help.d.ts +0 -124
  627. package/dist/cli/help.d.ts.map +0 -1
  628. package/dist/cli/help.js +0 -215
  629. package/dist/cli/logger.d.ts +0 -46
  630. package/dist/cli/logger.d.ts.map +0 -1
  631. package/dist/cli/logger.js +0 -48
  632. package/dist/cli/util.d.ts +0 -36
  633. package/dist/cli/util.d.ts.map +0 -1
  634. package/dist/cli/util.js +0 -50
  635. package/dist/realtime/sse_auth_guard.d.ts +0 -197
  636. package/dist/realtime/sse_auth_guard.d.ts.map +0 -1
  637. package/dist/realtime/sse_auth_guard.js +0 -238
  638. package/dist/realtime/subscriber_registry.d.ts.map +0 -1
  639. package/dist/testing/bootstrap_success.d.ts +0 -29
  640. package/dist/testing/bootstrap_success.d.ts.map +0 -1
  641. package/dist/testing/bootstrap_success.js +0 -144
  642. package/dist/testing/mock_fs.d.ts +0 -20
  643. package/dist/testing/mock_fs.d.ts.map +0 -1
  644. package/dist/testing/mock_fs.js +0 -28
  645. package/dist/testing/standard.d.ts +0 -122
  646. package/dist/testing/standard.d.ts.map +0 -1
  647. package/dist/testing/standard.js +0 -73
  648. package/dist/testing/testing_rate_limiter.d.ts +0 -65
  649. package/dist/testing/testing_rate_limiter.d.ts.map +0 -1
  650. package/dist/testing/testing_rate_limiter.js +0 -80
@@ -28,14 +28,15 @@
28
28
  *
29
29
  * @module
30
30
  */
31
- import { rpc_action } from '../actions/action_rpc.js';
31
+ import { rpc_action } from '../actions/action_types.js';
32
32
  import { queue_connection_close } from '../actions/connection_closer.js';
33
33
  import { credential_type_required_error } from '../actions/perform_action.js';
34
34
  import { jsonrpc_errors, ThrownJsonrpcError } from '../http/jsonrpc_errors.js';
35
35
  import { builtin_role_specs_by_name, list_roles_with_grant_path, ROLE_ADMIN, ROLE_KEEPER } from './role_schema.js';
36
36
  import { has_scoped_role } from './request_context.js';
37
- import { query_account_has_global_role, query_account_has_active_global_role, query_count_active_accounts_with_global_role } from './role_grant_queries.js';
37
+ import { query_account_has_global_role, query_account_has_active_global_role, query_count_active_accounts_with_global_role_for_update } from './role_grant_queries.js';
38
38
  import { GRANT_PATH_ADMIN } from './grant_path_schema.js';
39
+ import { query_role_grant_offer_supersede_outgoing } from './role_grant_offer_queries.js';
39
40
  import { query_account_by_email, query_account_by_id, query_account_by_username, query_account_soft_delete, query_account_undelete, query_actor_soft_delete, query_actor_undelete, query_actors_by_account, query_admin_account_list, query_purge_account } from './account_queries.js';
40
41
  import { query_session_list_all_active, query_session_revoke_all_for_account } from './session_queries.js';
41
42
  import { query_revoke_all_api_tokens_for_account } from './api_token_queries.js';
@@ -74,12 +75,17 @@ export const create_admin_actions = (deps, options = {}) => {
74
75
  const sessions = await query_session_list_all_active(ctx);
75
76
  return { sessions };
76
77
  };
77
- const session_revoke_all_handler = async (input, ctx) => {
78
+ /**
79
+ * Revoke every credential of one kind on an account — the body
80
+ * `session_revoke_all_handler` and `token_revoke_all_handler` share,
81
+ * differing only in the audit event and the revoke query.
82
+ */
83
+ const revoke_all_for_account = async (event_type, revoke, input, ctx) => {
78
84
  const auth = ctx.auth;
79
85
  const account = await query_account_by_id(ctx, input.account_id);
80
86
  if (!account) {
81
87
  deps.audit.emit(ctx, {
82
- event_type: 'session_revoke_all',
88
+ event_type,
83
89
  outcome: 'failure',
84
90
  account_id: auth.account.id,
85
91
  // `target_account_id` is null: the FK to `account` would reject
@@ -94,7 +100,7 @@ export const create_admin_actions = (deps, options = {}) => {
94
100
  });
95
101
  throw jsonrpc_errors.not_found('account', { reason: ERROR_ACCOUNT_NOT_FOUND });
96
102
  }
97
- const count = await query_session_revoke_all_for_account(ctx, input.account_id);
103
+ const count = await revoke(ctx, input.account_id);
98
104
  // Close the target account's live connections once the revoke has
99
105
  // committed — queued, so it never runs before the commit or on
100
106
  // rollback, and it does not depend on the audit write below. Queued at
@@ -114,44 +120,7 @@ export const create_admin_actions = (deps, options = {}) => {
114
120
  // `audit_log_list_with_usernames`; losing it on every success row
115
121
  // to harden a corner case isn't worth the query-shape change.
116
122
  deps.audit.emit(ctx, {
117
- event_type: 'session_revoke_all',
118
- account_id: auth.account.id,
119
- target_account_id: input.account_id,
120
- ip: ctx.client_ip,
121
- metadata: { count }
122
- });
123
- return { ok: true, count };
124
- };
125
- const token_revoke_all_handler = async (input, ctx) => {
126
- const auth = ctx.auth;
127
- const account = await query_account_by_id(ctx, input.account_id);
128
- if (!account) {
129
- deps.audit.emit(ctx, {
130
- event_type: 'token_revoke_all',
131
- outcome: 'failure',
132
- account_id: auth.account.id,
133
- // See `session_revoke_all_handler` — FK forces null here; the
134
- // probed id lives under `metadata.attempted_account_id`.
135
- target_account_id: null,
136
- ip: ctx.client_ip,
137
- metadata: {
138
- reason: ERROR_ACCOUNT_NOT_FOUND,
139
- attempted_account_id: input.account_id
140
- }
141
- });
142
- throw jsonrpc_errors.not_found('account', { reason: ERROR_ACCOUNT_NOT_FOUND });
143
- }
144
- const count = await query_revoke_all_api_tokens_for_account(ctx, input.account_id);
145
- // Post-commit close — see `session_revoke_all_handler`.
146
- queue_connection_close(ctx, connection_closer, {
147
- kind: 'account',
148
- account_id: input.account_id
149
- });
150
- // TOCTOU window — see `session_revoke_all_handler` for the rationale on
151
- // keeping `target_account_id` populated rather than switching to the
152
- // failure-shape.
153
- deps.audit.emit(ctx, {
154
- event_type: 'token_revoke_all',
123
+ event_type,
155
124
  account_id: auth.account.id,
156
125
  target_account_id: input.account_id,
157
126
  ip: ctx.client_ip,
@@ -159,6 +128,8 @@ export const create_admin_actions = (deps, options = {}) => {
159
128
  });
160
129
  return { ok: true, count };
161
130
  };
131
+ const session_revoke_all_handler = (input, ctx) => revoke_all_for_account('session_revoke_all', query_session_revoke_all_for_account, input, ctx);
132
+ const token_revoke_all_handler = (input, ctx) => revoke_all_for_account('token_revoke_all', query_revoke_all_api_tokens_for_account, input, ctx);
162
133
  const audit_log_list_handler = async (input, ctx) => {
163
134
  const events = await query_audit_log_list_with_usernames(ctx, {
164
135
  event_type: input.event_type ?? undefined,
@@ -245,9 +216,10 @@ export const create_admin_actions = (deps, options = {}) => {
245
216
  // keeper/daemon auth with no recovery (keeper role is non-web-
246
217
  // revocable and purge itself needs keeper auth). Out-of-band only.
247
218
  // 2. **Last admin** — the sole remaining *active* admin is protected
248
- // (soft-deleted admins can't log in, so they don't count). Unlike
249
- // the keeper guard this is keeper-recoverable, but it stops an admin
250
- // tombstoning the last admin in one call.
219
+ // (soft-deleted admins can't log in, so they don't count). The count
220
+ // locks the rows it counted, so two removals racing for the last two
221
+ // admins serialize and the second is refused — no web path re-grants
222
+ // a lost admin. `role_grant_revoke` guards the admin grant the same way.
251
223
  // A missing account holds neither role here and falls through to the
252
224
  // handler's own not-found path. `event_type` selects the audit event so
253
225
  // the failure row matches the operation in flight.
@@ -275,15 +247,38 @@ export const create_admin_actions = (deps, options = {}) => {
275
247
  // admin while another active admin exists. Keeper branch above stays
276
248
  // unconditional; the last-admin branch fires only for an *active* target.
277
249
  if ((await query_account_has_active_global_role(ctx, target_account_id, ROLE_ADMIN)) &&
278
- (await query_count_active_accounts_with_global_role(ctx, ROLE_ADMIN)) <= 1) {
250
+ (await query_count_active_accounts_with_global_role_for_update(ctx, ROLE_ADMIN)) <= 1) {
279
251
  deny(ERROR_CANNOT_DELETE_LAST_ADMIN, `cannot ${verb} the last admin account`);
280
252
  }
281
253
  };
254
+ // Supersede every pending offer the removed account's actors made, audited
255
+ // — the cascade a revoke runs on the revokee's offers. An offer records no
256
+ // authority, so one outliving its grantor's account would still confer on
257
+ // accept. No supersede notification: a cascade notifies the grantor, and the
258
+ // grantor's connections close with its account. `cause_id` is the account.
259
+ const cancel_outgoing_offers = async (ctx, target_account_id, actors) => {
260
+ const superseded = await query_role_grant_offer_supersede_outgoing(ctx, actors.map((a) => a.id));
261
+ for (const offer of superseded) {
262
+ deps.audit.emit_role_grant_target(ctx, ctx.auth, {
263
+ event_type: 'role_grant_offer_supersede',
264
+ target_account_id: offer.to_account_id,
265
+ target_actor_id: offer.to_actor_id,
266
+ metadata: {
267
+ offer_id: offer.id,
268
+ role: offer.role,
269
+ scope_id: offer.scope_id,
270
+ reason: 'account_deleted',
271
+ cause_id: target_account_id
272
+ }
273
+ });
274
+ }
275
+ };
282
276
  // Soft-delete an account (reversible tombstone). Self-or-admin:
283
277
  // deleting another account requires the admin role. A self-delete is
284
278
  // session-only — enforced here, not on the spec, whose gate stays open so
285
279
  // an admin deleting another account keeps any credential. Tombstones the
286
- // account + its actor(s), revokes sessions/tokens, closes sockets, and
280
+ // account + its actor(s), supersedes the pending offers its actors made,
281
+ // revokes sessions/tokens, closes sockets, and
287
282
  // emits `account_delete` + one `actor_delete` per soft-deleted actor —
288
283
  // each carrying its identity snapshot. `delete` = soft.
289
284
  const account_delete_handler = async (input, ctx) => {
@@ -322,6 +317,7 @@ export const create_admin_actions = (deps, options = {}) => {
322
317
  });
323
318
  throw jsonrpc_errors.not_found('account', { reason: ERROR_ACCOUNT_NOT_FOUND });
324
319
  }
320
+ await cancel_outgoing_offers(ctx, target_account_id, actors);
325
321
  const soft_deleted_actors = [];
326
322
  for (const actor of actors) {
327
323
  if (await query_actor_soft_delete(ctx, actor.id, auth.actor.id)) {
@@ -374,6 +370,9 @@ export const create_admin_actions = (deps, options = {}) => {
374
370
  await assert_account_removable(ctx, input.account_id, 'account_purge');
375
371
  // Snapshot actors before the cascade removes them.
376
372
  const actors = await query_actors_by_account(ctx, input.account_id);
373
+ // Before the cascade, whose `ON DELETE CASCADE` would take the offers
374
+ // with no audit row.
375
+ await cancel_outgoing_offers(ctx, input.account_id, actors);
377
376
  const snapshot = await query_purge_account(ctx, input.account_id);
378
377
  if (!snapshot) {
379
378
  deps.audit.emit(ctx, {
@@ -1,6 +1,16 @@
1
- import type { RpcAction } from '../actions/action_rpc.js';
1
+ import type { RpcAction } from '../actions/action_types.js';
2
2
  import { type CellActionDeps } from './cell_actions.js';
3
+ import { type CellGrantCreateAuthorize, type CellGrantRevokeAuthorize } from './cell_grant_actions.js';
3
4
  import type { RoleSchemaResult } from './role_schema.js';
5
+ /**
6
+ * Dependencies for `create_all_cell_actions` — the CRUD factory's
7
+ * `CellActionDeps` plus the grant factory's optional `authorize_grant_create`
8
+ * and `authorize_grant_revoke`.
9
+ */
10
+ export type AllCellActionDeps = CellActionDeps & {
11
+ authorize_grant_create?: CellGrantCreateAuthorize;
12
+ authorize_grant_revoke?: CellGrantRevokeAuthorize;
13
+ };
4
14
  /**
5
15
  * Options for `create_all_cell_actions`.
6
16
  *
@@ -27,9 +37,10 @@ export interface AllCellActionsOptions {
27
37
  * Distinct from `create_cell_actions` (the CRUD-only factory this bundles) —
28
38
  * reach for this whenever a backend mounts the complete cell layer.
29
39
  *
30
- * @param deps - `CellActionDeps` (`log`, `audit`, optional `validate_data`)
40
+ * @param deps - `AllCellActionDeps` (`log`, `audit`, the optional `validate_data`,
41
+ * `authorize_create`, `authorize_grant_create`, and `authorize_grant_revoke`)
31
42
  * @param options - the role schema for grant validation
32
43
  * @returns every cell `RpcAction`, in mount order
33
44
  */
34
- export declare const create_all_cell_actions: (deps: CellActionDeps, options: AllCellActionsOptions) => Array<RpcAction>;
45
+ export declare const create_all_cell_actions: (deps: AllCellActionDeps, options: AllCellActionsOptions) => Array<RpcAction>;
35
46
  //# sourceMappingURL=all_cell_actions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"all_cell_actions.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/auth/all_cell_actions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAuB,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAK7E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD;;;;;;GAMG;AACH,MAAM,WAAW,qBAAqB;IACrC,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC;CACjC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,uBAAuB,GACnC,MAAM,cAAc,EACpB,SAAS,qBAAqB,KAC5B,KAAK,CAAC,SAAS,CAMjB,CAAC"}
1
+ {"version":3,"file":"all_cell_actions.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/auth/all_cell_actions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAuB,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC7E,OAAO,EAEN,KAAK,wBAAwB,EAC7B,KAAK,wBAAwB,EAC7B,MAAM,yBAAyB,CAAC;AAIjC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,cAAc,GAAG;IAChD,sBAAsB,CAAC,EAAE,wBAAwB,CAAC;IAClD,sBAAsB,CAAC,EAAE,wBAAwB,CAAC;CAClD,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,WAAW,qBAAqB;IACrC,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC;CACjC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,uBAAuB,GACnC,MAAM,iBAAiB,EACvB,SAAS,qBAAqB,KAC5B,KAAK,CAAC,SAAS,CAMjB,CAAC"}
@@ -19,7 +19,8 @@ import { create_cell_audit_actions } from './cell_audit_actions.js';
19
19
  * Distinct from `create_cell_actions` (the CRUD-only factory this bundles) —
20
20
  * reach for this whenever a backend mounts the complete cell layer.
21
21
  *
22
- * @param deps - `CellActionDeps` (`log`, `audit`, optional `validate_data`)
22
+ * @param deps - `AllCellActionDeps` (`log`, `audit`, the optional `validate_data`,
23
+ * `authorize_create`, `authorize_grant_create`, and `authorize_grant_revoke`)
23
24
  * @param options - the role schema for grant validation
24
25
  * @returns every cell `RpcAction`, in mount order
25
26
  */
@@ -42,6 +42,7 @@ export declare const API_TOKEN_COLUMNS: readonly ["id", "account_id", "name", "t
42
42
  * @param account_id - the owning account
43
43
  * @param name - human-readable name
44
44
  * @param token_hash - blake3 hash of the raw token
45
+ * @param scope - the token's authority narrowing, stored as `jsonb`
45
46
  * @param expires_at - optional expiration
46
47
  * @returns the stored token record
47
48
  * @mutates `api_token` table - inserts the new row keyed by `id`
@@ -1 +1 @@
1
- {"version":3,"file":"api_token_queries.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/auth/api_token_queries.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAGpD,OAAO,EAAE,KAAK,UAAU,EAAmD,MAAM,kBAAkB,CAAC;AAEpG;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG;IACzD,KAAK,EAAE,UAAU,CAAC;IAClB;;;;;OAKG;IACH,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,CAAC;AAEF,yEAAyE;AACzE,MAAM,WAAW,iBAAkB,SAAQ,SAAS;IACnD,GAAG,EAAE,MAAM,CAAC;CACZ;AAED;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,0HAUoB,CAAC;AA6BnD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,sBAAsB,GAClC,MAAM,SAAS,EACf,IAAI,MAAM,EACV,YAAY,MAAM,EAClB,MAAM,MAAM,EACZ,YAAY,MAAM,EAClB,OAAO,UAAU,EACjB,aAAa,IAAI,GAAG,IAAI,KACtB,OAAO,CAAC,QAAQ,CAelB,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,wBAAwB,GACpC,MAAM,iBAAiB,EACvB,WAAW,MAAM,EACjB,IAAI,MAAM,GAAG,SAAS,EACtB,iBAAiB,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,KAC/C,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAkCvC,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAA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AAM,6BAA6B,GACzC,MAAM,SAAS,EACf,YAAY,MAAM,EAClB,YAAY,MAAM,KAChB,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAYvB,CAAC"}
@@ -57,6 +57,7 @@ const API_TOKEN_IS_LIVE = '(expires_at IS NULL OR expires_at > NOW())';
57
57
  * @param account_id - the owning account
58
58
  * @param name - human-readable name
59
59
  * @param token_hash - blake3 hash of the raw token
60
+ * @param scope - the token's authority narrowing, stored as `jsonb`
60
61
  * @param expires_at - optional expiration
61
62
  * @returns the stored token record
62
63
  * @mutates `api_token` table - inserts the new row keyed by `id`
@@ -43,7 +43,8 @@
43
43
  * - A **failure** row is announced as soon as it is written. It records an
44
44
  * attempt, which happened whether or not the request's transaction commits.
45
45
  * - A **success** row is announced only after the request's transaction
46
- * commits, and never when the handler throws: the fan-out is queued on
46
+ * commits (after the handler returns, on a route without one), and never
47
+ * when the handler throws: the fan-out is queued on
47
48
  * `ctx.post_commit_effects` and awaits the write. A success row reports a
48
49
  * state change, and the listeners act on it — the revocation listeners close
49
50
  * connections, the audit stream broadcasts it. Announced before the commit,
@@ -53,13 +54,18 @@
53
54
  * A success row emitted by a handler that later throws is still in the table —
54
55
  * the write is outside the transaction — but is never announced.
55
56
  *
56
- * The Rust spine reaches the same order by writing a success row inside the
57
- * transaction and queueing its fan-out behind the commit.
57
+ * A route that runs without a request transaction and opens its own around
58
+ * just its writes (`/login`, `/password`) emits its success row once that
59
+ * transaction has committed, so the row is written after the change it
60
+ * reports. The Rust spine follows the same order: a success row emitted inside
61
+ * a request transaction is written in that transaction and its fan-out queued
62
+ * behind the commit, and `/login` and `/password` emit on the pool after their
63
+ * own transaction commits.
58
64
  *
59
65
  * Listeners are a documented registration seam — `create_app_server`
60
66
  * registers additional listeners via `add_listener` after the backend is
61
- * built (the factory-managed audit-log SSE, per-endpoint WS auth guards, any
62
- * `extra_audit_handlers` on a `WsEndpointSpec`) before the first request
67
+ * built (the factory-managed audit-log SSE, the revocation guard) before the
68
+ * first request
63
69
  * runs, and removes each through the remover `add_listener` returns when its
64
70
  * assembly fails or the server closes. Consumers can also register
65
71
  * listeners directly on the emitter they return from `audit_factory` for
@@ -191,7 +197,7 @@ export interface AuditEmitter {
191
197
  * during its fan-out — it iterates a snapshot — and the next one does not.
192
198
  *
193
199
  * `create_app_server` registers the factory-managed audit-log SSE
194
- * listener and per-endpoint WS auth guards here so
200
+ * listener and the one revocation guard (`create_revocation_guard`) here so
195
201
  * SSE + WS fan-out compose on top of the consumer's `on_audit_event`
196
202
  * callback without shallow-copying `AppDeps`, and removes them when its
197
203
  * assembly fails or the server closes. Consumers can also register
@@ -1 +1 @@
1
- {"version":3,"file":"audit_emitter.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/auth/audit_emitter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAqB,KAAK,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAC5F,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAEhE,OAAO,EAEN,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,MAAM,uBAAuB,CAAC;AAE/B;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,WAAW,mBAAoB,SAAQ,sBAAsB;IAClE,eAAe,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;CACtC;AAED;;;;GAIG;AACH,MAAM,WAAW,yBAA0B,SAAQ,mBAAmB;IACrE,0FAA0F;IAC1F,SAAS,EAAE,MAAM,CAAC;CAClB;AAED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,eAAO,MAAM,oBAAoB,GAAI,SAAS,yBAAyB,KAAG,YAiJzE,CAAC"}
@@ -43,7 +43,8 @@
43
43
  * - A **failure** row is announced as soon as it is written. It records an
44
44
  * attempt, which happened whether or not the request's transaction commits.
45
45
  * - A **success** row is announced only after the request's transaction
46
- * commits, and never when the handler throws: the fan-out is queued on
46
+ * commits (after the handler returns, on a route without one), and never
47
+ * when the handler throws: the fan-out is queued on
47
48
  * `ctx.post_commit_effects` and awaits the write. A success row reports a
48
49
  * state change, and the listeners act on it — the revocation listeners close
49
50
  * connections, the audit stream broadcasts it. Announced before the commit,
@@ -53,13 +54,18 @@
53
54
  * A success row emitted by a handler that later throws is still in the table —
54
55
  * the write is outside the transaction — but is never announced.
55
56
  *
56
- * The Rust spine reaches the same order by writing a success row inside the
57
- * transaction and queueing its fan-out behind the commit.
57
+ * A route that runs without a request transaction and opens its own around
58
+ * just its writes (`/login`, `/password`) emits its success row once that
59
+ * transaction has committed, so the row is written after the change it
60
+ * reports. The Rust spine follows the same order: a success row emitted inside
61
+ * a request transaction is written in that transaction and its fan-out queued
62
+ * behind the commit, and `/login` and `/password` emit on the pool after their
63
+ * own transaction commits.
58
64
  *
59
65
  * Listeners are a documented registration seam — `create_app_server`
60
66
  * registers additional listeners via `add_listener` after the backend is
61
- * built (the factory-managed audit-log SSE, per-endpoint WS auth guards, any
62
- * `extra_audit_handlers` on a `WsEndpointSpec`) before the first request
67
+ * built (the factory-managed audit-log SSE, the revocation guard) before the
68
+ * first request
63
69
  * runs, and removes each through the remover `add_listener` returns when its
64
70
  * assembly fails or the server closes. Consumers can also register
65
71
  * listeners directly on the emitter they return from `audit_factory` for
@@ -1 +1 @@
1
- {"version":3,"file":"audit_log_route_schema.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/auth/audit_log_route_schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAGvD,2FAA2F;AAC3F,eAAO,MAAM,gBAAgB;;kBAA0C,CAAC;AACxE,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAEhE,+DAA+D;AAC/D,eAAO,MAAM,yBAAyB,UAAU,CAAC;AAEjD;;;;;;;;GAQG;AACH,eAAO,MAAM,4BAA4B,GACxC,gBAAe,MAAkC,KAC/C,IAAI,CAAC,SAAS,EAAE,SAAS,CA6B1B,CAAC"}
1
+ {"version":3,"file":"audit_log_route_schema.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/auth/audit_log_route_schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAGvD,2FAA2F;AAC3F,eAAO,MAAM,gBAAgB;;kBAA0C,CAAC;AACxE,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAEhE,+DAA+D;AAC/D,eAAO,MAAM,yBAAyB,UAAU,CAAC;AAEjD;;;;;;;;GAQG;AACH,eAAO,MAAM,4BAA4B,GACxC,gBAAe,MAAkC,KAC/C,IAAI,CAAC,SAAS,EAAE,SAAS,CA8B1B,CAAC"}
@@ -36,8 +36,9 @@ export const create_audit_log_route_shape = (required_role = DEFAULT_AUDIT_STREA
36
36
  // feed is not handed to a credential channel the deployment never
37
37
  // chose. Widening the gate loses no close — the handler registers a
38
38
  // bearer's stream under its API token id, and a token revocation closes
39
- // by that id (`create_sse_connection_closer`, and the `token` scope in
40
- // `create_sse_auth_guard`) — so widening is a consumer's explicit
39
+ // by that id (`create_sse_connection_closer`, which the handlers and the
40
+ // `token` scope of `create_revocation_guard` both close through) — so
41
+ // widening is a consumer's explicit
41
42
  // choice about the channel, not a hole in revocation.
42
43
  credential_types: ['session'],
43
44
  // Rule 3 — a narrowed token holds no audit feed. Same reasoning as the
@@ -7,14 +7,14 @@
7
7
  * `GET /audit/stream` SSE route — streams aren't an action-kind, so they
8
8
  * stay on REST. The event payload broadcast on the stream surfaces via
9
9
  * `audit_log_event_specs` (one `EventSpec` per audit event type) declared
10
- * alongside the broadcaster in `realtime/sse_auth_guard.ts`.
10
+ * alongside the broadcaster in `realtime/audit_log_sse.ts`.
11
11
  *
12
12
  * @module
13
13
  */
14
14
  import type { Logger } from '@fuzdev/fuz_util/log.ts';
15
15
  import type { RouteSpec } from '../http/route_spec.js';
16
16
  import { type SseNotification } from '../realtime/sse.js';
17
- import type { SubscriberRegistry } from '../realtime/subscriber_registry.js';
17
+ import type { SseRegistry } from '../realtime/sse_registry.js';
18
18
  /** Options for audit log route specs. */
19
19
  export interface AuditLogRouteOptions {
20
20
  /** Role required to access audit routes. Default `'admin'`. */
@@ -28,8 +28,15 @@ export interface AuditLogRouteOptions {
28
28
  * (`create_audit_log_sse`, or `AppServerContext.audit_sse`) satisfies it.
29
29
  */
30
30
  stream?: {
31
- registry: SubscriberRegistry<SseNotification>;
31
+ registry: SseRegistry<SseNotification>;
32
32
  log: Logger;
33
+ /**
34
+ * Each stream's keep-alive interval (`SseResponseOptions.keep_alive_ms`)
35
+ * — a test server shortens it. Validated here, at route creation.
36
+ *
37
+ * @default SSE_KEEP_ALIVE_INTERVAL_MS
38
+ */
39
+ keep_alive_ms?: number | null;
33
40
  };
34
41
  }
35
42
  /**
@@ -46,23 +53,25 @@ export interface AuditLogRouteOptions {
46
53
  * route-spec pipeline, before the handler and so before any stream is
47
54
  * registered — a revocation landing after them would close nothing. So the
48
55
  * handler registers the stream **pending**
49
- * (`SubscriberRegistry.subscribe_pending`), then re-reads the credential
50
- * (`revalidate_resolved_auth`) and the acting actor's role grants, and only
51
- * then admits (`SubscriberRegistry.admit`). A revocation that committed before
52
- * those reads is seen by them — `401 authentication_required` for a dead
53
- * credential, `403 insufficient_permissions` for a lost role — and one whose
56
+ * (`SseRegistry.subscribe_pending`), then re-reads the credential, the
57
+ * acting actor, and its role grants (`recheck_admission`, which the WebSocket
58
+ * upgrade shares), and only then admits (`SseRegistry.admit`). A
59
+ * revocation that committed before those reads is seen by them —
60
+ * `401 authentication_required` for a dead credential or an acting actor
61
+ * deleted since the gates ran, `403 insufficient_permissions` for a lost
62
+ * role — and one whose
54
63
  * close ran after the registration found the pending entry: admission then
55
64
  * fails, and the response is a `200` whose body is the connect comment and
56
65
  * nothing else — to an `EventSource`, a stream closed an instant after it
57
66
  * opened (the client's reconnect is answered by the gates, with the precise
58
67
  * status). A pending registration receives no audit row, counts toward no cap,
59
68
  * and is removed when a re-read refuses the request. Once the server is
60
- * shutting down (`SubscriberRegistry` class doc, "Shutdown") the registration
69
+ * shutting down (`SseRegistry` class doc, "Shutdown") the registration
61
70
  * is born closed, the re-reads are skipped, and the answer is that same
62
71
  * connect comment alone — as it is when the shutdown closes a registration
63
72
  * whose re-read is in flight, even if the re-read then fails. The twin of the
64
- * Rust spine's `audit_stream_router`, which registers before its role read
65
- * rather than repeating it.
73
+ * Rust spine's `audit_stream_router`, which runs the same order through its
74
+ * `recheck_admission`.
66
75
  *
67
76
  * ## Credential deadline
68
77
  *
@@ -1 +1 @@
1
- {"version":3,"file":"audit_log_routes.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/auth/audit_log_routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAUvD,OAAO,EAAuB,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC/E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAW7E,yCAAyC;AACzC,MAAM,WAAW,oBAAoB;IACpC,+DAA+D;IAC/D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE;QACR,QAAQ,EAAE,kBAAkB,CAAC,eAAe,CAAC,CAAC;QAC9C,GAAG,EAAE,MAAM,CAAC;KACZ,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,eAAO,MAAM,4BAA4B,GAAI,UAAU,oBAAoB,KAAG,KAAK,CAAC,SAAS,CAmH5F,CAAC"}
1
+ {"version":3,"file":"audit_log_routes.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/auth/audit_log_routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAGtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAUvD,OAAO,EAAuB,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE/E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAW/D,yCAAyC;AACzC,MAAM,WAAW,oBAAoB;IACpC,+DAA+D;IAC/D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE;QACR,QAAQ,EAAE,WAAW,CAAC,eAAe,CAAC,CAAC;QACvC,GAAG,EAAE,MAAM,CAAC;QACZ;;;;;WAKG;QACH,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KAC9B,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,4BAA4B,GAAI,UAAU,oBAAoB,KAAG,KAAK,CAAC,SAAS,CAgI5F,CAAC"}
@@ -7,18 +7,20 @@
7
7
  * `GET /audit/stream` SSE route — streams aren't an action-kind, so they
8
8
  * stay on REST. The event payload broadcast on the stream surfaces via
9
9
  * `audit_log_event_specs` (one `EventSpec` per audit event type) declared
10
- * alongside the broadcaster in `realtime/sse_auth_guard.ts`.
10
+ * alongside the broadcaster in `realtime/audit_log_sse.ts`.
11
11
  *
12
12
  * @module
13
13
  */
14
+ import { UnreachableError } from '@fuzdev/fuz_util/error.ts';
14
15
  import { ERROR_AUTHENTICATION_REQUIRED, ERROR_INSUFFICIENT_PERMISSIONS } from '../http/error_schemas.js';
15
- import { AUTH_API_TOKEN_ID_KEY, TEST_CONTEXT_PRESET_KEY } from '../hono_context.js';
16
+ import { TEST_CONTEXT_PRESET_KEY } from '../hono_context.js';
16
17
  import { create_audit_log_route_shape, DEFAULT_AUDIT_STREAM_ROLE } from './audit_log_route_schema.js';
17
18
  import { create_sse_response } from '../realtime/sse.js';
18
- import { AUTH_SESSION_TOKEN_HASH_KEY, has_scoped_role, refresh_role_grants, require_request_context } from './request_context.js';
19
- import { get_resolved_auth, revalidate_resolved_auth } from './resolved_auth.js';
19
+ import { validate_sse_keep_alive_ms } from '../realtime/sse_constants.js';
20
+ import { require_request_context } from './request_context.js';
21
+ import { get_resolved_auth, recheck_admission, resolved_auth_api_token_id, resolved_auth_session_hash } from './resolved_auth.js';
20
22
  import { schedule_credential_deadline } from './credential_deadline.js';
21
- import { AUDIT_LOG_CHANNEL } from '../realtime/sse_auth_guard.js';
23
+ import { AUDIT_LOG_CHANNEL } from '../realtime/audit_log_sse.js';
22
24
  /**
23
25
  * Create the optional audit-log SSE route spec.
24
26
  *
@@ -33,23 +35,25 @@ import { AUDIT_LOG_CHANNEL } from '../realtime/sse_auth_guard.js';
33
35
  * route-spec pipeline, before the handler and so before any stream is
34
36
  * registered — a revocation landing after them would close nothing. So the
35
37
  * handler registers the stream **pending**
36
- * (`SubscriberRegistry.subscribe_pending`), then re-reads the credential
37
- * (`revalidate_resolved_auth`) and the acting actor's role grants, and only
38
- * then admits (`SubscriberRegistry.admit`). A revocation that committed before
39
- * those reads is seen by them — `401 authentication_required` for a dead
40
- * credential, `403 insufficient_permissions` for a lost role — and one whose
38
+ * (`SseRegistry.subscribe_pending`), then re-reads the credential, the
39
+ * acting actor, and its role grants (`recheck_admission`, which the WebSocket
40
+ * upgrade shares), and only then admits (`SseRegistry.admit`). A
41
+ * revocation that committed before those reads is seen by them —
42
+ * `401 authentication_required` for a dead credential or an acting actor
43
+ * deleted since the gates ran, `403 insufficient_permissions` for a lost
44
+ * role — and one whose
41
45
  * close ran after the registration found the pending entry: admission then
42
46
  * fails, and the response is a `200` whose body is the connect comment and
43
47
  * nothing else — to an `EventSource`, a stream closed an instant after it
44
48
  * opened (the client's reconnect is answered by the gates, with the precise
45
49
  * status). A pending registration receives no audit row, counts toward no cap,
46
50
  * and is removed when a re-read refuses the request. Once the server is
47
- * shutting down (`SubscriberRegistry` class doc, "Shutdown") the registration
51
+ * shutting down (`SseRegistry` class doc, "Shutdown") the registration
48
52
  * is born closed, the re-reads are skipped, and the answer is that same
49
53
  * connect comment alone — as it is when the shutdown closes a registration
50
54
  * whose re-read is in flight, even if the re-read then fails. The twin of the
51
- * Rust spine's `audit_stream_router`, which registers before its role read
52
- * rather than repeating it.
55
+ * Rust spine's `audit_stream_router`, which runs the same order through its
56
+ * `recheck_admission`.
53
57
  *
54
58
  * ## Credential deadline
55
59
  *
@@ -67,7 +71,8 @@ import { AUDIT_LOG_CHANNEL } from '../realtime/sse_auth_guard.js';
67
71
  export const create_audit_log_route_specs = (options) => {
68
72
  if (!options?.stream)
69
73
  return [];
70
- const { registry, log } = options.stream;
74
+ const { registry, log, keep_alive_ms } = options.stream;
75
+ validate_sse_keep_alive_ms(keep_alive_ms);
71
76
  const required_role = options.required_role ?? DEFAULT_AUDIT_STREAM_ROLE;
72
77
  return [
73
78
  {
@@ -84,13 +89,16 @@ export const create_audit_log_route_specs = (options) => {
84
89
  // sessions only, so `api_token_id` is null here; it is registered
85
90
  // when present so that a consumer widening the credential gate
86
91
  // still has a revoked token's stream closed by `token_revoke`.
87
- const token_hash = c.get(AUTH_SESSION_TOKEN_HASH_KEY) ?? null;
88
- const api_token_id = c.get(AUTH_API_TOKEN_ID_KEY) ?? null;
92
+ // Both come off the resolved credential, which carries each only
93
+ // for its own credential type.
94
+ const resolved = get_resolved_auth(c);
95
+ const session_hash = resolved_auth_session_hash(resolved);
96
+ const api_token_id = resolved_auth_api_token_id(resolved);
89
97
  // Register pending first: from here every revocation finds the
90
98
  // stream (TSDoc, "Admission").
91
99
  const pending = registry.subscribe_pending({
92
100
  channels: [AUDIT_LOG_CHANNEL],
93
- scope: token_hash ?? undefined,
101
+ scope: session_hash ?? undefined,
94
102
  groups: api_token_id === null ? [ctx.account.id] : [ctx.account.id, api_token_id]
95
103
  });
96
104
  // The pending registration is released on every path that does not
@@ -107,20 +115,31 @@ export const create_audit_log_route_specs = (options) => {
107
115
  // refuses whatever they answer.
108
116
  if (!c.get(TEST_CONTEXT_PRESET_KEY) && !registry.closing) {
109
117
  const reread = async () => {
110
- const resolved = get_resolved_auth(c);
111
- const credential_is_live = resolved !== null && (await revalidate_resolved_auth(route, resolved));
112
- if (!credential_is_live) {
113
- log.info('audit stream: credential revoked during the request', ctx.account.id);
114
- return c.json({ error: ERROR_AUTHENTICATION_REQUIRED }, 401);
115
- }
116
118
  // Global grants only, like the `require_role` gate that ran in
117
119
  // the pipeline — a scoped grant must not open the instance-wide
118
120
  // stream.
119
- if (!has_scoped_role(await refresh_role_grants(ctx, route), required_role, null)) {
120
- log.info('audit stream: role revoked during the request', ctx.account.id);
121
- return c.json({ error: ERROR_INSUFFICIENT_PERMISSIONS, required_roles: [required_role] }, 403);
121
+ const recheck = resolved === null
122
+ ? 'credential_revoked'
123
+ : await recheck_admission(route, {
124
+ resolved,
125
+ request_context: ctx,
126
+ required_roles: [required_role]
127
+ });
128
+ switch (recheck) {
129
+ case 'admitted':
130
+ return null;
131
+ case 'credential_revoked':
132
+ log.info('audit stream: credential revoked during the request', ctx.account.id);
133
+ return c.json({ error: ERROR_AUTHENTICATION_REQUIRED }, 401);
134
+ case 'actor_inactive':
135
+ log.info('audit stream: acting actor deleted during the request', ctx.account.id);
136
+ return c.json({ error: ERROR_AUTHENTICATION_REQUIRED }, 401);
137
+ case 'role_revoked':
138
+ log.info('audit stream: role revoked during the request', ctx.account.id);
139
+ return c.json({ error: ERROR_INSUFFICIENT_PERMISSIONS, required_roles: [required_role] }, 403);
140
+ default:
141
+ throw new UnreachableError(recheck);
122
142
  }
123
- return null;
124
143
  };
125
144
  const refusal = await reread().catch((error) => {
126
145
  // the shutdown closed the registration and then the database
@@ -146,7 +165,8 @@ export const create_audit_log_route_specs = (options) => {
146
165
  // whose listener runs at once and removes the registration, so
147
166
  // `admit` refuses it rather than evicting a live stream for it.
148
167
  const { response, stream } = create_sse_response(c, log, {
149
- account_id: ctx.account.id
168
+ account_id: ctx.account.id,
169
+ keep_alive_ms
150
170
  });
151
171
  stream.on_close(pending.unsubscribe);
152
172
  admitted = registry.admit(pending, stream);
@@ -158,7 +178,7 @@ export const create_audit_log_route_specs = (options) => {
158
178
  // The stream ends when the credential it opened on expires —
159
179
  // closed as a revocation closes it (TSDoc, "Credential
160
180
  // deadline").
161
- stream.on_close(schedule_credential_deadline(get_resolved_auth(c)?.credential_deadline ?? null, () => {
181
+ stream.on_close(schedule_credential_deadline(resolved?.credential_deadline ?? null, () => {
162
182
  log.info('audit stream: credential expired', ctx.account.id);
163
183
  stream.close();
164
184
  }));