@mablhq/mabl-cli 2.46.12 → 2.49.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/http/httpUtil.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.postProcessHeaders = exports.getHttpAgent = exports.GENERAL_API_STEP_EXECUTION_ERROR_CODE = exports.EXECUTION_ENGINE_SSL_VERIFY = exports.USER_AGENT_HEADER = exports.USER_AGENT = void 0;
4
+ const agent_base_1 = require("agent-base");
4
5
  const socks_proxy_agent_1 = require("socks-proxy-agent");
5
6
  const pureUtil_1 = require("../util/pureUtil");
6
7
  const MablHttpAgent_1 = require("./MablHttpAgent");
@@ -9,8 +10,8 @@ exports.USER_AGENT = `${(0, pureUtil_1.getCliName)()}@${(0, pureUtil_1.getCliVer
9
10
  exports.USER_AGENT_HEADER = 'User-Agent';
10
11
  exports.EXECUTION_ENGINE_SSL_VERIFY = false;
11
12
  exports.GENERAL_API_STEP_EXECUTION_ERROR_CODE = '-1';
12
- function getHttpAgent(shouldFilterHttpRequests, linkServer, proxyConfig) {
13
- const linkAgent = maybeGetSocksAgent(linkServer);
13
+ function getHttpAgent(shouldFilterHttpRequests, linkServers, proxyConfig) {
14
+ const linkAgent = maybeGetSocksAgent(linkServers);
14
15
  if (linkAgent) {
15
16
  return MablHttpAgent_1.MablHttpAgent.createNewInstance({
16
17
  httpAgent: linkAgent,
@@ -23,11 +24,11 @@ function getHttpAgent(shouldFilterHttpRequests, linkServer, proxyConfig) {
23
24
  return MablHttpAgent_1.MablHttpAgent.createNewInstance({ proxyConfig });
24
25
  }
25
26
  exports.getHttpAgent = getHttpAgent;
26
- function maybeGetSocksAgent(linkServer) {
27
- if (!linkServer) {
27
+ function maybeGetSocksAgent(linkServers) {
28
+ if (!(linkServers === null || linkServers === void 0 ? void 0 : linkServers.length)) {
28
29
  return;
29
30
  }
30
- const agentOptions = {
31
+ const agentOptions = linkServers.map((linkServer) => ({
31
32
  host: linkServer.forwarding_host,
32
33
  port: linkServer.forwarding_port,
33
34
  userId: linkServer.workspace_id,
@@ -35,8 +36,26 @@ function maybeGetSocksAgent(linkServer) {
35
36
  tls: {
36
37
  rejectUnauthorized: false,
37
38
  },
38
- };
39
- return new socks_proxy_agent_1.SocksProxyAgent(agentOptions);
39
+ }));
40
+ if (agentOptions.length === 1) {
41
+ return new socks_proxy_agent_1.SocksProxyAgent(agentOptions[0]);
42
+ }
43
+ return new MultiSocksProxyAgent(agentOptions);
44
+ }
45
+ class MultiSocksProxyAgent extends agent_base_1.Agent {
46
+ constructor(options) {
47
+ super();
48
+ this.agents = options.map((proxy) => new socks_proxy_agent_1.SocksProxyAgent(proxy));
49
+ }
50
+ async callback(req, opts) {
51
+ return this.selectAgent().callback(req, opts);
52
+ }
53
+ selectAgent() {
54
+ return this.agents[Math.floor(Math.random() * this.agents.length)];
55
+ }
56
+ destroy() {
57
+ this.agents.forEach((agent) => agent.destroy());
58
+ }
40
59
  }
41
60
  function postProcessHeaders(response) {
42
61
  var _a, _b, _c;