@pithy-sh/auth 0.9.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 +8 -2
- package/dist/admin/users.js +1 -1
- package/dist/audit/actions.d.ts +40 -0
- package/dist/audit/actions.d.ts.map +1 -1
- package/dist/audit/actions.js +41 -1
- package/dist/audit/emit.d.ts +2 -0
- package/dist/audit/emit.d.ts.map +1 -1
- package/dist/audit/emit.js +2 -2
- package/dist/capability.d.ts +45 -1
- package/dist/capability.d.ts.map +1 -1
- package/dist/capability.js +40 -5
- package/dist/client/lifecycle.d.ts +19 -0
- package/dist/client/lifecycle.d.ts.map +1 -0
- package/dist/client/lifecycle.js +25 -0
- package/dist/client/projection.d.ts +4 -0
- package/dist/client/projection.d.ts.map +1 -1
- package/dist/data/betterAuth.d.ts +4 -0
- package/dist/data/betterAuth.d.ts.map +1 -1
- package/dist/data/betterAuth.js +6 -2
- package/dist/data/kitFields.d.ts +20 -25
- package/dist/data/kitFields.d.ts.map +1 -1
- package/dist/data/kitFields.js +28 -32
- package/dist/data/tables.d.ts +29 -2
- package/dist/data/tables.d.ts.map +1 -1
- package/dist/data/tables.js +5 -3
- package/dist/data/userLifecycle.d.ts +62 -0
- package/dist/data/userLifecycle.d.ts.map +1 -0
- package/dist/data/userLifecycle.js +51 -0
- package/dist/http/adminRoutes.d.ts.map +1 -1
- package/dist/http/adminRoutes.js +270 -5
- package/dist/http/guards.d.ts +24 -1
- package/dist/http/guards.d.ts.map +1 -1
- package/dist/http/guards.js +59 -3
- package/dist/http/lifecycleGate.d.ts +18 -0
- package/dist/http/lifecycleGate.d.ts.map +1 -0
- package/dist/http/lifecycleGate.js +75 -0
- package/dist/http/middleware.d.ts +30 -1
- package/dist/http/middleware.d.ts.map +1 -1
- package/dist/http/middleware.js +89 -7
- package/dist/http/providerRefusal.d.ts.map +1 -1
- package/dist/http/providerRefusal.js +8 -0
- package/dist/http/resolve.d.ts.map +1 -1
- package/dist/http/resolve.js +7 -4
- 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 +65 -4
- 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 +55 -3
- package/dist/instance/auth.d.ts.map +1 -1
- package/dist/instance/auth.js +53 -2
- package/dist/instance/microsoftEmail.d.ts +70 -0
- package/dist/instance/microsoftEmail.d.ts.map +1 -0
- package/dist/instance/microsoftEmail.js +96 -0
- package/dist/instance/providerSignInGate.d.ts +7 -6
- package/dist/instance/providerSignInGate.d.ts.map +1 -1
- package/dist/instance/providerSignInGate.js +7 -6
- package/dist/instance/providers.d.ts +7 -5
- package/dist/instance/providers.d.ts.map +1 -1
- package/dist/instance/providers.js +5 -3
- package/dist/instance/secrets.d.ts +64 -3
- package/dist/instance/secrets.d.ts.map +1 -1
- package/dist/instance/secrets.js +44 -5
- 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 +75 -0
- package/dist/lifecycle/enforce.d.ts.map +1 -0
- package/dist/lifecycle/enforce.js +111 -0
- package/dist/lifecycle/hooks.d.ts +53 -0
- package/dist/lifecycle/hooks.d.ts.map +1 -0
- package/dist/lifecycle/hooks.js +2 -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 +18 -0
- package/dist/lifecycle/request.d.ts.map +1 -0
- package/dist/lifecycle/request.js +31 -0
- package/dist/lifecycle/state.d.ts +64 -0
- package/dist/lifecycle/state.d.ts.map +1 -0
- package/dist/lifecycle/state.js +90 -0
- package/dist/lifecycle/transitions.d.ts +272 -0
- package/dist/lifecycle/transitions.d.ts.map +1 -0
- package/dist/lifecycle/transitions.js +623 -0
- package/dist/migrations/0004_user_lifecycle.d.ts +28 -0
- package/dist/migrations/0004_user_lifecycle.d.ts.map +1 -0
- package/dist/migrations/0004_user_lifecycle.js +47 -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/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 +3 -1
- package/dist/migrations/set.d.ts.map +1 -1
- package/dist/migrations/set.js +6 -2
- package/dist/peer.d.ts +4 -0
- package/dist/peer.d.ts.map +1 -1
- 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/test-utils/liveApp.d.ts +21 -0
- package/dist/test-utils/liveApp.d.ts.map +1 -1
- package/dist/test-utils/liveApp.js +1 -0
- package/dist/test-utils/scopedBackend.d.ts +21 -0
- package/dist/test-utils/scopedBackend.d.ts.map +1 -1
- package/dist/test-utils/scopedBackend.js +7 -1
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.d.ts.map +1 -1
- package/dist/version.generated.js +1 -1
- package/docs/account-lifecycle.md +217 -0
- package/docs/apple-signin.md +7 -1
- package/docs/facebook-oauth.md +7 -1
- package/docs/github-oauth.md +7 -1
- package/docs/google-oauth.md +7 -1
- package/docs/microsoft-oauth.md +177 -0
- package/package.json +5 -5
- package/pithy.manifest.json +17 -3
- package/src/audit/actions.ts +42 -0
- package/src/audit/emit.ts +4 -2
- package/src/capability.ts +170 -52
- package/src/client/lifecycle.ts +27 -0
- package/src/client/projection.ts +4 -0
- package/src/data/betterAuth.ts +21 -1
- package/src/data/kitFields.ts +27 -0
- package/src/data/tables.ts +4 -2
- package/src/data/userLifecycle.ts +83 -0
- package/src/http/adminRoutes.ts +398 -2
- package/src/http/guards.ts +61 -1
- package/src/http/lifecycleGate.ts +78 -0
- package/src/http/middleware.ts +104 -2
- package/src/http/providerRefusal.ts +10 -0
- package/src/http/resolve.ts +8 -3
- package/src/http/responses.ts +245 -0
- package/src/http/routes.ts +93 -4
- package/src/http/schemas.ts +110 -0
- package/src/http/views.ts +147 -2
- package/src/instance/auth.ts +74 -2
- package/src/instance/microsoftEmail.ts +111 -0
- package/src/instance/providerSignInGate.ts +7 -6
- package/src/instance/providers.ts +8 -4
- package/src/instance/secrets.ts +59 -5
- package/src/lifecycle/audited.ts +104 -0
- package/src/lifecycle/enforce.ts +139 -0
- package/src/lifecycle/hooks.ts +54 -0
- package/src/lifecycle/reason.ts +11 -0
- package/src/lifecycle/request.ts +39 -0
- package/src/lifecycle/state.ts +101 -0
- package/src/lifecycle/transitions.ts +872 -0
- package/src/migrations/0004_user_lifecycle.ts +68 -0
- package/src/migrations/0005_purge_once.ts +42 -0
- package/src/migrations/pluginTables.ts +19 -1
- package/src/migrations/set.ts +5 -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/test-utils/liveApp.ts +2 -1
- package/src/test-utils/scopedBackend.ts +2 -1
- package/src/version.generated.ts +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @pithy-sh/auth
|
|
2
2
|
|
|
3
|
-
Passwordless auth for Cloudflare. Magic link, email OTP, Google, Apple. Mobile and web, both first-class. Built on Better Auth. No email and password, ever.
|
|
3
|
+
Passwordless auth for Cloudflare. Magic link, email OTP, Google, Apple, Facebook, GitHub, Microsoft. Mobile and web, both first-class. Built on Better Auth. No email and password, ever.
|
|
4
4
|
|
|
5
5
|
This capability fills core's identity seams. It mints sessions, issues short-lived JWT access tokens, registers devices, and validates every request — so other capabilities just call `requireAuth()`.
|
|
6
6
|
|
|
@@ -54,7 +54,13 @@ Pressing a provider button while signed out is not a claim on an address. It is
|
|
|
54
54
|
|
|
55
55
|
**Rows 3 and 4 answer identically**, and that is a security property rather than a rough edge. They differ only in whether an account exists at an address the caller chose, and telling a stranger which one they hit is an account-enumeration oracle: one provider account, none on the target, unlimited queries. The decision is made in `src/instance/providerSignInGate.ts`, before Better Auth branches, so the two codes that used to answer it are never produced. The true reason goes to the audit trail, where an operator can read it and a browser cannot.
|
|
56
56
|
|
|
57
|
-
So: **do not "improve" this by matching more addresses, and do not make the refusal more helpful.** An address is not a credential — a provider hands over whatever primary happens to be set, chosen years ago for unrelated reasons — and every sentence that separates "you have no account here" from "you have one and this provider is not attached to it" is the oracle back. The remedy for a refused sign-in is the same either way: sign in with a magic link, then connect the provider from the account. Linking from inside the account is a different flow with both sides already proven, and it
|
|
57
|
+
So: **do not "improve" this by matching more addresses, and do not make the refusal more helpful.** An address is not a credential — a provider hands over whatever primary happens to be set, chosen years ago for unrelated reasons — and every sentence that separates "you have no account here" from "you have one and this provider is not attached to it" is the oracle back. The remedy for a refused sign-in is the same either way: sign in with a magic link, then connect the provider from the account. Linking from inside the account is a different flow with both sides already proven, and it may attach a provider whose address differs from the account's. It may not attach one whose address that provider never verified: outside the trusted providers, Better Auth refuses the link. For Microsoft an address that matches the account's counts as verified, so only a different, unverified one is refused.
|
|
58
|
+
|
|
59
|
+
**Microsoft reaches row 3 more than any other provider, on purpose.** Entra ID cannot vouch for an email it did not verify: its `email` is a directory attribute a tenant admin sets to anything. So a Microsoft address is verified only by the `xms_edov` claim, the personal-accounts tenant, or — connecting from inside the account — matching the address the account already holds. `src/instance/microsoftEmail.ts` is the rule and `docs/microsoft-oauth.md` is the setup.
|
|
60
|
+
|
|
61
|
+
## Account lifecycle
|
|
62
|
+
|
|
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.
|
|
58
64
|
|
|
59
65
|
## Server-authoritative writes
|
|
60
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
|
@@ -147,6 +147,46 @@ export declare const AuthAuditActions: {
|
|
|
147
147
|
readonly adminUserSessionsRevoked: "auth/admin_user_sessions_revoked";
|
|
148
148
|
/** One of a user's devices was signed out and its registration dropped, from the management surface. */
|
|
149
149
|
readonly adminDeviceRevoked: "auth/admin_device_revoked";
|
|
150
|
+
/**
|
|
151
|
+
* The account lifecycle (#620). Each is written by the transition in `../lifecycle/transitions.ts`, beside
|
|
152
|
+
* the `pithy_auth_user_lifecycle` row that records the same fact — the trail answers "who, from where", the
|
|
153
|
+
* table answers "what happened to this account". The admin ones carry `actorType: "control-plane"`; the
|
|
154
|
+
* self-service deletion carries the account's own holder, and the purge `system`.
|
|
155
|
+
*
|
|
156
|
+
* The dashboard's own `customer/user_suspended` and `customer/user_restored` are the client side of the
|
|
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.
|
|
164
|
+
*/
|
|
165
|
+
/** An account was suspended from the management surface. Carries the reason and any end date. */
|
|
166
|
+
readonly adminUserSuspended: "auth/admin_user_suspended";
|
|
167
|
+
/** A suspended account was reinstated from the management surface. */
|
|
168
|
+
readonly adminUserReinstated: "auth/admin_user_reinstated";
|
|
169
|
+
/** An account was deleted from the management surface, with its purge window starting now. */
|
|
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";
|
|
177
|
+
/** A deleted account was restored inside its purge window, from the management surface. */
|
|
178
|
+
readonly adminUserRestored: "auth/admin_user_restored";
|
|
179
|
+
/** A deleted account's data was erased. Recorded once, when the last purge step has run. */
|
|
180
|
+
readonly adminUserPurged: "auth/admin_user_purged";
|
|
181
|
+
/** The account's own holder deleted their account. Always a soft deletion, on the configured window. */
|
|
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";
|
|
150
190
|
};
|
|
151
191
|
/** One of the auth audit action codes. */
|
|
152
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;;;;;;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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;;;;;;;;;;;;;;OAcG;IAEH,iGAAiG;aACjG,kBAAkB,EAAE,2BAA2B;IAC/C,sEAAsE;aACtE,mBAAmB,EAAE,4BAA4B;IACjD,8FAA8F;aAC9F,oBAAoB,EAAE,8BAA8B;IACpD;;;;OAIG;aACH,oBAAoB,EAAE,8BAA8B;IACpD,2FAA2F;aAC3F,iBAAiB,EAAE,0BAA0B;IAC7C,4FAA4F;aAC5F,eAAe,EAAE,wBAAwB;IACzC,wGAAwG;aACxG,eAAe,EAAE,wBAAwB;IACzC;;;;;OAKG;aACH,iBAAiB,EAAE,0BAA0B;CACrC,CAAC;AAEX,0CAA0C;AAC1C,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,OAAO,gBAAgB,CAAC,CAAC"}
|
package/dist/audit/actions.js
CHANGED
|
@@ -147,7 +147,47 @@ const AuthAuditActions = {
|
|
|
147
147
|
/** Every session a user held was revoked from the management surface — signed out everywhere. */
|
|
148
148
|
adminUserSessionsRevoked: "auth/admin_user_sessions_revoked",
|
|
149
149
|
/** One of a user's devices was signed out and its registration dropped, from the management surface. */
|
|
150
|
-
adminDeviceRevoked: "auth/admin_device_revoked"
|
|
150
|
+
adminDeviceRevoked: "auth/admin_device_revoked",
|
|
151
|
+
/**
|
|
152
|
+
* The account lifecycle (#620). Each is written by the transition in `../lifecycle/transitions.ts`, beside
|
|
153
|
+
* the `pithy_auth_user_lifecycle` row that records the same fact — the trail answers "who, from where", the
|
|
154
|
+
* table answers "what happened to this account". The admin ones carry `actorType: "control-plane"`; the
|
|
155
|
+
* self-service deletion carries the account's own holder, and the purge `system`.
|
|
156
|
+
*
|
|
157
|
+
* The dashboard's own `customer/user_suspended` and `customer/user_restored` are the client side of the
|
|
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.
|
|
165
|
+
*/
|
|
166
|
+
/** An account was suspended from the management surface. Carries the reason and any end date. */
|
|
167
|
+
adminUserSuspended: "auth/admin_user_suspended",
|
|
168
|
+
/** A suspended account was reinstated from the management surface. */
|
|
169
|
+
adminUserReinstated: "auth/admin_user_reinstated",
|
|
170
|
+
/** An account was deleted from the management surface, with its purge window starting now. */
|
|
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",
|
|
178
|
+
/** A deleted account was restored inside its purge window, from the management surface. */
|
|
179
|
+
adminUserRestored: "auth/admin_user_restored",
|
|
180
|
+
/** A deleted account's data was erased. Recorded once, when the last purge step has run. */
|
|
181
|
+
adminUserPurged: "auth/admin_user_purged",
|
|
182
|
+
/** The account's own holder deleted their account. Always a soft deletion, on the configured window. */
|
|
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"
|
|
151
191
|
};
|
|
152
192
|
//#endregion
|
|
153
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,C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E,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,
|
|
@@ -307,7 +307,7 @@ async function emitProviderUnavailable(emit, context) {
|
|
|
307
307
|
const ProviderAccount = z.object({
|
|
308
308
|
id: z.string().describe("The account row's primary key — which link was made or broken."),
|
|
309
309
|
userId: z.string().describe("The user this provider can, or could, sign in as."),
|
|
310
|
-
providerId: z.string().describe("The provider slug (`google`, `apple`, `facebook`, `github`).")
|
|
310
|
+
providerId: z.string().describe("The provider slug (`google`, `apple`, `facebook`, `github`, `microsoft`).")
|
|
311
311
|
}).describe("The account-row columns `auth/oauth_linked` and `auth/oauth_unlinked` are built from.");
|
|
312
312
|
/**
|
|
313
313
|
* Better Auth's provider id for a password row. Pithy is passwordless, so one should never exist here —
|
package/dist/capability.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
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";
|
|
8
10
|
import { z } from "zod";
|
|
9
11
|
import type { GithubUserInfoResolver } from "./instance/githubUserInfo";
|
|
12
|
+
import type { UserLifecycleHooks } from "./lifecycle/hooks";
|
|
10
13
|
import { type AuthPeer } from "./peer";
|
|
11
14
|
/** The auth capability's configuration — the thin surface an adopter owns in `pithy.config.ts`. */
|
|
12
15
|
export declare const AuthConfig: z.ZodObject<{
|
|
@@ -31,12 +34,26 @@ export declare const AuthConfig: z.ZodObject<{
|
|
|
31
34
|
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
32
35
|
allowSignUp: z.ZodDefault<z.ZodBoolean>;
|
|
33
36
|
}, z.core.$strip>>;
|
|
37
|
+
microsoft: z.ZodPrefault<z.ZodObject<{
|
|
38
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
39
|
+
allowSignUp: z.ZodDefault<z.ZodBoolean>;
|
|
40
|
+
}, z.core.$strip>>;
|
|
34
41
|
sessionExpiresIn: z.ZodDefault<z.ZodNumber>;
|
|
35
42
|
sessionUpdateAge: z.ZodDefault<z.ZodNumber>;
|
|
36
43
|
sessionSecretRotateEveryDays: z.ZodOptional<z.ZodNumber>;
|
|
37
44
|
verificationExpiresIn: z.ZodDefault<z.ZodNumber>;
|
|
38
45
|
otpLength: z.ZodDefault<z.ZodNumber>;
|
|
39
46
|
disableSignUp: z.ZodDefault<z.ZodBoolean>;
|
|
47
|
+
retention: z.ZodPrefault<z.ZodObject<{
|
|
48
|
+
purgeAfterDays: z.ZodDefault<z.ZodNumber>;
|
|
49
|
+
restoreUrl: z.ZodOptional<z.ZodURL>;
|
|
50
|
+
}, z.core.$strip>>;
|
|
51
|
+
lifecycleEmails: z.ZodPrefault<z.ZodObject<{
|
|
52
|
+
accountSuspended: z.ZodDefault<z.ZodBoolean>;
|
|
53
|
+
accountReinstated: z.ZodDefault<z.ZodBoolean>;
|
|
54
|
+
deletionScheduled: z.ZodDefault<z.ZodBoolean>;
|
|
55
|
+
deletionComplete: z.ZodDefault<z.ZodBoolean>;
|
|
56
|
+
}, z.core.$strip>>;
|
|
40
57
|
plugins: z.ZodDefault<z.ZodArray<z.ZodCustom<import("better-auth").BetterAuthPlugin, import("better-auth").BetterAuthPlugin>>>;
|
|
41
58
|
}, z.core.$strip>;
|
|
42
59
|
export type AuthConfig = z.output<typeof AuthConfig>;
|
|
@@ -69,6 +86,18 @@ export interface AuthWiring {
|
|
|
69
86
|
* Optional on the wiring for the reason `onSessionRevoked` is: no resolver is the ordinary composition.
|
|
70
87
|
*/
|
|
71
88
|
resolveScopes?: ScopeResolver | undefined;
|
|
89
|
+
/**
|
|
90
|
+
* The adopter's lifecycle hooks, or absent. See {@link UserLifecycleHooks}.
|
|
91
|
+
*
|
|
92
|
+
* Optional on the wiring for the reason `onSessionRevoked` is: no hook is the ordinary composition.
|
|
93
|
+
*/
|
|
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;
|
|
72
101
|
}
|
|
73
102
|
/** The session a {@link ScopeResolver} is asked about — the one Better Auth just resolved for this request. */
|
|
74
103
|
export interface ScopeResolverSession {
|
|
@@ -106,7 +135,7 @@ export type SessionRevokedListener = (session: {
|
|
|
106
135
|
* `PaymentsOptions`: everything describable stays in {@link AuthConfig}, and a resolver is a sibling key
|
|
107
136
|
* destructured off before the parse.
|
|
108
137
|
*/
|
|
109
|
-
export type AuthOptions = AuthConfigInput & {
|
|
138
|
+
export type AuthOptions = AuthConfigInput & UserLifecycleHooks & {
|
|
110
139
|
/**
|
|
111
140
|
* Resolve a GitHub identity yourself, replacing the kit's primary-only rule.
|
|
112
141
|
*
|
|
@@ -161,6 +190,21 @@ export type AuthOptions = AuthConfigInput & {
|
|
|
161
190
|
/** The auth capability, with its resolved config attached for inspection. */
|
|
162
191
|
export interface AuthCapability extends Capability {
|
|
163
192
|
authConfig: AuthConfig;
|
|
193
|
+
/**
|
|
194
|
+
* The adopter's account-lifecycle hooks, as `auth()` was handed them. Read by whatever runs a transition
|
|
195
|
+
* outside a request this capability serves — the purge Workflow (#622) fires `onUserPurged` through it.
|
|
196
|
+
*/
|
|
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;
|
|
164
208
|
/**
|
|
165
209
|
* What a capability composed beside this one reads an account through — `matchmaking`, `support`,
|
|
166
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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G;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";
|
|
@@ -48,12 +52,23 @@ const AuthConfig = z.object({
|
|
|
48
52
|
apple: ProviderToggle.prefault({}).describe("Apple Sign-In. Enable it, then store credentials as the `auth-apple-credentials` secret. See docs/apple-signin.md."),
|
|
49
53
|
facebook: ProviderToggle.prefault({}).describe("Facebook Login. Enable it, then store credentials as the `auth-facebook-credentials` secret. See docs/facebook-oauth.md."),
|
|
50
54
|
github: ProviderToggle.prefault({}).describe("GitHub OAuth. Enable it, then store credentials as the `auth-github-credentials` secret. See docs/github-oauth.md."),
|
|
55
|
+
microsoft: ProviderToggle.prefault({}).describe("Microsoft sign-in — work, school, or personal accounts through Entra ID. Enable it, then store credentials and the tenant as the `auth-microsoft-credentials` secret. Entra ID cannot vouch for an email it did not verify, so an unverified one is verified by magic link before it links. See docs/microsoft-oauth.md."),
|
|
51
56
|
sessionExpiresIn: z.number().int().default(604800).describe("Session (refresh credential) lifetime in seconds. Defaults to 7 days. Expiry slides forward on use."),
|
|
52
57
|
sessionUpdateAge: z.number().int().default(86400).describe("How often (seconds) an active session's expiry slides forward. Defaults to 1 day."),
|
|
53
58
|
sessionSecretRotateEveryDays: z.number().int().positive().optional().describe("How often, in days, the secrets manager rotates `auth-session-secret` by itself. Unset by default, so nothing rotates it unattended. The previous version keeps verifying for the session lifetime, so nobody is signed out, and is retired once the JWKS keys sealed under it are re-encrypted. Must be longer than `sessionExpiresIn`."),
|
|
54
59
|
verificationExpiresIn: z.number().int().default(300).describe("Magic-link and OTP lifetime in seconds. Defaults to 5 minutes. Single-use regardless."),
|
|
55
60
|
otpLength: z.number().int().default(6).describe("The number of digits in an email OTP. Defaults to 6."),
|
|
56
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)."),
|
|
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."),
|
|
66
|
+
lifecycleEmails: z.object({
|
|
67
|
+
accountSuspended: z.boolean().default(true).describe("Email the person when their account is suspended, with the reason and any end date."),
|
|
68
|
+
accountReinstated: z.boolean().default(true).describe("Email the person when a suspension is lifted."),
|
|
69
|
+
deletionScheduled: z.boolean().default(true).describe("Email the person when their account is deleted, with the date its data will be erased."),
|
|
70
|
+
deletionComplete: z.boolean().default(true).describe("Email the person once their data has been erased. Sent before the address is.")
|
|
71
|
+
}).prefault({}).describe("Which account-lifecycle emails are sent. All four send by default, through `@pithy-sh/email`; switch one off by setting it to false."),
|
|
57
72
|
plugins: z.array(AuthPlugin).default([]).describe("Additional Better Auth plugins to compose — `organization()`, `passkey()`, `twoFactor()`, `apiKey()`, a generic OAuth provider. Additive: they join the set the kit composes (i18n, bearer, jwt, magic-link, email-otp) and cannot replace one. Tables a plugin declares are created by `pithy migrate`; add the matching client plugin to `createAuthClient` for its typed client surface.")
|
|
58
73
|
}).describe("Configuration for the auth capability.");
|
|
59
74
|
/**
|
|
@@ -87,8 +102,14 @@ function assertPluginTablesUnclaimed(capabilities, binding, extensions) {
|
|
|
87
102
|
* and emits `auth/*` through `audit` when those are composed.
|
|
88
103
|
*/
|
|
89
104
|
function auth(options) {
|
|
90
|
-
const { resolveGithubUserInfo, onSessionRevoked, resolveScopes, ...config } = options;
|
|
105
|
+
const { resolveGithubUserInfo, onSessionRevoked, resolveScopes, onUserSuspended, onUserReinstated, onUserDeleted, onUserPurged, ...config } = options;
|
|
91
106
|
const resolved = AuthConfig.parse(config);
|
|
107
|
+
const lifecycleHooks = {
|
|
108
|
+
...onUserSuspended ? { onUserSuspended } : {},
|
|
109
|
+
...onUserReinstated ? { onUserReinstated } : {},
|
|
110
|
+
...onUserDeleted ? { onUserDeleted } : {},
|
|
111
|
+
...onUserPurged ? { onUserPurged } : {}
|
|
112
|
+
};
|
|
92
113
|
assertAdditivePlugins(resolved.plugins);
|
|
93
114
|
const pluginPlan = authPluginPlan(resolved.plugins);
|
|
94
115
|
const wiring = {
|
|
@@ -97,8 +118,13 @@ function auth(options) {
|
|
|
97
118
|
enqueueEmail: void 0,
|
|
98
119
|
turnstile: void 0,
|
|
99
120
|
onSessionRevoked,
|
|
100
|
-
resolveScopes
|
|
121
|
+
resolveScopes,
|
|
122
|
+
lifecycleHooks,
|
|
123
|
+
purgeSteps: []
|
|
101
124
|
};
|
|
125
|
+
const steps = [];
|
|
126
|
+
wiring.purgeSteps = steps;
|
|
127
|
+
let composition = [];
|
|
102
128
|
const rateLimitMiddleware = (app) => {
|
|
103
129
|
app.use(`${resolved.basePath}/*`, createRateLimitMiddleware(resolved.rateLimiterBinding));
|
|
104
130
|
};
|
|
@@ -132,6 +158,8 @@ function auth(options) {
|
|
|
132
158
|
...pluginPlan.migrations
|
|
133
159
|
}
|
|
134
160
|
} },
|
|
161
|
+
purge: [authPurgeContribution(resolved.database, pluginPlan.userTables)],
|
|
162
|
+
workflows: authWorkflows,
|
|
135
163
|
compose: ({ capabilities }) => {
|
|
136
164
|
const email = capabilities.find(isEmailCapability);
|
|
137
165
|
if (!email) throw new ValidationError({
|
|
@@ -142,6 +170,8 @@ function auth(options) {
|
|
|
142
170
|
const loginMode = capabilities.find(isTurnstileCapability)?.turnstileConfig.protect[TURNSTILE_LOGIN_ACTION];
|
|
143
171
|
wiring.turnstile = loginMode ? { mode: loginMode } : void 0;
|
|
144
172
|
assertPluginTablesUnclaimed(capabilities, resolved.database, pluginPlan.extensions);
|
|
173
|
+
steps.splice(0, steps.length, ...purgeSteps(capabilities, "user"));
|
|
174
|
+
composition = capabilities;
|
|
145
175
|
},
|
|
146
176
|
/**
|
|
147
177
|
* The client-safe projection — what a sign-in screen needs and nothing more: where to call
|
|
@@ -166,13 +196,15 @@ function auth(options) {
|
|
|
166
196
|
google: resolved.google.enabled,
|
|
167
197
|
apple: resolved.apple.enabled,
|
|
168
198
|
facebook: resolved.facebook.enabled,
|
|
169
|
-
github: resolved.github.enabled
|
|
199
|
+
github: resolved.github.enabled,
|
|
200
|
+
microsoft: resolved.microsoft.enabled
|
|
170
201
|
},
|
|
171
202
|
providerSignUp: {
|
|
172
203
|
google: resolved.google.allowSignUp,
|
|
173
204
|
apple: resolved.apple.allowSignUp,
|
|
174
205
|
facebook: resolved.facebook.allowSignUp,
|
|
175
|
-
github: resolved.github.allowSignUp
|
|
206
|
+
github: resolved.github.allowSignUp,
|
|
207
|
+
microsoft: resolved.microsoft.allowSignUp
|
|
176
208
|
},
|
|
177
209
|
otpLength: resolved.otpLength,
|
|
178
210
|
signUpEnabled: !resolved.disableSignUp
|
|
@@ -191,7 +223,10 @@ function auth(options) {
|
|
|
191
223
|
});
|
|
192
224
|
return Object.assign(capability, {
|
|
193
225
|
authConfig: resolved,
|
|
194
|
-
authPeer
|
|
226
|
+
authPeer,
|
|
227
|
+
lifecycleHooks,
|
|
228
|
+
purgeSteps: steps,
|
|
229
|
+
auditFor: (env) => composedAuditEmit(composition, env)
|
|
195
230
|
});
|
|
196
231
|
}
|
|
197
232
|
/** Type guard: is this capability the auth capability? */
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
/**
|
|
4
|
+
* The two codes a refused account comes back with, for a screen to branch on (#620).
|
|
5
|
+
*
|
|
6
|
+
* **Imported rather than spelled**, for the reason the sign-in screen imports `NEUTRAL_PROVIDER_REFUSAL`: a
|
|
7
|
+
* literal in a copied screen and a literal in the Worker are a pair that can drift, and the drift shows as a
|
|
8
|
+
* locked-out person landing on a sign-in form that says nothing. The type ties each to the kit's taxonomy, so
|
|
9
|
+
* a rename there is a compile error here.
|
|
10
|
+
*
|
|
11
|
+
* Either arrives as a `PithyError` body's `code` from a JSON call, or as `?error=` on the screen a magic link
|
|
12
|
+
* or a social sign-in returned to.
|
|
13
|
+
*/
|
|
14
|
+
export declare const ACCOUNT_SUSPENDED = "auth/account_suspended";
|
|
15
|
+
/** The code for an account inside its purge window. See {@link ACCOUNT_SUSPENDED}. */
|
|
16
|
+
export declare const ACCOUNT_DELETED = "auth/account_deleted";
|
|
17
|
+
/** Which of the two a code is, or `null` for anything else — a refusal a screen should not reroute. */
|
|
18
|
+
export declare function accountRefusal(code: string | null | undefined): "suspended" | "deleted" | null;
|
|
19
|
+
//# sourceMappingURL=lifecycle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../../src/client/lifecycle.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,2BAAkD,CAAC;AAEjF,sFAAsF;AACtF,eAAO,MAAM,eAAe,yBAAgD,CAAC;AAE7E,uGAAuG;AACvG,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,IAAI,CAI9F"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
//#region src/client/lifecycle.ts
|
|
4
|
+
/**
|
|
5
|
+
* The two codes a refused account comes back with, for a screen to branch on (#620).
|
|
6
|
+
*
|
|
7
|
+
* **Imported rather than spelled**, for the reason the sign-in screen imports `NEUTRAL_PROVIDER_REFUSAL`: a
|
|
8
|
+
* literal in a copied screen and a literal in the Worker are a pair that can drift, and the drift shows as a
|
|
9
|
+
* locked-out person landing on a sign-in form that says nothing. The type ties each to the kit's taxonomy, so
|
|
10
|
+
* a rename there is a compile error here.
|
|
11
|
+
*
|
|
12
|
+
* Either arrives as a `PithyError` body's `code` from a JSON call, or as `?error=` on the screen a magic link
|
|
13
|
+
* or a social sign-in returned to.
|
|
14
|
+
*/
|
|
15
|
+
const ACCOUNT_SUSPENDED = "auth/account_suspended";
|
|
16
|
+
/** The code for an account inside its purge window. See {@link ACCOUNT_SUSPENDED}. */
|
|
17
|
+
const ACCOUNT_DELETED = "auth/account_deleted";
|
|
18
|
+
/** Which of the two a code is, or `null` for anything else — a refusal a screen should not reroute. */
|
|
19
|
+
function accountRefusal(code) {
|
|
20
|
+
if (code === "auth/account_suspended") return "suspended";
|
|
21
|
+
if (code === "auth/account_deleted") return "deleted";
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { ACCOUNT_DELETED, ACCOUNT_SUSPENDED, accountRefusal };
|
|
@@ -44,6 +44,8 @@ export type AuthClientProjection = {
|
|
|
44
44
|
facebook: boolean;
|
|
45
45
|
/** Whether Sign in with GitHub is offered. */
|
|
46
46
|
github: boolean;
|
|
47
|
+
/** Whether Sign in with Microsoft is offered. */
|
|
48
|
+
microsoft: boolean;
|
|
47
49
|
};
|
|
48
50
|
/**
|
|
49
51
|
* Whether each offered provider may create an account, from its `allowSignUp` toggle.
|
|
@@ -66,6 +68,8 @@ export type AuthClientProjection = {
|
|
|
66
68
|
facebook: boolean;
|
|
67
69
|
/** Whether a GitHub sign-in may create an account. */
|
|
68
70
|
github: boolean;
|
|
71
|
+
/** Whether a Microsoft sign-in may create an account. */
|
|
72
|
+
microsoft: boolean;
|
|
69
73
|
};
|
|
70
74
|
/** How many digits an email OTP carries. */
|
|
71
75
|
otpLength: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projection.d.ts","sourceRoot":"","sources":["../../src/client/projection.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,oBAAoB,GAC5B;IACE,mGAAmG;IACnG,OAAO,EAAE,KAAK,CAAC;CAChB,GACD;IACE,uCAAuC;IACvC,OAAO,EAAE,IAAI,CAAC;IACd,4DAA4D;IAC5D,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;;;;OAOG;IACH,SAAS,EAAE;QACT,8CAA8C;QAC9C,MAAM,EAAE,OAAO,CAAC;QAChB,6CAA6C;QAC7C,KAAK,EAAE,OAAO,CAAC;QACf,gDAAgD;QAChD,QAAQ,EAAE,OAAO,CAAC;QAClB,8CAA8C;QAC9C,MAAM,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"projection.d.ts","sourceRoot":"","sources":["../../src/client/projection.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,oBAAoB,GAC5B;IACE,mGAAmG;IACnG,OAAO,EAAE,KAAK,CAAC;CAChB,GACD;IACE,uCAAuC;IACvC,OAAO,EAAE,IAAI,CAAC;IACd,4DAA4D;IAC5D,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;;;;OAOG;IACH,SAAS,EAAE;QACT,8CAA8C;QAC9C,MAAM,EAAE,OAAO,CAAC;QAChB,6CAA6C;QAC7C,KAAK,EAAE,OAAO,CAAC;QACf,gDAAgD;QAChD,QAAQ,EAAE,OAAO,CAAC;QAClB,8CAA8C;QAC9C,MAAM,EAAE,OAAO,CAAC;QAChB,iDAAiD;QACjD,SAAS,EAAE,OAAO,CAAC;KACpB,CAAC;IACF;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE;QACf,sDAAsD;QACtD,MAAM,EAAE,OAAO,CAAC;QAChB,sDAAsD;QACtD,KAAK,EAAE,OAAO,CAAC;QACf,wDAAwD;QACxD,QAAQ,EAAE,OAAO,CAAC;QAClB,sDAAsD;QACtD,MAAM,EAAE,OAAO,CAAC;QAChB,yDAAyD;QACzD,SAAS,EAAE,OAAO,CAAC;KACpB,CAAC;IACF,4CAA4C;IAC5C,SAAS,EAAE,MAAM,CAAC;IAClB,4EAA4E;IAC5E,aAAa,EAAE,OAAO,CAAC;CACxB,CAAC"}
|
|
@@ -11,6 +11,10 @@ export declare const User: z.ZodObject<{
|
|
|
11
11
|
locale: z.ZodNullable<z.ZodString>;
|
|
12
12
|
createdAt: z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>;
|
|
13
13
|
updatedAt: z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>;
|
|
14
|
+
suspendedAt: z.ZodOptional<z.ZodNullable<z.ZodCodec<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodDate]>, z.ZodDate>>>;
|
|
15
|
+
suspendedUntil: z.ZodOptional<z.ZodNullable<z.ZodCodec<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodDate]>, z.ZodDate>>>;
|
|
16
|
+
deletedAt: z.ZodOptional<z.ZodNullable<z.ZodCodec<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodDate]>, z.ZodDate>>>;
|
|
17
|
+
purgeAfter: z.ZodOptional<z.ZodNullable<z.ZodCodec<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodDate]>, z.ZodDate>>>;
|
|
14
18
|
}, z.core.$strip>;
|
|
15
19
|
export type User = z.output<typeof User>;
|
|
16
20
|
/** `pithy_auth_sessions` — one active session (the long-lived, bearer/cookie credential). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"betterAuth.d.ts","sourceRoot":"","sources":["../../src/data/betterAuth.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAuBxB,2FAA2F;AAC3F,eAAO,MAAM,IAAI
|
|
1
|
+
{"version":3,"file":"betterAuth.d.ts","sourceRoot":"","sources":["../../src/data/betterAuth.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAuBxB,2FAA2F;AAC3F,eAAO,MAAM,IAAI;;;;;;;;;;;;;iBA8CwF,CAAC;AAC1G,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,CAAC;AAEzC,6FAA6F;AAC7F,eAAO,MAAM,OAAO;;;;;;;;;;;;iBAqCqF,CAAC;AAC1G,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,OAAO,CAAC,CAAC;AAE/C,mGAAmG;AACnG,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;iBA0CqF,CAAC;AAC1G,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,OAAO,CAAC,CAAC;AAE/C,8FAA8F;AAC9F,eAAO,MAAM,YAAY;;;;;;;iBAmBtB,CAAC;AACJ,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,YAAY,CAAC,CAAC;AAEzD,gGAAgG;AAChG,eAAO,MAAM,IAAI;;;;;;;;iBA8Bd,CAAC;AACJ,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,CAAC;AAEzC,sHAAsH;AACtH,eAAO,MAAM,SAAS;;;;;iBAcnB,CAAC;AACJ,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,SAAS,CAAC,CAAC"}
|
package/dist/data/betterAuth.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
import { JsonDate, SQLiteBoolean } from "@pithy-sh/core/src/data/codecs";
|
|
4
|
+
import { JsonDate, SQLiteBoolean, SQLiteDate } from "@pithy-sh/core/src/data/codecs";
|
|
5
5
|
import { Locale } from "@pithy-sh/core/src/i18n/locale";
|
|
6
6
|
//#region src/data/betterAuth.ts
|
|
7
7
|
/**
|
|
@@ -32,7 +32,11 @@ const User = z.object({
|
|
|
32
32
|
image: z.string().nullable().describe("The user's picture: a URL on the provider that signed them in, or bytes this application stores as a bounded `data:` URL — see `../profile/profile.ts` for why the column takes two shapes. Null when nobody has set one, and then a caller draws initials, which is a real answer and not a placeholder.\n\n**Permissive here and strict on the write, exactly as `name` is, and the asymmetry is the point.** `UserImage` runs at the database hook, so nothing this kit writes can put an unacceptable value in the column. What this schema decodes is what is *already there* — a row a provider wrote before the rule existed, a repair script, a restored backup. A strict column turns one such row into a `ZodError` on every read that touches it, and `getUsers` parses a page of rows at once: one poisoned row would take down the whole roster for every operator rather than drawing one gap. That is the failure mode `./kitFields.ts` records for `locale`, and it is worse here, because a roster is read by people who did not write the row.\n\nThe value is made safe on the way **out** instead. `userImageSource` answers null for anything the rule does not recognize, so an unrecognized value renders as initials; and the serving route refuses to hand out bytes it cannot type."),
|
|
33
33
|
locale: Locale.nullable().describe("The reader's chosen language as a BCP-47 tag, or null when they have never chosen. Null is not the default locale: it means negotiate from `Accept-Language`, so an unchosen reader follows their device. A stored tag outranks the header."),
|
|
34
34
|
createdAt: BetterAuthDate.describe("When the user record was created. ISO-8601 text in SQLite; a `Date` in app code."),
|
|
35
|
-
updatedAt: BetterAuthDate.describe("When the user record was last updated. ISO-8601 text in SQLite; a `Date` in app code.")
|
|
35
|
+
updatedAt: BetterAuthDate.describe("When the user record was last updated. ISO-8601 text in SQLite; a `Date` in app code."),
|
|
36
|
+
suspendedAt: SQLiteDate.nullish().describe("When this account was suspended, or null when it is not. A suspended account cannot sign in, refresh a token, or act on any route. Ms-epoch in SQLite; a `Date` in app code."),
|
|
37
|
+
suspendedUntil: SQLiteDate.nullish().describe("When the current suspension ends by itself, or null for one that lasts until an operator reinstates the account. A suspension past this instant is treated as absent, with no write needed to expire it. Ms-epoch in SQLite."),
|
|
38
|
+
deletedAt: SQLiteDate.nullish().describe("When this account was deleted, or null when it is not. A deleted account cannot sign in or act, and can be restored until `purgeAfter`. Ms-epoch in SQLite."),
|
|
39
|
+
purgeAfter: SQLiteDate.nullish().describe("When a deleted account's data may be erased — the deletion instant plus `retention.purgeAfterDays`. Null unless the account is deleted. Ms-epoch in SQLite.")
|
|
36
40
|
}).describe("A user in `pithy_auth_users` — the canonical identity every session and account hangs off.");
|
|
37
41
|
/** `pithy_auth_sessions` — one active session (the long-lived, bearer/cookie credential). */
|
|
38
42
|
const Session = z.object({
|
package/dist/data/kitFields.d.ts
CHANGED
|
@@ -1,30 +1,5 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
|
-
/**
|
|
4
|
-
* The columns Pithy adds to Better Auth's own tables, declared **once**.
|
|
5
|
-
*
|
|
6
|
-
* Better Auth owns every read and write to `pithy_auth_users` and `pithy_auth_sessions` through its
|
|
7
|
-
* Kysely adapter, and it writes only the fields its options declare. So a column that exists in the
|
|
8
|
-
* migration and in the `User` Zod object and *not* here is null forever and absent from every user
|
|
9
|
-
* object the instance returns — a migration and a schema field that silently did nothing.
|
|
10
|
-
*
|
|
11
|
-
* ## Why one module rather than two agreeing declarations
|
|
12
|
-
*
|
|
13
|
-
* These have to appear in two places: `makeAuth`'s live options (`../instance/auth.ts`) and the
|
|
14
|
-
* schema baseline `pluginSchemaDelta` subtracts each adopter plugin's schema from
|
|
15
|
-
* (`../migrations/pluginTables.ts`). Both were written out by hand, with a comment in each saying it
|
|
16
|
-
* "must match" the other and a test claiming to hold them together. The test did not: it compared the
|
|
17
|
-
* baseline against the `User` schema and never imported `makeAuth` at all, so reverting the live
|
|
18
|
-
* declaration left the whole suite green while Better Auth silently stopped writing the column (#441).
|
|
19
|
-
*
|
|
20
|
-
* `docs/CONVENTIONS.md` is explicit that removing an invariant beats watching it. There is one object
|
|
21
|
-
* now, imported by both, and the two cannot disagree because there is no second thing to disagree
|
|
22
|
-
* with. That is also why the consequence is worth restating rather than diluting: leave a kit column
|
|
23
|
-
* out of the baseline and `pluginSchemaDelta` reports it as something an adopter's plugin brought, so
|
|
24
|
-
* a plugin that also declares a user `locale` emits `ALTER TABLE … ADD COLUMN locale` against a table
|
|
25
|
-
* that already has one — a duplicate-column failure part-way through a migration D1 cannot roll back,
|
|
26
|
-
* because it has no transactional DDL.
|
|
27
|
-
*/
|
|
28
3
|
/**
|
|
29
4
|
* The extra `pithy_auth_users` columns.
|
|
30
5
|
*
|
|
@@ -49,6 +24,26 @@
|
|
|
49
24
|
* `updateUser({ locale: null })` answering 400 for the one state the schema calls ordinary.
|
|
50
25
|
*/
|
|
51
26
|
export declare const KIT_USER_FIELDS: {
|
|
27
|
+
readonly suspendedAt: {
|
|
28
|
+
readonly type: "number";
|
|
29
|
+
readonly required: false;
|
|
30
|
+
readonly input: false;
|
|
31
|
+
};
|
|
32
|
+
readonly suspendedUntil: {
|
|
33
|
+
readonly type: "number";
|
|
34
|
+
readonly required: false;
|
|
35
|
+
readonly input: false;
|
|
36
|
+
};
|
|
37
|
+
readonly deletedAt: {
|
|
38
|
+
readonly type: "number";
|
|
39
|
+
readonly required: false;
|
|
40
|
+
readonly input: false;
|
|
41
|
+
};
|
|
42
|
+
readonly purgeAfter: {
|
|
43
|
+
readonly type: "number";
|
|
44
|
+
readonly required: false;
|
|
45
|
+
readonly input: false;
|
|
46
|
+
};
|
|
52
47
|
readonly locale: {
|
|
53
48
|
readonly type: "string";
|
|
54
49
|
readonly required: false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kitFields.d.ts","sourceRoot":"","sources":["../../src/data/kitFields.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"kitFields.d.ts","sourceRoot":"","sources":["../../src/data/kitFields.ts"],"names":[],"mappings":"AAyDA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,eAAe;;iBA7BX,IAAI,EAAE,QAAQ;iBAAE,QAAQ;iBAAS,KAAK;;;iBACnC,IAAI,EAAE,QAAQ;iBAAE,QAAQ;iBAAS,KAAK;;;iBAC3C,IAAI,EAAE,QAAQ;iBAAE,QAAQ;iBAAS,KAAK;;;iBACrC,IAAI,EAAE,QAAQ;iBAAE,QAAQ;iBAAS,KAAK;;;iBA2B1C,IAAI,EAAE,QAAQ;iBAAE,QAAQ;iBAAS,KAAK;iBAAQ,SAAS;qBAAI,KAAK;;;CAElE,CAAC;AAEX;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,kBAAkB;aAC7B,QAAQ;iBAAI,IAAI,EAAE,QAAQ;iBAAE,QAAQ;iBAAS,KAAK;;aAClD,QAAQ;iBAAI,IAAI,EAAE,QAAQ;iBAAE,QAAQ;iBAAS,KAAK;;aAClD,eAAe;iBAAI,IAAI,EAAE,MAAM;iBAAE,QAAQ;iBAAS,KAAK;;CAC/C,CAAC"}
|