@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.
Files changed (188) hide show
  1. package/README.md +8 -2
  2. package/dist/admin/users.js +1 -1
  3. package/dist/audit/actions.d.ts +40 -0
  4. package/dist/audit/actions.d.ts.map +1 -1
  5. package/dist/audit/actions.js +41 -1
  6. package/dist/audit/emit.d.ts +2 -0
  7. package/dist/audit/emit.d.ts.map +1 -1
  8. package/dist/audit/emit.js +2 -2
  9. package/dist/capability.d.ts +45 -1
  10. package/dist/capability.d.ts.map +1 -1
  11. package/dist/capability.js +40 -5
  12. package/dist/client/lifecycle.d.ts +19 -0
  13. package/dist/client/lifecycle.d.ts.map +1 -0
  14. package/dist/client/lifecycle.js +25 -0
  15. package/dist/client/projection.d.ts +4 -0
  16. package/dist/client/projection.d.ts.map +1 -1
  17. package/dist/data/betterAuth.d.ts +4 -0
  18. package/dist/data/betterAuth.d.ts.map +1 -1
  19. package/dist/data/betterAuth.js +6 -2
  20. package/dist/data/kitFields.d.ts +20 -25
  21. package/dist/data/kitFields.d.ts.map +1 -1
  22. package/dist/data/kitFields.js +28 -32
  23. package/dist/data/tables.d.ts +29 -2
  24. package/dist/data/tables.d.ts.map +1 -1
  25. package/dist/data/tables.js +5 -3
  26. package/dist/data/userLifecycle.d.ts +62 -0
  27. package/dist/data/userLifecycle.d.ts.map +1 -0
  28. package/dist/data/userLifecycle.js +51 -0
  29. package/dist/http/adminRoutes.d.ts.map +1 -1
  30. package/dist/http/adminRoutes.js +270 -5
  31. package/dist/http/guards.d.ts +24 -1
  32. package/dist/http/guards.d.ts.map +1 -1
  33. package/dist/http/guards.js +59 -3
  34. package/dist/http/lifecycleGate.d.ts +18 -0
  35. package/dist/http/lifecycleGate.d.ts.map +1 -0
  36. package/dist/http/lifecycleGate.js +75 -0
  37. package/dist/http/middleware.d.ts +30 -1
  38. package/dist/http/middleware.d.ts.map +1 -1
  39. package/dist/http/middleware.js +89 -7
  40. package/dist/http/providerRefusal.d.ts.map +1 -1
  41. package/dist/http/providerRefusal.js +8 -0
  42. package/dist/http/resolve.d.ts.map +1 -1
  43. package/dist/http/resolve.js +7 -4
  44. package/dist/http/responses.d.ts +180 -0
  45. package/dist/http/responses.d.ts.map +1 -1
  46. package/dist/http/responses.js +142 -1
  47. package/dist/http/routes.d.ts +1 -0
  48. package/dist/http/routes.d.ts.map +1 -1
  49. package/dist/http/routes.js +65 -4
  50. package/dist/http/schemas.d.ts +57 -0
  51. package/dist/http/schemas.d.ts.map +1 -1
  52. package/dist/http/schemas.js +51 -1
  53. package/dist/http/views.d.ts +39 -2
  54. package/dist/http/views.d.ts.map +1 -1
  55. package/dist/http/views.js +105 -1
  56. package/dist/instance/auth.d.ts +55 -3
  57. package/dist/instance/auth.d.ts.map +1 -1
  58. package/dist/instance/auth.js +53 -2
  59. package/dist/instance/microsoftEmail.d.ts +70 -0
  60. package/dist/instance/microsoftEmail.d.ts.map +1 -0
  61. package/dist/instance/microsoftEmail.js +96 -0
  62. package/dist/instance/providerSignInGate.d.ts +7 -6
  63. package/dist/instance/providerSignInGate.d.ts.map +1 -1
  64. package/dist/instance/providerSignInGate.js +7 -6
  65. package/dist/instance/providers.d.ts +7 -5
  66. package/dist/instance/providers.d.ts.map +1 -1
  67. package/dist/instance/providers.js +5 -3
  68. package/dist/instance/secrets.d.ts +64 -3
  69. package/dist/instance/secrets.d.ts.map +1 -1
  70. package/dist/instance/secrets.js +44 -5
  71. package/dist/lifecycle/audited.d.ts +48 -0
  72. package/dist/lifecycle/audited.d.ts.map +1 -0
  73. package/dist/lifecycle/audited.js +65 -0
  74. package/dist/lifecycle/enforce.d.ts +75 -0
  75. package/dist/lifecycle/enforce.d.ts.map +1 -0
  76. package/dist/lifecycle/enforce.js +111 -0
  77. package/dist/lifecycle/hooks.d.ts +53 -0
  78. package/dist/lifecycle/hooks.d.ts.map +1 -0
  79. package/dist/lifecycle/hooks.js +2 -0
  80. package/dist/lifecycle/reason.d.ts +11 -0
  81. package/dist/lifecycle/reason.d.ts.map +1 -0
  82. package/dist/lifecycle/reason.js +13 -0
  83. package/dist/lifecycle/request.d.ts +18 -0
  84. package/dist/lifecycle/request.d.ts.map +1 -0
  85. package/dist/lifecycle/request.js +31 -0
  86. package/dist/lifecycle/state.d.ts +64 -0
  87. package/dist/lifecycle/state.d.ts.map +1 -0
  88. package/dist/lifecycle/state.js +90 -0
  89. package/dist/lifecycle/transitions.d.ts +272 -0
  90. package/dist/lifecycle/transitions.d.ts.map +1 -0
  91. package/dist/lifecycle/transitions.js +623 -0
  92. package/dist/migrations/0004_user_lifecycle.d.ts +28 -0
  93. package/dist/migrations/0004_user_lifecycle.d.ts.map +1 -0
  94. package/dist/migrations/0004_user_lifecycle.js +47 -0
  95. package/dist/migrations/0005_purge_once.d.ts +22 -0
  96. package/dist/migrations/0005_purge_once.d.ts.map +1 -0
  97. package/dist/migrations/0005_purge_once.js +35 -0
  98. package/dist/migrations/pluginTables.d.ts +8 -0
  99. package/dist/migrations/pluginTables.d.ts.map +1 -1
  100. package/dist/migrations/pluginTables.js +8 -1
  101. package/dist/migrations/set.d.ts +3 -1
  102. package/dist/migrations/set.d.ts.map +1 -1
  103. package/dist/migrations/set.js +6 -2
  104. package/dist/peer.d.ts +4 -0
  105. package/dist/peer.d.ts.map +1 -1
  106. package/dist/purge/contribution.d.ts +47 -0
  107. package/dist/purge/contribution.d.ts.map +1 -0
  108. package/dist/purge/contribution.js +141 -0
  109. package/dist/purge/retryPolicy.d.ts +22 -0
  110. package/dist/purge/retryPolicy.d.ts.map +1 -0
  111. package/dist/purge/retryPolicy.js +26 -0
  112. package/dist/purge/run.d.ts +88 -0
  113. package/dist/purge/run.d.ts.map +1 -0
  114. package/dist/purge/run.js +102 -0
  115. package/dist/purge/specs.d.ts +71 -0
  116. package/dist/purge/specs.d.ts.map +1 -0
  117. package/dist/purge/specs.js +72 -0
  118. package/dist/purge/start.d.ts +42 -0
  119. package/dist/purge/start.d.ts.map +1 -0
  120. package/dist/purge/start.js +37 -0
  121. package/dist/purge/workflow.d.ts +58 -0
  122. package/dist/purge/workflow.d.ts.map +1 -0
  123. package/dist/purge/workflow.js +96 -0
  124. package/dist/test-utils/accountFootprint.d.ts +10 -0
  125. package/dist/test-utils/accountFootprint.d.ts.map +1 -0
  126. package/dist/test-utils/accountFootprint.js +44 -0
  127. package/dist/test-utils/liveApp.d.ts +21 -0
  128. package/dist/test-utils/liveApp.d.ts.map +1 -1
  129. package/dist/test-utils/liveApp.js +1 -0
  130. package/dist/test-utils/scopedBackend.d.ts +21 -0
  131. package/dist/test-utils/scopedBackend.d.ts.map +1 -1
  132. package/dist/test-utils/scopedBackend.js +7 -1
  133. package/dist/version.generated.d.ts +1 -1
  134. package/dist/version.generated.d.ts.map +1 -1
  135. package/dist/version.generated.js +1 -1
  136. package/docs/account-lifecycle.md +217 -0
  137. package/docs/apple-signin.md +7 -1
  138. package/docs/facebook-oauth.md +7 -1
  139. package/docs/github-oauth.md +7 -1
  140. package/docs/google-oauth.md +7 -1
  141. package/docs/microsoft-oauth.md +177 -0
  142. package/package.json +5 -5
  143. package/pithy.manifest.json +17 -3
  144. package/src/audit/actions.ts +42 -0
  145. package/src/audit/emit.ts +4 -2
  146. package/src/capability.ts +170 -52
  147. package/src/client/lifecycle.ts +27 -0
  148. package/src/client/projection.ts +4 -0
  149. package/src/data/betterAuth.ts +21 -1
  150. package/src/data/kitFields.ts +27 -0
  151. package/src/data/tables.ts +4 -2
  152. package/src/data/userLifecycle.ts +83 -0
  153. package/src/http/adminRoutes.ts +398 -2
  154. package/src/http/guards.ts +61 -1
  155. package/src/http/lifecycleGate.ts +78 -0
  156. package/src/http/middleware.ts +104 -2
  157. package/src/http/providerRefusal.ts +10 -0
  158. package/src/http/resolve.ts +8 -3
  159. package/src/http/responses.ts +245 -0
  160. package/src/http/routes.ts +93 -4
  161. package/src/http/schemas.ts +110 -0
  162. package/src/http/views.ts +147 -2
  163. package/src/instance/auth.ts +74 -2
  164. package/src/instance/microsoftEmail.ts +111 -0
  165. package/src/instance/providerSignInGate.ts +7 -6
  166. package/src/instance/providers.ts +8 -4
  167. package/src/instance/secrets.ts +59 -5
  168. package/src/lifecycle/audited.ts +104 -0
  169. package/src/lifecycle/enforce.ts +139 -0
  170. package/src/lifecycle/hooks.ts +54 -0
  171. package/src/lifecycle/reason.ts +11 -0
  172. package/src/lifecycle/request.ts +39 -0
  173. package/src/lifecycle/state.ts +101 -0
  174. package/src/lifecycle/transitions.ts +872 -0
  175. package/src/migrations/0004_user_lifecycle.ts +68 -0
  176. package/src/migrations/0005_purge_once.ts +42 -0
  177. package/src/migrations/pluginTables.ts +19 -1
  178. package/src/migrations/set.ts +5 -1
  179. package/src/purge/contribution.ts +191 -0
  180. package/src/purge/retryPolicy.ts +26 -0
  181. package/src/purge/run.ts +185 -0
  182. package/src/purge/specs.ts +95 -0
  183. package/src/purge/start.ts +79 -0
  184. package/src/purge/workflow.ts +144 -0
  185. package/src/test-utils/accountFootprint.ts +95 -0
  186. package/src/test-utils/liveApp.ts +2 -1
  187. package/src/test-utils/scopedBackend.ts +2 -1
  188. package/src/version.generated.ts +1 -1
