@pithy-sh/auth 0.6.2 → 0.6.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 (69) hide show
  1. package/README.md +15 -0
  2. package/dist/audit/actions.d.ts +78 -5
  3. package/dist/audit/actions.d.ts.map +1 -1
  4. package/dist/audit/actions.js +78 -5
  5. package/dist/audit/emit.d.ts +223 -2
  6. package/dist/audit/emit.d.ts.map +1 -1
  7. package/dist/audit/emit.js +251 -20
  8. package/dist/audit/evidence.d.ts +207 -0
  9. package/dist/audit/evidence.d.ts.map +1 -0
  10. package/dist/audit/evidence.js +162 -0
  11. package/dist/capability.d.ts +7 -0
  12. package/dist/capability.d.ts.map +1 -1
  13. package/dist/capability.js +7 -2
  14. package/dist/client/api.d.ts +8 -0
  15. package/dist/client/api.d.ts.map +1 -1
  16. package/dist/client/api.js +8 -0
  17. package/dist/email/send.d.ts +10 -2
  18. package/dist/email/send.d.ts.map +1 -1
  19. package/dist/email/send.js +36 -14
  20. package/dist/http/errorCallbackUrl.d.ts +40 -0
  21. package/dist/http/errorCallbackUrl.d.ts.map +1 -0
  22. package/dist/http/errorCallbackUrl.js +395 -0
  23. package/dist/http/providerRefusal.d.ts +181 -0
  24. package/dist/http/providerRefusal.d.ts.map +1 -0
  25. package/dist/http/providerRefusal.js +363 -0
  26. package/dist/http/resolve.js +1 -0
  27. package/dist/http/routes.d.ts.map +1 -1
  28. package/dist/http/routes.js +12 -1
  29. package/dist/instance/auth.d.ts +132 -26
  30. package/dist/instance/auth.d.ts.map +1 -1
  31. package/dist/instance/auth.js +118 -13
  32. package/dist/instance/githubUserInfo.d.ts +13 -7
  33. package/dist/instance/githubUserInfo.d.ts.map +1 -1
  34. package/dist/instance/githubUserInfo.js +13 -7
  35. package/dist/instance/plugins.d.ts +41 -13
  36. package/dist/instance/plugins.d.ts.map +1 -1
  37. package/dist/instance/plugins.js +95 -18
  38. package/dist/instance/providerSignInGate.d.ts +130 -0
  39. package/dist/instance/providerSignInGate.d.ts.map +1 -0
  40. package/dist/instance/providerSignInGate.js +230 -0
  41. package/dist/instance/refusalTransport.d.ts +91 -0
  42. package/dist/instance/refusalTransport.d.ts.map +1 -0
  43. package/dist/instance/refusalTransport.js +32 -0
  44. package/dist/migrations/pluginTables.d.ts.map +1 -1
  45. package/dist/migrations/pluginTables.js +2 -1
  46. package/dist/peer.d.ts +54 -0
  47. package/dist/peer.d.ts.map +1 -0
  48. package/dist/peer.js +31 -0
  49. package/dist/version.generated.d.ts +1 -1
  50. package/dist/version.generated.js +1 -1
  51. package/package.json +5 -5
  52. package/src/audit/actions.ts +78 -5
  53. package/src/audit/emit.ts +340 -25
  54. package/src/audit/evidence.ts +297 -0
  55. package/src/capability.ts +19 -7
  56. package/src/client/api.ts +8 -0
  57. package/src/email/send.ts +51 -14
  58. package/src/http/errorCallbackUrl.ts +463 -0
  59. package/src/http/providerRefusal.ts +424 -0
  60. package/src/http/resolve.ts +3 -0
  61. package/src/http/routes.ts +38 -1
  62. package/src/instance/auth.ts +167 -19
  63. package/src/instance/githubUserInfo.ts +13 -7
  64. package/src/instance/plugins.ts +119 -18
  65. package/src/instance/providerSignInGate.ts +323 -0
  66. package/src/instance/refusalTransport.ts +119 -0
  67. package/src/migrations/pluginTables.ts +4 -1
  68. package/src/peer.ts +29 -0
  69. package/src/version.generated.ts +1 -1
