@pithy-sh/auth 0.1.2 → 0.1.4

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 (122) hide show
  1. package/dist/admin/users.d.ts +157 -0
  2. package/dist/admin/users.d.ts.map +1 -0
  3. package/dist/admin/users.js +207 -0
  4. package/dist/audit/actions.d.ts +68 -0
  5. package/dist/audit/actions.d.ts.map +1 -0
  6. package/dist/audit/actions.js +68 -0
  7. package/dist/audit/emit.d.ts +103 -0
  8. package/dist/audit/emit.d.ts.map +1 -0
  9. package/dist/audit/emit.js +172 -0
  10. package/dist/capability.d.ts +62 -0
  11. package/dist/capability.d.ts.map +1 -0
  12. package/dist/capability.js +171 -0
  13. package/dist/client/api.d.ts +301 -0
  14. package/dist/client/api.d.ts.map +1 -0
  15. package/dist/client/api.js +387 -0
  16. package/dist/client/projection.d.ts +53 -0
  17. package/dist/client/projection.d.ts.map +1 -0
  18. package/dist/client/projection.js +2 -0
  19. package/dist/data/betterAuth.d.ts +77 -0
  20. package/dist/data/betterAuth.d.ts.map +1 -0
  21. package/dist/data/betterAuth.js +94 -0
  22. package/dist/data/device.d.ts +38 -0
  23. package/dist/data/device.d.ts.map +1 -0
  24. package/dist/data/device.js +35 -0
  25. package/dist/data/kitFields.d.ts +80 -0
  26. package/dist/data/kitFields.d.ts.map +1 -0
  27. package/dist/data/kitFields.js +79 -0
  28. package/dist/data/rotatedToken.d.ts +22 -0
  29. package/dist/data/rotatedToken.d.ts.map +1 -0
  30. package/dist/data/rotatedToken.js +24 -0
  31. package/dist/data/tables.d.ts +106 -0
  32. package/dist/data/tables.d.ts.map +1 -0
  33. package/dist/data/tables.js +32 -0
  34. package/dist/device/registry.d.ts +56 -0
  35. package/dist/device/registry.d.ts.map +1 -0
  36. package/dist/device/registry.js +87 -0
  37. package/dist/email/send.d.ts +40 -0
  38. package/dist/email/send.d.ts.map +1 -0
  39. package/dist/email/send.js +50 -0
  40. package/dist/http/adminRoutes.d.ts +11 -0
  41. package/dist/http/adminRoutes.d.ts.map +1 -0
  42. package/dist/http/adminRoutes.js +276 -0
  43. package/dist/http/baseUrl.d.ts +43 -0
  44. package/dist/http/baseUrl.d.ts.map +1 -0
  45. package/dist/http/baseUrl.js +98 -0
  46. package/dist/http/csrf.d.ts +20 -0
  47. package/dist/http/csrf.d.ts.map +1 -0
  48. package/dist/http/csrf.js +83 -0
  49. package/dist/http/devLoginRoute.d.ts +44 -0
  50. package/dist/http/devLoginRoute.d.ts.map +1 -0
  51. package/dist/http/devLoginRoute.js +114 -0
  52. package/dist/http/errors.d.ts +26 -0
  53. package/dist/http/errors.d.ts.map +1 -0
  54. package/dist/http/errors.js +69 -0
  55. package/dist/http/guards.d.ts +105 -0
  56. package/dist/http/guards.d.ts.map +1 -0
  57. package/dist/http/guards.js +150 -0
  58. package/dist/http/middleware.d.ts +19 -0
  59. package/dist/http/middleware.d.ts.map +1 -0
  60. package/dist/http/middleware.js +49 -0
  61. package/dist/http/rateLimit.d.ts +19 -0
  62. package/dist/http/rateLimit.d.ts.map +1 -0
  63. package/dist/http/rateLimit.js +33 -0
  64. package/dist/http/resolve.d.ts +11 -0
  65. package/dist/http/resolve.d.ts.map +1 -0
  66. package/dist/http/resolve.js +94 -0
  67. package/dist/http/responses.d.ts +154 -0
  68. package/dist/http/responses.d.ts.map +1 -0
  69. package/dist/http/responses.js +123 -0
  70. package/dist/http/routes.d.ts +36 -0
  71. package/dist/http/routes.d.ts.map +1 -0
  72. package/dist/http/routes.js +270 -0
  73. package/dist/http/schemas.d.ts +68 -0
  74. package/dist/http/schemas.d.ts.map +1 -0
  75. package/dist/http/schemas.js +61 -0
  76. package/dist/http/views.d.ts +55 -0
  77. package/dist/http/views.d.ts.map +1 -0
  78. package/dist/http/views.js +88 -0
  79. package/dist/i18n/errorCopy.d.ts +26 -0
  80. package/dist/i18n/errorCopy.d.ts.map +1 -0
  81. package/dist/i18n/errorCopy.es.d.ts +33 -0
  82. package/dist/i18n/errorCopy.es.d.ts.map +1 -0
  83. package/dist/i18n/errorCopy.es.js +35 -0
  84. package/dist/i18n/errorCopy.js +93 -0
  85. package/dist/index.d.ts +16 -0
  86. package/dist/index.d.ts.map +1 -0
  87. package/dist/index.js +10 -0
  88. package/dist/instance/auth.d.ts +1124 -0
  89. package/dist/instance/auth.d.ts.map +1 -0
  90. package/dist/instance/auth.js +178 -0
  91. package/dist/instance/plugins.d.ts +89 -0
  92. package/dist/instance/plugins.d.ts.map +1 -0
  93. package/dist/instance/plugins.js +118 -0
  94. package/dist/instance/providers.d.ts +119 -0
  95. package/dist/instance/providers.d.ts.map +1 -0
  96. package/dist/instance/providers.js +113 -0
  97. package/dist/instance/secrets.d.ts +165 -0
  98. package/dist/instance/secrets.d.ts.map +1 -0
  99. package/dist/instance/secrets.js +171 -0
  100. package/dist/migrations/0001_init.d.ts +35 -0
  101. package/dist/migrations/0001_init.d.ts.map +1 -0
  102. package/dist/migrations/0001_init.js +79 -0
  103. package/dist/migrations/pluginTables.d.ts +128 -0
  104. package/dist/migrations/pluginTables.d.ts.map +1 -0
  105. package/dist/migrations/pluginTables.js +235 -0
  106. package/dist/seeds/devSession.d.ts +126 -0
  107. package/dist/seeds/devSession.d.ts.map +1 -0
  108. package/dist/seeds/devSession.js +213 -0
  109. package/dist/seeds/example.d.ts +14 -0
  110. package/dist/seeds/example.d.ts.map +1 -0
  111. package/dist/seeds/example.js +32 -0
  112. package/dist/test-utils/liveApp.d.ts +229 -0
  113. package/dist/test-utils/liveApp.d.ts.map +1 -0
  114. package/dist/test-utils/liveApp.js +242 -0
  115. package/dist/token/rotation.d.ts +58 -0
  116. package/dist/token/rotation.d.ts.map +1 -0
  117. package/dist/token/rotation.js +70 -0
  118. package/dist/version.generated.d.ts +7 -0
  119. package/dist/version.generated.d.ts.map +1 -0
  120. package/dist/version.generated.js +9 -0
  121. package/package.json +24 -13
  122. package/src/version.generated.ts +1 -1