@@ -0,0 +1,102 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import { completePurge, duePurges, mailPurgeComplete, purgeSubject, recordPurgeStep } from "../lifecycle/transitions.js";
4
+ import { AUTH_CAPABILITY } from "./specs.js";
5
+ import { authWorkflowRetry } from "./retryPolicy.js";
6
+ import { classifiedSteps } from "@pithy-sh/core/src/workflow/faults";
7
+ //#region src/purge/run.ts
8
+ /** The operations, over the lifecycle transitions. */
9
+ function purgeOps(deps) {
10
+ return {
11
+ due: async (userId) => (await purgeSubject(deps, userId)).state,
12
+ recordStep: (userId, step, summary) => recordPurgeStep(deps, {
13
+ userId,
14
+ step,
15
+ summary
16
+ }),
17
+ mailComplete: async (userId, notify) => {
18
+ const subject = await purgeSubject(deps, userId);
19
+ if (subject.state !== "due") return false;
20
+ const silenced = notify === false || subject.notify === false;
21
+ return (await mailPurgeComplete(deps, {
22
+ recipient: subject.recipient,
23
+ ...silenced ? { notify: false } : {}
24
+ })).mailed;
25
+ },
26
+ complete: async (userId) => (await completePurge(deps, { userId })).changed
27
+ };
28
+ }
29
+ /** Run one account's purge, one step per contribution, auth's last. See the file header for the order. */
30
+ async function purgeUser(run, step, terminalError, params) {
31
+ const own = classifiedSteps(step, authWorkflowRetry, terminalError);
32
+ const userId = params.userId;
33
+ const state = await own.do("due", () => run.ops.due(userId));
34
+ if (state !== "due") return {
35
+ userId,
36
+ state,
37
+ erased: [],
38
+ mailed: false
39
+ };
40
+ const context = {
41
+ subject: {
42
+ type: "user",
43
+ id: userId
44
+ },
45
+ env: run.env
46
+ };
47
+ const auth = run.steps.filter((each) => each.step === AUTH_CAPABILITY);
48
+ const others = run.steps.filter((each) => each.step !== AUTH_CAPABILITY);
49
+ const erased = [];
50
+ for (const each of others) erased.push(await eraseStep(step, run.ops, each, context));
51
+ const mailed = await own.do("mail", () => run.ops.mailComplete(userId, params.notify));
52
+ for (const each of auth) erased.push(await eraseStep(step, run.ops, each, context));
53
+ await own.do("complete", () => run.ops.complete(userId));
54
+ return {
55
+ userId,
56
+ state: "purged",
57
+ erased,
58
+ mailed
59
+ };
60
+ }
61
+ /**
62
+ * One capability's step: erase, then record that it ran. On the platform's own retry, unclassified — see the
63
+ * file header. Recorded inside the same step, so a step that erased and failed to record is retried whole, and
64
+ * the second erase finds nothing.
65
+ */
66
+ function eraseStep(step, ops, each, context) {
67
+ return step.do(`erase ${each.step}`, async () => {
68
+ await each.contribution.erase(context);
69
+ await ops.recordStep(context.subject.id, each.step, each.contribution.summary);
70
+ return each.step;
71
+ });
72
+ }
73
+ /** How many purges one `start` step dispatches — a page, so one pass over a backlog is a bounded number of steps. */
74
+ const PURGE_START_PAGE = 50;
75
+ /** The default size of one daily pass. */
76
+ const PURGE_DUE_DEFAULT_LIMIT = 500;
77
+ /**
78
+ * The daily pass (#622): list every account past its window, and start a purge for each — in pages, one step
79
+ * each, so a pass that dies part-way resumes after the page it finished rather than starting every purge
80
+ * again. An account still inside its window is not listed, so it is not started.
81
+ */
82
+ async function startDuePurges(run, step, terminalError, params) {
83
+ const own = classifiedSteps(step, authWorkflowRetry, terminalError);
84
+ const limit = params.limit ?? 500;
85
+ const due = await own.do("due", () => run.due(limit));
86
+ let started = 0;
87
+ for (let page = 0; page * 50 < due.length; page += 1) {
88
+ const ids = due.slice(page * 50, (page + 1) * 50);
89
+ started += await own.do(`start ${page + 1}`, async () => {
90
+ let running = 0;
91
+ for (const each of ids) if (await run.start(each)) running += 1;
92
+ return running;
93
+ });
94
+ }
95
+ return { started };
96
+ }
97
+ /** The daily pass's reads, over the lifecycle transitions. */
98
+ function duePurgesOf(deps) {
99
+ return (limit) => duePurges(deps, limit);
100
+ }
101
+ //#endregion
102
+ export { PURGE_DUE_DEFAULT_LIMIT, PURGE_START_PAGE, duePurgesOf, purgeOps, purgeUser, startDuePurges };
@@ -0,0 +1,71 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import type { WorkflowRegistry } from "@pithy-sh/core/src/workflow/spec";
4
+ import { z } from "zod";
5
+ /** This capability's name, and the first segment of its workflow dispatch keys. */
6
+ export declare const AUTH_CAPABILITY = "auth";
7
+ /** The binding the purge of one account is started on. */
8
+ export declare const AUTH_PURGE_BINDING = "AUTH_PURGE";
9
+ /** The binding the daily pass that starts every due purge runs on. */
10
+ export declare const AUTH_PURGE_DUE_BINDING = "AUTH_PURGE_DUE";
11
+ /** The dispatch key of the purge of one account. */
12
+ export declare const AUTH_PURGE_KEY: string;
13
+ /** One account's purge: which, and whether its last mail is sent. */
14
+ export declare const AuthPurgeParams: z.ZodObject<{
15
+ userId: z.ZodString;
16
+ notify: z.ZodOptional<z.ZodBoolean>;
17
+ }, z.core.$strip>;
18
+ export type AuthPurgeParams = z.infer<typeof AuthPurgeParams>;
19
+ /**
20
+ * The daily pass's parameters. Every field optional, because a cron passes none — `createEntrypoint` starts a
21
+ * scheduled job with `{}`.
22
+ */
23
+ export declare const AuthPurgeDueParams: z.ZodObject<{
24
+ limit: z.ZodOptional<z.ZodNumber>;
25
+ }, z.core.$strip>;
26
+ export type AuthPurgeDueParams = z.infer<typeof AuthPurgeDueParams>;
27
+ /**
28
+ * The two durable jobs auth owns (#622) — **both hosted by the adopter's own Worker**, the one that composes
29
+ * auth, never a prebuilt host.
30
+ *
31
+ * **Why not a host.** A purge runs every composed capability's contribution, the adopter's own `app` among
32
+ * them, and those exist only in the Worker whose `pithy.config.ts` composed them. A prebuilt host composes
33
+ * nothing. So each class is five lines in the adopter's entry, calling `runAuthPurge` and `runAuthPurgeDue` in
34
+ * `./workflow.ts`, exactly as `@pithy-sh/payments`' usage pass is: Cloudflare resolves a `class_name` in the
35
+ * script that binds it, and the body finds the composition the way a Workflow that sends mail finds email.
36
+ * No `className` here, deliberately: the class is the adopter's, and so is its `workflows` entry. The docs
37
+ * give both (`docs/account-lifecycle.md`).
38
+ *
39
+ * **`purge-due` is daily at 02:00 UTC**, ahead of storage's and the secrets rotation at 03:00, payments' 04:00
40
+ * and testers' 05:00. Daily because the window is counted in days: an hourly pass would start the same purge
41
+ * twenty-four times and erase nothing sooner. Both stay dispatchable on demand — a hard deletion starts
42
+ * `purge` directly.
43
+ *
44
+ * `optional: true` for both, so a Worker composing auth still boots before the adopter has bound them. A
45
+ * deletion then reports its purge as `pending`, and nothing is erased until they are.
46
+ */
47
+ export declare const authWorkflows: {
48
+ readonly purge: {
49
+ readonly binding: "AUTH_PURGE";
50
+ readonly params: z.ZodObject<{
51
+ userId: z.ZodString;
52
+ notify: z.ZodOptional<z.ZodBoolean>;
53
+ }, z.core.$strip>;
54
+ readonly optional: true;
55
+ };
56
+ readonly "purge-due": {
57
+ readonly binding: "AUTH_PURGE_DUE";
58
+ readonly params: z.ZodObject<{
59
+ limit: z.ZodOptional<z.ZodNumber>;
60
+ }, z.core.$strip>;
61
+ readonly schedule: "0 2 * * *";
62
+ readonly optional: true;
63
+ };
64
+ };
65
+ /**
66
+ * The jobs as a dispatch registry, keyed `auth/<job>`, built here for the reason testers builds its own: the key
67
+ * format is core's either way. The daily pass starts each purge on the binding directly, not through this, because
68
+ * it names the instance (`./start.ts`) and dispatch does not.
69
+ */
70
+ export declare const authWorkflowRegistry: WorkflowRegistry;
71
+ //# sourceMappingURL=specs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"specs.d.ts","sourceRoot":"","sources":["../../src/purge/specs.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAmB,MAAM,kCAAkC,CAAC;AAC1F,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,mFAAmF;AACnF,eAAO,MAAM,eAAe,SAAS,CAAC;AAEtC,0DAA0D;AAC1D,eAAO,MAAM,kBAAkB,eAAe,CAAC;AAE/C,sEAAsE;AACtE,eAAO,MAAM,sBAAsB,mBAAmB,CAAC;AAEvD,oDAAoD;AACpD,eAAO,MAAM,cAAc,QAAwC,CAAC;AAEpE,qEAAqE;AACrE,eAAO,MAAM,eAAe;;;iBAUkF,CAAC;AAC/G,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAE9D;;;GAGG;AACH,eAAO,MAAM,kBAAkB;;iBAUuE,CAAC;AACvG,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAEpE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,aAAa;;iBAEtB,OAAO;iBACP,MAAM;;;;iBACN,QAAQ;;;iBAGR,OAAO;iBACP,MAAM;;;iBACN,QAAQ,EAAE,WAAW;iBACrB,QAAQ;;CAEwB,CAAC;AAErC;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,EAAE,gBAKlC,CAAC"}
@@ -0,0 +1,72 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import { z } from "zod";
4
+ import { workflowKey } from "@pithy-sh/core/src/workflow/naming";
5
+ //#region src/purge/specs.ts
6
+ /** This capability's name, and the first segment of its workflow dispatch keys. */
7
+ const AUTH_CAPABILITY = "auth";
8
+ /** The binding the purge of one account is started on. */
9
+ const AUTH_PURGE_BINDING = "AUTH_PURGE";
10
+ /** The binding the daily pass that starts every due purge runs on. */
11
+ const AUTH_PURGE_DUE_BINDING = "AUTH_PURGE_DUE";
12
+ /** The dispatch key of the purge of one account. */
13
+ const AUTH_PURGE_KEY = workflowKey(AUTH_CAPABILITY, "purge");
14
+ /** One account's purge: which, and whether its last mail is sent. */
15
+ const AuthPurgeParams = z.object({
16
+ userId: z.string().min(1).max(255).describe("The account to erase, as `pithy_auth_users.id` stores it."),
17
+ notify: z.boolean().optional().describe("Whether the deletion-complete mail is sent. Absent is true; the config can still turn it off. A hard deletion with `notify: false` passes false.")
18
+ }).describe("One account's purge. It erases nothing unless the account is deleted and its window has closed.");
19
+ /**
20
+ * The daily pass's parameters. Every field optional, because a cron passes none — `createEntrypoint` starts a
21
+ * scheduled job with `{}`.
22
+ */
23
+ const AuthPurgeDueParams = z.object({ limit: z.number().int().min(1).max(1e3).optional().describe("How many due accounts to start a purge for in this pass, oldest first. Defaults to 500.") }).describe("One pass that starts a purge for every account past its window. A cron passes no field.");
24
+ /**
25
+ * The two durable jobs auth owns (#622) — **both hosted by the adopter's own Worker**, the one that composes
26
+ * auth, never a prebuilt host.
27
+ *
28
+ * **Why not a host.** A purge runs every composed capability's contribution, the adopter's own `app` among
29
+ * them, and those exist only in the Worker whose `pithy.config.ts` composed them. A prebuilt host composes
30
+ * nothing. So each class is five lines in the adopter's entry, calling `runAuthPurge` and `runAuthPurgeDue` in
31
+ * `./workflow.ts`, exactly as `@pithy-sh/payments`' usage pass is: Cloudflare resolves a `class_name` in the
32
+ * script that binds it, and the body finds the composition the way a Workflow that sends mail finds email.
33
+ * No `className` here, deliberately: the class is the adopter's, and so is its `workflows` entry. The docs
34
+ * give both (`docs/account-lifecycle.md`).
35
+ *
36
+ * **`purge-due` is daily at 02:00 UTC**, ahead of storage's and the secrets rotation at 03:00, payments' 04:00
37
+ * and testers' 05:00. Daily because the window is counted in days: an hourly pass would start the same purge
38
+ * twenty-four times and erase nothing sooner. Both stay dispatchable on demand — a hard deletion starts
39
+ * `purge` directly.
40
+ *
41
+ * `optional: true` for both, so a Worker composing auth still boots before the adopter has bound them. A
42
+ * deletion then reports its purge as `pending`, and nothing is erased until they are.
43
+ */
44
+ const authWorkflows = {
45
+ purge: {
46
+ binding: AUTH_PURGE_BINDING,
47
+ params: AuthPurgeParams,
48
+ optional: true
49
+ },
50
+ "purge-due": {
51
+ binding: AUTH_PURGE_DUE_BINDING,
52
+ params: AuthPurgeDueParams,
53
+ schedule: "0 2 * * *",
54
+ optional: true
55
+ }
56
+ };
57
+ /**
58
+ * The jobs as a dispatch registry, keyed `auth/<job>`, built here for the reason testers builds its own: the key
59
+ * format is core's either way. The daily pass starts each purge on the binding directly, not through this, because
60
+ * it names the instance (`./start.ts`) and dispatch does not.
61
+ */
62
+ const authWorkflowRegistry = Object.fromEntries(Object.entries(authWorkflows).map(([job, spec]) => {
63
+ const key = workflowKey(AUTH_CAPABILITY, job);
64
+ return [key, {
65
+ key,
66
+ capability: AUTH_CAPABILITY,
67
+ job,
68
+ spec
69
+ }];
70
+ }));
71
+ //#endregion
72
+ export { AUTH_CAPABILITY, AUTH_PURGE_BINDING, AUTH_PURGE_DUE_BINDING, AUTH_PURGE_KEY, AuthPurgeDueParams, AuthPurgeParams, authWorkflowRegistry, authWorkflows };
@@ -0,0 +1,42 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import type { WorkflowBinding } from "@pithy-sh/core/src/workflow/spec";
4
+ /**
5
+ * Starting one account's purge, from either door (#622) — a hard deletion's route and the daily pass.
6
+ *
7
+ * **Under an id the deletion names, so two starts of one purge are one instance.** A hard deletion repeated, a
8
+ * hard deletion the daily pass also finds due, a `start` step the pass retries: each asks for the same
9
+ * instance, and Cloudflare holds one instance per id, so the second `create` is refused and nothing runs
10
+ * twice. Two purges of one account running at once would both pass `due` and both reach the mail.
11
+ *
12
+ * **The id is the account, the deletion's start, and the UTC day of the start.** The account and the deletion,
13
+ * so a restored and re-deleted account is a different purge. The day, because the daily pass is the outer
14
+ * retry (`./retryPolicy.ts`): an instance that failed keeps its id, and a purge started under the same id
15
+ * forever could never be started again. So tomorrow's pass gets a fresh instance for an account still due,
16
+ * and every start within one day is the same one. Two instances of one purge can overlap only across a day
17
+ * boundary, while the first is still retrying; `complete` then records, audits and fires once whatever
18
+ * overlaps (`../lifecycle/transitions.ts`).
19
+ *
20
+ * **Hashed.** An instance id is at most 100 characters of `[A-Za-z0-9_-]`, and a user id is up to 255 of
21
+ * anything. A SHA-256 of the pair keeps the id inside the rule and says nothing about the account.
22
+ */
23
+ /** What starting a purge needs to know. */
24
+ export interface PurgeStart {
25
+ /** The account. */
26
+ readonly userId: string;
27
+ /** The deletion it is purged under — its start, ms-epoch. */
28
+ readonly deletedAt: number;
29
+ /** A hard deletion's `notify`, when it named one. The deletion's row carries it too. */
30
+ readonly notify?: boolean;
31
+ /** Now, for the day the id is named for. */
32
+ readonly at: Date;
33
+ }
34
+ /** The instance id of one purge, on one day. Deterministic: the same start always names the same instance. */
35
+ export declare function purgeInstanceId(start: Pick<PurgeStart, "userId" | "deletedAt" | "at">): Promise<string>;
36
+ /**
37
+ * Start one purge, or find it started. A `create` refused because the id is taken is a purge already started,
38
+ * so this asks the binding for the instance and succeeds when it is there. Any other failure is thrown, for the
39
+ * caller to report as `pending`. The parameters are the job's own schema, parsed.
40
+ */
41
+ export declare function startPurgeInstance(binding: WorkflowBinding, start: PurgeStart): Promise<void>;
42
+ //# sourceMappingURL=start.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"start.d.ts","sourceRoot":"","sources":["../../src/purge/start.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAGxE;;;;;;;;;;;;;;;;;;GAkBG;AAEH,2CAA2C;AAC3C,MAAM,WAAW,UAAU;IACzB,mBAAmB;IACnB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,6DAA6D;IAC7D,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,wFAAwF;IACxF,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,4CAA4C;IAC5C,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;CACnB;AAED,8GAA8G;AAC9G,wBAAsB,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,EAAE,QAAQ,GAAG,WAAW,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAK7G;AAWD;;;;GAIG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAkBnG"}
@@ -0,0 +1,37 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import { AuthPurgeParams } from "./specs.js";
4
+ //#region src/purge/start.ts
5
+ /** The instance id of one purge, on one day. Deterministic: the same start always names the same instance. */
6
+ async function purgeInstanceId(start) {
7
+ const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(`${start.userId}\n${start.deletedAt}`));
8
+ return `auth-purge-${Array.from(new Uint8Array(digest).slice(0, 20), (byte) => byte.toString(16).padStart(2, "0")).join("")}-${start.at.toISOString().slice(0, 10).replaceAll("-", "")}`;
9
+ }
10
+ function canLookUp(binding) {
11
+ return typeof binding.get === "function";
12
+ }
13
+ /**
14
+ * Start one purge, or find it started. A `create` refused because the id is taken is a purge already started,
15
+ * so this asks the binding for the instance and succeeds when it is there. Any other failure is thrown, for the
16
+ * caller to report as `pending`. The parameters are the job's own schema, parsed.
17
+ */
18
+ async function startPurgeInstance(binding, start) {
19
+ const id = await purgeInstanceId(start);
20
+ const params = AuthPurgeParams.parse({
21
+ userId: start.userId,
22
+ ...start.notify === void 0 ? {} : { notify: start.notify }
23
+ });
24
+ try {
25
+ await binding.create({
26
+ id,
27
+ params
28
+ });
29
+ } catch (error) {
30
+ if (canLookUp(binding)) {
31
+ if (await binding.get(id).then(() => true, () => false)) return;
32
+ }
33
+ throw error;
34
+ }
35
+ }
36
+ //#endregion
37
+ export { purgeInstanceId, startPurgeInstance };
@@ -0,0 +1,58 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import type { Logger } from "@pithy-sh/core/src/logger/logger";
4
+ import type { TerminalErrorConstructor, WorkflowStepLike } from "@pithy-sh/core/src/workflow/faults";
5
+ import { type PurgeDueRun, type PurgeOutcome } from "./run";
6
+ /**
7
+ * The purge's two Workflow bodies (#622) — run by classes **the adopter's own Worker** exports, beside the
8
+ * `createEntrypoint` it already exports, because a purge runs every composed capability's contribution and
9
+ * those exist nowhere else:
10
+ *
11
+ * // apps/api/src/index.ts
12
+ * import { WorkflowEntrypoint, type WorkflowEvent, type WorkflowStep } from "cloudflare:workers";
13
+ * import { NonRetryableError } from "cloudflare:workflows";
14
+ * import { runAuthPurge, runAuthPurgeDue } from "@pithy-sh/auth/src/purge/workflow";
15
+ *
16
+ * export class AuthPurgeWorkflow extends WorkflowEntrypoint<Record<string, unknown>> {
17
+ * override run(event: WorkflowEvent<unknown>, step: WorkflowStep) {
18
+ * return runAuthPurge(this.env, event, step, NonRetryableError);
19
+ * }
20
+ * }
21
+ * export class AuthPurgeDueWorkflow extends WorkflowEntrypoint<Record<string, unknown>> {
22
+ * override run(event: WorkflowEvent<unknown>, step: WorkflowStep) {
23
+ * return runAuthPurgeDue(this.env, event, step, NonRetryableError);
24
+ * }
25
+ * }
26
+ *
27
+ * plus a `workflows` entry binding `AUTH_PURGE` and `AUTH_PURGE_DUE` to them and the daily cron —
28
+ * `docs/account-lifecycle.md` has the stanza. **The class is the adopter's, the body is the kit's**, the split
29
+ * `@pithy-sh/payments`' usage pass has, for the same reason.
30
+ *
31
+ * Each body finds the composed auth capability the way a Workflow that sends mail finds email: the class is
32
+ * exported from the entry that calls `createEntrypoint`, so the composition has happened in this isolate. The
33
+ * steps, the hooks, the config and the audit recorder are on the capability; the mail is email's own enqueue.
34
+ */
35
+ /** What a Workflow event hands a body. */
36
+ interface PurgeEvent {
37
+ readonly payload?: unknown;
38
+ readonly workflowName?: string;
39
+ readonly instanceId?: string;
40
+ }
41
+ /** Purge one account: every composed contribution, one step each, auth's last. See `./run.ts`. */
42
+ export declare function runAuthPurge(env: Record<string, unknown>, event: PurgeEvent, step: WorkflowStepLike, terminalError: TerminalErrorConstructor): Promise<PurgeOutcome>;
43
+ /** The daily pass: start a purge for every account past its window. See `./run.ts`. */
44
+ export declare function runAuthPurgeDue(env: Record<string, unknown>, event: PurgeEvent, step: WorkflowStepLike, terminalError: TerminalErrorConstructor): Promise<{
45
+ started: number;
46
+ }>;
47
+ /**
48
+ * How the daily pass starts one account's purge: under the id the deletion names (`./start.ts`), so a purge a hard
49
+ * deletion already started today is the same instance, not a second one. No `notify`: the deletion's own row
50
+ * carries it, and the purge reads it there.
51
+ *
52
+ * **It answers whether the purge is running**, and the pass counts that. A Worker that has not bound the purge,
53
+ * and a start that failed, each log the skip rather than throwing inside a cron nobody watches — tomorrow's pass
54
+ * starts it again — and answer `false`, so the pass does not report a purge it never started.
55
+ */
56
+ export declare function purgeStarter(env: Record<string, unknown>, log: Logger, now?: () => Date): PurgeDueRun["start"];
57
+ export {};
58
+ //# sourceMappingURL=workflow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../../src/purge/workflow.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAG/D,OAAO,KAAK,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAOrG,OAAO,EAAe,KAAK,WAAW,EAAE,KAAK,YAAY,EAAuC,MAAM,OAAO,CAAC;AAI9G;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,0CAA0C;AAC1C,UAAU,UAAU;IAClB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAyBD,kGAAkG;AAClG,wBAAsB,YAAY,CAChC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,KAAK,EAAE,UAAU,EACjB,IAAI,EAAE,gBAAgB,EACtB,aAAa,EAAE,wBAAwB,GACtC,OAAO,CAAC,YAAY,CAAC,CAMvB;AAED,uFAAuF;AACvF,wBAAsB,eAAe,CACnC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,KAAK,EAAE,UAAU,EACjB,IAAI,EAAE,gBAAgB,EACtB,aAAa,EAAE,wBAAwB,GACtC,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAM9B;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,GAAG,EAAE,MAAM,EACX,GAAG,GAAE,MAAM,IAAuB,GACjC,WAAW,CAAC,OAAO,CAAC,CAuBtB"}
@@ -0,0 +1,96 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import { authDatabase } from "../data/tables.js";
4
+ import { resolveDb } from "../http/resolve.js";
5
+ import { AUTH_PURGE_BINDING, AUTH_PURGE_KEY, AuthPurgeDueParams, AuthPurgeParams } from "./specs.js";
6
+ import { startPurgeInstance } from "./start.js";
7
+ import { isAuthCapability } from "../capability.js";
8
+ import { duePurgesOf, purgeOps, purgeUser, startDuePurges } from "./run.js";
9
+ import { messageOf } from "@pithy-sh/core/src/error/pithyError";
10
+ import { bindWorkflowContext, createWorkerLogger } from "@pithy-sh/core/src/logger/worker";
11
+ import { workflowBindingFor } from "@pithy-sh/core/src/workflow/dispatch";
12
+ import { composedCapability } from "@pithy-sh/core/src/capability/composition";
13
+ import { enqueueFromEnv } from "@pithy-sh/email/src/send/fromComposition";
14
+ //#region src/purge/workflow.ts
15
+ /** The lifecycle transitions' dependencies, for a run with no request: this env, and the composition's seams. */
16
+ function lifecycleFor(auth, env, log) {
17
+ const d1 = resolveDb(env, auth.authConfig.database);
18
+ return {
19
+ db: authDatabase(d1),
20
+ d1,
21
+ emit: auth.auditFor(env),
22
+ config: auth.authConfig,
23
+ hooks: auth.lifecycleHooks,
24
+ enqueueEmail: (input) => enqueueFromEnv(env, input),
25
+ log
26
+ };
27
+ }
28
+ /** This run's logger, bound to the instance an operator reads it under. */
29
+ function runLog(env, event, name) {
30
+ return bindWorkflowContext(createWorkerLogger({ name }), {
31
+ workflow: event.workflowName ?? name,
32
+ instance: event.instanceId ?? "unknown",
33
+ env: typeof env.ENVIRONMENT === "string" ? env.ENVIRONMENT : "unknown"
34
+ });
35
+ }
36
+ /** Purge one account: every composed contribution, one step each, auth's last. See `./run.ts`. */
37
+ async function runAuthPurge(env, event, step, terminalError) {
38
+ const params = AuthPurgeParams.parse(event.payload ?? {});
39
+ const auth = composedCapability("auth", isAuthCapability);
40
+ const lifecycle = lifecycleFor(auth, env, runLog(env, event, "auth:purge"));
41
+ return purgeUser({
42
+ steps: auth.purgeSteps,
43
+ env,
44
+ ops: purgeOps(lifecycle)
45
+ }, step, terminalError, params);
46
+ }
47
+ /** The daily pass: start a purge for every account past its window. See `./run.ts`. */
48
+ async function runAuthPurgeDue(env, event, step, terminalError) {
49
+ const params = AuthPurgeDueParams.parse(event.payload ?? {});
50
+ const auth = composedCapability("auth", isAuthCapability);
51
+ const log = runLog(env, event, "auth:purge-due");
52
+ const lifecycle = lifecycleFor(auth, env, log);
53
+ return startDuePurges({
54
+ due: duePurgesOf(lifecycle),
55
+ start: purgeStarter(env, log)
56
+ }, step, terminalError, params);
57
+ }
58
+ /**
59
+ * How the daily pass starts one account's purge: under the id the deletion names (`./start.ts`), so a purge a hard
60
+ * deletion already started today is the same instance, not a second one. No `notify`: the deletion's own row
61
+ * carries it, and the purge reads it there.
62
+ *
63
+ * **It answers whether the purge is running**, and the pass counts that. A Worker that has not bound the purge,
64
+ * and a start that failed, each log the skip rather than throwing inside a cron nobody watches — tomorrow's pass
65
+ * starts it again — and answer `false`, so the pass does not report a purge it never started.
66
+ */
67
+ function purgeStarter(env, log, now = () => /* @__PURE__ */ new Date()) {
68
+ return async (due) => {
69
+ const binding = workflowBindingFor(env, AUTH_PURGE_BINDING);
70
+ if (!binding) {
71
+ log.warn("workflow skipped", {
72
+ workflow: AUTH_PURGE_KEY,
73
+ binding: AUTH_PURGE_BINDING,
74
+ reason: "binding absent — the purge Workflow is not bound"
75
+ });
76
+ return false;
77
+ }
78
+ try {
79
+ await startPurgeInstance(binding, {
80
+ userId: due.userId,
81
+ deletedAt: due.deletedAt,
82
+ at: now()
83
+ });
84
+ return true;
85
+ } catch (error) {
86
+ log.warn("workflow skipped", {
87
+ workflow: AUTH_PURGE_KEY,
88
+ binding: AUTH_PURGE_BINDING,
89
+ reason: messageOf(error)
90
+ });
91
+ return false;
92
+ }
93
+ };
94
+ }
95
+ //#endregion
96
+ export { purgeStarter, runAuthPurge, runAuthPurgeDue };
@@ -0,0 +1,10 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import type { D1Database } from "@cloudflare/workers-types";
4
+ /** Every table a footprint writes to, with the column that names the person in it. */
5
+ export declare const FOOTPRINT_TABLES: readonly [readonly ["pithy_auth_users", "id"], readonly ["pithy_auth_sessions", "user_id"], readonly ["pithy_auth_accounts", "user_id"], readonly ["pithy_auth_devices", "user_id"], readonly ["pithy_auth_rotated_tokens", "user_id"]];
6
+ /** Write a full footprint for one account: a user, a session, a provider link, a device, a spent token, two pending codes. */
7
+ export declare function seedAccountFootprint(d1: D1Database, userId: string, email?: string): Promise<void>;
8
+ /** How many rows one account still holds in each footprint table, and in the pending codes for its address. */
9
+ export declare function footprintCounts(d1: D1Database, userId: string, email?: string): Promise<Record<string, number>>;
10
+ //# sourceMappingURL=accountFootprint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accountFootprint.d.ts","sourceRoot":"","sources":["../../src/test-utils/accountFootprint.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAW5D,sFAAsF;AACtF,eAAO,MAAM,gBAAgB,sBAC1B,kBAAkB,EAAE,IAAI,aACxB,qBAAqB,EAAE,SAAS,aAChC,qBAAqB,EAAE,SAAS,aAChC,oBAAoB,EAAE,SAAS,aAC/B,2BAA2B,EAAE,SAAS,EAC/B,CAAC;AAEX,8HAA8H;AAC9H,wBAAsB,oBAAoB,CACxC,EAAE,EAAE,UAAU,EACd,MAAM,EAAE,MAAM,EACd,KAAK,SAAuB,GAC3B,OAAO,CAAC,IAAI,CAAC,CA2Cf;AAED,+GAA+G;AAC/G,wBAAsB,eAAe,CAAC,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,SAAuB,mCAoBjG"}
@@ -0,0 +1,44 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ //#region src/test-utils/accountFootprint.ts
4
+ /**
5
+ * One account's rows across every `pithy_auth_*` table that keys a row to a person — what a purge must erase
6
+ * and an export must read (#622). For the workers suites; the tables are the real ones, written by raw SQL in
7
+ * the shapes the kit's own writers produce, so a test reads back exactly what production would hold.
8
+ */
9
+ const AT = "2026-10-01T00:00:00.000Z";
10
+ const AT_MS = Date.parse(AT);
11
+ /** Every table a footprint writes to, with the column that names the person in it. */
12
+ const FOOTPRINT_TABLES = [
13
+ ["pithy_auth_users", "id"],
14
+ ["pithy_auth_sessions", "user_id"],
15
+ ["pithy_auth_accounts", "user_id"],
16
+ ["pithy_auth_devices", "user_id"],
17
+ ["pithy_auth_rotated_tokens", "user_id"]
18
+ ];
19
+ /** Write a full footprint for one account: a user, a session, a provider link, a device, a spent token, two pending codes. */
20
+ async function seedAccountFootprint(d1, userId, email = `${userId}@test.com`) {
21
+ await d1.batch([
22
+ d1.prepare("insert into pithy_auth_users (id, name, email, email_verified, locale, created_at, updated_at) values (?, 'Sam', ?, 1, null, ?, ?)").bind(userId, email, AT, AT),
23
+ d1.prepare("insert into pithy_auth_sessions (id, expires_at, token, created_at, updated_at, ip_address, user_agent, user_id, device_id) values (?, ?, ?, ?, ?, '203.0.113.9', 'Pithy/1.0', ?, ?)").bind(`s-${userId}`, "2099-01-01T00:00:00.000Z", `token-${userId}`, AT, AT, userId, `d-${userId}`),
24
+ d1.prepare("insert into pithy_auth_accounts (id, account_id, provider_id, user_id, access_token, refresh_token, created_at, updated_at) values (?, ?, 'google', ?, ?, ?, ?, ?)").bind(`a-${userId}`, `g-${userId}`, userId, `access-${userId}`, `refresh-${userId}`, AT, AT),
25
+ d1.prepare("insert into pithy_auth_devices (id, user_id, platform, push_token, last_ip, last_seen_at, created_at) values (?, ?, 'ios', ?, '203.0.113.9', ?, ?)").bind(`d-${userId}`, userId, `push-${userId}`, AT_MS, AT_MS),
26
+ d1.prepare("insert into pithy_auth_rotated_tokens (token, family_id, user_id, rotated_at) values (?, ?, ?, ?)").bind(`spent-${userId}`, `f-${userId}`, userId, AT_MS),
27
+ d1.prepare("insert into pithy_auth_verifications (id, identifier, value, expires_at, created_at, updated_at) values (?, ?, '123456:0', ?, ?, ?)").bind(`otp-${userId}`, `sign-in-otp-${email}`, "2099-01-01T00:00:00.000Z", AT, AT),
28
+ d1.prepare("insert into pithy_auth_verifications (id, identifier, value, expires_at, created_at, updated_at) values (?, ?, ?, ?, ?, ?)").bind(`link-${userId}`, `magic-link-${userId}`, JSON.stringify({
29
+ email,
30
+ name: "",
31
+ attempt: 0
32
+ }), "2099-01-01T00:00:00.000Z", AT, AT)
33
+ ]);
34
+ }
35
+ /** How many rows one account still holds in each footprint table, and in the pending codes for its address. */
36
+ async function footprintCounts(d1, userId, email = `${userId}@test.com`) {
37
+ const counts = {};
38
+ for (const [table, column] of FOOTPRINT_TABLES) counts[table] = (await d1.prepare(`select count(*) as n from ${table} where ${column} = ?`).bind(userId).first())?.n ?? 0;
39
+ counts.pithy_auth_verifications = (await d1.prepare("select count(*) as n from pithy_auth_verifications where identifier = ? or instr(value, ?) > 0").bind(`sign-in-otp-${email}`, JSON.stringify(email)).first())?.n ?? 0;
40
+ counts.pithy_auth_user_lifecycle = (await d1.prepare("select count(*) as n from pithy_auth_user_lifecycle where user_id = ?").bind(userId).first())?.n ?? 0;
41
+ return counts;
42
+ }
43
+ //#endregion
44
+ export { FOOTPRINT_TABLES, footprintCounts, seedAccountFootprint };
@@ -130,6 +130,27 @@ export declare const LIVE_REGISTRY: {
130
130
  readonly documentation: "https://github.com/settings/developers";
131
131
  };
