UNPKG

@zpg6-test-pkgs/better-auth

Version:

The most comprehensive authentication library for TypeScript.

174 lines (170 loc) 7.23 kB
import * as nanostores from 'nanostores'; import { Store, StoreValue } from 'nanostores'; export * from 'nanostores'; import * as _better_fetch_fetch from '@better-fetch/fetch'; import { BetterFetchError } from '@better-fetch/fetch'; export * from '@better-fetch/fetch'; import { C as ClientOptions, B as BetterAuthClientPlugin, I as IsSignal, a as InferClientAPI, b as InferActions, c as InferErrorCodes } from '../../shared/better-auth.ueSiK_dg.cjs'; import { U as UnionToIntersection, P as PrettifyDeep } from '../../shared/better-auth.DTtXpZYr.cjs'; import { DependencyList } from 'react'; import { g as BASE_ERROR_CODES } from '../../shared/better-auth.8Ira7TFx.cjs'; import 'better-call'; import 'kysely'; import 'zod/v4'; import '../../shared/better-auth.DtuOgks-.cjs'; import 'jose'; import 'zod/v4/core'; import 'zod'; import 'better-sqlite3'; import 'bun:sqlite'; type StoreKeys<T> = T extends { setKey: (k: infer K, v: any) => unknown; } ? K : never; interface UseStoreOptions<SomeStore> { /** * @default * ```ts * [store, options.keys] * ``` */ deps?: DependencyList; /** * Will re-render components only on specific key changes. */ keys?: StoreKeys<SomeStore>[]; } /** * Subscribe to store changes and get store's value. * * Can be user with store builder too. * * ```js * import { useStore } from 'nanostores/react' * * import { router } from '../store/router' * * export const Layout = () => { * let page = useStore(router) * if (page.route === 'home') { * return <HomePage /> * } else { * return <Error404 /> * } * } * ``` * * @param store Store instance. * @returns Store value. */ declare function useStore<SomeStore extends Store>(store: SomeStore, options?: UseStoreOptions<SomeStore>): StoreValue<SomeStore>; declare function capitalizeFirstLetter(str: string): string; type InferResolvedHooks<O extends ClientOptions> = O["plugins"] extends Array<infer Plugin> ? Plugin extends BetterAuthClientPlugin ? Plugin["getAtoms"] extends (fetch: any) => infer Atoms ? Atoms extends Record<string, any> ? { [key in keyof Atoms as IsSignal<key> extends true ? never : key extends string ? `use${Capitalize<key>}` : never]: () => ReturnType<Atoms[key]["get"]>; } : {} : {} : {} : {}; declare function createAuthClient<Option extends ClientOptions>(options?: Option): UnionToIntersection<InferResolvedHooks<Option>> & InferClientAPI<Option> & InferActions<Option> & { useSession: () => { data: InferClientAPI<Option> extends { getSession: () => Promise<infer Res>; } ? Res extends { data: infer S; error: null; } | { data: null; error: { message?: string | undefined; status: number; statusText: string; }; } ? S : Res : never; isPending: boolean; error: BetterFetchError | null; refetch: () => void; }; $Infer: { Session: NonNullable<InferClientAPI<Option> extends { getSession: () => Promise<infer Res>; } ? Res extends { data: infer S; error: null; } | { data: null; error: { message?: string | undefined; status: number; statusText: string; }; } ? S : Res : never>; }; $fetch: _better_fetch_fetch.BetterFetch<{ plugins: (_better_fetch_fetch.BetterFetchPlugin | { id: string; name: string; hooks: { onSuccess: ((context: _better_fetch_fetch.SuccessContext<any>) => Promise<void> | void) | undefined; onError: ((context: _better_fetch_fetch.ErrorContext) => Promise<void> | void) | undefined; onRequest: (<T extends Record<string, any>>(context: _better_fetch_fetch.RequestContext<T>) => Promise<_better_fetch_fetch.RequestContext | void> | _better_fetch_fetch.RequestContext | void) | undefined; onResponse: ((context: _better_fetch_fetch.ResponseContext) => Promise<Response | void | _better_fetch_fetch.ResponseContext> | Response | _better_fetch_fetch.ResponseContext | void) | undefined; }; } | { id: string; name: string; hooks: { onSuccess(context: _better_fetch_fetch.SuccessContext<any>): void; }; })[]; redirect?: RequestRedirect | undefined; method: string; headers?: (HeadersInit & (HeadersInit | { accept: "application/json" | "text/plain" | "application/octet-stream"; "content-type": "application/json" | "text/plain" | "application/x-www-form-urlencoded" | "multipart/form-data" | "application/octet-stream"; authorization: "Bearer" | "Basic"; })) | undefined; cache?: RequestCache | undefined; credentials?: RequestCredentials; integrity?: string | undefined; keepalive?: boolean | undefined; mode?: RequestMode | undefined; priority?: RequestPriority | undefined; referrer?: string | undefined; referrerPolicy?: ReferrerPolicy | undefined; signal?: (AbortSignal | null) | undefined; window?: null | undefined; onRetry?: ((response: _better_fetch_fetch.ResponseContext) => Promise<void> | void) | undefined; hookOptions?: { cloneResponse?: boolean; } | undefined; timeout?: number | undefined; customFetchImpl: _better_fetch_fetch.FetchEsque; baseURL: string; throw?: boolean | undefined; auth?: ({ type: "Bearer"; token: string | Promise<string | undefined> | (() => string | Promise<string | undefined> | undefined) | undefined; } | { type: "Basic"; username: string | (() => string | undefined) | undefined; password: string | (() => string | undefined) | undefined; } | { type: "Custom"; prefix: string | (() => string | undefined) | undefined; value: string | (() => string | undefined) | undefined; }) | undefined; body?: any; query?: any; params?: any; duplex?: "full" | "half" | undefined; jsonParser: (text: string) => Promise<any> | any; retry?: _better_fetch_fetch.RetryOptions | undefined; retryAttempt?: number | undefined; output?: (_better_fetch_fetch.StandardSchemaV1 | typeof Blob | typeof File) | undefined; errorSchema?: _better_fetch_fetch.StandardSchemaV1 | undefined; disableValidation?: boolean | undefined; }, unknown, unknown, {}>; $store: { notify: (signal?: Omit<string, "$sessionSignal"> | "$sessionSignal") => void; listen: (signal: Omit<string, "$sessionSignal"> | "$sessionSignal", listener: (value: boolean, oldValue?: boolean | undefined) => void) => void; atoms: Record<string, nanostores.WritableAtom<any>>; }; $ERROR_CODES: PrettifyDeep<InferErrorCodes<Option> & typeof BASE_ERROR_CODES>; }; export { capitalizeFirstLetter, createAuthClient, useStore };