import { Dispatcher, FormData } from 'undici'; export type Method = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'TRACE' | 'get' | 'post' | 'put' | 'patch' | 'delete' | 'head' | 'options' | 'trace'; export type Headers = Record; export type SearchParams = string | URLSearchParams | Record; export type RequestBody = string | Buffer | Uint8Array | URLSearchParams | FormData; export interface HttpsOptions { certificateAuthority?: string | Buffer | (string | Buffer)[]; key?: string | Buffer; /** Client certificate (PEM). */ certificate?: string | Buffer; /** Alias of `certificate`. */ cert?: string | Buffer; passphrase?: string; rejectUnauthorized?: boolean; } /** * The error shape a retry decision is based on. Deliberately structural (not * the {@link RequestError} class) so that `calculateDelay` functions written * against got 11's `RetryObject` type keep type-checking. */ export interface RetryError extends Error { code: string; options: { method: string; }; response?: { statusCode: number; headers: Record; body?: unknown; }; } export interface RetryObject { attemptCount: number; retryOptions: RequiredRetryOptions; error: RetryError; computedValue: number; /** Parsed `Retry-After` delay in milliseconds, when the response supplied one. */ retryAfter?: number; } export interface RequiredRetryOptions { limit: number; methods: Method[]; statusCodes: number[]; errorCodes: string[]; maxRetryAfter?: number; calculateDelay(retryObject: RetryObject): number | Promise; } export type RetryOptions = Partial | number; /** * A response a `beforeRequest` hook may return to short-circuit the network * call (got 11 contract), e.g. to serve a cached or stubbed response. */ export interface ResponseLike { statusCode: number; statusMessage?: string; headers?: Record; body?: string | Buffer; } export type BeforeRequestHook = (options: NormalizedOptions) => void | ResponseLike | Promise; export type BeforeRetryHook = (options: NormalizedOptions, error?: RequestError, retryCount?: number) => void | Promise; export type BeforeErrorHook = (error: RequestError) => RequestError | Promise; export type AfterResponseHook = (response: Response) => Response | Promise; export interface Hooks { beforeRequest?: BeforeRequestHook[]; beforeRetry?: BeforeRetryHook[]; beforeError?: BeforeErrorHook[]; afterResponse?: AfterResponseHook[]; } /** Runs once per call (not per retry), before any hooks. */ export type HandlerFunction = (options: NormalizedOptions) => void; export interface Options { method?: Method; prefixUrl?: string; headers?: Headers; json?: unknown; body?: RequestBody; /** application/x-www-form-urlencoded body */ form?: Record; searchParams?: SearchParams; parseJson?: (text: string) => unknown; retry?: RetryOptions; timeout?: number | { request?: number; }; throwHttpErrors?: boolean; username?: string; password?: string; context?: Record; https?: HttpsOptions; hooks?: Hooks; handlers?: HandlerFunction[]; } export interface NormalizedOptions { method: string; url: URL; prefixUrl: string; headers: Record; body?: RequestBody; json?: unknown; parseJson: (text: string) => unknown; retry: RequiredRetryOptions; timeout: { request?: number; }; throwHttpErrors: boolean; context: Record; https: HttpsOptions; hooks: Required; } export interface Response { statusCode: number; statusMessage: string; headers: Record; body: T; rawBody: Buffer; url: string; ok: boolean; retryCount: number; request: { options: NormalizedOptions; }; } export interface ResponsePromise> extends Promise { json(): Promise; text(): Promise; buffer(): Promise; cancel(reason?: string): void; readonly isCanceled: boolean; } type VerbFn = (url: string | URL, options?: Options) => ResponsePromise; export interface HttpClient { (url: string | URL, options?: Options): ResponsePromise; get: VerbFn; post: VerbFn; put: VerbFn; patch: VerbFn; delete: VerbFn; head: VerbFn; extend(options: Options): HttpClient; readonly defaults: Options; } export declare class RequestError extends Error { code: string; options: NormalizedOptions; request?: { options: NormalizedOptions; }; response?: Response; /** Always undefined; kept for got 11 shape compatibility. */ timings?: object; cause?: unknown; constructor(message: string, { code, options, response, cause, }: { code?: string; options: NormalizedOptions; response?: Response; cause?: unknown; }); } export declare class HTTPError extends RequestError { response: Response; constructor(response: Response, options?: NormalizedOptions); } export declare class TimeoutError extends RequestError { event: string; constructor(ms: number, options: NormalizedOptions); } export declare class CancelError extends RequestError { constructor(reason: string | undefined, options: NormalizedOptions); get isCanceled(): boolean; } export declare class ParseError extends RequestError { constructor(cause: Error, response: Response); } /** Network error codes that are retried (got 11 defaults plus undici/Node 24 codes). */ export declare const DEFAULT_RETRY_ERROR_CODES: string[]; /** * Parse a `Retry-After` header (delta-seconds or an HTTP-date) into milliseconds. * Returns `undefined` when the error carries no response, the status is not one * that uses `Retry-After`, or the header is absent. */ export declare const parseRetryAfter: (error: RetryError) => number | undefined; /** got 11-compatible default backoff: 2^(n-1) * 1000ms + up to 100ms jitter, honouring Retry-After. */ export declare const defaultCalculateDelay: ({ attemptCount, retryOptions, error, retryAfter, }: RetryObject) => number; /** Merge two option objects with got.extend()-like semantics. */ export declare function mergeOptions(base: Options, override?: Options): Options; /** * Returns the dispatcher for a request: the TLS-configured Agent (or the global * package-owned default Agent) composed with redirect following, as got 11 followed redirects. */ export declare function getDispatcher(https: HttpsOptions): Dispatcher; export declare function createHttpClient(defaults?: Options): HttpClient; /** Default client, analogous to `import got from 'got'`. */ export declare const http: HttpClient; export { FormData };