akeyless-client-commons 1.1.11 → 1.1.13

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.
@@ -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: OnSnapshotConfig[];
40
+ configForCache: OnSnapshotConfig[];
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
- socketConnected: boolean;
42
- };
43
- type UseSmartSubscriptionSettings = {
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: (configs: OnSnapshotConfig[], label?: string, settings?: {
51
+ cleanupForConfigChange?: boolean;
52
+ disableLogs?: boolean;
53
+ }) => {
55
54
  socketConnected: boolean;
56
55
  };
57
56
 
@@ -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: OnSnapshotConfig[];
40
+ configForCache: OnSnapshotConfig[];
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
- socketConnected: boolean;
42
- };
43
- type UseSmartSubscriptionSettings = {
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: (configs: OnSnapshotConfig[], label?: string, settings?: {
51
+ cleanupForConfigChange?: boolean;
52
+ disableLogs?: boolean;
53
+ }) => {
55
54
  socketConnected: boolean;
56
55
  };
57
56
 
@@ -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 import_react3 = require("react");
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,71 @@ 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(configs, 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 (socketConnected) {
949
+ setCleanupSubscriptions(function(prev) {
950
+ return _to_consumable_array(prev).concat([
951
+ socketServiceInstance.subscribeToCollections(configs)
952
+ ]);
953
+ });
954
+ if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs) && configs.length > 0) {
955
+ console.log("==> ".concat(label || "Cache snapshots", " subscribed to ").concat(configs.map(function(c) {
956
+ return c.collectionName;
957
+ }).join(", ")));
958
+ }
959
+ } else {
960
+ socketServiceInstance.getSocketInstance();
961
+ if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs) && configs.length > 0) {
962
+ console.log("==> ".concat(label || "Cache snapshots", " started... "));
963
+ }
964
+ }
965
+ var uiOnConnect = function() {
966
+ setSocketConnected(true);
967
+ };
968
+ var uiOnDisconnect = function() {
969
+ cleanupSubscriptions.forEach(function(cleanup) {
970
+ return cleanup();
971
+ });
972
+ setSocketConnected(false);
973
+ };
974
+ socketServiceInstance.onConnect(uiOnConnect);
975
+ socketServiceInstance.onDisconnect(uiOnDisconnect);
976
+ setSocketConnected(socketServiceInstance.isConnected());
977
+ return function() {
978
+ if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs) && configs.length > 0) {
979
+ console.log("==> ".concat(label || "Cache snapshots", " stopped. "));
980
+ }
981
+ if (settings === null || settings === void 0 ? void 0 : settings.cleanupForConfigChange) {
982
+ cleanupSubscriptions.forEach(function(cleanup) {
983
+ return cleanup();
984
+ });
985
+ socketServiceInstance.offConnect(uiOnConnect);
986
+ socketServiceInstance.offDisconnect(uiOnDisconnect);
987
+ }
988
+ };
989
+ }, [
990
+ socketConnected,
991
+ configs
992
+ ]);
993
+ (0, import_react3.useEffect)(function() {
994
+ return function() {
995
+ cleanupSubscriptions.forEach(function(cleanup) {
996
+ return cleanup();
997
+ });
998
+ };
999
+ }, []);
1000
+ return {
1001
+ socketConnected: socketConnected
1002
+ };
1003
+ };
930
1004
  // src/hooks/global.ts
