@m4l/core 0.0.20 → 0.0.23

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.
@@ -0,0 +1,24 @@
1
+ import { createContext, useState } from "react";
2
+ import { jsx } from "react/jsx-runtime";
3
+ const initialValue = {
4
+ isLocalhost: true,
5
+ host: "",
6
+ domain_token: "",
7
+ host_api_local: "",
8
+ host_api_remote: "",
9
+ host_static_assets: "",
10
+ environment: ""
11
+ };
12
+ const EnvironmentContext = createContext(initialValue);
13
+ function EnvironmentProvider(props) {
14
+ const {
15
+ children,
16
+ ...other
17
+ } = props;
18
+ const [finalEnvironment] = useState(other);
19
+ return /* @__PURE__ */ jsx(EnvironmentContext.Provider, {
20
+ value: finalEnvironment,
21
+ children
22
+ });
23
+ }
24
+ export { EnvironmentContext as E, EnvironmentProvider as a };
@@ -0,0 +1,34 @@
1
+ import { createContext, useState, useCallback } from "react";
2
+ import { v as voidFunction } from "../../utils/index.js";
3
+ import { jsx } from "react/jsx-runtime";
4
+ const initialState = {
5
+ flags: [],
6
+ clearFlags: voidFunction,
7
+ addFlag: voidFunction
8
+ };
9
+ const FlagsContext = createContext(initialState);
10
+ function FlagsProvider({
11
+ children
12
+ }) {
13
+ const [flags, setFlags] = useState([]);
14
+ const clearFlags = useCallback(() => {
15
+ setFlags([]);
16
+ }, []);
17
+ const addFlag = useCallback((newFlag) => {
18
+ setFlags((oldFlags) => {
19
+ if (oldFlags.findIndex((f) => f === newFlag) < 0) {
20
+ return [...oldFlags, newFlag];
21
+ }
22
+ return [...oldFlags];
23
+ });
24
+ }, []);
25
+ return /* @__PURE__ */ jsx(FlagsContext.Provider, {
26
+ value: {
27
+ flags,
28
+ addFlag,
29
+ clearFlags
30
+ },
31
+ children
32
+ });
33
+ }
34
+ export { FlagsContext as F, FlagsProvider as a };
@@ -0,0 +1,24 @@
1
+ import { createContext, useState } from "react";
2
+ import { v as voidFunction } from "../../utils/index.js";
3
+ import { jsx } from "react/jsx-runtime";
4
+ const initialValue = {
5
+ toast: () => 0,
6
+ startProgress: voidFunction,
7
+ stopProgress: voidFunction,
8
+ events_add_listener: voidFunction,
9
+ events_remove_listener: voidFunction,
10
+ events_emit: voidFunction
11
+ };
12
+ const HostToolsContext = createContext(initialValue);
13
+ function HostToolsProvider(props) {
14
+ const {
15
+ children,
16
+ ...hostTools
17
+ } = props;
18
+ const [finalTools] = useState(hostTools);
19
+ return /* @__PURE__ */ jsx(HostToolsContext.Provider, {
20
+ value: finalTools,
21
+ children
22
+ });
23
+ }
24
+ export { HostToolsContext as H, HostToolsProvider as a };
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import { ModuleDictionaryContextProps, ModuleDictionaryProviderProps } from './types';
3
+ declare const ModuleDictionaryContext: import("react").Context<ModuleDictionaryContextProps>;
4
+ declare function ModuleDictionaryProvider(props: ModuleDictionaryProviderProps): JSX.Element;
5
+ export { ModuleDictionaryProvider, ModuleDictionaryContext };
@@ -0,0 +1,88 @@
1
+ import { createContext, useState, useLayoutEffect, useCallback } from "react";
2
+ import { u as useHostTools } from "../../hooks/useHostTools/index.js";
3
+ import { u as useNetwork } from "../../hooks/useNetwork/index.js";
4
+ import { u as useEnvironment } from "../../hooks/useEnvironment/index.js";
5
+ import { u as useFlags } from "../../hooks/useFlags/index.js";
6
+ import { jsx } from "react/jsx-runtime";
7
+ const initialState = {
8
+ getLabel: () => "..",
9
+ getModuleLabel: () => "No dictionary context"
10
+ };
11
+ const ModuleDictionaryContext = createContext(initialState);
12
+ function ModuleDictionaryProvider(props) {
13
+ const {
14
+ children,
15
+ componentsDictionary,
16
+ moduleId,
17
+ moduleName = "module_name",
18
+ currentLang = "us",
19
+ isAuth = true
20
+ } = props;
21
+ const {
22
+ addFlag
23
+ } = useFlags();
24
+ const [moduleDictionary, setModuleDictionary] = useState(void 0);
25
+ const {
26
+ domain_token
27
+ } = useEnvironment();
28
+ const {
29
+ startProgress,
30
+ stopProgress
31
+ } = useHostTools();
32
+ const {
33
+ networkOperation
34
+ } = useNetwork();
35
+ useLayoutEffect(() => {
36
+ let mounted = true;
37
+ startProgress();
38
+ networkOperation({
39
+ method: "GET",
40
+ endPoint: isAuth ? `dictionaries/${moduleId}` : `na/dictionaries/${moduleId}`,
41
+ parms: {
42
+ comps: componentsDictionary,
43
+ ...isAuth ? {} : {
44
+ domain_token
45
+ }
46
+ }
47
+ }).then((response) => {
48
+ if (mounted) {
49
+ setModuleDictionary({
50
+ ...response
51
+ });
52
+ addFlag("dictionary_loaded");
53
+ }
54
+ }).finally(() => {
55
+ stopProgress();
56
+ });
57
+ return function cleanUp() {
58
+ mounted = false;
59
+ };
60
+ }, [currentLang]);
61
+ const getLabel = useCallback((key) => {
62
+ if (moduleDictionary === void 0)
63
+ return "No dictionary";
64
+ if (key === void 0)
65
+ return "No key";
66
+ const parts = key.split(".");
67
+ if (parts.length === 2) {
68
+ if (moduleDictionary[parts[0]] && moduleDictionary[parts[0]][parts[1]]) {
69
+ return moduleDictionary[parts[0]][parts[1]];
70
+ }
71
+ } else if (parts.length === 1) {
72
+ if (moduleDictionary.data && moduleDictionary.data[key]) {
73
+ return moduleDictionary.data[key];
74
+ }
75
+ }
76
+ return `No dictionary:${key}`;
77
+ }, [moduleDictionary]);
78
+ const getModuleLabel = useCallback(() => getLabel(moduleName), [moduleName, getLabel]);
79
+ return /* @__PURE__ */ jsx(ModuleDictionaryContext.Provider, {
80
+ value: {
81
+ moduleDictionary,
82
+ getLabel,
83
+ getModuleLabel
84
+ },
85
+ children
86
+ });
87
+ }
88
+ export { ModuleDictionaryContext as M, ModuleDictionaryProvider as a };
@@ -0,0 +1,15 @@
1
+ import { ReactNode } from 'react';
2
+ import type { GetLabelType, ModuleDictionary } from 'src/types/dictionary';
3
+ export interface ModuleDictionaryProviderProps {
4
+ currentLang?: string;
5
+ isAuth?: boolean;
6
+ moduleId: number;
7
+ moduleName?: string;
8
+ componentsDictionary: string[];
9
+ children: ReactNode;
10
+ }
11
+ export interface ModuleDictionaryContextProps {
12
+ moduleDictionary?: ModuleDictionary;
13
+ getLabel: GetLabelType;
14
+ getModuleLabel: () => string;
15
+ }
@@ -0,0 +1,26 @@
1
+ import { createContext, useCallback } from "react";
2
+ import { u as useEnvironment } from "../../hooks/useEnvironment/index.js";
3
+ import { u as useHostTools } from "../../hooks/useHostTools/index.js";
4
+ import { jsx } from "react/jsx-runtime";
5
+ const initialValue = {
6
+ networkOperation: () => Promise.resolve()
7
+ };
8
+ const NetworkContext = createContext(initialValue);
9
+ function NetworkProvider(props) {
10
+ const {
11
+ children,
12
+ axiosOperation
13
+ } = props;
14
+ const environment = useEnvironment();
15
+ const hostTools = useHostTools();
16
+ const networkOperation = useCallback(async (networkProps) => {
17
+ return axiosOperation(networkProps, environment, hostTools);
18
+ }, [axiosOperation]);
19
+ return /* @__PURE__ */ jsx(NetworkContext.Provider, {
20
+ value: {
21
+ networkOperation
22
+ },
23
+ children
24
+ });
25
+ }
26
+ export { NetworkContext as N, NetworkProvider as a };
@@ -0,0 +1,5 @@
1
+ export { EnvironmentContext, EnvironmentProvider } from './EnvironmentContext';
2
+ export { HostToolsContext, HostToolsProvider } from './HostToolsContext';
3
+ export { NetworkContext, NetworkProvider } from './NetworkContext';
4
+ export { FlagsContext, FlagsProvider } from './FlagsContext';
5
+ export { ModuleDictionaryContext, ModuleDictionaryProvider } from './ModuleDictionaryContext';
@@ -1,18 +1,5 @@
1
- function getAugmentedNamespace(n) {
2
- if (n.__esModule)
3
- return n;
4
- var a = Object.defineProperty({}, "__esModule", { value: true });
5
- Object.keys(n).forEach(function(k) {
6
- var d = Object.getOwnPropertyDescriptor(n, k);
7
- Object.defineProperty(a, k, d.get ? d : {
8
- enumerable: true,
9
- get: function() {
10
- return n[k];
11
- }
12
- });
13
- });
14
- return a;
15
- }
1
+ import { s as snakecaseKeys } from "./snakecase-keys.js";
2
+ import { E as EmitEvents } from "../types/index.js";
16
3
  var axios$2 = { exports: {} };
