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.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() {
|
|
@@ -663,19 +664,24 @@ var SocketService = /*#__PURE__*/ function() {
|
|
|
663
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
|
-
|
|
669
|
-
|
|
670
|
-
token
|
|
671
|
-
|
|
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
|
|
672
678
|
});
|
|
673
679
|
this.socket.on("connect", function() {
|
|
674
|
-
var _this_socket;
|
|
675
|
-
console.log("Socket connected:"
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
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, ")"));
|
|
682
|
+
_this.connectCallbacks.forEach(function(cb) {
|
|
683
|
+
return cb();
|
|
684
|
+
});
|
|
679
685
|
});
|
|
680
686
|
this.socket.on("disconnect", function(reason) {
|
|
681
687
|
console.log("Socket disconnected:", reason);
|
|
@@ -683,6 +689,12 @@ var SocketService = /*#__PURE__*/ function() {
|
|
|
683
689
|
return cb();
|
|
684
690
|
});
|
|
685
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
|
+
});
|
|
686
698
|
this.socket.on("connect_error", function(error) {
|
|
687
699
|
console.error("Socket connection error:", error);
|
|
688
700
|
});
|
|
@@ -705,10 +717,90 @@ var SocketService = /*#__PURE__*/ function() {
|
|
|
705
717
|
return this.socket;
|
|
706
718
|
}
|
|
707
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
|
+
},
|
|
708
799
|
{
|
|
709
800
|
/// subscribe to collections
|
|
710
801
|
key: "subscribeToCollections",
|
|
711
802
|
value: function subscribeToCollections(config) {
|
|
803
|
+
var _this = this;
|
|
712
804
|
if (config.length === 0) {
|
|
713
805
|
return function() {};
|
|
714
806
|
}
|
|
@@ -719,48 +811,24 @@ var SocketService = /*#__PURE__*/ function() {
|
|
|
719
811
|
var eventHandlers = [];
|
|
720
812
|
config.forEach(function(configuration) {
|
|
721
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;
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
eventName
|
|
725
|
-
handler: onFirstTime
|
|
726
|
-
});
|
|
727
|
-
s.on("add:".concat(collectionName), onAdd);
|
|
728
|
-
eventHandlers.push({
|
|
729
|
-
eventName: "add:".concat(collectionName),
|
|
730
|
-
handler: onAdd
|
|
731
|
-
});
|
|
732
|
-
s.on("update:".concat(collectionName), onModify);
|
|
733
|
-
eventHandlers.push({
|
|
734
|
-
eventName: "update:".concat(collectionName),
|
|
735
|
-
handler: onModify
|
|
736
|
-
});
|
|
737
|
-
s.on("delete:".concat(collectionName), onRemove);
|
|
738
|
-
eventHandlers.push({
|
|
739
|
-
eventName: "delete:".concat(collectionName),
|
|
740
|
-
handler: onRemove
|
|
741
|
-
});
|
|
742
|
-
extraParsers === null || extraParsers === void 0 ? void 0 : extraParsers.forEach(function(parsers) {
|
|
743
|
-
var extraOnAdd = parsers.onAdd, extraOnFirstTime = parsers.onFirstTime, extraOnModify = parsers.onModify, extraOnRemove = parsers.onRemove;
|
|
744
|
-
s.on("initial:".concat(collectionName), extraOnFirstTime);
|
|
745
|
-
eventHandlers.push({
|
|
746
|
-
eventName: "initial:".concat(collectionName),
|
|
747
|
-
handler: extraOnFirstTime
|
|
748
|
-
});
|
|
749
|
-
s.on("add:".concat(collectionName), extraOnAdd);
|
|
750
|
-
eventHandlers.push({
|
|
751
|
-
eventName: "add:".concat(collectionName),
|
|
752
|
-
handler: extraOnAdd
|
|
753
|
-
});
|
|
754
|
-
s.on("update:".concat(collectionName), extraOnModify);
|
|
755
|
-
eventHandlers.push({
|
|
756
|
-
eventName: "update:".concat(collectionName),
|
|
757
|
-
handler: extraOnModify
|
|
758
|
-
});
|
|
759
|
-
s.on("delete:".concat(collectionName), extraOnRemove);
|
|
814
|
+
var attach = function(eventName, handler) {
|
|
815
|
+
_this.socket.off(eventName, handler);
|
|
816
|
+
_this.socket.on(eventName, handler);
|
|
760
817
|
eventHandlers.push({
|
|
761
|
-
eventName:
|
|
762
|
-
handler:
|
|
818
|
+
eventName: eventName,
|
|
819
|
+
handler: handler
|
|
763
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);
|
|
764
832
|
});
|
|
765
833
|
});
|
|
766
834
|
s.emit("subscribe_collections", collectionsNames, function(callback) {
|
|
@@ -861,64 +929,6 @@ var SocketService = /*#__PURE__*/ function() {
|
|
|
861
929
|
});
|
|
862
930
|
});
|
|
863
931
|
}
|
|
864
|
-
},
|
|
865
|
-
{
|
|
866
|
-
/// connection management methods
|
|
867
|
-
key: "onConnect",
|
|
868
|
-
value: function onConnect(callback) {
|
|
869
|
-
var _this_socket;
|
|
870
|
-
this.connectCallbacks.push(callback);
|
|
871
|
-
if ((_this_socket = this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.connected) {
|
|
872
|
-
callback();
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
},
|
|
876
|
-
{
|
|
877
|
-
key: "offConnect",
|
|
878
|
-
value: function offConnect(callback) {
|
|
879
|
-
this.connectCallbacks = this.connectCallbacks.filter(function(cb) {
|
|
880
|
-
return cb !== callback;
|
|
881
|
-
});
|
|
882
|
-
}
|
|
883
|
-
},
|
|
884
|
-
{
|
|
885
|
-
key: "onDisconnect",
|
|
886
|
-
value: function onDisconnect(callback) {
|
|
887
|
-
this.disconnectCallbacks.push(callback);
|
|
888
|
-
if (this.socket && !this.socket.connected) {
|
|
889
|
-
callback();
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
},
|
|
893
|
-
{
|
|
894
|
-
key: "offDisconnect",
|
|
895
|
-
value: function offDisconnect(callback) {
|
|
896
|
-
this.disconnectCallbacks = this.disconnectCallbacks.filter(function(cb) {
|
|
897
|
-
return cb !== callback;
|
|
898
|
-
});
|
|
899
|
-
}
|
|
900
|
-
},
|
|
901
|
-
{
|
|
902
|
-
key: "isConnected",
|
|
903
|
-
value: function isConnected() {
|
|
904
|
-
var _this_socket;
|
|
905
|
-
return ((_this_socket = this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.connected) || false;
|
|
906
|
-
}
|
|
907
|
-
},
|
|
908
|
-
{
|
|
909
|
-
key: "setAuthToken",
|
|
910
|
-
value: function setAuthToken(token) {
|
|
911
|
-
this.authToken = token;
|
|
912
|
-
if (this.socket) {
|
|
913
|
-
this.socket.auth = {
|
|
914
|
-
token: token
|
|
915
|
-
};
|
|
916
|
-
if (this.socket.connected) {
|
|
917
|
-
this.socket.disconnect();
|
|
918
|
-
}
|
|
919
|
-
this.socket.connect();
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
932
|
}
|
|
923
933
|
], [
|
|
924
934
|
{
|
|
@@ -934,11 +944,54 @@ var SocketService = /*#__PURE__*/ function() {
|
|
|
934
944
|
return _SocketService;
|
|
935
945
|
}();
|
|
936
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
|
+
};
|
|
937
990
|
// src/hooks/react.ts
|
|
938
991
|
var import_lodash2 = require("lodash");
|
|
939
|
-
var
|
|
992
|
+
var import_react3 = require("react");
|
|
940
993
|
function useSafeEffect(callback, dependencies, error_message) {
|
|
941
|
-
(0,
|
|
994
|
+
(0, import_react3.useEffect)(function() {
|
|
942
995
|
try {
|
|
943
996
|
callback();
|
|
944
997
|
} catch (error) {
|
|
@@ -947,80 +1000,88 @@ function useSafeEffect(callback, dependencies, error_message) {
|
|
|
947
1000
|
}, dependencies);
|
|
948
1001
|
}
|
|
949
1002
|
var useDeepCompareMemo = function(factory, dependencies) {
|
|
950
|
-
var previousDepsRef = (0,
|
|
1003
|
+
var previousDepsRef = (0, import_react3.useRef)([]);
|
|
951
1004
|
if (!(0, import_lodash2.isEqual)(dependencies, previousDepsRef.current)) {
|
|
952
1005
|
previousDepsRef.current = dependencies;
|
|
953
1006
|
}
|
|
954
|
-
return (0,
|
|
1007
|
+
return (0, import_react3.useMemo)(factory, previousDepsRef.current);
|
|
955
1008
|
};
|
|
956
1009
|
function useDeepCompareEffect(effect, dependencies) {
|
|
957
|
-
var previousDepsRef = (0,
|
|
1010
|
+
var previousDepsRef = (0, import_react3.useRef)();
|
|
958
1011
|
if (!(0, import_lodash2.isEqual)(previousDepsRef.current, dependencies)) {
|
|
959
1012
|
previousDepsRef.current = dependencies;
|
|
960
1013
|
}
|
|
961
|
-
(0,
|
|
1014
|
+
(0, import_react3.useEffect)(effect, [
|
|
962
1015
|
previousDepsRef.current
|
|
963
1016
|
]);
|
|
964
1017
|
}
|
|
965
|
-
// src/hooks/
|
|
966
|
-
var
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
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);
|
|
970
1027
|
useDeepCompareEffect(function() {
|
|
971
1028
|
if (!auth.currentUser) {
|
|
972
1029
|
return;
|
|
973
1030
|
}
|
|
974
|
-
|
|
1031
|
+
var subscribe = function() {
|
|
1032
|
+
if (configs.length === 0) {
|
|
1033
|
+
return;
|
|
1034
|
+
}
|
|
1035
|
+
var disposer = socketServiceInstance.subscribeToCollections(configs);
|
|
975
1036
|
setCleanupSubscriptions(function(prev) {
|
|
976
1037
|
return _to_consumable_array(prev).concat([
|
|
977
|
-
|
|
1038
|
+
disposer
|
|
978
1039
|
]);
|
|
979
1040
|
});
|
|
980
|
-
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)
|
|
1041
|
+
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
|
|
981
1042
|
console.log("==> ".concat(label || "Cache snapshots", " subscribed to ").concat(configs.map(function(c) {
|
|
982
1043
|
return c.collectionName;
|
|
983
1044
|
}).join(", ")));
|
|
984
1045
|
}
|
|
985
|
-
}
|
|
1046
|
+
};
|
|
1047
|
+
if (socketServiceInstance.isConnected()) {
|
|
1048
|
+
setSocketConnected(true);
|
|
1049
|
+
subscribe();
|
|
1050
|
+
} else if (!socketStarted.current) {
|
|
1051
|
+
socketStarted.current = true;
|
|
986
1052
|
auth.currentUser.getIdToken().then(function(token) {
|
|
987
|
-
socketServiceInstance.
|
|
988
|
-
|
|
989
|
-
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs) && configs.length > 0) {
|
|
1053
|
+
socketServiceInstance.startSession(token);
|
|
1054
|
+
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
|
|
990
1055
|
console.log("==> ".concat(label || "Cache snapshots", " started... "));
|
|
991
1056
|
}
|
|
992
1057
|
});
|
|
993
1058
|
}
|
|
994
|
-
var
|
|
1059
|
+
var offConnect = socketServiceInstance.onConnect(function() {
|
|
995
1060
|
setSocketConnected(true);
|
|
996
|
-
|
|
997
|
-
|
|
1061
|
+
socketStarted.current = false;
|
|
1062
|
+
subscribe();
|
|
1063
|
+
});
|
|
1064
|
+
var offDisconnect = socketServiceInstance.onDisconnect(function() {
|
|
1065
|
+
setSocketConnected(false);
|
|
998
1066
|
cleanupSubscriptions.forEach(function(cleanup) {
|
|
999
1067
|
return cleanup();
|
|
1000
1068
|
});
|
|
1001
|
-
|
|
1002
|
-
};
|
|
1003
|
-
socketServiceInstance.onConnect(uiOnConnect);
|
|
1004
|
-
socketServiceInstance.onDisconnect(uiOnDisconnect);
|
|
1005
|
-
setSocketConnected(socketServiceInstance.isConnected());
|
|
1069
|
+
});
|
|
1006
1070
|
return function() {
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
socketServiceInstance.offDisconnect(uiOnDisconnect);
|
|
1013
|
-
}
|
|
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();
|
|
1014
1076
|
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs) && configs.length > 0) {
|
|
1015
1077
|
console.log("==> ".concat(label || "Cache snapshots", " unsubscribed. "));
|
|
1016
1078
|
}
|
|
1017
1079
|
};
|
|
1018
1080
|
}, [
|
|
1019
|
-
socketConnected,
|
|
1020
1081
|
configs,
|
|
1021
|
-
auth
|
|
1082
|
+
(_auth_currentUser = auth.currentUser) === null || _auth_currentUser === void 0 ? void 0 : _auth_currentUser.uid
|
|
1022
1083
|
]);
|
|
1023
|
-
(0,
|
|
1084
|
+
(0, import_react5.useEffect)(function() {
|
|
1024
1085
|
return function() {
|
|
1025
1086
|
cleanupSubscriptions.forEach(function(cleanup) {
|
|
1026
1087
|
return cleanup();
|
|
@@ -1031,16 +1092,7 @@ var useSocketSubscription = function(configs, label, settings) {
|
|
|
1031
1092
|
socketConnected: socketConnected
|
|
1032
1093
|
};
|
|
1033
1094
|
};
|
|
1034
|
-
|
|
1035
|
-
var useDocumentTitle = function(title) {
|
|
1036
|
-
(0, import_react5.useEffect)(function() {
|
|
1037
|
-
document.title = title;
|
|
1038
|
-
}, [
|
|
1039
|
-
title
|
|
1040
|
-
]);
|
|
1041
|
-
return null;
|
|
1042
|
-
};
|
|
1043
|
-
var useSnapshotBulk = function(configs, label, settings) {
|
|
1095
|
+
var useDbSnapshots = function(configs, label, settings) {
|
|
1044
1096
|
var snapshotsFirstTime = (0, import_react5.useRef)([]);
|
|
1045
1097
|
var unsubscribeFunctions = (0, import_react5.useRef)([]);
|
|
1046
1098
|
useDeepCompareEffect(function() {
|
|
@@ -1091,7 +1143,7 @@ var useSnapshotBulk = function(configs, label, settings) {
|
|
|
1091
1143
|
};
|
|
1092
1144
|
}, []);
|
|
1093
1145
|
};
|
|
1094
|
-
var
|
|
1146
|
+
var useSmartSnapshots = function(configs, label, settings) {
|
|
1095
1147
|
var _ref = _sliced_to_array((0, import_react5.useState)(null), 2), cacheCollectionsConfig = _ref[0], setCacheCollectionsConfig = _ref[1];
|
|
1096
1148
|
(0, import_react5.useEffect)(function() {
|
|
1097
1149
|
get_document_by_id("nx-settings", "cache_collections_config").then(function(res) {
|
|
@@ -1126,58 +1178,22 @@ var useSmartSnapshot = function(configs, label, settings) {
|
|
|
1126
1178
|
configs,
|
|
1127
1179
|
cacheCollectionsConfig
|
|
1128
1180
|
]);
|
|
1129
|
-
|
|
1130
|
-
var socketConnected =
|
|
1181
|
+
useDbSnapshots(groupedConfig.configForDb, label, settings);
|
|
1182
|
+
var socketConnected = useSocketSnapshots(groupedConfig.configForCache, label, settings).socketConnected;
|
|
1131
1183
|
return {
|
|
1132
1184
|
groupedConfig: groupedConfig,
|
|
1133
1185
|
socketConnected: socketConnected
|
|
1134
1186
|
};
|
|
1135
1187
|
};
|
|
1136
|
-
var useSetUserCountry = function(setUserCountry, changLang) {
|
|
1137
|
-
(0, import_react5.useLayoutEffect)(function() {
|
|
1138
|
-
var currentCountry = localStorage.getItem("userCountry");
|
|
1139
|
-
if (!currentCountry) {
|
|
1140
|
-
var updateCountry = /*#__PURE__*/ function() {
|
|
1141
|
-
var _ref = _async_to_generator(function() {
|
|
1142
|
-
var country;
|
|
1143
|
-
return _ts_generator(this, function(_state) {
|
|
1144
|
-
switch(_state.label){
|
|
1145
|
-
case 0:
|
|
1146
|
-
return [
|
|
1147
|
-
4,
|
|
1148
|
-
getUserCountryByIp()
|
|
1149
|
-
];
|
|
1150
|
-
case 1:
|
|
1151
|
-
country = _state.sent();
|
|
1152
|
-
changLang(country === import_akeyless_types_commons2.CountryOptions.IL ? "he" : "en");
|
|
1153
|
-
setUserCountry(country);
|
|
1154
|
-
localStorage.setItem("userCountry", country);
|
|
1155
|
-
return [
|
|
1156
|
-
2
|
|
1157
|
-
];
|
|
1158
|
-
}
|
|
1159
|
-
});
|
|
1160
|
-
});
|
|
1161
|
-
return function updateCountry() {
|
|
1162
|
-
return _ref.apply(this, arguments);
|
|
1163
|
-
};
|
|
1164
|
-
}();
|
|
1165
|
-
updateCountry();
|
|
1166
|
-
}
|
|
1167
|
-
}, []);
|
|
1168
|
-
return null;
|
|
1169
|
-
};
|
|
1170
|
-
// src/hooks/WebWorker.ts
|
|
1171
|
-
var import_react7 = require("react");
|
|
1172
1188
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1173
1189
|
0 && (module.exports = {
|
|
1190
|
+
useDbSnapshots: useDbSnapshots,
|
|
1174
1191
|
useDeepCompareEffect: useDeepCompareEffect,
|
|
1175
1192
|
useDeepCompareMemo: useDeepCompareMemo,
|
|
1176
1193
|
useDocumentTitle: useDocumentTitle,
|
|
1177
1194
|
useSafeEffect: useSafeEffect,
|
|
1178
1195
|
useSetUserCountry: useSetUserCountry,
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
useSocketSubscription: useSocketSubscription
|
|
1196
|
+
useSmartSnapshots: useSmartSnapshots,
|
|
1197
|
+
useSocketSnapshots: useSocketSnapshots
|
|
1182
1198
|
});
|
|
1183
1199
|
//# sourceMappingURL=index.js.map
|