@fuzdev/fuz_app 0.181.0 → 0.182.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/dist/actions/CLAUDE.md +24 -6
  2. package/dist/actions/action_rpc.d.ts +11 -1
  3. package/dist/actions/action_rpc.d.ts.map +1 -1
  4. package/dist/actions/action_rpc.js +3 -2
  5. package/dist/actions/action_types.d.ts +16 -1
  6. package/dist/actions/action_types.d.ts.map +1 -1
  7. package/dist/actions/action_types.js +1 -1
  8. package/dist/actions/notification_sender.d.ts +83 -0
  9. package/dist/actions/notification_sender.d.ts.map +1 -0
  10. package/dist/actions/notification_sender.js +85 -0
  11. package/dist/actions/perform_action.d.ts +9 -0
  12. package/dist/actions/perform_action.d.ts.map +1 -1
  13. package/dist/actions/perform_action.js +22 -13
  14. package/dist/actions/register_action_ws.d.ts +14 -0
  15. package/dist/actions/register_action_ws.d.ts.map +1 -1
  16. package/dist/actions/register_action_ws.js +3 -2
  17. package/dist/actions/ws_socket_session.d.ts +3 -0
  18. package/dist/actions/ws_socket_session.d.ts.map +1 -1
  19. package/dist/actions/ws_socket_session.js +2 -1
  20. package/dist/auth/CLAUDE.md +60 -41
  21. package/dist/auth/account_actions.d.ts.map +1 -1
  22. package/dist/auth/account_actions.js +13 -3
  23. package/dist/auth/account_queries.d.ts +158 -16
  24. package/dist/auth/account_queries.d.ts.map +1 -1
  25. package/dist/auth/account_queries.js +189 -18
  26. package/dist/auth/account_routes.d.ts +1 -1
  27. package/dist/auth/account_routes.d.ts.map +1 -1
  28. package/dist/auth/account_routes.js +27 -26
  29. package/dist/auth/admin_actions.d.ts.map +1 -1
  30. package/dist/auth/admin_actions.js +71 -28
  31. package/dist/auth/api_token_queries.d.ts +13 -5
  32. package/dist/auth/api_token_queries.d.ts.map +1 -1
  33. package/dist/auth/api_token_queries.js +24 -9
  34. package/dist/auth/bearer_auth.d.ts.map +1 -1
  35. package/dist/auth/bearer_auth.js +3 -2
  36. package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
  37. package/dist/auth/daemon_token_middleware.js +12 -1
  38. package/dist/auth/deps.d.ts +10 -0
  39. package/dist/auth/deps.d.ts.map +1 -1
  40. package/dist/auth/request_context.d.ts +73 -73
  41. package/dist/auth/request_context.d.ts.map +1 -1
  42. package/dist/auth/request_context.js +78 -96
  43. package/dist/auth/resolved_auth.d.ts +10 -5
  44. package/dist/auth/resolved_auth.d.ts.map +1 -1
  45. package/dist/auth/resolved_auth.js +2 -2
  46. package/dist/auth/role_grant_offer_action_specs.d.ts +1 -1
  47. package/dist/auth/role_grant_offer_action_specs.d.ts.map +1 -1
  48. package/dist/auth/role_grant_offer_action_specs.js +2 -1
  49. package/dist/auth/role_grant_offer_actions.d.ts +7 -11
  50. package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
  51. package/dist/auth/role_grant_offer_actions.js +61 -93
  52. package/dist/auth/role_grant_offer_notifications.d.ts +87 -38
  53. package/dist/auth/role_grant_offer_notifications.d.ts.map +1 -1
  54. package/dist/auth/role_grant_offer_notifications.js +75 -22
  55. package/dist/auth/role_grant_offer_queries.d.ts +96 -15
  56. package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
  57. package/dist/auth/role_grant_offer_queries.js +185 -70
  58. package/dist/auth/role_grant_offer_schema.js +1 -1
  59. package/dist/auth/role_grant_queries.d.ts +52 -12
  60. package/dist/auth/role_grant_queries.d.ts.map +1 -1
  61. package/dist/auth/role_grant_queries.js +75 -24
  62. package/dist/auth/role_grant_sql.d.ts +21 -0
  63. package/dist/auth/role_grant_sql.d.ts.map +1 -1
  64. package/dist/auth/role_grant_sql.js +21 -0
  65. package/dist/auth/self_service_role_actions.d.ts.map +1 -1
  66. package/dist/auth/self_service_role_actions.js +9 -2
  67. package/dist/auth/session_queries.d.ts +34 -13
  68. package/dist/auth/session_queries.d.ts.map +1 -1
  69. package/dist/auth/session_queries.js +48 -18
  70. package/dist/auth/standard_rpc_actions.d.ts +6 -19
  71. package/dist/auth/standard_rpc_actions.d.ts.map +1 -1
  72. package/dist/auth/standard_rpc_actions.js +5 -6
  73. package/dist/auth/token_scope.d.ts +1 -1
  74. package/dist/auth/token_scope.js +1 -1
  75. package/dist/http/CLAUDE.md +7 -6
  76. package/dist/http/auth_shape.d.ts +1 -1
  77. package/dist/http/error_schemas.d.ts +9 -21
  78. package/dist/http/error_schemas.d.ts.map +1 -1
  79. package/dist/http/error_schemas.js +14 -24
  80. package/dist/http/route_spec.d.ts +2 -2
  81. package/dist/server/app_backend.d.ts.map +1 -1
  82. package/dist/server/app_backend.js +3 -1
  83. package/dist/server/app_server.d.ts +26 -16
  84. package/dist/server/app_server.d.ts.map +1 -1
  85. package/dist/server/app_server.js +17 -7
  86. package/dist/server/serve_fact_route.d.ts +3 -3
  87. package/dist/server/serve_fact_route.js +12 -12
  88. package/dist/testing/CLAUDE.md +5 -5
  89. package/dist/testing/app_server.d.ts.map +1 -1
  90. package/dist/testing/app_server.js +3 -1
  91. package/dist/testing/auth_apps.js +1 -1
  92. package/dist/testing/cross_backend/account_lifecycle.d.ts.map +1 -1
  93. package/dist/testing/cross_backend/account_lifecycle.js +43 -0
  94. package/dist/testing/cross_backend/default_spine_surface.d.ts +1 -26
  95. package/dist/testing/cross_backend/default_spine_surface.d.ts.map +1 -1
  96. package/dist/testing/cross_backend/default_spine_surface.js +2 -6
  97. package/dist/testing/cross_backend/full_spine_mount.d.ts +3 -10
  98. package/dist/testing/cross_backend/full_spine_mount.d.ts.map +1 -1
  99. package/dist/testing/cross_backend/full_spine_mount.js +4 -4
  100. package/dist/testing/cross_backend/role_grant_offer_notification_ws.d.ts +5 -4
  101. package/dist/testing/cross_backend/role_grant_offer_notification_ws.d.ts.map +1 -1
  102. package/dist/testing/cross_backend/role_grant_offer_notification_ws.js +183 -30
  103. package/dist/testing/cross_backend/session_cap.d.ts.map +1 -1
  104. package/dist/testing/cross_backend/session_cap.js +26 -5
  105. package/dist/testing/middleware.d.ts +1 -1
  106. package/dist/testing/middleware.js +5 -5
  107. package/dist/testing/resolved_auth.d.ts +3 -1
  108. package/dist/testing/resolved_auth.d.ts.map +1 -1
  109. package/dist/testing/resolved_auth.js +4 -4
  110. package/dist/testing/stubs.d.ts.map +1 -1
  111. package/dist/testing/stubs.js +5 -2
  112. package/dist/testing/ws_round_trip.d.ts.map +1 -1
  113. package/dist/testing/ws_round_trip.js +8 -4
  114. package/package.json +1 -1
