akeyless-client-commons 1.1.17-test.8 → 1.1.17-test.9

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() {
@@ -2318,19 +2319,24 @@ var SocketService = /*#__PURE__*/ function() {
2318
2319
  var socketUrl = isLocal ? "http://localhost:9009" : mode === "qa" ? "https://nx-api.xyz" : "https://nx-api.info";
2319
2320
  this.socket = (0, import_socket.io)(socketUrl, {
2320
2321
  path: "/api/data-socket/connect",
2321
- transports: [
2322
- "websocket"
2323
- ],
2324
- auth: this.authToken ? {
2325
- token: this.authToken
2326
- } : void 0
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
2327
2333
  });
2328
2334
  this.socket.on("connect", function() {
2329
- var _this_socket;
2330
- console.log("Socket connected:", (_this_socket = _this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.id);
2331
- });
2332
- this.connectCallbacks.forEach(function(cb) {
2333
- return cb();
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, ")"));
2337
+ _this.connectCallbacks.forEach(function(cb) {
2338
+ return cb();
2339
+ });
2334
2340
  });
2335
2341
  this.socket.on("disconnect", function(reason) {
2336
2342
  console.log("Socket disconnected:", reason);
@@ -2338,6 +2344,12 @@ var SocketService = /*#__PURE__*/ function() {
2338
2344
  return cb();
2339
2345
  });
2340
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
+ });
2341
2353
  this.socket.on("connect_error", function(error) {
2342
2354
  console.error("Socket connection error:", error);
2343
2355
  });
@@ -2360,10 +2372,90 @@ var SocketService = /*#__PURE__*/ function() {
2360
2372
  return this.socket;
2361
2373
  }
