@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
@@ -42,7 +42,9 @@ import { queue_connection_close } from '../actions/connection_closer.js';
42
42
  import { jsonrpc_errors } from '../http/jsonrpc_errors.js';
43
43
  import { builtin_role_specs, is_builtin_role, list_roles_with_grant_path, RoleName } from './role_schema.js';
44
44
  import { GRANT_PATH_SELF_SERVICE } from './grant_path_schema.js';
45
- import { query_create_role_grant, query_revoke_role_grant } from './role_grant_queries.js';
45
+ import { query_create_role_grant } from './role_grant_queries.js';
46
+ import { query_revoke_role_grant } from './role_grant_offer_queries.js';
47
+ import { emit_supersede_audits } from './role_grant_offer_actions.js';
46
48
  import { is_role_grant_active } from './account_schema.js';
47
49
  import { has_scoped_role } from './request_context.js';
48
50
  import { queue_supersede_notifications } from './role_grant_offer_notifications.js';
@@ -189,27 +191,14 @@ export const create_self_service_role_actions = (deps, options = {}) => {
189
191
  self_service: true
190
192
  }
191
193
  });
192
- // Supersede cascade — `query_revoke_role_grant` marks any pending offers
193
- // for the same `(account, role, scope)` superseded as a side effect, and
194
- // each gets its forensic row like the admin revoke's (empty in practice:
195
- // offer creation gates on the role's `grant_paths`, so only a role that is
196
- // both offerable and self-service-eligible has siblings). Both parties are
197
- // told, as the admin revoke tells them: the recipient is the caller, but
198
- // its answer lists no offers, so its other connections learn of them here.
199
- for (const offer of result.superseded_offers) {
200
- await deps.audit.emit_role_grant_target(ctx, auth, {
201
- event_type: 'role_grant_offer_supersede',
202
- target_account_id: offer.to_account_id,
203
- target_actor_id: offer.to_actor_id,
204
- metadata: {
205
- offer_id: offer.id,
206
- role: offer.role,
207
- scope_id: offer.scope_id,
208
- reason: 'role_grant_revoked',
209
- cause_id: result.id
210
- }
211
- });
212
- }
194
+ // Supersede cascade — the revoke ended the caller's pending offers of the
195
+ // role (only a role both offerable and self-service-eligible has any) and
196
+ // every offer the caller's actor made, whatever its role, as the admin
197
+ // revoke ends them (`query_revoke_role_grant`). Each gets its forensic row
198
+ // like the admin revoke's, and both parties of each are told: the caller
199
+ // is one party of every offer, but its answer lists none, so its other
200
+ // connections learn of them here.
201
+ await emit_supersede_audits(ctx, deps.audit, result.superseded_offers, 'role_grant_revoked', result.id);
213
202
  const revoked_grant = { kind: 'id', id: result.id };
