import type { LylaError, LylaNonResponseError, LylaResponseError } from './error'; export type LylaMethod = 'get' | 'GET' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'head' | 'HEAD' | 'delete' | 'DELETE' | 'options' | 'OPTIONS' | 'TRACE' | 'trace' | 'CONNECT' | 'connect'; export type AbortSignal = { addEventListener(ev: 'abort', callback: () => void): void; removeEventListener(ev: 'abort', callback: () => void): void; }; export type LylaRequestOptions = { url?: string; method?: M['method']; timeout?: number; /** * True when credentials are to be included in a cross-origin request. * False when they are to be excluded in a cross-origin request and when * cookies are to be ignored in its response. */ withCredentials?: boolean; headers?: LylaRequestHeaders; /** * Type of `response.body`. */ responseType?: M['responseType']; body?: M['requestBody']; /** * JSON value to be written into the request body. It can't be used with * `body`. */ json?: any; query?: Record>; baseUrl?: string; /** * Abort signal of the request. */ signal?: AbortSignal; onUploadProgress?: (progress: LylaProgress) => void; onDownloadProgress?: (progress: LylaProgress) => void; context?: C; /** * Whether to allow get request with body. Default is false. * It's not recommended to use GET request with body. */ allowGetBody?: boolean; hooks?: { /** * Callbacks fired when options is passed into the request. In this moment, * request options haven't be normalized. */ onInit?: Array<(options: LylaRequestOptionsWithContext) => LylaRequestOptionsWithContext | Promise>>; /** * Callbacks fired before request is sent. In this moment, request options is * normalized. */ onBeforeRequest?: Array<(options: LylaRequestOptionsWithContext) => LylaRequestOptionsWithContext | Promise>>; /** * Callbacks fired after headers are received. */ onHeadersReceived?: Array<(payload: { headers: Record; originalRequest: M['originalRequest']; requestOptions: LylaRequestOptionsWithContext; }, reject: (reason: unknown) => void) => void>; /** * Callbacks fired after response is received. */ onAfterResponse?: Array<(response: LylaResponse, reject: (reason: unknown) => void) => LylaResponse | Promise>>; /** * Callbacks fired when there's error while response handling. It's only * fired by LylaError. Error thrown by user won't triggered the callback, * for example if user throws an error in `onAfterResponse` hook. The * callback won't be fired. */ onResponseError?: Array<(error: LylaResponseError, reject: (reason: unknown) => void) => void | Promise>; /** * Callbacks fired when a non-response error occurs. */ onNonResponseError?: Array<(error: LylaNonResponseError) => void | Promise>; }; extraOptions?: M['extraOptions']; }; export type LylaRequestOptionsWithContext = Omit, 'context'> & { context: C; }; export type LylaResponse = { requestOptions: LylaRequestOptions; status: number; statusText: string; /** * Headers of the response. All the keys are in lower case. */ headers: Record; /** * Response body. */ body: M['responseBody']; /** * JSON value of the response. If body is not valid JSON text, access the * field will cause an error. */ json: T; /** * Original */ detail: M['responseDetail']; /** * context */ context: C; }; export type LylaProgress = { /** * Percentage of the progress. From 0 to 100. */ percent: number; /** * Loaded bytes of the progress. */ loaded: number; /** * Total bytes of the progress. If progress is not length-computable it would * be 0. */ total: number; /** * Whether the total bytes of the progress is computable. */ lengthComputable: boolean; /** * Detail message of progress */ detail: M['progressDetail']; /** * Original request */ originalRequest: M['originalRequest']; requestOptions: LylaRequestOptionsWithContext; }; export type LylaRequestHeaders = Record; export type Lyla = { (options: LylaRequestOptions): Promise>; } & Record, (url: string, options?: Omit, 'url' | 'method'>) => Promise>> & { errorType: LylaError; } & { withRetry: LylaWithRetry; }; export type LylaRetryOnRejectedCommand = { action: 'retry'; value: () => Promise> | LylaRequestOptions; } | { action: 'reject'; value: unknown; }; export type LylaRetryOnResolvedCommand = { action: 'retry'; value: () => Promise> | LylaRequestOptions; } | { action: 'resolve'; value: LylaResponse; } | { action: 'reject'; value: unknown; }; export type LylaWithRetryOptions = { onResolved: (params: { state: S; options: LylaRequestOptions; context: C; response: LylaResponse; }) => Promise>; onRejected: (params: { state: S; options: LylaRequestOptions; context: C; lyla: Lyla; error: unknown; }) => Promise>; createState: () => S; }; export type LylaWithRetry = (options: LylaWithRetryOptions) => Lyla; export interface LylaAdapterMeta { method: LylaMethod; requestBody: any | undefined; responseType: 'arraybuffer' | 'blob' | 'text'; responseBody: any; networkErrorDetail: any; responseDetail: any; progressDetail: any; originalRequest: any; extraOptions: any; } export interface LylaAdapterOptions { url: string; method: T['method']; headers: Record; body: T['requestBody'] | undefined; json: object | undefined; responseType: T['responseType']; withCredentials: boolean; extraOptions: T['extraOptions']; onNetworkError(detail: T['networkErrorDetail']): void; onUploadProgress: ((progress: Omit, 'requestOptions'>) => void) | undefined; onDownloadProgress: ((progress: Omit, 'requestOptions'>) => void) | undefined; onHeadersReceived: ((headers: Record, originalRequest: T['originalRequest']) => void) | undefined; onResponse(response: { body: T['responseBody']; status: number; headers: Record; }, detail: T['responseDetail']): void; } export type LylaAdapter = (options: LylaAdapterOptions) => { abort: () => void; }; //# sourceMappingURL=types.d.ts.map