import type { AxiosError, AxiosInstance, AxiosRequestHeaders, AxiosResponse, AxiosStatic, CreateAxiosDefaults } from 'axios'; import type { Auth } from '../core/auth.gen'; import type { ServerSentEventsOptions, ServerSentEventsResult } from '../core/serverSentEvents.gen'; import type { Client as CoreClient, Config as CoreConfig } from '../core/types.gen'; export interface Config extends Omit, CoreConfig { /** * Axios implementation. You can use this option to provide either an * `AxiosStatic` or an `AxiosInstance`. * * @default axios */ axios?: AxiosStatic | AxiosInstance; /** * Base URL for all requests made by this client. */ baseURL?: T['baseURL']; /** * An object containing any HTTP headers that you want to pre-populate your * `Headers` object with. * * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more} */ headers?: AxiosRequestHeaders | Record; /** * Throw an error instead of returning it in the response? * * @default false */ throwOnError?: T['throwOnError']; } export interface RequestOptions extends Config<{ throwOnError: ThrowOnError; }>, Pick, 'onRequest' | '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 ClientOptions { baseURL?: string; throwOnError?: boolean; } export type RequestResult = ThrowOnError extends true ? Promise ? TData[keyof TData] : TData>> : Promise<(AxiosResponse ? TData[keyof TData] : TData> & { error: undefined; }) | (AxiosError ? TError[keyof TError] : TError> & { data: undefined; error: TError extends Record ? TError[keyof TError] : TError; })>; type MethodFn = (options: Omit, 'method'>) => RequestResult; type SseFn = (options: Omit, 'method'>) => Promise>; type RequestFn = (options: Omit, 'method'> & Pick>, 'method'>) => RequestResult; type BuildUrlFn = ; query?: Record; url: string; }>(options: TData & Pick, 'axios' | 'baseURL' | 'paramsSerializer' | 'querySerializer'>) => string; export type Client = CoreClient & { instance: AxiosInstance; }; /** * 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'> & ([TData] extends [never] ? unknown : Omit); export {};