17
4
  var bind$2 = function bind(fn, thisArg) {
18
5
  return function wrap() {
@@ -1232,4 +1219,81 @@ axios$1.isAxiosError = isAxiosError;
1232
1219
  axios$2.exports = axios$1;
1233
1220
  axios$2.exports.default = axios$1;
1234
1221
  var axios = axios$2.exports;
1235
- export { axios as a, getAugmentedNamespace as g };
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
+ } = props;
1280
+ let baseURL;
1281
+ if (isRemote) {
1282
+ baseURL = enviroment.host_api_remote;
1283
+ } else {
1284
+ baseURL = enviroment.host_api_local;
1285
+ }
1286
+ hostTools.startProgress();
1287
+ return axios({
1288
+ baseURL,
1289
+ withCredentials: isRemote,
1290
+ method,
1291
+ url: `/${endPoint}`,
1292
+ data: snakecaseKeys(data2, { deep: true }),
1293
+ params: snakecaseKeys(parms, { deep: true }),
1294
+ timeout
1295
+ }).then((response) => getResponse(endPoint, response)).catch((error) => Promise.reject(getError(error, hostTools, checkUnAuthorized))).finally(() => {
1296
+ hostTools.stopProgress();
1297
+ });
1298
+ };
1299
+ export { axiosOperation as a };
@@ -0,0 +1,18 @@
1
+ import { m as mapObj, r as require$$1 } from "../node_modules.js";
2
+ const map = mapObj.exports;
3
+ const { snakeCase } = require$$1;
4
+ var snakecaseKeys = function(obj, options) {
5
+ options = Object.assign({ deep: true, exclude: [], parsingOptions: {} }, options);
6
+ return map(obj, function(key, val) {
7
+ return [
8
+ matches(options.exclude, key) ? key : snakeCase(key, options.parsingOptions),
9
+ val
10
+ ];
11
+ }, options);
12
+ };
13
+ function matches(patterns, value) {
14
+ return patterns.some(function(pattern) {
15
+ return typeof pattern === "string" ? pattern === value : pattern.test(value);
16
+ });
17
+ }
18
+ export { snakecaseKeys as s };
@@ -0,0 +1,6 @@
1
+ export { useLocalStorage } from './useLocalStorage';
2
+ export { useHostTools } from './useHostTools';
3
+ export { useNetwork } from './useNetwork';
4
+ export { useEnvironment } from './useEnvironment';
5
+ export { useFlags, useFlagsPresent } from './useFlags';
6
+ export { useModuleDictionary } from './useModuleDictionary';
@@ -0,0 +1,9 @@
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 };
@@ -0,0 +1,9 @@
1
+ import { useContext } 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
+ export { useFlags as u };
@@ -0,0 +1,9 @@
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 };
@@ -0,0 +1,21 @@
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 };
@@ -0,0 +1 @@
1
+ export declare const useModuleDictionary: () => import("../../contexts/ModuleDictionaryContext/types").ModuleDictionaryContextProps;
@@ -0,0 +1,2 @@
1
+ import "react";
2
+ import "../../contexts/ModuleDictionaryContext/index.js";
@@ -0,0 +1,9 @@
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 };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './contexts';
1
2
  export { useEnvironment } from './hooks/useEnvironment';
