import * as undici from 'undici'; interface $Fetch { (request: FetchRequest, options?: FetchOptions): Promise>; raw(request: FetchRequest, options?: FetchOptions): Promise>>; native: Fetch; create(defaults: FetchOptions, globalOptions?: CreateFetchOptions): $Fetch; } interface FetchOptions extends Omit, FetchHooks { baseURL?: string; body?: RequestInit["body"] | Record; ignoreResponseError?: boolean; params?: Record; query?: Record; parseResponse?: (responseText: string) => any; responseType?: R; /** * @experimental Set to "half" to enable duplex streaming. * Will be automatically set to "half" when using a ReadableStream as body. * @see https://fetch.spec.whatwg.org/#enumdef-requestduplex */ duplex?: "half" | undefined; /** * Only supported in Node.js >= 18 using undici * * @see https://undici.nodejs.org/#/docs/api/Dispatcher */ dispatcher?: InstanceType; /** * Only supported older Node.js versions using node-fetch-native polyfill. */ agent?: unknown; /** timeout in milliseconds */ timeout?: number; retry?: number | false; /** Delay between retries in milliseconds. */ retryDelay?: number | ((context: FetchContext) => number); /** Default is [408, 409, 425, 429, 500, 502, 503, 504] */ retryStatusCodes?: number[]; } interface ResolvedFetchOptions extends FetchOptions { headers: Headers; } interface CreateFetchOptions { defaults?: FetchOptions; fetch?: Fetch; Headers?: typeof Headers; AbortController?: typeof AbortController; } type GlobalOptions = Pick; interface FetchContext { request: FetchRequest; options: ResolvedFetchOptions; response?: FetchResponse; error?: Error; } type MaybePromise = T | Promise; type MaybeArray = T | T[]; type FetchHook = (context: C) => MaybePromise; interface FetchHooks { onRequest?: MaybeArray>>; onRequestError?: MaybeArray & { error: Error; }>>; onResponse?: MaybeArray & { response: FetchResponse; }>>; onResponseError?: MaybeArray & { response: FetchResponse; }>>; } interface ResponseMap { blob: Blob; text: string; arrayBuffer: ArrayBuffer; stream: ReadableStream; } type ResponseType = keyof ResponseMap | "json"; type MappedResponseType = R extends keyof ResponseMap ? ResponseMap[R] : JsonType; interface FetchResponse extends Response { _data?: T; } interface IFetchError extends Error { request?: FetchRequest; options?: FetchOptions; response?: FetchResponse; data?: T; status?: number; statusText?: string; statusCode?: number; statusMessage?: string; } type Fetch = typeof globalThis.fetch; type FetchRequest = RequestInfo; interface SearchParameters { [key: string]: any; } declare function createFetch(globalOptions?: CreateFetchOptions): $Fetch; declare class FetchError extends Error implements IFetchError { constructor(message: string, opts?: { cause: unknown; }); } interface FetchError extends IFetchError { } declare function createFetchError(ctx: FetchContext): IFetchError; export { type $Fetch as $, type CreateFetchOptions as C, FetchError as F, type GlobalOptions as G, type IFetchError as I, type MappedResponseType as M, type ResolvedFetchOptions as R, type SearchParameters as S, createFetchError as a, type FetchOptions as b, createFetch as c, type FetchContext as d, type FetchHook as e, type FetchHooks as f, type ResponseMap as g, type ResponseType as h, type FetchResponse as i, type Fetch as j, type FetchRequest as k };