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.
@@ -1190,8 +1190,315 @@ var biDomain = isLocal ? "http://localhost:9002/api/bi" : baseDomain + "/bi";
1190
1190
  var notificationsDomain = isLocal ? "http://localhost:9006/api/notifications" : baseDomain + "/notifications";
1191
1191
  var callCenterGeoDomain = isLocal ? "http://localhost:9007/api/call-center/geo" : baseDomain + "/call-center/geo";
1192
1192
  var callCenterEventsDomain = isLocal ? "http://localhost:9008/api/call-center/events" : baseDomain + "/call-center/events";
1193
+ var dataSocketDomain = isLocal ? "http://localhost:9009/api/data-socket" : baseDomain + "/data-socket";
1194
+ var dataSyncDomain = isLocal ? "http://localhost:9010/api/data-sync" : baseDomain + "/data-sync";
1193
1195
  // src/helpers/emails.ts
1194
1196
  var import_axios3 = __toESM(require("axios"));
1197
+ // src/helpers/socket.ts
1198
+ var import_socket = require("socket.io-client");
1199
+ var SESSION_STORAGE_KEY = "sessionId";
1200
+ var SocketService = /*#__PURE__*/ function() {
1201
+ "use strict";
1202
+ function _SocketService() {
1203
+ _class_call_check(this, _SocketService);
1204
+ this.socket = null;
1205
+ this.connectCallbacks = [];
1206
+ this.disconnectCallbacks = [];
1207
+ this.authToken = null;
1208
+ }
1209
+ _create_class(_SocketService, [
1210
+ {
1211
+ /// Initialize the socket connection
1212
+ key: "initSocket",
1213
+ value: function initSocket() {
1214
+ var _this = this;
1215
+ if (!this.socket) {
1216
+ var socketUrl = isLocal ? "http://localhost:9009" : mode === "qa" ? "https://nx-api.xyz" : "https://nx-api.info";
1217
+ this.socket = (0, import_socket.io)(socketUrl, {
1218
+ path: "/api/data-socket/connect",
1219
+ auth: function(cb) {
1220
+ var sessionId = localStorage.getItem(SESSION_STORAGE_KEY) || void 0;
1221
+ var token = _this.authToken;
1222
+ var authPayload = {};
1223
+ if (token) authPayload.token = token;
1224
+ if (sessionId) authPayload.sessionId = sessionId;
1225
+ cb(authPayload);
1226
+ },
1227
+ transports: [
1228
+ "websocket"
1229
+ ],
1230
+ reconnection: true,
1231
+ reconnectionAttempts: 30,
1232
+ reconnectionDelay: 2 * 1e3
1233
+ });
1234
+ this.socket.on("connect", function() {
1235
+ var _this_socket, _this_socket1;
1236
+ 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, ")"));
1237
+ _this.connectCallbacks.forEach(function(cb) {
1238
+ return cb();
1239
+ });
1240
+ });
1241
+ this.socket.on("disconnect", function(reason) {
1242
+ console.log("Socket disconnected:", reason);
1243
+ _this.disconnectCallbacks.forEach(function(cb) {
1244
+ return cb();
1245
+ });
1246
+ });
1247
+ this.socket.on("session", function(param) {
1248
+ var session_id = param.session_id;
1249
+ if (session_id) {
1250
+ localStorage.setItem(SESSION_STORAGE_KEY, session_id);
1251
+ }
1252
+ });
1253
+ this.socket.on("connect_error", function(error) {
1254
+ console.error("Socket connection error:", error);
1255
+ });
1256
+ }
1257
+ }
1258
+ },
1259
+ {
1260
+ /// get socket instance
1261
+ key: "getSocketInstance",
1262
+ value: function getSocketInstance() {
1263
+ if (!this.socket) {
1264
+ this.initSocket();
1265
+ }
1266
+ if (!this.socket) {
1267
+ throw new Error("Socket not initialized");
1268
+ }
1269
+ if (!this.socket.connected) {
1270
+ this.socket.connect();
1271
+ }
1272
+ return this.socket;
1273
+ }
1274
+ },
1275
+ {
1276
+ /// connection management methods
1277
+ key: "startSession",
1278
+ value: function startSession(token) {
1279
+ this.setAuthToken(token);
1280
+ this.initSocket();
1281
+ }
1282
+ },
1283
+ {
1284
+ key: "onConnect",
1285
+ value: function onConnect(callback) {
1286
+ var _this = this;
1287
+ var _this_socket;
1288
+ if (!this.connectCallbacks.includes(callback)) {
1289
+ this.connectCallbacks.push(callback);
1290
+ }
1291
+ if ((_this_socket = this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.connected) {
1292
+ callback();
1293
+ }
1294
+ return function() {
1295
+ return _this.offConnect(callback);
1296
+ };
1297
+ }
1298
+ },
1299
+ {
1300
+ key: "offConnect",
1301
+ value: function offConnect(callback) {
1302
+ this.connectCallbacks = this.connectCallbacks.filter(function(cb) {
1303
+ return cb !== callback;
1304
+ });
1305
+ }
1306
+ },
1307
+ {
1308
+ key: "onDisconnect",
1309
+ value: function onDisconnect(callback) {
1310
+ var _this = this;
1311
+ if (!this.disconnectCallbacks.includes(callback)) {
1312
+ this.disconnectCallbacks.push(callback);
1313
+ }
1314
+ if (this.socket && !this.socket.connected) {
1315
+ callback();
1316
+ }
1317
+ return function() {
1318
+ return _this.offDisconnect(callback);
1319
+ };
1320
+ }
1321
+ },
1322
+ {
1323
+ key: "offDisconnect",
1324
+ value: function offDisconnect(callback) {
1325
+ this.disconnectCallbacks = this.disconnectCallbacks.filter(function(cb) {
1326
+ return cb !== callback;
1327
+ });
1328
+ }
1329
+ },
1330
+ {
1331
+ key: "isConnected",
1332
+ value: function isConnected() {
1333
+ var _this_socket;
1334
+ return ((_this_socket = this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.connected) || false;
1335
+ }
1336
+ },
1337
+ {
1338
+ key: "setAuthToken",
1339
+ value: function setAuthToken(token) {
1340
+ this.authToken = token;
1341
+ if (this.socket) {
1342
+ this.socket.connect();
1343
+ }
1344
+ }
1345
+ },
1346
+ {
1347
+ key: "disconnectSocket",
1348
+ value: function disconnectSocket() {
1349
+ if (this.socket) {
1350
+ this.socket.io.engine.close();
1351
+ }
1352
+ }
1353
+ },
1354
+ {
1355
+ /// subscribe to collections
1356
+ key: "subscribeToCollections",
1357
+ value: function subscribeToCollections(config) {
1358
+ var _this = this;
1359
+ if (config.length === 0) {
1360
+ return function() {};
1361
+ }
1362
+ var s = this.getSocketInstance();
1363
+ var collectionsNames = config.map(function(c) {
1364
+ return c.collectionName;
1365
+ });
1366
+ var eventHandlers = [];
1367
+ config.forEach(function(configuration) {
1368
+ 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;
1369
+ var attach = function(eventName, handler) {
1370
+ _this.socket.off(eventName, handler);
1371
+ _this.socket.on(eventName, handler);
1372
+ eventHandlers.push({
1373
+ eventName: eventName,
1374
+ handler: handler
1375
+ });
1376
+ };
1377
+ attach("initial:".concat(collectionName), onFirstTime);
1378
+ attach("add:".concat(collectionName), onAdd);
1379
+ attach("update:".concat(collectionName), onModify);
1380
+ attach("delete:".concat(collectionName), onRemove);
1381
+ extraParsers === null || extraParsers === void 0 ? void 0 : extraParsers.forEach(function(parsers) {
1382
+ var extraOnAdd = parsers.onAdd, extraOnFirstTime = parsers.onFirstTime, extraOnModify = parsers.onModify, extraOnRemove = parsers.onRemove;
1383
+ attach("initial:".concat(collectionName), extraOnFirstTime);
1384
+ attach("add:".concat(collectionName), extraOnAdd);
1385
+ attach("update:".concat(collectionName), extraOnModify);
1386
+ attach("delete:".concat(collectionName), extraOnRemove);
1387
+ });
1388
+ });
1389
+ s.emit("subscribe_collections", collectionsNames, function(callback) {
1390
+ if (callback.success) {
1391
+ console.log("Successfully subscribed to: ".concat(collectionsNames.join(", ")));
1392
+ } else {
1393
+ console.error("Failed to subscribe to ".concat(config.join(", "), ": ").concat(callback.message));
1394
+ }
1395
+ });
1396
+ return function() {
1397
+ console.log("Cleaning up subscriptions for: ".concat(collectionsNames.join(", ")));
1398
+ s.emit("unsubscribe_collections", collectionsNames);
1399
+ eventHandlers.forEach(function(eh) {
1400
+ s.off(eh.eventName, eh.handler);
1401
+ });
1402
+ };
1403
+ }
1404
+ },
1405
+ {
1406
+ /// set data
1407
+ key: "setData",
1408
+ value: function setData(payload) {
1409
+ var s = this.getSocketInstance();
1410
+ return new Promise(function(resolve, reject) {
1411
+ s.emit("set_data", payload, function(callback) {
1412
+ if (callback.success) {
1413
+ console.log("Data saved successfully:", payload);
1414
+ console.log("ack", callback);
1415
+ resolve(callback);
1416
+ } else {
1417
+ reject(new Error(callback.message || "Save operation failed"));
1418
+ }
1419
+ });
1420
+ });
1421
+ }
1422
+ },
1423
+ {
1424
+ /// get data
1425
+ key: "getCollectionData",
1426
+ value: function getCollectionData(payload) {
1427
+ var s = this.getSocketInstance();
1428
+ s.emit("get_data", {
1429
+ collection_name: payload.collection_name
1430
+ }, function(socketCallback) {
1431
+ if (socketCallback.success && socketCallback.data) {
1432
+ payload.callback(socketCallback.data);
1433
+ } else {
1434
+ payload.callback(payload.defaultValue);
1435
+ }
1436
+ });
1437
+ }
1438
+ },
1439
+ {
1440
+ key: "getDocumentData",
1441
+ value: function getDocumentData(payload) {
1442
+ var s = this.getSocketInstance();
1443
+ s.emit("get_data", {
1444
+ collection_name: payload.collection_name,
1445
+ key: payload.key
1446
+ }, function(socketCallback) {
1447
+ if (socketCallback.success && socketCallback.data) {
1448
+ payload.callback(socketCallback.data);
1449
+ } else {
1450
+ payload.callback(payload.defaultValue);
1451
+ }
1452
+ });
1453
+ }
1454
+ },
1455
+ {
1456
+ /// delete data
1457
+ key: "deleteData",
1458
+ value: function deleteData(payload) {
1459
+ var s = this.getSocketInstance();
1460
+ return new Promise(function(resolve, reject) {
1461
+ s.emit("delete_data", payload, function(callback) {
1462
+ if (callback.success) {
1463
+ console.log("Data deleted successfully:", payload);
1464
+ console.log("delete ack", callback);
1465
+ resolve(callback);
1466
+ } else {
1467
+ reject(new Error(callback.message || "Delete operation failed"));
1468
+ }
1469
+ });
1470
+ });
1471
+ }
1472
+ },
1473
+ {
1474
+ key: "clearAllRedisData",
1475
+ value: function clearAllRedisData() {
1476
+ var s = this.getSocketInstance();
1477
+ return new Promise(function(resolve, reject) {
1478
+ s.emit("clear_all_redis_data", function(ack) {
1479
+ if (ack.success) {
1480
+ resolve(ack);
1481
+ } else {
1482
+ reject(new Error(ack.message || "Clear all Redis data operation failed"));
1483
+ }
1484
+ });
1485
+ });
1486
+ }
1487
+ }
1488
+ ], [
1489
+ {
1490
+ key: "getInstance",
1491
+ value: function getInstance() {
1492
+ if (!_SocketService.instance) {
1493
+ _SocketService.instance = new _SocketService();
1494
+ }
1495
+ return _SocketService.instance;
1496
+ }
1497
+ }
1498
+ ]);
1499
+ return _SocketService;
1500
+ }();
1501
+ var socketServiceInstance = SocketService.getInstance();
1195
1502
  // src/components/utils/Checkboxes.tsx
