akeyless-client-commons 1.1.17-test.8 → 1.1.17-test.9
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/components/index.js +119 -109
- package/dist/components/index.mjs +119 -109
- package/dist/helpers/index.d.mts +9 -8
- package/dist/helpers/index.d.ts +9 -8
- package/dist/helpers/index.js +119 -109
- package/dist/helpers/index.mjs +119 -109
- package/dist/helpers/index.mjs.map +1 -1
- package/dist/hooks/index.d.mts +16 -16
- package/dist/hooks/index.d.ts +16 -16
- package/dist/hooks/index.js +224 -208
- package/dist/hooks/index.mjs +220 -204
- package/dist/hooks/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/hooks/index.mjs
CHANGED
|
@@ -253,7 +253,7 @@ function _ts_generator(thisArg, body) {
|
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
255
|
import { CountryOptions as CountryOptions2 } from "akeyless-types-commons";
|
|
256
|
-
import { useEffect
|
|
256
|
+
import { useEffect, useLayoutEffect } from "react";
|
|
257
257
|
// src/helpers/firebase.ts
|
|
258
258
|
import moment from "moment";
|
|
259
259
|
import { initializeApp } from "firebase/app";
|
|
@@ -425,11 +425,11 @@ var snapshot = function(config, snapshotsFirstTime, settings) {
|
|
|
425
425
|
collectionRef = query(collectionRef, orderBy(order.fieldName, order.direction));
|
|
426
426
|
});
|
|
427
427
|
}
|
|
428
|
-
var unsubscribe = onSnapshot(collectionRef, function(
|
|
428
|
+
var unsubscribe = onSnapshot(collectionRef, function(snapshot3) {
|
|
429
429
|
if (!snapshotsFirstTime.includes(config.collectionName)) {
|
|
430
430
|
var _config_onFirstTime, _config_extraParsers;
|
|
431
431
|
snapshotsFirstTime.push(config.collectionName);
|
|
432
|
-
var documents =
|
|
432
|
+
var documents = snapshot3.docs.map(function(doc2) {
|
|
433
433
|
return simpleExtractData(doc2);
|
|
434
434
|
});
|
|
435
435
|
(_config_onFirstTime = config.onFirstTime) === null || _config_onFirstTime === void 0 ? void 0 : _config_onFirstTime.call(config, documents, config);
|
|
@@ -443,7 +443,7 @@ var snapshot = function(config, snapshotsFirstTime, settings) {
|
|
|
443
443
|
var addedDocs = [];
|
|
444
444
|
var modifiedDocs = [];
|
|
445
445
|
var removedDocs = [];
|
|
446
|
-
|
|
446
|
+
snapshot3.docChanges().forEach(function(change) {
|
|
447
447
|
if (change.type === "added") {
|
|
448
448
|
addedDocs.push(simpleExtractData(change.doc));
|
|
449
449
|
} else if (change.type === "modified") {
|
|
@@ -550,6 +550,7 @@ var dataSocketDomain = isLocal ? "http://localhost:9009/api/data-socket" : baseD
|
|
|
550
550
|
var dataSyncDomain = isLocal ? "http://localhost:9010/api/data-sync" : baseDomain + "/data-sync";
|
|
551
551
|
// src/helpers/socket.ts
|
|
552
552
|
import { io } from "socket.io-client";
|
|
553
|
+
var SESSION_STORAGE_KEY = "sessionId";
|
|
553
554
|
var SocketService = /*#__PURE__*/ function() {
|
|
554
555
|
"use strict";
|
|
555
556
|
function _SocketService() {
|
|
@@ -569,19 +570,24 @@ var SocketService = /*#__PURE__*/ function() {
|
|
|
569
570
|
var socketUrl = isLocal ? "http://localhost:9009" : mode === "qa" ? "https://nx-api.xyz" : "https://nx-api.info";
|
|
570
571
|
this.socket = io(socketUrl, {
|
|
571
572
|
path: "/api/data-socket/connect",
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
token
|
|
577
|
-
|
|
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
|
|
578
584
|
});
|
|
579
585
|
this.socket.on("connect", function() {
|
|
580
|
-
var _this_socket;
|
|
581
|
-
console.log("Socket connected:"
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
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
|
+
});
|
|
585
591
|
});
|
|
586
592
|
this.socket.on("disconnect", function(reason) {
|
|
587
593
|
console.log("Socket disconnected:", reason);
|
|
@@ -589,6 +595,12 @@ var SocketService = /*#__PURE__*/ function() {
|
|
|
589
595
|
return cb();
|
|
590
596
|
});
|
|
591
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
|
+
});
|
|
592
604
|
this.socket.on("connect_error", function(error) {
|
|
593
605
|
console.error("Socket connection error:", error);
|
|
594
606
|
});
|
|
@@ -611,10 +623,90 @@ var SocketService = /*#__PURE__*/ function() {
|
|
|
611
623
|
return this.socket;
|
|
612
624
|
}
|
|
613
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
|
+
},
|
|
614
705
|
{
|
|
615
706
|
/// subscribe to collections
|
|
616
707
|
key: "subscribeToCollections",
|
|
617
708
|
value: function subscribeToCollections(config) {
|
|
709
|
+
var _this = this;
|
|
618
710
|
if (config.length === 0) {
|
|
619
711
|
return function() {};
|
|
620
712
|
}
|
|
@@ -625,48 +717,24 @@ var SocketService = /*#__PURE__*/ function() {
|
|
|
625
717
|
var eventHandlers = [];
|
|
626
718
|
config.forEach(function(configuration) {
|
|
627
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;
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
eventName
|
|
631
|
-
handler: onFirstTime
|
|
632
|
-
});
|
|
633
|
-
s.on("add:".concat(collectionName), onAdd);
|
|
634
|
-
eventHandlers.push({
|
|
635
|
-
eventName: "add:".concat(collectionName),
|
|
636
|
-
handler: onAdd
|
|
637
|
-
});
|
|
638
|
-
s.on("update:".concat(collectionName), onModify);
|
|
639
|
-
eventHandlers.push({
|
|
640
|
-
eventName: "update:".concat(collectionName),
|
|
641
|
-
handler: onModify
|
|
642
|
-
});
|
|
643
|
-
s.on("delete:".concat(collectionName), onRemove);
|
|
644
|
-
eventHandlers.push({
|
|
645
|
-
eventName: "delete:".concat(collectionName),
|
|
646
|
-
handler: onRemove
|
|
647
|
-
});
|
|
648
|
-
extraParsers === null || extraParsers === void 0 ? void 0 : extraParsers.forEach(function(parsers) {
|
|
649
|
-
var extraOnAdd = parsers.onAdd, extraOnFirstTime = parsers.onFirstTime, extraOnModify = parsers.onModify, extraOnRemove = parsers.onRemove;
|
|
650
|
-
s.on("initial:".concat(collectionName), extraOnFirstTime);
|
|
720
|
+
var attach = function(eventName, handler) {
|
|
721
|
+
_this.socket.off(eventName, handler);
|
|
722
|
+
_this.socket.on(eventName, handler);
|
|
651
723
|
eventHandlers.push({
|
|
652
|
-
eventName:
|
|
653
|
-
handler:
|
|
654
|
-
});
|
|
655
|
-
s.on("add:".concat(collectionName), extraOnAdd);
|
|
656
|
-
eventHandlers.push({
|
|
657
|
-
eventName: "add:".concat(collectionName),
|
|
658
|
-
handler: extraOnAdd
|
|
659
|
-
});
|
|
660
|
-
s.on("update:".concat(collectionName), extraOnModify);
|
|
661
|
-
eventHandlers.push({
|
|
662
|
-
eventName: "update:".concat(collectionName),
|
|
663
|
-
handler: extraOnModify
|
|
664
|
-
});
|
|
665
|
-
s.on("delete:".concat(collectionName), extraOnRemove);
|
|
666
|
-
eventHandlers.push({
|
|
667
|
-
eventName: "delete:".concat(collectionName),
|
|
668
|
-
handler: extraOnRemove
|
|
724
|
+
eventName: eventName,
|
|
725
|
+
handler: handler
|
|
669
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);
|
|
670
738
|
});
|
|
671
739
|
});
|
|
672
740
|
s.emit("subscribe_collections", collectionsNames, function(callback) {
|
|
@@ -767,64 +835,6 @@ var SocketService = /*#__PURE__*/ function() {
|
|
|
767
835
|
});
|
|
768
836
|
});
|
|
769
837
|
}
|
|
770
|
-
},
|
|
771
|
-
{
|
|
772
|
-
/// connection management methods
|
|
773
|
-
key: "onConnect",
|
|
774
|
-
value: function onConnect(callback) {
|
|
775
|
-
var _this_socket;
|
|
776
|
-
this.connectCallbacks.push(callback);
|
|
777
|
-
if ((_this_socket = this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.connected) {
|
|
778
|
-
callback();
|
|
779
|
-
}
|
|
780
|
-
}
|
|
781
|
-
},
|
|
782
|
-
{
|
|
783
|
-
key: "offConnect",
|
|
784
|
-
value: function offConnect(callback) {
|
|
785
|
-
this.connectCallbacks = this.connectCallbacks.filter(function(cb) {
|
|
786
|
-
return cb !== callback;
|
|
787
|
-
});
|
|
788
|
-
}
|
|
789
|
-
},
|
|
790
|
-
{
|
|
791
|
-
key: "onDisconnect",
|
|
792
|
-
value: function onDisconnect(callback) {
|
|
793
|
-
this.disconnectCallbacks.push(callback);
|
|
794
|
-
if (this.socket && !this.socket.connected) {
|
|
795
|
-
callback();
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
},
|
|
799
|
-
{
|
|
800
|
-
key: "offDisconnect",
|
|
801
|
-
value: function offDisconnect(callback) {
|
|
802
|
-
this.disconnectCallbacks = this.disconnectCallbacks.filter(function(cb) {
|
|
803
|
-
return cb !== callback;
|
|
804
|
-
});
|
|
805
|
-
}
|
|
806
|
-
},
|
|
807
|
-
{
|
|
808
|
-
key: "isConnected",
|
|
809
|
-
value: function isConnected() {
|
|
810
|
-
var _this_socket;
|
|
811
|
-
return ((_this_socket = this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.connected) || false;
|
|
812
|
-
}
|
|
813
|
-
},
|
|
814
|
-
{
|
|
815
|
-
key: "setAuthToken",
|
|
816
|
-
value: function setAuthToken(token) {
|
|
817
|
-
this.authToken = token;
|
|
818
|
-
if (this.socket) {
|
|
819
|
-
this.socket.auth = {
|
|
820
|
-
token: token
|
|
821
|
-
};
|
|
822
|
-
if (this.socket.connected) {
|
|
823
|
-
this.socket.disconnect();
|
|
824
|
-
}
|
|
825
|
-
this.socket.connect();
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
838
|
}
|
|
829
839
|
], [
|
|
830
840
|
{
|
|
@@ -840,11 +850,54 @@ var SocketService = /*#__PURE__*/ function() {
|
|
|
840
850
|
return _SocketService;
|
|
841
851
|
}();
|
|
842
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
|
+
};
|
|
843
896
|
// src/hooks/react.ts
|
|
844
897
|
import { isEqual as isEqual2 } from "lodash";
|
|
845
|
-
import { useEffect, useMemo, useRef } from "react";
|
|
898
|
+
import { useEffect as useEffect2, useMemo as useMemo2, useRef as useRef2 } from "react";
|
|
846
899
|
function useSafeEffect(callback, dependencies, error_message) {
|
|
847
|
-
|
|
900
|
+
useEffect2(function() {
|
|
848
901
|
try {
|
|
849
902
|
callback();
|
|
850
903
|
} catch (error) {
|
|
@@ -853,80 +906,88 @@ function useSafeEffect(callback, dependencies, error_message) {
|
|
|
853
906
|
}, dependencies);
|
|
854
907
|
}
|
|
855
908
|
var useDeepCompareMemo = function(factory, dependencies) {
|
|
856
|
-
var previousDepsRef =
|
|
909
|
+
var previousDepsRef = useRef2([]);
|
|
857
910
|
if (!isEqual2(dependencies, previousDepsRef.current)) {
|
|
858
911
|
previousDepsRef.current = dependencies;
|
|
859
912
|
}
|
|
860
|
-
return
|
|
913
|
+
return useMemo2(factory, previousDepsRef.current);
|
|
861
914
|
};
|
|
862
915
|
function useDeepCompareEffect(effect, dependencies) {
|
|
863
|
-
var previousDepsRef =
|
|
916
|
+
var previousDepsRef = useRef2();
|
|
864
917
|
if (!isEqual2(previousDepsRef.current, dependencies)) {
|
|
865
918
|
previousDepsRef.current = dependencies;
|
|
866
919
|
}
|
|
867
|
-
|
|
920
|
+
useEffect2(effect, [
|
|
868
921
|
previousDepsRef.current
|
|
869
922
|
]);
|
|
870
923
|
}
|
|
871
|
-
// src/hooks/
|
|
872
|
-
import { useEffect as
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
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);
|
|
876
933
|
useDeepCompareEffect(function() {
|
|
877
934
|
if (!auth.currentUser) {
|
|
878
935
|
return;
|
|
879
936
|
}
|
|
880
|
-
|
|
937
|
+
var subscribe = function() {
|
|
938
|
+
if (configs.length === 0) {
|
|
939
|
+
return;
|
|
940
|
+
}
|
|
941
|
+
var disposer = socketServiceInstance.subscribeToCollections(configs);
|
|
881
942
|
setCleanupSubscriptions(function(prev) {
|
|
882
943
|
return _to_consumable_array(prev).concat([
|
|
883
|
-
|
|
944
|
+
disposer
|
|
884
945
|
]);
|
|
885
946
|
});
|
|
886
|
-
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)
|
|
947
|
+
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
|
|
887
948
|
console.log("==> ".concat(label || "Cache snapshots", " subscribed to ").concat(configs.map(function(c) {
|
|
888
949
|
return c.collectionName;
|
|
889
950
|
}).join(", ")));
|
|
890
951
|
}
|
|
891
|
-
}
|
|
952
|
+
};
|
|
953
|
+
if (socketServiceInstance.isConnected()) {
|
|
954
|
+
setSocketConnected(true);
|
|
955
|
+
subscribe();
|
|
956
|
+
} else if (!socketStarted.current) {
|
|
957
|
+
socketStarted.current = true;
|
|
892
958
|
auth.currentUser.getIdToken().then(function(token) {
|
|
893
|
-
socketServiceInstance.
|
|
894
|
-
|
|
895
|
-
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs) && configs.length > 0) {
|
|
959
|
+
socketServiceInstance.startSession(token);
|
|
960
|
+
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
|
|
896
961
|
console.log("==> ".concat(label || "Cache snapshots", " started... "));
|
|
897
962
|
}
|
|
898
963
|
});
|
|
899
964
|
}
|
|
900
|
-
var
|
|
965
|
+
var offConnect = socketServiceInstance.onConnect(function() {
|
|
901
966
|
setSocketConnected(true);
|
|
902
|
-
|
|
903
|
-
|
|
967
|
+
socketStarted.current = false;
|
|
968
|
+
subscribe();
|
|
969
|
+
});
|
|
970
|
+
var offDisconnect = socketServiceInstance.onDisconnect(function() {
|
|
971
|
+
setSocketConnected(false);
|
|
904
972
|
cleanupSubscriptions.forEach(function(cleanup) {
|
|
905
973
|
return cleanup();
|
|
906
974
|
});
|
|
907
|
-
|
|
908
|
-
};
|
|
909
|
-
socketServiceInstance.onConnect(uiOnConnect);
|
|
910
|
-
socketServiceInstance.onDisconnect(uiOnDisconnect);
|
|
911
|
-
setSocketConnected(socketServiceInstance.isConnected());
|
|
975
|
+
});
|
|
912
976
|
return function() {
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
socketServiceInstance.offDisconnect(uiOnDisconnect);
|
|
919
|
-
}
|
|
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();
|
|
920
982
|
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs) && configs.length > 0) {
|
|
921
983
|
console.log("==> ".concat(label || "Cache snapshots", " unsubscribed. "));
|
|
922
984
|
}
|
|
923
985
|
};
|
|
924
986
|
}, [
|
|
925
|
-
socketConnected,
|
|
926
987
|
configs,
|
|
927
|
-
auth
|
|
988
|
+
(_auth_currentUser = auth.currentUser) === null || _auth_currentUser === void 0 ? void 0 : _auth_currentUser.uid
|
|
928
989
|
]);
|
|
929
|
-
|
|
990
|
+
useEffect4(function() {
|
|
930
991
|
return function() {
|
|
931
992
|
cleanupSubscriptions.forEach(function(cleanup) {
|
|
932
993
|
return cleanup();
|
|
@@ -937,18 +998,9 @@ var useSocketSubscription = function(configs, label, settings) {
|
|
|
937
998
|
socketConnected: socketConnected
|
|
938
999
|
};
|
|
939
1000
|
};
|
|
940
|
-
|
|
941
|
-
var
|
|
942
|
-
|
|
943
|
-
document.title = title;
|
|
944
|
-
}, [
|
|
945
|
-
title
|
|
946
|
-
]);
|
|
947
|
-
return null;
|
|
948
|
-
};
|
|
949
|
-
var useSnapshotBulk = function(configs, label, settings) {
|
|
950
|
-
var snapshotsFirstTime = useRef2([]);
|
|
951
|
-
var unsubscribeFunctions = useRef2([]);
|
|
1001
|
+
var useDbSnapshots = function(configs, label, settings) {
|
|
1002
|
+
var snapshotsFirstTime = useRef4([]);
|
|
1003
|
+
var unsubscribeFunctions = useRef4([]);
|
|
952
1004
|
useDeepCompareEffect(function() {
|
|
953
1005
|
var start = performance.now();
|
|
954
1006
|
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs) && configs.length > 0) {
|
|
@@ -984,7 +1036,7 @@ var useSnapshotBulk = function(configs, label, settings) {
|
|
|
984
1036
|
label,
|
|
985
1037
|
settings
|
|
986
1038
|
]);
|
|
987
|
-
|
|
1039
|
+
useEffect4(function() {
|
|
988
1040
|
return function() {
|
|
989
1041
|
unsubscribeFunctions.current.forEach(function(unsubscribe) {
|
|
990
1042
|
if (unsubscribe) {
|
|
@@ -997,9 +1049,9 @@ var useSnapshotBulk = function(configs, label, settings) {
|
|
|
997
1049
|
};
|
|
998
1050
|
}, []);
|
|
999
1051
|
};
|
|
1000
|
-
var
|
|
1052
|
+
var useSmartSnapshots = function(configs, label, settings) {
|
|
1001
1053
|
var _useState2 = _sliced_to_array(useState2(null), 2), cacheCollectionsConfig = _useState2[0], setCacheCollectionsConfig = _useState2[1];
|
|
1002
|
-
|
|
1054
|
+
useEffect4(function() {
|
|
1003
1055
|
get_document_by_id("nx-settings", "cache_collections_config").then(function(res) {
|
|
1004
1056
|
return setCacheCollectionsConfig(res);
|
|
1005
1057
|
});
|
|
@@ -1007,7 +1059,7 @@ var useSmartSnapshot = function(configs, label, settings) {
|
|
|
1007
1059
|
return setCacheCollectionsConfig(null);
|
|
1008
1060
|
};
|
|
1009
1061
|
}, []);
|
|
1010
|
-
var groupedConfig =
|
|
1062
|
+
var groupedConfig = useMemo3(function() {
|
|
1011
1063
|
if (!cacheCollectionsConfig) {
|
|
1012
1064
|
return {
|
|
1013
1065
|
configForDb: [],
|
|
@@ -1032,48 +1084,12 @@ var useSmartSnapshot = function(configs, label, settings) {
|
|
|
1032
1084
|
configs,
|
|
1033
1085
|
cacheCollectionsConfig
|
|
1034
1086
|
]);
|
|
1035
|
-
|
|
1036
|
-
var socketConnected =
|
|
1087
|
+
useDbSnapshots(groupedConfig.configForDb, label, settings);
|
|
1088
|
+
var socketConnected = useSocketSnapshots(groupedConfig.configForCache, label, settings).socketConnected;
|
|
1037
1089
|
return {
|
|
1038
1090
|
groupedConfig: groupedConfig,
|
|
1039
1091
|
socketConnected: socketConnected
|
|
1040
1092
|
};
|
|
1041
1093
|
};
|
|
1042
|
-
|
|
1043
|
-
useLayoutEffect(function() {
|
|
1044
|
-
var currentCountry = localStorage.getItem("userCountry");
|
|
1045
|
-
if (!currentCountry) {
|
|
1046
|
-
var updateCountry = /*#__PURE__*/ function() {
|
|
1047
|
-
var _ref = _async_to_generator(function() {
|
|
1048
|
-
var country;
|
|
1049
|
-
return _ts_generator(this, function(_state) {
|
|
1050
|
-
switch(_state.label){
|
|
1051
|
-
case 0:
|
|
1052
|
-
return [
|
|
1053
|
-
4,
|
|
1054
|
-
getUserCountryByIp()
|
|
1055
|
-
];
|
|
1056
|
-
case 1:
|
|
1057
|
-
country = _state.sent();
|
|
1058
|
-
changLang(country === CountryOptions2.IL ? "he" : "en");
|
|
1059
|
-
setUserCountry(country);
|
|
1060
|
-
localStorage.setItem("userCountry", country);
|
|
1061
|
-
return [
|
|
1062
|
-
2
|
|
1063
|
-
];
|
|
1064
|
-
}
|
|
1065
|
-
});
|
|
1066
|
-
});
|
|
1067
|
-
return function updateCountry() {
|
|
1068
|
-
return _ref.apply(this, arguments);
|
|
1069
|
-
};
|
|
1070
|
-
}();
|
|
1071
|
-
updateCountry();
|
|
1072
|
-
}
|
|
1073
|
-
}, []);
|
|
1074
|
-
return null;
|
|
1075
|
-
};
|
|
1076
|
-
// src/hooks/WebWorker.ts
|
|
1077
|
-
import { useCallback as useCallback2, useEffect as useEffect4, useRef as useRef3 } from "react";
|
|
1078
|
-
export { useDeepCompareEffect, useDeepCompareMemo, useDocumentTitle, useSafeEffect, useSetUserCountry, useSmartSnapshot, useSnapshotBulk, useSocketSubscription };
|
|
1094
|
+
export { useDbSnapshots, useDeepCompareEffect, useDeepCompareMemo, useDocumentTitle, useSafeEffect, useSetUserCountry, useSmartSnapshots, useSocketSnapshots };
|
|
1079
1095
|
//# sourceMappingURL=index.mjs.map
|
package/dist/hooks/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["c:\\work\\akeyless\\commons\\client_commons\\dist\\hooks\\index.mjs"],"names":[],"mappings":"AAAA,sBAAsB","sourcesContent":["// src/hooks/global.ts\nimport { CountryOptions as CountryOptions2 } from \"akeyless-types-commons\";\nimport { useEffect as useEffect2, useLayoutEffect, useRef as useRef2 } from \"react\";\n\n// src/helpers/firebase.ts\nimport moment from \"moment\";\nimport { initializeApp } from \"firebase/app\";\nimport { getStorage } from \"firebase/storage\";\nimport { getAuth } from \"firebase/auth\";\nimport {\n addDoc,\n collection,\n deleteDoc,\n doc,\n getDoc,\n getDocs,\n query,\n setDoc,\n Timestamp,\n where,\n getFirestore,\n onSnapshot,\n orderBy\n} from \"firebase/firestore\";\nvar initApp = () => {\n const isNodeEnv2 = typeof process !== \"undefined\" && process.env;\n const firebaseConfig = {\n apiKey: isNodeEnv2 ? process.env.NEXT_PUBLIC_API_KEY : import.meta.env.VITE_API_KEY,\n authDomain: isNodeEnv2 ? process.env.NEXT_PUBLIC_AUTH_DOMAIN : import.meta.env.VITE_AUTH_DOMAIN,\n projectId: isNodeEnv2 ? process.env.NEXT_PUBLIC_PROJECT_ID : import.meta.env.VITE_PROJECT_ID,\n storageBucket: isNodeEnv2 ? process.env.NEXT_PUBLIC_STORAGE_BUCKET : import.meta.env.VITE_STORAGE_BUCKET,\n messagingSenderId: isNodeEnv2 ? process.env.NEXT_PUBLIC_MESSAGING_SENDER_ID : import.meta.env.VITE_MESSAGING_SENDER_ID,\n appId: isNodeEnv2 ? process.env.NEXT_PUBLIC_APP_ID : import.meta.env.VITE_APP_ID\n };\n try {\n const app = initializeApp(firebaseConfig);\n const auth2 = getAuth(app);\n const db2 = getFirestore(app);\n const storage2 = getStorage(app);\n return { db: db2, auth: auth2, storage: storage2 };\n } catch (error) {\n console.error(\"Failed to initialize Firebase app:\", error);\n return {};\n }\n};\nvar { db, auth, storage } = initApp();\nvar collections = {\n clients: collection(db, \"nx-clients\"),\n sites: collection(db, \"nx-sites\"),\n cars: collection(db, \"units\"),\n users: collection(db, \"nx-users\"),\n lastLocations: collection(db, \"last_locations\"),\n ermEvents: collection(db, \"erm_events_general\"),\n erm2Events: collection(db, \"erm2_events_general\"),\n ruptelaEvents: collection(db, \"ruptela_events_general\"),\n polygons: collection(db, \"nx-polygons\"),\n polygonEvents: collection(db, \"polygon_events\"),\n polygonCars: collection(db, \"polygon_cars\"),\n canbus: collection(db, \"erm_canbus_parameters\"),\n states: collection(db, \"erm_states\"),\n app_pro_commands_queue: collection(db, \"app_pro_commands_queue\"),\n trips: collection(db, \"erm2_trip\"),\n tripsDetails: collection(db, \"erm2_trip_details\"),\n audit: collection(db, \"nx-audit\"),\n nx_settings: collection(db, \"nx-settings\"),\n settings: collection(db, \"settings\"),\n translations: collection(db, \"nx-translations\"),\n nx_cars: collection(db, \"nx-cars\"),\n boards: collection(db, \"boards\"),\n protection_types: collection(db, \"protectionTypes\"),\n board_types: collection(db, \"boardTypes\"),\n charge_capacities: collection(db, \"nx-charge-capacities\")\n};\nvar fire_base_TIME_TEMP = Timestamp.now;\nvar simpleExtractData = (doc2) => {\n const docData = doc2.data();\n return {\n ...docData,\n id: doc2.id\n };\n};\nvar snapshot = (config, snapshotsFirstTime) => {\n let resolvePromise;\n let isResolved = false;\n const promise = new Promise((resolve) => {\n console.log(`==> ${config.collectionName} subscribed.`);\n resolvePromise = () => {\n if (!isResolved) {\n isResolved = true;\n resolve();\n }\n };\n });\n let collectionRef = collection(db, config.collectionName);\n if (config.conditions) {\n config.conditions.forEach((condition) => {\n collectionRef = query(collectionRef, where(condition.field_name, condition.operator, condition.value));\n });\n }\n if (config.orderBy) {\n config.orderBy.forEach((order) => {\n collectionRef = query(collectionRef, orderBy(order.fieldName, order.direction));\n });\n }\n const unsubscribe = onSnapshot(\n collectionRef,\n (snapshot2) => {\n if (!snapshotsFirstTime.includes(config.collectionName)) {\n snapshotsFirstTime.push(config.collectionName);\n const documents = snapshot2.docs.map((doc2) => simpleExtractData(doc2));\n config.onFirstTime?.(documents, config);\n config.extraParsers?.forEach((extraParser) => {\n extraParser.onFirstTime?.(documents, config);\n });\n resolvePromise();\n } else {\n const addedDocs = [];\n const modifiedDocs = [];\n const removedDocs = [];\n snapshot2.docChanges().forEach((change) => {\n if (change.type === \"added\") {\n addedDocs.push(simpleExtractData(change.doc));\n } else if (change.type === \"modified\") {\n modifiedDocs.push(simpleExtractData(change.doc));\n } else if (change.type === \"removed\") {\n removedDocs.push(simpleExtractData(change.doc));\n }\n });\n addedDocs.length && config.onAdd?.(addedDocs, config);\n modifiedDocs.length && config.onModify?.(modifiedDocs, config);\n removedDocs.length && config.onRemove?.(removedDocs, config);\n config.extraParsers?.forEach((extraParser) => {\n addedDocs.length && extraParser.onAdd?.(addedDocs, config);\n modifiedDocs.length && extraParser.onModify?.(modifiedDocs, config);\n removedDocs.length && extraParser.onRemove?.(removedDocs, config);\n });\n }\n },\n (error) => {\n console.error(`Error listening to collection: ${config.collectionName}`, error);\n resolvePromise();\n }\n );\n return { promise, unsubscribe };\n};\n\n// src/helpers/global.ts\nimport { CountryOptions } from \"akeyless-types-commons\";\nimport axios from \"axios\";\n\n// src/helpers/phoneNumber.ts\nimport { parsePhoneNumberFromString } from \"libphonenumber-js\";\n\n// src/helpers/global.ts\nimport { isEqual } from \"lodash\";\nvar getUserCountryByIp = async () => {\n try {\n const response = await axios.get(\"https://ipapi.co/json/\");\n return (response.data.country_code || CountryOptions.IL).toLowerCase();\n } catch (error) {\n console.error(\"Error fetching Country:\", error);\n return CountryOptions.IL;\n }\n};\nvar isNodeEnv = typeof process !== \"undefined\" && process.env;\nvar { mode, isLocal } = {\n mode: isNodeEnv ? process.env.NEXT_PUBLIC_MODE : import.meta.env.VITE_MODE,\n isLocal: (isNodeEnv ? process.env.NEXT_PUBLIC_IS_LOCAL : import.meta.env.VITE_is_local) === \"true\"\n};\n\n// src/helpers/forms.ts\nimport XRegExp from \"xregexp\";\nvar textRegex = XRegExp(\"[^\\\\p{L}\\\\s-]\", \"gu\");\nvar numbersRegex = XRegExp(\"[^0-9\\\\s-+]\", \"g\");\nvar numbersOnlyRegex = XRegExp(\"[^0-9]\", \"g\");\nvar priceRegex = XRegExp(\"[^0-9.]\", \"g\");\nvar emailRegex = XRegExp(\"[^\\\\p{L}0-9.@\\\\s-]\", \"gu\");\nvar colorRegex = XRegExp(\"[^#0-9A-Fa-f]\", \"g\");\nvar carsRegex = XRegExp(\"[^\\\\p{L}0-9,_]\", \"gu\");\nvar textNumbersRegex = XRegExp(\"[^\\\\p{L}0-9\\\\s+\\\\-]\", \"gu\");\nvar addressRegex = XRegExp(\"[^\\\\p{L}0-9\\\\s.,+-\\\\-]\", \"gu\");\nvar chartsRegex = XRegExp(\"[^\\\\p{L}0-9\\\\s.,_@!+-\\\\-]\", \"gu\");\n\n// src/lib/utils.ts\nimport { clsx } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\n// src/helpers/time_helpers.ts\nimport { Timestamp as Timestamp2 } from \"firebase/firestore\";\nimport moment2 from \"moment-timezone\";\n\n// src/helpers/api.ts\nimport axios2 from \"axios\";\nvar baseDomain = mode === \"qa\" ? \"https://nx-api.xyz/api\" : \"https://nx-api.info/api\";\nvar devicesDomain = isLocal ? \"http://localhost:9001/api/devices\" : baseDomain + \"/devices\";\nvar biDomain = isLocal ? \"http://localhost:9002/api/bi\" : baseDomain + \"/bi\";\nvar callCenterDomain = isLocal ? \"http://localhost:9003/api/call-center\" : baseDomain + \"/call-center\";\n\n// src/hooks/react.ts\nimport { isEqual as isEqual2 } from \"lodash\";\nimport { useEffect, useMemo, useRef } from \"react\";\nfunction useSafeEffect(callback, dependencies, error_message) {\n useEffect(() => {\n try {\n callback();\n } catch (error) {\n console.error(error_message || \"Error in useEffect:\", error);\n }\n }, dependencies);\n}\nvar useDeepCompareMemo = (factory, dependencies) => {\n const previousDepsRef = useRef([]);\n if (!isEqual2(dependencies, previousDepsRef.current)) {\n previousDepsRef.current = dependencies;\n }\n return useMemo(factory, previousDepsRef.current);\n};\nfunction useDeepCompareEffect(effect, dependencies) {\n const previousDepsRef = useRef();\n if (!isEqual2(previousDepsRef.current, dependencies)) {\n previousDepsRef.current = dependencies;\n }\n useEffect(effect, [previousDepsRef.current]);\n}\n\n// src/hooks/global.ts\nvar useDocumentTitle = (title) => {\n useEffect2(() => {\n document.title = title;\n }, [title]);\n return null;\n};\nvar useSnapshotBulk = (configs, label) => {\n const snapshotsFirstTime = useRef2([]);\n const unsubscribeFunctions = useRef2([]);\n useDeepCompareEffect(() => {\n const start = performance.now();\n console.log(`==> ${label || \"Custom snapshots\"} started... `);\n const snapshotResults = configs.map((config) => snapshot(config, snapshotsFirstTime.current));\n unsubscribeFunctions.current = snapshotResults.map((result) => result.unsubscribe);\n Promise.all(snapshotResults.map((result) => result.promise)).then(() => {\n console.log(`==> ${label || \"Custom snapshots\"} ended. It took ${(performance.now() - start).toFixed(2)} ms`);\n });\n }, [configs, label]);\n useEffect2(() => {\n return () => {\n unsubscribeFunctions.current.forEach((unsubscribe) => {\n if (unsubscribe) {\n unsubscribe();\n }\n });\n };\n }, []);\n};\nvar useSetUserCountry = (setUserCountry, changLang) => {\n useLayoutEffect(() => {\n const currentCountry = localStorage.getItem(\"userCountry\");\n if (!currentCountry) {\n const updateCountry = async () => {\n const country = await getUserCountryByIp();\n changLang(country === CountryOptions2.IL ? \"he\" : \"en\");\n setUserCountry(country);\n localStorage.setItem(\"userCountry\", country);\n };\n updateCountry();\n }\n }, []);\n return null;\n};\n\n// src/hooks/WebWorker.ts\nimport { useCallback, useEffect as useEffect3, useRef as useRef3 } from \"react\";\nexport {\n useDeepCompareEffect,\n useDeepCompareMemo,\n useDocumentTitle,\n useSafeEffect,\n useSetUserCountry,\n useSnapshotBulk\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["c:\\work\\akeyless\\commons\\client_commons\\dist\\hooks\\index.mjs"],"names":[],"mappings":"sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oCAAtB","sourcesContent":["// src/hooks/global.ts\nimport { CountryOptions as CountryOptions2 } from \"akeyless-types-commons\";\nimport { useEffect as useEffect2, useLayoutEffect, useRef as useRef2 } from \"react\";\n\n// src/helpers/firebase.ts\nimport moment from \"moment\";\nimport { initializeApp } from \"firebase/app\";\nimport { getStorage } from \"firebase/storage\";\nimport { getAuth } from \"firebase/auth\";\nimport {\n addDoc,\n collection,\n deleteDoc,\n doc,\n getDoc,\n getDocs,\n query,\n setDoc,\n Timestamp,\n where,\n getFirestore,\n onSnapshot,\n orderBy\n} from \"firebase/firestore\";\nvar initApp = () => {\n const isNodeEnv2 = typeof process !== \"undefined\" && process.env;\n const firebaseConfig = {\n apiKey: isNodeEnv2 ? process.env.NEXT_PUBLIC_API_KEY : import.meta.env.VITE_API_KEY,\n authDomain: isNodeEnv2 ? process.env.NEXT_PUBLIC_AUTH_DOMAIN : import.meta.env.VITE_AUTH_DOMAIN,\n projectId: isNodeEnv2 ? process.env.NEXT_PUBLIC_PROJECT_ID : import.meta.env.VITE_PROJECT_ID,\n storageBucket: isNodeEnv2 ? process.env.NEXT_PUBLIC_STORAGE_BUCKET : import.meta.env.VITE_STORAGE_BUCKET,\n messagingSenderId: isNodeEnv2 ? process.env.NEXT_PUBLIC_MESSAGING_SENDER_ID : import.meta.env.VITE_MESSAGING_SENDER_ID,\n appId: isNodeEnv2 ? process.env.NEXT_PUBLIC_APP_ID : import.meta.env.VITE_APP_ID\n };\n try {\n const app = initializeApp(firebaseConfig);\n const auth2 = getAuth(app);\n const db2 = getFirestore(app);\n const storage2 = getStorage(app);\n return { db: db2, auth: auth2, storage: storage2 };\n } catch (error) {\n console.error(\"Failed to initialize Firebase app:\", error);\n return {};\n }\n};\nvar { db, auth, storage } = initApp();\nvar collections = {\n clients: collection(db, \"nx-clients\"),\n sites: collection(db, \"nx-sites\"),\n cars: collection(db, \"units\"),\n users: collection(db, \"nx-users\"),\n lastLocations: collection(db, \"last_locations\"),\n ermEvents: collection(db, \"erm_events_general\"),\n erm2Events: collection(db, \"erm2_events_general\"),\n ruptelaEvents: collection(db, \"ruptela_events_general\"),\n polygons: collection(db, \"nx-polygons\"),\n polygonEvents: collection(db, \"polygon_events\"),\n polygonCars: collection(db, \"polygon_cars\"),\n canbus: collection(db, \"erm_canbus_parameters\"),\n states: collection(db, \"erm_states\"),\n app_pro_commands_queue: collection(db, \"app_pro_commands_queue\"),\n trips: collection(db, \"erm2_trip\"),\n tripsDetails: collection(db, \"erm2_trip_details\"),\n audit: collection(db, \"nx-audit\"),\n nx_settings: collection(db, \"nx-settings\"),\n settings: collection(db, \"settings\"),\n translations: collection(db, \"nx-translations\"),\n nx_cars: collection(db, \"nx-cars\"),\n boards: collection(db, \"boards\"),\n protection_types: collection(db, \"protectionTypes\"),\n board_types: collection(db, \"boardTypes\"),\n charge_capacities: collection(db, \"nx-charge-capacities\")\n};\nvar fire_base_TIME_TEMP = Timestamp.now;\nvar simpleExtractData = (doc2) => {\n const docData = doc2.data();\n return {\n ...docData,\n id: doc2.id\n };\n};\nvar snapshot = (config, snapshotsFirstTime) => {\n let resolvePromise;\n let isResolved = false;\n const promise = new Promise((resolve) => {\n console.log(`==> ${config.collectionName} subscribed.`);\n resolvePromise = () => {\n if (!isResolved) {\n isResolved = true;\n resolve();\n }\n };\n });\n let collectionRef = collection(db, config.collectionName);\n if (config.conditions) {\n config.conditions.forEach((condition) => {\n collectionRef = query(collectionRef, where(condition.field_name, condition.operator, condition.value));\n });\n }\n if (config.orderBy) {\n config.orderBy.forEach((order) => {\n collectionRef = query(collectionRef, orderBy(order.fieldName, order.direction));\n });\n }\n const unsubscribe = onSnapshot(\n collectionRef,\n (snapshot2) => {\n if (!snapshotsFirstTime.includes(config.collectionName)) {\n snapshotsFirstTime.push(config.collectionName);\n const documents = snapshot2.docs.map((doc2) => simpleExtractData(doc2));\n config.onFirstTime?.(documents, config);\n config.extraParsers?.forEach((extraParser) => {\n extraParser.onFirstTime?.(documents, config);\n });\n resolvePromise();\n } else {\n const addedDocs = [];\n const modifiedDocs = [];\n const removedDocs = [];\n snapshot2.docChanges().forEach((change) => {\n if (change.type === \"added\") {\n addedDocs.push(simpleExtractData(change.doc));\n } else if (change.type === \"modified\") {\n modifiedDocs.push(simpleExtractData(change.doc));\n } else if (change.type === \"removed\") {\n removedDocs.push(simpleExtractData(change.doc));\n }\n });\n addedDocs.length && config.onAdd?.(addedDocs, config);\n modifiedDocs.length && config.onModify?.(modifiedDocs, config);\n removedDocs.length && config.onRemove?.(removedDocs, config);\n config.extraParsers?.forEach((extraParser) => {\n addedDocs.length && extraParser.onAdd?.(addedDocs, config);\n modifiedDocs.length && extraParser.onModify?.(modifiedDocs, config);\n removedDocs.length && extraParser.onRemove?.(removedDocs, config);\n });\n }\n },\n (error) => {\n console.error(`Error listening to collection: ${config.collectionName}`, error);\n resolvePromise();\n }\n );\n return { promise, unsubscribe };\n};\n\n// src/helpers/global.ts\nimport { CountryOptions } from \"akeyless-types-commons\";\nimport axios from \"axios\";\n\n// src/helpers/phoneNumber.ts\nimport { parsePhoneNumberFromString } from \"libphonenumber-js\";\n\n// src/helpers/global.ts\nimport { isEqual } from \"lodash\";\nvar getUserCountryByIp = async () => {\n try {\n const response = await axios.get(\"https://ipapi.co/json/\");\n return (response.data.country_code || CountryOptions.IL).toLowerCase();\n } catch (error) {\n console.error(\"Error fetching Country:\", error);\n return CountryOptions.IL;\n }\n};\nvar isNodeEnv = typeof process !== \"undefined\" && process.env;\nvar { mode, isLocal } = {\n mode: isNodeEnv ? process.env.NEXT_PUBLIC_MODE : import.meta.env.VITE_MODE,\n isLocal: (isNodeEnv ? process.env.NEXT_PUBLIC_IS_LOCAL : import.meta.env.VITE_is_local) === \"true\"\n};\n\n// src/helpers/forms.ts\nimport XRegExp from \"xregexp\";\nvar textRegex = XRegExp(\"[^\\\\p{L}\\\\s-]\", \"gu\");\nvar numbersRegex = XRegExp(\"[^0-9\\\\s-+]\", \"g\");\nvar numbersOnlyRegex = XRegExp(\"[^0-9]\", \"g\");\nvar priceRegex = XRegExp(\"[^0-9.]\", \"g\");\nvar emailRegex = XRegExp(\"[^\\\\p{L}0-9.@\\\\s-]\", \"gu\");\nvar colorRegex = XRegExp(\"[^#0-9A-Fa-f]\", \"g\");\nvar carsRegex = XRegExp(\"[^\\\\p{L}0-9,_]\", \"gu\");\nvar textNumbersRegex = XRegExp(\"[^\\\\p{L}0-9\\\\s+\\\\-]\", \"gu\");\nvar addressRegex = XRegExp(\"[^\\\\p{L}0-9\\\\s.,+-\\\\-]\", \"gu\");\nvar chartsRegex = XRegExp(\"[^\\\\p{L}0-9\\\\s.,_@!+-\\\\-]\", \"gu\");\n\n// src/lib/utils.ts\nimport { clsx } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\n// src/helpers/time_helpers.ts\nimport { Timestamp as Timestamp2 } from \"firebase/firestore\";\nimport moment2 from \"moment-timezone\";\n\n// src/helpers/api.ts\nimport axios2 from \"axios\";\nvar baseDomain = mode === \"qa\" ? \"https://nx-api.xyz/api\" : \"https://nx-api.info/api\";\nvar devicesDomain = isLocal ? \"http://localhost:9001/api/devices\" : baseDomain + \"/devices\";\nvar biDomain = isLocal ? \"http://localhost:9002/api/bi\" : baseDomain + \"/bi\";\nvar callCenterDomain = isLocal ? \"http://localhost:9003/api/call-center\" : baseDomain + \"/call-center\";\n\n// src/hooks/react.ts\nimport { isEqual as isEqual2 } from \"lodash\";\nimport { useEffect, useMemo, useRef } from \"react\";\nfunction useSafeEffect(callback, dependencies, error_message) {\n useEffect(() => {\n try {\n callback();\n } catch (error) {\n console.error(error_message || \"Error in useEffect:\", error);\n }\n }, dependencies);\n}\nvar useDeepCompareMemo = (factory, dependencies) => {\n const previousDepsRef = useRef([]);\n if (!isEqual2(dependencies, previousDepsRef.current)) {\n previousDepsRef.current = dependencies;\n }\n return useMemo(factory, previousDepsRef.current);\n};\nfunction useDeepCompareEffect(effect, dependencies) {\n const previousDepsRef = useRef();\n if (!isEqual2(previousDepsRef.current, dependencies)) {\n previousDepsRef.current = dependencies;\n }\n useEffect(effect, [previousDepsRef.current]);\n}\n\n// src/hooks/global.ts\nvar useDocumentTitle = (title) => {\n useEffect2(() => {\n document.title = title;\n }, [title]);\n return null;\n};\nvar useSnapshotBulk = (configs, label) => {\n const snapshotsFirstTime = useRef2([]);\n const unsubscribeFunctions = useRef2([]);\n useDeepCompareEffect(() => {\n const start = performance.now();\n console.log(`==> ${label || \"Custom snapshots\"} started... `);\n const snapshotResults = configs.map((config) => snapshot(config, snapshotsFirstTime.current));\n unsubscribeFunctions.current = snapshotResults.map((result) => result.unsubscribe);\n Promise.all(snapshotResults.map((result) => result.promise)).then(() => {\n console.log(`==> ${label || \"Custom snapshots\"} ended. It took ${(performance.now() - start).toFixed(2)} ms`);\n });\n }, [configs, label]);\n useEffect2(() => {\n return () => {\n unsubscribeFunctions.current.forEach((unsubscribe) => {\n if (unsubscribe) {\n unsubscribe();\n }\n });\n };\n }, []);\n};\nvar useSetUserCountry = (setUserCountry, changLang) => {\n useLayoutEffect(() => {\n const currentCountry = localStorage.getItem(\"userCountry\");\n if (!currentCountry) {\n const updateCountry = async () => {\n const country = await getUserCountryByIp();\n changLang(country === CountryOptions2.IL ? \"he\" : \"en\");\n setUserCountry(country);\n localStorage.setItem(\"userCountry\", country);\n };\n updateCountry();\n }\n }, []);\n return null;\n};\n\n// src/hooks/WebWorker.ts\nimport { useCallback, useEffect as useEffect3, useRef as useRef3 } from \"react\";\nexport {\n useDeepCompareEffect,\n useDeepCompareMemo,\n useDocumentTitle,\n useSafeEffect,\n useSetUserCountry,\n useSnapshotBulk\n};\n"]}
|