@fuzdev/fuz_app 0.183.0 → 0.184.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/CLAUDE.md +535 -1223
- package/dist/actions/action_codegen.d.ts +1 -1
- package/dist/actions/action_codegen.d.ts.map +1 -1
- package/dist/actions/action_codegen.js +3 -2
- package/dist/actions/connection_closer.d.ts +11 -9
- package/dist/actions/connection_closer.d.ts.map +1 -1
- package/dist/actions/connection_closer.js +11 -9
- package/dist/actions/frontend_rpc_client.d.ts +1 -1
- package/dist/actions/register_action_ws.d.ts +14 -1
- package/dist/actions/register_action_ws.d.ts.map +1 -1
- package/dist/actions/register_action_ws.js +2 -1
- package/dist/actions/ws_socket_session.d.ts +9 -1
- package/dist/actions/ws_socket_session.d.ts.map +1 -1
- package/dist/actions/ws_socket_session.js +43 -19
- package/dist/auth/CLAUDE.md +430 -1048
- package/dist/auth/account_queries.d.ts +1 -1
- package/dist/auth/account_queries.js +1 -1
- package/dist/auth/account_routes.d.ts +4 -5
- package/dist/auth/account_routes.d.ts.map +1 -1
- package/dist/auth/account_routes.js +8 -10
- package/dist/auth/admin_actions.d.ts.map +1 -1
- package/dist/auth/admin_actions.js +10 -11
- package/dist/auth/api_token.d.ts +20 -3
- package/dist/auth/api_token.d.ts.map +1 -1
- package/dist/auth/api_token.js +28 -9
- package/dist/auth/api_token_queries.d.ts +2 -2
- package/dist/auth/api_token_queries.js +2 -2
- package/dist/auth/audit_log_schema.d.ts +15 -9
- package/dist/auth/audit_log_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_schema.js +1 -2
- package/dist/auth/auth_guard_resolver.d.ts +1 -1
- package/dist/auth/auth_guard_resolver.js +1 -1
- package/dist/auth/bearer_auth.d.ts +2 -5
- package/dist/auth/bearer_auth.d.ts.map +1 -1
- package/dist/auth/bearer_auth.js +4 -13
- package/dist/auth/bootstrap_account.d.ts +13 -15
- package/dist/auth/bootstrap_account.d.ts.map +1 -1
- package/dist/auth/bootstrap_account.js +9 -11
- package/dist/auth/bootstrap_routes.d.ts +20 -21
- package/dist/auth/bootstrap_routes.d.ts.map +1 -1
- package/dist/auth/bootstrap_routes.js +21 -19
- package/dist/auth/bootstrap_token_store.d.ts +3 -4
- package/dist/auth/bootstrap_token_store.d.ts.map +1 -1
- package/dist/auth/bootstrap_token_store.js +1 -1
- package/dist/auth/daemon_token.d.ts +5 -1
- package/dist/auth/daemon_token.d.ts.map +1 -1
- package/dist/auth/daemon_token_middleware.d.ts +12 -8
- package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
- package/dist/auth/daemon_token_middleware.js +15 -21
- package/dist/auth/deps.d.ts +11 -0
- package/dist/auth/deps.d.ts.map +1 -1
- package/dist/auth/invite_queries.d.ts +51 -3
- package/dist/auth/invite_queries.d.ts.map +1 -1
- package/dist/auth/invite_queries.js +81 -6
- package/dist/auth/invite_schema.d.ts +2 -1
- package/dist/auth/invite_schema.d.ts.map +1 -1
- package/dist/auth/middleware.d.ts +2 -3
- package/dist/auth/middleware.d.ts.map +1 -1
- package/dist/auth/middleware.js +3 -3
- package/dist/auth/request_context.d.ts +3 -3
- package/dist/auth/request_context.js +3 -3
- package/dist/auth/role_grant_offer_actions.d.ts +2 -2
- package/dist/auth/role_grant_offer_actions.js +2 -2
- package/dist/auth/session_cookie.d.ts +82 -174
- package/dist/auth/session_cookie.d.ts.map +1 -1
- package/dist/auth/session_cookie.js +80 -130
- package/dist/auth/session_middleware.d.ts +8 -17
- package/dist/auth/session_middleware.d.ts.map +1 -1
- package/dist/auth/session_middleware.js +14 -23
- package/dist/auth/session_queries.d.ts +9 -14
- package/dist/auth/session_queries.d.ts.map +1 -1
- package/dist/auth/session_queries.js +8 -9
- package/dist/auth/signup_routes.d.ts.map +1 -1
- package/dist/auth/signup_routes.js +4 -6
- package/dist/db/CLAUDE.md +5 -3
- package/dist/dev/setup.d.ts +3 -1
- package/dist/dev/setup.d.ts.map +1 -1
- package/dist/dev/setup.js +3 -1
- package/dist/http/CLAUDE.md +315 -768
- package/dist/http/db_routes.d.ts +1 -1
- package/dist/http/db_routes.js +1 -1
- package/dist/http/origin.d.ts +7 -8
- package/dist/http/origin.d.ts.map +1 -1
- package/dist/http/origin.js +7 -8
- package/dist/http/pending_effects.d.ts +78 -4
- package/dist/http/pending_effects.d.ts.map +1 -1
- package/dist/http/pending_effects.js +82 -4
- package/dist/http/route_result.d.ts +1 -1
- package/dist/http/route_spec.d.ts +14 -11
- package/dist/http/route_spec.d.ts.map +1 -1
- package/dist/realtime/sse.d.ts +4 -23
- package/dist/realtime/sse.d.ts.map +1 -1
- package/dist/realtime/sse.js +4 -25
- package/dist/server/app_backend.d.ts +4 -5
- 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 +53 -30
- package/dist/server/app_server.d.ts.map +1 -1
- package/dist/server/app_server.js +81 -53
- package/dist/server/app_server_context.d.ts +1 -2
- package/dist/server/app_server_context.d.ts.map +1 -1
- package/dist/server/env.js +2 -2
- package/dist/testing/CLAUDE.md +17 -17
- package/dist/testing/admin_integration.d.ts +2 -3
- package/dist/testing/admin_integration.d.ts.map +1 -1
- package/dist/testing/admin_integration.js +3 -3
- package/dist/testing/app_server.d.ts +3 -8
- package/dist/testing/app_server.d.ts.map +1 -1
- package/dist/testing/app_server.js +10 -9
- package/dist/testing/attack_surface.d.ts +1 -1
- package/dist/testing/attack_surface.d.ts.map +1 -1
- package/dist/testing/audit_completeness.d.ts +2 -3
- package/dist/testing/audit_completeness.d.ts.map +1 -1
- package/dist/testing/audit_completeness.js +1 -1
- package/dist/testing/cross_backend/capability_mounts.d.ts.map +1 -1
- package/dist/testing/cross_backend/capability_mounts.js +16 -11
- package/dist/testing/cross_backend/conformance_table.d.ts +5 -6
- package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_table.js +4 -4
- package/dist/testing/cross_backend/cookie_attributes.js +1 -1
- package/dist/testing/cross_backend/default_backend_configs.d.ts +3 -3
- package/dist/testing/cross_backend/default_spine_surface.d.ts +0 -6
- package/dist/testing/cross_backend/default_spine_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/default_spine_surface.js +4 -9
- package/dist/testing/cross_backend/differential.d.ts +2 -3
- package/dist/testing/cross_backend/differential.d.ts.map +1 -1
- package/dist/testing/cross_backend/differential.js +1 -1
- package/dist/testing/cross_backend/full_spine_mount.d.ts +1 -42
- package/dist/testing/cross_backend/full_spine_mount.d.ts.map +1 -1
- package/dist/testing/cross_backend/full_spine_mount.js +45 -4
- package/dist/testing/cross_backend/in_process_setup.d.ts +6 -7
- package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/in_process_setup.js +9 -12
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +3 -4
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/rust_spine_consumer_surface.js +2 -2
- package/dist/testing/cross_backend/setup.d.ts +1 -1
- package/dist/testing/cross_backend/spine_suites.d.ts +2 -3
- package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_suites.js +5 -5
- package/dist/testing/cross_backend/standard.d.ts +2 -3
- package/dist/testing/cross_backend/standard.d.ts.map +1 -1
- package/dist/testing/cross_backend/standard.js +3 -3
- package/dist/testing/cross_backend/testing_credential_read.d.ts +10 -11
- package/dist/testing/cross_backend/testing_credential_read.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_credential_read.js +12 -12
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +35 -30
- package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_reset_actions.js +39 -31
- package/dist/testing/cross_backend/testing_server_core.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_server_core.js +2 -3
- package/dist/testing/daemon_token_rotation.d.ts.map +1 -1
- package/dist/testing/daemon_token_rotation.js +2 -3
- package/dist/testing/integration.d.ts +2 -3
- package/dist/testing/integration.d.ts.map +1 -1
- package/dist/testing/integration.js +4 -4
- package/dist/testing/rate_limiting.d.ts +2 -3
- package/dist/testing/rate_limiting.d.ts.map +1 -1
- package/dist/testing/rate_limiting.js +3 -3
- package/dist/testing/rpc_helpers.d.ts +1 -2
- package/dist/testing/rpc_helpers.d.ts.map +1 -1
- package/dist/testing/rpc_helpers.js +3 -3
- package/dist/testing/rpc_round_trip.d.ts +2 -3
- package/dist/testing/rpc_round_trip.d.ts.map +1 -1
- package/dist/testing/rpc_round_trip.js +1 -1
- package/dist/testing/sse_round_trip.d.ts +2 -3
- package/dist/testing/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/sse_round_trip.js +2 -2
- package/dist/testing/stubs.d.ts +5 -6
- package/dist/testing/stubs.d.ts.map +1 -1
- package/dist/testing/stubs.js +10 -8
- package/dist/testing/test_app.d.ts +5 -3
- package/dist/testing/test_app.d.ts.map +1 -1
- package/dist/testing/test_app.js +2 -3
- package/dist/testing/ws_round_trip.d.ts.map +1 -1
- package/dist/testing/ws_round_trip.js +3 -0
- package/dist/ui/ui_format.d.ts.map +1 -1
- package/dist/ui/ui_format.js +1 -2
- package/package.json +1 -1
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
* @module
|
|
8
8
|
*/
|
|
9
9
|
import { assert_row } from '../db/assert_row.js';
|
|
10
|
+
import { is_pg_unique_violation } from '../db/pg_error.js';
|
|
10
11
|
import { columns_sql, iso8601_timestamp_expr, qualify_columns } from '../db/sql_columns.js';
|
|
12
|
+
import { query_account_lock_live_many } from './account_queries.js';
|
|
11
13
|
/**
|
|
12
14
|
* The full `invite` column set, named explicitly so a row read fails loud on
|
|
13
15
|
* schema drift — invite rows ride the `invite_create` / `invite_list` RPC
|
|
@@ -29,17 +31,90 @@ export const INVITE_COLUMNS = [
|
|
|
29
31
|
/** The `invite` timestamp override, by row qualifier (`''` bare, `i` for the username JOIN). */
|
|
30
32
|
const invite_expr = iso8601_timestamp_expr(INVITE_COLUMNS, ['claimed_at', 'created_at']);
|
|
31
33
|
/**
|
|
32
|
-
*
|
|
34
|
+
* Error thrown by `query_create_invite` when an unclaimed invite already
|
|
35
|
+
* reserves the email or the username: the partial unique index
|
|
36
|
+
* `idx_invite_email_unclaimed` or `idx_invite_username_unclaimed` refused the
|
|
37
|
+
* insert (SQLSTATE `23505`), which aborts the caller's transaction. Twin of
|
|
38
|
+
* the Rust `InviteCreateError::Duplicate`.
|
|
39
|
+
*/
|
|
40
|
+
export class InviteDuplicateError extends Error {
|
|
41
|
+
constructor() {
|
|
42
|
+
super('an unclaimed invite already exists');
|
|
43
|
+
this.name = 'InviteDuplicateError';
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Error thrown by `query_create_invite` when the issuer is not an active
|
|
48
|
+
* account: its actor is missing or tombstoned, or its account soft-deleted — a
|
|
49
|
+
* delete that committed while the invite was in flight. Twin of the Rust
|
|
50
|
+
* `InviteCreateError::IssuerNotActive`.
|
|
51
|
+
*/
|
|
52
|
+
export class InviteIssuerNotActiveError extends Error {
|
|
53
|
+
constructor() {
|
|
54
|
+
super('the issuer is not an active account');
|
|
55
|
+
this.name = 'InviteIssuerNotActiveError';
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Create an invite issued by the actor `input.created_by`.
|
|
33
60
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
61
|
+
* The issuer must be an active actor of a live account, checked here so every
|
|
62
|
+
* caller — the spine's `invite_create` handler and a consumer minting invites
|
|
63
|
+
* on its own path — gets the rule: an invite records no authority, so one
|
|
64
|
+
* minted for an issuer deleted mid-flight would outlive the delete that should
|
|
65
|
+
* have voided it. The issuer's account row is read under `FOR SHARE`
|
|
66
|
+
* (`query_account_lock_live_many`) before the insert: an account delete writes
|
|
67
|
+
* its tombstone first, so a delete that wrote its tombstone before the read is
|
|
68
|
+
* waited for if uncommitted and seen (the invite is refused), and one that
|
|
69
|
+
* reaches the row after it waits for this transaction to
|
|
70
|
+
* commit and then deletes the invite with the account's other unclaimed ones
|
|
71
|
+
* (`query_invite_delete_unclaimed_by_creators`). The actor's tombstone is read
|
|
72
|
+
* after the lock, so a delete waited on is seen there too.
|
|
73
|
+
*
|
|
74
|
+
* Run it inside the caller's transaction, which the lock spans — on the pool
|
|
75
|
+
* the lock ends with its statement and orders nothing. Lock order: account
|
|
76
|
+
* rows come before actor and `role_grant` rows, as the last-admin guard
|
|
77
|
+
* (`query_count_active_accounts_with_global_role_locked`) takes them (account,
|
|
78
|
+
* then actor, then grant). So take it before the transaction locks any actor
|
|
79
|
+
* or `role_grant` row — or lock the issuer's account row first yourself
|
|
80
|
+
* (`query_account_lock_live_many`), which this query then re-takes without
|
|
81
|
+
* waiting: a transaction holding a lock on the issuer's admin grant while it
|
|
82
|
+
* waits here on an account row a removal holds, while the removal's guard
|
|
83
|
+
* waits on that grant, deadlocks.
|
|
84
|
+
*
|
|
85
|
+
* Callers that pre-check for account collisions on `email` / `username` do so
|
|
86
|
+
* upstream. Twin of the Rust `query_create_invite`.
|
|
87
|
+
*
|
|
88
|
+
* @param deps - query dependencies (must be the caller's transaction)
|
|
89
|
+
* @param input - the invite fields and its issuing actor
|
|
36
90
|
* @returns the created invite
|
|
37
91
|
* @mutates `invite` table - inserts the new row
|
|
92
|
+
* @throws InviteIssuerNotActiveError if `created_by` names no actor, a tombstoned one, or one whose account is soft-deleted; nothing is inserted
|
|
93
|
+
* @throws InviteDuplicateError if an unclaimed invite with the same email or username already exists
|
|
38
94
|
*/
|
|
39
95
|
export const query_create_invite = async (deps, input) => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
96
|
+
// An actor's account never changes, so it is read unlocked.
|
|
97
|
+
const issuer = await deps.db.query_one(`SELECT account_id FROM actor WHERE id = $1`, [input.created_by]);
|
|
98
|
+
if (!issuer ||
|
|
99
|
+
!(await query_account_lock_live_many(deps, [issuer.account_id])).has(issuer.account_id)) {
|
|
100
|
+
throw new InviteIssuerNotActiveError();
|
|
101
|
+
}
|
|
102
|
+
// After the lock, so a delete it waited on is seen.
|
|
103
|
+
const issuer_actor = await deps.db.query_one(`SELECT id FROM actor WHERE id = $1 AND deleted_at IS NULL`, [input.created_by]);
|
|
104
|
+
if (!issuer_actor) {
|
|
105
|
+
throw new InviteIssuerNotActiveError();
|
|
106
|
+
}
|
|
107
|
+
let row;
|
|
108
|
+
try {
|
|
109
|
+
row = await deps.db.query_one(`INSERT INTO invite (email, username, created_by)
|
|
110
|
+
VALUES ($1, $2, $3)
|
|
111
|
+
RETURNING ${columns_sql(INVITE_COLUMNS, invite_expr(''))}`, [input.email ?? null, input.username ?? null, input.created_by]);
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
if (is_pg_unique_violation(err))
|
|
115
|
+
throw new InviteDuplicateError();
|
|
116
|
+
throw err;
|
|
117
|
+
}
|
|
43
118
|
return assert_row(row, 'INSERT INTO invite');
|
|
44
119
|
};
|
|
45
120
|
/**
|
|
@@ -52,6 +52,7 @@ export type InviteWithUsernamesJson = Infer<typeof InviteWithUsernamesJson>;
|
|
|
52
52
|
export interface CreateInviteInput {
|
|
53
53
|
email?: Email | null;
|
|
54
54
|
username?: Username | null;
|
|
55
|
-
|
|
55
|
+
/** The issuing actor, which must be active on a live account (`query_create_invite`). */
|
|
56
|
+
created_by: Uuid;
|
|
56
57
|
}
|
|
57
58
|
//# sourceMappingURL=invite_schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invite_schema.d.ts","sourceRoot":"","sources":["../../src/lib/auth/invite_schema.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAA4B,KAAK,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAEpF,OAAO,EAAE,KAAK,EAAgC,IAAI,EAAE,KAAK,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAEnG,oCAAoC;AACpC,MAAM,WAAW,MAAM;IACtB,EAAE,EAAE,IAAI,CAAC;IACT,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC1B,UAAU,EAAE,IAAI,GAAG,IAAI,CAAC;IACxB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,IAAI,GAAG,IAAI,CAAC;CACxB;AAED;;;GAGG;AACH,eAAO,MAAM,UAAU;;;;;;;;EAQrB,CAAC;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AAElD;;;GAGG;AACH,eAAO,MAAM,uBAAuB;;;;;;;;;;EAIlC,CAAC;AACH,MAAM,MAAM,uBAAuB,GAAG,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAE5E,oCAAoC;AACpC,MAAM,WAAW,iBAAiB;IACjC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC;IACrB,QAAQ,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC3B,UAAU,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"invite_schema.d.ts","sourceRoot":"","sources":["../../src/lib/auth/invite_schema.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAA4B,KAAK,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAEpF,OAAO,EAAE,KAAK,EAAgC,IAAI,EAAE,KAAK,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAEnG,oCAAoC;AACpC,MAAM,WAAW,MAAM;IACtB,EAAE,EAAE,IAAI,CAAC;IACT,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC1B,UAAU,EAAE,IAAI,GAAG,IAAI,CAAC;IACxB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,IAAI,GAAG,IAAI,CAAC;CACxB;AAED;;;GAGG;AACH,eAAO,MAAM,UAAU;;;;;;;;EAQrB,CAAC;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AAElD;;;GAGG;AACH,eAAO,MAAM,uBAAuB;;;;;;;;;;EAIlC,CAAC;AACH,MAAM,MAAM,uBAAuB,GAAG,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAE5E,oCAAoC;AACpC,MAAM,WAAW,iBAAiB;IACjC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC;IACrB,QAAQ,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC3B,yFAAyF;IACzF,UAAU,EAAE,IAAI,CAAC;CACjB"}
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @module
|
|
8
8
|
*/
|
|
9
|
-
import type { SessionOptions } from './session_cookie.js';
|
|
10
9
|
import type { AppDeps } from './deps.js';
|
|
11
10
|
import type { DaemonTokenState } from './daemon_token.js';
|
|
12
11
|
import type { MiddlewareCarveOut, MiddlewareSpec } from '../http/middleware_spec.js';
|
|
@@ -144,7 +143,7 @@ export declare const assert_middleware_stack_mounted: (stack_specs: ReadonlyArra
|
|
|
144
143
|
*/
|
|
145
144
|
export interface AuthMiddlewareOptions {
|
|
146
145
|
allowed_origins: Array<RegExp>;
|
|
147
|
-
|
|
146
|
+
session_cookie_name: string;
|
|
148
147
|
/**
|
|
149
148
|
* Path pattern for the session, request-context, bearer, and daemon-token
|
|
150
149
|
* layers (default: `AUTH_MIDDLEWARE_PATH`, `'/api/*'`). The origin check
|
|
@@ -177,7 +176,7 @@ export interface AuthMiddlewareOptions {
|
|
|
177
176
|
* non-standard paths (e.g., tx's `/tx` binary endpoint).
|
|
178
177
|
*
|
|
179
178
|
* @param deps - stateless capabilities (keyring, db)
|
|
180
|
-
* @param options - middleware configuration (allowed_origins,
|
|
179
|
+
* @param options - middleware configuration (allowed_origins, session_cookie_name, path, daemon_token_state, origin_carve_outs)
|
|
181
180
|
* @throws Error when an origin carve-out has no path or no reason, or overlaps `path`
|
|
182
181
|
* @returns the middleware spec array
|
|
183
182
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/lib/auth/middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/lib/auth/middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACrF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAIvD;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAE1C;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,oBAAoB,WAAW,CAAC;AAE7C;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,6BAA6B,GACzC,QAAQ,eAAe,GAAG,cAAc,GAAG,wBAAwB,EACnE,MAAM,MAAM,KACV,IAQF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,sCAAsC,GAClD,aAAa,aAAa,CAAC,SAAS,CAAC,KACnC,IAcF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,8BAA8B,GAC1C,YAAY,aAAa,CAAC,kBAAkB,CAAC,EAC7C,YAAW,MAA6B,KACtC,IAkCF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,GACpC,YAAY,aAAa,CAAC,kBAAkB,CAAC,KAC3C,aAAa,CAAC,kBAAkB,CACkD,CAAC;AAEtF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,+BAA+B,GAC3C,aAAa,aAAa,CAAC,cAAc,CAAC,EAC1C,kBAAkB,aAAa,CAAC,cAAc,CAAC,KAC7C,IA+BF,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACrC,eAAe,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC/B,mBAAmB,EAAE,MAAM,CAAC;IAC5B;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;;OAMG;IACH,iBAAiB,CAAC,EAAE,aAAa,CAAC,kBAAkB,CAAC,CAAC;IACtD,mFAAmF;IACnF,kBAAkB,CAAC,EAAE,gBAAgB,CAAC;CACtC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,4BAA4B,GACxC,MAAM,OAAO,EACb,SAAS,qBAAqB,KAC5B,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,CAqF/B,CAAC"}
|
package/dist/auth/middleware.js
CHANGED
|
@@ -224,13 +224,13 @@ export const assert_middleware_stack_mounted = (stack_specs, middleware_specs) =
|
|
|
224
224
|
* non-standard paths (e.g., tx's `/tx` binary endpoint).
|
|
225
225
|
*
|
|
226
226
|
* @param deps - stateless capabilities (keyring, db)
|
|
227
|
-
* @param options - middleware configuration (allowed_origins,
|
|
227
|
+
* @param options - middleware configuration (allowed_origins, session_cookie_name, path, daemon_token_state, origin_carve_outs)
|
|
228
228
|
* @throws Error when an origin carve-out has no path or no reason, or overlaps `path`
|
|
229
229
|
* @returns the middleware spec array
|
|
230
230
|
*/
|
|
231
231
|
export const create_auth_middleware_specs = async (deps, options) => {
|
|
232
232
|
const { keyring, db } = deps;
|
|
233
|
-
const { allowed_origins,
|
|
233
|
+
const { allowed_origins, session_cookie_name, path = AUTH_MIDDLEWARE_PATH, daemon_token_state } = options;
|
|
234
234
|
// copied before it is checked, so what is checked is what runs
|
|
235
235
|
const origin_carve_outs = freeze_origin_carve_outs(options.origin_carve_outs ?? []);
|
|
236
236
|
assert_origin_carve_outs_valid(origin_carve_outs, path);
|
|
@@ -246,7 +246,7 @@ export const create_auth_middleware_specs = async (deps, options) => {
|
|
|
246
246
|
import('./request_context.js'),
|
|
247
247
|
import('./bearer_auth.js')
|
|
248
248
|
]);
|
|
249
|
-
const session_middleware = create_session_middleware(keyring,
|
|
249
|
+
const session_middleware = create_session_middleware(keyring, session_cookie_name);
|
|
250
250
|
// the first credential leg clears the resolved credential: the daemon
|
|
251
251
|
// token's when it is composed, else this one
|
|
252
252
|
const request_context_middleware = create_request_context_middleware(query_deps, {
|
|
@@ -489,9 +489,9 @@ export type AuthorizationResult = {
|
|
|
489
489
|
* Pure data — the function does not touch a Hono context. Each transport
|
|
490
490
|
* passes the account its credential resolved (`ResolvedAuth.account`) and
|
|
491
491
|
* binds the returned `AuthorizationResult` to its wire shape. The REST
|
|
492
|
-
* pipeline additionally writes `REQUEST_CONTEXT_KEY` on `c` for
|
|
493
|
-
* `require_role`
|
|
494
|
-
* the
|
|
492
|
+
* pipeline additionally writes `REQUEST_CONTEXT_KEY` on `c` for the
|
|
493
|
+
* downstream `require_role` middleware, which reads the resolved context off
|
|
494
|
+
* the Hono context.
|
|
495
495
|
*
|
|
496
496
|
* The account is never read here: the context is built on the credential
|
|
497
497
|
* leg's row, so a request reads its account once, as on the Rust spine,
|
|
@@ -499,9 +499,9 @@ export const build_request_context = async (deps, account, actor) => {
|
|
|
499
499
|
* Pure data — the function does not touch a Hono context. Each transport
|
|
500
500
|
* passes the account its credential resolved (`ResolvedAuth.account`) and
|
|
501
501
|
* binds the returned `AuthorizationResult` to its wire shape. The REST
|
|
502
|
-
* pipeline additionally writes `REQUEST_CONTEXT_KEY` on `c` for
|
|
503
|
-
* `require_role`
|
|
504
|
-
* the
|
|
502
|
+
* pipeline additionally writes `REQUEST_CONTEXT_KEY` on `c` for the
|
|
503
|
+
* downstream `require_role` middleware, which reads the resolved context off
|
|
504
|
+
* the Hono context.
|
|
505
505
|
*
|
|
506
506
|
* The account is never read here: the context is built on the credential
|
|
507
507
|
* leg's row, so a request reads its account once, as on the Rust spine,
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* The offer-lifecycle methods (create / accept / decline / retract / list /
|
|
5
5
|
* history) plus `role_grant_revoke` and `role_grant_assign` (both
|
|
6
6
|
* admin-only). All mount
|
|
7
|
-
* on a consumer's JSON-RPC endpoint
|
|
7
|
+
* on a consumer's JSON-RPC endpoint through `rpc_endpoints`. The action
|
|
8
8
|
* specs themselves live in `auth/role_grant_offer_action_specs.ts`. Mutations
|
|
9
9
|
* declare `side_effects: true` so the RPC dispatcher wraps the handler in
|
|
10
10
|
* a DB transaction; `role_grant_offer_list` and `role_grant_offer_history` declare
|
|
@@ -139,7 +139,7 @@ export interface RoleGrantOfferActionOptions {
|
|
|
139
139
|
*
|
|
140
140
|
* @param deps - `RevokingActionFactoryDeps`: `log`, `audit`, and the `connection_closer` a revoked global grant closes the revokee's role-gated connections through. WS notifications go through the handler context's `notification_sender`, not a dep
|
|
141
141
|
* @param options - role registry, default TTL, authorization override
|
|
142
|
-
* @returns the `RpcAction` array to spread into
|
|
142
|
+
* @returns the `RpcAction` array to spread into an `RpcEndpointSpec`'s `actions`
|
|
143
143
|
*/
|
|
144
144
|
export declare const create_role_grant_offer_actions: (deps: RevokingActionFactoryDeps, options?: RoleGrantOfferActionOptions) => Array<RpcAction>;
|
|
145
145
|
//# sourceMappingURL=role_grant_offer_actions.d.ts.map
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* The offer-lifecycle methods (create / accept / decline / retract / list /
|
|
5
5
|
* history) plus `role_grant_revoke` and `role_grant_assign` (both
|
|
6
6
|
* admin-only). All mount
|
|
7
|
-
* on a consumer's JSON-RPC endpoint
|
|
7
|
+
* on a consumer's JSON-RPC endpoint through `rpc_endpoints`. The action
|
|
8
8
|
* specs themselves live in `auth/role_grant_offer_action_specs.ts`. Mutations
|
|
9
9
|
* declare `side_effects: true` so the RPC dispatcher wraps the handler in
|
|
10
10
|
* a DB transaction; `role_grant_offer_list` and `role_grant_offer_history` declare
|
|
@@ -141,7 +141,7 @@ const default_authorize = async (auth, _input, _deps, _ctx) => {
|
|
|
141
141
|
*
|
|
142
142
|
* @param deps - `RevokingActionFactoryDeps`: `log`, `audit`, and the `connection_closer` a revoked global grant closes the revokee's role-gated connections through. WS notifications go through the handler context's `notification_sender`, not a dep
|
|
143
143
|
* @param options - role registry, default TTL, authorization override
|
|
144
|
-
* @returns the `RpcAction` array to spread into
|
|
144
|
+
* @returns the `RpcAction` array to spread into an `RpcEndpointSpec`'s `actions`
|
|
145
145
|
*/
|
|
146
146
|
export const create_role_grant_offer_actions = (deps, options = {}) => {
|
|
147
147
|
const { log, audit, connection_closer } = deps;
|
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The signed session cookie: its name, value format, verification, and the
|
|
3
|
+
* exact `Set-Cookie` strings that set and clear it — byte for byte the Rust
|
|
4
|
+
* spine's `fuz_auth::session_cookie`.
|
|
3
5
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* Cookie value format: `${encode(identity)}:${expires_at}` (signed with HMAC-SHA256).
|
|
6
|
+
* Cookie value: `keyring.sign("${session_token}:${expires_at}")`. The signed
|
|
7
|
+
* payload carries the raw session token (whose blake3 hash is the
|
|
8
|
+
* `auth_session` row id) and its expiry, so one HMAC covers both the token
|
|
9
|
+
* bind and the freshness check.
|
|
9
10
|
*
|
|
10
11
|
* @module
|
|
11
12
|
*/
|
|
12
13
|
import type { Keyring } from './keyring.js';
|
|
14
|
+
/**
|
|
15
|
+
* The default session cookie name — the Rust spine's `SESSION_COOKIE_NAME`,
|
|
16
|
+
* so a cookie either spine mints reads on both. An app with its own name
|
|
17
|
+
* passes it as `session_cookie_name` wherever the spine takes one.
|
|
18
|
+
*/
|
|
19
|
+
export declare const SESSION_COOKIE_NAME = "fuz_session";
|
|
13
20
|
/**
|
|
14
21
|
* Cookie max age in seconds (30 days — aligned with AUTH_SESSION_LIFETIME_MS).
|
|
15
22
|
*
|
|
16
23
|
* This is an **absolute** session lifetime: the cookie is signed once at
|
|
17
|
-
* mint (`expires_at = mint +
|
|
24
|
+
* mint (`expires_at = mint + SESSION_AGE_MAX`) and never re-signed, matching the DB
|
|
18
25
|
* row's fixed `expires_at`. There is deliberately no sliding renewal on
|
|
19
26
|
* either leg — see `docs/security.md` §Session Security.
|
|
20
27
|
*/
|
|
@@ -49,9 +56,8 @@ export declare const is_cookie_name: (name: string) => boolean;
|
|
|
49
56
|
* what a reader that decodes nothing needs. Twin of the Rust spine's
|
|
50
57
|
* `is_cookie_value`.
|
|
51
58
|
*
|
|
52
|
-
* Anything but a string is refused, whatever its type says:
|
|
53
|
-
*
|
|
54
|
-
* read `undefined` as the text `undefined`.
|
|
59
|
+
* Anything but a string is refused, whatever its type says: a regex alone
|
|
60
|
+
* would read `undefined` as the text `undefined`.
|
|
55
61
|
*
|
|
56
62
|
* @param value - a cookie value
|
|
57
63
|
*/
|
|
@@ -67,7 +73,7 @@ export declare const is_cookie_value: (value: string) => boolean;
|
|
|
67
73
|
* @param value - the signed cookie value (`create_session_cookie_value`)
|
|
68
74
|
* @param max_age - the cookie's lifetime in seconds
|
|
69
75
|
* @returns the `Set-Cookie` header value
|
|
70
|
-
* @throws Error when the name is not an RFC 6265 `cookie-name`, the value holds anything but `cookie-octet`s (
|
|
76
|
+
* @throws Error when the name is not an RFC 6265 `cookie-name`, the value holds anything but `cookie-octet`s (a space, a `;`, a non-ASCII character), or `max_age` is not a non-negative safe integer — a header that would read back differently is never written
|
|
71
77
|
*/
|
|
72
78
|
export declare const format_session_set_cookie: (cookie_name: string, value: string, max_age: number) => string;
|
|
73
79
|
/**
|
|
@@ -81,181 +87,83 @@ export declare const format_session_set_cookie: (cookie_name: string, value: str
|
|
|
81
87
|
*/
|
|
82
88
|
export declare const format_session_clear_cookie: (cookie_name: string) => string;
|
|
83
89
|
/**
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* The `TIdentity` type parameter determines the trust model:
|
|
90
|
-
* - `string` (e.g. a session_id) — the cookie references a server-side session record,
|
|
91
|
-
* enabling per-session revocation and metadata. Use when you need admin controls
|
|
92
|
-
* like "revoke all sessions" or per-session audit trails.
|
|
93
|
-
* - `number` (e.g. an account_id) — the cookie directly encodes the user identity,
|
|
94
|
-
* requiring no server-side session state. Simpler, but individual sessions
|
|
95
|
-
* can only be invalidated by rotating the signing key (which invalidates all sessions).
|
|
96
|
-
*
|
|
97
|
-
* The cookie helpers here take either. The spine's session middleware and
|
|
98
|
-
* auth chain take `SessionOptions<string>` — the identity is the session token
|
|
99
|
-
* the session leg hashes to find its `auth_session` row (`create_session_config`).
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* ```ts
|
|
103
|
-
* // zap: 3-part format (admin:session_id)
|
|
104
|
-
* const zap_config: SessionOptions<string> = {
|
|
105
|
-
* cookie_name: 'zap_session',
|
|
106
|
-
* encode_identity: (session_id) => `admin:${session_id}`,
|
|
107
|
-
* decode_identity: (payload) => {
|
|
108
|
-
* const parts = payload.split(':');
|
|
109
|
-
* if (parts.length !== 2 || parts[0] !== 'admin') return null;
|
|
110
|
-
* return parts[1] || null;
|
|
111
|
-
* },
|
|
112
|
-
* };
|
|
113
|
-
*
|
|
114
|
-
* // visiones: 1-part format (account_id)
|
|
115
|
-
* const visiones_config: SessionOptions<number> = {
|
|
116
|
-
* cookie_name: 'session_id',
|
|
117
|
-
* encode_identity: (id) => String(id),
|
|
118
|
-
* decode_identity: (payload) => {
|
|
119
|
-
* const n = parseInt(payload, 10);
|
|
120
|
-
* return Number.isFinite(n) && n > 0 ? n : null;
|
|
121
|
-
* },
|
|
122
|
-
* };
|
|
123
|
-
* ```
|
|
124
|
-
*/
|
|
125
|
-
export interface SessionOptions<TIdentity> {
|
|
126
|
-
cookie_name: string;
|
|
127
|
-
/**
|
|
128
|
-
* Cookie lifetime in seconds. Single source of truth for both the embedded
|
|
129
|
-
* `expires_at` (via `create_session_cookie_value`) and the cookie's HTTP
|
|
130
|
-
* `Max-Age` attribute (via `session_cookie_header`). Defaults to
|
|
131
|
-
* `SESSION_AGE_MAX` (30 days). Every other attribute is fixed
|
|
132
|
-
* (`SESSION_COOKIE_ATTRIBUTES`).
|
|
133
|
-
*/
|
|
134
|
-
max_age?: number;
|
|
135
|
-
/**
|
|
136
|
-
* Encode identity into the cookie payload (before the `:expires_at` suffix).
|
|
137
|
-
* The payload goes into the cookie as written, so it must hold only RFC
|
|
138
|
-
* 6265 `cookie-octet`s (`is_cookie_value`) — `session_cookie_header` throws
|
|
139
|
-
* on anything else.
|
|
140
|
-
*/
|
|
141
|
-
encode_identity: (identity: TIdentity) => string;
|
|
142
|
-
/** Decode identity from cookie payload. Return null if invalid. */
|
|
143
|
-
decode_identity: (payload: string) => TIdentity | null;
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* The `Set-Cookie` value that sets the session cookie to `value`, a signed
|
|
147
|
-
* cookie value (`create_session_cookie_value`, or the `cookie_value` of
|
|
148
|
-
* `create_capped_session`) — what a success carries
|
|
149
|
-
* (`route_ok(value, {set_cookie: [...]})`). `options.max_age` sets `Max-Age`,
|
|
150
|
-
* as it set the value's embedded expiry; `SESSION_AGE_MAX` when unset. Twin of
|
|
151
|
-
* the Rust `session_cookie_header`, which signs the token itself.
|
|
90
|
+
* Sign a session token into a session cookie value: the keyring's signature
|
|
91
|
+
* of `${session_token}:${expires_at}`, the expiry `SESSION_AGE_MAX` from now —
|
|
92
|
+
* what a `Cookie` header carries after `<name>=`. Signed once, at mint: the
|
|
93
|
+
* lifetime is absolute, never renewed (`docs/security.md` §Session Security).
|
|
94
|
+
* Twin of the Rust `create_session_cookie_value`.
|
|
152
95
|
*
|
|
153
|
-
* @param
|
|
154
|
-
* @param
|
|
155
|
-
* @
|
|
156
|
-
* @
|
|
96
|
+
* @param keyring - key ring for signing
|
|
97
|
+
* @param session_token - the raw session token
|
|
98
|
+
* @param now_seconds - current time in seconds (for testing)
|
|
99
|
+
* @returns the signed cookie value
|
|
157
100
|
*/
|
|
158
|
-
export declare const
|
|
101
|
+
export declare const create_session_cookie_value: (keyring: Keyring, session_token: string, now_seconds?: number) => Promise<string>;
|
|
159
102
|
/**
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
* `
|
|
103
|
+
* Sign a session token and build the `Set-Cookie` header value that sets it
|
|
104
|
+
* under `cookie_name` — `format_session_set_cookie` over
|
|
105
|
+
* `create_session_cookie_value`, with `SESSION_AGE_MAX` as its lifetime. What
|
|
106
|
+
* a success that mints a session carries (`route_ok(value, {set_cookie})`).
|
|
107
|
+
* Twin of the Rust `sign_session_cookie`.
|
|
163
108
|
*
|
|
164
|
-
* @param
|
|
165
|
-
* @
|
|
166
|
-
* @
|
|
109
|
+
* @param keyring - key ring for signing
|
|
110
|
+
* @param session_token - the raw session token (`create_capped_session`'s `token`)
|
|
111
|
+
* @param cookie_name - the session cookie's name
|
|
112
|
+
* @returns the `Set-Cookie` header value
|
|
113
|
+
* @throws Error when the cookie name, or the signed value, is outside the RFC 6265 grammar
|
|
167
114
|
*/
|
|
168
|
-
export declare const
|
|
115
|
+
export declare const sign_session_cookie: (keyring: Keyring, session_token: string, cookie_name: string) => Promise<string>;
|
|
169
116
|
/**
|
|
170
|
-
*
|
|
117
|
+
* A verified, unexpired session cookie: the raw session token it carries and
|
|
118
|
+
* the expiry signed beside it. Twin of the Rust `SessionCookie`.
|
|
171
119
|
*/
|
|
172
|
-
export interface
|
|
173
|
-
/** The
|
|
174
|
-
|
|
175
|
-
/** Index of the key that verified the signature (0 = primary). */
|
|
176
|
-
key_index: number;
|
|
120
|
+
export interface SessionCookie {
|
|
121
|
+
/** The raw session token — its blake3 hash is the `auth_session` row id. */
|
|
122
|
+
token: string;
|
|
177
123
|
/** The signed expiry, in seconds since the Unix epoch — later than the parse. */
|
|
178
124
|
expires_at: number;
|
|
179
125
|
}
|
|
180
126
|
/**
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
127
|
+
* How a request's `Cookie` lines read for the session cookie — what the
|
|
128
|
+
* cookie alone shows, before any database work. Twin of the Rust
|
|
129
|
+
* `SessionCookieRead`.
|
|
130
|
+
*
|
|
131
|
+
* - `absent` — no pair names the cookie
|
|
132
|
+
* - `invalid` — a pair names it and its value fails verification: unreadable,
|
|
133
|
+
* a bad MAC, a signed expiry that has passed, an empty token, an empty
|
|
134
|
+
* value. What the session middleware clears.
|
|
135
|
+
* - `valid` — it verifies under the keyring and its signed expiry is ahead.
|
|
136
|
+
* Says nothing about the `auth_session` row.
|
|
137
|
+
*/
|
|
138
|
+
export type SessionCookieRead = {
|
|
139
|
+
kind: 'absent';
|
|
140
|
+
} | {
|
|
141
|
+
kind: 'invalid';
|
|
142
|
+
} | {
|
|
143
|
+
kind: 'valid';
|
|
144
|
+
cookie: SessionCookie;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* Read the session cookie out of a request's `Cookie` lines: the
|
|
148
|
+
* `cookie_name` pair (`read_session_cookie_value` — the first, verbatim),
|
|
149
|
+
* verified under the keyring, its signed expiry checked, its session token
|
|
150
|
+
* answered with that expiry.
|
|
151
|
+
*
|
|
152
|
+
* The three answers are what the cookie alone shows (`SessionCookieRead`). An
|
|
153
|
+
* empty value (`name=`) is a cookie sent with none: present and invalid. A
|
|
154
|
+
* valid cookie whose `auth_session` row is gone is still valid here; nothing
|
|
155
|
+
* clears it. There is deliberately no refresh: a re-sign would compute a
|
|
156
|
+
* fresh expiry past the row's fixed `expires_at`, so the lifetime is the one
|
|
157
|
+
* signing at mint, on both spines.
|
|
158
|
+
*
|
|
159
|
+
* Twin of the Rust `parse_session_from_cookies`, which takes the request's
|
|
160
|
+
* headers.
|
|
161
|
+
*
|
|
162
|
+
* @param cookie_lines - the request's `Cookie` header lines
|
|
191
163
|
* @param keyring - key ring for verification
|
|
192
|
-
* @param
|
|
193
|
-
* @param now_seconds - current time in seconds (for testing)
|
|
194
|
-
* @returns `ParsedSession` if valid, null if invalid/expired (the empty string included), undefined if missing
|
|
195
|
-
*/
|
|
196
|
-
export declare const parse_session: <TIdentity>(signed_value: string | null | undefined, keyring: Keyring, options: SessionOptions<TIdentity>, now_seconds?: number) => Promise<ParsedSession<TIdentity> | null | undefined>;
|
|
197
|
-
/**
|
|
198
|
-
* Create a signed session cookie value.
|
|
199
|
-
*
|
|
200
|
-
* Format: `${encode(identity)}:${expires_at}` signed with HMAC-SHA256.
|
|
201
|
-
* Embeds expiration in the signed value itself for defense-in-depth.
|
|
202
|
-
*
|
|
203
|
-
* @param keyring - key ring for signing
|
|
204
|
-
* @param identity - the identity to encode
|
|
205
|
-
* @param options - session configuration with encode logic
|
|
206
|
-
* @param now_seconds - current time in seconds (for testing)
|
|
207
|
-
* @returns signed cookie value string
|
|
208
|
-
*/
|
|
209
|
-
export declare const create_session_cookie_value: <TIdentity>(keyring: Keyring, identity: TIdentity, options: SessionOptions<TIdentity>, now_seconds?: number) => Promise<string>;
|
|
210
|
-
/**
|
|
211
|
-
* Result of processing a session cookie.
|
|
212
|
-
*/
|
|
213
|
-
export interface ProcessSessionResult<TIdentity> {
|
|
214
|
-
/** Whether the session is valid. */
|
|
215
|
-
valid: boolean;
|
|
216
|
-
/** Action the adapter should take. */
|
|
217
|
-
action: 'none' | 'clear';
|
|
218
|
-
/** The decoded identity if the cookie was valid. */
|
|
219
|
-
identity?: TIdentity;
|
|
220
|
-
/** The cookie's signed expiry, epoch seconds, if the cookie was valid. */
|
|
221
|
-
expires_at?: number;
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Create a session config for raw session token identity.
|
|
225
|
-
*
|
|
226
|
-
* The standard pattern: cookie stores the raw session token,
|
|
227
|
-
* server hashes it (blake3) to look up the `auth_session` row.
|
|
228
|
-
* Only the `cookie_name` varies per app.
|
|
229
|
-
*
|
|
230
|
-
* @param cookie_name - cookie name (e.g. `'zap_session'`, `'visiones_session'`)
|
|
231
|
-
* @returns a `SessionOptions<string>` ready for use with session middleware
|
|
232
|
-
*/
|
|
233
|
-
export declare const create_session_config: (cookie_name: string) => SessionOptions<string>;
|
|
234
|
-
/** Canonical session config for fuz_app auth. */
|
|
235
|
-
export declare const fuz_session_config: SessionOptions<string>;
|
|
236
|
-
/**
|
|
237
|
-
* Process a session cookie and determine what action to take.
|
|
238
|
-
*
|
|
239
|
-
* There is deliberately no refresh action: any re-sign computes a fresh
|
|
240
|
-
* `now + max_age` expiry, extending the cookie past the DB row's fixed
|
|
241
|
-
* `expires_at` — the holder would go silently anonymous while carrying a
|
|
242
|
-
* self-perpetuating cookie. The absolute lifetime is one signing at mint,
|
|
243
|
-
* on both legs, matching the Rust spine. A cookie signed by a retired
|
|
244
|
-
* (non-primary) key keeps verifying until the key leaves the keyring;
|
|
245
|
-
* retired keys are safe to drop after `SESSION_AGE_MAX` (see
|
|
246
|
-
* `docs/security.md` §Cookie Key Rotation).
|
|
247
|
-
*
|
|
248
|
-
* The three outcomes are what the cookie alone shows: no cookie (`action:
|
|
249
|
-
* 'none'`), a cookie that fails verification — unreadable, a bad MAC, a signed
|
|
250
|
-
* expiry that has passed, an empty identity, an empty value — (`action:
|
|
251
|
-
* 'clear'`), and a valid one. A valid cookie whose `auth_session` row is gone
|
|
252
|
-
* is still valid here; nothing clears it.
|
|
253
|
-
*
|
|
254
|
-
* @param signed_value - the raw cookie value, nullish when the request carries no session cookie
|
|
255
|
-
* @param keyring - key ring for verification and signing
|
|
256
|
-
* @param options - session configuration
|
|
164
|
+
* @param cookie_name - the session cookie's name
|
|
257
165
|
* @param now_seconds - current time in seconds (for testing)
|
|
258
|
-
* @returns
|
|
166
|
+
* @returns the cookie's reading
|
|
259
167
|
*/
|
|
260
|
-
export declare const
|
|
168
|
+
export declare const parse_session_from_cookies: (cookie_lines: ReadonlyArray<string>, keyring: Keyring, cookie_name: string, now_seconds?: number) => Promise<SessionCookieRead>;
|
|
261
169
|
//# sourceMappingURL=session_cookie.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session_cookie.d.ts","sourceRoot":"","sources":["../../src/lib/auth/session_cookie.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"session_cookie.d.ts","sourceRoot":"","sources":["../../src/lib/auth/session_cookie.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAG5C;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,gBAAgB,CAAC;AAEjD;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,QAAoB,CAAC;AAWjD;;;;;;;;;GASG;AACH,eAAO,MAAM,yBAAyB,8CAA8C,CAAC;AAQrF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,KAAG,OACW,CAAC;AAE1D;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,MAAM,KAAG,OACY,CAAC;AAgB7D;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,yBAAyB,GACrC,aAAa,MAAM,EACnB,OAAO,MAAM,EACb,SAAS,MAAM,KACb,MAeF,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,2BAA2B,GAAI,aAAa,MAAM,KAAG,MAGjE,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,2BAA2B,GACvC,SAAS,OAAO,EAChB,eAAe,MAAM,EACrB,cAAc,MAAM,KAClB,OAAO,CAAC,MAAM,CAGhB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,mBAAmB,GAC/B,SAAS,OAAO,EAChB,eAAe,MAAM,EACrB,aAAa,MAAM,KACjB,OAAO,CAAC,MAAM,CAKf,CAAC;AAEH;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC7B,4EAA4E;IAC5E,KAAK,EAAE,MAAM,CAAC;IACd,iFAAiF;IACjF,UAAU,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,iBAAiB,GAC5B;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,aAAa,CAAA;CAAE,CAAC;AAoCrF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,0BAA0B,GACtC,cAAc,aAAa,CAAC,MAAM,CAAC,EACnC,SAAS,OAAO,EAChB,aAAa,MAAM,EACnB,cAAc,MAAM,KAClB,OAAO,CAAC,iBAAiB,CAS3B,CAAC"}
|