@fuzdev/fuz_app 0.182.0 → 0.184.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 (295) hide show
  1. package/README.md +2 -0
  2. package/dist/actions/CLAUDE.md +535 -1223
  3. package/dist/actions/action_codegen.d.ts +1 -1
  4. package/dist/actions/action_codegen.d.ts.map +1 -1
  5. package/dist/actions/action_codegen.js +3 -2
  6. package/dist/actions/connection_closer.d.ts +11 -9
  7. package/dist/actions/connection_closer.d.ts.map +1 -1
  8. package/dist/actions/connection_closer.js +11 -9
  9. package/dist/actions/frontend_rpc_client.d.ts +1 -1
  10. package/dist/actions/register_action_ws.d.ts +14 -1
  11. package/dist/actions/register_action_ws.d.ts.map +1 -1
  12. package/dist/actions/register_action_ws.js +2 -1
  13. package/dist/actions/ws_socket_session.d.ts +9 -1
  14. package/dist/actions/ws_socket_session.d.ts.map +1 -1
  15. package/dist/actions/ws_socket_session.js +43 -19
  16. package/dist/auth/CLAUDE.md +430 -1024
  17. package/dist/auth/account_queries.d.ts +1 -1
  18. package/dist/auth/account_queries.js +1 -1
  19. package/dist/auth/account_routes.d.ts +9 -8
  20. package/dist/auth/account_routes.d.ts.map +1 -1
  21. package/dist/auth/account_routes.js +78 -75
  22. package/dist/auth/admin_actions.d.ts.map +1 -1
  23. package/dist/auth/admin_actions.js +32 -28
  24. package/dist/auth/api_token.d.ts +20 -3
  25. package/dist/auth/api_token.d.ts.map +1 -1
  26. package/dist/auth/api_token.js +28 -9
  27. package/dist/auth/api_token_queries.d.ts +2 -2
  28. package/dist/auth/api_token_queries.js +2 -2
  29. package/dist/auth/audit_emitter.d.ts +75 -84
  30. package/dist/auth/audit_emitter.d.ts.map +1 -1
  31. package/dist/auth/audit_emitter.js +83 -71
  32. package/dist/auth/audit_log_schema.d.ts +25 -14
  33. package/dist/auth/audit_log_schema.d.ts.map +1 -1
  34. package/dist/auth/audit_log_schema.js +23 -8
  35. package/dist/auth/auth_guard_resolver.d.ts +1 -1
  36. package/dist/auth/auth_guard_resolver.js +1 -1
  37. package/dist/auth/bearer_auth.d.ts +2 -5
  38. package/dist/auth/bearer_auth.d.ts.map +1 -1
  39. package/dist/auth/bearer_auth.js +4 -13
  40. package/dist/auth/bootstrap_account.d.ts +42 -26
  41. package/dist/auth/bootstrap_account.d.ts.map +1 -1
  42. package/dist/auth/bootstrap_account.js +36 -19
  43. package/dist/auth/bootstrap_routes.d.ts +20 -21
  44. package/dist/auth/bootstrap_routes.d.ts.map +1 -1
  45. package/dist/auth/bootstrap_routes.js +26 -31
  46. package/dist/auth/bootstrap_token_store.d.ts +3 -4
  47. package/dist/auth/bootstrap_token_store.d.ts.map +1 -1
  48. package/dist/auth/bootstrap_token_store.js +1 -1
  49. package/dist/auth/daemon_token.d.ts +5 -1
  50. package/dist/auth/daemon_token.d.ts.map +1 -1
  51. package/dist/auth/daemon_token_middleware.d.ts +12 -8
  52. package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
  53. package/dist/auth/daemon_token_middleware.js +15 -21
  54. package/dist/auth/deps.d.ts +19 -5
  55. package/dist/auth/deps.d.ts.map +1 -1
  56. package/dist/auth/deps.js +3 -2
  57. package/dist/auth/invite_queries.d.ts +51 -3
  58. package/dist/auth/invite_queries.d.ts.map +1 -1
  59. package/dist/auth/invite_queries.js +81 -6
  60. package/dist/auth/invite_schema.d.ts +2 -1
  61. package/dist/auth/invite_schema.d.ts.map +1 -1
  62. package/dist/auth/middleware.d.ts +2 -3
  63. package/dist/auth/middleware.d.ts.map +1 -1
  64. package/dist/auth/middleware.js +3 -3
  65. package/dist/auth/request_context.d.ts +3 -3
  66. package/dist/auth/request_context.js +3 -3
  67. package/dist/auth/resolved_auth.d.ts +7 -7
  68. package/dist/auth/resolved_auth.d.ts.map +1 -1
  69. package/dist/auth/resolved_auth.js +4 -4
  70. package/dist/auth/role_grant_offer_actions.d.ts +27 -3
  71. package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
  72. package/dist/auth/role_grant_offer_actions.js +42 -35
  73. package/dist/auth/role_grant_offer_queries.d.ts +60 -4
  74. package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
  75. package/dist/auth/role_grant_offer_queries.js +79 -5
  76. package/dist/auth/role_grant_queries.d.ts +3 -52
  77. package/dist/auth/role_grant_queries.d.ts.map +1 -1
  78. package/dist/auth/role_grant_queries.js +5 -80
  79. package/dist/auth/self_service_role_actions.d.ts.map +1 -1
  80. package/dist/auth/self_service_role_actions.js +11 -22
  81. package/dist/auth/session_cookie.d.ts +82 -174
  82. package/dist/auth/session_cookie.d.ts.map +1 -1
  83. package/dist/auth/session_cookie.js +80 -130
  84. package/dist/auth/session_middleware.d.ts +8 -17
  85. package/dist/auth/session_middleware.d.ts.map +1 -1
  86. package/dist/auth/session_middleware.js +14 -23
  87. package/dist/auth/session_queries.d.ts +15 -17
  88. package/dist/auth/session_queries.d.ts.map +1 -1
  89. package/dist/auth/session_queries.js +28 -20
  90. package/dist/auth/signup_routes.d.ts.map +1 -1
  91. package/dist/auth/signup_routes.js +93 -43
  92. package/dist/db/CLAUDE.md +5 -3
  93. package/dist/db/sql_columns.d.ts +1 -1
  94. package/dist/db/sql_columns.js +1 -1
  95. package/dist/dev/setup.d.ts +3 -1
  96. package/dist/dev/setup.d.ts.map +1 -1
  97. package/dist/dev/setup.js +3 -1
  98. package/dist/http/CLAUDE.md +315 -763
  99. package/dist/http/db_routes.d.ts +8 -23
  100. package/dist/http/db_routes.d.ts.map +1 -1
  101. package/dist/http/db_routes.js +73 -73
  102. package/dist/http/origin.d.ts +7 -8
  103. package/dist/http/origin.d.ts.map +1 -1
  104. package/dist/http/origin.js +7 -8
  105. package/dist/http/pending_effects.d.ts +118 -6
  106. package/dist/http/pending_effects.d.ts.map +1 -1
  107. package/dist/http/pending_effects.js +114 -6
  108. package/dist/http/route_result.d.ts +1 -1
  109. package/dist/http/route_spec.d.ts +14 -11
  110. package/dist/http/route_spec.d.ts.map +1 -1
  111. package/dist/realtime/sse.d.ts +4 -23
  112. package/dist/realtime/sse.d.ts.map +1 -1
  113. package/dist/realtime/sse.js +4 -25
  114. package/dist/server/app_backend.d.ts +4 -5
  115. package/dist/server/app_backend.d.ts.map +1 -1
  116. package/dist/server/app_backend.js +3 -1
  117. package/dist/server/app_server.d.ts +80 -16
  118. package/dist/server/app_server.d.ts.map +1 -1
  119. package/dist/server/app_server.js +113 -31
  120. package/dist/server/app_server_context.d.ts +1 -2
  121. package/dist/server/app_server_context.d.ts.map +1 -1
  122. package/dist/server/env.js +2 -2
  123. package/dist/testing/CLAUDE.md +265 -796
  124. package/dist/testing/admin_integration.d.ts +2 -3
  125. package/dist/testing/admin_integration.d.ts.map +1 -1
  126. package/dist/testing/admin_integration.js +3 -3
  127. package/dist/testing/adversarial_404.d.ts +6 -1
  128. package/dist/testing/adversarial_404.d.ts.map +1 -1
  129. package/dist/testing/adversarial_404.js +38 -17
  130. package/dist/testing/app_server.d.ts +23 -148
  131. package/dist/testing/app_server.d.ts.map +1 -1
  132. package/dist/testing/app_server.js +53 -131
  133. package/dist/testing/attack_surface.d.ts +1 -1
  134. package/dist/testing/attack_surface.d.ts.map +1 -1
  135. package/dist/testing/audit_completeness.d.ts +2 -3
  136. package/dist/testing/audit_completeness.d.ts.map +1 -1
  137. package/dist/testing/audit_completeness.js +1 -1
  138. package/dist/testing/audit_drift_guard.d.ts +11 -6
  139. package/dist/testing/audit_drift_guard.d.ts.map +1 -1
  140. package/dist/testing/audit_drift_guard.js +15 -8
  141. package/dist/testing/cross_backend/audit_cross_helpers.d.ts +12 -9
  142. package/dist/testing/cross_backend/audit_cross_helpers.d.ts.map +1 -1
  143. package/dist/testing/cross_backend/audit_cross_helpers.js +13 -14
  144. package/dist/testing/cross_backend/capabilities.d.ts +9 -6
  145. package/dist/testing/cross_backend/capabilities.d.ts.map +1 -1
  146. package/dist/testing/cross_backend/capabilities.js +11 -7
  147. package/dist/testing/cross_backend/capability_mounts.d.ts +103 -0
  148. package/dist/testing/cross_backend/capability_mounts.d.ts.map +1 -0
  149. package/dist/testing/cross_backend/capability_mounts.js +428 -0
  150. package/dist/testing/cross_backend/cell_moderate.js +2 -2
  151. package/dist/testing/cross_backend/cell_relations.d.ts.map +1 -1
  152. package/dist/testing/cross_backend/cell_relations.js +12 -11
  153. package/dist/testing/cross_backend/conformance_principal.d.ts +54 -0
  154. package/dist/testing/cross_backend/conformance_principal.d.ts.map +1 -0
  155. package/dist/testing/cross_backend/conformance_principal.js +283 -0
  156. package/dist/testing/cross_backend/conformance_table.d.ts +7 -56
  157. package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
  158. package/dist/testing/cross_backend/conformance_table.js +6 -274
  159. package/dist/testing/cross_backend/cookie_attributes.js +1 -1
  160. package/dist/testing/cross_backend/credential_deadline.d.ts.map +1 -1
  161. package/dist/testing/cross_backend/credential_deadline.js +2 -0
  162. package/dist/testing/cross_backend/credential_wire.d.ts +1 -1
  163. package/dist/testing/cross_backend/credential_wire.d.ts.map +1 -1
  164. package/dist/testing/cross_backend/db_state_diff.d.ts +72 -0
  165. package/dist/testing/cross_backend/db_state_diff.d.ts.map +1 -0
  166. package/dist/testing/cross_backend/db_state_diff.js +444 -0
  167. package/dist/testing/cross_backend/declared_skips.d.ts +68 -0
  168. package/dist/testing/cross_backend/declared_skips.d.ts.map +1 -0
  169. package/dist/testing/cross_backend/declared_skips.js +132 -0
  170. package/dist/testing/cross_backend/default_backend_configs.d.ts +3 -3
  171. package/dist/testing/cross_backend/default_spine_surface.d.ts +0 -6
  172. package/dist/testing/cross_backend/default_spine_surface.d.ts.map +1 -1
  173. package/dist/testing/cross_backend/default_spine_surface.js +4 -9
  174. package/dist/testing/cross_backend/differential.d.ts +13 -5
  175. package/dist/testing/cross_backend/differential.d.ts.map +1 -1
  176. package/dist/testing/cross_backend/differential.js +35 -11
  177. package/dist/testing/cross_backend/differential_normalize.d.ts +12 -0
  178. package/dist/testing/cross_backend/differential_normalize.d.ts.map +1 -1
  179. package/dist/testing/cross_backend/differential_normalize.js +16 -0
  180. package/dist/testing/cross_backend/full_spine_mount.d.ts +1 -42
  181. package/dist/testing/cross_backend/full_spine_mount.d.ts.map +1 -1
  182. package/dist/testing/cross_backend/full_spine_mount.js +45 -4
  183. package/dist/testing/cross_backend/in_process_setup.d.ts +28 -19
  184. package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
  185. package/dist/testing/cross_backend/in_process_setup.js +156 -142
  186. package/dist/testing/cross_backend/login_security.d.ts +12 -0
  187. package/dist/testing/cross_backend/login_security.d.ts.map +1 -1
  188. package/dist/testing/cross_backend/login_security.js +21 -4
  189. package/dist/testing/cross_backend/request_target_conformance_wire.d.ts +0 -2
  190. package/dist/testing/cross_backend/request_target_conformance_wire.d.ts.map +1 -1
  191. package/dist/testing/cross_backend/request_target_conformance_wire.js +3 -1
  192. package/dist/testing/cross_backend/revocation_drivers.d.ts +18 -5
  193. package/dist/testing/cross_backend/revocation_drivers.d.ts.map +1 -1
  194. package/dist/testing/cross_backend/revocation_drivers.js +18 -10
  195. package/dist/testing/cross_backend/role_grant_cross_helpers.d.ts +1 -1
  196. package/dist/testing/cross_backend/role_grant_cross_helpers.d.ts.map +1 -1
  197. package/dist/testing/cross_backend/role_grant_offer_lifecycle.d.ts.map +1 -1
  198. package/dist/testing/cross_backend/role_grant_offer_lifecycle.js +33 -1
  199. package/dist/testing/cross_backend/role_grant_participation.js +4 -4
  200. package/dist/testing/cross_backend/rpc_adversarial.js +1 -1
  201. package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +3 -4
  202. package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
  203. package/dist/testing/cross_backend/rust_spine_consumer_surface.js +2 -2
  204. package/dist/testing/cross_backend/session_cap.d.ts +2 -2
  205. package/dist/testing/cross_backend/session_cap.d.ts.map +1 -1
  206. package/dist/testing/cross_backend/session_cap.js +22 -11
  207. package/dist/testing/cross_backend/setup.d.ts +32 -2
  208. package/dist/testing/cross_backend/setup.d.ts.map +1 -1
  209. package/dist/testing/cross_backend/setup.js +32 -1
  210. package/dist/testing/cross_backend/spine_suites.d.ts +125 -15
  211. package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
  212. package/dist/testing/cross_backend/spine_suites.js +459 -62
  213. package/dist/testing/cross_backend/spine_surface_constants.d.ts +1 -1
  214. package/dist/testing/cross_backend/spine_surface_constants.d.ts.map +1 -1
  215. package/dist/testing/cross_backend/spine_surface_constants.js +1 -0
  216. package/dist/testing/cross_backend/sse_round_trip.d.ts +9 -1
  217. package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
  218. package/dist/testing/cross_backend/sse_round_trip.js +123 -27
  219. package/dist/testing/cross_backend/standard.d.ts +2 -3
  220. package/dist/testing/cross_backend/standard.d.ts.map +1 -1
  221. package/dist/testing/cross_backend/standard.js +3 -3
  222. package/dist/testing/cross_backend/testing_backdoor.d.ts.map +1 -1
  223. package/dist/testing/cross_backend/testing_backdoor.js +4 -2
  224. package/dist/testing/cross_backend/testing_credential_read.d.ts +10 -11
  225. package/dist/testing/cross_backend/testing_credential_read.d.ts.map +1 -1
  226. package/dist/testing/cross_backend/testing_credential_read.js +12 -12
  227. package/dist/testing/cross_backend/testing_reset_actions.d.ts +84 -47
  228. package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
  229. package/dist/testing/cross_backend/testing_reset_actions.js +95 -63
  230. package/dist/testing/cross_backend/testing_server_core.d.ts.map +1 -1
  231. package/dist/testing/cross_backend/testing_server_core.js +2 -3
  232. package/dist/testing/cross_backend/transport_composition.d.ts +1 -1
  233. package/dist/testing/cross_backend/transport_composition.d.ts.map +1 -1
  234. package/dist/testing/cross_backend/transport_composition.js +7 -3
  235. package/dist/testing/cross_backend/ws_round_trip.d.ts +5 -0
  236. package/dist/testing/cross_backend/ws_round_trip.d.ts.map +1 -1
  237. package/dist/testing/cross_backend/ws_round_trip.js +54 -8
  238. package/dist/testing/daemon_token_rotation.d.ts.map +1 -1
  239. package/dist/testing/daemon_token_rotation.js +2 -3
  240. package/dist/testing/data_exposure.d.ts.map +1 -1
  241. package/dist/testing/data_exposure.js +3 -0
  242. package/dist/testing/db.d.ts +0 -32
  243. package/dist/testing/db.d.ts.map +1 -1
  244. package/dist/testing/db.js +0 -86
  245. package/dist/testing/db_entities.d.ts +14 -0
  246. package/dist/testing/db_entities.d.ts.map +1 -1
  247. package/dist/testing/db_entities.js +17 -0
  248. package/dist/testing/db_invariant_queries.d.ts +259 -0
  249. package/dist/testing/db_invariant_queries.d.ts.map +1 -0
  250. package/dist/testing/db_invariant_queries.js +400 -0
  251. package/dist/testing/db_invariants.d.ts +106 -0
  252. package/dist/testing/db_invariants.d.ts.map +1 -0
  253. package/dist/testing/db_invariants.gen.sql.d.ts +11 -0
  254. package/dist/testing/db_invariants.gen.sql.d.ts.map +1 -0
  255. package/dist/testing/db_invariants.gen.sql.js +13 -0
  256. package/dist/testing/db_invariants.js +141 -0
  257. package/dist/testing/db_invariants.sql +152 -0
  258. package/dist/testing/describe_db.d.ts +36 -0
  259. package/dist/testing/describe_db.d.ts.map +1 -0
  260. package/dist/testing/describe_db.js +71 -0
  261. package/dist/testing/integration.d.ts +8 -12
  262. package/dist/testing/integration.d.ts.map +1 -1
  263. package/dist/testing/integration.js +13 -17
  264. package/dist/testing/integration_helpers.d.ts +1 -1
  265. package/dist/testing/integration_helpers.d.ts.map +1 -1
  266. package/dist/testing/rate_limiting.d.ts +3 -4
  267. package/dist/testing/rate_limiting.d.ts.map +1 -1
  268. package/dist/testing/rate_limiting.js +6 -5
  269. package/dist/testing/role_grant_helpers.d.ts +1 -1
  270. package/dist/testing/role_grant_helpers.d.ts.map +1 -1
  271. package/dist/testing/round_trip.d.ts.map +1 -1
  272. package/dist/testing/round_trip.js +3 -0
  273. package/dist/testing/rpc_attack_surface.d.ts +8 -6
  274. package/dist/testing/rpc_attack_surface.d.ts.map +1 -1
  275. package/dist/testing/rpc_attack_surface.js +69 -6
  276. package/dist/testing/rpc_helpers.d.ts +1 -2
  277. package/dist/testing/rpc_helpers.d.ts.map +1 -1
  278. package/dist/testing/rpc_helpers.js +3 -3
  279. package/dist/testing/rpc_round_trip.d.ts +3 -4
  280. package/dist/testing/rpc_round_trip.d.ts.map +1 -1
  281. package/dist/testing/rpc_round_trip.js +4 -1
  282. package/dist/testing/sse_round_trip.d.ts +3 -4
  283. package/dist/testing/sse_round_trip.d.ts.map +1 -1
  284. package/dist/testing/sse_round_trip.js +15 -6
  285. package/dist/testing/stubs.d.ts +9 -8
  286. package/dist/testing/stubs.d.ts.map +1 -1
  287. package/dist/testing/stubs.js +20 -13
  288. package/dist/testing/test_app.d.ts +168 -0
  289. package/dist/testing/test_app.d.ts.map +1 -0
  290. package/dist/testing/test_app.js +123 -0
  291. package/dist/testing/ws_round_trip.d.ts.map +1 -1
  292. package/dist/testing/ws_round_trip.js +3 -0
  293. package/dist/ui/ui_format.d.ts.map +1 -1
  294. package/dist/ui/ui_format.js +1 -2
  295. package/package.json +1 -1
