akeyless-client-commons 1.1.17-test.0 → 1.1.17-test.10
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 +121 -90
- package/dist/components/index.mjs +121 -90
- package/dist/helpers/index.d.mts +10 -7
- package/dist/helpers/index.d.ts +10 -7
- package/dist/helpers/index.js +121 -90
- package/dist/helpers/index.mjs +121 -90
- package/dist/helpers/index.mjs.map +1 -1
- package/dist/hooks/index.d.mts +16 -18
- package/dist/hooks/index.d.ts +16 -18
- package/dist/hooks/index.js +248 -203
- package/dist/hooks/index.mjs +243 -198
- package/dist/hooks/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/hooks/index.js
CHANGED
|
@@ -317,6 +317,9 @@ var __toCommonJS = function(mod) {
|
|
|
317
317
|
// src/hooks/index.ts
|
|
318
318
|
var index_exports = {};
|
|
319
319
|
__export(index_exports, {
|
|
320
|
+
useDbSnapshots: function() {
|
|
321
|
+
return useDbSnapshots;
|
|
322
|
+
},
|
|
320
323
|
useDeepCompareEffect: function() {
|
|
321
324
|
return useDeepCompareEffect;
|
|
322
325
|
},
|
|
@@ -332,20 +335,17 @@ __export(index_exports, {
|
|
|
332
335
|
useSetUserCountry: function() {
|
|
333
336
|
return useSetUserCountry;
|
|
334
337
|
},
|
|
335
|
-
|
|
336
|
-
return
|
|
337
|
-
},
|
|
338
|
-
useSnapshotBulk: function() {
|
|
339
|
-
return useSnapshotBulk;
|
|
338
|
+
useSmartSnapshots: function() {
|
|
339
|
+
return useSmartSnapshots;
|
|
340
340
|
},
|
|
341
|
-
|
|
342
|
-
return
|
|
341
|
+
useSocketSnapshots: function() {
|
|
342
|
+
return useSocketSnapshots;
|
|
343
343
|
}
|
|
344
344
|
});
|
|
345
345
|
module.exports = __toCommonJS(index_exports);
|
|
346
346
|
// src/hooks/global.ts
|
|
347
347
|
var import_akeyless_types_commons2 = require("akeyless-types-commons");
|
|
348
|
-
var
|
|
348
|
+
var import_react2 = require("react");
|
|
349
349
|
// src/helpers/firebase.ts
|
|
350
350
|
var import_moment = __toESM(require("moment"));
|
|
351
351
|
var import_app = require("firebase/app");
|
|
@@ -518,11 +518,11 @@ var snapshot = function(config, snapshotsFirstTime, settings) {
|
|
|
518
518
|
collectionRef = (0, import_firestore.query)(collectionRef, (0, import_firestore.orderBy)(order.fieldName, order.direction));
|
|
519
519
|
});
|
|
520
520
|
}
|
|
521
|
-
var unsubscribe = (0, import_firestore.onSnapshot)(collectionRef, function(
|
|
521
|
+
var unsubscribe = (0, import_firestore.onSnapshot)(collectionRef, function(snapshot3) {
|
|
522
522
|
if (!snapshotsFirstTime.includes(config.collectionName)) {
|
|
523
523
|
var _config_onFirstTime, _config_extraParsers;
|
|
524
524
|
snapshotsFirstTime.push(config.collectionName);
|
|
525
|
-
var documents =
|
|
525
|
+
var documents = snapshot3.docs.map(function(doc2) {
|
|
526
526
|
return simpleExtractData(doc2);
|
|
527
527
|
});
|
|
528
528
|
(_config_onFirstTime = config.onFirstTime) === null || _config_onFirstTime === void 0 ? void 0 : _config_onFirstTime.call(config, documents, config);
|
|
@@ -536,7 +536,7 @@ var snapshot = function(config, snapshotsFirstTime, settings) {
|
|
|
536
536
|
var addedDocs = [];
|
|
537
537
|
var modifiedDocs = [];
|
|
538
538
|
var removedDocs = [];
|
|
539
|
-
|
|
539
|
+
snapshot3.docChanges().forEach(function(change) {
|
|
540
540
|
if (change.type === "added") {
|
|
541
541
|
addedDocs.push(simpleExtractData(change.doc));
|
|
542
542
|
} else if (change.type === "modified") {
|
|
@@ -644,6 +644,7 @@ var dataSocketDomain = isLocal ? "http://localhost:9009/api/data-socket" : baseD
|
|
|
644
644
|
var dataSyncDomain = isLocal ? "http://localhost:9010/api/data-sync" : baseDomain + "/data-sync";
|
|
645
645
|
// src/helpers/socket.ts
|
|
646
646
|
var import_socket = require("socket.io-client");
|
|
647
|
+
var SESSION_STORAGE_KEY = "sessionId";
|
|
647
648
|
var SocketService = /*#__PURE__*/ function() {
|
|
648
649
|
"use strict";
|
|
649
650
|
function _SocketService() {
|
|
@@ -651,6 +652,7 @@ var SocketService = /*#__PURE__*/ function() {
|
|
|
651
652
|
this.socket = null;
|
|
652
653
|
this.connectCallbacks = [];
|
|
653
654
|
this.disconnectCallbacks = [];
|
|
655
|
+
this.authToken = null;
|
|
654
656
|
}
|
|
655
657
|
_create_class(_SocketService, [
|
|
656
658
|
{
|
|
@@ -659,17 +661,24 @@ var SocketService = /*#__PURE__*/ function() {
|
|
|
659
661
|
value: function initSocket() {
|
|
660
662
|
var _this = this;
|
|
661
663
|
if (!this.socket) {
|
|
662
|
-
var socketUrl = isLocal ? "http://localhost:9009" : mode === "qa" ? "https://
|
|
663
|
-
console.log("socketUrl", socketUrl);
|
|
664
|
+
var socketUrl = isLocal ? "http://localhost:9009" : mode === "qa" ? "https://nx-api.xyz" : "https://nx-api.info";
|
|
664
665
|
this.socket = (0, import_socket.io)(socketUrl, {
|
|
665
666
|
path: "/api/data-socket/connect",
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
667
|
+
auth: function(cb) {
|
|
668
|
+
var sessionId = localStorage.getItem(SESSION_STORAGE_KEY) || void 0;
|
|
669
|
+
var token = _this.authToken;
|
|
670
|
+
var authPayload = {};
|
|
671
|
+
if (token) authPayload.token = token;
|
|
672
|
+
if (sessionId) authPayload.sessionId = sessionId;
|
|
673
|
+
cb(authPayload);
|
|
674
|
+
},
|
|
675
|
+
reconnection: true,
|
|
676
|
+
reconnectionAttempts: 30,
|
|
677
|
+
reconnectionDelay: 2 * 1e3
|
|
669
678
|
});
|
|
670
679
|
this.socket.on("connect", function() {
|
|
671
|
-
var _this_socket;
|
|
672
|
-
console.log("Socket connected:"
|
|
680
|
+
var _this_socket, _this_socket1;
|
|
681
|
+
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, ")"));
|
|
673
682
|
_this.connectCallbacks.forEach(function(cb) {
|
|
674
683
|
return cb();
|
|
675
684
|
});
|
|
@@ -680,6 +689,12 @@ var SocketService = /*#__PURE__*/ function() {
|
|
|
680
689
|
return cb();
|
|
681
690
|
});
|
|
682
691
|
});
|
|
692
|
+
this.socket.on("session", function(param) {
|
|
693
|
+
var sessionId = param.sessionId;
|
|
694
|
+
if (sessionId) {
|
|
695
|
+
localStorage.setItem(SESSION_STORAGE_KEY, sessionId);
|
|
696
|
+
}
|
|
697
|
+
});
|
|
683
698
|
this.socket.on("connect_error", function(error) {
|
|
684
699
|
console.error("Socket connection error:", error);
|
|
685
700
|
});
|
|
@@ -702,10 +717,93 @@ var SocketService = /*#__PURE__*/ function() {
|
|
|
702
717
|
return this.socket;
|
|
703
718
|
}
|
|
704
719
|
},
|
|
720
|
+
{
|
|
721
|
+
/// connection management methods
|
|
722
|
+
key: "startSession",
|
|
723
|
+
value: function startSession(token) {
|
|
724
|
+
this.setAuthToken(token);
|
|
725
|
+
this.initSocket();
|
|
726
|
+
}
|
|
727
|
+
},
|
|
728
|
+
{
|
|
729
|
+
key: "onConnect",
|
|
730
|
+
value: function onConnect(callback) {
|
|
731
|
+
var _this = this;
|
|
732
|
+
var _this_socket;
|
|
733
|
+
if (!this.connectCallbacks.includes(callback)) {
|
|
734
|
+
this.connectCallbacks.push(callback);
|
|
735
|
+
}
|
|
736
|
+
if ((_this_socket = this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.connected) {
|
|
737
|
+
callback();
|
|
738
|
+
}
|
|
739
|
+
return function() {
|
|
740
|
+
return _this.offConnect(callback);
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
},
|
|
744
|
+
{
|
|
745
|
+
key: "offConnect",
|
|
746
|
+
value: function offConnect(callback) {
|
|
747
|
+
this.connectCallbacks = this.connectCallbacks.filter(function(cb) {
|
|
748
|
+
return cb !== callback;
|
|
749
|
+
});
|
|
750
|
+
}
|
|
751
|
+
},
|
|
752
|
+
{
|
|
753
|
+
key: "onDisconnect",
|
|
754
|
+
value: function onDisconnect(callback) {
|
|
755
|
+
var _this = this;
|
|
756
|
+
if (!this.disconnectCallbacks.includes(callback)) {
|
|
757
|
+
this.disconnectCallbacks.push(callback);
|
|
758
|
+
}
|
|
759
|
+
if (this.socket && !this.socket.connected) {
|
|
760
|
+
callback();
|
|
761
|
+
}
|
|
762
|
+
return function() {
|
|
763
|
+
return _this.offDisconnect(callback);
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
},
|
|
767
|
+
{
|
|
768
|
+
key: "offDisconnect",
|
|
769
|
+
value: function offDisconnect(callback) {
|
|
770
|
+
this.disconnectCallbacks = this.disconnectCallbacks.filter(function(cb) {
|
|
771
|
+
return cb !== callback;
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
},
|
|
775
|
+
{
|
|
776
|
+
key: "isConnected",
|
|
777
|
+
value: function isConnected() {
|
|
778
|
+
var _this_socket;
|
|
779
|
+
return ((_this_socket = this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.connected) || false;
|
|
780
|
+
}
|
|
781
|
+
},
|
|
782
|
+
{
|
|
783
|
+
key: "setAuthToken",
|
|
784
|
+
value: function setAuthToken(token) {
|
|
785
|
+
this.authToken = token;
|
|
786
|
+
if (this.socket) {
|
|
787
|
+
this.socket.connect();
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
},
|
|
791
|
+
{
|
|
792
|
+
key: "disconnectSocket",
|
|
793
|
+
value: function disconnectSocket() {
|
|
794
|
+
if (this.socket) {
|
|
795
|
+
this.socket.io.engine.close();
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
},
|
|
705
799
|
{
|
|
706
800
|
/// subscribe to collections
|
|
707
801
|
key: "subscribeToCollections",
|
|
708
802
|
value: function subscribeToCollections(config) {
|
|
803
|
+
var _this = this;
|
|
804
|
+
if (config.length === 0) {
|
|
805
|
+
return function() {};
|
|
806
|
+
}
|
|
709
807
|
var s = this.getSocketInstance();
|
|
710
808
|
var collectionsNames = config.map(function(c) {
|
|
711
809
|
return c.collectionName;
|
|
@@ -713,48 +811,24 @@ var SocketService = /*#__PURE__*/ function() {
|
|
|
713
811
|
var eventHandlers = [];
|
|
714
812
|
config.forEach(function(configuration) {
|
|
715
813
|
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;
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
eventName
|
|
719
|
-
handler: onFirstTime
|
|
720
|
-
});
|
|
721
|
-
s.on("add:".concat(collectionName), onAdd);
|
|
722
|
-
eventHandlers.push({
|
|
723
|
-
eventName: "add:".concat(collectionName),
|
|
724
|
-
handler: onAdd
|
|
725
|
-
});
|
|
726
|
-
s.on("update:".concat(collectionName), onModify);
|
|
727
|
-
eventHandlers.push({
|
|
728
|
-
eventName: "update:".concat(collectionName),
|
|
729
|
-
handler: onModify
|
|
730
|
-
});
|
|
731
|
-
s.on("delete:".concat(collectionName), onRemove);
|
|
732
|
-
eventHandlers.push({
|
|
733
|
-
eventName: "delete:".concat(collectionName),
|
|
734
|
-
handler: onRemove
|
|
735
|
-
});
|
|
736
|
-
extraParsers === null || extraParsers === void 0 ? void 0 : extraParsers.forEach(function(parsers) {
|
|
737
|
-
var extraOnAdd = parsers.onAdd, extraOnFirstTime = parsers.onFirstTime, extraOnModify = parsers.onModify, extraOnRemove = parsers.onRemove;
|
|
738
|
-
s.on("initial:".concat(collectionName), extraOnFirstTime);
|
|
739
|
-
eventHandlers.push({
|
|
740
|
-
eventName: "initial:".concat(collectionName),
|
|
741
|
-
handler: extraOnFirstTime
|
|
742
|
-
});
|
|
743
|
-
s.on("add:".concat(collectionName), extraOnAdd);
|
|
814
|
+
var attach = function(eventName, handler) {
|
|
815
|
+
_this.socket.off(eventName, handler);
|
|
816
|
+
_this.socket.on(eventName, handler);
|
|
744
817
|
eventHandlers.push({
|
|
745
|
-
eventName:
|
|
746
|
-
handler:
|
|
747
|
-
});
|
|
748
|
-
s.on("update:".concat(collectionName), extraOnModify);
|
|
749
|
-
eventHandlers.push({
|
|
750
|
-
eventName: "update:".concat(collectionName),
|
|
751
|
-
handler: extraOnModify
|
|
752
|
-
});
|
|
753
|
-
s.on("delete:".concat(collectionName), extraOnRemove);
|
|
754
|
-
eventHandlers.push({
|
|
755
|
-
eventName: "delete:".concat(collectionName),
|
|
756
|
-
handler: extraOnRemove
|
|
818
|
+
eventName: eventName,
|
|
819
|
+
handler: handler
|
|
757
820
|
});
|
|
821
|
+
};
|
|
822
|
+
attach("initial:".concat(collectionName), onFirstTime);
|
|
823
|
+
attach("add:".concat(collectionName), onAdd);
|
|
824
|
+
attach("update:".concat(collectionName), onModify);
|
|
825
|
+
attach("delete:".concat(collectionName), onRemove);
|
|
826
|
+
extraParsers === null || extraParsers === void 0 ? void 0 : extraParsers.forEach(function(parsers) {
|
|
827
|
+
var extraOnAdd = parsers.onAdd, extraOnFirstTime = parsers.onFirstTime, extraOnModify = parsers.onModify, extraOnRemove = parsers.onRemove;
|
|
828
|
+
attach("initial:".concat(collectionName), extraOnFirstTime);
|
|
829
|
+
attach("add:".concat(collectionName), extraOnAdd);
|
|
830
|
+
attach("update:".concat(collectionName), extraOnModify);
|
|
831
|
+
attach("delete:".concat(collectionName), extraOnRemove);
|
|
758
832
|
});
|
|
759
833
|
});
|
|
760
834
|
s.emit("subscribe_collections", collectionsNames, function(callback) {
|
|
@@ -855,49 +929,6 @@ var SocketService = /*#__PURE__*/ function() {
|
|
|
855
929
|
});
|
|
856
930
|
});
|
|
857
931
|
}
|
|
858
|
-
},
|
|
859
|
-
{
|
|
860
|
-
/// connection management methods
|
|
861
|
-
key: "onConnect",
|
|
862
|
-
value: function onConnect(callback) {
|
|
863
|
-
var _this_socket;
|
|
864
|
-
this.connectCallbacks.push(callback);
|
|
865
|
-
if ((_this_socket = this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.connected) {
|
|
866
|
-
callback();
|
|
867
|
-
}
|
|
868
|
-
}
|
|
869
|
-
},
|
|
870
|
-
{
|
|
871
|
-
key: "offConnect",
|
|
872
|
-
value: function offConnect(callback) {
|
|
873
|
-
this.connectCallbacks = this.connectCallbacks.filter(function(cb) {
|
|
874
|
-
return cb !== callback;
|
|
875
|
-
});
|
|
876
|
-
}
|
|
877
|
-
},
|
|
878
|
-
{
|
|
879
|
-
key: "onDisconnect",
|
|
880
|
-
value: function onDisconnect(callback) {
|
|
881
|
-
this.disconnectCallbacks.push(callback);
|
|
882
|
-
if (this.socket && !this.socket.connected) {
|
|
883
|
-
callback();
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
|
-
},
|
|
887
|
-
{
|
|
888
|
-
key: "offDisconnect",
|
|
889
|
-
value: function offDisconnect(callback) {
|
|
890
|
-
this.disconnectCallbacks = this.disconnectCallbacks.filter(function(cb) {
|
|
891
|
-
return cb !== callback;
|
|
892
|
-
});
|
|
893
|
-
}
|
|
894
|
-
},
|
|
895
|
-
{
|
|
896
|
-
key: "isConnected",
|
|
897
|
-
value: function isConnected() {
|
|
898
|
-
var _this_socket;
|
|
899
|
-
return ((_this_socket = this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.connected) || false;
|
|
900
|
-
}
|
|
901
932
|
}
|
|
902
933
|
], [
|
|
903
934
|
{
|
|
@@ -913,11 +944,54 @@ var SocketService = /*#__PURE__*/ function() {
|
|
|
913
944
|
return _SocketService;
|
|
914
945
|
}();
|
|
915
946
|
var socketServiceInstance = SocketService.getInstance();
|
|
947
|
+
// src/hooks/global.ts
|
|
948
|
+
var useDocumentTitle = function(title) {
|
|
949
|
+
(0, import_react2.useEffect)(function() {
|
|
950
|
+
document.title = title;
|
|
951
|
+
}, [
|
|
952
|
+
title
|
|
953
|
+
]);
|
|
954
|
+
return null;
|
|
955
|
+
};
|
|
956
|
+
var useSetUserCountry = function(setUserCountry, changLang) {
|
|
957
|
+
(0, import_react2.useLayoutEffect)(function() {
|
|
958
|
+
var currentCountry = localStorage.getItem("userCountry");
|
|
959
|
+
if (!currentCountry) {
|
|
960
|
+
var updateCountry = /*#__PURE__*/ function() {
|
|
961
|
+
var _ref = _async_to_generator(function() {
|
|
962
|
+
var country;
|
|
963
|
+
return _ts_generator(this, function(_state) {
|
|
964
|
+
switch(_state.label){
|
|
965
|
+
case 0:
|
|
966
|
+
return [
|
|
967
|
+
4,
|
|
968
|
+
getUserCountryByIp()
|
|
969
|
+
];
|
|
970
|
+
case 1:
|
|
971
|
+
country = _state.sent();
|
|
972
|
+
changLang(country === import_akeyless_types_commons2.CountryOptions.IL ? "he" : "en");
|
|
973
|
+
setUserCountry(country);
|
|
974
|
+
localStorage.setItem("userCountry", country);
|
|
975
|
+
return [
|
|
976
|
+
2
|
|
977
|
+
];
|
|
978
|
+
}
|
|
979
|
+
});
|
|
980
|
+
});
|
|
981
|
+
return function updateCountry() {
|
|
982
|
+
return _ref.apply(this, arguments);
|
|
983
|
+
};
|
|
984
|
+
}();
|
|
985
|
+
updateCountry();
|
|
986
|
+
}
|
|
987
|
+
}, []);
|
|
988
|
+
return null;
|
|
989
|
+
};
|
|
916
990
|
// src/hooks/react.ts
|
|
917
991
|
var import_lodash2 = require("lodash");
|
|
918
|
-
var
|
|
992
|
+
var import_react3 = require("react");
|
|
919
993
|
function useSafeEffect(callback, dependencies, error_message) {
|
|
920
|
-
(0,
|
|
994
|
+
(0, import_react3.useEffect)(function() {
|
|
921
995
|
try {
|
|
922
996
|
callback();
|
|
923
997
|
} catch (error) {
|
|
@@ -926,73 +1000,88 @@ function useSafeEffect(callback, dependencies, error_message) {
|
|
|
926
1000
|
}, dependencies);
|
|
927
1001
|
}
|
|
928
1002
|
var useDeepCompareMemo = function(factory, dependencies) {
|
|
929
|
-
var previousDepsRef = (0,
|
|
1003
|
+
var previousDepsRef = (0, import_react3.useRef)([]);
|
|
930
1004
|
if (!(0, import_lodash2.isEqual)(dependencies, previousDepsRef.current)) {
|
|
931
1005
|
previousDepsRef.current = dependencies;
|
|
932
1006
|
}
|
|
933
|
-
return (0,
|
|
1007
|
+
return (0, import_react3.useMemo)(factory, previousDepsRef.current);
|
|
934
1008
|
};
|
|
935
1009
|
function useDeepCompareEffect(effect, dependencies) {
|
|
936
|
-
var previousDepsRef = (0,
|
|
1010
|
+
var previousDepsRef = (0, import_react3.useRef)();
|
|
937
1011
|
if (!(0, import_lodash2.isEqual)(previousDepsRef.current, dependencies)) {
|
|
938
1012
|
previousDepsRef.current = dependencies;
|
|
939
1013
|
}
|
|
940
|
-
(0,
|
|
1014
|
+
(0, import_react3.useEffect)(effect, [
|
|
941
1015
|
previousDepsRef.current
|
|
942
1016
|
]);
|
|
943
1017
|
}
|
|
944
|
-
// src/hooks/
|
|
945
|
-
var
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
1018
|
+
// src/hooks/WebWorker.ts
|
|
1019
|
+
var import_react4 = require("react");
|
|
1020
|
+
// src/hooks/snapshots.ts
|
|
1021
|
+
var import_react5 = require("react");
|
|
1022
|
+
var useSocketSnapshots = function(configs, label, settings) {
|
|
1023
|
+
var _auth_currentUser;
|
|
1024
|
+
var _ref = _sliced_to_array((0, import_react5.useState)(socketServiceInstance.isConnected()), 2), socketConnected = _ref[0], setSocketConnected = _ref[1];
|
|
1025
|
+
var _ref1 = _sliced_to_array((0, import_react5.useState)([]), 2), cleanupSubscriptions = _ref1[0], setCleanupSubscriptions = _ref1[1];
|
|
1026
|
+
var socketStarted = (0, import_react5.useRef)(false);
|
|
949
1027
|
useDeepCompareEffect(function() {
|
|
950
|
-
if (
|
|
1028
|
+
if (!auth.currentUser) {
|
|
1029
|
+
return;
|
|
1030
|
+
}
|
|
1031
|
+
var subscribe = function() {
|
|
1032
|
+
if (configs.length === 0) {
|
|
1033
|
+
return;
|
|
1034
|
+
}
|
|
1035
|
+
var disposer = socketServiceInstance.subscribeToCollections(configs);
|
|
951
1036
|
setCleanupSubscriptions(function(prev) {
|
|
952
1037
|
return _to_consumable_array(prev).concat([
|
|
953
|
-
|
|
1038
|
+
disposer
|
|
954
1039
|
]);
|
|
955
1040
|
});
|
|
956
|
-
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)
|
|
1041
|
+
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
|
|
957
1042
|
console.log("==> ".concat(label || "Cache snapshots", " subscribed to ").concat(configs.map(function(c) {
|
|
958
1043
|
return c.collectionName;
|
|
959
1044
|
}).join(", ")));
|
|
960
1045
|
}
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
1046
|
+
};
|
|
1047
|
+
if (socketServiceInstance.isConnected()) {
|
|
1048
|
+
setSocketConnected(true);
|
|
1049
|
+
subscribe();
|
|
1050
|
+
} else if (!socketStarted.current) {
|
|
1051
|
+
socketStarted.current = true;
|
|
1052
|
+
auth.currentUser.getIdToken().then(function(token) {
|
|
1053
|
+
socketServiceInstance.startSession(token);
|
|
1054
|
+
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
|
|
1055
|
+
console.log("==> ".concat(label || "Cache snapshots", " started... "));
|
|
1056
|
+
}
|
|
1057
|
+
});
|
|
966
1058
|
}
|
|
967
|
-
var
|
|
1059
|
+
var offConnect = socketServiceInstance.onConnect(function() {
|
|
968
1060
|
setSocketConnected(true);
|
|
969
|
-
|
|
970
|
-
|
|
1061
|
+
socketStarted.current = false;
|
|
1062
|
+
subscribe();
|
|
1063
|
+
});
|
|
1064
|
+
var offDisconnect = socketServiceInstance.onDisconnect(function() {
|
|
1065
|
+
setSocketConnected(false);
|
|
971
1066
|
cleanupSubscriptions.forEach(function(cleanup) {
|
|
972
1067
|
return cleanup();
|
|
973
1068
|
});
|
|
974
|
-
|
|
975
|
-
};
|
|
976
|
-
socketServiceInstance.onConnect(uiOnConnect);
|
|
977
|
-
socketServiceInstance.onDisconnect(uiOnDisconnect);
|
|
978
|
-
setSocketConnected(socketServiceInstance.isConnected());
|
|
1069
|
+
});
|
|
979
1070
|
return function() {
|
|
1071
|
+
cleanupSubscriptions.forEach(function(cleanup) {
|
|
1072
|
+
return cleanup();
|
|
1073
|
+
});
|
|
1074
|
+
offConnect === null || offConnect === void 0 ? void 0 : offConnect();
|
|
1075
|
+
offDisconnect === null || offDisconnect === void 0 ? void 0 : offDisconnect();
|
|
980
1076
|
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs) && configs.length > 0) {
|
|
981
|
-
console.log("==> ".concat(label || "Cache snapshots", "
|
|
982
|
-
}
|
|
983
|
-
if (settings === null || settings === void 0 ? void 0 : settings.cleanupForConfigChange) {
|
|
984
|
-
cleanupSubscriptions.forEach(function(cleanup) {
|
|
985
|
-
return cleanup();
|
|
986
|
-
});
|
|
987
|
-
socketServiceInstance.offConnect(uiOnConnect);
|
|
988
|
-
socketServiceInstance.offDisconnect(uiOnDisconnect);
|
|
1077
|
+
console.log("==> ".concat(label || "Cache snapshots", " unsubscribed. "));
|
|
989
1078
|
}
|
|
990
1079
|
};
|
|
991
1080
|
}, [
|
|
992
|
-
|
|
993
|
-
|
|
1081
|
+
configs,
|
|
1082
|
+
(_auth_currentUser = auth.currentUser) === null || _auth_currentUser === void 0 ? void 0 : _auth_currentUser.uid
|
|
994
1083
|
]);
|
|
995
|
-
(0,
|
|
1084
|
+
(0, import_react5.useEffect)(function() {
|
|
996
1085
|
return function() {
|
|
997
1086
|
cleanupSubscriptions.forEach(function(cleanup) {
|
|
998
1087
|
return cleanup();
|
|
@@ -1003,16 +1092,7 @@ var useSocketSubscription = function(configs, label, settings) {
|
|
|
1003
1092
|
socketConnected: socketConnected
|
|
1004
1093
|
};
|
|
1005
1094
|
};
|
|
1006
|
-
|
|
1007
|
-
var useDocumentTitle = function(title) {
|
|
1008
|
-
(0, import_react5.useEffect)(function() {
|
|
1009
|
-
document.title = title;
|
|
1010
|
-
}, [
|
|
1011
|
-
title
|
|
1012
|
-
]);
|
|
1013
|
-
return null;
|
|
1014
|
-
};
|
|
1015
|
-
var useSnapshotBulk = function(configs, label, settings) {
|
|
1095
|
+
var useDbSnapshots = function(configs, label, settings) {
|
|
1016
1096
|
var snapshotsFirstTime = (0, import_react5.useRef)([]);
|
|
1017
1097
|
var unsubscribeFunctions = (0, import_react5.useRef)([]);
|
|
1018
1098
|
useDeepCompareEffect(function() {
|
|
@@ -1063,7 +1143,7 @@ var useSnapshotBulk = function(configs, label, settings) {
|
|
|
1063
1143
|
};
|
|
1064
1144
|
}, []);
|
|
1065
1145
|
};
|
|
1066
|
-
var
|
|
1146
|
+
var useSmartSnapshots = function(configs, label, settings) {
|
|
1067
1147
|
var _ref = _sliced_to_array((0, import_react5.useState)(null), 2), cacheCollectionsConfig = _ref[0], setCacheCollectionsConfig = _ref[1];
|
|
1068
1148
|
(0, import_react5.useEffect)(function() {
|
|
1069
1149
|
get_document_by_id("nx-settings", "cache_collections_config").then(function(res) {
|
|
@@ -1073,83 +1153,48 @@ var useSmartSnapshot = function(configs, label, settings) {
|
|
|
1073
1153
|
return setCacheCollectionsConfig(null);
|
|
1074
1154
|
};
|
|
1075
1155
|
}, []);
|
|
1076
|
-
var
|
|
1156
|
+
var _ref1 = (0, import_react5.useMemo)(function() {
|
|
1077
1157
|
if (!cacheCollectionsConfig) {
|
|
1078
1158
|
return {
|
|
1079
|
-
|
|
1080
|
-
|
|
1159
|
+
dbConfig: [],
|
|
1160
|
+
cacheConfig: []
|
|
1081
1161
|
};
|
|
1082
1162
|
}
|
|
1083
|
-
var
|
|
1084
|
-
var
|
|
1163
|
+
var dbConfig2 = [];
|
|
1164
|
+
var cacheConfig2 = [];
|
|
1085
1165
|
configs.forEach(function(cfg) {
|
|
1086
1166
|
var collectionName = cfg.collectionName, _cfg_subscribeTo = cfg.subscribeTo, subscribeTo = _cfg_subscribeTo === void 0 ? "cache" : _cfg_subscribeTo;
|
|
1087
|
-
if (subscribeTo === "cache" && cacheCollectionsConfig[collectionName]) {
|
|
1088
|
-
|
|
1167
|
+
if (subscribeTo === "cache" && cacheCollectionsConfig[collectionName].sync_direction !== "redis_to_firebase") {
|
|
1168
|
+
cacheConfig2.push(cfg);
|
|
1089
1169
|
} else {
|
|
1090
|
-
|
|
1170
|
+
dbConfig2.push(cfg);
|
|
1091
1171
|
}
|
|
1092
1172
|
});
|
|
1093
1173
|
return {
|
|
1094
|
-
|
|
1095
|
-
|
|
1174
|
+
dbConfig: dbConfig2,
|
|
1175
|
+
cacheConfig: cacheConfig2
|
|
1096
1176
|
};
|
|
1097
1177
|
}, [
|
|
1098
1178
|
configs,
|
|
1099
1179
|
cacheCollectionsConfig
|
|
1100
|
-
]);
|
|
1101
|
-
|
|
1102
|
-
var socketConnected =
|
|
1180
|
+
]), dbConfig = _ref1.dbConfig, cacheConfig = _ref1.cacheConfig;
|
|
1181
|
+
useDbSnapshots(dbConfig, label, settings);
|
|
1182
|
+
var socketConnected = useSocketSnapshots(cacheConfig, label, settings).socketConnected;
|
|
1103
1183
|
return {
|
|
1104
|
-
|
|
1184
|
+
dbConfig: dbConfig,
|
|
1185
|
+
cacheConfig: cacheConfig,
|
|
1105
1186
|
socketConnected: socketConnected
|
|
1106
1187
|
};
|
|
1107
1188
|
};
|
|
1108
|
-
var useSetUserCountry = function(setUserCountry, changLang) {
|
|
1109
|
-
(0, import_react5.useLayoutEffect)(function() {
|
|
1110
|
-
var currentCountry = localStorage.getItem("userCountry");
|
|
1111
|
-
if (!currentCountry) {
|
|
1112
|
-
var updateCountry = /*#__PURE__*/ function() {
|
|
1113
|
-
var _ref = _async_to_generator(function() {
|
|
1114
|
-
var country;
|
|
1115
|
-
return _ts_generator(this, function(_state) {
|
|
1116
|
-
switch(_state.label){
|
|
1117
|
-
case 0:
|
|
1118
|
-
return [
|
|
1119
|
-
4,
|
|
1120
|
-
getUserCountryByIp()
|
|
1121
|
-
];
|
|
1122
|
-
case 1:
|
|
1123
|
-
country = _state.sent();
|
|
1124
|
-
changLang(country === import_akeyless_types_commons2.CountryOptions.IL ? "he" : "en");
|
|
1125
|
-
setUserCountry(country);
|
|
1126
|
-
localStorage.setItem("userCountry", country);
|
|
1127
|
-
return [
|
|
1128
|
-
2
|
|
1129
|
-
];
|
|
1130
|
-
}
|
|
1131
|
-
});
|
|
1132
|
-
});
|
|
1133
|
-
return function updateCountry() {
|
|
1134
|
-
return _ref.apply(this, arguments);
|
|
1135
|
-
};
|
|
1136
|
-
}();
|
|
1137
|
-
updateCountry();
|
|
1138
|
-
}
|
|
1139
|
-
}, []);
|
|
1140
|
-
return null;
|
|
1141
|
-
};
|
|
1142
|
-
// src/hooks/WebWorker.ts
|
|
1143
|
-
var import_react7 = require("react");
|
|
1144
1189
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1145
1190
|
0 && (module.exports = {
|
|
1191
|
+
useDbSnapshots: useDbSnapshots,
|
|
1146
1192
|
useDeepCompareEffect: useDeepCompareEffect,
|
|
1147
1193
|
useDeepCompareMemo: useDeepCompareMemo,
|
|
1148
1194
|
useDocumentTitle: useDocumentTitle,
|
|
1149
1195
|
useSafeEffect: useSafeEffect,
|
|
1150
1196
|
useSetUserCountry: useSetUserCountry,
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
useSocketSubscription: useSocketSubscription
|
|
1197
|
+
useSmartSnapshots: useSmartSnapshots,
|
|
1198
|
+
useSocketSnapshots: useSocketSnapshots
|
|
1154
1199
|
});
|
|
1155
1200
|
//# sourceMappingURL=index.js.map
|