@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
|
@@ -23,12 +23,13 @@ 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';
|
|
32
|
+
import { transaction_with_post_commit_rollback } from '../http/pending_effects.js';
|
|
32
33
|
import { rate_limit_ip_key } from '../http/ip_canonical.js';
|
|
33
34
|
import { parse_acting } from '../http/auth_shape.js';
|
|
34
35
|
import { reserve_optional } from '../rate_limiter.js';
|
|
@@ -49,7 +50,7 @@ import { query_first } from '../http/request_target.js';
|
|
|
49
50
|
* its verification state, and the acting actor's role grants; the route
|
|
50
51
|
* already answers anonymous callers, so that answer is the refusal — a 403
|
|
51
52
|
* would tell the holder nothing that dropping the header doesn't. The handler
|
|
52
|
-
* reads the credential through `
|
|
53
|
+
* reads the credential through `get_public_account`, which applies it.
|
|
53
54
|
*
|
|
54
55
|
* This eliminates the need for a separate `/health` fetch on page load —
|
|
55
56
|
* the frontend gets both session state and bootstrap availability in one request.
|
|
@@ -67,7 +68,7 @@ export const create_account_status_route_spec = (options) => {
|
|
|
67
68
|
path: options?.path ?? account_status_route_shape.path
|
|
68
69
|
}, async (route) => {
|
|
69
70
|
// a narrowed token is the anonymous caller here, never a refusal
|
|
70
|
-
const account_id =
|
|
71
|
+
const account_id = get_public_account(route)?.id;
|
|
71
72
|
if (!account_id)
|
|
72
73
|
return fail_anonymous();
|
|
73
74
|
// Honor a pre-populated request context. The dispatcher's authorization
|
|
@@ -104,33 +105,34 @@ export const create_account_status_route_spec = (options) => {
|
|
|
104
105
|
return route_fail(REST_INVALID_QUERY_PARAMS);
|
|
105
106
|
const acting_raw = query_first(route.query_pairs.value, 'acting');
|
|
106
107
|
const acting = parse_acting(acting_raw);
|
|
108
|
+
// The account read again for the answer, live (`deleted_at IS NULL`),
|
|
109
|
+
// as the Rust twin's summary read is: one deleted or purged since the
|
|
110
|
+
// credential leg is the anonymous caller.
|
|
111
|
+
const account = await query_account_by_id(route, account_id);
|
|
112
|
+
if (!account)
|
|
113
|
+
return fail_anonymous();
|
|
107
114
|
const acting_result = acting_raw !== undefined && acting === undefined
|
|
108
115
|
? null
|
|
109
|
-
: await resolve_acting_actor(route,
|
|
116
|
+
: await resolve_acting_actor(route, account.id, acting);
|
|
110
117
|
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
|
-
}
|
|
118
|
+
const ctx = await build_request_context(route, account, acting_result.actor);
|
|
119
|
+
const role_grants = ctx.role_grants.map((p) => ({
|
|
120
|
+
id: p.id,
|
|
121
|
+
role: p.role,
|
|
122
|
+
scope_kind: p.scope_kind,
|
|
123
|
+
scope_id: p.scope_id,
|
|
124
|
+
created_at: p.created_at,
|
|
125
|
+
expires_at: p.expires_at,
|
|
126
|
+
granted_by: p.granted_by
|
|
127
|
+
}));
|
|
128
|
+
return route_ok({
|
|
129
|
+
account: to_session_account(ctx.account),
|
|
130
|
+
actor: { id: ctx.actor.id, name: ctx.actor.name },
|
|
131
|
+
role_grants
|
|
132
|
+
});
|
|
128
133
|
}
|
|
129
|
-
const account_ctx = await build_account_context(route, account_id);
|
|
130
|
-
if (!account_ctx)
|
|
131
|
-
return fail_anonymous();
|
|
132
134
|
return route_ok({
|
|
133
|
-
account: to_session_account(
|
|
135
|
+
account: to_session_account(account),
|
|
134
136
|
actor: null,
|
|
135
137
|
role_grants: []
|
|
136
138
|
});
|
|
@@ -167,14 +169,16 @@ export const DEFAULT_LOGIN_FAIL_JITTER_MS = 25;
|
|
|
167
169
|
* every account surface serves it, matching the Rust `account_router`.
|
|
168
170
|
* Self-service session/token management is on `auth/account_actions.ts`.
|
|
169
171
|
*
|
|
170
|
-
* `/login` closes the connections of the sessions its cap evicts,
|
|
171
|
-
*
|
|
172
|
+
* `/login` closes the connections of the sessions its cap evicts, `/logout`
|
|
173
|
+
* those of the session it ends, and `/password` the account's, each once its revocation has
|
|
172
174
|
* committed: `/logout` through the route transaction's post-commit queue
|
|
173
175
|
* (`queue_connection_close`), `/login` and `/password` — which open their own
|
|
174
176
|
* transaction around just their writes — straight after it commits
|
|
175
177
|
* (`close_connections_after_commit`, which logs a failing close rather than
|
|
176
178
|
* failing the committed request), so a later throw can't drop a close a
|
|
177
|
-
* committed revocation owes. All on `deps.connection_closer`.
|
|
179
|
+
* committed revocation owes. All on `deps.connection_closer`. Each success
|
|
180
|
+
* audit row is written last in the transaction of the change it reports, so
|
|
181
|
+
* a refused row rolls the change back and closes nothing.
|
|
178
182
|
*
|
|
179
183
|
* @param deps - stateless capabilities (keyring, password, log, audit, connection_closer)
|
|
180
184
|
* @param options - per-factory configuration (session_options, login_ip_rate_limiter, login_account_rate_limiter, bootstrap_status)
|
|
@@ -254,35 +258,38 @@ export const create_account_route_specs = (deps, options) => {
|
|
|
254
258
|
return route_fail(REST_INVALID_CREDENTIALS);
|
|
255
259
|
}
|
|
256
260
|
const valid = await password.verify_password(pw, account.password_hash);
|
|
257
|
-
// The session INSERT
|
|
258
|
-
// writes, and only atomic together: one
|
|
259
|
-
// them (the route is `transaction: false`,
|
|
260
|
-
// waits above and the Argon2 verify held no
|
|
261
|
-
// the Rust login's
|
|
261
|
+
// The session INSERT, the cap eviction, and the `login` success
|
|
262
|
+
// row are the route's writes, and only atomic together: one
|
|
263
|
+
// transaction around just them (the route is `transaction: false`,
|
|
264
|
+
// so the reservation waits above and the Argon2 verify held no
|
|
265
|
+
// connection). Twin of the Rust login's `mint_login_session`. It
|
|
262
266
|
// first locks the account row as the verify read it — live, the
|
|
263
267
|
// verified hash — so a password change or a delete that committed
|
|
264
268
|
// since mints nothing, and one still to commit waits and then
|
|
265
269
|
// revokes this session (`query_account_lock_verified`). The
|
|
266
270
|
// cookie line is formatted inside it, so a value the formatter
|
|
267
271
|
// refuses rolls the session back, and rides the success, which is
|
|
268
|
-
// answered only once the commit has landed.
|
|
272
|
+
// answered only once the commit has landed. The audit row is
|
|
273
|
+
// written last, so a refused row mints no session.
|
|
269
274
|
const minted = valid
|
|
270
|
-
? await route
|
|
271
|
-
|
|
272
|
-
if (!(await query_account_lock_verified(tx_deps, account.id, account.password_hash))) {
|
|
275
|
+
? await transaction_with_post_commit_rollback(route, async (tx_ctx) => {
|
|
276
|
+
if (!(await query_account_lock_verified(tx_ctx, account.id, account.password_hash))) {
|
|
273
277
|
return null;
|
|
274
278
|
}
|
|
275
279
|
const session = await create_capped_session({
|
|
276
280
|
keyring,
|
|
277
|
-
deps:
|
|
281
|
+
deps: tx_ctx,
|
|
278
282
|
account_id: account.id,
|
|
279
283
|
session_options,
|
|
280
284
|
max_sessions
|
|
281
285
|
});
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
+
const set_cookie = session_cookie_header(session.cookie_value, session_options);
|
|
287
|
+
await deps.audit.emit(tx_ctx, {
|
|
288
|
+
event_type: 'login',
|
|
289
|
+
account_id: account.id,
|
|
290
|
+
ip: route.client_ip
|
|
291
|
+
});
|
|
292
|
+
return { evicted: session.evicted, set_cookie };
|
|
286
293
|
})
|
|
287
294
|
: null;
|
|
288
295
|
// A wrong password, and a right one whose account changed under
|
|
@@ -318,16 +325,11 @@ export const create_account_route_specs = (deps, options) => {
|
|
|
318
325
|
// rechecks. Close them now the eviction has committed — inline, not
|
|
319
326
|
// queued: with no route transaction, a throw later in the handler
|
|
320
327
|
// would drop a queued close while the eviction stands. No audit
|
|
321
|
-
// row: there is no eviction event, and the `login`
|
|
322
|
-
// the cause.
|
|
328
|
+
// row of their own: there is no eviction event, and the `login`
|
|
329
|
+
// row records the cause.
|
|
323
330
|
for (const session_hash of evicted) {
|
|
324
331
|
close_connections_after_commit(connection_closer, { kind: 'session', session_hash }, deps.log);
|
|
325
332
|
}
|
|
326
|
-
await deps.audit.emit(route, {
|
|
327
|
-
event_type: 'login',
|
|
328
|
-
account_id: account.id,
|
|
329
|
-
ip: route.client_ip
|
|
330
|
-
});
|
|
331
333
|
return route_ok({ ok: true }, { set_cookie: [set_cookie] });
|
|
332
334
|
}
|
|
333
335
|
finally {
|
|
@@ -340,28 +342,31 @@ export const create_account_route_specs = (deps, options) => {
|
|
|
340
342
|
// the shape admits only a session credential, so this is its hash
|
|
341
343
|
// (the Rust `account_logout` reads the same value)
|
|
342
344
|
const session_hash = resolved_auth_session_hash(route.credential);
|
|
343
|
-
if (session_hash
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
// committed — queued, so it never runs before the commit or on
|
|
347
|
-
// rollback, and it does not depend on the audit row below (written
|
|
348
|
-
// in the route transaction, so it commits with the revoke). Account-wide (not session-targeted) to match the Rust
|
|
349
|
-
// `account_logout` handler and the sibling `/password` handler
|
|
350
|
-
// — logout is a self-initiated account-grain operation. The
|
|
351
|
-
// audit listeners repeat the same close on the announced
|
|
352
|
-
// `logout` row; closing is idempotent.
|
|
353
|
-
queue_connection_close(route, connection_closer, {
|
|
354
|
-
kind: 'account',
|
|
355
|
-
account_id: ctx.account.id
|
|
356
|
-
});
|
|
345
|
+
if (session_hash === null) {
|
|
346
|
+
// a 500 with nothing changed, as the Rust handler answers
|
|
347
|
+
throw new Error('logout: the session gate admitted a caller with no session hash');
|
|
357
348
|
}
|
|
349
|
+
await query_session_revoke_by_hash_unscoped(route, session_hash);
|
|
350
|
+
// Close the live connections of the session this logout ends, once
|
|
351
|
+
// the revoke has committed — queued, so it never runs before the
|
|
352
|
+
// commit or on rollback, and it does not depend on the audit row below
|
|
353
|
+
// (written in the route transaction, so it commits with the revoke).
|
|
354
|
+
// Only that session's: logout ends one credential, and the account's
|
|
355
|
+
// other sessions, its API tokens and the daemon token stay valid, so
|
|
356
|
+
// their connections stay open. The audit listeners repeat the same
|
|
357
|
+
// close on the announced `logout` row, which names the session;
|
|
358
|
+
// closing is idempotent. The Rust `account_logout` closes the same.
|
|
359
|
+
queue_connection_close(route, connection_closer, { kind: 'session', session_hash });
|
|
358
360
|
// Account-grain operation — no `actor_id` (which actor was
|
|
359
361
|
// resolved per-request is incidental to "this account ended
|
|
360
|
-
// its session"). Mirrors `login`.
|
|
362
|
+
// its session"). Mirrors `login`. `session_id` names the ended
|
|
363
|
+
// session, as a `session_revoke` row does — what the revocation
|
|
364
|
+
// guard closes by.
|
|
361
365
|
await deps.audit.emit(route, {
|
|
362
366
|
event_type: 'logout',
|
|
363
367
|
account_id: ctx.account.id,
|
|
364
|
-
ip: route.client_ip
|
|
368
|
+
ip: route.client_ip,
|
|
369
|
+
metadata: { session_id: session_hash }
|
|
365
370
|
});
|
|
366
371
|
// the clear rides the success, answered once the revoke and this
|
|
367
372
|
// row have committed — a rollback clears nothing
|
|
@@ -419,20 +424,31 @@ export const create_account_route_specs = (deps, options) => {
|
|
|
419
424
|
// operation — `updated_by` stays null (the per-request actor is
|
|
420
425
|
// incidental; password is account-level state).
|
|
421
426
|
//
|
|
422
|
-
// The UPDATE
|
|
423
|
-
//
|
|
424
|
-
//
|
|
425
|
-
//
|
|
426
|
-
//
|
|
427
|
-
//
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
427
|
+
// The UPDATE, the two revocations, and the `password_change`
|
|
428
|
+
// success row are the route's writes, and commit together or not
|
|
429
|
+
// at all: one transaction around just them (the route is
|
|
430
|
+
// `transaction: false`, so the reservation waits above and the
|
|
431
|
+
// Argon2 verify and hash held no connection). Twin of the Rust
|
|
432
|
+
// spine's `change_password`. The audit row is written last, so a
|
|
433
|
+
// refused row changes no password and revokes nothing. `null` when
|
|
434
|
+
// the UPDATE matched nothing — a concurrent change committed first.
|
|
435
|
+
const change = await transaction_with_post_commit_rollback(route, async (tx_ctx) => {
|
|
436
|
+
const updated = await query_update_account_password(tx_ctx, ctx.account.id, new_hash, null, ctx.account.password_hash);
|
|
431
437
|
if (!updated)
|
|
432
438
|
return null;
|
|
433
439
|
// revoke all sessions and API tokens (force re-auth everywhere)
|
|
434
|
-
const sessions_revoked = await query_session_revoke_all_for_account(
|
|
435
|
-
const tokens_revoked = await query_revoke_all_api_tokens_for_account(
|
|
440
|
+
const sessions_revoked = await query_session_revoke_all_for_account(tx_ctx, ctx.account.id);
|
|
441
|
+
const tokens_revoked = await query_revoke_all_api_tokens_for_account(tx_ctx, ctx.account.id);
|
|
442
|
+
// Account-grain operation — no `actor_id`. The password is
|
|
443
|
+
// account-level state; which per-request actor was resolved
|
|
444
|
+
// has no semantic bearing on "this account changed its
|
|
445
|
+
// password". Mirrors `login`/`logout`.
|
|
446
|
+
await deps.audit.emit(tx_ctx, {
|
|
447
|
+
event_type: 'password_change',
|
|
448
|
+
account_id: ctx.account.id,
|
|
449
|
+
ip: route.client_ip,
|
|
450
|
+
metadata: { sessions_revoked, tokens_revoked, credential_type }
|
|
451
|
+
});
|
|
436
452
|
return { sessions_revoked, tokens_revoked };
|
|
437
453
|
});
|
|
438
454
|
// Verify-success contract — the caller proved knowledge, so wipe
|
|
@@ -470,22 +486,12 @@ export const create_account_route_specs = (deps, options) => {
|
|
|
470
486
|
}
|
|
471
487
|
const { sessions_revoked, tokens_revoked } = change;
|
|
472
488
|
// Close every live connection of this account now the password
|
|
473
|
-
// update
|
|
474
|
-
// queued: with no route transaction, a throw later in
|
|
475
|
-
// would drop a queued close while the revocation
|
|
476
|
-
//
|
|
477
|
-
//
|
|
489
|
+
// update, the revoke-all cascade, and its audit row have committed
|
|
490
|
+
// — inline, not queued: with no route transaction, a throw later in
|
|
491
|
+
// the handler would drop a queued close while the revocation
|
|
492
|
+
// stands. The audit listeners repeat it on the announced
|
|
493
|
+
// `password_change` row.
|
|
478
494
|
close_connections_after_commit(connection_closer, { kind: 'account', account_id: ctx.account.id }, deps.log);
|
|
479
|
-
// Account-grain operation — no `actor_id`. The password is
|
|
480
|
-
// account-level state; which per-request actor was resolved
|
|
481
|
-
// has no semantic bearing on "this account changed its
|
|
482
|
-
// password". Mirrors `login`/`logout`.
|
|
483
|
-
await deps.audit.emit(route, {
|
|
484
|
-
event_type: 'password_change',
|
|
485
|
-
account_id: ctx.account.id,
|
|
486
|
-
ip: route.client_ip,
|
|
487
|
-
metadata: { sessions_revoked, tokens_revoked, credential_type }
|
|
488
|
-
});
|
|
489
495
|
return route_ok({ ok: true, sessions_revoked, tokens_revoked }, { set_cookie: [clear_session_cookie_header(session_options)] });
|
|
490
496
|
}
|
|
491
497
|
finally {
|
|
@@ -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;AAyD1B,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,CAupBjB,CAAC"}
|
|
@@ -34,10 +34,12 @@ 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 { emit_supersede_audits } from './role_grant_offer_actions.js';
|
|
41
|
+
import { queue_supersede_notifications } from './role_grant_offer_notifications.js';
|
|
42
|
+
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
43
|
import { query_session_list_all_active, query_session_revoke_all_for_account } from './session_queries.js';
|
|
42
44
|
import { query_revoke_all_api_tokens_for_account } from './api_token_queries.js';
|
|
43
45
|
import { query_audit_log_list_role_grant_history, query_audit_log_list_with_usernames } from './audit_log_queries.js';
|
|
@@ -171,7 +173,7 @@ export const create_admin_actions = (deps, options = {}) => {
|
|
|
171
173
|
// is, as `account_token_create` refuses it — and one still to commit
|
|
172
174
|
// waits on this lock, then deletes the invite with the account's other
|
|
173
175
|
// unclaimed ones: a delete writes its tombstone first.
|
|
174
|
-
if (!(await
|
|
176
|
+
if (!(await query_account_lock_live_many(ctx, [auth.account.id])).has(auth.account.id)) {
|
|
175
177
|
throw jsonrpc_errors.unauthenticated('unauthenticated', {
|
|
176
178
|
reason: ERROR_AUTHENTICATION_REQUIRED
|
|
177
179
|
});
|
|
@@ -194,6 +196,7 @@ export const create_admin_actions = (deps, options = {}) => {
|
|
|
194
196
|
}
|
|
195
197
|
await deps.audit.emit(ctx, {
|
|
196
198
|
event_type: 'invite_create',
|
|
199
|
+
actor_id: auth.actor.id,
|
|
197
200
|
account_id: auth.account.id,
|
|
198
201
|
ip: ctx.client_ip,
|
|
199
202
|
metadata: { invite_id: invite.id, email, username }
|
|
@@ -208,10 +211,24 @@ export const create_admin_actions = (deps, options = {}) => {
|
|
|
208
211
|
const auth = ctx.auth;
|
|
209
212
|
const deleted = await query_invite_delete_unclaimed(ctx, input.invite_id);
|
|
210
213
|
if (!deleted) {
|
|
214
|
+
// The probe key is a UUID, so a failure row leaks nothing an admin's
|
|
215
|
+
// typo would (unlike `invite_create`'s email and username refusals,
|
|
216
|
+
// which write none), and a real admin aiming at a missing invite is
|
|
217
|
+
// forensic signal. Written through the pool, so it outlives the
|
|
218
|
+
// rollback this refusal causes. Twin of the Rust handler's row.
|
|
219
|
+
await deps.audit.emit(ctx, {
|
|
220
|
+
event_type: 'invite_delete',
|
|
221
|
+
outcome: 'failure',
|
|
222
|
+
actor_id: auth.actor.id,
|
|
223
|
+
account_id: auth.account.id,
|
|
224
|
+
ip: ctx.client_ip,
|
|
225
|
+
metadata: { reason: ERROR_INVITE_NOT_FOUND, attempted_invite_id: input.invite_id }
|
|
226
|
+
});
|
|
211
227
|
throw jsonrpc_errors.not_found('invite', { reason: ERROR_INVITE_NOT_FOUND });
|
|
212
228
|
}
|
|
213
229
|
await deps.audit.emit(ctx, {
|
|
214
230
|
event_type: 'invite_delete',
|
|
231
|
+
actor_id: auth.actor.id,
|
|
215
232
|
account_id: auth.account.id,
|
|
216
233
|
ip: ctx.client_ip,
|
|
217
234
|
metadata: { invite_id: input.invite_id }
|
|
@@ -258,56 +275,62 @@ export const create_admin_actions = (deps, options = {}) => {
|
|
|
258
275
|
// admin while another active admin exists. Keeper branch above stays
|
|
259
276
|
// unconditional; the last-admin branch fires only for an *active* target.
|
|
260
277
|
if ((await query_account_has_active_global_role(ctx, target_account_id, ROLE_ADMIN)) &&
|
|
261
|
-
(await
|
|
278
|
+
(await query_count_active_accounts_with_global_role_locked(ctx, ROLE_ADMIN)) <= 1) {
|
|
262
279
|
await deny(ERROR_CANNOT_DELETE_LAST_ADMIN, `cannot ${verb} the last admin account`);
|
|
263
280
|
}
|
|
264
281
|
};
|
|
265
282
|
// One `role_grant_offer_supersede` row per offer an account removal ended,
|
|
266
283
|
// `reason: 'account_deleted'` and `cause_id` the removed account, whichever
|
|
267
|
-
// side of the offer the account was on
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
target_actor_id: offer.to_actor_id,
|
|
274
|
-
metadata: {
|
|
275
|
-
offer_id: offer.id,
|
|
276
|
-
role: offer.role,
|
|
277
|
-
scope_id: offer.scope_id,
|
|
278
|
-
reason: 'account_deleted',
|
|
279
|
-
cause_id: target_account_id
|
|
280
|
-
}
|
|
281
|
-
});
|
|
282
|
-
}
|
|
284
|
+
// side of the offer the account was on, then the notification to the offer's
|
|
285
|
+
// other party — `audience`, the side the removed account is not on, with the
|
|
286
|
+
// `cause_id` that side is sent; the account's own connections close with it.
|
|
287
|
+
const emit_account_deleted_supersedes = async (ctx, target_account_id, superseded, audience) => {
|
|
288
|
+
await emit_supersede_audits(ctx, deps.audit, superseded, 'account_deleted', target_account_id);
|
|
289
|
+
queue_supersede_notifications(ctx, superseded, 'account_deleted', audience);
|
|
283
290
|
};
|
|
291
|
+
// Lock every pending offer the removal supersedes, both directions, in one
|
|
292
|
+
// id-ordered statement before either supersede writes — the order every
|
|
293
|
+
// multi-row offer write takes its rows in
|
|
294
|
+
// (`query_role_grant_offer_lock_for_account_removal` has why).
|
|
295
|
+
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
296
|
// Supersede every pending offer the removed account's actors made, audited
|
|
285
297
|
// — the cascade a revoke runs on the revokee's offers. An offer records no
|
|
286
298
|
// authority, so one outliving its grantor's account would still confer on
|
|
287
|
-
// accept.
|
|
288
|
-
//
|
|
299
|
+
// accept. Each recipient is told, sent its grantor's actor as `cause_id` — an
|
|
300
|
+
// id it already holds, where the audit row's is the removed account's; the
|
|
301
|
+
// grantor is the removed account.
|
|
289
302
|
const cancel_outgoing_offers = async (ctx, target_account_id, actors) => {
|
|
290
303
|
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
|
|
304
|
+
await emit_account_deleted_supersedes(ctx, target_account_id, superseded, {
|
|
305
|
+
grantor: null,
|
|
306
|
+
recipient: { kind: 'from_actor' }
|
|
307
|
+
});
|
|
292
308
|
};
|
|
293
|
-
// Supersede every pending offer made to the
|
|
294
|
-
// actor-addressed, audited as the outgoing cascade is
|
|
295
|
-
//
|
|
296
|
-
//
|
|
309
|
+
// Supersede every pending offer made to the removed account, account- or
|
|
310
|
+
// actor-addressed, audited as the outgoing cascade is, each grantor told,
|
|
311
|
+
// sent the removed account as `cause_id` (the offer's `to_account_id`). An
|
|
312
|
+
// undelete restores a deleted account, so an offer left pending through the
|
|
313
|
+
// delete would come back with it and could be accepted; a purge's cascade
|
|
314
|
+
// would take the offers with no audit row and no word to their grantors.
|
|
297
315
|
const cancel_incoming_offers = async (ctx, target_account_id) => {
|
|
298
316
|
const superseded = await query_role_grant_offer_supersede_incoming(ctx, target_account_id);
|
|
299
|
-
await emit_account_deleted_supersedes(ctx, target_account_id, superseded
|
|
317
|
+
await emit_account_deleted_supersedes(ctx, target_account_id, superseded, {
|
|
318
|
+
grantor: { kind: 'id', id: target_account_id },
|
|
319
|
+
recipient: null
|
|
320
|
+
});
|
|
300
321
|
};
|
|
301
322
|
// Delete the unclaimed invites the removed account's actors issued, each
|
|
302
|
-
// audited as an `invite_delete` is
|
|
303
|
-
//
|
|
304
|
-
// answers a signup as a revoked one
|
|
323
|
+
// audited as an `invite_delete` call is — the remover's actor and account.
|
|
324
|
+
// An invite records no authority, so one outliving its issuer's account
|
|
325
|
+
// would still admit a signup; deleted, it answers a signup as a revoked one
|
|
326
|
+
// does, and an undelete can't revive it.
|
|
305
327
|
// A claimed invite is untouched.
|
|
306
328
|
const void_unclaimed_invites = async (ctx, actors) => {
|
|
307
329
|
const invite_ids = await query_invite_delete_unclaimed_by_creators(ctx, actors.map((a) => a.id));
|
|
308
330
|
for (const invite_id of invite_ids) {
|
|
309
331
|
await deps.audit.emit(ctx, {
|
|
310
332
|
event_type: 'invite_delete',
|
|
333
|
+
actor_id: ctx.auth.actor.id,
|
|
311
334
|
account_id: ctx.auth.account.id,
|
|
312
335
|
ip: ctx.client_ip,
|
|
313
336
|
metadata: { invite_id }
|
|
@@ -319,7 +342,8 @@ export const create_admin_actions = (deps, options = {}) => {
|
|
|
319
342
|
// session-only — enforced here, not on the spec, whose gate stays open so
|
|
320
343
|
// an admin deleting another account keeps any credential. Tombstones the
|
|
321
344
|
// account + its actor(s), supersedes the pending offers its actors made and
|
|
322
|
-
// the ones made to it
|
|
345
|
+
// the ones made to it (each offer's other party told), revokes
|
|
346
|
+
// sessions/tokens, deletes the unclaimed
|
|
323
347
|
// invites its actors issued, closes sockets, and
|
|
324
348
|
// emits `account_delete` + one `actor_delete` per soft-deleted actor —
|
|
325
349
|
// each carrying its identity snapshot. `delete` = soft.
|
|
@@ -359,6 +383,7 @@ export const create_admin_actions = (deps, options = {}) => {
|
|
|
359
383
|
});
|
|
360
384
|
throw jsonrpc_errors.not_found('account', { reason: ERROR_ACCOUNT_NOT_FOUND });
|
|
361
385
|
}
|
|
386
|
+
await lock_removed_account_offers(ctx, target_account_id, actors);
|
|
362
387
|
await cancel_outgoing_offers(ctx, target_account_id, actors);
|
|
363
388
|
await cancel_incoming_offers(ctx, target_account_id);
|
|
364
389
|
const soft_deleted_actors = [];
|
|
@@ -398,7 +423,9 @@ export const create_admin_actions = (deps, options = {}) => {
|
|
|
398
423
|
return { ok: true, deleted: true };
|
|
399
424
|
};
|
|
400
425
|
// Hard-purge an account (keeper-only, irreversible). Fail-loud:
|
|
401
|
-
// requires `confirm: true` + emits a WARN.
|
|
426
|
+
// requires `confirm: true` + emits a WARN. Supersedes the account's pending
|
|
427
|
+
// offers, both ways, as a delete does, before its cascade deletes the rows —
|
|
428
|
+
// the audit rows and the notifications are what remain of them. Snapshots identity into
|
|
402
429
|
// `account_purge` + per-actor `actor_purge` before the cascading delete
|
|
403
430
|
// removes the rows — the `audit_log` id columns carry no FK, so the
|
|
404
431
|
// purged ids survive on historical rows and the snapshots name them.
|
|
@@ -410,18 +437,17 @@ export const create_admin_actions = (deps, options = {}) => {
|
|
|
410
437
|
reason: ERROR_PURGE_NOT_CONFIRMED
|
|
411
438
|
});
|
|
412
439
|
}
|
|
440
|
+
// Every admin's account row and the target's, in one id-ordered statement:
|
|
441
|
+
// the cascade writes admin rows (the grants the target's actors granted).
|
|
442
|
+
// Every other removal's guard and every other purge take those accounts
|
|
443
|
+
// first, and no other writer of an admin's grant waits on an account row
|
|
444
|
+
// while holding one, so holding the accounts orders the purge before any of
|
|
445
|
+
// them (`query_account_lock_admins_for_purge` has why). The last-admin guard
|
|
446
|
+
// then runs only for an admin target, in `assert_account_removable`.
|
|
447
|
+
await query_account_lock_admins_for_purge(ctx, input.account_id);
|
|
413
448
|
// Keeper + last-admin guards (fail-loud, before the cascade).
|
|
414
449
|
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) {
|
|
450
|
+
const refuse_not_found = async () => {
|
|
425
451
|
await deps.audit.emit(ctx, {
|
|
426
452
|
event_type: 'account_purge',
|
|
427
453
|
outcome: 'failure',
|
|
@@ -431,7 +457,29 @@ export const create_admin_actions = (deps, options = {}) => {
|
|
|
431
457
|
metadata: { reason: ERROR_ACCOUNT_NOT_FOUND, attempted_account_id: input.account_id }
|
|
432
458
|
});
|
|
433
459
|
throw jsonrpc_errors.not_found('account', { reason: ERROR_ACCOUNT_NOT_FOUND });
|
|
434
|
-
}
|
|
460
|
+
};
|
|
461
|
+
// The account row before any write, as every writer of the account takes
|
|
462
|
+
// it — `query_account_lock_for_purge` has why.
|
|
463
|
+
if (!(await query_account_lock_for_purge(ctx, input.account_id)))
|
|
464
|
+
await refuse_not_found();
|
|
465
|
+
// Snapshot actors before the cascade removes them.
|
|
466
|
+
const actors = await query_actors_by_account(ctx, input.account_id);
|
|
467
|
+
// Before the cascade, whose `ON DELETE CASCADE` would take the offers
|
|
468
|
+
// with no audit row and no notification, the ones the account made and
|
|
469
|
+
// the ones made to it. After the account row: an offer create from or to
|
|
470
|
+
// the account takes that row first, so it has committed or waits.
|
|
471
|
+
await lock_removed_account_offers(ctx, input.account_id, actors);
|
|
472
|
+
await cancel_outgoing_offers(ctx, input.account_id, actors);
|
|
473
|
+
await cancel_incoming_offers(ctx, input.account_id);
|
|
474
|
+
// Before the cascade too: `invite.created_by` is `ON DELETE SET NULL`, so
|
|
475
|
+
// the cascade would leave the account's unclaimed invites usable.
|
|
476
|
+
await void_unclaimed_invites(ctx, actors);
|
|
477
|
+
// Before the cascade as well: it would delete the account's sessions and
|
|
478
|
+
// tokens in its own plan's order, against a revoke or a sweep of the
|
|
479
|
+
// same rows taking them in id order — the order these take them in.
|
|
480
|
+
await query_session_revoke_all_for_account(ctx, input.account_id);
|
|
481
|
+
await query_revoke_all_api_tokens_for_account(ctx, input.account_id);
|
|
482
|
+
const snapshot = (await query_purge_account(ctx, input.account_id)) ?? (await refuse_not_found());
|
|
435
483
|
// The cascade removed every credential of the account; its connections
|
|
436
484
|
// close once that has committed.
|
|
437
485
|
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"}
|