export type Problem = { type: string; context: string | null; reason: string; details: any | null; }; /** * @typedef {{ type: string; context: string?; reason: string; details: any?; }} Problem */ declare class Failure extends Error { problems: Problem[]; /** * * @param {string} message * @param {Problem[]} problems * @param {*} cause */ constructor(message: string, problems: Problem[], cause: any); dropping(prefix: any): Failure; static dropProblemsContext(problems: any, prefix: any): any; } declare class Base64 { static encode(arrayBuffer: any, dialect: any): string; static decode(str: any, dialect: any): ArrayBuffer; } declare namespace Base64 { var STANDARD: string; var URL_SAFE: string; } declare class Hex { static decode(hex: any): Uint8Array; static encode(bytes: any, upper: any): string; } declare class MediaType { #private; constructor(type: any, subtype: any); get normalized(): string; get type(): any; get subtype(): any; /** * * @param {string|null|undefined} v * @returns */ static parse(v: string | null | undefined): MediaType; } export type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array; export type HttpInterceptor = { intercept: (url: URL, init: RequestInit | undefined, chain: HttpInterceptorChain) => Promise; }; /** * @typedef {Int8Array| Uint8Array| Uint8ClampedArray| Int16Array| Uint16Array| Int32Array| Uint32Array| Float32Array| Float64Array| BigInt64Array| BigUint64Array} TypedArray */ /** * @typedef {object} HttpInterceptor * @property {(url: URL, init: RequestInit|undefined, chain: HttpInterceptorChain) => Promise} intercept */ declare class HttpClientError extends Failure { status: number; /** * @param {string} message * @param {number} status * @param {{ type: string; context: string?; reason: string; details: any?; }[]} problems * @param {Error|undefined} [cause] */ constructor(message: string, status: number, problems: { type: string; context: string | null; reason: string; details: any | null; }[], cause?: Error | undefined); dropping(prefix: any): HttpClientError; /** * * @param {string} type * @param {any} cause * @returns */ static of(type: string, cause: any): HttpClientError; /** * Creates an HttpClientError from a Response. * @param {Response} response * @returns an HttpClientError */ static fromResponse(response: Response): Promise; } declare class HttpClientBuilder { #private; constructor(); withCsrfToken(): this; withRedirectOnUnauthorized(redirectUri: any): this; /** * @param {...HttpInterceptor} interceptors */ withInterceptors(...interceptors: HttpInterceptor[]): this; build(): HttpClient; } declare class HttpInterceptorChain { #private; /** * * @param {HttpInterceptor[]} interceptors * @param {number} current */ constructor(interceptors: HttpInterceptor[], current: number); /** * * @param {URL} url * @param {RequestInit} request * @returns {Promise} the response */ proceed(url: URL, request: RequestInit): Promise; } declare class HttpClient { #private; /** * Creates a builder for an HttpClient. * @returns {HttpClientBuilder} the client builder */ static builder(): HttpClientBuilder; /** * Creates an HttpClient. * @param {HttpInterceptor[]|undefined} interceptors - a list of interceptors to be registered for every request performed by the created client. */ constructor(interceptors: HttpInterceptor[] | undefined); /** * Performs an HTTP exchange. * @async * @param {string} uri - the (possibly relative) request url * @param {RequestInit|undefined} options - fetch options * @param {HttpInterceptor[]|undefined} interceptors - the HttpInterceptors to be registered for this exchange. * @returns {Promise} the response */ exchange(uri: string, options: RequestInit | undefined, interceptors: HttpInterceptor[] | undefined): Promise; /** * Creates a request builder. * @param {string} method - the HTTP method to be used * @param {string} uri - the (possibly relative) request url * @returns {HttpRequestBuilder} the request builder */ request(method: string, uri: string): HttpRequestBuilder; /** * Creates a request builder. * @param {string} uri - the (possibly relative) request url * @returns {HttpRequestBuilder} the request builder */ get(uri: string): HttpRequestBuilder; /** * Creates a request builder. * @param {string} uri - the (possibly relative) request url * @returns {HttpRequestBuilder} the request builder */ head(uri: string): HttpRequestBuilder; /** * Creates a request builder. * @param {string} uri - the (possibly relative) request url * @returns {HttpRequestBuilder} the request builder */ post(uri: string): HttpRequestBuilder; /** * Creates a request builder. * @param {string} uri - the (possibly relative) request url * @returns {HttpRequestBuilder} the request builder */ put(uri: string): HttpRequestBuilder; /** * Creates a request builder. * @param {string} uri - the (possibly relative) request url * @returns {HttpRequestBuilder} the request builder */ patch(uri: string): HttpRequestBuilder; /** * Creates a request builder. * @param {string} uri - the (possibly relative) request url * @returns {HttpRequestBuilder} the request builder */ delete(uri: string): HttpRequestBuilder; } declare class HttpRequestBuilder { #private; /** * Creates an HttpRequestBuilder. * @param {HttpClient} client * @param {string} method - the HTTP method to be used * @param {string} uri - the (possibly relative) request url * @returns {HttpRequestBuilder} the builder */ static create(client: HttpClient, method: string, uri: string): HttpRequestBuilder; /** * Creates an HttpRequestBuilder. * @param {HttpClient} client * @param {string} method - the HTTP method to be used * @param {string} uri - the (possibly relative) request url * @param {URLSearchParams} params * @param {Headers} headers * @param {any} body * @param {Omit} options * @param {HttpInterceptor[]} interceptors */ constructor(client: HttpClient, method: string, uri: string, params: URLSearchParams, headers: Headers, body: any, options: Omit, interceptors: HttpInterceptor[]); /** * Add all passed headers to the request, overriding existing ones if that key already exists. Null and undefined values cause the key to be removed. * @param {HeadersInit} hs * @returns {HttpRequestBuilder} this builder */ headers(hs: HeadersInit): HttpRequestBuilder; /** * Adds an header to the request, overriding it if it already exists. Null and undefined values cause the key to be removed * @param {string} k * @param {string} v * @returns {HttpRequestBuilder} this builder */ header(k: string, v: string): HttpRequestBuilder; /** * Add all query parameters to the request, overriding existing ones if that key already exists. Null and undefined values cause the key to be removed * @param {URLSearchParams|Record|string[][]|string} ps * @returns {HttpRequestBuilder} this builder */ params(ps: URLSearchParams | Record | string[][] | string): HttpRequestBuilder; /** * Adds a query parameter to the request, overriding it if it already exists. Empty vs, or a single null or undefined value cause the key to be removed. * @param {string} k * @param {...string} vs * @returns {HttpRequestBuilder} this builder */ param(k: string, ...vs: string[]): HttpRequestBuilder; /** * Sets the request body. * `Content-Type: multipart/form-data` header is automatically added by fetch when data is a FormData instance if not explicitly set. * `Content-Type: application/x-www-form-urlencoded` header is automatically added by fetch when data is an URLSearchParams instance if not explicitly set. * `Content-Type: text/plain` header is automatically added by fetch when data is a string instance if not explicitly set. * @param {string|ArrayBuffer|Blob|DataView|File|FormData|TypedArray|URLSearchParams|ReadableStream} data * @returns {HttpRequestBuilder} this builder */ body(data: string | ArrayBuffer | Blob | DataView | File | FormData | TypedArray | URLSearchParams | ReadableStream): HttpRequestBuilder; /** * Sets the request body that will be serialized as json. Calling this method adds the `Content-Type application/json` header for the request. * @param {any} body - the body to be serialized as json * @returns {HttpRequestBuilder} this builder */ json(body: any): HttpRequestBuilder; /** * Sets the request body as a FormData configured using the callback. * `Content-Type: multipart/form-data` header is automatically added by fetch if not explicitly set. * @param {function(HttpMultipartRequestCustomizer):void} callback */ multipart(callback: Function): this; /** * Sets a fetch options for the request. * @param {Omit} kvs * @returns {HttpRequestBuilder} this builder */ options(kvs: Omit): HttpRequestBuilder; /** * Sets a fetch option for the request. * @param {keyof Omit} k * @param {*} v * @returns {HttpRequestBuilder} this builder */ option(k: keyof Omit, v: any): HttpRequestBuilder; /** * Adds interceptors to the request. * @param {[HttpInterceptor]} is - the interceptor to be regisered * @returns {HttpRequestBuilder} this builder */ interceptors(is: [HttpInterceptor]): HttpRequestBuilder; /** * Adds an interceptor to the request. * @param {HttpInterceptor} i - the interceptor to be regisered * @returns {HttpRequestBuilder} this builder */ interceptor(i: HttpInterceptor): HttpRequestBuilder; /** * Performs an HTTP exchange using the configured client, request and interceptors. * @returns {Promise} the response */ exchange(): Promise; /** * Performs an HTTP exchange using the configured client request, and interceptos throwing a failure when response status is not in the 200-299 range. * @returns {Promise} the response */ fetch(): Promise; /** * Performs an HTTP exchange using the configured client request, and interceptos throwing a failure when response status is not in the 200-299 range. * @returns {Promise} the response body, as text */ fetchText(): Promise; /** * Performs an HTTP exchange using the configured client request, and interceptos throwing a failure when response status is not in the 200-299 range. * @returns {Promise} the response body, deserialized as JSON */ fetchJson(): Promise; /** * Performs an HTTP exchange using the configured client request, and interceptos throwing a failure when response status is not in the 200-299 range. * @returns {Promise} the response body, as a Blob */ fetchBlob(): Promise; /** * Performs an HTTP exchange using the configured client request, and interceptos throwing a failure when response status is not in the 200-299 range. * @returns {Promise} the response body, as an ArrayBuffer */ fetchArrayBuffer(): Promise; } export { Base64, Failure, Hex, HttpClient, HttpClientError, MediaType }; export as namespace httpc;