/// import http = require('http'); import https = require('https'); import Keyv = require('keyv'); import CacheableRequest = require('cacheable-request'); import PCancelable = require('p-cancelable'); import ResponseLike = require('responselike'); import { URL } from 'url'; import { Readable as ReadableStream } from 'stream'; import { Timings, IncomingMessageWithTimings } from '@szmarczak/http-timer'; import CacheableLookup from 'cacheable-lookup'; import { Except, Merge } from 'type-fest'; import { GotReturn } from './create'; import { GotError, HTTPError, MaxRedirectsError, ParseError, TimeoutError, RequestError } from './errors'; import { Hooks } from './known-hook-events'; import { URLOptions } from './utils/options-to-url'; export declare type GeneralError = Error | GotError | HTTPError | MaxRedirectsError | ParseError; export declare type Method = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'HEAD' | 'DELETE' | 'OPTIONS' | 'TRACE' | 'get' | 'post' | 'put' | 'patch' | 'head' | 'delete' | 'options' | 'trace'; export declare type ResponseType = 'json' | 'buffer' | 'text'; export interface Response extends IncomingMessageWithTimings { body: BodyType; statusCode: number; /** The remote IP address. Note: Not available when the response is cached. This is hopefully a temporary limitation, see [lukechilds/cacheable-request#86](https://github.com/lukechilds/cacheable-request/issues/86). */ ip: string; fromCache?: boolean; isFromCache?: boolean; req?: http.ClientRequest; requestUrl: string; retryCount: number; timings: Timings; redirectUrls: string[]; request: { options: NormalizedOptions; }; url: string; } export interface ResponseObject extends Partial { socket: { remoteAddress: string; }; } export interface RetryObject { attemptCount: number; retryOptions: Required; error: TimeoutError | RequestError; computedValue: number; } export declare type RetryFunction = (retryObject: RetryObject) => number; export declare type HandlerFunction = (options: NormalizedOptions, next: (options: NormalizedOptions) => T) => T | Promise; export interface DefaultRetryOptions { limit: number; methods: Method[]; statusCodes: number[]; errorCodes: string[]; calculateDelay: RetryFunction; maxRetryAfter?: number; } export interface RetryOptions extends Partial { retries?: number; } export declare type RequestFunction = typeof http.request; export interface AgentByProtocol { http?: http.Agent; https?: https.Agent; } export interface Delays { lookup?: number; connect?: number; secureConnect?: number; socket?: number; response?: number; send?: number; request?: number; } export declare type Headers = Record; interface ToughCookieJar { getCookieString(currentUrl: string, options: { [key: string]: unknown; }, cb: (err: Error | null, cookies: string) => void): void; getCookieString(url: string, callback: (error: Error | null, cookieHeader: string) => void): void; setCookie(cookieOrString: unknown, currentUrl: string, options: { [key: string]: unknown; }, cb: (err: Error | null, cookie: unknown) => void): void; setCookie(rawCookie: string, url: string, callback: (error: Error | null, result: unknown) => void): void; } interface PromiseCookieJar { getCookieString(url: string): Promise; setCookie(rawCookie: string, url: string): Promise; } export declare const requestSymbol: unique symbol; export declare type DefaultOptions = Merge>, { hooks: Required; retry: DefaultRetryOptions; timeout: Delays; context: { [key: string]: any; }; _pagination?: PaginationOptions['_pagination']; }>; export interface PaginationOptions { _pagination?: { transform?: (response: Response) => Promise | T[]; filter?: (item: T, allItems: T[]) => boolean; paginate?: (response: Response) => Options | false; shouldContinue?: (item: T, allItems: T[]) => boolean; countLimit?: number; }; } export interface GotOptions extends PaginationOptions { [requestSymbol]?: RequestFunction; url?: URL | string; body?: string | Buffer | ReadableStream; hooks?: Hooks; decompress?: boolean; isStream?: boolean; encoding?: BufferEncoding; method?: Method; retry?: RetryOptions | number; throwHttpErrors?: boolean; cookieJar?: ToughCookieJar | PromiseCookieJar; ignoreInvalidCookies?: boolean; request?: RequestFunction; agent?: http.Agent | https.Agent | boolean | AgentByProtocol; cache?: string | CacheableRequest.StorageAdapter | false; headers?: Headers; responseType?: ResponseType; resolveBodyOnly?: boolean; followRedirect?: boolean; prefixUrl?: URL | string; timeout?: number | Delays; dnsCache?: CacheableLookup | Map | Keyv | false; useElectronNet?: boolean; form?: { [key: string]: any; }; json?: { [key: string]: any; }; context?: { [key: string]: any; }; maxRedirects?: number; lookup?: CacheableLookup['lookup']; allowGetBody?: boolean; methodRewriting?: boolean; } export declare type Options = Merge>; export interface NormalizedOptions extends Options { headers: Headers; hooks: Required; timeout: Delays; dnsCache: CacheableLookup | false; lookup?: CacheableLookup['lookup']; retry: Required; prefixUrl: string; method: Method; url: URL; cacheableRequest?: (options: string | URL | http.RequestOptions, callback?: (response: http.ServerResponse | ResponseLike) => void) => CacheableRequest.Emitter; cookieJar?: PromiseCookieJar; maxRedirects: number; pagination?: Required['_pagination']>; [requestSymbol]: RequestFunction; decompress: boolean; isStream: boolean; throwHttpErrors: boolean; ignoreInvalidCookies: boolean; cache: CacheableRequest.StorageAdapter | false; responseType: ResponseType; resolveBodyOnly: boolean; followRedirect: boolean; useElectronNet: boolean; methodRewriting: boolean; allowGetBody: boolean; context: { [key: string]: any; }; path?: string; setHeader(name: string, value: string | string[], clobber?: boolean): string | false; setHeader(headers: Headers): void; hasHeader(name: string): string | false; getHeader(name: string): string | string[] | undefined; removeHeader(name: string): boolean; } export interface ExtendOptions extends Options { handlers?: HandlerFunction[]; mutableDefaults?: boolean; } export interface Defaults { options: DefaultOptions; handlers: HandlerFunction[]; mutableDefaults: boolean; _rawHandlers?: HandlerFunction[]; } export declare type URLOrOptions = Options | string; export interface Progress { percent: number; transferred: number; total?: number; } export interface GotEvents { on(name: 'request', listener: (request: http.ClientRequest) => void): T; on(name: 'response', listener: (response: Response) => void): T; on(name: 'redirect', listener: (response: Response, nextOptions: NormalizedOptions) => void): T; on(name: 'uploadProgress' | 'downloadProgress', listener: (progress: Progress) => void): T; } export interface CancelableRequest extends PCancelable, GotEvents> { json(): CancelableRequest; buffer(): CancelableRequest; text(): CancelableRequest; } export {};