akeyless-client-commons 1.1.17-test.9 → 1.1.19

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.
@@ -1,15 +1,4 @@
1
1
  // src/hooks/global.ts
2
- function _array_like_to_array(arr, len) {
3
- if (len == null || len > arr.length) len = arr.length;
4
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
5
- return arr2;
6
- }
7
- function _array_with_holes(arr) {
8
- if (Array.isArray(arr)) return arr;
9
- }
10
- function _array_without_holes(arr) {
11
- if (Array.isArray(arr)) return _array_like_to_array(arr);
12
- }
13
2
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
14
3
  try {
15
4
  var info = gen[key](arg);
@@ -39,25 +28,6 @@ function _async_to_generator(fn) {
39
28
  });
40
29
  };
41
30
  }
42
- function _class_call_check(instance, Constructor) {
43
- if (!(instance instanceof Constructor)) {
44
- throw new TypeError("Cannot call a class as a function");
45
- }
46
- }
47
- function _defineProperties(target, props) {
48
- for(var i = 0; i < props.length; i++){
49
- var descriptor = props[i];
50
- descriptor.enumerable = descriptor.enumerable || false;
51
- descriptor.configurable = true;
52
- if ("value" in descriptor) descriptor.writable = true;
53
- Object.defineProperty(target, descriptor.key, descriptor);
54
- }
55
- }
56
- function _create_class(Constructor, protoProps, staticProps) {
57
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
58
- if (staticProps) _defineProperties(Constructor, staticProps);
59
- return Constructor;
60
- }
61
31
  function _define_property(obj, key, value) {
62
32
  if (key in obj) {
63
33
  Object.defineProperty(obj, key, {
@@ -71,39 +41,6 @@ function _define_property(obj, key, value) {
71
41
  }
72
42
  return obj;
73
43
  }
74
- function _iterable_to_array(iter) {
75
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
76
- }
77
- function _iterable_to_array_limit(arr, i) {
78
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
79
- if (_i == null) return;
80
- var _arr = [];
81
- var _n = true;
82
- var _d = false;
83
- var _s, _e;
84
- try {
85
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
86
- _arr.push(_s.value);
87
- if (i && _arr.length === i) break;
88
- }
89
- } catch (err) {
90
- _d = true;
91
- _e = err;
92
- } finally{
93
- try {
94
- if (!_n && _i["return"] != null) _i["return"]();
95
- } finally{
96
- if (_d) throw _e;
97
- }
98
- }
99
- return _arr;
100
- }
101
- function _non_iterable_rest() {
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.");
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
- }
107
44
  function _object_spread(target) {
108
45
  for(var i = 1; i < arguments.length; i++){
109
46
  var source = arguments[i] != null ? arguments[i] : {};
@@ -143,20 +80,6 @@ function _object_spread_props(target, source) {
143
80
  }
144
81
  return target;
145
82
  }
146
- function _sliced_to_array(arr, i) {
147
- return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
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
- }
152
- function _unsupported_iterable_to_array(o, minLen) {
153
- if (!o) return;
154
- if (typeof o === "string") return _array_like_to_array(o, minLen);
155
- var n = Object.prototype.toString.call(o).slice(8, -1);
156
- if (n === "Object" && o.constructor) n = o.constructor.name;
157
- if (n === "Map" || n === "Set") return Array.from(n);
158
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
159
- }
160
83
  function _ts_generator(thisArg, body) {
161
84
  var f, y, t, g, _ = {
162
85
  label: 0,
@@ -253,7 +176,7 @@ function _ts_generator(thisArg, body) {
253
176
  }
254
177
  }
255
178
  import { CountryOptions as CountryOptions2 } from "akeyless-types-commons";
256
- import { useEffect, useLayoutEffect } from "react";
179
+ import { useEffect as useEffect2, useLayoutEffect, useRef as useRef2 } from "react";
257
180
  // src/helpers/firebase.ts
258
181
  import moment from "moment";
259
182
  import { initializeApp } from "firebase/app";
@@ -356,50 +279,6 @@ var simpleExtractData = function(doc2) {
356
279
  id: doc2.id
357
280
  });
358
281
  };
359
- var get_document_by_id = /*#__PURE__*/ function() {
360
- var _ref = _async_to_generator(function(collection_path, doc_id) {
361
- var doc_ref, doc_snap, error;
362
- return _ts_generator(this, function(_state) {
363
- switch(_state.label){
364
- case 0:
365
- _state.trys.push([
366
- 0,
367
- 2,
368
- ,
369
- 3
370
- ]);
371
- doc_ref = doc(db, collection_path, doc_id);
372
- return [
373
- 4,
374
- getDoc(doc_ref)
375
- ];
376
- case 1:
377
- doc_snap = _state.sent();
378
- if (!doc_snap.exists()) {
379
- throw new Error("Document not found, document id: " + doc_id);
380
- }
381
- return [
382
- 2,
383
- simpleExtractData(doc_snap)
384
- ];
385
- case 2:
386
- error = _state.sent();
387
- console.error("Error from get_document_by_id", error);
388
- return [
389
- 2,
390
- null
391
- ];
392
- case 3:
393
- return [
394
- 2
395
- ];
396
- }
397
- });
398
- });
399
- return function get_document_by_id(collection_path, doc_id) {
400
- return _ref.apply(this, arguments);
401
- };
402
- }();
403
282
  var snapshot = function(config, snapshotsFirstTime, settings) {
404
283
  var resolvePromise;
405
284
  var isResolved = false;
@@ -425,11 +304,11 @@ var snapshot = function(config, snapshotsFirstTime, settings) {
425
304
  collectionRef = query(collectionRef, orderBy(order.fieldName, order.direction));
426
305
  });
427
306
  }
428
- var unsubscribe = onSnapshot(collectionRef, function(snapshot3) {
307
+ var unsubscribe = onSnapshot(collectionRef, function(snapshot2) {
429
308
  if (!snapshotsFirstTime.includes(config.collectionName)) {
430
309
  var _config_onFirstTime, _config_extraParsers;
431
310
  snapshotsFirstTime.push(config.collectionName);
432
- var documents = snapshot3.docs.map(function(doc2) {
311
+ var documents = snapshot2.docs.map(function(doc2) {
433
312
  return simpleExtractData(doc2);
434
313
  });
435
314
  (_config_onFirstTime = config.onFirstTime) === null || _config_onFirstTime === void 0 ? void 0 : _config_onFirstTime.call(config, documents, config);
@@ -443,7 +322,7 @@ var snapshot = function(config, snapshotsFirstTime, settings) {
443
322
  var addedDocs = [];
444
323
  var modifiedDocs = [];
445
324
  var removedDocs = [];
446
- snapshot3.docChanges().forEach(function(change) {
325
+ snapshot2.docChanges().forEach(function(change) {
447
326
  if (change.type === "added") {
448
327
  addedDocs.push(simpleExtractData(change.doc));
449
328
  } else if (change.type === "modified") {
@@ -546,358 +425,11 @@ var biDomain = isLocal ? "http://localhost:9002/api/bi" : baseDomain + "/bi";
546
425
  var notificationsDomain = isLocal ? "http://localhost:9006/api/notifications" : baseDomain + "/notifications";
547
426
  var callCenterGeoDomain = isLocal ? "http://localhost:9007/api/call-center/geo" : baseDomain + "/call-center/geo";
548
427
  var callCenterEventsDomain = isLocal ? "http://localhost:9008/api/call-center/events" : baseDomain + "/call-center/events";
549
- var dataSocketDomain = isLocal ? "http://localhost:9009/api/data-socket" : baseDomain + "/data-socket";
550
- var dataSyncDomain = isLocal ? "http://localhost:9010/api/data-sync" : baseDomain + "/data-sync";
551
- // src/helpers/socket.ts
552
- import { io } from "socket.io-client";
553
- var SESSION_STORAGE_KEY = "sessionId";
554
- var SocketService = /*#__PURE__*/ function() {
555
- "use strict";
556
- function _SocketService() {
557
- _class_call_check(this, _SocketService);
558
- this.socket = null;
559
- this.connectCallbacks = [];
560
- this.disconnectCallbacks = [];
561
- this.authToken = null;
562
- }
563
- _create_class(_SocketService, [
564
- {
565
- /// Initialize the socket connection
566
- key: "initSocket",
567
- value: function initSocket() {
568
- var _this = this;
569
- if (!this.socket) {
570
- var socketUrl = isLocal ? "http://localhost:9009" : mode === "qa" ? "https://nx-api.xyz" : "https://nx-api.info";
571
- this.socket = io(socketUrl, {
572
- path: "/api/data-socket/connect",
573
- auth: function(cb) {
574
- var sessionId = localStorage.getItem(SESSION_STORAGE_KEY) || void 0;
575
- var token = _this.authToken;
576
- var authPayload = {};
577
- if (token) authPayload.token = token;
578
- if (sessionId) authPayload.sessionId = sessionId;
579
- cb(authPayload);
580
- },
581
- reconnection: true,
582
- reconnectionAttempts: 30,
583
- reconnectionDelay: 2 * 1e3
584
- });
585
- this.socket.on("connect", function() {
586
- var _this_socket, _this_socket1;
587
- console.log("\uD83D\uDFE2 Socket connected: ".concat((_this_socket = _this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.id, " (recovered - ").concat((_this_socket1 = _this.socket) === null || _this_socket1 === void 0 ? void 0 : _this_socket1.recovered, ")"));
588
- _this.connectCallbacks.forEach(function(cb) {
589
- return cb();
590
- });
591
- });
592
- this.socket.on("disconnect", function(reason) {
593
- console.log("Socket disconnected:", reason);
594
- _this.disconnectCallbacks.forEach(function(cb) {
595
- return cb();
596
- });
597
- });
598
- this.socket.on("session", function(param) {
599
- var sessionId = param.sessionId;
600
- if (sessionId) {
601
- localStorage.setItem(SESSION_STORAGE_KEY, sessionId);
602
- }
603
- });
604
- this.socket.on("connect_error", function(error) {
605
- console.error("Socket connection error:", error);
606
- });
607
- }
608
- }
609
- },
610
- {
611
- /// get socket instance
612
- key: "getSocketInstance",
613
- value: function getSocketInstance() {
614
- if (!this.socket) {
615
- this.initSocket();
616
- }
617
- if (!this.socket) {
618
- throw new Error("Socket not initialized");
619
- }
620
- if (!this.socket.connected) {
621
- this.socket.connect();
622
- }
623
- return this.socket;
624
- }
625
- },
626
- {
627
- /// connection management methods
628
- key: "startSession",
629
- value: function startSession(token) {
630
- this.setAuthToken(token);
631
- this.initSocket();
632
- }
633
- },
634
- {
635
- key: "onConnect",
636
- value: function onConnect(callback) {
637
- var _this = this;
638
- var _this_socket;
639
- if (!this.connectCallbacks.includes(callback)) {
640
- this.connectCallbacks.push(callback);
641
- }
642
- if ((_this_socket = this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.connected) {
643
- callback();
644
- }
645
- return function() {
646
- return _this.offConnect(callback);
647
- };
648
- }
649
- },
650
- {
651
- key: "offConnect",
652
- value: function offConnect(callback) {
653
- this.connectCallbacks = this.connectCallbacks.filter(function(cb) {
654
- return cb !== callback;
655
- });
656
- }
657
- },
658
- {
659
- key: "onDisconnect",
660
- value: function onDisconnect(callback) {
661
- var _this = this;
662
- if (!this.disconnectCallbacks.includes(callback)) {
663
- this.disconnectCallbacks.push(callback);
664
- }
665
- if (this.socket && !this.socket.connected) {
666
- callback();
667
- }
668
- return function() {
669
- return _this.offDisconnect(callback);
670
- };
671
- }
672
- },
673
- {
674
- key: "offDisconnect",
675
- value: function offDisconnect(callback) {
676
- this.disconnectCallbacks = this.disconnectCallbacks.filter(function(cb) {
677
- return cb !== callback;
678
- });
679
- }
680
- },
681
- {
682
- key: "isConnected",
683
- value: function isConnected() {
684
- var _this_socket;
685
- return ((_this_socket = this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.connected) || false;
686
- }
687
- },
688
- {
689
- key: "setAuthToken",
690
- value: function setAuthToken(token) {
691
- this.authToken = token;
692
- if (this.socket) {
693
- this.socket.connect();
694
- }
695
- }
696
- },
697
- {
698
- key: "disconnectSocket",
699
- value: function disconnectSocket() {
700
- if (this.socket) {
701
- this.socket.io.engine.close();
702
- }
703
- }
704
- },
705
- {
706
- /// subscribe to collections
707
- key: "subscribeToCollections",
708
- value: function subscribeToCollections(config) {
709
- var _this = this;
710
- if (config.length === 0) {
711
- return function() {};
712
- }
713
- var s = this.getSocketInstance();
714
- var collectionsNames = config.map(function(c) {
715
- return c.collectionName;
716
- });
717
- var eventHandlers = [];
718
- config.forEach(function(configuration) {
719
- var collectionName = configuration.collectionName, onAdd = configuration.onAdd, onFirstTime = configuration.onFirstTime, onModify = configuration.onModify, onRemove = configuration.onRemove, extraParsers = configuration.extraParsers, conditions = configuration.conditions, orderBy2 = configuration.orderBy;
720
- var attach = function(eventName, handler) {
721
- _this.socket.off(eventName, handler);
722
- _this.socket.on(eventName, handler);
723
- eventHandlers.push({
724
- eventName: eventName,
725
- handler: handler
726
- });
727
- };
728
- attach("initial:".concat(collectionName), onFirstTime);
729
- attach("add:".concat(collectionName), onAdd);
730
- attach("update:".concat(collectionName), onModify);
731
- attach("delete:".concat(collectionName), onRemove);
732
- extraParsers === null || extraParsers === void 0 ? void 0 : extraParsers.forEach(function(parsers) {
733
- var extraOnAdd = parsers.onAdd, extraOnFirstTime = parsers.onFirstTime, extraOnModify = parsers.onModify, extraOnRemove = parsers.onRemove;
734
- attach("initial:".concat(collectionName), extraOnFirstTime);
735
- attach("add:".concat(collectionName), extraOnAdd);
736
- attach("update:".concat(collectionName), extraOnModify);
737
- attach("delete:".concat(collectionName), extraOnRemove);
738
- });
739
- });
740
- s.emit("subscribe_collections", collectionsNames, function(callback) {
741
- if (callback.success) {
742
- console.log("Successfully subscribed to: ".concat(collectionsNames.join(", ")));
743
- } else {
744
- console.error("Failed to subscribe to ".concat(config.join(", "), ": ").concat(callback.message));
745
- }
746
- });
747
- return function() {
748
- console.log("Cleaning up subscriptions for: ".concat(collectionsNames.join(", ")));
749
- s.emit("unsubscribe_collections", collectionsNames);
750
- eventHandlers.forEach(function(eh) {
751
- s.off(eh.eventName, eh.handler);
752
- });
753
- };
754
- }
755
- },
756
- {
757
- /// set data
758
- key: "setData",
759
- value: function setData(payload) {
760
- var s = this.getSocketInstance();
761
- return new Promise(function(resolve, reject) {
762
- s.emit("set_data", payload, function(callback) {
763
- if (callback.success) {
764
- console.log("Data saved successfully:", payload);
765
- console.log("ack", callback);
766
- resolve(callback);
767
- } else {
768
- reject(new Error(callback.message || "Save operation failed"));
769
- }
770
- });
771
- });
772
- }
773
- },
774
- {
775
- /// get data
776
- key: "getCollectionData",
777
- value: function getCollectionData(payload) {
778
- var s = this.getSocketInstance();
779
- s.emit("get_data", {
780
- collection_name: payload.collection_name
781
- }, function(socketCallback) {
782
- if (socketCallback.success && socketCallback.data) {
783
- payload.callback(socketCallback.data);
784
- } else {
785
- payload.callback(payload.defaultValue);
786
- }
787
- });
788
- }
789
- },
790
- {
791
- key: "getDocumentData",
792
- value: function getDocumentData(payload) {
793
- var s = this.getSocketInstance();
794
- s.emit("get_data", {
795
- collection_name: payload.collection_name,
796
- key: payload.key
797
- }, function(socketCallback) {
798
- if (socketCallback.success && socketCallback.data) {
799
- payload.callback(socketCallback.data);
800
- } else {
801
- payload.callback(payload.defaultValue);
802
- }
803
- });
804
- }
805
- },
806
- {
807
- /// delete data
808
- key: "deleteData",
809
- value: function deleteData(payload) {
810
- var s = this.getSocketInstance();
811
- return new Promise(function(resolve, reject) {
812
- s.emit("delete_data", payload, function(callback) {
813
- if (callback.success) {
814
- console.log("Data deleted successfully:", payload);
815
- console.log("delete ack", callback);
816
- resolve(callback);
817
- } else {
818
- reject(new Error(callback.message || "Delete operation failed"));
819
- }
820
- });
821
- });
822
- }
823
- },
824
- {
825
- key: "clearAllRedisData",
826
- value: function clearAllRedisData() {
827
- var s = this.getSocketInstance();
828
- return new Promise(function(resolve, reject) {
829
- s.emit("clear_all_redis_data", function(ack) {
830
- if (ack.success) {
831
- resolve(ack);
832
- } else {
833
- reject(new Error(ack.message || "Clear all Redis data operation failed"));
834
- }
835
- });
836
- });
837
- }
838
- }
839
- ], [
840
- {
841
- key: "getInstance",
842
- value: function getInstance() {
843
- if (!_SocketService.instance) {
844
- _SocketService.instance = new _SocketService();
845
- }
846
- return _SocketService.instance;
847
- }
848
- }
849
- ]);
850
- return _SocketService;
851
- }();
852
- var socketServiceInstance = SocketService.getInstance();
853
- // src/hooks/global.ts
854
- var useDocumentTitle = function(title) {
855
- useEffect(function() {
856
- document.title = title;
857
- }, [
858
- title
859
- ]);
860
- return null;
861
- };
862
- var useSetUserCountry = function(setUserCountry, changLang) {
863
- useLayoutEffect(function() {
864
- var currentCountry = localStorage.getItem("userCountry");
865
- if (!currentCountry) {
866
- var updateCountry = /*#__PURE__*/ function() {
867
- var _ref = _async_to_generator(function() {
868
- var country;
869
- return _ts_generator(this, function(_state) {
870
- switch(_state.label){
871
- case 0:
872
- return [
873
- 4,
874
- getUserCountryByIp()
875
- ];
876
- case 1:
877
- country = _state.sent();
878
- changLang(country === CountryOptions2.IL ? "he" : "en");
879
- setUserCountry(country);
880
- localStorage.setItem("userCountry", country);
881
- return [
882
- 2
883
- ];
884
- }
885
- });
886
- });
887
- return function updateCountry() {
888
- return _ref.apply(this, arguments);
889
- };
890
- }();
891
- updateCountry();
892
- }
893
- }, []);
894
- return null;
895
- };
896
428
  // src/hooks/react.ts
897
429
  import { isEqual as isEqual2 } from "lodash";
898
- import { useEffect as useEffect2, useMemo as useMemo2, useRef as useRef2 } from "react";
430
+ import { useEffect, useMemo, useRef } from "react";
899
431
  function useSafeEffect(callback, dependencies, error_message) {
900
- useEffect2(function() {
432
+ useEffect(function() {
901
433
  try {
902
434
  callback();
903
435
  } catch (error) {
@@ -906,105 +438,37 @@ function useSafeEffect(callback, dependencies, error_message) {
906
438
  }, dependencies);
907
439
  }
908
440
  var useDeepCompareMemo = function(factory, dependencies) {
909
- var previousDepsRef = useRef2([]);
441
+ var previousDepsRef = useRef([]);
910
442
  if (!isEqual2(dependencies, previousDepsRef.current)) {
911
443
  previousDepsRef.current = dependencies;
912
444
  }
913
- return useMemo2(factory, previousDepsRef.current);
445
+ return useMemo(factory, previousDepsRef.current);
914
446
  };
915
447
  function useDeepCompareEffect(effect, dependencies) {
916
- var previousDepsRef = useRef2();
448
+ var previousDepsRef = useRef();
917
449
  if (!isEqual2(previousDepsRef.current, dependencies)) {
918
450
  previousDepsRef.current = dependencies;
919
451
  }
920
- useEffect2(effect, [
452
+ useEffect(effect, [
921
453
  previousDepsRef.current
922
454
  ]);
923
455
  }
924
- // src/hooks/WebWorker.ts
925
- import { useCallback as useCallback2, useEffect as useEffect3, useRef as useRef3 } from "react";
926
- // src/hooks/snapshots.ts
927
- import { useEffect as useEffect4, useMemo as useMemo3, useRef as useRef4, useState as useState2 } from "react";
928
- var useSocketSnapshots = function(configs, label, settings) {
929
- var _auth_currentUser;
930
- var _useState2 = _sliced_to_array(useState2(socketServiceInstance.isConnected()), 2), socketConnected = _useState2[0], setSocketConnected = _useState2[1];
931
- var _useState21 = _sliced_to_array(useState2([]), 2), cleanupSubscriptions = _useState21[0], setCleanupSubscriptions = _useState21[1];
932
- var socketStarted = useRef4(false);
933
- useDeepCompareEffect(function() {
934
- if (!auth.currentUser) {
935
- return;
936
- }
937
- var subscribe = function() {
938
- if (configs.length === 0) {
939
- return;
940
- }
941
- var disposer = socketServiceInstance.subscribeToCollections(configs);
942
- setCleanupSubscriptions(function(prev) {
943
- return _to_consumable_array(prev).concat([
944
- disposer
945
- ]);
946
- });
947
- if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
948
- console.log("==> ".concat(label || "Cache snapshots", " subscribed to ").concat(configs.map(function(c) {
949
- return c.collectionName;
950
- }).join(", ")));
951
- }
952
- };
953
- if (socketServiceInstance.isConnected()) {
954
- setSocketConnected(true);
955
- subscribe();
956
- } else if (!socketStarted.current) {
957
- socketStarted.current = true;
958
- auth.currentUser.getIdToken().then(function(token) {
959
- socketServiceInstance.startSession(token);
960
- if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
961
- console.log("==> ".concat(label || "Cache snapshots", " started... "));
962
- }
963
- });
964
- }
965
- var offConnect = socketServiceInstance.onConnect(function() {
966
- setSocketConnected(true);
967
- socketStarted.current = false;
968
- subscribe();
969
- });
970
- var offDisconnect = socketServiceInstance.onDisconnect(function() {
971
- setSocketConnected(false);
972
- cleanupSubscriptions.forEach(function(cleanup) {
973
- return cleanup();
974
- });
975
- });
976
- return function() {
977
- cleanupSubscriptions.forEach(function(cleanup) {
978
- return cleanup();
979
- });
980
- offConnect === null || offConnect === void 0 ? void 0 : offConnect();
981
- offDisconnect === null || offDisconnect === void 0 ? void 0 : offDisconnect();
982
- if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs) && configs.length > 0) {
983
- console.log("==> ".concat(label || "Cache snapshots", " unsubscribed. "));
984
- }
985
- };
456
+ // src/hooks/global.ts
457
+ var useDocumentTitle = function(title) {
458
+ useEffect2(function() {
459
+ document.title = title;
986
460
  }, [
987
- configs,
988
- (_auth_currentUser = auth.currentUser) === null || _auth_currentUser === void 0 ? void 0 : _auth_currentUser.uid
461
+ title
989
462
  ]);
990
- useEffect4(function() {
991
- return function() {
992
- cleanupSubscriptions.forEach(function(cleanup) {
993
- return cleanup();
994
- });
995
- };
996
- }, []);
997
- return {
998
- socketConnected: socketConnected
999
- };
463
+ return null;
1000
464
  };
1001
- var useDbSnapshots = function(configs, label, settings) {
1002
- var snapshotsFirstTime = useRef4([]);
1003
- var unsubscribeFunctions = useRef4([]);
465
+ var useSnapshotBulk = function(configs, label, settings) {
466
+ var snapshotsFirstTime = useRef2([]);
467
+ var unsubscribeFunctions = useRef2([]);
1004
468
  useDeepCompareEffect(function() {
1005
469
  var start = performance.now();
1006
- if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs) && configs.length > 0) {
1007
- console.log("==> ".concat(label || "DB snapshots", " started from db... "));
470
+ if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
471
+ console.log("==> ".concat(label || "Custom snapshots", " started... "));
1008
472
  }
1009
473
  var snapshotResults = configs.map(function(config) {
1010
474
  return snapshot(config, snapshotsFirstTime.current, settings);
@@ -1015,8 +479,8 @@ var useDbSnapshots = function(configs, label, settings) {
1015
479
  Promise.all(snapshotResults.map(function(result) {
1016
480
  return result.promise;
1017
481
  })).then(function() {
1018
- if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs) && configs.length > 0) {
1019
- console.log("==> ".concat(label || "DB snapshots", " ended from db. It took ").concat((performance.now() - start).toFixed(2), " ms"));
482
+ if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
483
+ console.log("==> ".concat(label || "Custom snapshots", " ended. It took ").concat((performance.now() - start).toFixed(2), " ms"));
1020
484
  }
1021
485
  });
1022
486
  if (settings === null || settings === void 0 ? void 0 : settings.cleanupForConfigChange) {
@@ -1026,8 +490,8 @@ var useDbSnapshots = function(configs, label, settings) {
1026
490
  unsubscribe();
1027
491
  }
1028
492
  });
1029
- if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs) && configs.length > 0) {
1030
- console.log("==> ".concat(label || "DB snapshots", " unsubscribed from db"));
493
+ if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
494
+ console.log("==> ".concat(label || "Custom snapshots", " unsubscribed"));
1031
495
  }
1032
496
  };
1033
497
  }
@@ -1036,7 +500,7 @@ var useDbSnapshots = function(configs, label, settings) {
1036
500
  label,
1037
501
  settings
1038
502
  ]);
1039
- useEffect4(function() {
503
+ useEffect2(function() {
1040
504
  return function() {
1041
505
  unsubscribeFunctions.current.forEach(function(unsubscribe) {
1042
506
  if (unsubscribe) {
@@ -1044,52 +508,46 @@ var useDbSnapshots = function(configs, label, settings) {
1044
508
  }
1045
509
  });
1046
510
  if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
1047
- console.log("==> ".concat(label || "DB snapshots", " unsubscribed"));
511
+ console.log("==> ".concat(label || "Custom snapshots", " unsubscribed"));
1048
512
  }
1049
513
  };
1050
514
  }, []);
1051
515
  };
1052
- var useSmartSnapshots = function(configs, label, settings) {
1053
- var _useState2 = _sliced_to_array(useState2(null), 2), cacheCollectionsConfig = _useState2[0], setCacheCollectionsConfig = _useState2[1];
1054
- useEffect4(function() {
1055
- get_document_by_id("nx-settings", "cache_collections_config").then(function(res) {
1056
- return setCacheCollectionsConfig(res);
1057
- });
1058
- return function() {
1059
- return setCacheCollectionsConfig(null);
1060
- };
1061
- }, []);
1062
- var groupedConfig = useMemo3(function() {
1063
- if (!cacheCollectionsConfig) {
1064
- return {
1065
- configForDb: [],
1066
- configForCache: []
1067
- };
516
+ var useSetUserCountry = function(setUserCountry, changLang) {
517
+ useLayoutEffect(function() {
518
+ var currentCountry = localStorage.getItem("userCountry");
519
+ if (!currentCountry) {
520
+ var updateCountry = /*#__PURE__*/ function() {
521
+ var _ref = _async_to_generator(function() {
522
+ var country;
523
+ return _ts_generator(this, function(_state) {
524
+ switch(_state.label){
525
+ case 0:
526
+ return [
527
+ 4,
528
+ getUserCountryByIp()
529
+ ];
530
+ case 1:
531
+ country = _state.sent();
532
+ changLang(country === CountryOptions2.IL ? "he" : "en");
533
+ setUserCountry(country);
534
+ localStorage.setItem("userCountry", country);
535
+ return [
536
+ 2
537
+ ];
538
+ }
539
+ });
540
+ });
541
+ return function updateCountry() {
542
+ return _ref.apply(this, arguments);
543
+ };
544
+ }();
545
+ updateCountry();
1068
546
  }
1069
- var configForDb = [];
1070
- var configForCache = [];
1071
- configs.forEach(function(cfg) {
1072
- var collectionName = cfg.collectionName, _cfg_subscribeTo = cfg.subscribeTo, subscribeTo = _cfg_subscribeTo === void 0 ? "cache" : _cfg_subscribeTo;
1073
- if (subscribeTo === "cache" && cacheCollectionsConfig[collectionName]) {
1074
- configForCache.push(cfg);
1075
- } else {
1076
- configForDb.push(cfg);
1077
- }
1078
- });
1079
- return {
1080
- configForDb: configForDb,
1081
- configForCache: configForCache
1082
- };
1083
- }, [
1084
- configs,
1085
- cacheCollectionsConfig
1086
- ]);
1087
- useDbSnapshots(groupedConfig.configForDb, label, settings);
1088
- var socketConnected = useSocketSnapshots(groupedConfig.configForCache, label, settings).socketConnected;
1089
- return {
1090
- groupedConfig: groupedConfig,
1091
- socketConnected: socketConnected
1092
- };
547
+ }, []);
548
+ return null;
1093
549
  };
1094
- export { useDbSnapshots, useDeepCompareEffect, useDeepCompareMemo, useDocumentTitle, useSafeEffect, useSetUserCountry, useSmartSnapshots, useSocketSnapshots };
550
+ // src/hooks/WebWorker.ts
551
+ import { useCallback as useCallback2, useEffect as useEffect3, useRef as useRef3 } from "react";
552
+ export { useDeepCompareEffect, useDeepCompareMemo, useDocumentTitle, useSafeEffect, useSetUserCountry, useSnapshotBulk };
1095
553
  //# sourceMappingURL=index.mjs.map