@m4l/core 0.0.20 → 0.0.21
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/EnvironmentContext.js +13 -0
- package/dist/HostToolsContext.js +13 -0
- package/dist/NetworkContext.js +9 -0
- package/dist/axios.js +80 -16
- package/dist/index.d.ts +0 -1
- package/dist/index.js +12 -188
- package/dist/snakecase-keys.js +1 -99
- package/dist/useEnvironment.js +9 -0
- package/dist/useHostTools.js +9 -0
- package/dist/useLocalStorage.js +21 -0
- package/dist/useNetwork.js +9 -0
- package/dist/vendor.js +153 -0
- package/dist/voidFunction.js +3 -0
- package/package.json +1 -1
- package/dist/contexts/FlagsContext/index.d.ts +0 -5
- package/dist/contexts/FlagsContext/types.d.ts +0 -10
- package/dist/hooks/useFlags/index.d.ts +0 -3
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createContext } from "react";
|
|
2
|
+
import "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
|
+
export { EnvironmentContext as E };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createContext } from "react";
|
|
2
|
+
import { v as voidFunction } from "./voidFunction.js";
|
|
3
|
+
import "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
|
+
export { HostToolsContext as H };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createContext } from "react";
|
|
2
|
+
import "./EnvironmentContext.js";
|
|
3
|
+
import "./HostToolsContext.js";
|
|
4
|
+
import "react/jsx-runtime";
|
|
5
|
+
const initialValue = {
|
|
6
|
+
networkOperation: () => Promise.resolve()
|
|
7
|
+
};
|
|
8
|
+
const NetworkContext = createContext(initialValue);
|
|
9
|
+
export { NetworkContext as N };
|
package/dist/axios.js
CHANGED
|
@@ -1,18 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 "./vendor.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
|
-
|
|
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 };
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,189 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
export { u as useEnvironment } from "./useEnvironment.js";
|
|
2
|
+
export { u as useHostTools } from "./useHostTools.js";
|
|
3
|
+
export { u as useLocalStorage } from "./useLocalStorage.js";
|
|
4
|
+
export { u as useNetwork } from "./useNetwork.js";
|
|
5
|
+
export { E as EmitEvents, a as getLocalStorage, g as getPropertyByString, s as setLocalStorage } from "./vendor.js";
|
|
6
|
+
export { v as voidFunction } from "./voidFunction.js";
|
|
7
|
+
export { a as axiosOperation } from "./axios.js";
|
|
8
|
+
import "react";
|
|
9
|
+
import "./EnvironmentContext.js";
|
|
2
10
|
import "react/jsx-runtime";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
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 };
|
|
11
|
+
import "./HostToolsContext.js";
|
|
12
|
+
import "./NetworkContext.js";
|
|
13
|
+
import "./snakecase-keys.js";
|
package/dist/snakecase-keys.js
CHANGED
|
@@ -1,102 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
var mapObj = { exports: {} };
|
|
3
|
-
const isObject = (value) => typeof value === "object" && value !== null;
|
|
4
|
-
const mapObjectSkip = Symbol("skip");
|
|
5
|
-
const isObjectCustom = (value) => isObject(value) && !(value instanceof RegExp) && !(value instanceof Error) && !(value instanceof Date);
|
|
6
|
-
const mapObject = (object, mapper, options, isSeen = /* @__PURE__ */ new WeakMap()) => {
|
|
7
|
-
options = {
|
|
8
|
-
deep: false,
|
|
9
|
-
target: {},
|
|
10
|
-
...options
|
|
11
|
-
};
|
|
12
|
-
if (isSeen.has(object)) {
|
|
13
|
-
return isSeen.get(object);
|
|
14
|
-
}
|
|
15
|
-
isSeen.set(object, options.target);
|
|
16
|
-
const { target } = options;
|
|
17
|
-
delete options.target;
|
|
18
|
-
const mapArray = (array) => array.map((element) => isObjectCustom(element) ? mapObject(element, mapper, options, isSeen) : element);
|
|
19
|
-
if (Array.isArray(object)) {
|
|
20
|
-
return mapArray(object);
|
|
21
|
-
}
|
|
22
|
-
for (const [key, value] of Object.entries(object)) {
|
|
23
|
-
const mapResult = mapper(key, value, object);
|
|
24
|
-
if (mapResult === mapObjectSkip) {
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
let [newKey, newValue, { shouldRecurse = true } = {}] = mapResult;
|
|
28
|
-
if (newKey === "__proto__") {
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
if (options.deep && shouldRecurse && isObjectCustom(newValue)) {
|
|
32
|
-
newValue = Array.isArray(newValue) ? mapArray(newValue) : mapObject(newValue, mapper, options, isSeen);
|
|
33
|
-
}
|
|
34
|
-
target[newKey] = newValue;
|
|
35
|
-
}
|
|
36
|
-
return target;
|
|
37
|
-
};
|
|
38
|
-
mapObj.exports = (object, mapper, options) => {
|
|
39
|
-
if (!isObject(object)) {
|
|
40
|
-
throw new TypeError(`Expected an object, got \`${object}\` (${typeof object})`);
|
|
41
|
-
}
|
|
42
|
-
return mapObject(object, mapper, options);
|
|
43
|
-
};
|
|
44
|
-
mapObj.exports.mapObjectSkip = mapObjectSkip;
|
|
45
|
-
var __assign = function() {
|
|
46
|
-
__assign = Object.assign || function __assign2(t) {
|
|
47
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
48
|
-
s = arguments[i];
|
|
49
|
-
for (var p in s)
|
|
50
|
-
if (Object.prototype.hasOwnProperty.call(s, p))
|
|
51
|
-
t[p] = s[p];
|
|
52
|
-
}
|
|
53
|
-
return t;
|
|
54
|
-
};
|
|
55
|
-
return __assign.apply(this, arguments);
|
|
56
|
-
};
|
|
57
|
-
function lowerCase(str) {
|
|
58
|
-
return str.toLowerCase();
|
|
59
|
-
}
|
|
60
|
-
var DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g];
|
|
61
|
-
var DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;
|
|
62
|
-
function noCase(input, options) {
|
|
63
|
-
if (options === void 0) {
|
|
64
|
-
options = {};
|
|
65
|
-
}
|
|
66
|
-
var _a = options.splitRegexp, splitRegexp = _a === void 0 ? DEFAULT_SPLIT_REGEXP : _a, _b = options.stripRegexp, stripRegexp = _b === void 0 ? DEFAULT_STRIP_REGEXP : _b, _c = options.transform, transform = _c === void 0 ? lowerCase : _c, _d = options.delimiter, delimiter = _d === void 0 ? " " : _d;
|
|
67
|
-
var result = replace(replace(input, splitRegexp, "$1\0$2"), stripRegexp, "\0");
|
|
68
|
-
var start = 0;
|
|
69
|
-
var end = result.length;
|
|
70
|
-
while (result.charAt(start) === "\0")
|
|
71
|
-
start++;
|
|
72
|
-
while (result.charAt(end - 1) === "\0")
|
|
73
|
-
end--;
|
|
74
|
-
return result.slice(start, end).split("\0").map(transform).join(delimiter);
|
|
75
|
-
}
|
|
76
|
-
function replace(input, re, value) {
|
|
77
|
-
if (re instanceof RegExp)
|
|
78
|
-
return input.replace(re, value);
|
|
79
|
-
return re.reduce(function(input2, re2) {
|
|
80
|
-
return input2.replace(re2, value);
|
|
81
|
-
}, input);
|
|
82
|
-
}
|
|
83
|
-
function dotCase(input, options) {
|
|
84
|
-
if (options === void 0) {
|
|
85
|
-
options = {};
|
|
86
|
-
}
|
|
87
|
-
return noCase(input, __assign({ delimiter: "." }, options));
|
|
88
|
-
}
|
|
89
|
-
function snakeCase$1(input, options) {
|
|
90
|
-
if (options === void 0) {
|
|
91
|
-
options = {};
|
|
92
|
-
}
|
|
93
|
-
return dotCase(input, __assign({ delimiter: "_" }, options));
|
|
94
|
-
}
|
|
95
|
-
const dist_es2015 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
96
|
-
__proto__: null,
|
|
97
|
-
snakeCase: snakeCase$1
|
|
98
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
99
|
-
const require$$1 = /* @__PURE__ */ getAugmentedNamespace(dist_es2015);
|
|
1
|
+
import { m as mapObj, r as require$$1 } from "./vendor.js";
|
|
100
2
|
const map = mapObj.exports;
|
|
101
3
|
const { snakeCase } = require$$1;
|
|
102
4
|
var snakecaseKeys = function(obj, options) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { E as EnvironmentContext } from "./EnvironmentContext.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 { H as HostToolsContext } from "./HostToolsContext.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,9 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { N as NetworkContext } from "./NetworkContext.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/vendor.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import "./axios.js";
|
|
2
|
+
import "./useEnvironment.js";
|
|
3
|
+
import "./useHostTools.js";
|
|
4
|
+
import "./useLocalStorage.js";
|
|
5
|
+
import "./useNetwork.js";
|
|
6
|
+
import "./voidFunction.js";
|
|
7
|
+
var EmitEvents = /* @__PURE__ */ ((EmitEvents2) => {
|
|
8
|
+
EmitEvents2["EMMIT_EVENT_NET_SERVICE_UNAUTHORIZED"] = `netsevice_unauthorized`;
|
|
9
|
+
EmitEvents2["EMMIT_EVENT_HOST_THEME_CHANGE"] = "host_theme_change";
|
|
10
|
+
return EmitEvents2;
|
|
11
|
+
})(EmitEvents || {});
|
|
12
|
+
function getPropertyByString(object, propString) {
|
|
13
|
+
let value = object;
|
|
14
|
+
const props = propString.split(".");
|
|
15
|
+
for (let index = 0; index < props.length; index += 1) {
|
|
16
|
+
if (props[index] === void 0)
|
|
17
|
+
break;
|
|
18
|
+
value = value[props[index]];
|
|
19
|
+
}
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
function getLocalStorage(key, initialValue) {
|
|
23
|
+
try {
|
|
24
|
+
const item = window.localStorage.getItem(key);
|
|
25
|
+
return item !== null ? JSON.parse(item) : initialValue;
|
|
26
|
+
} catch (e) {
|
|
27
|
+
return initialValue;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function setLocalStorage(key, value) {
|
|
31
|
+
try {
|
|
32
|
+
const item = window.localStorage.getItem(key);
|
|
33
|
+
let newValue = item !== null ? JSON.parse(item) : {};
|
|
34
|
+
newValue = { ...newValue, ...value };
|
|
35
|
+
window.localStorage.setItem(key, JSON.stringify(newValue));
|
|
36
|
+
} catch (e) {
|
|
37
|
+
console.error(e);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function getAugmentedNamespace(n) {
|
|
41
|
+
if (n.__esModule)
|
|
42
|
+
return n;
|
|
43
|
+
var a = Object.defineProperty({}, "__esModule", { value: true });
|
|
44
|
+
Object.keys(n).forEach(function(k) {
|
|
45
|
+
var d = Object.getOwnPropertyDescriptor(n, k);
|
|
46
|
+
Object.defineProperty(a, k, d.get ? d : {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
get: function() {
|
|
49
|
+
return n[k];
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
return a;
|
|
54
|
+
}
|
|
55
|
+
var mapObj = { exports: {} };
|
|
56
|
+
const isObject = (value) => typeof value === "object" && value !== null;
|
|
57
|
+
const mapObjectSkip = Symbol("skip");
|
|
58
|
+
const isObjectCustom = (value) => isObject(value) && !(value instanceof RegExp) && !(value instanceof Error) && !(value instanceof Date);
|
|
59
|
+
const mapObject = (object, mapper, options, isSeen = /* @__PURE__ */ new WeakMap()) => {
|
|
60
|
+
options = {
|
|
61
|
+
deep: false,
|
|
62
|
+
target: {},
|
|
63
|
+
...options
|
|
64
|
+
};
|
|
65
|
+
if (isSeen.has(object)) {
|
|
66
|
+
return isSeen.get(object);
|
|
67
|
+
}
|
|
68
|
+
isSeen.set(object, options.target);
|
|
69
|
+
const { target } = options;
|
|
70
|
+
delete options.target;
|
|
71
|
+
const mapArray = (array) => array.map((element) => isObjectCustom(element) ? mapObject(element, mapper, options, isSeen) : element);
|
|
72
|
+
if (Array.isArray(object)) {
|
|
73
|
+
return mapArray(object);
|
|
74
|
+
}
|
|
75
|
+
for (const [key, value] of Object.entries(object)) {
|
|
76
|
+
const mapResult = mapper(key, value, object);
|
|
77
|
+
if (mapResult === mapObjectSkip) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
let [newKey, newValue, { shouldRecurse = true } = {}] = mapResult;
|
|
81
|
+
if (newKey === "__proto__") {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (options.deep && shouldRecurse && isObjectCustom(newValue)) {
|
|
85
|
+
newValue = Array.isArray(newValue) ? mapArray(newValue) : mapObject(newValue, mapper, options, isSeen);
|
|
86
|
+
}
|
|
87
|
+
target[newKey] = newValue;
|
|
88
|
+
}
|
|
89
|
+
return target;
|
|
90
|
+
};
|
|
91
|
+
mapObj.exports = (object, mapper, options) => {
|
|
92
|
+
if (!isObject(object)) {
|
|
93
|
+
throw new TypeError(`Expected an object, got \`${object}\` (${typeof object})`);
|
|
94
|
+
}
|
|
95
|
+
return mapObject(object, mapper, options);
|
|
96
|
+
};
|
|
97
|
+
mapObj.exports.mapObjectSkip = mapObjectSkip;
|
|
98
|
+
var __assign = function() {
|
|
99
|
+
__assign = Object.assign || function __assign2(t) {
|
|
100
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
101
|
+
s = arguments[i];
|
|
102
|
+
for (var p in s)
|
|
103
|
+
if (Object.prototype.hasOwnProperty.call(s, p))
|
|
104
|
+
t[p] = s[p];
|
|
105
|
+
}
|
|
106
|
+
return t;
|
|
107
|
+
};
|
|
108
|
+
return __assign.apply(this, arguments);
|
|
109
|
+
};
|
|
110
|
+
function lowerCase(str) {
|
|
111
|
+
return str.toLowerCase();
|
|
112
|
+
}
|
|
113
|
+
var DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g];
|
|
114
|
+
var DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;
|
|
115
|
+
function noCase(input, options) {
|
|
116
|
+
if (options === void 0) {
|
|
117
|
+
options = {};
|
|
118
|
+
}
|
|
119
|
+
var _a = options.splitRegexp, splitRegexp = _a === void 0 ? DEFAULT_SPLIT_REGEXP : _a, _b = options.stripRegexp, stripRegexp = _b === void 0 ? DEFAULT_STRIP_REGEXP : _b, _c = options.transform, transform = _c === void 0 ? lowerCase : _c, _d = options.delimiter, delimiter = _d === void 0 ? " " : _d;
|
|
120
|
+
var result = replace(replace(input, splitRegexp, "$1\0$2"), stripRegexp, "\0");
|
|
121
|
+
var start = 0;
|
|
122
|
+
var end = result.length;
|
|
123
|
+
while (result.charAt(start) === "\0")
|
|
124
|
+
start++;
|
|
125
|
+
while (result.charAt(end - 1) === "\0")
|
|
126
|
+
end--;
|
|
127
|
+
return result.slice(start, end).split("\0").map(transform).join(delimiter);
|
|
128
|
+
}
|
|
129
|
+
function replace(input, re, value) {
|
|
130
|
+
if (re instanceof RegExp)
|
|
131
|
+
return input.replace(re, value);
|
|
132
|
+
return re.reduce(function(input2, re2) {
|
|
133
|
+
return input2.replace(re2, value);
|
|
134
|
+
}, input);
|
|
135
|
+
}
|
|
136
|
+
function dotCase(input, options) {
|
|
137
|
+
if (options === void 0) {
|
|
138
|
+
options = {};
|
|
139
|
+
}
|
|
140
|
+
return noCase(input, __assign({ delimiter: "." }, options));
|
|
141
|
+
}
|
|
142
|
+
function snakeCase(input, options) {
|
|
143
|
+
if (options === void 0) {
|
|
144
|
+
options = {};
|
|
145
|
+
}
|
|
146
|
+
return dotCase(input, __assign({ delimiter: "_" }, options));
|
|
147
|
+
}
|
|
148
|
+
const dist_es2015 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
149
|
+
__proto__: null,
|
|
150
|
+
snakeCase
|
|
151
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
152
|
+
const require$$1 = /* @__PURE__ */ getAugmentedNamespace(dist_es2015);
|
|
153
|
+
export { EmitEvents as E, getLocalStorage as a, getPropertyByString as g, mapObj as m, require$$1 as r, setLocalStorage as s };
|
package/package.json
CHANGED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { FlagsContextProps, FlagsProviderProps } from './types';
|
|
3
|
-
declare const FlagsContext: import("react").Context<FlagsContextProps>;
|
|
4
|
-
declare function FlagsProvider({ children }: FlagsProviderProps): JSX.Element;
|
|
5
|
-
export { FlagsProvider, FlagsContext };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
export interface FlagsProviderProps {
|
|
3
|
-
children: ReactNode;
|
|
4
|
-
}
|
|
5
|
-
export declare type Flag = string;
|
|
6
|
-
export interface FlagsContextProps {
|
|
7
|
-
flags: Array<Flag>;
|
|
8
|
-
clearFlags: () => void;
|
|
9
|
-
addFlag: (flag: Flag) => void;
|
|
10
|
-
}
|