UNPKG

@datadog/datadog-api-client

Version:

OpenAPI client for Datadog APIs

155 lines (154 loc) 4.59 kB
/// <reference types="node" /> import FormData from "form-data"; /** * Interface for aborting fetch requests. */ export interface AbortSignal { aborted: boolean; reason: any; addEventListener: (type: "abort", listener: (this: AbortSignal, event: any) => any, options?: boolean | { capture?: boolean; once?: boolean; passive?: boolean; }) => void; removeEventListener: (type: "abort", listener: (this: AbortSignal, event: any) => any, options?: boolean | { capture?: boolean; }) => void; dispatchEvent: (event: any) => boolean; onabort: null | ((this: AbortSignal, event: any) => void); throwIfAborted(): void; } /** * Represents an HTTP method. */ export declare enum HttpMethod { GET = "GET", HEAD = "HEAD", POST = "POST", PUT = "PUT", DELETE = "DELETE", CONNECT = "CONNECT", OPTIONS = "OPTIONS", TRACE = "TRACE", PATCH = "PATCH" } /** * Represents an HTTP file which will be transferred from or to a server. */ export declare type HttpFile = { data: Buffer; name: string; }; export declare class HttpException extends Error { constructor(msg: string); } /** * Represents the body of an outgoing HTTP request. */ export declare type RequestBody = undefined | string | Buffer | FormData; /** * Represents an HTTP transport configuration. */ export interface HttpConfiguration { compress?: boolean; signal?: AbortSignal; } /** * Represents an HTTP request context */ export declare class RequestContext { private httpMethod; private headers; private body; private url; private httpConfig; /** * Creates the request context using a http method and request resource url * * @param url url of the requested resource * @param httpMethod http method */ constructor(url: string, httpMethod: HttpMethod); getUrl(): string; /** * Replaces the url set in the constructor with this url. * */ setUrl(url: string): void; /** * Sets the body of the http request either as a string or FormData * * Note that setting a body on a HTTP GET, HEAD, DELETE, CONNECT or TRACE * request is discouraged. * https://httpwg.org/http-core/draft-ietf-httpbis-semantics-latest.html#rfc.section.7.3.1 * * @param body the body of the request */ setBody(body: RequestBody): void; getHttpMethod(): HttpMethod; getHeaders(): { [key: string]: string; }; getBody(): RequestBody; /** * Sets query parameters on the request URL * * @param name the name of the query parameter * @param value the value of the query parameter * @param collectionFormat the format of the query parameter See https://spec.openapis.org/oas/v3.0.2#style-values */ setQueryParam(name: string, value: string | string[], collectionFormat: string): void; /** * Sets a cookie with the name and value. NO check for duplicate cookies is performed * */ addCookie(name: string, value: string): void; setHeaderParam(key: string, value: string): void; setHttpConfig(conf: HttpConfiguration): void; getHttpConfig(): HttpConfiguration; } export interface ResponseBody { text(): Promise<string>; binary(): Promise<Buffer>; } /** * Helper class to generate a `ResponseBody` from binary data */ export declare class SelfDecodingBody implements ResponseBody { private dataSource; constructor(dataSource: Promise<Buffer>); binary(): Promise<Buffer>; text(): Promise<string>; } export declare class ResponseContext { httpStatusCode: number; headers: { [key: string]: string; }; body: ResponseBody; constructor(httpStatusCode: number, headers: { [key: string]: string; }, body: ResponseBody); /** * Parse header value in the form `value; param1="value1"` * * E.g. for Content-Type or Content-Disposition * Parameter names are converted to lower case * The first parameter is returned with the key `""` */ getParsedHeader(headerName: string): { [parameter: string]: string; }; getBodyAsFile(): Promise<HttpFile>; } export declare type ZstdCompressorCallback = (body: string) => Buffer; export interface HttpLibrary { enableRetry?: boolean | undefined; maxRetries?: number; backoffBase?: number; backoffMultiplier?: number; debug?: boolean; fetch?: any; zstdCompressorCallback?: ZstdCompressorCallback; send(request: RequestContext): Promise<ResponseContext>; }