akeyless-client-commons 1.1.11 → 1.1.12
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/hooks/index.d.mts +14 -15
- package/dist/hooks/index.d.ts +14 -15
- package/dist/hooks/index.js +118 -82
- package/dist/hooks/index.mjs +116 -80
- package/package.json +1 -1
package/dist/hooks/index.d.mts
CHANGED
|
@@ -31,27 +31,26 @@ declare const useSnapshotBulk: (configs: OnSnapshotConfig[], label?: string, set
|
|
|
31
31
|
cleanupForConfigChange?: boolean;
|
|
32
32
|
disableLogs?: boolean;
|
|
33
33
|
}) => void;
|
|
34
|
+
declare const useSmartSnapshot: (configs: OnSnapshotConfig[], label?: string, settings?: {
|
|
35
|
+
cleanupForConfigChange?: boolean;
|
|
36
|
+
disableLogs?: boolean;
|
|
37
|
+
}) => {
|
|
38
|
+
groupedConfig: {
|
|
39
|
+
configForDb: any[];
|
|
40
|
+
configForCache: any[];
|
|
41
|
+
};
|
|
42
|
+
socketConnected: boolean;
|
|
43
|
+
};
|
|
34
44
|
declare const useSetUserCountry: (setUserCountry: Dispatch<SetStateAction<CountryOptions>>, changLang: (lang: string) => void) => any;
|
|
35
45
|
|
|
36
46
|
declare function useSafeEffect(callback: () => void, dependencies: any[], error_message?: string): void;
|
|
37
47
|
declare const useDeepCompareMemo: <T>(factory: () => T, dependencies: any[]) => T;
|
|
38
48
|
declare function useDeepCompareEffect(effect: EffectCallback, dependencies: any[]): void;
|
|
39
49
|
|
|
40
|
-
declare const useSocketSubscription: (config: OnSnapshotConfig[]
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
label?: string;
|
|
45
|
-
settings?: {
|
|
46
|
-
cleanupForConfigChange?: boolean;
|
|
47
|
-
disableLogs?: boolean;
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
declare const useSmartSnapshot: (configs: OnSnapshotConfig[], options?: UseSmartSubscriptionSettings) => {
|
|
51
|
-
groupedConfig: {
|
|
52
|
-
configForDb: any[];
|
|
53
|
-
configForCache: any[];
|
|
54
|
-
};
|
|
50
|
+
declare const useSocketSubscription: (config: OnSnapshotConfig[], label?: string, settings?: {
|
|
51
|
+
cleanupForConfigChange?: boolean;
|
|
52
|
+
disableLogs?: boolean;
|
|
53
|
+
}) => {
|
|
55
54
|
socketConnected: boolean;
|
|
56
55
|
};
|
|
57
56
|
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -31,27 +31,26 @@ declare const useSnapshotBulk: (configs: OnSnapshotConfig[], label?: string, set
|
|
|
31
31
|
cleanupForConfigChange?: boolean;
|
|
32
32
|
disableLogs?: boolean;
|
|
33
33
|
}) => void;
|
|
34
|
+
declare const useSmartSnapshot: (configs: OnSnapshotConfig[], label?: string, settings?: {
|
|
35
|
+
cleanupForConfigChange?: boolean;
|
|
36
|
+
disableLogs?: boolean;
|
|
37
|
+
}) => {
|
|
38
|
+
groupedConfig: {
|
|
39
|
+
configForDb: any[];
|
|
40
|
+
configForCache: any[];
|
|
41
|
+
};
|
|
42
|
+
socketConnected: boolean;
|
|
43
|
+
};
|
|
34
44
|
declare const useSetUserCountry: (setUserCountry: Dispatch<SetStateAction<CountryOptions>>, changLang: (lang: string) => void) => any;
|
|
35
45
|
|
|
36
46
|
declare function useSafeEffect(callback: () => void, dependencies: any[], error_message?: string): void;
|
|
37
47
|
declare const useDeepCompareMemo: <T>(factory: () => T, dependencies: any[]) => T;
|
|
38
48
|
declare function useDeepCompareEffect(effect: EffectCallback, dependencies: any[]): void;
|
|
39
49
|
|
|
40
|
-
declare const useSocketSubscription: (config: OnSnapshotConfig[]
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
label?: string;
|
|
45
|
-
settings?: {
|
|
46
|
-
cleanupForConfigChange?: boolean;
|
|
47
|
-
disableLogs?: boolean;
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
declare const useSmartSnapshot: (configs: OnSnapshotConfig[], options?: UseSmartSubscriptionSettings) => {
|
|
51
|
-
groupedConfig: {
|
|
52
|
-
configForDb: any[];
|
|
53
|
-
configForCache: any[];
|
|
54
|
-
};
|
|
50
|
+
declare const useSocketSubscription: (config: OnSnapshotConfig[], label?: string, settings?: {
|
|
51
|
+
cleanupForConfigChange?: boolean;
|
|
52
|
+
disableLogs?: boolean;
|
|
53
|
+
}) => {
|
|
55
54
|
socketConnected: boolean;
|
|
56
55
|
};
|
|
57
56
|
|
package/dist/hooks/index.js
CHANGED
|
@@ -7,6 +7,9 @@ function _array_like_to_array(arr, len) {
|
|
|
7
7
|
function _array_with_holes(arr) {
|
|
8
8
|
if (Array.isArray(arr)) return arr;
|
|
9
9
|
}
|
|
10
|
+
function _array_without_holes(arr) {
|
|
11
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
12
|
+
}
|
|
10
13
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
11
14
|
try {
|
|
12
15
|
var info = gen[key](arg);
|
|
@@ -68,6 +71,9 @@ function _define_property(obj, key, value) {
|
|
|
68
71
|
}
|
|
69
72
|
return obj;
|
|
70
73
|
}
|
|
74
|
+
function _iterable_to_array(iter) {
|
|
75
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
76
|
+
}
|
|
71
77
|
function _iterable_to_array_limit(arr, i) {
|
|
72
78
|
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
73
79
|
if (_i == null) return;
|
|
@@ -95,6 +101,9 @@ function _iterable_to_array_limit(arr, i) {
|
|
|
95
101
|
function _non_iterable_rest() {
|
|
96
102
|
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
97
103
|
}
|
|
104
|
+
function _non_iterable_spread() {
|
|
105
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
106
|
+
}
|
|
98
107
|
function _object_spread(target) {
|
|
99
108
|
for(var i = 1; i < arguments.length; i++){
|
|
100
109
|
var source = arguments[i] != null ? arguments[i] : {};
|
|
@@ -137,6 +146,9 @@ function _object_spread_props(target, source) {
|
|
|
137
146
|
function _sliced_to_array(arr, i) {
|
|
138
147
|
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
139
148
|
}
|
|
149
|
+
function _to_consumable_array(arr) {
|
|
150
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
151
|
+
}
|
|
140
152
|
function _type_of(obj) {
|
|
141
153
|
"@swc/helpers - typeof";
|
|
142
154
|
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
@@ -333,7 +345,7 @@ __export(index_exports, {
|
|
|
333
345
|
module.exports = __toCommonJS(index_exports);
|
|
334
346
|
// src/hooks/global.ts
|
|
335
347
|
var import_akeyless_types_commons2 = require("akeyless-types-commons");
|
|
336
|
-
var
|
|
348
|
+
var import_react5 = require("react");
|
|
337
349
|
// src/helpers/firebase.ts
|
|
338
350
|
var import_moment = __toESM(require("moment"));
|
|
339
351
|
var import_app = require("firebase/app");
|
|
@@ -927,9 +939,65 @@ function useDeepCompareEffect(effect, dependencies) {
|
|
|
927
939
|
previousDepsRef.current
|
|
928
940
|
]);
|
|
929
941
|
}
|
|
942
|
+
// src/hooks/socket.ts
|
|
943
|
+
var import_react3 = require("react");
|
|
944
|
+
var useSocketSubscription = function(config, label, settings) {
|
|
945
|
+
var _ref = _sliced_to_array((0, import_react3.useState)(socketServiceInstance.isConnected()), 2), socketConnected = _ref[0], setSocketConnected = _ref[1];
|
|
946
|
+
var _ref1 = _sliced_to_array((0, import_react3.useState)([]), 2), cleanupSubscriptions = _ref1[0], setCleanupSubscriptions = _ref1[1];
|
|
947
|
+
useDeepCompareEffect(function() {
|
|
948
|
+
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
|
|
949
|
+
console.log("==> ".concat(label || "Custom snapshots", " started from cache... "));
|
|
950
|
+
}
|
|
951
|
+
if (socketConnected) {
|
|
952
|
+
setCleanupSubscriptions(function(prev) {
|
|
953
|
+
return _to_consumable_array(prev).concat([
|
|
954
|
+
socketServiceInstance.subscribeToCollections(config)
|
|
955
|
+
]);
|
|
956
|
+
});
|
|
957
|
+
} else {
|
|
958
|
+
socketServiceInstance.getSocketInstance();
|
|
959
|
+
}
|
|
960
|
+
var uiOnConnect = function() {
|
|
961
|
+
setSocketConnected(true);
|
|
962
|
+
};
|
|
963
|
+
var uiOnDisconnect = function() {
|
|
964
|
+
cleanupSubscriptions.forEach(function(cleanup) {
|
|
965
|
+
return cleanup();
|
|
966
|
+
});
|
|
967
|
+
setSocketConnected(false);
|
|
968
|
+
};
|
|
969
|
+
socketServiceInstance.onConnect(uiOnConnect);
|
|
970
|
+
socketServiceInstance.onDisconnect(uiOnDisconnect);
|
|
971
|
+
setSocketConnected(socketServiceInstance.isConnected());
|
|
972
|
+
return function() {
|
|
973
|
+
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
|
|
974
|
+
console.log("==> ".concat(label || "Custom snapshots", " stopped from cache... "));
|
|
975
|
+
}
|
|
976
|
+
if (settings === null || settings === void 0 ? void 0 : settings.cleanupForConfigChange) {
|
|
977
|
+
cleanupSubscriptions.forEach(function(cleanup) {
|
|
978
|
+
return cleanup();
|
|
979
|
+
});
|
|
980
|
+
socketServiceInstance.offConnect(uiOnConnect);
|
|
981
|
+
socketServiceInstance.offDisconnect(uiOnDisconnect);
|
|
982
|
+
}
|
|
983
|
+
};
|
|
984
|
+
}, [
|
|
985
|
+
socketConnected
|
|
986
|
+
]);
|
|
987
|
+
(0, import_react3.useEffect)(function() {
|
|
988
|
+
return function() {
|
|
989
|
+
cleanupSubscriptions.forEach(function(cleanup) {
|
|
990
|
+
return cleanup();
|
|
991
|
+
});
|
|
992
|
+
};
|
|
993
|
+
}, []);
|
|
994
|
+
return {
|
|
995
|
+
socketConnected: socketConnected
|
|
996
|
+
};
|
|
997
|
+
};
|
|
930
998
|
// src/hooks/global.ts
|
|
931
999
|
var useDocumentTitle = function(title) {
|
|
932
|
-
(0,
|
|
1000
|
+
(0, import_react5.useEffect)(function() {
|
|
933
1001
|
document.title = title;
|
|
934
1002
|
}, [
|
|
935
1003
|
title
|
|
@@ -937,12 +1005,12 @@ var useDocumentTitle = function(title) {
|
|
|
937
1005
|
return null;
|
|
938
1006
|
};
|
|
939
1007
|
var useSnapshotBulk = function(configs, label, settings) {
|
|
940
|
-
var snapshotsFirstTime = (0,
|
|
941
|
-
var unsubscribeFunctions = (0,
|
|
1008
|
+
var snapshotsFirstTime = (0, import_react5.useRef)([]);
|
|
1009
|
+
var unsubscribeFunctions = (0, import_react5.useRef)([]);
|
|
942
1010
|
useDeepCompareEffect(function() {
|
|
943
1011
|
var start = performance.now();
|
|
944
1012
|
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
|
|
945
|
-
console.log("==> ".concat(label || "Custom snapshots", " started... "));
|
|
1013
|
+
console.log("==> ".concat(label || "Custom snapshots", " started from db... "));
|
|
946
1014
|
}
|
|
947
1015
|
var snapshotResults = configs.map(function(config) {
|
|
948
1016
|
return snapshot(config, snapshotsFirstTime.current, settings);
|
|
@@ -954,7 +1022,7 @@ var useSnapshotBulk = function(configs, label, settings) {
|
|
|
954
1022
|
return result.promise;
|
|
955
1023
|
})).then(function() {
|
|
956
1024
|
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
|
|
957
|
-
console.log("==> ".concat(label || "Custom snapshots", " ended. It took ").concat((performance.now() - start).toFixed(2), " ms"));
|
|
1025
|
+
console.log("==> ".concat(label || "Custom snapshots", " ended from db. It took ").concat((performance.now() - start).toFixed(2), " ms"));
|
|
958
1026
|
}
|
|
959
1027
|
});
|
|
960
1028
|
if (settings === null || settings === void 0 ? void 0 : settings.cleanupForConfigChange) {
|
|
@@ -965,7 +1033,7 @@ var useSnapshotBulk = function(configs, label, settings) {
|
|
|
965
1033
|
}
|
|
966
1034
|
});
|
|
967
1035
|
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
|
|
968
|
-
console.log("==> ".concat(label || "Custom snapshots", " unsubscribed"));
|
|
1036
|
+
console.log("==> ".concat(label || "Custom snapshots", " unsubscribed from db"));
|
|
969
1037
|
}
|
|
970
1038
|
};
|
|
971
1039
|
}
|
|
@@ -974,7 +1042,7 @@ var useSnapshotBulk = function(configs, label, settings) {
|
|
|
974
1042
|
label,
|
|
975
1043
|
settings
|
|
976
1044
|
]);
|
|
977
|
-
(0,
|
|
1045
|
+
(0, import_react5.useEffect)(function() {
|
|
978
1046
|
return function() {
|
|
979
1047
|
unsubscribeFunctions.current.forEach(function(unsubscribe) {
|
|
980
1048
|
if (unsubscribe) {
|
|
@@ -987,77 +1055,9 @@ var useSnapshotBulk = function(configs, label, settings) {
|
|
|
987
1055
|
};
|
|
988
1056
|
}, []);
|
|
989
1057
|
};
|
|
990
|
-
var
|
|
991
|
-
(0,
|
|
992
|
-
|
|
993
|
-
if (!currentCountry) {
|
|
994
|
-
var updateCountry = /*#__PURE__*/ function() {
|
|
995
|
-
var _ref = _async_to_generator(function() {
|
|
996
|
-
var country;
|
|
997
|
-
return _ts_generator(this, function(_state) {
|
|
998
|
-
switch(_state.label){
|
|
999
|
-
case 0:
|
|
1000
|
-
return [
|
|
1001
|
-
4,
|
|
1002
|
-
getUserCountryByIp()
|
|
1003
|
-
];
|
|
1004
|
-
case 1:
|
|
1005
|
-
country = _state.sent();
|
|
1006
|
-
changLang(country === import_akeyless_types_commons2.CountryOptions.IL ? "he" : "en");
|
|
1007
|
-
setUserCountry(country);
|
|
1008
|
-
localStorage.setItem("userCountry", country);
|
|
1009
|
-
return [
|
|
1010
|
-
2
|
|
1011
|
-
];
|
|
1012
|
-
}
|
|
1013
|
-
});
|
|
1014
|
-
});
|
|
1015
|
-
return function updateCountry() {
|
|
1016
|
-
return _ref.apply(this, arguments);
|
|
1017
|
-
};
|
|
1018
|
-
}();
|
|
1019
|
-
updateCountry();
|
|
1020
|
-
}
|
|
1021
|
-
}, []);
|
|
1022
|
-
return null;
|
|
1023
|
-
};
|
|
1024
|
-
// src/hooks/WebWorker.ts
|
|
1025
|
-
var import_react5 = require("react");
|
|
1026
|
-
// src/hooks/socket.ts
|
|
1027
|
-
var import_react6 = require("react");
|
|
1028
|
-
var useSocketSubscription = function(config) {
|
|
1029
|
-
var _ref = _sliced_to_array((0, import_react6.useState)(socketServiceInstance.isConnected()), 2), socketConnected = _ref[0], setSocketConnected = _ref[1];
|
|
1030
|
-
useDeepCompareEffect(function() {
|
|
1031
|
-
var cleanupSubscriptions;
|
|
1032
|
-
if (socketConnected) {
|
|
1033
|
-
cleanupSubscriptions = socketServiceInstance.subscribeToCollections(config);
|
|
1034
|
-
}
|
|
1035
|
-
var uiOnConnect = function() {
|
|
1036
|
-
setSocketConnected(true);
|
|
1037
|
-
};
|
|
1038
|
-
var uiOnDisconnect = function() {
|
|
1039
|
-
cleanupSubscriptions === null || cleanupSubscriptions === void 0 ? void 0 : cleanupSubscriptions();
|
|
1040
|
-
setSocketConnected(false);
|
|
1041
|
-
};
|
|
1042
|
-
socketServiceInstance.onConnect(uiOnConnect);
|
|
1043
|
-
socketServiceInstance.onDisconnect(uiOnDisconnect);
|
|
1044
|
-
setSocketConnected(socketServiceInstance.isConnected());
|
|
1045
|
-
return function() {
|
|
1046
|
-
console.log("cleanupSubscriptions");
|
|
1047
|
-
cleanupSubscriptions === null || cleanupSubscriptions === void 0 ? void 0 : cleanupSubscriptions();
|
|
1048
|
-
socketServiceInstance.offConnect(uiOnConnect);
|
|
1049
|
-
socketServiceInstance.offDisconnect(uiOnDisconnect);
|
|
1050
|
-
};
|
|
1051
|
-
}, [
|
|
1052
|
-
socketConnected
|
|
1053
|
-
]);
|
|
1054
|
-
return {
|
|
1055
|
-
socketConnected: socketConnected
|
|
1056
|
-
};
|
|
1057
|
-
};
|
|
1058
|
-
var useSmartSnapshot = function(configs, options) {
|
|
1059
|
-
var _ref = _sliced_to_array((0, import_react6.useState)(null), 2), cacheCollectionsConfig = _ref[0], setCacheCollectionsConfig = _ref[1];
|
|
1060
|
-
(0, import_react6.useEffect)(function() {
|
|
1058
|
+
var useSmartSnapshot = function(configs, label, settings) {
|
|
1059
|
+
var _ref = _sliced_to_array((0, import_react5.useState)(null), 2), cacheCollectionsConfig = _ref[0], setCacheCollectionsConfig = _ref[1];
|
|
1060
|
+
(0, import_react5.useEffect)(function() {
|
|
1061
1061
|
get_document_by_id("nx-settings", "cache_collections_config").then(function(res) {
|
|
1062
1062
|
return setCacheCollectionsConfig(res);
|
|
1063
1063
|
});
|
|
@@ -1065,7 +1065,7 @@ var useSmartSnapshot = function(configs, options) {
|
|
|
1065
1065
|
return setCacheCollectionsConfig(null);
|
|
1066
1066
|
};
|
|
1067
1067
|
}, []);
|
|
1068
|
-
var groupedConfig = (
|
|
1068
|
+
var groupedConfig = useDeepCompareMemo(function() {
|
|
1069
1069
|
if (!cacheCollectionsConfig) {
|
|
1070
1070
|
return {
|
|
1071
1071
|
configForDb: [],
|
|
@@ -1090,13 +1090,49 @@ var useSmartSnapshot = function(configs, options) {
|
|
|
1090
1090
|
configs,
|
|
1091
1091
|
cacheCollectionsConfig
|
|
1092
1092
|
]);
|
|
1093
|
-
useSnapshotBulk(groupedConfig.configForDb,
|
|
1094
|
-
var socketConnected = useSocketSubscription(groupedConfig.configForCache).socketConnected;
|
|
1093
|
+
useSnapshotBulk(groupedConfig.configForDb, label, settings);
|
|
1094
|
+
var socketConnected = useSocketSubscription(groupedConfig.configForCache, label, settings).socketConnected;
|
|
1095
1095
|
return {
|
|
1096
1096
|
groupedConfig: groupedConfig,
|
|
1097
1097
|
socketConnected: socketConnected
|
|
1098
1098
|
};
|
|
1099
1099
|
};
|
|
1100
|
+
var useSetUserCountry = function(setUserCountry, changLang) {
|
|
1101
|
+
(0, import_react5.useLayoutEffect)(function() {
|
|
1102
|
+
var currentCountry = localStorage.getItem("userCountry");
|
|
1103
|
+
if (!currentCountry) {
|
|
1104
|
+
var updateCountry = /*#__PURE__*/ function() {
|
|
1105
|
+
var _ref = _async_to_generator(function() {
|
|
1106
|
+
var country;
|
|
1107
|
+
return _ts_generator(this, function(_state) {
|
|
1108
|
+
switch(_state.label){
|
|
1109
|
+
case 0:
|
|
1110
|
+
return [
|
|
1111
|
+
4,
|
|
1112
|
+
getUserCountryByIp()
|
|
1113
|
+
];
|
|
1114
|
+
case 1:
|
|
1115
|
+
country = _state.sent();
|
|
1116
|
+
changLang(country === import_akeyless_types_commons2.CountryOptions.IL ? "he" : "en");
|
|
1117
|
+
setUserCountry(country);
|
|
1118
|
+
localStorage.setItem("userCountry", country);
|
|
1119
|
+
return [
|
|
1120
|
+
2
|
|
1121
|
+
];
|
|
1122
|
+
}
|
|
1123
|
+
});
|
|
1124
|
+
});
|
|
1125
|
+
return function updateCountry() {
|
|
1126
|
+
return _ref.apply(this, arguments);
|
|
1127
|
+
};
|
|
1128
|
+
}();
|
|
1129
|
+
updateCountry();
|
|
1130
|
+
}
|
|
1131
|
+
}, []);
|
|
1132
|
+
return null;
|
|
1133
|
+
};
|
|
1134
|
+
// src/hooks/WebWorker.ts
|
|
1135
|
+
var import_react7 = require("react");
|
|
1100
1136
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1101
1137
|
0 && (module.exports = {
|
|
1102
1138
|
useDeepCompareEffect: useDeepCompareEffect,
|
package/dist/hooks/index.mjs
CHANGED
|
@@ -7,6 +7,9 @@ function _array_like_to_array(arr, len) {
|
|
|
7
7
|
function _array_with_holes(arr) {
|
|
8
8
|
if (Array.isArray(arr)) return arr;
|
|
9
9
|
}
|
|
10
|
+
function _array_without_holes(arr) {
|
|
11
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
12
|
+
}
|
|
10
13
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
11
14
|
try {
|
|
12
15
|
var info = gen[key](arg);
|
|
@@ -68,6 +71,9 @@ function _define_property(obj, key, value) {
|
|
|
68
71
|
}
|
|
69
72
|
return obj;
|
|
70
73
|
}
|
|
74
|
+
function _iterable_to_array(iter) {
|
|
75
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
76
|
+
}
|
|
71
77
|
function _iterable_to_array_limit(arr, i) {
|
|
72
78
|
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
73
79
|
if (_i == null) return;
|
|
@@ -95,6 +101,9 @@ function _iterable_to_array_limit(arr, i) {
|
|
|
95
101
|
function _non_iterable_rest() {
|
|
96
102
|
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
97
103
|
}
|
|
104
|
+
function _non_iterable_spread() {
|
|
105
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
106
|
+
}
|
|
98
107
|
function _object_spread(target) {
|
|
99
108
|
for(var i = 1; i < arguments.length; i++){
|
|
100
109
|
var source = arguments[i] != null ? arguments[i] : {};
|
|
@@ -137,6 +146,9 @@ function _object_spread_props(target, source) {
|
|
|
137
146
|
function _sliced_to_array(arr, i) {
|
|
138
147
|
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
139
148
|
}
|
|
149
|
+
function _to_consumable_array(arr) {
|
|
150
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
151
|
+
}
|
|
140
152
|
function _unsupported_iterable_to_array(o, minLen) {
|
|
141
153
|
if (!o) return;
|
|
142
154
|
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
@@ -241,7 +253,7 @@ function _ts_generator(thisArg, body) {
|
|
|
241
253
|
}
|
|
242
254
|
}
|
|
243
255
|
import { CountryOptions as CountryOptions2 } from "akeyless-types-commons";
|
|
244
|
-
import { useEffect as
|
|
256
|
+
import { useEffect as useEffect3, useLayoutEffect, useRef as useRef2, useState as useState2 } from "react";
|
|
245
257
|
// src/helpers/firebase.ts
|
|
246
258
|
import moment from "moment";
|
|
247
259
|
import { initializeApp } from "firebase/app";
|
|
@@ -833,9 +845,65 @@ function useDeepCompareEffect(effect, dependencies) {
|
|
|
833
845
|
previousDepsRef.current
|
|
834
846
|
]);
|
|
835
847
|
}
|
|
848
|
+
// src/hooks/socket.ts
|
|
849
|
+
import { useEffect as useEffect2, useState } from "react";
|
|
850
|
+
var useSocketSubscription = function(config, label, settings) {
|
|
851
|
+
var _useState = _sliced_to_array(useState(socketServiceInstance.isConnected()), 2), socketConnected = _useState[0], setSocketConnected = _useState[1];
|
|
852
|
+
var _useState1 = _sliced_to_array(useState([]), 2), cleanupSubscriptions = _useState1[0], setCleanupSubscriptions = _useState1[1];
|
|
853
|
+
useDeepCompareEffect(function() {
|
|
854
|
+
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
|
|
855
|
+
console.log("==> ".concat(label || "Custom snapshots", " started from cache... "));
|
|
856
|
+
}
|
|
857
|
+
if (socketConnected) {
|
|
858
|
+
setCleanupSubscriptions(function(prev) {
|
|
859
|
+
return _to_consumable_array(prev).concat([
|
|
860
|
+
socketServiceInstance.subscribeToCollections(config)
|
|
861
|
+
]);
|
|
862
|
+
});
|
|
863
|
+
} else {
|
|
864
|
+
socketServiceInstance.getSocketInstance();
|
|
865
|
+
}
|
|
866
|
+
var uiOnConnect = function() {
|
|
867
|
+
setSocketConnected(true);
|
|
868
|
+
};
|
|
869
|
+
var uiOnDisconnect = function() {
|
|
870
|
+
cleanupSubscriptions.forEach(function(cleanup) {
|
|
871
|
+
return cleanup();
|
|
872
|
+
});
|
|
873
|
+
setSocketConnected(false);
|
|
874
|
+
};
|
|
875
|
+
socketServiceInstance.onConnect(uiOnConnect);
|
|
876
|
+
socketServiceInstance.onDisconnect(uiOnDisconnect);
|
|
877
|
+
setSocketConnected(socketServiceInstance.isConnected());
|
|
878
|
+
return function() {
|
|
879
|
+
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
|
|
880
|
+
console.log("==> ".concat(label || "Custom snapshots", " stopped from cache... "));
|
|
881
|
+
}
|
|
882
|
+
if (settings === null || settings === void 0 ? void 0 : settings.cleanupForConfigChange) {
|
|
883
|
+
cleanupSubscriptions.forEach(function(cleanup) {
|
|
884
|
+
return cleanup();
|
|
885
|
+
});
|
|
886
|
+
socketServiceInstance.offConnect(uiOnConnect);
|
|
887
|
+
socketServiceInstance.offDisconnect(uiOnDisconnect);
|
|
888
|
+
}
|
|
889
|
+
};
|
|
890
|
+
}, [
|
|
891
|
+
socketConnected
|
|
892
|
+
]);
|
|
893
|
+
useEffect2(function() {
|
|
894
|
+
return function() {
|
|
895
|
+
cleanupSubscriptions.forEach(function(cleanup) {
|
|
896
|
+
return cleanup();
|
|
897
|
+
});
|
|
898
|
+
};
|
|
899
|
+
}, []);
|
|
900
|
+
return {
|
|
901
|
+
socketConnected: socketConnected
|
|
902
|
+
};
|
|
903
|
+
};
|
|
836
904
|
// src/hooks/global.ts
|
|
837
905
|
var useDocumentTitle = function(title) {
|
|
838
|
-
|
|
906
|
+
useEffect3(function() {
|
|
839
907
|
document.title = title;
|
|
840
908
|
}, [
|
|
841
909
|
title
|
|
@@ -848,7 +916,7 @@ var useSnapshotBulk = function(configs, label, settings) {
|
|
|
848
916
|
useDeepCompareEffect(function() {
|
|
849
917
|
var start = performance.now();
|
|
850
918
|
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
|
|
851
|
-
console.log("==> ".concat(label || "Custom snapshots", " started... "));
|
|
919
|
+
console.log("==> ".concat(label || "Custom snapshots", " started from db... "));
|
|
852
920
|
}
|
|
853
921
|
var snapshotResults = configs.map(function(config) {
|
|
854
922
|
return snapshot(config, snapshotsFirstTime.current, settings);
|
|
@@ -860,7 +928,7 @@ var useSnapshotBulk = function(configs, label, settings) {
|
|
|
860
928
|
return result.promise;
|
|
861
929
|
})).then(function() {
|
|
862
930
|
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
|
|
863
|
-
console.log("==> ".concat(label || "Custom snapshots", " ended. It took ").concat((performance.now() - start).toFixed(2), " ms"));
|
|
931
|
+
console.log("==> ".concat(label || "Custom snapshots", " ended from db. It took ").concat((performance.now() - start).toFixed(2), " ms"));
|
|
864
932
|
}
|
|
865
933
|
});
|
|
866
934
|
if (settings === null || settings === void 0 ? void 0 : settings.cleanupForConfigChange) {
|
|
@@ -871,7 +939,7 @@ var useSnapshotBulk = function(configs, label, settings) {
|
|
|
871
939
|
}
|
|
872
940
|
});
|
|
873
941
|
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
|
|
874
|
-
console.log("==> ".concat(label || "Custom snapshots", " unsubscribed"));
|
|
942
|
+
console.log("==> ".concat(label || "Custom snapshots", " unsubscribed from db"));
|
|
875
943
|
}
|
|
876
944
|
};
|
|
877
945
|
}
|
|
@@ -880,7 +948,7 @@ var useSnapshotBulk = function(configs, label, settings) {
|
|
|
880
948
|
label,
|
|
881
949
|
settings
|
|
882
950
|
]);
|
|
883
|
-
|
|
951
|
+
useEffect3(function() {
|
|
884
952
|
return function() {
|
|
885
953
|
unsubscribeFunctions.current.forEach(function(unsubscribe) {
|
|
886
954
|
if (unsubscribe) {
|
|
@@ -893,77 +961,9 @@ var useSnapshotBulk = function(configs, label, settings) {
|
|
|
893
961
|
};
|
|
894
962
|
}, []);
|
|
895
963
|
};
|
|
896
|
-
var
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
if (!currentCountry) {
|
|
900
|
-
var updateCountry = /*#__PURE__*/ function() {
|
|
901
|
-
var _ref = _async_to_generator(function() {
|
|
902
|
-
var country;
|
|
903
|
-
return _ts_generator(this, function(_state) {
|
|
904
|
-
switch(_state.label){
|
|
905
|
-
case 0:
|
|
906
|
-
return [
|
|
907
|
-
4,
|
|
908
|
-
getUserCountryByIp()
|
|
909
|
-
];
|
|
910
|
-
case 1:
|
|
911
|
-
country = _state.sent();
|
|
912
|
-
changLang(country === CountryOptions2.IL ? "he" : "en");
|
|
913
|
-
setUserCountry(country);
|
|
914
|
-
localStorage.setItem("userCountry", country);
|
|
915
|
-
return [
|
|
916
|
-
2
|
|
917
|
-
];
|
|
918
|
-
}
|
|
919
|
-
});
|
|
920
|
-
});
|
|
921
|
-
return function updateCountry() {
|
|
922
|
-
return _ref.apply(this, arguments);
|
|
923
|
-
};
|
|
924
|
-
}();
|
|
925
|
-
updateCountry();
|
|
926
|
-
}
|
|
927
|
-
}, []);
|
|
928
|
-
return null;
|
|
929
|
-
};
|
|
930
|
-
// src/hooks/WebWorker.ts
|
|
931
|
-
import { useCallback as useCallback2, useEffect as useEffect3, useRef as useRef3 } from "react";
|
|
932
|
-
// src/hooks/socket.ts
|
|
933
|
-
import { useEffect as useEffect4, useMemo as useMemo2, useState } from "react";
|
|
934
|
-
var useSocketSubscription = function(config) {
|
|
935
|
-
var _useState = _sliced_to_array(useState(socketServiceInstance.isConnected()), 2), socketConnected = _useState[0], setSocketConnected = _useState[1];
|
|
936
|
-
useDeepCompareEffect(function() {
|
|
937
|
-
var cleanupSubscriptions;
|
|
938
|
-
if (socketConnected) {
|
|
939
|
-
cleanupSubscriptions = socketServiceInstance.subscribeToCollections(config);
|
|
940
|
-
}
|
|
941
|
-
var uiOnConnect = function() {
|
|
942
|
-
setSocketConnected(true);
|
|
943
|
-
};
|
|
944
|
-
var uiOnDisconnect = function() {
|
|
945
|
-
cleanupSubscriptions === null || cleanupSubscriptions === void 0 ? void 0 : cleanupSubscriptions();
|
|
946
|
-
setSocketConnected(false);
|
|
947
|
-
};
|
|
948
|
-
socketServiceInstance.onConnect(uiOnConnect);
|
|
949
|
-
socketServiceInstance.onDisconnect(uiOnDisconnect);
|
|
950
|
-
setSocketConnected(socketServiceInstance.isConnected());
|
|
951
|
-
return function() {
|
|
952
|
-
console.log("cleanupSubscriptions");
|
|
953
|
-
cleanupSubscriptions === null || cleanupSubscriptions === void 0 ? void 0 : cleanupSubscriptions();
|
|
954
|
-
socketServiceInstance.offConnect(uiOnConnect);
|
|
955
|
-
socketServiceInstance.offDisconnect(uiOnDisconnect);
|
|
956
|
-
};
|
|
957
|
-
}, [
|
|
958
|
-
socketConnected
|
|
959
|
-
]);
|
|
960
|
-
return {
|
|
961
|
-
socketConnected: socketConnected
|
|
962
|
-
};
|
|
963
|
-
};
|
|
964
|
-
var useSmartSnapshot = function(configs, options) {
|
|
965
|
-
var _useState = _sliced_to_array(useState(null), 2), cacheCollectionsConfig = _useState[0], setCacheCollectionsConfig = _useState[1];
|
|
966
|
-
useEffect4(function() {
|
|
964
|
+
var useSmartSnapshot = function(configs, label, settings) {
|
|
965
|
+
var _useState2 = _sliced_to_array(useState2(null), 2), cacheCollectionsConfig = _useState2[0], setCacheCollectionsConfig = _useState2[1];
|
|
966
|
+
useEffect3(function() {
|
|
967
967
|
get_document_by_id("nx-settings", "cache_collections_config").then(function(res) {
|
|
968
968
|
return setCacheCollectionsConfig(res);
|
|
969
969
|
});
|
|
@@ -971,7 +971,7 @@ var useSmartSnapshot = function(configs, options) {
|
|
|
971
971
|
return setCacheCollectionsConfig(null);
|
|
972
972
|
};
|
|
973
973
|
}, []);
|
|
974
|
-
var groupedConfig =
|
|
974
|
+
var groupedConfig = useDeepCompareMemo(function() {
|
|
975
975
|
if (!cacheCollectionsConfig) {
|
|
976
976
|
return {
|
|
977
977
|
configForDb: [],
|
|
@@ -996,12 +996,48 @@ var useSmartSnapshot = function(configs, options) {
|
|
|
996
996
|
configs,
|
|
997
997
|
cacheCollectionsConfig
|
|
998
998
|
]);
|
|
999
|
-
useSnapshotBulk(groupedConfig.configForDb,
|
|
1000
|
-
var socketConnected = useSocketSubscription(groupedConfig.configForCache).socketConnected;
|
|
999
|
+
useSnapshotBulk(groupedConfig.configForDb, label, settings);
|
|
1000
|
+
var socketConnected = useSocketSubscription(groupedConfig.configForCache, label, settings).socketConnected;
|
|
1001
1001
|
return {
|
|
1002
1002
|
groupedConfig: groupedConfig,
|
|
1003
1003
|
socketConnected: socketConnected
|
|
1004
1004
|
};
|
|
1005
1005
|
};
|
|
1006
|
+
var useSetUserCountry = function(setUserCountry, changLang) {
|
|
1007
|
+
useLayoutEffect(function() {
|
|
1008
|
+
var currentCountry = localStorage.getItem("userCountry");
|
|
1009
|
+
if (!currentCountry) {
|
|
1010
|
+
var updateCountry = /*#__PURE__*/ function() {
|
|
1011
|
+
var _ref = _async_to_generator(function() {
|
|
1012
|
+
var country;
|
|
1013
|
+
return _ts_generator(this, function(_state) {
|
|
1014
|
+
switch(_state.label){
|
|
1015
|
+
case 0:
|
|
1016
|
+
return [
|
|
1017
|
+
4,
|
|
1018
|
+
getUserCountryByIp()
|
|
1019
|
+
];
|
|
1020
|
+
case 1:
|
|
1021
|
+
country = _state.sent();
|
|
1022
|
+
changLang(country === CountryOptions2.IL ? "he" : "en");
|
|
1023
|
+
setUserCountry(country);
|
|
1024
|
+
localStorage.setItem("userCountry", country);
|
|
1025
|
+
return [
|
|
1026
|
+
2
|
|
1027
|
+
];
|
|
1028
|
+
}
|
|
1029
|
+
});
|
|
1030
|
+
});
|
|
1031
|
+
return function updateCountry() {
|
|
1032
|
+
return _ref.apply(this, arguments);
|
|
1033
|
+
};
|
|
1034
|
+
}();
|
|
1035
|
+
updateCountry();
|
|
1036
|
+
}
|
|
1037
|
+
}, []);
|
|
1038
|
+
return null;
|
|
1039
|
+
};
|
|
1040
|
+
// src/hooks/WebWorker.ts
|
|
1041
|
+
import { useCallback as useCallback2, useEffect as useEffect4, useRef as useRef3 } from "react";
|
|
1006
1042
|
export { useDeepCompareEffect, useDeepCompareMemo, useDocumentTitle, useSafeEffect, useSetUserCountry, useSmartSnapshot, useSnapshotBulk, useSocketSubscription };
|
|
1007
1043
|
//# sourceMappingURL=index.mjs.map
|