@foir/sdk 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/next.js ADDED
@@ -0,0 +1,275 @@
1
+ // src/next/cookieAdapter.ts
2
+ var DEFAULT_COOKIE_OPTIONS = {
3
+ httpOnly: true,
4
+ secure: true,
5
+ sameSite: "lax",
6
+ path: "/"
7
+ };
8
+ function foirCookieName(key) {
9
+ return key.replace(/[^a-zA-Z0-9_-]/g, "_");
10
+ }
11
+ function createFoirCookieAdapter(store, opts = {}) {
12
+ const options = { ...DEFAULT_COOKIE_OPTIONS, ...opts.cookieOptions };
13
+ return {
14
+ get: (key) => store.get(foirCookieName(key))?.value ?? null,
15
+ set: (key, value) => store.set(foirCookieName(key), value, options),
16
+ unset: (key) => store.delete(foirCookieName(key))
17
+ };
18
+ }
19
+
20
+ // src/graphql/foir-request.ts
21
+ import { print } from "graphql";
22
+ function isFoirPreview(env) {
23
+ return env.FOIR_PREVIEW === "true";
24
+ }
25
+ var FoirRequestError = class extends Error {
26
+ /** HTTP status code, when the request failed at the HTTP layer. */
27
+ status;
28
+ /** GraphQL errors, when the request failed with a no-data error envelope. */
29
+ graphQLErrors;
30
+ cause;
31
+ constructor(message, options) {
32
+ super(message);
33
+ this.name = "FoirRequestError";
34
+ this.cause = options?.cause;
35
+ this.status = options?.status;
36
+ this.graphQLErrors = options?.graphQLErrors;
37
+ }
38
+ };
39
+ async function foirRequest(env, document, variables, options) {
40
+ const endpoint = env.PLATFORM_API_URL;
41
+ const apiKey = isFoirPreview(env) ? env.PLATFORM_PREVIEW_API_KEY ?? env.PLATFORM_API_KEY : env.PLATFORM_API_KEY;
42
+ if (!endpoint || !apiKey) {
43
+ throw new FoirRequestError(
44
+ "[foir] PLATFORM_API_URL or PLATFORM_API_KEY is not set \u2014 add them to .env"
45
+ );
46
+ }
47
+ const headers = {
48
+ "Content-Type": "application/json",
49
+ "x-api-key": apiKey
50
+ };
51
+ if (isFoirPreview(env)) {
52
+ headers["X-Foir-Schema-Channel"] = "draft";
53
+ }
54
+ if (options?.bearerToken) {
55
+ headers["Authorization"] = `Bearer ${options.bearerToken}`;
56
+ }
57
+ let res;
58
+ try {
59
+ res = await fetch(endpoint, {
60
+ method: "POST",
61
+ headers,
62
+ body: JSON.stringify({ query: print(document), variables })
63
+ });
64
+ } catch (err) {
65
+ throw new FoirRequestError("[foir] network error", { cause: err });
66
+ }
67
+ if (!res.ok) {
68
+ throw new FoirRequestError(`[foir] HTTP ${res.status} ${res.statusText}`, {
69
+ status: res.status
70
+ });
71
+ }
72
+ const json = await res.json();
73
+ if (json.errors?.length) {
74
+ const msg = json.errors.map((e) => e.message).join("; ");
75
+ if (json.data) {
76
+ console.warn(`[foir] GraphQL partial errors (data returned): ${msg}`);
77
+ } else {
78
+ throw new FoirRequestError(`[foir] GraphQL errors: ${msg}`, {
79
+ graphQLErrors: json.errors
80
+ });
81
+ }
82
+ }
83
+ if (!json.data) {
84
+ throw new FoirRequestError("[foir] empty GraphQL response");
85
+ }
86
+ return json.data;
87
+ }
88
+
89
+ // src/auth/operations.ts
90
+ import { parse } from "graphql";
91
+ var AUTH_RESULT_FIELDS = "token refreshToken customerId email";
92
+ var CustomerLoginDocument = parse(
93
+ `mutation CustomerLogin($email: String!, $password: String!) {
94
+ customerLogin(email: $email, password: $password) { ${AUTH_RESULT_FIELDS} }
95
+ }`
96
+ );
97
+ var CustomerRegisterDocument = parse(
98
+ `mutation CustomerRegister($email: String!, $password: String!) {
99
+ customerRegister(email: $email, password: $password) { ${AUTH_RESULT_FIELDS} }
100
+ }`
101
+ );
102
+ var CustomerRefreshTokenDocument = parse(
103
+ `mutation CustomerRefreshToken($refreshToken: String!) {
104
+ customerRefreshToken(refreshToken: $refreshToken) { ${AUTH_RESULT_FIELDS} }
105
+ }`
106
+ );
107
+ var CustomerRequestOTPDocument = parse(
108
+ `mutation CustomerRequestOTP($email: String!) {
109
+ customerRequestOTP(email: $email)
110
+ }`
111
+ );
112
+ var CustomerLoginOTPDocument = parse(
113
+ `mutation CustomerLoginOTP($email: String!, $otp: String!) {
114
+ customerLoginOTP(email: $email, otp: $otp) { ${AUTH_RESULT_FIELDS} }
115
+ }`
116
+ );
117
+ var CustomerLoginWithProviderDocument = parse(
118
+ `mutation CustomerLoginWithProvider($input: ProviderLoginInput!) {
119
+ customerLoginWithProvider(input: $input) { redirectUrl token }
120
+ }`
121
+ );
122
+ var CustomerProviderCallbackDocument = parse(
123
+ `mutation CustomerProviderCallback($input: ProviderCallbackInput!) {
124
+ customerProviderCallback(input: $input) { ${AUTH_RESULT_FIELDS} }
125
+ }`
126
+ );
127
+ var CustomerProviderVerifyOTPDocument = parse(
128
+ `mutation CustomerProviderVerifyOTP($input: ProviderOTPVerifyInput!) {
129
+ customerProviderVerifyOTP(input: $input) { ${AUTH_RESULT_FIELDS} }
130
+ }`
131
+ );
132
+ var AuthProvidersDocument = parse(
133
+ `query AuthProviders {
134
+ authProviders { key name type isDefault }
135
+ }`
136
+ );
137
+
138
+ // src/auth/auth.ts
139
+ var TOKEN_KEY = "foir:token";
140
+ var REFRESH_KEY = "foir:refreshToken";
141
+ var CUSTOMER_ID_KEY = "foir:customerId";
142
+ var EMAIL_KEY = "foir:email";
143
+ async function customerLogin(env, vars) {
144
+ return (await foirRequest(env, CustomerLoginDocument, vars)).customerLogin;
145
+ }
146
+ async function customerRegister(env, vars) {
147
+ return (await foirRequest(env, CustomerRegisterDocument, vars)).customerRegister;
148
+ }
149
+ async function customerLoginOTP(env, vars) {
150
+ return (await foirRequest(env, CustomerLoginOTPDocument, vars)).customerLoginOTP;
151
+ }
152
+ async function customerProviderCallback(env, input) {
153
+ return (await foirRequest(env, CustomerProviderCallbackDocument, { input })).customerProviderCallback;
154
+ }
155
+ async function saveSession(adapter, result) {
156
+ await adapter.set(TOKEN_KEY, result.token);
157
+ await adapter.set(REFRESH_KEY, result.refreshToken);
158
+ await adapter.set(CUSTOMER_ID_KEY, result.customerId);
159
+ await adapter.set(EMAIL_KEY, result.email);
160
+ return { id: result.customerId, email: result.email };
161
+ }
162
+ async function clearSession(adapter) {
163
+ await adapter.unset(TOKEN_KEY);
164
+ await adapter.unset(REFRESH_KEY);
165
+ await adapter.unset(CUSTOMER_ID_KEY);
166
+ await adapter.unset(EMAIL_KEY);
167
+ }
168
+ async function getSessionToken(adapter) {
169
+ return await adapter.get(TOKEN_KEY) ?? null;
170
+ }
171
+ async function getSessionCustomer(adapter) {
172
+ const id = await adapter.get(CUSTOMER_ID_KEY) ?? null;
173
+ const email = await adapter.get(EMAIL_KEY) ?? null;
174
+ if (!id) return null;
175
+ return { id, email: email ?? "" };
176
+ }
177
+ async function loginWithPassword(adapter, env, vars) {
178
+ return saveSession(adapter, await customerLogin(env, vars));
179
+ }
180
+ async function registerWithPassword(adapter, env, vars) {
181
+ return saveSession(adapter, await customerRegister(env, vars));
182
+ }
183
+ async function loginWithOTP(adapter, env, vars) {
184
+ return saveSession(adapter, await customerLoginOTP(env, vars));
185
+ }
186
+
187
+ // src/next/session.ts
188
+ async function getFoirSession(store) {
189
+ return getSessionCustomer(createFoirCookieAdapter(store));
190
+ }
191
+ async function getFoirToken(store) {
192
+ return getSessionToken(createFoirCookieAdapter(store));
193
+ }
194
+ async function foirSignOut(store, opts) {
195
+ return clearSession(createFoirCookieAdapter(store, opts));
196
+ }
197
+ function foirSignInWithPassword({
198
+ env,
199
+ store,
200
+ email,
201
+ password,
202
+ cookieOptions
203
+ }) {
204
+ return loginWithPassword(createFoirCookieAdapter(store, { cookieOptions }), env, {
205
+ email,
206
+ password
207
+ });
208
+ }
209
+ function foirRegisterWithPassword({
210
+ env,
211
+ store,
212
+ email,
213
+ password,
214
+ cookieOptions
215
+ }) {
216
+ return registerWithPassword(createFoirCookieAdapter(store, { cookieOptions }), env, {
217
+ email,
218
+ password
219
+ });
220
+ }
221
+ function foirSignInWithOtp({
222
+ env,
223
+ store,
224
+ email,
225
+ otp,
226
+ cookieOptions
227
+ }) {
228
+ return loginWithOTP(createFoirCookieAdapter(store, { cookieOptions }), env, {
229
+ email,
230
+ otp
231
+ });
232
+ }
233
+ async function completeFoirProviderLogin(opts) {
234
+ const result = await customerProviderCallback(opts.env, {
235
+ providerKey: opts.providerKey,
236
+ code: opts.code,
237
+ state: opts.state
238
+ });
239
+ return saveSession(
240
+ createFoirCookieAdapter(opts.store, { cookieOptions: opts.cookieOptions }),
241
+ result
242
+ );
243
+ }
244
+
245
+ // src/next/middleware.ts
246
+ function createFoirMiddleware(config) {
247
+ const cookieName = config.cookieName ?? foirCookieName("foir:token");
248
+ const returnParam = config.returnParam ?? "returnTo";
249
+ return function foirMiddleware(request) {
250
+ if (config.isProtected && !config.isProtected(request)) {
251
+ return void 0;
252
+ }
253
+ if (request.cookies.get(cookieName)?.value) {
254
+ return void 0;
255
+ }
256
+ const url = new URL(config.signInUrl, request.url);
257
+ url.searchParams.set(
258
+ returnParam,
259
+ request.nextUrl.pathname + request.nextUrl.search
260
+ );
261
+ return Response.redirect(url.toString(), 307);
262
+ };
263
+ }
264
+ export {
265
+ completeFoirProviderLogin,
266
+ createFoirCookieAdapter,
267
+ createFoirMiddleware,
268
+ foirCookieName,
269
+ foirRegisterWithPassword,
270
+ foirSignInWithOtp,
271
+ foirSignInWithPassword,
272
+ foirSignOut,
273
+ getFoirSession,
274
+ getFoirToken
275
+ };
@@ -0,0 +1,319 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+
4
+ /**
5
+ * Foir GraphQL client — a single typed fetch wrapper for SSR/edge loaders.
6
+ *
7
+ * No GraphQL client (Apollo/urql) required: the Foir public API is a plain
8
+ * `POST` with an `x-api-key` header, and the dominant consumers (Hydrogen on
9
+ * Oxygen, React Router loaders, TanStack Start on CF Workers) fetch in
10
+ * server-only loaders and render — so Apollo's `InMemoryCache`/`useQuery`
11
+ * reactivity is dead weight, and a shared cache on a stateless multi-tenant
12
+ * edge worker is a cross-tenant hazard. This helper carries only the
13
+ * Foir-specific transport concerns (auth header, preview schema channel,
14
+ * error shape). Consumers on a GraphQL client (Apollo / urql / react-query /
15
+ * graphql-request) use the generated `TypedDocumentNode`s directly with their
16
+ * own client and replicate the two Foir-specific headers below — the
17
+ * `x-api-key` and, in preview, `X-Foir-Schema-Channel: draft`.
18
+ *
19
+ * Deduplicates the hand-copied `lib/foir/client.ts` that shipped identically
20
+ * across the Foir storefronts.
21
+ */
22
+
23
+ interface FoirEnv {
24
+ PLATFORM_API_URL?: string;
25
+ PLATFORM_API_KEY?: string;
26
+ PLATFORM_PREVIEW_API_KEY?: string;
27
+ FOIR_PREVIEW?: string;
28
+ }
29
+
30
+ /**
31
+ * Foir customer-auth GraphQL operations + result types.
32
+ *
33
+ * These are PLATFORM-STABLE primitives — `customerLogin`/`customerRegister`/
34
+ * `customerRefreshToken`/OTP/provider login are fixed-shape operations served
35
+ * by api-public for every project (gated per-project by the password/OTP/
36
+ * provider flags, but identical in shape when present). Unlike per-project
37
+ * model types, they don't vary by configured models, so the SDK owns the
38
+ * documents directly rather than relying on the consumer's codegen.
39
+ *
40
+ * The project-specific customer PROFILE (e.g. `myProfile.isAdmin`) is NOT here
41
+ * — that shape varies per project, so it stays consumer-injected (see
42
+ * `requireAuth`'s `resolveUser`).
43
+ */
44
+
45
+ /** A configured auth provider, as exposed to unauthenticated callers. */
46
+ interface AuthProviderPublic {
47
+ key: string;
48
+ name: string;
49
+ /** OAUTH2 | TOKEN_SSO | SAML | OIDC | EXTERNAL */
50
+ type: string;
51
+ isDefault: boolean | null;
52
+ }
53
+ interface ProviderLoginInput {
54
+ providerKey: string;
55
+ email?: string;
56
+ returnTo?: string;
57
+ /** Override the provider's default redirect_uri (must be allow-listed). */
58
+ redirectUri?: string;
59
+ }
60
+ interface ProviderCallbackInput {
61
+ providerKey: string;
62
+ code?: string;
63
+ state?: string;
64
+ email?: string;
65
+ idToken?: string;
66
+ }
67
+
68
+ /**
69
+ * Foir customer auth — framework-agnostic flows, token lifecycle, and guards.
70
+ *
71
+ * Session I/O is injected via {@link SessionAdapter} (no Hydrogen/React-Router
72
+ * coupling). Pre-login flows authenticate with the project `x-api-key`;
73
+ * post-login reads add the customer bearer. The project-specific profile (e.g.
74
+ * `isAdmin`) is resolved by a consumer-supplied `resolveUser` — the SDK never
75
+ * hardcodes the per-project customer profile shape.
76
+ */
77
+
78
+ /** The customer identity carried by an auth result. */
79
+ interface FoirCustomer {
80
+ id: string;
81
+ email: string;
82
+ }
83
+ /**
84
+ * Injected session store. Methods may be sync or async so consumers can plug
85
+ * in a cookie session (Hydrogen/Remix), a KV store, etc.
86
+ */
87
+ interface SessionAdapter {
88
+ get(key: string): string | null | undefined | Promise<string | null | undefined>;
89
+ set(key: string, value: string): void | Promise<void>;
90
+ unset(key: string): void | Promise<void>;
91
+ }
92
+
93
+ /**
94
+ * Foir-hosted first-party sessions, from the browser — the model for a
95
+ * backend-less SPA (Vite, CRA, a static site) that wants no tokens in JS.
96
+ *
97
+ * The sibling `fetchHostedSession` in ./hosted does the same exchange from a
98
+ * SERVER: it reads the cookie off an incoming request and forwards it by hand.
99
+ * A browser cannot set a `Cookie` header, so that function is unusable from an
100
+ * SPA by construction. This one lets the browser send the cookie the only way it
101
+ * can — `credentials: 'include'` — and keeps the resulting bearer in memory.
102
+ *
103
+ * How the pieces divide:
104
+ *
105
+ * cookie — long-lived (30d), HttpOnly, first-party on your registrable
106
+ * domain, set by Foir when hosted login finalizes. JS cannot read
107
+ * it, so XSS cannot exfiltrate it.
108
+ * bearer — 15 minutes, held in a closure here. Never written to
109
+ * localStorage/sessionStorage/IndexedDB, never in a cookie of ours.
110
+ *
111
+ * There is no refresh token in this flow. Re-exchanging the cookie IS the
112
+ * refresh, which is why nothing here needs rotation or reuse-detection: the
113
+ * durable credential is an opaque server-side session handle, revocable at any
114
+ * time from the admin panel or `signOut()`.
115
+ *
116
+ * REQUIRES a verified custom login domain that shares a registrable domain with
117
+ * your app (app.acme.com + login.acme.com). That is what makes the cookie
118
+ * first-party and lets `SameSite=Lax` send it. The same endpoints exist on
119
+ * api.foir.dev but a browser cannot reach them there — the cookie would be
120
+ * cross-site, and that CORS surface deliberately refuses credentials.
121
+ */
122
+ interface FoirSessionConfig {
123
+ /**
124
+ * Your verified custom login domain, e.g. `https://login.acme.com`. Must share
125
+ * a registrable domain with the app calling it.
126
+ */
127
+ loginOrigin: string;
128
+ /** Session-exchange path. Default `/session/token`. */
129
+ sessionPath?: string;
130
+ /** Logout path. Default `/session/logout`. */
131
+ logoutPath?: string;
132
+ /** Seconds before expiry to re-exchange. Default 60. */
133
+ refreshSkewSeconds?: number;
134
+ /**
135
+ * Called when the session goes away — the cookie expired, was revoked, or
136
+ * `signOut()` ran. Use it to redirect to `signInUrl()`.
137
+ */
138
+ onSignOut?: () => void;
139
+ }
140
+
141
+ /** Where the session hydration stands. */
142
+ type FoirStatus = 'loading' | 'authenticated' | 'unauthenticated';
143
+ /** The full context value. Read it through the hooks below, not directly. */
144
+ interface FoirContextValue {
145
+ status: FoirStatus;
146
+ customer: FoirCustomer | null;
147
+ /** The API config; exposed so advanced consumers can call `@foir/sdk/auth` directly. */
148
+ env: FoirEnv;
149
+ /** The session store backing this provider. */
150
+ adapter: SessionAdapter;
151
+ signIn(vars: {
152
+ email: string;
153
+ password: string;
154
+ }): Promise<FoirCustomer>;
155
+ register(vars: {
156
+ email: string;
157
+ password: string;
158
+ }): Promise<FoirCustomer>;
159
+ requestOtp(email: string): Promise<boolean>;
160
+ signInWithOtp(vars: {
161
+ email: string;
162
+ otp: string;
163
+ }): Promise<FoirCustomer>;
164
+ /** Start a provider (OAuth/OIDC) login. Redirect providers navigate away. */
165
+ signInWithProvider(providerKey: string, opts?: Omit<ProviderLoginInput, 'providerKey'>): Promise<void>;
166
+ /** Complete a provider login from your callback route (code + state). */
167
+ completeProviderLogin(input: Omit<ProviderCallbackInput, 'providerKey'> & {
168
+ providerKey: string;
169
+ }): Promise<FoirCustomer>;
170
+ signOut(): Promise<void>;
171
+ /** Rotate the access token; returns false (and signs out) if it can't. */
172
+ refresh(): Promise<boolean>;
173
+ /** The current access token, or null when signed out. */
174
+ getToken(): Promise<string | null>;
175
+ /** The project's configured auth providers (for OAuth buttons). */
176
+ getProviders(): Promise<AuthProviderPublic[]>;
177
+ /**
178
+ * In `hostedSession` mode, where to send the browser to sign in — sign-in is a
179
+ * redirect to your Foir login domain, not an in-page form. Null in token mode,
180
+ * where you call {@link FoirContextValue.signIn} instead.
181
+ */
182
+ hostedSignInUrl: ((returnTo?: string) => string) | null;
183
+ }
184
+ interface FoirProviderProps {
185
+ /** API config: `{ PLATFORM_API_URL, PLATFORM_API_KEY }` (a publishable `pk_` key). */
186
+ env: FoirEnv;
187
+ /** Session store for token mode. Defaults to a browser localStorage adapter. */
188
+ adapter?: SessionAdapter;
189
+ /**
190
+ * Opt into Foir-hosted first-party sessions: the durable credential is an
191
+ * HttpOnly cookie on your own domain and the access token lives only in
192
+ * memory, so nothing authentication-related is reachable from JS. This is the
193
+ * secure default for a backend-less SPA, and it REPLACES `adapter` — pass one
194
+ * or the other, not both.
195
+ *
196
+ * Requires a verified custom login domain sharing a registrable domain with
197
+ * your app (`app.acme.com` + `login.acme.com`). Sign-in becomes a redirect to
198
+ * {@link FoirContextValue.hostedSignInUrl}; the password/OTP/provider actions
199
+ * do not apply and will throw.
200
+ */
201
+ hostedSession?: Omit<FoirSessionConfig, 'onSignOut'>;
202
+ children: ReactNode;
203
+ }
204
+ /**
205
+ * Provides Foir customer auth to a React tree. Hydrates the session on mount,
206
+ * then exposes the current customer and sign-in/out actions through
207
+ * {@link useFoirSession}, {@link useFoirUser}, and {@link useFoirAuth}.
208
+ *
209
+ * Two session models:
210
+ *
211
+ * default tokens in a `SessionAdapter` (localStorage unless you pass
212
+ * your own). Simple, but a refresh token sits in JS.
213
+ * `hostedSession` Foir-hosted first-party cookie; the bearer never leaves
214
+ * memory. Needs a custom login domain. Prefer this.
215
+ */
216
+ declare function FoirProvider({ env, adapter, hostedSession, children, }: FoirProviderProps): react_jsx_runtime.JSX.Element;
217
+ /** The current session state. */
218
+ interface FoirSession {
219
+ status: FoirStatus;
220
+ customer: FoirCustomer | null;
221
+ isLoading: boolean;
222
+ isAuthenticated: boolean;
223
+ }
224
+ /** Read the current session status and customer. */
225
+ declare function useFoirSession(): FoirSession;
226
+ /** The signed-in customer (`{ id, email }`), or null. */
227
+ declare function useFoirUser(): FoirCustomer | null;
228
+ /** The sign-in / sign-out actions. */
229
+ declare function useFoirAuth(): {
230
+ signIn: (vars: {
231
+ email: string;
232
+ password: string;
233
+ }) => Promise<FoirCustomer>;
234
+ register: (vars: {
235
+ email: string;
236
+ password: string;
237
+ }) => Promise<FoirCustomer>;
238
+ requestOtp: (email: string) => Promise<boolean>;
239
+ signInWithOtp: (vars: {
240
+ email: string;
241
+ otp: string;
242
+ }) => Promise<FoirCustomer>;
243
+ signInWithProvider: (providerKey: string, opts?: Omit<ProviderLoginInput, "providerKey">) => Promise<void>;
244
+ completeProviderLogin: (input: Omit<ProviderCallbackInput, "providerKey"> & {
245
+ providerKey: string;
246
+ }) => Promise<FoirCustomer>;
247
+ signOut: () => Promise<void>;
248
+ refresh: () => Promise<boolean>;
249
+ getToken: () => Promise<string | null>;
250
+ getProviders: () => Promise<AuthProviderPublic[]>;
251
+ hostedSignInUrl: ((returnTo?: string) => string) | null;
252
+ };
253
+
254
+ interface SignInProps {
255
+ /** `password` (default) or `otp` (email one-time code). Ignored when `hostedUrl` is set. */
256
+ method?: 'password' | 'otp';
257
+ /** Render a single button that redirects to a hosted login page instead of an embedded form. */
258
+ hostedUrl?: string;
259
+ /** Show OAuth provider buttons below the form. Default true. */
260
+ oauth?: boolean;
261
+ /** Navigate here after a successful sign-in. */
262
+ afterSignInUrl?: string;
263
+ /** Called with the customer on a successful sign-in (before any redirect). */
264
+ onSignIn?(customer: FoirCustomer): void;
265
+ className?: string;
266
+ }
267
+ /**
268
+ * A drop-in customer sign-in. Renders an email/password (or OTP) form and,
269
+ * unless disabled, OAuth provider buttons. Set `hostedUrl` to instead render a
270
+ * button that redirects to a hosted login page. All state is handled through
271
+ * {@link FoirProvider}; on success it calls `onSignIn` and optionally navigates
272
+ * to `afterSignInUrl`.
273
+ */
274
+ declare function SignIn({ method, hostedUrl, oauth, afterSignInUrl, onSignIn, className, }: SignInProps): react_jsx_runtime.JSX.Element;
275
+
276
+ interface OAuthButtonsProps {
277
+ /** Passed to the provider login (where the callback returns the user). */
278
+ returnTo?: string;
279
+ /** Override the provider's default redirect URI (must be allow-listed). */
280
+ redirectUri?: string;
281
+ /** Filter which providers render (defaults to every redirect-capable one). */
282
+ filter?(provider: AuthProviderPublic): boolean;
283
+ /** Render your own button. Receives the provider and a click handler. */
284
+ children?(provider: AuthProviderPublic, signIn: () => void): ReactNode;
285
+ className?: string;
286
+ onError?(error: unknown): void;
287
+ }
288
+ /**
289
+ * Renders a sign-in button per configured OAuth/OIDC/SAML provider. Clicking a
290
+ * button starts the provider login and (for redirect flows) navigates away.
291
+ * Pass a `children` render prop to fully control the button markup.
292
+ */
293
+ declare function OAuthButtons({ returnTo, redirectUri, filter, children, className, onError, }: OAuthButtonsProps): react_jsx_runtime.JSX.Element | null;
294
+
295
+ interface UserButtonProps {
296
+ /** Called after a successful sign-out. */
297
+ afterSignOut?(): void;
298
+ /** Navigate here after sign-out. */
299
+ afterSignOutUrl?: string;
300
+ className?: string;
301
+ }
302
+ /**
303
+ * A minimal signed-in affordance: the customer's email plus a sign-out button.
304
+ * Renders nothing when signed out. Style it via `className` (the default is an
305
+ * unopinionated inline layout).
306
+ */
307
+ declare function UserButton({ afterSignOut, afterSignOutUrl, className }: UserButtonProps): react_jsx_runtime.JSX.Element | null;
308
+
309
+ /**
310
+ * A {@link SessionAdapter} backed by the browser's `localStorage`.
311
+ *
312
+ * SSR-safe: with no `window` (server render) reads return `null` and writes are
313
+ * no-ops, so {@link FoirProvider} starts in `loading` and hydrates the real
314
+ * session on the client after mount. This is the default adapter when you don't
315
+ * pass one to `FoirProvider`.
316
+ */
317
+ declare function createLocalStorageAdapter(): SessionAdapter;
318
+
319
+ export { type AuthProviderPublic, type FoirContextValue, type FoirCustomer, type FoirEnv, FoirProvider, type FoirProviderProps, type FoirSession, type FoirStatus, OAuthButtons, type OAuthButtonsProps, type SessionAdapter, SignIn, type SignInProps, UserButton, type UserButtonProps, createLocalStorageAdapter, useFoirAuth, useFoirSession, useFoirUser };