/** * @license * Copyright 2018 Palantir Technologies, Inc. * * 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 { IHttpApiBridge, IHttpEndpointOptions } from "../httpApiBridge"; import { IUserAgent } from "../userAgent"; export interface IFetchBody { json(): Promise; text(): Promise; blob(): Promise; } export interface IFetchResponse extends IFetchBody { readonly body: ReadableStream | null; readonly headers: Headers; readonly ok: boolean; readonly status: number; } export type FetchFunction = (url: string | Request, init?: RequestInit) => Promise; export type Supplier = () => T; export interface IFetchBridgeParams { baseUrl: string | Supplier; /** * All network requests will add this userAgent as a header param called 'Fetch-User-Agent'. * This will be logged in receiving service's request logs as params.User-Agent */ userAgent: IUserAgent | ReadonlyArray>; token?: string | Supplier | Supplier>; fetch?: FetchFunction; } export declare class FetchBridge implements IHttpApiBridge { private static ACCEPT_HEADER; private readonly getBaseUrl; private readonly getToken; private readonly fetch; private readonly userAgentSuppliers; constructor(params: IFetchBridgeParams); call(serviceName: string, endpointName: string, method: string, endpointPath: string, data?: any, headers?: { [p: string]: string | number | boolean | undefined | null; }, queryArguments?: { [p: string]: any; }, pathArguments?: any[], requestMediaType?: string, responseMediaType?: string): Promise; callEndpoint(params: IHttpEndpointOptions): Promise; private makeFetchCall; private getUserAgent; private getQoSMetadataFromHeaders; private handleBinaryResponseBody; private appendQueryParameter; private buildPath; private buildQueryString; private handleBody; private normalizeWithNoLeadingSlash; private getMediaType; private isBinaryMedia; }