import { Prettify } from "./type-utils.mjs"; import { FetcherFetchOptions } from "./fetcher.mjs"; import { CombinedClientContributions, InferUserFields, StoresOf } from "./infer.mjs"; import { CoreContribution } from "./routes.mjs"; import { PluginOverrides } from "./plugin.mjs"; import { AnyClientPlugin } from "./define-plugin.mjs"; import { ReadableAtom } from "nanostores"; //#region src/types.d.ts type ClientFetchOptions = Partial; type CreateAuthClientOptions = { /** Server origin, e.g. `"http://localhost:8080"`. Trailing slash is stripped. */baseURL: string; /** Path where the Limen handler is mounted. Defaults to `"/auth"`. */ basePath?: string; /** Options that modify how the SDK performs HTTP requests. */ fetchOptions?: ClientFetchOptions; /** * Optional transformer for non-default session payloads. * * Provide this when your server returns custom user/session fields. It must * map the raw response into `Session`. */ parseSession?: ParseSession>; /** * How the SDK navigates the browser when a flow hands control to an external * page (e.g. an OAuth provider's authorization URL). Defaults to * `window.location.href = url` when a `window` is available; a no-op in * non-browser environments. Provide a custom function to integrate with a * client-side router. */ redirectFn?: RedirectFn; /** Plugins to register. */ plugins?: Plugins; /** * Response-envelope config. Set this when the server wraps successful or all * responses. */ envelope?: EnvelopeConfig; /** * Per-plugin route overrides. Keys are camelCased plugin ids, e.g. * `{ magicLink: { basePath: "/passwordless" } }`. */ overrides?: PluginOverrides; /** * SSR seed for the session store. Provide the session resolved server-side to * avoid a hydration flash. When provided, lazy hydration is skipped until you * call `getSession()` or the store revalidates. */ initialSession?: Session> | null; /** * Keep session state in sync across browser tabs. * Enabled by default in browsers. Set `false` to disable. */ crossTabSync?: boolean; /** * Refresh session state when the tab becomes active again. * Enabled by default in browsers. Set `false` to disable. */ refetchOnWindowFocus?: boolean; }; type PrettyUserFields = Prettify>; /** Each store exposed on the client under a `$` prefix, read-only. */ type StoreAtoms = { readonly [K in keyof Stores & string as `$${K}`]: ReadableAtom }; type AuthClient = Prettify<{ readonly baseURL: string; readonly basePath: string; } & StoreAtoms> & CoreContribution> & CombinedClientContributions>; /** * The user object returned from `/me` and any session-bearing response. * * `TFields` lets consumers extend the shape with custom user fields. The * fields listed here are always present. * * @example * type AppUser = User<{ firstName: string; orgId: string }>; */ type User = { id: string; email: string; emailVerifiedAt: string | null; } & TFields; type Session = { user: User; }; /** * Query values for a request. An array value is sent comma-separated. */ type QueryParams = Record; /** * Pagination accepted by list routes. */ type PaginationInput = { page?: number; perPage?: number; }; type Page = { items: T[]; total: number; page: number; perPage: number; totalPages: number; }; type EnvelopeMode = "off" | "wrap-success" | "always"; type EnvelopeFields = { data: string; message: string; }; type EnvelopeConfig = { mode: EnvelopeMode; fields?: EnvelopeFields; }; type ParseSession = (raw: unknown) => Session; type HTTPMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS"; type RedirectFn = (url: string) => boolean; //#endregion export { AuthClient, ClientFetchOptions, CreateAuthClientOptions, EnvelopeConfig, EnvelopeFields, EnvelopeMode, HTTPMethod, Page, PaginationInput, ParseSession, QueryParams, RedirectFn, Session, StoreAtoms, User };