@m4l/core 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -3
- package/dist/contexts/EnvironmentContext/index.d.ts +0 -5
- package/dist/contexts/EnvironmentContext/index.js +0 -32
- package/dist/contexts/EnvironmentContext/types.d.ts +0 -6
- package/dist/contexts/FlagsContext/index.d.ts +0 -5
- package/dist/contexts/FlagsContext/index.js +0 -34
- package/dist/contexts/FlagsContext/types.d.ts +0 -10
- package/dist/contexts/HostToolsContext/index.d.ts +0 -6
- package/dist/contexts/HostToolsContext/index.js +0 -25
- package/dist/contexts/HostToolsContext/types.d.ts +0 -6
- package/dist/contexts/ModuleDictionaryContext/index.d.ts +0 -5
- package/dist/contexts/ModuleDictionaryContext/index.js +0 -90
- package/dist/contexts/ModuleDictionaryContext/types.d.ts +0 -15
- package/dist/contexts/ModulePrivilegesContext/index.d.ts +0 -5
- package/dist/contexts/ModulePrivilegesContext/index.js +0 -68
- package/dist/contexts/ModulePrivilegesContext/types.d.ts +0 -9
- package/dist/contexts/ModuleSkeletonContext/index.d.ts +0 -5
- package/dist/contexts/ModuleSkeletonContext/index.js +0 -26
- package/dist/contexts/ModuleSkeletonContext/types.d.ts +0 -8
- package/dist/contexts/NetworkContext/index.d.ts +0 -5
- package/dist/contexts/NetworkContext/index.js +0 -26
- package/dist/contexts/NetworkContext/types.d.ts +0 -11
- package/dist/contexts/index.d.ts +0 -7
- package/dist/external/axios.js +0 -1261
- package/dist/hooks/index.d.ts +0 -11
- package/dist/hooks/useEnvironment/index.d.ts +0 -2
- package/dist/hooks/useEnvironment/index.js +0 -9
- package/dist/hooks/useFlags/index.d.ts +0 -3
- package/dist/hooks/useFlags/index.js +0 -25
- package/dist/hooks/useHostTools/index.d.ts +0 -2
- package/dist/hooks/useHostTools/index.js +0 -9
- package/dist/hooks/useLocalStorage/index.d.ts +0 -1
- package/dist/hooks/useLocalStorage/index.js +0 -21
- package/dist/hooks/useModuleDictionary/index.d.ts +0 -1
- package/dist/hooks/useModuleDictionary/index.js +0 -9
- package/dist/hooks/useModulePrivileges/index.d.ts +0 -1
- package/dist/hooks/useModulePrivileges/index.js +0 -9
- package/dist/hooks/useModuleSkeleton/index.d.ts +0 -1
- package/dist/hooks/useModuleSkeleton/index.js +0 -9
- package/dist/hooks/useNetwork/index.d.ts +0 -2
- package/dist/hooks/useNetwork/index.js +0 -9
- package/dist/hooks/usePaginate/index.d.ts +0 -10
- package/dist/hooks/usePaginate/index.js +0 -74
- package/dist/hooks/usePaginate/types.d.ts +0 -12
- package/dist/index.d.ts +0 -6
- package/dist/index.js +0 -23
- package/dist/jest.d.ts +0 -1
- package/dist/types/dictionary.d.ts +0 -13
- package/dist/types/index.d.ts +0 -49
- package/dist/types/index.js +0 -6
- package/dist/utils/axiosOperation/index.d.ts +0 -2
- package/dist/utils/axiosOperation/types.d.ts +0 -5
- package/dist/utils/axiosOperation.js +0 -90
- package/dist/utils/getLocalStorage.d.ts +0 -1
- package/dist/utils/getPropertyByString.d.ts +0 -1
- package/dist/utils/index.d.ts +0 -5
- package/dist/utils/index.js +0 -33
- package/dist/utils/setLocalStorage.d.ts +0 -1
- package/dist/utils/voidFunction.d.ts +0 -1
- package/dist/vite-env.d.ts +0 -4
package/dist/hooks/index.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export { useEnvironment } from './useEnvironment';
|
|
2
|
-
export { useFlags, useFlagsPresent } from './useFlags';
|
|
3
|
-
export { useHostTools } from './useHostTools';
|
|
4
|
-
export { useLocalStorage } from './useLocalStorage';
|
|
5
|
-
export { useModuleDictionary } from './useModuleDictionary';
|
|
6
|
-
export { useModulePrivileges } from './useModulePrivileges';
|
|
7
|
-
export { useModuleSkeleton } from './useModuleSkeleton';
|
|
8
|
-
export { useNetwork } from './useNetwork';
|
|
9
|
-
export { usePaginate } from './usePaginate';
|
|
10
|
-
export type { PagerState } from './usePaginate/types';
|
|
11
|
-
export { initialPagerState } from './usePaginate/types';
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { useContext } from "react";
|
|
2
|
-
import { E as EnvironmentContext } from "../../contexts/EnvironmentContext/index.js";
|
|
3
|
-
const useEnvironment = () => {
|
|
4
|
-
const context = useContext(EnvironmentContext);
|
|
5
|
-
if (!context)
|
|
6
|
-
throw new Error("useEnvironment context must be use inside EnvironmentContext");
|
|
7
|
-
return context;
|
|
8
|
-
};
|
|
9
|
-
export { useEnvironment as u };
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { useContext, useState, useEffect } from "react";
|
|
2
|
-
import { F as FlagsContext } from "../../contexts/FlagsContext/index.js";
|
|
3
|
-
const useFlags = () => {
|
|
4
|
-
const context = useContext(FlagsContext);
|
|
5
|
-
if (!context)
|
|
6
|
-
throw new Error("useFlags context must be use inside FlagsProvider");
|
|
7
|
-
return context;
|
|
8
|
-
};
|
|
9
|
-
function isFlagsPresent(compareFlags, flags) {
|
|
10
|
-
const filterFlags = compareFlags.filter(
|
|
11
|
-
(findFlag) => flags.findIndex((sFlag) => sFlag === findFlag) !== -1
|
|
12
|
-
);
|
|
13
|
-
return filterFlags.length === compareFlags.length;
|
|
14
|
-
}
|
|
15
|
-
const useFlagsPresent = (compareFlags) => {
|
|
16
|
-
const context = useFlags();
|
|
17
|
-
const [isPresent, setIsPresent] = useState(isFlagsPresent(compareFlags, context.flags));
|
|
18
|
-
useEffect(() => {
|
|
19
|
-
if (isFlagsPresent(compareFlags, context.flags)) {
|
|
20
|
-
setIsPresent(true);
|
|
21
|
-
}
|
|
22
|
-
}, [context.flags, compareFlags]);
|
|
23
|
-
return isPresent;
|
|
24
|
-
};
|
|
25
|
-
export { useFlagsPresent as a, useFlags as u };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { useContext } from "react";
|
|
2
|
-
import { H as HostToolsContext } from "../../contexts/HostToolsContext/index.js";
|
|
3
|
-
const useHostTools = () => {
|
|
4
|
-
const context = useContext(HostToolsContext);
|
|
5
|
-
if (!context)
|
|
6
|
-
throw new Error("useHostTools context must be use inside HostToolsContext");
|
|
7
|
-
return context;
|
|
8
|
-
};
|
|
9
|
-
export { useHostTools as u };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function useLocalStorage<ValueType>(key: string, initialValue: ValueType): any[];
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { useState } from "react";
|
|
2
|
-
function useLocalStorage(key, initialValue) {
|
|
3
|
-
const [value, setValue] = useState(() => {
|
|
4
|
-
try {
|
|
5
|
-
const item = window.localStorage.getItem(key);
|
|
6
|
-
return item !== null ? JSON.parse(item) : initialValue;
|
|
7
|
-
} catch (e) {
|
|
8
|
-
return initialValue;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const setValueInLocalStorage = (newValue) => {
|
|
12
|
-
try {
|
|
13
|
-
window.localStorage.setItem(key, JSON.stringify(newValue));
|
|
14
|
-
setValue(newValue);
|
|
15
|
-
} catch (e) {
|
|
16
|
-
console.error(e);
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
return [value, setValueInLocalStorage];
|
|
20
|
-
}
|
|
21
|
-
export { useLocalStorage as u };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const useModuleDictionary: () => import("../../contexts/ModuleDictionaryContext/types").ModuleDictionaryContextProps;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { useContext } from "react";
|
|
2
|
-
import { M as ModuleDictionaryContext } from "../../contexts/ModuleDictionaryContext/index.js";
|
|
3
|
-
const useModuleDictionary = () => {
|
|
4
|
-
const context = useContext(ModuleDictionaryContext);
|
|
5
|
-
if (!context)
|
|
6
|
-
throw new Error("useModuleDictionary context must be use inside ModuleDictionaryProvider");
|
|
7
|
-
return context;
|
|
8
|
-
};
|
|
9
|
-
export { useModuleDictionary as u };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const useModulePrivileges: () => import("../../contexts/ModulePrivilegesContext/types").ModulePrivilegesContextProps;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { useContext } from "react";
|
|
2
|
-
import { M as ModulePrivilegesContext } from "../../contexts/ModulePrivilegesContext/index.js";
|
|
3
|
-
const useModulePrivileges = () => {
|
|
4
|
-
const context = useContext(ModulePrivilegesContext);
|
|
5
|
-
if (!context)
|
|
6
|
-
throw new Error("useModulePrivileges context must be use inside ModulePrivilegesContext");
|
|
7
|
-
return context;
|
|
8
|
-
};
|
|
9
|
-
export { useModulePrivileges as u };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const useModuleSkeleton: () => boolean;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { useContext } from "react";
|
|
2
|
-
import { M as ModuleSkeletonContext } from "../../contexts/ModuleSkeletonContext/index.js";
|
|
3
|
-
const useModuleSkeleton = () => {
|
|
4
|
-
const context = useContext(ModuleSkeletonContext);
|
|
5
|
-
if (!context)
|
|
6
|
-
throw new Error("useModuleSkeleton context must be use inside ModuleSkeletonContext");
|
|
7
|
-
return context.isSkeleton;
|
|
8
|
-
};
|
|
9
|
-
export { useModuleSkeleton as u };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { useContext } from "react";
|
|
2
|
-
import { N as NetworkContext } from "../../contexts/NetworkContext/index.js";
|
|
3
|
-
const useNetwork = () => {
|
|
4
|
-
const context = useContext(NetworkContext);
|
|
5
|
-
if (!context)
|
|
6
|
-
throw new Error("useNetwork context must be use inside NetworkContext");
|
|
7
|
-
return context;
|
|
8
|
-
};
|
|
9
|
-
export { useNetwork as u };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { UsePaginateProps } from './types';
|
|
2
|
-
import type { PagerState } from './types';
|
|
3
|
-
export declare const usePaginate: <TRow>(props: UsePaginateProps) => {
|
|
4
|
-
onPageChange: (newPage: number) => void;
|
|
5
|
-
onRowsPerPageChange: (newRowsPerPage: number) => void;
|
|
6
|
-
pagerState: PagerState;
|
|
7
|
-
rows: TRow[];
|
|
8
|
-
clearRows: () => void;
|
|
9
|
-
Refresh: () => void;
|
|
10
|
-
};
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { useState, useRef, useCallback, useEffect } from "react";
|
|
2
|
-
import { u as useHostTools } from "../useHostTools/index.js";
|
|
3
|
-
import { u as useNetwork } from "../useNetwork/index.js";
|
|
4
|
-
const initialPagerState = {
|
|
5
|
-
page: 0,
|
|
6
|
-
rowsPerPage: 25,
|
|
7
|
-
totalRecords: 0
|
|
8
|
-
};
|
|
9
|
-
const usePaginate = (props) => {
|
|
10
|
-
const { endPoint, timeout = 5e3, queryParams = {}, fireOnChangeParms } = props;
|
|
11
|
-
const [refresh, setRefresh] = useState(fireOnChangeParms ? 1 : 0);
|
|
12
|
-
const [rows, setRows] = useState([]);
|
|
13
|
-
const [pagerState, setPagerState] = useState(initialPagerState);
|
|
14
|
-
const refPagerState = useRef(initialPagerState);
|
|
15
|
-
const { startProgress, stopProgress } = useHostTools();
|
|
16
|
-
const { networkOperation } = useNetwork();
|
|
17
|
-
const Refresh = useCallback(() => {
|
|
18
|
-
setRefresh((oldValue) => oldValue + 1);
|
|
19
|
-
}, []);
|
|
20
|
-
useEffect(() => {
|
|
21
|
-
if (fireOnChangeParms) {
|
|
22
|
-
Refresh();
|
|
23
|
-
}
|
|
24
|
-
}, [queryParams]);
|
|
25
|
-
useEffect(() => {
|
|
26
|
-
let mounted = true;
|
|
27
|
-
if (refresh === 0)
|
|
28
|
-
return;
|
|
29
|
-
startProgress();
|
|
30
|
-
networkOperation({
|
|
31
|
-
method: "GET",
|
|
32
|
-
endPoint,
|
|
33
|
-
timeout,
|
|
34
|
-
parms: {
|
|
35
|
-
...queryParams,
|
|
36
|
-
page: refPagerState.current.page,
|
|
37
|
-
limit: refPagerState.current.rowsPerPage
|
|
38
|
-
}
|
|
39
|
-
}).then((response) => {
|
|
40
|
-
if (mounted) {
|
|
41
|
-
setRows(response.data);
|
|
42
|
-
refPagerState.current.page = response.pager.page;
|
|
43
|
-
setPagerState((oldPagerState) => ({
|
|
44
|
-
...oldPagerState,
|
|
45
|
-
page: response.pager.page,
|
|
46
|
-
totalRecords: response.pager.total
|
|
47
|
-
}));
|
|
48
|
-
}
|
|
49
|
-
}).finally(() => {
|
|
50
|
-
if (mounted) {
|
|
51
|
-
stopProgress();
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
return function cleanUp() {
|
|
55
|
-
stopProgress();
|
|
56
|
-
mounted = false;
|
|
57
|
-
};
|
|
58
|
-
}, [refresh]);
|
|
59
|
-
const onPageChange = (newPage) => {
|
|
60
|
-
refPagerState.current.page = newPage;
|
|
61
|
-
setRefresh((oldValue) => oldValue + 1);
|
|
62
|
-
};
|
|
63
|
-
const onRowsPerPageChange = (newRowsPerPage) => {
|
|
64
|
-
refPagerState.current.rowsPerPage = newRowsPerPage;
|
|
65
|
-
setPagerState((oldPagerState) => ({ ...oldPagerState, rowsPerPage: newRowsPerPage }));
|
|
66
|
-
setRefresh((oldValue) => oldValue + 1);
|
|
67
|
-
};
|
|
68
|
-
const clearRows = () => {
|
|
69
|
-
setRows([]);
|
|
70
|
-
setPagerState(initialPagerState);
|
|
71
|
-
};
|
|
72
|
-
return { onPageChange, onRowsPerPageChange, pagerState, rows, clearRows, Refresh };
|
|
73
|
-
};
|
|
74
|
-
export { initialPagerState as i, usePaginate as u };
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export declare interface PagerState {
|
|
2
|
-
page: number;
|
|
3
|
-
rowsPerPage: number;
|
|
4
|
-
totalRecords: number;
|
|
5
|
-
}
|
|
6
|
-
export declare const initialPagerState: PagerState;
|
|
7
|
-
export interface UsePaginateProps {
|
|
8
|
-
endPoint: string;
|
|
9
|
-
timeout?: number;
|
|
10
|
-
fireOnChangeParms?: boolean;
|
|
11
|
-
queryParams?: Record<string, unknown>;
|
|
12
|
-
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export * from './contexts';
|
|
2
|
-
export * from './hooks';
|
|
3
|
-
export { EmitEvents } from './types';
|
|
4
|
-
export type { Maybe, HostToolsType, NetworkProps, EnvironmentType, AxiosOperation, EventFunListener, } from './types';
|
|
5
|
-
export type { GetLabelType, Dictionary, ModuleDictionary, ComponentDictionary, } from './types/dictionary';
|
|
6
|
-
export * from './utils';
|
package/dist/index.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import "react";
|
|
2
|
-
export { E as EnvironmentContext, a as EnvironmentProvider } from "./contexts/EnvironmentContext/index.js";
|
|
3
|
-
export { F as FlagsContext, a as FlagsProvider } from "./contexts/FlagsContext/index.js";
|
|
4
|
-
export { H as HostToolsContext, a as HostToolsProvider } from "./contexts/HostToolsContext/index.js";
|
|
5
|
-
export { M as ModuleDictionaryContext, a as ModuleDictionaryProvider } from "./contexts/ModuleDictionaryContext/index.js";
|
|
6
|
-
export { M as ModulePrivilegesContext, a as ModulePrivilegesProvider } from "./contexts/ModulePrivilegesContext/index.js";
|
|
7
|
-
export { M as ModuleSkeletonContext, a as ModuleSkeletonProvider } from "./contexts/ModuleSkeletonContext/index.js";
|
|
8
|
-
export { N as NetworkContext, a as NetworkProvider } from "./contexts/NetworkContext/index.js";
|
|
9
|
-
export { u as useEnvironment } from "./hooks/useEnvironment/index.js";
|
|
10
|
-
export { u as useFlags, a as useFlagsPresent } from "./hooks/useFlags/index.js";
|
|
11
|
-
export { u as useHostTools } from "./hooks/useHostTools/index.js";
|
|
12
|
-
export { u as useLocalStorage } from "./hooks/useLocalStorage/index.js";
|
|
13
|
-
export { u as useModuleDictionary } from "./hooks/useModuleDictionary/index.js";
|
|
14
|
-
export { u as useModulePrivileges } from "./hooks/useModulePrivileges/index.js";
|
|
15
|
-
export { u as useModuleSkeleton } from "./hooks/useModuleSkeleton/index.js";
|
|
16
|
-
export { u as useNetwork } from "./hooks/useNetwork/index.js";
|
|
17
|
-
export { i as initialPagerState, u as usePaginate } from "./hooks/usePaginate/index.js";
|
|
18
|
-
export { E as EmitEvents } from "./types/index.js";
|
|
19
|
-
export { a as getLocalStorage, g as getPropertyByString, s as setLocalStorage, v as voidFunction } from "./utils/index.js";
|
|
20
|
-
export { a as axiosOperation } from "./utils/axiosOperation.js";
|
|
21
|
-
import "react/jsx-runtime";
|
|
22
|
-
import "./external/axios.js";
|
|
23
|
-
import "qs";
|
package/dist/jest.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/// <reference types="jest" />
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare type GetLabelType = (key: string) => string;
|
|
2
|
-
export interface ComponentDictionary {
|
|
3
|
-
[key: string]: string;
|
|
4
|
-
}
|
|
5
|
-
export interface Dictionary {
|
|
6
|
-
[key: string]: ComponentDictionary | boolean | undefined | string;
|
|
7
|
-
}
|
|
8
|
-
export interface DataDictionary extends ComponentDictionary {
|
|
9
|
-
module_name: string;
|
|
10
|
-
}
|
|
11
|
-
export interface ModuleDictionary extends Dictionary {
|
|
12
|
-
data: DataDictionary;
|
|
13
|
-
}
|
package/dist/types/index.d.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { Id, ToastContent, ToastOptions } from 'react-toastify';
|
|
2
|
-
import type { BrowserHistory } from 'history';
|
|
3
|
-
export declare type Maybe<T> = T | undefined | null;
|
|
4
|
-
export declare interface DfnFormat {
|
|
5
|
-
date_format: string;
|
|
6
|
-
date_mask: string;
|
|
7
|
-
time_format: string;
|
|
8
|
-
time_mask: string;
|
|
9
|
-
datetime_format: string;
|
|
10
|
-
datetime_mask: string;
|
|
11
|
-
}
|
|
12
|
-
export declare interface EnvironmentType {
|
|
13
|
-
isLocalhost: boolean;
|
|
14
|
-
host: string;
|
|
15
|
-
domain_token: string;
|
|
16
|
-
host_api_remote: string;
|
|
17
|
-
host_api_local: string;
|
|
18
|
-
host_static_assets: string;
|
|
19
|
-
environment_assets: string;
|
|
20
|
-
dfnsFormat: DfnFormat;
|
|
21
|
-
}
|
|
22
|
-
export declare type NetworkProps = {
|
|
23
|
-
method: any;
|
|
24
|
-
endPoint: string;
|
|
25
|
-
timeout?: number;
|
|
26
|
-
parms?: object;
|
|
27
|
-
data?: object;
|
|
28
|
-
headers?: Record<string, string | number | boolean>;
|
|
29
|
-
checkUnAuthorized?: boolean;
|
|
30
|
-
isRemote?: boolean;
|
|
31
|
-
showSuccesInfo?: boolean;
|
|
32
|
-
};
|
|
33
|
-
export declare type ToastFunction = (content: ToastContent, options?: ToastOptions) => Id;
|
|
34
|
-
export declare type EventFunListener = (...args: any[]) => void;
|
|
35
|
-
export declare interface HostToolsType {
|
|
36
|
-
history?: BrowserHistory;
|
|
37
|
-
toast: ToastFunction;
|
|
38
|
-
startProgress: VoidFunction;
|
|
39
|
-
stopProgress: VoidFunction;
|
|
40
|
-
formatDate: (date: Date | number, format: string, options?: any) => string;
|
|
41
|
-
events_add_listener: (eventName: string, handler: EventFunListener) => void;
|
|
42
|
-
events_remove_listener: (eventName: string, handler: Maybe<EventFunListener>) => void;
|
|
43
|
-
events_emit: (eventName: string, arg: any) => void;
|
|
44
|
-
}
|
|
45
|
-
export declare enum EmitEvents {
|
|
46
|
-
EMMIT_EVENT_NET_SERVICE_UNAUTHORIZED = "netsevice_unauthorized",
|
|
47
|
-
EMMIT_EVENT_HOST_THEME_CHANGE = "host_theme_change"
|
|
48
|
-
}
|
|
49
|
-
export declare type AxiosOperation = (props: NetworkProps, enviroment: EnvironmentType, hostTools: HostToolsType) => Promise<any>;
|
package/dist/types/index.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
var EmitEvents = /* @__PURE__ */ ((EmitEvents2) => {
|
|
2
|
-
EmitEvents2["EMMIT_EVENT_NET_SERVICE_UNAUTHORIZED"] = `netsevice_unauthorized`;
|
|
3
|
-
EmitEvents2["EMMIT_EVENT_HOST_THEME_CHANGE"] = "host_theme_change";
|
|
4
|
-
return EmitEvents2;
|
|
5
|
-
})(EmitEvents || {});
|
|
6
|
-
export { EmitEvents as E };
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { a as axios } from "../external/axios.js";
|
|
2
|
-
import qs from "qs";
|
|
3
|
-
import { E as EmitEvents } from "../types/index.js";
|
|
4
|
-
function getResponse(endPoint, response, hostTools) {
|
|
5
|
-
console.log("Axios response", response, typeof response.data);
|
|
6
|
-
const { toast } = hostTools;
|
|
7
|
-
if (response && response.data && typeof response.data === "object") {
|
|
8
|
-
if (response.data.error && response.data.error?.code && response.data.error?.msg !== void 0) {
|
|
9
|
-
return Promise.reject({ ...response.data.error, status: response.status });
|
|
10
|
-
}
|
|
11
|
-
if (response.data.message) {
|
|
12
|
-
toast(response.data.message, { type: "success", autoClose: 1e4 });
|
|
13
|
-
}
|
|
14
|
-
return response.data;
|
|
15
|
-
}
|
|
16
|
-
return Promise.reject({
|
|
17
|
-
code: 1,
|
|
18
|
-
msg: `Incorrect endpoint: ${endPoint}`,
|
|
19
|
-
status: response.status
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
function getError(error, hostTools, checkUnAuthorized = true) {
|
|
23
|
-
const { toast } = hostTools;
|
|
24
|
-
let err = {
|
|
25
|
-
message: "",
|
|
26
|
-
status: 1,
|
|
27
|
-
code: 0
|
|
28
|
-
};
|
|
29
|
-
console.log("getError", error);
|
|
30
|
-
if (error?.code !== void 0 && err.status !== void 0 && error.message !== void 0) {
|
|
31
|
-
err = { ...err, ...error };
|
|
32
|
-
} else if (error?.response) {
|
|
33
|
-
if (error.response.data && typeof error.response.data === "object" && error.response.data.error && error.response.data.error?.code && error.response.data.error?.message !== void 0) {
|
|
34
|
-
err = { ...error.response.data.error, status: error.response.status };
|
|
35
|
-
} else {
|
|
36
|
-
err.message = error.message;
|
|
37
|
-
err.status = error.response.status;
|
|
38
|
-
err.code = 0;
|
|
39
|
-
}
|
|
40
|
-
if (checkUnAuthorized && error.response.status === 401) {
|
|
41
|
-
hostTools.events_emit(EmitEvents.EMMIT_EVENT_NET_SERVICE_UNAUTHORIZED, {});
|
|
42
|
-
}
|
|
43
|
-
} else if (error?.request) {
|
|
44
|
-
err.message = `${error?.code} ${error.message}`;
|
|
45
|
-
err.code = -1;
|
|
46
|
-
} else {
|
|
47
|
-
err.message = `${error?.code} ${error.message}`;
|
|
48
|
-
err.status = 0;
|
|
49
|
-
err.code = -2;
|
|
50
|
-
}
|
|
51
|
-
if (checkUnAuthorized) {
|
|
52
|
-
toast(`${err.message} - status: ${err.status} - code: ${err.code}`, { type: "error" });
|
|
53
|
-
}
|
|
54
|
-
return err;
|
|
55
|
-
}
|
|
56
|
-
const axiosOperation = async (props, enviroment, hostTools) => {
|
|
57
|
-
const {
|
|
58
|
-
method,
|
|
59
|
-
endPoint,
|
|
60
|
-
timeout = 5e3,
|
|
61
|
-
parms = {},
|
|
62
|
-
data = {},
|
|
63
|
-
isRemote = true,
|
|
64
|
-
checkUnAuthorized = true,
|
|
65
|
-
headers
|
|
66
|
-
} = props;
|
|
67
|
-
let baseURL;
|
|
68
|
-
if (isRemote) {
|
|
69
|
-
baseURL = enviroment.host_api_remote;
|
|
70
|
-
} else {
|
|
71
|
-
baseURL = enviroment.host_api_local;
|
|
72
|
-
}
|
|
73
|
-
hostTools.startProgress();
|
|
74
|
-
return axios({
|
|
75
|
-
baseURL,
|
|
76
|
-
withCredentials: isRemote,
|
|
77
|
-
method,
|
|
78
|
-
url: `/${endPoint}`,
|
|
79
|
-
data,
|
|
80
|
-
params: {},
|
|
81
|
-
paramsSerializer: () => {
|
|
82
|
-
return qs.stringify(parms, { encode: true });
|
|
83
|
-
},
|
|
84
|
-
headers,
|
|
85
|
-
timeout
|
|
86
|
-
}).then((response) => getResponse(endPoint, response, hostTools)).catch((error) => Promise.reject(getError(error, hostTools, checkUnAuthorized))).finally(() => {
|
|
87
|
-
hostTools.stopProgress();
|
|
88
|
-
});
|
|
89
|
-
};
|
|
90
|
-
export { axiosOperation as a };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getLocalStorage<ValueType>(key: string, initialValue: ValueType): ValueType;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getPropertyByString(object: Record<string, unknown>, propString: string): any;
|
package/dist/utils/index.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { voidFunction } from './voidFunction';
|
|
2
|
-
export { getPropertyByString } from './getPropertyByString';
|
|
3
|
-
export { getLocalStorage } from './getLocalStorage';
|
|
4
|
-
export { setLocalStorage } from './setLocalStorage';
|
|
5
|
-
export { axiosOperation } from './axiosOperation';
|
package/dist/utils/index.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import "../external/axios.js";
|
|
2
|
-
import "qs";
|
|
3
|
-
function voidFunction() {
|
|
4
|
-
}
|
|
5
|
-
function getPropertyByString(object, propString) {
|
|
6
|
-
let value = object;
|
|
7
|
-
const props = propString.split(".");
|
|
8
|
-
for (let index = 0; index < props.length; index += 1) {
|
|
9
|
-
if (props[index] === void 0)
|
|
10
|
-
break;
|
|
11
|
-
value = value[props[index]];
|
|
12
|
-
}
|
|
13
|
-
return value;
|
|
14
|
-
}
|
|
15
|
-
function getLocalStorage(key, initialValue) {
|
|
16
|
-
try {
|
|
17
|
-
const item = window.localStorage.getItem(key);
|
|
18
|
-
return item !== null ? JSON.parse(item) : initialValue;
|
|
19
|
-
} catch (e) {
|
|
20
|
-
return initialValue;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
function setLocalStorage(key, value) {
|
|
24
|
-
try {
|
|
25
|
-
const item = window.localStorage.getItem(key);
|
|
26
|
-
let newValue = item !== null ? JSON.parse(item) : {};
|
|
27
|
-
newValue = { ...newValue, ...value };
|
|
28
|
-
window.localStorage.setItem(key, JSON.stringify(newValue));
|
|
29
|
-
} catch (e) {
|
|
30
|
-
console.error(e);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
export { getLocalStorage as a, getPropertyByString as g, setLocalStorage as s, voidFunction as v };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function setLocalStorage<ValueType>(key: string, value: ValueType): void;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function voidFunction(): void;
|
package/dist/vite-env.d.ts
DELETED