@fuzdev/fuz_app 0.181.0 → 0.183.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/README.md +2 -0
- package/dist/actions/CLAUDE.md +28 -10
- 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 +113 -70
- 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 +6 -4
- package/dist/auth/account_routes.d.ts.map +1 -1
- package/dist/auth/account_routes.js +98 -92
- package/dist/auth/admin_actions.d.ts.map +1 -1
- package/dist/auth/admin_actions.js +93 -45
- 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/audit_emitter.d.ts +75 -84
- package/dist/auth/audit_emitter.d.ts.map +1 -1
- package/dist/auth/audit_emitter.js +83 -71
- package/dist/auth/audit_log_schema.d.ts +10 -5
- package/dist/auth/audit_log_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_schema.js +22 -6
- package/dist/auth/bearer_auth.d.ts.map +1 -1
- package/dist/auth/bearer_auth.js +3 -2
- package/dist/auth/bootstrap_account.d.ts +31 -13
- package/dist/auth/bootstrap_account.d.ts.map +1 -1
- package/dist/auth/bootstrap_account.js +34 -15
- package/dist/auth/bootstrap_routes.d.ts +1 -1
- package/dist/auth/bootstrap_routes.d.ts.map +1 -1
- package/dist/auth/bootstrap_routes.js +7 -14
- 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 +18 -5
- package/dist/auth/deps.d.ts.map +1 -1
- package/dist/auth/deps.js +3 -2
- 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 +16 -11
- package/dist/auth/resolved_auth.d.ts.map +1 -1
- package/dist/auth/resolved_auth.js +6 -6
- 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 +32 -12
- package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_actions.js +91 -116
- 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 +155 -18
- package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_queries.js +262 -73
- package/dist/auth/role_grant_offer_schema.js +1 -1
- package/dist/auth/role_grant_queries.d.ts +43 -52
- package/dist/auth/role_grant_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_queries.js +50 -74
- 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 +17 -21
- package/dist/auth/session_queries.d.ts +40 -16
- package/dist/auth/session_queries.d.ts.map +1 -1
- package/dist/auth/session_queries.js +68 -29
- package/dist/auth/signup_routes.d.ts.map +1 -1
- package/dist/auth/signup_routes.js +90 -38
- 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/db/sql_columns.d.ts +1 -1
- package/dist/db/sql_columns.js +1 -1
- package/dist/http/CLAUDE.md +22 -16
- package/dist/http/auth_shape.d.ts +1 -1
- package/dist/http/db_routes.d.ts +7 -22
- package/dist/http/db_routes.d.ts.map +1 -1
- package/dist/http/db_routes.js +72 -72
- 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/pending_effects.d.ts +42 -4
- package/dist/http/pending_effects.d.ts.map +1 -1
- package/dist/http/pending_effects.js +34 -4
- 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 +69 -18
- package/dist/server/app_server.d.ts.map +1 -1
- package/dist/server/app_server.js +74 -10
- package/dist/server/serve_fact_route.d.ts +3 -3
- package/dist/server/serve_fact_route.js +12 -12
- package/dist/testing/CLAUDE.md +259 -790
- package/dist/testing/adversarial_404.d.ts +6 -1
- package/dist/testing/adversarial_404.d.ts.map +1 -1
- package/dist/testing/adversarial_404.js +38 -17
- package/dist/testing/app_server.d.ts +20 -140
- package/dist/testing/app_server.d.ts.map +1 -1
- package/dist/testing/app_server.js +48 -125
- package/dist/testing/audit_drift_guard.d.ts +11 -6
- package/dist/testing/audit_drift_guard.d.ts.map +1 -1
- package/dist/testing/audit_drift_guard.js +15 -8
- 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/audit_cross_helpers.d.ts +12 -9
- package/dist/testing/cross_backend/audit_cross_helpers.d.ts.map +1 -1
- package/dist/testing/cross_backend/audit_cross_helpers.js +13 -14
- package/dist/testing/cross_backend/capabilities.d.ts +9 -6
- package/dist/testing/cross_backend/capabilities.d.ts.map +1 -1
- package/dist/testing/cross_backend/capabilities.js +11 -7
- package/dist/testing/cross_backend/capability_mounts.d.ts +103 -0
- package/dist/testing/cross_backend/capability_mounts.d.ts.map +1 -0
- package/dist/testing/cross_backend/capability_mounts.js +423 -0
- package/dist/testing/cross_backend/cell_moderate.js +2 -2
- package/dist/testing/cross_backend/cell_relations.d.ts.map +1 -1
- package/dist/testing/cross_backend/cell_relations.js +12 -11
- package/dist/testing/cross_backend/conformance_principal.d.ts +54 -0
- package/dist/testing/cross_backend/conformance_principal.d.ts.map +1 -0
- package/dist/testing/cross_backend/conformance_principal.js +283 -0
- package/dist/testing/cross_backend/conformance_table.d.ts +2 -50
- package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_table.js +2 -270
- package/dist/testing/cross_backend/credential_deadline.d.ts.map +1 -1
- package/dist/testing/cross_backend/credential_deadline.js +2 -0
- package/dist/testing/cross_backend/credential_wire.d.ts +1 -1
- package/dist/testing/cross_backend/credential_wire.d.ts.map +1 -1
- package/dist/testing/cross_backend/db_state_diff.d.ts +72 -0
- package/dist/testing/cross_backend/db_state_diff.d.ts.map +1 -0
- package/dist/testing/cross_backend/db_state_diff.js +444 -0
- package/dist/testing/cross_backend/declared_skips.d.ts +68 -0
- package/dist/testing/cross_backend/declared_skips.d.ts.map +1 -0
- package/dist/testing/cross_backend/declared_skips.js +132 -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/differential.d.ts +11 -2
- package/dist/testing/cross_backend/differential.d.ts.map +1 -1
- package/dist/testing/cross_backend/differential.js +35 -11
- package/dist/testing/cross_backend/differential_normalize.d.ts +12 -0
- package/dist/testing/cross_backend/differential_normalize.d.ts.map +1 -1
- package/dist/testing/cross_backend/differential_normalize.js +16 -0
- 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/in_process_setup.d.ts +22 -12
- package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/in_process_setup.js +151 -134
- package/dist/testing/cross_backend/login_security.d.ts +12 -0
- package/dist/testing/cross_backend/login_security.d.ts.map +1 -1
- package/dist/testing/cross_backend/login_security.js +21 -4
- package/dist/testing/cross_backend/request_target_conformance_wire.d.ts +0 -2
- package/dist/testing/cross_backend/request_target_conformance_wire.d.ts.map +1 -1
- package/dist/testing/cross_backend/request_target_conformance_wire.js +3 -1
- package/dist/testing/cross_backend/revocation_drivers.d.ts +18 -5
- package/dist/testing/cross_backend/revocation_drivers.d.ts.map +1 -1
- package/dist/testing/cross_backend/revocation_drivers.js +18 -10
- package/dist/testing/cross_backend/role_grant_cross_helpers.d.ts +1 -1
- package/dist/testing/cross_backend/role_grant_cross_helpers.d.ts.map +1 -1
- package/dist/testing/cross_backend/role_grant_offer_lifecycle.d.ts.map +1 -1
- package/dist/testing/cross_backend/role_grant_offer_lifecycle.js +33 -1
- 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/role_grant_participation.js +4 -4
- package/dist/testing/cross_backend/rpc_adversarial.js +1 -1
- package/dist/testing/cross_backend/session_cap.d.ts +2 -2
- package/dist/testing/cross_backend/session_cap.d.ts.map +1 -1
- package/dist/testing/cross_backend/session_cap.js +48 -16
- package/dist/testing/cross_backend/setup.d.ts +31 -1
- package/dist/testing/cross_backend/setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/setup.js +32 -1
- package/dist/testing/cross_backend/spine_suites.d.ts +123 -12
- package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_suites.js +454 -57
- package/dist/testing/cross_backend/spine_surface_constants.d.ts +1 -1
- package/dist/testing/cross_backend/spine_surface_constants.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_surface_constants.js +1 -0
- package/dist/testing/cross_backend/sse_round_trip.d.ts +9 -1
- package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/sse_round_trip.js +123 -27
- package/dist/testing/cross_backend/testing_backdoor.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_backdoor.js +4 -2
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +59 -27
- package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_reset_actions.js +66 -42
- package/dist/testing/cross_backend/transport_composition.d.ts +1 -1
- package/dist/testing/cross_backend/transport_composition.d.ts.map +1 -1
- package/dist/testing/cross_backend/transport_composition.js +7 -3
- package/dist/testing/cross_backend/ws_round_trip.d.ts +5 -0
- package/dist/testing/cross_backend/ws_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_round_trip.js +54 -8
- package/dist/testing/data_exposure.d.ts.map +1 -1
- package/dist/testing/data_exposure.js +3 -0
- package/dist/testing/db.d.ts +0 -32
- package/dist/testing/db.d.ts.map +1 -1
- package/dist/testing/db.js +0 -86
- package/dist/testing/db_entities.d.ts +14 -0
- package/dist/testing/db_entities.d.ts.map +1 -1
- package/dist/testing/db_entities.js +17 -0
- package/dist/testing/db_invariant_queries.d.ts +259 -0
- package/dist/testing/db_invariant_queries.d.ts.map +1 -0
- package/dist/testing/db_invariant_queries.js +400 -0
- package/dist/testing/db_invariants.d.ts +106 -0
- package/dist/testing/db_invariants.d.ts.map +1 -0
- package/dist/testing/db_invariants.gen.sql.d.ts +11 -0
- package/dist/testing/db_invariants.gen.sql.d.ts.map +1 -0
- package/dist/testing/db_invariants.gen.sql.js +13 -0
- package/dist/testing/db_invariants.js +141 -0
- package/dist/testing/db_invariants.sql +152 -0
- package/dist/testing/describe_db.d.ts +36 -0
- package/dist/testing/describe_db.d.ts.map +1 -0
- package/dist/testing/describe_db.js +71 -0
- package/dist/testing/integration.d.ts +6 -9
- package/dist/testing/integration.d.ts.map +1 -1
- package/dist/testing/integration.js +9 -13
- package/dist/testing/integration_helpers.d.ts +1 -1
- package/dist/testing/integration_helpers.d.ts.map +1 -1
- package/dist/testing/middleware.d.ts +1 -1
- package/dist/testing/middleware.js +5 -5
- package/dist/testing/rate_limiting.d.ts +1 -1
- package/dist/testing/rate_limiting.d.ts.map +1 -1
- package/dist/testing/rate_limiting.js +3 -2
- 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/role_grant_helpers.d.ts +1 -1
- package/dist/testing/role_grant_helpers.d.ts.map +1 -1
- package/dist/testing/round_trip.d.ts.map +1 -1
- package/dist/testing/round_trip.js +3 -0
- package/dist/testing/rpc_attack_surface.d.ts +8 -6
- package/dist/testing/rpc_attack_surface.d.ts.map +1 -1
- package/dist/testing/rpc_attack_surface.js +69 -6
- package/dist/testing/rpc_round_trip.d.ts +1 -1
- package/dist/testing/rpc_round_trip.d.ts.map +1 -1
- package/dist/testing/rpc_round_trip.js +3 -0
- package/dist/testing/sse_round_trip.d.ts +1 -1
- package/dist/testing/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/sse_round_trip.js +13 -4
- package/dist/testing/stubs.d.ts +4 -2
- package/dist/testing/stubs.d.ts.map +1 -1
- package/dist/testing/stubs.js +15 -7
- package/dist/testing/test_app.d.ts +166 -0
- package/dist/testing/test_app.d.ts.map +1 -0
- package/dist/testing/test_app.js +124 -0
- 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
|
@@ -42,8 +42,8 @@ export declare const query_create_account: (deps: QueryDeps, input: CreateAccoun
|
|
|
42
42
|
/**
|
|
43
43
|
* Find an **active** account by id (`deleted_at IS NULL`).
|
|
44
44
|
*
|
|
45
|
-
* This is the auth-resolution workhorse (
|
|
46
|
-
*
|
|
45
|
+
* This is the auth-resolution workhorse (every credential leg reads the
|
|
46
|
+
* account through it) and the admin-target lookup, so it
|
|
47
47
|
* deliberately excludes soft-deleted accounts: a tombstoned account must
|
|
48
48
|
* not authenticate (`delete` = soft, `purge` = hard). Purge, which must operate on
|
|
49
49
|
* soft-deleted rows too, uses `query_purge_account` directly.
|
|
@@ -110,9 +110,24 @@ export declare const query_update_account_password: (deps: QueryDeps, id: string
|
|
|
110
110
|
* writers write the account row before they revoke, which is what makes the
|
|
111
111
|
* lock order them.
|
|
112
112
|
*
|
|
113
|
-
* `FOR
|
|
114
|
-
*
|
|
115
|
-
*
|
|
113
|
+
* `FOR NO KEY UPDATE`, the strength of their `UPDATE`s, so it also conflicts
|
|
114
|
+
* with itself: the mints of one account take turns. The session cap needs
|
|
115
|
+
* that. A mint inserts its session and evicts the oldest past the cap in one
|
|
116
|
+
* transaction, and two mints running together each count without the other's
|
|
117
|
+
* uncommitted row — both commit above the cap — while their evictions lock
|
|
118
|
+
* the same old rows in orders the query plan picks, and can deadlock. Taken
|
|
119
|
+
* in turn, the second mint runs its statements after the first commits and
|
|
120
|
+
* counts its row. The foreign-key `FOR KEY SHARE` of a row inserted under the
|
|
121
|
+
* account does not conflict with it, so no write that merely references the
|
|
122
|
+
* account waits on a login. Besides the writers it orders against, it
|
|
123
|
+
* conflicts with `query_account_lock_live` (the token mint, the same
|
|
124
|
+
* strength), the `FOR SHARE` of `query_account_lock_live_many` (an offer or
|
|
125
|
+
* invite create), an offer accept's locks (`query_account_lock_for_offer_accept`,
|
|
126
|
+
* the recipient's at this strength, a grantor's shared), and the last-admin
|
|
127
|
+
* guard's `FOR NO KEY UPDATE`. None of
|
|
128
|
+
* those waits on an account row while holding a session row, and once a mint
|
|
129
|
+
* holds the lock it waits on nothing but the session rows its eviction
|
|
130
|
+
* deletes, so no cycle runs through it. Twin of the Rust
|
|
116
131
|
* `fuz_auth::query_account_lock_verified`.
|
|
117
132
|
*
|
|
118
133
|
* @param deps - query dependencies (must be the mint's transaction)
|
|
@@ -130,13 +145,13 @@ export declare const query_account_lock_verified: (deps: QueryDeps, id: string,
|
|
|
130
145
|
* token before the new one exists. Run first in the mint's transaction, this
|
|
131
146
|
* read waits on the delete's row lock and then sees its tombstone; once it
|
|
132
147
|
* holds the lock, a delete waits for the mint to commit and then revokes the
|
|
133
|
-
* token. The password is not re-checked: the mint verified none.
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
* `
|
|
148
|
+
* token. The password is not re-checked: the mint verified none. Taken
|
|
149
|
+
* `FOR NO KEY UPDATE` for the token cap, as the login's lock is for the session
|
|
150
|
+
* cap — `query_account_lock_verified` has why, and what it conflicts with; a
|
|
151
|
+
* token mint and a login of one account take turns too. A write that only
|
|
152
|
+
* needs ordering against a delete takes `query_account_lock_live_many`, which
|
|
153
|
+
* lets such writes run together. Twin of the Rust
|
|
154
|
+
* `fuz_auth::query_account_lock_live`.
|
|
140
155
|
*
|
|
141
156
|
* @param deps - query dependencies (must be the mint's transaction)
|
|
142
157
|
* @param id - the account the credential is for
|
|
@@ -144,13 +159,96 @@ export declare const query_account_lock_verified: (deps: QueryDeps, id: string,
|
|
|
144
159
|
*/
|
|
145
160
|
export declare const query_account_lock_live: (deps: QueryDeps, id: string) => Promise<boolean>;
|
|
146
161
|
/**
|
|
147
|
-
* Lock
|
|
148
|
-
*
|
|
149
|
-
*
|
|
162
|
+
* Lock, for a purge, the account rows of every holder of an unrevoked global
|
|
163
|
+
* `admin` grant and the purged account's own, in one statement, in id order,
|
|
164
|
+
* `FOR NO KEY UPDATE`.
|
|
165
|
+
*
|
|
166
|
+
* A purge's cascade writes rows of other accounts: it sets null the
|
|
167
|
+
* `granted_by` and `revoked_by` of every grant the purged account's actors
|
|
168
|
+
* named, admins' grants among them, in whatever order the plan walks them. A
|
|
169
|
+
* last-admin guard of another removal takes admin accounts, actors and grants
|
|
170
|
+
* in account-id order. A purge reaching an admin's grant before the guard does
|
|
171
|
+
* and waiting on one the guard took could hold a row the guard waits on.
|
|
172
|
+
* Holding every admin's account first, in the order the guard and
|
|
173
|
+
* `query_account_lock_live_many` take account rows, another guard waits at its
|
|
174
|
+
* first account holding nothing, and two purges take turns. The purged
|
|
175
|
+
* account's row is taken in the same statement, so an offer create holding one
|
|
176
|
+
* of these rows `FOR SHARE` and waiting on another meets them in the same order.
|
|
177
|
+
* No `deleted_at` filter on either: a tombstoned admin's grant is written by
|
|
178
|
+
* the cascade as well, and a purge removes a tombstoned account. The admins
|
|
179
|
+
* are those the statement's snapshot sees; one made by a transaction that
|
|
180
|
+
* commits after it starts is not among them. Cost: a purge waits behind
|
|
181
|
+
* admins' logins, token creates and offers. Run first in the purge's
|
|
182
|
+
* transaction, before the last-admin guard (an admin target's only) and
|
|
183
|
+
* `query_account_lock_for_purge`.
|
|
184
|
+
* Twin of the Rust `fuz_auth::account_queries::query_account_lock_admins_for_purge`.
|
|
185
|
+
*
|
|
186
|
+
* @param deps - query dependencies (must be the purge's transaction)
|
|
187
|
+
* @param id - the account to purge
|
|
188
|
+
*/
|
|
189
|
+
export declare const query_account_lock_admins_for_purge: (deps: QueryDeps, id: string) => Promise<void>;
|
|
190
|
+
/**
|
|
191
|
+
* Lock the account row of a revoke's revokee, by its actor, tombstoned or not,
|
|
192
|
+
* `FOR NO KEY UPDATE`.
|
|
193
|
+
*
|
|
194
|
+
* Every revoke of a grant takes it, before it locks the offers it supersedes
|
|
195
|
+
* and before it updates the grant. It keeps those offers from growing: an offer
|
|
196
|
+
* to or from the account takes the row `FOR SHARE`
|
|
197
|
+
* (`query_account_lock_live_many`), so none is made while the revoke runs, and
|
|
198
|
+
* an accept by the account takes it `FOR NO KEY UPDATE`
|
|
199
|
+
* (`query_account_lock_for_offer_accept`), so none claims one. And it is the
|
|
200
|
+
* lock an accept of an offer from the revokee is ordered by: the accept reads
|
|
201
|
+
* its grantor's authority under the grantor's account row, and a revoke of that
|
|
202
|
+
* authority takes the row here whether or not its last-admin guard ran (the
|
|
203
|
+
* guard runs only while the account holds an active global `admin`). A revoke
|
|
204
|
+
* of an admin grant takes it after the guard, which holds it already among the
|
|
205
|
+
* admins' rows in id order. Twin of the Rust
|
|
206
|
+
* `fuz_auth::account_queries::query_account_lock_for_revoke`.
|
|
207
|
+
*
|
|
208
|
+
* @param deps - query dependencies (must be the revoke's transaction)
|
|
209
|
+
* @param actor_id - the revokee actor
|
|
210
|
+
*/
|
|
211
|
+
export declare const query_account_lock_for_revoke: (deps: QueryDeps, actor_id: string) => Promise<void>;
|
|
212
|
+
/**
|
|
213
|
+
* Lock an account row for its purge, tombstoned or not.
|
|
214
|
+
*
|
|
215
|
+
* Every writer of an account takes the account row before its other rows — a
|
|
216
|
+
* credential mint its lock, a password change or a delete its `UPDATE` — and a
|
|
217
|
+
* purge takes it first as well, ahead of the credential rows its revokes and
|
|
218
|
+
* its cascade delete. A purge reaching the row only at its `DELETE` would hold
|
|
219
|
+
* the account's sessions and tokens while waiting on a writer that holds the
|
|
220
|
+
* row and goes on to those same rows: a login evicting at the cap, a password
|
|
221
|
+
* change or a delete revoking. `FOR UPDATE`, the lock the purge's `DELETE`
|
|
222
|
+
* takes anyway: it conflicts with every other lock on the row, so a writer
|
|
223
|
+
* holding one is waited out, and a writer arriving later waits for the purge
|
|
224
|
+
* and then finds no row. No `deleted_at` filter — a purge removes a tombstoned
|
|
225
|
+
* account too. Run after `query_account_lock_admins_for_purge`, which takes the
|
|
226
|
+
* row `FOR NO KEY UPDATE` among every admin's in id order, and, for an admin
|
|
227
|
+
* target, the last-admin guard, so this only strengthens a lock the purge
|
|
228
|
+
* already holds. Twin of the Rust
|
|
229
|
+
* `fuz_auth::account_queries::query_account_lock_for_purge`.
|
|
230
|
+
*
|
|
231
|
+
* @param deps - query dependencies (must be the purge's transaction)
|
|
232
|
+
* @param id - the account to purge
|
|
233
|
+
* @returns `true` when the row is locked, `false` when there is no such account
|
|
234
|
+
*/
|
|
235
|
+
export declare const query_account_lock_for_purge: (deps: QueryDeps, id: string) => Promise<boolean>;
|
|
236
|
+
/**
|
|
237
|
+
* Lock live account rows in one statement, in id order, for a write that must
|
|
238
|
+
* be ordered against a delete of any of them.
|
|
239
|
+
*
|
|
240
|
+
* An offer locks its two parties (`query_role_grant_offer_create`), an invite
|
|
241
|
+
* its issuer (`invite_create`, one id).
|
|
242
|
+
*
|
|
243
|
+
* `FOR SHARE`: the weakest lock that conflicts with a delete's `UPDATE` of the
|
|
244
|
+
* row, so these writes don't wait on one another. It also waits on a
|
|
245
|
+
* credential mint's `FOR NO KEY UPDATE` (`query_account_lock_verified`), and a
|
|
246
|
+
* mint waits on it — but a mint holding its lock waits on no row these writes
|
|
247
|
+
* hold.
|
|
150
248
|
*
|
|
151
249
|
* The rows are locked as the sort returns them, so every caller takes them in
|
|
152
250
|
* id order, as the last-admin guard
|
|
153
|
-
* (`
|
|
251
|
+
* (`query_count_active_accounts_with_global_role_locked`) takes its
|
|
154
252
|
* account rows: two transactions locking two of the same accounts never wait
|
|
155
253
|
* on each other in opposite orders. Taken one statement per account, an offer
|
|
156
254
|
* between two admins could hold one party's row while the guard held the
|
|
@@ -165,6 +263,50 @@ export declare const query_account_lock_live: (deps: QueryDeps, id: string) => P
|
|
|
165
263
|
* @returns the ids locked: those of the accounts neither deleted nor tombstoned
|
|
166
264
|
*/
|
|
167
265
|
export declare const query_account_lock_live_many: (deps: QueryDeps, ids: ReadonlyArray<string>) => Promise<Set<string>>;
|
|
266
|
+
/**
|
|
267
|
+
* Lock the account rows an offer accept is ordered by, in id order: the
|
|
268
|
+
* recipient's `FOR NO KEY UPDATE`, and — when the offer confers the global
|
|
269
|
+
* `admin` its grantor must still hold — the grantor's `FOR SHARE`.
|
|
270
|
+
*
|
|
271
|
+
* The recipient's lock is a credential mint's strength
|
|
272
|
+
* (`query_account_lock_verified`), so it conflicts with itself: two accepts
|
|
273
|
+
* by one recipient take turns, and the second claims after the first has
|
|
274
|
+
* superseded its siblings. It conflicts with a delete's or a purge's first
|
|
275
|
+
* write of the account (the soft-delete `UPDATE`,
|
|
276
|
+
* `query_account_lock_admins_for_purge`, the last-admin guard), so a removal of
|
|
277
|
+
* the recipient waits here or is waited for whole, and never meets the accept
|
|
278
|
+
* at its offers or its actor; with a revoke's `query_account_lock_for_revoke`,
|
|
279
|
+
* so a revoke of the recipient's grant and the accept take turns; and with
|
|
280
|
+
* `query_account_lock_live_many`, so no offer to the recipient is made or
|
|
281
|
+
* refreshed while the accept holds it. Cost: an accept waits behind the
|
|
282
|
+
* recipient's own logins and token mints, which take the same lock.
|
|
283
|
+
*
|
|
284
|
+
* The grantor's share lock is what the grantor's authority is read under (an
|
|
285
|
+
* unlocked read after this one): every write that ends a grantor's global
|
|
286
|
+
* `admin` takes the grantor's account row first — a revoke of the grant through
|
|
287
|
+
* `query_account_lock_for_revoke` (whether or not its last-admin guard ran), a
|
|
288
|
+
* delete through its write of the row, a purge through
|
|
289
|
+
* `query_account_lock_admins_for_purge` and `query_account_lock_for_purge` — so
|
|
290
|
+
* it either commits before the read, which sees it, or waits for the accept to
|
|
291
|
+
* commit. A share lock on the account,
|
|
292
|
+
* not on the grant, so a purge's cascade reaching the grant (its `granted_by`
|
|
293
|
+
* naming an actor of the purged account) never waits on the accept.
|
|
294
|
+
*
|
|
295
|
+
* Two statements, as the two strengths can't share one locking clause, the
|
|
296
|
+
* lower id first — the order the last-admin guard
|
|
297
|
+
* (`query_count_active_accounts_with_global_role_locked`) and
|
|
298
|
+
* `query_account_lock_live_many` take account rows in — so an accept and a
|
|
299
|
+
* guard over an admin recipient and its grantor never wait on each other in
|
|
300
|
+
* opposite orders. Neither is filtered on the grantor's tombstone: the
|
|
301
|
+
* authority read judges it. Twin of the Rust
|
|
302
|
+
* `fuz_auth::query_account_lock_for_offer_accept`.
|
|
303
|
+
*
|
|
304
|
+
* @param deps - query dependencies (must be the accept's transaction)
|
|
305
|
+
* @param recipient_id - the accepting account
|
|
306
|
+
* @param grantor_id - the grantor's account, or `null` when the offer needs no grantor authority
|
|
307
|
+
* @returns `true` when the recipient's row is locked and live, `false` when it was deleted or tombstoned
|
|
308
|
+
*/
|
|
309
|
+
export declare const query_account_lock_for_offer_accept: (deps: QueryDeps, recipient_id: string, grantor_id: string | null) => Promise<boolean>;
|
|
168
310
|
/**
|
|
169
311
|
* Identifying values snapshotted into a deletion/purge audit event so the
|
|
170
312
|
* identity behind a now-orphaned `audit_log` id isn't lost. Mirrors the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account_queries.d.ts","sourceRoot":"","sources":["../../src/lib/auth/account_queries.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAQrD,OAAO,EAEN,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC1B,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"account_queries.d.ts","sourceRoot":"","sources":["../../src/lib/auth/account_queries.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAQrD,OAA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E,OAAO,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,CAI5C,CAAC;AAgDF,8CAA8C;AAC9C,MAAM,WAAW,uBAAuB;IACvC;;;;;OAKG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,wCAAwC;IACxC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB;;;;;OAKG;IACH,eAAe,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CACjC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,wBAAwB,GACpC,MAAM,SAAS,EACf,UAAU,uBAAuB,KAC/B,OAAO,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAkHtC,CAAC"}
|
|
@@ -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.
|
|
@@ -140,14 +140,16 @@ export interface AccountRouteOptions extends AuthSessionRouteOptions {
|
|
|
140
140
|
* every account surface serves it, matching the Rust `account_router`.
|
|
141
141
|
* Self-service session/token management is on `auth/account_actions.ts`.
|
|
142
142
|
*
|
|
143
|
-
* `/login` closes the connections of the sessions its cap evicts,
|
|
144
|
-
*
|
|
143
|
+
* `/login` closes the connections of the sessions its cap evicts, `/logout`
|
|
144
|
+
* those of the session it ends, and `/password` the account's, each once its revocation has
|
|
145
145
|
* committed: `/logout` through the route transaction's post-commit queue
|
|
146
146
|
* (`queue_connection_close`), `/login` and `/password` — which open their own
|
|
147
147
|
* transaction around just their writes — straight after it commits
|
|
148
148
|
* (`close_connections_after_commit`, which logs a failing close rather than
|
|
149
149
|
* failing the committed request), so a later throw can't drop a close a
|
|
150
|
-
* committed revocation owes. All on `deps.connection_closer`.
|
|
150
|
+
* committed revocation owes. All on `deps.connection_closer`. Each success
|
|
151
|
+
* audit row is written last in the transaction of the change it reports, so
|
|
152
|
+
* a refused row rolls the change back and closes nothing.
|
|
151
153
|
*
|
|
152
154
|
* @param deps - stateless capabilities (keyring, password, log, audit, connection_closer)
|
|
153
155
|
* @param options - per-factory configuration (session_options, login_ip_rate_limiter, login_account_rate_limiter, bootstrap_status)
|
|
@@ -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;
|
|
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;AAK7E,OAAO,EAAoB,KAAK,WAAW,EAA6B,MAAM,oBAAoB,CAAC;AACnG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAclD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,gCAAgC,GAAI,UAAU,oBAAoB,KAAG,SAiFjF,CAAC;AAEF,iDAAiD;AACjD,MAAM,WAAW,oBAAoB;IACpC,yDAAyD;IACzD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,8FAA8F;IAC9F,gBAAgB,CAAC,EAAE;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC;CAC1C;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,2BAA2B,MAAM,CAAC;AAE/C;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B,KAAK,CAAC;AAE/C;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,uBAAuB;IACvC,eAAe,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC;CACxC;AAED;;GAEG;AACH,MAAM,WAAW,mBAAoB,SAAQ,uBAAuB;IACnE;;;;;;;OAOG;IACH,qBAAqB,EAAE,WAAW,GAAG,IAAI,C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