@@ -238,7 +238,7 @@ export declare const query_account_lock_for_purge: (deps: QueryDeps, id: string)
238
238
  * be ordered against a delete of any of them.
239
239
  *
240
240
  * An offer locks its two parties (`query_role_grant_offer_create`), an invite
241
- * its issuer (`invite_create`, one id).
241
+ * its issuer (`query_create_invite`, one id).
242
242
  *
243
243
  * `FOR SHARE`: the weakest lock that conflicts with a delete's `UPDATE` of the
244
244
  * row, so these writes don't wait on one another. It also waits on a
@@ -325,7 +325,7 @@ export const query_account_lock_for_purge = async (deps, id) => {
325
325
  * be ordered against a delete of any of them.
326
326
  *
327
327
  * An offer locks its two parties (`query_role_grant_offer_create`), an invite
328
- * its issuer (`invite_create`, one id).
328
+ * its issuer (`query_create_invite`, one id).
329
329
  *
330
330
  * `FOR SHARE`: the weakest lock that conflicts with a delete's `UPDATE` of the
331
331
  * row, so these writes don't wait on one another. It also waits on a
@@ -19,7 +19,6 @@
19
19
  *
20
20
  * @module
21
21
  */
22
- import { type SessionOptions } from './session_cookie.js';
23
22
  import { type RouteSpec } from '../http/route_spec.js';
24
23
  import { type RateLimiter } from '../rate_limiter.js';
25
24
  import type { RouteFactoryDeps } from './deps.js';
@@ -87,7 +86,7 @@ export declare const DEFAULT_LOGIN_FAIL_JITTER_MS = 25;
87
86
  * budget that bounds guessing on every other one.
88
87
  */
89
88
  export interface AuthSessionRouteOptions {
90
- session_options: SessionOptions<string>;
89
+ session_cookie_name: string;
91
90
  }
92
91
  /**
93
92
  * Per-factory configuration for account route specs.
@@ -133,24 +132,26 @@ export interface AccountRouteOptions extends AuthSessionRouteOptions {
133
132
  /**
134
133
  * Create account route specs for session-based auth.
135
134
  *
136
- * The returned specs cover the REST flows that stay after the RPC migration:
135
+ * The returned specs cover the account surface's REST flows:
137
136
  * `/status` (account info + bootstrap availability), `/login`, `/logout`,
138
137
  * `/password`. `/status` is bundled
139
138
  * here (relative path, prefixed to `/api/account/status` by the caller) so
140
139
  * every account surface serves it, matching the Rust `account_router`.
141
140
  * Self-service session/token management is on `auth/account_actions.ts`.
142
141
  *
143
- * `/login` closes the connections of the sessions its cap evicts, and
144
- * `/logout` and `/password` close the account's, each once its revocation has
142
+ * `/login` closes the connections of the sessions its cap evicts, `/logout`
143
+ * those of the session it ends, and `/password` the account's, each once its revocation has
145
144
  * committed: `/logout` through the route transaction's post-commit queue
146
145
  * (`queue_connection_close`), `/login` and `/password` — which open their own
147
146
  * transaction around just their writes — straight after it commits
148
147
  * (`close_connections_after_commit`, which logs a failing close rather than
149
148
  * failing the committed request), so a later throw can't drop a close a
150
- * committed revocation owes. All on `deps.connection_closer`.
149
+ * committed revocation owes. All on `deps.connection_closer`. Each success
150
+ * audit row is written last in the transaction of the change it reports, so
151
+ * a refused row rolls the change back and closes nothing.
151
152
  *
152
- * @param deps - stateless capabilities (keyring, password, log, audit, connection_closer)
153
- * @param options - per-factory configuration (session_options, login_ip_rate_limiter, login_account_rate_limiter, bootstrap_status)
153
+ * @param deps - capabilities (keyring, password, log, audit, connection_closer)
154
+ * @param options - per-factory configuration (session_cookie_name, login_ip_rate_limiter, login_account_rate_limiter, bootstrap_status)
154
155
  * @returns route specs (not yet applied to Hono)
155
156
  */
156
157
  export declare const create_account_route_specs: (deps: RouteFactoryDeps, options: AccountRouteOptions) => Array<RouteSpec>;
@@ -1 +1 @@
1
- {"version":3,"file":"account_routes.d.ts","sourceRoot":"","sources":["../../src/lib/auth/account_routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAGN,KAAK,cAAc,EACnB,MAAM,qBAAqB,CAAC;AAyB7B,OAAO,EAAwB,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAI7E,OAAO,EAAoB,KAAK,WAAW,EAA6B,MAAM,oBAAoB,CAAC;AACnG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAclD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,gCAAgC,GAAI,UAAU,oBAAoB,KAAG,SAiFjF,CAAC;AAEF,iDAAiD;AACjD,MAAM,WAAW,oBAAoB;IACpC,yDAAyD;IACzD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,8FAA8F;IAC9F,gBAAgB,CAAC,EAAE;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC;CAC1C;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,2BAA2B,MAAM,CAAC;AAE/C;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B,KAAK,CAAC;AAE/C;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,uBAAuB;IACvC,eAAe,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC;CACxC;AAED;;GAEG;AACH,MAAM,WAAW,mBAAoB,SAAQ,uBAAuB;IACnE;;;;;;;OAOG;IACH,qBAAqB,EAAE,WAAW,GAAG,IAAI,CAAC;IAC1C,4FAA4F;IAC5F,0BAA0B,EAAE,WAAW,GAAG,IAAI,CAAC;IAC/C,2FAA2F;IAC3F,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;;;;OAOG;IACH,gBAAgB,CAAC,EAAE;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC;CAC1C;AAID;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,0BAA0B,GACtC,MAAM,gBAAgB,EACtB,SAAS,mBAAmB,KAC1B,KAAK,CAAC,SAAS,CAkXjB,CAAC"}
1
+ {"version":3,"file":"account_routes.d.ts","sourceRoot":"","sources":["../../src/lib/auth/account_routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AA2BH,OAAO,EAAwB,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAK7E,OAAO,EAAoB,KAAK,WAAW,EAA6B,MAAM,oBAAoB,CAAC;AACnG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAclD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,gCAAgC,GAAI,UAAU,oBAAoB,KAAG,SAiFjF,CAAC;AAEF,iDAAiD;AACjD,MAAM,WAAW,oBAAoB;IACpC,yDAAyD;IACzD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,8FAA8F;IAC9F,gBAAgB,CAAC,EAAE;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC;CAC1C;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,2BAA2B,MAAM,CAAC;AAE/C;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B,KAAK,CAAC;AAE/C;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,uBAAuB;IACvC,mBAAmB,EAAE,MAAM,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,mBAAoB,SAAQ,uBAAuB;IACnE;;;;;;;OAOG;IACH,qBAAqB,EAAE,WAAW,GAAG,IAAI,CAAC;IAC1C,4FAA4F;IAC5F,0BAA0B,EAAE,WAAW,GAAG,IAAI,CAAC;IAC/C,2FAA2F;IAC3F,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;;;;OAOG;IACH,gBAAgB,CAAC,EAAE;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC;CAC1C;AAID;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,0BAA0B,GACtC,MAAM,gBAAgB,EACtB,SAAS,mBAAmB,KAC1B,KAAK,CAAC,SAAS,CAoXjB,CAAC"}
@@ -19,7 +19,7 @@
19
19
  *
20
20
  * @module
21
21
  */
22
- import { clear_session_cookie_header, session_cookie_header } from './session_cookie.js';
22
+ import { format_session_clear_cookie, sign_session_cookie } from './session_cookie.js';
23
23
  import { RoleGrantSummaryJson, to_session_account } from './account_schema.js';
24
24
  import { account_status_route_shape, create_account_route_shapes, DEFAULT_MAX_SESSIONS } from './account_route_schema.js';
25
25
  import { create_capped_session, query_session_revoke_all_for_account, query_session_revoke_by_hash_unscoped } from './session_queries.js';
@@ -29,6 +29,7 @@ import { build_request_context, get_public_account, resolve_acting_actor } from
29
29
  import { resolved_auth_session_hash } from './resolved_auth.js';
30
30
  import { attach_route_handler } from '../http/route_spec.js';
31
31
  import { route_fail, route_ok } from '../http/route_result.js';
32
+ import { transaction_with_post_commit_rollback } from '../http/pending_effects.js';
32
33
  import { rate_limit_ip_key } from '../http/ip_canonical.js';
33
34
  import { parse_acting } from '../http/auth_shape.js';
34
35
  import { reserve_optional } from '../rate_limiter.js';
@@ -161,29 +162,31 @@ export const DEFAULT_LOGIN_FAIL_JITTER_MS = 25;
161
162
  /**
162
163
  * Create account route specs for session-based auth.
163
164
  *
164
- * The returned specs cover the REST flows that stay after the RPC migration:
165
+ * The returned specs cover the account surface's REST flows:
165
166
  * `/status` (account info + bootstrap availability), `/login`, `/logout`,
166
167
  * `/password`. `/status` is bundled
167
168
  * here (relative path, prefixed to `/api/account/status` by the caller) so
168
169
  * every account surface serves it, matching the Rust `account_router`.
169
170
  * Self-service session/token management is on `auth/account_actions.ts`.
170
171
  *
171
- * `/login` closes the connections of the sessions its cap evicts, and
172
- * `/logout` and `/password` close the account's, each once its revocation has
172
+ * `/login` closes the connections of the sessions its cap evicts, `/logout`
173
+ * those of the session it ends, and `/password` the account's, each once its revocation has
173
174
  * committed: `/logout` through the route transaction's post-commit queue
174
175
  * (`queue_connection_close`), `/login` and `/password` — which open their own
175
176
  * transaction around just their writes — straight after it commits
176
177
  * (`close_connections_after_commit`, which logs a failing close rather than
177
178
  * failing the committed request), so a later throw can't drop a close a
178
- * committed revocation owes. All on `deps.connection_closer`.
179
+ * committed revocation owes. All on `deps.connection_closer`. Each success
180
+ * audit row is written last in the transaction of the change it reports, so
181
+ * a refused row rolls the change back and closes nothing.
179
182
  *
180
- * @param deps - stateless capabilities (keyring, password, log, audit, connection_closer)
181
- * @param options - per-factory configuration (session_options, login_ip_rate_limiter, login_account_rate_limiter, bootstrap_status)
183
+ * @param deps - capabilities (keyring, password, log, audit, connection_closer)
184
+ * @param options - per-factory configuration (session_cookie_name, login_ip_rate_limiter, login_account_rate_limiter, bootstrap_status)
182
185
  * @returns route specs (not yet applied to Hono)
183
186
  */
184
187
  export const create_account_route_specs = (deps, options) => {
185
188
  const { keyring, password, connection_closer } = deps;
186
- const { session_options, login_ip_rate_limiter, login_account_rate_limiter, max_sessions = DEFAULT_MAX_SESSIONS, login_fail_floor_ms = DEFAULT_LOGIN_FAIL_FLOOR_MS, login_fail_jitter_ms = DEFAULT_LOGIN_FAIL_JITTER_MS, bootstrap_status } = options;
189
+ const { session_cookie_name, login_ip_rate_limiter, login_account_rate_limiter, max_sessions = DEFAULT_MAX_SESSIONS, login_fail_floor_ms = DEFAULT_LOGIN_FAIL_FLOOR_MS, login_fail_jitter_ms = DEFAULT_LOGIN_FAIL_JITTER_MS, bootstrap_status } = options;
187
190
  warn_if_fail_floor_disabled('login', login_fail_floor_ms, deps.log);
188
191
  const [login_shape, logout_shape, password_shape] = create_account_route_shapes({
189
192
  login_account_rate_limited: login_account_rate_limiter !== null
@@ -255,35 +258,36 @@ export const create_account_route_specs = (deps, options) => {
255
258
  return route_fail(REST_INVALID_CREDENTIALS);
256
259
  }
257
260
  const valid = await password.verify_password(pw, account.password_hash);
258
- // The session INSERT and the cap eviction are the route's only
259
- // writes, and only atomic together: one transaction around just
260
- // them (the route is `transaction: false`, so the reservation
261
- // waits above and the Argon2 verify held no connection). Twin of
262
- // the Rust login's transaction around `create_capped_session`. It
261
+ // The session INSERT, the cap eviction, and the `login` success
262
+ // row are the route's writes, and only atomic together: one
263
+ // transaction around just them (the route is `transaction: false`,
264
+ // so the reservation waits above and the Argon2 verify held no
265
+ // connection). Twin of the Rust login's `mint_login_session`. It
263
266
  // first locks the account row as the verify read it — live, the
264
267
  // verified hash — so a password change or a delete that committed
265
268
  // since mints nothing, and one still to commit waits and then
266
269
  // revokes this session (`query_account_lock_verified`). The
267
270
  // cookie line is formatted inside it, so a value the formatter
268
271
  // refuses rolls the session back, and rides the success, which is
269
- // answered only once the commit has landed.
272
+ // answered only once the commit has landed. The audit row is
273
+ // written last, so a refused row mints no session.
270
274
  const minted = valid
271
- ? await route.db.transaction(async (tx) => {
272
- const tx_deps = { db: tx };
273
- if (!(await query_account_lock_verified(tx_deps, account.id, account.password_hash))) {
275
+ ? await transaction_with_post_commit_rollback(route, async (tx_ctx) => {
276
+ if (!(await query_account_lock_verified(tx_ctx, account.id, account.password_hash))) {
274
277
  return null;
275
278
  }
276
279
  const session = await create_capped_session({
277
- keyring,
278
- deps: tx_deps,
280
+ deps: tx_ctx,
279
281
  account_id: account.id,
280
- session_options,
281
282
  max_sessions
282
283
  });
283
- return {
284
- evicted: session.evicted,
285
- set_cookie: session_cookie_header(session.cookie_value, session_options)
286
- };
284
+ const set_cookie = await sign_session_cookie(keyring, session.token, session_cookie_name);
285
+ await deps.audit.emit(tx_ctx, {
286
+ event_type: 'login',
287
+ account_id: account.id,
288
+ ip: route.client_ip
289
+ });
290
+ return { evicted: session.evicted, set_cookie };
287
291
  })
288
292
  : null;
289
293
  // A wrong password, and a right one whose account changed under
@@ -319,16 +323,11 @@ export const create_account_route_specs = (deps, options) => {
319
323
  // rechecks. Close them now the eviction has committed — inline, not
320
324
  // queued: with no route transaction, a throw later in the handler
321
325
  // would drop a queued close while the eviction stands. No audit
322
- // row: there is no eviction event, and the `login` row records
323
- // the cause.
326
+ // row of their own: there is no eviction event, and the `login`
327
+ // row records the cause.
324
328
  for (const session_hash of evicted) {
325
329
  close_connections_after_commit(connection_closer, { kind: 'session', session_hash }, deps.log);
326
330
  }
327
- await deps.audit.emit(route, {
328
- event_type: 'login',
329
- account_id: account.id,
330
- ip: route.client_ip
331
- });
332
331
  return route_ok({ ok: true }, { set_cookie: [set_cookie] });
333
332
  }
334
333
  finally {
@@ -341,32 +340,35 @@ export const create_account_route_specs = (deps, options) => {
341
340
  // the shape admits only a session credential, so this is its hash
342
341
  // (the Rust `account_logout` reads the same value)
343
342
  const session_hash = resolved_auth_session_hash(route.credential);
344
- if (session_hash !== null) {
345
- await query_session_revoke_by_hash_unscoped(route, session_hash);
346
- // Close this account's live connections once the revoke has
347
- // committed — queued, so it never runs before the commit or on
348
- // rollback, and it does not depend on the audit row below (written
349
- // in the route transaction, so it commits with the revoke). Account-wide (not session-targeted) to match the Rust
350
- // `account_logout` handler and the sibling `/password` handler
351
- // — logout is a self-initiated account-grain operation. The
352
- // audit listeners repeat the same close on the announced
353
- // `logout` row; closing is idempotent.
354
- queue_connection_close(route, connection_closer, {
355
- kind: 'account',
356
- account_id: ctx.account.id
357
- });
343
+ if (session_hash === null) {
344
+ // a 500 with nothing changed, as the Rust handler answers
345
+ throw new Error('logout: the session gate admitted a caller with no session hash');
358
346
  }
347
+ await query_session_revoke_by_hash_unscoped(route, session_hash);
348
+ // Close the live connections of the session this logout ends, once
349
+ // the revoke has committed — queued, so it never runs before the
350
+ // commit or on rollback, and it does not depend on the audit row below
351
+ // (written in the route transaction, so it commits with the revoke).
352
+ // Only that session's: logout ends one credential, and the account's
353
+ // other sessions, its API tokens and the daemon token stay valid, so
354
+ // their connections stay open. The audit listeners repeat the same
355
+ // close on the announced `logout` row, which names the session;
356
+ // closing is idempotent. The Rust `account_logout` closes the same.
357
+ queue_connection_close(route, connection_closer, { kind: 'session', session_hash });
359
358
  // Account-grain operation — no `actor_id` (which actor was
360
359
  // resolved per-request is incidental to "this account ended
361
- // its session"). Mirrors `login`.
360
+ // its session"). Mirrors `login`. `session_id` names the ended
361
+ // session, as a `session_revoke` row does — what the revocation
362
+ // guard closes by.
362
363
  await deps.audit.emit(route, {
363
364
  event_type: 'logout',
364
365
  account_id: ctx.account.id,
365
- ip: route.client_ip
366
+ ip: route.client_ip,
367
+ metadata: { session_id: session_hash }
366
368
  });
367
369
  // the clear rides the success, answered once the revoke and this
368
370
  // row have committed — a rollback clears nothing
369
- return route_ok({ ok: true, username: ctx.account.username }, { set_cookie: [clear_session_cookie_header(session_options)] });
371
+ return route_ok({ ok: true, username: ctx.account.username }, { set_cookie: [format_session_clear_cookie(session_cookie_name)] });
370
372
  }),
371
373
  attach_route_handler(password_shape, async (route) => {
372
374
  // Per-IP rate limit (before argon2 work). Reserved, not checked:
@@ -420,20 +422,31 @@ export const create_account_route_specs = (deps, options) => {
420
422
  // operation — `updated_by` stays null (the per-request actor is
421
423
  // incidental; password is account-level state).
422
424
  //
423
- // The UPDATE and the two revocations are the route's writes, and
424
- // commit together or not at all: one transaction around just them
425
- // (the route is `transaction: false`, so the reservation waits
426
- // above and the Argon2 verify and hash held no connection). Twin of
427
- // the Rust spine's `change_password`. `null` when the UPDATE matched
428
- // nothing — a concurrent change committed first.
429
- const change = await route.db.transaction(async (tx) => {
430
- const tx_deps = { db: tx };
431
- const updated = await query_update_account_password(tx_deps, ctx.account.id, new_hash, null, ctx.account.password_hash);
425
+ // The UPDATE, the two revocations, and the `password_change`
426
+ // success row are the route's writes, and commit together or not
427
+ // at all: one transaction around just them (the route is
428
+ // `transaction: false`, so the reservation waits above and the
429
+ // Argon2 verify and hash held no connection). Twin of the Rust
430
+ // spine's `change_password`. The audit row is written last, so a
431
+ // refused row changes no password and revokes nothing. `null` when
432
+ // the UPDATE matched nothing — a concurrent change committed first.
433
+ const change = await transaction_with_post_commit_rollback(route, async (tx_ctx) => {
434
+ const updated = await query_update_account_password(tx_ctx, ctx.account.id, new_hash, null, ctx.account.password_hash);
432
435
  if (!updated)
433
436
  return null;
434
437
  // revoke all sessions and API tokens (force re-auth everywhere)
435
- const sessions_revoked = await query_session_revoke_all_for_account(tx_deps, ctx.account.id);
436
- const tokens_revoked = await query_revoke_all_api_tokens_for_account(tx_deps, ctx.account.id);
438
+ const sessions_revoked = await query_session_revoke_all_for_account(tx_ctx, ctx.account.id);
439
+ const tokens_revoked = await query_revoke_all_api_tokens_for_account(tx_ctx, ctx.account.id);
440
+ // Account-grain operation — no `actor_id`. The password is
441
+ // account-level state; which per-request actor was resolved
442
+ // has no semantic bearing on "this account changed its
443
+ // password". Mirrors `login`/`logout`.
444
+ await deps.audit.emit(tx_ctx, {
445
+ event_type: 'password_change',
446
+ account_id: ctx.account.id,
447
+ ip: route.client_ip,
448
+ metadata: { sessions_revoked, tokens_revoked, credential_type }
449
+ });
437
450
  return { sessions_revoked, tokens_revoked };
438
451
  });
439
452
  // Verify-success contract — the caller proved knowledge, so wipe
@@ -471,23 +484,13 @@ export const create_account_route_specs = (deps, options) => {
471
484
  }
472
485
  const { sessions_revoked, tokens_revoked } = change;
473
486
  // Close every live connection of this account now the password
474
- // update and the revoke-all cascade have committed — inline, not
475
- // queued: with no route transaction, a throw later in the handler
476
- // would drop a queued close while the revocation stands. It does
477
- // not depend on the fail-open audit write below; the audit
478
- // listeners repeat it on the announced `password_change` row.
487
+ // update, the revoke-all cascade, and its audit row have committed
488
+ // — inline, not queued: with no route transaction, a throw later in
489
+ // the handler would drop a queued close while the revocation
490
+ // stands. The audit listeners repeat it on the announced
491
+ // `password_change` row.
479
492
  close_connections_after_commit(connection_closer, { kind: 'account', account_id: ctx.account.id }, deps.log);
480
- // Account-grain operation — no `actor_id`. The password is
481
- // account-level state; which per-request actor was resolved
482
- // has no semantic bearing on "this account changed its
483
- // password". Mirrors `login`/`logout`.
484
- await deps.audit.emit(route, {
485
- event_type: 'password_change',
486
- account_id: ctx.account.id,
487
- ip: route.client_ip,
488
- metadata: { sessions_revoked, tokens_revoked, credential_type }
489
- });
490
- return route_ok({ ok: true, sessions_revoked, tokens_revoked }, { set_cookie: [clear_session_cookie_header(session_options)] });
493
+ return route_ok({ ok: true, sessions_revoked, tokens_revoked }, { set_cookie: [format_session_clear_cookie(session_cookie_name)] });
491
494
  }
492
495
  finally {
493
496
  ip_reserved.reservation.release();
@@ -1 +1 @@
1
- {"version":3,"file":"admin_actions.d.ts","sourceRoot":"","sources":["../../src/lib/auth/admin_actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAuC,KAAK,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAIjG,OAAO,EAKN,KAAK,YAAY,EACjB,MAAM,kBAAkB,CAAC;AAwD1B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AA2D3D,0CAA0C;AAC1C,MAAM,WAAW,kBAAkB;IAClC;;;;;OAKG;IACH,KAAK,CAAC,EAAE,YAAY,CAAC;CACrB;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,oBAAoB,GAChC,MAAM,yBAAyB,EAC/B,UAAS,kBAAuB,KAC9B,KAAK,CAAC,SAAS,CAmpBjB,CAAC"}
1
+ {"version":3,"file":"admin_actions.d.ts","sourceRoot":"","sources":["../../src/lib/auth/admin_actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAuC,KAAK,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAIjG,OAAO,EAKN,KAAK,YAAY,EACjB,MAAM,kBAAkB,CAAC;AA0D1B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AA0D3D,0CAA0C;AAC1C,MAAM,WAAW,kBAAkB;IAClC;;;;;OAKG;IACH,KAAK,CAAC,EAAE,YAAY,CAAC;CACrB;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,oBAAoB,GAChC,MAAM,yBAAyB,EAC/B,UAAS,kBAAuB,KAC9B,KAAK,CAAC,SAAS,CAupBjB,CAAC"}
@@ -37,15 +37,15 @@ import { has_scoped_role } from './request_context.js';
37
37
  import { query_account_has_global_role, query_account_has_active_global_role, query_count_active_accounts_with_global_role_locked } from './role_grant_queries.js';
38
38
  import { GRANT_PATH_ADMIN } from './grant_path_schema.js';
39
39
  import { query_role_grant_offer_lock_for_account_removal, query_role_grant_offer_supersede_incoming, query_role_grant_offer_supersede_outgoing } from './role_grant_offer_queries.js';
40
+ import { emit_supersede_audits } from './role_grant_offer_actions.js';
40
41
  import { queue_supersede_notifications } from './role_grant_offer_notifications.js';
41
- import { query_account_by_email, query_account_by_id, query_account_by_username, query_account_lock_admins_for_purge, query_account_lock_for_purge, query_account_lock_live_many, 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';
42
+ import { query_account_by_email, query_account_by_id, query_account_by_username, query_account_lock_admins_for_purge, query_account_lock_for_purge, 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';
42
43
  import { query_session_list_all_active, query_session_revoke_all_for_account } from './session_queries.js';
43
44
  import { query_revoke_all_api_tokens_for_account } from './api_token_queries.js';
44
45
  import { query_audit_log_list_role_grant_history, query_audit_log_list_with_usernames } from './audit_log_queries.js';
45
46
  import { AUDIT_LOG_DEFAULT_LIMIT } from './audit_log_schema.js';
46
- import { query_create_invite, query_invite_delete_unclaimed, query_invite_delete_unclaimed_by_creators, query_invite_list_all_with_usernames } from './invite_queries.js';
47
+ import { InviteDuplicateError, InviteIssuerNotActiveError, query_create_invite, query_invite_delete_unclaimed, query_invite_delete_unclaimed_by_creators, query_invite_list_all_with_usernames } from './invite_queries.js';
47
48
  import { query_app_settings_load, query_app_settings_load_with_username, query_app_settings_update } from './app_settings_queries.js';
48
- import { is_pg_unique_violation } from '../db/pg_error.js';
49
49
  import { ERROR_ACCOUNT_NOT_FOUND, ERROR_AUTHENTICATION_REQUIRED, ERROR_INSUFFICIENT_PERMISSIONS, ERROR_INVITE_ACCOUNT_EXISTS_EMAIL, ERROR_INVITE_ACCOUNT_EXISTS_USERNAME, ERROR_INVITE_DUPLICATE, ERROR_INVITE_NOT_FOUND } from '../http/error_schemas.js';
50
50
  import { admin_account_list_action_spec, admin_session_list_action_spec, admin_session_revoke_all_action_spec, admin_token_revoke_all_action_spec, audit_log_list_action_spec, audit_log_role_grant_history_action_spec, invite_create_action_spec, invite_list_action_spec, invite_delete_action_spec, account_delete_action_spec, account_purge_action_spec, account_undelete_action_spec, app_settings_get_action_spec, app_settings_update_action_spec, ERROR_PURGE_NOT_CONFIRMED, ERROR_CANNOT_DELETE_KEEPER, ERROR_CANNOT_DELETE_LAST_ADMIN } from './admin_action_specs.js';
51
51
  /**
@@ -170,13 +170,8 @@ export const create_admin_actions = (deps, options = {}) => {
170
170
  // The issuer's account was read before this transaction. A delete
171
171
  // committed since creates nothing — refused as the dead credential it now
172
172
  // is, as `account_token_create` refuses it — and one still to commit
173
- // waits on this lock, then deletes the invite with the account's other
174
- // unclaimed ones: a delete writes its tombstone first.
175
- if (!(await query_account_lock_live_many(ctx, [auth.account.id])).has(auth.account.id)) {
176
- throw jsonrpc_errors.unauthenticated('unauthenticated', {
177
- reason: ERROR_AUTHENTICATION_REQUIRED
178
- });
179
- }
173
+ // waits on the query's issuer lock, then deletes the invite with the
174
+ // account's other unclaimed ones. Twin of the Rust handler's.
180
175
  let invite;
181
176
  try {
182
177
  invite = await query_create_invite(ctx, {
@@ -186,7 +181,12 @@ export const create_admin_actions = (deps, options = {}) => {
186
181
  });
187
182
  }
188
183
  catch (err) {
189
- if (is_pg_unique_violation(err)) {
184
+ if (err instanceof InviteIssuerNotActiveError) {
185
+ throw jsonrpc_errors.unauthenticated('unauthenticated', {
186
+ reason: ERROR_AUTHENTICATION_REQUIRED
187
+ });
188
+ }
189
+ if (err instanceof InviteDuplicateError) {
190
190
  throw jsonrpc_errors.conflict('an unclaimed invite already exists', {
191
191
  reason: ERROR_INVITE_DUPLICATE
192
192
  });
@@ -195,6 +195,7 @@ export const create_admin_actions = (deps, options = {}) => {
195
195
  }
196
196
  await deps.audit.emit(ctx, {
197
197
  event_type: 'invite_create',
198
+ actor_id: auth.actor.id,
198
199
  account_id: auth.account.id,
199
200
  ip: ctx.client_ip,
200
201
  metadata: { invite_id: invite.id, email, username }
@@ -209,10 +210,24 @@ export const create_admin_actions = (deps, options = {}) => {
209
210
  const auth = ctx.auth;
210
211
  const deleted = await query_invite_delete_unclaimed(ctx, input.invite_id);
211
212
  if (!deleted) {
213
+ // The probe key is a UUID, so a failure row leaks nothing an admin's
214
+ // typo would (unlike `invite_create`'s email and username refusals,
215
+ // which write none), and a real admin aiming at a missing invite is
216
+ // forensic signal. Written through the pool, so it outlives the
217
+ // rollback this refusal causes. Twin of the Rust handler's row.
218
+ await deps.audit.emit(ctx, {
219
+ event_type: 'invite_delete',
220
+ outcome: 'failure',
221
+ actor_id: auth.actor.id,
222
+ account_id: auth.account.id,
223
+ ip: ctx.client_ip,
224
+ metadata: { reason: ERROR_INVITE_NOT_FOUND, attempted_invite_id: input.invite_id }
225
+ });
212
226
  throw jsonrpc_errors.not_found('invite', { reason: ERROR_INVITE_NOT_FOUND });
213
227
  }
214
228
  await deps.audit.emit(ctx, {
215
229
  event_type: 'invite_delete',
230
+ actor_id: auth.actor.id,
216
231
  account_id: auth.account.id,
217
232
  ip: ctx.client_ip,
218
233
  metadata: { invite_id: input.invite_id }
@@ -269,20 +284,7 @@ export const create_admin_actions = (deps, options = {}) => {
269
284
  // other party — `audience`, the side the removed account is not on, with the
270
285
  // `cause_id` that side is sent; the account's own connections close with it.
271
286
  const emit_account_deleted_supersedes = async (ctx, target_account_id, superseded, audience) => {
272
- for (const offer of superseded) {
273
- await deps.audit.emit_role_grant_target(ctx, ctx.auth, {
274
- event_type: 'role_grant_offer_supersede',
275
- target_account_id: offer.to_account_id,
276
- target_actor_id: offer.to_actor_id,
277
- metadata: {
278
- offer_id: offer.id,
279
- role: offer.role,
280
- scope_id: offer.scope_id,
281
- reason: 'account_deleted',
282
- cause_id: target_account_id
283
- }
284
- });
285
- }
287
+ await emit_supersede_audits(ctx, deps.audit, superseded, 'account_deleted', target_account_id);
286
288
  queue_supersede_notifications(ctx, superseded, 'account_deleted', audience);
287
289
  };
288
290
  // Lock every pending offer the removal supersedes, both directions, in one
@@ -317,15 +319,17 @@ export const create_admin_actions = (deps, options = {}) => {
317
319
  });
318
320
  };
319
321
  // Delete the unclaimed invites the removed account's actors issued, each
320
- // audited as an `invite_delete` is. An invite records no authority, so one
321
- // outliving its issuer's account would still admit a signup; deleted, it
322
- // answers a signup as a revoked one does, and an undelete can't revive it.
322
+ // audited as an `invite_delete` call is — the remover's actor and account.
323
+ // An invite records no authority, so one outliving its issuer's account
324
+ // would still admit a signup; deleted, it answers a signup as a revoked one
325
+ // does, and an undelete can't revive it.
323
326
  // A claimed invite is untouched.
324
327
  const void_unclaimed_invites = async (ctx, actors) => {
325
328
  const invite_ids = await query_invite_delete_unclaimed_by_creators(ctx, actors.map((a) => a.id));
326
329
  for (const invite_id of invite_ids) {
327
330
  await deps.audit.emit(ctx, {
328
331
  event_type: 'invite_delete',
332
+ actor_id: ctx.auth.actor.id,
329
333
  account_id: ctx.auth.account.id,
330
334
  ip: ctx.client_ip,
331
335
  metadata: { invite_id }
@@ -31,10 +31,14 @@ export declare const API_TOKEN_REGEX: RegExp;
31
31
  * @returns `true` when `raw` matches `API_TOKEN_REGEX`
32
32
  */
33
33
  export declare const is_api_token_shaped: (raw: string) => boolean;
34
+ /** Prefix on the public API token id (e.g. `tok_abC0_d-3xyzA`). */
35
+ export declare const API_TOKEN_ID_PREFIX = "tok_";
36
+ /** Length of the public id's body — the raw token body's first characters. */
37
+ export declare const API_TOKEN_ID_BODY_LENGTH = 12;
34
38
  /**
35
- * Regex for the public API token id (e.g. `tok_abC0_d-3xyzA`). Twelve
36
- * base64url characters after the `tok_` prefix. Matches the format produced
37
- * by `generate_api_token`.
39
+ * Regex for the public API token id (e.g. `tok_abC0_d-3xyzA`):
40
+ * `API_TOKEN_ID_PREFIX` plus `API_TOKEN_ID_BODY_LENGTH` base64url characters.
41
+ * Matches the format `to_api_token_id` derives.
38
42
  */
39
43
  export declare const API_TOKEN_ID_REGEX: RegExp;
40
44
  /** The public API token id, `API_TOKEN_ID_REGEX`, a `@fuzdev/fuz_schema` schema. */
@@ -47,6 +51,19 @@ export type ApiTokenId = Infer<typeof ApiTokenId>;
47
51
  * @returns hex-encoded blake3 hash
48
52
  */
49
53
  export declare const hash_api_token: (token: string) => string;
54
+ /**
55
+ * The public id of a raw API token: `API_TOKEN_ID_PREFIX` and the first
56
+ * `API_TOKEN_ID_BODY_LENGTH` characters of the body after `API_TOKEN_PREFIX`.
57
+ * Both spines derive it the same way, so a token minted by either names the
58
+ * same id on both. Twin of the Rust spine's `fuz_auth::api_token::to_api_token_id`,
59
+ * which answers `None` where this throws.
60
+ *
61
+ * @param token - the whole raw token, `API_TOKEN_PREFIX` included
62
+ * @returns the token's public id
63
+ * @throws Error when `token` is not `is_api_token_shaped` — a caller holds a
64
+ * minted or prechecked token, so anything else is a bug
65
+ */
66
+ export declare const to_api_token_id: (token: string) => ApiTokenId;
50
67
  /**
51
68
  * Generate a new API token with its hash and public id.
52
69
  *
@@ -1 +1 @@
1
- {"version":3,"file":"api_token.d.ts","sourceRoot":"","sources":["../../src/lib/auth/api_token.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAuB,KAAK,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAK/E,+DAA+D;AAC/D,eAAO,MAAM,gBAAgB,sBAAsB,CAAC;AAEpD,+DAA+D;AAC/D,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAE1C,oFAAoF;AACpF,eAAO,MAAM,qBAAqB,QAA+C,CAAC;AAElF;;;;GAIG;AACH,eAAO,MAAM,eAAe,QAE3B,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB,GAAI,KAAK,MAAM,KAAG,OAAoC,CAAC;AAEvF;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,QAA4B,CAAC;AAE5D,oFAAoF;AACpF,eAAO,MAAM,UAAU,gHAA0C,CAAC;AAClE,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AAElD;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,KAAG,MAA4B,CAAC;AAE5E;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,QAAO;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAMpF,CAAC"}
1
+ {"version":3,"file":"api_token.d.ts","sourceRoot":"","sources":["../../src/lib/auth/api_token.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAuB,KAAK,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAK/E,+DAA+D;AAC/D,eAAO,MAAM,gBAAgB,sBAAsB,CAAC;AAEpD,+DAA+D;AAC/D,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAE1C,oFAAoF;AACpF,eAAO,MAAM,qBAAqB,QAA+C,CAAC;AAElF;;;;GAIG;AACH,eAAO,MAAM,eAAe,QAE3B,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB,GAAI,KAAK,MAAM,KAAG,OAAoC,CAAC;AAEvF,mEAAmE;AACnE,eAAO,MAAM,mBAAmB,SAAS,CAAC;AAE1C,8EAA8E;AAC9E,eAAO,MAAM,wBAAwB,KAAK,CAAC;AAE3C;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,QAE9B,CAAC;AAEF,oFAAoF;AACpF,eAAO,MAAM,UAAU,gHAA0C,CAAC;AAClE,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AAElD;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,KAAG,MAA4B,CAAC;AAE5E;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,MAAM,KAAG,UAM/C,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,QAAO;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAGpF,CAAC"}
@@ -33,12 +33,16 @@ export const API_TOKEN_REGEX = new RegExp(`^${API_TOKEN_PREFIX}[A-Za-z0-9_-]{${A
33
33
  * @returns `true` when `raw` matches `API_TOKEN_REGEX`
34
34
  */
35
35
  export const is_api_token_shaped = (raw) => API_TOKEN_REGEX.test(raw);
36
+ /** Prefix on the public API token id (e.g. `tok_abC0_d-3xyzA`). */
37
+ export const API_TOKEN_ID_PREFIX = 'tok_';
38
+ /** Length of the public id's body — the raw token body's first characters. */
39
+ export const API_TOKEN_ID_BODY_LENGTH = 12;
36
40
  /**
37
- * Regex for the public API token id (e.g. `tok_abC0_d-3xyzA`). Twelve
38
- * base64url characters after the `tok_` prefix. Matches the format produced
39
- * by `generate_api_token`.
41
+ * Regex for the public API token id (e.g. `tok_abC0_d-3xyzA`):
42
+ * `API_TOKEN_ID_PREFIX` plus `API_TOKEN_ID_BODY_LENGTH` base64url characters.
43
+ * Matches the format `to_api_token_id` derives.
40
44
  */
41
- export const API_TOKEN_ID_REGEX = /^tok_[A-Za-z0-9_-]{12}$/;
45
+ export const API_TOKEN_ID_REGEX = new RegExp(`^${API_TOKEN_ID_PREFIX}[A-Za-z0-9_-]{${API_TOKEN_ID_BODY_LENGTH}}$`);
42
46
  /** The public API token id, `API_TOKEN_ID_REGEX`, a `@fuzdev/fuz_schema` schema. */
43
47
  export const ApiTokenId = pipe(string, regex(API_TOKEN_ID_REGEX));
44
48
  /**
@@ -48,6 +52,24 @@ export const ApiTokenId = pipe(string, regex(API_TOKEN_ID_REGEX));
48
52
  * @returns hex-encoded blake3 hash
49
53
  */
50
54
  export const hash_api_token = (token) => hash_blake3(token);
55
+ /**
56
+ * The public id of a raw API token: `API_TOKEN_ID_PREFIX` and the first
57
+ * `API_TOKEN_ID_BODY_LENGTH` characters of the body after `API_TOKEN_PREFIX`.
58
+ * Both spines derive it the same way, so a token minted by either names the
59
+ * same id on both. Twin of the Rust spine's `fuz_auth::api_token::to_api_token_id`,
60
+ * which answers `None` where this throws.
61
+ *
62
+ * @param token - the whole raw token, `API_TOKEN_PREFIX` included
63
+ * @returns the token's public id
64
+ * @throws Error when `token` is not `is_api_token_shaped` — a caller holds a
65
+ * minted or prechecked token, so anything else is a bug
66
+ */
67
+ export const to_api_token_id = (token) => {
68
+ if (!is_api_token_shaped(token))
69
+ throw new Error('to_api_token_id: not an API token');
70
+ return (API_TOKEN_ID_PREFIX +
71
+ token.slice(API_TOKEN_PREFIX.length, API_TOKEN_PREFIX.length + API_TOKEN_ID_BODY_LENGTH));
72
+ };
51
73
  /**
52
74
  * Generate a new API token with its hash and public id.
53
75
  *
@@ -57,9 +79,6 @@ export const hash_api_token = (token) => hash_blake3(token);
57
79
  * @returns the raw token, a public id, and the blake3 hash for storage
58
80
  */
59
81
  export const generate_api_token = () => {
60
- const raw = generate_random_base64url(API_TOKEN_ENTROPY_BYTES);
61
- const token = `${API_TOKEN_PREFIX}${raw}`;
62
- const token_hash = hash_api_token(token);
63
- const id = `tok_${raw.slice(0, 12)}`;
64
- return { token, id, token_hash };
82
+ const token = `${API_TOKEN_PREFIX}${generate_random_base64url(API_TOKEN_ENTROPY_BYTES)}`;
83
+ return { token, id: to_api_token_id(token), token_hash: hash_api_token(token) };
65
84
  };
@@ -38,7 +38,7 @@ export declare const API_TOKEN_COLUMNS: readonly ["id", "account_id", "name", "t
38
38
  * Store a new API token (the hash, not the raw token).
39
39
  *
40
40
  * @param deps - query dependencies
41
- * @param id - the public token id (e.g. `tok_abc123`)
41
+ * @param id - the public token id (e.g. `tok_abC0_d-3xyzA`)
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
@@ -87,7 +87,7 @@ export declare const query_api_token_touch: (deps: QueryDeps, id: string, ip: st
87
87
  * admitted with, and nothing rewrites the column after the mint.
88
88
  *
89
89
  * @param deps - query dependencies
90
- * @param id - the public token id (e.g. `tok_abc123`)
90
+ * @param id - the public token id (e.g. `tok_abC0_d-3xyzA`)
91
91
  * @returns the owning account id, or `undefined` when the token is gone or expired
92
92
  */
93
93
  export declare const query_api_token_live_account: (deps: QueryDeps, id: string) => Promise<string | undefined>;
@@ -53,7 +53,7 @@ const API_TOKEN_IS_LIVE = '(expires_at IS NULL OR expires_at > NOW())';
53
53
  * Store a new API token (the hash, not the raw token).
54
54
  *
55
55
  * @param deps - query dependencies
56
- * @param id - the public token id (e.g. `tok_abc123`)
56
+ * @param id - the public token id (e.g. `tok_abC0_d-3xyzA`)
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
@@ -134,7 +134,7 @@ export const query_api_token_touch = async (deps, id, ip) => {
134
134
  * admitted with, and nothing rewrites the column after the mint.
135
135
  *
136
136
  * @param deps - query dependencies
137
- * @param id - the public token id (e.g. `tok_abc123`)
137
+ * @param id - the public token id (e.g. `tok_abC0_d-3xyzA`)
138
138
  * @returns the owning account id, or `undefined` when the token is gone or expired
139
139
  */
140
140
  export const query_api_token_live_account = async (deps, id) => {