@fuzdev/fuz_app 0.182.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 +4 -4
- package/dist/auth/CLAUDE.md +58 -34
- package/dist/auth/account_routes.d.ts +5 -3
- package/dist/auth/account_routes.d.ts.map +1 -1
- package/dist/auth/account_routes.js +71 -66
- package/dist/auth/admin_actions.d.ts.map +1 -1
- package/dist/auth/admin_actions.js +22 -17
- 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/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/deps.d.ts +8 -5
- package/dist/auth/deps.d.ts.map +1 -1
- package/dist/auth/deps.js +3 -2
- package/dist/auth/resolved_auth.d.ts +7 -7
- package/dist/auth/resolved_auth.d.ts.map +1 -1
- package/dist/auth/resolved_auth.js +4 -4
- package/dist/auth/role_grant_offer_actions.d.ts +25 -1
- package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_actions.js +40 -33
- package/dist/auth/role_grant_offer_queries.d.ts +60 -4
- package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_queries.js +79 -5
- package/dist/auth/role_grant_queries.d.ts +3 -52
- package/dist/auth/role_grant_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_queries.js +5 -80
- package/dist/auth/self_service_role_actions.d.ts.map +1 -1
- package/dist/auth/self_service_role_actions.js +11 -22
- package/dist/auth/session_queries.d.ts +6 -3
- package/dist/auth/session_queries.d.ts.map +1 -1
- package/dist/auth/session_queries.js +20 -11
- package/dist/auth/signup_routes.d.ts.map +1 -1
- package/dist/auth/signup_routes.js +90 -38
- package/dist/db/sql_columns.d.ts +1 -1
- package/dist/db/sql_columns.js +1 -1
- package/dist/http/CLAUDE.md +15 -10
- 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/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/server/app_server.d.ts +43 -2
- package/dist/server/app_server.d.ts.map +1 -1
- package/dist/server/app_server.js +57 -3
- package/dist/testing/CLAUDE.md +255 -786
- 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 +45 -124
- 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/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/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/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_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 +22 -11
- 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/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/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 +10 -5
- 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/package.json +1 -1
|
@@ -70,10 +70,11 @@ export const AUDIT_EVENT_TYPES = Object.freeze([
|
|
|
70
70
|
* until it declares its scope here.
|
|
71
71
|
*
|
|
72
72
|
* A scope other than `none` marks an event whose success invalidates a live
|
|
73
|
-
* connection's credential or access: `
|
|
73
|
+
* connection's credential or access: `password_change`,
|
|
74
74
|
* `session_revoke_all`, `token_revoke_all`, `account_delete`, and
|
|
75
|
-
* `account_purge` are account-wide, `session_revoke
|
|
76
|
-
* the one credential they ended, and `role_grant_revoke`
|
|
75
|
+
* `account_purge` are account-wide, `session_revoke`, `logout` and
|
|
76
|
+
* `token_revoke` name the one credential they ended, and `role_grant_revoke`
|
|
77
|
+
* names the lost role.
|
|
77
78
|
* Granting access revokes nothing, and neither does an event about a subject
|
|
78
79
|
* other than a connection's identity.
|
|
79
80
|
*
|
|
@@ -82,7 +83,7 @@ export const AUDIT_EVENT_TYPES = Object.freeze([
|
|
|
82
83
|
*/
|
|
83
84
|
export const audit_event_revocation_scopes = Object.freeze({
|
|
84
85
|
login: 'none',
|
|
85
|
-
logout: '
|
|
86
|
+
logout: 'session',
|
|
86
87
|
bootstrap: 'none',
|
|
87
88
|
signup: 'none',
|
|
88
89
|
password_change: 'account',
|
|
@@ -185,7 +186,11 @@ export const audit_metadata_schemas = Object.freeze({
|
|
|
185
186
|
login: nullable(loose_object({
|
|
186
187
|
username: meta(string, { description: 'Username submitted with the login attempt.' })
|
|
187
188
|
})),
|
|
188
|
-
logout:
|
|
189
|
+
logout: loose_object({
|
|
190
|
+
session_id: meta(SessionId, {
|
|
191
|
+
description: 'Blake3 hash identifying the session row the logout ended.'
|
|
192
|
+
})
|
|
193
|
+
}),
|
|
189
194
|
bootstrap: nullable(loose_object({
|
|
190
195
|
error: meta(string, { description: 'Error message for a failed bootstrap attempt.' })
|
|
191
196
|
})),
|
|
@@ -373,8 +378,19 @@ export const audit_metadata_schemas = Object.freeze({
|
|
|
373
378
|
email: meta(nullable(string), { description: 'Invited email address; null when not set.' }),
|
|
374
379
|
username: meta(nullable(string), { description: 'Invited username; null when not set.' })
|
|
375
380
|
}),
|
|
381
|
+
// A delete of an id naming no unclaimed invite writes an `outcome=failure`
|
|
382
|
+
// row with no `invite_id`: `reason` carries the failure category and
|
|
383
|
+
// `attempted_invite_id` the probed id.
|
|
376
384
|
invite_delete: loose_object({
|
|
377
|
-
invite_id: meta(Uuid, {
|
|
385
|
+
invite_id: meta(optional(Uuid), {
|
|
386
|
+
description: 'Id of the deleted invite. Omitted on `outcome=failure`.'
|
|
387
|
+
}),
|
|
388
|
+
reason: meta(optional(string), {
|
|
389
|
+
description: 'Failure category. Set only on `outcome=failure`.'
|
|
390
|
+
}),
|
|
391
|
+
attempted_invite_id: meta(optional(Uuid), {
|
|
392
|
+
description: 'Probed invite id when no unclaimed invite matched. Set only on `outcome=failure`.'
|
|
393
|
+
})
|
|
378
394
|
}),
|
|
379
395
|
// Account/actor deletion snapshots identity into metadata so the
|
|
380
396
|
// identity behind a now-orphaned audit id survives a purge (the
|
|
@@ -13,10 +13,11 @@ import type { Logger } from '@fuzdev/fuz_util/log.ts';
|
|
|
13
13
|
import type { PasswordHashDeps } from './password.js';
|
|
14
14
|
import { ERROR_INVALID_TOKEN, ERROR_ALREADY_BOOTSTRAPPED, ERROR_TOKEN_FILE_MISSING, ERROR_TOKEN_FILE_UNDELETABLE } from '../http/error_schemas.js';
|
|
15
15
|
import type { Account, Actor, RoleGrant } from './account_schema.js';
|
|
16
|
-
import type
|
|
16
|
+
import { type RequestEffectsContext } from '../http/pending_effects.js';
|
|
17
|
+
import type { AuditEmitter } from './audit_emitter.js';
|
|
17
18
|
import type { BootstrapTokenStore } from './bootstrap_token_store.js';
|
|
18
19
|
import type { Keyring } from './keyring.js';
|
|
19
|
-
import type
|
|
20
|
+
import { type SessionOptions } from './session_cookie.js';
|
|
20
21
|
/** Input for the bootstrap account creation. */
|
|
21
22
|
export interface BootstrapAccountInput {
|
|
22
23
|
username: string;
|
|
@@ -35,11 +36,11 @@ export interface BootstrapAccountCreated {
|
|
|
35
36
|
export interface BootstrapAccountSuccess extends BootstrapAccountCreated {
|
|
36
37
|
ok: true;
|
|
37
38
|
/**
|
|
38
|
-
* The
|
|
39
|
-
* transaction, for the caller to set on its
|
|
40
|
-
* because the transaction committed.
|
|
39
|
+
* The `Set-Cookie` line of the session minted in the bootstrap
|
|
40
|
+
* transaction, formatted inside it, for the caller to set on its
|
|
41
|
+
* response — it exists only because the transaction committed.
|
|
41
42
|
*/
|
|
42
|
-
|
|
43
|
+
set_cookie: string;
|
|
43
44
|
}
|
|
44
45
|
/** Bootstrap failure result. */
|
|
45
46
|
export type BootstrapAccountFailure = {
|
|
@@ -65,7 +66,8 @@ export type BootstrapAccountResult = BootstrapAccountSuccess | BootstrapAccountF
|
|
|
65
66
|
* Dependencies for `bootstrap_account`.
|
|
66
67
|
*/
|
|
67
68
|
export interface BootstrapAccountDeps {
|
|
68
|
-
|
|
69
|
+
/** Writes the `bootstrap` success row in the bootstrap transaction. */
|
|
70
|
+
audit: Pick<AuditEmitter, 'emit'>;
|
|
69
71
|
/**
|
|
70
72
|
* The one-shot token: read through the hardened secret read (a symlinked,
|
|
71
73
|
* non-regular, group/other-readable, multiply-linked, or oversized file is
|
|
@@ -80,6 +82,16 @@ export interface BootstrapAccountDeps {
|
|
|
80
82
|
/** Structured logger instance. */
|
|
81
83
|
log: Logger;
|
|
82
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* The request `bootstrap_account` runs for: its pool-level `db` (the bootstrap
|
|
87
|
+
* opens its own transaction), its side-effect queues (the success row's
|
|
88
|
+
* listener fan-out is queued post-commit), and the client IP its audit row
|
|
89
|
+
* records. A `RouteContext` satisfies it.
|
|
90
|
+
*/
|
|
91
|
+
export interface BootstrapAccountContext extends RequestEffectsContext {
|
|
92
|
+
/** Resolved client IP from the trusted-proxy middleware — `'unknown'` if not resolved. */
|
|
93
|
+
client_ip: string;
|
|
94
|
+
}
|
|
83
95
|
/** Static options for `bootstrap_account`. */
|
|
84
96
|
export interface BootstrapAccountOptions {
|
|
85
97
|
/** Session cookie configuration for the session the bootstrap mints. */
|
|
@@ -119,27 +131,33 @@ export declare const read_bootstrap_token: (deps: Pick<BootstrapAccountDeps, "to
|
|
|
119
131
|
* the race loser, `already_bootstrapped`, nothing burned); create the
|
|
120
132
|
* account + actor; grant keeper and admin (no expiry, `granted_by =
|
|
121
133
|
* null`); mint the session through the capped minter login uses (the cap
|
|
122
|
-
* evicts nothing on a new account)
|
|
134
|
+
* evicts nothing on a new account) and format its `Set-Cookie` line; write
|
|
135
|
+
* the `bootstrap` success audit row; then burn the token file, last, just
|
|
123
136
|
* before the commit
|
|
124
137
|
*
|
|
125
138
|
* The burn comes after the lock, so only the lock winner burns (its row lock
|
|
126
139
|
* is held across the unlink, so a concurrent attempt waits on its UPDATE);
|
|
127
140
|
* after the inserts, so a failed insert spends nothing; last, so the window
|
|
128
|
-
* between a burn and a failed commit is one round trip.
|
|
141
|
+
* between a burn and a failed commit is one round trip. The audit row is
|
|
142
|
+
* written before the burn, so a refused row rolls the bootstrap back with the
|
|
143
|
+
* token unburned and the window open, as a failed insert does; its listener
|
|
144
|
+
* fan-out is discarded with any rollback. A burn that fails
|
|
129
145
|
* rolls everything back and answers `token_file_undeletable`: nothing was
|
|
130
146
|
* created and the token is still valid, so the operator fixes the directory
|
|
131
147
|
* and retries. A commit that fails after the burn is logged as an error — the
|
|
132
148
|
* token is gone and a new one must be written. Twin of the Rust
|
|
133
149
|
* `bootstrap_handler`.
|
|
134
150
|
*
|
|
135
|
-
* @param deps -
|
|
151
|
+
* @param deps - token store, password hashing, keyring, audit emitter, and logger
|
|
152
|
+
* @param ctx - the request's pool `db`, side-effect queues, and client IP
|
|
136
153
|
* @param provided_token - the bootstrap token from the user
|
|
137
154
|
* @param input - username and password
|
|
138
155
|
* @param options - the session cookie configuration
|
|
139
|
-
* @returns the created account, actor, role_grants, and session
|
|
156
|
+
* @returns the created account, actor, role_grants, and the session's `Set-Cookie` line — or a bootstrap failure
|
|
140
157
|
* @mutates `bootstrap_lock` row - flips `bootstrapped` to `true` atomically
|
|
141
|
-
* @mutates `account` / `actor` / `role_grant` / `auth_session` tables - inserts the bootstrap account, actor, keeper + admin role_grants, and
|
|
158
|
+
* @mutates `account` / `actor` / `role_grant` / `auth_session` / `audit_log` tables - inserts the bootstrap account, actor, keeper + admin role_grants, session, and success row
|
|
159
|
+
* @mutates `ctx.post_commit_effects` - appends the success row's listener fan-out, discarded on rollback
|
|
142
160
|
* @mutates filesystem - burns the bootstrap token file inside the transaction
|
|
143
161
|
*/
|
|
144
|
-
export declare const bootstrap_account: (deps: BootstrapAccountDeps, provided_token: string, input: BootstrapAccountInput, options: BootstrapAccountOptions) => Promise<BootstrapAccountResult>;
|
|
162
|
+
export declare const bootstrap_account: (deps: BootstrapAccountDeps, ctx: BootstrapAccountContext, provided_token: string, input: BootstrapAccountInput, options: BootstrapAccountOptions) => Promise<BootstrapAccountResult>;
|
|
145
163
|
//# sourceMappingURL=bootstrap_account.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap_account.d.ts","sourceRoot":"","sources":["../../src/lib/auth/bootstrap_account.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAGtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EACN,mBAAmB,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eAAO,MAAM,yBAAyB,KAAK,CAAC;AAE5C;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,oBAAoB,GAChC,MAAM,IAAI,CAAC,oBAAoB,EAAE,aAAa,GAAG,KAAK,CAAC,KACrD,OAAO,CAAC,UAAU,CASpB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,eAAO,MAAM,iBAAiB,GAC7B,MAAM,oBAAoB,EAC1B,KAAK,uBAAuB,EAC5B,gBAAgB,MAAM,EACtB,OAAO,qBAAqB,EAC5B,SAAS,uBAAuB,KAC9B,OAAO,CAAC,sBAAsB,CAsHhC,CAAC"}
|
|
@@ -15,6 +15,8 @@ import { ERROR_INVALID_TOKEN, ERROR_ALREADY_BOOTSTRAPPED, ERROR_TOKEN_FILE_MISSI
|
|
|
15
15
|
import { ROLE_ADMIN, ROLE_KEEPER } from './role_schema.js';
|
|
16
16
|
import { query_create_account_with_actor } from './account_queries.js';
|
|
17
17
|
import { query_create_role_grant } from './role_grant_queries.js';
|
|
18
|
+
import { transaction_with_post_commit_rollback } from '../http/pending_effects.js';
|
|
19
|
+
import { session_cookie_header } from './session_cookie.js';
|
|
18
20
|
import { create_capped_session } from './session_queries.js';
|
|
19
21
|
import { DEFAULT_MAX_SESSIONS } from './account_route_schema.js';
|
|
20
22
|
/**
|
|
@@ -78,30 +80,36 @@ export const read_bootstrap_token = async (deps) => {
|
|
|
78
80
|
* the race loser, `already_bootstrapped`, nothing burned); create the
|
|
79
81
|
* account + actor; grant keeper and admin (no expiry, `granted_by =
|
|
80
82
|
* null`); mint the session through the capped minter login uses (the cap
|
|
81
|
-
* evicts nothing on a new account)
|
|
83
|
+
* evicts nothing on a new account) and format its `Set-Cookie` line; write
|
|
84
|
+
* the `bootstrap` success audit row; then burn the token file, last, just
|
|
82
85
|
* before the commit
|
|
83
86
|
*
|
|
84
87
|
* The burn comes after the lock, so only the lock winner burns (its row lock
|
|
85
88
|
* is held across the unlink, so a concurrent attempt waits on its UPDATE);
|
|
86
89
|
* after the inserts, so a failed insert spends nothing; last, so the window
|
|
87
|
-
* between a burn and a failed commit is one round trip.
|
|
90
|
+
* between a burn and a failed commit is one round trip. The audit row is
|
|
91
|
+
* written before the burn, so a refused row rolls the bootstrap back with the
|
|
92
|
+
* token unburned and the window open, as a failed insert does; its listener
|
|
93
|
+
* fan-out is discarded with any rollback. A burn that fails
|
|
88
94
|
* rolls everything back and answers `token_file_undeletable`: nothing was
|
|
89
95
|
* created and the token is still valid, so the operator fixes the directory
|
|
90
96
|
* and retries. A commit that fails after the burn is logged as an error — the
|
|
91
97
|
* token is gone and a new one must be written. Twin of the Rust
|
|
92
98
|
* `bootstrap_handler`.
|
|
93
99
|
*
|
|
94
|
-
* @param deps -
|
|
100
|
+
* @param deps - token store, password hashing, keyring, audit emitter, and logger
|
|
101
|
+
* @param ctx - the request's pool `db`, side-effect queues, and client IP
|
|
95
102
|
* @param provided_token - the bootstrap token from the user
|
|
96
103
|
* @param input - username and password
|
|
97
104
|
* @param options - the session cookie configuration
|
|
98
|
-
* @returns the created account, actor, role_grants, and session
|
|
105
|
+
* @returns the created account, actor, role_grants, and the session's `Set-Cookie` line — or a bootstrap failure
|
|
99
106
|
* @mutates `bootstrap_lock` row - flips `bootstrapped` to `true` atomically
|
|
100
|
-
* @mutates `account` / `actor` / `role_grant` / `auth_session` tables - inserts the bootstrap account, actor, keeper + admin role_grants, and
|
|
107
|
+
* @mutates `account` / `actor` / `role_grant` / `auth_session` / `audit_log` tables - inserts the bootstrap account, actor, keeper + admin role_grants, session, and success row
|
|
108
|
+
* @mutates `ctx.post_commit_effects` - appends the success row's listener fan-out, discarded on rollback
|
|
101
109
|
* @mutates filesystem - burns the bootstrap token file inside the transaction
|
|
102
110
|
*/
|
|
103
|
-
export const bootstrap_account = async (deps, provided_token, input, options) => {
|
|
104
|
-
const {
|
|
111
|
+
export const bootstrap_account = async (deps, ctx, provided_token, input, options) => {
|
|
112
|
+
const { token_store, password, keyring, audit, log } = deps;
|
|
105
113
|
// 1. Read and verify token (non-destructive, before transaction). The
|
|
106
114
|
// secure read fails loud on a symlink / non-regular file / permissive mode /
|
|
107
115
|
// second hard link / oversized file, and the read refuses a token under the minimum length —
|
|
@@ -128,23 +136,22 @@ export const bootstrap_account = async (deps, provided_token, input, options) =>
|
|
|
128
136
|
let burned = false;
|
|
129
137
|
let tx_result;
|
|
130
138
|
try {
|
|
131
|
-
tx_result = await
|
|
132
|
-
const lock_rows = await
|
|
139
|
+
tx_result = await transaction_with_post_commit_rollback(ctx, async (tx_ctx) => {
|
|
140
|
+
const lock_rows = await tx_ctx.db.query('UPDATE bootstrap_lock SET bootstrapped = true WHERE id = 1 AND bootstrapped = false RETURNING id');
|
|
133
141
|
if (lock_rows.length === 0) {
|
|
134
142
|
return { ok: false, error: ERROR_ALREADY_BOOTSTRAPPED, status: 403 };
|
|
135
143
|
}
|
|
136
|
-
const
|
|
137
|
-
const { account, actor } = await query_create_account_with_actor(tx_deps, {
|
|
144
|
+
const { account, actor } = await query_create_account_with_actor(tx_ctx, {
|
|
138
145
|
username: input.username,
|
|
139
146
|
password_hash
|
|
140
147
|
});
|
|
141
|
-
const keeper_role_grant = await query_create_role_grant(
|
|
148
|
+
const keeper_role_grant = await query_create_role_grant(tx_ctx, {
|
|
142
149
|
actor_id: actor.id,
|
|
143
150
|
role: ROLE_KEEPER,
|
|
144
151
|
granted_by: null,
|
|
145
152
|
expires_at: null
|
|
146
153
|
});
|
|
147
|
-
const admin_role_grant = await query_create_role_grant(
|
|
154
|
+
const admin_role_grant = await query_create_role_grant(tx_ctx, {
|
|
148
155
|
actor_id: actor.id,
|
|
149
156
|
role: ROLE_ADMIN,
|
|
150
157
|
granted_by: null,
|
|
@@ -155,11 +162,23 @@ export const bootstrap_account = async (deps, provided_token, input, options) =>
|
|
|
155
162
|
// creation, not of the login route.
|
|
156
163
|
const { cookie_value } = await create_capped_session({
|
|
157
164
|
keyring,
|
|
158
|
-
deps:
|
|
165
|
+
deps: tx_ctx,
|
|
159
166
|
account_id: account.id,
|
|
160
167
|
session_options: options.session_options,
|
|
161
168
|
max_sessions: DEFAULT_MAX_SESSIONS
|
|
162
169
|
});
|
|
170
|
+
// formatted here, as login and signup format theirs: a value the
|
|
171
|
+
// formatter refuses rolls the bootstrap back with the token unburned
|
|
172
|
+
const set_cookie = session_cookie_header(cookie_value, options.session_options);
|
|
173
|
+
// The success row, in the transaction and ahead of the burn: a refused
|
|
174
|
+
// INSERT rolls the bootstrap back with the token unburned and the
|
|
175
|
+
// window open, as a failed insert above does.
|
|
176
|
+
await audit.emit(tx_ctx, {
|
|
177
|
+
event_type: 'bootstrap',
|
|
178
|
+
actor_id: actor.id,
|
|
179
|
+
account_id: account.id,
|
|
180
|
+
ip: ctx.client_ip
|
|
181
|
+
});
|
|
163
182
|
// the burn, last before the commit
|
|
164
183
|
let outcome;
|
|
165
184
|
try {
|
|
@@ -177,7 +196,7 @@ export const bootstrap_account = async (deps, provided_token, input, options) =>
|
|
|
177
196
|
account,
|
|
178
197
|
actor,
|
|
179
198
|
role_grants: { keeper: keeper_role_grant, admin: admin_role_grant },
|
|
180
|
-
|
|
199
|
+
set_cookie
|
|
181
200
|
};
|
|
182
201
|
});
|
|
183
202
|
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* @module
|
|
8
8
|
*/
|
|
9
9
|
import type { Logger } from '@fuzdev/fuz_util/log.ts';
|
|
10
|
-
import {
|
|
10
|
+
import type { SessionOptions } from './session_cookie.js';
|
|
11
11
|
import { type BootstrapAccountCreated } from './bootstrap_account.js';
|
|
12
12
|
import type { BootstrapTokenStore } from './bootstrap_token_store.js';
|
|
13
13
|
import type { Db } from '../db/db.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap_routes.d.ts","sourceRoot":"","sources":["../../src/lib/auth/bootstrap_routes.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,MAAM,EA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C,CAAC;IAC1B,GAAG,EAAE,MAAM,CAAC;CACZ;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,sBAAsB,GAClC,MAAM,wBAAwB,EAC9B,SAAS;IAAE,WAAW,EAAE,mBAAmB,GAAG,IAAI,CAAA;CAAE,KAClD,OAAO,CAAC,eAAe,CA0CzB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B,GACxC,MAAM,gBAAgB,EACtB,SAAS,qBAAqB,KAC5B,KAAK,CAAC,SAAS,CA4HjB,CAAC"}
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
* @module
|
|
8
8
|
*/
|
|
9
9
|
import { to_error_message } from '@fuzdev/fuz_util/error.ts';
|
|
10
|
-
import { session_cookie_header } from './session_cookie.js';
|
|
11
10
|
import { bootstrap_account, read_bootstrap_token } from './bootstrap_account.js';
|
|
12
11
|
import { bootstrap_route_shape } from './bootstrap_route_schema.js';
|
|
13
12
|
import { attach_route_handler } from '../http/route_spec.js';
|
|
@@ -117,14 +116,15 @@ export const create_bootstrap_route_specs = (deps, options) => {
|
|
|
117
116
|
try {
|
|
118
117
|
const input = route.input;
|
|
119
118
|
// `transaction: false` makes `route.db` the pool. `bootstrap_account`
|
|
120
|
-
// manages its own transaction internally
|
|
119
|
+
// manages its own transaction internally, and writes the success
|
|
120
|
+
// row in it.
|
|
121
121
|
const result = await bootstrap_account({
|
|
122
|
-
db: route.db,
|
|
123
122
|
token_store,
|
|
124
123
|
password: deps.password,
|
|
125
124
|
keyring: deps.keyring,
|
|
125
|
+
audit: deps.audit,
|
|
126
126
|
log: deps.log
|
|
127
|
-
}, input.token, input, { session_options });
|
|
127
|
+
}, route, input.token, input, { session_options });
|
|
128
128
|
if (!result.ok) {
|
|
129
129
|
// The lock-race loser — the window open here, the lock already
|
|
130
130
|
// flipped in the database. Close the window so the next caller
|
|
@@ -166,10 +166,9 @@ export const create_bootstrap_route_specs = (deps, options) => {
|
|
|
166
166
|
// most `max_attempts - 1` residual entries survive — and they sit
|
|
167
167
|
// on this route's own limiter, not login's.
|
|
168
168
|
bootstrap_status.available = false;
|
|
169
|
-
// the session was minted
|
|
170
|
-
// success
|
|
171
|
-
const set_cookie =
|
|
172
|
-
const { account, actor, role_grants } = result;
|
|
169
|
+
// the session was minted, and its cookie line formatted, in the
|
|
170
|
+
// transaction; the line rides the success
|
|
171
|
+
const { account, actor, role_grants, set_cookie } = result;
|
|
173
172
|
if (on_bootstrap) {
|
|
174
173
|
try {
|
|
175
174
|
await on_bootstrap({ account, actor, role_grants });
|
|
@@ -178,12 +177,6 @@ export const create_bootstrap_route_specs = (deps, options) => {
|
|
|
178
177
|
deps.log.error(`on_bootstrap callback failed: ${to_error_message(err)}`);
|
|
179
178
|
}
|
|
180
179
|
}
|
|
181
|
-
await deps.audit.emit(route, {
|
|
182
|
-
event_type: 'bootstrap',
|
|
183
|
-
actor_id: actor.id,
|
|
184
|
-
account_id: account.id,
|
|
185
|
-
ip: route.client_ip
|
|
186
|
-
});
|
|
187
180
|
return route_ok({
|
|
188
181
|
ok: true,
|
|
189
182
|
account: { id: account.id, username: account.username },
|
package/dist/auth/deps.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Capabilities bundle for fuz_app backends.
|
|
3
3
|
*
|
|
4
4
|
* `AppDeps` is the central dependency injection type — injectable and swappable
|
|
5
5
|
* per environment (production vs test). Does not contain config (static values)
|
|
6
|
-
* or runtime state (mutable refs)
|
|
6
|
+
* or app runtime state (mutable refs like `bootstrap_status`); the audit emitter
|
|
7
|
+
* and the realtime fan-outs hold only their registered members.
|
|
7
8
|
*
|
|
8
9
|
* @module
|
|
9
10
|
*/
|
|
@@ -16,10 +17,12 @@ import type { AuditEmitter } from './audit_emitter.js';
|
|
|
16
17
|
import type { ConnectionCloser, RealtimeCloser } from '../actions/connection_closer.js';
|
|
17
18
|
import type { RealtimeNotificationSender } from '../actions/notification_sender.js';
|
|
18
19
|
/**
|
|
19
|
-
*
|
|
20
|
+
* Capabilities bundle for fuz_app backends.
|
|
20
21
|
*
|
|
21
|
-
* Injectable and swappable per environment (production vs test).
|
|
22
|
-
*
|
|
22
|
+
* Injectable and swappable per environment (production vs test). Does not
|
|
23
|
+
* contain config (static values) or app runtime state (mutable refs like
|
|
24
|
+
* `bootstrap_status`); the audit emitter and the realtime fan-outs hold only
|
|
25
|
+
* their registered members.
|
|
23
26
|
*/
|
|
24
27
|
export interface AppDeps {
|
|
25
28
|
/** HMAC-SHA256 cookie signing keyring. */
|
package/dist/auth/deps.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deps.d.ts","sourceRoot":"","sources":["../../src/lib/auth/deps.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"deps.d.ts","sourceRoot":"","sources":["../../src/lib/auth/deps.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACxF,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AAEpF;;;;;;;GAOG;AACH,MAAM,WAAW,OAAO;IACvB,0CAA0C;IAC1C,OAAO,EAAE,OAAO,CAAC;IACjB,6EAA6E;IAC7E,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,yBAAyB;IACzB,EAAE,EAAE,EAAE,CAAC;IACP,kCAAkC;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ;;;;;;;OAOG;IACH,KAAK,EAAE,YAAY,CAAC;IACpB;;;;;;;;OAQG;IACH,iBAAiB,EAAE,cAAc,CAAC;IAClC;;;;;;;OAOG;IACH,mBAAmB,EAAE,0BAA0B,CAAC;IAChD;;;;;;;;;OASG;IACH,UAAU,CAAC,EAAE,aAAa,CAAC;CAC3B;AAED;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AAEnD;;;;;;;;GAQG;AACH,MAAM,WAAW,iBAAiB;IACjC,kCAAkC;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ,4CAA4C;IAC5C,KAAK,EAAE,YAAY,CAAC;CACpB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,yBAA0B,SAAQ,iBAAiB;IACnE;;;;;;OAMG;IACH,iBAAiB,EAAE,gBAAgB,CAAC;CACpC"}
|
package/dist/auth/deps.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Capabilities bundle for fuz_app backends.
|
|
3
3
|
*
|
|
4
4
|
* `AppDeps` is the central dependency injection type — injectable and swappable
|
|
5
5
|
* per environment (production vs test). Does not contain config (static values)
|
|
6
|
-
* or runtime state (mutable refs)
|
|
6
|
+
* or app runtime state (mutable refs like `bootstrap_status`); the audit emitter
|
|
7
|
+
* and the realtime fan-outs hold only their registered members.
|
|
7
8
|
*
|
|
8
9
|
* @module
|
|
9
10
|
*/
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import type { Context } from 'hono';
|
|
17
17
|
import type { QueryDeps } from '../db/query_deps.js';
|
|
18
|
-
import type { Account } from './account_schema.js';
|
|
18
|
+
import type { Account, SessionId } from './account_schema.js';
|
|
19
19
|
import { type RequestContext } from './request_context.js';
|
|
20
20
|
import { type TokenScope } from './token_scope.js';
|
|
21
21
|
/** The fields every resolved credential carries. */
|
|
@@ -47,7 +47,7 @@ interface ResolvedAuthBase {
|
|
|
47
47
|
export interface ResolvedSessionAuth extends ResolvedAuthBase {
|
|
48
48
|
readonly credential_type: 'session';
|
|
49
49
|
/** Blake3 hash of the session token — the `auth_session.id`. */
|
|
50
|
-
readonly session_hash:
|
|
50
|
+
readonly session_hash: SessionId;
|
|
51
51
|
}
|
|
52
52
|
/** An `Authorization: Bearer` API token — the only credential a scope narrows. */
|
|
53
53
|
export interface ResolvedApiTokenAuth extends ResolvedAuthBase {
|
|
@@ -90,7 +90,7 @@ export declare const resolved_auth_scope: (auth: ResolvedAuth | null) => TokenSc
|
|
|
90
90
|
* @param auth - the resolved credential, or `null` for an anonymous caller
|
|
91
91
|
* @returns the `auth_session.id`, or `null`
|
|
92
92
|
*/
|
|
93
|
-
export declare const resolved_auth_session_hash: (auth: ResolvedAuth | null) =>
|
|
93
|
+
export declare const resolved_auth_session_hash: (auth: ResolvedAuth | null) => SessionId | null;
|
|
94
94
|
/**
|
|
95
95
|
* The token id of an API token credential, `null` for any other (or none).
|
|
96
96
|
*
|
|
@@ -140,10 +140,10 @@ export declare const get_resolved_auth: (c: Context) => ResolvedAuth | null;
|
|
|
140
140
|
* - **Every credential** — the account row still exists and is not
|
|
141
141
|
* soft-deleted.
|
|
142
142
|
*
|
|
143
|
-
* It re-checks the **credential**, not what a revocation chose to close:
|
|
144
|
-
* `
|
|
145
|
-
*
|
|
146
|
-
* check and is refused only if that account-wide close found its pending
|
|
143
|
+
* It re-checks the **credential**, not what a revocation chose to close: an
|
|
144
|
+
* `admin_token_revoke_all` closes every connection of the account but deletes
|
|
145
|
+
* only its API tokens, so a session's connection opening concurrently passes
|
|
146
|
+
* this check and is refused only if that account-wide close found its pending
|
|
147
147
|
* registration — the same two outcomes an already-open connection has.
|
|
148
148
|
*
|
|
149
149
|
* **No side effects.** Unlike the bearer middleware this never touches
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolved_auth.d.ts","sourceRoot":"","sources":["../../src/lib/auth/resolved_auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"resolved_auth.d.ts","sourceRoot":"","sources":["../../src/lib/auth/resolved_auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAE9D,OAAO,EAGN,KAAK,cAAc,EACnB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAoB,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAErE,oDAAoD;AACpD,UAAU,gBAAgB;IACzB;;;;;;;;;OASG;IACH,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B;;;;;;;;;OASG;IACH,QAAQ,CAAC,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5C;AAED,iEAAiE;AACjE,MAAM,WAAW,mBAAoB,SAAQ,gBAAgB;IAC5D,QAAQ,CAAC,eAAe,EAAE,SAAS,CAAC;IACpC,gEAAgE;IAChE,QAAQ,CAAC,YAAY,EAAE,SAAS,CAAC;CACjC;AAED,kFAAkF;AAClF,MAAM,WAAW,oBAAqB,SAAQ,gBAAgB;IAC7D,QAAQ,CAAC,eAAe,EAAE,WAAW,CAAC;IACtC,0BAA0B;IAC1B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B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AO,MAAM,iBAAiB,GAC7B,MAAM,SAAS,EACf,OAAO,qBAAqB,KAC1B,OAAO,CAAC,gBAAgB,CAa1B,CAAC"}
|
|
@@ -91,10 +91,10 @@ export const get_resolved_auth = (c) => c.get(RESOLVED_AUTH_KEY) ?? null;
|
|
|
91
91
|
* - **Every credential** — the account row still exists and is not
|
|
92
92
|
* soft-deleted.
|
|
93
93
|
*
|
|
94
|
-
* It re-checks the **credential**, not what a revocation chose to close:
|
|
95
|
-
* `
|
|
96
|
-
*
|
|
97
|
-
* check and is refused only if that account-wide close found its pending
|
|
94
|
+
* It re-checks the **credential**, not what a revocation chose to close: an
|
|
95
|
+
* `admin_token_revoke_all` closes every connection of the account but deletes
|
|
96
|
+
* only its API tokens, so a session's connection opening concurrently passes
|
|
97
|
+
* this check and is refused only if that account-wide close found its pending
|
|
98
98
|
* registration — the same two outcomes an already-open connection has.
|
|
99
99
|
*
|
|
100
100
|
* **No side effects.** Unlike the bearer middleware this never touches
|
|
@@ -55,11 +55,31 @@
|
|
|
55
55
|
*
|
|
56
56
|
* @module
|
|
57
57
|
*/
|
|
58
|
+
import type { Uuid } from '../primitive_schemas.js';
|
|
58
59
|
import type { Logger } from '@fuzdev/fuz_util/log.ts';
|
|
59
|
-
import { type ActionContext, type RpcAction } from '../actions/action_types.js';
|
|
60
|
+
import { type ActionActorContext, type ActionContext, type RpcAction } from '../actions/action_types.js';
|
|
60
61
|
import { type RoleRegistry } from './role_schema.js';
|
|
62
|
+
import { type SupersededOffer } from './role_grant_offer_schema.js';
|
|
61
63
|
import { type RequestContext } from './request_context.js';
|
|
62
64
|
import type { RevokingActionFactoryDeps } from './deps.js';
|
|
65
|
+
import type { AuditEmitter } from './audit_emitter.js';
|
|
66
|
+
import { type RoleGrantOfferSupersedeParams } from './role_grant_offer_notifications.js';
|
|
67
|
+
/**
|
|
68
|
+
* Emit one `role_grant_offer_supersede` audit row per offer a cascade ended —
|
|
69
|
+
* the revokes (`role_grant_revoke` and the self-service disable, both
|
|
70
|
+
* `'role_grant_revoked'` with the revoked grant as `cause_id`) and account
|
|
71
|
+
* removal (`'account_deleted'`, the removed account). The acting pair is the
|
|
72
|
+
* caller's; the target pair is the offer's recipient (`to_account_id`, and
|
|
73
|
+
* `to_actor_id` when the offer named an actor). Twin of the Rust
|
|
74
|
+
* `emit_supersede_audits`.
|
|
75
|
+
*
|
|
76
|
+
* @param ctx - the handler context; the rows are the caller's
|
|
77
|
+
* @param audit - the emitter
|
|
78
|
+
* @param superseded - the offers the cascade ended
|
|
79
|
+
* @param reason - why they were superseded
|
|
80
|
+
* @param cause_id - the row that caused it
|
|
81
|
+
*/
|
|
82
|
+
export declare const emit_supersede_audits: (ctx: ActionActorContext, audit: AuditEmitter, superseded: ReadonlyArray<SupersededOffer>, reason: RoleGrantOfferSupersedeParams["reason"], cause_id: Uuid) => Promise<void>;
|
|
63
83
|
/**
|
|
64
84
|
* Authorization callback for `role_grant_offer_create` and `role_grant_assign`.
|
|
65
85
|
* Returns `true` to allow, `false` to reject (handler converts to `forbidden`
|
|
@@ -73,6 +93,10 @@ import type { RevokingActionFactoryDeps } from './deps.js';
|
|
|
73
93
|
* role that must be scoped, a scope that must be real) holds on both paths.
|
|
74
94
|
* Twin of the Rust `OfferCreateAuthorize`.
|
|
75
95
|
*
|
|
96
|
+
* An offer authorized by a scoped grant must stay at that grant's scope: a
|
|
97
|
+
* scope teardown (`query_role_grant_revoke_for_scope`) supersedes only that
|
|
98
|
+
* scope's offers, so a revokee's offers elsewhere survive it.
|
|
99
|
+
*
|
|
76
100
|
* `ctx` is the request's: both verbs have side effects, so `ctx.db` is the
|
|
77
101
|
* request transaction, and a callback needing the database (a scope-existence
|
|
78
102
|
* check, say) reads through it. **Read-only** — the callback decides, it never
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"role_grant_offer_actions.d.ts","sourceRoot":"","sources":["../../src/lib/auth/role_grant_offer_actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;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