@pithy-sh/auth 0.9.0 → 0.10.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.
Files changed (125) hide show
  1. package/README.md +8 -2
  2. package/dist/audit/actions.d.ts +21 -0
  3. package/dist/audit/actions.d.ts.map +1 -1
  4. package/dist/audit/actions.js +22 -1
  5. package/dist/audit/emit.js +1 -1
  6. package/dist/capability.d.ts +26 -1
  7. package/dist/capability.d.ts.map +1 -1
  8. package/dist/capability.js +23 -5
  9. package/dist/client/lifecycle.d.ts +19 -0
  10. package/dist/client/lifecycle.d.ts.map +1 -0
  11. package/dist/client/lifecycle.js +25 -0
  12. package/dist/client/projection.d.ts +4 -0
  13. package/dist/client/projection.d.ts.map +1 -1
  14. package/dist/data/betterAuth.d.ts +4 -0
  15. package/dist/data/betterAuth.d.ts.map +1 -1
  16. package/dist/data/betterAuth.js +6 -2
  17. package/dist/data/kitFields.d.ts +20 -25
  18. package/dist/data/kitFields.d.ts.map +1 -1
  19. package/dist/data/kitFields.js +28 -32
  20. package/dist/data/tables.d.ts +28 -2
  21. package/dist/data/tables.d.ts.map +1 -1
  22. package/dist/data/tables.js +5 -3
  23. package/dist/data/userLifecycle.d.ts +61 -0
  24. package/dist/data/userLifecycle.d.ts.map +1 -0
  25. package/dist/data/userLifecycle.js +50 -0
  26. package/dist/http/guards.d.ts +23 -1
  27. package/dist/http/guards.d.ts.map +1 -1
  28. package/dist/http/guards.js +28 -3
  29. package/dist/http/lifecycleGate.d.ts +18 -0
  30. package/dist/http/lifecycleGate.d.ts.map +1 -0
  31. package/dist/http/lifecycleGate.js +75 -0
  32. package/dist/http/middleware.d.ts +5 -0
  33. package/dist/http/middleware.d.ts.map +1 -1
  34. package/dist/http/middleware.js +47 -6
  35. package/dist/http/providerRefusal.d.ts.map +1 -1
  36. package/dist/http/providerRefusal.js +8 -0
  37. package/dist/http/resolve.d.ts.map +1 -1
  38. package/dist/http/resolve.js +7 -4
  39. package/dist/http/routes.d.ts.map +1 -1
  40. package/dist/http/routes.js +20 -1
  41. package/dist/instance/auth.d.ts +55 -3
  42. package/dist/instance/auth.d.ts.map +1 -1
  43. package/dist/instance/auth.js +53 -2
  44. package/dist/instance/microsoftEmail.d.ts +70 -0
  45. package/dist/instance/microsoftEmail.d.ts.map +1 -0
  46. package/dist/instance/microsoftEmail.js +96 -0
  47. package/dist/instance/providerSignInGate.d.ts +7 -6
  48. package/dist/instance/providerSignInGate.d.ts.map +1 -1
  49. package/dist/instance/providerSignInGate.js +7 -6
  50. package/dist/instance/providers.d.ts +7 -5
  51. package/dist/instance/providers.d.ts.map +1 -1
  52. package/dist/instance/providers.js +5 -3
  53. package/dist/instance/secrets.d.ts +64 -3
  54. package/dist/instance/secrets.d.ts.map +1 -1
  55. package/dist/instance/secrets.js +44 -5
  56. package/dist/lifecycle/enforce.d.ts +40 -0
  57. package/dist/lifecycle/enforce.d.ts.map +1 -0
  58. package/dist/lifecycle/enforce.js +70 -0
  59. package/dist/lifecycle/hooks.d.ts +53 -0
  60. package/dist/lifecycle/hooks.d.ts.map +1 -0
  61. package/dist/lifecycle/hooks.js +2 -0
  62. package/dist/lifecycle/request.d.ts +15 -0
  63. package/dist/lifecycle/request.d.ts.map +1 -0
  64. package/dist/lifecycle/request.js +27 -0
  65. package/dist/lifecycle/state.d.ts +64 -0
  66. package/dist/lifecycle/state.d.ts.map +1 -0
  67. package/dist/lifecycle/state.js +90 -0
  68. package/dist/lifecycle/transitions.d.ts +132 -0
  69. package/dist/lifecycle/transitions.d.ts.map +1 -0
  70. package/dist/lifecycle/transitions.js +349 -0
  71. package/dist/migrations/0004_user_lifecycle.d.ts +28 -0
  72. package/dist/migrations/0004_user_lifecycle.d.ts.map +1 -0
  73. package/dist/migrations/0004_user_lifecycle.js +47 -0
  74. package/dist/migrations/set.d.ts +2 -1
  75. package/dist/migrations/set.d.ts.map +1 -1
  76. package/dist/migrations/set.js +4 -2
  77. package/dist/peer.d.ts +4 -0
  78. package/dist/peer.d.ts.map +1 -1
  79. package/dist/test-utils/liveApp.d.ts +21 -0
  80. package/dist/test-utils/liveApp.d.ts.map +1 -1
  81. package/dist/test-utils/liveApp.js +1 -0
  82. package/dist/test-utils/scopedBackend.d.ts +21 -0
  83. package/dist/test-utils/scopedBackend.d.ts.map +1 -1
  84. package/dist/test-utils/scopedBackend.js +7 -1
  85. package/dist/version.generated.d.ts +1 -1
  86. package/dist/version.generated.d.ts.map +1 -1
  87. package/dist/version.generated.js +1 -1
  88. package/docs/account-lifecycle.md +105 -0
  89. package/docs/apple-signin.md +7 -1
  90. package/docs/facebook-oauth.md +7 -1
  91. package/docs/github-oauth.md +7 -1
  92. package/docs/google-oauth.md +7 -1
  93. package/docs/microsoft-oauth.md +177 -0
  94. package/package.json +5 -5
  95. package/pithy.manifest.json +17 -3
  96. package/src/audit/actions.ts +23 -0
  97. package/src/audit/emit.ts +1 -1
  98. package/src/capability.ts +125 -54
  99. package/src/client/lifecycle.ts +27 -0
  100. package/src/client/projection.ts +4 -0
  101. package/src/data/betterAuth.ts +21 -1
  102. package/src/data/kitFields.ts +27 -0
  103. package/src/data/tables.ts +4 -2
  104. package/src/data/userLifecycle.ts +80 -0
  105. package/src/http/guards.ts +29 -1
  106. package/src/http/lifecycleGate.ts +78 -0
  107. package/src/http/middleware.ts +61 -2
  108. package/src/http/providerRefusal.ts +10 -0
  109. package/src/http/resolve.ts +8 -3
  110. package/src/http/routes.ts +38 -1
  111. package/src/instance/auth.ts +69 -2
  112. package/src/instance/microsoftEmail.ts +111 -0
  113. package/src/instance/providerSignInGate.ts +7 -6
  114. package/src/instance/providers.ts +8 -4
  115. package/src/instance/secrets.ts +59 -5
  116. package/src/lifecycle/enforce.ts +89 -0
  117. package/src/lifecycle/hooks.ts +54 -0
  118. package/src/lifecycle/request.ts +31 -0
  119. package/src/lifecycle/state.ts +101 -0
  120. package/src/lifecycle/transitions.ts +483 -0
  121. package/src/migrations/0004_user_lifecycle.ts +68 -0
  122. package/src/migrations/set.ts +3 -1
  123. package/src/test-utils/liveApp.ts +2 -1
  124. package/src/test-utils/scopedBackend.ts +2 -1
  125. 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 is deliberately unconstrained by the address.
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. Auth's own routes, sign-in and token refresh answer `auth/account_suspended` or `auth/account_deleted` (403); another capability's `requireAuth()` answers 401, and the client's next refresh gets the code. [`docs/account-lifecycle.md`](docs/account-lifecycle.md) has the two states, the record, the scopes, the mail, the hooks, the screens, and the purge contribution a capability declares for its own rows.
58
64
 
