@applitools/ec-client 1.2.34 → 1.4.0

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,79 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.4.0](https://github.com/applitools/eyes.sdk.javascript1/compare/js/ec-client@1.3.0...js/ec-client@1.4.0) (2023-06-28)
4
+
5
+
6
+ ### Features
7
+
8
+ * handled abandoned tunnels ([#1669](https://github.com/applitools/eyes.sdk.javascript1/issues/1669)) ([e01a9f6](https://github.com/applitools/eyes.sdk.javascript1/commit/e01a9f6f7543fc5e6bd842acf6ee8de8cfb49998))
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * remove content type when request doesn't contain any body ([354e877](https://github.com/applitools/eyes.sdk.javascript1/commit/354e8779af9e0be2d9ec1f321acd312862448f91))
14
+
15
+
16
+ ### Dependencies
17
+
18
+ * @applitools/utils bumped from 1.4.0 to 1.5.0
19
+ #### Features
20
+
21
+ * handled abandoned tunnels ([#1669](https://github.com/applitools/eyes.sdk.javascript1/issues/1669)) ([e01a9f6](https://github.com/applitools/eyes.sdk.javascript1/commit/e01a9f6f7543fc5e6bd842acf6ee8de8cfb49998))
22
+ * @applitools/tunnel-client bumped from 0.0.5 to 0.1.0
23
+ #### Features
24
+
25
+ * handled abandoned tunnels ([#1669](https://github.com/applitools/eyes.sdk.javascript1/issues/1669)) ([e01a9f6](https://github.com/applitools/eyes.sdk.javascript1/commit/e01a9f6f7543fc5e6bd842acf6ee8de8cfb49998))
26
+
27
+
28
+
29
+ * @applitools/core-base bumped from 1.2.0 to 1.2.1
30
+
31
+ * @applitools/image bumped from 1.0.35 to 1.0.36
32
+
33
+ * @applitools/logger bumped from 2.0.4 to 2.0.5
34
+
35
+ * @applitools/req bumped from 1.3.2 to 1.3.3
36
+
37
+ * @applitools/driver bumped from 1.12.3 to 1.12.4
38
+
39
+ * @applitools/socket bumped from 1.1.4 to 1.1.5
40
+
41
+ * @applitools/spec-driver-webdriver bumped from 1.0.35 to 1.0.36
42
+
43
+
44
+ ## [1.3.0](https://github.com/applitools/eyes.sdk.javascript1/compare/js/ec-client@1.2.34...js/ec-client@1.3.0) (2023-06-21)
45
+
46
+
47
+ ### Features
48
+
49
+ * put in a queue create tunnel requests which cannot succeed due to a limit ([3309147](https://github.com/applitools/eyes.sdk.javascript1/commit/33091473f3fcbc4dd5fc853624bbe441ce11ce87))
50
+
51
+
52
+ ### Dependencies
53
+
54
+ * @applitools/core-base bumped from 1.1.58 to 1.2.0
55
+ #### Features
56
+
57
+ * **js/core-base:** new feature ([dd5705d](https://github.com/applitools/eyes.sdk.javascript1/commit/dd5705d5e99d34f9492e890a0b4af6c52d6b33e3))
58
+
59
+
60
+ #### Bug Fixes
61
+
62
+ * rerelease ([2d46d0c](https://github.com/applitools/eyes.sdk.javascript1/commit/2d46d0c9ee14a72406e60350d4cce92991272afd))
63
+
64
+
65
+
66
+ * @applitools/driver bumped from 1.12.2 to 1.12.3
67
+
68
+ * @applitools/logger bumped from 2.0.3 to 2.0.4
69
+ #### Bug Fixes
70
+
71
+ * fixed issue when extended logger didn't preserve base's handler ([7c5e029](https://github.com/applitools/eyes.sdk.javascript1/commit/7c5e0299522f792aad72b7b3827df31a1ab2d68f))
72
+ * @applitools/socket bumped from 1.1.3 to 1.1.4
73
+
74
+ * @applitools/spec-driver-webdriver bumped from 1.0.34 to 1.0.35
75
+
76
+
3
77
  ## [1.2.34](https://github.com/applitools/eyes.sdk.javascript1/compare/js/ec-client@1.2.33...js/ec-client@1.2.34) (2023-06-15)
4
78
 
5
79
 
package/dist/client.js CHANGED
@@ -35,12 +35,12 @@ async function makeECClient({ settings, logger: defaultLogger, } = {}) {
35
35
  (_a = settings.serverUrl) !== null && _a !== void 0 ? _a : (settings.serverUrl = (_b = utils.general.getEnvValue('EG_SERVER_URL')) !== null && _b !== void 0 ? _b : 'https://exec-wus.applitools.com');
36
36
  (_c = settings.proxy) !== null && _c !== void 0 ? _c : (settings.proxy = utils.general.getEnvValue('PROXY_URL') ? { url: utils.general.getEnvValue('PROXY_URL') } : undefined);
37
37
  (_d = settings.tunnel) !== null && _d !== void 0 ? _d : (settings.tunnel = {});
38
- (_e = (_7 = settings.tunnel).serverUrl) !== null && _e !== void 0 ? _e : (_7.serverUrl = utils.general.getEnvValue('EG_TUNNEL_URL'));
38
+ (_e = (_7 = settings.tunnel).serviceUrl) !== null && _e !== void 0 ? _e : (_7.serviceUrl = utils.general.getEnvValue('EG_TUNNEL_URL'));
39
39
  (_f = (_8 = settings.tunnel).groupSize) !== null && _f !== void 0 ? _f : (_8.groupSize = (_g = utils.general.getEnvValue('TUNNEL_GROUP_SIZE', 'number')) !== null && _g !== void 0 ? _g : 2);
40
40
  (_h = (_9 = settings.tunnel).pool) !== null && _h !== void 0 ? _h : (_9.pool = {});
41
41
  (_j = (_10 = settings.tunnel.pool).maxInuse) !== null && _j !== void 0 ? _j : (_10.maxInuse = (_k = utils.general.getEnvValue('TUNNEL_POOL_MAX_INUSE', 'number')) !== null && _k !== void 0 ? _k : 4);
42
42
  (_l = (_11 = settings.tunnel.pool).timeout) !== null && _l !== void 0 ? _l : (_11.timeout = {});
43
- (_m = (_12 = settings.tunnel.pool.timeout).idle) !== null && _m !== void 0 ? _m : (_12.idle = (_o = utils.general.getEnvValue('TUNNEL_POOL_TIMEOUT_IDLE', 'number')) !== null && _o !== void 0 ? _o : 10 * 60000);
43
+ (_m = (_12 = settings.tunnel.pool.timeout).idle) !== null && _m !== void 0 ? _m : (_12.idle = (_o = utils.general.getEnvValue('TUNNEL_POOL_TIMEOUT_IDLE', 'number')) !== null && _o !== void 0 ? _o : 20 * 60000);
44
44
  (_p = (_13 = settings.tunnel.pool.timeout).expiration) !== null && _p !== void 0 ? _p : (_13.expiration = (_q = utils.general.getEnvValue('TUNNEL_POOL_TIMEOUT_EXPIRATION', 'number')) !== null && _q !== void 0 ? _q : 30000);
45
45
  (_r = settings.options) !== null && _r !== void 0 ? _r : (settings.options = {});
46
46
  (_s = (_14 = settings.options).eyesServerUrl) !== null && _s !== void 0 ? _s : (_14.eyesServerUrl = (_u = (_t = utils.general.getEnvValue('EYES_SERVER_URL')) !== null && _t !== void 0 ? _t : utils.general.getEnvValue('SERVER_URL')) !== null && _u !== void 0 ? _u : 'https://eyesapi.applitools.com');
@@ -6,7 +6,7 @@ function makeEndSession({ req, tunnels }) {
6
6
  var _a, _b;
7
7
  var _c;
8
8
  logger.log(`Request was intercepted with sessionId:`, session.sessionId);
9
- await req(request.url, { body: null, io: { request, response }, logger });
9
+ await req(request.url, { io: { request, response }, logger });
10
10
  if ((_a = session.tests) === null || _a === void 0 ? void 0 : _a.current) {
11
11
  await session.tests.current.abort({ settings: { testMetadata: session.metadata }, logger });
12
12
  (_b = (_c = session.tests).ended) !== null && _b !== void 0 ? _b : (_c.ended = []);
@@ -24,9 +24,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.makeStartSession = void 0;
27
- const queue_1 = require("../utils/queue");
28
27
  //@ts-ignore
29
28
  const execution_grid_tunnel_1 = require("@applitools/execution-grid-tunnel");
29
+ const abort_controller_1 = require("abort-controller");
30
30
  const utils = __importStar(require("@applitools/utils"));
31
31
  const RETRY_BACKOFF = [
32
32
  ...Array(5).fill(2000),
@@ -84,7 +84,9 @@ function makeStartSession({ settings, req, tunnels }) {
84
84
  const queueKey = JSON.stringify(session.credentials);
85
85
  let queue = queues.get(queueKey);
86
86
  if (!queue) {
87
- queue = (0, queue_1.makeQueue)({ logger: logger.extend({ tags: [`queue-${queueKey}`] }) });
87
+ queue = utils.queues.makeCorkableQueue({
88
+ makeAbortController: () => new abort_controller_1.AbortController(),
89
+ });
88
90
  queues.set(queueKey, queue);
89
91
  }
90
92
  request.socket.on('close', () => queue.cancel(task));
package/dist/req-proxy.js CHANGED
@@ -33,17 +33,20 @@ function makeReqProxy(config) {
33
33
  retry: config.retry,
34
34
  hooks: {
35
35
  afterOptionsMerged({ options }) {
36
- var _a, _b, _c, _d;
37
- (_a = options.method) !== null && _a !== void 0 ? _a : (options.method = options.io.request.method);
36
+ var _a, _b, _c;
37
+ (_a = options.method) !== null && _a !== void 0 ? _a : (options.method = (_b = options.io.request.method) !== null && _b !== void 0 ? _b : 'GET');
38
38
  options.headers = {
39
39
  ...options.io.request.headers,
40
40
  ...options.headers,
41
41
  host: options.baseUrl && new URL(options.baseUrl).host,
42
42
  };
43
- if (!['GET', 'HEAD'].includes((_c = (_b = options.method) === null || _b === void 0 ? void 0 : _b.toUpperCase()) !== null && _c !== void 0 ? _c : 'GET')) {
44
- (_d = options.body) !== null && _d !== void 0 ? _d : (options.body = utils.streams.persist(options.io.request));
43
+ if (['POST', 'PUT', 'PATCH'].includes(options.method.toUpperCase())) {
44
+ (_c = options.body) !== null && _c !== void 0 ? _c : (options.body = utils.streams.persist(options.io.request));
45
45
  }
46
- if (options.body && !utils.types.isFunction(options.body, 'pipe')) {
46
+ if (options.body === undefined) {
47
+ delete options.headers['content-type'];
48
+ }
49
+ else if (!utils.types.isFunction(options.body, 'pipe')) {
47
50
  options.headers['content-length'] = Buffer.byteLength(utils.types.isArray(options.body) || utils.types.isPlainObject(options.body) || options.body === null
48
51
  ? JSON.stringify(options.body)
49
52
  : options.body).toString();
package/dist/server.js CHANGED
@@ -54,7 +54,7 @@ async function makeServer({ settings, logger: mainLogger, }) {
54
54
  },
55
55
  });
56
56
  const core = (0, core_base_1.makeCore)({ agentId: `js/ec-client/${require('../package.json').version}` });
57
- const tunnels = ((_a = settings.tunnel) === null || _a === void 0 ? void 0 : _a.serverUrl)
57
+ const tunnels = ((_a = settings.tunnel) === null || _a === void 0 ? void 0 : _a.serviceUrl)
58
58
  ? await (0, manager_1.makeTunnelManager)({ settings: settings.tunnel, logger: serverLogger })
59
59
  : await (0, manager_client_1.makeTunnelManagerClient)({ settings: settings.tunnel });
60
60
  const sessions = new Map();
@@ -28,10 +28,6 @@ async function makeTunnelManagerClient({ settings, } = {}) {
28
28
  });
29
29
  socket.once('ready', () => socket.target.unref());
30
30
  return {
31
- create: (options) => {
32
- return socket.request('Tunnel.create', options);
33
- },
34
- destroy: (options) => socket.request('Tunnel.destroy', options),
35
31
  acquire: (options) => socket.request('Tunnel.acquire', options),
36
32
  release: (options) => socket.request('Tunnel.release', options),
37
33
  close: () => server === null || server === void 0 ? void 0 : server.close(),
@@ -63,27 +63,33 @@ async function makeTunnelManagerServer({ settings, path, idleTimeout = 600000, /
63
63
  });
64
64
  const sockets = new Set();
65
65
  server.on('connection', client => {
66
- if (idle) {
67
- clearTimeout(idle);
68
- idle = null;
69
- }
66
+ const store = new Map();
67
+ if (idle)
68
+ idle = clearTimeout(idle);
70
69
  const socket = (0, socket_1.makeSocket)(client, { transport: 'ipc', logger });
71
70
  sockets.add(socket);
72
- socket.on('close', () => {
71
+ socket.on('close', async () => {
72
+ logger.log('Connection is closed, remaining tunnels are going to be released');
73
73
  sockets.delete(socket);
74
- if (sockets.size > 0 || serverClosed)
75
- return;
76
- idle = setTimeout(close, idleTimeout);
74
+ await Promise.all(Array.from(store.values(), manager.release)).catch(logger.error);
75
+ if (sockets.size === 0 && !serverClosed)
76
+ idle = setTimeout(close, idleTimeout);
77
+ });
78
+ socket.command('Tunnel.acquire', async (credentials) => {
79
+ const tunnels = await manager.acquire(credentials);
80
+ store.set(JSON.stringify(tunnels), tunnels);
81
+ return tunnels;
82
+ });
83
+ socket.command('Tunnel.release', async (tunnels) => {
84
+ await manager.release(tunnels);
85
+ store.delete(JSON.stringify(tunnels));
77
86
  });
78
- socket.command('Tunnel.create', manager.create);
79
- socket.command('Tunnel.destroy', manager.destroy);
80
- socket.command('Tunnel.acquire', manager.acquire);
81
- socket.command('Tunnel.release', manager.release);
82
87
  });
83
88
  return { close };
84
89
  async function close() {
90
+ logger.log('Server is going to be closed');
85
91
  server.close();
86
- manager.close();
92
+ await manager.close();
87
93
  process.kill(0);
88
94
  }
89
95
  }
@@ -24,51 +24,19 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.makeTunnelManager = void 0;
27
- const req_1 = require("@applitools/req");
28
- //@ts-ignore
29
- const execution_grid_tunnel_1 = require("@applitools/execution-grid-tunnel");
27
+ const tunnel_client_1 = require("@applitools/tunnel-client");
30
28
  const utils = __importStar(require("@applitools/utils"));
31
29
  async function makeTunnelManager({ settings, logger, }) {
32
- let server;
33
- const getTunnelServiceUrl = utils.general.cachify(async () => {
34
- const { port, cleanupFunction } = await (0, execution_grid_tunnel_1.startEgTunnelService)({ logger });
35
- server = {
36
- port,
37
- async close() {
38
- await cleanupFunction();
39
- server = undefined;
40
- getTunnelServiceUrl.clearCache();
41
- },
42
- };
43
- return `http://localhost:${port}`;
44
- });
45
- const req = (0, req_1.makeReq)({
46
- retry: {
47
- validate: async ({ response }) => {
48
- if (!response)
49
- return false;
50
- const body = await response
51
- .clone()
52
- .json()
53
- .catch(() => null);
54
- return ['CONCURRENCY_LIMIT_REACHED', 'NO_AVAILABLE_TUNNEL_PROXY'].includes(body === null || body === void 0 ? void 0 : body.message);
55
- },
56
- timeout: [
57
- ...Array(5).fill(2000),
58
- ...Array(4).fill(5000),
59
- 10000, // all next tries with delay 10s
60
- ],
61
- },
62
- });
30
+ const client = (0, tunnel_client_1.makeTunnelClient)({ settings, logger });
63
31
  const pools = new Map();
64
- return { create, destroy, acquire, release, close: async () => server === null || server === void 0 ? void 0 : server.close() };
32
+ return { acquire, release, close: client.close };
65
33
  async function acquire(credentials) {
66
34
  const key = JSON.stringify(credentials);
67
35
  let pool = pools.get(key);
68
36
  if (!pool) {
69
37
  pool = makePool({
70
- create: () => { var _a; return Promise.all(Array.from({ length: (_a = settings === null || settings === void 0 ? void 0 : settings.groupSize) !== null && _a !== void 0 ? _a : 1 }, () => create(credentials))); },
71
- destroy: tunnels => Promise.all(tunnels.map(destroy)).then(() => undefined),
38
+ create: () => { var _a; return Promise.all(Array.from({ length: (_a = settings === null || settings === void 0 ? void 0 : settings.groupSize) !== null && _a !== void 0 ? _a : 1 }, () => client.create(credentials))); },
39
+ destroy: tunnels => Promise.all(tunnels.map(client.destroy)).then(() => undefined),
72
40
  ...settings === null || settings === void 0 ? void 0 : settings.pool,
73
41
  });
74
42
  pools.set(key, pool);
@@ -82,46 +50,6 @@ async function makeTunnelManager({ settings, logger, }) {
82
50
  return;
83
51
  await pool.release(tunnels);
84
52
  }
85
- async function create(credentials) {
86
- var _a, _b;
87
- if (!(settings === null || settings === void 0 ? void 0 : settings.serverUrl)) {
88
- settings !== null && settings !== void 0 ? settings : (settings = {});
89
- settings.serverUrl = await getTunnelServiceUrl();
90
- }
91
- const response = await req('/tunnels', {
92
- method: 'POST',
93
- baseUrl: settings.serverUrl,
94
- headers: {
95
- 'x-eyes-api-key': credentials.apiKey,
96
- 'x-eyes-server-url': credentials.eyesServerUrl,
97
- },
98
- });
99
- const body = await response.json().catch(() => null);
100
- if (response.status === 201)
101
- return { tunnelId: body, credentials };
102
- logger.error(`Failed to create tunnel with status ${response.status} and code ${(_a = body === null || body === void 0 ? void 0 : body.message) !== null && _a !== void 0 ? _a : 'UNKNOWN_ERROR'}`);
103
- throw new Error(`Failed to create tunnel with code ${(_b = body === null || body === void 0 ? void 0 : body.message) !== null && _b !== void 0 ? _b : 'UNKNOWN_ERROR'}`);
104
- }
105
- async function destroy(tunnel) {
106
- var _a, _b;
107
- if (!(settings === null || settings === void 0 ? void 0 : settings.serverUrl)) {
108
- settings !== null && settings !== void 0 ? settings : (settings = {});
109
- settings.serverUrl = await getTunnelServiceUrl();
110
- }
111
- const response = await req(`/tunnels/${tunnel.tunnelId}`, {
112
- method: 'DELETE',
113
- baseUrl: settings.serverUrl,
114
- headers: {
115
- 'x-eyes-api-key': tunnel.credentials.apiKey,
116
- 'x-eyes-server-url': tunnel.credentials.eyesServerUrl,
117
- },
118
- });
119
- const body = await response.json().catch(() => null);
120
- if (response.status === 200)
121
- return;
122
- logger.error(`Failed to delete tunnel with status ${response.status} and code ${(_a = body === null || body === void 0 ? void 0 : body.message) !== null && _a !== void 0 ? _a : 'UNKNOWN_ERROR'}`);
123
- throw new Error(`Failed to delete tunnel with code ${(_b = body === null || body === void 0 ? void 0 : body.message) !== null && _b !== void 0 ? _b : 'UNKNOWN_ERROR'}`);
124
- }
125
53
  }
126
54
  exports.makeTunnelManager = makeTunnelManager;
127
55
  function makePool(options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applitools/ec-client",
3
- "version": "1.2.34",
3
+ "version": "1.4.0",
4
4
  "homepage": "https://applitools.com",
5
5
  "bugs": {
6
6
  "url": "https://github.com/applitools/eyes.sdk.javascript1/issues"
@@ -52,14 +52,15 @@
52
52
  "test:it": "MOCHA_GROUP=it run --top-level mocha './test/it/*.spec.ts'"
53
53
  },
54
54
  "dependencies": {
55
- "@applitools/core-base": "1.1.58",
56
- "@applitools/driver": "1.12.2",
57
- "@applitools/execution-grid-tunnel": "2.1.0",
58
- "@applitools/logger": "2.0.3",
59
- "@applitools/req": "1.3.2",
60
- "@applitools/socket": "1.1.3",
61
- "@applitools/spec-driver-webdriver": "1.0.34",
62
- "@applitools/utils": "1.4.0",
55
+ "@applitools/core-base": "1.2.1",
56
+ "@applitools/driver": "1.12.4",
57
+ "@applitools/execution-grid-tunnel": "^2.1.2",
58
+ "@applitools/logger": "2.0.5",
59
+ "@applitools/req": "1.3.3",
60
+ "@applitools/socket": "1.1.5",
61
+ "@applitools/spec-driver-webdriver": "1.0.36",
62
+ "@applitools/tunnel-client": "0.1.0",
63
+ "@applitools/utils": "1.5.0",
63
64
  "abort-controller": "3.0.0",
64
65
  "webdriver": "7",
65
66
  "yargs": "^17.7.2"
@@ -1,4 +1,5 @@
1
- import { type TunnelManager, type TunnelManagerSettings } from './manager';
1
+ import type { TunnelManagerSettings } from '../types';
2
+ import { type TunnelManager } from './manager';
2
3
  export declare function makeTunnelManagerClient({ settings, }?: {
3
4
  settings?: TunnelManagerSettings;
4
5
  }): Promise<TunnelManager & {
@@ -1,4 +1,4 @@
1
- import { type TunnelManagerSettings } from './manager';
1
+ import type { TunnelManagerSettings } from '../types';
2
2
  export type TunnelManagerServer = {
3
3
  close(): Promise<void>;
4
4
  };
@@ -1,29 +1,11 @@
1
+ import type { TunnelManagerSettings } from '../types';
1
2
  import { type Logger } from '@applitools/logger';
3
+ import { type Tunnel, type TunnelCredentials } from '@applitools/tunnel-client';
2
4
  export interface TunnelManager {
3
- create(credentials: TunnelCredentials): Promise<Tunnel>;
4
- destroy(tunnel: Tunnel): Promise<void>;
5
5
  acquire(credentials: TunnelCredentials): Promise<Tunnel[]>;
6
6
  release(tunnels: Tunnel[]): Promise<void>;
7
+ close(): Promise<void>;
7
8
  }
8
- export interface Tunnel {
9
- tunnelId: string;
10
- credentials: TunnelCredentials;
11
- }
12
- export interface TunnelCredentials {
13
- eyesServerUrl: string;
14
- apiKey: string;
15
- }
16
- export type TunnelManagerSettings = {
17
- serverUrl?: string;
18
- groupSize?: number;
19
- pool?: {
20
- maxInuse?: number;
21
- timeout?: {
22
- idle?: number;
23
- expiration?: number;
24
- };
25
- };
26
- };
27
9
  export declare function makeTunnelManager({ settings, logger, }: {
28
10
  settings?: TunnelManagerSettings;
29
11
  logger: Logger;
package/types/types.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { type Proxy } from '@applitools/req';
2
2
  import { type Batch, type FunctionalSession } from '@applitools/core-base';
3
- import { type Tunnel } from './tunnels/manager';
3
+ import { type TunnelClientSettings, type Tunnel } from '@applitools/tunnel-client';
4
4
  export interface ECClient {
5
5
  readonly url: string;
6
6
  readonly port: number;
@@ -13,17 +13,7 @@ export interface ECClientSettings {
13
13
  options?: ECCapabilitiesOptions;
14
14
  port?: number;
15
15
  /** @internal */
16
- tunnel?: {
17
- serverUrl?: string;
18
- groupSize?: number;
19
- pool?: {
20
- maxInuse?: number;
21
- timeout?: {
22
- idle?: number;
23
- expiration?: number;
24
- };
25
- };
26
- };
16
+ tunnel?: TunnelManagerSettings;
27
17
  }
28
18
  export interface ECCapabilitiesOptions {
29
19
  eyesServerUrl?: string;
@@ -56,3 +46,13 @@ export interface ECSession {
56
46
  ended?: FunctionalSession[];
57
47
  };
58
48
  }
49
+ export type TunnelManagerSettings = TunnelClientSettings & {
50
+ groupSize?: number;
51
+ pool?: {
52
+ maxInuse?: number;
53
+ timeout?: {
54
+ idle?: number;
55
+ expiration?: number;
56
+ };
57
+ };
58
+ };
@@ -1,108 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.makeQueue = void 0;
27
- const abort_controller_1 = require("abort-controller");
28
- const utils = __importStar(require("@applitools/utils"));
29
- function makeQueue({ logger }) {
30
- const pool = [];
31
- const map = new Map();
32
- let corked = false;
33
- return {
34
- get corked() {
35
- return corked;
36
- },
37
- pause: Symbol('pause queue'),
38
- run,
39
- cancel,
40
- cork,
41
- uncork,
42
- };
43
- async function run(task) {
44
- const handle = {};
45
- handle.running = false;
46
- handle.start = async () => {
47
- if (handle.running)
48
- return;
49
- handle.running = true;
50
- handle.controller = new abort_controller_1.AbortController();
51
- try {
52
- const result = await task(handle.controller.signal);
53
- if (handle.running) {
54
- map.delete(task);
55
- pool.splice(pool.indexOf(handle), 1);
56
- handle.resolve(result);
57
- }
58
- }
59
- catch (error) {
60
- if (handle.running || !utils.types.instanceOf(error, 'AbortError'))
61
- handle.reject(error);
62
- }
63
- finally {
64
- return handle.promise;
65
- }
66
- };
67
- handle.abort = () => {
68
- if (!handle.running)
69
- return;
70
- handle.running = false;
71
- handle.controller.abort();
72
- };
73
- handle.promise = new Promise((resolve, reject) => {
74
- handle.resolve = resolve;
75
- handle.reject = reject;
76
- });
77
- pool.push(handle);
78
- map.set(task, handle);
79
- logger.log('Task was added to the queue');
80
- if (!corked)
81
- handle.start();
82
- return handle.promise;
83
- }
84
- function cancel(task) {
85
- const handle = map.get(task);
86
- if (!(handle === null || handle === void 0 ? void 0 : handle.running))
87
- return;
88
- handle.abort();
89
- map.delete(task);
90
- pool.splice(pool.indexOf(handle), 1);
91
- logger.log('Task was cancelled');
92
- }
93
- function cork() {
94
- if (corked)
95
- return;
96
- corked = true;
97
- pool.slice(1).forEach(handle => handle.abort());
98
- logger.log('Queue was corked');
99
- }
100
- function uncork() {
101
- if (!corked)
102
- return;
103
- corked = false;
104
- pool.forEach(handle => handle.start());
105
- logger.log('Queue was uncorked');
106
- }
107
- }
108
- exports.makeQueue = makeQueue;
@@ -1,15 +0,0 @@
1
- import { type Logger } from '@applitools/logger';
2
- import { type AbortSignal } from 'abort-controller';
3
- export type Queue = {
4
- readonly corked: boolean;
5
- readonly pause: never;
6
- run<TResult>(task: Task<TResult>): Promise<TResult>;
7
- cancel(task: (signal: AbortSignal) => Promise<any>): void;
8
- cork(): void;
9
- uncork(): void;
10
- };
11
- type Task<TResult> = (signal: AbortSignal) => Promise<TResult>;
12
- export declare function makeQueue({ logger }: {
13
- logger: Logger;
14
- }): Queue;
15
- export {};