@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.
- package/dist/actions/CLAUDE.md +24 -6
- package/dist/actions/action_rpc.d.ts +11 -1
- package/dist/actions/action_rpc.d.ts.map +1 -1
- package/dist/actions/action_rpc.js +3 -2
- package/dist/actions/action_types.d.ts +16 -1
- package/dist/actions/action_types.d.ts.map +1 -1
- package/dist/actions/action_types.js +1 -1
- package/dist/actions/notification_sender.d.ts +83 -0
- package/dist/actions/notification_sender.d.ts.map +1 -0
- package/dist/actions/notification_sender.js +85 -0
- package/dist/actions/perform_action.d.ts +9 -0
- package/dist/actions/perform_action.d.ts.map +1 -1
- package/dist/actions/perform_action.js +22 -13
- package/dist/actions/register_action_ws.d.ts +14 -0
- package/dist/actions/register_action_ws.d.ts.map +1 -1
- package/dist/actions/register_action_ws.js +3 -2
- package/dist/actions/ws_socket_session.d.ts +3 -0
- package/dist/actions/ws_socket_session.d.ts.map +1 -1
- package/dist/actions/ws_socket_session.js +2 -1
- package/dist/auth/CLAUDE.md +60 -41
- package/dist/auth/account_actions.d.ts.map +1 -1
- package/dist/auth/account_actions.js +13 -3
- package/dist/auth/account_queries.d.ts +158 -16
- package/dist/auth/account_queries.d.ts.map +1 -1
- package/dist/auth/account_queries.js +189 -18
- package/dist/auth/account_routes.d.ts +1 -1
- package/dist/auth/account_routes.d.ts.map +1 -1
- package/dist/auth/account_routes.js +27 -26
- package/dist/auth/admin_actions.d.ts.map +1 -1
- package/dist/auth/admin_actions.js +71 -28
- package/dist/auth/api_token_queries.d.ts +13 -5
- package/dist/auth/api_token_queries.d.ts.map +1 -1
- package/dist/auth/api_token_queries.js +24 -9
- package/dist/auth/bearer_auth.d.ts.map +1 -1
- package/dist/auth/bearer_auth.js +3 -2
- package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
- package/dist/auth/daemon_token_middleware.js +12 -1
- package/dist/auth/deps.d.ts +10 -0
- package/dist/auth/deps.d.ts.map +1 -1
- package/dist/auth/request_context.d.ts +73 -73
- package/dist/auth/request_context.d.ts.map +1 -1
- package/dist/auth/request_context.js +78 -96
- package/dist/auth/resolved_auth.d.ts +10 -5
- package/dist/auth/resolved_auth.d.ts.map +1 -1
- package/dist/auth/resolved_auth.js +2 -2
- package/dist/auth/role_grant_offer_action_specs.d.ts +1 -1
- package/dist/auth/role_grant_offer_action_specs.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_action_specs.js +2 -1
- package/dist/auth/role_grant_offer_actions.d.ts +7 -11
- package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_actions.js +61 -93
- package/dist/auth/role_grant_offer_notifications.d.ts +87 -38
- package/dist/auth/role_grant_offer_notifications.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_notifications.js +75 -22
- package/dist/auth/role_grant_offer_queries.d.ts +96 -15
- package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_queries.js +185 -70
- package/dist/auth/role_grant_offer_schema.js +1 -1
- package/dist/auth/role_grant_queries.d.ts +52 -12
- package/dist/auth/role_grant_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_queries.js +75 -24
- package/dist/auth/role_grant_sql.d.ts +21 -0
- package/dist/auth/role_grant_sql.d.ts.map +1 -1
- package/dist/auth/role_grant_sql.js +21 -0
- package/dist/auth/self_service_role_actions.d.ts.map +1 -1
- package/dist/auth/self_service_role_actions.js +9 -2
- package/dist/auth/session_queries.d.ts +34 -13
- package/dist/auth/session_queries.d.ts.map +1 -1
- package/dist/auth/session_queries.js +48 -18
- package/dist/auth/standard_rpc_actions.d.ts +6 -19
- package/dist/auth/standard_rpc_actions.d.ts.map +1 -1
- package/dist/auth/standard_rpc_actions.js +5 -6
- package/dist/auth/token_scope.d.ts +1 -1
- package/dist/auth/token_scope.js +1 -1
- package/dist/http/CLAUDE.md +7 -6
- package/dist/http/auth_shape.d.ts +1 -1
- package/dist/http/error_schemas.d.ts +9 -21
- package/dist/http/error_schemas.d.ts.map +1 -1
- package/dist/http/error_schemas.js +14 -24
- package/dist/http/route_spec.d.ts +2 -2
- package/dist/server/app_backend.d.ts.map +1 -1
- package/dist/server/app_backend.js +3 -1
- package/dist/server/app_server.d.ts +26 -16
- package/dist/server/app_server.d.ts.map +1 -1
- package/dist/server/app_server.js +17 -7
- package/dist/server/serve_fact_route.d.ts +3 -3
- package/dist/server/serve_fact_route.js +12 -12
- package/dist/testing/CLAUDE.md +5 -5
- package/dist/testing/app_server.d.ts.map +1 -1
- package/dist/testing/app_server.js +3 -1
- package/dist/testing/auth_apps.js +1 -1
- package/dist/testing/cross_backend/account_lifecycle.d.ts.map +1 -1
- package/dist/testing/cross_backend/account_lifecycle.js +43 -0
- package/dist/testing/cross_backend/default_spine_surface.d.ts +1 -26
- package/dist/testing/cross_backend/default_spine_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/default_spine_surface.js +2 -6
- package/dist/testing/cross_backend/full_spine_mount.d.ts +3 -10
- package/dist/testing/cross_backend/full_spine_mount.d.ts.map +1 -1
- package/dist/testing/cross_backend/full_spine_mount.js +4 -4
- package/dist/testing/cross_backend/role_grant_offer_notification_ws.d.ts +5 -4
- package/dist/testing/cross_backend/role_grant_offer_notification_ws.d.ts.map +1 -1
- package/dist/testing/cross_backend/role_grant_offer_notification_ws.js +183 -30
- package/dist/testing/cross_backend/session_cap.d.ts.map +1 -1
- package/dist/testing/cross_backend/session_cap.js +26 -5
- package/dist/testing/middleware.d.ts +1 -1
- package/dist/testing/middleware.js +5 -5
- package/dist/testing/resolved_auth.d.ts +3 -1
- package/dist/testing/resolved_auth.d.ts.map +1 -1
- package/dist/testing/resolved_auth.js +4 -4
- package/dist/testing/stubs.d.ts.map +1 -1
- package/dist/testing/stubs.js +5 -2
- package/dist/testing/ws_round_trip.d.ts.map +1 -1
- package/dist/testing/ws_round_trip.js +8 -4
- package/package.json +1 -1
|
@@ -147,11 +147,20 @@ export const query_session_revoke_for_account = async (deps, token_hash, account
|
|
|
147
147
|
/**
|
|
148
148
|
* Revoke all sessions for an account.
|
|
149
149
|
*
|
|
150
|
+
* Locks its rows in id order before it deletes them (`ORDER BY id FOR
|
|
151
|
+
* UPDATE`), as every multi-row delete of `auth_session` rows does — the cap's
|
|
152
|
+
* eviction, the expiry sweep, the revoke-all — so two of them reaching the
|
|
153
|
+
* same rows wait one on the other instead of deadlocking in the opposite
|
|
154
|
+
* orders their plans would otherwise walk. Twin of the Rust
|
|
155
|
+
* `fuz_auth::query_session_revoke_all_for_account`.
|
|
156
|
+
*
|
|
150
157
|
* @returns the number of sessions revoked
|
|
151
158
|
* @mutates `auth_session` table - deletes every row for `account_id`
|
|
152
159
|
*/
|
|
153
160
|
export const query_session_revoke_all_for_account = async (deps, account_id) => {
|
|
154
|
-
const rows = await deps.db.query(`DELETE FROM auth_session
|
|
161
|
+
const rows = await deps.db.query(`DELETE FROM auth_session
|
|
162
|
+
WHERE id IN (SELECT id FROM auth_session WHERE account_id = $1 ORDER BY id FOR UPDATE)
|
|
163
|
+
RETURNING id`, [account_id]);
|
|
155
164
|
return rows.length;
|
|
156
165
|
};
|
|
157
166
|
/**
|
|
@@ -166,21 +175,21 @@ export const query_session_list_for_account = async (deps, account_id, limit = 5
|
|
|
166
175
|
* Keeps the newest `max_sessions` sessions and deletes the rest.
|
|
167
176
|
*
|
|
168
177
|
* Race safety: this function must run inside a transaction alongside the
|
|
169
|
-
* INSERT that created the new session.
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
* - `POST /login`, `POST /bootstrap` and `POST /signup` manage their own
|
|
173
|
-
* transactions and pass the transaction-scoped `deps` to
|
|
174
|
-
* `create_capped_session`
|
|
178
|
+
* INSERT that created the new session. Its one caller is
|
|
179
|
+
* `create_capped_session`, which `POST /login`, `POST /bootstrap` and
|
|
180
|
+
* `POST /signup` each run in a transaction of their own.
|
|
175
181
|
*
|
|
176
182
|
* The transaction makes one creator's INSERT + enforce_limit pair atomic, but it
|
|
177
183
|
* does **not** serialize concurrent creators. Under Read Committed, two
|
|
178
184
|
* transactions can't see each other's uncommitted session row, so each computes
|
|
179
185
|
* its `OFFSET` eviction against a stale count, each preserves its own row, and
|
|
180
|
-
* both commit above `max_sessions
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
186
|
+
* both commit above `max_sessions` — and their two `DELETE`s lock the same old
|
|
187
|
+
* rows in orders the plan picks, so they can deadlock. A transaction is
|
|
188
|
+
* necessary here but not sufficient: a creator for an existing account first
|
|
189
|
+
* takes its account row `FOR NO KEY UPDATE` (`query_account_lock_verified`),
|
|
190
|
+
* which makes the creators of one account take turns, each counting the rows
|
|
191
|
+
* the one before committed. A creator for an account its own transaction just
|
|
192
|
+
* made needs none — no other can reach the account.
|
|
184
193
|
*
|
|
185
194
|
* Ordering is `created_at DESC, id DESC`. The `id` leg is a **stability**
|
|
186
195
|
* tie-breaker, not a recency one: `created_at` defaults to `NOW()`, the
|
|
@@ -189,11 +198,17 @@ export const query_session_list_for_account = async (deps, account_id, limit = 5
|
|
|
189
198
|
* `OFFSET` may keep a different set on two evaluations of the same rows. `id` is
|
|
190
199
|
* the blake3 token hash, so the tie-break is arbitrary but deterministic; it
|
|
191
200
|
* makes the survivors reproducible, it does not make the row just inserted a
|
|
192
|
-
* guaranteed survivor. Only the
|
|
201
|
+
* guaranteed survivor. Only the account lock above does that.
|
|
193
202
|
*
|
|
194
203
|
* Expired-but-unreaped rows count toward the cap (the predicate is `account_id`
|
|
195
204
|
* alone). Matches the Rust twin `query_session_enforce_limit`.
|
|
196
205
|
*
|
|
206
|
+
* The victims are locked in id order before the delete (`ORDER BY id FOR
|
|
207
|
+
* UPDATE`), as every multi-row delete of `auth_session` rows locks them: a
|
|
208
|
+
* revoke-all or the expiry sweep reaching the same rows waits on the eviction,
|
|
209
|
+
* or the eviction on it, instead of the two deadlocking in whatever orders
|
|
210
|
+
* their plans walk (`query_session_revoke_all_for_account`).
|
|
211
|
+
*
|
|
197
212
|
* Deleting a session row does not end the connections it opened: a WebSocket
|
|
198
213
|
* keeps the authority it resolved at upgrade and an SSE stream never rechecks.
|
|
199
214
|
* The returned ids are the token hashes those connections are registered
|
|
@@ -210,9 +225,14 @@ export const query_session_enforce_limit = async (deps, account_id, max_sessions
|
|
|
210
225
|
const rows = await deps.db.query(`DELETE FROM auth_session
|
|
211
226
|
WHERE id IN (
|
|
212
227
|
SELECT id FROM auth_session
|
|
213
|
-
WHERE
|
|
214
|
-
|
|
215
|
-
|
|
228
|
+
WHERE id IN (
|
|
229
|
+
SELECT id FROM auth_session
|
|
230
|
+
WHERE account_id = $1
|
|
231
|
+
ORDER BY created_at DESC, id DESC
|
|
232
|
+
OFFSET $2
|
|
233
|
+
)
|
|
234
|
+
ORDER BY id
|
|
235
|
+
FOR UPDATE
|
|
216
236
|
) RETURNING id`, [account_id, max_sessions]);
|
|
217
237
|
return rows.map((row) => row.id);
|
|
218
238
|
};
|
|
@@ -252,15 +272,19 @@ export const query_session_list_all_active = async (deps, limit = 200) => {
|
|
|
252
272
|
* a concurrent pass gets a disjoint set. Run it in a transaction, as the
|
|
253
273
|
* caller above does, so the ids are in hand before the delete commits — on a
|
|
254
274
|
* pool-level `Db` a connection lost on the response leaves the rows deleted
|
|
255
|
-
* and their ids unread. Served by `idx_auth_session_expires`.
|
|
256
|
-
*
|
|
275
|
+
* and their ids unread. Served by `idx_auth_session_expires`. The rows are
|
|
276
|
+
* locked in id order before the delete, as every multi-row delete of
|
|
277
|
+
* `auth_session` rows locks them (`query_session_revoke_all_for_account`). Twin
|
|
278
|
+
* of the Rust `query_session_cleanup_expired`.
|
|
257
279
|
*
|
|
258
280
|
* @param deps - query dependencies (transaction-scoped, see above)
|
|
259
281
|
* @returns the deleted sessions' ids (their token hashes), empty when nothing had expired
|
|
260
282
|
* @mutates `auth_session` table - deletes every row past `expires_at`
|
|
261
283
|
*/
|
|
262
284
|
export const query_session_cleanup_expired = async (deps) => {
|
|
263
|
-
const rows = await deps.db.query(`DELETE FROM auth_session
|
|
285
|
+
const rows = await deps.db.query(`DELETE FROM auth_session
|
|
286
|
+
WHERE id IN (SELECT id FROM auth_session WHERE expires_at <= NOW() ORDER BY id FOR UPDATE)
|
|
287
|
+
RETURNING id`);
|
|
264
288
|
return rows.map((row) => row.id);
|
|
265
289
|
};
|
|
266
290
|
/**
|
|
@@ -276,6 +300,12 @@ export const query_session_cleanup_expired = async (deps) => {
|
|
|
276
300
|
* `session` target, as `POST /login` does. A caller that mints for an account
|
|
277
301
|
* created in the same transaction (signup, bootstrap) evicts nothing.
|
|
278
302
|
*
|
|
303
|
+
* A caller minting for an existing account first takes its row lock in the
|
|
304
|
+
* same transaction (`query_account_lock_verified`) and refuses on `false`: a
|
|
305
|
+
* password change or a delete in flight is ordered against the mint, and the
|
|
306
|
+
* account's mints take turns, which the cap counts on
|
|
307
|
+
* (`query_session_enforce_limit`).
|
|
308
|
+
*
|
|
279
309
|
* @returns the signed cookie value and the evicted sessions' token hashes
|
|
280
310
|
* @mutates `auth_session` table - inserts the new session row (and evicts older rows when `max_sessions` is set)
|
|
281
311
|
*/
|
|
@@ -9,11 +9,10 @@
|
|
|
9
9
|
*
|
|
10
10
|
* Option routing: shared `roles` flows to both admin and role-grant-offer;
|
|
11
11
|
* `default_ttl_ms` and `authorize` go to role-grant-offer only; `max_tokens`
|
|
12
|
-
* goes to account only
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* it.
|
|
12
|
+
* goes to account only. `deps.connection_closer` is read by admin, account,
|
|
13
|
+
* and role-grant-offer, whose revocation handlers close live connections
|
|
14
|
+
* through it. WS notifications go through each handler context's
|
|
15
|
+
* `notification_sender`, which the dispatcher supplies.
|
|
17
16
|
*
|
|
18
17
|
* Paired with `create_admin_rpc_adapters` on the UI side.
|
|
19
18
|
*
|
|
@@ -23,7 +22,6 @@ import { type AdminActionOptions } from './admin_actions.js';
|
|
|
23
22
|
import { type RoleGrantOfferActionOptions } from './role_grant_offer_actions.js';
|
|
24
23
|
import { type AccountActionOptions } from './account_actions.js';
|
|
25
24
|
import type { RevokingActionFactoryDeps } from './deps.js';
|
|
26
|
-
import type { NotificationSender } from './role_grant_offer_notifications.js';
|
|
27
25
|
import type { RpcAction } from '../actions/action_types.js';
|
|
28
26
|
/**
|
|
29
27
|
* Options for `create_standard_rpc_actions`.
|
|
@@ -36,17 +34,6 @@ import type { RpcAction } from '../actions/action_types.js';
|
|
|
36
34
|
*/
|
|
37
35
|
export interface StandardRpcActionsOptions extends AdminActionOptions, RoleGrantOfferActionOptions, AccountActionOptions {
|
|
38
36
|
}
|
|
39
|
-
/**
|
|
40
|
-
* Dependencies for `create_standard_rpc_actions`.
|
|
41
|
-
*
|
|
42
|
-
* Stack-standard `RevokingActionFactoryDeps` (`log`, `audit`,
|
|
43
|
-
* `connection_closer`) plus an optional `notification_sender` consumed only by the
|
|
44
|
-
* role-grant-offer sub-factory for WS fan-out. Admin and account
|
|
45
|
-
* sub-factories ignore `notification_sender`.
|
|
46
|
-
*/
|
|
47
|
-
export interface StandardRpcActionsDeps extends RevokingActionFactoryDeps {
|
|
48
|
-
notification_sender?: NotificationSender | null;
|
|
49
|
-
}
|
|
50
37
|
/**
|
|
51
38
|
* Build the combined admin + role-grant-offer + account RPC action set.
|
|
52
39
|
*
|
|
@@ -55,9 +42,9 @@ export interface StandardRpcActionsDeps extends RevokingActionFactoryDeps {
|
|
|
55
42
|
* and `create_account_actions(deps, {max_tokens})`. The shared `roles`
|
|
56
43
|
* option flows to admin + role-grant-offer.
|
|
57
44
|
*
|
|
58
|
-
* @param deps - `
|
|
45
|
+
* @param deps - `RevokingActionFactoryDeps`: `log`, `audit`, `connection_closer`
|
|
59
46
|
* @param options - role registry, role-grant-offer config, account config
|
|
60
47
|
* @returns RPC actions to pass as `rpc_endpoints` or spread into `create_rpc_endpoint`
|
|
61
48
|
*/
|
|
62
|
-
export declare const create_standard_rpc_actions: (deps:
|
|
49
|
+
export declare const create_standard_rpc_actions: (deps: RevokingActionFactoryDeps, options?: StandardRpcActionsOptions) => Array<RpcAction>;
|
|
63
50
|
//# sourceMappingURL=standard_rpc_actions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standard_rpc_actions.d.ts","sourceRoot":"","sources":["../../src/lib/auth/standard_rpc_actions.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"standard_rpc_actions.d.ts","sourceRoot":"","sources":["../../src/lib/auth/standard_rpc_actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAwB,KAAK,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACnF,OAAO,EAEN,KAAK,2BAA2B,EAChC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAA0B,KAAK,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACzF,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAE5D;;;;;;;;GAQG;AACH,MAAM,WAAW,yBAChB,SAAQ,kBAAkB,EAAE,2BAA2B,EAAE,oBAAoB;CAAG;AAEjF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,2BAA2B,GACvC,MAAM,yBAAyB,EAC/B,UAAS,yBAA8B,KACrC,KAAK,CAAC,SAAS,CAIjB,CAAC"}
|
|
@@ -9,11 +9,10 @@
|
|
|
9
9
|
*
|
|
10
10
|
* Option routing: shared `roles` flows to both admin and role-grant-offer;
|
|
11
11
|
* `default_ttl_ms` and `authorize` go to role-grant-offer only; `max_tokens`
|
|
12
|
-
* goes to account only
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* it.
|
|
12
|
+
* goes to account only. `deps.connection_closer` is read by admin, account,
|
|
13
|
+
* and role-grant-offer, whose revocation handlers close live connections
|
|
14
|
+
* through it. WS notifications go through each handler context's
|
|
15
|
+
* `notification_sender`, which the dispatcher supplies.
|
|
17
16
|
*
|
|
18
17
|
* Paired with `create_admin_rpc_adapters` on the UI side.
|
|
19
18
|
*
|
|
@@ -30,7 +29,7 @@ import { create_account_actions } from './account_actions.js';
|
|
|
30
29
|
* and `create_account_actions(deps, {max_tokens})`. The shared `roles`
|
|
31
30
|
* option flows to admin + role-grant-offer.
|
|
32
31
|
*
|
|
33
|
-
* @param deps - `
|
|
32
|
+
* @param deps - `RevokingActionFactoryDeps`: `log`, `audit`, `connection_closer`
|
|
34
33
|
* @param options - role registry, role-grant-offer config, account config
|
|
35
34
|
* @returns RPC actions to pass as `rpc_endpoints` or spread into `create_rpc_endpoint`
|
|
36
35
|
*/
|
|
@@ -115,7 +115,7 @@ export declare const token_scope_admits_method: (scope: TokenScope, method: stri
|
|
|
115
115
|
* so it fits in one sentence a user can hold — *a scoped token is RPC-only*.
|
|
116
116
|
* Placement is per site: a route that refuses anonymous callers declares
|
|
117
117
|
* `auth.required_scope`, one that answers them reads the credential through
|
|
118
|
-
* `
|
|
118
|
+
* `get_public_account` and answers a narrowed token as anonymous, and the
|
|
119
119
|
* surface census pins every site.
|
|
120
120
|
*/
|
|
121
121
|
export declare const token_scope_admits_non_rpc: (scope: TokenScope) => boolean;
|
package/dist/auth/token_scope.js
CHANGED
|
@@ -123,7 +123,7 @@ export const token_scope_admits_method = (scope, method) => scope.kind === 'full
|
|
|
123
123
|
* so it fits in one sentence a user can hold — *a scoped token is RPC-only*.
|
|
124
124
|
* Placement is per site: a route that refuses anonymous callers declares
|
|
125
125
|
* `auth.required_scope`, one that answers them reads the credential through
|
|
126
|
-
* `
|
|
126
|
+
* `get_public_account` and answers a narrowed token as anonymous, and the
|
|
127
127
|
* surface census pins every site.
|
|
128
128
|
*/
|
|
129
129
|
export const token_scope_admits_non_rpc = (scope) => scope.kind === 'full';
|
package/dist/http/CLAUDE.md
CHANGED
|
@@ -66,7 +66,7 @@ consumers.
|
|
|
66
66
|
- `input: AnySchema` — request body schema; `literal(null)` for no body, and on every `GET` (`apply_route_specs` refuses any other)
|
|
67
67
|
- `output: AnySchema` — success response schema
|
|
68
68
|
- `mints_credential?: boolean` — the route issues a session cookie while declaring no auth (login, signup, bootstrap); assembly refuses it outside `AUTH_MIDDLEWARE_PATH`, as it does any route whose `auth.account` is not `'none'` (`assert_credential_routes_in_auth_scope` in `auth/middleware.ts`)
|
|
69
|
-
- `reads_credential?: boolean` — the handler reads the resolved account while the route declares no auth gate, answering an anonymous caller itself (account status, the cell-scoped fact read, `create_rpc_endpoint`'s pair, whose dispatcher gates per action); held inside `AUTH_MIDDLEWARE_PATH` by the same assertion. Such a handler reads the account through `
|
|
69
|
+
- `reads_credential?: boolean` — the handler reads the resolved account while the route declares no auth gate, answering an anonymous caller itself (account status, the cell-scoped fact read, `create_rpc_endpoint`'s pair, whose dispatcher gates per action); held inside `AUTH_MIDDLEWARE_PATH` by the same assertion. Such a handler reads the account through `get_public_account` (`auth/request_context.ts`), which answers a scope-narrowed token as anonymous — the RPC pair excepted, its dispatcher gating each method
|
|
70
70
|
- `rate_limit?: RateLimitKey` — metadata only (`'ip' | 'account' | 'both'`); auto-derives 429
|
|
71
71
|
- `errors?: ReadonlyArray<RestErrorDef>` — the handler's own error definitions (`rest_error`); joins the route error map beside the derived and middleware ones
|
|
72
72
|
- `jsonrpc?: boolean` — the route answers JSON-RPC envelopes, not REST bodies; set by `create_rpc_endpoint`, read by the DEV error check and `assert_response_matches_spec`
|
|
@@ -209,7 +209,7 @@ interface RouteContext<TAuth, TInput, TParams, TQuery> {
|
|
|
209
209
|
answers 500, not a handler running on `null`).
|
|
210
210
|
- **`route.credential`** is the whole resolved credential. A
|
|
211
211
|
`reads_credential` route never reads the account off it: it calls
|
|
212
|
-
`
|
|
212
|
+
`get_public_account(route)` (`auth/request_context.ts`), which answers
|
|
213
213
|
a scope-narrowed API token as the anonymous caller
|
|
214
214
|
(`src/test/auth/token_scope_surface_census.test.ts` holds every route
|
|
215
215
|
module to that).
|
|
@@ -270,7 +270,7 @@ declares any), so every stage after it answers with them:
|
|
|
270
270
|
1. **Params validation** — `spec.params` → `validated_params` context var; mismatch returns 400 `ERROR_INVALID_ROUTE_PARAMS` with `issues`. Each param is decoded strictly from the raw target first (`read_request_route_params`): an escape that doesn't decode is the same 400 with no `issues`, whatever the schema
|
|
271
271
|
2. **Query validation** — `spec.query` → `validated_query`; mismatch returns 400 `ERROR_INVALID_QUERY_PARAMS`. The query is decoded strictly first (`read_request_query_pairs`): an escape that doesn't decode, in any key or value, is the same 400
|
|
272
272
|
3. **Pre-authorization auth guards** — every gate that reads only what the auth middleware set, in coarse-to-fine order: `require_auth` (401 `ERROR_AUTHENTICATION_REQUIRED`) when `auth.account === 'required'` or `auth.actor === 'required'`; `require_credential_types(types)` (403 `ERROR_CREDENTIAL_TYPE_REQUIRED` with `required_credential_types: ReadonlyArray<string>`) when `auth.credential_types?.length`; `require_token_scope(capability)` (403 `ERROR_TOKEN_SCOPE_REQUIRED` with `required_scope`, the token-scope refusal) when `auth.required_scope` names a capability. All fire before any body parsing — so a caller they refuse never sees route-shape information from input parse failures — and before actor resolution, so a wrong channel costs no DB work and never learns account state (e.g. that the account is multi-actor). The `AuthGuardResolver` (e.g. `fuz_auth_guard_resolver` from `auth/auth_guard_resolver.ts`) returns this set as `pre_authorization: Array<MiddlewareHandler>`.
|
|
273
|
-
4. **Authorization phase** — when `spec.auth.actor !== 'none'`, resolves the acting actor against the resolved credential's account (`get_resolved_auth`, set by the auth middleware) plus the `acting` selector (`validated_query.acting` on GETs; read off the raw body on mutations, since body validation now runs after the gates), builds `RequestContext` via `build_request_context`, and sets `REQUEST_CONTEXT_KEY`. When `auth.account !== 'none' && auth.actor === 'none'`, an account-only context is built. Resolution failures return 400 `ERROR_ACTOR_REQUIRED` (with `available[]`) or `ERROR_ACTOR_NOT_ON_ACCOUNT` (or 500 `ERROR_NO_ACTORS_ON_ACCOUNT` on signup-invariant violation
|
|
273
|
+
4. **Authorization phase** — when `spec.auth.actor !== 'none'`, resolves the acting actor against the resolved credential's account (`get_resolved_auth`, set by the auth middleware) plus the `acting` selector (`validated_query.acting` on GETs; read off the raw body on mutations, since body validation now runs after the gates), builds `RequestContext` via `build_request_context`, and sets `REQUEST_CONTEXT_KEY`. When `auth.account !== 'none' && auth.actor === 'none'`, an account-only context is built. Resolution failures return 400 `ERROR_ACTOR_REQUIRED` (with `available[]`) or `ERROR_ACTOR_NOT_ON_ACCOUNT` (or 500 `ERROR_NO_ACTORS_ON_ACCOUNT` on signup-invariant violation — a live account with no actor — and 401 `ERROR_AUTHENTICATION_REQUIRED` when the account was deleted or purged after the credential leg read it). The phase builds on the account row that leg read, reading the account again only to tell a removed account from one with no actor. Public routes (`account: 'none' && actor: 'none'`) skip this phase entirely.
|
|
274
274
|
5. **Post-authorization auth guards** — `require_role(roles)` (403 `ERROR_INSUFFICIENT_PERMISSIONS` with `required_roles: ReadonlyArray<string>`) when `auth.roles?.length`. The only gate in this phase, because it is the only one that reads `REQUEST_CONTEXT_KEY` (populated by step 4) rather than the auth middleware's own context vars. Multi-role specs admit any-of via `has_any_scoped_role(ctx, roles, null)`.
|
|
275
275
|
6. **Input validation** — JSON body parsed (`read_json_body`) + validated; mismatch returns 400 `ERROR_INVALID_JSON_BODY` (not JSON, or JSON the Rust spine refuses — `parse_json_text`) or `ERROR_INVALID_REQUEST_BODY` (schema failure with `issues`). Every schema refusal's `issues` are `WireIssue`s (`to_wire_issues`, `schema_issues.ts`), sent under DEV only (`dev_only`). Skipped on a null input (`is_null_schema`: `literal(null)`), which every `GET` has — `apply_route_specs` refuses a `GET` with any other input. The validated input lands on `c.var.validated_input`.
|
|
276
276
|
7. **Handler** — wrapped in transaction when `use_transaction` (see above), receives `RouteContext`; its result is prepared inside the transaction and emitted after the commit (`prepare_route_response`, `emit_route_response`)
|
|
@@ -354,7 +354,7 @@ definitions (`defs`) and the status map they group into (`schemas`):
|
|
|
354
354
|
1. **Derived** — `derive_route_errors({method, auth, has_input?, has_params?, has_query?, rate_limit?})`, narrowed to the slots the route has:
|
|
355
355
|
- a body — `input` not null, `method` not `GET` (registration refuses a `GET` with an input; a surface built from specs alone derives none for one) → 400 `invalid_request_body`, `invalid_json_body`
|
|
356
356
|
- `params` → 400 `invalid_route_params`; `query` → 400 `invalid_query_params`
|
|
357
|
-
- `auth.actor !== 'none'` → 400 `actor_required`, `actor_not_on_account`, 500 `no_actors_on_account`, `
|
|
357
|
+
- `auth.actor !== 'none'` → 400 `actor_required`, `actor_not_on_account`, 500 `no_actors_on_account`, 401 `authentication_required` (an account removed after the credential leg read it — declared on an actor-optional route too) — what the dispatcher's authorization phase emits on routes whose input declares `acting?: ActingActor` (per registry-time invariant 2)
|
|
358
358
|
- `auth.account === 'required'` or `auth.actor === 'required'` → 401 `authentication_required` (`REST_AUTHENTICATION_REQUIRED`), the only body the pre-authorization gate answers
|
|
359
359
|
- `auth.required_scope` → 403 `token_scope_required`; `auth.credential_types?.length` → 403 `credential_type_required`; `auth.roles?.length` → 403 `insufficient_permissions` — in the order the gates fire, each carrying what the route demanded
|
|
360
360
|
- `rate_limit` → 429 `rate_limit_exceeded` (`retry_after`, a non-negative integer of seconds)
|
|
@@ -718,10 +718,11 @@ two-sided contract + Rust-twin parity note live on the helper's TSDoc in
|
|
|
718
718
|
`http/pending_effects.ts`.
|
|
719
719
|
|
|
720
720
|
```typescript
|
|
721
|
-
emit_after_commit(ctx, () => notification_sender.send_to_account(account_id, msg));
|
|
721
|
+
emit_after_commit(ctx, () => ctx.notification_sender.send_to_account(account_id, msg));
|
|
722
722
|
```
|
|
723
723
|
|
|
724
|
-
Used for WS sends (`
|
|
724
|
+
Used for WS sends (`ctx.notification_sender`, through
|
|
725
|
+
`queue_offer_notification` / `queue_supersede_notifications` for the
|
|
725
726
|
role-grant-offer notifications — see `auth/CLAUDE.md` §WS notifications),
|
|
726
727
|
a revocation's connection closes (`queue_connection_close` — see
|
|
727
728
|
`actions/CLAUDE.md` §Connection closer), the audit emitter's listener fan-out
|
|
@@ -134,7 +134,7 @@ export interface RouteAuth {
|
|
|
134
134
|
* RPC endpoint runs its own per-method check inside the dispatcher, the
|
|
135
135
|
* `reads_credential` routes that answer anonymous callers (account status,
|
|
136
136
|
* the cell-scoped fact read) can't take the field and answer a narrowed
|
|
137
|
-
* token as anonymous in their handler (`
|
|
137
|
+
* token as anonymous in their handler (`get_public_account`), and the
|
|
138
138
|
* server-status route admits a narrowed token by design — and all are
|
|
139
139
|
* route specs too.
|
|
140
140
|
*
|
|
@@ -136,22 +136,10 @@ export declare const ERROR_ACTOR_NOT_ON_ACCOUNT: "actor_not_on_account";
|
|
|
136
136
|
* violation — signup / bootstrap always create an actor in the same
|
|
137
137
|
* transaction. Surfaced from the dispatcher's authorization phase as a
|
|
138
138
|
* 500 so the operator sees the corruption signal rather than a confusing
|
|
139
|
-
* 4xx.
|
|
140
|
-
*
|
|
139
|
+
* 4xx. An account removed after its credential was read reaches it too: the
|
|
140
|
+
* removal takes the account's actors with it.
|
|
141
141
|
*/
|
|
142
142
|
export declare const ERROR_NO_ACTORS_ON_ACCOUNT: "no_actors_on_account";
|
|
143
|
-
/**
|
|
144
|
-
* Authentication validated an account, but a follow-up read in the
|
|
145
|
-
* authorization phase came back null — the account or its named actor
|
|
146
|
-
* row was deleted between the credential check and the dispatcher's
|
|
147
|
-
* `build_request_context` / `build_account_context` step. Torn read,
|
|
148
|
-
* not a missing-actor invariant violation. Surfaced as 500 so the
|
|
149
|
-
* operator sees the race signal; clients can retry. Distinct from
|
|
150
|
-
* `ERROR_ACCOUNT_NOT_FOUND` (stale token referencing a long-deleted
|
|
151
|
-
* account, raised at credential validation) and
|
|
152
|
-
* `ERROR_NO_ACTORS_ON_ACCOUNT` (the actor list enumerated empty).
|
|
153
|
-
*/
|
|
154
|
-
export declare const ERROR_ACCOUNT_VANISHED: "account_vanished";
|
|
155
143
|
/** Keeper account ID set but account row not found. */
|
|
156
144
|
export declare const ERROR_KEEPER_ACCOUNT_NOT_FOUND: "keeper_account_not_found";
|
|
157
145
|
/** Bootstrap lock already acquired — system already bootstrapped. */
|
|
@@ -406,8 +394,6 @@ export declare const REST_RATE_LIMIT_EXCEEDED: RestErrorDef<429, "rate_limit_exc
|
|
|
406
394
|
}>;
|
|
407
395
|
/** The account's actors enumerated empty, a signup invariant broken. */
|
|
408
396
|
export declare const REST_NO_ACTORS_ON_ACCOUNT: RestErrorDef<500, "no_actors_on_account", Record<never, never>>;
|
|
409
|
-
/** The account or actor row was deleted between credential validation and the actor read. */
|
|
410
|
-
export declare const REST_ACCOUNT_VANISHED: RestErrorDef<500, "account_vanished", Record<never, never>>;
|
|
411
397
|
export declare const REST_INTERNAL_ERROR: RestErrorDef<500, "internal_error", Record<never, never>>;
|
|
412
398
|
/** Bootstrap's token matched and its file couldn't be burned; the bootstrap rolled back. */
|
|
413
399
|
export declare const REST_TOKEN_FILE_UNDELETABLE: RestErrorDef<500, "token_file_undeletable", Record<never, never>>;
|
|
@@ -454,9 +440,11 @@ export interface DeriveRouteErrorsOptions {
|
|
|
454
440
|
* the body's errors there either.
|
|
455
441
|
* - **`params`**: 400 `invalid_route_params`. **`query`**: 400
|
|
456
442
|
* `invalid_query_params`.
|
|
457
|
-
* - **`auth.account === 'required'`** or **`auth.actor
|
|
443
|
+
* - **`auth.account === 'required'`** or **`auth.actor !== 'none'`**: 401
|
|
458
444
|
* `authentication_required` — the pre-authorization gate's refusal when the
|
|
459
|
-
* credential isn't there
|
|
445
|
+
* credential isn't there, and the authorization phase's when the account it
|
|
446
|
+
* resolved was removed before the phase listed its actors. An optional
|
|
447
|
+
* account with no actor axis does not derive 401.
|
|
460
448
|
* - **`auth.required_scope`**: 403 `token_scope_required` (carrying
|
|
461
449
|
* `required_scope`). **`auth.credential_types?.length`**: 403
|
|
462
450
|
* `credential_type_required` (carrying `required_credential_types`).
|
|
@@ -464,9 +452,9 @@ export interface DeriveRouteErrorsOptions {
|
|
|
464
452
|
* `required_roles`). In the order the gates fire; a route with more than
|
|
465
453
|
* one has each.
|
|
466
454
|
* - **`auth.actor !== 'none'`**: 400 `actor_required` and
|
|
467
|
-
* `actor_not_on_account`, and 500 `no_actors_on_account`
|
|
468
|
-
*
|
|
469
|
-
*
|
|
455
|
+
* `actor_not_on_account`, and 500 `no_actors_on_account` — what the
|
|
456
|
+
* dispatcher's authorization phase emits when it resolves an actor (its 401
|
|
457
|
+
* is the rule above).
|
|
470
458
|
* - **`rate_limit`**: 429 `rate_limit_exceeded` (with `retry_after`).
|
|
471
459
|
* - **`POST`**: 415 `unsupported_content_type` (see
|
|
472
460
|
* `is_post_content_type_refused` in `http/simple_request.ts`).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error_schemas.d.ts","sourceRoot":"","sources":["../../src/lib/http/error_schemas.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAYN,KAAK,SAAS,EACd,KAAK,KAAK,EACV,KAAK,MAAM,EACX,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAInD,4CAA4C;AAC5C,eAAO,MAAM,0BAA0B,EAAG,sBAA+B,CAAC;AAE1E,uDAAuD;AACvD,eAAO,MAAM,uBAAuB,EAAG,mBAA4B,CAAC;AAEpE,2CAA2C;AAC3C,eAAO,MAAM,0BAA0B,EAAG,sBAA+B,CAAC;AAE1E,4CAA4C;AAC5C,eAAO,MAAM,0BAA0B,EAAG,sBAA+B,CAAC;AAE1E;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,EAAG,kBAA2B,CAAC;AAElE;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,EAAG,Y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pB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,YAAY,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,eAAO,MAAM,mBAAmB,GAAI,gEAOjC,wBAAwB,KAAG,KAAK,CAAC,YAAY,CAoC/C,CAAC"}
|
|
@@ -140,22 +140,10 @@ export const ERROR_ACTOR_NOT_ON_ACCOUNT = 'actor_not_on_account';
|
|
|
140
140
|
* violation — signup / bootstrap always create an actor in the same
|
|
141
141
|
* transaction. Surfaced from the dispatcher's authorization phase as a
|
|
142
142
|
* 500 so the operator sees the corruption signal rather than a confusing
|
|
143
|
-
* 4xx.
|
|
144
|
-
*
|
|
143
|
+
* 4xx. An account removed after its credential was read reaches it too: the
|
|
144
|
+
* removal takes the account's actors with it.
|
|
145
145
|
*/
|
|
146
146
|
export const ERROR_NO_ACTORS_ON_ACCOUNT = 'no_actors_on_account';
|
|
147
|
-
/**
|
|
148
|
-
* Authentication validated an account, but a follow-up read in the
|
|
149
|
-
* authorization phase came back null — the account or its named actor
|
|
150
|
-
* row was deleted between the credential check and the dispatcher's
|
|
151
|
-
* `build_request_context` / `build_account_context` step. Torn read,
|
|
152
|
-
* not a missing-actor invariant violation. Surfaced as 500 so the
|
|
153
|
-
* operator sees the race signal; clients can retry. Distinct from
|
|
154
|
-
* `ERROR_ACCOUNT_NOT_FOUND` (stale token referencing a long-deleted
|
|
155
|
-
* account, raised at credential validation) and
|
|
156
|
-
* `ERROR_NO_ACTORS_ON_ACCOUNT` (the actor list enumerated empty).
|
|
157
|
-
*/
|
|
158
|
-
export const ERROR_ACCOUNT_VANISHED = 'account_vanished';
|
|
159
147
|
// --- Keeper / daemon token ---
|
|
160
148
|
/** Keeper account ID set but account row not found. */
|
|
161
149
|
export const ERROR_KEEPER_ACCOUNT_NOT_FOUND = 'keeper_account_not_found';
|
|
@@ -422,8 +410,6 @@ export const REST_RATE_LIMIT_EXCEEDED = rest_error(429, ERROR_RATE_LIMIT_EXCEEDE
|
|
|
422
410
|
// 500: the authorization phase, and the catch layer any route can answer with
|
|
423
411
|
/** The account's actors enumerated empty, a signup invariant broken. */
|
|
424
412
|
export const REST_NO_ACTORS_ON_ACCOUNT = rest_error(500, ERROR_NO_ACTORS_ON_ACCOUNT);
|
|
425
|
-
/** The account or actor row was deleted between credential validation and the actor read. */
|
|
426
|
-
export const REST_ACCOUNT_VANISHED = rest_error(500, ERROR_ACCOUNT_VANISHED);
|
|
427
413
|
export const REST_INTERNAL_ERROR = rest_error(500, ERROR_INTERNAL_ERROR);
|
|
428
414
|
/** Bootstrap's token matched and its file couldn't be burned; the bootstrap rolled back. */
|
|
429
415
|
export const REST_TOKEN_FILE_UNDELETABLE = rest_error(500, ERROR_TOKEN_FILE_UNDELETABLE);
|
|
@@ -453,9 +439,11 @@ export const REST_DB_UNREACHABLE = rest_error(503, ERROR_DB_UNREACHABLE);
|
|
|
453
439
|
* the body's errors there either.
|
|
454
440
|
* - **`params`**: 400 `invalid_route_params`. **`query`**: 400
|
|
455
441
|
* `invalid_query_params`.
|
|
456
|
-
* - **`auth.account === 'required'`** or **`auth.actor
|
|
442
|
+
* - **`auth.account === 'required'`** or **`auth.actor !== 'none'`**: 401
|
|
457
443
|
* `authentication_required` — the pre-authorization gate's refusal when the
|
|
458
|
-
* credential isn't there
|
|
444
|
+
* credential isn't there, and the authorization phase's when the account it
|
|
445
|
+
* resolved was removed before the phase listed its actors. An optional
|
|
446
|
+
* account with no actor axis does not derive 401.
|
|
459
447
|
* - **`auth.required_scope`**: 403 `token_scope_required` (carrying
|
|
460
448
|
* `required_scope`). **`auth.credential_types?.length`**: 403
|
|
461
449
|
* `credential_type_required` (carrying `required_credential_types`).
|
|
@@ -463,9 +451,9 @@ export const REST_DB_UNREACHABLE = rest_error(503, ERROR_DB_UNREACHABLE);
|
|
|
463
451
|
* `required_roles`). In the order the gates fire; a route with more than
|
|
464
452
|
* one has each.
|
|
465
453
|
* - **`auth.actor !== 'none'`**: 400 `actor_required` and
|
|
466
|
-
* `actor_not_on_account`, and 500 `no_actors_on_account`
|
|
467
|
-
*
|
|
468
|
-
*
|
|
454
|
+
* `actor_not_on_account`, and 500 `no_actors_on_account` — what the
|
|
455
|
+
* dispatcher's authorization phase emits when it resolves an actor (its 401
|
|
456
|
+
* is the rule above).
|
|
469
457
|
* - **`rate_limit`**: 429 `rate_limit_exceeded` (with `retry_after`).
|
|
470
458
|
* - **`POST`**: 415 `unsupported_content_type` (see
|
|
471
459
|
* `is_post_content_type_refused` in `http/simple_request.ts`).
|
|
@@ -485,13 +473,15 @@ export const derive_route_errors = ({ method, auth, has_input = false, has_param
|
|
|
485
473
|
if (has_query)
|
|
486
474
|
defs.push(REST_INVALID_QUERY_PARAMS);
|
|
487
475
|
if (needs_actor(auth)) {
|
|
488
|
-
defs.push(REST_ACTOR_REQUIRED, REST_ACTOR_NOT_ON_ACCOUNT, REST_NO_ACTORS_ON_ACCOUNT
|
|
476
|
+
defs.push(REST_ACTOR_REQUIRED, REST_ACTOR_NOT_ON_ACCOUNT, REST_NO_ACTORS_ON_ACCOUNT);
|
|
489
477
|
}
|
|
490
478
|
// 401 fires when the dispatcher's pre-authorization gate rejects an
|
|
491
479
|
// unauthenticated caller — `account === 'required'` (no credential) or
|
|
492
480
|
// `actor === 'required'` (no credential to resolve an actor against,
|
|
493
|
-
// per registry-time invariant 3 forbidding accountless actors in v1)
|
|
494
|
-
|
|
481
|
+
// per registry-time invariant 3 forbidding accountless actors in v1) — and
|
|
482
|
+
// when the authorization phase, resolving an actor, finds the account
|
|
483
|
+
// removed since its credential was read
|
|
484
|
+
if (auth.account === 'required' || needs_actor(auth)) {
|
|
495
485
|
defs.push(REST_AUTHENTICATION_REQUIRED);
|
|
496
486
|
}
|
|
497
487
|
// 403 fires from any of three gates: the token-scope refusal
|
|
@@ -115,7 +115,7 @@ export interface RouteContext<TAuth extends RequestContext | null = RequestConte
|
|
|
115
115
|
* The credential the auth middleware resolved, `null` for an anonymous
|
|
116
116
|
* caller. A `reads_credential` route — one that answers anonymous callers
|
|
117
117
|
* itself — reads the account it may act on through
|
|
118
|
-
* `
|
|
118
|
+
* `get_public_account(route)` (`auth/request_context.ts`), never from
|
|
119
119
|
* here: a scope-narrowed API token is the anonymous caller there, and only
|
|
120
120
|
* that function applies the rule.
|
|
121
121
|
*/
|
|
@@ -328,7 +328,7 @@ export interface RouteSpec {
|
|
|
328
328
|
* The handler owns the token-scope rule a gate would otherwise apply: a
|
|
329
329
|
* scope-narrowed API token reaches no non-RPC surface that reads account
|
|
330
330
|
* data, and `auth.required_scope` is refused on a route that admits
|
|
331
|
-
* anonymous callers. Read the credential through `
|
|
331
|
+
* anonymous callers. Read the credential through `get_public_account`
|
|
332
332
|
* (`auth/request_context.ts`), not `get_resolved_auth`, so a narrowed token is
|
|
333
333
|
* answered as the anonymous caller. The RPC endpoint is the exception — its
|
|
334
334
|
* dispatcher gates each method against the scope.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app_backend.d.ts","sourceRoot":"","sources":["../../src/lib/server/app_backend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEjD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAwB,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACnF,OAAO,EAA0B,KAAK,cAAc,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"app_backend.d.ts","sourceRoot":"","sources":["../../src/lib/server/app_backend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEjD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAwB,KAA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,CAAC;IACnC;;;;;;;;;;;;;OAaG;IACH,oBAAoB,CAAC,EAAE,aAAa,CAAC,kBAAkB,CAAC,CAAC;IACzD;;;;;;;;;OASG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC;;;;;;;OAOG;IACH,4BAA4B,CAAC,EAAE,MAAM,CAAC;CACtC;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,kBAAkB,GAAU,SAAS,uBAAuB,KAAG,OAAO,CAAC,UAAU,CAwD7F,CAAC"}
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import { Logger } from '@fuzdev/fuz_util/log.ts';
|
|
14
14
|
import { create_audit_emitter } from '../auth/audit_emitter.js';
|
|
15
15
|
import { create_realtime_closer } from '../actions/connection_closer.js';
|
|
16
|
+
import { create_realtime_notification_sender } from '../actions/notification_sender.js';
|
|
16
17
|
import { run_migrations } from '../db/migrate.js';
|
|
17
18
|
import { AUTH_MIGRATION_NS } from '../auth/migrations.js';
|
|
18
19
|
import { create_db, is_pg_database_url } from '../db/create_db.js';
|
|
@@ -80,7 +81,8 @@ export const create_app_backend = async (options) => {
|
|
|
80
81
|
db,
|
|
81
82
|
log,
|
|
82
83
|
audit,
|
|
83
|
-
connection_closer: options.connection_closer ?? create_realtime_closer()
|
|
84
|
+
connection_closer: options.connection_closer ?? create_realtime_closer(),
|
|
85
|
+
notification_sender: create_realtime_notification_sender()
|
|
84
86
|
}
|
|
85
87
|
};
|
|
86
88
|
}
|
|
@@ -363,7 +363,7 @@ export interface AppServerOptions {
|
|
|
363
363
|
* `(ctx: AppServerContext) => ReadonlyArray<WsEndpointSpec>`
|
|
364
364
|
* (evaluated after the server context is assembled). Use the factory
|
|
365
365
|
* form when action lists depend on `ctx.deps` — e.g. when spreading
|
|
366
|
-
* `create_standard_rpc_actions(
|
|
366
|
+
* `create_standard_rpc_actions(ctx.deps)` over WS.
|
|
367
367
|
*
|
|
368
368
|
* When non-empty, `upgrade_websocket` must be supplied (throws
|
|
369
369
|
* otherwise). A factory returning `[]` does NOT trip the check —
|
|
@@ -387,7 +387,11 @@ export interface AppServerOptions {
|
|
|
387
387
|
* the revocation handlers' post-commit closes reach its sockets, and so
|
|
388
388
|
* does the one revocation guard `create_app_server` registers on that
|
|
389
389
|
* closer (`create_revocation_guard`) when it mounts a WS endpoint or the
|
|
390
|
-
* audit stream. `
|
|
390
|
+
* audit stream. Each is added to `deps.notification_sender` too, so a
|
|
391
|
+
* notification any action handler sends — over HTTP RPC or a socket —
|
|
392
|
+
* reaches the account's sockets on every mounted registry, once per
|
|
393
|
+
* registry however many endpoints share it. `AppServer.close` removes
|
|
394
|
+
* both memberships again.
|
|
391
395
|
*/
|
|
392
396
|
ws_endpoints?: ReadonlyArray<WsEndpointSpec> | ((context: AppServerContext) => ReadonlyArray<WsEndpointSpec>);
|
|
393
397
|
/**
|
|
@@ -472,14 +476,16 @@ export interface AppServer {
|
|
|
472
476
|
* a closed registry hosts no other server
|
|
473
477
|
* 3. release what assembly acquired, last acquired first: remove the
|
|
474
478
|
* audit listeners `create_app_server` registered on `deps.audit` (the
|
|
475
|
-
* revocation guard, the audit-log SSE listener)
|
|
476
|
-
* `deps.connection_closer` (each mounted connection registry, the
|
|
477
|
-
* registry)
|
|
478
|
-
*
|
|
479
|
-
*
|
|
480
|
-
*
|
|
481
|
-
*
|
|
482
|
-
*
|
|
479
|
+
* revocation guard, the audit-log SSE listener), the members it added
|
|
480
|
+
* to `deps.connection_closer` (each mounted connection registry, the
|
|
481
|
+
* audit stream registry) and to `deps.notification_sender` (each
|
|
482
|
+
* mounted connection registry), and `dispose` the rate limiters it
|
|
483
|
+
* built for omitted options — never one passed in, which its caller
|
|
484
|
+
* owns. A release that throws is logged and the rest still run. The
|
|
485
|
+
* backend's emitter, closer and notification sender are left as they
|
|
486
|
+
* were before assembly, so a failed assembly can be retried on the same
|
|
487
|
+
* backend, and a backend whose `close` you own (a test harness) can
|
|
488
|
+
* host another server
|
|
483
489
|
* 4. close the database connection (`AppBackend.close`)
|
|
484
490
|
*
|
|
485
491
|
* Idempotent: a second call settles with the first one's outcome (a failed
|
|
@@ -639,7 +645,10 @@ export declare const collect_config_diagnostics: (input: ConfigDiagnosticsInput)
|
|
|
639
645
|
* to `backend.deps.connection_closer`, so the revocation handlers built from
|
|
640
646
|
* `ctx.deps` close their connections with no further wiring, and — when the
|
|
641
647
|
* server mounts either — one `create_revocation_guard` listener on that closer
|
|
642
|
-
* repeats each close on the audit row.
|
|
648
|
+
* repeats each close on the audit row. Each WebSocket connection registry is
|
|
649
|
+
* added to `backend.deps.notification_sender` as well, the sender every
|
|
650
|
+
* mounted RPC and WebSocket dispatcher puts on its handler contexts, so an
|
|
651
|
+
* action's notification reaches the account's sockets with no wiring either.
|
|
643
652
|
* The
|
|
644
653
|
* `audit_sse` field on the returned `AppServer` (and the
|
|
645
654
|
* `AppServerContext` passed to `create_route_specs`) is non-null in that
|
|
@@ -648,11 +657,12 @@ export declare const collect_config_diagnostics: (input: ConfigDiagnosticsInput)
|
|
|
648
657
|
*
|
|
649
658
|
* Assembly acquires a few things that outlive it — the rate limiters it
|
|
650
659
|
* builds, the listeners it registers on `deps.audit`, the members it adds to
|
|
651
|
-
* `deps.connection_closer` — and records a
|
|
652
|
-
*
|
|
653
|
-
* (one that throws is logged and the rest
|
|
654
|
-
* is rethrown: a failed assembly leaves
|
|
655
|
-
*
|
|
660
|
+
* `deps.connection_closer` and `deps.notification_sender` — and records a
|
|
661
|
+
* release for each as it goes. When assembly throws, every release recorded
|
|
662
|
+
* so far runs, last acquired first (one that throws is logged and the rest
|
|
663
|
+
* still run), and the original error is rethrown: a failed assembly leaves
|
|
664
|
+
* the backend's emitter, closer and notification sender as it found them and
|
|
665
|
+
* no limiter timer running. When `auth_cleanup` is set, the
|
|
656
666
|
* auth cleanup schedule starts as the last step of assembly — nothing after
|
|
657
667
|
* it can throw, so an assembly that throws leaves no schedule running.
|
|
658
668
|
*
|