@fuzdev/fuz_app 0.150.0 → 0.152.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 (597) hide show
  1. package/README.md +1 -1
  2. package/dist/actions/CLAUDE.md +324 -299
  3. package/dist/actions/action_bridge.d.ts +5 -86
  4. package/dist/actions/action_bridge.d.ts.map +1 -1
  5. package/dist/actions/action_bridge.js +4 -84
  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_rpc.d.ts +10 -215
  19. package/dist/actions/action_rpc.d.ts.map +1 -1
  20. package/dist/actions/action_rpc.js +56 -111
  21. package/dist/actions/action_spec.d.ts +2 -2
  22. package/dist/actions/action_spec.js +2 -2
  23. package/dist/actions/action_types.d.ts +229 -8
  24. package/dist/actions/action_types.d.ts.map +1 -1
  25. package/dist/actions/action_types.js +56 -5
  26. package/dist/actions/broadcast_api.d.ts +22 -17
  27. package/dist/actions/broadcast_api.d.ts.map +1 -1
  28. package/dist/actions/broadcast_api.js +16 -27
  29. package/dist/actions/cancel.d.ts +4 -13
  30. package/dist/actions/cancel.d.ts.map +1 -1
  31. package/dist/actions/cancel.js +5 -17
  32. package/dist/actions/compile_action_registry.d.ts +1 -2
  33. package/dist/actions/compile_action_registry.d.ts.map +1 -1
  34. package/dist/actions/connection_closer.d.ts +120 -50
  35. package/dist/actions/connection_closer.d.ts.map +1 -1
  36. package/dist/actions/connection_closer.js +139 -31
  37. package/dist/actions/{transports_ws_backend.d.ts → connection_registry.d.ts} +120 -132
  38. package/dist/actions/connection_registry.d.ts.map +1 -0
  39. package/dist/actions/{transports_ws_backend.js → connection_registry.js} +149 -152
  40. package/dist/actions/frontend_rpc_client.d.ts +52 -2
  41. package/dist/actions/frontend_rpc_client.d.ts.map +1 -1
  42. package/dist/actions/frontend_rpc_client.js +42 -4
  43. package/dist/actions/peer_ping.d.ts +7 -9
  44. package/dist/actions/peer_ping.d.ts.map +1 -1
  45. package/dist/actions/peer_ping.js +6 -8
  46. package/dist/actions/peer_request.d.ts +6 -5
  47. package/dist/actions/peer_request.d.ts.map +1 -1
  48. package/dist/actions/peer_request.js +6 -5
  49. package/dist/actions/perform_action.d.ts +36 -28
  50. package/dist/actions/perform_action.d.ts.map +1 -1
  51. package/dist/actions/perform_action.js +60 -34
  52. package/dist/actions/protocol.d.ts +14 -0
  53. package/dist/actions/protocol.d.ts.map +1 -1
  54. package/dist/actions/protocol.js +18 -0
  55. package/dist/actions/register_action_ws.d.ts +137 -298
  56. package/dist/actions/register_action_ws.d.ts.map +1 -1
  57. package/dist/actions/register_action_ws.js +155 -923
  58. package/dist/actions/socket.svelte.d.ts +9 -0
  59. package/dist/actions/socket.svelte.d.ts.map +1 -1
  60. package/dist/actions/socket.svelte.js +16 -5
  61. package/dist/actions/transports.d.ts +88 -34
  62. package/dist/actions/transports.d.ts.map +1 -1
  63. package/dist/actions/transports.js +76 -76
  64. package/dist/actions/transports_http.d.ts +48 -12
  65. package/dist/actions/transports_http.d.ts.map +1 -1
  66. package/dist/actions/transports_http.js +75 -44
  67. package/dist/actions/transports_ws.d.ts +29 -0
  68. package/dist/actions/transports_ws.d.ts.map +1 -1
  69. package/dist/actions/transports_ws.js +34 -8
  70. package/dist/actions/ws_endpoint_spec.d.ts +52 -75
  71. package/dist/actions/ws_endpoint_spec.d.ts.map +1 -1
  72. package/dist/actions/ws_endpoint_spec.js +27 -10
  73. package/dist/actions/ws_outbound_writer.d.ts +3 -3
  74. package/dist/actions/ws_outbound_writer.js +3 -3
  75. package/dist/actions/ws_socket_session.d.ts +321 -0
  76. package/dist/actions/ws_socket_session.d.ts.map +1 -0
  77. package/dist/actions/ws_socket_session.js +783 -0
  78. package/dist/auth/CLAUDE.md +70 -44
  79. package/dist/auth/account_action_specs.d.ts +2 -0
  80. package/dist/auth/account_action_specs.d.ts.map +1 -1
  81. package/dist/auth/account_actions.d.ts +1 -1
  82. package/dist/auth/account_actions.d.ts.map +1 -1
  83. package/dist/auth/account_actions.js +9 -3
  84. package/dist/auth/account_queries.d.ts +10 -0
  85. package/dist/auth/account_queries.d.ts.map +1 -1
  86. package/dist/auth/account_queries.js +27 -17
  87. package/dist/auth/account_routes.d.ts +2 -1
  88. package/dist/auth/account_routes.d.ts.map +1 -1
  89. package/dist/auth/account_routes.js +14 -17
  90. package/dist/auth/account_schema.d.ts +5 -5
  91. package/dist/auth/account_schema.d.ts.map +1 -1
  92. package/dist/auth/account_schema.js +5 -2
  93. package/dist/auth/actor_lookup_actions.d.ts +1 -1
  94. package/dist/auth/actor_lookup_actions.d.ts.map +1 -1
  95. package/dist/auth/actor_lookup_actions.js +1 -1
  96. package/dist/auth/actor_search_action_specs.d.ts.map +1 -1
  97. package/dist/auth/actor_search_action_specs.js +2 -1
  98. package/dist/auth/actor_search_actions.d.ts +1 -1
  99. package/dist/auth/actor_search_actions.d.ts.map +1 -1
  100. package/dist/auth/actor_search_actions.js +1 -1
  101. package/dist/auth/actor_search_queries.d.ts +5 -5
  102. package/dist/auth/actor_search_queries.d.ts.map +1 -1
  103. package/dist/auth/actor_search_queries.js +7 -7
  104. package/dist/auth/admin_action_specs.d.ts.map +1 -1
  105. package/dist/auth/admin_action_specs.js +3 -1
  106. package/dist/auth/admin_actions.d.ts +1 -1
  107. package/dist/auth/admin_actions.d.ts.map +1 -1
  108. package/dist/auth/admin_actions.js +12 -42
  109. package/dist/auth/all_cell_actions.d.ts +6 -4
  110. package/dist/auth/all_cell_actions.d.ts.map +1 -1
  111. package/dist/auth/all_cell_actions.js +1 -1
  112. package/dist/auth/api_token_queries.d.ts +1 -0
  113. package/dist/auth/api_token_queries.d.ts.map +1 -1
  114. package/dist/auth/api_token_queries.js +1 -0
  115. package/dist/auth/audit_emitter.d.ts +3 -3
  116. package/dist/auth/audit_emitter.js +2 -2
  117. package/dist/auth/audit_log_route_schema.d.ts.map +1 -1
  118. package/dist/auth/audit_log_route_schema.js +3 -2
  119. package/dist/auth/audit_log_routes.d.ts +20 -11
  120. package/dist/auth/audit_log_routes.d.ts.map +1 -1
  121. package/dist/auth/audit_log_routes.js +49 -29
  122. package/dist/auth/audit_log_schema.d.ts +13 -21
  123. package/dist/auth/audit_log_schema.d.ts.map +1 -1
  124. package/dist/auth/audit_log_schema.js +10 -18
  125. package/dist/auth/bearer_auth.d.ts +7 -4
  126. package/dist/auth/bearer_auth.d.ts.map +1 -1
  127. package/dist/auth/bearer_auth.js +21 -15
  128. package/dist/auth/cell_action_helpers.d.ts +89 -0
  129. package/dist/auth/cell_action_helpers.d.ts.map +1 -0
  130. package/dist/auth/cell_action_helpers.js +113 -0
  131. package/dist/auth/cell_actions.d.ts +22 -13
  132. package/dist/auth/cell_actions.d.ts.map +1 -1
  133. package/dist/auth/cell_actions.js +105 -167
  134. package/dist/auth/cell_audit_actions.d.ts +1 -1
  135. package/dist/auth/cell_audit_actions.d.ts.map +1 -1
  136. package/dist/auth/cell_audit_actions.js +3 -12
  137. package/dist/auth/cell_audit_metadata.d.ts +1 -1
  138. package/dist/auth/cell_audit_metadata.js +1 -1
  139. package/dist/auth/cell_field_actions.d.ts +1 -1
  140. package/dist/auth/cell_field_actions.d.ts.map +1 -1
  141. package/dist/auth/cell_field_actions.js +16 -66
  142. package/dist/auth/cell_grant_action_specs.d.ts +2 -2
  143. package/dist/auth/cell_grant_action_specs.js +3 -3
  144. package/dist/auth/cell_grant_actions.d.ts +73 -11
  145. package/dist/auth/cell_grant_actions.d.ts.map +1 -1
  146. package/dist/auth/cell_grant_actions.js +63 -55
  147. package/dist/auth/cell_grant_audit_metadata.d.ts +6 -3
  148. package/dist/auth/cell_grant_audit_metadata.d.ts.map +1 -1
  149. package/dist/auth/cell_grant_audit_metadata.js +7 -4
  150. package/dist/auth/cell_item_actions.d.ts +1 -1
  151. package/dist/auth/cell_item_actions.d.ts.map +1 -1
  152. package/dist/auth/cell_item_actions.js +21 -82
  153. package/dist/auth/cleanup.d.ts +1 -1
  154. package/dist/auth/cleanup.d.ts.map +1 -1
  155. package/dist/auth/cleanup.js +6 -3
  156. package/dist/auth/credential_deadline.d.ts +3 -3
  157. package/dist/auth/credential_deadline.js +3 -3
  158. package/dist/auth/credential_type_schema.d.ts +5 -5
  159. package/dist/auth/credential_type_schema.js +5 -5
  160. package/dist/auth/daemon_token_middleware.d.ts +12 -6
  161. package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
  162. package/dist/auth/daemon_token_middleware.js +28 -17
  163. package/dist/auth/deps.d.ts +4 -4
  164. package/dist/auth/fail_floor.d.ts +55 -0
  165. package/dist/auth/fail_floor.d.ts.map +1 -0
  166. package/dist/auth/fail_floor.js +63 -0
  167. package/dist/auth/invite_queries.d.ts +3 -15
  168. package/dist/auth/invite_queries.d.ts.map +1 -1
  169. package/dist/auth/invite_queries.js +3 -21
  170. package/dist/auth/middleware.d.ts +12 -7
  171. package/dist/auth/middleware.d.ts.map +1 -1
  172. package/dist/auth/middleware.js +42 -29
  173. package/dist/auth/migrations.d.ts +5 -33
  174. package/dist/auth/migrations.d.ts.map +1 -1
  175. package/dist/auth/migrations.js +9 -16
  176. package/dist/auth/request_context.d.ts +101 -71
  177. package/dist/auth/request_context.d.ts.map +1 -1
  178. package/dist/auth/request_context.js +137 -140
  179. package/dist/auth/resolved_auth.d.ts +122 -36
  180. package/dist/auth/resolved_auth.d.ts.map +1 -1
  181. package/dist/auth/resolved_auth.js +89 -38
  182. package/dist/auth/role_grant_offer_action_specs.d.ts +99 -14
  183. package/dist/auth/role_grant_offer_action_specs.d.ts.map +1 -1
  184. package/dist/auth/role_grant_offer_action_specs.js +26 -13
  185. package/dist/auth/role_grant_offer_actions.d.ts +13 -7
  186. package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
  187. package/dist/auth/role_grant_offer_actions.js +14 -12
  188. package/dist/auth/role_grant_offer_notifications.d.ts +3 -3
  189. package/dist/auth/role_grant_offer_notifications.js +1 -1
  190. package/dist/auth/role_grant_offer_queries.d.ts +0 -5
  191. package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
  192. package/dist/auth/role_grant_offer_queries.js +9 -41
  193. package/dist/auth/role_grant_queries.d.ts +17 -67
  194. package/dist/auth/role_grant_queries.d.ts.map +1 -1
  195. package/dist/auth/role_grant_queries.js +34 -106
  196. package/dist/auth/role_grant_sql.d.ts +42 -0
  197. package/dist/auth/role_grant_sql.d.ts.map +1 -0
  198. package/dist/auth/role_grant_sql.js +54 -0
  199. package/dist/auth/scope_kind_schema.d.ts +1 -1
  200. package/dist/auth/scope_kind_schema.js +1 -1
  201. package/dist/auth/self_service_role_actions.d.ts +1 -1
  202. package/dist/auth/self_service_role_actions.d.ts.map +1 -1
  203. package/dist/auth/self_service_role_actions.js +1 -1
  204. package/dist/auth/session_queries.d.ts +2 -1
  205. package/dist/auth/session_queries.d.ts.map +1 -1
  206. package/dist/auth/session_queries.js +2 -1
  207. package/dist/auth/signup_routes.d.ts +2 -1
  208. package/dist/auth/signup_routes.d.ts.map +1 -1
  209. package/dist/auth/signup_routes.js +14 -13
  210. package/dist/auth/standard_rpc_actions.d.ts +1 -1
  211. package/dist/auth/standard_rpc_actions.d.ts.map +1 -1
  212. package/dist/auth/token_scope.d.ts +19 -46
  213. package/dist/auth/token_scope.d.ts.map +1 -1
  214. package/dist/auth/token_scope.js +23 -41
  215. package/dist/db/CLAUDE.md +9 -4
  216. package/dist/db/cell_ddl.d.ts +5 -142
  217. package/dist/db/cell_ddl.d.ts.map +1 -1
  218. package/dist/db/cell_ddl.js +17 -16
  219. package/dist/db/cell_field_queries.d.ts +0 -13
  220. package/dist/db/cell_field_queries.d.ts.map +1 -1
  221. package/dist/db/cell_field_queries.js +0 -16
  222. package/dist/db/cell_grant_queries.d.ts +10 -5
  223. package/dist/db/cell_grant_queries.d.ts.map +1 -1
  224. package/dist/db/cell_grant_queries.js +13 -7
  225. package/dist/db/cell_item_queries.d.ts +0 -7
  226. package/dist/db/cell_item_queries.d.ts.map +1 -1
  227. package/dist/db/cell_item_queries.js +0 -10
  228. package/dist/db/cell_queries.d.ts +12 -48
  229. package/dist/db/cell_queries.d.ts.map +1 -1
  230. package/dist/db/cell_queries.js +24 -55
  231. package/dist/db/cell_view_sql.d.ts +1 -6
  232. package/dist/db/cell_view_sql.d.ts.map +1 -1
  233. package/dist/db/cell_view_sql.js +1 -2
  234. package/dist/db/fact_ddl.d.ts +5 -30
  235. package/dist/db/fact_ddl.d.ts.map +1 -1
  236. package/dist/db/fact_ddl.js +14 -13
  237. package/dist/db/fact_store.d.ts +11 -0
  238. package/dist/db/fact_store.d.ts.map +1 -1
  239. package/dist/db/fact_store.js +4 -1
  240. package/dist/db/migrate.d.ts +44 -6
  241. package/dist/db/migrate.d.ts.map +1 -1
  242. package/dist/db/migrate.js +63 -4
  243. package/dist/dev/setup.d.ts +18 -14
  244. package/dist/dev/setup.d.ts.map +1 -1
  245. package/dist/dev/setup.js +42 -39
  246. package/dist/env/dotenv.d.ts +2 -2
  247. package/dist/env/dotenv.js +2 -2
  248. package/dist/env/update_env_variable.d.ts +33 -21
  249. package/dist/env/update_env_variable.d.ts.map +1 -1
  250. package/dist/env/update_env_variable.js +54 -35
  251. package/dist/hono_context.d.ts +15 -90
  252. package/dist/hono_context.d.ts.map +1 -1
  253. package/dist/hono_context.js +9 -56
  254. package/dist/http/CLAUDE.md +35 -20
  255. package/dist/http/auth_shape.d.ts +1 -8
  256. package/dist/http/auth_shape.d.ts.map +1 -1
  257. package/dist/http/auth_shape.js +6 -12
  258. package/dist/http/common_routes.d.ts.map +1 -1
  259. package/dist/http/common_routes.js +3 -2
  260. package/dist/http/db_routes.d.ts +3 -3
  261. package/dist/http/db_routes.js +3 -3
  262. package/dist/http/error_schemas.d.ts +1 -2
  263. package/dist/http/error_schemas.d.ts.map +1 -1
  264. package/dist/http/error_schemas.js +1 -2
  265. package/dist/http/health_schema.d.ts +16 -0
  266. package/dist/http/health_schema.d.ts.map +1 -0
  267. package/dist/http/health_schema.js +12 -0
  268. package/dist/http/jsonrpc_errors.d.ts +22 -2
  269. package/dist/http/jsonrpc_errors.d.ts.map +1 -1
  270. package/dist/http/jsonrpc_errors.js +41 -3
  271. package/dist/http/jsonrpc_helpers.d.ts +60 -17
  272. package/dist/http/jsonrpc_helpers.d.ts.map +1 -1
  273. package/dist/http/jsonrpc_helpers.js +67 -25
  274. package/dist/http/origin.d.ts +30 -1
  275. package/dist/http/origin.d.ts.map +1 -1
  276. package/dist/http/origin.js +46 -9
  277. package/dist/http/origin_wildcard.d.ts +97 -0
  278. package/dist/http/origin_wildcard.d.ts.map +1 -0
  279. package/dist/http/origin_wildcard.js +142 -0
  280. package/dist/http/pending_effects.d.ts +28 -0
  281. package/dist/http/pending_effects.d.ts.map +1 -1
  282. package/dist/http/pending_effects.js +32 -1
  283. package/dist/http/route_spec.d.ts +4 -3
  284. package/dist/http/route_spec.d.ts.map +1 -1
  285. package/dist/http/route_spec.js +54 -45
  286. package/dist/http/surface.d.ts +1 -1
  287. package/dist/http/surface.d.ts.map +1 -1
  288. package/dist/http/surface_query.d.ts +9 -50
  289. package/dist/http/surface_query.d.ts.map +1 -1
  290. package/dist/http/surface_query.js +48 -94
  291. package/dist/realtime/audit_log_sse.d.ts +180 -0
  292. package/dist/realtime/audit_log_sse.d.ts.map +1 -0
  293. package/dist/realtime/audit_log_sse.js +154 -0
  294. package/dist/realtime/sse.d.ts +21 -6
  295. package/dist/realtime/sse.d.ts.map +1 -1
  296. package/dist/realtime/sse.js +33 -10
  297. package/dist/realtime/sse_constants.d.ts +29 -2
  298. package/dist/realtime/sse_constants.d.ts.map +1 -1
  299. package/dist/realtime/sse_constants.js +35 -2
  300. package/dist/realtime/{subscriber_registry.d.ts → sse_registry.d.ts} +12 -12
  301. package/dist/realtime/sse_registry.d.ts.map +1 -0
  302. package/dist/realtime/{subscriber_registry.js → sse_registry.js} +4 -4
  303. package/dist/schema_meta.d.ts +30 -10
  304. package/dist/schema_meta.d.ts.map +1 -1
  305. package/dist/schema_meta.js +85 -21
  306. package/dist/sensitivity.d.ts +9 -3
  307. package/dist/sensitivity.d.ts.map +1 -1
  308. package/dist/sensitivity.js +3 -2
  309. package/dist/server/app_backend.d.ts +8 -5
  310. package/dist/server/app_backend.d.ts.map +1 -1
  311. package/dist/server/app_backend.js +6 -12
  312. package/dist/server/app_server.d.ts +62 -51
  313. package/dist/server/app_server.d.ts.map +1 -1
  314. package/dist/server/app_server.js +84 -71
  315. package/dist/server/app_server_context.d.ts +1 -1
  316. package/dist/server/app_server_context.d.ts.map +1 -1
  317. package/dist/server/env.d.ts +24 -20
  318. package/dist/server/env.d.ts.map +1 -1
  319. package/dist/server/env.js +24 -34
  320. package/dist/server/serve_fact_route.d.ts +12 -16
  321. package/dist/server/serve_fact_route.d.ts.map +1 -1
  322. package/dist/server/serve_fact_route.js +59 -34
  323. package/dist/server/static.d.ts.map +1 -1
  324. package/dist/server/static.js +2 -2
  325. package/dist/testing/CLAUDE.md +179 -158
  326. package/dist/testing/admin_integration.d.ts.map +1 -1
  327. package/dist/testing/admin_integration.js +10 -19
  328. package/dist/testing/adversarial_headers.d.ts.map +1 -1
  329. package/dist/testing/adversarial_headers.js +8 -0
  330. package/dist/testing/app_server.d.ts +9 -77
  331. package/dist/testing/app_server.d.ts.map +1 -1
  332. package/dist/testing/app_server.js +31 -112
  333. package/dist/testing/attack_surface.d.ts.map +1 -1
  334. package/dist/testing/attack_surface.js +3 -4
  335. package/dist/testing/audit_completeness.d.ts.map +1 -1
  336. package/dist/testing/audit_completeness.js +4 -5
  337. package/dist/testing/auth_apps.d.ts +3 -3
  338. package/dist/testing/auth_apps.d.ts.map +1 -1
  339. package/dist/testing/auth_apps.js +9 -6
  340. package/dist/testing/connection_closer_helpers.d.ts +8 -16
  341. package/dist/testing/connection_closer_helpers.d.ts.map +1 -1
  342. package/dist/testing/connection_closer_helpers.js +7 -20
  343. package/dist/testing/cross_backend/action_manifest.d.ts +15 -4
  344. package/dist/testing/cross_backend/action_manifest.d.ts.map +1 -1
  345. package/dist/testing/cross_backend/action_manifest.js +13 -3
  346. package/dist/testing/cross_backend/action_manifest_parity.d.ts +15 -7
  347. package/dist/testing/cross_backend/action_manifest_parity.d.ts.map +1 -1
  348. package/dist/testing/cross_backend/action_manifest_parity.js +8 -1
  349. package/dist/testing/cross_backend/body_size.d.ts.map +1 -1
  350. package/dist/testing/cross_backend/body_size.js +25 -22
  351. package/dist/testing/cross_backend/build_test_backend_paths.d.ts +22 -3
  352. package/dist/testing/cross_backend/build_test_backend_paths.d.ts.map +1 -1
  353. package/dist/testing/cross_backend/build_test_backend_paths.js +34 -11
  354. package/dist/testing/cross_backend/capabilities.d.ts +13 -7
  355. package/dist/testing/cross_backend/capabilities.d.ts.map +1 -1
  356. package/dist/testing/cross_backend/cell_grant_role.js +2 -2
  357. package/dist/testing/cross_backend/cell_grant_steward.d.ts +4 -0
  358. package/dist/testing/cross_backend/cell_grant_steward.d.ts.map +1 -0
  359. package/dist/testing/cross_backend/cell_grant_steward.js +120 -0
  360. package/dist/testing/cross_backend/cell_relations.d.ts.map +1 -1
  361. package/dist/testing/cross_backend/cell_relations.js +21 -0
  362. package/dist/testing/cross_backend/conformance_table.d.ts +1 -1
  363. package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
  364. package/dist/testing/cross_backend/default_backend_configs.d.ts +18 -4
  365. package/dist/testing/cross_backend/default_backend_configs.d.ts.map +1 -1
  366. package/dist/testing/cross_backend/default_backend_configs.js +29 -9
  367. package/dist/testing/cross_backend/default_spine_surface.d.ts +7 -7
  368. package/dist/testing/cross_backend/default_spine_surface.js +2 -2
  369. package/dist/testing/cross_backend/fact_serving.d.ts.map +1 -1
  370. package/dist/testing/cross_backend/fact_serving.js +48 -0
  371. package/dist/testing/cross_backend/full_spine_mount.d.ts +3 -4
  372. package/dist/testing/cross_backend/full_spine_mount.d.ts.map +1 -1
  373. package/dist/testing/cross_backend/full_spine_mount.js +9 -2
  374. package/dist/testing/cross_backend/origin_scope.d.ts.map +1 -1
  375. package/dist/testing/cross_backend/origin_scope.js +5 -13
  376. package/dist/testing/cross_backend/peer_ping_ws.d.ts.map +1 -1
  377. package/dist/testing/cross_backend/peer_ping_ws.js +29 -4
  378. package/dist/testing/cross_backend/postgres_database.d.ts +32 -0
  379. package/dist/testing/cross_backend/postgres_database.d.ts.map +1 -1
  380. package/dist/testing/cross_backend/postgres_database.js +56 -1
  381. package/dist/testing/cross_backend/query_shape.d.ts.map +1 -1
  382. package/dist/testing/cross_backend/query_shape.js +18 -1
  383. package/dist/testing/cross_backend/role_grant_offer_lifecycle.d.ts.map +1 -1
  384. package/dist/testing/cross_backend/role_grant_offer_lifecycle.js +23 -1
  385. package/dist/testing/cross_backend/rpc_success_fixtures.js +2 -2
  386. package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +1 -1
  387. package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
  388. package/dist/testing/cross_backend/rust_spine_stub_backend_config.d.ts +17 -5
  389. package/dist/testing/cross_backend/rust_spine_stub_backend_config.d.ts.map +1 -1
  390. package/dist/testing/cross_backend/rust_spine_stub_backend_config.js +5 -4
  391. package/dist/testing/cross_backend/session_cap.d.ts +8 -0
  392. package/dist/testing/cross_backend/session_cap.d.ts.map +1 -1
  393. package/dist/testing/cross_backend/session_cap.js +66 -2
  394. package/dist/testing/cross_backend/setup.d.ts.map +1 -1
  395. package/dist/testing/cross_backend/setup.js +5 -4
  396. package/dist/testing/cross_backend/spine_suites.d.ts +4 -1
  397. package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
  398. package/dist/testing/cross_backend/spine_suites.js +21 -0
  399. package/dist/testing/cross_backend/spine_surface_constants.d.ts +22 -7
  400. package/dist/testing/cross_backend/spine_surface_constants.d.ts.map +1 -1
  401. package/dist/testing/cross_backend/spine_surface_constants.js +22 -7
  402. package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
  403. package/dist/testing/cross_backend/sse_round_trip.js +4 -3
  404. package/dist/testing/cross_backend/standard.d.ts +6 -12
  405. package/dist/testing/cross_backend/standard.d.ts.map +1 -1
  406. package/dist/testing/cross_backend/test_cell_grant_steward_revoke_authorize.d.ts +8 -0
  407. package/dist/testing/cross_backend/test_cell_grant_steward_revoke_authorize.d.ts.map +1 -0
  408. package/dist/testing/cross_backend/test_cell_grant_steward_revoke_authorize.js +22 -0
  409. package/dist/testing/cross_backend/testing_backdoor.d.ts.map +1 -1
  410. package/dist/testing/cross_backend/testing_backdoor.js +4 -6
  411. package/dist/testing/cross_backend/testing_origin_check.d.ts +1 -1
  412. package/dist/testing/cross_backend/testing_origin_check.d.ts.map +1 -1
  413. package/dist/testing/cross_backend/testing_origin_check.js +1 -1
  414. package/dist/testing/cross_backend/testing_reset_actions.d.ts +10 -5
  415. package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
  416. package/dist/testing/cross_backend/testing_reset_actions.js +7 -6
  417. package/dist/testing/cross_backend/testing_server_bun.d.ts.map +1 -1
  418. package/dist/testing/cross_backend/testing_server_bun.js +5 -4
  419. package/dist/testing/cross_backend/testing_server_core.d.ts +6 -7
  420. package/dist/testing/cross_backend/testing_server_core.d.ts.map +1 -1
  421. package/dist/testing/cross_backend/testing_server_core.js +1 -1
  422. package/dist/testing/cross_backend/testing_server_node.d.ts.map +1 -1
  423. package/dist/testing/cross_backend/testing_server_node.js +13 -2
  424. package/dist/testing/cross_backend/token_lifetime.d.ts.map +1 -1
  425. package/dist/testing/cross_backend/token_lifetime.js +68 -0
  426. package/dist/testing/cross_backend/transport_composition.d.ts +1 -1
  427. package/dist/testing/cross_backend/transport_composition.d.ts.map +1 -1
  428. package/dist/testing/cross_backend/transport_composition.js +45 -3
  429. package/dist/testing/cross_backend/ts_spine_backend_config.d.ts +16 -2
  430. package/dist/testing/cross_backend/ts_spine_backend_config.d.ts.map +1 -1
  431. package/dist/testing/cross_backend/ts_spine_backend_config.js +11 -8
  432. package/dist/testing/cross_backend/ws_action_rate_limit.d.ts.map +1 -1
  433. package/dist/testing/cross_backend/ws_action_rate_limit.js +30 -12
  434. package/dist/testing/cross_backend/ws_connection_cap.d.ts.map +1 -1
  435. package/dist/testing/cross_backend/ws_connection_cap.js +5 -7
  436. package/dist/testing/cross_backend/ws_endpoint.d.ts +2 -3
  437. package/dist/testing/cross_backend/ws_endpoint.d.ts.map +1 -1
  438. package/dist/testing/cross_backend/ws_envelope.d.ts +17 -0
  439. package/dist/testing/cross_backend/ws_envelope.d.ts.map +1 -0
  440. package/dist/testing/cross_backend/ws_envelope.js +172 -0
  441. package/dist/testing/cross_backend/ws_inbound_dispatch.d.ts +16 -0
  442. package/dist/testing/cross_backend/ws_inbound_dispatch.d.ts.map +1 -1
  443. package/dist/testing/cross_backend/ws_inbound_dispatch.js +8 -4
  444. package/dist/testing/cross_backend/ws_outbound_overflow.d.ts.map +1 -1
  445. package/dist/testing/cross_backend/ws_outbound_overflow.js +5 -8
  446. package/dist/testing/cross_backend/ws_role_gated.js +2 -2
  447. package/dist/testing/cross_backend/ws_round_trip.d.ts.map +1 -1
  448. package/dist/testing/cross_backend/ws_round_trip.js +6 -4
  449. package/dist/{cli/daemon.d.ts → testing/daemon_info.d.ts} +15 -47
  450. package/dist/testing/daemon_info.d.ts.map +1 -0
  451. package/dist/testing/daemon_info.js +108 -0
  452. package/dist/testing/daemon_token_rotation.js +1 -1
  453. package/dist/testing/data_exposure.d.ts.map +1 -1
  454. package/dist/testing/data_exposure.js +3 -4
  455. package/dist/testing/db.js +2 -2
  456. package/dist/testing/integration.d.ts.map +1 -1
  457. package/dist/testing/integration.js +35 -65
  458. package/dist/testing/integration_helpers.d.ts +0 -15
  459. package/dist/testing/integration_helpers.d.ts.map +1 -1
  460. package/dist/testing/integration_helpers.js +2 -42
  461. package/dist/testing/middleware.d.ts +20 -12
  462. package/dist/testing/middleware.d.ts.map +1 -1
  463. package/dist/testing/middleware.js +49 -40
  464. package/dist/testing/rate_limiting.d.ts.map +1 -1
  465. package/dist/testing/rate_limiting.js +13 -22
  466. package/dist/testing/resolved_auth.d.ts +30 -0
  467. package/dist/testing/resolved_auth.d.ts.map +1 -0
  468. package/dist/testing/resolved_auth.js +41 -0
  469. package/dist/testing/rpc_envelope_cases.d.ts.map +1 -1
  470. package/dist/testing/rpc_envelope_cases.js +3 -0
  471. package/dist/testing/rpc_helpers.d.ts +1 -1
  472. package/dist/testing/rpc_helpers.d.ts.map +1 -1
  473. package/dist/testing/rpc_helpers.js +2 -1
  474. package/dist/testing/sse_round_trip.d.ts +5 -4
  475. package/dist/testing/sse_round_trip.d.ts.map +1 -1
  476. package/dist/testing/sse_round_trip.js +2 -2
  477. package/dist/testing/stubs.d.ts +2 -2
  478. package/dist/testing/stubs.d.ts.map +1 -1
  479. package/dist/testing/stubs.js +24 -21
  480. package/dist/testing/test_origin.d.ts +25 -0
  481. package/dist/testing/test_origin.d.ts.map +1 -0
  482. package/dist/testing/test_origin.js +28 -0
  483. package/dist/testing/transports/raw_http.d.ts +54 -0
  484. package/dist/testing/transports/raw_http.d.ts.map +1 -1
  485. package/dist/testing/transports/raw_http.js +58 -0
  486. package/dist/testing/transports/ws_raw_client.d.ts +8 -0
  487. package/dist/testing/transports/ws_raw_client.d.ts.map +1 -1
  488. package/dist/testing/transports/ws_raw_client.js +13 -0
  489. package/dist/testing/transports/ws_transport.d.ts +15 -2
  490. package/dist/testing/transports/ws_transport.d.ts.map +1 -1
  491. package/dist/testing/transports/ws_transport.js +4 -2
  492. package/dist/testing/ws_round_trip.d.ts +27 -25
  493. package/dist/testing/ws_round_trip.d.ts.map +1 -1
  494. package/dist/testing/ws_round_trip.js +34 -26
  495. package/dist/ui/AccountSessions.svelte +48 -19
  496. package/dist/ui/AccountSessions.svelte.d.ts +2 -17
  497. package/dist/ui/AccountSessions.svelte.d.ts.map +1 -1
  498. package/dist/ui/AdminAccounts.svelte +6 -1
  499. package/dist/ui/AdminAuditLog.svelte +61 -22
  500. package/dist/ui/AdminAuditLog.svelte.d.ts.map +1 -1
  501. package/dist/ui/AdminInvites.svelte +1 -1
  502. package/dist/ui/AdminOverview.svelte +76 -37
  503. package/dist/ui/AdminOverview.svelte.d.ts.map +1 -1
  504. package/dist/ui/AdminRoleGrantHistory.svelte +6 -1
  505. package/dist/ui/AdminSessions.svelte +1 -1
  506. package/dist/ui/AppShell.svelte +3 -2
  507. package/dist/ui/AppShell.svelte.d.ts +3 -2
  508. package/dist/ui/AppShell.svelte.d.ts.map +1 -1
  509. package/dist/ui/CLAUDE.md +121 -35
  510. package/dist/ui/Datatable.svelte +33 -18
  511. package/dist/ui/Datatable.svelte.d.ts +2 -14
  512. package/dist/ui/Datatable.svelte.d.ts.map +1 -1
  513. package/dist/ui/OpenSignupToggle.svelte +10 -1
  514. package/dist/ui/OpenSignupToggle.svelte.d.ts.map +1 -1
  515. package/dist/ui/PopoverButton.svelte +13 -8
  516. package/dist/ui/PopoverButton.svelte.d.ts.map +1 -1
  517. package/dist/ui/RoleGrantOfferForm.svelte +3 -2
  518. package/dist/ui/RoleGrantOfferForm.svelte.d.ts +3 -2
  519. package/dist/ui/RoleGrantOfferForm.svelte.d.ts.map +1 -1
  520. package/dist/ui/RoleGrantOfferHistory.svelte +3 -3
  521. package/dist/ui/RoleGrantOfferInbox.svelte +19 -15
  522. package/dist/ui/RoleGrantOfferInbox.svelte.d.ts.map +1 -1
  523. package/dist/ui/SurfaceExplorer.svelte +66 -27
  524. package/dist/ui/SurfaceExplorer.svelte.d.ts.map +1 -1
  525. package/dist/ui/account_sessions_state.svelte.d.ts +7 -14
  526. package/dist/ui/account_sessions_state.svelte.d.ts.map +1 -1
  527. package/dist/ui/admin_accounts_state.svelte.d.ts +14 -9
  528. package/dist/ui/admin_accounts_state.svelte.d.ts.map +1 -1
  529. package/dist/ui/admin_accounts_state.svelte.js +6 -4
  530. package/dist/ui/admin_invites_state.svelte.d.ts +2 -2
  531. package/dist/ui/admin_invites_state.svelte.d.ts.map +1 -1
  532. package/dist/ui/admin_rpc_adapters.d.ts +9 -9
  533. package/dist/ui/admin_rpc_adapters.d.ts.map +1 -1
  534. package/dist/ui/admin_rpc_adapters.js +9 -9
  535. package/dist/ui/app_settings_state.svelte.d.ts +2 -2
  536. package/dist/ui/app_settings_state.svelte.d.ts.map +1 -1
  537. package/dist/ui/audit_log_state.svelte.d.ts +70 -13
  538. package/dist/ui/audit_log_state.svelte.d.ts.map +1 -1
  539. package/dist/ui/audit_log_state.svelte.js +239 -47
  540. package/dist/ui/backend_probe.svelte.d.ts +93 -0
  541. package/dist/ui/backend_probe.svelte.d.ts.map +1 -0
  542. package/dist/ui/backend_probe.svelte.js +140 -0
  543. package/dist/ui/format_scope.d.ts +7 -7
  544. package/dist/ui/format_scope.d.ts.map +1 -1
  545. package/dist/ui/format_scope.js +4 -4
  546. package/dist/ui/keyed_async_slot.svelte.d.ts +2 -2
  547. package/dist/ui/keyed_async_slot.svelte.js +2 -2
  548. package/dist/ui/popover.svelte.d.ts +18 -19
  549. package/dist/ui/popover.svelte.d.ts.map +1 -1
  550. package/dist/ui/popover.svelte.js +103 -16
  551. package/dist/ui/role_grant_offers_state.svelte.d.ts +41 -46
  552. package/dist/ui/role_grant_offers_state.svelte.d.ts.map +1 -1
  553. package/dist/ui/role_grant_offers_state.svelte.js +37 -19
  554. package/dist/ui/ui_format.d.ts +17 -0
  555. package/dist/ui/ui_format.d.ts.map +1 -1
  556. package/dist/ui/ui_format.js +20 -0
  557. package/package.json +9 -8
  558. package/dist/actions/register_ws_endpoint.d.ts +0 -79
  559. package/dist/actions/register_ws_endpoint.d.ts.map +0 -1
  560. package/dist/actions/register_ws_endpoint.js +0 -109
  561. package/dist/actions/transports_ws_auth_guard.d.ts +0 -96
  562. package/dist/actions/transports_ws_auth_guard.d.ts.map +0 -1
  563. package/dist/actions/transports_ws_auth_guard.js +0 -141
  564. package/dist/actions/transports_ws_backend.d.ts.map +0 -1
  565. package/dist/cli/args.d.ts +0 -55
  566. package/dist/cli/args.d.ts.map +0 -1
  567. package/dist/cli/args.js +0 -100
  568. package/dist/cli/config.d.ts +0 -47
  569. package/dist/cli/config.d.ts.map +0 -1
  570. package/dist/cli/config.js +0 -77
  571. package/dist/cli/daemon.d.ts.map +0 -1
  572. package/dist/cli/daemon.js +0 -181
  573. package/dist/cli/help.d.ts +0 -124
  574. package/dist/cli/help.d.ts.map +0 -1
  575. package/dist/cli/help.js +0 -215
  576. package/dist/cli/logger.d.ts +0 -46
  577. package/dist/cli/logger.d.ts.map +0 -1
  578. package/dist/cli/logger.js +0 -48
  579. package/dist/cli/util.d.ts +0 -36
  580. package/dist/cli/util.d.ts.map +0 -1
  581. package/dist/cli/util.js +0 -50
  582. package/dist/realtime/sse_auth_guard.d.ts +0 -197
  583. package/dist/realtime/sse_auth_guard.d.ts.map +0 -1
  584. package/dist/realtime/sse_auth_guard.js +0 -239
  585. package/dist/realtime/subscriber_registry.d.ts.map +0 -1
  586. package/dist/testing/bootstrap_success.d.ts +0 -29
  587. package/dist/testing/bootstrap_success.d.ts.map +0 -1
  588. package/dist/testing/bootstrap_success.js +0 -144
  589. package/dist/testing/mock_fs.d.ts +0 -20
  590. package/dist/testing/mock_fs.d.ts.map +0 -1
  591. package/dist/testing/mock_fs.js +0 -28
  592. package/dist/testing/standard.d.ts +0 -122
  593. package/dist/testing/standard.d.ts.map +0 -1
  594. package/dist/testing/standard.js +0 -73
  595. package/dist/testing/testing_rate_limiter.d.ts +0 -65
  596. package/dist/testing/testing_rate_limiter.d.ts.map +0 -1
  597. package/dist/testing/testing_rate_limiter.js +0 -80
