@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,130 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import type { AuditEmit } from "@pithy-sh/core/src/audit/recorder";
4
+ import type { BetterAuthPlugin } from "better-auth";
5
+ /**
6
+ * One answer for both provider sign-in refusals, decided before Better Auth branches (#625).
7
+ *
8
+ * ## Reach, first, because that is the claim
9
+ *
10
+ * This plugin decorates `getUserInfo` on **every provider object Better Auth already built** — the live
11
+ * `ctx.socialProviders` array, wrapped rather than replaced. So the guarantee is: **on the OAuth redirect
12
+ * callback, for every provider this instance serves, rows 3 and 4 below are refused with one answer, and
13
+ * neither `account_not_linked` nor `signup_disabled` is produced at all.**
14
+ *
15
+ * It does not reach three things, named here rather than left for a ninth round to find:
16
+ *
17
+ * - **`POST /sign-in/social` carrying an `idToken`** (`api/routes/sign-in.mjs:154-200`). That request
18
+ * returns before `generateState`, so there is no OAuth state and the gate cannot tell it from
19
+ * `/link-social`'s own id-token branch, which must be passed through. It reaches the same two codes.
20
+ * The mitigating fact is that it requires a provider-signed, audience-bound assertion of the address,
21
+ * so it is not an address an attacker picks — which is why the claim above says *the redirect
22
+ * callback* and not *provider sign-in*.
23
+ * - **A plugin that calls `handleOAuthUserInfo` without going through `provider.getUserInfo`.**
24
+ * `plugins/one-tap/index.mjs:45-70` builds the user info straight from a verified Google id token;
25
+ * `plugins/oauth-proxy/index.mjs:110` lifts it out of an encrypted proxy payload. The kit composes
26
+ * neither. `./refusalTransport` is where a composed plugin is ruled on.
27
+ * - **An adopter plugin that replaces `ctx.socialProviders` in its own `init`.** Kit plugins run first
28
+ * by contract (`./auth.ts` composes them ahead of the adopter's), so the wrap is installed before
29
+ * anything an adopter adds — but the plugin contract permits the replacement and nothing can detect
30
+ * it from in here. Same class of escape `./refusalTransport` already exists to bound.
31
+ *
32
+ * ## The defect
33
+ *
34
+ * Signing in with a provider while not signed in has four outcomes, and the first two are untouched by
35
+ * everything below:
36
+ *
37
+ * | # | Situation | Outcome |
38
+ * | --- | --- | --- |
39
+ * | 1 | The provider identity is already attached to an account | Signs in |
40
+ * | 2 | Not attached, and the provider's **verified** address matches an account | Links and signs in |
41
+ * | 3 | Not attached, address unverified at the provider, an account exists there | Refused |
42
+ * | 4 | Not attached, no account at that address | Refused |
43
+ *
44
+ * Rows 3 and 4 differ only in whether a row exists at an address **the caller chose**, and Better Auth
45
+ * answers them with two different codes — `account_not_linked` (`oauth2/link-account.mjs:86`, returned
46
+ * only inside `if (dbUser)`) and `signup_disabled` (`:202`, the `else` of that same branch). Both reach
47
+ * the browser as `?error=<code>`. That is an account-enumeration oracle needing one provider account,
48
+ * none on the target, and no page render.
49
+ *
50
+ * ## Why here, and not on the way out
51
+ *
52
+ * Eight earlier rounds rewrote the response instead. Each closed one transport and the next found
53
+ * another, and the last keyed on a value `callbackURL` supplies, so it rewrote *successful* sign-ins.
54
+ * By the time a response exists the fact that distinguished the two cases is gone and what is left is
55
+ * partly the caller's. `getUserInfo` is the last seam that holds the fact itself: `callback.mjs:120`
56
+ * calls it, `:220` calls `handleOAuthUserInfo`, and **nothing runs in between** — so a refusal thrown
57
+ * here means neither of those two lines is ever reached and there is no pair left to collapse.
58
+ *
59
+ * ## Why a wrapper, and not a `getUserInfo` supplied in the config block
60
+ *
61
+ * `options.getUserInfo` short-circuits each provider's own resolver on its first line
62
+ * (`social-providers/google.mjs:118`, `facebook.mjs:93`, `apple.mjs:62`, `github.mjs:65`), so supplying
63
+ * one means reimplementing the profile fetch it replaced — Google's id-token decode, Facebook's
64
+ * access-token-owner check. `./githubUserInfo.ts` already records what that costs: replacing GitHub's
65
+ * resolver silently dropped `name` and `image`, which had to be re-derived. Wrapping calls the
66
+ * dependency's own resolver and reads its result, so nothing is reimplemented and nothing reconstructed.
67
+ *
68
+ * **And it is the wrapping that makes the predicate read the right flag.** `mapProfileToUser` is applied
69
+ * *inside* each provider's own `getUserInfo` — every one of the four spreads `...userMap` over the
70
+ * `emailVerified` it computed — so the value this module reads is by construction the **effective** flag.
71
+ * Facebook is the trap that makes this load-bearing: it sits outside `trustedProviders` like GitHub, but
72
+ * `./auth.ts` asserts its address as verified with a documented reason, and its OAuth response carries no
73
+ * `email_verified` claim at all. A predicate reading the raw provider payload would see nothing, conclude
74
+ * unverified, and refuse a Facebook sign-in that works today. From in here the raw payload is not even in
75
+ * scope to read by mistake.
76
+ */
77
+ /**
78
+ * The plugin id, reserved in `./plugins.ts` like the four Better Auth ones.
79
+ *
80
+ * Prefixed because it is the kit's own rather than a dependency's, and an adopter shadowing it would
81
+ * silently win the registration — which for this plugin means silently removing the gate.
82
+ */
83
+ export declare const PROVIDER_SIGN_IN_GATE_ID = "pithy-provider-sign-in-gate";
84
+ /**
85
+ * What the trail records, which is the half the browser does not get.
86
+ *
87
+ * Two values, because the whole point is that the distinction survives *server-side*. They are the kit's
88
+ * own words rather than Better Auth's two codes: those codes are no longer produced anywhere, and
89
+ * recording a string the dependency can no longer emit would send the next reader looking for it.
90
+ */
91
+ export declare const PROVIDER_SIGN_IN_REFUSAL_REASONS: {
92
+ /** Row 3: an account exists at the address the provider asserted, and nothing licensed a link to it. */
93
+ readonly accountExists: "unlinked_identity_account_exists";
94
+ /** Row 4: no account at that address, and this attempt may not create one. */
95
+ readonly noAccount: "unlinked_identity_no_account";
96
+ };
97
+ /** What the gate needs from the instance: the audit seam, and enough of the request to attribute a row. */
98
+ export interface ProviderSignInGateDeps {
99
+ /** Audit seam — where the true reason for a refusal goes, since the browser no longer gets it. */
100
+ emit: AuditEmit;
101
+ /**
102
+ * This request's headers, for the `ip` and `user-agent` every other denial row carries.
103
+ *
104
+ * **Threaded rather than read from the flow, and it has to be.** `getUserInfo` is handed the OAuth
105
+ * tokens and nothing else — no request, no endpoint context — so the only way this correlation reaches
106
+ * the row is from where the instance is built, which is per request (`../http/resolve.ts`). Without it
107
+ * these refusals would be the one kind of denial in the trail that cannot be counted per caller, which
108
+ * is most of what a trail of refused sign-ins is for.
109
+ *
110
+ * `undefined` where no request built the instance — a seed, a test harness — and `correlation` already
111
+ * answers that with two absent fields rather than a throw.
112
+ */
113
+ headers: Headers | undefined;
114
+ }
115
+ /**
116
+ * The kit's provider sign-in gate, as a Better Auth plugin.
117
+ *
118
+ * `init` is handed the live `AuthContext` — `runPluginInit` runs after `create-context.mjs` has built
119
+ * every provider and stored the finished array on `ctx.socialProviders`, and `Object.assign`s whatever
120
+ * the plugin returns. So this is the one seam that reaches **all** providers without naming any of them:
121
+ * a provider an adopter's config adds later is wrapped by the same loop.
122
+ *
123
+ * **`ctx.internalAdapter` is read at call time and never captured**, because `runPluginInit` *replaces*
124
+ * `context.internalAdapter` after the plugin loop (`context/helpers.mjs:47`). Capturing it in `init`
125
+ * would hold the pre-hook adapter. `ctx.trustedProviders` is closed over, which is sound while the kit's
126
+ * own value is the static `["google", "apple"]` it sets in `./auth.ts`; `auth/base.mjs` recomputes it on
127
+ * a per-request clone, so this would need revisiting if it ever became a function of the request.
128
+ */
129
+ export declare function providerSignInGate(deps: ProviderSignInGateDeps): BetterAuthPlugin;
130
+ //# sourceMappingURL=providerSignInGate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"providerSignInGate.d.ts","sourceRoot":"","sources":["../../src/instance/providerSignInGate.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,KAAK,EAAe,gBAAgB,EAAiB,MAAM,aAAa,CAAC;AAKhF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuEG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,gCAAgC,CAAC;AAEtE;;;;;;GAMG;AACH,eAAO,MAAM,gCAAgC;IAC3C,wGAAwG;aACxG,aAAa,EAAE,kCAAkC;IACjD,8EAA8E;aAC9E,SAAS,EAAE,8BAA8B;CACjC,CAAC;AAEX,2GAA2G;AAC3G,MAAM,WAAW,sBAAsB;IACrC,kGAAkG;IAClG,IAAI,EAAE,SAAS,CAAC;IAChB;;;;;;;;;;;OAWG;IACH,OAAO,EAAE,OAAO,GAAG,SAAS,CAAC;CAC9B;AAyKD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,sBAAsB,GAAG,gBAAgB,CAkBjF"}
@@ -0,0 +1,230 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import { correlation, emitDenied } from "../audit/emit.js";
4
+ import { NEUTRAL_PROVIDER_REFUSAL } from "../http/providerRefusal.js";
5
+ import { APIError, getOAuthState } from "better-auth/api";
6
+ //#region src/instance/providerSignInGate.ts
7
+ /**
8
+ * One answer for both provider sign-in refusals, decided before Better Auth branches (#625).
9
+ *
10
+ * ## Reach, first, because that is the claim
11
+ *
12
+ * This plugin decorates `getUserInfo` on **every provider object Better Auth already built** — the live
13
+ * `ctx.socialProviders` array, wrapped rather than replaced. So the guarantee is: **on the OAuth redirect
14
+ * callback, for every provider this instance serves, rows 3 and 4 below are refused with one answer, and
15
+ * neither `account_not_linked` nor `signup_disabled` is produced at all.**
16
+ *
17
+ * It does not reach three things, named here rather than left for a ninth round to find:
18
+ *
19
+ * - **`POST /sign-in/social` carrying an `idToken`** (`api/routes/sign-in.mjs:154-200`). That request
20
+ * returns before `generateState`, so there is no OAuth state and the gate cannot tell it from
21
+ * `/link-social`'s own id-token branch, which must be passed through. It reaches the same two codes.
22
+ * The mitigating fact is that it requires a provider-signed, audience-bound assertion of the address,
23
+ * so it is not an address an attacker picks — which is why the claim above says *the redirect
24
+ * callback* and not *provider sign-in*.
25
+ * - **A plugin that calls `handleOAuthUserInfo` without going through `provider.getUserInfo`.**
26
+ * `plugins/one-tap/index.mjs:45-70` builds the user info straight from a verified Google id token;
27
+ * `plugins/oauth-proxy/index.mjs:110` lifts it out of an encrypted proxy payload. The kit composes
28
+ * neither. `./refusalTransport` is where a composed plugin is ruled on.
29
+ * - **An adopter plugin that replaces `ctx.socialProviders` in its own `init`.** Kit plugins run first
30
+ * by contract (`./auth.ts` composes them ahead of the adopter's), so the wrap is installed before
31
+ * anything an adopter adds — but the plugin contract permits the replacement and nothing can detect
32
+ * it from in here. Same class of escape `./refusalTransport` already exists to bound.
33
+ *
34
+ * ## The defect
35
+ *
36
+ * Signing in with a provider while not signed in has four outcomes, and the first two are untouched by
37
+ * everything below:
38
+ *
39
+ * | # | Situation | Outcome |
40
+ * | --- | --- | --- |
41
+ * | 1 | The provider identity is already attached to an account | Signs in |
42
+ * | 2 | Not attached, and the provider's **verified** address matches an account | Links and signs in |
43
+ * | 3 | Not attached, address unverified at the provider, an account exists there | Refused |
44
+ * | 4 | Not attached, no account at that address | Refused |
45
+ *
46
+ * Rows 3 and 4 differ only in whether a row exists at an address **the caller chose**, and Better Auth
47
+ * answers them with two different codes — `account_not_linked` (`oauth2/link-account.mjs:86`, returned
48
+ * only inside `if (dbUser)`) and `signup_disabled` (`:202`, the `else` of that same branch). Both reach
49
+ * the browser as `?error=<code>`. That is an account-enumeration oracle needing one provider account,
50
+ * none on the target, and no page render.
51
+ *
52
+ * ## Why here, and not on the way out
53
+ *
54
+ * Eight earlier rounds rewrote the response instead. Each closed one transport and the next found
55
+ * another, and the last keyed on a value `callbackURL` supplies, so it rewrote *successful* sign-ins.
56
+ * By the time a response exists the fact that distinguished the two cases is gone and what is left is
57
+ * partly the caller's. `getUserInfo` is the last seam that holds the fact itself: `callback.mjs:120`
58
+ * calls it, `:220` calls `handleOAuthUserInfo`, and **nothing runs in between** — so a refusal thrown
59
+ * here means neither of those two lines is ever reached and there is no pair left to collapse.
60
+ *
61
+ * ## Why a wrapper, and not a `getUserInfo` supplied in the config block
62
+ *
63
+ * `options.getUserInfo` short-circuits each provider's own resolver on its first line
64
+ * (`social-providers/google.mjs:118`, `facebook.mjs:93`, `apple.mjs:62`, `github.mjs:65`), so supplying
65
+ * one means reimplementing the profile fetch it replaced — Google's id-token decode, Facebook's
66
+ * access-token-owner check. `./githubUserInfo.ts` already records what that costs: replacing GitHub's
67
+ * resolver silently dropped `name` and `image`, which had to be re-derived. Wrapping calls the
68
+ * dependency's own resolver and reads its result, so nothing is reimplemented and nothing reconstructed.
69
+ *
70
+ * **And it is the wrapping that makes the predicate read the right flag.** `mapProfileToUser` is applied
71
+ * *inside* each provider's own `getUserInfo` — every one of the four spreads `...userMap` over the
72
+ * `emailVerified` it computed — so the value this module reads is by construction the **effective** flag.
73
+ * Facebook is the trap that makes this load-bearing: it sits outside `trustedProviders` like GitHub, but
74
+ * `./auth.ts` asserts its address as verified with a documented reason, and its OAuth response carries no
75
+ * `email_verified` claim at all. A predicate reading the raw provider payload would see nothing, conclude
76
+ * unverified, and refuse a Facebook sign-in that works today. From in here the raw payload is not even in
77
+ * scope to read by mistake.
78
+ */
79
+ /**
80
+ * The plugin id, reserved in `./plugins.ts` like the four Better Auth ones.
81
+ *
82
+ * Prefixed because it is the kit's own rather than a dependency's, and an adopter shadowing it would
83
+ * silently win the registration — which for this plugin means silently removing the gate.
84
+ */
85
+ const PROVIDER_SIGN_IN_GATE_ID = "pithy-provider-sign-in-gate";
86
+ /**
87
+ * What the trail records, which is the half the browser does not get.
88
+ *
89
+ * Two values, because the whole point is that the distinction survives *server-side*. They are the kit's
90
+ * own words rather than Better Auth's two codes: those codes are no longer produced anywhere, and
91
+ * recording a string the dependency can no longer emit would send the next reader looking for it.
92
+ */
93
+ const PROVIDER_SIGN_IN_REFUSAL_REASONS = {
94
+ /** Row 3: an account exists at the address the provider asserted, and nothing licensed a link to it. */
95
+ accountExists: "unlinked_identity_account_exists",
96
+ /** Row 4: no account at that address, and this attempt may not create one. */
97
+ noAccount: "unlinked_identity_no_account"
98
+ };
99
+ /**
100
+ * Build the redirect a refusal leaves by.
101
+ *
102
+ * **This mirrors `oauth2/errors.mjs`'s `redirectOnError` deliberately, and the mirror is measured rather
103
+ * than asserted:** `providerSignInGate.workers.test.ts` drives a refusal the dependency still emits
104
+ * (`email_not_found`) beside one this gate emits and requires the two `Location` headers to differ in
105
+ * nothing but the code. `ctx.redirect(url)` is itself only `new APIError("FOUND", undefined, headers)`
106
+ * with `location` set (`better-call/dist/context.mjs:60`), and better-auth's router passes a `FOUND`
107
+ * straight through its `onError` to `toResponse` (`api/index.mjs:192`), so this is the same object the
108
+ * dependency would have thrown — built without the endpoint context `getUserInfo` is not handed.
109
+ *
110
+ * The value being appended to is the OAuth state's own `errorURL`, which is where `redirectOnError`
111
+ * reads it from too, and which `../http/errorCallbackUrl` has already normalized on the way in.
112
+ */
113
+ function refusalRedirect(errorURL) {
114
+ const separator = errorURL.includes("?") ? "&" : "?";
115
+ const query = new URLSearchParams({ error: NEUTRAL_PROVIDER_REFUSAL }).toString();
116
+ return new APIError("FOUND", void 0, new Headers({ location: `${errorURL}${separator}${query}` }));
117
+ }
118
+ /**
119
+ * The refusal when the state carried no `errorURL` to redirect to.
120
+ *
121
+ * Unreachable on the callback — `parseState` fills `errorURL` from `onAPIError.errorURL` or
122
+ * `${baseURL}/error` before it returns (`oauth2/state.mjs:61`) — and written anyway, because the
123
+ * alternative to a refusal with nowhere to send it is passing the attempt through, which is the one
124
+ * direction this module must never fail in.
125
+ */
126
+ function refusalWithoutRedirect() {
127
+ return new APIError("FORBIDDEN", {
128
+ code: NEUTRAL_PROVIDER_REFUSAL,
129
+ message: "That provider did not sign you in."
130
+ });
131
+ }
132
+ /**
133
+ * Is this provider identity already attached to some account here? Row 1.
134
+ *
135
+ * **Keyed on `(providerId, accountId)`, which is wider than Better Auth's `(issuer, accountId)`, and
136
+ * wider is the safe direction.** Deriving the issuer means copying `createOAuthAccountIssuer` —
137
+ * `local:oauth:${encodeAccountIssuerProviderId(id)}` — from a package the kit does not depend on, and a
138
+ * second copy of a dependency's decision is the defect class this repo has been bitten by four times
139
+ * (#106, #108, #109, #113). A false match here passes the attempt through and lets Better Auth decide,
140
+ * which is today's behavior; a false *miss* is what would be dangerous, and widening cannot cause one.
141
+ *
142
+ * It reads no address and no verified flag, which is what keeps an `allowDifferentEmails` link signing in.
143
+ *
144
+ * `ctx.adapter` rather than a Kysely query: the adapter already maps `account` to `pithyAuthAccounts`
145
+ * and camelCase to snake_case, and a query written here would be a second spelling of that mapping.
146
+ */
147
+ async function identityAlreadyAttached(ctx, provider, token, profile) {
148
+ const subject = await provider.accountSubject({
149
+ tokens: token,
150
+ profile
151
+ });
152
+ const accountId = String(subject);
153
+ if (accountId.trim().length === 0) return false;
154
+ const row = await ctx.adapter.findOne({
155
+ model: "account",
156
+ where: [{
157
+ field: "providerId",
158
+ value: provider.id
159
+ }, {
160
+ field: "accountId",
161
+ value: accountId
162
+ }]
163
+ });
164
+ return row !== null && row !== void 0;
165
+ }
166
+ /**
167
+ * Decide one social sign-in callback: pass it through, or refuse it identically whichever row it is.
168
+ *
169
+ * **Scope first, then decide, and the default is pass-through**, because pass-through is today's
170
+ * behavior and is the only safe mispredict: an attempt this lets past is one Better Auth then rules on
171
+ * exactly as it does now.
172
+ */
173
+ async function gateProviderSignIn(args) {
174
+ const { ctx, provider, token, result, deps } = args;
175
+ const state = await getOAuthState();
176
+ if (state === null) return;
177
+ if (state.link !== void 0 && state.link !== null) return;
178
+ const email = result.user.email;
179
+ if (!email) return;
180
+ if (await identityAlreadyAttached(ctx, provider, token, result.data)) return;
181
+ const local = await ctx.internalAdapter.findUserByEmail(email);
182
+ const providerVouches = ctx.trustedProviders.includes(provider.id) || result.user.emailVerified === true;
183
+ const localVouches = !(ctx.options.account?.accountLinking?.requireLocalEmailVerified ?? true) || local?.user.emailVerified === true;
184
+ if (local && providerVouches && localVouches) return;
185
+ if (!(local !== null || provider.options?.disableSignUp === true || result.user.emailVerified !== true)) return;
186
+ await emitDenied(deps.emit, {
187
+ ...correlation(deps.headers),
188
+ detail: local ? PROVIDER_SIGN_IN_REFUSAL_REASONS.accountExists : PROVIDER_SIGN_IN_REFUSAL_REASONS.noAccount
189
+ });
190
+ const errorURL = typeof state.errorURL === "string" ? state.errorURL : void 0;
191
+ throw errorURL ? refusalRedirect(errorURL) : refusalWithoutRedirect();
192
+ }
193
+ /**
194
+ * The kit's provider sign-in gate, as a Better Auth plugin.
195
+ *
196
+ * `init` is handed the live `AuthContext` — `runPluginInit` runs after `create-context.mjs` has built
197
+ * every provider and stored the finished array on `ctx.socialProviders`, and `Object.assign`s whatever
198
+ * the plugin returns. So this is the one seam that reaches **all** providers without naming any of them:
199
+ * a provider an adopter's config adds later is wrapped by the same loop.
200
+ *
201
+ * **`ctx.internalAdapter` is read at call time and never captured**, because `runPluginInit` *replaces*
202
+ * `context.internalAdapter` after the plugin loop (`context/helpers.mjs:47`). Capturing it in `init`
203
+ * would hold the pre-hook adapter. `ctx.trustedProviders` is closed over, which is sound while the kit's
204
+ * own value is the static `["google", "apple"]` it sets in `./auth.ts`; `auth/base.mjs` recomputes it on
205
+ * a per-request clone, so this would need revisiting if it ever became a function of the request.
206
+ */
207
+ function providerSignInGate(deps) {
208
+ return {
209
+ id: PROVIDER_SIGN_IN_GATE_ID,
210
+ init: (ctx) => {
211
+ for (const provider of ctx.socialProviders) {
212
+ const resolve = provider.getUserInfo.bind(provider);
213
+ provider.getUserInfo = async (token) => {
214
+ const result = await resolve(token);
215
+ if (!result?.user) return result;
216
+ await gateProviderSignIn({
217
+ ctx,
218
+ provider,
219
+ token,
220
+ result,
221
+ deps
222
+ });
223
+ return result;
224
+ };
225
+ }
226
+ }
227
+ };
228
+ }
229
+ //#endregion
230
+ export { PROVIDER_SIGN_IN_GATE_ID, PROVIDER_SIGN_IN_REFUSAL_REASONS, providerSignInGate };
@@ -0,0 +1,91 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ /**
4
+ * Which composed plugins can answer a callback refusal somewhere the collapse cannot read (#625).
5
+ *
6
+ * ## What the collapse actually covers
7
+ *
8
+ * `../http/providerRefusal` reads one thing: the `Location` header of the Response
9
+ * `instance.handler()` returned. So the guarantee it gives is exactly that — **a refusal that leaves
10
+ * this Worker through that header is collapsed to one neutral code**. Everything the kit itself composes
11
+ * answers that way, because Better Auth's social callback answers that way. A plugin an adopter composes
12
+ * need not.
13
+ *
14
+ * ## The sixth round, and why it is not a sixth channel guard
15
+ *
16
+ * Five rounds each closed one transport for a malformed `errorCallbackURL` — a relative `Location`, a
17
+ * planted `error` parameter, a fragment, a body the prefilter did not read, a query string — and each
18
+ * time the next shape was found somewhere else. The sixth needs no malformed input at all.
19
+ *
20
+ * `better-auth/plugins`' own `oauthPopup()` registers an `after` hook matching `/callback/…`. Its
21
+ * handler reads the `location` Better Auth just wrote, lifts `error` and `error_description` off it, and
22
+ * assigns `c.context.returned` a **200 HTML page** that posts those values to the opener
23
+ * (`dist/plugins/oauth-popup/index.mjs:216-226`). By the time `handleBetterAuth` sees the response there
24
+ * is no redirect left to collapse and the revealing code is in a body. Drive
25
+ * `/auth/oauth-popup/start` with a perfectly well-formed `errorCallbackURL` — no fragment, nothing to
26
+ * normalize, nothing an input guard could object to — and the account-enumeration oracle is whole.
27
+ *
28
+ * **So there is nothing left to guard on the way in.** Either the kit collapses refusals wherever a
29
+ * composed plugin might put one, which is unbounded because a plugin may write any response it likes, or
30
+ * it says which compositions its guarantee covers and refuses the rest at the door. This module is the
31
+ * second. It is a scope decision: the claim is bounded to what the kit can actually hold.
32
+ *
33
+ * ## Why this is a roster of ids and not a property of a plugin object
34
+ *
35
+ * The honest predicate — the thing that separates `oauth-popup` from every plugin that is fine — is that
36
+ * its hook **replaces** the response rather than amending its headers. That is a fact about the body of a
37
+ * function. What a composed plugin object exposes at `auth()` is its `id`, its hook `matcher`s, which can
38
+ * be called, and its `handler`s, which are opaque.
39
+ *
40
+ * Calling the matchers is possible, and sound in the direction that matters: a plugin that rewrites the
41
+ * callback's response has to register an `after` hook that claims the callback path, because
42
+ * `BetterAuthPlugin` offers no other seam for it. It is also far too wide to be a refusal. Measured
43
+ * against `better-auth` 1.7.1 — every plugin its barrel exports, constructed, every `after` matcher asked
44
+ * about `/callback/:id`, `/callback/github` and `/oauth2/callback/:id` — seven say yes: `anonymous`,
45
+ * `bearer`, `last-login-method`, `multi-session`, `one-time-token`, `oauth-proxy` and `oauth-popup`.
46
+ * `matcher: () => true` is the ordinary idiom for a hook that only wants to read `set-cookie`. Six of the
47
+ * seven amend headers and nothing else, so refusing on that property would print, six times out of seven,
48
+ * a claim about a plugin that is not true of it. A gate whose stated reason is wider than its actual
49
+ * reason is the defect this round exists to stop repeating, one level up.
50
+ *
51
+ * **So the rule is a list, and its completeness is gated rather than asserted.**
52
+ * `refusalTransport.test.ts` scans `better-auth`'s own shipped plugin sources for the assignment that
53
+ * *is* the real predicate — `…context.returned = …` — and requires every plugin family it finds to carry
54
+ * a verdict here. Same shape as `../http/providerRefusal`'s code roster, for the same reason: the review
55
+ * is written down, and it cannot silently fall behind the thing it reviews. A bump that teaches a new
56
+ * plugin to replace the callback's response turns that red naming the directory.
57
+ *
58
+ * ## What this does not reach, stated rather than left to be inferred
59
+ *
60
+ * An adopter's **own** plugin can assign `context.returned` on the callback exactly as `oauthPopup` does,
61
+ * and nothing here will know. This gate runs inside their Worker while `pithy.config.ts` loads, where the
62
+ * only thing in hand is the object; the source scan reaches `better-auth`'s plugins because their source
63
+ * is on disk in a place the kit's own test suite can read, which is not true of an adopter's repo at
64
+ * `auth()`. The guarantee is therefore bounded, and every docblock that states it says so: **the kit's own
65
+ * routes, and any composed plugin that answers refusals through `Location`.**
66
+ */
67
+ /** Whether a Better Auth plugin can answer a callback refusal off the `Location` header, and why. */
68
+ export interface RefusalTransportVerdict {
69
+ /**
70
+ * The directory under `better-auth/dist/plugins/` this verdict was read from.
71
+ *
72
+ * Recorded rather than derived from the key, because the two are not the same string in general — the
73
+ * `haveibeenpwned` directory ships a plugin whose id is `have-i-been-pwned`. The completeness gate
74
+ * compares directories, since a source scan finds files.
75
+ */
76
+ readonly source: string;
77
+ /**
78
+ * `true` when the plugin answers a refused callback through something other than the `Location` header,
79
+ * which is the only transport the collapse reads. Such a plugin is refused at composition.
80
+ */
81
+ readonly outsideLocation: boolean;
82
+ /** Why. Written for the next person asked to make an exception, and for the next dependency bump. */
83
+ readonly why: string;
84
+ }
85
+ /** The roster, for the completeness gate. Not part of the package's surface. */
86
+ export declare const REFUSAL_TRANSPORT_ROSTER: Readonly<Record<string, RefusalTransportVerdict>>;
87
+ /** The plugin ids `auth()` refuses. Derived from the roster, so the gate and the review cannot disagree. */
88
+ export declare const REFUSED_PLUGIN_IDS: readonly string[];
89
+ /** The written verdict for a plugin id, or `undefined` when nobody has had to rule on that plugin. */
90
+ export declare function refusalTransportVerdict(id: string): RefusalTransportVerdict | undefined;
91
+ //# sourceMappingURL=refusalTransport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refusalTransport.d.ts","sourceRoot":"","sources":["../../src/instance/refusalTransport.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AAEH,qGAAqG;AACrG,MAAM,WAAW,uBAAuB;IACtC;;;;;;OAMG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC;IAClC,qGAAqG;IACrG,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAsBD,gFAAgF;AAChF,eAAO,MAAM,wBAAwB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAA8B,CAAC;AAEtH,4GAA4G;AAC5G,eAAO,MAAM,kBAAkB,EAAE,SAAS,MAAM,EAE5B,CAAC;AAErB,sGAAsG;AACtG,wBAAgB,uBAAuB,CAAC,EAAE,EAAE,MAAM,GAAG,uBAAuB,GAAG,SAAS,CAEvF"}
@@ -0,0 +1,32 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ //#region src/instance/refusalTransport.ts
4
+ /**
5
+ * Every `better-auth` plugin that replaces the response on a path the social callback reaches, reviewed.
6
+ *
7
+ * Keyed by plugin id, which is what `assertAdditivePlugins` has in hand. Two entries today because two
8
+ * plugins in `better-auth` 1.7.1 assign `context.returned` at all, and the completeness gate is what
9
+ * keeps that number honest on the next bump.
10
+ */
11
+ const REFUSAL_TRANSPORT_VERDICTS = {
12
+ "oauth-popup": {
13
+ source: "oauth-popup",
14
+ outsideLocation: true,
15
+ why: "oauth-popup/index.mjs:216-226 — the after hook matches `/callback/` and `/oauth2/callback/`, reads `error` and `error_description` off the `location` Better Auth just wrote, and assigns `c.context.returned` a 200 HTML page carrying both in a JSON script block for `postMessage`. The redirect the collapse reads never leaves the Worker, so whatever code the callback settled on is legible to anyone who can open the popup, and nothing about the request needs to be malformed. **The pair it originally restored is no longer produced** — `./providerSignInGate` decides rows 3 and 4 before Better Auth branches — but the refusal stands on the codes that gate deliberately passes through: `unable_to_create_user` and `validation_context_missing` are raised inside `createUser`, the no-row side, and `INVALID_PROFILE_FIELD` on the matched-row side, so the same question still has two readable answers through a body the collapse cannot reach."
16
+ },
17
+ "oauth-proxy": {
18
+ source: "oauth-proxy",
19
+ outsideLocation: false,
20
+ why: "oauth-proxy/index.mjs:331 assigns `context.returned`, but on the `/sign-in/social` hook, which answers the provider's authorize URL and carries no refusal this roster is about. Its callback hook (:340) touches only the `location` header, and only to swap in a `callbackURL` the same header already carried — so a refusal reaching it stays a refusal in `Location`, where the collapse still reads it."
21
+ }
22
+ };
23
+ /** The roster, for the completeness gate. Not part of the package's surface. */
24
+ const REFUSAL_TRANSPORT_ROSTER = REFUSAL_TRANSPORT_VERDICTS;
25
+ /** The plugin ids `auth()` refuses. Derived from the roster, so the gate and the review cannot disagree. */
26
+ const REFUSED_PLUGIN_IDS = Object.entries(REFUSAL_TRANSPORT_VERDICTS).filter(([, verdict]) => verdict.outsideLocation).map(([id]) => id);
27
+ /** The written verdict for a plugin id, or `undefined` when nobody has had to rule on that plugin. */
28
+ function refusalTransportVerdict(id) {
29
+ return REFUSAL_TRANSPORT_VERDICTS[id];
30
+ }
31
+ //#endregion
32
+ export { REFUSAL_TRANSPORT_ROSTER, REFUSED_PLUGIN_IDS, refusalTransportVerdict };
@@ -1 +1 @@
1
- {"version":3,"file":"pluginTables.d.ts","sourceRoot":"","sources":["../../src/migrations/pluginTables.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAKlD;;;;;;;;;;;;;;;;;;GAkBG;AAEH;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,SAAS,gBAAgB,EAAE,GAAG,iBAAiB,CAuBzF;AAED,6FAA6F;AAC7F,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,SAAS,CAAC;AAElD,iDAAiD;AACjD,MAAM,WAAW,iBAAiB;IAChC,sFAAsF;IACtF,IAAI,EAAE,MAAM,CAAC;IACb,0BAA0B;IAC1B,IAAI,EAAE,gBAAgB,CAAC;IACvB,wCAAwC;IACxC,OAAO,EAAE,OAAO,CAAC;IACjB,oDAAoD;IACpD,UAAU,EAAE,OAAO,CAAC;IACpB,wDAAwD;IACxD,MAAM,EAAE,OAAO,CAAC;IAChB,mDAAmD;IACnD,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,yCAAyC;AACzC,MAAM,WAAW,WAAW;IAC1B,kEAAkE;IAClE,IAAI,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,OAAO,EAAE,iBAAiB,EAAE,CAAC;CAC9B;AAED,uGAAuG;AACvG,MAAM,WAAW,YAAY;IAC3B,wCAAwC;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,iCAAiC;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,0BAA0B;IAC1B,IAAI,EAAE,gBAAgB,CAAC;IACvB,sDAAsD;IACtD,OAAO,EAAE,OAAO,CAAC;IACjB,mDAAmD;IACnD,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,wGAAwG;AACxG,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,OAAO,EAAE,YAAY,EAAE,CAAC;CACzB;AA0BD;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,gBAAgB,GAAG,iBAAiB,CA0C7E;AAOD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,iBAAiB,GAAG,SAAS,CAoDnE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAKrD;AAED,sFAAsF;AACtF,MAAM,WAAW,cAAc;IAC7B,4FAA4F;IAC5F,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACtC,gFAAgF;IAChF,UAAU,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE,EAAE,CAAC;CAChD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,SAAS,gBAAgB,EAAE,GAAG,cAAc,CAwCnF"}
1
+ {"version":3,"file":"pluginTables.d.ts","sourceRoot":"","sources":["../../src/migrations/pluginTables.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAKlD;;;;;;;;;;;;;;;;;;GAkBG;AAEH;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,SAAS,gBAAgB,EAAE,GAAG,iBAAiB,CA0BzF;AAED,6FAA6F;AAC7F,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,SAAS,CAAC;AAElD,iDAAiD;AACjD,MAAM,WAAW,iBAAiB;IAChC,sFAAsF;IACtF,IAAI,EAAE,MAAM,CAAC;IACb,0BAA0B;IAC1B,IAAI,EAAE,gBAAgB,CAAC;IACvB,wCAAwC;IACxC,OAAO,EAAE,OAAO,CAAC;IACjB,oDAAoD;IACpD,UAAU,EAAE,OAAO,CAAC;IACpB,wDAAwD;IACxD,MAAM,EAAE,OAAO,CAAC;IAChB,mDAAmD;IACnD,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,yCAAyC;AACzC,MAAM,WAAW,WAAW;IAC1B,kEAAkE;IAClE,IAAI,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,OAAO,EAAE,iBAAiB,EAAE,CAAC;CAC9B;AAED,uGAAuG;AACvG,MAAM,WAAW,YAAY;IAC3B,wCAAwC;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,iCAAiC;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,0BAA0B;IAC1B,IAAI,EAAE,gBAAgB,CAAC;IACvB,sDAAsD;IACtD,OAAO,EAAE,OAAO,CAAC;IACjB,mDAAmD;IACnD,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,wGAAwG;AACxG,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,OAAO,EAAE,YAAY,EAAE,CAAC;CACzB;AA0BD;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,gBAAgB,GAAG,iBAAiB,CA0C7E;AAOD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,iBAAiB,GAAG,SAAS,CAoDnE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAKrD;AAED,sFAAsF;AACtF,MAAM,WAAW,cAAc;IAC7B,4FAA4F;IAC5F,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACtC,gFAAgF;IAChF,UAAU,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE,EAAE,CAAC;CAChD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,SAAS,gBAAgB,EAAE,GAAG,cAAc,CAwCnF"}
@@ -55,7 +55,8 @@ function authSchemaOptions(plugins) {
55
55
  verificationExpiresIn: 300,
56
56
  otpLength: 6,
57
57
  disableSignUp: false,
58
- sendEmail: async () => void 0
58
+ sendEmail: async () => ({ delivery: "queued" }),
59
+ emit: async () => void 0
59
60
  }), ...plugins]
