import { type Options as PRetryOptions } from 'p-retry'; export declare class HttpError extends Error { response: Response; statusCode: number; isRetryable: boolean; jsonBody?: unknown; constructor(response: Response, message?: string, options?: { isRetryable?: boolean; jsonBody?: unknown; }); } export type RetryOptions = Pick & { /** * Maximum retry after in ms (overrides retries) * If retry-after header is greater than maxRetryAfter, the request will not be retried */ readonly maxRetryAfter?: number; /** * Status codes to retry */ readonly statusCodes?: number[]; /** * Whether do retries on network errors */ readonly networkErrors?: boolean; /** * Should retry will only be called for non HTTPError * The exception being if networkErrors is true it will not be called with network related errors */ readonly shouldRetry?: (context: { error: Error; attemptNumber: number; retriesLeft: number; }) => boolean | Promise; }; export type URLSearchParamsInit = ConstructorParameters[0]; type RequestBaseOptions = RequestInit & { searchParams?: URLSearchParamsInit; cookieJar?: ToughCookieJar; json?: boolean; /** * Throw HttpError for non-2xx responses (default true) */ throwOnHttpError?: boolean; jsonBody?: unknown; timeout?: number; retry?: RetryOptions; }; export type RequestInitToHooks = Omit & { headers: Headers; afterResponse?: AfterResponseHook; }; export type BeforeRequestInitToHooks = Omit & { headers: Headers; afterResponse?: AfterResponseHook; }; export type BeforeRequestHook = (url: URL, opts: BeforeRequestInitToHooks) => Promise<{ url?: URL; opts?: BeforeRequestInitToHooks; }>; export type AfterResponseHook = (response: Response, url: URL, opts: RequestInitToHooks) => Promise; export type RequestOptions = RequestBaseOptions & { /** * Note this only occurs before the first request is made */ beforeRequest?: BeforeRequestHook; /** * You can throw HttpError with isRetryable: true from this hook to retry the request * You may modify the url and opts here as well for the next request */ afterResponse?: AfterResponseHook; }; export type CreateOptions = RequestOptions & { prefixUrl?: string; cookieJar?: ToughCookieJar; json?: boolean; }; type RequestReturn = D extends { json: true; } ? D extends { throwOnHttpError: false; } | { throwOnHttpError?: false; } ? Promise : Promise : Promise; type MergeOptions = O extends RequestOptions ? [RequestOptions] extends [O] ? D : Omit & O : D; type MergeExtend = O extends CreateOptions ? Omit & O : D; export type Request = { (url: string | URL): RequestReturn; (url: string | URL, options?: O): Promise; (url: string | URL, options?: O): Promise; (url: string | URL, options?: O): D extends { throwOnHttpError: false; } | { throwOnHttpError?: false; } ? Promise : Promise; (url: string | URL, options?: O): Promise; (url: string | URL, options?: O): Promise; (url: string | URL, options?: O): D extends { json: true; } ? Promise : Promise; (url: string | URL, options?: O): RequestReturn, T>; extend(extendOpts: T): Request>; }; export type ToughCookieJar = { getCookieString: (url: string) => Promise; setCookie: (cookieOrString: string, currentUrl: string, options?: Record) => Promise | void; }; declare const _default: Request; export default _default; //# sourceMappingURL=index.d.ts.map