@@ -0,0 +1,162 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ //#region src/audit/evidence.ts
4
+ /** Session rows that disappeared during one request, keyed by that request's Better Auth context object. */
5
+ const endedSessions = /* @__PURE__ */ new WeakMap();
6
+ /**
7
+ * Record that a session row was deleted during this request, and whose it was.
8
+ *
9
+ * Called from `session.delete.after`, which fires for a sign-out, a revoke, an admin ending somebody's
10
+ * devices and the user-deletion cascade alike. Only the first of those has a path event to qualify, and
11
+ * the rest are harmless to mark: nothing reads this except `/sign-out`.
12
+ *
13
+ * **The owner, because `/sign-out` cannot name one otherwise.** That endpoint declares no session
14
+ * middleware — it reads the cookie itself — so `ctx.context.session` is null even on a sign-out that
15
+ * worked, and the row came out `anonymous` for the one person it was certainly about. The session that
16
+ * disappeared is the answer.
17
+ */
18
+ function markSessionEnded(requestContext, userId) {
19
+ if (typeof requestContext !== "object" || requestContext === null) return;
20
+ if (typeof userId !== "string" || userId === "") return;
21
+ if (!endedSessions.has(requestContext)) endedSessions.set(requestContext, { userId });
22
+ }
23
+ /** Which session actually disappeared during this request, if any. `/sign-out`'s evidence. */
24
+ function sessionEndedDuring(requestContext) {
25
+ if (typeof requestContext !== "object" || requestContext === null) return null;
26
+ return endedSessions.get(requestContext) ?? null;
27
+ }
28
+ /** The one reason a failed delivery reports. The thrown error's own text never reaches an audit row. */
29
+ const SEND_FAULT = "enqueue-failed";
30
+ /** What the email seam answered during one request, keyed by that request's Better Auth context object. */
31
+ const messageDeliveries = /* @__PURE__ */ new WeakMap();
32
+ /**
33
+ * Record what the email seam did with this request's magic link or OTP.
34
+ *
35
+ * **Called from the send callback, which is the only place that knows.** `auth/magic_link_sent` and
36
+ * `auth/otp_sent` claim a message exists, and the two send endpoints answer `200 {"success":true}`
37
+ * whether or not one does. `/email-otp/send-verification-otp` declines twice over before the callback is
38
+ * even reached: Better Auth drops the verification row and returns success rather than confirm that an
39
+ * address is registered (`plugins/email-otp/routes.mjs`), and the kit's own `sendVerificationOTP` returns
40
+ * without queuing for any `type` but `sign-in`. Neither decline is visible from the status, from the
41
+ * body, or from anywhere the `after` hook can reach.
42
+ *
43
+ * **Marked after the await, which is the whole of #627's last hole.** An earlier revision marked at the
44
+ * call — before `sendEmail` was awaited — reasoning that `runInBackgroundOrAwait` might defer the rest of
45
+ * the callback past the response. It defers only when `options.advanced.backgroundTasks.handler` is set
46
+ * (`better-auth/dist/context/create-context.mjs`, `runInBackgroundOrAwait`), and `makeAuth` sets no such
47
+ * handler and exposes no way for an adopter to; absent one it awaits, so the mark still lands before the
48
+ * `after` hook. What marking early cost was everything underneath: a suppressed recipient and a thrown
49
+ * enqueue both wrote `auth/otp_sent outcome=success`, over a `200 {"success":true}`, for an
50
+ * unauthenticated caller on the default composition.
51
+ *
52
+ * So the claim recorded here is *what the email seam did*, which is as far as any of this can see —
53
+ * delivery belongs to a Workflow that runs long after the response.
54
+ */
55
+ function markMessageDelivery(requestContext, delivery) {
56
+ if (typeof requestContext !== "object" || requestContext === null) return;
57
+ messageDeliveries.set(requestContext, delivery);
58
+ }
59
+ /** What the email seam answered during this request, or null if it was never reached. The send paths' evidence. */
60
+ function messageDeliveryDuring(requestContext) {
61
+ if (typeof requestContext !== "object" || requestContext === null) return null;
62
+ return messageDeliveries.get(requestContext) ?? null;
63
+ }
64
+ /** Kysely reports a delete's row count as a bigint; anything else means the dialect told us nothing. */
65
+ function removedARow(numDeletedRows) {
66
+ if (typeof numDeletedRows === "bigint") return numDeletedRows > 0n;
67
+ if (typeof numDeletedRows === "number") return numDeletedRows > 0;
68
+ return false;
69
+ }
70
+ /**
71
+ * Remove one row ahead of Better Auth and report whether this caller is the one that removed it.
72
+ *
73
+ * **A failed claim claims anyway.** If the delete throws — the binding is gone, the table is locked — the
74
+ * caller still saw a row and a removal is still happening, so falling silent would turn a database fault
75
+ * into a missing event. A trail that occasionally double-counts a removal costs somebody an afternoon;
76
+ * one that silently drops removals costs the trail its purpose.
77
+ */
78
+ async function claimRemoval(db, table, row) {
79
+ const id = row.id;
80
+ if (typeof id !== "string" && typeof id !== "number") return false;
81
+ try {
82
+ return removedARow((await db.deleteFrom(table).where("id", "=", String(id)).executeTakeFirst())?.numDeletedRows);
83
+ } catch {
84
+ return true;
85
+ }
86
+ }
87
+ /**
88
+ * The brand `claimedDelete` stamps on the `after` it produces, and the whole of what
89
+ * {@link surveyDeleteHooks} reads.
90
+ *
91
+ * A private symbol rather than a property name, so nothing can satisfy the gate by declaring a flag: the
92
+ * only way to carry it is to have come out of the function below.
93
+ */
94
+ const CLAIMS_ITS_REMOVALS = Symbol("pithy.auth.claimsItsRemovals");
95
+ /**
96
+ * **Build a `delete` hook pair whose `after` runs once per removal rather than once per caller.**
97
+ *
98
+ * This is the shape every `delete.after` in this kit is wired through — session, account, and whatever
99
+ * is added next — because the hole is in `deleteWithHooks` and therefore under all of them equally.
100
+ * Handing back the pair rather than two loose functions is what makes the protection hard to omit: there
101
+ * is no `after` to register without a `before` beside it, and the `after` carries a brand
102
+ * {@link surveyDeleteHooks} can see, so a third model wired the obvious way fails a test rather than
103
+ * quietly becoming the third producer.
104
+ *
105
+ * The claim is carried between the two hooks in a `WeakSet` keyed by the row object Better Auth passes to
106
+ * both — the same instance, held weakly, so nothing here outlives the request — and the set is private to
107
+ * one pair, so two models cannot read each other's claims.
108
+ *
109
+ * **What the gated handler must therefore be: a claim about a removal, wanting exactly-once.** An audit
110
+ * event is one. So is `onSessionRevoked`, which tells whoever keyed state on a session that it has gone:
111
+ * at-least-once still holds under the gate, because the only way a claim loses is that another caller won
112
+ * it, and that caller runs the handler.
113
+ */
114
+ function claimedDelete(spec) {
115
+ const won = /* @__PURE__ */ new WeakSet();
116
+ const after = async (row, ctx) => {
117
+ if (!won.has(row)) return;
118
+ await spec.after(row, ctx);
119
+ };
120
+ Object.defineProperty(after, CLAIMS_ITS_REMOVALS, { value: true });
121
+ return {
122
+ before: async (row) => {
123
+ if (await claimRemoval(spec.db, spec.table, row)) won.add(row);
124
+ },
125
+ after
126
+ };
127
+ }
128
+ /**
129
+ * **Walk a `databaseHooks` object and report every `delete.after` that is not claimed.**
130
+ *
131
+ * The rule this enforces is about the primitive, not about the models that happen to be wired today: it
132
+ * reads whatever keys are there, so a model added tomorrow is covered the day it lands, and nothing here
133
+ * mentions `session` or `account`. A `delete.after` passes only by being the function `claimedDelete`
134
+ * produced — a `before` beside it is necessary and nowhere near sufficient, since a `before` that does
135
+ * something else entirely would satisfy a shape check.
136
+ *
137
+ * `wired` is reported alongside so a caller can assert there was something to check. A gate whose subject
138
+ * has gone missing — a renamed option, a hooks object built somewhere else — would otherwise pass by
139
+ * finding nothing, which is the failure mode a gate exists to not have.
140
+ */
141
+ function surveyDeleteHooks(databaseHooks) {
142
+ const survey = {
143
+ wired: [],
144
+ unclaimed: []
145
+ };
146
+ if (typeof databaseHooks !== "object" || databaseHooks === null) return survey;
147
+ for (const [model, hooks] of Object.entries(databaseHooks)) {
148
+ if (typeof hooks !== "object" || hooks === null) continue;
149
+ const remove = hooks.delete;
150
+ if (typeof remove !== "object" || remove === null) continue;
151
+ const { after, before } = remove;
152
+ if (typeof after !== "function") continue;
153
+ survey.wired.push(model);
154
+ const branded = after[CLAIMS_ITS_REMOVALS] === true;
155
+ if (typeof before !== "function" || !branded) survey.unclaimed.push(model);
156
+ }
157
+ survey.wired.sort();
158
+ survey.unclaimed.sort();
159
+ return survey;
160
+ }
161
+ //#endregion
162
+ export { SEND_FAULT, claimedDelete, markMessageDelivery, markSessionEnded, messageDeliveryDuring, sessionEndedDuring, surveyDeleteHooks };
@@ -6,6 +6,7 @@ import type { EmailCapability } from "@pithy-sh/email/src/capability";
6
6
  import { type TurnstileMode } from "@pithy-sh/turnstile/src/config/config";