2
3
  export { useFlags } from './hooks/useFlags';
3
4
  export { useHostTools } from './hooks/useHostTools';
package/dist/index.js CHANGED
@@ -1,189 +1,18 @@
1
- import { createContext, useContext, useState } from "react";
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";
4
+ export { F as FlagsContext, a as FlagsProvider } from "./contexts/FlagsContext/index.js";
5
+ export { M as ModuleDictionaryContext, a as ModuleDictionaryProvider } from "./contexts/ModuleDictionaryContext/index.js";
6
+ export { u as useEnvironment } from "./hooks/useEnvironment/index.js";
7
+ export { u as useFlags } from "./hooks/useFlags/index.js";
8
+ export { u as useHostTools } from "./hooks/useHostTools/index.js";
9
+ export { u as useLocalStorage } from "./hooks/useLocalStorage/index.js";
10
+ export { u as useNetwork } from "./hooks/useNetwork/index.js";
11
+ export { E as EmitEvents } from "./types/index.js";
12
+ export { a as getLocalStorage, g as getPropertyByString, s as setLocalStorage, v as voidFunction } from "./utils/index.js";
13
+ export { a as axiosOperation } from "./external/axios.js";
14
+ import "react";
2
15
  import "react/jsx-runtime";
3
- import { a as axios } from "./axios.js";
4
- import { s as snakecaseKeys } from "./snakecase-keys.js";
5
- const initialValue$2 = {
6
- isLocalhost: true,
7
- host: "",
8
- domain_token: "",
9
- host_api_local: "",
10
- host_api_remote: "",
11
- host_static_assets: "",
12
- environment: ""
13
- };
14
- const EnvironmentContext = createContext(initialValue$2);
15
- const useEnvironment = () => {
16
- const context = useContext(EnvironmentContext);
17
- if (!context)
18
- throw new Error("useEnvironment context must be use inside EnvironmentContext");
19
- return context;
20
- };
21
- function voidFunction() {
22
- }
23
- const initialState = {
24
- flags: [],
25
- clearFlags: voidFunction,
26
- addFlag: voidFunction
27
- };
28
- const FlagsContext = createContext(initialState);
29
- const useFlags = () => {
30
- const context = useContext(FlagsContext);
31
- if (!context)
32
- throw new Error("useFlags context must be use inside FlagsProvider");
33
- return context;
34
- };
35
- const initialValue$1 = {
36
- toast: () => 0,
37
- startProgress: voidFunction,
38
- stopProgress: voidFunction,
39
- events_add_listener: voidFunction,
40
- events_remove_listener: voidFunction,
41
- events_emit: voidFunction
42
- };
43
- const HostToolsContext = createContext(initialValue$1);
44
- const useHostTools = () => {
45
- const context = useContext(HostToolsContext);
46
- if (!context)
47
- throw new Error("useHostTools context must be use inside HostToolsContext");
48
- return context;
49
- };
50
- function useLocalStorage(key, initialValue2) {
51
- const [value, setValue] = useState(() => {
52
- try {
53
- const item = window.localStorage.getItem(key);
54
- return item !== null ? JSON.parse(item) : initialValue2;
55
- } catch (e) {
56
- return initialValue2;
57
- }
58
- });
59
- const setValueInLocalStorage = (newValue) => {
60
- try {
61
- window.localStorage.setItem(key, JSON.stringify(newValue));
62
- setValue(newValue);
63
- } catch (e) {
64
- console.error(e);
65
- }
66
- };
67
- return [value, setValueInLocalStorage];
68
- }
69
- const initialValue = {
70
- networkOperation: () => Promise.resolve()
71
- };
72
- const NetworkContext = createContext(initialValue);
73
- const useNetwork = () => {
74
- const context = useContext(NetworkContext);
75
- if (!context)
76
- throw new Error("useNetwork context must be use inside NetworkContext");
77
- return context;
78
- };
79
- var EmitEvents = /* @__PURE__ */ ((EmitEvents2) => {
80
- EmitEvents2["EMMIT_EVENT_NET_SERVICE_UNAUTHORIZED"] = `netsevice_unauthorized`;
81
- EmitEvents2["EMMIT_EVENT_HOST_THEME_CHANGE"] = "host_theme_change";
82
- return EmitEvents2;
83
- })(EmitEvents || {});
84
- function getPropertyByString(object, propString) {
85
- let value = object;
86
- const props = propString.split(".");
87
- for (let index = 0; index < props.length; index += 1) {
88
- if (props[index] === void 0)
89
- break;
90
- value = value[props[index]];
91
- }
92
- return value;
93
- }
94
- function getLocalStorage(key, initialValue2) {
95
- try {
96
- const item = window.localStorage.getItem(key);
97
- return item !== null ? JSON.parse(item) : initialValue2;
98
- } catch (e) {
99
- return initialValue2;
100
- }
101
- }
102
- function setLocalStorage(key, value) {
103
- try {
104
- const item = window.localStorage.getItem(key);
105
- let newValue = item !== null ? JSON.parse(item) : {};
106
- newValue = { ...newValue, ...value };
107
- window.localStorage.setItem(key, JSON.stringify(newValue));
108
- } catch (e) {
109
- console.error(e);
110
- }
111
- }
112
- function getResponse(endPoint, response) {
113
- console.log("Axios response", response, typeof response.data);
114
- if (response && response.data && typeof response.data === "object") {
115
- if (response.data.error && response.data.error?.code && response.data.error?.msg !== void 0) {
116
- return Promise.reject({ ...response.data.error, status: response.status });
117
- }
118
- return response.data;
119
- }
120
- return Promise.reject({
121
- code: 1,
122
- msg: `Incorrect endpoint: ${endPoint}`,
123
- status: response.status
124
- });
125
- }
126
- function getError(error, hostTools, checkUnAuthorized = true) {
127
- const { toast } = hostTools;
128
- let err = {
129
- message: "",
130
- status: 1,
131
- code: 0
132
- };
133
- console.log("getError", error);
134
- if (error?.code !== void 0 && err.status !== void 0 && error.message !== void 0) {
135
- err = { ...err, ...error };
136
- } else if (error?.response) {
137
- 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) {
138
- err = { ...error.response.data.error, status: error.response.status };
139
- } else {
140
- err.message = error.message;
141
- err.status = error.response.status;
142
- err.code = 0;
143
- }
144
- if (checkUnAuthorized && error.response.status === 401) {
145
- hostTools.events_emit(EmitEvents.EMMIT_EVENT_NET_SERVICE_UNAUTHORIZED, {});
146
- }
147
- } else if (error?.request) {
148
- err.message = `${error?.code} ${error.message}`;
149
- err.code = -1;
150
- } else {
151
- err.message = `${error?.code} ${error.message}`;
152
- err.status = 0;
153
- err.code = -2;
154
- }
155
- if (checkUnAuthorized) {
156
- toast(`${err.message} - status: ${err.status} - code: ${err.code}`, { type: "error" });
157
- }
158
- return err;
159
- }
160
- const axiosOperation = async (props, enviroment, hostTools) => {
161
- const {
162
- method,
163
- endPoint,
164
- timeout = 5e3,
165
- parms = {},
166
- data = {},
167
- isRemote = true,
168
- checkUnAuthorized = true
169
- } = props;
170
- let baseURL;
171
- if (isRemote) {
172
- baseURL = enviroment.host_api_remote;
173
- } else {
174
- baseURL = enviroment.host_api_local;
175
- }
176
- hostTools.startProgress();
177
- return axios({
178
- baseURL,
179
- withCredentials: isRemote,
180
- method,
181
- url: `/${endPoint}`,
182
- data: snakecaseKeys(data, { deep: true }),
183
- params: snakecaseKeys(parms, { deep: true }),
184
- timeout
185
- }).then((response) => getResponse(endPoint, response)).catch((error) => Promise.reject(getError(error, hostTools, checkUnAuthorized))).finally(() => {
186
- hostTools.stopProgress();
187
- });
188
- };
189
- export { EmitEvents, axiosOperation, getLocalStorage, getPropertyByString, setLocalStorage, useEnvironment, useFlags, useHostTools, useLocalStorage, useNetwork, voidFunction };
16
+ import "./node_modules.js";
17
+ import "./vendor.js";
18
+ import "./external/snakecase-keys.js";
@@ -1,4 +1,4 @@
1
- import { g as getAugmentedNamespace } from "./axios.js";
1
+ import { g as getAugmentedNamespace } from "./vendor.js";
2
2
  var mapObj = { exports: {} };
