@pithy-sh/auth 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (246) hide show
  1. package/README.md +30 -2
  2. package/dist/audit/actions.d.ts +39 -0
  3. package/dist/audit/actions.d.ts.map +1 -1
  4. package/dist/audit/actions.js +40 -1
  5. package/dist/audit/emit.d.ts +34 -0
  6. package/dist/audit/emit.d.ts.map +1 -1
  7. package/dist/audit/emit.js +47 -1
  8. package/dist/audit/evidence.d.ts +8 -2
  9. package/dist/audit/evidence.d.ts.map +1 -1
  10. package/dist/capability.d.ts +31 -11
  11. package/dist/capability.d.ts.map +1 -1
  12. package/dist/capability.js +38 -5
  13. package/dist/client/api.d.ts +55 -12
  14. package/dist/client/api.d.ts.map +1 -1
  15. package/dist/client/api.js +57 -18
  16. package/dist/client/bearer.d.ts +110 -0
  17. package/dist/client/bearer.d.ts.map +1 -0
  18. package/dist/client/bearer.js +265 -0
  19. package/dist/client/handoff.d.ts +77 -0
  20. package/dist/client/handoff.d.ts.map +1 -0
  21. package/dist/client/handoff.js +119 -0
  22. package/dist/client/mcp.d.ts +70 -0
  23. package/dist/client/mcp.d.ts.map +1 -0
  24. package/dist/client/mcp.js +65 -0
  25. package/dist/data/betterAuth.d.ts +3 -2
  26. package/dist/data/betterAuth.d.ts.map +1 -1
  27. package/dist/data/betterAuth.js +5 -3
  28. package/dist/data/kitFields.d.ts +5 -0
  29. package/dist/data/kitFields.d.ts.map +1 -1
  30. package/dist/data/kitFields.js +5 -0
  31. package/dist/data/tables.d.ts +25 -4
  32. package/dist/data/tables.d.ts.map +1 -1
  33. package/dist/data/tables.js +5 -3
  34. package/dist/data/userLifecycle.d.ts +9 -0
  35. package/dist/data/userLifecycle.d.ts.map +1 -1
  36. package/dist/data/userLifecycle.js +6 -2
  37. package/dist/data/verificationOutcome.d.ts +53 -0
  38. package/dist/data/verificationOutcome.d.ts.map +1 -0
  39. package/dist/data/verificationOutcome.js +50 -0
  40. package/dist/email/send.js +6 -2
  41. package/dist/http/adminRoutes.d.ts.map +1 -1
  42. package/dist/http/adminRoutes.js +56 -10
  43. package/dist/http/csrf.d.ts.map +1 -1
  44. package/dist/http/csrf.js +2 -1
  45. package/dist/http/guards.d.ts +15 -11
  46. package/dist/http/guards.d.ts.map +1 -1
  47. package/dist/http/guards.js +46 -11
  48. package/dist/http/handoff.d.ts +76 -0
  49. package/dist/http/handoff.d.ts.map +1 -0
  50. package/dist/http/handoff.js +316 -0
  51. package/dist/http/middleware.d.ts +12 -0
  52. package/dist/http/middleware.d.ts.map +1 -1
  53. package/dist/http/middleware.js +25 -4
  54. package/dist/http/resolve.d.ts.map +1 -1
  55. package/dist/http/resolve.js +9 -3
  56. package/dist/http/responses.d.ts +142 -0
  57. package/dist/http/responses.d.ts.map +1 -1
  58. package/dist/http/responses.js +66 -10
  59. package/dist/http/routes.d.ts +2 -0
  60. package/dist/http/routes.d.ts.map +1 -1
  61. package/dist/http/routes.js +35 -4
  62. package/dist/http/schemas.d.ts +57 -0
  63. package/dist/http/schemas.d.ts.map +1 -1
  64. package/dist/http/schemas.js +44 -1
  65. package/dist/http/views.d.ts +22 -2
  66. package/dist/http/views.d.ts.map +1 -1
  67. package/dist/http/views.js +40 -4
  68. package/dist/index.d.ts +2 -0
  69. package/dist/index.d.ts.map +1 -1
  70. package/dist/index.js +4 -2
  71. package/dist/instance/auth.d.ts +148 -10
  72. package/dist/instance/auth.d.ts.map +1 -1
  73. package/dist/instance/auth.js +86 -41
  74. package/dist/instance/plugins.d.ts +6 -0
  75. package/dist/instance/plugins.d.ts.map +1 -1
  76. package/dist/instance/plugins.js +14 -1
  77. package/dist/ledger/read.d.ts +53 -0
  78. package/dist/ledger/read.d.ts.map +1 -0
  79. package/dist/ledger/read.js +85 -0
  80. package/dist/ledger/record.d.ts +35 -0
  81. package/dist/ledger/record.d.ts.map +1 -0
  82. package/dist/ledger/record.js +98 -0
  83. package/dist/lifecycle/erasure.d.ts +9 -0
  84. package/dist/lifecycle/erasure.d.ts.map +1 -0
  85. package/dist/lifecycle/erasure.js +96 -0
  86. package/dist/lifecycle/inactivity.d.ts +19 -0
  87. package/dist/lifecycle/inactivity.d.ts.map +1 -0
  88. package/dist/lifecycle/inactivity.js +28 -0
  89. package/dist/lifecycle/transitions.d.ts +22 -1
  90. package/dist/lifecycle/transitions.d.ts.map +1 -1
  91. package/dist/lifecycle/transitions.js +51 -4
  92. package/dist/mcp/argumentClass.d.ts +51 -0
  93. package/dist/mcp/argumentClass.d.ts.map +1 -0
  94. package/dist/mcp/argumentClass.js +69 -0
  95. package/dist/mcp/capability.d.ts +50 -0
  96. package/dist/mcp/capability.d.ts.map +1 -0
  97. package/dist/mcp/capability.js +140 -0
  98. package/dist/mcp/clientMetadata.d.ts +40 -0
  99. package/dist/mcp/clientMetadata.d.ts.map +1 -0
  100. package/dist/mcp/clientMetadata.js +68 -0
  101. package/dist/mcp/consent.d.ts +49 -0
  102. package/dist/mcp/consent.d.ts.map +1 -0
  103. package/dist/mcp/consent.js +69 -0
  104. package/dist/mcp/dispatch.d.ts +35 -0
  105. package/dist/mcp/dispatch.d.ts.map +1 -0
  106. package/dist/mcp/dispatch.js +135 -0
  107. package/dist/mcp/floor.d.ts +37 -0
  108. package/dist/mcp/floor.d.ts.map +1 -0
  109. package/dist/mcp/floor.js +41 -0
  110. package/dist/mcp/host.d.ts +34 -0
  111. package/dist/mcp/host.d.ts.map +1 -0
  112. package/dist/mcp/host.js +2 -0
  113. package/dist/mcp/http/redirectList.d.ts +9 -0
  114. package/dist/mcp/http/redirectList.d.ts.map +1 -0
  115. package/dist/mcp/http/redirectList.js +24 -0
  116. package/dist/mcp/http/responses.d.ts +143 -0
  117. package/dist/mcp/http/responses.d.ts.map +1 -0
  118. package/dist/mcp/http/responses.js +83 -0
  119. package/dist/mcp/http/routes.d.ts +28 -0
  120. package/dist/mcp/http/routes.d.ts.map +1 -0
  121. package/dist/mcp/http/routes.js +517 -0
  122. package/dist/mcp/http/schemas.d.ts +24 -0
  123. package/dist/mcp/http/schemas.d.ts.map +1 -0
  124. package/dist/mcp/http/schemas.js +18 -0
  125. package/dist/mcp/marker.d.ts +15 -0
  126. package/dist/mcp/marker.d.ts.map +1 -0
  127. package/dist/mcp/marker.js +15 -0
  128. package/dist/mcp/provider.d.ts +78 -0
  129. package/dist/mcp/provider.d.ts.map +1 -0
  130. package/dist/mcp/provider.js +108 -0
  131. package/dist/mcp/purge.d.ts +15 -0
  132. package/dist/mcp/purge.d.ts.map +1 -0
  133. package/dist/mcp/purge.js +31 -0
  134. package/dist/mcp/rpc.d.ts +79 -0
  135. package/dist/mcp/rpc.d.ts.map +1 -0
  136. package/dist/mcp/rpc.js +103 -0
  137. package/dist/mcp/toolAudit.d.ts +76 -0
  138. package/dist/mcp/toolAudit.d.ts.map +1 -0
  139. package/dist/mcp/toolAudit.js +86 -0
  140. package/dist/migrations/0006_verification_outcomes.d.ts +15 -0
  141. package/dist/migrations/0006_verification_outcomes.d.ts.map +1 -0
  142. package/dist/migrations/0006_verification_outcomes.js +35 -0
  143. package/dist/migrations/0007_erasure_record.d.ts +17 -0
  144. package/dist/migrations/0007_erasure_record.d.ts.map +1 -0
  145. package/dist/migrations/0007_erasure_record.js +36 -0
  146. package/dist/migrations/0008_last_active.d.ts +15 -0
  147. package/dist/migrations/0008_last_active.d.ts.map +1 -0
  148. package/dist/migrations/0008_last_active.js +29 -0
  149. package/dist/migrations/set.d.ts +4 -1
  150. package/dist/migrations/set.d.ts.map +1 -1
  151. package/dist/migrations/set.js +8 -2
  152. package/dist/peer.d.ts +3 -2
  153. package/dist/peer.d.ts.map +1 -1
  154. package/dist/processing/activities.d.ts +6 -0
  155. package/dist/processing/activities.d.ts.map +1 -0
  156. package/dist/processing/activities.js +12 -0
  157. package/dist/purge/contribution.d.ts +20 -5
  158. package/dist/purge/contribution.d.ts.map +1 -1
  159. package/dist/purge/contribution.js +20 -6
  160. package/dist/purge/run.d.ts +75 -5
  161. package/dist/purge/run.d.ts.map +1 -1
  162. package/dist/purge/run.js +117 -14
  163. package/dist/purge/workflow.d.ts +15 -2
  164. package/dist/purge/workflow.d.ts.map +1 -1
  165. package/dist/purge/workflow.js +51 -7
  166. package/dist/test-utils/accountFootprint.d.ts +5 -2
  167. package/dist/test-utils/accountFootprint.d.ts.map +1 -1
  168. package/dist/test-utils/accountFootprint.js +7 -2
  169. package/dist/test-utils/liveApp.d.ts +6 -0
  170. package/dist/test-utils/liveApp.d.ts.map +1 -1
  171. package/dist/test-utils/liveApp.js +7 -2
  172. package/dist/token/handoff.d.ts +80 -0
  173. package/dist/token/handoff.d.ts.map +1 -0
  174. package/dist/token/handoff.js +136 -0
  175. package/dist/version.generated.d.ts +1 -1
  176. package/dist/version.generated.js +1 -1
  177. package/docs/account-lifecycle.md +59 -7
  178. package/docs/apple-signin.md +32 -4
  179. package/docs/facebook-oauth.md +2 -2
  180. package/docs/github-oauth.md +2 -2
  181. package/docs/google-oauth.md +9 -7
  182. package/docs/microsoft-oauth.md +2 -2
  183. package/package.json +11 -5
  184. package/pithy.manifest.json +2 -2
  185. package/pithy.mcp.manifest.json +36 -0
  186. package/src/audit/actions.ts +39 -0
  187. package/src/audit/emit.ts +63 -0
  188. package/src/audit/evidence.ts +8 -4
  189. package/src/capability.ts +80 -23
  190. package/src/client/api.ts +69 -19
  191. package/src/client/bearer.ts +388 -0
  192. package/src/client/handoff.ts +172 -0
  193. package/src/client/mcp.ts +140 -0
  194. package/src/data/betterAuth.ts +8 -4
  195. package/src/data/kitFields.ts +2 -0
  196. package/src/data/tables.ts +4 -2
  197. package/src/data/userLifecycle.ts +15 -3
  198. package/src/data/verificationOutcome.ts +86 -0
  199. package/src/email/send.ts +2 -2
  200. package/src/http/adminRoutes.ts +68 -3
  201. package/src/http/csrf.ts +4 -1
  202. package/src/http/guards.ts +48 -11
  203. package/src/http/handoff.ts +350 -0
  204. package/src/http/middleware.ts +29 -3
  205. package/src/http/resolve.ts +25 -25
  206. package/src/http/responses.ts +134 -8
  207. package/src/http/routes.ts +63 -4
  208. package/src/http/schemas.ts +85 -0
  209. package/src/http/views.ts +46 -2
  210. package/src/index.ts +2 -0
  211. package/src/instance/auth.ts +51 -1
  212. package/src/instance/plugins.ts +20 -2
  213. package/src/ledger/read.ts +133 -0
  214. package/src/ledger/record.ts +198 -0
  215. package/src/lifecycle/erasure.ts +118 -0
  216. package/src/lifecycle/inactivity.ts +56 -0
  217. package/src/lifecycle/transitions.ts +75 -5
  218. package/src/mcp/argumentClass.ts +112 -0
  219. package/src/mcp/capability.ts +194 -0
  220. package/src/mcp/clientMetadata.ts +81 -0
  221. package/src/mcp/consent.ts +95 -0
  222. package/src/mcp/dispatch.ts +154 -0
  223. package/src/mcp/floor.ts +62 -0
  224. package/src/mcp/host.ts +36 -0
  225. package/src/mcp/http/redirectList.ts +26 -0
  226. package/src/mcp/http/responses.ts +157 -0
  227. package/src/mcp/http/routes.ts +635 -0
  228. package/src/mcp/http/schemas.ts +37 -0
  229. package/src/mcp/marker.ts +18 -0
  230. package/src/mcp/provider.ts +151 -0
  231. package/src/mcp/purge.ts +39 -0
  232. package/src/mcp/rpc.ts +135 -0
  233. package/src/mcp/toolAudit.ts +132 -0
  234. package/src/migrations/0006_verification_outcomes.ts +51 -0
  235. package/src/migrations/0007_erasure_record.ts +43 -0
  236. package/src/migrations/0008_last_active.ts +30 -0
  237. package/src/migrations/set.ts +7 -1
  238. package/src/processing/activities.ts +14 -0
  239. package/src/purge/contribution.ts +37 -10
  240. package/src/purge/run.ts +179 -16
  241. package/src/purge/workflow.ts +65 -7
  242. package/src/seeds/example.ts +2 -2
  243. package/src/test-utils/accountFootprint.ts +10 -1
  244. package/src/test-utils/liveApp.ts +10 -1
  245. package/src/token/handoff.ts +180 -0
  246. package/src/version.generated.ts +1 -1
