akeyless-client-commons 1.1.22 → 1.1.24

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