@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.
- package/dist/admin/users.d.ts +157 -0
- package/dist/admin/users.d.ts.map +1 -0
- package/dist/admin/users.js +207 -0
- package/dist/audit/actions.d.ts +68 -0
- package/dist/audit/actions.d.ts.map +1 -0
- package/dist/audit/actions.js +68 -0
- package/dist/audit/emit.d.ts +103 -0
- package/dist/audit/emit.d.ts.map +1 -0
- package/dist/audit/emit.js +172 -0
- package/dist/capability.d.ts +62 -0
- package/dist/capability.d.ts.map +1 -0
- package/dist/capability.js +171 -0
- package/dist/client/api.d.ts +301 -0
- package/dist/client/api.d.ts.map +1 -0
- package/dist/client/api.js +387 -0
- package/dist/client/projection.d.ts +53 -0
- package/dist/client/projection.d.ts.map +1 -0
- package/dist/client/projection.js +2 -0
- package/dist/data/betterAuth.d.ts +77 -0
- package/dist/data/betterAuth.d.ts.map +1 -0
- package/dist/data/betterAuth.js +94 -0
- package/dist/data/device.d.ts +38 -0
- package/dist/data/device.d.ts.map +1 -0
- package/dist/data/device.js +35 -0
- package/dist/data/kitFields.d.ts +80 -0
- package/dist/data/kitFields.d.ts.map +1 -0
- package/dist/data/kitFields.js +79 -0
- package/dist/data/rotatedToken.d.ts +22 -0
- package/dist/data/rotatedToken.d.ts.map +1 -0
- package/dist/data/rotatedToken.js +24 -0
- package/dist/data/tables.d.ts +106 -0
- package/dist/data/tables.d.ts.map +1 -0
- package/dist/data/tables.js +32 -0
- package/dist/device/registry.d.ts +56 -0
- package/dist/device/registry.d.ts.map +1 -0
- package/dist/device/registry.js +87 -0
- package/dist/email/send.d.ts +40 -0
- package/dist/email/send.d.ts.map +1 -0
- package/dist/email/send.js +50 -0
- package/dist/http/adminRoutes.d.ts +11 -0
- package/dist/http/adminRoutes.d.ts.map +1 -0
- package/dist/http/adminRoutes.js +276 -0
- package/dist/http/baseUrl.d.ts +43 -0
- package/dist/http/baseUrl.d.ts.map +1 -0
- package/dist/http/baseUrl.js +98 -0
- package/dist/http/csrf.d.ts +20 -0
- package/dist/http/csrf.d.ts.map +1 -0
- package/dist/http/csrf.js +83 -0
- package/dist/http/devLoginRoute.d.ts +44 -0
- package/dist/http/devLoginRoute.d.ts.map +1 -0
- package/dist/http/devLoginRoute.js +114 -0
- package/dist/http/errors.d.ts +26 -0
- package/dist/http/errors.d.ts.map +1 -0
- package/dist/http/errors.js +69 -0
- package/dist/http/guards.d.ts +105 -0
- package/dist/http/guards.d.ts.map +1 -0
- package/dist/http/guards.js +150 -0
- package/dist/http/middleware.d.ts +19 -0
- package/dist/http/middleware.d.ts.map +1 -0
- package/dist/http/middleware.js +49 -0
- package/dist/http/rateLimit.d.ts +19 -0
- package/dist/http/rateLimit.d.ts.map +1 -0
- package/dist/http/rateLimit.js +33 -0
- package/dist/http/resolve.d.ts +11 -0
- package/dist/http/resolve.d.ts.map +1 -0
- package/dist/http/resolve.js +94 -0
- package/dist/http/responses.d.ts +154 -0
- package/dist/http/responses.d.ts.map +1 -0
- package/dist/http/responses.js +123 -0
- package/dist/http/routes.d.ts +36 -0
- package/dist/http/routes.d.ts.map +1 -0
- package/dist/http/routes.js +270 -0
- package/dist/http/schemas.d.ts +68 -0
- package/dist/http/schemas.d.ts.map +1 -0
- package/dist/http/schemas.js +61 -0
- package/dist/http/views.d.ts +55 -0
- package/dist/http/views.d.ts.map +1 -0
- package/dist/http/views.js +88 -0
- package/dist/i18n/errorCopy.d.ts +26 -0
- package/dist/i18n/errorCopy.d.ts.map +1 -0
- package/dist/i18n/errorCopy.es.d.ts +33 -0
- package/dist/i18n/errorCopy.es.d.ts.map +1 -0
- package/dist/i18n/errorCopy.es.js +35 -0
- package/dist/i18n/errorCopy.js +93 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/instance/auth.d.ts +1124 -0
- package/dist/instance/auth.d.ts.map +1 -0
- package/dist/instance/auth.js +178 -0
- package/dist/instance/plugins.d.ts +89 -0
- package/dist/instance/plugins.d.ts.map +1 -0
- package/dist/instance/plugins.js +118 -0
- package/dist/instance/providers.d.ts +119 -0
- package/dist/instance/providers.d.ts.map +1 -0
- package/dist/instance/providers.js +113 -0
- package/dist/instance/secrets.d.ts +165 -0
- package/dist/instance/secrets.d.ts.map +1 -0
- package/dist/instance/secrets.js +171 -0
- package/dist/migrations/0001_init.d.ts +35 -0
- package/dist/migrations/0001_init.d.ts.map +1 -0
- package/dist/migrations/0001_init.js +79 -0
- package/dist/migrations/pluginTables.d.ts +128 -0
- package/dist/migrations/pluginTables.d.ts.map +1 -0
- package/dist/migrations/pluginTables.js +235 -0
- package/dist/seeds/devSession.d.ts +126 -0
- package/dist/seeds/devSession.d.ts.map +1 -0
- package/dist/seeds/devSession.js +213 -0
- package/dist/seeds/example.d.ts +14 -0
- package/dist/seeds/example.d.ts.map +1 -0
- package/dist/seeds/example.js +32 -0
- package/dist/test-utils/liveApp.d.ts +229 -0
- package/dist/test-utils/liveApp.d.ts.map +1 -0
- package/dist/test-utils/liveApp.js +242 -0
- package/dist/token/rotation.d.ts +58 -0
- package/dist/token/rotation.d.ts.map +1 -0
- package/dist/token/rotation.js +70 -0
- package/dist/version.generated.d.ts +7 -0
- package/dist/version.generated.d.ts.map +1 -0
- package/dist/version.generated.js +9 -0
- package/package.json +24 -13
- package/src/version.generated.ts +1 -1
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
/**
|
|
4
|
+
* The browser half of `@pithy-sh/auth`: the one place that knows how a browser program makes a
|
|
5
|
+
* same-origin, cookie-bearing request to this Worker, and the calls made through it — the six a
|
|
6
|
+
* scaffolded screen makes, and {@link updateUser}, which an adopter's own screen calls.
|
|
7
|
+
*
|
|
8
|
+
* **This module lives in the package for the reason `@pithy-sh/payments`'s counterpart does, only more
|
|
9
|
+
* so.** `pithy ui add` writes the auth screens once and may never rewrite them: they are copied into
|
|
10
|
+
* the adopter's repository and become the adopter's files. Every request written into one of those
|
|
11
|
+
* files is frozen there at the moment `pithy init` ran, and a later fix to the base path, the cookie
|
|
12
|
+
* mode or the failure directions reaches none of them. Six such requests existed — `/get-session`,
|
|
13
|
+
* `/sign-out`, the two OTP routes, the magic link, and the social handoff — each spelling out the same
|
|
14
|
+
* transport by hand. They call this now, and this upgrades with a minor release (#370).
|
|
15
|
+
*
|
|
16
|
+
* **Cookie/session, same origin, and that is enforced rather than assumed.** Every request carries
|
|
17
|
+
* `credentials: "include"` and nothing else: no token in `localStorage` or `sessionStorage`, no
|
|
18
|
+
* `Authorization` header, no refresh rotation. The SPA and its Worker share an origin, so the session
|
|
19
|
+
* rides an httpOnly cookie JavaScript cannot read. Bearer is the mobile path — the same routes serve
|
|
20
|
+
* it, documented rather than scaffolded.
|
|
21
|
+
*
|
|
22
|
+
* **CSRF travels with the cookie mode, and half of it is on this side of the wire.** The server's
|
|
23
|
+
* `requireSameOrigin()` refuses a cookie-authenticated mutating request whose `Origin` does not match;
|
|
24
|
+
* the browser only attaches that header to a request it considers this page's own. So the client half
|
|
25
|
+
* of the rule is that the request never leaves the origin — {@link callAuth} builds its URL from a base
|
|
26
|
+
* path and a relative path and **refuses anything that is not a rooted same-origin path**, rather than
|
|
27
|
+
* handing an ambient session to whatever a mis-set `basePath` names. A caller cannot forget the check,
|
|
28
|
+
* because a caller no longer writes the request.
|
|
29
|
+
*
|
|
30
|
+
* **Nothing here throws.** Not a stylistic choice: this module imports nothing, so `PithyError` is not
|
|
31
|
+
* in reach, and a bare `throw new Error` is exactly what this kit forbids. An unreachable Worker, a
|
|
32
|
+
* proxy's HTML error page, a 500 — each becomes a renderable {@link AuthFailure} on an
|
|
33
|
+
* {@link AuthResult}, and every caller answers one. The Worker is still the security boundary; nothing
|
|
34
|
+
* on this side of the wire protects anything, it only decides what a screen shows.
|
|
35
|
+
*
|
|
36
|
+
* **No absolute URL literals, and no schema library.** Paths are relative, so the calls follow whatever
|
|
37
|
+
* origin the bundle is served from. Answers are narrowed by hand-written `is…(value: unknown): value is
|
|
38
|
+
* T` guards rather than Zod: this file compiles into an adopter's browser bundle, and it must not drag
|
|
39
|
+
* the Worker's schema graph in behind it. `sameOrigin.test.ts` holds the import list to empty, so the
|
|
40
|
+
* property is structural rather than a habit.
|
|
41
|
+
*/
|
|
42
|
+
/** Where the auth handler mounts by default — the same default `AuthConfig.basePath` carries. */
|
|
43
|
+
export declare const AUTH_BASE_PATH = "/auth";
|
|
44
|
+
/**
|
|
45
|
+
* The slice of `fetch` this module uses, declared structurally.
|
|
46
|
+
*
|
|
47
|
+
* Not `typeof fetch`: the package compiles against `@cloudflare/workers-types`, whose `RequestInit` has
|
|
48
|
+
* no `credentials` — and `credentials: "include"` is the entire cookie story. Declaring the shape keeps
|
|
49
|
+
* one signature true in a Worker-typed program, in a browser, and in a test that injects a stub.
|
|
50
|
+
*/
|
|
51
|
+
export interface AuthRequestInit {
|
|
52
|
+
/** The HTTP method. Absent means GET. */
|
|
53
|
+
method?: string;
|
|
54
|
+
/** Request headers. */
|
|
55
|
+
headers?: Record<string, string>;
|
|
56
|
+
/** The JSON body, already serialized. */
|
|
57
|
+
body?: string;
|
|
58
|
+
/** Cookie policy. Always `include` here — same-origin, httpOnly session cookie. */
|
|
59
|
+
credentials?: "include" | "same-origin" | "omit";
|
|
60
|
+
}
|
|
61
|
+
/** The slice of `Response` this module reads. */
|
|
62
|
+
export interface AuthResponse {
|
|
63
|
+
/** Whether the status was 2xx. */
|
|
64
|
+
ok: boolean;
|
|
65
|
+
/** The HTTP status. */
|
|
66
|
+
status: number;
|
|
67
|
+
/** The parsed body, or a rejection when it was not JSON. */
|
|
68
|
+
json(): Promise<unknown>;
|
|
69
|
+
}
|
|
70
|
+
/** A fetch this module can call. */
|
|
71
|
+
export type AuthFetch = (input: string, init?: AuthRequestInit) => Promise<AuthResponse>;
|
|
72
|
+
/**
|
|
73
|
+
* The browser globals this module reaches for, as an injectable seam.
|
|
74
|
+
*
|
|
75
|
+
* Reached through an object rather than `window` because the package compiles in a program with no DOM
|
|
76
|
+
* lib, alongside the Worker code. Injecting it is also what lets a test prove the no-browser path
|
|
77
|
+
* without a DOM.
|
|
78
|
+
*/
|
|
79
|
+
export interface AuthGlobal {
|
|
80
|
+
/** The browser's fetch. */
|
|
81
|
+
fetch?: AuthFetch;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* What a humanity check contributes to a gated request: the body it wants sent, and any headers.
|
|
85
|
+
*
|
|
86
|
+
* Exactly the shape `@pithy-sh/turnstile`'s scaffolded helper already returns, so a screen hands its
|
|
87
|
+
* check straight in. Absent means no check is composed, which is the common case.
|
|
88
|
+
*/
|
|
89
|
+
export type AuthGate = (body: Record<string, unknown>) => {
|
|
90
|
+
/** The body to send, with whatever field the check wanted added. */
|
|
91
|
+
body: Record<string, unknown>;
|
|
92
|
+
/** The headers to send, with whatever header the check wanted added. */
|
|
93
|
+
headers: Record<string, string>;
|
|
94
|
+
};
|
|
95
|
+
/** What every call takes: where the routes are, and the seams a test replaces. */
|
|
96
|
+
export interface AuthClientOptions {
|
|
97
|
+
/** Where the auth routes mount. Defaults to {@link AUTH_BASE_PATH}. */
|
|
98
|
+
basePath?: string;
|
|
99
|
+
/** The fetch to use. Defaults to the one on {@link AuthClientOptions.global}. */
|
|
100
|
+
fetch?: AuthFetch;
|
|
101
|
+
/** The global object the default fetch comes off. Defaults to `globalThis`. */
|
|
102
|
+
global?: AuthGlobal;
|
|
103
|
+
/** The humanity check to satisfy, on the two routes that are gated by one. */
|
|
104
|
+
gate?: AuthGate;
|
|
105
|
+
}
|
|
106
|
+
/** A refusal a screen can render: the namespaced code, the public message, and what to do next. */
|
|
107
|
+
export interface AuthFailure {
|
|
108
|
+
/** The namespaced code — `auth/invalid_token`, or a `client/*` sentinel this module minted. */
|
|
109
|
+
code: string;
|
|
110
|
+
/** The public message. The server's `detail` never crosses the HTTP codec, so this is all there is. */
|
|
111
|
+
message: string;
|
|
112
|
+
/** What to do next, when the server offered one. */
|
|
113
|
+
action: string | null;
|
|
114
|
+
}
|
|
115
|
+
/** Either the value, or a failure to render. Never a throw. */
|
|
116
|
+
export type AuthResult<T> = {
|
|
117
|
+
ok: true;
|
|
118
|
+
value: T;
|
|
119
|
+
} | {
|
|
120
|
+
ok: false;
|
|
121
|
+
failure: AuthFailure;
|
|
122
|
+
};
|
|
123
|
+
/** The worker could not be reached at all. Offline, or a DNS failure, or no fetch in this program. */
|
|
124
|
+
export declare const AUTH_UNREACHABLE: AuthFailure;
|
|
125
|
+
/** The worker answered with something this client cannot read. A proxy's HTML page, or a shape change. */
|
|
126
|
+
export declare const AUTH_UNREADABLE: AuthFailure;
|
|
127
|
+
/**
|
|
128
|
+
* The request would have left this origin, so it was never sent.
|
|
129
|
+
*
|
|
130
|
+
* The only way to reach it is a `basePath` or a path that is not a rooted same-origin path — an
|
|
131
|
+
* absolute URL, a protocol-relative `//host`, a backslash form a URL parser reads as one. Sending it
|
|
132
|
+
* would attach an ambient session to a request this page is not entitled to make, which is the thing
|
|
133
|
+
* the cookie mode exists to keep from happening.
|
|
134
|
+
*/
|
|
135
|
+
export declare const AUTH_CROSS_ORIGIN: AuthFailure;
|
|
136
|
+
/**
|
|
137
|
+
* One call: same-origin, cookie-carrying, never throwing. **The only producer of that request.**
|
|
138
|
+
*
|
|
139
|
+
* The body is read before the status is judged, because a refusal's body is the failure a screen
|
|
140
|
+
* renders. A body that will not parse is the generic failure rather than a crash — a corporate proxy's
|
|
141
|
+
* HTML page reaches a browser far more often than anyone expects.
|
|
142
|
+
*
|
|
143
|
+
* **Exported, and that is the point of it.** `@pithy-sh/auth` shipped no browser primitive at all, so
|
|
144
|
+
* six scaffolded screens each wrote the transport out by hand — and those screens are copied into an
|
|
145
|
+
* adopter's repository, where Pithy can never fix them. Every browser program that asks this Worker an
|
|
146
|
+
* auth question calls this, and `sameOrigin.test.ts` fails the build on any module that grows its own
|
|
147
|
+
* (#370).
|
|
148
|
+
*
|
|
149
|
+
* **Zod-free, like everything on this side of the wire.** The answer is narrowed by the hand-written
|
|
150
|
+
* `guard` a caller passes, never by a schema: this compiles into an adopter's browser bundle, and
|
|
151
|
+
* dragging the Worker's schema graph in behind it would break their build rather than ours.
|
|
152
|
+
*/
|
|
153
|
+
export declare function callAuth<T>(path: string, init: AuthRequestInit, options: AuthClientOptions | undefined, guard: (value: unknown) => value is T): Promise<AuthResult<T>>;
|
|
154
|
+
/** The signed-in user, as far as a browser is concerned. */
|
|
155
|
+
export interface AuthUser {
|
|
156
|
+
/** The user's id. */
|
|
157
|
+
id: string;
|
|
158
|
+
/** Their email address. */
|
|
159
|
+
email: string;
|
|
160
|
+
/** Their display name, when they have one. */
|
|
161
|
+
name?: string;
|
|
162
|
+
}
|
|
163
|
+
/** A live session, or `null` when nobody is signed in. */
|
|
164
|
+
export type AuthSession = {
|
|
165
|
+
user: AuthUser;
|
|
166
|
+
} | null;
|
|
167
|
+
/**
|
|
168
|
+
* Who is signed in, or `null`.
|
|
169
|
+
*
|
|
170
|
+
* **A failure is not a signed-out session**, and the return type is what keeps the two apart. A screen
|
|
171
|
+
* that renders "signed out" from an unreachable Worker offers a sign-in form to somebody who is
|
|
172
|
+
* already signed in, and the sign-in it starts replaces a live session with a new one. A caller that
|
|
173
|
+
* wants to treat them alike writes `result.ok ? result.value : null` — one line, reading as the
|
|
174
|
+
* decision it is.
|
|
175
|
+
*/
|
|
176
|
+
export declare function getSession(options?: AuthClientOptions): Promise<AuthResult<AuthSession>>;
|
|
177
|
+
/**
|
|
178
|
+
* End the session server-side.
|
|
179
|
+
*
|
|
180
|
+
* **The content type is not decoration, and the scaffolded screen was missing it.** The route refuses a
|
|
181
|
+
* POST without `application/json` with a 415 — so every app scaffolded so far has been signing nobody
|
|
182
|
+
* out. It went unnoticed because the screen ignored the answer and navigated to `/sign-in` regardless,
|
|
183
|
+
* which looks exactly like a successful sign-out until the back button restores a live session.
|
|
184
|
+
* `clientRoundTrip.test.ts` is what found it, and is what would find it again: a request written into a
|
|
185
|
+
* file Pithy may never rewrite is a request nobody ever tested against the route it names (#370).
|
|
186
|
+
*
|
|
187
|
+
* The body is an empty object rather than nothing, because a declared JSON content type with no body is
|
|
188
|
+
* the other half of the same 415.
|
|
189
|
+
*/
|
|
190
|
+
export declare function signOut(options?: AuthClientOptions): Promise<AuthResult<Record<string, unknown>>>;
|
|
191
|
+
/**
|
|
192
|
+
* Store something on the signed-in reader's own account. Today that is their language, and only that.
|
|
193
|
+
*
|
|
194
|
+
* **The rule it exists to serve is `docs/I18N.md`'s: `pithy_auth_users.locale` is the one home for a
|
|
195
|
+
* person's language — do not put language in your own preferences table.** A preferences table is the
|
|
196
|
+
* right home for time zone, date format, a 24-hour clock; none of those is language. Two homes for one
|
|
197
|
+
* fact is not a duplicate row, it is a magic-link email in the wrong language with nothing anywhere
|
|
198
|
+
* failing to say so, because the send Workflow reads the auth column and the settings pane reads the
|
|
199
|
+
* other one. This is the write that keeps the home single, and `useNegotiatedLocale`'s `persist` seam
|
|
200
|
+
* (`@pithy-sh/i18n`) is the caller it was written for: `persist: (next) => { void updateUser({ locale: next }); }`.
|
|
201
|
+
* The discard is deliberate: `persist` returns `void | Promise<void>` and this resolves to an
|
|
202
|
+
* `AuthResult`, so returning the call straight does not typecheck — and nothing is lost by dropping
|
|
203
|
+
* it, because nothing here throws.
|
|
204
|
+
*
|
|
205
|
+
* **`locale` is the only field it takes, because it is the only kit user field declared `input: true`**
|
|
206
|
+
* (`../data/kitFields`). Every other column Pithy adds is server-set — a client that could name its own
|
|
207
|
+
* device or token family could name somebody else's — while a language is the reader's own preference
|
|
208
|
+
* and no admin route is a thing a reader has. What makes taking it from a client safe is the `Locale`
|
|
209
|
+
* validator on the field rather than this signature: Better Auth runs it before the write, so the same
|
|
210
|
+
* schema that guards every read guards the write one hop earlier, and a megabyte of junk is a 400 here
|
|
211
|
+
* instead of a row that throws for every operator who later lists users.
|
|
212
|
+
*
|
|
213
|
+
* **`null` is accepted deliberately, and it is not the empty string.** Null means *this reader has not
|
|
214
|
+
* chosen*, which is what makes the server fall back to `Accept-Language`; taking a language choice back
|
|
215
|
+
* is an ordinary thing a reader does, and a call that refused it would answer 400 for the one state the
|
|
216
|
+
* schema calls ordinary.
|
|
217
|
+
*
|
|
218
|
+
* **Not `jsonPost`, for the reason {@link signOut} is not.** That folds in the humanity check, and this
|
|
219
|
+
* is not a gated route: `createAuthRoutes` stacks the Turnstile gate on `/sign-in/magic-link` and
|
|
220
|
+
* `/email-otp/send-verification-otp` and on nothing else, so a token folded in here would be an
|
|
221
|
+
* unexpected field on a request Better Auth validates itself. The content type and the `{}` body are
|
|
222
|
+
* the same 415 story as sign-out — a declared JSON type with no body is refused just as an undeclared
|
|
223
|
+
* one is.
|
|
224
|
+
*
|
|
225
|
+
* **And it is kit code rather than an adopter's, because both alternatives are worse than this
|
|
226
|
+
* function.** Standing up a second Better Auth client with `inferAdditionalFields` duplicates
|
|
227
|
+
* configuration `@pithy-sh/auth` already owns. Reaching for {@link callAuth} instead means an adopter
|
|
228
|
+
* spelling out the path, the content type and the guard themselves, one deep import below the surface
|
|
229
|
+
* every other auth call in their app goes through — written into a file Pithy can never fix (#446).
|
|
230
|
+
*
|
|
231
|
+
* **The answer carries no user, whatever the route's own OpenAPI block advertises.** Better Auth's
|
|
232
|
+
* `/update-user` ends `ctx.json({ status: true })`, so `value` is `{ status: true }` and
|
|
233
|
+
* `value.locale` is `undefined`. Nothing is lost by that — a screen already has the value it just
|
|
234
|
+
* wrote — but do not reach into it for the row.
|
|
235
|
+
*
|
|
236
|
+
* **A refusal is a failure to render and never a throw, and it is `client/unreadable` more often than
|
|
237
|
+
* it looks.** This is Better Auth's own route, and Better Auth turns its own `APIError`s into
|
|
238
|
+
* Responses inside `instance.handler`, so they never reach the `apiErrorToPithy` re-homing in
|
|
239
|
+
* `../http/routes`. The body stays Better Auth's flat `{ message, code }` rather than the kit's error
|
|
240
|
+
* envelope, and {@link AUTH_UNREADABLE} is what `readFailure` makes of anything that is not that
|
|
241
|
+
* envelope: a signed-out reader's 401 reads as `client/unreadable`, and so does a tag the `Locale`
|
|
242
|
+
* validator rejected. Which is enough for the caller this exists for — `useNegotiatedLocale` drops a
|
|
243
|
+
* failed preference write either way, because the reader already has the language they picked.
|
|
244
|
+
*/
|
|
245
|
+
export declare function updateUser(fields: {
|
|
246
|
+
locale?: string | null;
|
|
247
|
+
}, options?: AuthClientOptions): Promise<AuthResult<Record<string, unknown>>>;
|
|
248
|
+
/** Sign in with a one-time code the user typed. The answer is the session it created. */
|
|
249
|
+
export declare function signInWithOtp(input: {
|
|
250
|
+
email: string;
|
|
251
|
+
otp: string;
|
|
252
|
+
}, options?: AuthClientOptions): Promise<AuthResult<Record<string, unknown>>>;
|
|
253
|
+
/**
|
|
254
|
+
* Mail a one-time code.
|
|
255
|
+
*
|
|
256
|
+
* Gated by the humanity check when one is composed — `options.gate` puts the token where the middleware
|
|
257
|
+
* reads it, and a screen cannot forget to.
|
|
258
|
+
*/
|
|
259
|
+
export declare function sendOtp(input: {
|
|
260
|
+
email: string;
|
|
261
|
+
type: "sign-in";
|
|
262
|
+
}, options?: AuthClientOptions): Promise<AuthResult<Record<string, unknown>>>;
|
|
263
|
+
/**
|
|
264
|
+
* Mail a magic link.
|
|
265
|
+
*
|
|
266
|
+
* `callbackURL` is the adopter's own screen, so it is theirs to name. Gated the same way as
|
|
267
|
+
* {@link sendOtp}.
|
|
268
|
+
*/
|
|
269
|
+
export declare function sendMagicLink(input: {
|
|
270
|
+
email: string;
|
|
271
|
+
callbackURL: string;
|
|
272
|
+
}, options?: AuthClientOptions): Promise<AuthResult<Record<string, unknown>>>;
|
|
273
|
+
/**
|
|
274
|
+
* What asking for a social authorization URL produced. Three outcomes, and a screen must tell them apart.
|
|
275
|
+
*
|
|
276
|
+
* `authorize` is a URL to leave for. `unconfigured` is the provider being switched on in config with a
|
|
277
|
+
* blank credential behind it — the server answers, and the URL it mints names no client. `refused` is
|
|
278
|
+
* our own Worker not answering. Different faults, different copy, and collapsing them would tell a user
|
|
279
|
+
* to try again when the fix is a secret nobody set.
|
|
280
|
+
*/
|
|
281
|
+
export type SocialSignIn = {
|
|
282
|
+
kind: "authorize";
|
|
283
|
+
url: string;
|
|
284
|
+
} | {
|
|
285
|
+
kind: "unconfigured";
|
|
286
|
+
} | {
|
|
287
|
+
kind: "refused";
|
|
288
|
+
failure: AuthFailure;
|
|
289
|
+
};
|
|
290
|
+
/**
|
|
291
|
+
* Ask for a provider's authorization URL.
|
|
292
|
+
*
|
|
293
|
+
* **No humanity check, deliberately**: the redirect carries no token to check and the provider runs its
|
|
294
|
+
* own bot defense, which is what `@pithy-sh/auth` already assumes when it stacks the check on the
|
|
295
|
+
* magic-link route alone. Gating it would only stop people signing in.
|
|
296
|
+
*/
|
|
297
|
+
export declare function startSocialSignIn(input: {
|
|
298
|
+
provider: string;
|
|
299
|
+
callbackURL: string;
|
|
300
|
+
}, options?: AuthClientOptions): Promise<SocialSignIn>;
|
|
301
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/client/api.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,iGAAiG;AACjG,eAAO,MAAM,cAAc,UAAU,CAAC;AAEtC;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC9B,yCAAyC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,uBAAuB;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,yCAAyC;IACzC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,mFAAmF;IACnF,WAAW,CAAC,EAAE,SAAS,GAAG,aAAa,GAAG,MAAM,CAAC;CAClD;AAED,iDAAiD;AACjD,MAAM,WAAW,YAAY;IAC3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