7
7
  import { z } from "zod";
8
8
  import type { GithubUserInfoResolver } from "./instance/githubUserInfo";
9
+ import { type AuthPeer } from "./peer";
9
10
  /** The auth capability's configuration — the thin surface an adopter owns in `pithy.config.ts`. */
10
11
  export declare const AuthConfig: z.ZodObject<{
11
12
  basePath: z.ZodDefault<z.ZodString>;
@@ -117,6 +118,12 @@ export type AuthOptions = AuthConfigInput & {
117
118
  /** The auth capability, with its resolved config attached for inspection. */
118
119
  export interface AuthCapability extends Capability {
119
120
  authConfig: AuthConfig;
121
+ /**
122
+ * What a capability composed beside this one reads an account through — `matchmaking`, `support`,
123
+ * `testers`. Found in their `compose` hooks, so none of them imports this package and a project without
124
+ * auth bundles them (#645). See `peer.ts`.
125
+ */
126
+ authPeer: AuthPeer;
120
127
  }
121
128
  /**
122
129
  * The auth capability. Passwordless sign-in (magic link, OTP, Google, Apple), the hybr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ACzB,MAAM,EAAE,UAAU,CAAC;IACnB,8GAA8G;IAC9G,qBAAqB,EAAE,sBAAsB,GAAG,SAAS,CAAC;IAC1D,sGAAsG;IACtG,YAAY,EAAE,eAAe,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;IACrD,6FAA6F;IAC7F,SAAS,EAAE;QAAE,IAAI,EAAE,aAAa,CAAA;KAAE,GAAG,SAAS,CAAC;IAC/C;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,sBAAsB,GAAG,SAAS,CAAC;CACvD;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,sBAAsB,GAAG,CAAC,OAAO,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAAE,EAAE,EAAE,UAAU,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEhH;;;;;;;GAOG;AACH,MAAM,MAAM,WAAW,GAAG,eAAe,GAAG;IAC1C;;;;;;;;;;;;;OAaG;IACH,qBAAqB,CAAC,EAAE,sBAAsB,CAAC;IAC/C;;;;;;;;;;;;;;OAcG;IACH,gBAAgB,CAAC,EAAE,sBAAsB,CAAC;CAC3C,CAAC;AAEF,6EAA6E;AAC7E,MAAM,WAAW,cAAe,SAAQ,UAAU;IAChD,UAAU,EAAE,UAAU,CAAC;IACvB;;;;OAIG;IACH,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAiCD;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,cAAc,CA+JzD;AAED,0DAA0D;AAC1D,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,IAAI,cAAc,CAErF"}
@@ -13,8 +13,9 @@ import { createAuthRoutes } from "./http/routes.js";
13
13
  import "./migrations/0001_init.js";
14
14
  import { authPluginPlan } from "./migrations/pluginTables.js";
15
15
  import { AUTH_MIGRATIONS } from "./migrations/set.js";
16
+ import { authPeer } from "./peer.js";
16
17
  import { authExampleSeed } from "./seeds/example.js";
17
- import { PACKAGE_VERSION } from "./version.generated.js";
18
+ import { PACKAGE_NAME, PACKAGE_VERSION } from "./version.generated.js";
18
19
  import { defineCapability } from "@pithy-sh/core/src/capability/capability";
19
20
  import { ValidationError } from "@pithy-sh/core/src/error/pithyError";
20
21
  import { isEmailCapability } from "@pithy-sh/email/src/capability";
@@ -102,6 +103,7 @@ function auth(options) {
102
103
  const capability = defineCapability({
103
104
  name: "auth",
104
105
  version: PACKAGE_VERSION,
106
+ package: PACKAGE_NAME,
105
107
  config: AuthConfig,
106
108
  dependsOn: ["secrets", "email"],
107
109
  secretRegistry: authSecretsRegistry,
@@ -184,7 +186,10 @@ function auth(options) {
184
186
  adminRoutes: authAdminRoutes(resolved.basePath),
185
187
  seeds: [authExampleSeed, authDevSessionSeed]
186
188
  });
187
- return Object.assign(capability, { authConfig: resolved });
189
+ return Object.assign(capability, {
190
+ authConfig: resolved,
191
+ authPeer
192
+ });
188
193
  }
189
194
  /** Type guard: is this capability the auth capability? */
190
195
  function isAuthCapability(capability) {
@@ -300,6 +300,14 @@ export type SocialSignIn = {
300
300
  * about what just happened. Pass the sign-in screen's own path and the refusal returns to the control
301
301
  * that started it, as `?error=<code>`. That is the transport the whole GitHub rejection copy depends on
302
302
  * (pithy-sh/pithy#554); without it the sentence exists and is unreachable.
303
+ *
304
+ * **The value has a shape, and the Worker refuses one that does not fit (#625).** An absolute URL on a
305
+ * trusted origin, or a root-relative path — with **no fragment** and no `error`/`error_description`
306
+ * parameter already on it. Better Auth appends `?error=<code>` to this string without parsing it, so a
307
+ * `#` anywhere in it swallows the code the refusal screen is waiting for, and an `error` already there
308
+ * makes two. A value that cannot be normalized is answered `400 validation/invalid_input` naming the
309
+ * field, rather than quietly rewritten into a destination nobody asked for. A hash-routed error screen
310
+ * passes its route as a query parameter instead. See `../http/errorCallbackUrl`.
303
311
  */
304
312
  export declare function startSocialSignIn(input: {
305
313
  provider: string;
@@ -1 +1 @@
1
- {"version":3,"file":"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CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,YAAY,CAAC,CAOvB"}
@@ -374,6 +374,14 @@ function isAuthorization(value) {
374
374
  * about what just happened. Pass the sign-in screen's own path and the refusal returns to the control
375
375
  * that started it, as `?error=<code>`. That is the transport the whole GitHub rejection copy depends on
376
376
  * (pithy-sh/pithy#554); without it the sentence exists and is unreachable.
377
+ *
378
+ * **The value has a shape, and the Worker refuses one that does not fit (#625).** An absolute URL on a
379
+ * trusted origin, or a root-relative path — with **no fragment** and no `error`/`error_description`
380
+ * parameter already on it. Better Auth appends `?error=<code>` to this string without parsing it, so a
381
+ * `#` anywhere in it swallows the code the refusal screen is waiting for, and an `error` already there
382
+ * makes two. A value that cannot be normalized is answered `400 validation/invalid_input` naming the
383
+ * field, rather than quietly rewritten into a destination nobody asked for. A hash-routed error screen
384
+ * passes its route as a query parameter instead. See `../http/errorCallbackUrl`.
377
385
  */
378
386
  async function startSocialSignIn(input, options) {
379
387
  const ungated = options && {
@@ -1,6 +1,7 @@
1
1
  // SPDX-FileCopyrightText: 2026 Pithy
2
2
  // SPDX-License-Identifier: MIT
3
3
  import type { EmailCapability } from "@pithy-sh/email/src/capability";
4
+ import type { EnqueueResult } from "@pithy-sh/email/src/send/enqueue";
4
5
  import type { SendAuthEmail } from "../instance/auth";
5
6
  /**
6
7
  * The email-delivery seam. Auth never assembles the email infrastructure — it calls the `enqueue` the
@@ -8,8 +9,15 @@ import type { SendAuthEmail } from "../instance/auth";
8
9
  * high-level input. The email capability owns the `DB`/`EMAIL_SENDER` bindings, the from-identity, and
9
10
  * the theme. Delivery is the email Workflow's job; auth only enqueues.
10
11
  */
11
- /** An env-bound enqueue — the email capability's `enqueue`, partially applied with the request env. */
12
- export type EnqueueEmail = (input: Parameters<EmailCapability["enqueue"]>[1]) => Promise<unknown>;
12
+ /**
13
+ * An env-bound enqueue — the email capability's `enqueue`, partially applied with the request env.
14
+ *
15
+ * **Its result is the point, and it used to be `unknown`.** The capability answers with the job id, the
16
+ * status the row was born with and, where it withheld the message, the reason — which is the only place
17
+ * anything knows whether a send is coming. Thrown away, the two audit events that claim a message had
18
+ * nothing left to read but the fact that this function was called (#627).
19
+ */
20
+ export type EnqueueEmail = (input: Parameters<EmailCapability["enqueue"]>[1]) => Promise<EnqueueResult>;
13
21
  /**
14
22
  * The language to write to this person in, resolved per message.
15
23
  *
@@ -1 +1 @@
1
- {"version":3,"file":"send.d.ts","sourceRoot":"","sources":["../../src/email/send.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,KAAK,EAAoB,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAExE;;;;;GAKG;AAEH,uGAAuG;AACvG,MAAM,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,UAAU,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAElG;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;AAE/E;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,YAAY,EACrB,cAAc,EAAE,MAAM,EACtB,SAAS,CAAC,EAAE,sBAAsB,GACjC,aAAa,CAmBf"}
1
+ {"version":3,"file":"send.d.ts","sourceRoot":"","sources":["../../src/email/send.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AAEtE,OAAO,KAAK,EAAoB,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAExE;;;;;GAKG;AAEH;;;;;;;GAOG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,UAAU,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;AAExG;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;AAE/E;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,YAAY,EACrB,cAAc,EAAE,MAAM,EACtB,SAAS,CAAC,EAAE,sBAAsB,GACjC,aAAa,CAsBf"}
@@ -23,19 +23,16 @@
23
23
  function makeSendAuthEmail(enqueue, expiresMinutes, localeFor) {
24
24
  return async (message) => {
25
25
  const locale = await localeFor?.(message.to) ?? void 0;
26
- if (message.template === "magicLink") {
27
- await enqueue({
28
- to: message.to,
29
- template: "magicLink",
30
- payload: {
31
- url: message.url,
32
- expiresMinutes
33
- },
34
- ...locale ? { locale } : {}
35
- });
36
- return;
37
- }
38
- await enqueue({
26
+ if (message.template === "magicLink") return deliveryOf(await enqueue({
27
+ to: message.to,
28
+ template: "magicLink",
29
+ payload: {
30
+ url: message.url,
31
+ expiresMinutes
32
+ },
33
+ ...locale ? { locale } : {}
34
+ }));
35
+ return deliveryOf(await enqueue({
39
36
  to: message.to,
40
37
  template: "otp",
41
38
  payload: {
@@ -43,8 +40,33 @@ function makeSendAuthEmail(enqueue, expiresMinutes, localeFor) {
43
40
  expiresMinutes
44
41
  },
45
42
  ...locale ? { locale } : {}
46
- });
43
+ }));
44
+ };
45
+ }
46
+ /**
47
+ * What one enqueue means for the trail — the translation from the email capability's vocabulary into
48
+ * `auth`'s.
49
+ *
50
+ * **`suppressed` is the only status that is not a send.** The capability consulted the global suppression
51
+ * list, withheld the message and started nothing; the row it wrote exists so an operator can see the
52
+ * withholding, not because anything is coming for it. The reason rides along because "suppressed" alone
53
+ * does not tell anybody whether the mailbox is dead, the person complained, or an operator did it by
54
+ * hand — and those are three different next moves. `suppressionReason` is optional on the result, so its
55
+ * absence falls back to the status itself rather than to a fabricated reason.
56
+ *
57
+ * **`undispatched` is a send, deliberately.** It means this composition binds no send Workflow yet, so
58
+ * nothing was *started* — but the job row exists and the scheduler drains those the day a host is
59
+ * deployed (pithy-sh/pithy#410). `auth/otp_sent` claims a message was enqueued for delivery, which is
60
+ * exactly what happened; the deployment gap is the email capability's own channel to report, and
61
+ * recording it here as a decline would put "this deployment is incomplete" in a column an abuse count is
62
+ * read from.
63
+ */
64
+ function deliveryOf(result) {
65
+ if (result.status === "suppressed") return {
66
+ delivery: "withheld",
67
+ reason: result.suppressionReason ?? result.status
47
68
  };
69
+ return { delivery: "queued" };
48
70
  }
49
71
  //#endregion
50
72
  export { makeSendAuthEmail };
@@ -0,0 +1,40 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ /**
4
+ * Normalize one `errorCallbackURL`, or refuse it.
5
+ *
6
+ * **The caller's intent is preserved.** A root-relative input stays root-relative — this Worker's origin
7
+ * is not necessarily the adopter's, and answering `/sign-in` as `https://this-worker/sign-in` would
8
+ * retarget their error screen at us. An absolute one stays absolute, on its own origin. What changes is
9
+ * only the shape: percent-encoding, dot segments and an empty trailing `?` are canonicalized, which is
10
+ * what a browser does to the same string before it fetches it.
11
+ *
12
+ * **A `//host/path` input is *not* root-relative**, even though it starts with a slash. It resolves to
13
+ * another origin, and treating it as a path would hand it this Worker's. It is parsed as an absolute URL
14
+ * — `new URL()` alone refuses it, so it is refused here, which is what Better Auth's own origin check
15
+ * does with it too.
16
+ *
17
+ * @param value The raw string from the request body.
18
+ * @param requestUrl The absolute URL of the request carrying it, used only to resolve a root-relative
19
+ * path for parsing. Only `pathname` and `search` are kept from that resolution, so it never reaches
20
+ * the returned value.
21
+ */
22
+ export declare function normalizeErrorCallbackURL(value: string, requestUrl: string): string;
23
+ /**
24
+ * Hand back the request Better Auth should see: the same one, or one whose `errorCallbackURL` is normalized.
25
+ *
26
+ * **The original is returned untouched whenever nothing needs doing**, which is almost every request.
27
+ * Rebuilding a request costs a body round trip and is a second place for a header to go missing, so it
28
+ * happens only when the field is actually present and actually changed.
29
+ *
30
+ * **The body is read from a clone.** A request body is a stream and Better Auth reads the original; this
31
+ * one is consumed here.
32
+ *
33
+ * **Both channels, in the dependency's own order**: the router's query first, because it builds one for
34
+ * every request, then `getBody`'s body branches in `getBody`'s order — see the module docblock on reach.
35
+ * A body it decodes to something that is not a keyed object (`text/plain` to a string,
36
+ * `application/octet-stream` to a buffer, an unknown type to the stream itself) carries no field to
37
+ * guard, so it is left alone here for the same reason it is ignored there.
38
+ */
39
+ export declare function guardErrorCallbackURL(request: Request, requestUrl: string): Promise<Request>;
40
+ //# sourceMappingURL=errorCallbackUrl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errorCallbackUrl.d.ts","sourceRoot":"","sources":["../../src/http/errorCallbackUrl.ts"],"names":[],"mappings":"AAiKA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CA8CnF;AA0ED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAkBlG"}