214
203
  queue_supersede_notifications(ctx, result.superseded_offers, 'role_grant_revoked', {
215
204
  grantor: revoked_grant,
@@ -1,20 +1,27 @@
1
1
  /**
2
- * Generic session management for cookie-based auth.
2
+ * The signed session cookie: its name, value format, verification, and the
3
+ * exact `Set-Cookie` strings that set and clear it — byte for byte the Rust
4
+ * spine's `fuz_auth::session_cookie`.
3
5
  *
4
- * Parameterized on identity type via `SessionOptions<TIdentity>`.
5
- * Handles signing, expiration, and key rotation. Apps provide
6
- * encode/decode for their specific identity format.
7
- *
8
- * Cookie value format: `${encode(identity)}:${expires_at}` (signed with HMAC-SHA256).
6
+ * Cookie value: `keyring.sign("${session_token}:${expires_at}")`. The signed
7
+ * payload carries the raw session token (whose blake3 hash is the
8
+ * `auth_session` row id) and its expiry, so one HMAC covers both the token
9
+ * bind and the freshness check.
9
10
  *
10
11
  * @module
11
12
  */
12
13
  import type { Keyring } from './keyring.js';
14
+ /**
15
+ * The default session cookie name — the Rust spine's `SESSION_COOKIE_NAME`,
16
+ * so a cookie either spine mints reads on both. An app with its own name
17
+ * passes it as `session_cookie_name` wherever the spine takes one.
18
+ */
19
+ export declare const SESSION_COOKIE_NAME = "fuz_session";
13
20
  /**
14
21
  * Cookie max age in seconds (30 days — aligned with AUTH_SESSION_LIFETIME_MS).
15
22
  *
16
23
  * This is an **absolute** session lifetime: the cookie is signed once at
17
- * mint (`expires_at = mint + max_age`) and never re-signed, matching the DB
24
+ * mint (`expires_at = mint + SESSION_AGE_MAX`) and never re-signed, matching the DB
18
25
  * row's fixed `expires_at`. There is deliberately no sliding renewal on
19
26
  * either leg — see `docs/security.md` §Session Security.
20
27
  */
@@ -49,9 +56,8 @@ export declare const is_cookie_name: (name: string) => boolean;
49
56
  * what a reader that decodes nothing needs. Twin of the Rust spine's
50
57
  * `is_cookie_value`.
51
58
  *
52
- * Anything but a string is refused, whatever its type says: the value comes
53
- * out of a consumer's `encode_identity` and keyring, and a regex alone would
54
- * read `undefined` as the text `undefined`.
59
+ * Anything but a string is refused, whatever its type says: a regex alone
60
+ * would read `undefined` as the text `undefined`.
55
61
  *
56
62
  * @param value - a cookie value
57
63
  */
@@ -67,7 +73,7 @@ export declare const is_cookie_value: (value: string) => boolean;
67
73
  * @param value - the signed cookie value (`create_session_cookie_value`)
68
74
  * @param max_age - the cookie's lifetime in seconds
69
75
  * @returns the `Set-Cookie` header value
70
- * @throws Error when the name is not an RFC 6265 `cookie-name`, the value holds anything but `cookie-octet`s (an `encode_identity` that emits a space, a `;`, or a non-ASCII character), or `max_age` is not a non-negative safe integer — a header that would read back differently is never written
76
+ * @throws Error when the name is not an RFC 6265 `cookie-name`, the value holds anything but `cookie-octet`s (a space, a `;`, a non-ASCII character), or `max_age` is not a non-negative safe integer — a header that would read back differently is never written
71
77
  */
72
78
  export declare const format_session_set_cookie: (cookie_name: string, value: string, max_age: number) => string;
73
79
  /**
@@ -81,181 +87,83 @@ export declare const format_session_set_cookie: (cookie_name: string, value: str
81
87
  */
82
88
  export declare const format_session_clear_cookie: (cookie_name: string) => string;
83
89
  /**
84
- * Configuration for a session cookie format.
85
- *
86
- * Apps provide encode/decode to control the identity portion
87
- * of the cookie payload.
88
- *
89
- * The `TIdentity` type parameter determines the trust model:
90
- * - `string` (e.g. a session_id) — the cookie references a server-side session record,
91
- * enabling per-session revocation and metadata. Use when you need admin controls
92
- * like "revoke all sessions" or per-session audit trails.
93
- * - `number` (e.g. an account_id) — the cookie directly encodes the user identity,
94
- * requiring no server-side session state. Simpler, but individual sessions
95
- * can only be invalidated by rotating the signing key (which invalidates all sessions).
96
- *
97
- * The cookie helpers here take either. The spine's session middleware and
98
- * auth chain take `SessionOptions<string>` — the identity is the session token
99
- * the session leg hashes to find its `auth_session` row (`create_session_config`).
100
- *
101
- * @example
102
- * ```ts
103
- * // zap: 3-part format (admin:session_id)
104
- * const zap_config: SessionOptions<string> = {
105
- * cookie_name: 'zap_session',
106
- * encode_identity: (session_id) => `admin:${session_id}`,
107
- * decode_identity: (payload) => {
108
- * const parts = payload.split(':');
109
- * if (parts.length !== 2 || parts[0] !== 'admin') return null;
110
- * return parts[1] || null;
111
- * },
112
- * };
113
- *
114
- * // visiones: 1-part format (account_id)
115
- * const visiones_config: SessionOptions<number> = {
116
- * cookie_name: 'session_id',
117
- * encode_identity: (id) => String(id),
118
- * decode_identity: (payload) => {
119
- * const n = parseInt(payload, 10);
120
- * return Number.isFinite(n) && n > 0 ? n : null;
121
- * },
122
- * };
123
- * ```
124
- */
125
- export interface SessionOptions<TIdentity> {
126
- cookie_name: string;
127
- /**
128
- * Cookie lifetime in seconds. Single source of truth for both the embedded
129
- * `expires_at` (via `create_session_cookie_value`) and the cookie's HTTP
130
- * `Max-Age` attribute (via `session_cookie_header`). Defaults to
131
- * `SESSION_AGE_MAX` (30 days). Every other attribute is fixed
132
- * (`SESSION_COOKIE_ATTRIBUTES`).
133
- */
134
- max_age?: number;
135
- /**
136
- * Encode identity into the cookie payload (before the `:expires_at` suffix).
137
- * The payload goes into the cookie as written, so it must hold only RFC
138
- * 6265 `cookie-octet`s (`is_cookie_value`) — `session_cookie_header` throws
139
- * on anything else.
140
- */
141
- encode_identity: (identity: TIdentity) => string;
142
- /** Decode identity from cookie payload. Return null if invalid. */
143
- decode_identity: (payload: string) => TIdentity | null;
144
- }
145
- /**
146
- * The `Set-Cookie` value that sets the session cookie to `value`, a signed
147
- * cookie value (`create_session_cookie_value`, or the `cookie_value` of
148
- * `create_capped_session`) — what a success carries
149
- * (`route_ok(value, {set_cookie: [...]})`). `options.max_age` sets `Max-Age`,
150
- * as it set the value's embedded expiry; `SESSION_AGE_MAX` when unset. Twin of
151
- * the Rust `session_cookie_header`, which signs the token itself.
90
+ * Sign a session token into a session cookie value: the keyring's signature
91
+ * of `${session_token}:${expires_at}`, the expiry `SESSION_AGE_MAX` from now —
92
+ * what a `Cookie` header carries after `<name>=`. Signed once, at mint: the
93
+ * lifetime is absolute, never renewed (`docs/security.md` §Session Security).
94
+ * Twin of the Rust `create_session_cookie_value`.
152
95
  *
153
- * @param value - the signed cookie value
154
- * @param options - the cookie name and lifetime
155
- * @returns the `Set-Cookie` header value (`format_session_set_cookie`)
156
- * @throws Error when the cookie name or the value is outside the RFC 6265 grammar
96
+ * @param keyring - key ring for signing
97
+ * @param session_token - the raw session token
98
+ * @param now_seconds - current time in seconds (for testing)
99
+ * @returns the signed cookie value
157
100
  */
158
- export declare const session_cookie_header: <T>(value: string, options: SessionOptions<T>) => string;
101
+ export declare const create_session_cookie_value: (keyring: Keyring, session_token: string, now_seconds?: number) => Promise<string>;
159
102
  /**
160
- * The `Set-Cookie` value that clears the session cookie — what a logout or a
161
- * password change carries on its success. Twin of the Rust
162
- * `clear_session_cookie_header`.
103
+ * Sign a session token and build the `Set-Cookie` header value that sets it
104
+ * under `cookie_name` — `format_session_set_cookie` over
105
+ * `create_session_cookie_value`, with `SESSION_AGE_MAX` as its lifetime. What
106
+ * a success that mints a session carries (`route_ok(value, {set_cookie})`).
107
+ * Twin of the Rust `sign_session_cookie`.
163
108
  *
164
- * @param options - the cookie name
165
- * @returns the `Set-Cookie` header value (`format_session_clear_cookie`)
166
- * @throws Error when the cookie name is outside the RFC 6265 grammar
109
+ * @param keyring - key ring for signing
110
+ * @param session_token - the raw session token (`create_capped_session`'s `token`)
111
+ * @param cookie_name - the session cookie's name
112
+ * @returns the `Set-Cookie` header value
113
+ * @throws Error when the cookie name, or the signed value, is outside the RFC 6265 grammar
167
114
  */
168
- export declare const clear_session_cookie_header: <T>(options: SessionOptions<T>) => string;
115
+ export declare const sign_session_cookie: (keyring: Keyring, session_token: string, cookie_name: string) => Promise<string>;
169
116
  /**
170
- * Result of parsing a signed session cookie.
117
+ * A verified, unexpired session cookie: the raw session token it carries and
118
+ * the expiry signed beside it. Twin of the Rust `SessionCookie`.
171
119
  */
172
- export interface ParsedSession<TIdentity> {
173
- /** The decoded identity. */
174
- identity: TIdentity;
175
- /** Index of the key that verified the signature (0 = primary). */
176
- key_index: number;
120
+ export interface SessionCookie {
121
+ /** The raw session token — its blake3 hash is the `auth_session` row id. */
122
+ token: string;
177
123
  /** The signed expiry, in seconds since the Unix epoch — later than the parse. */
178
124
  expires_at: number;
179
125
  }
180
126
  /**
181
- * Parse a signed session cookie value.
182
- *
183
- * The signed value format is `${encode(identity)}:${expires_at}`.
184
- * Tries all keys in order to support key rotation.
185
- *
186
- * An empty string is a cookie that was sent with no value (`name=`): present
187
- * and invalid, like any other value that fails verification. Only a nullish
188
- * `signed_value` is "no cookie".
189
- *
190
- * @param signed_value - the raw cookie value (signed), nullish when the request carries no session cookie
127
+ * How a request's `Cookie` lines read for the session cookie — what the
128
+ * cookie alone shows, before any database work. Twin of the Rust
129
+ * `SessionCookieRead`.
130
+ *
131
+ * - `absent` — no pair names the cookie
132
+ * - `invalid` — a pair names it and its value fails verification: unreadable,
133
+ * a bad MAC, a signed expiry that has passed, an empty token, an empty
134
+ * value. What the session middleware clears.
135
+ * - `valid` — it verifies under the keyring and its signed expiry is ahead.
136
+ * Says nothing about the `auth_session` row.
137
+ */
138
+ export type SessionCookieRead = {
139
+ kind: 'absent';
140
+ } | {
141
+ kind: 'invalid';
142
+ } | {
143
+ kind: 'valid';
144
+ cookie: SessionCookie;
145
+ };
146
+ /**
147
+ * Read the session cookie out of a request's `Cookie` lines: the
148
+ * `cookie_name` pair (`read_session_cookie_value` — the first, verbatim),
149
+ * verified under the keyring, its signed expiry checked, its session token
150
+ * answered with that expiry.
151
+ *
152
+ * The three answers are what the cookie alone shows (`SessionCookieRead`). An
153
+ * empty value (`name=`) is a cookie sent with none: present and invalid. A
154
+ * valid cookie whose `auth_session` row is gone is still valid here; nothing
155
+ * clears it. There is deliberately no refresh: a re-sign would compute a
156
+ * fresh expiry past the row's fixed `expires_at`, so the lifetime is the one
157
+ * signing at mint, on both spines.
158
+ *
159
+ * Twin of the Rust `parse_session_from_cookies`, which takes the request's
160
+ * headers.
161
+ *
162
+ * @param cookie_lines - the request's `Cookie` header lines
191
163
  * @param keyring - key ring for verification
192
- * @param options - session configuration with decode logic
193
- * @param now_seconds - current time in seconds (for testing)
194
- * @returns `ParsedSession` if valid, null if invalid/expired (the empty string included), undefined if missing
195
- */
196
- export declare const parse_session: <TIdentity>(signed_value: string | null | undefined, keyring: Keyring, options: SessionOptions<TIdentity>, now_seconds?: number) => Promise<ParsedSession<TIdentity> | null | undefined>;
197
- /**
198
- * Create a signed session cookie value.
199
- *
200
- * Format: `${encode(identity)}:${expires_at}` signed with HMAC-SHA256.
201
- * Embeds expiration in the signed value itself for defense-in-depth.
202
- *
203
- * @param keyring - key ring for signing
204
- * @param identity - the identity to encode
205
- * @param options - session configuration with encode logic
206
- * @param now_seconds - current time in seconds (for testing)
207
- * @returns signed cookie value string
208
- */
209
- export declare const create_session_cookie_value: <TIdentity>(keyring: Keyring, identity: TIdentity, options: SessionOptions<TIdentity>, now_seconds?: number) => Promise<string>;
210
- /**
211
- * Result of processing a session cookie.
212
- */
213
- export interface ProcessSessionResult<TIdentity> {
214
- /** Whether the session is valid. */
215
- valid: boolean;
216
- /** Action the adapter should take. */
217
- action: 'none' | 'clear';
218
- /** The decoded identity if the cookie was valid. */
219
- identity?: TIdentity;
220
- /** The cookie's signed expiry, epoch seconds, if the cookie was valid. */
221
- expires_at?: number;
222
- }
223
- /**
224
- * Create a session config for raw session token identity.
225
- *
226
- * The standard pattern: cookie stores the raw session token,
227
- * server hashes it (blake3) to look up the `auth_session` row.
228
- * Only the `cookie_name` varies per app.
229
- *
230
- * @param cookie_name - cookie name (e.g. `'zap_session'`, `'visiones_session'`)
231
- * @returns a `SessionOptions<string>` ready for use with session middleware
232
- */
233
- export declare const create_session_config: (cookie_name: string) => SessionOptions<string>;
234
- /** Canonical session config for fuz_app auth. */
235
- export declare const fuz_session_config: SessionOptions<string>;
236
- /**
237
- * Process a session cookie and determine what action to take.
238
- *
239
- * There is deliberately no refresh action: any re-sign computes a fresh
240
- * `now + max_age` expiry, extending the cookie past the DB row's fixed
241
- * `expires_at` — the holder would go silently anonymous while carrying a
242
- * self-perpetuating cookie. The absolute lifetime is one signing at mint,
243
- * on both legs, matching the Rust spine. A cookie signed by a retired
244
- * (non-primary) key keeps verifying until the key leaves the keyring;
245
- * retired keys are safe to drop after `SESSION_AGE_MAX` (see
246
- * `docs/security.md` §Cookie Key Rotation).
247
- *
248
- * The three outcomes are what the cookie alone shows: no cookie (`action:
249
- * 'none'`), a cookie that fails verification — unreadable, a bad MAC, a signed
250
- * expiry that has passed, an empty identity, an empty value — (`action:
251
- * 'clear'`), and a valid one. A valid cookie whose `auth_session` row is gone
252
- * is still valid here; nothing clears it.
253
- *
254
- * @param signed_value - the raw cookie value, nullish when the request carries no session cookie
255
- * @param keyring - key ring for verification and signing
256
- * @param options - session configuration
164
+ * @param cookie_name - the session cookie's name
257
165
  * @param now_seconds - current time in seconds (for testing)
258
- * @returns result with validity and action to take
166
+ * @returns the cookie's reading
259
167
  */
260
- export declare const process_session_cookie: <TIdentity>(signed_value: string | null | undefined, keyring: Keyring, options: SessionOptions<TIdentity>, now_seconds?: number) => Promise<ProcessSessionResult<TIdentity>>;
168
+ export declare const parse_session_from_cookies: (cookie_lines: ReadonlyArray<string>, keyring: Keyring, cookie_name: string, now_seconds?: number) => Promise<SessionCookieRead>;
261
169
  //# sourceMappingURL=session_cookie.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"session_cookie.d.ts","sourceRoot":"","sources":["../../src/lib/auth/session_cookie.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,QAAoB,CAAC;AAWjD;;;;;;;;;GASG;AACH,eAAO,MAAM,yBAAyB,8CAA8C,CAAC;AAQrF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,KAAG,OACW,CAAC;AAE1D;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,MAAM,KAAG,OACY,CAAC;AAgB7D;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,yBAAyB,GACrC,aAAa,MAAM,EACnB,OAAO,MAAM,EACb,SAAS,MAAM,KACb,MAeF,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,2BAA2B,GAAI,aAAa,MAAM,KAAG,MAGjE,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,MAAM,WAAW,cAAc,CAAC,SAAS;IACxC,WAAW,EAAE,MAAM,CAAC;IACpB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,eAAe,EAAE,CAAC,QAAQ,EAAE,SAAS,KAAK,MAAM,CAAC;IACjD,mEAAmE;IACnE,eAAe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