///
import type * as stream from 'stream';
/**
* Represents a controller object that allows to abort one or more requests as and when desired.
*/
declare interface AbortController_2 {
/**
* Aborts a request before it has completed.
*/
abort(): void;
/**
* Returns an AbortSignal object instance, which can be used to communicate with a request.
*/
signal: AbortSignal_2;
}
export { AbortController_2 as AbortController }
declare type AbortSignal_2 = HttpClientAbortSignal | globalThis.AbortSignal;
export { AbortSignal_2 as AbortSignal }
export declare interface BaseError extends Error {
readonly name: string;
readonly cause?: any;
}
/**
* Represents an environment agnostic (browser vs node) abstraction layer for binary data.
*/
export declare interface Binary {
/**
* Returns the binary data in a form that conforms to the specified type.
*
* @param type The type of the data.
* Can be `text`, `json`, `array-buffer`, `blob`, `readable-stream`, `buffer` or `stream`.
* @throws {DataTypeError} Data does not conform to the specified type.
* @throws {UnsupportedOperationError} Type is not supported by the platform.
*/
get(type: T): DataTypes[T];
}
/**
* Represents an binary field.
*/
export declare interface BinaryFormDataRequestField {
/**
* A binary field type discriminator.
*/
type: 'binary';
/**
* The name of the field.
*/
name: string;
/**
* The content type of the data contained in `value`.
* The default content type for the binary is 'application/octet-stream'.
*/
contentType?: string;
/**
* The filename reported to the server.
* The default filename for the binary is 'binary'.
*/
filename?: string;
/**
* The field's value.
*/
value: ArrayBuffer | Blob | ReadableStream | Buffer | stream.Readable | Binary | File;
}
export declare interface BinaryFormDataResponseField {
type: 'binary';
name: string;
contentType: string;
filename: string;
value: Binary;
}
export declare interface DataTypeError extends BaseError {
/**
* The error name.
*/
readonly name: 'DataTypeError';
/**
* The error root cause.
*/
readonly cause?: any;
}
/**
* Mapping between the data type names and types.
*/
export declare type DataTypes = {
/**
* A text type.
*/
text: Promise;
/**
* A JSON type.
*/
json: Promise;
/**
* An ArrayBuffer type.
*/
'array-buffer': Promise;
/**
* A Blob type. Browser only.
*/
blob: Promise;
/**
* A ReadableStream type. Browser only.
*/
'readable-stream': ReadableStream;
/**
* A Buffer type. Node only.
*/
buffer: Promise;
/**
* A Stream type. Node only.
*/
stream: stream.Readable;
};
/**
* Represents a multipart/form-data body.
*/
export declare type FormDataRequestBody = Array;
/**
* Represents a multipart/form-data field.
*/
export declare type FormDataRequestField = TextFormDataRequestField | JsonFormDataRequestField | BinaryFormDataRequestField;
export declare type FormDataResponseBody = Array;
export declare type FormDataResponseField = TextFormDataResponseField | BinaryFormDataResponseField;
/**
* Represents http headers.
*/
declare interface Headers_2 {
[key: string]: string;
}
export { Headers_2 as Headers }
/**
* The http client that serves as an environment agnostic (browser vs node) abstraction for making http calls.
* It handles the authentication of the requests made to the Platform Services and the Serverless Functions.
*
* Currently, only the requests to the Platform Services and the Serverless Functions are supported.
*/
export declare interface HttpClient {
/**
* Sends an http request as configured by the `options`.
* Returns a promise that resolves with a response object for successful requests or rejects with an appropriate error
* when one of the following situations happen:
* - `DataTypeError` - request body does not conform to the specified request body type,
* - `HttpClientRequestError` - request cannot be sent (e.g. due to network error or invalid request),
* - `HttpClientResponseError` - response status is considered invalid by the status validator,
* - `HttpClientAbortError` - request was aborted.
*
* @param options Options used to configure the request.
* @return Promise A promise that resolves with the response object or rejects with an error.
*/
send(options: HttpClientRequestOptions): Promise;
}
export declare const httpClient: PlatformHttpClient;
/**
* Represents a situation when the request was aborted.
*/
export declare interface HttpClientAbortError extends BaseError {
/**
* The error name.
*/
readonly name: 'AbortError';
/**
* The error root cause.
*/
readonly cause?: any;
}
/**
* Represents a signal object that allows to communicate with the request and abort it using the `AbortController`.
* @deprecated Will be removed from HttpClient. We encourage using native interface for AbortSignal.
*/
declare interface HttpClientAbortSignal extends EventTarget {
readonly reason: any;
throwIfAborted(): void;
/**
* A flag indicating whether the requests the signal is communicating with are aborted.
*/
readonly aborted: boolean;
/**
* Invoked when the requests the signal is communicating with are aborted.
*/
onabort: ((this: AbortSignal_2, event: Event) => void) | null;
}
declare interface HttpClientConfiguration {
baseUrl?: string;
defaultHeaders?: Headers_2;
}
/**
* Represents a situation when a network error occurred.
*/
export declare interface HttpClientNetworkError extends BaseError {
/**
* The error name.
*/
readonly name: 'NetworkError';
/**
* The error root cause.
*/
readonly cause?: any;
}
/**
* Represents a situation when the request is invalid and cannot be sent.
*/
export declare interface HttpClientRequestError extends BaseError {
/**
* The error name.
*/
readonly name: 'RequestError';
/**
* The error root cause.
*/
readonly cause?: any;
}
/**
* Represents the options used to configure the request.
*/
export declare interface HttpClientRequestOptions {
/**
* The URL of the resource to fetch.
*/
url: string;
/**
* The request method, e.g. `GET`, `POST`.
*/
method?: string;
/**
* The request headers.
*/
headers?: Headers_2;
/**
* A request body that will be send along with the request.
* The structure of the request body needs to conform to the specified request body type.
*/
body?: RequestBodyTypes[T];
/**
* The type of the request body. Can be `text`, `json`, `binary` or `form-data`.
* The default request body type is `json`.
*/
requestBodyType?: T;
/**
* An AbortSignal instance that can be used to cancel the request.
*/
abortSignal?: AbortSignal_2;
/**
* A custom status validator function.
* If the status validator function returns `true` the returned promise resolves with the `HttpClientResponse`
* Otherwise the promise rejects with the `StatusError`.
* The default status validator function considers the `2xx` status codes as valid.
*/
statusValidator?: StatusValidator;
}
/**
* Represents the response to a request.
*/
export declare interface HttpClientResponse {
/**
* The URL of the response. May differ from `requestUrl` if the request was
* redirected.
*/
readonly url: string;
/**
* The URL that was originally requested, before any redirects were followed.
*/
readonly requestUrl: string;
/**
* The status code of the response.
*/
readonly status: number;
/**
* The status message corresponding to the status code.
*/
readonly statusText: string;
/**
* The response headers.
*/
readonly headers: Headers_2;
/**
* Returns the response body in a form that conforms to the specified response body type.
*
* @param responseBodyType The type of the response body.
* Can be `text`, `json`, `binary`, `form-data`, `array-buffer`, `blob`, `readable-stream`, `buffer` or `stream`.
* The default response body type is `json`.
* @throws {DataTypeError} Response body does not conform to the specified response body type.
* @throws {UnsupportedOperationError} Response body type is not supported by the platform.
*/
body(responseBodyType?: T): ResponseBodyTypes[T];
}
/**
* Represents a situation when the response status is considered invalid by the status validator.
*/
export declare interface HttpClientResponseError extends BaseError {
/**
* The error name.
*/
readonly name: 'ResponseError';
/**
* The error root cause.
*/
readonly cause?: any;
/**
* The response.
*/
readonly response: HttpClientResponse;
}
export declare function isHttpClientAbortError(e: any): e is HttpClientAbortError;
export declare function isHttpClientNetworkError(e: any): e is HttpClientNetworkError;
export declare function isHttpClientRequestError(e: any): e is HttpClientRequestError;
export declare function isHttpClientResponseError(e: any): e is HttpClientResponseError;
/**
* Represents a JSON field.
*/
export declare interface JsonFormDataRequestField {
/**
* A JSON field type discriminator.
*/
type: 'json';
/**
* The name of the field.
*/
name: string;
/**
* The content type of the data contained in `value`.
* The default content type for the JSON is 'application/json'.
*/
contentType?: string;
/**
* The filename reported to the server.
* The default filename for the JSON is 'json'.
*/
filename?: string;
/**
* The field's value.
*/
value: any;
}
/**
* DO NOT USE - internal use only.
*/
export declare class _OAuthHttpClient implements types.HttpClient {
private readonly config;
private oauthToken?;
constructor(config: _OAuthHttpClientConfig);
send(options: types.HttpClientRequestOptions): Promise;
private requestToken;
}
/**
* DO NOT USE - internal use only.
*/
export declare interface _OAuthHttpClientConfig {
clientId: string;
secret: string;
scopes: string[];
environmentUrl: string;
authUrl: string;
}
export declare const PlatformAbortController: {
new (): types.AbortController;
};
export declare type PlatformAbortController = InstanceType;
export declare const PlatformAbortSignal: {
new (): types.AbortSignal;
};
export declare type PlatformAbortSignal = InstanceType;
export declare abstract class PlatformBaseError extends Error implements types.BaseError {
readonly cause?: any;
protected constructor(message: string, cause?: any);
}
export declare class PlatformBinary implements types.Binary {
readonly data: Blob | ArrayBuffer | ReadableStream;
static fromText(text: string): PlatformBinary;
static fromJson(json: any): PlatformBinary;
static from(data: Blob | ArrayBuffer | ReadableStream | Buffer | stream.Readable): PlatformBinary;
private constructor();
get(type: T): types.DataTypes[T];
}
export declare class PlatformDataTypeError extends PlatformBaseError implements types.DataTypeError {
readonly name = "DataTypeError";
constructor(message: string, cause?: any);
}
export declare class PlatformHttpClient implements types.HttpClient {
private _baseUrl;
private _defaultHeaders;
constructor(options?: HttpClientConfiguration);
/**
* Sets HTTP Client Instance baseUrl param to the incoming value `baseUrl`.
* @param baseUrl Base URL used in the request path.
*/
_setBaseURL(baseUrl: string): void;
/**
* Sets HTTP Client Instance defaultHeaders param to the incoming value `defaultHeaders`.
* @param defaultHeaders HTTP Headers to be used in outgoing requests.
*/
_setDefaultHeaders(defaultHeaders: Headers_2): void;
send(options: types.HttpClientRequestOptions): Promise;
}
export declare class PlatformHttpClientAbortError extends Error implements types.HttpClientAbortError {
readonly cause: any;
readonly name = "AbortError";
constructor(cause: any);
}
export declare class PlatformHttpClientRequestError extends PlatformBaseError implements types.HttpClientRequestError {
readonly cause: any;
readonly name = "RequestError";
constructor(cause: any);
}
export declare class PlatformHttpClientResponse implements types.HttpClientResponse {
private response;
readonly requestUrl: string;
constructor(response: Response, data?: {
requestUrl: string;
});
get url(): string;
get status(): number;
get statusText(): string;
get headers(): types.Headers;
body(responseBodyType?: T): types.ResponseBodyTypes[T];
}
export declare class PlatformHttpClientResponseError extends PlatformBaseError implements types.HttpClientResponseError {
readonly name = "ResponseError";
readonly response: PlatformHttpClientResponse;
readonly requestMethod?: string;
constructor(response: Response, data?: {
requestUrl?: string;
requestMethod?: string;
});
}
export declare class PlatformUnsupportedOperationError extends PlatformBaseError implements types.UnsupportedOperationError {
readonly name = "UnsupportedOperationError";
constructor(message: string, cause?: any);
}
/**
* Mapping between the request body type names and types.
*/
export declare type RequestBodyTypes = {
/**
* A text request body type.
*/
text: string;
/**
* A JSON request body type.
*/
json: any;
/**
* A multipart/form-data request body type.
*/
'form-data': FormDataRequestBody;
/**
* A binary request body type.
*/
binary: Binary | ArrayBuffer | Blob | ReadableStream | Buffer | stream.Readable;
};
/**
* Mapping between the response body type names and types.
*/
export declare type ResponseBodyTypes = {
/**
* A text response body type.
*/
text: Promise;
/**
* A JSON response body type.
*/
json: Promise;
/**
* A binary body type.
*/
binary: Promise;
/**
* A multipart/form-data body type.
*/
'form-data': Promise;
/**
* An ArrayBuffer response body type.
*/
'array-buffer': Promise;
/**
* A Blob response body type. Browser only.
*/
blob: Promise;
/**
* A ReadableStream response body type. Browser only.
*/
'readable-stream': ReadableStream;
/**
* A Buffer response body type. Node only.
*/
buffer: Promise;
/**
* A Stream response body type. Node only.
*/
stream: stream.Readable;
};
/**
* Represents a function used to validate the response status code.
* If `true` is returned, the status is considered valid (request succeeded), otherwise it's considered invalid (request failed).
*/
export declare interface StatusValidator {
(status: number): boolean;
}
/**
* Represents a plain text field. No filename and content type is set.
*/
export declare interface TextFormDataRequestField {
/**
* A plain text field type discriminator.
*/
type: 'text';
/**
* The name of the field.
*/
name: string;
/**
* The field's value.
*/
value: string;
}
export declare interface TextFormDataResponseField {
type: 'text';
name: string;
value: string;
}
declare namespace types {
export {
BaseError,
isHttpClientRequestError,
HttpClientRequestError,
UnsupportedOperationError,
StatusValidator,
ResponseBodyTypes,
HttpClient,
HttpClientResponse,
DataTypes,
HttpClientRequestOptions,
isHttpClientAbortError,
HttpClientAbortError,
AbortController_2 as AbortController,
TextFormDataResponseField,
BinaryFormDataResponseField,
FormDataResponseField,
FormDataResponseBody,
AbortSignal_2 as AbortSignal,
isHttpClientResponseError,
HttpClientResponseError,
TextFormDataRequestField,
JsonFormDataRequestField,
BinaryFormDataRequestField,
FormDataRequestField,
FormDataRequestBody,
Binary,
Headers_2 as Headers,
RequestBodyTypes,
DataTypeError,
isHttpClientNetworkError,
HttpClientNetworkError
}
}
export declare interface UnsupportedOperationError extends BaseError {
/**
* The error name.
*/
readonly name: 'UnsupportedOperationError';
/**
* The error root cause.
*/
readonly cause?: any;
}
export { }