@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
|
@@ -12,6 +12,7 @@ import { to_admin_account } from './account_schema.js';
|
|
|
12
12
|
import { ADMIN_ACCOUNT_LIST_DEFAULT_LIMIT } from './admin_action_specs.js';
|
|
13
13
|
import { ROLE_GRANT_COLUMNS } from './role_grant_queries.js';
|
|
14
14
|
import { offer_pending_predicate, role_grant_active_sql } from './role_grant_sql.js';
|
|
15
|
+
import { ROLE_ADMIN } from './role_schema.js';
|
|
15
16
|
/**
|
|
16
17
|
* The full `account` column set, named explicitly so a row read fails loud
|
|
17
18
|
* on schema drift.
|
|
@@ -84,8 +85,8 @@ export const query_create_account = async (deps, input) => {
|
|
|
84
85
|
/**
|
|
85
86
|
* Find an **active** account by id (`deleted_at IS NULL`).
|
|
86
87
|
*
|
|
87
|
-
* This is the auth-resolution workhorse (
|
|
88
|
-
*
|
|
88
|
+
* This is the auth-resolution workhorse (every credential leg reads the
|
|
89
|
+
* account through it) and the admin-target lookup, so it
|
|
89
90
|
* deliberately excludes soft-deleted accounts: a tombstoned account must
|
|
90
91
|
* not authenticate (`delete` = soft, `purge` = hard). Purge, which must operate on
|
|
91
92
|
* soft-deleted rows too, uses `query_purge_account` directly.
|
|
@@ -172,9 +173,24 @@ export const query_update_account_password = async (deps, id, password_hash, upd
|
|
|
172
173
|
* writers write the account row before they revoke, which is what makes the
|
|
173
174
|
* lock order them.
|
|
174
175
|
*
|
|
175
|
-
* `FOR
|
|
176
|
-
*
|
|
177
|
-
*
|
|
176
|
+
* `FOR NO KEY UPDATE`, the strength of their `UPDATE`s, so it also conflicts
|
|
177
|
+
* with itself: the mints of one account take turns. The session cap needs
|
|
178
|
+
* that. A mint inserts its session and evicts the oldest past the cap in one
|
|
179
|
+
* transaction, and two mints running together each count without the other's
|
|
180
|
+
* uncommitted row — both commit above the cap — while their evictions lock
|
|
181
|
+
* the same old rows in orders the query plan picks, and can deadlock. Taken
|
|
182
|
+
* in turn, the second mint runs its statements after the first commits and
|
|
183
|
+
* counts its row. The foreign-key `FOR KEY SHARE` of a row inserted under the
|
|
184
|
+
* account does not conflict with it, so no write that merely references the
|
|
185
|
+
* account waits on a login. Besides the writers it orders against, it
|
|
186
|
+
* conflicts with `query_account_lock_live` (the token mint, the same
|
|
187
|
+
* strength), the `FOR SHARE` of `query_account_lock_live_many` (an offer or
|
|
188
|
+
* invite create), an offer accept's locks (`query_account_lock_for_offer_accept`,
|
|
189
|
+
* the recipient's at this strength, a grantor's shared), and the last-admin
|
|
190
|
+
* guard's `FOR NO KEY UPDATE`. None of
|
|
191
|
+
* those waits on an account row while holding a session row, and once a mint
|
|
192
|
+
* holds the lock it waits on nothing but the session rows its eviction
|
|
193
|
+
* deletes, so no cycle runs through it. Twin of the Rust
|
|
178
194
|
* `fuz_auth::query_account_lock_verified`.
|
|
179
195
|
*
|
|
180
196
|
* @param deps - query dependencies (must be the mint's transaction)
|
|
@@ -185,7 +201,7 @@ export const query_update_account_password = async (deps, id, password_hash, upd
|
|
|
185
201
|
export const query_account_lock_verified = async (deps, id, password_hash) => {
|
|
186
202
|
const row = await deps.db.query_one(`SELECT id FROM account
|
|
187
203
|
WHERE id = $1 AND deleted_at IS NULL AND password_hash = $2
|
|
188
|
-
FOR
|
|
204
|
+
FOR NO KEY UPDATE`, [id, password_hash]);
|
|
189
205
|
return row !== undefined;
|
|
190
206
|
};
|
|
191
207
|
/**
|
|
@@ -197,30 +213,129 @@ export const query_account_lock_verified = async (deps, id, password_hash) => {
|
|
|
197
213
|
* token before the new one exists. Run first in the mint's transaction, this
|
|
198
214
|
* read waits on the delete's row lock and then sees its tombstone; once it
|
|
199
215
|
* holds the lock, a delete waits for the mint to commit and then revokes the
|
|
200
|
-
* token. The password is not re-checked: the mint verified none.
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
* `
|
|
216
|
+
* token. The password is not re-checked: the mint verified none. Taken
|
|
217
|
+
* `FOR NO KEY UPDATE` for the token cap, as the login's lock is for the session
|
|
218
|
+
* cap — `query_account_lock_verified` has why, and what it conflicts with; a
|
|
219
|
+
* token mint and a login of one account take turns too. A write that only
|
|
220
|
+
* needs ordering against a delete takes `query_account_lock_live_many`, which
|
|
221
|
+
* lets such writes run together. Twin of the Rust
|
|
222
|
+
* `fuz_auth::query_account_lock_live`.
|
|
207
223
|
*
|
|
208
224
|
* @param deps - query dependencies (must be the mint's transaction)
|
|
209
225
|
* @param id - the account the credential is for
|
|
210
226
|
* @returns `true` when the row is locked and not tombstoned, `false` when it was deleted or tombstoned
|
|
211
227
|
*/
|
|
212
228
|
export const query_account_lock_live = async (deps, id) => {
|
|
213
|
-
const row = await deps.db.query_one(`SELECT id FROM account WHERE id = $1 AND deleted_at IS NULL FOR
|
|
229
|
+
const row = await deps.db.query_one(`SELECT id FROM account WHERE id = $1 AND deleted_at IS NULL FOR NO KEY UPDATE`, [id]);
|
|
214
230
|
return row !== undefined;
|
|
215
231
|
};
|
|
216
232
|
/**
|
|
217
|
-
* Lock
|
|
218
|
-
*
|
|
219
|
-
*
|
|
233
|
+
* Lock, for a purge, the account rows of every holder of an unrevoked global
|
|
234
|
+
* `admin` grant and the purged account's own, in one statement, in id order,
|
|
235
|
+
* `FOR NO KEY UPDATE`.
|
|
236
|
+
*
|
|
237
|
+
* A purge's cascade writes rows of other accounts: it sets null the
|
|
238
|
+
* `granted_by` and `revoked_by` of every grant the purged account's actors
|
|
239
|
+
* named, admins' grants among them, in whatever order the plan walks them. A
|
|
240
|
+
* last-admin guard of another removal takes admin accounts, actors and grants
|
|
241
|
+
* in account-id order. A purge reaching an admin's grant before the guard does
|
|
242
|
+
* and waiting on one the guard took could hold a row the guard waits on.
|
|
243
|
+
* Holding every admin's account first, in the order the guard and
|
|
244
|
+
* `query_account_lock_live_many` take account rows, another guard waits at its
|
|
245
|
+
* first account holding nothing, and two purges take turns. The purged
|
|
246
|
+
* account's row is taken in the same statement, so an offer create holding one
|
|
247
|
+
* of these rows `FOR SHARE` and waiting on another meets them in the same order.
|
|
248
|
+
* No `deleted_at` filter on either: a tombstoned admin's grant is written by
|
|
249
|
+
* the cascade as well, and a purge removes a tombstoned account. The admins
|
|
250
|
+
* are those the statement's snapshot sees; one made by a transaction that
|
|
251
|
+
* commits after it starts is not among them. Cost: a purge waits behind
|
|
252
|
+
* admins' logins, token creates and offers. Run first in the purge's
|
|
253
|
+
* transaction, before the last-admin guard (an admin target's only) and
|
|
254
|
+
* `query_account_lock_for_purge`.
|
|
255
|
+
* Twin of the Rust `fuz_auth::account_queries::query_account_lock_admins_for_purge`.
|
|
256
|
+
*
|
|
257
|
+
* @param deps - query dependencies (must be the purge's transaction)
|
|
258
|
+
* @param id - the account to purge
|
|
259
|
+
*/
|
|
260
|
+
export const query_account_lock_admins_for_purge = async (deps, id) => {
|
|
261
|
+
await deps.db.query(`SELECT a.id FROM account a
|
|
262
|
+
WHERE a.id = $1
|
|
263
|
+
OR a.id IN (
|
|
264
|
+
SELECT act.account_id FROM actor act
|
|
265
|
+
JOIN role_grant rg ON rg.actor_id = act.id
|
|
266
|
+
WHERE rg.role = $2 AND rg.scope_id IS NULL AND rg.revoked_at IS NULL)
|
|
267
|
+
ORDER BY a.id
|
|
268
|
+
FOR NO KEY UPDATE`, [id, ROLE_ADMIN]);
|
|
269
|
+
};
|
|
270
|
+
/**
|
|
271
|
+
* Lock the account row of a revoke's revokee, by its actor, tombstoned or not,
|
|
272
|
+
* `FOR NO KEY UPDATE`.
|
|
273
|
+
*
|
|
274
|
+
* Every revoke of a grant takes it, before it locks the offers it supersedes
|
|
275
|
+
* and before it updates the grant. It keeps those offers from growing: an offer
|
|
276
|
+
* to or from the account takes the row `FOR SHARE`
|
|
277
|
+
* (`query_account_lock_live_many`), so none is made while the revoke runs, and
|
|
278
|
+
* an accept by the account takes it `FOR NO KEY UPDATE`
|
|
279
|
+
* (`query_account_lock_for_offer_accept`), so none claims one. And it is the
|
|
280
|
+
* lock an accept of an offer from the revokee is ordered by: the accept reads
|
|
281
|
+
* its grantor's authority under the grantor's account row, and a revoke of that
|
|
282
|
+
* authority takes the row here whether or not its last-admin guard ran (the
|
|
283
|
+
* guard runs only while the account holds an active global `admin`). A revoke
|
|
284
|
+
* of an admin grant takes it after the guard, which holds it already among the
|
|
285
|
+
* admins' rows in id order. Twin of the Rust
|
|
286
|
+
* `fuz_auth::account_queries::query_account_lock_for_revoke`.
|
|
287
|
+
*
|
|
288
|
+
* @param deps - query dependencies (must be the revoke's transaction)
|
|
289
|
+
* @param actor_id - the revokee actor
|
|
290
|
+
*/
|
|
291
|
+
export const query_account_lock_for_revoke = async (deps, actor_id) => {
|
|
292
|
+
await deps.db.query(`SELECT a.id FROM actor act JOIN account a ON a.id = act.account_id
|
|
293
|
+
WHERE act.id = $1
|
|
294
|
+
FOR NO KEY UPDATE OF a`, [actor_id]);
|
|
295
|
+
};
|
|
296
|
+
/**
|
|
297
|
+
* Lock an account row for its purge, tombstoned or not.
|
|
298
|
+
*
|
|
299
|
+
* Every writer of an account takes the account row before its other rows — a
|
|
300
|
+
* credential mint its lock, a password change or a delete its `UPDATE` — and a
|
|
301
|
+
* purge takes it first as well, ahead of the credential rows its revokes and
|
|
302
|
+
* its cascade delete. A purge reaching the row only at its `DELETE` would hold
|
|
303
|
+
* the account's sessions and tokens while waiting on a writer that holds the
|
|
304
|
+
* row and goes on to those same rows: a login evicting at the cap, a password
|
|
305
|
+
* change or a delete revoking. `FOR UPDATE`, the lock the purge's `DELETE`
|
|
306
|
+
* takes anyway: it conflicts with every other lock on the row, so a writer
|
|
307
|
+
* holding one is waited out, and a writer arriving later waits for the purge
|
|
308
|
+
* and then finds no row. No `deleted_at` filter — a purge removes a tombstoned
|
|
309
|
+
* account too. Run after `query_account_lock_admins_for_purge`, which takes the
|
|
310
|
+
* row `FOR NO KEY UPDATE` among every admin's in id order, and, for an admin
|
|
311
|
+
* target, the last-admin guard, so this only strengthens a lock the purge
|
|
312
|
+
* already holds. Twin of the Rust
|
|
313
|
+
* `fuz_auth::account_queries::query_account_lock_for_purge`.
|
|
314
|
+
*
|
|
315
|
+
* @param deps - query dependencies (must be the purge's transaction)
|
|
316
|
+
* @param id - the account to purge
|
|
317
|
+
* @returns `true` when the row is locked, `false` when there is no such account
|
|
318
|
+
*/
|
|
319
|
+
export const query_account_lock_for_purge = async (deps, id) => {
|
|
320
|
+
const row = await deps.db.query_one(`SELECT id FROM account WHERE id = $1 FOR UPDATE`, [id]);
|
|
321
|
+
return row !== undefined;
|
|
322
|
+
};
|
|
323
|
+
/**
|
|
324
|
+
* Lock live account rows in one statement, in id order, for a write that must
|
|
325
|
+
* be ordered against a delete of any of them.
|
|
326
|
+
*
|
|
327
|
+
* An offer locks its two parties (`query_role_grant_offer_create`), an invite
|
|
328
|
+
* its issuer (`invite_create`, one id).
|
|
329
|
+
*
|
|
330
|
+
* `FOR SHARE`: the weakest lock that conflicts with a delete's `UPDATE` of the
|
|
331
|
+
* row, so these writes don't wait on one another. It also waits on a
|
|
332
|
+
* credential mint's `FOR NO KEY UPDATE` (`query_account_lock_verified`), and a
|
|
333
|
+
* mint waits on it — but a mint holding its lock waits on no row these writes
|
|
334
|
+
* hold.
|
|
220
335
|
*
|
|
221
336
|
* The rows are locked as the sort returns them, so every caller takes them in
|
|
222
337
|
* id order, as the last-admin guard
|
|
223
|
-
* (`
|
|
338
|
+
* (`query_count_active_accounts_with_global_role_locked`) takes its
|
|
224
339
|
* account rows: two transactions locking two of the same accounts never wait
|
|
225
340
|
* on each other in opposite orders. Taken one statement per account, an offer
|
|
226
341
|
* between two admins could hold one party's row while the guard held the
|
|
@@ -240,6 +355,62 @@ export const query_account_lock_live_many = async (deps, ids) => {
|
|
|
240
355
|
const rows = await deps.db.query(`SELECT id FROM account WHERE id = ANY($1) AND deleted_at IS NULL ORDER BY id FOR SHARE`, [ids]);
|
|
241
356
|
return new Set(rows.map((row) => row.id));
|
|
242
357
|
};
|
|
358
|
+
/**
|
|
359
|
+
* Lock the account rows an offer accept is ordered by, in id order: the
|
|
360
|
+
* recipient's `FOR NO KEY UPDATE`, and — when the offer confers the global
|
|
361
|
+
* `admin` its grantor must still hold — the grantor's `FOR SHARE`.
|
|
362
|
+
*
|
|
363
|
+
* The recipient's lock is a credential mint's strength
|
|
364
|
+
* (`query_account_lock_verified`), so it conflicts with itself: two accepts
|
|
365
|
+
* by one recipient take turns, and the second claims after the first has
|
|
366
|
+
* superseded its siblings. It conflicts with a delete's or a purge's first
|
|
367
|
+
* write of the account (the soft-delete `UPDATE`,
|
|
368
|
+
* `query_account_lock_admins_for_purge`, the last-admin guard), so a removal of
|
|
369
|
+
* the recipient waits here or is waited for whole, and never meets the accept
|
|
370
|
+
* at its offers or its actor; with a revoke's `query_account_lock_for_revoke`,
|
|
371
|
+
* so a revoke of the recipient's grant and the accept take turns; and with
|
|
372
|
+
* `query_account_lock_live_many`, so no offer to the recipient is made or
|
|
373
|
+
* refreshed while the accept holds it. Cost: an accept waits behind the
|
|
374
|
+
* recipient's own logins and token mints, which take the same lock.
|
|
375
|
+
*
|
|
376
|
+
* The grantor's share lock is what the grantor's authority is read under (an
|
|
377
|
+
* unlocked read after this one): every write that ends a grantor's global
|
|
378
|
+
* `admin` takes the grantor's account row first — a revoke of the grant through
|
|
379
|
+
* `query_account_lock_for_revoke` (whether or not its last-admin guard ran), a
|
|
380
|
+
* delete through its write of the row, a purge through
|
|
381
|
+
* `query_account_lock_admins_for_purge` and `query_account_lock_for_purge` — so
|
|
382
|
+
* it either commits before the read, which sees it, or waits for the accept to
|
|
383
|
+
* commit. A share lock on the account,
|
|
384
|
+
* not on the grant, so a purge's cascade reaching the grant (its `granted_by`
|
|
385
|
+
* naming an actor of the purged account) never waits on the accept.
|
|
386
|
+
*
|
|
387
|
+
* Two statements, as the two strengths can't share one locking clause, the
|
|
388
|
+
* lower id first — the order the last-admin guard
|
|
389
|
+
* (`query_count_active_accounts_with_global_role_locked`) and
|
|
390
|
+
* `query_account_lock_live_many` take account rows in — so an accept and a
|
|
391
|
+
* guard over an admin recipient and its grantor never wait on each other in
|
|
392
|
+
* opposite orders. Neither is filtered on the grantor's tombstone: the
|
|
393
|
+
* authority read judges it. Twin of the Rust
|
|
394
|
+
* `fuz_auth::query_account_lock_for_offer_accept`.
|
|
395
|
+
*
|
|
396
|
+
* @param deps - query dependencies (must be the accept's transaction)
|
|
397
|
+
* @param recipient_id - the accepting account
|
|
398
|
+
* @param grantor_id - the grantor's account, or `null` when the offer needs no grantor authority
|
|
399
|
+
* @returns `true` when the recipient's row is locked and live, `false` when it was deleted or tombstoned
|
|
400
|
+
*/
|
|
401
|
+
export const query_account_lock_for_offer_accept = async (deps, recipient_id, grantor_id) => {
|
|
402
|
+
const lock_grantor = async () => {
|
|
403
|
+
if (grantor_id === null)
|
|
404
|
+
return;
|
|
405
|
+
await deps.db.query(`SELECT id FROM account WHERE id = $1 FOR SHARE`, [grantor_id]);
|
|
406
|
+
};
|
|
407
|
+
if (grantor_id !== null && grantor_id < recipient_id)
|
|
408
|
+
await lock_grantor();
|
|
409
|
+
const recipient = await deps.db.query_one(`SELECT id FROM account WHERE id = $1 AND deleted_at IS NULL FOR NO KEY UPDATE`, [recipient_id]);
|
|
410
|
+
if (grantor_id !== null && grantor_id > recipient_id)
|
|
411
|
+
await lock_grantor();
|
|
412
|
+
return recipient !== undefined;
|
|
413
|
+
};
|
|
243
414
|
/**
|
|
244
415
|
* Soft-delete an account — the reversible tombstone (`delete` = soft).
|
|
245
416
|
*
|
|
@@ -36,7 +36,7 @@ import type { RouteFactoryDeps } from './deps.js';
|
|
|
36
36
|
* its verification state, and the acting actor's role grants; the route
|
|
37
37
|
* already answers anonymous callers, so that answer is the refusal — a 403
|
|
38
38
|
* would tell the holder nothing that dropping the header doesn't. The handler
|
|
39
|
-
* reads the credential through `
|
|
39
|
+
* reads the credential through `get_public_account`, which applies it.
|
|
40
40
|
*
|
|
41
41
|
* This eliminates the need for a separate `/health` fetch on page load —
|
|
42
42
|
* the frontend gets both session state and bootstrap availability in one request.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account_routes.d.ts","sourceRoot":"","sources":["../../src/lib/auth/account_routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAGN,KAAK,cAAc,EACnB,MAAM,qBAAqB,CAAC;AAyB7B,OAAO,EAAwB,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAI7E,OAAO,EAAoB,KAAK,WAAW,EAA6B,MAAM,oBAAoB,CAAC;AACnG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAclD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,gCAAgC,GAAI,UAAU,oBAAoB,KAAG,
|
|
1
|
+
{"version":3,"file":"account_routes.d.ts","sourceRoot":"","sources":["../../src/lib/auth/account_routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAGN,KAAK,cAAc,EACnB,MAAM,qBAAqB,CAAC;AAyB7B,OAAO,EAAwB,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAI7E,OAAO,EAAoB,KAAK,WAAW,EAA6B,MAAM,oBAAoB,CAAC;AACnG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAclD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,gCAAgC,GAAI,UAAU,oBAAoB,KAAG,SAiFjF,CAAC;AAEF,iDAAiD;AACjD,MAAM,WAAW,oBAAoB;IACpC,yDAAyD;IACzD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,8FAA8F;IAC9F,gBAAgB,CAAC,EAAE;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC;CAC1C;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,2BAA2B,MAAM,CAAC;AAE/C;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B,KAAK,CAAC;AAE/C;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,uBAAuB;IACvC,eAAe,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC;CACxC;AAED;;GAEG;AACH,MAAM,WAAW,mBAAoB,SAAQ,uBAAuB;IACnE;;;;;;;OAOG;IACH,qBAAqB,EAAE,WAAW,GAAG,IAAI,CAAC;IAC1C,4FAA4F;IAC5F,0BAA0B,EAAE,WAAW,GAAG,IAAI,CAAC;IAC/C,2FAA2F;IAC3F,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;;;;OAOG;IACH,gBAAgB,CAAC,EAAE;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC;CAC1C;AAID;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,0BAA0B,GACtC,MAAM,gBAAgB,EACtB,SAAS,mBAAmB,KAC1B,KAAK,CAAC,SAAS,CAkXjB,CAAC"}
|
|
@@ -23,9 +23,9 @@ import { clear_session_cookie_header, session_cookie_header } from './session_co
|
|
|
23
23
|
import { RoleGrantSummaryJson, to_session_account } from './account_schema.js';
|
|
24
24
|
import { account_status_route_shape, create_account_route_shapes, DEFAULT_MAX_SESSIONS } from './account_route_schema.js';
|
|
25
25
|
import { create_capped_session, query_session_revoke_all_for_account, query_session_revoke_by_hash_unscoped } from './session_queries.js';
|
|
26
|
-
import { query_account_by_username_or_email, query_account_lock_verified, query_update_account_password } from './account_queries.js';
|
|
26
|
+
import { query_account_by_id, query_account_by_username_or_email, query_account_lock_verified, query_update_account_password } from './account_queries.js';
|
|
27
27
|
import { query_revoke_all_api_tokens_for_account } from './api_token_queries.js';
|
|
28
|
-
import {
|
|
28
|
+
import { build_request_context, get_public_account, resolve_acting_actor } from './request_context.js';
|
|
29
29
|
import { resolved_auth_session_hash } from './resolved_auth.js';
|
|
30
30
|
import { attach_route_handler } from '../http/route_spec.js';
|
|
31
31
|
import { route_fail, route_ok } from '../http/route_result.js';
|
|
@@ -49,7 +49,7 @@ import { query_first } from '../http/request_target.js';
|
|
|
49
49
|
* its verification state, and the acting actor's role grants; the route
|
|
50
50
|
* already answers anonymous callers, so that answer is the refusal — a 403
|
|
51
51
|
* would tell the holder nothing that dropping the header doesn't. The handler
|
|
52
|
-
* reads the credential through `
|
|
52
|
+
* reads the credential through `get_public_account`, which applies it.
|
|
53
53
|
*
|
|
54
54
|
* This eliminates the need for a separate `/health` fetch on page load —
|
|
55
55
|
* the frontend gets both session state and bootstrap availability in one request.
|
|
@@ -67,7 +67,7 @@ export const create_account_status_route_spec = (options) => {
|
|
|
67
67
|
path: options?.path ?? account_status_route_shape.path
|
|
68
68
|
}, async (route) => {
|
|
69
69
|
// a narrowed token is the anonymous caller here, never a refusal
|
|
70
|
-
const account_id =
|
|
70
|
+
const account_id = get_public_account(route)?.id;
|
|
71
71
|
if (!account_id)
|
|
72
72
|
return fail_anonymous();
|
|
73
73
|
// Honor a pre-populated request context. The dispatcher's authorization
|
|
@@ -104,33 +104,34 @@ export const create_account_status_route_spec = (options) => {
|
|
|
104
104
|
return route_fail(REST_INVALID_QUERY_PARAMS);
|
|
105
105
|
const acting_raw = query_first(route.query_pairs.value, 'acting');
|
|
106
106
|
const acting = parse_acting(acting_raw);
|
|
107
|
+
// The account read again for the answer, live (`deleted_at IS NULL`),
|
|
108
|
+
// as the Rust twin's summary read is: one deleted or purged since the
|
|
109
|
+
// credential leg is the anonymous caller.
|
|
110
|
+
const account = await query_account_by_id(route, account_id);
|
|
111
|
+
if (!account)
|
|
112
|
+
return fail_anonymous();
|
|
107
113
|
const acting_result = acting_raw !== undefined && acting === undefined
|
|
108
114
|
? null
|
|
109
|
-
: await resolve_acting_actor(route,
|
|
115
|
+
: await resolve_acting_actor(route, account.id, acting);
|
|
110
116
|
if (acting_result?.ok) {
|
|
111
|
-
const ctx = await build_request_context(route,
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
});
|
|
127
|
-
}
|
|
117
|
+
const ctx = await build_request_context(route, account, acting_result.actor);
|
|
118
|
+
const role_grants = ctx.role_grants.map((p) => ({
|
|
119
|
+
id: p.id,
|
|
120
|
+
role: p.role,
|
|
121
|
+
scope_kind: p.scope_kind,
|
|
122
|
+
scope_id: p.scope_id,
|
|
123
|
+
created_at: p.created_at,
|
|
124
|
+
expires_at: p.expires_at,
|
|
125
|
+
granted_by: p.granted_by
|
|
126
|
+
}));
|
|
127
|
+
return route_ok({
|
|
128
|
+
account: to_session_account(ctx.account),
|
|
129
|
+
actor: { id: ctx.actor.id, name: ctx.actor.name },
|
|
130
|
+
role_grants
|
|
131
|
+
});
|
|
128
132
|
}
|
|
129
|
-
const account_ctx = await build_account_context(route, account_id);
|
|
130
|
-
if (!account_ctx)
|
|
131
|
-
return fail_anonymous();
|
|
132
133
|
return route_ok({
|
|
133
|
-
account: to_session_account(
|
|
134
|
+
account: to_session_account(account),
|
|
134
135
|
actor: null,
|
|
135
136
|
role_grants: []
|
|
136
137
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"admin_actions.d.ts","sourceRoot":"","sources":["../../src/lib/auth/admin_actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAuC,KAAK,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAIjG,OAAO,EAKN,KAAK,YAAY,EACjB,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"admin_actions.d.ts","sourceRoot":"","sources":["../../src/lib/auth/admin_actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAuC,KAAK,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAIjG,OAAO,EAKN,KAAK,YAAY,EACjB,MAAM,kBAAkB,CAAC;AAwD1B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AA2D3D,0CAA0C;AAC1C,MAAM,WAAW,kBAAkB;IAClC;;;;;OAKG;IACH,KAAK,CAAC,EAAE,YAAY,CAAC;CACrB;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,oBAAoB,GAChC,MAAM,yBAAyB,EAC/B,UAAS,kBAAuB,KAC9B,KAAK,CAAC,SAAS,CAmpBjB,CAAC"}
|
|
@@ -34,10 +34,11 @@ import { credential_type_required_error } from '../actions/perform_action.js';
|
|
|
34
34
|
import { jsonrpc_errors, ThrownJsonrpcError } from '../http/jsonrpc_errors.js';
|
|
35
35
|
import { builtin_role_specs, list_roles_with_grant_path, ROLE_ADMIN, ROLE_KEEPER } from './role_schema.js';
|
|
36
36
|
import { has_scoped_role } from './request_context.js';
|
|
37
|
-
import { query_account_has_global_role, query_account_has_active_global_role,
|
|
37
|
+
import { query_account_has_global_role, query_account_has_active_global_role, query_count_active_accounts_with_global_role_locked } from './role_grant_queries.js';
|
|
38
38
|
import { GRANT_PATH_ADMIN } from './grant_path_schema.js';
|
|
39
|
-
import { query_role_grant_offer_supersede_incoming, query_role_grant_offer_supersede_outgoing } from './role_grant_offer_queries.js';
|
|
40
|
-
import {
|
|
39
|
+
import { query_role_grant_offer_lock_for_account_removal, query_role_grant_offer_supersede_incoming, query_role_grant_offer_supersede_outgoing } from './role_grant_offer_queries.js';
|
|
40
|
+
import { queue_supersede_notifications } from './role_grant_offer_notifications.js';
|
|
41
|
+
import { query_account_by_email, query_account_by_id, query_account_by_username, query_account_lock_admins_for_purge, query_account_lock_for_purge, query_account_lock_live_many, query_account_soft_delete, query_account_undelete, query_actor_soft_delete, query_actor_undelete, query_actors_by_account, query_admin_account_list, query_purge_account } from './account_queries.js';
|
|
41
42
|
import { query_session_list_all_active, query_session_revoke_all_for_account } from './session_queries.js';
|
|
42
43
|
import { query_revoke_all_api_tokens_for_account } from './api_token_queries.js';
|
|
43
44
|
import { query_audit_log_list_role_grant_history, query_audit_log_list_with_usernames } from './audit_log_queries.js';
|
|
@@ -171,7 +172,7 @@ export const create_admin_actions = (deps, options = {}) => {
|
|
|
171
172
|
// is, as `account_token_create` refuses it — and one still to commit
|
|
172
173
|
// waits on this lock, then deletes the invite with the account's other
|
|
173
174
|
// unclaimed ones: a delete writes its tombstone first.
|
|
174
|
-
if (!(await
|
|
175
|
+
if (!(await query_account_lock_live_many(ctx, [auth.account.id])).has(auth.account.id)) {
|
|
175
176
|
throw jsonrpc_errors.unauthenticated('unauthenticated', {
|
|
176
177
|
reason: ERROR_AUTHENTICATION_REQUIRED
|
|
177
178
|
});
|
|
@@ -258,14 +259,16 @@ export const create_admin_actions = (deps, options = {}) => {
|
|
|
258
259
|
// admin while another active admin exists. Keeper branch above stays
|
|
259
260
|
// unconditional; the last-admin branch fires only for an *active* target.
|
|
260
261
|
if ((await query_account_has_active_global_role(ctx, target_account_id, ROLE_ADMIN)) &&
|
|
261
|
-
(await
|
|
262
|
+
(await query_count_active_accounts_with_global_role_locked(ctx, ROLE_ADMIN)) <= 1) {
|
|
262
263
|
await deny(ERROR_CANNOT_DELETE_LAST_ADMIN, `cannot ${verb} the last admin account`);
|
|
263
264
|
}
|
|
264
265
|
};
|
|
265
266
|
// One `role_grant_offer_supersede` row per offer an account removal ended,
|
|
266
267
|
// `reason: 'account_deleted'` and `cause_id` the removed account, whichever
|
|
267
|
-
// side of the offer the account was on
|
|
268
|
-
|
|
268
|
+
// side of the offer the account was on, then the notification to the offer's
|
|
269
|
+
// other party — `audience`, the side the removed account is not on, with the
|
|
270
|
+
// `cause_id` that side is sent; the account's own connections close with it.
|
|
271
|
+
const emit_account_deleted_supersedes = async (ctx, target_account_id, superseded, audience) => {
|
|
269
272
|
for (const offer of superseded) {
|
|
270
273
|
await deps.audit.emit_role_grant_target(ctx, ctx.auth, {
|
|
271
274
|
event_type: 'role_grant_offer_supersede',
|
|
@@ -280,23 +283,38 @@ export const create_admin_actions = (deps, options = {}) => {
|
|
|
280
283
|
}
|
|
281
284
|
});
|
|
282
285
|
}
|
|
286
|
+
queue_supersede_notifications(ctx, superseded, 'account_deleted', audience);
|
|
283
287
|
};
|
|
288
|
+
// Lock every pending offer the removal supersedes, both directions, in one
|
|
289
|
+
// id-ordered statement before either supersede writes — the order every
|
|
290
|
+
// multi-row offer write takes its rows in
|
|
291
|
+
// (`query_role_grant_offer_lock_for_account_removal` has why).
|
|
292
|
+
const lock_removed_account_offers = (ctx, target_account_id, actors) => query_role_grant_offer_lock_for_account_removal(ctx, target_account_id, actors.map((a) => a.id));
|
|
284
293
|
// Supersede every pending offer the removed account's actors made, audited
|
|
285
294
|
// — the cascade a revoke runs on the revokee's offers. An offer records no
|
|
286
295
|
// authority, so one outliving its grantor's account would still confer on
|
|
287
|
-
// accept.
|
|
288
|
-
//
|
|
296
|
+
// accept. Each recipient is told, sent its grantor's actor as `cause_id` — an
|
|
297
|
+
// id it already holds, where the audit row's is the removed account's; the
|
|
298
|
+
// grantor is the removed account.
|
|
289
299
|
const cancel_outgoing_offers = async (ctx, target_account_id, actors) => {
|
|
290
300
|
const superseded = await query_role_grant_offer_supersede_outgoing(ctx, actors.map((a) => a.id));
|
|
291
|
-
await emit_account_deleted_supersedes(ctx, target_account_id, superseded
|
|
301
|
+
await emit_account_deleted_supersedes(ctx, target_account_id, superseded, {
|
|
302
|
+
grantor: null,
|
|
303
|
+
recipient: { kind: 'from_actor' }
|
|
304
|
+
});
|
|
292
305
|
};
|
|
293
|
-
// Supersede every pending offer made to the
|
|
294
|
-
// actor-addressed, audited as the outgoing cascade is
|
|
295
|
-
//
|
|
296
|
-
//
|
|
306
|
+
// Supersede every pending offer made to the removed account, account- or
|
|
307
|
+
// actor-addressed, audited as the outgoing cascade is, each grantor told,
|
|
308
|
+
// sent the removed account as `cause_id` (the offer's `to_account_id`). An
|
|
309
|
+
// undelete restores a deleted account, so an offer left pending through the
|
|
310
|
+
// delete would come back with it and could be accepted; a purge's cascade
|
|
311
|
+
// would take the offers with no audit row and no word to their grantors.
|
|
297
312
|
const cancel_incoming_offers = async (ctx, target_account_id) => {
|
|
298
313
|
const superseded = await query_role_grant_offer_supersede_incoming(ctx, target_account_id);
|
|
299
|
-
await emit_account_deleted_supersedes(ctx, target_account_id, superseded
|
|
314
|
+
await emit_account_deleted_supersedes(ctx, target_account_id, superseded, {
|
|
315
|
+
grantor: { kind: 'id', id: target_account_id },
|
|
316
|
+
recipient: null
|
|
317
|
+
});
|
|
300
318
|
};
|
|
301
319
|
// Delete the unclaimed invites the removed account's actors issued, each
|
|
302
320
|
// audited as an `invite_delete` is. An invite records no authority, so one
|
|
@@ -319,7 +337,8 @@ export const create_admin_actions = (deps, options = {}) => {
|
|
|
319
337
|
// session-only — enforced here, not on the spec, whose gate stays open so
|
|
320
338
|
// an admin deleting another account keeps any credential. Tombstones the
|
|
321
339
|
// account + its actor(s), supersedes the pending offers its actors made and
|
|
322
|
-
// the ones made to it
|
|
340
|
+
// the ones made to it (each offer's other party told), revokes
|
|
341
|
+
// sessions/tokens, deletes the unclaimed
|
|
323
342
|
// invites its actors issued, closes sockets, and
|
|
324
343
|
// emits `account_delete` + one `actor_delete` per soft-deleted actor —
|
|
325
344
|
// each carrying its identity snapshot. `delete` = soft.
|
|
@@ -359,6 +378,7 @@ export const create_admin_actions = (deps, options = {}) => {
|
|
|
359
378
|
});
|
|
360
379
|
throw jsonrpc_errors.not_found('account', { reason: ERROR_ACCOUNT_NOT_FOUND });
|
|
361
380
|
}
|
|
381
|
+
await lock_removed_account_offers(ctx, target_account_id, actors);
|
|
362
382
|
await cancel_outgoing_offers(ctx, target_account_id, actors);
|
|
363
383
|
await cancel_incoming_offers(ctx, target_account_id);
|
|
364
384
|
const soft_deleted_actors = [];
|
|
@@ -398,7 +418,9 @@ export const create_admin_actions = (deps, options = {}) => {
|
|
|
398
418
|
return { ok: true, deleted: true };
|
|
399
419
|
};
|
|
400
420
|
// Hard-purge an account (keeper-only, irreversible). Fail-loud:
|
|
401
|
-
// requires `confirm: true` + emits a WARN.
|
|
421
|
+
// requires `confirm: true` + emits a WARN. Supersedes the account's pending
|
|
422
|
+
// offers, both ways, as a delete does, before its cascade deletes the rows —
|
|
423
|
+
// the audit rows and the notifications are what remain of them. Snapshots identity into
|
|
402
424
|
// `account_purge` + per-actor `actor_purge` before the cascading delete
|
|
403
425
|
// removes the rows — the `audit_log` id columns carry no FK, so the
|
|
404
426
|
// purged ids survive on historical rows and the snapshots name them.
|
|
@@ -410,18 +432,17 @@ export const create_admin_actions = (deps, options = {}) => {
|
|
|
410
432
|
reason: ERROR_PURGE_NOT_CONFIRMED
|
|
411
433
|
});
|
|
412
434
|
}
|
|
435
|
+
// Every admin's account row and the target's, in one id-ordered statement:
|
|
436
|
+
// the cascade writes admin rows (the grants the target's actors granted).
|
|
437
|
+
// Every other removal's guard and every other purge take those accounts
|
|
438
|
+
// first, and no other writer of an admin's grant waits on an account row
|
|
439
|
+
// while holding one, so holding the accounts orders the purge before any of
|
|
440
|
+
// them (`query_account_lock_admins_for_purge` has why). The last-admin guard
|
|
441
|
+
// then runs only for an admin target, in `assert_account_removable`.
|
|
442
|
+
await query_account_lock_admins_for_purge(ctx, input.account_id);
|
|
413
443
|
// Keeper + last-admin guards (fail-loud, before the cascade).
|
|
414
444
|
await assert_account_removable(ctx, input.account_id, 'account_purge');
|
|
415
|
-
|
|
416
|
-
const actors = await query_actors_by_account(ctx, input.account_id);
|
|
417
|
-
// Before the cascade, whose `ON DELETE CASCADE` would take the offers
|
|
418
|
-
// with no audit row.
|
|
419
|
-
await cancel_outgoing_offers(ctx, input.account_id, actors);
|
|
420
|
-
// Before the cascade too: `invite.created_by` is `ON DELETE SET NULL`, so
|
|
421
|
-
// the cascade would leave the account's unclaimed invites usable.
|
|
422
|
-
await void_unclaimed_invites(ctx, actors);
|
|
423
|
-
const snapshot = await query_purge_account(ctx, input.account_id);
|
|
424
|
-
if (!snapshot) {
|
|
445
|
+
const refuse_not_found = async () => {
|
|
425
446
|
await deps.audit.emit(ctx, {
|
|
426
447
|
event_type: 'account_purge',
|
|
427
448
|
outcome: 'failure',
|
|
@@ -431,7 +452,29 @@ export const create_admin_actions = (deps, options = {}) => {
|
|
|
431
452
|
metadata: { reason: ERROR_ACCOUNT_NOT_FOUND, attempted_account_id: input.account_id }
|
|
432
453
|
});
|
|
433
454
|
throw jsonrpc_errors.not_found('account', { reason: ERROR_ACCOUNT_NOT_FOUND });
|
|
434
|
-
}
|
|
455
|
+
};
|
|
456
|
+
// The account row before any write, as every writer of the account takes
|
|
457
|
+
// it — `query_account_lock_for_purge` has why.
|
|
458
|
+
if (!(await query_account_lock_for_purge(ctx, input.account_id)))
|
|
459
|
+
await refuse_not_found();
|
|
460
|
+
// Snapshot actors before the cascade removes them.
|
|
461
|
+
const actors = await query_actors_by_account(ctx, input.account_id);
|
|
462
|
+
// Before the cascade, whose `ON DELETE CASCADE` would take the offers
|
|
463
|
+
// with no audit row and no notification, the ones the account made and
|
|
464
|
+
// the ones made to it. After the account row: an offer create from or to
|
|
465
|
+
// the account takes that row first, so it has committed or waits.
|
|
466
|
+
await lock_removed_account_offers(ctx, input.account_id, actors);
|
|
467
|
+
await cancel_outgoing_offers(ctx, input.account_id, actors);
|
|
468
|
+
await cancel_incoming_offers(ctx, input.account_id);
|
|
469
|
+
// Before the cascade too: `invite.created_by` is `ON DELETE SET NULL`, so
|
|
470
|
+
// the cascade would leave the account's unclaimed invites usable.
|
|
471
|
+
await void_unclaimed_invites(ctx, actors);
|
|
472
|
+
// Before the cascade as well: it would delete the account's sessions and
|
|
473
|
+
// tokens in its own plan's order, against a revoke or a sweep of the
|
|
474
|
+
// same rows taking them in id order — the order these take them in.
|
|
475
|
+
await query_session_revoke_all_for_account(ctx, input.account_id);
|
|
476
|
+
await query_revoke_all_api_tokens_for_account(ctx, input.account_id);
|
|
477
|
+
const snapshot = (await query_purge_account(ctx, input.account_id)) ?? (await refuse_not_found());
|
|
435
478
|
// The cascade removed every credential of the account; its connections
|
|
436
479
|
// close once that has committed.
|
|
437
480
|
queue_connection_close(ctx, connection_closer, {
|
|
@@ -94,6 +94,12 @@ export declare const query_api_token_live_account: (deps: QueryDeps, id: string)
|
|
|
94
94
|
/**
|
|
95
95
|
* Revoke all tokens for an account.
|
|
96
96
|
*
|
|
97
|
+
* Locks its rows in id order before it deletes them (`ORDER BY id FOR
|
|
98
|
+
* UPDATE`), as the cap's eviction (`query_api_token_enforce_limit`) does, so
|
|
99
|
+
* the two reaching the same rows wait one on the other instead of
|
|
100
|
+
* deadlocking in the opposite orders their plans would otherwise walk. Twin
|
|
101
|
+
* of the Rust `fuz_auth::query_revoke_all_api_tokens_for_account`.
|
|
102
|
+
*
|
|
97
103
|
* @param deps - query dependencies
|
|
98
104
|
* @param account_id - the account whose tokens to revoke
|
|
99
105
|
* @returns the number of tokens revoked
|
|
@@ -126,14 +132,16 @@ export declare const query_api_token_list_for_account: (deps: QueryDeps, account
|
|
|
126
132
|
* spec declares `side_effects: true`, making one creator's INSERT +
|
|
127
133
|
* enforce_limit pair atomic. That does **not** serialize concurrent creators:
|
|
128
134
|
* under Read Committed, two transactions can't see each other's uncommitted
|
|
129
|
-
* token row, so each
|
|
130
|
-
* `max_tokens`.
|
|
131
|
-
* `
|
|
132
|
-
*
|
|
135
|
+
* token row, so each would evict against a stale count and both commit above
|
|
136
|
+
* `max_tokens`. The handler serializes them first, taking the account row
|
|
137
|
+
* `FOR NO KEY UPDATE` (`query_account_lock_live`) — see the matching note on
|
|
138
|
+
* `query_session_enforce_limit`.
|
|
133
139
|
*
|
|
134
140
|
* Ordering carries the same `id DESC` stability tie-breaker, with the same
|
|
135
141
|
* caveat, as `query_session_enforce_limit` — deterministic survivors under a
|
|
136
|
-
* `created_at` tie, not a guarantee that the row just inserted survives.
|
|
142
|
+
* `created_at` tie, not a guarantee that the row just inserted survives. The
|
|
143
|
+
* victims are locked in id order before the delete, as the revoke-all
|
|
144
|
+
* (`query_revoke_all_api_tokens_for_account`) locks its rows.
|
|
137
145
|
*
|
|
138
146
|
* Deleting a token row does not end the connections it opened, so the
|
|
139
147
|
* returned ids are what the caller closes once the transaction commits
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api_token_queries.d.ts","sourceRoot":"","sources":["../../src/lib/auth/api_token_queries.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAGpD,OAAO,EAAE,KAAK,UAAU,EAAmD,MAAM,kBAAkB,CAAC;AAEpG;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG;IACzD,KAAK,EAAE,UAAU,CAAC;IAClB;;;;;OAKG;IACH,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,CAAC;AAEF,yEAAyE;AACzE,MAAM,WAAW,iBAAkB,SAAQ,SAAS;IACnD,GAAG,EAAE,MAAM,CAAC;CACZ;AAED;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,0HAUoB,CAAC;AA6BnD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,sBAAsB,GAClC,MAAM,SAAS,EACf,IAAI,MAAM,EACV,YAAY,MAAM,EAClB,MAAM,MAAM,EACZ,YAAY,MAAM,EAClB,OAAO,UAAU,EACjB,aAAa,IAAI,GAAG,IAAI,KACtB,OAAO,CAAC,QAAQ,CAelB,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,wBAAwB,GACpC,MAAM,iBAAiB,EACvB,WAAW,MAAM,KACf,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAsBvC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,qBAAqB,GACjC,MAAM,SAAS,EACf,IAAI,MAAM,EACV,IAAI,MAAM,GAAG,SAAS,KACpB,OAAO,CAAC,IAAI,CAKd,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,4BAA4B,GACxC,MAAM,SAAS,EACf,IAAI,MAAM,KACR,OAAO,CAAC,MAAM,GAAG,SAAS,CAM5B,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"api_token_queries.d.ts","sourceRoot":"","sources":["../../src/lib/auth/api_token_queries.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAGpD,OAAO,EAAE,KAAK,UAAU,EAAmD,MAAM,kBAAkB,CAAC;AAEpG;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG;IACzD,KAAK,EAAE,UAAU,CAAC;IAClB;;;;;OAKG;IACH,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,CAAC;AAEF,yEAAyE;AACzE,MAAM,WAAW,iBAAkB,SAAQ,SAAS;IACnD,GAAG,EAAE,MAAM,CAAC;CACZ;AAED;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,0HAUoB,CAAC;AA6BnD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,sBAAsB,GAClC,MAAM,SAAS,EACf,IAAI,MAAM,EACV,YAAY,MAAM,EAClB,MAAM,MAAM,EACZ,YAAY,MAAM,EAClB,OAAO,UAAU,EACjB,aAAa,IAAI,GAAG,IAAI,KACtB,OAAO,CAAC,QAAQ,CAelB,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,wBAAwB,GACpC,MAAM,iBAAiB,EACvB,WAAW,MAAM,KACf,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAsBvC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,qBAAqB,GACjC,MAAM,SAAS,EACf,IAAI,MAAM,EACV,IAAI,MAAM,GAAG,SAAS,KACpB,OAAO,CAAC,IAAI,CAKd,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,4BAA4B,GACxC,MAAM,SAAS,EACf,IAAI,MAAM,KACR,OAAO,CAAC,MAAM,GAAG,SAAS,CAM5B,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,uCAAuC,GACnD,MAAM,SAAS,EACf,YAAY,MAAM,KAChB,OAAO,CAAC,MAAM,CAQhB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,kCAAkC,GAC9C,MAAM,SAAS,EACf,IAAI,MAAM,EACV,YAAY,MAAM,KAChB,OAAO,CAAC,OAAO,CAMjB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,gCAAgC,GAC5C,MAAM,SAAS,EACf,YAAY,MAAM,KAChB,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC,CAM7C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,6BAA6B,GACzC,MAAM,SAAS,EACf,YAAY,MAAM,EAClB,YAAY,MAAM,KAChB,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAiBvB,CAAC"}
|