59
65
  ## Server-authoritative writes
60
66
 
@@ -147,6 +147,27 @@ 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
+ /** An account was suspended from the management surface. Carries the reason and any end date. */
160
+ readonly adminUserSuspended: "auth/admin_user_suspended";
161
+ /** A suspended account was reinstated from the management surface. */
162
+ readonly adminUserReinstated: "auth/admin_user_reinstated";
163
+ /** An account was deleted from the management surface, with its purge window starting now. */
164
+ readonly adminUserSoftDeleted: "auth/admin_user_soft_deleted";
165
+ /** A deleted account was restored inside its purge window, from the management surface. */
166
+ readonly adminUserRestored: "auth/admin_user_restored";
167
+ /** A deleted account's data was erased. Recorded once, when the last purge step has run. */
168
+ readonly adminUserPurged: "auth/admin_user_purged";
169
+ /** The account's own holder deleted their account. Always a soft deletion, on the configured window. */
170
+ readonly userSelfDeleted: "auth/user_self_deleted";
150
171
  };
151
172
  /** One of the auth audit action codes. */
152
173
  export type AuthAuditAction = (typeof AuthAuditActions)[keyof typeof AuthAuditActions];
@@ -1 +1 @@
1
- {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/audit/actions.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB;IAC3B,+FAA+F;aAC/F,MAAM,EAAE,aAAa;IACrB;;;;;;;;OAQG;aACH,OAAO,EAAE,cAAc;IACvB;;;;OAIG;aACH,YAAY,EAAE,oBAAoB;IAClC,sHAAsH;aACtH,kBAAkB,EAAE,2BAA2B;IAC/C;;;;;OAKG;aACH,aAAa,EAAE,sBAAsB;IACrC;;;;;;;;;;;;;;;;;;;;;;OAsBG;aACH,OAAO,EAAE,eAAe;IACxB;;;;;;;;;;;;;;;;OAgBG;aACH,WAAW,EAAE,mBAAmB;IAChC;;;;;;;;;;;;;;;;OAgBG;aACH,aAAa,EAAE,qBAAqB;IACpC,gEAAgE;aAChE,gBAAgB,EAAE,wBAAwB;IAC1C,wDAAwD;aACxD,aAAa,EAAE,qBAAqB;IACpC;;;;;;;;;;OAUG;aACH,mBAAmB,EAAE,2BAA2B;IAChD;;;;;;;;;;OAUG;aACH,eAAe,EAAE,wBAAwB;IAEzC;;;;;;;;;;OAUG;IAEH,wGAAwG;aACxG,gBAAgB,EAAE,yBAAyB;IAC3C,sFAAsF;aACtF,aAAa,EAAE,sBAAsB;IACrC,kEAAkE;aAClE,kBAAkB,EAAE,2BAA2B;IAC/C,iEAAiE;aACjE,mBAAmB,EAAE,4BAA4B;IACjD,iGAAiG;aACjG,wBAAwB,EAAE,kCAAkC;IAC5D,wGAAwG;aACxG,kBAAkB,EAAE,2BAA2B;CACvC,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AAE,8BAA8B;IACpD,2FAA2F;aAC3F,iBAAiB,EAAE,0BAA0B;IAC7C,4FAA4F;aAC5F,eAAe,EAAE,wBAAwB;IACzC,wGAAwG;aACxG,eAAe,EAAE,wBAAwB;CACjC,CAAC;AAEX,0CAA0C;AAC1C,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,OAAO,gBAAgB,CAAC,CAAC"}
@@ -147,7 +147,28 @@ 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
+ /** An account was suspended from the management surface. Carries the reason and any end date. */
161
+ adminUserSuspended: "auth/admin_user_suspended",
162
+ /** A suspended account was reinstated from the management surface. */
163
+ adminUserReinstated: "auth/admin_user_reinstated",
164
+ /** An account was deleted from the management surface, with its purge window starting now. */
165
+ adminUserSoftDeleted: "auth/admin_user_soft_deleted",
166
+ /** A deleted account was restored inside its purge window, from the management surface. */
167
+ adminUserRestored: "auth/admin_user_restored",
168
+ /** A deleted account's data was erased. Recorded once, when the last purge step has run. */
169
+ adminUserPurged: "auth/admin_user_purged",
170
+ /** The account's own holder deleted their account. Always a soft deletion, on the configured window. */
171
+ userSelfDeleted: "auth/user_self_deleted"
151
172
  };
