akeyless-client-commons 1.1.22 → 1.1.23

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.
@@ -39,6 +39,25 @@ function _async_to_generator(fn) {
39
39
  });
40
40
  };
41
41
  }
42
+ function _class_call_check(instance, Constructor) {
43
+ if (!(instance instanceof Constructor)) {
44
+ throw new TypeError("Cannot call a class as a function");
45
+ }
46
+ }
47
+ function _defineProperties(target, props) {
48
+ for(var i = 0; i < props.length; i++){
49
+ var descriptor = props[i];
50
+ descriptor.enumerable = descriptor.enumerable || false;
51
+ descriptor.configurable = true;
52
+ if ("value" in descriptor) descriptor.writable = true;
53
+ Object.defineProperty(target, descriptor.key, descriptor);
54
+ }
55
+ }
56
+ function _create_class(Constructor, protoProps, staticProps) {
57
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
58
+ if (staticProps) _defineProperties(Constructor, staticProps);
59
+ return Constructor;
60
+ }
42
61
  function _define_property(obj, key, value) {
43
62
  if (key in obj) {
44
63
  Object.defineProperty(obj, key, {
@@ -374,6 +393,12 @@ __export(index_exports, {
374
393
  createSelectors: function() {
375
394
  return createSelectors;
376
395
  },
396
+ dataSocketDomain: function() {
397
+ return dataSocketDomain;
398
+ },
399
+ dataSyncDomain: function() {
400
+ return dataSyncDomain;
401
+ },
377
402
  db: function() {
378
403
  return db;
379
404
  },
@@ -563,6 +588,9 @@ __export(index_exports, {
563
588
  snapshotDocument: function() {
564
589
  return snapshotDocument;
565
590
  },
591
+ socketServiceInstance: function() {
592
+ return socketServiceInstance;
593
+ },
566
594
  sort_by_timestamp: function() {
567
595
  return sort_by_timestamp;
568
596
  },
@@ -2283,6 +2311,8 @@ var biDomain = isLocal ? "http://localhost:9002/api/bi" : baseDomain + "/bi";
2283
2311
  var notificationsDomain = isLocal ? "http://localhost:9006/api/notifications" : baseDomain + "/notifications";
2284
2312
  var callCenterGeoDomain = isLocal ? "http://localhost:9007/api/call-center/geo" : baseDomain + "/call-center/geo";
2285
2313
  var callCenterEventsDomain = isLocal ? "http://localhost:9008/api/call-center/events" : baseDomain + "/call-center/events";
2314
+ var dataSocketDomain = isLocal ? "http://localhost:9009/api/data-socket" : baseDomain + "/data-socket";
2315
+ var dataSyncDomain = isLocal ? "http://localhost:9010/api/data-sync" : baseDomain + "/data-sync";
2286
2316
  var akeylessOnlineDomain = mode === "qa" ? "https://akeyless-online.xyz" : "https://akeyless-online.info";
2287
2317
  var nxApiCall = /*#__PURE__*/ function() {
2288
2318
  var _ref = _async_to_generator(function(serverName, method, url, data) {
@@ -2313,6 +2343,12 @@ var nxApiCall = /*#__PURE__*/ function() {
2313
2343
  case "call-center-geo":
2314
2344
  urlResult = "".concat(callCenterGeoDomain, "/").concat(url);
2315
2345
  break;
2346
+ case "data-socket":
2347
+ urlResult = "".concat(dataSocketDomain, "/").concat(url);
2348
+ break;
2349
+ case "data-sync":
2350
+ urlResult = "".concat(dataSyncDomain, "/").concat(url);
2351
+ break;
2316
2352
  default:
2317
2353
  break;
2318
2354
  }
@@ -2466,6 +2502,311 @@ var createAttachmentFromUrl = /*#__PURE__*/ function() {
2466
2502
  return _ref.apply(this, arguments);
2467
2503
  };
2468
2504
  }();
2505
+ // src/helpers/socket.ts
2506
+ var import_socket = require("socket.io-client");
2507
+ var SESSION_STORAGE_KEY = "sessionId";
2508
+ var SocketService = /*#__PURE__*/ function() {
2509
+ "use strict";
2510
+ function _SocketService() {
2511
+ _class_call_check(this, _SocketService);
2512
+ this.socket = null;
2513
+ this.connectCallbacks = [];
2514
+ this.disconnectCallbacks = [];
2515
+ this.authToken = null;
2516
+ }
2517
+ _create_class(_SocketService, [
2518
+ {
2519
+ /// Initialize the socket connection
2520
+ key: "initSocket",
2521
+ value: function initSocket() {
2522
+ var _this = this;
2523
+ if (!this.socket) {
2524
+ var socketUrl = isLocal ? "http://localhost:9009" : mode === "qa" ? "https://nx-api.xyz" : "https://nx-api.info";
2525
+ this.socket = (0, import_socket.io)(socketUrl, {
2526
+ path: "/api/data-socket/connect",
2527
+ auth: function(cb) {
2528
+ var sessionId = localStorage.getItem(SESSION_STORAGE_KEY) || void 0;
2529
+ var token = _this.authToken;
2530
+ var authPayload = {};
2531
+ if (token) authPayload.token = token;
2532
+ if (sessionId) authPayload.sessionId = sessionId;
2533
+ cb(authPayload);
2534
+ },
2535
+ transports: [
2536
+ "websocket"
2537
+ ],
2538
+ reconnection: true,
2539
+ reconnectionAttempts: 30,
2540
+ reconnectionDelay: 2 * 1e3
2541
+ });
2542
+ this.socket.on("connect", function() {
2543
+ var _this_socket, _this_socket1;
2544
+ 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, ")"));
2545
+ _this.connectCallbacks.forEach(function(cb) {
2546
+ return cb();
2547
+ });
2548
+ });
2549
+ this.socket.on("disconnect", function(reason) {
2550
+ console.log("Socket disconnected:", reason);
2551
+ _this.disconnectCallbacks.forEach(function(cb) {
2552
+ return cb();
2553
+ });
2554
+ });
2555
+ this.socket.on("session", function(param) {
2556
+ var session_id = param.session_id;
2557
+ if (session_id) {
2558
+ localStorage.setItem(SESSION_STORAGE_KEY, session_id);
2559
+ }
2560
+ });
2561
+ this.socket.on("connect_error", function(error) {
2562
+ console.error("Socket connection error:", error);
2563
+ });
2564
+ }
2565
+ }
2566
+ },
2567
+ {
2568
+ /// get socket instance
2569
+ key: "getSocketInstance",
2570
+ value: function getSocketInstance() {
2571
+ if (!this.socket) {
2572
+ this.initSocket();
2573
+ }
2574
+ if (!this.socket) {
2575
+ throw new Error("Socket not initialized");
2576
+ }
2577
+ if (!this.socket.connected) {
2578
+ this.socket.connect();
2579
+ }
2580
+ return this.socket;
2581
+ }
2582
+ },
2583
+ {
2584
+ /// connection management methods
2585
+ key: "startSession",
2586
+ value: function startSession(token) {
2587
+ this.setAuthToken(token);
2588
+ this.initSocket();
2589
+ }
2590
+ },
2591
+ {
2592
+ key: "onConnect",
2593
+ value: function onConnect(callback) {
2594
+ var _this = this;
2595
+ var _this_socket;
2596
+ if (!this.connectCallbacks.includes(callback)) {
2597
+ this.connectCallbacks.push(callback);
2598
+ }
2599
+ if ((_this_socket = this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.connected) {
2600
+ callback();
2601
+ }
2602
+ return function() {
2603
+ return _this.offConnect(callback);
2604
+ };
2605
+ }
2606
+ },
2607
+ {
2608
+ key: "offConnect",
2609
+ value: function offConnect(callback) {
2610
+ this.connectCallbacks = this.connectCallbacks.filter(function(cb) {
2611
+ return cb !== callback;
2612
+ });
2613
+ }
2614
+ },
2615
+ {
2616
+ key: "onDisconnect",
2617
+ value: function onDisconnect(callback) {
2618
+ var _this = this;
2619
+ if (!this.disconnectCallbacks.includes(callback)) {
2620
+ this.disconnectCallbacks.push(callback);
2621
+ }
2622
+ if (this.socket && !this.socket.connected) {
2623
+ callback();
2624
+ }
2625
+ return function() {
2626
+ return _this.offDisconnect(callback);
2627
+ };
2628
+ }
2629
+ },
2630
+ {
2631
+ key: "offDisconnect",
2632
+ value: function offDisconnect(callback) {
2633
+ this.disconnectCallbacks = this.disconnectCallbacks.filter(function(cb) {
2634
+ return cb !== callback;
2635
+ });
2636
+ }
2637
+ },
2638
+ {
2639
+ key: "isConnected",
2640
+ value: function isConnected() {
2641
+ var _this_socket;
2642
+ return ((_this_socket = this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.connected) || false;
2643
+ }
2644
+ },
2645
+ {
2646
+ key: "setAuthToken",
2647
+ value: function setAuthToken(token) {
2648
+ this.authToken = token;
2649
+ if (this.socket) {
2650
+ this.socket.connect();
2651
+ }
2652
+ }
2653
+ },
2654
+ {
2655
+ key: "disconnectSocket",
2656
+ value: function disconnectSocket() {
2657
+ if (this.socket) {
2658
+ this.socket.io.engine.close();
2659
+ }
2660
+ }
2661
+ },
2662
+ {
2663
+ /// subscribe to collections
2664
+ key: "subscribeToCollections",
2665
+ value: function subscribeToCollections(config) {
2666
+ var _this = this;
2667
+ if (config.length === 0) {
2668
+ return function() {};
2669
+ }
2670
+ var s = this.getSocketInstance();
2671
+ var collectionsNames = config.map(function(c) {
2672
+ return c.collectionName;
2673
+ });
2674
+ var eventHandlers = [];
2675
+ config.forEach(function(configuration) {
2676
+ 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;
2677
+ var attach = function(eventName, handler) {
2678
+ _this.socket.off(eventName, handler);
2679
+ _this.socket.on(eventName, handler);
2680
+ eventHandlers.push({
2681
+ eventName: eventName,
2682
+ handler: handler
2683
+ });
2684
+ };
2685
+ attach("initial:".concat(collectionName), onFirstTime);
2686
+ attach("add:".concat(collectionName), onAdd);
2687
+ attach("update:".concat(collectionName), onModify);
2688
+ attach("delete:".concat(collectionName), onRemove);
2689
+ extraParsers === null || extraParsers === void 0 ? void 0 : extraParsers.forEach(function(parsers) {
2690
+ var extraOnAdd = parsers.onAdd, extraOnFirstTime = parsers.onFirstTime, extraOnModify = parsers.onModify, extraOnRemove = parsers.onRemove;
2691
+ attach("initial:".concat(collectionName), extraOnFirstTime);
2692
+ attach("add:".concat(collectionName), extraOnAdd);
2693
+ attach("update:".concat(collectionName), extraOnModify);
2694
+ attach("delete:".concat(collectionName), extraOnRemove);
2695
+ });
2696
+ });
2697
+ s.emit("subscribe_collections", collectionsNames, function(callback) {
2698
+ if (callback.success) {
2699
+ console.log("Successfully subscribed to: ".concat(collectionsNames.join(", ")));
2700
+ } else {
2701
+ console.error("Failed to subscribe to ".concat(config.join(", "), ": ").concat(callback.message));
2702
+ }
2703
+ });
2704
+ return function() {
2705
+ console.log("Cleaning up subscriptions for: ".concat(collectionsNames.join(", ")));
2706
+ s.emit("unsubscribe_collections", collectionsNames);
2707
+ eventHandlers.forEach(function(eh) {
2708
+ s.off(eh.eventName, eh.handler);
2709
+ });
2710
+ };
2711
+ }
2712
+ },
2713
+ {
2714
+ /// set data
2715
+ key: "setData",
2716
+ value: function setData(payload) {
2717
+ var s = this.getSocketInstance();
2718
+ return new Promise(function(resolve, reject) {
2719
+ s.emit("set_data", payload, function(callback) {
2720
+ if (callback.success) {
2721
+ console.log("Data saved successfully:", payload);
2722
+ console.log("ack", callback);
2723
+ resolve(callback);
2724
+ } else {
2725
+ reject(new Error(callback.message || "Save operation failed"));
2726
+ }
2727
+ });
2728
+ });
2729
+ }
2730
+ },
2731
+ {
2732
+ /// get data
2733
+ key: "getCollectionData",
2734
+ value: function getCollectionData(payload) {
2735
+ var s = this.getSocketInstance();
2736
+ s.emit("get_data", {
2737
+ collection_name: payload.collection_name
2738
+ }, function(socketCallback) {
2739
+ if (socketCallback.success && socketCallback.data) {
2740
+ payload.callback(socketCallback.data);
2741
+ } else {
2742
+ payload.callback(payload.defaultValue);
2743
+ }
2744
+ });
2745
+ }
2746
+ },
2747
+ {
2748
+ key: "getDocumentData",
2749
+ value: function getDocumentData(payload) {
2750
+ var s = this.getSocketInstance();
2751
+ s.emit("get_data", {
2752
+ collection_name: payload.collection_name,
2753
+ key: payload.key
2754
+ }, function(socketCallback) {
2755
+ if (socketCallback.success && socketCallback.data) {
2756
+ payload.callback(socketCallback.data);
2757
+ } else {
2758
+ payload.callback(payload.defaultValue);
2759
+ }
2760
+ });
2761
+ }
2762
+ },
2763
+ {
2764
+ /// delete data
2765
+ key: "deleteData",
2766
+ value: function deleteData(payload) {
2767
+ var s = this.getSocketInstance();
2768
+ return new Promise(function(resolve, reject) {
2769
+ s.emit("delete_data", payload, function(callback) {
2770
+ if (callback.success) {
2771
+ console.log("Data deleted successfully:", payload);
2772
+ console.log("delete ack", callback);
2773
+ resolve(callback);
2774
+ } else {
2775
+ reject(new Error(callback.message || "Delete operation failed"));
2776
+ }
2777
+ });
2778
+ });
2779
+ }
2780
+ },
2781
+ {
2782
+ key: "clearAllRedisData",
2783
+ value: function clearAllRedisData() {
2784
+ var s = this.getSocketInstance();
2785
+ return new Promise(function(resolve, reject) {
2786
+ s.emit("clear_all_redis_data", function(ack) {
2787
+ if (ack.success) {
2788
+ resolve(ack);
2789
+ } else {
2790
+ reject(new Error(ack.message || "Clear all Redis data operation failed"));
2791
+ }
2792
+ });
2793
+ });
2794
+ }
2795
+ }
2796
+ ], [
2797
+ {
2798
+ key: "getInstance",
2799
+ value: function getInstance() {
2800
+ if (!_SocketService.instance) {
2801
+ _SocketService.instance = new _SocketService();
2802
+ }
2803
+ return _SocketService.instance;
2804
+ }
2805
+ }
2806
+ ]);
2807
+ return _SocketService;
2808
+ }();
2809
+ var socketServiceInstance = SocketService.getInstance();
2469
2810
  // Annotate the CommonJS export names for ESM import in node:
2470
2811
  0 && (module.exports = {
2471
2812
  addAuditRecord: addAuditRecord,
@@ -2491,6 +2832,8 @@ var createAttachmentFromUrl = /*#__PURE__*/ function() {
2491
2832
  createAttachmentFromBlob: createAttachmentFromBlob,
2492
2833
  createAttachmentFromUrl: createAttachmentFromUrl,
2493
2834
  createSelectors: createSelectors,
2835
+ dataSocketDomain: dataSocketDomain,
2836
+ dataSyncDomain: dataSyncDomain,
2494
2837
  db: db,
2495
2838
  delete_document: delete_document,
2496
2839
  devicesDomain: devicesDomain,
@@ -2554,6 +2897,7 @@ var createAttachmentFromUrl = /*#__PURE__*/ function() {
2554
2897
  simpleExtractData: simpleExtractData,
2555
2898
  snapshot: snapshot,
2556
2899
  snapshotDocument: snapshotDocument,
2900
+ socketServiceInstance: socketServiceInstance,
2557
2901
  sort_by_timestamp: sort_by_timestamp,
2558
2902
  storage: storage,
2559
2903
  textNumbersRegex: textNumbersRegex,