@@ -15,6 +15,7 @@ import { assert_row } from '../db/assert_row.js';
15
15
  import { columns_sql, qualify_columns } from '../db/sql_columns.js';
16
16
  import { ROLE_GRANT_OFFER_COLUMNS, role_grant_offer_expr, 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';
17
17
  import { query_create_role_grant, query_role_grant_by_id } from './role_grant_queries.js';
18
+ import { offer_pending_predicate, role_grant_active_sql } from './role_grant_sql.js';
18
19
  import { query_audit_log } from './audit_log_queries.js';
19
20
  import { is_builtin_role, ROLE_ADMIN, ROLE_KEEPER } from './role_schema.js';
20
21
  /**
@@ -168,7 +169,7 @@ export const query_role_grant_offer_create = async (deps, input) => {
168
169
  COALESCE(scope_id, '${ROLE_GRANT_OFFER_SCOPE_SENTINEL_UUID}'::uuid),
169
170
  from_actor_id
170
171
  )
171
- WHERE accepted_at IS NULL AND declined_at IS NULL AND retracted_at IS NULL AND superseded_at IS NULL
172
+ WHERE ${offer_pending_predicate('')}
172
173
  DO UPDATE SET
173
174
  to_actor_id = EXCLUDED.to_actor_id,
174
175
  message = EXCLUDED.message,
@@ -209,10 +210,7 @@ export const query_role_grant_offer_decline = async (deps, offer_id, to_account_
209
210
  SET declined_at = NOW(), decline_reason = $3
210
211
  WHERE id = $1
211
212
  AND to_account_id = $2
212
- AND accepted_at IS NULL
213
- AND declined_at IS NULL
214
- AND retracted_at IS NULL
215
- AND superseded_at IS NULL
213
+ AND ${offer_pending_predicate('')}
216
214
  -- raw columns; the outer grantor select formats them
217
215
  RETURNING ${columns_sql(ROLE_GRANT_OFFER_COLUMNS)}
218
216
  )
@@ -237,10 +235,7 @@ export const query_role_grant_offer_retract = async (deps, offer_id, from_actor_
237
235
  SET retracted_at = NOW()
238
236
  WHERE id = $1
239
237
  AND from_actor_id = $2
240
- AND accepted_at IS NULL
241
- AND declined_at IS NULL
242
- AND retracted_at IS NULL
243
- AND superseded_at IS NULL
238
+ AND ${offer_pending_predicate('')}
244
239
  RETURNING ${columns_sql(ROLE_GRANT_OFFER_COLUMNS, role_grant_offer_expr(''))}`, [offer_id, from_actor_id]);
245
240
  if (updated)
246
241
  return updated;
@@ -277,10 +272,7 @@ const resolve_terminal_or_missing = async (deps, offer_id, scope) => {
277
272
  export const query_role_grant_offer_list = async (deps, to_account_id) => {
278
273
  return deps.db.query(`SELECT ${columns_sql(ROLE_GRANT_OFFER_COLUMNS, role_grant_offer_expr(''))} FROM role_grant_offer
279
274
  WHERE to_account_id = $1
280
- AND accepted_at IS NULL
281
- AND declined_at IS NULL
282
- AND retracted_at IS NULL
283
- AND superseded_at IS NULL
275
+ AND ${offer_pending_predicate('')}
284
276
  AND expires_at > NOW()
285
277
  ORDER BY role_grant_offer.expires_at ASC`, [to_account_id]);
286
278
  };
@@ -296,20 +288,6 @@ export const query_role_grant_offer_history_for_account = async (deps, account_i
296
288
  ORDER BY o.created_at DESC
297
289
  LIMIT $2 OFFSET $3`, [account_id, limit, offset]);
298
290
  };
299
- /**
300
- * Look up a pending offer by id. Returns `null` if the offer is terminal,
301
- * expired (server-side filter), or missing.
302
- */
303
- export const query_role_grant_offer_find_pending = async (deps, offer_id) => {
304
- const row = await deps.db.query_one(`SELECT ${columns_sql(ROLE_GRANT_OFFER_COLUMNS, role_grant_offer_expr(''))} FROM role_grant_offer
305
- WHERE id = $1
306
- AND accepted_at IS NULL
307
- AND declined_at IS NULL
308
- AND retracted_at IS NULL
309
- AND superseded_at IS NULL
310
- AND expires_at > NOW()`, [offer_id]);
311
- return row ?? null;
312
- };
313
291
  /**
314
292
  * Claim the pending offers whose `expires_at` has passed and whose expiry has
315
293
  * not been audited yet, stamping `expire_audited_at` on each, and return them
@@ -329,10 +307,7 @@ export const query_role_grant_offer_sweep_expired = async (deps) => {
329
307
  return deps.db.query(`WITH claimed AS (
330
308
  UPDATE role_grant_offer
331
309
  SET expire_audited_at = NOW()
332
- WHERE accepted_at IS NULL
333
- AND declined_at IS NULL
334
- AND retracted_at IS NULL
335
- AND superseded_at IS NULL
310
+ WHERE ${offer_pending_predicate('')}
336
311
  AND expires_at <= NOW()
337
312
  AND expire_audited_at IS NULL
338
313
  -- raw columns; the outer select formats them
@@ -363,8 +338,7 @@ const query_grantor_holds_global_admin = async (deps, grantor_actor_id) => {
363
338
  WHERE rg.actor_id = $1
364
339
  AND rg.role = $2
365
340
  AND rg.scope_id IS NULL
366
- AND rg.revoked_at IS NULL
367
- AND (rg.expires_at IS NULL OR rg.expires_at > NOW())
341
+ AND ${role_grant_active_sql('rg')}
368
342
  AND act.deleted_at IS NULL
369
343
  AND a.deleted_at IS NULL
370
344
  LIMIT 1
@@ -553,10 +527,7 @@ export const query_accept_offer = async (deps, input) => {
553
527
  AND role = $2
554
528
  AND scope_id IS NOT DISTINCT FROM $3
555
529
  AND id <> $4
556
- AND accepted_at IS NULL
557
- AND declined_at IS NULL
558
- AND retracted_at IS NULL
559
- AND superseded_at IS NULL
530
+ AND ${offer_pending_predicate('')}
560
531
  -- raw columns; the outer grantor select formats them
561
532
  RETURNING ${columns_sql(ROLE_GRANT_OFFER_COLUMNS)}
562
533
  )
@@ -654,10 +625,7 @@ export const query_role_grant_offer_supersede_outgoing = async (deps, from_actor
654
625
  UPDATE role_grant_offer
655
626
  SET superseded_at = NOW()
656
627
  WHERE from_actor_id = ANY($1)
657
- AND accepted_at IS NULL
658
- AND declined_at IS NULL
659
- AND retracted_at IS NULL
660
- AND superseded_at IS NULL
628
+ AND ${offer_pending_predicate('')}
661
629
  -- raw columns; the outer grantor select formats them
662
630
  RETURNING ${columns_sql(ROLE_GRANT_OFFER_COLUMNS)}
663
631
  )
@@ -21,8 +21,14 @@ import type { SupersededOffer } from './role_grant_offer_schema.js';
21
21
  export declare const ROLE_GRANT_COLUMNS: readonly ["id", "actor_id", "role", "scope_kind", "scope_id", "created_at", "expires_at", "revoked_at", "revoked_by", "revoked_reason", "granted_by", "source_offer_id"];
22
22
  /**
23
23
  * Grant a role_grant to an actor.
24
- * Idempotent — if an active role_grant already exists for this actor, role, and
25
- * scope, returns the existing role_grant instead of creating a duplicate.
24
+ * Idempotent — if an active (unrevoked and unexpired) role_grant already
25
+ * exists for this actor, role, and scope, returns it instead of creating a
26
+ * duplicate. An expired but unrevoked row in the slot is first revoked
27
+ * (`revoked_reason = 'expired'`, `revoked_by` null — nobody chose to revoke
28
+ * it) so the fresh grant can take its place; returning the expired row would
29
+ * report a grant that confers nothing. The revoke and the insert are two
30
+ * statements, atomic when the caller runs them in a transaction (the action
31
+ * and offer-accept paths do).
26
32
  *
27
33
  * The `ON CONFLICT` target and the fallback `SELECT` both collapse `NULL`
28
34
  * scopes via the same sentinel + index-side `'GLOBAL'` token used by the
@@ -37,7 +43,7 @@ export declare const ROLE_GRANT_COLUMNS: readonly ["id", "actor_id", "role", "sc
37
43
  * @param deps - query dependencies
38
44
  * @param input - the role_grant fields
39
45
  * @returns the created or existing active role_grant
40
- * @mutates `role_grant` table - inserts a row when no active role_grant matches `(actor_id, role, scope_kind, scope_id)`
46
+ * @mutates `role_grant` table - revokes an expired unrevoked row at `(actor_id, role, scope_kind, scope_id)`, then inserts a row when no active role_grant matches
41
47
  */
42
48
  export declare const query_create_role_grant: (deps: QueryDeps, input: CreateRoleGrantInput) => Promise<RoleGrant>;
43
49
  /**
@@ -122,23 +128,11 @@ export declare const query_revoke_role_grant: (deps: QueryDeps, role_grant_id: U
122
128
  * Find all active (non-revoked, non-expired) role_grants for an actor.
123
129
  */
124
130
  export declare const query_role_grant_find_active_for_actor: (deps: QueryDeps, actor_id: string) => Promise<Array<RoleGrant>>;
125
- /**
126
- * Check if an actor has an active role_grant for a given role.
127
- *
128
- * The `scope_id` parameter selects between global and scoped checks:
129
- * - Omitted or `null` — matches a global role_grant (`scope_id IS NULL`).
130
- * Pre-scope callers keep their existing semantics.
131
- * - A scope uuid — matches a role_grant bound to that exact scope.
132
- *
133
- * The `IS NOT DISTINCT FROM` comparison handles the NULL case uniformly.
134
- */
135
- export declare const query_role_grant_has_role: (deps: QueryDeps, actor_id: string, role: string, scope_id?: string | null) => Promise<boolean>;
136
131
  /**
137
132
  * Account-grain check: does any actor on `account_id` hold an active
138
133
  * global role_grant for `role`?
139
134
  *
140
- * Symmetric with `query_role_grant_has_role` but keyed on the account
141
- * instead of a single actor — for surfaces with `auth: actor: 'none'`
135
+ * Keyed on the account rather than a single actor — for surfaces with `auth: actor: 'none'`
142
136
  * that don't load `auth.role_grants` and can't use the in-memory
143
137
  * `has_scoped_role` predicate. Joins `role_grant` → `actor`; matches
144
138
  * only global role_grants (`scope_id IS NULL`) since the use case is
@@ -214,11 +208,11 @@ export declare const query_account_has_active_global_role: (deps: QueryDeps, acc
214
208
  */
215
209
  export declare const query_count_active_accounts_with_global_role_for_update: (deps: QueryDeps, role: string, exclude_role_grant_id?: Uuid | null) => Promise<number>;
216
210
  /**
217
- * List all role_grants for an actor (including revoked/expired).
218
- */
219
- export declare const query_role_grant_list_for_actor: (deps: QueryDeps, actor_id: string) => Promise<Array<RoleGrant>>;
220
- /**
221
- * Find the account ID of an account that holds an active role_grant for a given role.
211
+ * Find the account ID of an account that holds an active **global** role_grant
212
+ * for a given role.
213
+ *
214
+ * Global-only (`scope_id IS NULL`), like every builtin read: a scoped row of
215
+ * the role confers nothing, so it must not resolve the keeper identity.
222
216
  *
223
217
  * Joins role_grant → actor → account, counting only an **active account + active
224
218
  * actor** (`deleted_at IS NULL` on both). This *resolves* an identity (the
@@ -275,8 +269,8 @@ export interface RevokeForScopeResult {
275
269
  * orphan role_grants and offers. The cascade is **role-agnostic**: anything
276
270
  * attached to the destroyed scope is cleaned up.
277
271
  *
278
- * Both updates run as separate statements inside the caller's transaction
279
- * (mirrors `query_role_grant_revoke_role`'s shape). The two halves are
272
+ * Both updates run as separate statements inside the caller's transaction,
273
+ * the `role_grant` revoke first. The two halves are
280
274
  * independent — orphan pending offers can exist at a scope with no active
281
275
  * role_grants, so the supersede half always runs even when no role_grant was
282
276
  * revoked.
@@ -290,48 +284,4 @@ export interface RevokeForScopeResult {
290
284
  * @mutates `role_grant_offer` table - stamps `superseded_at` on every pending row at `scope_id`
291
285
  */
292
286
  export declare const query_role_grant_revoke_for_scope: (deps: QueryDeps, scope_id: Uuid, revoked_by: Uuid | null, reason?: string | null) => Promise<RevokeForScopeResult>;
293
- /** Result of `query_role_grant_revoke_role` — every role_grant revoked plus the pending offers superseded by the bulk revoke. */
294
- export interface RevokeRoleResult {
295
- /**
296
- * One entry per role_grant revoked by this call. Carries the revokee's
297
- * `account_id` so callers can fan out a `role_grant_revoke` notification per
298
- * scope-instance. Empty array means nothing was active for `(actor, role)`.
299
- */
300
- revoked: Array<{
301
- role_grant_id: string;
302
- role: string;
303
- scope_kind: string | null;
304
- scope_id: string | null;
305
- account_id: string;
306
- }>;
307
- /**
308
- * Pending offers for the actor's account+role (all scopes) superseded by
309
- * the bulk revoke. Each entry carries its grantor's `from_account_id` so
310
- * callers can fan out `role_grant_offer_supersede` notifications without a
311
- * second round-trip.
312
- */
313
- superseded_offers: Array<SupersededOffer>;
314
- }
315
- /**
316
- * Revoke every active role_grant an actor holds for a given role.
317
- *
318
- * With scoped role_grants a single actor+role tuple can hold several active
319
- * role_grants (one per scope), so this revokes all of them. Pass
320
- * `query_revoke_role_grant(role_grant_id, ...)` when a single scoped role_grant
321
- * is the target.
322
- *
323
- * Also supersedes pending offers for the actor's account across every
324
- * scope of this role (the actor can no longer hold the role, so any
325
- * pending offer of the same role is a bypass vector).
326
- *
327
- * @param deps - query dependencies
328
- * @param actor_id - the actor whose role_grants to revoke
329
- * @param role - the role to revoke
330
- * @param revoked_by - the actor who revoked it (for audit trail)
331
- * @param reason - optional free-form reason, stamped on `role_grant.revoked_reason`.
332
- * @returns the list of revoked role_grants (empty if none were active) and superseded pending offers
333
- * @mutates `role_grant` table - sets `revoked_at`/`revoked_by`/`revoked_reason` on every active row for `(actor, role)`
334
- * @mutates `role_grant_offer` table - stamps `superseded_at` on every matching pending offer
335
- */
336
- export declare const query_role_grant_revoke_role: (deps: QueryDeps, actor_id: string, role: string, revoked_by: string | null, reason?: string | null) => Promise<RevokeRoleResult>;
337
287
  //# sourceMappingURL=role_grant_queries.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"role_grant_queries.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/auth/role_grant_queries.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAS3E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAEpE;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,0KAaoB,CAAC;AAcpD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,uBAAuB,GACnC,MAAM,SAAS,EACf,OAAO,oBAAoB,KACzB,OAAO,CAAC,SAAS,CAmCnB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,GAClC,MAAM,SAAS,EACf,IAAI,IAAI,KACN,OAAO,CAAC,SAAS,GAAG,SAAS,CAI9B,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,2CAA2C,GACvD,MAAM,SAAS,EACf,eAAe,MAAM,EACrB,UAAU,MAAM,KACd,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAC;IAAC,UAAU,EAAE,IAAI,CAAA;CAAE,GAAG,IAAI,CAS1E,CAAC;AAEF,qHAAqH;AACrH,MAAM,WAAW,qBAAqB;IACrC,EAAE,EAAE,IAAI,CAAC;IACT,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MA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MAAM,GAAG,IAAI,CAAC;QAC1B,QAAQ,EAAE,IAAI,CAAC;QACf,QAAQ,EAAE,IAAI,CAAC;QACf,UAAU,EAAE,IAAI,CAAC;KACjB,CAAC,CAAC;IACH;;;;;;;;;;OAUG;IACH,iBAAiB,EAAE,KAAK,CAAC,eAAe,CAAC,CAAC;CAC1C;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,iCAAiC,GAC7C,MAAM,SAAS,EACf,UAAU,IAAI,EACd,YAAY,IAAI,GAAG,IAAI,EACvB,SAAS,MAAM,GAAG,IAAI,KACpB,OAAO,CAAC,oBAAoB,CA0C9B,CAAC"}
@@ -9,6 +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
13
  /**
13
14
  * The full `role_grant` column set, named explicitly so a row read fails loud
14
15
  * on schema drift (see `ACCOUNT_COLUMNS` in `auth/account_queries.ts` for the
@@ -44,8 +45,14 @@ const role_grant_expr = iso8601_timestamp_expr(ROLE_GRANT_COLUMNS, [
44
45
  ])('');
45
46
  /**
46
47
  * Grant a role_grant to an actor.
47
- * Idempotent — if an active role_grant already exists for this actor, role, and
48
- * scope, returns the existing role_grant instead of creating a duplicate.
48
+ * Idempotent — if an active (unrevoked and unexpired) role_grant already
49
+ * exists for this actor, role, and scope, returns it instead of creating a
50
+ * duplicate. An expired but unrevoked row in the slot is first revoked
51
+ * (`revoked_reason = 'expired'`, `revoked_by` null — nobody chose to revoke
52
+ * it) so the fresh grant can take its place; returning the expired row would
53
+ * report a grant that confers nothing. The revoke and the insert are two
54
+ * statements, atomic when the caller runs them in a transaction (the action
55
+ * and offer-accept paths do).
49
56
  *
50
57
  * The `ON CONFLICT` target and the fallback `SELECT` both collapse `NULL`
51
58
  * scopes via the same sentinel + index-side `'GLOBAL'` token used by the
@@ -60,9 +67,17 @@ const role_grant_expr = iso8601_timestamp_expr(ROLE_GRANT_COLUMNS, [
60
67
  * @param deps - query dependencies
61
68
  * @param input - the role_grant fields
62
69
  * @returns the created or existing active role_grant
63
- * @mutates `role_grant` table - inserts a row when no active role_grant matches `(actor_id, role, scope_kind, scope_id)`
70
+ * @mutates `role_grant` table - revokes an expired unrevoked row at `(actor_id, role, scope_kind, scope_id)`, then inserts a row when no active role_grant matches
64
71
  */
65
72
  export const query_create_role_grant = async (deps, input) => {
73
+ // an expired row still holds the partial unique slot (`revoked_at IS NULL`)
74
+ await deps.db.query(`UPDATE role_grant SET revoked_at = NOW(), revoked_by = NULL, revoked_reason = 'expired'
75
+ WHERE actor_id = $1
76
+ AND role = $2
77
+ AND scope_kind IS NOT DISTINCT FROM $3
78
+ AND scope_id IS NOT DISTINCT FROM $4
79
+ AND revoked_at IS NULL
80
+ AND expires_at <= NOW()`, [input.actor_id, input.role, input.scope_kind ?? null, input.scope_id ?? null]);
66
81
  const inserted = await deps.db.query_one(`INSERT INTO role_grant (actor_id, role, scope_kind, scope_id, expires_at, granted_by, source_offer_id)
67
82
  VALUES ($1, $2, $3, $4, $5, $6, $7)
68
83
  ON CONFLICT (
@@ -176,10 +191,7 @@ export const query_revoke_role_grant = async (deps, role_grant_id, actor_id, rev
176
191
  AND o.to_account_id = a.account_id
177
192
  AND o.role = $2
178
193
  AND o.scope_id IS NOT DISTINCT FROM $3
179
- AND o.accepted_at IS NULL
180
- AND o.declined_at IS NULL
181
- AND o.retracted_at IS NULL
182
- AND o.superseded_at IS NULL
194
+ AND ${offer_pending_predicate('o')}
183
195
  -- raw columns; the outer grantor select formats them
184
196
  RETURNING ${qualify_columns(ROLE_GRANT_OFFER_COLUMNS, 'o')}
185
197
  )
@@ -198,37 +210,14 @@ export const query_revoke_role_grant = async (deps, role_grant_id, actor_id, rev
198
210
  export const query_role_grant_find_active_for_actor = async (deps, actor_id) => {
199
211
  return deps.db.query(`SELECT ${columns_sql(ROLE_GRANT_COLUMNS, role_grant_expr)} FROM role_grant
200
212
  WHERE actor_id = $1
201
- AND revoked_at IS NULL
202
- AND (expires_at IS NULL OR expires_at > NOW())
213
+ AND ${role_grant_active_sql('')}
203
214
  ORDER BY role_grant.created_at`, [actor_id]);
204
215
  };
205
- /**
206
- * Check if an actor has an active role_grant for a given role.
207
- *
208
- * The `scope_id` parameter selects between global and scoped checks:
209
- * - Omitted or `null` — matches a global role_grant (`scope_id IS NULL`).
210
- * Pre-scope callers keep their existing semantics.
211
- * - A scope uuid — matches a role_grant bound to that exact scope.
212
- *
213
- * The `IS NOT DISTINCT FROM` comparison handles the NULL case uniformly.
214
- */
215
- export const query_role_grant_has_role = async (deps, actor_id, role, scope_id) => {
216
- const row = await deps.db.query_one(`SELECT EXISTS(
217
- SELECT 1 FROM role_grant
218
- WHERE actor_id = $1
219
- AND role = $2
220
- AND scope_id IS NOT DISTINCT FROM $3
221
- AND revoked_at IS NULL
222
- AND (expires_at IS NULL OR expires_at > NOW())
223
- ) AS exists`, [actor_id, role, scope_id ?? null]);
224
- return row?.exists ?? false;
225
- };
226
216
  /**
227
217
  * Account-grain check: does any actor on `account_id` hold an active
228
218
  * global role_grant for `role`?
229
219
  *
230
- * Symmetric with `query_role_grant_has_role` but keyed on the account
231
- * instead of a single actor — for surfaces with `auth: actor: 'none'`
220
+ * Keyed on the account rather than a single actor — for surfaces with `auth: actor: 'none'`
232
221
  * that don't load `auth.role_grants` and can't use the in-memory
233
222
  * `has_scoped_role` predicate. Joins `role_grant` → `actor`; matches
234
223
  * only global role_grants (`scope_id IS NULL`) since the use case is
@@ -256,8 +245,7 @@ export const query_account_has_global_role = async (deps, account_id, role) => {
256
245
  WHERE actor_id IN (SELECT id FROM actor WHERE account_id = $1)
257
246
  AND role = $2
258
247
  AND scope_id IS NULL
259
- AND revoked_at IS NULL
260
- AND (expires_at IS NULL OR expires_at > NOW())
248
+ AND ${role_grant_active_sql('')}
261
249
  ) AS exists`, [account_id, role]);
262
250
  return row?.exists ?? false;
263
251
  };
@@ -291,8 +279,7 @@ export const query_account_has_active_global_role = async (deps, account_id, rol
291
279
  AND act.deleted_at IS NULL
292
280
  AND rg.role = $2
293
281
  AND rg.scope_id IS NULL
294
- AND rg.revoked_at IS NULL
295
- AND (rg.expires_at IS NULL OR rg.expires_at > NOW())
282
+ AND ${role_grant_active_sql('rg')}
296
283
  ) AS exists`, [account_id, role]);
297
284
  return row?.exists ?? false;
298
285
  };
@@ -339,8 +326,7 @@ export const query_count_active_accounts_with_global_role_for_update = async (de
339
326
  AND act.deleted_at IS NULL
340
327
  AND rg.role = $1
341
328
  AND rg.scope_id IS NULL
342
- AND rg.revoked_at IS NULL
343
- AND (rg.expires_at IS NULL OR rg.expires_at > NOW())
329
+ AND ${role_grant_active_sql('rg')}
344
330
  FOR UPDATE`, [role]);