931
1005
  var useDocumentTitle = function(title) {
932
- (0, import_react3.useEffect)(function() {
1006
+ (0, import_react5.useEffect)(function() {
933
1007
  document.title = title;
934
1008
  }, [
935
1009
  title
@@ -937,12 +1011,12 @@ var useDocumentTitle = function(title) {
937
1011
  return null;
938
1012
  };
939
1013
  var useSnapshotBulk = function(configs, label, settings) {
940
- var snapshotsFirstTime = (0, import_react3.useRef)([]);
941
- var unsubscribeFunctions = (0, import_react3.useRef)([]);
1014
+ var snapshotsFirstTime = (0, import_react5.useRef)([]);
1015
+ var unsubscribeFunctions = (0, import_react5.useRef)([]);
942
1016
  useDeepCompareEffect(function() {
943
1017
  var start = performance.now();
944
- if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
945
- console.log("==> ".concat(label || "Custom snapshots", " started... "));
1018
+ if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs) && configs.length > 0) {
1019
+ console.log("==> ".concat(label || "DB snapshots", " started from db... "));
946
1020
  }
947
1021
  var snapshotResults = configs.map(function(config) {
948
1022
  return snapshot(config, snapshotsFirstTime.current, settings);
@@ -953,8 +1027,8 @@ var useSnapshotBulk = function(configs, label, settings) {
953
1027
  Promise.all(snapshotResults.map(function(result) {
954
1028
  return result.promise;
955
1029
  })).then(function() {
956
- 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"));
1030
+ if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs) && configs.length > 0) {
1031
+ console.log("==> ".concat(label || "DB snapshots", " ended from db. It took ").concat((performance.now() - start).toFixed(2), " ms"));
958
1032
  }
959
1033
  });
960
1034
  if (settings === null || settings === void 0 ? void 0 : settings.cleanupForConfigChange) {
@@ -964,8 +1038,8 @@ var useSnapshotBulk = function(configs, label, settings) {
964
1038
  unsubscribe();
965
1039
  }
966
1040
  });
967
- if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
968
- console.log("==> ".concat(label || "Custom snapshots", " unsubscribed"));
1041
+ if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs) && configs.length > 0) {
1042
+ console.log("==> ".concat(label || "DB snapshots", " unsubscribed from db"));
969
1043
  }
970
1044
  };
971
1045
  }
@@ -974,7 +1048,7 @@ var useSnapshotBulk = function(configs, label, settings) {
974
1048
  label,
975
1049
  settings
976
1050
  ]);
977
- (0, import_react3.useEffect)(function() {
1051
+ (0, import_react5.useEffect)(function() {
978
1052
  return function() {
979
1053
  unsubscribeFunctions.current.forEach(function(unsubscribe) {
980
1054
  if (unsubscribe) {
@@ -982,82 +1056,14 @@ var useSnapshotBulk = function(configs, label, settings) {
982
1056
  }
983
1057
  });
984
1058
  if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
985
- console.log("==> ".concat(label || "Custom snapshots", " unsubscribed"));
1059
+ console.log("==> ".concat(label || "DB snapshots", " unsubscribed"));
986
1060
  }
987
1061
  };
988
1062
  }, []);
989
1063
  };
990
- var useSetUserCountry = function(setUserCountry, changLang) {
991
- (0, import_react3.useLayoutEffect)(function() {
992
- var currentCountry = localStorage.getItem("userCountry");
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() {
1064
+ var useSmartSnapshot = function(configs, label, settings) {
1065
+ var _ref = _sliced_to_array((0, import_react5.useState)(null), 2), cacheCollectionsConfig = _ref[0], setCacheCollectionsConfig = _ref[1];
1066
+ (0, import_react5.useEffect)(function() {
1061
1067
  get_document_by_id("nx-settings", "cache_collections_config").then(function(res) {
1062
1068
  return setCacheCollectionsConfig(res);
1063
1069
  });
@@ -1065,7 +1071,7 @@ var useSmartSnapshot = function(configs, options) {
1065
1071
  return setCacheCollectionsConfig(null);
1066
1072
  };
1067
1073
  }, []);
1068
- var groupedConfig = (0, import_react6.useMemo)(function() {
1074
+ var groupedConfig = (0, import_react5.useMemo)(function() {
1069
1075
  if (!cacheCollectionsConfig) {
1070
1076
  return {
1071
1077
  configForDb: [],
@@ -1090,13 +1096,49 @@ var useSmartSnapshot = function(configs, options) {
1090
1096
  configs,
1091
1097
  cacheCollectionsConfig
1092
1098
  ]);
1093
- useSnapshotBulk(groupedConfig.configForDb, options === null || options === void 0 ? void 0 : options.label, options === null || options === void 0 ? void 0 : options.settings);
1094
- var socketConnected = useSocketSubscription(groupedConfig.configForCache).socketConnected;
1099
+ useSnapshotBulk(groupedConfig.configForDb, label, settings);
1100
+ var socketConnected = useSocketSubscription(groupedConfig.configForCache, label, settings).socketConnected;
1095
1101
  return {
1096
1102
  groupedConfig: groupedConfig,
1097
1103
  socketConnected: socketConnected
1098
1104
  };
1099
1105
  };
1106
+ var useSetUserCountry = function(setUserCountry, changLang) {
1107
+ (0, import_react5.useLayoutEffect)(function() {
1108
+ var currentCountry = localStorage.getItem("userCountry");
1109
+ if (!currentCountry) {
1110
+ var updateCountry = /*#__PURE__*/ function() {
1111
+ var _ref = _async_to_generator(function() {
1112
+ var country;
1113
+ return _ts_generator(this, function(_state) {
1114
+ switch(_state.label){
1115
+ case 0:
1116
+ return [
1117
+ 4,
1118
+ getUserCountryByIp()
1119
+ ];
1120
+ case 1:
1121
+ country = _state.sent();
1122
+ changLang(country === import_akeyless_types_commons2.CountryOptions.IL ? "he" : "en");
1123
+ setUserCountry(country);
1124
+ localStorage.setItem("userCountry", country);
1125
+ return [
1126
+ 2
1127
+ ];
1128
+ }
1129
+ });
1130
+ });
1131
+ return function updateCountry() {
1132
+ return _ref.apply(this, arguments);
1133
+ };
1134
+ }();
1135
+ updateCountry();
1136
+ }
1137
+ }, []);
1138
+ return null;
1139
+ };
1140
+ // src/hooks/WebWorker.ts
1141
+ var import_react7 = require("react");
1100
1142
  // Annotate the CommonJS export names for ESM import in node:
1101
1143
  0 && (module.exports = {
1102
1144
  useDeepCompareEffect: useDeepCompareEffect,
@@ -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 useEffect2, useLayoutEffect, useRef as useRef2 } from "react";
256
+ import { useEffect as useEffect3, useLayoutEffect, useMemo as useMemo2, 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,71 @@ 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(configs, 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 (socketConnected) {
855
+ setCleanupSubscriptions(function(prev) {
856
+ return _to_consumable_array(prev).concat([
857
+ socketServiceInstance.subscribeToCollections(configs)
858
+ ]);
859
+ });
860
+ if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs) && configs.length > 0) {
861
+ console.log("==> ".concat(label || "Cache snapshots", " subscribed to ").concat(configs.map(function(c) {
862
+ return c.collectionName;
863
+ }).join(", ")));
864
+ }
865
+ } else {
866
+ socketServiceInstance.getSocketInstance();
867
+ if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs) && configs.length > 0) {
868
+ console.log("==> ".concat(label || "Cache snapshots", " started... "));
869
+ }
870
+ }
871
+ var uiOnConnect = function() {
872
+ setSocketConnected(true);
873
+ };
874
+ var uiOnDisconnect = function() {
875
+ cleanupSubscriptions.forEach(function(cleanup) {
876
+ return cleanup();
877
+ });
878
+ setSocketConnected(false);
879
+ };
880
+ socketServiceInstance.onConnect(uiOnConnect);
881
+ socketServiceInstance.onDisconnect(uiOnDisconnect);
882
+ setSocketConnected(socketServiceInstance.isConnected());
883
+ return function() {
884
+ if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs) && configs.length > 0) {
885
+ console.log("==> ".concat(label || "Cache snapshots", " stopped. "));
886
+ }
887
+ if (settings === null || settings === void 0 ? void 0 : settings.cleanupForConfigChange) {
888
+ cleanupSubscriptions.forEach(function(cleanup) {
889
+ return cleanup();
890
+ });
891
+ socketServiceInstance.offConnect(uiOnConnect);
892
+ socketServiceInstance.offDisconnect(uiOnDisconnect);
893
+ }
894
+ };
895
+ }, [
896
+ socketConnected,
897
+ configs
898
+ ]);
899
+ useEffect2(function() {
900
+ return function() {
901
+ cleanupSubscriptions.forEach(function(cleanup) {
902
+ return cleanup();
903
+ });
904
+ };
905
+ }, []);
906
+ return {
907
+ socketConnected: socketConnected
908
+ };
909
+ };
836
910
  // src/hooks/global.ts
837
911
  var useDocumentTitle = function(title) {
838
- useEffect2(function() {
912
+ useEffect3(function() {
839
913
  document.title = title;
840
914
  }, [
841
915
  title
@@ -847,8 +921,8 @@ var useSnapshotBulk = function(configs, label, settings) {
847
921
  var unsubscribeFunctions = useRef2([]);
848
922
  useDeepCompareEffect(function() {
849
923
  var start = performance.now();
850
- if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
851
- console.log("==> ".concat(label || "Custom snapshots", " started... "));
924
+ if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs) && configs.length > 0) {
925
+ console.log("==> ".concat(label || "DB snapshots", " started from db... "));
852
926
  }
853
927
  var snapshotResults = configs.map(function(config) {
854
928
  return snapshot(config, snapshotsFirstTime.current, settings);
@@ -859,8 +933,8 @@ var useSnapshotBulk = function(configs, label, settings) {
859
933
  Promise.all(snapshotResults.map(function(result) {
860
934
  return result.promise;
861
935
  })).then(function() {
862
- 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"));
936
+ if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs) && configs.length > 0) {
937
+ console.log("==> ".concat(label || "DB snapshots", " ended from db. It took ").concat((performance.now() - start).toFixed(2), " ms"));
864
938
  }
865
939
  });
866
940
  if (settings === null || settings === void 0 ? void 0 : settings.cleanupForConfigChange) {
@@ -870,8 +944,8 @@ var useSnapshotBulk = function(configs, label, settings) {
870
944
  unsubscribe();
871
945
  }
872
946
  });
873
- if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
874
- console.log("==> ".concat(label || "Custom snapshots", " unsubscribed"));
947
+ if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs) && configs.length > 0) {
948
+ console.log("==> ".concat(label || "DB snapshots", " unsubscribed from db"));
875
949
  }
876
950
  };
877
951
  }
@@ -880,7 +954,7 @@ var useSnapshotBulk = function(configs, label, settings) {
880
954
  label,
881
955
  settings
882
956
  ]);
883
- useEffect2(function() {
957
+ useEffect3(function() {
884
958
  return function() {
885
959
  unsubscribeFunctions.current.forEach(function(unsubscribe) {
886
960
  if (unsubscribe) {
@@ -888,82 +962,14 @@ var useSnapshotBulk = function(configs, label, settings) {
888
962
  }
889
963
  });
890
964
  if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
891
- console.log("==> ".concat(label || "Custom snapshots", " unsubscribed"));
965
+ console.log("==> ".concat(label || "DB snapshots", " unsubscribed"));
892
966
  }
893
967
  };
894
968
  }, []);
895
969
  };
896
- var useSetUserCountry = function(setUserCountry, changLang) {
897
- useLayoutEffect(function() {
898
- var currentCountry = localStorage.getItem("userCountry");
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() {
970
+ var useSmartSnapshot = function(configs, label, settings) {
971
+ var _useState2 = _sliced_to_array(useState2(null), 2), cacheCollectionsConfig = _useState2[0], setCacheCollectionsConfig = _useState2[1];
972
+ useEffect3(function() {
967
973
  get_document_by_id("nx-settings", "cache_collections_config").then(function(res) {
968
974
  return setCacheCollectionsConfig(res);
969
975
  });
@@ -996,12 +1002,48 @@ var useSmartSnapshot = function(configs, options) {
996
1002
  configs,
997
1003
  cacheCollectionsConfig
998
1004
  ]);
999
- useSnapshotBulk(groupedConfig.configForDb, options === null || options === void 0 ? void 0 : options.label, options === null || options === void 0 ? void 0 : options.settings);
1000
- var socketConnected = useSocketSubscription(groupedConfig.configForCache).socketConnected;
1005
+ useSnapshotBulk(groupedConfig.configForDb, label, settings);
1006
+ var socketConnected = useSocketSubscription(groupedConfig.configForCache, label, settings).socketConnected;
1001
1007
  return {
1002
1008
  groupedConfig: groupedConfig,
1003
1009
  socketConnected: socketConnected
1004
1010
  };
1005
1011
  };
1012
+ var useSetUserCountry = function(setUserCountry, changLang) {
1013
+ useLayoutEffect(function() {
1014
+ var currentCountry = localStorage.getItem("userCountry");
1015
+ if (!currentCountry) {
1016
+ var updateCountry = /*#__PURE__*/ function() {
1017
+ var _ref = _async_to_generator(function() {
1018
+ var country;
1019
+ return _ts_generator(this, function(_state) {
1020
+ switch(_state.label){
1021
+ case 0:
1022
+ return [
1023
+ 4,
1024
+ getUserCountryByIp()
1025
+ ];
1026
+ case 1:
1027
+ country = _state.sent();
1028
+ changLang(country === CountryOptions2.IL ? "he" : "en");
1029
+ setUserCountry(country);
1030
+ localStorage.setItem("userCountry", country);
1031
+ return [
1032
+ 2
1033
+ ];
1034
+ }
1035
+ });
1036
+ });
1037
+ return function updateCountry() {
1038
+ return _ref.apply(this, arguments);
1039
+ };
1040
+ }();
1041
+ updateCountry();
1042
+ }
1043
+ }, []);
1044
+ return null;
1045
+ };
1046
+ // src/hooks/WebWorker.ts
1047
+ import { useCallback as useCallback2, useEffect as useEffect4, useRef as useRef3 } from "react";
1006
1048
  export { useDeepCompareEffect, useDeepCompareMemo, useDocumentTitle, useSafeEffect, useSetUserCountry, useSmartSnapshot, useSnapshotBulk, useSocketSubscription };
1007
1049
  //# sourceMappingURL=index.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akeyless-client-commons",
3
- "version": "1.1.11",
3
+ "version": "1.1.13",
4
4
  "scripts": {
5
5
  "build": "tsup",
6
6
  "deploy": "npm run build && npm version patch --no-git-tag-version && npm publish",