/*! * Copyright Adaptavist 2022 (c) All rights reserved */ export interface IsomorphicBlob { text(): Promise; arrayBuffer(): Promise; } export interface IsomorphicFormData { entries(): Iterator; } export declare class Body { private body; private implementation; constructor(body?: string | ArrayBuffer | IsomorphicBlob | IsomorphicFormData | null); arrayBuffer(): Promise; text(): Promise; json(): Promise; setBufferImplementation(bufferImplementation: BufferImplementation): void; } export declare class Response extends Body { url: string; status: number; statusText: string; headers: Headers; ok: boolean; constructor(url: string, status: number, statusText: string, headers: Headers, body?: string | ArrayBuffer | null); } export declare class Request extends Body { method: string; url: string; headers: Headers; constructor(method: string, url: string, headers: Headers, body?: string | ArrayBuffer | IsomorphicBlob | IsomorphicFormData | null); } export declare class Headers { private headers; constructor(init?: ApiHeaders); forEach(callback: (value: string, name: string) => void): void; append(name: string, value: string): void; delete(name: string): void; get(name: string): string | null; getAll(name: string): string[]; has(name: string): boolean; raw(): { [k: string]: string[]; }; set(name: string, value: string): void; entries(): Iterator<[string, string]>; keys(): Iterator; values(): Iterator; private sortHeaders; private convertHeaders; [Symbol.iterator](): Iterator<[string, string]>; } export declare class FormData { private _data; private implementation; /** * Append a field * * @param {string} name field name * @param {string|Blob|File} value string / blob / file * @param {string=} filename filename to use with blob * @return {undefined} */ append(name: any, value: any, filename: any): void; /** * Delete all fields values given name * * @param {string} name Field name * @return {undefined} */ delete(name: any): void; /** * Iterate over all fields as [name, value] * * @return {Iterator} */ entries(): Generator; /** * Iterate over all fields * * @param {Function} callback Executed for each item with parameters (value, name, thisArg) * @param {Object=} thisArg `this` context for callback function * @return {undefined} */ forEach(callback: any, thisArg: any): void; /** * Return first field value given name * or null if non existen * * @param {string} name Field name * @return {string|File|null} value Fields value */ get(name: any): any; /** * Return all fields values given name * * @param {string} name Fields name * @return {Array} [{String|File}] */ getAll(name: any): never[]; /** * Check for field name existence * * @param {string} name Field name * @return {boolean} */ has(name: any): boolean; /** * Iterate over all fields name * * @return {Iterator} */ keys(): Generator; /** * Overwrite all values given name * * @param {string} name Filed name * @param {string} value Field value * @param {string=} filename Filename (optional) * @return {undefined} */ set(name: any, value: any, filename: any): void; /** * Iterate over all fields * * @return {Iterator} */ values(): Generator; getBlob(): Blob; /** * The class itself is iterable * alias for formdata.entries() * * @return {Iterator} */ [Symbol.iterator](): Generator; /** * Create the default string description. * * @return {string} [object FormData] */ toString(): string; private ensureArgs; private normalizeArgs; private normalizeValue; private each; setBufferImplementation(bufferImplementation: BufferImplementation): void; } export declare class Blob { size: number; type: string; private _buffer; private implementation; constructor(implementation: any, chunks: any, opts: any); arrayBuffer(): Promise; arrayBufferSync(): ArrayBuffer; text(): Promise; textSync(): string; slice(start: number, end: number, type: string): Blob; private isArrayBufferView; private bufferClone; private isDataView; private concatTypedArrays; } export declare abstract class BaseErrorStrategyBuilder> { protected options?: ESH | undefined; constructor(options?: ESH | undefined); protected abstract buildNewBuilder(options?: ESH): this; /** * Error handler for HTTP code 400 (Bad Request). Return the value you wish to continue with, or return 'retry()' for retrying the request, or return 'continuePropagation()' for allowing the error to propagate. */ http400Error(handler: (error: BadRequestError, attempt: number) => AnythingButUndefined): this; /** * Error handler for HTTP code 401 (Unauthorized). Return the value you wish to continue with, or return 'retry()' for retrying the request, or return 'continuePropagation()' for allowing the error to propagate. */ http401Error(handler: (error: UnauthorizedError, attempt: number) => AnythingButUndefined): this; /** * Error handler for HTTP code 403 (Forbidden). Return the value you wish to continue with, or return 'retry()' for retrying the request, or return 'continuePropagation()' for allowing the error to propagate. */ http403Error(handler: (error: ForbiddenError, attempt: number) => AnythingButUndefined): this; /** * Error handler for HTTP code 404 (Not Found). Return the value you wish to continue with, or return 'retry()' for retrying the request, or return 'continuePropagation()' for allowing the error to propagate. */ http404Error(handler: (error: NotFoundError, attempt: number) => AnythingButUndefined): this; /** * Error handler for HTTP code 429 (Too Many Requests). Return the value you wish to continue with, or return 'retry()' for retrying the request, or return 'continuePropagation()' for allowing the error to propagate. */ http429Error(handler: (error: TooManyRequestsError, attempt: number) => AnythingButUndefined): this; /** * Error handler for any HTTP code in 500 range (various server side errors). Return the value you wish to continue with, or return 'retry()' for retrying the request, or return 'continuePropagation()' for allowing the error to propagate. */ http5xxError(handler: (error: ServerError, attempt: number) => AnythingButUndefined): this; /** * Error handler for any invalid HTTP code (anything other than in 200 and 300 range). Return the value you wish to continue with, or return 'retry()' for retrying the request, or return 'continuePropagation()' for allowing the error to propagate. */ httpAnyError(handler: (error: HttpError, attempt: number) => AnythingButUndefined): this; /** * Error handler for unexpected error, usually either network error or JSON parsing error. Return the value you wish to continue with, or return 'retry()' for retrying the request, or return 'continuePropagation()' for allowing the error to propagate. */ unexpectedError(handler: (error: UnexpectedError, attempt: number) => AnythingButUndefined): this; /** * Error handler for any error. Return the value you wish to continue with, or return 'retry()' for retrying the request, or return 'continuePropagation()' for allowing the error to propagate. */ anyError(handler: (error: HttpError | UnexpectedError | AdditionalErrorTypes, attempt: number) => AnythingButUndefined): this; /** * Retry when HTTP request is being rate limited (429 response). * @param total How many times to re-try. Set to -1 to retry indefinitely (default). * @param verbose Whether to show rate limit warning message. Default: true. * @param delay How long to delay before re-trying again, in milliseconds. Default: 1 second. * @param delayIncrease Delay to increase per each unsuccessful re-try, in milliseconds. Default: 1 second. */ retryOnRateLimiting(total?: number, delay?: number, delayIncrease?: number, verbose?: boolean): this; /** * Retry on any HTTP error. * @param total How many times to re-try. Set to -1 to retry indefinitely. Default: 3. * @param delay How long to delay before re-trying again, in milliseconds. Set to -1 to try to follow 'Retry-After' header value. Default: 1 second. * @param delayIncrease Delay to increase per each unsuccessful re-try, in milliseconds. Default: 1 second. */ retryOnHttpError(total?: number, delay?: number, delayIncrease?: number): this; /** * Retry on any failure. * @param total How many times to re-try. Set to -1 to retry indefinitely. Default: 3. * @param delay How long to delay before re-trying again, in milliseconds. Set to -1 to try to follow 'Retry-After' header value. Default: 1 second. * @param delayIncrease Delay to increase per each unsuccessful re-try, in milliseconds. Default: 1 second. */ retryOnAnyError(total?: number, delay?: number, delayIncrease?: number): this; build(): ESH | undefined; } export declare type AnythingButUndefined = string | number | boolean | symbol | Record | null; export interface BufferImplementation { buffer: { encode(input: string): ArrayBuffer; decode(input: ArrayBuffer): string; }; } export interface PlatformImplementation extends BufferImplementation { performHttpCall(request: Request): Promise; errorMessageBuilder?: ErrorMessageBuilder; } export declare type ApiHeaders = Record | Iterable> | Headers; export interface HeadersOption { headers?: ApiHeaders; } export declare type ErrorStrategyOptionType, ESB extends BaseErrorStrategyBuilder> = ESH | AssistedErrorStrategyFunction | null; export interface BaseErrorStrategyOption, ESB extends BaseErrorStrategyBuilder> { errorStrategy?: ErrorStrategyOptionType; } export declare type AssistedErrorStrategyFunction, ESB extends BaseErrorStrategyBuilder> = (builder: ESB) => ESH | ESB; export declare type ErrorMessageBuilder = (response: Response, reason?: string) => Promise; export interface CustomErrorHandler { errorName: string; handlerName: string; processResponse?(response: Response): Promise; } export declare type ErrorStrategyBuilderConstructor, ESB extends BaseErrorStrategyBuilder> = () => ESB; export interface BaseErrorStrategyHandlers { /** * Error handler for HTTP code 400 (Bad Request). Return the value you wish to continue with, or return 'retry()' for retrying the request, or return 'continuePropagation()' for allowing the error to propagate. * @param error Error that happened. * @param attempt How many times this request has already been executed. Starts with 1 and increases after each 'retry()'. */ handleHttp400Error?(error: BadRequestError, attempt: number): AnythingButUndefined; /** * Error handler for HTTP code 401 (Unauthorized). Return the value you wish to continue with, or return 'retry()' for retrying the request, or return 'continuePropagation()' for allowing the error to propagate. * @param error Error that happened. * @param attempt How many times this request has already been executed. Starts with 1 and increases after each 'retry()'. */ handleHttp401Error?(error: UnauthorizedError, attempt: number): AnythingButUndefined; /** * Error handler for HTTP code 403 (Forbidden). Return the value you wish to continue with, or return 'retry()' for retrying the request, or return 'continuePropagation()' for allowing the error to propagate. * @param error Error that happened. * @param attempt How many times this request has already been executed. Starts with 1 and increases after each 'retry()'. */ handleHttp403Error?(error: ForbiddenError, attempt: number): AnythingButUndefined; /** * Error handler for HTTP code 404 (Not Found). Return the value you wish to continue with, or return 'retry()' for retrying the request, or return 'continuePropagation()' for allowing the error to propagate. * @param error Error that happened. * @param attempt How many times this request has already been executed. Starts with 1 and increases after each 'retry()'. */ handleHttp404Error?(error: NotFoundError, attempt: number): AnythingButUndefined; /** * Error handler for HTTP code 429 (Too Many Requests). Return the value you wish to continue with, or return 'retry()' for retrying the request, or return 'continuePropagation()' for allowing the error to propagate. * @param error Error that happened. * @param attempt How many times this request has already been executed. Starts with 1 and increases after each 'retry()'. */ handleHttp429Error?(error: TooManyRequestsError, attempt: number): AnythingButUndefined; /** * Error handler for any HTTP code in 500 range (various server side errors). Return the value you wish to continue with, or return 'retry()' for retrying the request, or return 'continuePropagation()' for allowing the error to propagate. * @param error Error that happened. * @param attempt How many times this request has already been executed. Starts with 1 and increases after each 'retry()'. */ handleHttp5xxError?(error: ServerError, attempt: number): AnythingButUndefined; /** * Error handler for any invalid HTTP code (anything other than in 200 and 300 range). Return the value you wish to continue with, or return 'retry()' for retrying the request, or return 'continuePropagation()' for allowing the error to propagate. * @param error Error that happened. * @param attempt How many times this request has already been executed. Starts with 1 and increases after each 'retry()'. */ handleHttpAnyError?(error: HttpError, attempt: number): AnythingButUndefined; /** * Error handler for unexpected error, usually either network error or JSON parsing error. Return the value you wish to continue with, or return 'retry()' for retrying the request, or return 'continuePropagation()' for allowing the error to propagate. * @param error Error that happened. * @param attempt How many times this request has already been executed. Starts with 1 and increases after each 'retry()'. */ handleUnexpectedError?(error: UnexpectedError, attempt: number): AnythingButUndefined; /** * Error handler for any error. Return the value you wish to continue with, or return 'retry()' for retrying the request, or return 'continuePropagation()' for allowing the error to propagate. * @param error Error that happened. * @param attempt How many times this request has already been executed. Starts with 1 and increases after each 'retry()'. */ handleAnyError?(error: HttpError | UnexpectedError | AdditionalErrorTypes, attempt: number): AnythingButUndefined; } export declare class RetryRequested { delay: number; constructor(delay: number); } export declare class PropagationRequested { skipErrorStrategyPropagation: boolean; constructor(skipErrorStrategyPropagation: boolean); } export interface FetchOptions { method?: string; headers?: ApiHeaders; body?: string | ArrayBuffer | IsomorphicBlob | IsomorphicFormData; } export declare class HttpError extends Error { response: Response; name: string; constructor(response: Response, message: string, name?: string); } export declare class UnauthorizedError extends HttpError { constructor(response: Response, message: string); } export declare class ForbiddenError extends HttpError { constructor(response: Response, message: string); } export declare class NotFoundError extends HttpError { constructor(response: Response, message: string); } export declare class BadRequestError extends HttpError { constructor(response: Response, message: string); } export declare class ServerError extends HttpError { constructor(response: Response, message: string); } export declare class TooManyRequestsError extends HttpError { constructor(response: Response, message: string); } export declare class UnexpectedError extends Error { originalError: any; message: string; name: string; constructor(originalError: any, message: string); } export declare function constructUrl(url: string, queryParams?: Record, duplicateParams?: boolean): string; export declare function getHeaders(body?: any, manualHeaders?: HeadersOption['headers']): Headers; export declare function executeHttpCall, ESB extends BaseErrorStrategyBuilder, FullResponse, OptionalResponses = FullResponse>(implementation: PlatformImplementation, request: Request, errorStrategyBuilderConstructor: ErrorStrategyBuilderConstructor, globalErrorHandlers?: ErrorStrategyOptionType, errorHandlers?: ErrorStrategyOptionType, errorMessageBuilder?: ErrorMessageBuilder, customErrorHandlers?: CustomErrorHandler[], skipBodyParsing?: boolean | ((response: Response) => Promise), attempt?: number): Promise; export declare function mapStatusCodeToError(implementation: PlatformImplementation, response: Response, errorMessageBuilder?: ErrorMessageBuilder): Promise>; export declare function delay(ms: number): Promise; /** * Asks the current request to be re-tried. * @param delay Delay in milliseconds after which the re-try is invoked. Optional, defaults to 0. */ export declare function retry(delay?: number): RetryRequested; /** * Asks the current error handler to propagate the error to next error handler. * @param skipErrorStrategyPropagation If this value is set to true then any further error strategy handler is skipped and the error is sent directly to Promise rejection. Optional, defaults to false. */ export declare function continuePropagation(skipErrorStrategyPropagation?: boolean): PropagationRequested; /** * Returns error handler for re-trying on failures. * @param total How many times to re-try. Set to -1 to retry indefinitely (default). * @param delay How long to delay before re-trying again, in milliseconds. Set to -1 to try to follow 'Retry-After' header value (default). * @param delayIncrease Delay to increase per each unsuccessful re-try, in milliseconds. Default: 0 second. * @param verbose Whether to show a specific warning message. */ export declare function getRetryErrorHandler(total?: number, delay?: number, delayIncrease?: number, verbose?: boolean): (error: any, attempt: number, verboseMessage?: VerboseMessageBuilder | undefined) => RetryRequested | PropagationRequested; export declare function constructHeaders(body?: any, manualHeaders?: ApiHeaders): Headers; export declare abstract class BaseApiCore { protected implementation: PlatformImplementation; constructor(); protected abstract getPlatformImplementation(): PlatformImplementation; fetch(resource: string | Request, options?: FetchOptions): Promise>; } export declare class VerboseMessageBuilder { method: string; url: string; constructor(method: string, url: string); getTooManyRequestsVerboseMessage(delayMs: number, headerApplied: boolean): string; } export declare function getUint8ArrayOfFormDataEntries(implementation: BufferImplementation, formEntries: Iterable): Promise<{ uint8Array: Uint8Array; boundary: string; }>; //# sourceMappingURL=index.d.ts.map