152
173
  //#endregion
153
174
  export { AuthAuditActions };
@@ -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 —
@@ -7,6 +7,7 @@ import { type TurnstileMode } from "@pithy-sh/turnstile/src/config/config";
7
7
  import type { Context } from "hono";
8
8
  import { z } from "zod";
9
9
  import type { GithubUserInfoResolver } from "./instance/githubUserInfo";
10
+ import type { UserLifecycleHooks } from "./lifecycle/hooks";
10
11
  import { type AuthPeer } from "./peer";
11
12
  /** The auth capability's configuration — the thin surface an adopter owns in `pithy.config.ts`. */
12
13
  export declare const AuthConfig: z.ZodObject<{
@@ -31,12 +32,25 @@ export declare const AuthConfig: z.ZodObject<{
31
32
  enabled: z.ZodDefault<z.ZodBoolean>;
32
33
  allowSignUp: z.ZodDefault<z.ZodBoolean>;
33
34
  }, z.core.$strip>>;
35
+ microsoft: z.ZodPrefault<z.ZodObject<{
36
+ enabled: z.ZodDefault<z.ZodBoolean>;
37
+ allowSignUp: z.ZodDefault<z.ZodBoolean>;
38
+ }, z.core.$strip>>;
34
39
  sessionExpiresIn: z.ZodDefault<z.ZodNumber>;
35
40
  sessionUpdateAge: z.ZodDefault<z.ZodNumber>;
36
41
  sessionSecretRotateEveryDays: z.ZodOptional<z.ZodNumber>;
37
42
  verificationExpiresIn: z.ZodDefault<z.ZodNumber>;
38
43
  otpLength: z.ZodDefault<z.ZodNumber>;
39
44
  disableSignUp: z.ZodDefault<z.ZodBoolean>;
45
+ retention: z.ZodPrefault<z.ZodObject<{
46
+ purgeAfterDays: z.ZodDefault<z.ZodNumber>;
47
+ }, z.core.$strip>>;
48
+ lifecycleEmails: z.ZodPrefault<z.ZodObject<{
49
+ accountSuspended: z.ZodDefault<z.ZodBoolean>;
50
+ accountReinstated: z.ZodDefault<z.ZodBoolean>;
51
+ deletionScheduled: z.ZodDefault<z.ZodBoolean>;
52
+ deletionComplete: z.ZodDefault<z.ZodBoolean>;
53
+ }, z.core.$strip>>;
40
54
  plugins: z.ZodDefault<z.ZodArray<z.ZodCustom<import("better-auth").BetterAuthPlugin, import("better-auth").BetterAuthPlugin>>>;
41
55
  }, z.core.$strip>;