345
331
  const account_ids = new Set();
346
332
  for (const row of rows) {
@@ -350,13 +336,11 @@ export const query_count_active_accounts_with_global_role_for_update = async (de
350
336
  return account_ids.size;
351
337
  };
352
338
  /**
353
- * List all role_grants for an actor (including revoked/expired).
354
- */
355
- export const query_role_grant_list_for_actor = async (deps, actor_id) => {
356
- return deps.db.query(`SELECT ${columns_sql(ROLE_GRANT_COLUMNS, role_grant_expr)} FROM role_grant WHERE actor_id = $1 ORDER BY role_grant.created_at DESC`, [actor_id]);
357
- };
358
- /**
359
- * Find the account ID of an account that holds an active role_grant for a given role.
339
+ * Find the account ID of an account that holds an active **global** role_grant
340
+ * for a given role.
341
+ *
342
+ * Global-only (`scope_id IS NULL`), like every builtin read: a scoped row of
343
+ * the role confers nothing, so it must not resolve the keeper identity.
360
344
  *
361
345
  * Joins role_grant → actor → account, counting only an **active account + active
362
346
  * actor** (`deleted_at IS NULL` on both). This *resolves* an identity (the
@@ -376,10 +360,10 @@ export const query_role_grant_find_account_id_for_role = async (deps, role) => {
376
360
  JOIN actor act ON act.id = p.actor_id
377
361
  JOIN account a ON a.id = act.account_id
378
362
  WHERE p.role = $1
363
+ AND p.scope_id IS NULL
379
364
  AND a.deleted_at IS NULL
380
365
  AND act.deleted_at IS NULL
381
- AND p.revoked_at IS NULL
382
- AND (p.expires_at IS NULL OR p.expires_at > NOW())
366
+ AND ${role_grant_active_sql('p')}
383
367
  ORDER BY a.id ASC
384
368
  LIMIT 1`, [role]);
385
369
  return row?.account_id ?? null;
@@ -394,8 +378,8 @@ export const query_role_grant_find_account_id_for_role = async (deps, role) => {
394
378
  * orphan role_grants and offers. The cascade is **role-agnostic**: anything
395
379
  * attached to the destroyed scope is cleaned up.
396
380
  *
397
- * Both updates run as separate statements inside the caller's transaction
398
- * (mirrors `query_role_grant_revoke_role`'s shape). The two halves are
381
+ * Both updates run as separate statements inside the caller's transaction,
382
+ * the `role_grant` revoke first. The two halves are
399
383
  * independent — orphan pending offers can exist at a scope with no active
400
384
  * role_grants, so the supersede half always runs even when no role_grant was
401
385
  * revoked.
@@ -431,66 +415,10 @@ export const query_role_grant_revoke_for_scope = async (deps, scope_id, revoked_
431
415
  UPDATE role_grant_offer o
432
416
  SET superseded_at = NOW()
433
417
  WHERE o.scope_id = $1
434
- AND o.accepted_at IS NULL
435
- AND o.declined_at IS NULL
436
- AND o.retracted_at IS NULL
437
- AND o.superseded_at IS NULL
418
+ AND ${offer_pending_predicate('o')}
438
419
  -- raw columns; the outer grantor select formats them
439
420
  RETURNING ${qualify_columns(ROLE_GRANT_OFFER_COLUMNS, 'o')}
440
421
  )
441
422
  ${ROLE_GRANT_OFFER_WITH_GRANTOR_SELECT}`, [scope_id]);
442
423
  return { revoked, superseded_offers };
443
424
  };
444
- /**
445
- * Revoke every active role_grant an actor holds for a given role.
446
- *
447
- * With scoped role_grants a single actor+role tuple can hold several active
448
- * role_grants (one per scope), so this revokes all of them. Pass
449
- * `query_revoke_role_grant(role_grant_id, ...)` when a single scoped role_grant
450
- * is the target.
451
- *
452
- * Also supersedes pending offers for the actor's account across every
453
- * scope of this role (the actor can no longer hold the role, so any
454
- * pending offer of the same role is a bypass vector).
455
- *
456
- * @param deps - query dependencies
457
- * @param actor_id - the actor whose role_grants to revoke
458
- * @param role - the role to revoke
459
- * @param revoked_by - the actor who revoked it (for audit trail)
460
- * @param reason - optional free-form reason, stamped on `role_grant.revoked_reason`.
461
- * @returns the list of revoked role_grants (empty if none were active) and superseded pending offers
462
- * @mutates `role_grant` table - sets `revoked_at`/`revoked_by`/`revoked_reason` on every active row for `(actor, role)`
463
- * @mutates `role_grant_offer` table - stamps `superseded_at` on every matching pending offer
464
- */
465
- export const query_role_grant_revoke_role = async (deps, actor_id, role, revoked_by, reason) => {
466
- // CTE pulls the revokee's `account_id` via a join on `actor` so callers
467
- // can address the revokee without an extra round-trip.
468
- const revoked = await deps.db.query(`WITH updated AS (
469
- UPDATE role_grant
470
- SET revoked_at = NOW(), revoked_by = $3, revoked_reason = $4
471
- WHERE actor_id = $1 AND role = $2 AND revoked_at IS NULL
472
- RETURNING id, role, scope_kind, scope_id, actor_id
473
- )
474
- SELECT u.id AS role_grant_id, u.role, u.scope_kind, u.scope_id, a.account_id
475
- FROM updated u
476
- JOIN actor a ON a.id = u.actor_id`, [actor_id, role, revoked_by ?? null, reason ?? null]);
477
- if (revoked.length === 0) {
478
- return { revoked: [], superseded_offers: [] };
479
- }
480
- const superseded_offers = await deps.db.query(`WITH updated AS (
481
- UPDATE role_grant_offer o
482
- SET superseded_at = NOW()
483
- FROM actor a
484
- WHERE a.id = $1
485
- AND o.to_account_id = a.account_id
486
- AND o.role = $2
487
- AND o.accepted_at IS NULL
488
- AND o.declined_at IS NULL
489
- AND o.retracted_at IS NULL
490
- AND o.superseded_at IS NULL
491
- -- raw columns; the outer grantor select formats them
492
- RETURNING ${qualify_columns(ROLE_GRANT_OFFER_COLUMNS, 'o')}
493
- )
494
- ${ROLE_GRANT_OFFER_WITH_GRANTOR_SELECT}`, [actor_id, role]);
495
- return { revoked, superseded_offers };
496
- };
@@ -0,0 +1,42 @@
1
+ /**
2
+ * The liveness predicates of `role_grant` and `role_grant_offer` — one
3
+ * spelling each, so a new terminal state or liveness condition lands in one
4
+ * place instead of at every query that filters on it.
5
+ *
6
+ * Twins of the Rust spine's `role_grant_active_sql` and
7
+ * `offer_pending_predicate` (with its `OFFER_TERMINAL_COLUMNS`). The frozen
8
+ * partial-index DDL (`auth/role_grant_offer_ddl.ts`, `auth/migrations.ts`)
9
+ * keeps its literal predicate text, since a migration body never changes.
10
+ *
11
+ * @module
12
+ */
13
+ /**
14
+ * The SQL predicate for an **active** role grant: not revoked and not
15
+ * expired.
16
+ *
17
+ * The grant row's own liveness only. Whether its holder is live — the actor
18
+ * and its account not soft-deleted, which doesn't revoke grants — is a join
19
+ * the caller adds where the read needs it.
20
+ *
21
+ * @param alias - the table alias qualifying the columns, or `''` for unqualified columns
22
+ * @returns the predicate, with no surrounding parentheses (it is a top-level `AND` chain)
23
+ */
24
+ export declare const role_grant_active_sql: (alias: string) => string;
25
+ /**
26
+ * The `role_grant_offer` timestamp columns that each end an offer. An offer is
27
+ * pending while every one is null.
28
+ */
29
+ export declare const OFFER_TERMINAL_COLUMNS: readonly ["accepted_at", "declined_at", "retracted_at", "superseded_at"];
30
+ /**
31
+ * The still-pending predicate for a role grant offer — every
32
+ * `OFFER_TERMINAL_COLUMNS` entry `IS NULL`, `AND`-joined.
33
+ *
34
+ * Expiry is not part of it: an expired offer that no sweep has terminated is
35
+ * still pending here, and each read that must refuse one adds its own
36
+ * `expires_at` condition.
37
+ *
38
+ * @param alias - the table alias qualifying the columns, or `''` for unqualified columns
39
+ * @returns the predicate, with no surrounding parentheses
40
+ */
41
+ export declare const offer_pending_predicate: (alias: string) => string;
42
+ //# sourceMappingURL=role_grant_sql.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"role_grant_sql.d.ts","sourceRoot":"../src/lib/","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"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * The liveness predicates of `role_grant` and `role_grant_offer` — one
3
+ * spelling each, so a new terminal state or liveness condition lands in one
4
+ * place instead of at every query that filters on it.
5
+ *
6
+ * Twins of the Rust spine's `role_grant_active_sql` and
7
+ * `offer_pending_predicate` (with its `OFFER_TERMINAL_COLUMNS`). The frozen
8
+ * partial-index DDL (`auth/role_grant_offer_ddl.ts`, `auth/migrations.ts`)
9
+ * keeps its literal predicate text, since a migration body never changes.
10
+ *
11
+ * @module
12
+ */
13
+ /**
14
+ * Prefix `column` with `alias`, or leave it bare when `alias` is empty.
15
+ */
16
+ const qualify = (alias, column) => alias === '' ? column : `${alias}.${column}`;
17
+ /**
18
+ * The SQL predicate for an **active** role grant: not revoked and not
19
+ * expired.
20
+ *
21
+ * The grant row's own liveness only. Whether its holder is live — the actor
22
+ * and its account not soft-deleted, which doesn't revoke grants — is a join
23
+ * the caller adds where the read needs it.
24
+ *
25
+ * @param alias - the table alias qualifying the columns, or `''` for unqualified columns
26
+ * @returns the predicate, with no surrounding parentheses (it is a top-level `AND` chain)
27
+ */
28
+ export const role_grant_active_sql = (alias) => {
29
+ const revoked_at = qualify(alias, 'revoked_at');
30
+ const expires_at = qualify(alias, 'expires_at');
31
+ return `${revoked_at} IS NULL AND (${expires_at} IS NULL OR ${expires_at} > NOW())`;
32
+ };
33
+ /**
34
+ * The `role_grant_offer` timestamp columns that each end an offer. An offer is
35
+ * pending while every one is null.
36
+ */
37
+ export const OFFER_TERMINAL_COLUMNS = [
38
+ 'accepted_at',
39
+ 'declined_at',
40
+ 'retracted_at',
41
+ 'superseded_at'
42
+ ];
43
+ /**
44
+ * The still-pending predicate for a role grant offer — every
45
+ * `OFFER_TERMINAL_COLUMNS` entry `IS NULL`, `AND`-joined.
46
+ *
47
+ * Expiry is not part of it: an expired offer that no sweep has terminated is
48
+ * still pending here, and each read that must refuse one adds its own
49
+ * `expires_at` condition.
50
+ *
51
+ * @param alias - the table alias qualifying the columns, or `''` for unqualified columns
52
+ * @returns the predicate, with no surrounding parentheses
53
+ */
54
+ export const offer_pending_predicate = (alias) => OFFER_TERMINAL_COLUMNS.map((column) => `${qualify(alias, column)} IS NULL`).join(' AND ');
@@ -18,7 +18,7 @@
18
18
  * `create_scope_kind_schema(consumer_kinds)` and pass the result to
19
19
  * `create_role_schema` so `RoleSpec.applicable_scope_kinds` can be
20
20
  * validated at construction time. Mirrors the open-string registry
21
- * pattern used for `RoleName`, `AuditEventTypeName`, and `CredentialType`.
21
+ * pattern used for `RoleName`, `AuditEventTypeName`, and `CredentialTypeName`.
22
22
  *
23
23
  * The literal `'GLOBAL'` (uppercase) appears as an index expression
24
24
  * inside the partial unique indexes on `role_grant` and `role_grant_offer`
@@ -18,7 +18,7 @@
18
18
  * `create_scope_kind_schema(consumer_kinds)` and pass the result to
19
19
  * `create_role_schema` so `RoleSpec.applicable_scope_kinds` can be
20
20
  * validated at construction time. Mirrors the open-string registry
21
- * pattern used for `RoleName`, `AuditEventTypeName`, and `CredentialType`.
21
+ * pattern used for `RoleName`, `AuditEventTypeName`, and `CredentialTypeName`.
22
22
  *
23
23
  * The literal `'GLOBAL'` (uppercase) appears as an index expression
24
24
  * inside the partial unique indexes on `role_grant` and `role_grant_offer`
@@ -36,7 +36,7 @@
36
36
  *
37
37
  * @module
38
38
  */
39
- import { type RpcAction } from '../actions/action_rpc.js';
39
+ import { type RpcAction } from '../actions/action_types.js';
40
40
  import { type RoleSchemaResult } from './role_schema.js';
41
41
  import type { ActionFactoryDeps } from './deps.js';
42
42
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"self_service_role_actions.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/auth/self_service_role_actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,EAAuC,KAAK,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAE/F,OAAO,EAKN,KAAK,gBAAgB,EACrB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAWnD;;;;;;;;;;;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,gBAAgB,CAAC;CACzB;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,gCAAgC,GAC5C,MAAM,iBAAiB,EACvB,UAAS,6BAAkC,KACzC,KAAK,CAAC,SAAS,CAiJjB,CAAC"}
1
+ {"version":3,"file":"self_service_role_actions.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/auth/self_service_role_actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,EAAuC,KAAK,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAEjG,OAAO,EAKN,KAAK,gBAAgB,EACrB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAWnD;;;;;;;;;;;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,gBAAgB,CAAC;CACzB;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,gCAAgC,GAC5C,MAAM,iBAAiB,EACvB,UAAS,6BAAkC,KACzC,KAAK,CAAC,SAAS,CAiJjB,CAAC"}
@@ -36,7 +36,7 @@
36
36
  *
37
37
  * @module
38
38
  */
39
- import { rpc_action } from '../actions/action_rpc.js';
39
+ import { rpc_action } from '../actions/action_types.js';
40
40
  import { jsonrpc_errors } from '../http/jsonrpc_errors.js';
41
41
  import { builtin_role_specs_by_name, is_builtin_role, list_roles_with_grant_path, RoleName } from './role_schema.js';
42
42
  import { GRANT_PATH_SELF_SERVICE } from './grant_path_schema.js';
@@ -179,7 +179,8 @@ export declare const query_session_list_all_active: (deps: QueryDeps, limit?: nu
179
179
  * Delete every expired session, returning the ids (token hashes) of the rows
180
180
  * it deleted.
181
181
  *
182
- * The ids are the keys `ConnectionCloser.close_sockets_for_session` closes by.
182
+ * The ids are the `session_hash` of the `session` close target
183
+ * (`ConnectionCloser.close_connections`).
183
184
  * A row past `expires_at` already fails `query_session_get_valid`, but
184
185
  * deleting it does not end the connections it opened: a WebSocket keeps the
185
186
  * authority it resolved at upgrade and an SSE stream never rechecks. The row