akeyless-client-commons 1.1.101 → 1.1.103

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.
@@ -302,6 +302,8 @@ declare class SocketService {
302
302
  private connectCallbacks;
303
303
  private disconnectCallbacks;
304
304
  private authToken;
305
+ private isDisconnected;
306
+ private handleDisconnect;
305
307
  private initSocket;
306
308
  private constructor();
307
309
  static getInstance(): SocketService;
@@ -322,7 +324,6 @@ declare class SocketService {
322
324
  key: string;
323
325
  collection_name: string;
324
326
  }): Promise<SocketCallbackResponse>;
325
- clearAllRedisData(): Promise<SocketCallbackResponse>;
326
327
  }
327
328
  declare const socketServiceInstance: SocketService;
328
329
 
@@ -302,6 +302,8 @@ declare class SocketService {
302
302
  private connectCallbacks;
303
303
  private disconnectCallbacks;
304
304
  private authToken;
305
+ private isDisconnected;
306
+ private handleDisconnect;
305
307
  private initSocket;
306
308
  private constructor();
307
309
  static getInstance(): SocketService;
@@ -322,7 +324,6 @@ declare class SocketService {
322
324
  key: string;
323
325
  collection_name: string;
324
326
  }): Promise<SocketCallbackResponse>;
325
- clearAllRedisData(): Promise<SocketCallbackResponse>;
326
327
  }
327
328
  declare const socketServiceInstance: SocketService;
328
329
 
@@ -2748,11 +2748,25 @@ var SESSION_STORAGE_KEY = "sessionId";
2748
2748
  var SocketService = /*#__PURE__*/ function() {
2749
2749
  "use strict";
2750
2750
  function _SocketService() {
2751
+ var _this = this;
2751
2752
  _class_call_check(this, _SocketService);
2752
2753
  this.socket = null;
2753
2754
  this.connectCallbacks = [];
2754
2755
  this.disconnectCallbacks = [];
2755
2756
  this.authToken = null;
2757
+ this.isDisconnected = true;
2758
+ this.handleDisconnect = function(source, reason) {
2759
+ var _this_socket;
2760
+ if (_this.isDisconnected) {
2761
+ return;
2762
+ }
2763
+ _this.isDisconnected = true;
2764
+ var transport = (_this_socket = _this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.io.engine.transport.name;
2765
+ console.log("Socket disconnected (".concat(source, ") [transport=").concat(transport, "]:"), reason);
2766
+ _this.disconnectCallbacks.forEach(function(cb) {
2767
+ return cb();
2768
+ });
2769
+ };
2756
2770
  }
2757
2771
  _create_class(_SocketService, [
2758
2772
  {
@@ -2777,32 +2791,27 @@ var SocketService = /*#__PURE__*/ function() {
2777
2791
  ],
2778
2792
  reconnection: true,
2779
2793
  reconnectionAttempts: 30,
2780
- reconnectionDelay: 2 * 1e3
2794
+ reconnectionDelay: 2 * 1e3,
2795
+ reconnectionDelayMax: 10 * 1e3,
2796
+ timeout: 20 * 1e3
2781
2797
  });
2782
2798
  this.socket.on("connect", function() {
2783
- var _this_socket, _this_socket1;
2784
- 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, ")"));
2799
+ var _this_socket, _this_socket1, _this_socket2;
2800
+ var transport = (_this_socket = _this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.io.engine.transport.name;
2801
+ console.log("\uD83D\uDFE2 Socket connected: ".concat((_this_socket1 = _this.socket) === null || _this_socket1 === void 0 ? void 0 : _this_socket1.id, " (recovered - ").concat((_this_socket2 = _this.socket) === null || _this_socket2 === void 0 ? void 0 : _this_socket2.recovered, ") (transport - ").concat(transport, ")"));
2802
+ _this.isDisconnected = false;
2785
2803
  _this.connectCallbacks.forEach(function(cb) {
2786
2804
  return cb();
2787
2805
  });
2788
2806
  });
2789
2807
  this.socket.on("disconnect", function(reason) {
2790
- console.log("Socket disconnected:", reason);
2791
- _this.disconnectCallbacks.forEach(function(cb) {
2792
- return cb();
2793
- });
2808
+ _this.handleDisconnect("disconnect", reason);
2794
2809
  });
2795
2810
  this.socket.io.on("close", function(reason) {
2796
- console.log("Socket Manager close:", reason);
2797
- _this.disconnectCallbacks.forEach(function(cb) {
2798
- return cb();
2799
- });
2811
+ _this.handleDisconnect("manager_close", reason);
2800
2812
  });
2801
2813
  this.socket.io.engine.on("close", function(reason) {
2802
- console.log("Socket Engine close:", reason);
2803
- _this.disconnectCallbacks.forEach(function(cb) {
2804
- return cb();
2805
- });
2814
+ _this.handleDisconnect("engine_close", reason);
2806
2815
  });
2807
2816
  this.socket.on("session", function(param) {
2808
2817
  var session_id = param.session_id;
@@ -2813,6 +2822,16 @@ var SocketService = /*#__PURE__*/ function() {
2813
2822
  this.socket.on("connect_error", function(error) {
2814
2823
  console.error("Socket connection error:", error);
2815
2824
  });
2825
+ this.socket.io.on("reconnect_attempt", function(attempt) {
2826
+ console.log("Socket reconnect attempt:", attempt);
2827
+ });
2828
+ this.socket.io.on("reconnect_error", function(error) {
2829
+ console.error("Socket reconnect error:", error);
2830
+ });
2831
+ this.socket.io.on("reconnect", function(attempt) {
2832
+ console.log("Socket reconnected after attempts:", attempt);
2833
+ _this.isDisconnected = false;
2834
+ });
2816
2835
  }
2817
2836
  }
2818
2837
  },
@@ -3031,21 +3050,6 @@ var SocketService = /*#__PURE__*/ function() {
3031
3050
  });
3032
3051
  });