132
132
  };
133
+ "auth-microsoft-credentials": {
134
+ readonly backend: "d1";
135
+ readonly scope: "environment";
136
+ readonly rotatable: true;
137
+ readonly valueType: "json";
138
+ readonly schema: import("zod").ZodObject<{
139
+ clientId: import("zod").ZodString;
140
+ clientSecret: import("zod").ZodString;
141
+ tenantId: import("zod").ZodString;
142
+ }, import("zod/v4/core").$strip>;
143
+ readonly origin: {
144
+ readonly kind: "obtained";
145
+ readonly issuer: "microsoft";
146
+ readonly documentation: "https://entra.microsoft.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade";
147
+ };
148
+ readonly rotation: {
149
+ readonly kind: "manual";
150
+ readonly issuer: "microsoft";
151
+ readonly documentation: "https://entra.microsoft.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade";
152
+ };
153
+ };
133
154
  "turnstile-secret-keys": {
134
155
  readonly backend: "d1";
135
156
  readonly scope: "environment";
@@ -1 +1 @@
1
- {"version":3,"file":"liveApp.d.ts","sourceRoot":"","sources":["../../src/test-utils/liveApp.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAuB3E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,iHAAiH;AACjH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAA0D,CAAC;AAErF,4GAA4G;AAC5G,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC;AAwBD,4GAA4G;AAC5G,MAAM,WAAW,aAAa;IAC5B,qFAAqF;IACrF,QAAQ,EAAE,MAAM,CAAC;IACjB,6BAA6B;IAC7B,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,uGAAuG;AACvG,MAAM,WAAW,cAAc;IAC7B;;;;;;;OAOG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB,mFAAmF;IACnF,MAAM,CAAC,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;IAChE,yGAAyG;IACzG,SAAS,CAAC,EAAE;QAAE,IAAI,EAAE,SAAS,GAAG,WAAW,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;IAC7E;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,mFAAmF;AACnF,MAAM,WAAW,OAAO;IACtB,sGAAsG;IACtG,MAAM,EAAE,MAAM,CAAC;IACf,uGAAu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AE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;IAChE,yGAAyG;IACzG,SAAS,CAAC,EAAE;QAAE,IAAI,EAAE,SAAS,GAAG,WAAW,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;IAC7E;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,mFAAmF;AACnF,MAAM,WAAW,OAAO;IACtB,sGAAsG;IACtG,MAAM,EAAE,MAAM,CAAC;IACf,uGAAuG;IACvG,QAAQ,EAAE,MAAM,CAAC;IACjB,mGAAmG;IACnG,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IACtC,mDAAmD;IACnD,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,0GAA0G;IAC1G,QAAQ,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;IACrC;;;;;;;;;;OAUG;IACH,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC9C,yFAAyF;IACzF,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAyF5E"}
@@ -60,6 +60,7 @@ const TABLES = [
60
60
  "pithy_auth_jwks",
61
61
  "pithy_auth_rate_limit",
62
62
  "pithy_auth_rotated_tokens",
63
+ "pithy_auth_user_lifecycle",
63
64
  "pithy_auth_sessions",
64
65
  "pithy_auth_users",
65
66
  "pithy_auth_verifications",
@@ -125,6 +125,27 @@ export declare const SCOPED_REGISTRY: {
125
125
  readonly documentation: "https://github.com/settings/developers";
126
126
  };
127
127
  };
128
+ "auth-microsoft-credentials": {
129
+ readonly backend: "d1";
130
+ readonly scope: "environment";
131
+ readonly rotatable: true;
132
+ readonly valueType: "json";
133
+ readonly schema: import("zod").ZodObject<{
134
+ clientId: import("zod").ZodString;
135
+ clientSecret: import("zod").ZodString;
136
+ tenantId: import("zod").ZodString;
137
+ }, import("zod/v4/core").$strip>;
138
+ readonly origin: {
139
+ readonly kind: "obtained";
140
+ readonly issuer: "microsoft";
141
+ readonly documentation: "https://entra.microsoft.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade";
142
+ };
143
+ readonly rotation: {
144
+ readonly kind: "manual";
145
+ readonly issuer: "microsoft";
146
+ readonly documentation: "https://entra.microsoft.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade";
147
+ };
148
+ };
128
149
  "email-link-signing-key": {
129
150
  readonly backend: "cf-secrets-store";
130
151
  readonly scope: "environment";
@@ -1 +1 @@
1
- {"version":3,"file":"scopedBackend.d.ts","sourceRoot":"","sources":["../../src/test-utils/scopedBackend.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAM5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,KAAK,aAAa,EAAe,MAAM,iDAAiD,CAAC;AAClG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAQlD;;;;;;;;;;GAUG;AAEH,iGAAiG;AACjG,eAAO,MAAM,qBAAqB,4CAA4C,CAAC;AAE/E,6FAA6F;AAC7F,eAAO,MAAM,aAAa,qBAAqB,CAAC;AAEhD,+FAA+F;AAC/F,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAAsD,CAAC;AAEnF,gHAAgH;AAChH,eAAO,MAAM,cAAc,EAAE,aAAa,CAAC,OAAO,eAAe,CAOhE,CAAC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