3
3
  const isObject = (value) => typeof value === "object" && value !== null;
4
4
  const mapObjectSkip = Symbol("skip");
@@ -86,7 +86,7 @@ function dotCase(input, options) {
86
86
  }
87
87
  return noCase(input, __assign({ delimiter: "." }, options));
88
88
  }
89
- function snakeCase$1(input, options) {
89
+ function snakeCase(input, options) {
90
90
  if (options === void 0) {
91
91
  options = {};
92
92
  }
@@ -94,23 +94,7 @@ function snakeCase$1(input, options) {
94
94
  }
95
95
  const dist_es2015 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
96
96
  __proto__: null,
97
- snakeCase: snakeCase$1
97
+ snakeCase
98
98
  }, Symbol.toStringTag, { value: "Module" }));
99
99
  const require$$1 = /* @__PURE__ */ getAugmentedNamespace(dist_es2015);
100
- const map = mapObj.exports;
101
- const { snakeCase } = require$$1;
102
- var snakecaseKeys = function(obj, options) {
103
- options = Object.assign({ deep: true, exclude: [], parsingOptions: {} }, options);
104
- return map(obj, function(key, val) {
105
- return [
106
- matches(options.exclude, key) ? key : snakeCase(key, options.parsingOptions),
107
- val
108
- ];
109
- }, options);
110
- };
111
- function matches(patterns, value) {
112
- return patterns.some(function(pattern) {
113
- return typeof pattern === "string" ? pattern === value : pattern.test(value);
114
- });
115
- }
116
- export { snakecaseKeys as s };
100
+ export { mapObj as m, require$$1 as r };
@@ -0,0 +1,6 @@
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 };
@@ -0,0 +1,33 @@
1
+ import "../external/axios.js";
2
+ import "../node_modules.js";
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 };
package/dist/vendor.js ADDED
@@ -0,0 +1,30 @@
1
+ import "react";
2
+ import "./contexts/HostToolsContext/index.js";
3
+ import "./contexts/NetworkContext/index.js";
4
+ import "./contexts/EnvironmentContext/index.js";
5
+ import "./contexts/FlagsContext/index.js";
6
+ import "./contexts/ModuleDictionaryContext/index.js";
7
+ import "./hooks/useEnvironment/index.js";
8
+ import "./hooks/useFlags/index.js";
9
+ import "./hooks/useHostTools/index.js";
10
+ import "./hooks/useLocalStorage/index.js";
11
+ import "./hooks/useNetwork/index.js";
12
+ import "./types/index.js";
13
+ import "./utils/index.js";
14
+ import "./external/axios.js";
15
+ function getAugmentedNamespace(n) {
16
+ if (n.__esModule)
17
+ return n;
18
+ var a = Object.defineProperty({}, "__esModule", { value: true });
19
+ Object.keys(n).forEach(function(k) {
20
+ var d = Object.getOwnPropertyDescriptor(n, k);
21
+ Object.defineProperty(a, k, d.get ? d : {
22
+ enumerable: true,
23
+ get: function() {
24
+ return n[k];
25
+ }
26
+ });
27
+ });
28
+ return a;
29
+ }
30
+ export { getAugmentedNamespace as g };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@m4l/core",
3
3
  "private": false,
4
- "version": "0.0.20",
4
+ "version": "0.0.23",
5
5
  "license": "UNLICENSED",
6
6
  "author": "M4L Team",
7
7
  "scripts": {