3033
3052
  }
3034
- },
3035
- {
3036
- key: "clearAllRedisData",
3037
- value: function clearAllRedisData() {
3038
- var s = this.getSocketInstance();
3039
- return new Promise(function(resolve, reject) {
3040
- s.emit("clear_all_redis_data", function(ack) {
3041
- if (ack.success) {
3042
- resolve(ack);
3043
- } else {
3044
- reject(new Error(ack.message || "Clear all Redis data operation failed"));
3045
- }
3046
- });
3047
- });
3048
- }
3049
3053
  }
3050
3054
  ], [
3051
3055
  {
@@ -2357,11 +2357,25 @@ var SESSION_STORAGE_KEY = "sessionId";
2357
2357
  var SocketService = /*#__PURE__*/ function() {
2358
2358
  "use strict";
2359
2359
  function _SocketService() {
2360
+ var _this = this;
2360
2361
  _class_call_check(this, _SocketService);
2361
2362
  this.socket = null;
2362
2363
  this.connectCallbacks = [];
2363
2364
  this.disconnectCallbacks = [];
2364
2365
  this.authToken = null;
2366
+ this.isDisconnected = true;
2367
+ this.handleDisconnect = function(source, reason) {
2368
+ var _this_socket;
2369
+ if (_this.isDisconnected) {
2370
+ return;
2371
+ }
2372
+ _this.isDisconnected = true;
2373
+ var transport = (_this_socket = _this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.io.engine.transport.name;
2374
+ console.log("Socket disconnected (".concat(source, ") [transport=").concat(transport, "]:"), reason);
2375
+ _this.disconnectCallbacks.forEach(function(cb) {
2376
+ return cb();
2377
+ });
2378
+ };
2365
2379
  }
2366
2380
  _create_class(_SocketService, [
2367
2381
  {
@@ -2386,32 +2400,27 @@ var SocketService = /*#__PURE__*/ function() {
2386
2400
  ],
2387
2401
  reconnection: true,
2388
2402
  reconnectionAttempts: 30,
2389
- reconnectionDelay: 2 * 1e3
2403
+ reconnectionDelay: 2 * 1e3,
2404
+ reconnectionDelayMax: 10 * 1e3,
2405
+ timeout: 20 * 1e3
2390
2406
  });
2391
2407
  this.socket.on("connect", function() {
2392
- var _this_socket, _this_socket1;
2393
- 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, ")"));
2408
+ var _this_socket, _this_socket1, _this_socket2;
2409
+ var transport = (_this_socket = _this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.io.engine.transport.name;
2410
+ console.log("\uD83D\uDFE2 Socket connected: ".concat((_this_socket1 = _this.socket) === null || _this_socket1 === void 0 ? void 0 : _this_socket1.id, " (recovered - ").concat((_this_socket2 = _this.socket) === null || _this_socket2 === void 0 ? void 0 : _this_socket2.recovered, ") (transport - ").concat(transport, ")"));
2411
+ _this.isDisconnected = false;
2394
2412
  _this.connectCallbacks.forEach(function(cb) {
2395
2413
  return cb();
2396
2414
  });
2397
2415
  });
2398
2416
  this.socket.on("disconnect", function(reason) {
2399
- console.log("Socket disconnected:", reason);
2400
- _this.disconnectCallbacks.forEach(function(cb) {
2401
- return cb();
2402
- });
2417
+ _this.handleDisconnect("disconnect", reason);
2403
2418
  });
2404
2419
  this.socket.io.on("close", function(reason) {
2405
- console.log("Socket Manager close:", reason);
2406
- _this.disconnectCallbacks.forEach(function(cb) {
2407
- return cb();
2408
- });
2420
+ _this.handleDisconnect("manager_close", reason);
2409
2421
  });
2410
2422
  this.socket.io.engine.on("close", function(reason) {
2411
- console.log("Socket Engine close:", reason);
2412
- _this.disconnectCallbacks.forEach(function(cb) {
2413
- return cb();
2414
- });
2423
+ _this.handleDisconnect("engine_close", reason);
2415
2424
  });
2416
2425
  this.socket.on("session", function(param) {
2417
2426
  var session_id = param.session_id;
@@ -2422,6 +2431,16 @@ var SocketService = /*#__PURE__*/ function() {
2422
2431
  this.socket.on("connect_error", function(error) {
2423
2432
  console.error("Socket connection error:", error);
2424
2433
  });
2434
+ this.socket.io.on("reconnect_attempt", function(attempt) {
2435
+ console.log("Socket reconnect attempt:", attempt);
2436
+ });
2437
+ this.socket.io.on("reconnect_error", function(error) {
2438
+ console.error("Socket reconnect error:", error);
2439
+ });
2440
+ this.socket.io.on("reconnect", function(attempt) {
2441
+ console.log("Socket reconnected after attempts:", attempt);
2442
+ _this.isDisconnected = false;
2443
+ });
2425
2444
  }
2426
2445
  }
2427
2446
  },
@@ -2640,21 +2659,6 @@ var SocketService = /*#__PURE__*/ function() {
2640
2659
  });
2641
2660
  });
2642
2661
  }
