import type { ICache } from '../cache/deckCacheFactory'; type IPrimitive = string | boolean | number; type IParams = Record; interface Headers { [headerName: string]: string; } /** * A Builder API for making requests to Gate backend service */ export interface IRequestBuilder { /** * Appends one or more path segments to the URL, separated by slashes. * Each path segment is uri encoded. */ path(...pathSegments: IPrimitive[]): this; headers(headers: Headers): this; /** Adds query parameters to the URL */ query(queryParams: IParams): this; /** Enables or disables caching of the response */ useCache(useCache?: boolean): this; /** issues a GET request */ get(): PromiseLike; /** issues a POST request */ post(data?: P): PromiseLike; /** issues a PUT request */ put(data?: P): PromiseLike; /** issues a PATCH request */ patch(data?: P): PromiseLike; /** issues a DELETE request */ delete(data?: P): PromiseLike; } /** * Internal interface to encapsulate a request * Passed to the IHttpClientImplementation */ interface IRequestBuilderConfig { url: string; timeout?: number; headers?: Headers; /** @deprecated used for AngularJS backwards compat */ data?: any; params?: object; cache?: boolean; } /** * The old API interface */ export interface IDeprecatedRequestBuilder extends IRequestBuilder { useCache(): this; useCache(useCache: boolean): this; useCache(useCache: ICache): this; withParams(queryParams: IParams): this; /** @deprecated do not use this config object */ config: IRequestBuilderConfig; /** @deprecated use SETTINGS.gateUrl */ baseUrl: string; /** @deprecated use path() instead (this is a passthrough to path) */ one(...urls: string[]): this; /** @deprecated use one() instead (this is a passthrough to one) */ all(...urls: string[]): this; /** @deprecated use put(data) or post(data) instead */ data(data: any): this; get(params?: IParams): PromiseLike; /** @deprecated use delete() instead (this is a passthrough to delete) */ remove(params?: IParams): PromiseLike; /** @deprecated use get() instead (this is a passthrough to get) */ getList(params?: IParams): PromiseLike; } /** * An interface to support pluggable http clients * In the future, we should have a TestingHttpClient and a FetchHttpClient (or whatever http client we go with) */ export interface IHttpClientImplementation { get(config: IRequestBuilderConfig): PromiseLike; post(config: IRequestBuilderConfig): PromiseLike; put(config: IRequestBuilderConfig): PromiseLike; patch(config: IRequestBuilderConfig): PromiseLike; delete(config: IRequestBuilderConfig): PromiseLike; } export declare class InvalidAPIResponse extends Error { originalResult: any; data: { message: string; }; constructor(message: string, originalResult: any); } /** The base request builder implementation */ export declare class RequestBuilder implements IRequestBuilder { protected config: IRequestBuilderConfig; protected _httpClient?: IHttpClientImplementation; protected _baseUrl?: string; static defaultHttpClient: IHttpClientImplementation; constructor(config?: IRequestBuilderConfig, _httpClient?: IHttpClientImplementation, _baseUrl?: string); protected builder(newRequest: IRequestBuilderConfig): this; protected get httpClient(): IHttpClientImplementation; protected get baseUrl(): string; path(...paths: IPrimitive[]): this; headers(headers: Headers): this; get(queryParams?: object): PromiseLike; post(postData?: any): PromiseLike; put(putData?: any): PromiseLike; patch(putData?: any): PromiseLike; delete(deleteData?: any): PromiseLike; useCache(cache?: boolean): this; query(queryParams: IParams): this; } /** * This class extends RequestBuilder and re-implements the deprecated API for backwards compat * @deprecated */ export declare class DeprecatedRequestBuilder extends RequestBuilder implements IDeprecatedRequestBuilder { protected builder: (newRequest: IRequestBuilderConfig) => this; config: IRequestBuilderConfig; get baseUrl(): string; getList: any; one: any; all: any; remove: any; data: (data: any) => this; withParams: any; useCache: (cache?: boolean | ICache) => this; } export declare const invalidContentMessage = "API response was neither JSON nor zero-length html or text"; export declare function makeRequestBuilderConfig(pathPrefix?: string): IRequestBuilderConfig; /** @deprecated use REST('/path/to/gate/endpoint') */ export declare const API: IDeprecatedRequestBuilder; /** * A REST client used to access Gate endpoints * @param staticPathPrefix a static string, i.e., '/proxies/foo/endpoint' -- * avoid dynamic strings like `/entity/${id}`, use .path('entity', id) instead */ export declare const REST: (staticPathPrefix?: string) => IRequestBuilder; export {};