@@ -15,12 +15,13 @@
15
15
  * schema declared `acting?: ActingActor` (reference equality with the
16
16
  * canonical `ActingActor` schema) or the auth requires role_grants
17
17
  * (`role` / `keeper`), `apply_authorization_phase` resolves the actor
18
- * against the resolved account id plus the validated `acting` value via
18
+ * against the resolved account plus the validated `acting` value via
19
19
  * `resolve_acting_actor`, builds the `{account, actor, role_grants}`
20
20
  * context via `build_request_context`, and sets it on
21
21
  * `REQUEST_CONTEXT_KEY` before auth guards fire. Authenticated routes
22
- * that don't need an actor still get an account-only context via
23
- * `build_account_context` so handler signatures stay uniform.
22
+ * that don't need an actor still get an account-only context, so handler
23
+ * signatures stay uniform. The account is the row the credential leg
24
+ * read (`ResolvedAuth.account`) — the phase does not read it again.
24
25
  *
25
26
  * Account-grain operations (logout, password_change, account_verify,
26
27
  * etc.) declare neither `acting` nor role_grant-requiring auth, so no actor
@@ -29,15 +30,15 @@
29
30
  * which is what makes multi-actor logout work without first picking a
30
31
  * persona.
31
32
  *
32
- * `build_request_context` loads `account → actor → role_grants` and verifies
33
- * the `actor.account_id === account.id` binding. `refresh_role_grants`
34
- * reloads role_grants on an existing context.
33
+ * `build_request_context` loads the acting actor's role_grants onto the
34
+ * account and the actor `resolve_acting_actor` read off that account.
35
+ * `refresh_role_grants` reloads role_grants on an existing context.
35
36
  *
36
37
  * @module
37
38
  */
38
39
  import { is_role_grant_active } from './account_schema.js';
39
40
  import { hash_session_token, query_session_get_valid } from './session_queries.js';
