@m4l/core 0.0.31 → 0.0.34

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.
@@ -7,7 +7,13 @@ const initialValue = {
7
7
  host_api_local: "",
8
8
  host_api_remote: "",
9
9
  host_static_assets: "",
10
- environment: ""
10
+ environment_assets: "",
11
+ date_format: "yyyy-MM-dd",
12
+ date_mask: "____-__-__",
13
+ time_format: "HH:mm:ss",
14
+ time_mask: "__:__:__",
15
+ datetime_format: "yyyy-MM-dd HH:mm:ss",
16
+ datetime_mask: "____-__-__ __:__:__"
11
17
  };
12
18
  const EnvironmentContext = createContext(initialValue);
13
19
  function EnvironmentProvider(props) {
@@ -1,5 +1,3 @@
1
- import { l as lib } from "./qs.js";
2
- import { E as EmitEvents } from "../types/index.js";
3
1
  var axios$2 = { exports: {} };
4
2
  var bind$2 = function bind(fn, thisArg) {
5
3
  return function wrap() {
@@ -1219,86 +1217,4 @@ axios$1.isAxiosError = isAxiosError;
1219
1217
  axios$2.exports = axios$1;
1220
1218
  axios$2.exports.default = axios$1;
1221
1219
  var axios = axios$2.exports;
1222
- function getResponse(endPoint, response) {
1223
- console.log("Axios response", response, typeof response.data);
1224
- if (response && response.data && typeof response.data === "object") {
1225
- if (response.data.error && response.data.error?.code && response.data.error?.msg !== void 0) {
1226
- return Promise.reject({ ...response.data.error, status: response.status });
1227
- }
1228
- return response.data;
1229
- }
1230
- return Promise.reject({
1231
- code: 1,
1232
- msg: `Incorrect endpoint: ${endPoint}`,
1233
- status: response.status
1234
- });
1235
- }
1236
- function getError(error, hostTools, checkUnAuthorized = true) {
1237
- const { toast } = hostTools;
1238
- let err = {
1239
- message: "",
1240
- status: 1,
1241
- code: 0
1242
- };
1243
- console.log("getError", error);
1244
- if (error?.code !== void 0 && err.status !== void 0 && error.message !== void 0) {
1245
- err = { ...err, ...error };
1246
- } else if (error?.response) {
1247
- 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) {
1248
- err = { ...error.response.data.error, status: error.response.status };
1249
- } else {
1250
- err.message = error.message;
1251
- err.status = error.response.status;
1252
- err.code = 0;
1253
- }
1254
- if (checkUnAuthorized && error.response.status === 401) {
1255
- hostTools.events_emit(EmitEvents.EMMIT_EVENT_NET_SERVICE_UNAUTHORIZED, {});
1256
- }
1257
- } else if (error?.request) {
1258
- err.message = `${error?.code} ${error.message}`;
1259
- err.code = -1;
1260
- } else {
1261
- err.message = `${error?.code} ${error.message}`;
1262
- err.status = 0;
1263
- err.code = -2;
1264
- }
1265
- if (checkUnAuthorized) {
1266
- toast(`${err.message} - status: ${err.status} - code: ${err.code}`, { type: "error" });
1267
- }
1268
- return err;
1269
- }
1270
- const axiosOperation = async (props, enviroment, hostTools) => {
1271
- const {
1272
- method,
1273
- endPoint,
1274
- timeout = 5e3,
1275
- parms = {},
1276
- data: data2 = {},
1277
- isRemote = true,
1278
- checkUnAuthorized = true,
1279
- headers
1280
- } = props;
1281
- let baseURL;
1282
- if (isRemote) {
1283
- baseURL = enviroment.host_api_remote;
1284
- } else {
1285
- baseURL = enviroment.host_api_local;
1286
- }
1287
- hostTools.startProgress();
1288
- return axios({
1289
- baseURL,
1290
- withCredentials: isRemote,
1291
- method,
1292
- url: `/${endPoint}`,
1293
- data: data2,
1294
- params: {},
1295
- paramsSerializer: () => {
1296
- return lib.stringify(parms, { encode: true });
1297
- },
1298
- headers,
1299
- timeout
1300
- }).then((response) => getResponse(endPoint, response)).catch((error) => Promise.reject(getError(error, hostTools, checkUnAuthorized))).finally(() => {
1301
- hostTools.stopProgress();
1302
- });
1303
- };
1304
- export { axiosOperation as a };
1220
+ export { axios as a };
package/dist/index.js CHANGED
@@ -1,8 +1,9 @@
1
- export { E as EnvironmentContext, a as EnvironmentProvider } from "./contexts/EnvironmentContext/index.js";
2
- export { H as HostToolsContext, a as HostToolsProvider } from "./contexts/HostToolsContext/index.js";
3
- export { N as NetworkContext, a as NetworkProvider } from "./contexts/NetworkContext/index.js";
1
+ import "react";
4
2
  export { F as FlagsContext, a as FlagsProvider } from "./contexts/FlagsContext/index.js";
3
+ export { H as HostToolsContext, a as HostToolsProvider } from "./contexts/HostToolsContext/index.js";
5
4
  export { M as ModuleDictionaryContext, a as ModuleDictionaryProvider } from "./contexts/ModuleDictionaryContext/index.js";
5
+ export { N as NetworkContext, a as NetworkProvider } from "./contexts/NetworkContext/index.js";
6
+ export { E as EnvironmentContext, a as EnvironmentProvider } from "./contexts/EnvironmentContext/index.js";
6
7
  export { u as useFlags, a as useFlagsPresent } from "./hooks/useFlags/index.js";
7
8
  export { u as useHostTools } from "./hooks/useHostTools/index.js";
8
9
  export { u as useLocalStorage } from "./hooks/useLocalStorage/index.js";
@@ -12,10 +13,7 @@ export { u as useEnvironment } from "./hooks/useEnvironment/index.js";
12
13
  export { i as initialPagerState, u as usePaginate } from "./hooks/usePaginate/index.js";
13
14
  export { E as EmitEvents } from "./types/index.js";
14
15
  export { a as getLocalStorage, g as getPropertyByString, s as setLocalStorage, v as voidFunction } from "./utils/index.js";
15
- export { a as axiosOperation } from "./external/axios.js";
16
- import "react";
16
+ export { a as axiosOperation } from "./utils/axiosOperation.js";
17
17
  import "react/jsx-runtime";
18
- import "./external/qs.js";
19
- import "./external/side-channel.js";
20
- import "./node_modules.js";
21
- import "./vendor.js";
18
+ import "./external/axios.js";
19
+ import "qs";
@@ -8,7 +8,13 @@ export declare interface EnvironmentType {
8
8
  host_api_remote: string;
9
9
  host_api_local: string;
10
10
  host_static_assets: string;
11
- environment: string;
11
+ environment_assets: string;
12
+ date_format: string;
13
+ date_mask: string;
14
+ time_format: string;
15
+ time_mask: string;
16
+ datetime_format: string;
17
+ datetime_mask: string;
12
18
  }
13
19
  export declare type NetworkProps = {
14
20
  method: any;
@@ -0,0 +1,86 @@
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) {
5
+ console.log("Axios response", response, typeof response.data);
6
+ if (response && response.data && typeof response.data === "object") {
7
+ if (response.data.error && response.data.error?.code && response.data.error?.msg !== void 0) {
8
+ return Promise.reject({ ...response.data.error, status: response.status });
9
+ }
10
+ return response.data;
11
+ }
12
+ return Promise.reject({
13
+ code: 1,
14
+ msg: `Incorrect endpoint: ${endPoint}`,
15
+ status: response.status
16
+ });
17
+ }
18
+ function getError(error, hostTools, checkUnAuthorized = true) {
19
+ const { toast } = hostTools;
20
+ let err = {
21
+ message: "",
22
+ status: 1,
23
+ code: 0
24
+ };
25
+ console.log("getError", error);
26
+ if (error?.code !== void 0 && err.status !== void 0 && error.message !== void 0) {
27
+ err = { ...err, ...error };
28
+ } else if (error?.response) {
29
+ 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) {
30
+ err = { ...error.response.data.error, status: error.response.status };
31
+ } else {
32
+ err.message = error.message;
33
+ err.status = error.response.status;
34
+ err.code = 0;
35
+ }
36
+ if (checkUnAuthorized && error.response.status === 401) {
37
+ hostTools.events_emit(EmitEvents.EMMIT_EVENT_NET_SERVICE_UNAUTHORIZED, {});
38
+ }
39
+ } else if (error?.request) {
40
+ err.message = `${error?.code} ${error.message}`;
41
+ err.code = -1;
42
+ } else {
43
+ err.message = `${error?.code} ${error.message}`;
44
+ err.status = 0;
45
+ err.code = -2;
46
+ }
47
+ if (checkUnAuthorized) {
48
+ toast(`${err.message} - status: ${err.status} - code: ${err.code}`, { type: "error" });
49
+ }
50
+ return err;
51
+ }
52
+ const axiosOperation = async (props, enviroment, hostTools) => {
53
+ const {
54
+ method,
55
+ endPoint,
56
+ timeout = 5e3,
57
+ parms = {},
58
+ data = {},
59
+ isRemote = true,
60
+ checkUnAuthorized = true,
61
+ headers
62
+ } = props;
63
+ let baseURL;
64
+ if (isRemote) {
65
+ baseURL = enviroment.host_api_remote;
66
+ } else {
67
+ baseURL = enviroment.host_api_local;
68
+ }
69
+ hostTools.startProgress();
70
+ return axios({
71
+ baseURL,
72
+ withCredentials: isRemote,
73
+ method,
74
+ url: `/${endPoint}`,
75
+ data,
76
+ params: {},
77
+ paramsSerializer: () => {
78
+ return qs.stringify(parms, { encode: true });
79
+ },
80
+ headers,
81
+ timeout
82
+ }).then((response) => getResponse(endPoint, response)).catch((error) => Promise.reject(getError(error, hostTools, checkUnAuthorized))).finally(() => {
83
+ hostTools.stopProgress();
84
+ });
85
+ };
86
+ export { axiosOperation as a };
@@ -1,5 +1,5 @@
1
1
  import "../external/axios.js";
2
- import "../external/qs.js";
2
+ import "qs";
3
3
  function voidFunction() {
4
4
  }
5
5
  function getPropertyByString(object, propString) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@m4l/core",
3
3
  "private": false,
4
- "version": "0.0.31",
4
+ "version": "0.0.34",
5
5
  "license": "UNLICENSED",
6
6
  "author": "M4L Team",
7
7
  "scripts": {
@@ -17,6 +17,9 @@
17
17
  "coverage": "vitest run --coverage",
18
18
  "Oldprepack": "json -f package.json -I -e \"delete this.devDependencies; delete this.dependencies\""
19
19
  },
20
+ "dependencies": {
21
+ "qs": "^6.11.0"
22
+ },
20
23
  "peerDependencies": {
21
24
  "react": ">=18"
22
25
  },
@@ -47,7 +50,6 @@
47
50
  "jsdom": "^20.0.0",
48
51
  "json": "^11.0.0",
49
52
  "prettier": "^2.6.2",
50
- "qs": "^6.11.0",
51
53
  "react": "^18.2.0",
52
54
  "react-dom": "^18.2.0",
53
55
  "react-toastify": "^9.0.5",
@@ -78,4 +80,5 @@
78
80
  "engines": {
79
81
  "node": ">=12.0.0"
80
82
  }
83
+
81
84
  }