42
56
  export type AuthConfig = z.output<typeof AuthConfig>;
@@ -69,6 +83,12 @@ export interface AuthWiring {
69
83
  * Optional on the wiring for the reason `onSessionRevoked` is: no resolver is the ordinary composition.
70
84
  */
71
85
  resolveScopes?: ScopeResolver | undefined;
86
+ /**
87
+ * The adopter's lifecycle hooks, or absent. See {@link UserLifecycleHooks}.
88
+ *
89
+ * Optional on the wiring for the reason `onSessionRevoked` is: no hook is the ordinary composition.
90
+ */
91
+ lifecycleHooks?: UserLifecycleHooks | undefined;
72
92
  }
73
93
  /** The session a {@link ScopeResolver} is asked about — the one Better Auth just resolved for this request. */
74
94
  export interface ScopeResolverSession {
@@ -106,7 +126,7 @@ export type SessionRevokedListener = (session: {
106
126
  * `PaymentsOptions`: everything describable stays in {@link AuthConfig}, and a resolver is a sibling key
107
127
  * destructured off before the parse.
108
128
  */
109
- export type AuthOptions = AuthConfigInput & {
129
+ export type AuthOptions = AuthConfigInput & UserLifecycleHooks & {
110
130
  /**
111
131
  * Resolve a GitHub identity yourself, replacing the kit's primary-only rule.
112
132
  *
@@ -161,6 +181,11 @@ export type AuthOptions = AuthConfigInput & {
161
181
  /** The auth capability, with its resolved config attached for inspection. */
162
182
  export interface AuthCapability extends Capability {
163
183
  authConfig: AuthConfig;
184
+ /**
185
+ * The adopter's account-lifecycle hooks, as `auth()` was handed them. Read by whatever runs a transition
186
+ * outside a request this capability serves — the purge Workflow (#622) fires `onUserPurged` through it.
187
+ */
188
+ lifecycleHooks: UserLifecycleHooks;
164
189
  /**
165
190
  * What a capability composed beside this one reads an account through — `matchmaking`, `support`,
166
191
  * `testers`. Found in their `compose` hooks, so none of them imports this package and a project without
@@ -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;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAmB,MAAM,0CAA0C,CAAC;AAG1G,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAGtE,OAAO,EAA0B,KAAK,aAAa,EAAE,MAAM,uCAAuC,CAAC;AACnG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AASxB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAMxE,OAAO,EAAE,KAAK,QAAQ,EAAY,MAAM,QAAQ,CAAC;AA8BjD,mGAAmG;AACnG,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8E8B,CAAC;AACtD,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AACrD,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AAEzD;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,UAAU,CAAC;IACnB,8GAA8G;IAC9G,qBAAqB,EAAE,sBAAsB,GAAG,SAAS,CAAC;IAC1D,sGAAsG;IACtG,YAAY,EAAE,eAAe,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;IACrD,6FAA6F;IAC7F,SAAS,EAAE;QAAE,IAAI,EAAE,aAAa,CAAA;KAAE,GAAG,SAAS,C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DAA0D;AAC1D,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,IAAI,cAAc,CAErF"}
@@ -48,12 +48,20 @@ const AuthConfig = z.object({
48
48
  apple: ProviderToggle.prefault({}).describe("Apple Sign-In. Enable it, then store credentials as the `auth-apple-credentials` secret. See docs/apple-signin.md."),
49
49
  facebook: ProviderToggle.prefault({}).describe("Facebook Login. Enable it, then store credentials as the `auth-facebook-credentials` secret. See docs/facebook-oauth.md."),
50
50
  github: ProviderToggle.prefault({}).describe("GitHub OAuth. Enable it, then store credentials as the `auth-github-credentials` secret. See docs/github-oauth.md."),
51
+ 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
52
  sessionExpiresIn: z.number().int().default(604800).describe("Session (refresh credential) lifetime in seconds. Defaults to 7 days. Expiry slides forward on use."),
52
53
  sessionUpdateAge: z.number().int().default(86400).describe("How often (seconds) an active session's expiry slides forward. Defaults to 1 day."),
53
54
  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
55
  verificationExpiresIn: z.number().int().default(300).describe("Magic-link and OTP lifetime in seconds. Defaults to 5 minutes. Single-use regardless."),
55
56
  otpLength: z.number().int().default(6).describe("The number of digits in an email OTP. Defaults to 6."),
56
57
  disableSignUp: z.boolean().default(false).describe("When true, sign-in never provisions a new user — existing accounts only. Unknown emails get no email (anti-enumeration)."),
58
+ retention: z.object({ 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.") }).prefault({}).describe("How long a deleted account is kept before it is purged. Self-service deletion and an operator's soft deletion both use this window."),
59
+ lifecycleEmails: z.object({
60
+ accountSuspended: z.boolean().default(true).describe("Email the person when their account is suspended, with the reason and any end date."),
61
+ accountReinstated: z.boolean().default(true).describe("Email the person when a suspension is lifted."),
62
+ deletionScheduled: z.boolean().default(true).describe("Email the person when their account is deleted, with the date its data will be erased."),
63
+ deletionComplete: z.boolean().default(true).describe("Email the person once their data has been erased. Sent before the address is.")
64
+ }).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
65
  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
66
  }).describe("Configuration for the auth capability.");
59
67
  /**
@@ -87,8 +95,14 @@ function assertPluginTablesUnclaimed(capabilities, binding, extensions) {
87
95
  * and emits `auth/*` through `audit` when those are composed.
88
96
  */
89
97
  function auth(options) {
90
- const { resolveGithubUserInfo, onSessionRevoked, resolveScopes, ...config } = options;
98
+ const { resolveGithubUserInfo, onSessionRevoked, resolveScopes, onUserSuspended, onUserReinstated, onUserDeleted, onUserPurged, ...config } = options;
91
99
  const resolved = AuthConfig.parse(config);
100
+ const lifecycleHooks = {
101
+ ...onUserSuspended ? { onUserSuspended } : {},
102
+ ...onUserReinstated ? { onUserReinstated } : {},
103
+ ...onUserDeleted ? { onUserDeleted } : {},
104
+ ...onUserPurged ? { onUserPurged } : {}
105
+ };
92
106
  assertAdditivePlugins(resolved.plugins);
93
107
  const pluginPlan = authPluginPlan(resolved.plugins);
94
108
  const wiring = {
@@ -97,7 +111,8 @@ function auth(options) {
97
111
  enqueueEmail: void 0,
98
112
  turnstile: void 0,
99
113
  onSessionRevoked,
100
- resolveScopes
114
+ resolveScopes,
115
+ lifecycleHooks
101
116
  };
102
117
  const rateLimitMiddleware = (app) => {
103
118
  app.use(`${resolved.basePath}/*`, createRateLimitMiddleware(resolved.rateLimiterBinding));
@@ -166,13 +181,15 @@ function auth(options) {
166
181
  google: resolved.google.enabled,
167
182
  apple: resolved.apple.enabled,
168
183
  facebook: resolved.facebook.enabled,
169
- github: resolved.github.enabled
184
+ github: resolved.github.enabled,
185
+ microsoft: resolved.microsoft.enabled
170
186
  },
171
187
  providerSignUp: {
172
188
  google: resolved.google.allowSignUp,
173
189
  apple: resolved.apple.allowSignUp,
174
190
  facebook: resolved.facebook.allowSignUp,
175
- github: resolved.github.allowSignUp
191
+ github: resolved.github.allowSignUp,
192
+ microsoft: resolved.microsoft.allowSignUp
176
193
  },
177
194
  otpLength: resolved.otpLength,
178
195
  signUpEnabled: !resolved.disableSignUp
@@ -191,7 +208,8 @@ function auth(options) {
191
208
  });
192
209
  return Object.assign(capability, {
193
210
  authConfig: resolved,
194
- authPeer
211
+ authPeer,
212
+ lifecycleHooks
195
213
  });
196
214
  }
197
215
  /** 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;KACjB,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;KACjB,CAAC;IACF,4CAA4C;IAC5C,SAAS,EAAE,MAAM,CAAC;IAClB,4EAA4E;IAC5E,aAAa,EAAE,OAAO,CAAC;CACxB,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;;;;;;;;;iBA0BwF,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,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,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,SAAS,CAAC,CAAC"}
@@ -1,7 +1,7 @@
1
1
  // SPDX-FileCopyrightText: 2026 Pithy
2
2
  // SPDX-License-Identifier: MIT
3
3
  import { z } from "zod";
4
- import { 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({
@@ -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":"AAKA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,eAAe;aAC1B,MAAM;iBAAI,IAAI,EAAE,QAAQ;iBAAE,QAAQ;iBAAS,KAAK;iBAAQ,SAAS;qBAAI,KAAK;;;CAClE,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"}
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"}
@@ -1,32 +1,6 @@
1
1
  // SPDX-FileCopyrightText: 2026 Pithy
2
2
  // SPDX-License-Identifier: MIT
3
3
  import { Locale } from "@pithy-sh/core/src/i18n/locale";
4
- //#region src/data/kitFields.ts
5
- /**
6
- * The columns Pithy adds to Better Auth's own tables, declared **once**.
7
- *
8
- * Better Auth owns every read and write to `pithy_auth_users` and `pithy_auth_sessions` through its
9
- * Kysely adapter, and it writes only the fields its options declare. So a column that exists in the
10
- * migration and in the `User` Zod object and *not* here is null forever and absent from every user
11
- * object the instance returns — a migration and a schema field that silently did nothing.
12
- *
13
- * ## Why one module rather than two agreeing declarations
14
- *
15
- * These have to appear in two places: `makeAuth`'s live options (`../instance/auth.ts`) and the
16
- * schema baseline `pluginSchemaDelta` subtracts each adopter plugin's schema from
17
- * (`../migrations/pluginTables.ts`). Both were written out by hand, with a comment in each saying it
18
- * "must match" the other and a test claiming to hold them together. The test did not: it compared the
19
- * baseline against the `User` schema and never imported `makeAuth` at all, so reverting the live
20
- * declaration left the whole suite green while Better Auth silently stopped writing the column (#441).
21
- *
22
- * `docs/CONVENTIONS.md` is explicit that removing an invariant beats watching it. There is one object
23
- * now, imported by both, and the two cannot disagree because there is no second thing to disagree
24
- * with. That is also why the consequence is worth restating rather than diluting: leave a kit column
25
- * out of the baseline and `pluginSchemaDelta` reports it as something an adopter's plugin brought, so
26
- * a plugin that also declares a user `locale` emits `ALTER TABLE … ADD COLUMN locale` against a table
27
- * that already has one — a duplicate-column failure part-way through a migration D1 cannot roll back,
28
- * because it has no transactional DDL.
29
- */
30
4
  /**
31
5
  * The extra `pithy_auth_users` columns.
32
6
  *
@@ -50,12 +24,34 @@ import { Locale } from "@pithy-sh/core/src/i18n/locale";
50
24
  * that accepted a tag but refused `null` would let a reader pick a language and never take it back —
51
25
  * `updateUser({ locale: null })` answering 400 for the one state the schema calls ordinary.
52
26
  */
53
- const KIT_USER_FIELDS = { locale: {
54
- type: "string",
55
- required: false,
56
- input: true,
57
- validator: { input: Locale.nullable() }
58
- } };
27
+ const KIT_USER_FIELDS = {
28
+ locale: {
29
+ type: "string",
30
+ required: false,
31
+ input: true,
32
+ validator: { input: Locale.nullable() }
33
+ },
34
+ suspendedAt: {
35
+ type: "number",
36
+ required: false,
37
+ input: false
38
+ },
39
+ suspendedUntil: {
40
+ type: "number",
41
+ required: false,
42
+ input: false
43
+ },
44
+ deletedAt: {
45
+ type: "number",
46
+ required: false,
47
+ input: false
48
+ },
49
+ purgeAfter: {
50
+ type: "number",
51
+ required: false,
52
+ input: false
53
+ }
54
+ };
59
55
  /**
60
56
  * **`authenticatedAt` carries three decisions a future author must not undo.**
61
57
  *
@@ -8,8 +8,8 @@ import type { Kysely } from "kysely";
8
8
  * `pithy_auth_*` SQL. One source of truth shared by the capability wiring, the Better-Auth instance
9
9
  * (whose Kysely adapter wraps this same Kysely), the device registry, and the migration.
10
10
  *
11
- * The first six tables are Better-Auth-managed; `pithyAuthDevices` and `pithyAuthRotatedTokens` are
12
- * ours. Setting Better Auth's `modelName` to these exact camelCase keys lets the one `CamelCasePlugin`
11
+ * The first six tables are Better-Auth-managed; `pithyAuthDevices`, `pithyAuthRotatedTokens` and
12
+ * `pithyAuthUserLifecycle` are ours. Setting Better Auth's `modelName` to these exact camelCase keys lets the one `CamelCasePlugin`
13
13
  * own the camelCase ↔ snake_case boundary uniformly for both Better Auth's queries and our migration DDL.
14
14
  */
15
15
  export declare const authTables: {
@@ -22,6 +22,10 @@ export declare const authTables: {
22
22
  locale: import("zod").ZodNullable<import("zod").ZodString>;
23
23
  createdAt: import("zod").ZodCodec<import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodNumber, import("zod").ZodDate]>, import("zod").ZodDate>;
24
24
  updatedAt: import("zod").ZodCodec<import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodNumber, import("zod").ZodDate]>, import("zod").ZodDate>;
25
+ suspendedAt: 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>>>;
26
+ 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>>>;
27
+ 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>>>;
28
+ 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>>>;
25
29
  }, import("zod/v4/core").$strip>;
26
30
  pithyAuthSessions: import("zod").ZodObject<{
27
31
  id: import("zod").ZodString;
@@ -98,6 +102,28 @@ export declare const authTables: {
98
102
  userId: import("zod").ZodString;
99
103
  rotatedAt: import("zod").ZodCodec<import("zod").ZodUnion<readonly [import("zod").ZodNumber, import("zod").ZodString, import("zod").ZodDate]>, import("zod").ZodDate>;
100
104
  }, import("zod/v4/core").$strip>;
105
+ pithyAuthUserLifecycle: import("zod").ZodObject<{
106
+ id: import("zod").ZodNumber;
107
+ userId: import("zod").ZodString;
108
+ action: import("zod").ZodEnum<{
109
+ deleted: "deleted";
110
+ purge_step: "purge_step";
111
+ purged: "purged";
112
+ reinstated: "reinstated";
113
+ restored: "restored";
114
+ suspended: "suspended";
115
+ }>;
116
+ actorType: import("zod").ZodEnum<{
117
+ "control-plane": "control-plane";
118
+ system: "system";
119
+ user: "user";
120
+ }>;
121
+ actorId: import("zod").ZodNullable<import("zod").ZodString>;
122
+ reason: import("zod").ZodNullable<import("zod").ZodString>;
123
+ suspendedUntil: import("zod").ZodNullable<import("zod").ZodCodec<import("zod").ZodUnion<readonly [import("zod").ZodNumber, import("zod").ZodString, import("zod").ZodDate]>, import("zod").ZodDate>>;
124
+ step: import("zod").ZodNullable<import("zod").ZodString>;
125
+ createdAt: import("zod").ZodCodec<import("zod").ZodUnion<readonly [import("zod").ZodNumber, import("zod").ZodString, import("zod").ZodDate]>, import("zod").ZodDate>;
126
+ }, import("zod/v4/core").$strip>;
101
127
  };
102
128
  export type AuthTables = typeof authTables;
103
129
  /** The typed Kysely view over the auth tables — shared by the Better-Auth adapter and the device registry. */
@@ -1 +1 @@
1
- {"version":3,"file":"tables.d.ts","sourceRoot":"","sources":["../../src/data/tables.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACjF,OAA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G,wBAAgB,YAAY,CAAC,EAAE,EAAE,UAAU,GAAG,YAAY,CAEzD"}
@@ -3,6 +3,7 @@
3
3
  import { Account, Jwks, RateLimit, Session, User, Verification } from "./betterAuth.js";
4
4
  import { Device } from "./device.js";
5
5
  import { RotatedToken } from "./rotatedToken.js";
6
+ import { UserLifecycleEvent } from "./userLifecycle.js";
6
7
  import { createDatabase } from "@pithy-sh/core/src/data/db";
7
8
  //#region src/data/tables.ts
8
9
  /**
@@ -10,8 +11,8 @@ import { createDatabase } from "@pithy-sh/core/src/data/db";
10
11
  * `pithy_auth_*` SQL. One source of truth shared by the capability wiring, the Better-Auth instance
11
12
  * (whose Kysely adapter wraps this same Kysely), the device registry, and the migration.
12
13
  *
13
- * The first six tables are Better-Auth-managed; `pithyAuthDevices` and `pithyAuthRotatedTokens` are
14
- * ours. Setting Better Auth's `modelName` to these exact camelCase keys lets the one `CamelCasePlugin`
14
+ * The first six tables are Better-Auth-managed; `pithyAuthDevices`, `pithyAuthRotatedTokens` and
15
+ * `pithyAuthUserLifecycle` are ours. Setting Better Auth's `modelName` to these exact camelCase keys lets the one `CamelCasePlugin`
15
16
  * own the camelCase ↔ snake_case boundary uniformly for both Better Auth's queries and our migration DDL.
16
17
  */
17
18
  const authTables = {
@@ -22,7 +23,8 @@ const authTables = {
22
23
  pithyAuthJwks: Jwks,
23
24
  pithyAuthRateLimit: RateLimit,
24
25
  pithyAuthDevices: Device,
25
- pithyAuthRotatedTokens: RotatedToken
26
+ pithyAuthRotatedTokens: RotatedToken,
27
+ pithyAuthUserLifecycle: UserLifecycleEvent
26
28
  };
27
29
  /** Build the auth Kysely over a D1 binding. Carries `CamelCasePlugin`, so query code stays camelCase. */
28
30
  function authDatabase(d1) {