import { HasRequiredKeys, IsAny, Prettify as Prettify$1, UnionToIntersection } from "../types/helper.mjs"; import { InferAdditionalFromClient, InferSessionFromClient, InferUserFromClient } from "./types.mjs"; import { BetterAuthClientOptions, ClientFetchOption } from "@better-auth/core"; import { SocialProviderList } from "@better-auth/core/social-providers"; import { Endpoint, InputContext, StandardSchemaV1 as StandardSchemaV1$1 } from "better-call"; import { BetterFetchResponse } from "@better-fetch/fetch"; //#region src/client/path-to-object.d.ts /** * Extract generic OAuth provider IDs from the client options. * Supports both `$InferAuth` (server type bridge) and client plugins * with `$InferServerPlugin`. */ type InferGenericOAuthProviderIds = (O extends { $InferAuth: { options: { plugins: Array; }; }; } ? P extends { id: "generic-oauth"; options: { config: Array<{ providerId: infer ID; }>; }; } ? ID & string : never : never) | (O extends { plugins: Array; } ? P extends { $InferServerPlugin: { id: "generic-oauth"; options: { config: Array<{ providerId: infer ID; }>; }; }; } ? ID & string : never : never); type KeepNullishFromOriginal = Replaced | (undefined extends Original ? undefined : never) | (null extends Original ? null : never); type ReplaceTopLevelField = Data extends object ? Field extends keyof Data ? Omit & { [K in Field]: KeepNullishFromOriginal } : Data : Data; type ReplaceAuthUserAndSession = ReplaceTopLevelField>, "session", InferSessionFromClient>; type MergeCustomSessionField = Field extends keyof R ? { [K in Field]: KeepNullishFromOriginal & InferType> } : {}; type MergeCustomSessionWithInferred = R extends object ? Omit & MergeCustomSessionField> & MergeCustomSessionField> : never; type RefineAuthResponse = Data extends { token: unknown; } | { redirect: unknown; } ? ReplaceAuthUserAndSession : Data; 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 | undefined; callbackURL?: string | undefined; fetchOptions?: FetchOptions | undefined; } & UnionToIntersection>; type InferUserUpdateCtx = { image?: (string | null) | undefined; name?: string | undefined; fetchOptions?: FetchOptions | undefined; } & Partial>>; type InferSessionUpdateCtx = { fetchOptions?: FetchOptions | undefined; } & Partial>>; type InferCtxQuery, FetchOptions extends ClientFetchOption> = C["query"] extends Record ? { query: C["query"]; fetchOptions?: FetchOptions | undefined; } : C["query"] extends Record | undefined ? { query?: C["query"] | undefined; fetchOptions?: FetchOptions | undefined; } : { fetchOptions?: FetchOptions | undefined; }; type InferBodyCtx = Body extends Record ? Body & { fetchOptions?: FetchOptions | undefined; } : never; type PrettifyUnion = T extends unknown ? Prettify$1 : never; type HasRequiredKeysInUnion = true extends (T extends unknown ? HasRequiredKeys : never) ? true : false; type HasRequiredCtx, FetchOptions extends ClientFetchOption> = IsAny extends true ? HasRequiredKeysInUnion> : undefined extends C["body"] ? HasRequiredKeysInUnion> : HasRequiredKeysInUnion>; type InferCtx, FetchOptions extends ClientFetchOption> = IsAny extends true ? InferCtxQuery : [NonNullable] extends [never] ? InferCtxQuery : NonNullable extends Record ? InferBodyCtx, FetchOptions> : InferCtxQuery; type MergeRoutes = UnionToIntersection; type InferRoute = API extends Record ? T extends Endpoint ? T["options"]["metadata"] extends { isAction: false; } | { SERVER_ONLY: true; } | { scope: "http"; } | { scope: "server"; } ? {} : PathToObject infer R) ? C extends InputContext ? & Record, Partial & Record, C["params"]>>(...data: HasRequiredCtx extends true ? [PrettifyUnion : T["path"] extends `/sign-in/social` ? Omit, "provider"> & { provider: SocialProviderList[number] | InferGenericOAuthProviderIds | (string & {}); fetchOptions?: FetchOptions | undefined; } : InferCtx>, FetchOptions?] : [PrettifyUnion : T["path"] extends `/update-session` ? InferSessionUpdateCtx : InferCtx>?, FetchOptions?]) => Promise>, COpts> : T["path"] extends "/get-session" ? { user: InferUserFromClient; session: InferSessionFromClient; } | null : RefineAuthResponse>, COpts>, T["options"]["error"] extends StandardSchemaV1$1 ? NonNullable["output"] : { code?: string | undefined; message?: string | undefined; }, FetchOptions["throw"] extends true ? true : COpts["fetchOptions"] extends { throw: true; } ? true : false>> : never : never> : {} : never; type InferRoutes, ClientOpts extends BetterAuthClientOptions> = MergeRoutes>; type ProxyRequest = { options?: ClientFetchOption | undefined; query?: any | undefined; [key: string]: any; }; //#endregion export { CamelCase, InferCtx, InferRoute, InferRoutes, InferSessionUpdateCtx, InferSignUpEmailCtx, InferUserUpdateCtx, MergeRoutes, PathToObject, ProxyRequest };