/** * Copyright (c) 2020-present, Goldman Sachs * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { StatusCodes } from 'http-status-codes'; export declare const HttpStatus: typeof StatusCodes; export declare const CHARSET = "charset=utf-8"; export declare enum ContentType { APPLICATION_JSON = "application/json", APPLICATION_XML = "application/xml", APPLICATION_ZLIB = "application/zlib", TEXT_PLAIN = "text/plain", ALL = "*/*" } export declare enum HttpMethod { GET = "GET", PUT = "PUT", POST = "POST", DELETE = "DELETE" } /** * NOTE: the latter headers value will override the those of the first */ export declare const mergeRequestHeaders: (headersOne: RequestHeaders | undefined, headersTwo: RequestHeaders | undefined) => RequestHeaders; declare type ParamterValue = string | number | boolean | undefined; /** * NOTE: we could not use the Headers class object since `fetch` * does not process it but treat it simply as an object, so we will in fact * lose header if we send the network request. As such we create this * type for request header purely for annotation purpose * See https://github.github.io/fetch/ */ export declare type RequestHeaders = Record; export declare type Parameters = Record; export declare type Payload = Record | string; export declare const unauthenticated: (response: Response) => boolean; export declare const authenticate: (authenticationUrl: string) => Promise; export declare class NetworkClientError extends Error { response: Response & { data?: Record; }; payload?: Payload; constructor(response: Response, payload: Payload | undefined); } export declare const makeUrl: (baseUrl: string | undefined, relativeUrl: string, parameters: Parameters) => string; export interface ResponseProcessConfig { skipProcessing?: boolean; preprocess?: (response: Response) => void; authenticationUrl?: string; } export interface RequestProcessConfig { enableCompression?: boolean; } export declare const createRequestHeaders: (method: HttpMethod, headers?: RequestHeaders | undefined) => RequestHeaders; interface NetworkClientConfig { options?: Record; baseUrl?: string; } /** * Simple wrapper around native `fetch` API. For `options`, see documentation for "init" * See https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API */ export declare class NetworkClient { private options; baseUrl?: string; constructor(config?: NetworkClientConfig); get(url: string, options?: RequestInit, headers?: RequestHeaders, parameters?: Parameters, requestProcessConfig?: RequestProcessConfig, responseProcessConfig?: ResponseProcessConfig): Promise; put(url: string, data?: unknown, options?: RequestInit, headers?: RequestHeaders, parameters?: Parameters, requestProcessConfig?: RequestProcessConfig, responseProcessConfig?: ResponseProcessConfig): Promise; post(url: string, data?: unknown, options?: RequestInit, headers?: RequestHeaders, parameters?: Parameters, requestProcessConfig?: RequestProcessConfig, responseProcessConfig?: ResponseProcessConfig): Promise; delete(url: string, data?: unknown, options?: RequestInit, headers?: RequestHeaders, parameters?: Parameters, requestProcessConfig?: RequestProcessConfig, responseProcessConfig?: ResponseProcessConfig): Promise; request(method: HttpMethod, url: string, data: unknown, options: RequestInit, headers?: RequestHeaders, parameters?: Parameters, requestProcessConfig?: RequestProcessConfig, responseProcessConfig?: ResponseProcessConfig): Promise; } /** * Create and download a file using data URI * See http://stackoverflow.com/questions/283956 */ export declare const downloadFile: (fileName: string, content: string, contentType: ContentType) => void; export declare const createUrlStringFromData: (data: string, contentType: ContentType, base64: boolean) => string; export declare const getQueryParameters: (url: string, isFullUrl?: boolean) => T; export {}; //# sourceMappingURL=NetworkUtils.d.ts.map