@pithy-sh/auth 0.10.0 → 0.11.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 +1 -1
- package/dist/admin/users.js +1 -1
- package/dist/audit/actions.d.ts +19 -0
- package/dist/audit/actions.d.ts.map +1 -1
- package/dist/audit/actions.js +20 -1
- package/dist/audit/emit.d.ts +2 -0
- package/dist/audit/emit.d.ts.map +1 -1
- package/dist/audit/emit.js +1 -1
- package/dist/capability.d.ts +19 -0
- package/dist/capability.d.ts.map +1 -1
- package/dist/capability.js +20 -3
- package/dist/data/tables.d.ts +1 -0
- package/dist/data/tables.d.ts.map +1 -1
- package/dist/data/userLifecycle.d.ts +1 -0
- package/dist/data/userLifecycle.d.ts.map +1 -1
- package/dist/data/userLifecycle.js +2 -1
- package/dist/http/adminRoutes.d.ts.map +1 -1
- package/dist/http/adminRoutes.js +270 -5
- package/dist/http/guards.d.ts +8 -7
- package/dist/http/guards.d.ts.map +1 -1
- package/dist/http/guards.js +38 -7
- package/dist/http/middleware.d.ts +25 -1
- package/dist/http/middleware.d.ts.map +1 -1
- package/dist/http/middleware.js +44 -3
- package/dist/http/responses.d.ts +180 -0
- package/dist/http/responses.d.ts.map +1 -1
- package/dist/http/responses.js +142 -1
- package/dist/http/routes.d.ts +1 -0
- package/dist/http/routes.d.ts.map +1 -1
- package/dist/http/routes.js +45 -3
- package/dist/http/schemas.d.ts +57 -0
- package/dist/http/schemas.d.ts.map +1 -1
- package/dist/http/schemas.js +51 -1
- package/dist/http/views.d.ts +39 -2
- package/dist/http/views.d.ts.map +1 -1
- package/dist/http/views.js +105 -1
- package/dist/instance/auth.d.ts.map +1 -1
- package/dist/instance/auth.js +2 -2
- package/dist/lifecycle/audited.d.ts +48 -0
- package/dist/lifecycle/audited.d.ts.map +1 -0
- package/dist/lifecycle/audited.js +65 -0
- package/dist/lifecycle/enforce.d.ts +37 -2
- package/dist/lifecycle/enforce.d.ts.map +1 -1
- package/dist/lifecycle/enforce.js +46 -5
- package/dist/lifecycle/reason.d.ts +11 -0
- package/dist/lifecycle/reason.d.ts.map +1 -0
- package/dist/lifecycle/reason.js +13 -0
- package/dist/lifecycle/request.d.ts +5 -2
- package/dist/lifecycle/request.d.ts.map +1 -1
- package/dist/lifecycle/request.js +6 -2
- package/dist/lifecycle/transitions.d.ts +158 -18
- package/dist/lifecycle/transitions.d.ts.map +1 -1
- package/dist/lifecycle/transitions.js +344 -70
- package/dist/migrations/0005_purge_once.d.ts +22 -0
- package/dist/migrations/0005_purge_once.d.ts.map +1 -0
- package/dist/migrations/0005_purge_once.js +35 -0
- package/dist/migrations/pluginTables.d.ts +8 -0
- package/dist/migrations/pluginTables.d.ts.map +1 -1
- package/dist/migrations/pluginTables.js +8 -1
- package/dist/migrations/set.d.ts +2 -1
- package/dist/migrations/set.d.ts.map +1 -1
- package/dist/migrations/set.js +4 -2
- package/dist/purge/contribution.d.ts +47 -0
- package/dist/purge/contribution.d.ts.map +1 -0
- package/dist/purge/contribution.js +141 -0
- package/dist/purge/retryPolicy.d.ts +22 -0
- package/dist/purge/retryPolicy.d.ts.map +1 -0
- package/dist/purge/retryPolicy.js +26 -0
- package/dist/purge/run.d.ts +88 -0
- package/dist/purge/run.d.ts.map +1 -0
- package/dist/purge/run.js +102 -0
- package/dist/purge/specs.d.ts +71 -0
- package/dist/purge/specs.d.ts.map +1 -0
- package/dist/purge/specs.js +72 -0
- package/dist/purge/start.d.ts +42 -0
- package/dist/purge/start.d.ts.map +1 -0
- package/dist/purge/start.js +37 -0
- package/dist/purge/workflow.d.ts +58 -0
- package/dist/purge/workflow.d.ts.map +1 -0
- package/dist/purge/workflow.js +96 -0
- package/dist/test-utils/accountFootprint.d.ts +10 -0
- package/dist/test-utils/accountFootprint.d.ts.map +1 -0
- package/dist/test-utils/accountFootprint.js +44 -0
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.js +1 -1
- package/docs/account-lifecycle.md +123 -11
- package/package.json +5 -5
- package/pithy.manifest.json +1 -1
- package/src/audit/actions.ts +19 -0
- package/src/audit/emit.ts +3 -1
- package/src/capability.ts +48 -1
- package/src/data/userLifecycle.ts +4 -1
- package/src/http/adminRoutes.ts +398 -2
- package/src/http/guards.ts +39 -7
- package/src/http/middleware.ts +45 -2
- package/src/http/responses.ts +245 -0
- package/src/http/routes.ts +55 -3
- package/src/http/schemas.ts +110 -0
- package/src/http/views.ts +147 -2
- package/src/instance/auth.ts +7 -2
- package/src/lifecycle/audited.ts +104 -0
- package/src/lifecycle/enforce.ts +55 -5
- package/src/lifecycle/reason.ts +11 -0
- package/src/lifecycle/request.ts +10 -2
- package/src/lifecycle/transitions.ts +482 -93
- package/src/migrations/0005_purge_once.ts +42 -0
- package/src/migrations/pluginTables.ts +19 -1
- package/src/migrations/set.ts +3 -1
- package/src/purge/contribution.ts +191 -0
- package/src/purge/retryPolicy.ts +26 -0
- package/src/purge/run.ts +185 -0
- package/src/purge/specs.ts +95 -0
- package/src/purge/start.ts +79 -0
- package/src/purge/workflow.ts +144 -0
- package/src/test-utils/accountFootprint.ts +95 -0
- package/src/version.generated.ts +1 -1
package/dist/http/views.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"views.d.ts","sourceRoot":"","sources":["../../src/http/views.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"views.d.ts","sourceRoot":"","sources":["../../src/http/views.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACh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,GAAG,qBAAqB,CAEnF;AAOD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE;IACxC,IAAI,EAAE,IAAI,CAAC;IACX,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAC;IAC7B,QAAQ,EAAE,SAAS,IAAI,CAAC,OAAO,EAAE,YAAY,GAAG,WAAW,CAAC,EAAE,CAAC;IAC/D,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,OAAO,EAAE,SAAS,kBAAkB,EAAE,CAAC;IACvC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;CACrD,GAAG,cAAc,CAyBjB;AAED,kGAAkG;AAClG,wBAAgB,UAAU,CACxB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,IAAI,EAChB,OAAO,EAAE,SAAS,gBAAgB,EAAE,GACnC,uBAAuB,CAMzB"}
|
package/dist/http/views.js
CHANGED
|
@@ -84,5 +84,109 @@ function deviceView(device) {
|
|
|
84
84
|
createdAt: device.createdAt.toISOString()
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* The suspension projection (#621): the suspension the transition left in force, and the sessions the route
|
|
89
|
+
* revoked after it. Dates cross as ISO-8601, like every other response here.
|
|
90
|
+
*/
|
|
91
|
+
function suspensionView(userId, result, sessionsRevoked) {
|
|
92
|
+
return {
|
|
93
|
+
userId,
|
|
94
|
+
state: "suspended",
|
|
95
|
+
outcome: result.updated ? "updated" : "suspended",
|
|
96
|
+
suspendedAt: result.suspendedAt.toISOString(),
|
|
97
|
+
suspendedUntil: result.suspendedUntil?.toISOString() ?? null,
|
|
98
|
+
sessionsRevoked,
|
|
99
|
+
mailed: result.mailed
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/** The reinstatement projection (#621). A call that found no suspension in force is `unchanged`. */
|
|
103
|
+
function reinstatementView(userId, result) {
|
|
104
|
+
return {
|
|
105
|
+
userId,
|
|
106
|
+
state: "active",
|
|
107
|
+
outcome: result.changed ? "reinstated" : "unchanged",
|
|
108
|
+
mailed: result.mailed
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The deletion projection (#622): the deletion the transition left in force, the sessions the route revoked
|
|
113
|
+
* after it, and what became of the purge.
|
|
114
|
+
*/
|
|
115
|
+
function deletionView(userId, mode, result, purge, sessionsRevoked) {
|
|
116
|
+
return {
|
|
117
|
+
userId,
|
|
118
|
+
state: "deleted",
|
|
119
|
+
mode,
|
|
120
|
+
outcome: result.outcome,
|
|
121
|
+
deletedAt: result.deletedAt.toISOString(),
|
|
122
|
+
purgeAfter: result.purgeAfter.toISOString(),
|
|
123
|
+
purge,
|
|
124
|
+
sessionsRevoked,
|
|
125
|
+
mailed: result.mailed
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/** The restoration projection (#622). A call that found the account not deleted is `unchanged`. */
|
|
129
|
+
function restorationView(userId, result) {
|
|
130
|
+
return {
|
|
131
|
+
userId,
|
|
132
|
+
state: result.state,
|
|
133
|
+
outcome: result.changed ? "restored" : "unchanged"
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/** The self-service deletion projection (#622). */
|
|
137
|
+
function accountDeletionView(result) {
|
|
138
|
+
return {
|
|
139
|
+
state: "deleted",
|
|
140
|
+
purgeAfter: result.purgeAfter.toISOString(),
|
|
141
|
+
mailed: result.mailed
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/** A date as the wire carries it, or null. */
|
|
145
|
+
function iso(date) {
|
|
146
|
+
return date ? date.toISOString() : null;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* What auth holds about one account, as its export carries it (#622) — the person's own data, projected through
|
|
150
|
+
* the same views a support pane sees, so a session token, a provider token and a push token are absent here by
|
|
151
|
+
* the same construction that keeps them out of every other response. The operator who made a transition is
|
|
152
|
+
* theirs to disclose, not the person's, so the history carries the kind of actor and not its id.
|
|
153
|
+
*/
|
|
154
|
+
function authUserExportView(input) {
|
|
155
|
+
const { user } = input;
|
|
156
|
+
return {
|
|
157
|
+
user: {
|
|
158
|
+
...userView(user),
|
|
159
|
+
suspendedAt: iso(user.suspendedAt),
|
|
160
|
+
suspendedUntil: iso(user.suspendedUntil),
|
|
161
|
+
deletedAt: iso(user.deletedAt),
|
|
162
|
+
purgeAfter: iso(user.purgeAfter)
|
|
163
|
+
},
|
|
164
|
+
sessions: input.sessions.map(sessionView),
|
|
165
|
+
providers: input.accounts.map((account) => ({
|
|
166
|
+
providerId: account.providerId,
|
|
167
|
+
createdAt: account.createdAt.toISOString()
|
|
168
|
+
})),
|
|
169
|
+
devices: input.devices.map(deviceView),
|
|
170
|
+
history: input.history.map((event) => ({
|
|
171
|
+
action: event.action,
|
|
172
|
+
actorType: event.actorType,
|
|
173
|
+
reason: event.reason,
|
|
174
|
+
suspendedUntil: iso(event.suspendedUntil),
|
|
175
|
+
createdAt: event.createdAt.toISOString()
|
|
176
|
+
})),
|
|
177
|
+
plugins: input.plugins ?? {}
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
/** The export document (#622): who it is about, when it was read, and every capability's part. */
|
|
181
|
+
function exportView(userId, exportedAt, entries) {
|
|
182
|
+
return {
|
|
183
|
+
subject: {
|
|
184
|
+
type: "user",
|
|
185
|
+
id: userId
|
|
186
|
+
},
|
|
187
|
+
exportedAt: exportedAt.toISOString(),
|
|
188
|
+
capabilities: entries.map((entry) => ({ ...entry }))
|
|
189
|
+
};
|
|
190
|
+
}
|
|
87
191
|
//#endregion
|
|
88
|
-
export { deviceView, sessionView, userView };
|
|
192
|
+
export { accountDeletionView, authUserExportView, deletionView, deviceView, exportView, reinstatementView, restorationView, sessionView, suspensionView, userView };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/instance/auth.ts"],"names":[],"mappings":"AAGA,OAAO,KAA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T_SESSION_FIELDS, KIT_USER_FIELDS } from "../data/kitFields.js";
|
|
6
6
|
import { parseDeviceMeta, registerDevice } from "../device/registry.js";
|
|
7
7
|
import "../http/providerFreshness.js";
|
|
8
|
-
import { lifecycleRefusalFor } from "../lifecycle/enforce.js";
|
|
8
|
+
import { admitsDeletionSignIn, lifecycleRefusalFor } from "../lifecycle/enforce.js";
|
|
9
9
|
import { refuseUnsafeProfile, sanitizeProfile } from "../profile/profile.js";
|
|
10
10
|
import { defaultGithubUserInfo } from "./githubUserInfo.js";
|
|
11
11
|
import { microsoftProfileToUser } from "./microsoftEmail.js";
|
|
@@ -290,7 +290,7 @@ function makeAuth(deps) {
|
|
|
290
290
|
*/
|
|
291
291
|
before: async (session, ctx) => {
|
|
292
292
|
const refusal = await lifecycleRefusalFor(deps.db, session.userId, null, /* @__PURE__ */ new Date());
|
|
293
|
-
if (refusal) refuseSession(refusal, ctx);
|
|
293
|
+
if (refusal && !admitsDeletionSignIn(refusal, ctx?.headers)) refuseSession(refusal, ctx);
|
|
294
294
|
const carried = session.authenticatedAt;
|
|
295
295
|
const authenticatedAt = carried !== void 0 ? carried : /* @__PURE__ */ new Date();
|
|
296
296
|
const meta = ctx?.headers ? parseDeviceMeta(ctx.headers) : void 0;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import type { AuditEmit } from "@pithy-sh/core/src/audit/recorder";
|
|
4
|
+
/**
|
|
5
|
+
* Every control-plane lifecycle call is audited, including the ones that changed nothing (#621).
|
|
6
|
+
*
|
|
7
|
+
* A transition that moves the account writes its own audit event, beside the history row, in
|
|
8
|
+
* `./transitions.ts`. That leaves two kinds of call with no event, and both matter to somebody reading the
|
|
9
|
+
* trail after an incident: **a refusal** — an unknown account, a deleted one, an end in the past — which says
|
|
10
|
+
* a credential was trying, and **a call that found the account already where it asked to put it**, which
|
|
11
|
+
* says somebody pressed the button. This records both, under the same action as the transition, so one
|
|
12
|
+
* filter finds every attempt: a refusal is `denied` (or `failure` for a fault) with the code, and a no-op is
|
|
13
|
+
* a `success` with `changed: false`. A refusal is still thrown, unchanged.
|
|
14
|
+
*
|
|
15
|
+
* A body the route's validator refuses never reaches the call, so the route records it with
|
|
16
|
+
* {@link recordLifecycleRefusal}, on the same event, before the 400 is thrown.
|
|
17
|
+
*/
|
|
18
|
+
/** Who called, about whom, and why — what every lifecycle audit event carries. */
|
|
19
|
+
export interface LifecycleCall {
|
|
20
|
+
/** The audit action the transition writes when it moves the account. */
|
|
21
|
+
readonly action: string;
|
|
22
|
+
/** The management client's verified `sub`: which person acted. */
|
|
23
|
+
readonly subject: string;
|
|
24
|
+
/** The connection the call came through. */
|
|
25
|
+
readonly connectionId: string;
|
|
26
|
+
/** The account acted on. */
|
|
27
|
+
readonly userId: string;
|
|
28
|
+
/** The reason the caller gave — `null` for a refused body that carried none. */
|
|
29
|
+
readonly reason: string | null;
|
|
30
|
+
/** The request's correlation. */
|
|
31
|
+
readonly ip?: string | undefined;
|
|
32
|
+
readonly userAgent?: string | undefined;
|
|
33
|
+
readonly requestId?: string | undefined;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Record one refused lifecycle call — `denied` with its code, or `failure` for a fault. `code` names the
|
|
37
|
+
* refusal when the thrown error carries none of its own, as a body Hono could not parse does not.
|
|
38
|
+
*/
|
|
39
|
+
export declare function recordLifecycleRefusal(emit: AuditEmit, call: LifecycleCall, error: unknown, fallback?: {
|
|
40
|
+
code: string;
|
|
41
|
+
outcome: "denied" | "failure";
|
|
42
|
+
}): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Run one lifecycle call and audit whatever the transition did not. `unchanged` says whether a result is a
|
|
45
|
+
* call that changed nothing; the event for a call that did change something is the transition's own.
|
|
46
|
+
*/
|
|
47
|
+
export declare function auditedLifecycleCall<T>(emit: AuditEmit, call: LifecycleCall, run: () => Promise<T>, unchanged: (result: T) => boolean): Promise<T>;
|
|
48
|
+
//# sourceMappingURL=audited.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audited.d.ts","sourceRoot":"","sources":["../../src/lifecycle/audited.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAInE;;;;;;;;;;;;;GAaG;AAEH,kFAAkF;AAClF,MAAM,WAAW,aAAa;IAC5B,wEAAwE;IACxE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,kEAAkE;IAClE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,4CAA4C;IAC5C,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,4BAA4B;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,gFAAgF;IAChF,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,iCAAiC;IACjC,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACzC;AA0BD;;;GAGG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,aAAa,EACnB,KAAK,EAAE,OAAO,EACd,QAAQ,CAAC,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,QAAQ,GAAG,SAAS,CAAA;CAAE,GACzD,OAAO,CAAC,IAAI,CAAC,CAOf;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CAAC,CAAC,EAC1C,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,aAAa,EACnB,GAAG,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACrB,SAAS,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,GAChC,OAAO,CAAC,CAAC,CAAC,CAYZ"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import { emitControlPlaneAction } from "../audit/emit.js";
|
|
4
|
+
import { PithyError } from "@pithy-sh/core/src/error/pithyError";
|
|
5
|
+
//#region src/lifecycle/audited.ts
|
|
6
|
+
/** The public code of a thrown error, or `core/internal` for anything that is not a `PithyError`. */
|
|
7
|
+
function codeOf(error) {
|
|
8
|
+
return error instanceof PithyError ? error.payload.code : "core/internal";
|
|
9
|
+
}
|
|
10
|
+
/** A refusal this Worker made on purpose is `denied`; a fault, a 5xx or a throw that is not ours, `failure`. */
|
|
11
|
+
function outcomeOf(error) {
|
|
12
|
+
return error instanceof PithyError && error.payload.status < 500 ? "denied" : "failure";
|
|
13
|
+
}
|
|
14
|
+
/** The event every lifecycle audit record shares, before its outcome and metadata. */
|
|
15
|
+
function eventOf(call) {
|
|
16
|
+
return {
|
|
17
|
+
action: call.action,
|
|
18
|
+
subject: call.subject,
|
|
19
|
+
connectionId: call.connectionId,
|
|
20
|
+
resourceType: "user",
|
|
21
|
+
resourceId: call.userId,
|
|
22
|
+
ip: call.ip,
|
|
23
|
+
userAgent: call.userAgent,
|
|
24
|
+
requestId: call.requestId
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Record one refused lifecycle call — `denied` with its code, or `failure` for a fault. `code` names the
|
|
29
|
+
* refusal when the thrown error carries none of its own, as a body Hono could not parse does not.
|
|
30
|
+
*/
|
|
31
|
+
async function recordLifecycleRefusal(emit, call, error, fallback) {
|
|
32
|
+
const ours = error instanceof PithyError;
|
|
33
|
+
await emitControlPlaneAction(emit, {
|
|
34
|
+
...eventOf(call),
|
|
35
|
+
outcome: ours || !fallback ? outcomeOf(error) : fallback.outcome,
|
|
36
|
+
metadata: {
|
|
37
|
+
reason: call.reason,
|
|
38
|
+
changed: false,
|
|
39
|
+
code: ours || !fallback ? codeOf(error) : fallback.code
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Run one lifecycle call and audit whatever the transition did not. `unchanged` says whether a result is a
|
|
45
|
+
* call that changed nothing; the event for a call that did change something is the transition's own.
|
|
46
|
+
*/
|
|
47
|
+
async function auditedLifecycleCall(emit, call, run, unchanged) {
|
|
48
|
+
let result;
|
|
49
|
+
try {
|
|
50
|
+
result = await run();
|
|
51
|
+
} catch (error) {
|
|
52
|
+
await recordLifecycleRefusal(emit, call, error);
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
if (unchanged(result)) await emitControlPlaneAction(emit, {
|
|
56
|
+
...eventOf(call),
|
|
57
|
+
metadata: {
|
|
58
|
+
reason: call.reason,
|
|
59
|
+
changed: false
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
//#endregion
|
|
65
|
+
export { auditedLifecycleCall, recordLifecycleRefusal };
|
|
@@ -33,8 +33,43 @@ export declare function readLifecycleColumns(db: AuthDatabase, userId: string):
|
|
|
33
33
|
* read here, which is the sign-in path: a session about to be created has no user object yet.
|
|
34
34
|
*/
|
|
35
35
|
export declare function lifecycleRefusalFor(db: AuthDatabase, userId: string, columns: Partial<LifecycleColumns> | null | undefined, now: Date): Promise<PithyError | null>;
|
|
36
|
-
/**
|
|
37
|
-
export
|
|
36
|
+
/** The holder of a refused credential: whose session it is. Known because the credential itself is genuine. */
|
|
37
|
+
export interface RefusedHolder {
|
|
38
|
+
/** The account the session belongs to. */
|
|
39
|
+
readonly userId: string;
|
|
40
|
+
/** The session the request presented. */
|
|
41
|
+
readonly sessionId: string;
|
|
42
|
+
}
|
|
43
|
+
/** Remember that this request's credential belongs to an account that may not act, and whose it is. */
|
|
44
|
+
export declare function noteRefusal(context: object, refusal: PithyError, holder?: RefusedHolder): void;
|
|
38
45
|
/** The refusal the session middleware reached for this request, if it reached one. */
|
|
39
46
|
export declare function noticedRefusal(context: object): PithyError | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* The holder of a **suspended** account's credential on this request, or `undefined` (#622).
|
|
49
|
+
*
|
|
50
|
+
* Only a suspension: a deleted account has nothing left to delete, and a check that could not be made has
|
|
51
|
+
* established nobody. The one reader is the self-service deletion, through `../http/middleware.ts`.
|
|
52
|
+
*/
|
|
53
|
+
export declare function suspendedHolder(context: object): RefusedHolder | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* The header a sign-in carries to ask for a session that can do nothing but delete its account, and the one
|
|
56
|
+
* value it takes (#622).
|
|
57
|
+
*
|
|
58
|
+
* A suspension revokes every session the account holds and refuses every new one, so without this a suspended
|
|
59
|
+
* person would hold no credential and could get none — and the one route a suspension leaves open, deleting the
|
|
60
|
+
* account, would be one nobody could reach. With it, the sign-in completes: the person still proves who they are,
|
|
61
|
+
* by the code, the link or the provider, exactly as for any sign-in. **The session that results is still a
|
|
62
|
+
* suspended account's**, so the session middleware refuses it everywhere, Better Auth's own endpoints included,
|
|
63
|
+
* and only `DELETE /auth/account` admits it. Nothing about the header is trusted beyond that: it asks for a
|
|
64
|
+
* session no more capable than none, save for leaving.
|
|
65
|
+
*/
|
|
66
|
+
export declare const ACCOUNT_DELETION_INTENT_HEADER = "x-pithy-intent";
|
|
67
|
+
/** The value of `ACCOUNT_DELETION_INTENT_HEADER` that asks for a deletion-only session. */
|
|
68
|
+
export declare const ACCOUNT_DELETION_INTENT = "delete-account";
|
|
69
|
+
/**
|
|
70
|
+
* Whether a sign-in refused with `refusal` may still create its session: only a **suspended** account's, and only
|
|
71
|
+
* when the request asks for nothing but deleting it. A deleted account has nothing left to delete, and a check
|
|
72
|
+
* that could not be made has established nobody, so neither is admitted.
|
|
73
|
+
*/
|
|
74
|
+
export declare function admitsDeletionSignIn(refusal: PithyError, headers: Headers | null | undefined): boolean;
|
|
40
75
|
//# sourceMappingURL=enforce.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enforce.d.ts","sourceRoot":"","sources":["../../src/lifecycle/enforce.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAmB,gBAAgB,EAAoB,MAAM,SAAS,CAAC;AAE9E;;;;;;;;;;;;;;;;;;GAkBG;AAEH,iHAAiH;AACjH,wBAAsB,gBAAgB,CAAC,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAW/F;AAED,kGAAkG;AAClG,wBAAsB,oBAAoB,CAAC,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAO7G;AAED;;;;;GAKG;AACH,wBAAsB,mBAAmB,CACvC,EAAE,EAAE,YAAY,EAChB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,IAAI,GAAG,SAAS,EACrD,GAAG,EAAE,IAAI,GACR,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAM5B;
|
|
1
|
+
{"version":3,"file":"enforce.d.ts","sourceRoot":"","sources":["../../src/lifecycle/enforce.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAmB,gBAAgB,EAAoB,MAAM,SAAS,CAAC;AAE9E;;;;;;;;;;;;;;;;;;GAkBG;AAEH,iHAAiH;AACjH,wBAAsB,gBAAgB,CAAC,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAW/F;AAED,kGAAkG;AAClG,wBAAsB,oBAAoB,CAAC,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAO7G;AAED;;;;;GAKG;AACH,wBAAsB,mBAAmB,CACvC,EAAE,EAAE,YAAY,EAChB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,IAAI,GAAG,SAAS,EACrD,GAAG,EAAE,IAAI,GACR,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAM5B;AAED,+GAA+G;AAC/G,MAAM,WAAW,aAAa;IAC5B,0CAA0C;IAC1C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,yCAAyC;IACzC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAgBD,uGAAuG;AACvG,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,aAAa,GAAG,IAAI,CAE9F;AAED,sFAAsF;AACtF,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAEtE;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAG1E;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,8BAA8B,mBAAmB,CAAC;AAC/D,2FAA2F;AAC3F,eAAO,MAAM,uBAAuB,mBAAmB,CAAC;AAExD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAItG"}
|
|
@@ -56,15 +56,56 @@ async function lifecycleRefusalFor(db, userId, columns, now) {
|
|
|
56
56
|
* capability's own guards read — a refused account already has no `AuthContext`, which is the part every
|
|
57
57
|
* other capability's guard needs. Keyed by the context the way `../http/resolve.ts` caches the instance, so
|
|
58
58
|
* it dies with the request.
|
|
59
|
+
*
|
|
60
|
+
* **The holder rides with it (#622).** A suspended account may still delete itself — the app stores require
|
|
61
|
+
* that a person can always leave — and that one route has to know whose account the refused credential
|
|
62
|
+
* opens. Nothing else reads it: the holder is reachable only through `accountHolder`, and only that route uses it.
|
|
59
63
|
*/
|
|
60
64
|
const refusals = /* @__PURE__ */ new WeakMap();
|
|
61
|
-
/** Remember that this request's credential belongs to an account that may not act. */
|
|
62
|
-
function noteRefusal(context, refusal) {
|
|
63
|
-
refusals.set(context,
|
|
65
|
+
/** Remember that this request's credential belongs to an account that may not act, and whose it is. */
|
|
66
|
+
function noteRefusal(context, refusal, holder) {
|
|
67
|
+
refusals.set(context, {
|
|
68
|
+
refusal,
|
|
69
|
+
holder
|
|
70
|
+
});
|
|
64
71
|
}
|
|
65
72
|
/** The refusal the session middleware reached for this request, if it reached one. */
|
|
66
73
|
function noticedRefusal(context) {
|
|
67
|
-
return refusals.get(context);
|
|
74
|
+
return refusals.get(context)?.refusal;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The holder of a **suspended** account's credential on this request, or `undefined` (#622).
|
|
78
|
+
*
|
|
79
|
+
* Only a suspension: a deleted account has nothing left to delete, and a check that could not be made has
|
|
80
|
+
* established nobody. The one reader is the self-service deletion, through `../http/middleware.ts`.
|
|
81
|
+
*/
|
|
82
|
+
function suspendedHolder(context) {
|
|
83
|
+
const noted = refusals.get(context);
|
|
84
|
+
return noted?.refusal.payload.code === "auth/account_suspended" ? noted.holder : void 0;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The header a sign-in carries to ask for a session that can do nothing but delete its account, and the one
|
|
88
|
+
* value it takes (#622).
|
|
89
|
+
*
|
|
90
|
+
* A suspension revokes every session the account holds and refuses every new one, so without this a suspended
|
|
91
|
+
* person would hold no credential and could get none — and the one route a suspension leaves open, deleting the
|
|
92
|
+
* account, would be one nobody could reach. With it, the sign-in completes: the person still proves who they are,
|
|
93
|
+
* by the code, the link or the provider, exactly as for any sign-in. **The session that results is still a
|
|
94
|
+
* suspended account's**, so the session middleware refuses it everywhere, Better Auth's own endpoints included,
|
|
95
|
+
* and only `DELETE /auth/account` admits it. Nothing about the header is trusted beyond that: it asks for a
|
|
96
|
+
* session no more capable than none, save for leaving.
|
|
97
|
+
*/
|
|
98
|
+
const ACCOUNT_DELETION_INTENT_HEADER = "x-pithy-intent";
|
|
99
|
+
/** The value of `ACCOUNT_DELETION_INTENT_HEADER` that asks for a deletion-only session. */
|
|
100
|
+
const ACCOUNT_DELETION_INTENT = "delete-account";
|
|
101
|
+
/**
|
|
102
|
+
* Whether a sign-in refused with `refusal` may still create its session: only a **suspended** account's, and only
|
|
103
|
+
* when the request asks for nothing but deleting it. A deleted account has nothing left to delete, and a check
|
|
104
|
+
* that could not be made has established nobody, so neither is admitted.
|
|
105
|
+
*/
|
|
106
|
+
function admitsDeletionSignIn(refusal, headers) {
|
|
107
|
+
if (refusal.payload.code !== "auth/account_suspended") return false;
|
|
108
|
+
return headers?.get(ACCOUNT_DELETION_INTENT_HEADER)?.trim().toLowerCase() === ACCOUNT_DELETION_INTENT;
|
|
68
109
|
}
|
|
69
110
|
//#endregion
|
|
70
|
-
export { lifecycleRefusalFor, noteRefusal, noticedRefusal, readLifecycleColumns, suspensionReason };
|
|
111
|
+
export { ACCOUNT_DELETION_INTENT, ACCOUNT_DELETION_INTENT_HEADER, admitsDeletionSignIn, lifecycleRefusalFor, noteRefusal, noticedRefusal, readLifecycleColumns, suspendedHolder, suspensionReason };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
/**
|
|
4
|
+
* The longest reason the kit stores. It is shown to the person, so it is a sentence, not a case file.
|
|
5
|
+
*
|
|
6
|
+
* A leaf with no imports, because two programs read it: the transitions, which refuse a longer one, and the
|
|
7
|
+
* request schemas in `../http/schemas.ts`, which a browser program compiles (`tooling/browser-scopes`). Kept
|
|
8
|
+
* in `./transitions.ts`, it pulled the email capability and the Workers types into that program (#621).
|
|
9
|
+
*/
|
|
10
|
+
export declare const MAX_REASON = 500;
|
|
11
|
+
//# sourceMappingURL=reason.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reason.d.ts","sourceRoot":"","sources":["../../src/lifecycle/reason.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,MAAM,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
//#region src/lifecycle/reason.ts
|
|
4
|
+
/**
|
|
5
|
+
* The longest reason the kit stores. It is shown to the person, so it is a sentence, not a case file.
|
|
6
|
+
*
|
|
7
|
+
* A leaf with no imports, because two programs read it: the transitions, which refuse a longer one, and the
|
|
8
|
+
* request schemas in `../http/schemas.ts`, which a browser program compiles (`tooling/browser-scopes`). Kept
|
|
9
|
+
* in `./transitions.ts`, it pulled the email capability and the Workers types into that program (#621).
|
|
10
|
+
*/
|
|
11
|
+
const MAX_REASON = 500;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { MAX_REASON };
|
|
@@ -3,13 +3,16 @@
|
|
|
3
3
|
import type { PithyHonoEnv } from "@pithy-sh/core/src/capability/capability";
|
|
4
4
|
import type { Context } from "hono";
|
|
5
5
|
import type { AuthWiring } from "../capability";
|
|
6
|
-
import type { LifecycleDeps } from "./transitions";
|
|
6
|
+
import type { LifecycleAuditContext, LifecycleDeps } from "./transitions";
|
|
7
7
|
/**
|
|
8
8
|
* The transitions' dependencies, resolved from one request — what a lifecycle route hands `./transitions.ts`.
|
|
9
9
|
*
|
|
10
10
|
* One function so every route resolves them the same way: this request's database, its audit seam and logger,
|
|
11
11
|
* the composed email capability's enqueue bound to this request's env, and the adopter's hooks as `auth()` was
|
|
12
12
|
* handed them. A route that assembled its own would be the second place a hook could be forgotten.
|
|
13
|
+
*
|
|
14
|
+
* `context` is what the caller adds to each audit event: the request's correlation, and for a management call
|
|
15
|
+
* the connection it came through. The caller passes it because only the caller knows who it is.
|
|
13
16
|
*/
|
|
14
|
-
export declare function lifecycleDeps(c: Context<PithyHonoEnv>, wiring: AuthWiring): LifecycleDeps;
|
|
17
|
+
export declare function lifecycleDeps(c: Context<PithyHonoEnv>, wiring: AuthWiring, context?: LifecycleAuditContext): LifecycleDeps;
|
|
15
18
|
//# sourceMappingURL=request.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/lifecycle/request.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAE7E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGhD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/lifecycle/request.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAE7E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGhD,OAAO,KAAK,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE1E;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC3B,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,EACxB,MAAM,EAAE,UAAU,EAClB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,aAAa,CAaf"}
|
|
@@ -9,8 +9,11 @@ import { resolveDb } from "../http/resolve.js";
|
|
|
9
9
|
* One function so every route resolves them the same way: this request's database, its audit seam and logger,
|
|
10
10
|
* the composed email capability's enqueue bound to this request's env, and the adopter's hooks as `auth()` was
|
|
11
11
|
* handed them. A route that assembled its own would be the second place a hook could be forgotten.
|
|
12
|
+
*
|
|
13
|
+
* `context` is what the caller adds to each audit event: the request's correlation, and for a management call
|
|
14
|
+
* the connection it came through. The caller passes it because only the caller knows who it is.
|
|
12
15
|
*/
|
|
13
|
-
function lifecycleDeps(c, wiring) {
|
|
16
|
+
function lifecycleDeps(c, wiring, context) {
|
|
14
17
|
const d1 = resolveDb(c.env, wiring.config.database);
|
|
15
18
|
const enqueue = wiring.enqueueEmail;
|
|
16
19
|
return {
|
|
@@ -20,7 +23,8 @@ function lifecycleDeps(c, wiring) {
|
|
|
20
23
|
config: wiring.config,
|
|
21
24
|
hooks: wiring.lifecycleHooks ?? {},
|
|
22
25
|
enqueueEmail: enqueue ? (input) => enqueue(c.env, input) : void 0,
|
|
23
|
-
log: c.var.log?.child("auth")
|
|
26
|
+
log: c.var.log?.child("auth"),
|
|
27
|
+
...context ? { context } : {}
|
|
24
28
|
};
|
|
25
29
|
}
|
|
26
30
|
//#endregion
|