akeyless-client-commons 1.1.17-test.1 → 1.1.17-test.10

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.
@@ -2299,6 +2299,7 @@ var nxApiCall = /*#__PURE__*/ function() {
2299
2299
  }();
2300
2300
  // src/helpers/socket.ts
2301
2301
  var import_socket = require("socket.io-client");
2302
+ var SESSION_STORAGE_KEY = "sessionId";
2302
2303
  var SocketService = /*#__PURE__*/ function() {
2303
2304
  "use strict";
2304
2305
  function _SocketService() {
@@ -2306,6 +2307,7 @@ var SocketService = /*#__PURE__*/ function() {
2306
2307
  this.socket = null;
2307
2308
  this.connectCallbacks = [];
2308
2309
  this.disconnectCallbacks = [];
2310
+ this.authToken = null;
2309
2311
  }
2310
2312
  _create_class(_SocketService, [
2311
2313
  {
@@ -2315,16 +2317,23 @@ var SocketService = /*#__PURE__*/ function() {
2315
2317
  var _this = this;
2316
2318
  if (!this.socket) {
2317
2319
  var socketUrl = isLocal ? "http://localhost:9009" : mode === "qa" ? "https://nx-api.xyz" : "https://nx-api.info";
2318
- console.log("socketUrl", socketUrl);
2319
2320
  this.socket = (0, import_socket.io)(socketUrl, {
2320
2321
  path: "/api/data-socket/connect",
2321
- transports: [
2322
- "websocket"
2323
- ]
2322
+ auth: function(cb) {
2323
+ var sessionId = localStorage.getItem(SESSION_STORAGE_KEY) || void 0;
2324
+ var token = _this.authToken;
2325
+ var authPayload = {};
2326
+ if (token) authPayload.token = token;
2327
+ if (sessionId) authPayload.sessionId = sessionId;
2328
+ cb(authPayload);
2329
+ },
2330
+ reconnection: true,
2331
+ reconnectionAttempts: 30,
2332
+ reconnectionDelay: 2 * 1e3
2324
2333
  });
2325
2334
  this.socket.on("connect", function() {
2326
- var _this_socket;
2327
- console.log("Socket connected:", (_this_socket = _this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.id);
2335
+ var _this_socket, _this_socket1;
2336
+ 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, ")"));
2328
2337
  _this.connectCallbacks.forEach(function(cb) {
2329
2338
  return cb();
2330
2339
  });
@@ -2335,6 +2344,12 @@ var SocketService = /*#__PURE__*/ function() {
2335
2344
  return cb();
2336
2345
  });
2337
2346
  });
2347
+ this.socket.on("session", function(param) {
2348
+ var sessionId = param.sessionId;
2349
+ if (sessionId) {
2350
+ localStorage.setItem(SESSION_STORAGE_KEY, sessionId);
2351
+ }
2352
+ });
2338
2353
  this.socket.on("connect_error", function(error) {
2339
2354
  console.error("Socket connection error:", error);
2340
2355
  });
@@ -2357,10 +2372,93 @@ var SocketService = /*#__PURE__*/ function() {
2357
2372
  return this.socket;
2358
2373
  }
2359
2374
  },
2375
+ {
2376
+ /// connection management methods
2377
+ key: "startSession",
2378
+ value: function startSession(token) {
2379
+ this.setAuthToken(token);
2380
+ this.initSocket();
2381
+ }
2382
+ },
2383
+ {
2384
+ key: "onConnect",
2385
+ value: function onConnect(callback) {
2386
+ var _this = this;
2387
+ var _this_socket;
2388
+ if (!this.connectCallbacks.includes(callback)) {
2389
+ this.connectCallbacks.push(callback);
2390
+ }
2391
+ if ((_this_socket = this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.connected) {
2392
+ callback();
2393
+ }
2394
+ return function() {
2395
+ return _this.offConnect(callback);
2396
+ };
2397
+ }
2398
+ },
2399
+ {
2400
+ key: "offConnect",
2401
+ value: function offConnect(callback) {
2402
+ this.connectCallbacks = this.connectCallbacks.filter(function(cb) {
2403
+ return cb !== callback;
2404
+ });
2405
+ }
2406
+ },
2407
+ {
2408
+ key: "onDisconnect",
2409
+ value: function onDisconnect(callback) {
2410
+ var _this = this;
2411
+ if (!this.disconnectCallbacks.includes(callback)) {
2412
+ this.disconnectCallbacks.push(callback);
2413
+ }
2414
+ if (this.socket && !this.socket.connected) {
2415
+ callback();
2416
+ }
2417
+ return function() {
2418
+ return _this.offDisconnect(callback);
2419
+ };
2420
+ }
2421
+ },
2422
+ {
2423
+ key: "offDisconnect",
2424
+ value: function offDisconnect(callback) {
2425
+ this.disconnectCallbacks = this.disconnectCallbacks.filter(function(cb) {
2426
+ return cb !== callback;
2427
+ });
2428
+ }
2429
+ },
2430
+ {
2431
+ key: "isConnected",
2432
+ value: function isConnected() {
2433
+ var _this_socket;
2434
+ return ((_this_socket = this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.connected) || false;
2435
+ }
2436
+ },
2437
+ {
2438
+ key: "setAuthToken",
2439
+ value: function setAuthToken(token) {
2440
+ this.authToken = token;
2441
+ if (this.socket) {
2442
+ this.socket.connect();
2443
+ }
2444
+ }
2445
+ },
2446
+ {
2447
+ key: "disconnectSocket",
2448
+ value: function disconnectSocket() {
2449
+ if (this.socket) {
2450
+ this.socket.io.engine.close();
2451
+ }
2452
+ }
2453
+ },
2360
2454
  {
2361
2455
  /// subscribe to collections
2362
2456
  key: "subscribeToCollections",
2363
2457
  value: function subscribeToCollections(config) {
2458
+ var _this = this;
2459
+ if (config.length === 0) {
2460
+ return function() {};
2461
+ }
2364
2462
  var s = this.getSocketInstance();
2365
2463
  var collectionsNames = config.map(function(c) {
2366
2464
  return c.collectionName;
@@ -2368,48 +2466,24 @@ var SocketService = /*#__PURE__*/ function() {
2368
2466
  var eventHandlers = [];
2369
2467
  config.forEach(function(configuration) {
2370
2468
  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;
2371
- s.on("initial:".concat(collectionName), onFirstTime);
2372
- eventHandlers.push({
2373
- eventName: "initial:".concat(collectionName),
2374
- handler: onFirstTime
2375
- });
2376
- s.on("add:".concat(collectionName), onAdd);
2377
- eventHandlers.push({
2378
- eventName: "add:".concat(collectionName),
2379
- handler: onAdd
2380
- });
2381
- s.on("update:".concat(collectionName), onModify);
2382
- eventHandlers.push({
2383
- eventName: "update:".concat(collectionName),
2384
- handler: onModify
2385
- });
2386
- s.on("delete:".concat(collectionName), onRemove);
2387
- eventHandlers.push({
2388
- eventName: "delete:".concat(collectionName),
2389
- handler: onRemove
2390
- });
2391
- extraParsers === null || extraParsers === void 0 ? void 0 : extraParsers.forEach(function(parsers) {
2392
- var extraOnAdd = parsers.onAdd, extraOnFirstTime = parsers.onFirstTime, extraOnModify = parsers.onModify, extraOnRemove = parsers.onRemove;
2393
- s.on("initial:".concat(collectionName), extraOnFirstTime);
2394
- eventHandlers.push({
2395
- eventName: "initial:".concat(collectionName),
2396
- handler: extraOnFirstTime
2397
- });
2398
- s.on("add:".concat(collectionName), extraOnAdd);
2399
- eventHandlers.push({
2400
- eventName: "add:".concat(collectionName),
2401
- handler: extraOnAdd
2402
- });
2403
- s.on("update:".concat(collectionName), extraOnModify);
2469
+ var attach = function(eventName, handler) {
2470
+ _this.socket.off(eventName, handler);
2471
+ _this.socket.on(eventName, handler);
2404
2472
  eventHandlers.push({
2405
- eventName: "update:".concat(collectionName),
2406
- handler: extraOnModify
2407
- });
2408
- s.on("delete:".concat(collectionName), extraOnRemove);
2409
- eventHandlers.push({
2410
- eventName: "delete:".concat(collectionName),
2411
- handler: extraOnRemove
2473
+ eventName: eventName,
2474
+ handler: handler
2412
2475
  });
2476
+ };
2477
+ attach("initial:".concat(collectionName), onFirstTime);
2478
+ attach("add:".concat(collectionName), onAdd);
2479
+ attach("update:".concat(collectionName), onModify);
2480
+ attach("delete:".concat(collectionName), onRemove);
2481
+ extraParsers === null || extraParsers === void 0 ? void 0 : extraParsers.forEach(function(parsers) {
2482
+ var extraOnAdd = parsers.onAdd, extraOnFirstTime = parsers.onFirstTime, extraOnModify = parsers.onModify, extraOnRemove = parsers.onRemove;
2483
+ attach("initial:".concat(collectionName), extraOnFirstTime);
2484
+ attach("add:".concat(collectionName), extraOnAdd);
2485
+ attach("update:".concat(collectionName), extraOnModify);
2486
+ attach("delete:".concat(collectionName), extraOnRemove);
2413
2487
  });
2414
2488
  });
2415
2489
  s.emit("subscribe_collections", collectionsNames, function(callback) {
@@ -2510,49 +2584,6 @@ var SocketService = /*#__PURE__*/ function() {
2510
2584
  });
2511
2585
  });
2512
2586
  }
2513
- },
2514
- {
2515
- /// connection management methods
2516
- key: "onConnect",
2517
- value: function onConnect(callback) {
2518
- var _this_socket;
2519
- this.connectCallbacks.push(callback);
2520
- if ((_this_socket = this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.connected) {
2521
- callback();
2522
- }
2523
- }
2524
- },
2525
- {
2526
- key: "offConnect",
2527
- value: function offConnect(callback) {
2528
- this.connectCallbacks = this.connectCallbacks.filter(function(cb) {
2529
- return cb !== callback;
2530
- });
2531
- }
2532
- },
2533
- {
2534
- key: "onDisconnect",
2535
- value: function onDisconnect(callback) {
2536
- this.disconnectCallbacks.push(callback);
2537
- if (this.socket && !this.socket.connected) {
2538
- callback();
2539
- }
2540
- }
2541
- },
2542
- {
2543
- key: "offDisconnect",
2544
- value: function offDisconnect(callback) {
2545
- this.disconnectCallbacks = this.disconnectCallbacks.filter(function(cb) {
2546
- return cb !== callback;
2547
- });
2548
- }
2549
- },
2550
- {
2551
- key: "isConnected",
2552
- value: function isConnected() {
2553
- var _this_socket;
2554
- return ((_this_socket = this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.connected) || false;
2555
- }
2556
2587
  }
2557
2588
  ], [
2558
2589
  {
@@ -1935,6 +1935,7 @@ var nxApiCall = /*#__PURE__*/ function() {
1935
1935
  }();
1936
1936
  // src/helpers/socket.ts
1937
1937
  import { io } from "socket.io-client";
1938
+ var SESSION_STORAGE_KEY = "sessionId";
1938
1939
  var SocketService = /*#__PURE__*/ function() {
1939
1940
  "use strict";
1940
1941
  function _SocketService() {
@@ -1942,6 +1943,7 @@ var SocketService = /*#__PURE__*/ function() {
1942
1943
  this.socket = null;
1943
1944
  this.connectCallbacks = [];
1944
1945
  this.disconnectCallbacks = [];
1946
+ this.authToken = null;
1945
1947
  }
1946
1948
  _create_class(_SocketService, [
1947
1949
  {
@@ -1951,16 +1953,23 @@ var SocketService = /*#__PURE__*/ function() {
1951
1953
  var _this = this;
1952
1954
  if (!this.socket) {
1953
1955
  var socketUrl = isLocal ? "http://localhost:9009" : mode === "qa" ? "https://nx-api.xyz" : "https://nx-api.info";
1954
- console.log("socketUrl", socketUrl);
1955
1956
  this.socket = io(socketUrl, {
1956
1957
  path: "/api/data-socket/connect",
1957
- transports: [
1958
- "websocket"
1959
- ]
1958
+ auth: function(cb) {
1959
+ var sessionId = localStorage.getItem(SESSION_STORAGE_KEY) || void 0;
1960
+ var token = _this.authToken;
1961
+ var authPayload = {};
1962
+ if (token) authPayload.token = token;
1963
+ if (sessionId) authPayload.sessionId = sessionId;
1964
+ cb(authPayload);
1965
+ },
1966
+ reconnection: true,
1967
+ reconnectionAttempts: 30,
1968
+ reconnectionDelay: 2 * 1e3
1960
1969
  });
1961
1970
  this.socket.on("connect", function() {
1962
- var _this_socket;
1963
- console.log("Socket connected:", (_this_socket = _this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.id);
1971
+ var _this_socket, _this_socket1;
1972
+ 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, ")"));
1964
1973
  _this.connectCallbacks.forEach(function(cb) {
1965
1974
  return cb();
1966
1975
  });
@@ -1971,6 +1980,12 @@ var SocketService = /*#__PURE__*/ function() {
1971
1980
  return cb();
1972
1981
  });
1973
1982
  });
1983
+ this.socket.on("session", function(param) {
1984
+ var sessionId = param.sessionId;
1985
+ if (sessionId) {
1986
+ localStorage.setItem(SESSION_STORAGE_KEY, sessionId);
1987
+ }
1988
+ });
1974
1989
  this.socket.on("connect_error", function(error) {
1975
1990
  console.error("Socket connection error:", error);
1976
1991
  });
@@ -1993,10 +2008,93 @@ var SocketService = /*#__PURE__*/ function() {
1993
2008
  return this.socket;
1994
2009
  }
1995
2010
  },
2011
+ {
2012
+ /// connection management methods
2013
+ key: "startSession",
2014
+ value: function startSession(token) {
2015
+ this.setAuthToken(token);
2016
+ this.initSocket();
2017
+ }
2018
+ },
2019
+ {
2020
+ key: "onConnect",
2021
+ value: function onConnect(callback) {
2022
+ var _this = this;
2023
+ var _this_socket;
2024
+ if (!this.connectCallbacks.includes(callback)) {
2025
+ this.connectCallbacks.push(callback);
2026
+ }
2027
+ if ((_this_socket = this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.connected) {
2028
+ callback();
2029
+ }
2030
+ return function() {
2031
+ return _this.offConnect(callback);
2032
+ };
2033
+ }
2034
+ },
2035
+ {
2036
+ key: "offConnect",
2037
+ value: function offConnect(callback) {
2038
+ this.connectCallbacks = this.connectCallbacks.filter(function(cb) {
2039
+ return cb !== callback;
2040
+ });
2041
+ }
2042
+ },
2043
+ {
2044
+ key: "onDisconnect",
2045
+ value: function onDisconnect(callback) {
2046
+ var _this = this;
2047
+ if (!this.disconnectCallbacks.includes(callback)) {
2048
+ this.disconnectCallbacks.push(callback);
2049
+ }
2050
+ if (this.socket && !this.socket.connected) {
2051
+ callback();
2052
+ }
2053
+ return function() {
2054
+ return _this.offDisconnect(callback);
2055
+ };
2056
+ }
2057
+ },
2058
+ {
2059
+ key: "offDisconnect",
2060
+ value: function offDisconnect(callback) {
2061
+ this.disconnectCallbacks = this.disconnectCallbacks.filter(function(cb) {
2062
+ return cb !== callback;
2063
+ });
2064
+ }
2065
+ },
2066
+ {
2067
+ key: "isConnected",
2068
+ value: function isConnected() {
2069
+ var _this_socket;
2070
+ return ((_this_socket = this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.connected) || false;
2071
+ }
2072
+ },
2073
+ {
2074
+ key: "setAuthToken",
2075
+ value: function setAuthToken(token) {
2076
+ this.authToken = token;
2077
+ if (this.socket) {
2078
+ this.socket.connect();
2079
+ }
2080
+ }
2081
+ },
2082
+ {
2083
+ key: "disconnectSocket",
2084
+ value: function disconnectSocket() {
2085
+ if (this.socket) {
2086
+ this.socket.io.engine.close();
2087
+ }
2088
+ }
2089
+ },
1996
2090
  {
1997
2091
  /// subscribe to collections
1998
2092
  key: "subscribeToCollections",
1999
2093
  value: function subscribeToCollections(config) {
2094
+ var _this = this;
2095
+ if (config.length === 0) {
2096
+ return function() {};
2097
+ }
2000
2098
  var s = this.getSocketInstance();
2001
2099
  var collectionsNames = config.map(function(c) {
2002
2100
  return c.collectionName;
@@ -2004,48 +2102,24 @@ var SocketService = /*#__PURE__*/ function() {
2004
2102
  var eventHandlers = [];
2005
2103
  config.forEach(function(configuration) {
2006
2104
  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;
2007
- s.on("initial:".concat(collectionName), onFirstTime);
2008
- eventHandlers.push({
2009
- eventName: "initial:".concat(collectionName),
2010
- handler: onFirstTime
2011
- });
2012
- s.on("add:".concat(collectionName), onAdd);
2013
- eventHandlers.push({
2014
- eventName: "add:".concat(collectionName),
2015
- handler: onAdd
2016
- });
2017
- s.on("update:".concat(collectionName), onModify);
2018
- eventHandlers.push({
2019
- eventName: "update:".concat(collectionName),
2020
- handler: onModify
2021
- });
2022
- s.on("delete:".concat(collectionName), onRemove);
2023
- eventHandlers.push({
2024
- eventName: "delete:".concat(collectionName),
2025
- handler: onRemove
2026
- });
2027
- extraParsers === null || extraParsers === void 0 ? void 0 : extraParsers.forEach(function(parsers) {
2028
- var extraOnAdd = parsers.onAdd, extraOnFirstTime = parsers.onFirstTime, extraOnModify = parsers.onModify, extraOnRemove = parsers.onRemove;
2029
- s.on("initial:".concat(collectionName), extraOnFirstTime);
2030
- eventHandlers.push({
2031
- eventName: "initial:".concat(collectionName),
2032
- handler: extraOnFirstTime
2033
- });
2034
- s.on("add:".concat(collectionName), extraOnAdd);
2035
- eventHandlers.push({
2036
- eventName: "add:".concat(collectionName),
2037
- handler: extraOnAdd
2038
- });
2039
- s.on("update:".concat(collectionName), extraOnModify);
2105
+ var attach = function(eventName, handler) {
2106
+ _this.socket.off(eventName, handler);
2107
+ _this.socket.on(eventName, handler);
2040
2108
  eventHandlers.push({
2041
- eventName: "update:".concat(collectionName),
2042
- handler: extraOnModify
2043
- });
2044
- s.on("delete:".concat(collectionName), extraOnRemove);
2045
- eventHandlers.push({
2046
- eventName: "delete:".concat(collectionName),
2047
- handler: extraOnRemove
2109
+ eventName: eventName,
2110
+ handler: handler
2048
2111
  });
2112
+ };
2113
+ attach("initial:".concat(collectionName), onFirstTime);
2114
+ attach("add:".concat(collectionName), onAdd);
2115
+ attach("update:".concat(collectionName), onModify);
2116
+ attach("delete:".concat(collectionName), onRemove);
2117
+ extraParsers === null || extraParsers === void 0 ? void 0 : extraParsers.forEach(function(parsers) {
2118
+ var extraOnAdd = parsers.onAdd, extraOnFirstTime = parsers.onFirstTime, extraOnModify = parsers.onModify, extraOnRemove = parsers.onRemove;
2119
+ attach("initial:".concat(collectionName), extraOnFirstTime);
2120
+ attach("add:".concat(collectionName), extraOnAdd);
2121
+ attach("update:".concat(collectionName), extraOnModify);
2122
+ attach("delete:".concat(collectionName), extraOnRemove);
2049
2123
  });
2050
2124
  });
2051
2125
  s.emit("subscribe_collections", collectionsNames, function(callback) {
@@ -2146,49 +2220,6 @@ var SocketService = /*#__PURE__*/ function() {
2146
2220
  });
2147
2221
  });
2148
2222
  }
2149
- },
2150
- {
2151
- /// connection management methods
2152
- key: "onConnect",
2153
- value: function onConnect(callback) {
2154
- var _this_socket;
2155
- this.connectCallbacks.push(callback);
2156
- if ((_this_socket = this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.connected) {
2157
- callback();
2158
- }
2159
- }
2160
- },
2161
- {
2162
- key: "offConnect",
2163
- value: function offConnect(callback) {
2164
- this.connectCallbacks = this.connectCallbacks.filter(function(cb) {
2165
- return cb !== callback;
2166
- });
2167
- }
2168
- },
2169
- {
2170
- key: "onDisconnect",
2171
- value: function onDisconnect(callback) {
2172
- this.disconnectCallbacks.push(callback);
2173
- if (this.socket && !this.socket.connected) {
2174
- callback();
2175
- }
2176
- }
2177
- },
2178
- {
2179
- key: "offDisconnect",
2180
- value: function offDisconnect(callback) {
2181
- this.disconnectCallbacks = this.disconnectCallbacks.filter(function(cb) {
2182
- return cb !== callback;
2183
- });
2184
- }
2185
- },
2186
- {
2187
- key: "isConnected",
2188
- value: function isConnected() {
2189
- var _this_socket;
2190
- return ((_this_socket = this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.connected) || false;
2191
- }
2192
2223
  }
2193
2224
  ], [
2194
2225
  {