2643
- },
2644
- {
2645
- key: "clearAllRedisData",
2646
- value: function clearAllRedisData() {
2647
- var s = this.getSocketInstance();
2648
- return new Promise(function(resolve, reject) {
2649
- s.emit("clear_all_redis_data", function(ack) {
2650
- if (ack.success) {
2651
- resolve(ack);
2652
- } else {
2653
- reject(new Error(ack.message || "Clear all Redis data operation failed"));
2654
- }
2655
- });
2656
- });
2657
- }
2658
2662
  }
2659
2663
  ], [
2660
2664
  {
@@ -67,6 +67,8 @@ declare class SocketService {
67
67
  private connectCallbacks;
68
68
  private disconnectCallbacks;
69
69
  private authToken;
70
+ private isDisconnected;
71
+ private handleDisconnect;
70
72
  private initSocket;
71
73
  private constructor();
72
74
  static getInstance(): SocketService;
@@ -87,13 +89,14 @@ declare class SocketService {
87
89
  key: string;
88
90
  collection_name: string;
89
91
  }): Promise<SocketCallbackResponse>;
90
- clearAllRedisData(): Promise<SocketCallbackResponse>;
91
92
  }
92
93
  declare const socketServiceInstance: SocketService;
93
94
 
94
95
  interface UseDbSnapshotsSettings {
95
96
  cleanupForConfigChange?: boolean;
96
97
  disableLogs?: boolean;
98
+ /** When false, snapshots run on main thread without Web Worker. Default true. */
99
+ useWorker?: boolean;
97
100
  worker?: UseWebWorkerOptions;
98
101
  socket?: {
99
102
  getSocket?: (socket: typeof socketServiceInstance) => void;
@@ -67,6 +67,8 @@ declare class SocketService {
67
67
  private connectCallbacks;
68
68
  private disconnectCallbacks;
69
69
  private authToken;
70
+ private isDisconnected;
71
+ private handleDisconnect;
70
72
  private initSocket;
71
73
  private constructor();
72
74
  static getInstance(): SocketService;
@@ -87,13 +89,14 @@ declare class SocketService {
87
89
  key: string;
88
90
  collection_name: string;
89
91
  }): Promise<SocketCallbackResponse>;
90
- clearAllRedisData(): Promise<SocketCallbackResponse>;
91
92
  }
92
93
  declare const socketServiceInstance: SocketService;
93
94
 
94
95
  interface UseDbSnapshotsSettings {
95
96
  cleanupForConfigChange?: boolean;
96
97
  disableLogs?: boolean;
98
+ /** When false, snapshots run on main thread without Web Worker. Default true. */
99
+ useWorker?: boolean;
97
100
  worker?: UseWebWorkerOptions;
98
101
  socket?: {
99
102
  getSocket?: (socket: typeof socketServiceInstance) => void;
@@ -753,11 +753,25 @@ var SESSION_STORAGE_KEY = "sessionId";
753
753
  var SocketService = /*#__PURE__*/ function() {
754
754
  "use strict";
755
755
  function _SocketService() {
756
+ var _this = this;
756
757
  _class_call_check(this, _SocketService);
757
758
  this.socket = null;
758
759
  this.connectCallbacks = [];
759
760
  this.disconnectCallbacks = [];
760
761
  this.authToken = null;
762
+ this.isDisconnected = true;
763
+ this.handleDisconnect = function(source, reason) {
764
+ var _this_socket;
765
+ if (_this.isDisconnected) {
766
+ return;
767
+ }
768
+ _this.isDisconnected = true;
769
+ var transport = (_this_socket = _this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.io.engine.transport.name;
770
+ console.log("Socket disconnected (".concat(source, ") [transport=").concat(transport, "]:"), reason);
771
+ _this.disconnectCallbacks.forEach(function(cb) {
772
+ return cb();
773
+ });
774
+ };
761
775
  }
762
776
  _create_class(_SocketService, [
763
777
  {
@@ -782,32 +796,27 @@ var SocketService = /*#__PURE__*/ function() {
782
796
  ],
783
797
  reconnection: true,
784
798
  reconnectionAttempts: 30,
785
- reconnectionDelay: 2 * 1e3
799
+ reconnectionDelay: 2 * 1e3,
800
+ reconnectionDelayMax: 10 * 1e3,
801
+ timeout: 20 * 1e3
786
802
  });
787
803
  this.socket.on("connect", function() {
788
- var _this_socket, _this_socket1;
789
- 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, ")"));
804
+ var _this_socket, _this_socket1, _this_socket2;
805
+ var transport = (_this_socket = _this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.io.engine.transport.name;
806
+ console.log("\uD83D\uDFE2 Socket connected: ".concat((_this_socket1 = _this.socket) === null || _this_socket1 === void 0 ? void 0 : _this_socket1.id, " (recovered - ").concat((_this_socket2 = _this.socket) === null || _this_socket2 === void 0 ? void 0 : _this_socket2.recovered, ") (transport - ").concat(transport, ")"));
807
+ _this.isDisconnected = false;
790
808
  _this.connectCallbacks.forEach(function(cb) {
791
809
  return cb();
792
810
  });
793
811
  });
794
812
  this.socket.on("disconnect", function(reason) {
795
- console.log("Socket disconnected:", reason);
796
- _this.disconnectCallbacks.forEach(function(cb) {
797
- return cb();
798
- });
813
+ _this.handleDisconnect("disconnect", reason);
799
814
  });
800
815
  this.socket.io.on("close", function(reason) {
801
- console.log("Socket Manager close:", reason);
802
- _this.disconnectCallbacks.forEach(function(cb) {
803
- return cb();
804
- });
816
+ _this.handleDisconnect("manager_close", reason);
805
817
  });
806
818
  this.socket.io.engine.on("close", function(reason) {
807
- console.log("Socket Engine close:", reason);
808
- _this.disconnectCallbacks.forEach(function(cb) {
809
- return cb();
810
- });
819
+ _this.handleDisconnect("engine_close", reason);
811
820
  });
812
821
  this.socket.on("session", function(param) {
813
822
  var session_id = param.session_id;
@@ -818,6 +827,16 @@ var SocketService = /*#__PURE__*/ function() {
818
827
  this.socket.on("connect_error", function(error) {
819
828
  console.error("Socket connection error:", error);
820
829
  });
830
+ this.socket.io.on("reconnect_attempt", function(attempt) {
831
+ console.log("Socket reconnect attempt:", attempt);
832
+ });
833
+ this.socket.io.on("reconnect_error", function(error) {
834
+ console.error("Socket reconnect error:", error);
835
+ });
836
+ this.socket.io.on("reconnect", function(attempt) {
837
+ console.log("Socket reconnected after attempts:", attempt);
838
+ _this.isDisconnected = false;
839
+ });
821
840
  }
822
841
  }
823
842
  },
@@ -1036,21 +1055,6 @@ var SocketService = /*#__PURE__*/ function() {
1036
1055
  });
1037
1056
  });
1038
1057
  }
1039
- },
1040
- {
1041
- key: "clearAllRedisData",
1042
- value: function clearAllRedisData() {
1043
- var s = this.getSocketInstance();
1044
- return new Promise(function(resolve, reject) {
1045
- s.emit("clear_all_redis_data", function(ack) {
1046
- if (ack.success) {
1047
- resolve(ack);
1048
- } else {
1049
- reject(new Error(ack.message || "Clear all Redis data operation failed"));
1050
- }
1051
- });
1052
- });
1053
- }
1054
1058
  }
1055
1059
  ], [
1056
1060
  {
@@ -1633,15 +1637,16 @@ var useDbSnapshots = function(configs, label, settings) {
1633
1637
  });
1634
1638
  };
