@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/README.md
CHANGED
|
@@ -60,7 +60,7 @@ So: **do not "improve" this by matching more addresses, and do not make the refu
|
|
|
60
60
|
|
|
61
61
|
## Account lifecycle
|
|
62
62
|
|
|
63
|
-
An account can be suspended or deleted, and the kit refuses it at every door. Auth's own routes, sign-in and token refresh answer `auth/account_suspended` or `auth/account_deleted` (403); another capability's `requireAuth()` answers 401, and the client's next refresh gets the code. [`docs/account-lifecycle.md`](docs/account-lifecycle.md) has the two states, the record, the scopes, the mail, the hooks, the screens, and the purge contribution a capability declares for its own rows.
|
|
63
|
+
An account can be suspended or deleted, and the kit refuses it at every door. An operator suspends and reinstates one through `POST /auth/admin/users/:userId/suspend` and `/reinstate`, under `auth:users:suspend`, with a reason the trail keeps. They delete one through `DELETE /auth/admin/users/:userId` — soft by default, restorable through `POST …/restore` until the purge window closes, or `mode: "hard"` to purge now — under `auth:users:delete`, and export everything the kit holds about one person through `GET …/export`, under `auth:users:export`. A person deletes their own account with `DELETE /auth/account { confirm: true }`, which is what the App Store and Google Play require of an app with accounts. A purge Workflow, hosted by your own Worker, erases a deleted account from every capability that holds it, one step per capability. Auth's own routes, sign-in and token refresh answer `auth/account_suspended` or `auth/account_deleted` (403); another capability's `requireAuth()` answers 401, and the client's next refresh gets the code. [`docs/account-lifecycle.md`](docs/account-lifecycle.md) has the two states, the record, the scopes, the routes, the purge and the Workflow classes to export for it, the mail, the hooks, the screens, and the purge contribution a capability declares for its own rows.
|
|
64
64
|
|
|
65
65
|
## Server-authoritative writes
|
|
66
66
|
|
package/dist/admin/users.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
import { Session, User } from "../data/betterAuth.js";
|
|
4
4
|
import { Device } from "../data/device.js";
|
|
5
5
|
import { ValidationError } from "@pithy-sh/core/src/error/pithyError";
|
|
6
|
-
import { decodeCursor, pageLimit, toPage } from "@pithy-sh/core/src/data/cursor";
|
|
7
6
|
import { MAX_BOUND_PARAMETERS, boundParameterBudget } from "@pithy-sh/core/src/data/boundParameters";
|
|
7
|
+
import { decodeCursor, pageLimit, toPage } from "@pithy-sh/core/src/data/cursor";
|
|
8
8
|
import { sql } from "kysely";
|
|
9
9
|
//#region src/admin/users.ts
|
|
10
10
|
/**
|
package/dist/audit/actions.d.ts
CHANGED
|
@@ -155,6 +155,12 @@ export declare const AuthAuditActions: {
|
|
|
155
155
|
*
|
|
156
156
|
* The dashboard's own `customer/user_suspended` and `customer/user_restored` are the client side of the
|
|
157
157
|
* same events, recorded where the operator pressed the button.
|
|
158
|
+
*
|
|
159
|
+
* **The suspend and reinstate routes record every call under the same action (#621)**, the ones the
|
|
160
|
+
* transition did not write included: a refusal as `denied` with its code in `metadata.code`, and a
|
|
161
|
+
* reinstatement that found nothing to lift as a `success` with `metadata.changed: false`. A restated
|
|
162
|
+
* suspension is the transition's own event, with `metadata.updated: true`. So one filter on the action
|
|
163
|
+
* finds every attempt on one account. `../lifecycle/audited.ts` writes the route's half.
|
|
158
164
|
*/
|
|
159
165
|
/** An account was suspended from the management surface. Carries the reason and any end date. */
|
|
160
166
|
readonly adminUserSuspended: "auth/admin_user_suspended";
|
|
@@ -162,12 +168,25 @@ export declare const AuthAuditActions: {
|
|
|
162
168
|
readonly adminUserReinstated: "auth/admin_user_reinstated";
|
|
163
169
|
/** An account was deleted from the management surface, with its purge window starting now. */
|
|
164
170
|
readonly adminUserSoftDeleted: "auth/admin_user_soft_deleted";
|
|
171
|
+
/**
|
|
172
|
+
* An account was deleted from the management surface with no window — its purge starts now (#622). Also
|
|
173
|
+
* written when a hard deletion brings an already-deleted account's purge forward, with
|
|
174
|
+
* `metadata.broughtForward: true`. Never written by omission: the route reaches it only for `mode: "hard"`.
|
|
175
|
+
*/
|
|
176
|
+
readonly adminUserHardDeleted: "auth/admin_user_hard_deleted";
|
|
165
177
|
/** A deleted account was restored inside its purge window, from the management surface. */
|
|
166
178
|
readonly adminUserRestored: "auth/admin_user_restored";
|
|
167
179
|
/** A deleted account's data was erased. Recorded once, when the last purge step has run. */
|
|
168
180
|
readonly adminUserPurged: "auth/admin_user_purged";
|
|
169
181
|
/** The account's own holder deleted their account. Always a soft deletion, on the configured window. */
|
|
170
182
|
readonly userSelfDeleted: "auth/user_self_deleted";
|
|
183
|
+
/**
|
|
184
|
+
* Everything the kit holds about one account was exported from the management surface — an access request
|
|
185
|
+
* answered (#622). A **disclosure**, and the largest one on this surface: it carries every composed
|
|
186
|
+
* capability's rows about the person. Recorded with the caller, the reason they gave, and which capabilities
|
|
187
|
+
* answered; never with any of the data.
|
|
188
|
+
*/
|
|
189
|
+
readonly adminUserExported: "auth/admin_user_exported";
|
|
171
190
|
};
|
|
172
191
|
/** One of the auth audit action codes. */
|
|
173
192
|
export type AuthAuditAction = (typeof AuthAuditActions)[keyof typeof AuthAuditActions];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/audit/actions.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB;IAC3B,+FAA+F;aAC/F,MAAM,EAAE,aAAa;IACrB;;;;;;;;OAQG;aACH,OAAO,EAAE,cAAc;IACvB;;;;OAIG;aACH,YAAY,EAAE,oBAAoB;IAClC,sHAAsH;aACtH,kBAAkB,EAAE,2BAA2B;IAC/C;;;;;OAKG;aACH,aAAa,EAAE,sBAAsB;IACrC;;;;;;;;;;;;;;;;;;;;;;OAsBG;aACH,OAAO,EAAE,eAAe;IACxB;;;;;;;;;;;;;;;;OAgBG;aACH,WAAW,EAAE,mBAAmB;IAChC;;;;;;;;;;;;;;;;OAgBG;aACH,aAAa,EAAE,qBAAqB;IACpC,gEAAgE;aAChE,gBAAgB,EAAE,wBAAwB;IAC1C,wDAAwD;aACxD,aAAa,EAAE,qBAAqB;IACpC;;;;;;;;;;OAUG;aACH,mBAAmB,EAAE,2BAA2B;IAChD;;;;;;;;;;OAUG;aACH,eAAe,EAAE,wBAAwB;IAEzC;;;;;;;;;;OAUG;IAEH,wGAAwG;aACxG,gBAAgB,EAAE,yBAAyB;IAC3C,sFAAsF;aACtF,aAAa,EAAE,sBAAsB;IACrC,kEAAkE;aAClE,kBAAkB,EAAE,2BAA2B;IAC/C,iEAAiE;aACjE,mBAAmB,EAAE,4BAA4B;IACjD,iGAAiG;aACjG,wBAAwB,EAAE,kCAAkC;IAC5D,wGAAwG;aACxG,kBAAkB,EAAE,2BAA2B;IAE/C
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/audit/actions.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB;IAC3B,+FAA+F;aAC/F,MAAM,EAAE,aAAa;IACrB;;;;;;;;OAQG;aACH,OAAO,EAAE,cAAc;IACvB;;;;OAIG;aACH,YAAY,EAAE,oBAAoB;IAClC,sHAAsH;aACtH,kBAAkB,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@@ -156,6 +156,12 @@ const AuthAuditActions = {
|
|
|
156
156
|
*
|
|
157
157
|
* The dashboard's own `customer/user_suspended` and `customer/user_restored` are the client side of the
|
|
158
158
|
* same events, recorded where the operator pressed the button.
|
|
159
|
+
*
|
|
160
|
+
* **The suspend and reinstate routes record every call under the same action (#621)**, the ones the
|
|
161
|
+
* transition did not write included: a refusal as `denied` with its code in `metadata.code`, and a
|
|
162
|
+
* reinstatement that found nothing to lift as a `success` with `metadata.changed: false`. A restated
|
|
163
|
+
* suspension is the transition's own event, with `metadata.updated: true`. So one filter on the action
|
|
164
|
+
* finds every attempt on one account. `../lifecycle/audited.ts` writes the route's half.
|
|
159
165
|
*/
|
|
160
166
|
/** An account was suspended from the management surface. Carries the reason and any end date. */
|
|
161
167
|
adminUserSuspended: "auth/admin_user_suspended",
|
|
@@ -163,12 +169,25 @@ const AuthAuditActions = {
|
|
|
163
169
|
adminUserReinstated: "auth/admin_user_reinstated",
|
|
164
170
|
/** An account was deleted from the management surface, with its purge window starting now. */
|
|
165
171
|
adminUserSoftDeleted: "auth/admin_user_soft_deleted",
|
|
172
|
+
/**
|
|
173
|
+
* An account was deleted from the management surface with no window — its purge starts now (#622). Also
|
|
174
|
+
* written when a hard deletion brings an already-deleted account's purge forward, with
|
|
175
|
+
* `metadata.broughtForward: true`. Never written by omission: the route reaches it only for `mode: "hard"`.
|
|
176
|
+
*/
|
|
177
|
+
adminUserHardDeleted: "auth/admin_user_hard_deleted",
|
|
166
178
|
/** A deleted account was restored inside its purge window, from the management surface. */
|
|
167
179
|
adminUserRestored: "auth/admin_user_restored",
|
|
168
180
|
/** A deleted account's data was erased. Recorded once, when the last purge step has run. */
|
|
169
181
|
adminUserPurged: "auth/admin_user_purged",
|
|
170
182
|
/** The account's own holder deleted their account. Always a soft deletion, on the configured window. */
|
|
171
|
-
userSelfDeleted: "auth/user_self_deleted"
|
|
183
|
+
userSelfDeleted: "auth/user_self_deleted",
|
|
184
|
+
/**
|
|
185
|
+
* Everything the kit holds about one account was exported from the management surface — an access request
|
|
186
|
+
* answered (#622). A **disclosure**, and the largest one on this surface: it carries every composed
|
|
187
|
+
* capability's rows about the person. Recorded with the caller, the reason they gave, and which capabilities
|
|
188
|
+
* answered; never with any of the data.
|
|
189
|
+
*/
|
|
190
|
+
adminUserExported: "auth/admin_user_exported"
|
|
172
191
|
};
|
|
173
192
|
//#endregion
|
|
174
193
|
export { AuthAuditActions };
|
package/dist/audit/emit.d.ts
CHANGED
|
@@ -231,6 +231,8 @@ export declare function emitControlPlaneAction(emit: AuditEmit, event: {
|
|
|
231
231
|
userAgent?: string;
|
|
232
232
|
requestId?: string;
|
|
233
233
|
metadata?: Record<string, unknown>;
|
|
234
|
+
/** `success` unless the call was refused (`denied`) or broke (`failure`) — #621 records both. */
|
|
235
|
+
outcome?: "success" | "denied" | "failure";
|
|
234
236
|
}): Promise<void>;
|
|
235
237
|
/**
|
|
236
238
|
* Emit a `provider_unavailable` event — somebody asked for a sign-in method this deployment enables and
|
package/dist/audit/emit.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../src/audit/emit.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAEnE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,KAAK,eAAe,EAAoB,MAAM,WAAW,CAAC;AACnE,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAElE;;;;;;;GAOG;AAEH,gFAAgF;AAChF,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,SAAS,GAAG;IAAE,EAAE,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAK7F;AAUD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,MAAM,YAAY,GAAG,eAAe,GA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A;CAAE,GAC1D,OAAO,CAAC,IAAI,CAAC,CASf;AAED,2FAA2F;AAC3F,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,QAAQ,CAAC;AAE/C;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe;;;;iBAMwE,CAAC;AACrG,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,eAAe,CAAC,CAAC;AAc/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAsB,0BAA0B,CAC9C,IAAI,EAAE,SAAS,EACf,OAAO,EAAE;IACP,MAAM,EAAE,cAAc,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,iGAAiG;IACjG,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,oGAAoG;IACpG,WAAW,EAAE,OAAO,CAAC;IACrB,OAAO,EAAE,OAAO,GAAG,SAAS,CAAC;CAC9B,GACA,OAAO,CAAC,IAAI,CAAC,CAuBf;AAED;;;;;;;GAOG;AACH,wBAAsB,0BAA0B,CAC9C,IAAI,EAAE,SAAS,EACf,OAAO,EAAE;IAAE,MAAM,EAAE,cAAc,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,GAAG,SAAS,CAAA;CAAE,GACnG,OAAO,CAAC,IAAI,CAAC,CAcf;AAED,0EAA0E;AAC1E,wBAAsB,UAAU,CAC9B,IAAI,EAAE,SAAS,EACf,OAAO,EAAE;IAAE,EAAE,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5D,OAAO,CAAC,IAAI,CAAC,CASf"}
|
package/dist/audit/emit.js
CHANGED
|
@@ -257,7 +257,7 @@ async function emitDeviceRevoked(emit, context) {
|
|
|
257
257
|
async function emitControlPlaneAction(emit, event) {
|
|
258
258
|
await safeEmit(emit, {
|
|
259
259
|
action: event.action,
|
|
260
|
-
outcome: "success",
|
|
260
|
+
outcome: event.outcome ?? "success",
|
|
261
261
|
actorType: "control-plane",
|
|
262
262
|
actorId: event.subject,
|
|
263
263
|
resourceType: event.resourceType,
|
package/dist/capability.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
import type { D1Database } from "@cloudflare/workers-types";
|
|
4
|
+
import type { AuditEmit } from "@pithy-sh/core/src/audit/recorder";
|
|
4
5
|
import type { Capability, PithyHonoEnv } from "@pithy-sh/core/src/capability/capability";
|
|
6
|
+
import { type PurgeStep } from "@pithy-sh/core/src/capability/purge";
|
|
5
7
|
import type { EmailCapability } from "@pithy-sh/email/src/capability";
|
|
6
8
|
import { type TurnstileMode } from "@pithy-sh/turnstile/src/config/config";
|
|
7
9
|
import type { Context } from "hono";
|
|
@@ -44,6 +46,7 @@ export declare const AuthConfig: z.ZodObject<{
|
|
|
44
46
|
disableSignUp: z.ZodDefault<z.ZodBoolean>;
|
|
45
47
|
retention: z.ZodPrefault<z.ZodObject<{
|
|
46
48
|
purgeAfterDays: z.ZodDefault<z.ZodNumber>;
|
|
49
|
+
restoreUrl: z.ZodOptional<z.ZodURL>;
|
|
47
50
|
}, z.core.$strip>>;
|
|
48
51
|
lifecycleEmails: z.ZodPrefault<z.ZodObject<{
|
|
49
52
|
accountSuspended: z.ZodDefault<z.ZodBoolean>;
|
|
@@ -89,6 +92,12 @@ export interface AuthWiring {
|
|
|
89
92
|
* Optional on the wiring for the reason `onSessionRevoked` is: no hook is the ordinary composition.
|
|
90
93
|
*/
|
|
91
94
|
lifecycleHooks?: UserLifecycleHooks | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* Every composed capability's purge step for a user, auth's own among them, in composition order (#622). Filled
|
|
97
|
+
* by `compose`; the export route reads every capability's contribution from it, and the purge runs it.
|
|
98
|
+
* Optional on the wiring for the reason `onSessionRevoked` is: a harness that builds this by hand composes none.
|
|
99
|
+
*/
|
|
100
|
+
purgeSteps?: readonly PurgeStep[] | undefined;
|
|
92
101
|
}
|
|
93
102
|
/** The session a {@link ScopeResolver} is asked about — the one Better Auth just resolved for this request. */
|
|
94
103
|
export interface ScopeResolverSession {
|
|
@@ -186,6 +195,16 @@ export interface AuthCapability extends Capability {
|
|
|
186
195
|
* outside a request this capability serves — the purge Workflow (#622) fires `onUserPurged` through it.
|
|
187
196
|
*/
|
|
188
197
|
lifecycleHooks: UserLifecycleHooks;
|
|
198
|
+
/**
|
|
199
|
+
* Every composed capability's purge step for a user, auth's own among them, in composition order (#622). Empty
|
|
200
|
+
* until `compose` has run. Read by the purge Workflow, which runs in the Worker that composed it.
|
|
201
|
+
*/
|
|
202
|
+
purgeSteps: readonly PurgeStep[];
|
|
203
|
+
/**
|
|
204
|
+
* The audit recorder for code with no request, over one run's env — the composed audit capability's, or the
|
|
205
|
+
* no-op (#622). Read by the purge Workflow, which owes the trail its `auth/admin_user_purged`.
|
|
206
|
+
*/
|
|
207
|
+
auditFor: (env: Record<string, unknown>) => AuditEmit;
|
|
189
208
|
/**
|
|
190
209
|
* What a capability composed beside this one reads an account through — `matchmaking`, `support`,
|
|
191
210
|
* `testers`. Found in their `compose` hooks, so none of them imports this package and a project without
|
package/dist/capability.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capability.d.ts","sourceRoot":"","sources":["../src/capability.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"capability.d.ts","sourceRoot":"","sources":["../src/capability.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,KAAK,E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IACH,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAiCD;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,cAAc,CA6MzD;AAED,0DAA0D;AAC1D,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,IAAI,cAAc,CAErF"}
|
package/dist/capability.js
CHANGED
|
@@ -9,14 +9,18 @@ import { registerDevLoginRoute } from "./http/devLoginRoute.js";
|
|
|
9
9
|
import { authAdminRoutes } from "./http/guards.js";
|
|
10
10
|
import { createSessionMiddleware } from "./http/middleware.js";
|
|
11
11
|
import { createRateLimitMiddleware } from "./http/rateLimit.js";
|
|
12
|
+
import { authWorkflows } from "./purge/specs.js";
|
|
12
13
|
import { createAuthRoutes } from "./http/routes.js";
|
|
13
14
|
import "./migrations/0001_init.js";
|
|
14
15
|
import { authPluginPlan } from "./migrations/pluginTables.js";
|
|
15
16
|
import { AUTH_MIGRATIONS } from "./migrations/set.js";
|
|
16
17
|
import { authPeer } from "./peer.js";
|
|
18
|
+
import { authPurgeContribution } from "./purge/contribution.js";
|
|
17
19
|
import { authExampleSeed } from "./seeds/example.js";
|
|
18
20
|
import { PACKAGE_NAME, PACKAGE_VERSION } from "./version.generated.js";
|
|
21
|
+
import { composedAuditEmit } from "@pithy-sh/core/src/audit/composed";
|
|
19
22
|
import { defineCapability } from "@pithy-sh/core/src/capability/capability";
|
|
23
|
+
import { purgeSteps } from "@pithy-sh/core/src/capability/purge";
|
|
20
24
|
import { ValidationError } from "@pithy-sh/core/src/error/pithyError";
|
|
21
25
|
import { isEmailCapability } from "@pithy-sh/email/src/capability";
|
|
22
26
|
import { isTurnstileCapability } from "@pithy-sh/turnstile/src/capability";
|
|
@@ -55,7 +59,10 @@ const AuthConfig = z.object({
|
|
|
55
59
|
verificationExpiresIn: z.number().int().default(300).describe("Magic-link and OTP lifetime in seconds. Defaults to 5 minutes. Single-use regardless."),
|
|
56
60
|
otpLength: z.number().int().default(6).describe("The number of digits in an email OTP. Defaults to 6."),
|
|
57
61
|
disableSignUp: z.boolean().default(false).describe("When true, sign-in never provisions a new user — existing accounts only. Unknown emails get no email (anti-enumeration)."),
|
|
58
|
-
retention: z.object({
|
|
62
|
+
retention: z.object({
|
|
63
|
+
purgeAfterDays: z.number().int().positive().default(30).describe("How many days a deleted account waits before its data is erased. Inside the window it cannot sign in and can be restored; after it, the purge erases its rows from every capability that holds them. Defaults to 30."),
|
|
64
|
+
restoreUrl: z.url({ protocol: /^https?$/ }).optional().describe("Where a person whose account is deleted asks for it back inside the window: an http(s) page of yours. Carried in the deletion-scheduled mail as its restore button, so it must be a web address — a tracked click redirects only to one. Absent, the mail still tells them to reply before the purge date.")
|
|
65
|
+
}).prefault({}).describe("How long a deleted account is kept before it is purged. Self-service deletion and an operator's soft deletion both use this window."),
|
|
59
66
|
lifecycleEmails: z.object({
|
|
60
67
|
accountSuspended: z.boolean().default(true).describe("Email the person when their account is suspended, with the reason and any end date."),
|
|
61
68
|
accountReinstated: z.boolean().default(true).describe("Email the person when a suspension is lifted."),
|
|
@@ -112,8 +119,12 @@ function auth(options) {
|
|
|
112
119
|
turnstile: void 0,
|
|
113
120
|
onSessionRevoked,
|
|
114
121
|
resolveScopes,
|
|
115
|
-
lifecycleHooks
|
|
122
|
+
lifecycleHooks,
|
|
123
|
+
purgeSteps: []
|
|
116
124
|
};
|
|
125
|
+
const steps = [];
|
|
126
|
+
wiring.purgeSteps = steps;
|
|
127
|
+
let composition = [];
|
|
117
128
|
const rateLimitMiddleware = (app) => {
|
|
118
129
|
app.use(`${resolved.basePath}/*`, createRateLimitMiddleware(resolved.rateLimiterBinding));
|
|
119
130
|
};
|
|
@@ -147,6 +158,8 @@ function auth(options) {
|
|
|
147
158
|
...pluginPlan.migrations
|
|
148
159
|
}
|
|
149
160
|
} },
|
|
161
|
+
purge: [authPurgeContribution(resolved.database, pluginPlan.userTables)],
|
|
162
|
+
workflows: authWorkflows,
|
|
150
163
|
compose: ({ capabilities }) => {
|
|
151
164
|
const email = capabilities.find(isEmailCapability);
|
|
152
165
|
if (!email) throw new ValidationError({
|
|
@@ -157,6 +170,8 @@ function auth(options) {
|
|
|
157
170
|
const loginMode = capabilities.find(isTurnstileCapability)?.turnstileConfig.protect[TURNSTILE_LOGIN_ACTION];
|
|
158
171
|
wiring.turnstile = loginMode ? { mode: loginMode } : void 0;
|
|
159
172
|
assertPluginTablesUnclaimed(capabilities, resolved.database, pluginPlan.extensions);
|
|
173
|
+
steps.splice(0, steps.length, ...purgeSteps(capabilities, "user"));
|
|
174
|
+
composition = capabilities;
|
|
160
175
|
},
|
|
161
176
|
/**
|
|
162
177
|
* The client-safe projection — what a sign-in screen needs and nothing more: where to call
|
|
@@ -209,7 +224,9 @@ function auth(options) {
|
|
|
209
224
|
return Object.assign(capability, {
|
|
210
225
|
authConfig: resolved,
|
|
211
226
|
authPeer,
|
|
212
|
-
lifecycleHooks
|
|
227
|
+
lifecycleHooks,
|
|
228
|
+
purgeSteps: steps,
|
|
229
|
+
auditFor: (env) => composedAuditEmit(composition, env)
|
|
213
230
|
});
|
|
214
231
|
}
|
|
215
232
|
/** Type guard: is this capability the auth capability? */
|
package/dist/data/tables.d.ts
CHANGED
|
@@ -122,6 +122,7 @@ export declare const authTables: {
|
|
|
122
122
|
reason: import("zod").ZodNullable<import("zod").ZodString>;
|
|
123
123
|
suspendedUntil: import("zod").ZodNullable<import("zod").ZodCodec<import("zod").ZodUnion<readonly [import("zod").ZodNumber, import("zod").ZodString, import("zod").ZodDate]>, import("zod").ZodDate>>;
|
|
124
124
|
step: import("zod").ZodNullable<import("zod").ZodString>;
|
|
125
|
+
notify: import("zod").ZodNullable<import("zod").ZodCodec<import("zod").ZodUnion<readonly [import("zod").ZodLiteral<0>, import("zod").ZodLiteral<1>, import("zod").ZodBoolean, import("zod").ZodString]>, import("zod").ZodBoolean>>;
|
|
125
126
|
createdAt: import("zod").ZodCodec<import("zod").ZodUnion<readonly [import("zod").ZodNumber, import("zod").ZodString, import("zod").ZodDate]>, import("zod").ZodDate>;
|
|
126
127
|
}, import("zod/v4/core").$strip>;
|
|
127
128
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tables.d.ts","sourceRoot":"","sources":["../../src/data/tables.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACjF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAMrC;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU;IACrB,cAAc;;;;;;;;;;;;;;IACd,iBAAiB;;;;;;;;;;;;;IACjB,iBAAiB;;;;;;;;;;;;;;;;IACjB,sBAAsB;;;;;;;;IACtB,aAAa;;;;;;;;;IACb,kBAAkB;;;;;;IAClB,gBAAgB;;;;;;;;;;;;;;;;;IAChB,sBAAsB;;;;;;IACtB,sBAAsB
|
|
1
|
+
{"version":3,"file":"tables.d.ts","sourceRoot":"","sources":["../../src/data/tables.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACjF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAMrC;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU;IACrB,cAAc;;;;;;;;;;;;;;IACd,iBAAiB;;;;;;;;;;;;;IACjB,iBAAiB;;;;;;;;;;;;;;;;IACjB,sBAAsB;;;;;;;;IACtB,aAAa;;;;;;;;;IACb,kBAAkB;;;;;;IAClB,gBAAgB;;;;;;;;;;;;;;;;;IAChB,sBAAsB;;;;;;IACtB,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;CACvB,CAAC;AACF,MAAM,MAAM,UAAU,GAAG,OAAO,UAAU,CAAC;AAE3C,8GAA8G;AAC9G,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC;AAE9D,yGAAyG;AACzG,wBAAgB,YAAY,CAAC,EAAE,EAAE,UAAU,GAAG,YAAY,CAEzD"}
|
|
@@ -55,6 +55,7 @@ export declare const UserLifecycleEvent: z.ZodObject<{
|
|
|
55
55
|
reason: z.ZodNullable<z.ZodString>;
|
|
56
56
|
suspendedUntil: z.ZodNullable<z.ZodCodec<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodDate]>, z.ZodDate>>;
|
|
57
57
|
step: z.ZodNullable<z.ZodString>;
|
|
58
|
+
notify: z.ZodNullable<z.ZodCodec<z.ZodUnion<readonly [z.ZodLiteral<0>, z.ZodLiteral<1>, z.ZodBoolean, z.ZodString]>, z.ZodBoolean>>;
|
|
58
59
|
createdAt: z.ZodCodec<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodDate]>, z.ZodDate>;
|
|
59
60
|
}, z.core.$strip>;
|
|
60
61
|
export type UserLifecycleEvent = z.output<typeof UserLifecycleEvent>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userLifecycle.d.ts","sourceRoot":"","sources":["../../src/data/userLifecycle.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;;;;;GAeG;AAEH,oCAAoC;AACpC,eAAO,MAAM,mBAAmB;;;;;;;EAI7B,CAAC;AACJ,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEvE,+BAA+B;AAC/B,eAAO,MAAM,sBAAsB;;;;EAIhC,CAAC;AACJ,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAE7E,iCAAiC;AACjC,eAAO,MAAM,kBAAkB
|
|
1
|
+
{"version":3,"file":"userLifecycle.d.ts","sourceRoot":"","sources":["../../src/data/userLifecycle.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;;;;;GAeG;AAEH,oCAAoC;AACpC,eAAO,MAAM,mBAAmB;;;;;;;EAI7B,CAAC;AACJ,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEvE,+BAA+B;AAC/B,eAAO,MAAM,sBAAsB;;;;EAIhC,CAAC;AACJ,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAE7E,iCAAiC;AACjC,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;iBAyC5B,CAAC;AACJ,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
import { SQLiteDate } from "@pithy-sh/core/src/data/codecs";
|
|
4
|
+
import { SQLiteBoolean, SQLiteDate } from "@pithy-sh/core/src/data/codecs";
|
|
5
5
|
//#region src/data/userLifecycle.ts
|
|
6
6
|
/**
|
|
7
7
|
* `pithy_auth_user_lifecycle` — every transition an account went through, who made it, and why.
|
|
@@ -44,6 +44,7 @@ const UserLifecycleEvent = z.object({
|
|
|
44
44
|
reason: z.string().nullable().describe("Why, in the words of whoever made the transition. For a suspension this is the sentence the locked-out person is shown, so it is written for them. Null for a transition nobody had to justify — a purge, a self-service deletion."),
|
|
45
45
|
suspendedUntil: SQLiteDate.nullable().describe("For a `suspended` row, when that suspension ends by itself; null for one that lasts until a reinstatement, and for every other action. Ms-epoch in SQLite."),
|
|
46
46
|
step: z.string().nullable().describe("For a `purge_step` row, the capability whose rows that step erased — the purge's step name. Null for every other action."),
|
|
47
|
+
notify: SQLiteBoolean.nullable().describe("For a hard deletion's `deleted` row, whether the purge sends the deletion-complete mail — false when the deletion asked for none. Null for every other row, and for a hard deletion that did not say. The purge reads it, so a purge the daily pass starts keeps the choice (#622)."),
|
|
47
48
|
createdAt: SQLiteDate.describe("When the transition happened. Ms-epoch in SQLite; a `Date` in app code.")
|
|
48
49
|
}).describe("One transition in `pithy_auth_user_lifecycle`: an account suspended, reinstated, deleted, restored or purged, with who did it and why.");
|
|
49
50
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adminRoutes.d.ts","sourceRoot":"","sources":["../../src/http/adminRoutes.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;
|
|
1
|
+
{"version":3,"file":"adminRoutes.d.ts","sourceRoot":"","sources":["../../src/http/adminRoutes.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAS7E,OAAO,KAAK,EAAW,IAAI,EAAE,MAAM,MAAM,CAAC;AAe1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAuThD;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,UAAU,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,YAAY,CAAC,KAAK,IAAI,CAyc7F"}
|