2362
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
+ },
2363
2454
  {
2364
2455
  /// subscribe to collections
2365
2456
  key: "subscribeToCollections",
2366
2457
  value: function subscribeToCollections(config) {
2458
+ var _this = this;
2367
2459
  if (config.length === 0) {
2368
2460
  return function() {};
2369
2461
  }
@@ -2374,48 +2466,24 @@ var SocketService = /*#__PURE__*/ function() {
2374
2466
  var eventHandlers = [];
2375
2467
  config.forEach(function(configuration) {
2376
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;
2377
- s.on("initial:".concat(collectionName), onFirstTime);
2378
- eventHandlers.push({
2379
- eventName: "initial:".concat(collectionName),
2380
- handler: onFirstTime
2381
- });
2382
- s.on("add:".concat(collectionName), onAdd);
2383
- eventHandlers.push({
2384
- eventName: "add:".concat(collectionName),
2385
- handler: onAdd
2386
- });
2387
- s.on("update:".concat(collectionName), onModify);
2388
- eventHandlers.push({
2389
- eventName: "update:".concat(collectionName),
2390
- handler: onModify
2391
- });
2392
- s.on("delete:".concat(collectionName), onRemove);
2393
- eventHandlers.push({
2394
- eventName: "delete:".concat(collectionName),
2395
- handler: onRemove
2396
- });
2397
- extraParsers === null || extraParsers === void 0 ? void 0 : extraParsers.forEach(function(parsers) {
2398
- var extraOnAdd = parsers.onAdd, extraOnFirstTime = parsers.onFirstTime, extraOnModify = parsers.onModify, extraOnRemove = parsers.onRemove;
2399
- s.on("initial:".concat(collectionName), extraOnFirstTime);
2469
+ var attach = function(eventName, handler) {
2470
+ _this.socket.off(eventName, handler);
2471
+ _this.socket.on(eventName, handler);
2400
2472
  eventHandlers.push({
2401
- eventName: "initial:".concat(collectionName),
2402
- handler: extraOnFirstTime
2403
- });
2404
- s.on("add:".concat(collectionName), extraOnAdd);
2405
- eventHandlers.push({
2406
- eventName: "add:".concat(collectionName),
2407
- handler: extraOnAdd
2408
- });
2409
- s.on("update:".concat(collectionName), extraOnModify);
2410
- eventHandlers.push({
2411
- eventName: "update:".concat(collectionName),
2412
- handler: extraOnModify
2413
- });
2414
- s.on("delete:".concat(collectionName), extraOnRemove);
2415
- eventHandlers.push({
2416
- eventName: "delete:".concat(collectionName),
2417
- handler: extraOnRemove
2473
+ eventName: eventName,
2474
+ handler: handler
2418
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);
2419
2487
  });
2420
2488
  });
2421
2489
  s.emit("subscribe_collections", collectionsNames, function(callback) {
@@ -2516,64 +2584,6 @@ var SocketService = /*#__PURE__*/ function() {
2516
2584
  });
2517
2585
  });
2518
2586
  }
2519
- },
2520
- {
2521
- /// connection management methods
2522
- key: "onConnect",
2523
- value: function onConnect(callback) {
2524
- var _this_socket;
2525
- this.connectCallbacks.push(callback);
2526
- if ((_this_socket = this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.connected) {
2527
- callback();
2528
- }
2529
- }
2530
- },
2531
- {
2532
- key: "offConnect",
2533
- value: function offConnect(callback) {
2534
- this.connectCallbacks = this.connectCallbacks.filter(function(cb) {
2535
- return cb !== callback;
2536
- });
2537
- }
2538
- },
2539
- {
2540
- key: "onDisconnect",
2541
- value: function onDisconnect(callback) {
2542
- this.disconnectCallbacks.push(callback);
2543
- if (this.socket && !this.socket.connected) {
2544
- callback();
2545
- }
2546
- }
2547
- },
2548
- {
2549
- key: "offDisconnect",
2550
- value: function offDisconnect(callback) {
2551
- this.disconnectCallbacks = this.disconnectCallbacks.filter(function(cb) {
2552
- return cb !== callback;
2553
- });
2554
- }
2555
- },
2556
- {
2557
- key: "isConnected",
2558
- value: function isConnected() {
2559
- var _this_socket;
2560
- return ((_this_socket = this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.connected) || false;
2561
- }
2562
- },
2563
- {
2564
- key: "setAuthToken",
2565
- value: function setAuthToken(token) {
2566
- this.authToken = token;
2567
- if (this.socket) {
2568
- this.socket.auth = {
2569
- token: token
2570
- };
2571
- if (this.socket.connected) {
2572
- this.socket.disconnect();
2573
- }
2574
- this.socket.connect();
2575
- }
2576
- }
2577
2587
  }
2578
2588
  ], [
2579
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() {
@@ -1954,19 +1955,24 @@ var SocketService = /*#__PURE__*/ function() {
1954
1955
  var socketUrl = isLocal ? "http://localhost:9009" : mode === "qa" ? "https://nx-api.xyz" : "https://nx-api.info";
1955
1956
  this.socket = io(socketUrl, {
1956
1957
  path: "/api/data-socket/connect",
1957
- transports: [
1958
- "websocket"
1959
- ],
1960
- auth: this.authToken ? {
1961
- token: this.authToken
1962
- } : void 0
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
1963
1969
  });
1964
1970
  this.socket.on("connect", function() {
1965
- var _this_socket;
1966
- console.log("Socket connected:", (_this_socket = _this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.id);
1967
- });
1968
- this.connectCallbacks.forEach(function(cb) {
1969
- return cb();
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, ")"));
1973
+ _this.connectCallbacks.forEach(function(cb) {
1974
+ return cb();
1975
+ });
1970
1976
  });
1971
1977
  this.socket.on("disconnect", function(reason) {
1972
1978
  console.log("Socket disconnected:", reason);
@@ -1974,6 +1980,12 @@ var SocketService = /*#__PURE__*/ function() {
1974
1980
  return cb();
1975
1981
  });
1976
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
+ });
1977
1989
  this.socket.on("connect_error", function(error) {
1978
1990
  console.error("Socket connection error:", error);
1979
1991
  });
@@ -1996,10 +2008,90 @@ var SocketService = /*#__PURE__*/ function() {
1996
2008
  return this.socket;
1997
2009
  }
1998
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
+ },
1999
2090
  {
2000
2091
  /// subscribe to collections
2001
2092
  key: "subscribeToCollections",
2002
2093
  value: function subscribeToCollections(config) {
2094
+ var _this = this;
2003
2095
  if (config.length === 0) {
2004
2096
  return function() {};
2005
2097
  }
@@ -2010,48 +2102,24 @@ var SocketService = /*#__PURE__*/ function() {
2010
2102
  var eventHandlers = [];
2011
2103
  config.forEach(function(configuration) {
2012
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;
2013
- s.on("initial:".concat(collectionName), onFirstTime);
2014
- eventHandlers.push({
2015
- eventName: "initial:".concat(collectionName),
2016
- handler: onFirstTime
2017
- });
2018
- s.on("add:".concat(collectionName), onAdd);
2019
- eventHandlers.push({
2020
- eventName: "add:".concat(collectionName),
2021
- handler: onAdd
2022
- });
2023
- s.on("update:".concat(collectionName), onModify);
2024
- eventHandlers.push({
2025
- eventName: "update:".concat(collectionName),
2026
- handler: onModify
2027
- });
2028
- s.on("delete:".concat(collectionName), onRemove);
2029
- eventHandlers.push({
2030
- eventName: "delete:".concat(collectionName),
2031
- handler: onRemove
2032
- });
2033
- extraParsers === null || extraParsers === void 0 ? void 0 : extraParsers.forEach(function(parsers) {
2034
- var extraOnAdd = parsers.onAdd, extraOnFirstTime = parsers.onFirstTime, extraOnModify = parsers.onModify, extraOnRemove = parsers.onRemove;
2035
- s.on("initial:".concat(collectionName), extraOnFirstTime);
2105
+ var attach = function(eventName, handler) {
2106
+ _this.socket.off(eventName, handler);
2107
+ _this.socket.on(eventName, handler);
2036
2108
  eventHandlers.push({
2037
- eventName: "initial:".concat(collectionName),
2038
- handler: extraOnFirstTime
2039
- });
2040
- s.on("add:".concat(collectionName), extraOnAdd);
2041
- eventHandlers.push({
2042
- eventName: "add:".concat(collectionName),
2043
- handler: extraOnAdd
2044
- });
2045
- s.on("update:".concat(collectionName), extraOnModify);
2046
- eventHandlers.push({
2047
- eventName: "update:".concat(collectionName),
2048
- handler: extraOnModify
2049
- });
2050
- s.on("delete:".concat(collectionName), extraOnRemove);
2051
- eventHandlers.push({
2052
- eventName: "delete:".concat(collectionName),
2053
- handler: extraOnRemove
2109
+ eventName: eventName,
2110
+ handler: handler
2054
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);
2055
2123
  });
2056
2124
  });
2057
2125
  s.emit("subscribe_collections", collectionsNames, function(callback) {
@@ -2152,64 +2220,6 @@ var SocketService = /*#__PURE__*/ function() {
2152
2220
  });
2153
2221
  });
2154
2222
  }
2155
- },
2156
- {
2157
- /// connection management methods
2158
- key: "onConnect",
2159
- value: function onConnect(callback) {
2160
- var _this_socket;
2161
- this.connectCallbacks.push(callback);
2162
- if ((_this_socket = this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.connected) {
2163
- callback();
2164
- }
2165
- }
2166
- },
2167
- {
2168
- key: "offConnect",
2169
- value: function offConnect(callback) {
2170
- this.connectCallbacks = this.connectCallbacks.filter(function(cb) {
2171
- return cb !== callback;
2172
- });
2173
- }
2174
- },
2175
- {
2176
- key: "onDisconnect",
2177
- value: function onDisconnect(callback) {
2178
- this.disconnectCallbacks.push(callback);
2179
- if (this.socket && !this.socket.connected) {
2180
- callback();
2181
- }
2182
- }
2183
- },
2184
- {
2185
- key: "offDisconnect",
2186
- value: function offDisconnect(callback) {
2187
- this.disconnectCallbacks = this.disconnectCallbacks.filter(function(cb) {
2188
- return cb !== callback;
2189
- });
2190
- }
2191
- },
2192
- {
2193
- key: "isConnected",
2194
- value: function isConnected() {
2195
- var _this_socket;
2196
- return ((_this_socket = this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.connected) || false;
2197
- }
2198
- },
2199
- {
2200
- key: "setAuthToken",
2201
- value: function setAuthToken(token) {
2202
- this.authToken = token;
2203
- if (this.socket) {
2204
- this.socket.auth = {
2205
- token: token
2206
- };
2207
- if (this.socket.connected) {
2208
- this.socket.disconnect();
2209
- }
2210
- this.socket.connect();
2211
- }
2212
- }
2213
2223
  }
2214
2224
  ], [
2215
2225
  {