60
61
  };
61
62
  }
package/dist/peer.d.ts ADDED
@@ -0,0 +1,54 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import { authDatabase } from "./data/tables";
4
+ /**
5
+ * **What a capability composed beside auth may read — handed to it, never imported by it** (#645).
6
+ *
7
+ * `@pithy-sh/auth` is an optional peer of `matchmaking` (an invite resolved by address), `support` (a sender
8
+ * linked to an account) and `testers` (whether a tester has used the app). Each reached these modules by
9
+ * `import()` behind a `try`, and a literal specifier is one a bundler resolves whether or not the branch
10
+ * holding it ever runs — so a project without auth could not bundle any of the three.
11
+ *
12
+ * So `auth()` carries this object as `authPeer`, a dependent finds it among the composed capabilities in its
13
+ * `compose` hook, and a host Worker — which composes nothing — is handed it by the entry `pithy` generates when
14
+ * the project composes auth. The dependent names this package only in a type, which a bundler never sees.
15
+ *
16
+ * Read access to the account tables and the schemas that decode them, and nothing that writes: every
17
+ * dependent reads who someone is, and none of them may decide it.
18
+ *
19
+ * Its own module, so that generated host entry imports these and not `capability.ts`, which brings Better
20
+ * Auth and every route with it.
21
+ */
22
+ export declare const authPeer: {
23
+ readonly authDatabase: typeof authDatabase;
24
+ readonly User: import("zod").ZodObject<{
25
+ id: import("zod").ZodString;
26
+ name: import("zod").ZodString;
27
+ email: import("zod").ZodString;
28
+ emailVerified: import("zod").ZodCodec<import("zod").ZodUnion<readonly [import("zod").ZodLiteral<0>, import("zod").ZodLiteral<1>, import("zod").ZodBoolean, import("zod").ZodString]>, import("zod").ZodBoolean>;
29
+ image: import("zod").ZodNullable<import("zod").ZodString>;
30
+ locale: import("zod").ZodNullable<import("zod").ZodString>;
31
+ createdAt: import("zod").ZodCodec<import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodNumber, import("zod").ZodDate]>, import("zod").ZodDate>;
32
+ updatedAt: import("zod").ZodCodec<import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodNumber, import("zod").ZodDate]>, import("zod").ZodDate>;
33
+ }, import("zod/v4/core").$strip>;
34
+ readonly Device: import("zod").ZodObject<{
35
+ id: import("zod").ZodString;
36
+ userId: import("zod").ZodString;
37
+ platform: import("zod").ZodEnum<{
38
+ android: "android";
39
+ ios: "ios";
40
+ web: "web";
41
+ }>;
42
+ name: import("zod").ZodNullable<import("zod").ZodString>;
43
+ model: import("zod").ZodNullable<import("zod").ZodString>;
44
+ osVersion: import("zod").ZodNullable<import("zod").ZodString>;
45
+ appVersion: import("zod").ZodNullable<import("zod").ZodString>;
46
+ pushToken: import("zod").ZodNullable<import("zod").ZodString>;
47
+ lastIp: import("zod").ZodNullable<import("zod").ZodString>;
48
+ lastSeenAt: import("zod").ZodCodec<import("zod").ZodUnion<readonly [import("zod").ZodNumber, import("zod").ZodString, import("zod").ZodDate]>, import("zod").ZodDate>;
49
+ createdAt: import("zod").ZodCodec<import("zod").ZodUnion<readonly [import("zod").ZodNumber, import("zod").ZodString, import("zod").ZodDate]>, import("zod").ZodDate>;
50
+ }, import("zod/v4/core").$strip>;
51
+ };
52
+ /** Auth's peer surface, by type — what `authPeer` holds. */
53
+ export type AuthPeer = typeof authPeer;
54
+ //# sourceMappingURL=peer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"peer.d.ts","sourceRoot":"","sources":["../src/peer.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAA0C,CAAC;AAEhE,4DAA4D;AAC5D,MAAM,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAC"}
package/dist/peer.js ADDED
@@ -0,0 +1,31 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import { User } from "./data/betterAuth.js";
4
+ import { Device } from "./data/device.js";
5
+ import { authDatabase } from "./data/tables.js";
6
+ //#region src/peer.ts
7
+ /**
8
+ * **What a capability composed beside auth may read — handed to it, never imported by it** (#645).
9
+ *
10
+ * `@pithy-sh/auth` is an optional peer of `matchmaking` (an invite resolved by address), `support` (a sender
11
+ * linked to an account) and `testers` (whether a tester has used the app). Each reached these modules by
12
+ * `import()` behind a `try`, and a literal specifier is one a bundler resolves whether or not the branch
13
+ * holding it ever runs — so a project without auth could not bundle any of the three.
14
+ *
15
+ * So `auth()` carries this object as `authPeer`, a dependent finds it among the composed capabilities in its
16
+ * `compose` hook, and a host Worker — which composes nothing — is handed it by the entry `pithy` generates when
17
+ * the project composes auth. The dependent names this package only in a type, which a bundler never sees.
18
+ *
19
+ * Read access to the account tables and the schemas that decode them, and nothing that writes: every
20
+ * dependent reads who someone is, and none of them may decide it.
21
+ *
22
+ * Its own module, so that generated host entry imports these and not `capability.ts`, which brings Better
23
+ * Auth and every route with it.
24
+ */
25
+ const authPeer = {
26
+ authDatabase,
27
+ User,
28
+ Device
29
+ };
30
+ //#endregion
31
+ export { authPeer };
@@ -3,5 +3,5 @@
3
3
  /** This package's npm name — the join key against a release feed. */
4
4
  export declare const PACKAGE_NAME = "@pithy-sh/auth";
5
5
  /** This package's version, stamped from its own package.json at generation time. */
6
- export declare const PACKAGE_VERSION = "0.6.2";
6
+ export declare const PACKAGE_VERSION = "0.6.4";
7
7
  //# sourceMappingURL=version.generated.d.ts.map
@@ -4,6 +4,6 @@
4
4
  /** This package's npm name — the join key against a release feed. */
5
5
  const PACKAGE_NAME = "@pithy-sh/auth";
6
6
  /** This package's version, stamped from its own package.json at generation time. */
7
- const PACKAGE_VERSION = "0.6.2";
7
+ const PACKAGE_VERSION = "0.6.4";
8
8
  //#endregion
9
9
  export { PACKAGE_NAME, PACKAGE_VERSION };