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; /** * @deprecated use query instead. */ 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 { FetchError as F, createFetchError as a, createFetch as c }; export type { $Fetch as $, CreateFetchOptions as C, GlobalOptions as G, IFetchError as I, MappedResponseType as M, ResolvedFetchOptions as R, SearchParameters as S, FetchOptions as b, FetchContext as d, FetchHook as e, FetchHooks as f, ResponseMap as g, ResponseType as h, FetchResponse as i, Fetch as j, FetchRequest as k };