@pithy-sh/auth 0.10.0 → 0.12.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 +30 -2
- package/dist/admin/users.js +1 -1
- package/dist/audit/actions.d.ts +58 -0
- package/dist/audit/actions.d.ts.map +1 -1
- package/dist/audit/actions.js +59 -1
- package/dist/audit/emit.d.ts +36 -0
- package/dist/audit/emit.d.ts.map +1 -1
- package/dist/audit/emit.js +48 -2
- package/dist/audit/evidence.d.ts +8 -2
- package/dist/audit/evidence.d.ts.map +1 -1
- package/dist/capability.d.ts +47 -8
- package/dist/capability.d.ts.map +1 -1
- package/dist/capability.js +56 -6
- package/dist/client/api.d.ts +55 -12
- package/dist/client/api.d.ts.map +1 -1
- package/dist/client/api.js +57 -18
- package/dist/client/bearer.d.ts +110 -0
- package/dist/client/bearer.d.ts.map +1 -0
- package/dist/client/bearer.js +265 -0
- package/dist/client/handoff.d.ts +77 -0
- package/dist/client/handoff.d.ts.map +1 -0
- package/dist/client/handoff.js +119 -0
- package/dist/client/mcp.d.ts +70 -0
- package/dist/client/mcp.d.ts.map +1 -0
- package/dist/client/mcp.js +65 -0
- package/dist/data/betterAuth.d.ts +3 -2
- package/dist/data/betterAuth.d.ts.map +1 -1
- package/dist/data/betterAuth.js +5 -3
- package/dist/data/kitFields.d.ts +5 -0
- package/dist/data/kitFields.d.ts.map +1 -1
- package/dist/data/kitFields.js +5 -0
- package/dist/data/tables.d.ts +26 -4
- package/dist/data/tables.d.ts.map +1 -1
- package/dist/data/tables.js +5 -3
- package/dist/data/userLifecycle.d.ts +10 -0
- package/dist/data/userLifecycle.d.ts.map +1 -1
- package/dist/data/userLifecycle.js +8 -3
- package/dist/data/verificationOutcome.d.ts +53 -0
- package/dist/data/verificationOutcome.d.ts.map +1 -0
- package/dist/data/verificationOutcome.js +50 -0
- package/dist/email/send.js +6 -2
- package/dist/http/adminRoutes.d.ts.map +1 -1
- package/dist/http/adminRoutes.js +319 -8
- package/dist/http/csrf.d.ts.map +1 -1
- package/dist/http/csrf.js +2 -1
- package/dist/http/guards.d.ts +15 -10
- package/dist/http/guards.d.ts.map +1 -1
- package/dist/http/guards.js +76 -10
- package/dist/http/handoff.d.ts +76 -0
- package/dist/http/handoff.d.ts.map +1 -0
- package/dist/http/handoff.js +316 -0
- package/dist/http/middleware.d.ts +37 -1
- package/dist/http/middleware.d.ts.map +1 -1
- package/dist/http/middleware.js +68 -6
- package/dist/http/resolve.d.ts.map +1 -1
- package/dist/http/resolve.js +9 -3
- package/dist/http/responses.d.ts +322 -0
- package/dist/http/responses.d.ts.map +1 -1
- package/dist/http/responses.js +202 -5
- package/dist/http/routes.d.ts +3 -0
- package/dist/http/routes.d.ts.map +1 -1
- package/dist/http/routes.js +78 -5
- package/dist/http/schemas.d.ts +114 -0
- package/dist/http/schemas.d.ts.map +1 -1
- package/dist/http/schemas.js +94 -1
- package/dist/http/views.d.ts +60 -3
- package/dist/http/views.d.ts.map +1 -1
- package/dist/http/views.js +143 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/instance/auth.d.ts +148 -10
- package/dist/instance/auth.d.ts.map +1 -1
- package/dist/instance/auth.js +87 -42
- package/dist/instance/plugins.d.ts +6 -0
- package/dist/instance/plugins.d.ts.map +1 -1
- package/dist/instance/plugins.js +14 -1
- package/dist/ledger/read.d.ts +53 -0
- package/dist/ledger/read.d.ts.map +1 -0
- package/dist/ledger/read.js +85 -0
- package/dist/ledger/record.d.ts +35 -0
- package/dist/ledger/record.d.ts.map +1 -0
- package/dist/ledger/record.js +98 -0
- 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/erasure.d.ts +9 -0
- package/dist/lifecycle/erasure.d.ts.map +1 -0
- package/dist/lifecycle/erasure.js +96 -0
- package/dist/lifecycle/inactivity.d.ts +19 -0
- package/dist/lifecycle/inactivity.d.ts.map +1 -0
- package/dist/lifecycle/inactivity.js +28 -0
- 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 +179 -18
- package/dist/lifecycle/transitions.d.ts.map +1 -1
- package/dist/lifecycle/transitions.js +391 -70
- package/dist/mcp/argumentClass.d.ts +51 -0
- package/dist/mcp/argumentClass.d.ts.map +1 -0
- package/dist/mcp/argumentClass.js +69 -0
- package/dist/mcp/capability.d.ts +50 -0
- package/dist/mcp/capability.d.ts.map +1 -0
- package/dist/mcp/capability.js +140 -0
- package/dist/mcp/clientMetadata.d.ts +40 -0
- package/dist/mcp/clientMetadata.d.ts.map +1 -0
- package/dist/mcp/clientMetadata.js +68 -0
- package/dist/mcp/consent.d.ts +49 -0
- package/dist/mcp/consent.d.ts.map +1 -0
- package/dist/mcp/consent.js +69 -0
- package/dist/mcp/dispatch.d.ts +35 -0
- package/dist/mcp/dispatch.d.ts.map +1 -0
- package/dist/mcp/dispatch.js +135 -0
- package/dist/mcp/floor.d.ts +37 -0
- package/dist/mcp/floor.d.ts.map +1 -0
- package/dist/mcp/floor.js +41 -0
- package/dist/mcp/host.d.ts +34 -0
- package/dist/mcp/host.d.ts.map +1 -0
- package/dist/mcp/host.js +2 -0
- package/dist/mcp/http/redirectList.d.ts +9 -0
- package/dist/mcp/http/redirectList.d.ts.map +1 -0
- package/dist/mcp/http/redirectList.js +24 -0
- package/dist/mcp/http/responses.d.ts +143 -0
- package/dist/mcp/http/responses.d.ts.map +1 -0
- package/dist/mcp/http/responses.js +83 -0
- package/dist/mcp/http/routes.d.ts +28 -0
- package/dist/mcp/http/routes.d.ts.map +1 -0
- package/dist/mcp/http/routes.js +517 -0
- package/dist/mcp/http/schemas.d.ts +24 -0
- package/dist/mcp/http/schemas.d.ts.map +1 -0
- package/dist/mcp/http/schemas.js +18 -0
- package/dist/mcp/marker.d.ts +15 -0
- package/dist/mcp/marker.d.ts.map +1 -0
- package/dist/mcp/marker.js +15 -0
- package/dist/mcp/provider.d.ts +78 -0
- package/dist/mcp/provider.d.ts.map +1 -0
- package/dist/mcp/provider.js +108 -0
- package/dist/mcp/purge.d.ts +15 -0
- package/dist/mcp/purge.d.ts.map +1 -0
- package/dist/mcp/purge.js +31 -0
- package/dist/mcp/rpc.d.ts +79 -0
- package/dist/mcp/rpc.d.ts.map +1 -0
- package/dist/mcp/rpc.js +103 -0
- package/dist/mcp/toolAudit.d.ts +76 -0
- package/dist/mcp/toolAudit.d.ts.map +1 -0
- package/dist/mcp/toolAudit.js +86 -0
- 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/0006_verification_outcomes.d.ts +15 -0
- package/dist/migrations/0006_verification_outcomes.d.ts.map +1 -0
- package/dist/migrations/0006_verification_outcomes.js +35 -0
- package/dist/migrations/0007_erasure_record.d.ts +17 -0
- package/dist/migrations/0007_erasure_record.d.ts.map +1 -0
- package/dist/migrations/0007_erasure_record.js +36 -0
- package/dist/migrations/0008_last_active.d.ts +15 -0
- package/dist/migrations/0008_last_active.d.ts.map +1 -0
- package/dist/migrations/0008_last_active.js +29 -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 +5 -1
- package/dist/migrations/set.d.ts.map +1 -1
- package/dist/migrations/set.js +10 -2
- package/dist/peer.d.ts +3 -2
- package/dist/peer.d.ts.map +1 -1
- package/dist/processing/activities.d.ts +6 -0
- package/dist/processing/activities.d.ts.map +1 -0
- package/dist/processing/activities.js +12 -0
- package/dist/purge/contribution.d.ts +62 -0
- package/dist/purge/contribution.d.ts.map +1 -0
- package/dist/purge/contribution.js +155 -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 +158 -0
- package/dist/purge/run.d.ts.map +1 -0
- package/dist/purge/run.js +205 -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 +71 -0
- package/dist/purge/workflow.d.ts.map +1 -0
- package/dist/purge/workflow.js +140 -0
- package/dist/test-utils/accountFootprint.d.ts +13 -0
- package/dist/test-utils/accountFootprint.d.ts.map +1 -0
- package/dist/test-utils/accountFootprint.js +49 -0
- package/dist/test-utils/liveApp.d.ts +6 -0
- package/dist/test-utils/liveApp.d.ts.map +1 -1
- package/dist/test-utils/liveApp.js +7 -2
- package/dist/token/handoff.d.ts +80 -0
- package/dist/token/handoff.d.ts.map +1 -0
- package/dist/token/handoff.js +136 -0
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.js +1 -1
- package/docs/account-lifecycle.md +176 -12
- package/docs/apple-signin.md +32 -4
- package/docs/facebook-oauth.md +2 -2
- package/docs/github-oauth.md +2 -2
- package/docs/google-oauth.md +9 -7
- package/docs/microsoft-oauth.md +2 -2
- package/package.json +11 -5
- package/pithy.manifest.json +2 -2
- package/pithy.mcp.manifest.json +36 -0
- package/src/audit/actions.ts +58 -0
- package/src/audit/emit.ts +66 -1
- package/src/audit/evidence.ts +8 -4
- package/src/capability.ts +122 -18
- package/src/client/api.ts +69 -19
- package/src/client/bearer.ts +388 -0
- package/src/client/handoff.ts +172 -0
- package/src/client/mcp.ts +140 -0
- package/src/data/betterAuth.ts +8 -4
- package/src/data/kitFields.ts +2 -0
- package/src/data/tables.ts +4 -2
- package/src/data/userLifecycle.ts +19 -4
- package/src/data/verificationOutcome.ts +86 -0
- package/src/email/send.ts +2 -2
- package/src/http/adminRoutes.ts +465 -4
- package/src/http/csrf.ts +4 -1
- package/src/http/guards.ts +79 -10
- package/src/http/handoff.ts +350 -0
- package/src/http/middleware.ts +74 -5
- package/src/http/resolve.ts +25 -25
- package/src/http/responses.ts +374 -3
- package/src/http/routes.ts +116 -5
- package/src/http/schemas.ts +195 -0
- package/src/http/views.ts +192 -3
- package/src/index.ts +2 -0
- package/src/instance/auth.ts +58 -3
- package/src/instance/plugins.ts +20 -2
- package/src/ledger/read.ts +133 -0
- package/src/ledger/record.ts +198 -0
- package/src/lifecycle/audited.ts +104 -0
- package/src/lifecycle/enforce.ts +55 -5
- package/src/lifecycle/erasure.ts +118 -0
- package/src/lifecycle/inactivity.ts +56 -0
- package/src/lifecycle/reason.ts +11 -0
- package/src/lifecycle/request.ts +10 -2
- package/src/lifecycle/transitions.ts +552 -93
- package/src/mcp/argumentClass.ts +112 -0
- package/src/mcp/capability.ts +194 -0
- package/src/mcp/clientMetadata.ts +81 -0
- package/src/mcp/consent.ts +95 -0
- package/src/mcp/dispatch.ts +154 -0
- package/src/mcp/floor.ts +62 -0
- package/src/mcp/host.ts +36 -0
- package/src/mcp/http/redirectList.ts +26 -0
- package/src/mcp/http/responses.ts +157 -0
- package/src/mcp/http/routes.ts +635 -0
- package/src/mcp/http/schemas.ts +37 -0
- package/src/mcp/marker.ts +18 -0
- package/src/mcp/provider.ts +151 -0
- package/src/mcp/purge.ts +39 -0
- package/src/mcp/rpc.ts +135 -0
- package/src/mcp/toolAudit.ts +132 -0
- package/src/migrations/0005_purge_once.ts +42 -0
- package/src/migrations/0006_verification_outcomes.ts +51 -0
- package/src/migrations/0007_erasure_record.ts +43 -0
- package/src/migrations/0008_last_active.ts +30 -0
- package/src/migrations/pluginTables.ts +19 -1
- package/src/migrations/set.ts +9 -1
- package/src/processing/activities.ts +14 -0
- package/src/purge/contribution.ts +218 -0
- package/src/purge/retryPolicy.ts +26 -0
- package/src/purge/run.ts +348 -0
- package/src/purge/specs.ts +95 -0
- package/src/purge/start.ts +79 -0
- package/src/purge/workflow.ts +202 -0
- package/src/seeds/example.ts +2 -2
- package/src/test-utils/accountFootprint.ts +104 -0
- package/src/test-utils/liveApp.ts +10 -1
- package/src/token/handoff.ts +180 -0
- package/src/version.generated.ts +1 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import type { Migration } from "kysely/migration";
|
|
4
|
+
/**
|
|
5
|
+
* The erasure record (#823): what a deletion asked for, kept where the purge cannot erase it.
|
|
6
|
+
*
|
|
7
|
+
* **`mode` and `purge_after` on `pithy_auth_user_lifecycle`.** The attestation says whether a deletion was soft or
|
|
8
|
+
* hard and when its purge came due. Both sat only on `pithy_auth_users`, as `purgeAfter`, or nowhere, and the purge
|
|
9
|
+
* erases that row. So a `deleted` row now carries them: `soft` or `hard`, and the instant, ms-epoch. Null on every
|
|
10
|
+
* other row, and on a deletion recorded before this ran — the attestation says so rather than guessing.
|
|
11
|
+
*
|
|
12
|
+
* **Two indexes for the period read**, which asks which purges came due, ran a step, failed or finished in a window.
|
|
13
|
+
*
|
|
14
|
+
* **A `0007`, appended.** `@pithy-sh/auth` has shipped, so its chain is history. No backfill.
|
|
15
|
+
*/
|
|
16
|
+
export declare const auth_0007_erasure_record: Migration;
|
|
17
|
+
//# sourceMappingURL=0007_erasure_record.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"0007_erasure_record.d.ts","sourceRoot":"","sources":["../../src/migrations/0007_erasure_record.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAQlD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,wBAAwB,EAAE,SAkBtC,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import { sql } from "kysely";
|
|
4
|
+
//#region src/migrations/0007_erasure_record.ts
|
|
5
|
+
/** The period read's index: every erasure row written in a window. */
|
|
6
|
+
const CREATED_INDEX = "pithyAuthUserLifecycleCreatedAtIdx";
|
|
7
|
+
/** The period read's other index: every deletion whose purge came due in a window. */
|
|
8
|
+
const PURGE_AFTER_INDEX = "pithyAuthUserLifecyclePurgeAfterIdx";
|
|
9
|
+
/**
|
|
10
|
+
* The erasure record (#823): what a deletion asked for, kept where the purge cannot erase it.
|
|
11
|
+
*
|
|
12
|
+
* **`mode` and `purge_after` on `pithy_auth_user_lifecycle`.** The attestation says whether a deletion was soft or
|
|
13
|
+
* hard and when its purge came due. Both sat only on `pithy_auth_users`, as `purgeAfter`, or nowhere, and the purge
|
|
14
|
+
* erases that row. So a `deleted` row now carries them: `soft` or `hard`, and the instant, ms-epoch. Null on every
|
|
15
|
+
* other row, and on a deletion recorded before this ran — the attestation says so rather than guessing.
|
|
16
|
+
*
|
|
17
|
+
* **Two indexes for the period read**, which asks which purges came due, ran a step, failed or finished in a window.
|
|
18
|
+
*
|
|
19
|
+
* **A `0007`, appended.** `@pithy-sh/auth` has shipped, so its chain is history. No backfill.
|
|
20
|
+
*/
|
|
21
|
+
const auth_0007_erasure_record = {
|
|
22
|
+
async up(db) {
|
|
23
|
+
await db.schema.alterTable("pithyAuthUserLifecycle").addColumn("mode", "text").execute();
|
|
24
|
+
await db.schema.alterTable("pithyAuthUserLifecycle").addColumn("purgeAfter", "integer").execute();
|
|
25
|
+
await db.schema.createIndex(CREATED_INDEX).on("pithyAuthUserLifecycle").column("createdAt").execute();
|
|
26
|
+
await db.schema.createIndex(PURGE_AFTER_INDEX).on("pithyAuthUserLifecycle").column("purgeAfter").where(sql`purge_after is not null`).execute();
|
|
27
|
+
},
|
|
28
|
+
async down(db) {
|
|
29
|
+
await db.schema.dropIndex(PURGE_AFTER_INDEX).execute();
|
|
30
|
+
await db.schema.dropIndex(CREATED_INDEX).execute();
|
|
31
|
+
await db.schema.alterTable("pithyAuthUserLifecycle").dropColumn("purgeAfter").execute();
|
|
32
|
+
await db.schema.alterTable("pithyAuthUserLifecycle").dropColumn("mode").execute();
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
//#endregion
|
|
36
|
+
export { auth_0007_erasure_record };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import type { Migration } from "kysely/migration";
|
|
4
|
+
/**
|
|
5
|
+
* When an account was last active — stamped on `pithy_auth_users` by every session the account opens, so the
|
|
6
|
+
* retention policy's class ages have a clock that a sign-out cannot erase: a session row goes when its holder signs
|
|
7
|
+
* out, and this column stays.
|
|
8
|
+
*
|
|
9
|
+
* **Every existing account starts its clock now.** A row written before this column existed has no record of its
|
|
10
|
+
* last sign-in, and reading its absence as "never" would soft-delete an account somebody used last week the first
|
|
11
|
+
* night the pass runs. So `up` stamps the migration's own instant on every row, and an account becomes inactive no
|
|
12
|
+
* sooner than its class age after the upgrade. `down` drops the column and the index.
|
|
13
|
+
*/
|
|
14
|
+
export declare const auth_0008_last_active: Migration;
|
|
15
|
+
//# sourceMappingURL=0008_last_active.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"0008_last_active.d.ts","sourceRoot":"","sources":["../../src/migrations/0008_last_active.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAKlD;;;;;;;;;GASG;AACH,eAAO,MAAM,qBAAqB,EAAE,SAUnC,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import { sql } from "kysely";
|
|
4
|
+
//#region src/migrations/0008_last_active.ts
|
|
5
|
+
/** The inactivity pass's index: every account by when it was last active. */
|
|
6
|
+
const LAST_ACTIVE_INDEX = "pithyAuthUsersLastActiveAtIdx";
|
|
7
|
+
/**
|
|
8
|
+
* When an account was last active — stamped on `pithy_auth_users` by every session the account opens, so the
|
|
9
|
+
* retention policy's class ages have a clock that a sign-out cannot erase: a session row goes when its holder signs
|
|
10
|
+
* out, and this column stays.
|
|
11
|
+
*
|
|
12
|
+
* **Every existing account starts its clock now.** A row written before this column existed has no record of its
|
|
13
|
+
* last sign-in, and reading its absence as "never" would soft-delete an account somebody used last week the first
|
|
14
|
+
* night the pass runs. So `up` stamps the migration's own instant on every row, and an account becomes inactive no
|
|
15
|
+
* sooner than its class age after the upgrade. `down` drops the column and the index.
|
|
16
|
+
*/
|
|
17
|
+
const auth_0008_last_active = {
|
|
18
|
+
async up(db) {
|
|
19
|
+
await db.schema.alterTable("pithyAuthUsers").addColumn("lastActiveAt", "integer").execute();
|
|
20
|
+
await sql`update pithy_auth_users set last_active_at = cast(strftime('%s', 'now') as integer) * 1000`.execute(db);
|
|
21
|
+
await db.schema.createIndex(LAST_ACTIVE_INDEX).on("pithyAuthUsers").column("lastActiveAt").execute();
|
|
22
|
+
},
|
|
23
|
+
async down(db) {
|
|
24
|
+
await db.schema.dropIndex(LAST_ACTIVE_INDEX).execute();
|
|
25
|
+
await db.schema.alterTable("pithyAuthUsers").dropColumn("lastActiveAt").execute();
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
//#endregion
|
|
29
|
+
export { auth_0008_last_active };
|
|
@@ -110,6 +110,14 @@ export interface AuthPluginPlan {
|
|
|
110
110
|
id: string;
|
|
111
111
|
tables: string[];
|
|
112
112
|
}[];
|
|
113
|
+
/**
|
|
114
|
+
* The tables a plugin created that are keyed to one account by a `userId` column — `twoFactor`, `passkey`,
|
|
115
|
+
* an API key's table — which the purge erases and the export reads with auth's own (#622). Every one of them
|
|
116
|
+
* holds rows about the person and nothing else does, because a plugin's tables have no foreign key to cascade
|
|
117
|
+
* from the user row. `organization`'s are not here: a membership is the organization's as much as the
|
|
118
|
+
* person's, and what erasing one means is #623's.
|
|
119
|
+
*/
|
|
120
|
+
userTables: string[];
|
|
113
121
|
}
|
|
114
122
|
/**
|
|
115
123
|
* Derive everything the auth capability needs from an adopter's plugin list, in one pass.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pluginTables.d.ts","sourceRoot":"","sources":["../../src/migrations/pluginTables.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAKlD;;;;;;;;;;;;;;;;;;GAkBG;AAEH;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,SAAS,gBAAgB,EAAE,GAAG,iBAAiB,CA0BzF;AAED,6FAA6F;AAC7F,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,SAAS,CAAC;AAElD,iDAAiD;AACjD,MAAM,WAAW,iBAAiB;IAChC,sFAAsF;IACtF,IAAI,EAAE,MAAM,CAAC;IACb,0BAA0B;IAC1B,IAAI,EAAE,gBAAgB,CAAC;IACvB,wCAAwC;IACxC,OAAO,EAAE,OAAO,CAAC;IACjB,oDAAoD;IACpD,UAAU,EAAE,OAAO,CAAC;IACpB,wDAAwD;IACxD,MAAM,EAAE,OAAO,CAAC;IAChB,mDAAmD;IACnD,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,yCAAyC;AACzC,MAAM,WAAW,WAAW;IAC1B,kEAAkE;IAClE,IAAI,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,OAAO,EAAE,iBAAiB,EAAE,CAAC;CAC9B;AA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5F,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACtC,gFAAgF;IAChF,UAAU,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE,EAAE,CAAC;IAC/C;;;;;;OAMG;IACH,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AAQD;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,SAAS,gBAAgB,EAAE,GAAG,cAAc,CA4CnF"}
|
|
@@ -181,6 +181,10 @@ function pluginMigration(delta) {
|
|
|
181
181
|
function pluginMigrationKey(id) {
|
|
182
182
|
return `0002_plugin_${id.toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "")}`;
|
|
183
183
|
}
|
|
184
|
+
/** The column a plugin's table names its account by — Better Auth's own convention for a user-keyed row. */
|
|
185
|
+
const USER_KEY = "userId";
|
|
186
|
+
/** Plugins whose user-keyed tables the purge leaves to their own issue — see {@link AuthPluginPlan.userTables}. */
|
|
187
|
+
const PURGE_DEFERRED_PLUGINS = ["organization"];
|
|
184
188
|
/**
|
|
185
189
|
* Derive everything the auth capability needs from an adopter's plugin list, in one pass.
|
|
186
190
|
*
|
|
@@ -197,6 +201,7 @@ function pluginMigrationKey(id) {
|
|
|
197
201
|
function authPluginPlan(plugins) {
|
|
198
202
|
const migrations = {};
|
|
199
203
|
const extensions = [];
|
|
204
|
+
const userTables = [];
|
|
200
205
|
const claimed = /* @__PURE__ */ new Map();
|
|
201
206
|
for (const plugin of plugins) {
|
|
202
207
|
const delta = pluginSchemaDelta(plugin);
|
|
@@ -217,6 +222,7 @@ function authPluginPlan(plugins) {
|
|
|
217
222
|
detail: `plugins "${owner}" and "${plugin.id}" both claim table "${table.name}"`
|
|
218
223
|
});
|
|
219
224
|
claimed.set(table.name, plugin.id);
|
|
225
|
+
if (!PURGE_DEFERRED_PLUGINS.includes(plugin.id) && table.columns.some((column) => column.name === USER_KEY)) userTables.push(table.name);
|
|
220
226
|
}
|
|
221
227
|
if (delta.tables.length === 0 && delta.columns.length === 0) continue;
|
|
222
228
|
const key = pluginMigrationKey(plugin.id);
|
|
@@ -229,7 +235,8 @@ function authPluginPlan(plugins) {
|
|
|
229
235
|
}
|
|
230
236
|
return {
|
|
231
237
|
migrations,
|
|
232
|
-
extensions
|
|
238
|
+
extensions,
|
|
239
|
+
userTables
|
|
233
240
|
};
|
|
234
241
|
}
|
|
235
242
|
//#endregion
|
package/dist/migrations/set.d.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* migration. Adding a `0002` turned all five into a schema one column short of the code, and the symptom
|
|
11
11
|
* was `table pithy_auth_sessions has no column named authenticated_at` in thirteen unrelated tests.
|
|
12
12
|
*
|
|
13
|
-
* `0003`
|
|
13
|
+
* `0003` through `0007` appended here and reached every reader, which is the point. `0001_init.workers.test.ts` is deliberately not a reader:
|
|
14
14
|
* its subject is that one migration's own `up` and `down`, so it names it directly.
|
|
15
15
|
*/
|
|
16
16
|
export declare const AUTH_MIGRATIONS: {
|
|
@@ -18,5 +18,9 @@ export declare const AUTH_MIGRATIONS: {
|
|
|
18
18
|
readonly "0002_session_authenticated_at": import("kysely/migration").Migration;
|
|
19
19
|
readonly "0003_account_issuer_nullable": import("kysely/migration").Migration;
|
|
20
20
|
readonly "0004_user_lifecycle": import("kysely/migration").Migration;
|
|
21
|
+
readonly "0005_purge_once": import("kysely/migration").Migration;
|
|
22
|
+
readonly "0006_verification_outcomes": import("kysely/migration").Migration;
|
|
23
|
+
readonly "0007_erasure_record": import("kysely/migration").Migration;
|
|
24
|
+
readonly "0008_last_active": import("kysely/migration").Migration;
|
|
21
25
|
};
|
|
22
26
|
//# sourceMappingURL=set.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"set.d.ts","sourceRoot":"","sources":["../../src/migrations/set.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"set.d.ts","sourceRoot":"","sources":["../../src/migrations/set.ts"],"names":[],"mappings":"AAYA;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,eAAe;aAC1B,WAAW;aACX,+BAA+B;aAC/B,8BAA8B;aAC9B,qBAAqB;aACrB,iBAAiB;aACjB,4BAA4B;aAC5B,qBAAqB;aACrB,kBAAkB;CACV,CAAC"}
|
package/dist/migrations/set.js
CHANGED
|
@@ -4,6 +4,10 @@ import { auth_0001_init } from "./0001_init.js";
|
|
|
4
4
|
import { auth_0002_session_authenticated_at } from "./0002_session_authenticated_at.js";
|
|
5
5
|
import { auth_0003_account_issuer_nullable } from "./0003_account_issuer_nullable.js";
|
|
6
6
|
import { auth_0004_user_lifecycle } from "./0004_user_lifecycle.js";
|
|
7
|
+
import { auth_0005_purge_once } from "./0005_purge_once.js";
|
|
8
|
+
import { auth_0006_verification_outcomes } from "./0006_verification_outcomes.js";
|
|
9
|
+
import { auth_0007_erasure_record } from "./0007_erasure_record.js";
|
|
10
|
+
import { auth_0008_last_active } from "./0008_last_active.js";
|
|
7
11
|
//#region src/migrations/set.ts
|
|
8
12
|
/**
|
|
9
13
|
* Every migration `@pithy-sh/auth` ships, keyed as `pithy migrate` composes them.
|
|
@@ -15,14 +19,18 @@ import { auth_0004_user_lifecycle } from "./0004_user_lifecycle.js";
|
|
|
15
19
|
* migration. Adding a `0002` turned all five into a schema one column short of the code, and the symptom
|
|
16
20
|
* was `table pithy_auth_sessions has no column named authenticated_at` in thirteen unrelated tests.
|
|
17
21
|
*
|
|
18
|
-
* `0003`
|
|
22
|
+
* `0003` through `0007` appended here and reached every reader, which is the point. `0001_init.workers.test.ts` is deliberately not a reader:
|
|
19
23
|
* its subject is that one migration's own `up` and `down`, so it names it directly.
|
|
20
24
|
*/
|
|
21
25
|
const AUTH_MIGRATIONS = {
|
|
22
26
|
"0001_init": auth_0001_init,
|
|
23
27
|
"0002_session_authenticated_at": auth_0002_session_authenticated_at,
|
|
24
28
|
"0003_account_issuer_nullable": auth_0003_account_issuer_nullable,
|
|
25
|
-
"0004_user_lifecycle": auth_0004_user_lifecycle
|
|
29
|
+
"0004_user_lifecycle": auth_0004_user_lifecycle,
|
|
30
|
+
"0005_purge_once": auth_0005_purge_once,
|
|
31
|
+
"0006_verification_outcomes": auth_0006_verification_outcomes,
|
|
32
|
+
"0007_erasure_record": auth_0007_erasure_record,
|
|
33
|
+
"0008_last_active": auth_0008_last_active
|
|
26
34
|
};
|
|
27
35
|
//#endregion
|
|
28
36
|
export { AUTH_MIGRATIONS };
|
package/dist/peer.d.ts
CHANGED
|
@@ -23,8 +23,8 @@ export declare const authPeer: {
|
|
|
23
23
|
readonly authDatabase: typeof authDatabase;
|
|
24
24
|
readonly User: import("zod").ZodObject<{
|
|
25
25
|
id: import("zod").ZodString;
|
|
26
|
-
name: import("zod").ZodString
|
|
27
|
-
email: import("zod").ZodString
|
|
26
|
+
name: import("@pithy-sh/core/src/privacy/classes").Marked<import("zod").ZodString, "pii">;
|
|
27
|
+
email: import("@pithy-sh/core/src/privacy/classes").Marked<import("zod").ZodString, "pii">;
|
|
28
28
|
emailVerified: import("zod").ZodCodec<import("zod").ZodUnion<readonly [import("zod").ZodLiteral<0>, import("zod").ZodLiteral<1>, import("zod").ZodBoolean, import("zod").ZodString]>, import("zod").ZodBoolean>;
|
|
29
29
|
image: import("zod").ZodNullable<import("zod").ZodString>;
|
|
30
30
|
locale: import("zod").ZodNullable<import("zod").ZodString>;
|
|
@@ -34,6 +34,7 @@ export declare const authPeer: {
|
|
|
34
34
|
suspendedUntil: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodCodec<import("zod").ZodUnion<readonly [import("zod").ZodNumber, import("zod").ZodString, import("zod").ZodDate]>, import("zod").ZodDate>>>;
|
|
35
35
|
deletedAt: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodCodec<import("zod").ZodUnion<readonly [import("zod").ZodNumber, import("zod").ZodString, import("zod").ZodDate]>, import("zod").ZodDate>>>;
|
|
36
36
|
purgeAfter: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodCodec<import("zod").ZodUnion<readonly [import("zod").ZodNumber, import("zod").ZodString, import("zod").ZodDate]>, import("zod").ZodDate>>>;
|
|
37
|
+
lastActiveAt: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodCodec<import("zod").ZodUnion<readonly [import("zod").ZodNumber, import("zod").ZodString, import("zod").ZodDate]>, import("zod").ZodDate>>>;
|
|
37
38
|
}, import("zod/v4/core").$strip>;
|
|
38
39
|
readonly Device: import("zod").ZodObject<{
|
|
39
40
|
id: import("zod").ZodString;
|
package/dist/peer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"peer.d.ts","sourceRoot":"","sources":["../src/peer.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,QAAQ
|
|
1
|
+
{"version":3,"file":"peer.d.ts","sourceRoot":"","sources":["../src/peer.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAA0C,CAAC;AAEhE,4DAA4D;AAC5D,MAAM,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import type { ProcessingActivityInput } from "@pithy-sh/core/src/processing/activity";
|
|
4
|
+
/** What auth does with personal data: it keeps accounts and signs their holders in. */
|
|
5
|
+
export declare const AUTH_PROCESSING: readonly ProcessingActivityInput[];
|
|
6
|
+
//# sourceMappingURL=activities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"activities.d.ts","sourceRoot":"","sources":["../../src/processing/activities.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AAEtF,uFAAuF;AACvF,eAAO,MAAM,eAAe,EAAE,SAAS,uBAAuB,EAO7D,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
//#region src/processing/activities.ts
|
|
4
|
+
/** What auth does with personal data: it keeps accounts and signs their holders in. */
|
|
5
|
+
const AUTH_PROCESSING = [{
|
|
6
|
+
id: "auth.account",
|
|
7
|
+
purpose: "Keep a person's account, sign them in, and keep the sessions that prove it.",
|
|
8
|
+
classes: ["pii"],
|
|
9
|
+
legalBasis: "contract"
|
|
10
|
+
}];
|
|
11
|
+
//#endregion
|
|
12
|
+
export { AUTH_PROCESSING };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import type { D1Database } from "@cloudflare/workers-types";
|
|
4
|
+
import type { ErasingPurgeContribution } from "@pithy-sh/core/src/capability/purge";
|
|
5
|
+
import { type CompiledQuery, type Kysely } from "kysely";
|
|
6
|
+
import { type AuthDatabase } from "../data/tables";
|
|
7
|
+
import type { AuthUserExport } from "../http/responses";
|
|
8
|
+
/**
|
|
9
|
+
* Auth's own purge contribution (#622): what erasing one person means for the `pithy_auth_*` tables, and what
|
|
10
|
+
* exporting them hands back.
|
|
11
|
+
*
|
|
12
|
+
* **Every row keyed to the account goes, except its history.** The user row, its sessions, its linked
|
|
13
|
+
* providers, its devices, its refresh-token ledger, any sign-in code or link still pending for its address, its
|
|
14
|
+
* rows in the verification ledger (#829), and its rows in every table a composed Better Auth plugin created keyed by `userId` — a two-factor secret
|
|
15
|
+
* and its backup codes, a passkey, an API key. Those tables have no foreign key to the user row, so deleting
|
|
16
|
+
* it removes nothing from them; they are named by the plugin plan (`../migrations/pluginTables.ts`). `pithy_auth_user_lifecycle` stays: it is the record that the account existed, was deleted and was
|
|
17
|
+
* erased, and it names the account by id and holds nothing else about the person (`../data/userLifecycle.ts`).
|
|
18
|
+
* The rate-limit and JWKS tables are keyed to no person and are not touched.
|
|
19
|
+
*
|
|
20
|
+
* **One transaction.** The deletes are one `d1.batch()`, which D1 runs as one, so a failure leaves every row
|
|
21
|
+
* where it was and the retried step erases the lot. **Idempotent**, as the contract requires: a second run
|
|
22
|
+
* finds no rows and deletes nothing, and succeeds.
|
|
23
|
+
*
|
|
24
|
+
* The purge Workflow runs this step **last**, after every other capability's and after the deletion-complete
|
|
25
|
+
* mail, because the address that mail is sent to lives on the user row this deletes.
|
|
26
|
+
*/
|
|
27
|
+
/** The one sentence the purge records with this step. */
|
|
28
|
+
export declare const AUTH_PURGE_SUMMARY = "Deletes the account, its sessions, linked providers, devices, refresh-token ledger, pending sign-in codes, the record of the sign-in links and codes it was sent, and its rows in the tables its Better Auth plugins created. Its lifecycle history stays.";
|
|
29
|
+
/** The auth Kysely without its table map — a plugin's table is named by the plan, not by `authTables`. */
|
|
30
|
+
export declare function untyped(db: AuthDatabase): Kysely<Record<string, Record<string, unknown>>>;
|
|
31
|
+
/** The D1 binding the auth tables live in, off a run's env — or a wiring fault naming it. */
|
|
32
|
+
export declare function bindingOf(env: Record<string, unknown>, database: string): D1Database;
|
|
33
|
+
/** Bind a compiled statement to D1, so it can join a `batch`. */
|
|
34
|
+
export declare function prepared(d1: D1Database, compiled: CompiledQuery): import("@cloudflare/workers-types").D1PreparedStatement;
|
|
35
|
+
/**
|
|
36
|
+
* Erase one account's `pithy_auth_*` rows, its history excepted. Succeeds, having found nothing, when they are
|
|
37
|
+
* already gone.
|
|
38
|
+
*
|
|
39
|
+
* The pending sign-in codes are found by the address, which is why it is read first: an email OTP's identifier
|
|
40
|
+
* is `<type>-otp-<address>`, and a magic link's value is JSON carrying `"email":"<address>"`. With the user row
|
|
41
|
+
* already gone there is no address to look for, and none is needed — a code lives for minutes.
|
|
42
|
+
*/
|
|
43
|
+
export declare function eraseAuthUser(db: AuthDatabase, d1: D1Database, userId: string, pluginTables?: readonly string[]): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* What auth holds about one account, for an export: the account, its sessions, providers, devices and
|
|
46
|
+
* history, every list whole. `null` when there is no account to export.
|
|
47
|
+
*/
|
|
48
|
+
export declare function exportAuthUser(db: AuthDatabase, userId: string, pluginTables?: readonly string[]): Promise<AuthUserExport | null>;
|
|
49
|
+
/** One plugin table's rows about the account, every column but a credential's. */
|
|
50
|
+
export declare function pluginRows(db: AuthDatabase, table: string, userId: string): Promise<Record<string, unknown>[]>;
|
|
51
|
+
/**
|
|
52
|
+
* The contribution `auth()` declares, over the D1 binding its config names. The export of an account that is
|
|
53
|
+
* not there is an empty object, which the route never reaches: it answers 404 before it reads any capability.
|
|
54
|
+
*/
|
|
55
|
+
/**
|
|
56
|
+
* An account's address by user id, over the env's auth database — what auth answers through core's `addressOf`
|
|
57
|
+
* seam, so a capability holding state by address (email's suppression list) finds it without importing auth.
|
|
58
|
+
* `null` for an account that has none, or no longer exists.
|
|
59
|
+
*/
|
|
60
|
+
export declare function authAddressOf(database: string): (env: Record<string, unknown>, userId: string) => Promise<string | null>;
|
|
61
|
+
export declare function authPurgeContribution(database: string, pluginTables?: readonly string[]): ErasingPurgeContribution;
|
|
62
|
+
//# sourceMappingURL=contribution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contribution.d.ts","sourceRoot":"","sources":["../../src/purge/contribution.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,wBAAwB,EAAgB,MAAM,qCAAqC,CAAC;AAElG,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,MAAM,EAAqB,MAAM,Q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E,OAAO,CAAC,UAAU,MAAM,KAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAE9E;AAED,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,EAChB,YAAY,GAAE,SAAS,MAAM,EAAO,GACnC,wBAAwB,CAc1B"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import { Account, Session, User } from "../data/betterAuth.js";
|
|
4
|
+
import { Device } from "../data/device.js";
|
|
5
|
+
import { UserLifecycleEvent } from "../data/userLifecycle.js";
|
|
6
|
+
import { VerificationOutcome } from "../data/verificationOutcome.js";
|
|
7
|
+
import { authDatabase } from "../data/tables.js";
|
|
8
|
+
import { purgeAddress } from "../lifecycle/transitions.js";
|
|
9
|
+
import { authUserExportView } from "../http/views.js";
|
|
10
|
+
import { InternalError } from "@pithy-sh/core/src/error/pithyError";
|
|
11
|
+
import { sql } from "kysely";
|
|
12
|
+
//#region src/purge/contribution.ts
|
|
13
|
+
/**
|
|
14
|
+
* Auth's own purge contribution (#622): what erasing one person means for the `pithy_auth_*` tables, and what
|
|
15
|
+
* exporting them hands back.
|
|
16
|
+
*
|
|
17
|
+
* **Every row keyed to the account goes, except its history.** The user row, its sessions, its linked
|
|
18
|
+
* providers, its devices, its refresh-token ledger, any sign-in code or link still pending for its address, its
|
|
19
|
+
* rows in the verification ledger (#829), and its rows in every table a composed Better Auth plugin created keyed by `userId` — a two-factor secret
|
|
20
|
+
* and its backup codes, a passkey, an API key. Those tables have no foreign key to the user row, so deleting
|
|
21
|
+
* it removes nothing from them; they are named by the plugin plan (`../migrations/pluginTables.ts`). `pithy_auth_user_lifecycle` stays: it is the record that the account existed, was deleted and was
|
|
22
|
+
* erased, and it names the account by id and holds nothing else about the person (`../data/userLifecycle.ts`).
|
|
23
|
+
* The rate-limit and JWKS tables are keyed to no person and are not touched.
|
|
24
|
+
*
|
|
25
|
+
* **One transaction.** The deletes are one `d1.batch()`, which D1 runs as one, so a failure leaves every row
|
|
26
|
+
* where it was and the retried step erases the lot. **Idempotent**, as the contract requires: a second run
|
|
27
|
+
* finds no rows and deletes nothing, and succeeds.
|
|
28
|
+
*
|
|
29
|
+
* The purge Workflow runs this step **last**, after every other capability's and after the deletion-complete
|
|
30
|
+
* mail, because the address that mail is sent to lives on the user row this deletes.
|
|
31
|
+
*/
|
|
32
|
+
/** The one sentence the purge records with this step. */
|
|
33
|
+
const AUTH_PURGE_SUMMARY = "Deletes the account, its sessions, linked providers, devices, refresh-token ledger, pending sign-in codes, the record of the sign-in links and codes it was sent, and its rows in the tables its Better Auth plugins created. Its lifecycle history stays.";
|
|
34
|
+
/**
|
|
35
|
+
* A plugin table's column that holds a credential — a TOTP secret, backup codes, a key or its hash, a token.
|
|
36
|
+
* The export leaves these out, as it leaves out a session's token and a provider's: an access request is
|
|
37
|
+
* answered with what is held, never with the means to sign in as the person.
|
|
38
|
+
*/
|
|
39
|
+
const CREDENTIAL_COLUMN = /secret|token|key|code|hash|password|credential/i;
|
|
40
|
+
/** The auth Kysely without its table map — a plugin's table is named by the plan, not by `authTables`. */
|
|
41
|
+
function untyped(db) {
|
|
42
|
+
return db;
|
|
43
|
+
}
|
|
44
|
+
/** The D1 binding the auth tables live in, off a run's env — or a wiring fault naming it. */
|
|
45
|
+
function bindingOf(env, database) {
|
|
46
|
+
const binding = env[database];
|
|
47
|
+
if (typeof binding !== "object" || binding === null) throw new InternalError({
|
|
48
|
+
message: "The auth database is not bound, so this purge step could not run.",
|
|
49
|
+
action: `Bind the ${database} D1 database to the Worker that runs the purge.`,
|
|
50
|
+
detail: `auth purge contribution found no ${database} binding on the env`
|
|
51
|
+
});
|
|
52
|
+
return binding;
|
|
53
|
+
}
|
|
54
|
+
/** `%` and `_` escaped, so an address is matched as itself inside a LIKE pattern and nothing wider. */
|
|
55
|
+
function literal(value) {
|
|
56
|
+
return value.replace(/[\\%_]/g, (character) => `\\${character}`);
|
|
57
|
+
}
|
|
58
|
+
/** Bind a compiled statement to D1, so it can join a `batch`. */
|
|
59
|
+
function prepared(d1, compiled) {
|
|
60
|
+
return d1.prepare(compiled.sql).bind(...compiled.parameters);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Erase one account's `pithy_auth_*` rows, its history excepted. Succeeds, having found nothing, when they are
|
|
64
|
+
* already gone.
|
|
65
|
+
*
|
|
66
|
+
* The pending sign-in codes are found by the address, which is why it is read first: an email OTP's identifier
|
|
67
|
+
* is `<type>-otp-<address>`, and a magic link's value is JSON carrying `"email":"<address>"`. With the user row
|
|
68
|
+
* already gone there is no address to look for, and none is needed — a code lives for minutes.
|
|
69
|
+
*/
|
|
70
|
+
async function eraseAuthUser(db, d1, userId, pluginTables = []) {
|
|
71
|
+
const user = await db.selectFrom("pithyAuthUsers").select("email").where("id", "=", userId).executeTakeFirst();
|
|
72
|
+
const statements = [
|
|
73
|
+
db.deleteFrom("pithyAuthSessions").where("userId", "=", userId),
|
|
74
|
+
db.deleteFrom("pithyAuthAccounts").where("userId", "=", userId),
|
|
75
|
+
db.deleteFrom("pithyAuthDevices").where("userId", "=", userId),
|
|
76
|
+
db.deleteFrom("pithyAuthRotatedTokens").where("userId", "=", userId),
|
|
77
|
+
db.deleteFrom("pithyAuthVerificationOutcomes").where("userId", "=", userId)
|
|
78
|
+
].map((query) => prepared(d1, query.compile()));
|
|
79
|
+
for (const table of pluginTables) statements.push(prepared(d1, untyped(db).deleteFrom(table).where("userId", "=", userId).compile()));
|
|
80
|
+
if (user) {
|
|
81
|
+
const address = literal(user.email);
|
|
82
|
+
const otp = `%-otp-${address}`;
|
|
83
|
+
const changingFrom = `%-otp-${address}-%`;
|
|
84
|
+
const link = `%"email":${literal(JSON.stringify(user.email))}%`;
|
|
85
|
+
const pending = db.deleteFrom("pithyAuthVerifications").where(sql`(identifier like ${otp} escape '\\' or identifier like ${changingFrom} escape '\\' or value like ${link} escape '\\')`);
|
|
86
|
+
statements.push(prepared(d1, pending.compile()));
|
|
87
|
+
}
|
|
88
|
+
statements.push(prepared(d1, db.deleteFrom("pithyAuthUsers").where("id", "=", userId).compile()));
|
|
89
|
+
await d1.batch(statements);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* What auth holds about one account, for an export: the account, its sessions, providers, devices and
|
|
93
|
+
* history, every list whole. `null` when there is no account to export.
|
|
94
|
+
*/
|
|
95
|
+
async function exportAuthUser(db, userId, pluginTables = []) {
|
|
96
|
+
const row = await db.selectFrom("pithyAuthUsers").selectAll().where("id", "=", userId).executeTakeFirst();
|
|
97
|
+
if (!row) return null;
|
|
98
|
+
const [sessions, accounts, devices, history, verifications, plugins] = await Promise.all([
|
|
99
|
+
db.selectFrom("pithyAuthSessions").selectAll().where("userId", "=", userId).orderBy("createdAt", "desc").orderBy("id", "desc").execute(),
|
|
100
|
+
db.selectFrom("pithyAuthAccounts").select(["providerId", "createdAt"]).where("userId", "=", userId).orderBy("providerId", "asc").execute(),
|
|
101
|
+
db.selectFrom("pithyAuthDevices").selectAll().where("userId", "=", userId).orderBy("lastSeenAt", "desc").orderBy("id", "desc").execute(),
|
|
102
|
+
db.selectFrom("pithyAuthUserLifecycle").selectAll().where("userId", "=", userId).orderBy("id", "asc").execute(),
|
|
103
|
+
db.selectFrom("pithyAuthVerificationOutcomes").selectAll().where("userId", "=", userId).orderBy("issuedAt", "desc").orderBy("id", "desc").execute(),
|
|
104
|
+
Promise.all(pluginTables.map(async (table) => [table, await pluginRows(db, table, userId)]))
|
|
105
|
+
]);
|
|
106
|
+
return authUserExportView({
|
|
107
|
+
now: /* @__PURE__ */ new Date(),
|
|
108
|
+
user: User.parse(row),
|
|
109
|
+
sessions: sessions.map((session) => Session.parse(session)),
|
|
110
|
+
accounts: accounts.map((account) => Account.pick({
|
|
111
|
+
providerId: true,
|
|
112
|
+
createdAt: true
|
|
113
|
+
}).parse(account)),
|
|
114
|
+
devices: devices.map((device) => Device.parse(device)),
|
|
115
|
+
history: history.map((event) => UserLifecycleEvent.parse(event)),
|
|
116
|
+
verifications: verifications.map((row) => VerificationOutcome.parse(row)),
|
|
117
|
+
plugins: Object.fromEntries(plugins)
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
/** One plugin table's rows about the account, every column but a credential's. */
|
|
121
|
+
async function pluginRows(db, table, userId) {
|
|
122
|
+
return (await untyped(db).selectFrom(table).selectAll().where("userId", "=", userId).execute()).map((row) => Object.fromEntries(Object.entries(row).filter(([column]) => !CREDENTIAL_COLUMN.test(column))));
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* The contribution `auth()` declares, over the D1 binding its config names. The export of an account that is
|
|
126
|
+
* not there is an empty object, which the route never reaches: it answers 404 before it reads any capability.
|
|
127
|
+
*/
|
|
128
|
+
/**
|
|
129
|
+
* An account's address by user id, over the env's auth database — what auth answers through core's `addressOf`
|
|
130
|
+
* seam, so a capability holding state by address (email's suppression list) finds it without importing auth.
|
|
131
|
+
* `null` for an account that has none, or no longer exists.
|
|
132
|
+
*/
|
|
133
|
+
function authAddressOf(database) {
|
|
134
|
+
return (env, userId) => purgeAddress(authDatabase(bindingOf(env, database)), userId);
|
|
135
|
+
}
|
|
136
|
+
function authPurgeContribution(database, pluginTables = []) {
|
|
137
|
+
const open = (context) => {
|
|
138
|
+
const d1 = bindingOf(context.env, database);
|
|
139
|
+
return {
|
|
140
|
+
d1,
|
|
141
|
+
db: authDatabase(d1)
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
return {
|
|
145
|
+
subject: "user",
|
|
146
|
+
summary: AUTH_PURGE_SUMMARY,
|
|
147
|
+
erase: async (context) => {
|
|
148
|
+
const { d1, db } = open(context);
|
|
149
|
+
await eraseAuthUser(db, d1, context.subject.id, pluginTables);
|
|
150
|
+
},
|
|
151
|
+
export: async (context) => await exportAuthUser(open(context).db, context.subject.id, pluginTables) ?? {}
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
//#endregion
|
|
155
|
+
export { AUTH_PURGE_SUMMARY, authAddressOf, authPurgeContribution, bindingOf, eraseAuthUser, exportAuthUser, pluginRows, prepared, untyped };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import type { WorkflowRetryPolicy } from "@pithy-sh/core/src/workflow/faults";
|
|
4
|
+
/**
|
|
5
|
+
* **What the purge's own steps retry, and what they refuse to** (#622).
|
|
6
|
+
*
|
|
7
|
+
* The purge's own steps — reading whether the account is due, the last mail, the final record — and the daily
|
|
8
|
+
* pass's are D1, and core answers for D1's transient vocabulary through `withD1Retry`. There is no `auth/*`
|
|
9
|
+
* code a second attempt can answer differently, so the record is empty, and that is a statement: an account
|
|
10
|
+
* that is not due, or a binding that is not there, is the same answer next time.
|
|
11
|
+
*
|
|
12
|
+
* **A capability's erase step is not classified here, deliberately.** It runs the contribution's own code —
|
|
13
|
+
* another capability's, or the adopter's — whose fault vocabulary the kit cannot know, and the contract makes
|
|
14
|
+
* every `erase` idempotent precisely so that any fault in it can be retried. So the purge hands those steps to
|
|
15
|
+
* the platform's own retry, with its backoff: a failing contribution retries alone, and the steps that finished
|
|
16
|
+
* are served from the journal. That is the classification, stated at its one site, `./run.ts`.
|
|
17
|
+
*
|
|
18
|
+
* **The cron is the outer retry.** A pass whose `start` step fails is run again the next day, and a purge whose
|
|
19
|
+
* instance failed is started again for the account still past its window.
|
|
20
|
+
*/
|
|
21
|
+
export declare const authWorkflowRetry: WorkflowRetryPolicy;
|
|
22
|
+
//# sourceMappingURL=retryPolicy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retryPolicy.d.ts","sourceRoot":"","sources":["../../src/purge/retryPolicy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAE9E;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,iBAAiB,EAAE,mBAG/B,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
//#region src/purge/retryPolicy.ts
|
|
4
|
+
/**
|
|
5
|
+
* **What the purge's own steps retry, and what they refuse to** (#622).
|
|
6
|
+
*
|
|
7
|
+
* The purge's own steps — reading whether the account is due, the last mail, the final record — and the daily
|
|
8
|
+
* pass's are D1, and core answers for D1's transient vocabulary through `withD1Retry`. There is no `auth/*`
|
|
9
|
+
* code a second attempt can answer differently, so the record is empty, and that is a statement: an account
|
|
10
|
+
* that is not due, or a binding that is not there, is the same answer next time.
|
|
11
|
+
*
|
|
12
|
+
* **A capability's erase step is not classified here, deliberately.** It runs the contribution's own code —
|
|
13
|
+
* another capability's, or the adopter's — whose fault vocabulary the kit cannot know, and the contract makes
|
|
14
|
+
* every `erase` idempotent precisely so that any fault in it can be retried. So the purge hands those steps to
|
|
15
|
+
* the platform's own retry, with its backoff: a failing contribution retries alone, and the steps that finished
|
|
16
|
+
* are served from the journal. That is the classification, stated at its one site, `./run.ts`.
|
|
17
|
+
*
|
|
18
|
+
* **The cron is the outer retry.** A pass whose `start` step fails is run again the next day, and a purge whose
|
|
19
|
+
* instance failed is started again for the account still past its window.
|
|
20
|
+
*/
|
|
21
|
+
const authWorkflowRetry = {
|
|
22
|
+
capability: "auth",
|
|
23
|
+
retryable: {}
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
26
|
+
export { authWorkflowRetry };
|