import { _assign, ResultEnum } from '@eciol/shared'; import type { AnyFunction, AnyNormalFunction, ErrorMessageMode, RequestResult } from '@eciol/types'; import type { AxiosResponse } from 'axios'; export interface ContextOptions { errorFunction: AnyFunction; createMessage: AnyFunction; errorModalFunction: AnyFunction; createSuccessModal: AnyFunction; getTokenFunction: () => unknown; unauthorizedFunction: (msg?: string) => void; timeoutFunction: (res: AxiosResponse) => any; handleErrorFunction: (message?: string, mode?: ErrorMessageMode) => void; requestInterceptors: AnyFunction; apiUrl?: string; urlPrefix?: string; uploadUrl?: string; authenticationScheme?: string; ResultEnum?: typeof ResultEnum; } export let context: ContextOptions = { getTokenFunction: () => undefined, unauthorizedFunction: () => {}, errorFunction: () => {}, createMessage: () => {}, createSuccessModal: () => {}, errorModalFunction: () => {}, handleErrorFunction: () => {}, timeoutFunction: () => {}, requestInterceptors: () => {}, apiUrl: '', urlPrefix: '', uploadUrl: '', authenticationScheme: undefined, ResultEnum, }; export const initRequest = async (func: AnyNormalFunction) => { context = _assign(context, func()); }; export const setMsg = (func: AnyFunction) => { context.createMessage = func; };