40
- import { query_account_by_id, query_actor_by_id, query_active_actors_by_account } from './account_queries.js';
41
+ import { query_account_by_id, query_active_actors_by_account } from './account_queries.js';
41
42
  import { query_role_grant_find_active_for_actor } from './role_grant_queries.js';
42
43
  import { has_test_context_preset, RESOLVED_AUTH_KEY, SESSION_COOKIE_EXPIRES_AT_KEY, SESSION_TOKEN_KEY } from '../hono_context.js';
43
44
  import { credential_deadline_after } from './credential_deadline.js';
@@ -46,7 +47,7 @@ import { get_resolved_auth, resolved_auth_scope } from './resolved_auth.js';
46
47
  import { is_route_scope_capability, token_scope_admits_non_rpc, token_scope_denied_body } from './token_scope.js';
47
48
  import { is_public_auth, needs_actor, parse_acting } from '../http/auth_shape.js';
48
49
  import { is_null_schema } from '../http/schema_helpers.js';
49
- import { ERROR_AUTHENTICATION_REQUIRED, ERROR_INSUFFICIENT_PERMISSIONS, ERROR_CREDENTIAL_TYPE_REQUIRED, ERROR_ACTOR_REQUIRED, ERROR_ACTOR_NOT_ON_ACCOUNT, ERROR_NO_ACTORS_ON_ACCOUNT, ERROR_ACCOUNT_VANISHED } from '../http/error_schemas.js';
50
+ import { ERROR_AUTHENTICATION_REQUIRED, ERROR_INSUFFICIENT_PERMISSIONS, ERROR_CREDENTIAL_TYPE_REQUIRED, ERROR_ACTOR_REQUIRED, ERROR_ACTOR_NOT_ON_ACCOUNT, ERROR_NO_ACTORS_ON_ACCOUNT } from '../http/error_schemas.js';
50
51
  import { read_json_body } from '../http/json_text.js';
51
52
  /** Hono context variable name for the request context. */
52
53
  export const REQUEST_CONTEXT_KEY = 'request_context';