@@ -0,0 +1,387 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ //#region src/client/api.ts
4
+ /**
5
+ * The browser half of `@pithy-sh/auth`: the one place that knows how a browser program makes a
6
+ * same-origin, cookie-bearing request to this Worker, and the calls made through it — the six a
7
+ * scaffolded screen makes, and {@link updateUser}, which an adopter's own screen calls.
8
+ *
9
+ * **This module lives in the package for the reason `@pithy-sh/payments`'s counterpart does, only more
10
+ * so.** `pithy ui add` writes the auth screens once and may never rewrite them: they are copied into
11
+ * the adopter's repository and become the adopter's files. Every request written into one of those
12
+ * files is frozen there at the moment `pithy init` ran, and a later fix to the base path, the cookie
13
+ * mode or the failure directions reaches none of them. Six such requests existed — `/get-session`,
14
+ * `/sign-out`, the two OTP routes, the magic link, and the social handoff — each spelling out the same
15
+ * transport by hand. They call this now, and this upgrades with a minor release (#370).
16
+ *
17
+ * **Cookie/session, same origin, and that is enforced rather than assumed.** Every request carries
18
+ * `credentials: "include"` and nothing else: no token in `localStorage` or `sessionStorage`, no
19
+ * `Authorization` header, no refresh rotation. The SPA and its Worker share an origin, so the session
20
+ * rides an httpOnly cookie JavaScript cannot read. Bearer is the mobile path — the same routes serve
21
+ * it, documented rather than scaffolded.
22
+ *
23
+ * **CSRF travels with the cookie mode, and half of it is on this side of the wire.** The server's
24
+ * `requireSameOrigin()` refuses a cookie-authenticated mutating request whose `Origin` does not match;
25
+ * the browser only attaches that header to a request it considers this page's own. So the client half
26
+ * of the rule is that the request never leaves the origin — {@link callAuth} builds its URL from a base
27
+ * path and a relative path and **refuses anything that is not a rooted same-origin path**, rather than
28
+ * handing an ambient session to whatever a mis-set `basePath` names. A caller cannot forget the check,
29
+ * because a caller no longer writes the request.
30
+ *
31
+ * **Nothing here throws.** Not a stylistic choice: this module imports nothing, so `PithyError` is not
32
+ * in reach, and a bare `throw new Error` is exactly what this kit forbids. An unreachable Worker, a
33
+ * proxy's HTML error page, a 500 — each becomes a renderable {@link AuthFailure} on an
34
+ * {@link AuthResult}, and every caller answers one. The Worker is still the security boundary; nothing
35
+ * on this side of the wire protects anything, it only decides what a screen shows.
36
+ *
37
+ * **No absolute URL literals, and no schema library.** Paths are relative, so the calls follow whatever
38
+ * origin the bundle is served from. Answers are narrowed by hand-written `is…(value: unknown): value is
39
+ * T` guards rather than Zod: this file compiles into an adopter's browser bundle, and it must not drag
40
+ * the Worker's schema graph in behind it. `sameOrigin.test.ts` holds the import list to empty, so the
41
+ * property is structural rather than a habit.
42
+ */
43
+ /** Where the auth handler mounts by default — the same default `AuthConfig.basePath` carries. */
44
+ const AUTH_BASE_PATH = "/auth";
45
+ /** The worker could not be reached at all. Offline, or a DNS failure, or no fetch in this program. */
46
+ const AUTH_UNREACHABLE = {
47
+ code: "client/unreachable",
48
+ message: "We couldn't reach the server.",
49
+ action: "Check your connection, then try again."
50
+ };
51
+ /** The worker answered with something this client cannot read. A proxy's HTML page, or a shape change. */
52
+ const AUTH_UNREADABLE = {
53
+ code: "client/unreadable",
54
+ message: "The server answered with something we couldn't read.",
55
+ action: "Try again. If it keeps happening, the app and the backend are out of step."
56
+ };
57
+ /**
58
+ * The request would have left this origin, so it was never sent.
59
+ *
60
+ * The only way to reach it is a `basePath` or a path that is not a rooted same-origin path — an
61
+ * absolute URL, a protocol-relative `//host`, a backslash form a URL parser reads as one. Sending it
62
+ * would attach an ambient session to a request this page is not entitled to make, which is the thing
63
+ * the cookie mode exists to keep from happening.
64
+ */
65
+ const AUTH_CROSS_ORIGIN = {
66
+ code: "client/cross_origin",
67
+ message: "That request would have left this site, so it wasn't sent.",
68
+ action: "Check the auth `basePath` in pithy.config.ts — it is a path on this worker, not a URL."
69
+ };
70
+ /** Whether a value is a plain record — the first step of every guard below. */
71
+ function isRecord(value) {
72
+ return typeof value === "object" && value !== null && !Array.isArray(value);
73
+ }
74
+ /**
75
+ * Whether a composed path stays on this origin.
76
+ *
77
+ * A rooted path and nothing that resolves elsewhere. `//host` and `/\host` are the two forms a URL
78
+ * parser reads as an authority rather than as a path, and a browser follows both — which is why the
79
+ * check is on the second character rather than on a scheme it would never find after a leading `/`.
80
+ */
81
+ function isSameOriginPath(path) {
82
+ if (!path.startsWith("/")) return false;
83
+ const second = path.charAt(1);
84
+ return second !== "/" && second !== "\\";
85
+ }
86
+ /**
87
+ * A failure read off either shape this Worker answers with, or the generic one when the body is neither.
88
+ *
89
+ * **Two shapes, because two packages own routes here and only one of them is ours.** Everything this
90
+ * capability writes answers `{ error: { code, message, action } }` through `pithyErrorHandler`. Every
91
+ * route Better Auth owns — the one-time code, the magic link, sign-out, `get-session`, the social
92
+ * handoff, `update-user` — answers its own flat `{ message, code }`, because better-call renders an
93
+ * endpoint's `APIError` into a Response inside `instance.handler` and nothing on our side of that ever
94
+ * sees it (#449).
95
+ *
96
+ * Reading only the envelope meant every one of those refusals arrived as {@link AUTH_UNREADABLE}, so a
97
+ * reader who mistyped their one-time code was told the app was broken rather than that the code was
98
+ * wrong — in a screen `pithy ui add` copies into an adopter's repository, where it can never be fixed.
99
+ *
100
+ * **The flat shape is read rather than rewritten on the server, deliberately.** `packages/auth/README.md`
101
+ * documents `createAuthClient` from `better-auth/client` as a first-class client surface (#271), and
102
+ * `@better-fetch/fetch` builds its error as `{ ...parsedBody, status }` — so an adopter on that path
103
+ * reads `error.code === "INVALID_OTP"` today. Re-homing the body into our envelope would make that
104
+ * `undefined` for every one of them. The wire is Better Auth's contract; this side learns to read it.
105
+ *
106
+ * So `code` arrives in whichever vocabulary produced it, and the two are told apart by their shape:
107
+ * `auth/invalid_token` is ours, `INVALID_OTP` is Better Auth's. A screen matching on a code should
108
+ * expect the one belonging to the route it called.
109
+ */
110
+ function readFailure(body) {
111
+ if (!isRecord(body)) return AUTH_UNREADABLE;
112
+ if (isRecord(body.error)) {
113
+ const { code, message, action } = body.error;
114
+ if (typeof code !== "string" || typeof message !== "string") return AUTH_UNREADABLE;
115
+ return {
116
+ code,
117
+ message,
118
+ action: typeof action === "string" ? action : null
119
+ };
120
+ }
121
+ const { code, message } = body;
122
+ if (typeof code !== "string" || typeof message !== "string") return AUTH_UNREADABLE;
123
+ return {
124
+ code,
125
+ message,
126
+ action: null
127
+ };
128
+ }
129
+ /**
130
+ * One call: same-origin, cookie-carrying, never throwing. **The only producer of that request.**
131
+ *
132
+ * The body is read before the status is judged, because a refusal's body is the failure a screen
133
+ * renders. A body that will not parse is the generic failure rather than a crash — a corporate proxy's
134
+ * HTML page reaches a browser far more often than anyone expects.
135
+ *
136
+ * **Exported, and that is the point of it.** `@pithy-sh/auth` shipped no browser primitive at all, so
137
+ * six scaffolded screens each wrote the transport out by hand — and those screens are copied into an
138
+ * adopter's repository, where Pithy can never fix them. Every browser program that asks this Worker an
139
+ * auth question calls this, and `sameOrigin.test.ts` fails the build on any module that grows its own
140
+ * (#370).
141
+ *
142
+ * **Zod-free, like everything on this side of the wire.** The answer is narrowed by the hand-written
143
+ * `guard` a caller passes, never by a schema: this compiles into an adopter's browser bundle, and
144
+ * dragging the Worker's schema graph in behind it would break their build rather than ours.
145
+ */
146
+ async function callAuth(path, init, options, guard) {
147
+ const url = `${options?.basePath ?? "/auth"}${path}`;
148
+ if (!isSameOriginPath(url)) return {
149
+ ok: false,
150
+ failure: AUTH_CROSS_ORIGIN
151
+ };
152
+ const fetcher = options?.fetch ?? (options?.global ?? globalThis).fetch;
153
+ if (!fetcher) return {
154
+ ok: false,
155
+ failure: AUTH_UNREACHABLE
156
+ };
157
+ let response;
158
+ try {
159
+ response = await fetcher(url, {
160
+ ...init,
161
+ credentials: "include"
162
+ });
163
+ } catch {
164
+ return {
165
+ ok: false,
166
+ failure: AUTH_UNREACHABLE
167
+ };
168
+ }
169
+ let body;
170
+ try {
171
+ body = await response.json();
172
+ } catch {
173
+ return {
174
+ ok: false,
175
+ failure: AUTH_UNREADABLE
176
+ };
177
+ }
178
+ if (!response.ok) return {
179
+ ok: false,
180
+ failure: readFailure(body)
181
+ };
182
+ return guard(body) ? {
183
+ ok: true,
184
+ value: body
185
+ } : {
186
+ ok: false,
187
+ failure: AUTH_UNREADABLE
188
+ };
189
+ }
190
+ /**
191
+ * A JSON POST, with the humanity check's contribution already folded in.
192
+ *
193
+ * The gate is applied here rather than at each call site for the reason the cookie mode is: a screen
194
+ * that forgets it sends an ungated request to a gated route and gets a 403 it cannot explain.
195
+ */
196
+ function jsonPost(body, options) {
197
+ const gated = options?.gate ? options.gate(body) : {
198
+ body,
199
+ headers: {}
200
+ };
201
+ return {
202
+ method: "POST",
203
+ headers: {
204
+ "content-type": "application/json",
205
+ ...gated.headers
206
+ },
207
+ body: JSON.stringify(gated.body)
208
+ };
209
+ }
210
+ /**
211
+ * Whether a value is a session envelope, or the explicit "nobody" the route answers with.
212
+ *
213
+ * `null` is a valid answer and a distinct one from a failure — signed out is not the same as unread —
214
+ * so it is narrowed here rather than collapsed into one by a caller.
215
+ */
216
+ function isSession(value) {
217
+ if (value === null) return true;
218
+ if (!isRecord(value)) return false;
219
+ const user = value.user;
220
+ return isRecord(user) && typeof user.id === "string" && typeof user.email === "string";
221
+ }
222
+ /** Whether a value is any JSON object. The floor for a route whose success body a screen does not read. */
223
+ function isObject(value) {
224
+ return isRecord(value);
225
+ }
226
+ /**
227
+ * Who is signed in, or `null`.
228
+ *
229
+ * **A failure is not a signed-out session**, and the return type is what keeps the two apart. A screen
230
+ * that renders "signed out" from an unreachable Worker offers a sign-in form to somebody who is
231
+ * already signed in, and the sign-in it starts replaces a live session with a new one. A caller that
232
+ * wants to treat them alike writes `result.ok ? result.value : null` — one line, reading as the
233
+ * decision it is.
234
+ */
235
+ function getSession(options) {
236
+ return callAuth("/get-session", {}, options, isSession);
237
+ }
238
+ /**
239
+ * End the session server-side.
240
+ *
241
+ * **The content type is not decoration, and the scaffolded screen was missing it.** The route refuses a
242
+ * POST without `application/json` with a 415 — so every app scaffolded so far has been signing nobody
243
+ * out. It went unnoticed because the screen ignored the answer and navigated to `/sign-in` regardless,
244
+ * which looks exactly like a successful sign-out until the back button restores a live session.
245
+ * `clientRoundTrip.test.ts` is what found it, and is what would find it again: a request written into a
246
+ * file Pithy may never rewrite is a request nobody ever tested against the route it names (#370).
247
+ *
248
+ * The body is an empty object rather than nothing, because a declared JSON content type with no body is
249
+ * the other half of the same 415.
250
+ */
251
+ function signOut(options) {
252
+ return callAuth("/sign-out", {
253
+ method: "POST",
254
+ headers: { "content-type": "application/json" },
255
+ body: "{}"
256
+ }, options, isObject);
257
+ }
258
+ /**
259
+ * Store something on the signed-in reader's own account. Today that is their language, and only that.
260
+ *
261
+ * **The rule it exists to serve is `docs/I18N.md`'s: `pithy_auth_users.locale` is the one home for a
262
+ * person's language — do not put language in your own preferences table.** A preferences table is the
263
+ * right home for time zone, date format, a 24-hour clock; none of those is language. Two homes for one
264
+ * fact is not a duplicate row, it is a magic-link email in the wrong language with nothing anywhere
265
+ * failing to say so, because the send Workflow reads the auth column and the settings pane reads the
266
+ * other one. This is the write that keeps the home single, and `useNegotiatedLocale`'s `persist` seam
267
+ * (`@pithy-sh/i18n`) is the caller it was written for: `persist: (next) => { void updateUser({ locale: next }); }`.
268
+ * The discard is deliberate: `persist` returns `void | Promise<void>` and this resolves to an
269
+ * `AuthResult`, so returning the call straight does not typecheck — and nothing is lost by dropping
270
+ * it, because nothing here throws.
271
+ *
272
+ * **`locale` is the only field it takes, because it is the only kit user field declared `input: true`**
273
+ * (`../data/kitFields`). Every other column Pithy adds is server-set — a client that could name its own
274
+ * device or token family could name somebody else's — while a language is the reader's own preference
275
+ * and no admin route is a thing a reader has. What makes taking it from a client safe is the `Locale`
276
+ * validator on the field rather than this signature: Better Auth runs it before the write, so the same
277
+ * schema that guards every read guards the write one hop earlier, and a megabyte of junk is a 400 here
278
+ * instead of a row that throws for every operator who later lists users.
279
+ *
280
+ * **`null` is accepted deliberately, and it is not the empty string.** Null means *this reader has not
281
+ * chosen*, which is what makes the server fall back to `Accept-Language`; taking a language choice back
282
+ * is an ordinary thing a reader does, and a call that refused it would answer 400 for the one state the
283
+ * schema calls ordinary.
284
+ *
285
+ * **Not `jsonPost`, for the reason {@link signOut} is not.** That folds in the humanity check, and this
286
+ * is not a gated route: `createAuthRoutes` stacks the Turnstile gate on `/sign-in/magic-link` and
287
+ * `/email-otp/send-verification-otp` and on nothing else, so a token folded in here would be an
288
+ * unexpected field on a request Better Auth validates itself. The content type and the `{}` body are
289
+ * the same 415 story as sign-out — a declared JSON type with no body is refused just as an undeclared
290
+ * one is.
291
+ *
292
+ * **And it is kit code rather than an adopter's, because both alternatives are worse than this
293
+ * function.** Standing up a second Better Auth client with `inferAdditionalFields` duplicates
294
+ * configuration `@pithy-sh/auth` already owns. Reaching for {@link callAuth} instead means an adopter
295
+ * spelling out the path, the content type and the guard themselves, one deep import below the surface
296
+ * every other auth call in their app goes through — written into a file Pithy can never fix (#446).
297
+ *
298
+ * **The answer carries no user, whatever the route's own OpenAPI block advertises.** Better Auth's
299
+ * `/update-user` ends `ctx.json({ status: true })`, so `value` is `{ status: true }` and
300
+ * `value.locale` is `undefined`. Nothing is lost by that — a screen already has the value it just
301
+ * wrote — but do not reach into it for the row.
302
+ *
303
+ * **A refusal is a failure to render and never a throw, and it is `client/unreadable` more often than
304
+ * it looks.** This is Better Auth's own route, and Better Auth turns its own `APIError`s into
305
+ * Responses inside `instance.handler`, so they never reach the `apiErrorToPithy` re-homing in
306
+ * `../http/routes`. The body stays Better Auth's flat `{ message, code }` rather than the kit's error
307
+ * envelope, and {@link AUTH_UNREADABLE} is what `readFailure` makes of anything that is not that
308
+ * envelope: a signed-out reader's 401 reads as `client/unreadable`, and so does a tag the `Locale`
309
+ * validator rejected. Which is enough for the caller this exists for — `useNegotiatedLocale` drops a
310
+ * failed preference write either way, because the reader already has the language they picked.
311
+ */
312
+ function updateUser(fields, options) {
313
+ return callAuth("/update-user", {
314
+ method: "POST",
315
+ headers: { "content-type": "application/json" },
316
+ body: JSON.stringify({ ...fields })
317
+ }, options, isObject);
318
+ }
319
+ /** Sign in with a one-time code the user typed. The answer is the session it created. */
320
+ function signInWithOtp(input, options) {
321
+ return callAuth("/sign-in/email-otp", jsonPost({ ...input }, options), options, isObject);
322
+ }
323
+ /**
324
+ * Mail a one-time code.
325
+ *
326
+ * Gated by the humanity check when one is composed — `options.gate` puts the token where the middleware
327
+ * reads it, and a screen cannot forget to.
328
+ */
329
+ function sendOtp(input, options) {
330
+ return callAuth("/email-otp/send-verification-otp", jsonPost({ ...input }, options), options, isObject);
331
+ }
332
+ /**
333
+ * Mail a magic link.
334
+ *
335
+ * `callbackURL` is the adopter's own screen, so it is theirs to name. Gated the same way as
336
+ * {@link sendOtp}.
337
+ */
338
+ function sendMagicLink(input, options) {
339
+ return callAuth("/sign-in/magic-link", jsonPost({ ...input }, options), options, isObject);
340
+ }
341
+ /**
342
+ * Whether an answer is an authorization URL a browser may be sent to, and the two reasons it might not be.
343
+ *
344
+ * **The scheme check.** `window.location.href = url` with a `javascript:` URL executes that script in
345
+ * this page, so a response body is not something to hand straight to a navigator however trusted its
346
+ * origin.
347
+ *
348
+ * **The `client_id` check.** An OAuth 2.0 authorization request must carry one, so an authorization URL
349
+ * naming no client is a provider with a blank credential behind it. The client projection carries
350
+ * booleans and never credentials, so a browser cannot know that in advance — refusing the *response* is
351
+ * what turns a blank credential into a sentence on the screen rather than a bounce to Google's own
352
+ * error page.
353
+ */
354
+ function isAuthorization(value) {
355
+ if (!isRecord(value) || typeof value.url !== "string") return false;
356
+ try {
357
+ const parsed = new URL(value.url);
358
+ if (parsed.protocol !== "https:" && parsed.protocol !== "http:") return false;
359
+ return (parsed.searchParams.get("client_id") ?? "") !== "";
360
+ } catch {
361
+ return false;
362
+ }
363
+ }
364
+ /**
365
+ * Ask for a provider's authorization URL.
366
+ *
367
+ * **No humanity check, deliberately**: the redirect carries no token to check and the provider runs its
368
+ * own bot defense, which is what `@pithy-sh/auth` already assumes when it stacks the check on the
369
+ * magic-link route alone. Gating it would only stop people signing in.
370
+ */
371
+ async function startSocialSignIn(input, options) {
372
+ const ungated = options && {
373
+ ...options,
374
+ gate: void 0
375
+ };
376
+ const result = await callAuth("/sign-in/social", jsonPost({ ...input }, void 0), ungated, isObject);
377
+ if (!result.ok) return {
378
+ kind: "refused",
379
+ failure: result.failure
380
+ };
381
+ return isAuthorization(result.value) ? {
382
+ kind: "authorize",
383
+ url: result.value.url
384
+ } : { kind: "unconfigured" };
385
+ }
386
+ //#endregion
387
+ export { AUTH_BASE_PATH, AUTH_CROSS_ORIGIN, AUTH_UNREACHABLE, AUTH_UNREADABLE, callAuth, getSession, sendMagicLink, sendOtp, signInWithOtp, signOut, startSocialSignIn, updateUser };
@@ -0,0 +1,53 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ /**
4
+ * What a browser may know about this project's auth — the shape of `virtual:pithy/auth`.
5
+ *
6
+ * **This declaration is the contract, and the projection is checked against it.** It is written here
7
+ * rather than inferred from the closure that builds it, and that is the whole point: an inferred type
8
+ * follows whatever the producer last happened to say, so a projection that dropped `otpLength`, or that
9
+ * started projecting `baseURL` because one screen wanted it, would take the type with it and nothing
10
+ * would go red. Declared, both are a compile error at the `client:` that wrote them, and widening what
11
+ * every adopter's bundle carries becomes a decision made here, on purpose.
12
+ *
13
+ * The `enabled: false` branch is not this capability's to produce. `resolveClientProjection` answers it
14
+ * for a capability nobody composed, and a front end is written against the capabilities it *may* have.
15
+ * It is declared here because it is what a browser reads, and the browser cannot tell the two apart.
16
+ *
17
+ * **This is the only statement of the shape.** `@pithy-sh/ui-react`'s `templates/client-env.d.ts` — the
18
+ * ambient declaration `pithy ui add react` copies into an adopter's Worker — is generated from this type
19
+ * by `@pithy-sh/vite`'s `clientEnvDeclaration.ts` (#398). The unions and the per-field doc comments below
20
+ * are emitted verbatim, so what is written here is what a screen author reads.
21
+ */
22
+ export type AuthClientProjection = {
23
+ /** Auth is not composed on this worker. A screen branches rather than rendering a sign-in form. */
24
+ enabled: false;
25
+ } | {
26
+ /** Auth is composed on this worker. */
27
+ enabled: true;
28
+ /** The path the auth handler mounts under, e.g. `/auth`. */
29
+ basePath: string;
30
+ /**
31
+ * Which social providers are switched on in pithy.config.ts. Credentials never reach the client —
32
+ * they are not in the config this projection can see, they are in the secrets store.
33
+ *
34
+ * Nested, so a screen iterates the set rather than naming four booleans. A fifth provider is one
35
+ * key here — and until it is written here, projecting it is a compile error, not a surprise in
36
+ * somebody's bundle.
37
+ */
38
+ providers: {
39
+ /** Whether Sign in with Google is offered. */
40
+ google: boolean;
41
+ /** Whether Sign in with Apple is offered. */
42
+ apple: boolean;
43
+ /** Whether Sign in with Facebook is offered. */
44
+ facebook: boolean;
45
+ /** Whether Sign in with GitHub is offered. */
46
+ github: boolean;
47
+ };
48
+ /** How many digits an email OTP carries. */
49
+ otpLength: number;
50
+ /** Whether signing in may provision a new user. Drives the sign-up copy. */
51
+ signUpEnabled: boolean;
52
+ };
53
+ //# sourceMappingURL=projection.d.ts.map
@@ -0,0 +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,4CAA4C;IAC5C,SAAS,EAAE,MAAM,CAAC;IAClB,4EAA4E;IAC5E,aAAa,EAAE,OAAO,CAAC;CACxB,CAAC"}
@@ -0,0 +1,2 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
@@ -0,0 +1,77 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import { z } from "zod";
4
+ /** `pithy_auth_users` — one end user. Text/UUID id (anti-enumeration); email is unique. */
5
+ export declare const User: z.ZodObject<{
6
+ id: z.ZodString;
7
+ name: z.ZodString;
8
+ email: z.ZodString;
9
+ emailVerified: z.ZodCodec<z.ZodUnion<readonly [z.ZodLiteral<0>, z.ZodLiteral<1>, z.ZodBoolean, z.ZodString]>, z.ZodBoolean>;
10
+ image: z.ZodNullable<z.ZodString>;
11
+ locale: z.ZodNullable<z.ZodString>;
12
+ createdAt: z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>;
13
+ updatedAt: z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>;
14
+ }, z.core.$strip>;
15
+ export type User = z.output<typeof User>;
16
+ /** `pithy_auth_sessions` — one active session (the long-lived, bearer/cookie credential). */
17
+ export declare const Session: z.ZodObject<{
18
+ id: z.ZodString;
19
+ expiresAt: z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>;
20
+ token: z.ZodString;
21
+ createdAt: z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>;
22
+ updatedAt: z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>;
23
+ ipAddress: z.ZodNullable<z.ZodString>;
24
+ userAgent: z.ZodNullable<z.ZodString>;
25
+ userId: z.ZodString;
26
+ deviceId: z.ZodNullable<z.ZodString>;
27
+ familyId: z.ZodNullable<z.ZodString>;
28
+ }, z.core.$strip>;
29
+ export type Session = z.output<typeof Session>;
30
+ /** `pithy_auth_accounts` — a credential/identity link for a user (one row per social provider). */
31
+ export declare const Account: z.ZodObject<{
32
+ id: z.ZodString;
33
+ issuer: z.ZodString;
34
+ accountId: z.ZodString;
35
+ providerId: z.ZodString;
36
+ userId: z.ZodString;
37
+ accessToken: z.ZodNullable<z.ZodString>;
38
+ refreshToken: z.ZodNullable<z.ZodString>;
39
+ idToken: z.ZodNullable<z.ZodString>;
40
+ accessTokenExpiresAt: z.ZodNullable<z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>>;
41
+ refreshTokenExpiresAt: z.ZodNullable<z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>>;
42
+ scope: z.ZodNullable<z.ZodString>;
43
+ password: z.ZodNullable<z.ZodString>;
44
+ createdAt: z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>;
45
+ updatedAt: z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>;
46
+ }, z.core.$strip>;
47
+ export type Account = z.output<typeof Account>;
48
+ /** `pithy_auth_verifications` — short-lived tokens: magic-link, OTP, and OAuth PKCE/state. */
49
+ export declare const Verification: z.ZodObject<{
50
+ id: z.ZodString;
51
+ identifier: z.ZodString;
52
+ value: z.ZodString;
53
+ expiresAt: z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>;
54
+ createdAt: z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>;
55
+ updatedAt: z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>;
56
+ }, z.core.$strip>;
57
+ export type Verification = z.output<typeof Verification>;
58
+ /** `pithy_auth_jwks` — the JWKS keypairs that sign and verify short-lived JWT access tokens. */
59
+ export declare const Jwks: z.ZodObject<{
60
+ id: z.ZodString;
61
+ publicKey: z.ZodString;
62
+ privateKey: z.ZodString;
63
+ createdAt: z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>;
64
+ expiresAt: z.ZodNullable<z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>>;
65
+ alg: z.ZodNullable<z.ZodString>;
66
+ crv: z.ZodNullable<z.ZodString>;
67
+ }, z.core.$strip>;
68
+ export type Jwks = z.output<typeof Jwks>;
69
+ /** `pithy_auth_rate_limit` — Better Auth's database-backed rate-limit counters (per key, durable across isolates). */
70
+ export declare const RateLimit: z.ZodObject<{
71
+ id: z.ZodString;
72
+ key: z.ZodString;
73
+ count: z.ZodNumber;
74
+ lastRequest: z.ZodNumber;
75
+ }, z.core.$strip>;
76
+ export type RateLimit = z.output<typeof RateLimit>;
77
+ //# sourceMappingURL=betterAuth.d.ts.map
@@ -0,0 +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;;;;;;;;;iBAqBwF,CAAC;AAC1G,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,CAAC;AAEzC,6FAA6F;AAC7F,eAAO,MAAM,OAAO;;;;;;;;;;;iBAkCqF,CAAC;AAC1G,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,OAAO,CAAC,CAAC;AAE/C,mGAAmG;AACnG,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;iBAyCqF,CAAC;AAC1G,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,OAAO,CAAC,CAAC;AAE/C,8FAA8F;AAC9F,eAAO,MAAM,YAAY;;;;;;;iBAmBtB,CAAC;AACJ,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,YAAY,CAAC,CAAC;AAEzD,gGAAgG;AAChG,eAAO,MAAM,IAAI;;;;;;;;iBA8Bd,CAAC;AACJ,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,CAAC;AAEzC,sHAAsH;AACtH,eAAO,MAAM,SAAS;;;;;iBAcnB,CAAC;AACJ,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,SAAS,CAAC,CAAC"}
@@ -0,0 +1,94 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import { z } from "zod";
4
+ import { JsonDate, SQLiteBoolean } from "@pithy-sh/core/src/data/codecs";
5
+ import { Locale } from "@pithy-sh/core/src/i18n/locale";
6
+ //#region src/data/betterAuth.ts
7
+ /**
8
+ * The Better-Auth-managed tables, one Zod object per table.
9
+ *
10
+ * Better Auth owns the reads and writes to these via its Kysely adapter (which wraps our shared
11
+ * Kysely + `CamelCasePlugin`, so it issues camelCase identifiers that map to the snake_case
12
+ * `pithy_auth_*` columns our migration creates). These schemas are the table definitions of record:
13
+ * they back the migration, document the model, and decode any direct read Pithy does. Columns are
14
+ * column-exact to Better Auth 1.6.19's generated SQLite schema. Dates are ISO-8601 text
15
+ * (`BetterAuthDate`), booleans are `0|1` (`SQLiteBoolean`) — matching Better Auth's on-disk
16
+ * representation, not Pithy's ms-epoch house default. `z.input` is the SQLite row; `z.output` the
17
+ * app shape.
18
+ */
19
+ /**
20
+ * Date codec for Better-Auth columns. On SQLite/D1 Better Auth's adapter serializes `date` fields with
21
+ * `Date#toISOString()` — ISO-8601 **text**, not the ms-epoch number Pithy's house `SQLiteDate` assumes.
22
+ * That on-disk shape is exactly core's `JsonDate` (Date ↔ ISO-8601 string), so this is an alias, named
23
+ * for its use so the right codec is obvious at each Better-Auth column (`SQLiteDate` would mis-decode).
24
+ */
25
+ const BetterAuthDate = JsonDate;
26
+ /** `pithy_auth_users` — one end user. Text/UUID id (anti-enumeration); email is unique. */
27
+ const User = z.object({
28
+ id: z.string().describe("Primary key. A random/UUID text id (not auto-increment) so users cannot be enumerated."),
29
+ name: z.string().describe("The user's display name, supplied by the provider profile or at sign-up."),
30
+ email: z.string().describe("The user's email address. Unique across all users; the identity key for passwordless sign-in."),
31
+ emailVerified: SQLiteBoolean.describe("Whether the email has been verified. Stored as `0|1`; magic-link/OTP sign-in sets it true."),
32
+ image: z.string().nullable().describe("URL of the user's avatar from a social profile, or null."),
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
+ 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.")
36
+ }).describe("A user in `pithy_auth_users` — the canonical identity every session and account hangs off.");
37
+ /** `pithy_auth_sessions` — one active session (the long-lived, bearer/cookie credential). */
38
+ const Session = z.object({
39
+ id: z.string().describe("Primary key. A random/UUID text id."),
40
+ expiresAt: BetterAuthDate.describe("When the session expires. Slides forward on use within `updateAge`. ISO-8601 text in SQLite."),
41
+ token: z.string().describe("The opaque session token. Unique; presented as the cookie value or `Authorization: Bearer`. The refresh credential."),
42
+ createdAt: BetterAuthDate.describe("When the session was created. ISO-8601 text in SQLite."),
43
+ updatedAt: BetterAuthDate.describe("When the session was last refreshed. ISO-8601 text in SQLite."),
44
+ ipAddress: z.string().nullable().describe("The client IP at sign-in, for the device registry and `new sign-in from…` security signals. Nullable."),
45
+ userAgent: z.string().nullable().describe("The client user-agent at sign-in. Nullable."),
46
+ userId: z.string().describe("The owning user's id. Foreign key to `pithy_auth_users(id)`, ON DELETE CASCADE."),
47
+ deviceId: z.string().nullable().describe("The id of the `pithy_auth_devices` row this session is bound to (per-device sessions), or null for a device-less web login."),
48
+ familyId: z.string().nullable().describe("The refresh-token family this session belongs to, carried across rotations so a replayed refresh token can revoke the whole chain. Server-set; null for a session created before rotation or one never rotated.")
49
+ }).describe("A session in `pithy_auth_sessions` — a signed-in credential, optionally bound to a device.");
50
+ /** `pithy_auth_accounts` — a credential/identity link for a user (one row per social provider). */
51
+ const Account = z.object({
52
+ id: z.string().describe("Primary key. A random/UUID text id."),
53
+ issuer: z.string().describe("Who asserted this identity, as the identity provider names itself: an OIDC issuer URL (`https://accounts.google.com`), `local:oauth:<id>` for an OAuth provider that publishes none, or `local:credential` for a password. With `accountId` it is the account's identity and carries a unique index — a provider slug is a name this project chose, so two providers pointed at one directory could assert the same `accountId` and land on two rows."),
54
+ accountId: z.string().describe("The provider's stable id for this user (e.g. the Google `sub` claim)."),
55
+ providerId: z.string().describe("The provider slug, e.g. `google`. Identifies which OAuth/credential provider this row links."),
56
+ userId: z.string().describe("The owning user's id. Foreign key to `pithy_auth_users(id)`, ON DELETE CASCADE."),
57
+ accessToken: z.string().nullable().describe("The provider OAuth access token, if granted. Never returned to clients. Nullable."),
58
+ refreshToken: z.string().nullable().describe("The provider OAuth refresh token, if granted (`accessType: offline`). Never returned to clients. Nullable."),
59
+ idToken: z.string().nullable().describe("The provider OIDC id token from the last sign-in. Never returned to clients. Nullable."),
60
+ accessTokenExpiresAt: BetterAuthDate.nullable().describe("When the provider access token expires. ISO-8601 text in SQLite. Nullable."),
61
+ refreshTokenExpiresAt: BetterAuthDate.nullable().describe("When the provider refresh token expires. ISO-8601 text in SQLite. Nullable."),
62
+ scope: z.string().nullable().describe("The OAuth scopes granted, space-delimited. Nullable."),
63
+ password: z.string().nullable().describe("Unused — Pithy is passwordless-only, so this Better-Auth column is always null."),
64
+ createdAt: BetterAuthDate.describe("When the account link was created. ISO-8601 text in SQLite."),
65
+ updatedAt: BetterAuthDate.describe("When the account link was last updated. ISO-8601 text in SQLite.")
66
+ }).describe("An account link in `pithy_auth_accounts` — a user's connection to a social/OAuth provider.");
67
+ /** `pithy_auth_verifications` — short-lived tokens: magic-link, OTP, and OAuth PKCE/state. */
68
+ const Verification = z.object({
69
+ id: z.string().describe("Primary key. A random/UUID text id."),
70
+ identifier: z.string().describe("What the value verifies — a namespaced email for OTP/magic-link, or the OAuth `state` for PKCE. Indexed."),
71
+ value: z.string().describe("The token, code, or serialized PKCE/state payload. Consumed atomically on first verify (single-use)."),
72
+ expiresAt: BetterAuthDate.describe("When the verification expires (5 min for magic-link/OTP, ~10 min for OAuth state). ISO-8601 text in SQLite."),
73
+ createdAt: BetterAuthDate.describe("When the verification was created. ISO-8601 text in SQLite."),
74
+ updatedAt: BetterAuthDate.describe("When the verification was last updated. ISO-8601 text in SQLite.")
75
+ }).describe("A verification record in `pithy_auth_verifications` — the store behind magic-link, OTP, and OAuth PKCE state.");
76
+ /** `pithy_auth_jwks` — the JWKS keypairs that sign and verify short-lived JWT access tokens. */
77
+ const Jwks = z.object({
78
+ id: z.string().describe("Primary key. A random/UUID text id, used as the JWT `kid`."),
79
+ publicKey: z.string().describe("The public key (JWK), published at `/jwks` so resource servers verify access tokens locally."),
80
+ privateKey: z.string().describe("The private signing key, encrypted at rest with the Better-Auth secret (sourced from `@pithy-sh/secrets`). Never published."),
81
+ createdAt: BetterAuthDate.describe("When the keypair was created. ISO-8601 text in SQLite."),
82
+ expiresAt: BetterAuthDate.nullable().describe("When the keypair is retired. Retired keys stay published through their grace window so in-flight tokens still verify. Nullable."),
83
+ alg: z.string().nullable().describe("The signing algorithm this keypair is for (`EdDSA`, `RS256`), published in the key's JWKS entry so a verifier picks the right one without guessing. Nullable because Better Auth declares it optional and a key minted before 1.7 has none — the plugin falls back to `EdDSA`, which is what those keys are."),
84
+ crv: z.string().nullable().describe("The elliptic curve for an EC or OKP key (`Ed25519`, `P-256`), and null for RSA, which has no curve. Published beside `alg` for the same reason.")
85
+ }).describe("A signing keypair in `pithy_auth_jwks` — rotation keeps prior public keys published so issued tokens keep verifying.");
86
+ /** `pithy_auth_rate_limit` — Better Auth's database-backed rate-limit counters (per key, durable across isolates). */
87
+ const RateLimit = z.object({
88
+ id: z.string().describe("Primary key. A random/UUID text id."),
89
+ key: z.string().describe("The rate-limit bucket key (path + client IP). Unique."),
90
+ count: z.number().int().describe("The number of requests counted in the current window."),
91
+ lastRequest: z.number().int().describe("The ms-epoch timestamp of the most recent request in the window. A raw number, written by Better Auth's limiter.")
92
+ }).describe("A rate-limit counter in `pithy_auth_rate_limit` — durable per-isolate-safe throttling for the auth send/sign-in routes.");
93
+ //#endregion
94
+ export { Account, Jwks, RateLimit, Session, User, Verification };