@m4l/core 0.0.14 → 0.0.15
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/dist/contexts/HostToolsContext/index.d.ts +1 -1
- package/dist/contexts/NetworkContext/index.d.ts +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +83 -112
- package/dist/types/index.d.ts +1 -2
- package/package.json +1 -1
- 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/setLocalStorage.d.ts +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { HostToolsType } from '../../types';
|
|
3
|
-
import { HostToolsProviderProps } from './types';
|
|
3
|
+
import type { HostToolsProviderProps } from './types';
|
|
4
4
|
declare const HostToolsContext: import("react").Context<HostToolsType>;
|
|
5
5
|
declare function HostToolsProvider(props: HostToolsProviderProps): JSX.Element;
|
|
6
6
|
export { HostToolsProvider, HostToolsContext };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { NetworkProviderProps } from './types';
|
|
2
|
+
import type { NetworkProviderProps } from './types';
|
|
3
3
|
declare const NetworkContext: import("react").Context<import("./types").NetworkType>;
|
|
4
4
|
declare function NetworkProvider(props: NetworkProviderProps): JSX.Element;
|
|
5
5
|
export { NetworkProvider, NetworkContext };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ export * from './hooks';
|
|
|
3
3
|
export { EmitEvents } from './types';
|
|
4
4
|
export type { Maybe, HostToolsType, NetworkProps, EnvironmentType, AxiosOperation, EventFunListener, } from './types';
|
|
5
5
|
export type { GetLabelType, Dictionary, ModuleDictionary, ComponentDictionary, } from './types/dictionary';
|
|
6
|
-
export
|
|
6
|
+
export { voidFunction } from './utils/voidFunction';
|
|
7
|
+
export { axiosOperation } from './utils/axiosOperation/index';
|
package/dist/index.js
CHANGED
|
@@ -25,117 +25,6 @@ function EnvironmentProvider(props) {
|
|
|
25
25
|
}
|
|
26
26
|
function voidFunction() {
|
|
27
27
|
}
|
|
28
|
-
function getPropertyByString(object, propString) {
|
|
29
|
-
let value = object;
|
|
30
|
-
const props = propString.split(".");
|
|
31
|
-
for (let index = 0; index < props.length; index += 1) {
|
|
32
|
-
if (props[index] === void 0)
|
|
33
|
-
break;
|
|
34
|
-
value = value[props[index]];
|
|
35
|
-
}
|
|
36
|
-
return value;
|
|
37
|
-
}
|
|
38
|
-
function getLocalStorage(key, initialValue2) {
|
|
39
|
-
try {
|
|
40
|
-
const item = window.localStorage.getItem(key);
|
|
41
|
-
return item !== null ? JSON.parse(item) : initialValue2;
|
|
42
|
-
} catch (e) {
|
|
43
|
-
return initialValue2;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
function setLocalStorage(key, value) {
|
|
47
|
-
try {
|
|
48
|
-
const item = window.localStorage.getItem(key);
|
|
49
|
-
let newValue = item !== null ? JSON.parse(item) : {};
|
|
50
|
-
newValue = { ...newValue, ...value };
|
|
51
|
-
window.localStorage.setItem(key, JSON.stringify(newValue));
|
|
52
|
-
} catch (e) {
|
|
53
|
-
console.error(e);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
var EmitEvents = /* @__PURE__ */ ((EmitEvents2) => {
|
|
57
|
-
EmitEvents2["EMMIT_EVENT_NET_SERVICE_UNAUTHORIZED"] = `netsevice_unauthorized`;
|
|
58
|
-
EmitEvents2["EMMIT_EVENT_HOST_THEME_CHANGE"] = "host_theme_change";
|
|
59
|
-
return EmitEvents2;
|
|
60
|
-
})(EmitEvents || {});
|
|
61
|
-
const axiosInstance = axios.create({});
|
|
62
|
-
function getResponse(endPoint, response) {
|
|
63
|
-
console.log("Axios response", response, typeof response.data);
|
|
64
|
-
if (response && response.data && typeof response.data === "object") {
|
|
65
|
-
if (response.data.error && response.data.error?.code && response.data.error?.msg !== void 0) {
|
|
66
|
-
return Promise.reject({ ...response.data.error, status: response.status });
|
|
67
|
-
}
|
|
68
|
-
return response.data;
|
|
69
|
-
}
|
|
70
|
-
return Promise.reject({
|
|
71
|
-
code: 1,
|
|
72
|
-
msg: `Incorrect endpoint: ${endPoint}`,
|
|
73
|
-
status: response.status
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
function getError(error, hostTools, checkUnAuthorized = true) {
|
|
77
|
-
const { toast } = hostTools;
|
|
78
|
-
let err = {
|
|
79
|
-
message: "",
|
|
80
|
-
status: 1,
|
|
81
|
-
code: 0
|
|
82
|
-
};
|
|
83
|
-
console.log("getError", error);
|
|
84
|
-
if (error?.code !== void 0 && err.status !== void 0 && error.message !== void 0) {
|
|
85
|
-
err = { ...err, ...error };
|
|
86
|
-
} else if (error?.response) {
|
|
87
|
-
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) {
|
|
88
|
-
err = { ...error.response.data.error, status: error.response.status };
|
|
89
|
-
} else {
|
|
90
|
-
err.message = error.message;
|
|
91
|
-
err.status = error.response.status;
|
|
92
|
-
err.code = 0;
|
|
93
|
-
}
|
|
94
|
-
if (checkUnAuthorized && error.response.status === 401) {
|
|
95
|
-
hostTools.events_emit(EmitEvents.EMMIT_EVENT_NET_SERVICE_UNAUTHORIZED, {});
|
|
96
|
-
}
|
|
97
|
-
} else if (error?.request) {
|
|
98
|
-
err.message = `${error?.code} ${error.message}`;
|
|
99
|
-
err.code = -1;
|
|
100
|
-
} else {
|
|
101
|
-
err.message = `${error?.code} ${error.message}`;
|
|
102
|
-
err.status = 0;
|
|
103
|
-
err.code = -2;
|
|
104
|
-
}
|
|
105
|
-
if (checkUnAuthorized) {
|
|
106
|
-
toast(`${err.message} - status: ${err.status} - code: ${err.code}`, { type: "error" });
|
|
107
|
-
}
|
|
108
|
-
return err;
|
|
109
|
-
}
|
|
110
|
-
const axiosOperation = async (props, enviroment, hostTools) => {
|
|
111
|
-
const {
|
|
112
|
-
method,
|
|
113
|
-
endPoint,
|
|
114
|
-
timeout = 5e3,
|
|
115
|
-
parms = {},
|
|
116
|
-
data = {},
|
|
117
|
-
isRemote = true,
|
|
118
|
-
checkUnAuthorized = true
|
|
119
|
-
} = props;
|
|
120
|
-
let baseURL;
|
|
121
|
-
if (isRemote) {
|
|
122
|
-
baseURL = enviroment.host_api_remote;
|
|
123
|
-
} else {
|
|
124
|
-
baseURL = enviroment.host_api_local;
|
|
125
|
-
}
|
|
126
|
-
hostTools.startProgress();
|
|
127
|
-
return axiosInstance({
|
|
128
|
-
baseURL,
|
|
129
|
-
withCredentials: isRemote,
|
|
130
|
-
method,
|
|
131
|
-
url: `/${endPoint}`,
|
|
132
|
-
data: snakecaseKeys(data, { deep: true }),
|
|
133
|
-
params: snakecaseKeys(parms, { deep: true }),
|
|
134
|
-
timeout
|
|
135
|
-
}).then((response) => getResponse(endPoint, response)).catch((error) => Promise.reject(getError(error, hostTools, checkUnAuthorized))).finally(() => {
|
|
136
|
-
hostTools.stopProgress();
|
|
137
|
-
});
|
|
138
|
-
};
|
|
139
28
|
const initialValue$1 = {
|
|
140
29
|
toast: () => 0,
|
|
141
30
|
startProgress: voidFunction,
|
|
@@ -351,4 +240,86 @@ function ModuleDictionaryProvider(props) {
|
|
|
351
240
|
children
|
|
352
241
|
});
|
|
353
242
|
}
|
|
354
|
-
|
|
243
|
+
var EmitEvents = /* @__PURE__ */ ((EmitEvents2) => {
|
|
244
|
+
EmitEvents2["EMMIT_EVENT_NET_SERVICE_UNAUTHORIZED"] = `netsevice_unauthorized`;
|
|
245
|
+
EmitEvents2["EMMIT_EVENT_HOST_THEME_CHANGE"] = "host_theme_change";
|
|
246
|
+
return EmitEvents2;
|
|
247
|
+
})(EmitEvents || {});
|
|
248
|
+
function getResponse(endPoint, response) {
|
|
249
|
+
console.log("Axios response", response, typeof response.data);
|
|
250
|
+
if (response && response.data && typeof response.data === "object") {
|
|
251
|
+
if (response.data.error && response.data.error?.code && response.data.error?.msg !== void 0) {
|
|
252
|
+
return Promise.reject({ ...response.data.error, status: response.status });
|
|
253
|
+
}
|
|
254
|
+
return response.data;
|
|
255
|
+
}
|
|
256
|
+
return Promise.reject({
|
|
257
|
+
code: 1,
|
|
258
|
+
msg: `Incorrect endpoint: ${endPoint}`,
|
|
259
|
+
status: response.status
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
function getError(error, hostTools, checkUnAuthorized = true) {
|
|
263
|
+
const { toast } = hostTools;
|
|
264
|
+
let err = {
|
|
265
|
+
message: "",
|
|
266
|
+
status: 1,
|
|
267
|
+
code: 0
|
|
268
|
+
};
|
|
269
|
+
console.log("getError", error);
|
|
270
|
+
if (error?.code !== void 0 && err.status !== void 0 && error.message !== void 0) {
|
|
271
|
+
err = { ...err, ...error };
|
|
272
|
+
} else if (error?.response) {
|
|
273
|
+
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) {
|
|
274
|
+
err = { ...error.response.data.error, status: error.response.status };
|
|
275
|
+
} else {
|
|
276
|
+
err.message = error.message;
|
|
277
|
+
err.status = error.response.status;
|
|
278
|
+
err.code = 0;
|
|
279
|
+
}
|
|
280
|
+
if (checkUnAuthorized && error.response.status === 401) {
|
|
281
|
+
hostTools.events_emit(EmitEvents.EMMIT_EVENT_NET_SERVICE_UNAUTHORIZED, {});
|
|
282
|
+
}
|
|
283
|
+
} else if (error?.request) {
|
|
284
|
+
err.message = `${error?.code} ${error.message}`;
|
|
285
|
+
err.code = -1;
|
|
286
|
+
} else {
|
|
287
|
+
err.message = `${error?.code} ${error.message}`;
|
|
288
|
+
err.status = 0;
|
|
289
|
+
err.code = -2;
|
|
290
|
+
}
|
|
291
|
+
if (checkUnAuthorized) {
|
|
292
|
+
toast(`${err.message} - status: ${err.status} - code: ${err.code}`, { type: "error" });
|
|
293
|
+
}
|
|
294
|
+
return err;
|
|
295
|
+
}
|
|
296
|
+
const axiosOperation = async (props, enviroment, hostTools) => {
|
|
297
|
+
const {
|
|
298
|
+
method,
|
|
299
|
+
endPoint,
|
|
300
|
+
timeout = 5e3,
|
|
301
|
+
parms = {},
|
|
302
|
+
data = {},
|
|
303
|
+
isRemote = true,
|
|
304
|
+
checkUnAuthorized = true
|
|
305
|
+
} = props;
|
|
306
|
+
let baseURL;
|
|
307
|
+
if (isRemote) {
|
|
308
|
+
baseURL = enviroment.host_api_remote;
|
|
309
|
+
} else {
|
|
310
|
+
baseURL = enviroment.host_api_local;
|
|
311
|
+
}
|
|
312
|
+
hostTools.startProgress();
|
|
313
|
+
return axios({
|
|
314
|
+
baseURL,
|
|
315
|
+
withCredentials: isRemote,
|
|
316
|
+
method,
|
|
317
|
+
url: `/${endPoint}`,
|
|
318
|
+
data: snakecaseKeys(data, { deep: true }),
|
|
319
|
+
params: snakecaseKeys(parms, { deep: true }),
|
|
320
|
+
timeout
|
|
321
|
+
}).then((response) => getResponse(endPoint, response)).catch((error) => Promise.reject(getError(error, hostTools, checkUnAuthorized))).finally(() => {
|
|
322
|
+
hostTools.stopProgress();
|
|
323
|
+
});
|
|
324
|
+
};
|
|
325
|
+
export { EmitEvents, EnvironmentContext, EnvironmentProvider, FlagsContext, FlagsProvider, HostToolsContext, HostToolsProvider, ModuleDictionaryContext, ModuleDictionaryProvider, NetworkContext, NetworkProvider, axiosOperation, useEnvironment, useFlags, useFlagsPresent, useHostTools, useLocalStorage, useModuleDictionary, useNetwork, voidFunction };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Method } from 'axios';
|
|
2
1
|
import type { Id, ToastContent, ToastOptions } from 'react-toastify';
|
|
3
2
|
import type { BrowserHistory } from 'history';
|
|
4
3
|
export declare type Maybe<T> = T | undefined | null;
|
|
@@ -12,7 +11,7 @@ export declare interface EnvironmentType {
|
|
|
12
11
|
environment: string;
|
|
13
12
|
}
|
|
14
13
|
export declare type NetworkProps = {
|
|
15
|
-
method:
|
|
14
|
+
method: any;
|
|
16
15
|
endPoint: string;
|
|
17
16
|
timeout?: number;
|
|
18
17
|
parms?: object;
|
package/package.json
CHANGED
|
@@ -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';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function setLocalStorage<ValueType>(key: string, value: ValueType): void;
|