import { h as BetterAuthPlugin, B as BetterAuthOptions, ad as InferFieldsInputClient, ab as InferFieldsOutput, U as User, S as Session, n as Auth } from './better-auth.UgZtsmr9.js'; import { BetterFetchOption, BetterFetchResponse, BetterFetch, BetterFetchPlugin } from '@better-fetch/fetch'; import { WritableAtom, Atom } from 'nanostores'; import { U as UnionToIntersection, H as HasRequiredKeys, a as Prettify, L as LiteralString, S as StripEmptyObjects } from './better-auth.ZSfSbnQT.js'; import { Endpoint, InputContext } from 'better-call'; type CamelCase = S extends `${infer P1}-${infer P2}${infer P3}` ? `${Lowercase}${Uppercase}${CamelCase}` : Lowercase; type PathToObject any> = T extends `/${infer Segment}/${infer Rest}` ? { [K in CamelCase]: PathToObject<`/${Rest}`, Fn>; } : T extends `/${infer Segment}` ? { [K in CamelCase]: Fn; } : never; type InferSignUpEmailCtx = { email: string; name: string; password: string; image?: string; callbackURL?: string; fetchOptions?: FetchOptions; } & UnionToIntersection>; type InferUserUpdateCtx = { image?: string | null; name?: string; fetchOptions?: FetchOptions; } & Partial>>; type InferCtx, FetchOptions extends BetterFetchOption> = C["body"] extends Record ? C["body"] & { fetchOptions?: FetchOptions; } : C["query"] extends Record ? { query: C["query"]; fetchOptions?: FetchOptions; } : C["query"] extends Record | undefined ? { query?: C["query"]; fetchOptions?: FetchOptions; } : { fetchOptions?: FetchOptions; }; type MergeRoutes = UnionToIntersection; type InferRoute = API extends Record ? T extends Endpoint ? T["options"]["metadata"] extends { isAction: false; } | { SERVER_ONLY: true; } ? {} : PathToObject infer R ? C extends InputContext ? & Record, Partial & Record, C["params"]>>(...data: HasRequiredKeys> extends true ? [ Prettify : InferCtx>, FetchOptions? ] : [ Prettify : InferCtx>?, FetchOptions? ]) => Promise> : T["path"] extends "/get-session" ? { user: InferUserFromClient; session: InferSessionFromClient; } | null : NonNullable>, { code?: string; message?: string; }, FetchOptions["throw"] extends true ? true : COpts["fetchOptions"] extends { throw: true; } ? true : false>> : never : never> : {} : never; type InferRoutes, ClientOpts extends ClientOptions> = MergeRoutes>; type AtomListener = { matcher: (path: string) => boolean; signal: "$sessionSignal" | Omit; }; interface Store { notify: (signal: string) => void; listen: (signal: string, listener: () => void) => void; atoms: Record>; } interface BetterAuthClientPlugin { id: LiteralString; /** * only used for type inference. don't pass the * actual plugin */ $InferServerPlugin?: BetterAuthPlugin; /** * Custom actions */ getActions?: ($fetch: BetterFetch, $store: Store, /** * better-auth client options */ options: ClientOptions | undefined) => Record; /** * State atoms that'll be resolved by each framework * auth store. */ getAtoms?: ($fetch: BetterFetch) => Record>; /** * specify path methods for server plugin inferred * endpoints to force a specific method. */ pathMethods?: Record; /** * Better fetch plugins */ fetchPlugins?: BetterFetchPlugin[]; /** * a list of recaller based on a matcher function. * The signal name needs to match a signal in this * plugin or any plugin the user might have added. */ atomListeners?: AtomListener[]; } interface ClientOptions { fetchOptions?: BetterFetchOption; plugins?: BetterAuthClientPlugin[]; baseURL?: string; basePath?: string; disableDefaultFetchPlugins?: boolean; $InferAuth?: BetterAuthOptions; } type InferClientAPI = InferRoutes ? Auth["api"] & (O["plugins"] extends Array ? UnionToIntersection : {}) : Auth["api"], O>; type InferActions = (O["plugins"] extends Array ? UnionToIntersection infer Actions ? Actions : {} : {}> : {}) & InferRoutes ? Plugin extends { endpoints: infer Endpoints; } ? Endpoints : {} : {} : {}, O>; type InferErrorCodes = O["plugins"] extends Array ? UnionToIntersection : {}; /** * signals are just used to recall a computed value. * as a convention they start with "$" */ type IsSignal = T extends `$${infer _}` ? true : false; type InferPluginsFromClient = O["plugins"] extends Array ? Array : undefined; type InferSessionFromClient = StripEmptyObjects>>; type InferUserFromClient = StripEmptyObjects>>; type InferAdditionalFromClient = Options["plugins"] extends Array ? T extends BetterAuthClientPlugin ? T["$InferServerPlugin"] extends { schema: { [key in Key]: { fields: infer Field; }; }; } ? Format extends "input" ? InferFieldsInputClient : InferFieldsOutput : {} : {} : {}; export type { AtomListener as A, BetterAuthClientPlugin as B, ClientOptions as C, IsSignal as I, Store as S, InferClientAPI as a, InferActions as b, InferErrorCodes as c, InferRoute as d, InferPluginsFromClient as e, InferSessionFromClient as f, InferUserFromClient as g, InferAdditionalFromClient as h };