import { BaseContext } from './BaseContext'; import { AnalyticsContext } from './AnalyticsContext'; import { IApiContext, ApiStatus, ApiRecoveryReason, ApiCallInfo, IProcessRequest } from '../types'; interface ApiCall extends ApiCallInfo { /** Request promise resolve callback */ resolve: (value?: any) => any; /** Request promise reject callback */ reject: (value?: any) => any; } export declare class ApiCallError extends Error { call: ApiCall; constructor(call: ApiCall); } /** * Options which are passed to the HTTP request. */ export interface FetchingOptions { /** * Signal of request aborting. */ signal: AbortSignal; } export interface FileUploadOptions { /** Called during the file uploading, used to track upload progress */ onProgress?: (progress: number) => any; /** Callback to receive the instance of xhr. Can be used to abort the request. */ getXHR?: (xhr: XMLHttpRequest) => any; } export interface FileUploadResponse { /** ID of the file */ id: number; /** Name of the file */ name: string; /** File size */ size: number; /** Path to the file source */ path?: string; /** Type of file representation. Used for UUI SlateRTE file displaying. */ type?: BlockTypes; /** Extension of the file */ extension?: string; /** Upload error */ error?: { /** If true, indicates about error while file uploading */ isError: boolean; /** Error message */ message?: string; }; } export type BlockTypes = 'attachment' | 'iframe' | 'image'; export interface ApiContextProps { /** Url to the relogin page. Used to open new browser window by this path, in case of auth lost error. * Opened by this path page, should process authentication and then post 'authSuccess' cross-window message to the opener, to recover failed requests. * @default '/auth/login' * */ apiReloginPath?: string; /** Url to the api, which ApiContext will start pinging in case of 'connection lost', until it gets 200 status. Then it will retry failed requests. * @default '/auth/ping' * */ apiPingPath?: string; /** Url to the server api under which all requests will be processed. Usefully for cases, when all api located by some specific url, which is not much app url. * @default '' * */ apiServerUrl?: string; /** * Allows to replace fetch implementation, for adding auth headers, mocking for testing, etc. * By default, standard fetch will be used. */ fetch?: typeof fetch; } export declare class ApiContext extends BaseContext implements IApiContext { private props; private analyticsCtx?; private queue; private isRunScheduled; status: ApiStatus; recoveryReason: ApiRecoveryReason | null; apiReloginPath: string; private readonly authRecoveryContext; constructor(props: ApiContextProps, analyticsCtx?: AnalyticsContext); init(): void; private handleSuccessAuthRecovery; destroyContext(): void; getActiveCalls(): ApiCallInfo[]; reset(): void; private setStatus; private handleApiError; private startCall; private handleResponse; private removeFromQueue; private resolveCall; private runQueue; private recoverConnection; private scheduleRun; private defaultParseResponse; processRequest: IProcessRequest; uploadFile(url: string, file: File, options?: FileUploadOptions): Promise; } export {}; //# sourceMappingURL=ApiContext.d.ts.map