1196
1503
  var import_react2 = require("react");
1197
1504
  var import_jsx_runtime = require("react/jsx-runtime");
@@ -3744,14 +4051,14 @@ function rectsAreEqual(a, b) {
3744
4051
  return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
3745
4052
  }
3746
4053
  function observeMove(element, onMove) {
3747
- var io = null;
4054
+ var io2 = null;
3748
4055
  var timeoutId;
3749
4056
  var root = getDocumentElement(element);
3750
4057
  function cleanup() {
3751
4058
  var _io;
3752
4059
  clearTimeout(timeoutId);
3753
- (_io = io) == null || _io.disconnect();
3754
- io = null;
4060
+ (_io = io2) == null || _io.disconnect();
4061
+ io2 = null;
3755
4062
  }
3756
4063
  function refresh(skip, threshold) {
3757
4064
  if (skip === void 0) {
@@ -3799,14 +4106,14 @@ function observeMove(element, onMove) {
3799
4106
  isFirstUpdate = false;
3800
4107
  }
3801
4108
  try {
3802
- io = new IntersectionObserver(handleObserve, _object_spread_props(_object_spread({}, options), {
4109
+ io2 = new IntersectionObserver(handleObserve, _object_spread_props(_object_spread({}, options), {
3803
4110
  // Handle <iframe>s
3804
4111
  root: root.ownerDocument
3805
4112
  }));
3806
4113
  } catch (e) {
3807
- io = new IntersectionObserver(handleObserve, options);
4114
+ io2 = new IntersectionObserver(handleObserve, options);
3808
4115
  }
3809
- io.observe(element);
4116
+ io2.observe(element);
3810
4117
  }
3811
4118
  refresh(true);
3812
4119
  return cleanup;