@@ -144,9 +145,10 @@ export const has_any_scoped_role = (ctx, roles, scope_id, now = new Date()) => {
144
145
  * (from the request payload). Applies the uniform resolution rules:
145
146
  *
146
147
  * - `acting_actor_id` omitted + 1 actor → use it.
147
- * - `acting_actor_id` omitted + 0 actors → `no_actors` (defensive —
148
+ * - 0 actors → `no_actors` when the account is still live (defensive —
148
149
  * signup / bootstrap always create an actor in the same tx, so this
149
- * is a server error).
150
+ * is a server error), `account_removed` when it is tombstoned or gone:
151
+ * removed since its credential was read, its actors with it.
150
152
  * - `acting_actor_id` omitted + multiple actors → `actor_required` with
151
153
  * the available list so the client can prompt; never pick silently.
152
154
  * - `acting_actor_id` present + matches an actor on the account → use it.
@@ -154,6 +156,10 @@ export const has_any_scoped_role = (ctx, roles, scope_id, now = new Date()) => {
154
156
  * The available list is intentionally not echoed in this branch (treat
155
157
  * as opaque rejection).
156
158
  *
159
+ * The actor comes back as the row the account's actor list read, so the
160
+ * caller builds on it without reading it again — one read, as on the Rust
161
+ * spine, which leaves no window for the actor to vanish between two.
162
+ *
157
163
  * `acting_actor_id` is compared lowercased, the form actor ids are stored and
158
164
  * read back in, so a caller passing an id that skipped the `Uuid` schema
159
165
  * still matches its actor whatever its case.
@@ -164,11 +170,16 @@ export const has_any_scoped_role = (ctx, roles, scope_id, now = new Date()) => {
164
170
  */
165
171
  export const resolve_acting_actor = async (deps, account_id, acting_actor_id) => {
166
172
  const actors = await query_active_actors_by_account(deps, account_id);
167
- if (actors.length === 0)
168
- return { ok: false, reason: 'no_actors' };
173
+ if (actors.length === 0) {
174
+ // a live account with no actor, or one removed since its credential was
175
+ // read — one read, on this path alone, tells them apart
176
+ return (await query_account_by_id(deps, account_id))
177
+ ? { ok: false, reason: 'no_actors' }
178
+ : { ok: false, reason: 'account_removed' };
179
+ }
169
180
  if (acting_actor_id == null) {
170
181
  if (actors.length === 1)
171
- return { ok: true, actor_id: actors[0].id };
182
+ return { ok: true, actor: actors[0] };
172
183
  return {
173
184
  ok: false,
174
185
  reason: 'actor_required',
@@ -179,7 +190,7 @@ export const resolve_acting_actor = async (deps, account_id, acting_actor_id) =>
179
190
  const match = actors.find((a) => a.id === acting);
180
191
  if (!match)
181
192
  return { ok: false, reason: 'actor_not_on_account' };
182
- return { ok: true, actor_id: match.id };
193
+ return { ok: true, actor: match };
183
194
  };
184
195
  /**
185
196
  * Create middleware that authenticates the account from a session cookie —
@@ -234,7 +245,8 @@ export const create_request_context_middleware = (deps, options = {}) => {
234
245
  }
235
246
  // a tombstoned account authenticates nothing — its session resolves as
236
247
  // no credential, the anonymous caller, as on the Rust spine
237
- if (!(await query_account_by_id(deps, session.account_id))) {
248
+ const account = await query_account_by_id(deps, session.account_id);
249
+ if (!account) {
238
250
  await next();
239
251
  return;
240
252
  }
@@ -243,7 +255,7 @@ export const create_request_context_middleware = (deps, options = {}) => {
243
255
  const cookie_expires_at = c.get(SESSION_COOKIE_EXPIRES_AT_KEY) ?? null;
244
256
  c.set(RESOLVED_AUTH_KEY, {
245
257
  credential_type: 'session',
246
- account_id: session.account_id,
258
+ account,
247
259
  session_hash,
248
260
  credential_deadline: credential_deadline_after([
249
261
  cookie_expires_at === null ? null : cookie_expires_at * 1000 - Date.now(),
@@ -288,10 +300,10 @@ export const token_scope_surface_denial = (c, capability) => {
288
300
  return null;
289
301
  };
290
302
  /**
291
- * The account id a public route — one that answers anonymous callers and reads
292
- * the credential (`reads_credential`) — may act on: `null` for the anonymous
293
- * caller **and for a scope-narrowed API token**. Rule 3 in its
294
- * anonymous-admitting disposition — the downgrade the Rust
303
+ * The account a public route — one that answers anonymous callers and reads
304
+ * the credential (`reads_credential`) — may act on, as the credential leg read
305
+ * it: `null` for the anonymous caller **and for a scope-narrowed API token**.
306
+ * Rule 3 in its anonymous-admitting disposition — the downgrade the Rust
295
307
  * `AuthGate::public_request_context` applies.
296
308
  *
297
309
  * A narrowed token reaches no non-RPC surface that reads account data
@@ -307,15 +319,15 @@ export const token_scope_surface_denial = (c, capability) => {
307
319
  * the scope, so it reads the full credential.
308
320
  *
309
321
  * @param route - the handler's `RouteContext`, or anything carrying its `credential`
310
- * @returns the account id, or `null` for an anonymous caller or a narrowed token
322
+ * @returns the account the credential resolved, or `null` for an anonymous caller or a narrowed token
311
323
  */
312
- export const get_public_account_id = (route) => {
324
+ export const get_public_account = (route) => {
313
325
  const auth = route.credential;
314
326
  if (auth === null)
315
327
  return null;
316
328
  if (!token_scope_admits_non_rpc(resolved_auth_scope(auth)))
317
329
  return null;
318
- return auth.account_id;
330
+ return auth.account;
319
331
  };
320
332
  /**
321
333
  * Create middleware refusing a route to a credential whose scope does not admit
@@ -454,60 +466,29 @@ export const refresh_role_grants = async (ctx, deps) => {
454
466
  return { ...ctx, role_grants };
455
467
  };
456
468
  /**
457
- * Build a full `RequestContext` from an account id and an explicit
458
- * actor id (already resolved via `resolve_acting_actor`).
469
+ * Build an actor-bound `RequestContext` from the account the credential
470
+ * resolved and the actor `resolve_acting_actor` read off it, loading the
471
+ * actor's active role_grants.
459
472
  *
460
- * Loads `account` + the named `actor` + the actor's active role_grants.
461
- * Verifies the `actor.account_id === account.id` binding so downstream
462
- * handlers can trust `ctx.actor.account_id === ctx.account.id`. Returns
463
- * `null` when the account is missing, the actor is missing, or the
464
- * actor doesn't belong to the supplied account.
473
+ * Reads only the grants: the account is the credential leg's row
474
+ * (`ResolvedAuth.account`) and the actor the account's own actor list read,
475
+ * so neither is read twice in a request and there is no torn read between
476
+ * the reads — a delete landing after them is the handler's to meet, as on
477
+ * the Rust spine.
465
478
  *
466
- * Called by the route-spec / RPC dispatcher's authorization phase for
467
- * routes that need an acting actor; account-grain routes use
468
- * `build_account_context` instead.
479
+ * Called by the dispatcher's authorization phase for routes that need an
480
+ * acting actor; account-grain routes get `{account, actor: null,
481
+ * role_grants: []}` with no read at all.
469
482
  *
470
483
  * @param deps - query dependencies
471
- * @param account_id - the account to build context for
472
- * @param actor_id - the actor this request acts as
473
- * @returns a request context, or `null` if account/actor not found or mismatched
484
+ * @param account - the account the credential resolved
485
+ * @param actor - the acting actor, one of `account`'s active actors
486
+ * @returns the actor-bound request context
474
487
  */
475
- export const build_request_context = async (deps, account_id, actor_id) => {
476
- const account = await query_account_by_id(deps, account_id);
477
- if (!account)
478
- return null;
479
- const actor = await query_actor_by_id(deps, actor_id);
480
- if (!actor)
481
- return null;
482
- if (actor.account_id !== account.id)
483
- return null;
488
+ export const build_request_context = async (deps, account, actor) => {
484
489
  const role_grants = await query_role_grant_find_active_for_actor(deps, actor.id);
485
490
  return { account, actor, role_grants };
486
491
  };
487
- /**
488
- * Build an account-only `RequestContext` (no actor, no role_grants) from
489
- * an account id.
490
- *
491
- * Used by the dispatcher's authorization phase for authenticated routes
492
- * that don't need an acting actor — account-grain operations (logout,
493
- * password change, account self-service). Lets handlers read
494
- * `auth.account.id` / `auth.account.username` uniformly with role_grant-bound
495
- * routes; the cost is one extra `query_account_by_id` per request.
496
- *
497
- * Returns `null` when the account row is missing (e.g. deleted between
498
- * the auth middleware's session lookup and the dispatcher) — caller
499
- * surfaces that as a 500 since it represents a torn read.
500
- *
501
- * @param deps - query dependencies
502
- * @param account_id - the account to build context for
503
- * @returns an account-only request context, or `null` if the account is missing
504
- */
505
- export const build_account_context = async (deps, account_id) => {
506
- const account = await query_account_by_id(deps, account_id);
507
- if (!account)
508
- return null;
509
- return { account, actor: null, role_grants: [] };
510
- };
511
492
  /**
512
493
  * Apply the dispatcher's authorization phase against the flat-record
513
494
  * `RouteAuth` shape. Shared by the route-spec wrapper, the HTTP RPC
@@ -516,57 +497,57 @@ export const build_account_context = async (deps, account_id) => {
516
497
  * input validation 400.
517
498
  *
518
499
  * Pure data — the function does not touch a Hono context. Each transport
519
- * passes `account_id` (extracted from its own credential surface) and
500
+ * passes the account its credential resolved (`ResolvedAuth.account`) and
520
501
  * binds the returned `AuthorizationResult` to its wire shape. The REST
521
502
  * pipeline additionally writes `REQUEST_CONTEXT_KEY` on `c` for downstream
522
503
  * `require_role` / `require_credential_types` middleware that still reads
523
504
  * the resolved context off the Hono context.
524
505
  *
506
+ * The account is never read here: the context is built on the credential
507
+ * leg's row, so a request reads its account once, as on the Rust spine,
508
+ * whose `apply_authorization_phase` takes the resolved account the same way.
509
+ *
525
510
  * Branching by `auth.account` × `auth.actor`:
526
511
  *
527
512
  * - Both `'none'` → `{ok: true, request_context: null}`. Public actions
528
513
  * never see a `RequestContext`.
529
- * - `account_id == null` on any non-public route → same null
514
+ * - `account == null` on any non-public route → same null
530
515
  * `request_context`. The `'required'` callers were already rejected at
531
516
  * the pre-authorization gate in the dispatcher; only genuine anonymous
532
517
  * access on an `'optional'` axis lands here.
533
- * - `actor === 'none'` → builds account-only context via
534
- * `build_account_context`. Null lookup → `account_vanished` 500 failure.
518
+ * - `actor === 'none'` → an account-only context, `{account, actor: null,
519
+ * role_grants: []}`.
535
520
  * - `actor === 'required'` → resolves the actor from `acting_value` (or
536
- * single-actor account); failures map to 400 / 500.
521
+ * single-actor account); failures map to 400 / 401 / 500.
537
522
  * - `actor === 'optional'` → same as `'required'` except multi-actor
538
523
  * accounts without an `acting` value fall back to account-only context
539
524
  * (no `actor_required` 400). Bad `acting` ids still 400.
540
525
  *
541
- * 500 branches stay distinct: `ERROR_NO_ACTORS_ON_ACCOUNT` (signup
542
- * invariant violation), `ERROR_ACCOUNT_VANISHED` (torn read after
543
- * resolve).
526
+ * An account removed since the credential leg read it takes its actors with
527
+ * it: an actor-grain route then finds none, and answers the dead credential's
528
+ * 401 `ERROR_AUTHENTICATION_REQUIRED`, as a request that arrived after the
529
+ * removal does. The one 500 is `ERROR_NO_ACTORS_ON_ACCOUNT`: a live account
530
+ * with no active actor, a signup invariant violation.
544
531
  */
545
- export const apply_authorization_phase = async (deps, account_id, auth, acting_value) => {
532
+ export const apply_authorization_phase = async (deps, account, auth, acting_value) => {
546
533
  if (is_public_auth(auth))
547
534
  return { ok: true, request_context: null };
548
- if (account_id == null) {
535
+ if (account === null) {
549
536
  // Optional-auth route hit without a credential — leave `RequestContext`
550
537
  // null so the handler can branch on it. `'required'` callers already
551
538
  // got rejected at the pre-authorization gate.
552
539
  return { ok: true, request_context: null };
553
540
  }
554
541
  if (!needs_actor(auth)) {
555
- const ctx = await build_account_context(deps, account_id);
556
- if (!ctx)
557
- return { ok: false, status: 500, body: { error: ERROR_ACCOUNT_VANISHED } };
558
- return { ok: true, request_context: ctx };
542
+ return { ok: true, request_context: { account, actor: null, role_grants: [] } };
559
543
  }
560
544
  // actor 'required' or 'optional' — resolve.
561
- const acting = await resolve_acting_actor(deps, account_id, acting_value);
545
+ const acting = await resolve_acting_actor(deps, account.id, acting_value);
562
546
  if (!acting.ok) {
563
547
  if (acting.reason === 'actor_required') {
564
548
  if (auth.actor === 'optional') {
565
549
  // Multi-actor account, no pick — fall back to account-only context.
566
- const ctx = await build_account_context(deps, account_id);
567
- if (!ctx)
568
- return { ok: false, status: 500, body: { error: ERROR_ACCOUNT_VANISHED } };
569
- return { ok: true, request_context: ctx };
550
+ return { ok: true, request_context: { account, actor: null, role_grants: [] } };
570
551
  }
571
552
  return {
572
553
  ok: false,
@@ -577,12 +558,12 @@ export const apply_authorization_phase = async (deps, account_id, auth, acting_v
577
558
  if (acting.reason === 'actor_not_on_account') {
578
559
  return { ok: false, status: 400, body: { error: ERROR_ACTOR_NOT_ON_ACCOUNT } };
579
560
  }
561
+ if (acting.reason === 'account_removed') {
562
+ return { ok: false, status: 401, body: { error: ERROR_AUTHENTICATION_REQUIRED } };
563
+ }
580
564
  return { ok: false, status: 500, body: { error: ERROR_NO_ACTORS_ON_ACCOUNT } };
581
565
  }
582
- const ctx = await build_request_context(deps, account_id, acting.actor_id);
583
- if (!ctx)
584
- return { ok: false, status: 500, body: { error: ERROR_ACCOUNT_VANISHED } };
585
- return { ok: true, request_context: ctx };
566
+ return { ok: true, request_context: await build_request_context(deps, account, acting.actor) };
586
567
  };
587
568
  /**
588
569
  * Run the authorization phase on a Hono request: resolve the acting actor from
@@ -606,16 +587,17 @@ export const apply_authorization_phase = async (deps, account_id, auth, acting_v
606
587
  * @param deps - query deps for actor resolution
607
588
  * @param auth - the route's auth shape
608
589
  * @param acting - the `acting` selector, already through `parse_acting`; `undefined` when absent
609
- * @returns the refusal to answer (`400` actor selection, `500` a vanished
610
- * account), or nothing when the request may proceed
590
+ * @returns the refusal to answer (`400` actor selection, `401` an account
591
+ * removed since its credential was read, `500` a live account with no active
592
+ * actor), or nothing when the request may proceed
611
593
  */
612
594
  export const run_authorization_phase = async (c, deps, auth, acting) => {
613
595
  if (has_test_context_preset(c))
614
596
  return;
615
597
  if (is_public_auth(auth))
616
598
  return;
617
- const account_id = get_resolved_auth(c)?.account_id ?? null;
618
- const result = await apply_authorization_phase(deps, account_id, auth, acting);
599
+ const account = get_resolved_auth(c)?.account ?? null;
600
+ const result = await apply_authorization_phase(deps, account, auth, acting);
619
601
  if (!result.ok)
620
602
  return c.json(result.body, result.status);
621
603
  if (result.request_context !== null) {
@@ -15,17 +15,22 @@
15
15
  */
16
16
  import type { Context } from 'hono';
17
17
  import type { QueryDeps } from '../db/query_deps.js';
18
+ import type { Account } from './account_schema.js';
18
19
  import { type RequestContext } from './request_context.js';
19
20
  import { type TokenScope } from './token_scope.js';
20
21
  /** The fields every resolved credential carries. */
21
22
  interface ResolvedAuthBase {
22
23
  /**
23
- * The authenticated account. Its id, not its row — the twin of the Rust
24
- * spine's `ResolvedAuth::account`, which loads the row as it resolves. Here
25
- * the middleware stays one query per credential and the authorization phase
26
- * loads the account when a route needs it.
24
+ * The authenticated account, as the credential leg read it — live, not
25
+ * tombstoned. The authorization phase builds its request context on this
26
+ * row rather than reading the account again, so a request reads its account
27
+ * once, and an account removed after the leg is no torn read. On a
28
+ * long-lived connection it is the row read at the upgrade: a revocation
29
+ * closes the connection after its commit, and a re-read would race the
30
+ * revocation the same way. The twin of the Rust spine's
31
+ * `ResolvedAuth::account`.
27
32
  */
28
- readonly account_id: string;
33
+ readonly account: Account;
29
34
  /**
30
35
  * When the credential stops authenticating, as a monotonic
31
36
  * `performance.now()` timestamp — the moment a long-lived connection opened
@@ -1 +1 @@
1
- {"version":3,"file":"resolved_auth.d.ts","sourceRoot":"","sources":["../../src/lib/auth/resolved_auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAIrD,OAAO,EAGN,KAAK,cAAc,EACnB,MAAM,sBAAsB,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AC;AAEF;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAC3B,UAAU,GAAG,oBAAoB,GAAG,gBAAgB,GAAG,cAAc,CAAC;AAEvE,8DAA8D;AAC9D,MAAM,WAAW,qBAAqB;IACrC,2EAA2E;IAC3E,QAAQ,EAAE,YAAY,CAAC;IACvB,yFAAyF;IACzF,eAAe,EAAE,cAAc,CAAC;IAChC;;;OAGG;IACH,cAAc,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CACtC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,iBAAiB,GAC7B,MAAM,SAAS,EACf,OAAO,qBAAqB,KAC1B,OAAO,CAAC,gBAAgB,CAa1B,CAAC"}
@@ -110,7 +110,7 @@ export const get_resolved_auth = (c) => c.get(RESOLVED_AUTH_KEY) ?? null;
110
110
  * unchecked credential is not a valid one.
111
111
  */
112
112
  export const revalidate_resolved_auth = async (deps, resolved) => {
113
- const { account_id } = resolved;
113
+ const account_id = resolved.account.id;
114
114
  let credential_is_live;
115
115
  switch (resolved.credential_type) {
116
116
  case 'session': {
@@ -163,7 +163,7 @@ export const recheck_admission = async (deps, input) => {
163
163
  return 'credential_revoked';
164
164
  const acting_actor = request_context.actor;
165
165
  if (acting_actor) {
166
- const active = await query_active_actors_by_account(deps, resolved.account_id);
166
+ const active = await query_active_actors_by_account(deps, resolved.account.id);
167
167
  if (!active.some((a) => a.id === acting_actor.id))
168
168
  return 'actor_inactive';
169
169
  }
@@ -465,7 +465,7 @@ export declare const role_grant_offer_accept_action_spec: {
465
465
  }>;
466
466
  async: true;
467
467
  description: string;
468
- error_reasons: ("role_grant_offer_terminal" | "role_grant_offer_expired" | "role_grant_offer_not_found" | "role_grant_offer_role_not_grantable" | "role_grant_offer_not_authorized" | "role_grant_offer_actor_mismatch" | "role_grant_builtin_scoped")[];
468
+ error_reasons: ("role_grant_offer_terminal" | "role_grant_offer_expired" | "role_grant_offer_not_found" | "role_grant_offer_role_not_grantable" | "role_grant_offer_not_authorized" | "role_grant_offer_actor_mismatch" | "role_grant_builtin_scoped" | "authentication_required")[];
469
469
  rate_limit: "account";
470
470
  };
471
471
  export declare const role_grant_offer_decline_action_spec: {
@@ -1 +1 @@
1
- {"version":3,"file":"role_grant_offer_action_specs.d.ts","sourceRoot":"","sources":["../../src/lib/auth/role_grant_offer_action_specs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,EAcN,KAAK,KAAK,EACV,MAAM,8BAA8B,CAAC;AAGtC,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAkB3E,oEAAoE;AACpE,eAAO,MAAM,kCAAkC,EAAG,8BAAuC,CAAC;AAC1F,kEAAkE;AAClE,eAAO,MAAM,+BAA+B,EAAG,2BAAoC,CAAC;AACpF,sDAAsD;AACtD,eAAO,MAAM,8BAA8B,EAAG,0BAAmC,CAAC;AAClF,wGAAwG;AACxG,eAAO,MAAM,gCAAgC,EAAG,4BAAqC,CAAC;AACtF,uIAAuI;AACvI,eAAO,MAAM,yCAAyC,EACrD,qCAA8C,CAAC;AAChD,gKAAgK;AAChK,eAAO,MAAM,qCAAqC,EAAG,iCAA0C,CAAC;AAChG,6FAA6F;AAC7F,eAAO,MAAM,qCAAqC,EAAG,iCAA0C,CAAC;AAChG,wHAAwH;AACxH,eAAO,MAAM,6CAA6C,EACzD,yCAAkD,CAAC;AACpD;;;;GAIG;AACH,eAAO,MAAM,+BAA+B,EAAG,2BAAoC,CAAC;AACpF;;;;;;GAMG;AACH,eAAO,MAAM,gCAAgC,EAAG,4BAAqC,CAAC;AACtF;;;;;;GAMG;AACH,eAAO,MAAM,8BAA8B,EAAG,0BAAmC,CAAC;AAElF;;;;;;;;;GASG;AACH,eAAO,MAAM,qBAAqB,GAAI,OAAO;IAC5C,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,GAAG,IAA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;;;;;;;;;;;CAmBL,CAAC;AAEtC;;;;GAIG;AACH,eAAO,MAAM,iCAAiC,EAAE,KAAK,CAAC,yBAAyB,CAS9E,CAAC"}
@@ -312,7 +312,8 @@ export const role_grant_offer_accept_action_spec = {
312
312
  ERROR_ROLE_GRANT_OFFER_ACTOR_MISMATCH,
313
313
  ERROR_ROLE_GRANT_OFFER_ROLE_NOT_GRANTABLE,
314
314
  ERROR_ROLE_GRANT_BUILTIN_SCOPED,
315
- ERROR_ROLE_GRANT_OFFER_NOT_AUTHORIZED
315
+ ERROR_ROLE_GRANT_OFFER_NOT_AUTHORIZED,
316
+ ERROR_AUTHENTICATION_REQUIRED
316
317
  ],
317
318
  rate_limit: 'account'
318
319
  };
@@ -44,13 +44,12 @@
44
44
  * transaction, a failure row on the pool). `audit.notify` (SSE/WS broadcast)
45
45
  * fires post-commit in both paths.
46
46
  *
47
- * WS notifications fan out post-commit via `emit_after_commit` when a
48
- * `notification_sender` is wired: offer lifecycle transitions notify the
47
+ * WS notifications go through the handler context's sender
48
+ * (`ctx.notification_sender`), queued post-commit (`queue_offer_notification`,
49
+ * `queue_supersede_notifications`): offer lifecycle transitions notify the
49
50
  * counterparty, `role_grant_revoke` notifies the revokee (`role_grant_revoked`)
50
- * plus each superseded
51
- * pending offer's grantor. Under DEV each notification's params are checked
52
- * against its spec's schema before it is sent, a mismatch logged
53
- * (`create_validated_notification_sender`). `role_grant_revoke` of a global
51
+ * plus both parties of each superseded pending offer, and an accept each
52
+ * superseded sibling's grantor. `role_grant_revoke` of a global
54
53
  * grant also closes the revokee's connections gated on the role through
55
54
  * `deps.connection_closer`, after the commit.
56
55
  *
@@ -61,7 +60,6 @@ import { type ActionContext, type RpcAction } from '../actions/action_types.js';
61
60
  import { type RoleRegistry } from './role_schema.js';
62
61
  import { type RequestContext } from './request_context.js';
63
62
  import type { RevokingActionFactoryDeps } from './deps.js';
64
- import { type NotificationSender } from './role_grant_offer_notifications.js';
65
63
  /**
66
64
  * Authorization callback for `role_grant_offer_create` and `role_grant_assign`.
67
65
  * Returns `true` to allow, `false` to reject (handler converts to `forbidden`
@@ -115,11 +113,9 @@ export interface RoleGrantOfferActionOptions {
115
113
  * Create the role-grant-offer RPC actions: the offer-lifecycle methods plus
116
114
  * `role_grant_revoke` and the immediate `role_grant_assign`.
117
115
  *
118
- * @param deps - `RevokingActionFactoryDeps` (`log`, `audit`, and the `connection_closer` a revoked global grant closes the revokee's role-gated connections through) plus optional `notification_sender` for WS fan-out — when absent, WS fan-out is silently skipped (DB-only side effects still happen). Consumers wiring `ConnectionRegistry` assign its instance directly (the registry's `send_to_account` signature accepts the broader `JsonrpcMessageFromServerToClient`, which is contravariantly compatible)
116
+ * @param deps - `RevokingActionFactoryDeps`: `log`, `audit`, and the `connection_closer` a revoked global grant closes the revokee's role-gated connections through. WS notifications go through the handler context's `notification_sender`, not a dep
119
117
  * @param options - role registry, default TTL, authorization override
120
118
  * @returns the `RpcAction` array to spread into a `create_rpc_endpoint` call
121
119
  */
122
- export declare const create_role_grant_offer_actions: (deps: RevokingActionFactoryDeps & {
123
- notification_sender?: NotificationSender | null;
124
- }, options?: RoleGrantOfferActionOptions) => Array<RpcAction>;
120
+ export declare const create_role_grant_offer_actions: (deps: RevokingActionFactoryDeps, options?: RoleGrantOfferActionOptions) => Array<RpcAction>;
125
121
  //# sourceMappingURL=role_grant_offer_actions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"role_grant_offer_actions.d.ts","sourceRoot":"","sources":["../../src/lib/auth/role_grant_offer_actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,EAGN,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,MAAM,4BAA4B,CAAC;AAIpC,OAAO,EAMN,KAAK,YAAY,EACjB,MAAM,kBAAkB,CA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