@@ -218,6 +218,37 @@ export declare function makeAuth<const Plugins extends readonly BetterAuthPlugin
218
218
  throw: true;
219
219
  };
220
220
  databaseHooks: {
221
+ /**
222
+ * The verification ledger's two hooks on Better Auth's own verification rows (#829).
223
+ *
224
+ * **`create.after` remembers the row** — a sign-in link or code about to be sent, OAuth state, or a wrong
225
+ * code re-created with one more attempt counted; `../ledger/record.ts` tells them apart by what follows.
226
+ * **`delete.before` remembers the row about to be consumed**, and changes nothing: it returns nothing, so it
227
+ * never vetoes, and it is not a `delete.after` because claiming a verification removal the way
228
+ * `claimedDelete` does would delete the row before the consume could read it.
229
+ */
230
+ verification: {
231
+ create: {
232
+ after: (verification: {
233
+ id: string;
234
+ createdAt: Date;
235
+ updatedAt: Date;
236
+ value: string;
237
+ expiresAt: Date;
238
+ identifier: string;
239
+ } & Record<string, unknown>, ctx: import("better-auth").GenericEndpointContext | null) => Promise<void>;
240
+ };
241
+ delete: {
242
+ before: (verification: {
243
+ id: string;
244
+ createdAt: Date;
245
+ updatedAt: Date;
246
+ value: string;
247
+ expiresAt: Date;
248
+ identifier: string;
249
+ } & Record<string, unknown>, ctx: import("better-auth").GenericEndpointContext | null) => Promise<void>;
250
+ };
251
+ };
221
252
  user: {
222
253
  create: {
223
254
  before: (user: {
@@ -359,6 +390,39 @@ export declare function makeAuth<const Plugins extends readonly BetterAuthPlugin
359
390
  authenticatedAt: Date | null;
360
391
  };
361
392
  }>;
393
+ /**
394
+ * Stamp the sign-in link or code this session was made from as used (#829), and name the account a
395
+ * sign-up just created. Only a row consumed earlier in this same request is stamped, so a token
396
+ * refresh, an OAuth callback and every other session stamp nothing — see `../ledger/record.ts`.
397
+ * After, because the session exists by now: a sign-in the `before` above refused stamps nothing.
398
+ */
399
+ after: (session: {
400
+ id: string;
401
+ createdAt: Date;
402
+ updatedAt: Date;
403
+ userId: string;
404
+ expiresAt: Date;
405
+ token: string;
406
+ ipAddress?: string | null | undefined;
407
+ userAgent?: string | null | undefined;
408
+ } & Record<string, unknown>, ctx: import("better-auth").GenericEndpointContext | null) => Promise<void>;
409
+ };
410
+ update: {
411
+ /**
412
+ * The activity clock again, for a session that stays open. Better Auth slides a session forward in place
413
+ * once `updateAge` has passed, and that refresh is an update, never a create, so the hook above never
414
+ * sees it. Without this, signing out after weeks of use on one session would read as weeks idle.
415
+ */
416
+ after: (session: {
417
+ id: string;
418
+ createdAt: Date;
419
+ updatedAt: Date;
420
+ userId: string;
421
+ expiresAt: Date;
422
+ token: string;
423
+ ipAddress?: string | null | undefined;
424
+ userAgent?: string | null | undefined;
425
+ } & Record<string, unknown>) => Promise<void>;
362
426
  };
363
427
  /**
364
428
  * Tell whoever keyed state on this session that it has gone, and record that it did.
@@ -452,6 +516,11 @@ export declare function makeAuth<const Plugins extends readonly BetterAuthPlugin
452
516
  readonly required: false;
453
517
  readonly input: false;
454
518
  };
519
+ readonly lastActiveAt: {
520
+ readonly type: "number";
521
+ readonly required: false;
522
+ readonly input: false;
523
+ };
455
524
  readonly locale: {
456
525
  readonly type: "string";
457
526
  readonly required: false;
@@ -558,11 +627,11 @@ export declare function makeAuth<const Plugins extends readonly BetterAuthPlugin
558
627
  handler: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<void>>;
559
628
  }[];
560
629
  };
561
- options: import("better-auth/plugins/bearer").BearerOptions | undefined;
630
+ options: import("better-auth/plugins").BearerOptions | undefined;
562
631
  }, {
563
632
  id: "jwt";
564
633
  version: string;
565
- options: NoInfer<import("better-auth/plugins/jwt").JwtOptions>;
634
+ options: NoInfer<import("better-auth/plugins").JwtOptions>;
566
635
  init(ctx: import("better-auth").AuthContext): {
567
636
  context: {
568
637
  sessionConfig: {
@@ -713,7 +782,7 @@ export declare function makeAuth<const Plugins extends readonly BetterAuthPlugin
713
782
  $Infer: {
714
783
  body: {
715
784
  payload: import("better-auth").JWTPayload;
716
- overrideOptions?: import("better-auth/plugins/jwt").JwtOptions | undefined;
785
+ overrideOptions?: import("better-auth/plugins").JwtOptions | undefined;
717
786
  };
718
787
  };
719
788
  };
@@ -891,7 +960,7 @@ export declare function makeAuth<const Plugins extends readonly BetterAuthPlugin
891
960
  window: number;
892
961
  max: number;
893
962
  }[];
894
- options: import("better-auth/plugins/magic-link").MagicLinkOptions;
963
+ options: import("better-auth/plugins").MagicLinkOptions;
895
964
  }, {
896
965
  id: "email-otp";
897
966
  version: string;
@@ -1418,7 +1487,7 @@ export declare function makeAuth<const Plugins extends readonly BetterAuthPlugin
1418
1487
  window: number;
1419
1488
  max: number;
1420
1489
  })[];
1421
- options: import("better-auth/plugins/email-otp").EmailOTPOptions;
1490
+ options: import("better-auth/plugins").EmailOTPOptions;
1422
1491
  $ERROR_CODES: {
1423
1492
  OTP_EXPIRED: import("better-auth").RawError<"OTP_EXPIRED">;
1424
1493
  INVALID_OTP: import("better-auth").RawError<"INVALID_OTP">;
@@ -1449,6 +1518,37 @@ export declare function makeAuth<const Plugins extends readonly BetterAuthPlugin
1449
1518
  throw: true;
1450
1519
  };
1451
1520
  databaseHooks: {
1521
+ /**
1522
+ * The verification ledger's two hooks on Better Auth's own verification rows (#829).
1523
+ *
1524
+ * **`create.after` remembers the row** — a sign-in link or code about to be sent, OAuth state, or a wrong
1525
+ * code re-created with one more attempt counted; `../ledger/record.ts` tells them apart by what follows.
1526
+ * **`delete.before` remembers the row about to be consumed**, and changes nothing: it returns nothing, so it
1527
+ * never vetoes, and it is not a `delete.after` because claiming a verification removal the way
1528
+ * `claimedDelete` does would delete the row before the consume could read it.
1529
+ */
1530
+ verification: {
1531
+ create: {
1532
+ after: (verification: {
1533
+ id: string;
1534
+ createdAt: Date;
1535
+ updatedAt: Date;
1536
+ value: string;
1537
+ expiresAt: Date;
1538
+ identifier: string;
1539
+ } & Record<string, unknown>, ctx: import("better-auth").GenericEndpointContext | null) => Promise<void>;
1540
+ };
1541
+ delete: {
1542
+ before: (verification: {
1543
+ id: string;
1544
+ createdAt: Date;
1545
+ updatedAt: Date;
1546
+ value: string;
1547
+ expiresAt: Date;
1548
+ identifier: string;
1549
+ } & Record<string, unknown>, ctx: import("better-auth").GenericEndpointContext | null) => Promise<void>;
1550
+ };
1551
+ };
1452
1552
  user: {
1453
1553
  create: {
1454
1554
  before: (user: {
@@ -1590,6 +1690,39 @@ export declare function makeAuth<const Plugins extends readonly BetterAuthPlugin
1590
1690
  authenticatedAt: Date | null;
1591
1691
  };
1592
1692
  }>;
1693
+ /**
1694
+ * Stamp the sign-in link or code this session was made from as used (#829), and name the account a
1695
+ * sign-up just created. Only a row consumed earlier in this same request is stamped, so a token
1696
+ * refresh, an OAuth callback and every other session stamp nothing — see `../ledger/record.ts`.
1697
+ * After, because the session exists by now: a sign-in the `before` above refused stamps nothing.
1698
+ */
1699
+ after: (session: {
1700
+ id: string;
1701
+ createdAt: Date;
1702
+ updatedAt: Date;
1703
+ userId: string;
1704
+ expiresAt: Date;
1705
+ token: string;
1706
+ ipAddress?: string | null | undefined;
1707
+ userAgent?: string | null | undefined;
1708
+ } & Record<string, unknown>, ctx: import("better-auth").GenericEndpointContext | null) => Promise<void>;
1709
+ };
1710
+ update: {
1711
+ /**
1712
+ * The activity clock again, for a session that stays open. Better Auth slides a session forward in place
1713
+ * once `updateAge` has passed, and that refresh is an update, never a create, so the hook above never
1714
+ * sees it. Without this, signing out after weeks of use on one session would read as weeks idle.
1715
+ */
1716
+ after: (session: {
1717
+ id: string;
1718
+ createdAt: Date;
1719
+ updatedAt: Date;
1720
+ userId: string;
1721
+ expiresAt: Date;
1722
+ token: string;
1723
+ ipAddress?: string | null | undefined;
1724
+ userAgent?: string | null | undefined;
1725
+ } & Record<string, unknown>) => Promise<void>;
1593
1726
  };
1594
1727
  /**
1595
1728
  * Tell whoever keyed state on this session that it has gone, and record that it did.
@@ -1683,6 +1816,11 @@ export declare function makeAuth<const Plugins extends readonly BetterAuthPlugin
1683
1816
  readonly required: false;
1684
1817
  readonly input: false;
1685
1818
  };
1819
+ readonly lastActiveAt: {
1820
+ readonly type: "number";
1821
+ readonly required: false;
1822
+ readonly input: false;
1823
+ };
1686
1824
  readonly locale: {
1687
1825
  readonly type: "string";
1688
1826
  readonly required: false;
@@ -1789,11 +1927,11 @@ export declare function makeAuth<const Plugins extends readonly BetterAuthPlugin
1789
1927
  handler: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<void>>;
1790
1928
  }[];
1791
1929
  };
1792
- options: import("better-auth/plugins/bearer").BearerOptions | undefined;
1930
+ options: import("better-auth/plugins").BearerOptions | undefined;
1793
1931
  }, {
1794
1932
  id: "jwt";
1795
1933
  version: string;
1796
- options: NoInfer<import("better-auth/plugins/jwt").JwtOptions>;
1934
+ options: NoInfer<import("better-auth/plugins").JwtOptions>;
1797
1935
  init(ctx: import("better-auth").AuthContext): {
1798
1936
  context: {
1799
1937
  sessionConfig: {
@@ -1944,7 +2082,7 @@ export declare function makeAuth<const Plugins extends readonly BetterAuthPlugin
1944
2082
  $Infer: {
1945
2083
  body: {
1946
2084
  payload: import("better-auth").JWTPayload;
1947
- overrideOptions?: import("better-auth/plugins/jwt").JwtOptions | undefined;
2085
+ overrideOptions?: import("better-auth/plugins").JwtOptions | undefined;
1948
2086
  };
1949
2087
  };
1950
2088
  };
@@ -2122,7 +2260,7 @@ export declare function makeAuth<const Plugins extends readonly BetterAuthPlugin
2122
2260
  window: number;
2123
2261
  max: number;
2124
2262
  }[];
2125
- options: import("better-auth/plugins/magic-link").MagicLinkOptions;
2263
+ options: import("better-auth/plugins").MagicLinkOptions;
2126
2264
  }, {
2127
2265
  id: "email-otp";
2128
2266
  version: string;
@@ -2649,7 +2787,7 @@ export declare function makeAuth<const Plugins extends readonly BetterAuthPlugin
2649
2787
  window: number;
2650
2788
  max: number;
2651
2789
  })[];
2652
- options: import("better-auth/plugins/email-otp").EmailOTPOptions;
2790
+ options: import("better-auth/plugins").EmailOTPOptions;
2653
2791
  $ERROR_CODES: {
2654
2792
  OTP_EXPIRED: import("better-auth").RawError<"OTP_EXPIRED">;
2655
2793
  INVALID_OTP: import("better-auth").RawError<"INVALID_OT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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAUtD"}
@@ -5,7 +5,9 @@ import { claimedDelete, markSessionEnded, messageDeliveryDuring, sessionEndedDur
5
5
  import { KIT_SESSION_FIELDS, KIT_USER_FIELDS } from "../data/kitFields.js";
6
6
  import { parseDeviceMeta, registerDevice } from "../device/registry.js";
7
7
  import "../http/providerFreshness.js";
8
+ import { verificationLedger } from "../ledger/record.js";
8
9
  import { admitsDeletionSignIn, lifecycleRefusalFor } from "../lifecycle/enforce.js";
10
+ import { recordActivity } from "../lifecycle/inactivity.js";
9
11
  import { refuseUnsafeProfile, sanitizeProfile } from "../profile/profile.js";
10
12
  import { defaultGithubUserInfo } from "./githubUserInfo.js";
11
13
  import { microsoftProfileToUser } from "./microsoftEmail.js";
@@ -184,6 +186,7 @@ function callerOf(ctx) {
184
186
  * UUIDs; rate limiting is durable (D1-backed) since memory limiting is per-isolate on Workers.
185
187
  */
186
188
  function makeAuth(deps) {
189
+ const ledger = verificationLedger(deps.db);
187
190
  return betterAuth({
188
191
  appName: "Pithy",
189
192
  baseURL: deps.baseURL,
@@ -202,6 +205,23 @@ function makeAuth(deps) {
202
205
  } },
203
206
  onAPIError: { throw: true },
204
207
  databaseHooks: {
208
+ /**
209
+ * The verification ledger's two hooks on Better Auth's own verification rows (#829).
210
+ *
211
+ * **`create.after` remembers the row** — a sign-in link or code about to be sent, OAuth state, or a wrong
212
+ * code re-created with one more attempt counted; `../ledger/record.ts` tells them apart by what follows.
213
+ * **`delete.before` remembers the row about to be consumed**, and changes nothing: it returns nothing, so it
214
+ * never vetoes, and it is not a `delete.after` because claiming a verification removal the way
215
+ * `claimedDelete` does would delete the row before the consume could read it.
216
+ */
217
+ verification: {
218
+ create: { after: async (verification, ctx) => {
219
+ await ledger.created(verification, ctx?.context);
220
+ } },
221
+ delete: { before: async (verification, ctx) => {
222
+ ledger.consuming(verification, ctx?.context);
223
+ } }
224
+ },
205
225
  user: {
206
226
  create: { before: async (user) => {
207
227
  if (isUnverifiedSignup(user)) throw new APIError("FORBIDDEN", {
@@ -266,48 +286,70 @@ function makeAuth(deps) {
266
286
  })
267
287
  },
268
288
  session: {
269
- create: {
289
+ create: {
290
+ /**
291
+ * Stamp when this session's holder authenticated, and bind the session to its device.
292
+ *
293
+ * **`authenticatedAt` is stamped here and nowhere else.** A sign-in is the only event that is
294
+ * an authentication; `/token/rotate` carries the value forward through `createSession`'s
295
+ * override instead, which is why a rotated session keeps the original instant. A field
296
+ * `defaultValue` would have looked equivalent and is not: `getSessionDefaultFields` is spread
297
+ * into the row *after* the caller's override, so it would overwrite the carried value and
298
+ * silently restore the defect the column exists to fix (#558).
299
+ *
300
+ * A value already on the row is left alone — that is the rotation, passing its own.
301
+ *
302
+ * **Every other `createSession` is treated as an authentication, which is right for all of
303
+ * them the kit composes.** `better-auth/plugins/admin`'s `impersonateUser` would be the
304
+ * exception — an admin impersonating somebody would get a freshly-stamped session and could
305
+ * attach a provider to that account — but the kit composes no admin plugin, so it is a note
306
+ * for whoever does rather than a live path.
307
+ *
308
+ * Device binding only fires when the request carried device headers; a rotation passes
309
+ * `deviceId` by override for the same reason.
310
+ */
311
+ before: async (session, ctx) => {
312
+ const refusal = await lifecycleRefusalFor(deps.db, session.userId, null, /* @__PURE__ */ new Date());
313
+ if (refusal && !admitsDeletionSignIn(refusal, ctx?.headers)) refuseSession(refusal, ctx);
314
+ const carried = session.authenticatedAt;
315
+ const authenticatedAt = carried !== void 0 ? carried : /* @__PURE__ */ new Date();
316
+ const meta = ctx?.headers ? parseDeviceMeta(ctx.headers) : void 0;
317
+ if (!meta) return { data: {
318
+ ...session,
319
+ authenticatedAt
320
+ } };
321
+ await registerDevice(deps.db, meta, {
322
+ userId: session.userId,
323
+ lastIp: session.ipAddress ?? null,
324
+ now: /* @__PURE__ */ new Date()
325
+ });
326
+ return { data: {
327
+ ...session,
328
+ deviceId: meta.id,
329
+ authenticatedAt
330
+ } };
331
+ },
332
+ /**
333
+ * Stamp the sign-in link or code this session was made from as used (#829), and name the account a
334
+ * sign-up just created. Only a row consumed earlier in this same request is stamped, so a token
335
+ * refresh, an OAuth callback and every other session stamp nothing — see `../ledger/record.ts`.
336
+ * After, because the session exists by now: a sign-in the `before` above refused stamps nothing.
337
+ */
338
+ after: async (session, ctx) => {
339
+ await ledger.signedIn(ctx?.context, session.userId);
340
+ await recordActivity(deps.db, session.userId, /* @__PURE__ */ new Date()).catch(() => void 0);
341
+ }
342
+ },
343
+ update: {
270
344
  /**
271
- * Stamp when this session's holder authenticated, and bind the session to its device.
272
- *
273
- * **`authenticatedAt` is stamped here and nowhere else.** A sign-in is the only event that is
274
- * an authentication; `/token/rotate` carries the value forward through `createSession`'s
275
- * override instead, which is why a rotated session keeps the original instant. A field
276
- * `defaultValue` would have looked equivalent and is not: `getSessionDefaultFields` is spread
277
- * into the row *after* the caller's override, so it would overwrite the carried value and
278
- * silently restore the defect the column exists to fix (#558).
279
- *
280
- * A value already on the row is left alone — that is the rotation, passing its own.
281
- *
282
- * **Every other `createSession` is treated as an authentication, which is right for all of
283
- * them the kit composes.** `better-auth/plugins/admin`'s `impersonateUser` would be the
284
- * exception — an admin impersonating somebody would get a freshly-stamped session and could
285
- * attach a provider to that account — but the kit composes no admin plugin, so it is a note
286
- * for whoever does rather than a live path.
287
- *
288
- * Device binding only fires when the request carried device headers; a rotation passes
289
- * `deviceId` by override for the same reason.
345
+ * The activity clock again, for a session that stays open. Better Auth slides a session forward in place
346
+ * once `updateAge` has passed, and that refresh is an update, never a create, so the hook above never
347
+ * sees it. Without this, signing out after weeks of use on one session would read as weeks idle.
290
348
  */
291
- before: async (session, ctx) => {
292
- const refusal = await lifecycleRefusalFor(deps.db, session.userId, null, /* @__PURE__ */ new Date());
293
- if (refusal && !admitsDeletionSignIn(refusal, ctx?.headers)) refuseSession(refusal, ctx);
294
- const carried = session.authenticatedAt;
295
- const authenticatedAt = carried !== void 0 ? carried : /* @__PURE__ */ new Date();
296
- const meta = ctx?.headers ? parseDeviceMeta(ctx.headers) : void 0;
297
- if (!meta) return { data: {
298
- ...session,
299
- authenticatedAt
300
- } };
301
- await registerDevice(deps.db, meta, {
302
- userId: session.userId,
303
- lastIp: session.ipAddress ?? null,
304
- now: /* @__PURE__ */ new Date()
305
- });
306
- return { data: {
307
- ...session,
308
- deviceId: meta.id,
309
- authenticatedAt
310
- } };
349
+ after: async (session) => {
350
+ const userId = session?.userId;
351
+ if (typeof userId !== "string") return;
352
+ await recordActivity(deps.db, userId, /* @__PURE__ */ new Date()).catch(() => void 0);
311
353
  } },
312
354
  /**
313
355
  * Tell whoever keyed state on this session that it has gone, and record that it did.
@@ -479,7 +521,10 @@ before: async (session, ctx) => {
479
521
  const providers = socialProviders(deps);
480
522
  return providers ? { socialProviders: providers } : {};
481
523
  })(),
482
- plugins: [...kitPlugins(deps), ...deps.plugins]
524
+ plugins: [...kitPlugins({
525
+ ...deps,
526
+ ledger
527
+ }), ...deps.plugins]
483
528
  });
484
529
  }
485
530
  //#endregion
@@ -7,6 +7,7 @@ import { emailOTP } from "better-auth/plugins/email-otp";
7
7
  import { jwt } from "better-auth/plugins/jwt";
8
8
  import { magicLink } from "better-auth/plugins/magic-link";
9
9
  import { z } from "zod";
10
+ import type { VerificationLedger } from "../ledger/record";
10
11
  import type { SendAuthEmail } from "./auth";
11
12
  /**
12
13
  * The Better Auth plugins the kit composes for itself, and the reason they are fixed.
@@ -57,6 +58,11 @@ export interface KitPluginDeps {
57
58
  * built the instance — the schema baseline, a seed, a unit test. See `./providerSignInGate`.
58
59
  */
59
60
  requestHeaders?: Headers;
61
+ /**
62
+ * The verification ledger (#829) — told what each send was and which mail carries it, once the email seam
63
+ * has answered. Absent where no instance will ever send: the schema baseline in `../migrations/pluginTables.ts`.
64
+ */
65
+ ledger?: VerificationLedger;
60
66
  }
61
67
  /**
62
68
  * The kit's own, as a **tuple** rather than an array. Better Auth infers a composed instance's whole
@@ -1 +1 @@
1
- {"version":3,"file":"plugins.d.ts","sourceRoot":"","sources":["../../src/instance/plugins.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAEnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AACzD,OAAO,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,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AgB,UAAU,CAAC,IAAI,EAAE,aAAa,GAAG,UAAU,CAkE1D;AAmDD;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU,iDAMpB,CAAC;AAEJ;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,SAAS,gBAAgB,EAAE,GAAG,IAAI,CA4BhF"}
@@ -118,15 +118,28 @@ function kitPlugins(deps) {
118
118
  */
119
119
  async function sendAndRecord(deps, message, ctx) {
120
120
  const requestContext = ctx?.context;
121
+ const type = message.template === "magicLink" ? "magic_link" : "otp";
122
+ let delivery;
121
123
  try {
122
- markMessageDelivery(requestContext, await deps.sendEmail(message));
124
+ delivery = await deps.sendEmail(message);
123
125
  } catch (error) {
124
126
  markMessageDelivery(requestContext, {
125
127
  delivery: "failed",
126
128
  reason: SEND_FAULT
127
129
  });
130
+ await deps.ledger?.issued(requestContext, {
131
+ type,
132
+ email: message.to,
133
+ emailJobId: null
134
+ });
128
135
  throw error;
129
136
  }
137
+ markMessageDelivery(requestContext, delivery);
138
+ await deps.ledger?.issued(requestContext, {
139
+ type,
140
+ email: message.to,
141
+ emailJobId: delivery.delivery === "failed" ? null : delivery.jobId ?? null
142
+ });
130
143
  }
131
144
  /** Is this value shaped like a Better Auth plugin — an object carrying a non-empty string `id`? */
132
145
  function isBetterAuthPlugin(value) {
@@ -0,0 +1,53 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import type { AdminPage } from "../admin/users";
4
+ import type { AuthDatabase } from "../data/tables";
5
+ import { VerificationOutcome, type VerificationState, VerificationType } from "../data/verificationOutcome";
6
+ import type { VerificationTypeCounts } from "../http/responses";
7
+ /**
8
+ * Reading the verification ledger (#829): what `GET {auth}/admin/verifications` answers.
9
+ *
10
+ * Two reads over one window of issue times: the counts by type and state, and the rows themselves, paged. The
11
+ * state is computed at read time — an unused row becomes expired the moment its expiry passes, with nothing
12
+ * written — so both reads take the same `now`, and a row counted as pending is listed as pending.
13
+ */
14
+ /** How far back a window reaches when the caller names no start. */
15
+ export declare const DEFAULT_WINDOW_DAYS = 30;
16
+ /** A window of issue times: `since` inclusive, `until` exclusive. */
17
+ export interface VerificationWindow {
18
+ since: Date;
19
+ until: Date;
20
+ }
21
+ /**
22
+ * The window a read covers. `until` defaults to now and `since` to 30 days before it; a window that ends where it
23
+ * starts, or before, is refused rather than answered with nothing, because an empty answer would read as "no
24
+ * sign-ins".
25
+ */
26
+ export declare function resolveVerificationWindow(input: {
27
+ since?: Date;
28
+ until?: Date;
29
+ }, now: Date): VerificationWindow;
30
+ /**
31
+ * The counts by type and state over a window: one aggregate, grouped by type, and every type answered — a type
32
+ * nothing was issued for reads as zeros rather than going missing, so a reader never has to tell "none" from
33
+ * "not reported".
34
+ */
35
+ export declare function verificationCounts(db: AuthDatabase, window: VerificationWindow, now: Date): Promise<VerificationTypeCounts[]>;
36
+ /** What the row listing filters on and where it resumes. */
37
+ export interface ListVerificationOutcomesOptions {
38
+ window: VerificationWindow;
39
+ /** Only this type. */
40
+ type?: VerificationType | undefined;
41
+ /** Only rows in this state at `now`. */
42
+ state?: VerificationState | undefined;
43
+ /** The moment `state` is judged at — the same `now` the counts took. */
44
+ now: Date;
45
+ cursor?: string | undefined;
46
+ limit?: number | undefined;
47
+ }
48
+ /**
49
+ * The window's rows, newest issue first, paged by keyset on `(issuedAt, id)` — the index the migration built for
50
+ * exactly this. A malformed cursor is a first page, as everywhere in the kit.
51
+ */
52
+ export declare function listVerificationOutcomes(db: AuthDatabase, options: ListVerificationOutcomesOptions): Promise<AdminPage<VerificationOutcome>>;
53
+ //# sourceMappingURL=read.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../src/ledger/read.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,g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
+ // SPDX-License-Identifier: MIT
3
+ import { VerificationOutcome, VerificationType } from "../data/verificationOutcome.js";
4
+ import { ValidationError } from "@pithy-sh/core/src/error/pithyError";
5
+ import { SQLiteDate } from "@pithy-sh/core/src/data/codecs";
6
+ import { decodeCursor, pageLimit, toPage } from "@pithy-sh/core/src/data/cursor";
7
+ import { sql } from "kysely";
8
+ //#region src/ledger/read.ts
9
+ /**
10
+ * Reading the verification ledger (#829): what `GET {auth}/admin/verifications` answers.
11
+ *
12
+ * Two reads over one window of issue times: the counts by type and state, and the rows themselves, paged. The
13
+ * state is computed at read time — an unused row becomes expired the moment its expiry passes, with nothing
14
+ * written — so both reads take the same `now`, and a row counted as pending is listed as pending.
15
+ */
16
+ /** How far back a window reaches when the caller names no start. */
17
+ const DEFAULT_WINDOW_DAYS = 30;
18
+ /**
19
+ * The window a read covers. `until` defaults to now and `since` to 30 days before it; a window that ends where it
20
+ * starts, or before, is refused rather than answered with nothing, because an empty answer would read as "no
21
+ * sign-ins".
22
+ */
23
+ function resolveVerificationWindow(input, now) {
24
+ const until = input.until ?? now;
25
+ const since = input.since ?? /* @__PURE__ */ new Date(until.getTime() - 2592e6);
26
+ if (since.getTime() >= until.getTime()) throw new ValidationError({
27
+ message: "The window must start before it ends.",
28
+ detail: `since ${since.toISOString()} is not before until ${until.toISOString()}`
29
+ });
30
+ return {
31
+ since,
32
+ until
33
+ };
34
+ }
35
+ /**
36
+ * The counts by type and state over a window: one aggregate, grouped by type, and every type answered — a type
37
+ * nothing was issued for reads as zeros rather than going missing, so a reader never has to tell "none" from
38
+ * "not reported".
39
+ */
40
+ async function verificationCounts(db, window, now) {
41
+ const at = SQLiteDate.encode(now);
42
+ const rows = await db.selectFrom("pithyAuthVerificationOutcomes").select((eb) => [
43
+ "type",
44
+ eb.fn.countAll().as("issued"),
45
+ sql`sum(case when ${eb.ref("usedAt")} is not null then 1 else 0 end)`.as("used"),
46
+ sql`sum(case when ${eb.ref("usedAt")} is null and ${eb.ref("expiresAt")} <= ${at} then 1 else 0 end)`.as("expired")
47
+ ]).where("issuedAt", ">=", SQLiteDate.encode(window.since)).where("issuedAt", "<", SQLiteDate.encode(window.until)).groupBy("type").execute();
48
+ return VerificationType.options.map((type) => {
49
+ const row = rows.find((candidate) => candidate.type === type);
50
+ const issued = Number(row?.issued ?? 0);
51
+ const used = Number(row?.used ?? 0);
52
+ const expired = Number(row?.expired ?? 0);
53
+ return {
54
+ type,
55
+ issued,
56
+ used,
57
+ expired,
58
+ pending: issued - used - expired
59
+ };
60
+ });
61
+ }
62
+ /**
63
+ * The window's rows, newest issue first, paged by keyset on `(issuedAt, id)` — the index the migration built for
64
+ * exactly this. A malformed cursor is a first page, as everywhere in the kit.
65
+ */
66
+ async function listVerificationOutcomes(db, options) {
67
+ const limit = pageLimit(options.limit);
68
+ const at = SQLiteDate.encode(options.now);
69
+ let query = db.selectFrom("pithyAuthVerificationOutcomes").selectAll().where("issuedAt", ">=", SQLiteDate.encode(options.window.since)).where("issuedAt", "<", SQLiteDate.encode(options.window.until)).orderBy("issuedAt", "desc").orderBy("id", "desc").limit(limit + 1);
70
+ if (options.type) query = query.where("type", "=", options.type);
71
+ if (options.state === "used") query = query.where("usedAt", "is not", null);
72
+ if (options.state === "expired") query = query.where("usedAt", "is", null).where("expiresAt", "<=", at);
73
+ if (options.state === "pending") query = query.where("usedAt", "is", null).where("expiresAt", ">", at);
74
+ const cursor = decodeCursor(options.cursor);
75
+ const sort = cursor ? Number(cursor.sort) : NaN;
76
+ const id = cursor ? Number(cursor.id) : NaN;
77
+ if (Number.isFinite(sort) && Number.isFinite(id)) query = query.where((eb) => eb.or([eb("issuedAt", "<", sort), eb.and([eb("issuedAt", "=", sort), eb("id", "<", id)])]));
78
+ const rows = await query.execute();
79
+ return toPage(rows.map((row) => VerificationOutcome.parse(row)), limit, (row) => ({
80
+ sort: row.issuedAt.getTime(),
81
+ id: row.id
82
+ }));
83
+ }
84
+ //#endregion
85
+ export { DEFAULT_WINDOW_DAYS, listVerificationOutcomes, resolveVerificationWindow, verificationCounts };