import { ActionCreator, Dispatch } from 'redux'; import { State } from './reducer'; import { BindingsStore } from './helpers/createBinding'; import { StringifyOptions } from 'query-string'; export declare type NetworkStatus = 'ready' | 'loading' | 'failed' | 'success'; export declare type NormalizeResult = string | number | Array; export interface NormalizedData { entities: { [type: string]: { [id: string]: any; }; }; result: NormalizeResult; } /** * Map parameter names to values. */ export interface EndpointParams { [paramName: string]: string | number | string[] | number[]; } /** * Information about a request made to an endpoint. */ export interface DataRequest { result?: any; networkStatus: NetworkStatus; lastCall: number; duration: number; response?: Response; errorBody?: any; endpointKey: string; params?: EndpointParams; url: string; } export interface GlobalConfig { setHeaders?: (defaultHeaders: any, state: any) => any; setRequestProperties?: (defaultProperties: object, state: object) => object; beforeSuccess?: (handledResponse: { response: Response; body: any; }, beforeProps: ConfigBeforeProps) => { response: Response; body: any; }; afterSuccess?: (afterProps: ConfigAfterProps) => void; beforeFailed?: (handledResponse: { response: Response; body: any; }, beforeProps: ConfigBeforeProps) => { response: Response; body: any; }; afterFailed?: (afterProps: ConfigAfterProps) => void; timeout?: number; autoTrigger?: boolean; enableSuspense?: boolean; parseMethod?: ParseMethod; } /** * Specification and configuration of an endpoint. */ export declare type Method = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'; export interface EndpointConfig { url: string; method: Method; cacheDuration?: number; responseSchema?: any; queryStringOpts?: StringifyOptions; transformResponseBody?: (responseBody: any) => NormalizedData; handleErrorResponse?: (responseBody: any, params: EndpointParams, requestBody: any, dispatch: ActionCreator, getState: () => { apiData: State; }, response?: Response) => boolean | void; beforeFailed?: (handledResponse: { response: Response; body: any; }, beforeProps: ConfigBeforeProps) => { response: Response; body: any; }; afterFailed?: (afterProps: ConfigAfterProps) => boolean | void; beforeSuccess?: (handledResponse: { response: Response; body: any; }, beforeProps: ConfigBeforeProps) => { response: Response; body: any; }; afterSuccess?: (afterProps: ConfigAfterProps) => boolean | void; setHeaders?: (defaultHeaders: object, state: object) => object; setRequestProperties?: (defaultProperties: object, state: object) => object; defaultParams?: { [paramName: string]: string | number; }; timeout?: number; autoTrigger?: boolean; enableSuspense?: boolean; parseMethod?: ParseMethod; } export interface ConfigBeforeProps { endpointKey: string; request: DataRequest; requestBody?: any; } export interface ConfigAfterProps { endpointKey: string; request: DataRequest; requestBody?: any; resultData: any; actions: Actions; dispatch: Dispatch; getState: () => any; } /** * The value that withApiData binds to the property of your component. * @example * type Props = { * users: Binding> * } */ export interface Binding { data?: T; dataFailed?: F; loading: boolean; request: DataRequest; perform: (params?: EndpointParams, body?: any) => Promise>; invalidateCache: () => void; purge: () => void; getInstance: (instanceId: string) => Binding; } export interface Actions { perform: (endpointKey: string, params?: EndpointParams, body?: any, instanceId?: string, bindingsStore?: BindingsStore) => Promise>; invalidateCache: (endpointKey: string, params?: EndpointParams, instanceId?: string) => void; purgeRequest: (endpointKey: string, params?: EndpointParams, instanceId?: string) => void; purgeAll: () => void; } export interface Options { instanceId?: string; isSSR?: boolean; } export interface HookOptions extends Partial, Options { } export interface HandledResponse { response: Response; body: any; } export declare type ParseMethod = 'json' | 'blob' | 'text' | 'arrayBuffer' | 'formData'; export interface RequestConfig { parseMethod?: ParseMethod; } export declare type RequestHandler = (url: string, requestProperties?: RequestInit, config?: RequestConfig) => Promise;