import { Headers } from 'node-fetch'; import { HttpError } from './errors'; import { Client } from '../clients/client'; import { AbortSignal } from 'node-fetch/externals'; export declare class HttpClient { private _client?; constructor(client?: Client); /** * Performs a fetch request. * * @param options */ fetch(options: EnvatoHttpRequest): Promise>; /** * Returns the fetch init object to use for the request. * * @param opts */ private _getRequestOptions; /** * Returns an object containing the request headers to use for the given request. * * @param options */ private _getRequestHeaders; /** * Returns an `HttpError` instance for erroneous responses, or `undefined` for successful responses. * * @param status * @param message * @param body */ private _getHttpError; /** * Parses the given response text as JSON and converts timestamps into dates. Returns `undefined` if there is a * parse error. * * @param data */ private _parseResponseText; } export interface EnvatoHttpRequest { /** * The request URL. */ url: string; /** * The request method. * @default GET */ method?: RequestMethod; /** * The headers to send with the request. */ headers: RequestHeaders; /** * Optional form data to send with the request. If provided, the `Content-Type` will automatically be set to * `x-www-form-urlencoded` and the form data will be encoded accordingly. */ form?: RequestForm; /** * Optional fetch options. These will override client defaults if provided. */ options?: RequestOptions; } export interface EnvatoHttpResponse { /** * The options for this request. */ request: EnvatoHttpRequest; /** * The status code for the request. */ status: number; /** * For requests with an erroneous status code, this will contain an `HttpError` instance. */ error?: HttpError; /** * The parsed body from the response. */ body: T; /** * The response headers. */ headers: Headers; /** * The number of milliseconds the request took to execute. */ took: number; } export interface EnvatoHttpOptions { /** * The default timeout for requests in milliseconds, or `0` to disable. * @default 0 */ timeout?: number; /** * Whether or not to support gzip/deflate content encoding for requests. * @default true */ compress?: boolean; } export type RequestMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS'; export type RequestForm = { [name: string]: any; }; export type RequestHeaders = { [name: string]: string; }; export type RequestOptions = EnvatoHttpOptions & { /** * An optional abort signal for cancelling a request before it completes. This is preferred over `timeout`. */ signal?: AbortSignal | null; };