import type { Auth } from "../core/auth.gen.js"; import type { ServerSentEventsOptions, ServerSentEventsResult } from "../core/serverSentEvents.gen.js"; import type { Client as CoreClient, Config as CoreConfig } from "../core/types.gen.js"; import type { Middleware } from "./utils.gen.js"; export type ResponseStyle = "data" | "fields"; export interface Config extends Omit, CoreConfig { /** * Base URL for all requests made by this client. */ baseUrl?: T["baseUrl"]; /** * Fetch API implementation. You can use this option to provide a custom * fetch instance. * * @default globalThis.fetch */ fetch?: (request: Request) => ReturnType; /** * Please don't use the Fetch client for Next.js applications. The `next` * options won't have any effect. * * Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead. */ next?: never; /** * Return the response data parsed in a specified format. By default, `auto` * will infer the appropriate method from the `Content-Type` response header. * You can override this behavior with any of the {@link Body} methods. * Select `stream` if you don't want to parse response data at all. * * @default 'auto' */ parseAs?: "arrayBuffer" | "auto" | "blob" | "formData" | "json" | "stream" | "text"; /** * Should we return only data or multiple fields (data, error, response, etc.)? * * @default 'fields' */ responseStyle?: ResponseStyle; /** * Throw an error instead of returning it in the response? * * @default false */ throwOnError?: T["throwOnError"]; } export interface RequestOptions extends Config<{ responseStyle: TResponseStyle; throwOnError: ThrowOnError; }>, Pick, "onSseError" | "onSseEvent" | "sseDefaultRetryDelay" | "sseMaxRetryAttempts" | "sseMaxRetryDelay"> { /** * Any body that you want to add to your request. * * {@link https://developer.mozilla.org/docs/Web/API/fetch#body} */ body?: unknown; path?: Record; query?: Record; /** * Security mechanism(s) to use for the request. */ security?: ReadonlyArray; url: Url; } export interface ResolvedRequestOptions extends RequestOptions { serializedBody?: string; } export type RequestResult = ThrowOnError extends true ? Promise ? TData[keyof TData] : TData : { data: TData extends Record ? TData[keyof TData] : TData; request: Request; response: Response; }> : Promise ? TData[keyof TData] : TData) | undefined : ({ data: TData extends Record ? TData[keyof TData] : TData; error: undefined; } | { data: undefined; error: TError extends Record ? TError[keyof TError] : TError; }) & { request: Request; response: Response; }>; export interface ClientOptions { baseUrl?: string; responseStyle?: ResponseStyle; throwOnError?: boolean; } type MethodFnBase = (options: Omit, "method">) => RequestResult; type MethodFnServerSentEvents = (options: Omit, "method">) => Promise>; type MethodFn = MethodFnBase & { sse: MethodFnServerSentEvents; }; type RequestFn = (options: Omit, "method"> & Pick>, "method">) => RequestResult; type BuildUrlFn = ; query?: Record; url: string; }>(options: Pick & Options) => string; export type Client = CoreClient & { interceptors: Middleware; }; /** * The `createClientConfig()` function will be called on client initialization * and the returned object will become the client's initial configuration. * * You may want to initialize your client this way instead of calling * `setConfig()`. This is useful for example if you're using Next.js * to ensure your client always has the correct values. */ export type CreateClientConfig = (override?: Config) => Config & T>; export interface TDataShape { body?: unknown; headers?: unknown; path?: unknown; query?: unknown; url: string; } type OmitKeys = Pick>; export type Options = OmitKeys, "body" | "path" | "query" | "url"> & Omit; export type OptionsLegacyParser = TData extends { body?: any; } ? TData extends { headers?: any; } ? OmitKeys, "body" | "headers" | "url"> & TData : OmitKeys, "body" | "url"> & TData & Pick, "headers"> : TData extends { headers?: any; } ? OmitKeys, "headers" | "url"> & TData & Pick, "body"> : OmitKeys, "url"> & TData; export {};