1635
1639
  useDeepCompareEffect(function() {
1640
+ var useWorker = (settings === null || settings === void 0 ? void 0 : settings.useWorker) !== false;
1641
+ var configsToUse = useWorker ? wrapConfigsForWorker(configs) : configs;
1636
1642
  var start = performance.now();
1637
1643
  if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs) && configs.length > 0) {
1638
1644
  console.log("==> ".concat(label || "DB snapshots", " started from db... "));
1639
1645
  }
1640
- var wrappedConfigs = wrapConfigsForWorker(configs);
1641
1646
  lastDbCollectionsRef.current = configs.map(function(c) {
1642
1647
  return c.collectionName;
1643
1648
  });
1644
- var snapshotResults = wrappedConfigs.map(function(config) {
1649
+ var snapshotResults = configsToUse.map(function(config) {
1645
1650
  return snapshot(config, snapshotsFirstTime.current, settings);
1646
1651
  });
1647
1652
  unsubscribeFunctions.current = snapshotResults.map(function(result) {
@@ -1720,15 +1725,16 @@ var useDbDocumentSnapshots = function(configs, label, settings) {
1720
1725
  return perDocFirstTimeRef.current[key];
1721
1726
  };
1722
1727
  useDeepCompareEffect(function() {
1728
+ var useWorker = (settings === null || settings === void 0 ? void 0 : settings.useWorker) !== false;
1729
+ var configsToUse = useWorker ? wrapConfigsForWorker(configs) : configs;
1723
1730
  var start = performance.now();
1724
1731
  if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs) && configs.length > 0) {
1725
1732
  console.log("==> ".concat(label || "DB document snapshots", " started from db... "));
1726
1733
  }
1727
- var wrappedConfigs = wrapConfigsForWorker(configs);
1728
1734
  lastDbDocsRef.current = configs.map(function(c) {
1729
1735
  return "".concat(c.collectionName, "/").concat(c.documentId);
1730
1736
  });
1731
- var snapshotResults = wrappedConfigs.map(function(config) {
1737
+ var snapshotResults = configsToUse.map(function(config) {
1732
1738
  return snapshotDocument(config, getFirstTimeBucket(config));
1733
1739
  });
1734
1740
  unsubscribeFunctions.current = snapshotResults.map(function(result) {
@@ -1850,6 +1856,10 @@ var useSocketSnapshots = function(configs, label, settings) {
1850
1856
  if (!auth.currentUser) {
1851
1857
  return;
1852
1858
  }
1859
+ var useWorker = (settings === null || settings === void 0 ? void 0 : settings.useWorker) !== false;
1860
+ var configsToUse = function(cfgs) {
1861
+ return useWorker ? wrapConfigsForWorker(cfgs) : cfgs;
1862
+ };
1853
1863
  var subscribe = function() {
1854
1864
  var desiredNames = new Set(configs.map(function(c) {
1855
1865
  return c.collectionName;
@@ -1864,7 +1874,7 @@ var useSocketSnapshots = function(configs, label, settings) {
1864
1874
  cleanupSubscriptionsRef.current = [];
1865
1875
  }
1866
1876
  if (configs.length === 0) return;
1867
- var disposer2 = socketServiceInstance.subscribeToCollections(wrapConfigsForWorker(configs));
1877
+ var disposer2 = socketServiceInstance.subscribeToCollections(configsToUse(configs));
1868
1878
  cleanupSubscriptionsRef.current.push(disposer2);
1869
1879
  activeCollectionsRef.current = new Set(desiredNames);
1870
1880
  activeSubscriptionKeyRef.current = key;
@@ -1884,7 +1894,7 @@ var useSocketSnapshots = function(configs, label, settings) {
1884
1894
  var configsToAdd = configs.filter(function(c) {
1885
1895
  return toAdd.includes(c.collectionName);
1886
1896
  });
1887
- var disposer = socketServiceInstance.subscribeToCollections(wrapConfigsForWorker(configsToAdd));
1897
+ var disposer = socketServiceInstance.subscribeToCollections(configsToUse(configsToAdd));
1888
1898
  cleanupSubscriptionsRef.current.push(disposer);
1889
1899
  toAdd.forEach(function(n) {
1890
1900
  return activeCollectionsRef.current.add(n);
@@ -653,11 +653,25 @@ var SESSION_STORAGE_KEY = "sessionId";
653
653
  var SocketService = /*#__PURE__*/ function() {
654
654
  "use strict";
655
655
  function _SocketService() {
656
+ var _this = this;
656
657
  _class_call_check(this, _SocketService);
657
658
  this.socket = null;
658
659
  this.connectCallbacks = [];
659
660
  this.disconnectCallbacks = [];
660
661
  this.authToken = null;
662
+ this.isDisconnected = true;
663
+ this.handleDisconnect = function(source, reason) {
664
+ var _this_socket;
665
+ if (_this.isDisconnected) {
666
+ return;
667
+ }
668
+ _this.isDisconnected = true;
669
+ var transport = (_this_socket = _this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.io.engine.transport.name;
670
+ console.log("Socket disconnected (".concat(source, ") [transport=").concat(transport, "]:"), reason);
671
+ _this.disconnectCallbacks.forEach(function(cb) {
672
+ return cb();
673
+ });
674
+ };
661
675
  }
662
676
  _create_class(_SocketService, [
663
677
  {
@@ -682,32 +696,27 @@ var SocketService = /*#__PURE__*/ function() {
682
696
  ],
683
697
  reconnection: true,
684
698
  reconnectionAttempts: 30,
685
- reconnectionDelay: 2 * 1e3
699
+ reconnectionDelay: 2 * 1e3,
700
+ reconnectionDelayMax: 10 * 1e3,
701
+ timeout: 20 * 1e3
686
702
  });
687
703
  this.socket.on("connect", function() {
688
- var _this_socket, _this_socket1;
689
- 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, ")"));
704
+ var _this_socket, _this_socket1, _this_socket2;
705
+ var transport = (_this_socket = _this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.io.engine.transport.name;
706
+ console.log("\uD83D\uDFE2 Socket connected: ".concat((_this_socket1 = _this.socket) === null || _this_socket1 === void 0 ? void 0 : _this_socket1.id, " (recovered - ").concat((_this_socket2 = _this.socket) === null || _this_socket2 === void 0 ? void 0 : _this_socket2.recovered, ") (transport - ").concat(transport, ")"));
707
+ _this.isDisconnected = false;
690
708
  _this.connectCallbacks.forEach(function(cb) {
691
709
  return cb();
692
710
  });
693
711
  });
694
712
  this.socket.on("disconnect", function(reason) {
695
- console.log("Socket disconnected:", reason);
696
- _this.disconnectCallbacks.forEach(function(cb) {
697
- return cb();
698
- });
713
+ _this.handleDisconnect("disconnect", reason);
699
714
  });
700
715
  this.socket.io.on("close", function(reason) {
701
- console.log("Socket Manager close:", reason);
702
- _this.disconnectCallbacks.forEach(function(cb) {
703
- return cb();
704
- });
716
+ _this.handleDisconnect("manager_close", reason);
705
717
  });
706
718
  this.socket.io.engine.on("close", function(reason) {
707
- console.log("Socket Engine close:", reason);
708
- _this.disconnectCallbacks.forEach(function(cb) {
709
- return cb();
710
- });
719
+ _this.handleDisconnect("engine_close", reason);
711
720
  });
712
721
  this.socket.on("session", function(param) {
713
722
  var session_id = param.session_id;
@@ -718,6 +727,16 @@ var SocketService = /*#__PURE__*/ function() {
718
727
  this.socket.on("connect_error", function(error) {
719
728
  console.error("Socket connection error:", error);
720
729
  });
730
+ this.socket.io.on("reconnect_attempt", function(attempt) {
731
+ console.log("Socket reconnect attempt:", attempt);
732
+ });
733
+ this.socket.io.on("reconnect_error", function(error) {
734
+ console.error("Socket reconnect error:", error);
735
+ });
736
+ this.socket.io.on("reconnect", function(attempt) {
737
+ console.log("Socket reconnected after attempts:", attempt);
738
+ _this.isDisconnected = false;
739
+ });
721
740
  }
722
741
  }
723
742
  },
@@ -936,21 +955,6 @@ var SocketService = /*#__PURE__*/ function() {
936
955
  });
937
956
  });
938
957
  }
939
- },
940
- {
941
- key: "clearAllRedisData",
942
- value: function clearAllRedisData() {
943
- var s = this.getSocketInstance();
944
- return new Promise(function(resolve, reject) {
945
- s.emit("clear_all_redis_data", function(ack) {
946
- if (ack.success) {
947
- resolve(ack);
948
- } else {
949
- reject(new Error(ack.message || "Clear all Redis data operation failed"));
950
- }
951
- });
952
- });
953
- }
954
958
  }
955
959
  ], [
956
960
  {
@@ -1533,15 +1537,16 @@ var useDbSnapshots = function(configs, label, settings) {
1533
1537
  });
1534
1538
  };
1535
1539
  useDeepCompareEffect(function() {
1540
+ var useWorker = (settings === null || settings === void 0 ? void 0 : settings.useWorker) !== false;
1541
+ var configsToUse = useWorker ? wrapConfigsForWorker(configs) : configs;
1536
1542
  var start = performance.now();
1537
1543
  if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs) && configs.length > 0) {
1538
1544
  console.log("==> ".concat(label || "DB snapshots", " started from db... "));
1539
1545
  }
1540
- var wrappedConfigs = wrapConfigsForWorker(configs);
1541
1546
  lastDbCollectionsRef.current = configs.map(function(c) {
1542
1547
  return c.collectionName;
1543
1548
  });
1544
- var snapshotResults = wrappedConfigs.map(function(config) {
1549
+ var snapshotResults = configsToUse.map(function(config) {
1545
1550
  return snapshot(config, snapshotsFirstTime.current, settings);
1546
1551
  });
1547
1552
  unsubscribeFunctions.current = snapshotResults.map(function(result) {
@@ -1620,15 +1625,16 @@ var useDbDocumentSnapshots = function(configs, label, settings) {
1620
1625
  return perDocFirstTimeRef.current[key];
1621
1626
  };
1622
1627
  useDeepCompareEffect(function() {
1628
+ var useWorker = (settings === null || settings === void 0 ? void 0 : settings.useWorker) !== false;
1629
+ var configsToUse = useWorker ? wrapConfigsForWorker(configs) : configs;
1623
1630
  var start = performance.now();
1624
1631
  if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs) && configs.length > 0) {
1625
1632
  console.log("==> ".concat(label || "DB document snapshots", " started from db... "));
1626
1633
  }
1627
- var wrappedConfigs = wrapConfigsForWorker(configs);
1628
1634
  lastDbDocsRef.current = configs.map(function(c) {
1629
1635
  return "".concat(c.collectionName, "/").concat(c.documentId);
1630
1636
  });
1631
- var snapshotResults = wrappedConfigs.map(function(config) {
1637
+ var snapshotResults = configsToUse.map(function(config) {
1632
1638
  return snapshotDocument(config, getFirstTimeBucket(config));
1633
1639
  });
1634
1640
  unsubscribeFunctions.current = snapshotResults.map(function(result) {
@@ -1750,6 +1756,10 @@ var useSocketSnapshots = function(configs, label, settings) {
1750
1756
  if (!auth.currentUser) {
1751
1757
  return;
1752
1758
  }
1759
+ var useWorker = (settings === null || settings === void 0 ? void 0 : settings.useWorker) !== false;
1760
+ var configsToUse = function(cfgs) {
1761
+ return useWorker ? wrapConfigsForWorker(cfgs) : cfgs;
1762
+ };
1753
1763
  var subscribe = function() {
1754
1764
  var desiredNames = new Set(configs.map(function(c) {
1755
1765
  return c.collectionName;
@@ -1764,7 +1774,7 @@ var useSocketSnapshots = function(configs, label, settings) {
1764
1774
  cleanupSubscriptionsRef.current = [];
1765
1775
  }
1766
1776
  if (configs.length === 0) return;
1767
- var disposer2 = socketServiceInstance.subscribeToCollections(wrapConfigsForWorker(configs));
1777
+ var disposer2 = socketServiceInstance.subscribeToCollections(configsToUse(configs));
1768
1778
  cleanupSubscriptionsRef.current.push(disposer2);
1769
1779
  activeCollectionsRef.current = new Set(desiredNames);
1770
1780
  activeSubscriptionKeyRef.current = key;
@@ -1784,7 +1794,7 @@ var useSocketSnapshots = function(configs, label, settings) {
1784
1794
  var configsToAdd = configs.filter(function(c) {
1785
1795
  return toAdd.includes(c.collectionName);
1786
1796
  });
1787
- var disposer = socketServiceInstance.subscribeToCollections(wrapConfigsForWorker(configsToAdd));
1797
+ var disposer = socketServiceInstance.subscribeToCollections(configsToUse(configsToAdd));
1788
1798
  cleanupSubscriptionsRef.current.push(disposer);
1789
1799
  toAdd.forEach(function(n) {
1790
1800
  return activeCollectionsRef.current.add(n);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akeyless-client-commons",
3
- "version": "1.1.101",
3
+ "version": "1.1.103",
4
4
  "scripts": {
5
5
  "build": "tsup",
6
6
  "deploy": "npm run build && npm version patch --no-git-tag-version && npm publish",