@cmk/fe_utils
Version:
frontend utility library
36 lines (34 loc) • 1.46 kB
TypeScript
import { AxiosRequestConfig, AxiosResponse } from 'axios';
/** Definitions and Types */
/** ********************** */
/** HTTP Query method + 2 custom Response types with File (response=blob) */
export declare enum QUERY_METHOD {
GET = "GET",
POST = "POST",
PUT = "PUT",
DELETE = "DELETE",
GET_FILE = "GET_FILE",// GET with responseType: 'blob'
POST_GET_FILE = "POST_GET_FILE",// POST with responseType: 'blob'
PATCH = "PATCH"
}
/** Unknown Query Payload */
export type UnknownQueryPayloadType = Record<string, unknown>;
/** AxiosConfig with some minor adjustments */
export type QueryConfigType = Omit<AxiosRequestConfig, 'data' | 'url' | 'method'> & {
disableRedirectToLogin?: boolean;
};
export type QueryParamType<PayloadType> = QueryConfigType & {
url: string;
payload?: PayloadType;
};
/** The type of the query functions */
export type QueryFnType<PayloadType = UnknownQueryPayloadType, ResponseType = unknown> = (params: QueryParamType<PayloadType>) => Promise<AxiosResponse<ResponseType>>;
export type QueryResponseType<ResponseType = unknown> = {
data: ResponseType | null;
status: number | string;
statusText: string;
headers: Record<string, string>;
error?: unknown;
};
/** the query for all methods */
export declare const query: <PayloadType = unknown, ResponseType = unknown>(method: QUERY_METHOD, params: QueryParamType<PayloadType>) => Promise<QueryResponseType<ResponseType>>;