@capawesome/cli 3.5.0 → 3.6.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
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
4
4
 
5
+ ## [3.6.0](https://github.com/capawesome-team/cli/compare/v3.5.0...v3.6.0) (2025-11-29)
6
+
7
+
8
+ ### Features
9
+
10
+ * add proxy support for HTTP and HTTPS requests ([#99](https://github.com/capawesome-team/cli/issues/99)) ([5a6e627](https://github.com/capawesome-team/cli/commit/5a6e627a85634628ea9c365d4e7b25cc69fbe11d))
11
+
5
12
  ## [3.5.0](https://github.com/capawesome-team/cli/compare/v3.4.2...v3.5.0) (2025-11-24)
6
13
 
7
14
 
package/README.md CHANGED
@@ -34,6 +34,8 @@ npx @capawesome/cli --help
34
34
 
35
35
  ## Development
36
36
 
37
+ ### Getting Started
38
+
37
39
  Run the following commands to get started with development:
38
40
 
39
41
  1. Clone the repository:
@@ -57,6 +59,26 @@ Run the following commands to get started with development:
57
59
 
58
60
  **Note:** The `--` is required to pass arguments to the script.
59
61
 
62
+ ### Testing Proxy Support
63
+
64
+ To test HTTP/HTTPS proxy functionality locally:
65
+
66
+ 1. Start Squid proxy in a separate terminal:
67
+ ```bash
68
+ docker run --rm --name squid-proxy -p 3128:3128 -v $(pwd)/squid.conf:/etc/squid/squid.conf:ro sameersbn/squid:latest
69
+ ```
70
+
71
+ 2. Set proxy environment variables and run the CLI:
72
+ ```bash
73
+ export https_proxy=http://localhost:3128
74
+ npm run build && node ./dist/index.js login
75
+ ```
76
+
77
+ 3. To see debug output:
78
+ ```bash
79
+ DEBUG=https-proxy-agent node ./dist/index.js login
80
+ ```
81
+
60
82
  ## Changelog
61
83
 
62
84
  See [CHANGELOG](./CHANGELOG.md).
@@ -2,6 +2,8 @@ import { createRequire } from 'module';
2
2
  import configService from '../services/config.js';
3
3
  import axios from 'axios';
4
4
  import axiosRetry from 'axios-retry';
5
+ import { HttpProxyAgent } from 'http-proxy-agent';
6
+ import { HttpsProxyAgent } from 'https-proxy-agent';
5
7
  const require = createRequire(import.meta.url);
6
8
  const pkg = require('../../package.json');
7
9
  // Register middleware to retry failed requests
@@ -14,6 +16,22 @@ axiosRetry(axios, {
14
16
  (error.response?.status !== undefined && error.response.status >= 500));
15
17
  },
16
18
  });
19
+ /**
20
+ * Gets the appropriate proxy agent based on the target URL protocol and environment variables.
21
+ * This ensures that HTTPS requests use HTTPS even when the proxy itself is accessed via HTTP.
22
+ */
23
+ function getProxyAgent(targetUrl) {
24
+ const isHttps = targetUrl.startsWith('https://');
25
+ const proxyUrl = isHttps
26
+ ? process.env.HTTPS_PROXY || process.env.https_proxy
27
+ : process.env.HTTP_PROXY || process.env.http_proxy;
28
+ if (!proxyUrl) {
29
+ return undefined;
30
+ }
31
+ // Use the appropriate agent based on the TARGET protocol, not the proxy protocol
32
+ // This allows using an HTTP proxy for HTTPS requests
33
+ return isHttps ? new HttpsProxyAgent(proxyUrl) : new HttpProxyAgent(proxyUrl);
34
+ }
17
35
  class HttpClientImpl {
18
36
  baseHeaders = {
19
37
  'User-Agent': `Capawesome CLI v${pkg.version}`,
@@ -21,27 +39,62 @@ class HttpClientImpl {
21
39
  async delete(url, config) {
22
40
  const baseUrl = await configService.getValueForKey('API_BASE_URL');
23
41
  const urlWithHost = url.startsWith('http') ? url : baseUrl + url;
24
- return axios.delete(urlWithHost, { ...config, headers: { ...this.baseHeaders, ...config?.headers } });
42
+ const proxyAgent = getProxyAgent(urlWithHost);
43
+ const axiosConfig = {
44
+ ...config,
45
+ headers: { ...this.baseHeaders, ...config?.headers },
46
+ ...(proxyAgent && urlWithHost.startsWith('https://') ? { httpsAgent: proxyAgent, proxy: false } : {}),
47
+ ...(proxyAgent && urlWithHost.startsWith('http://') ? { httpAgent: proxyAgent, proxy: false } : {}),
48
+ };
49
+ return axios.delete(urlWithHost, axiosConfig);
25
50
  }
26
51
  async get(url, config) {
27
52
  const baseUrl = await configService.getValueForKey('API_BASE_URL');
28
53
  const urlWithHost = url.startsWith('http') ? url : baseUrl + url;
29
- return axios.get(urlWithHost, { ...config, headers: { ...this.baseHeaders, ...config?.headers } });
54
+ const proxyAgent = getProxyAgent(urlWithHost);
55
+ const axiosConfig = {
56
+ ...config,
57
+ headers: { ...this.baseHeaders, ...config?.headers },
58
+ ...(proxyAgent && urlWithHost.startsWith('https://') ? { httpsAgent: proxyAgent, proxy: false } : {}),
59
+ ...(proxyAgent && urlWithHost.startsWith('http://') ? { httpAgent: proxyAgent, proxy: false } : {}),
60
+ };
61
+ return axios.get(urlWithHost, axiosConfig);
30
62
  }
31
63
  async patch(url, data, config) {
32
64
  const baseUrl = await configService.getValueForKey('API_BASE_URL');
33
65
  const urlWithHost = url.startsWith('http') ? url : baseUrl + url;
34
- return axios.patch(urlWithHost, data, { ...config, headers: { ...this.baseHeaders, ...config?.headers } });
66
+ const proxyAgent = getProxyAgent(urlWithHost);
67
+ const axiosConfig = {
68
+ ...config,
69
+ headers: { ...this.baseHeaders, ...config?.headers },
70
+ ...(proxyAgent && urlWithHost.startsWith('https://') ? { httpsAgent: proxyAgent, proxy: false } : {}),
71
+ ...(proxyAgent && urlWithHost.startsWith('http://') ? { httpAgent: proxyAgent, proxy: false } : {}),
72
+ };
73
+ return axios.patch(urlWithHost, data, axiosConfig);
35
74
  }
36
75
  async post(url, data, config) {
37
76
  const baseUrl = await configService.getValueForKey('API_BASE_URL');
38
77
  const urlWithHost = url.startsWith('http') ? url : baseUrl + url;
39
- return axios.post(urlWithHost, data, { ...config, headers: { ...this.baseHeaders, ...config?.headers } });
78
+ const proxyAgent = getProxyAgent(urlWithHost);
79
+ const axiosConfig = {
80
+ ...config,
81
+ headers: { ...this.baseHeaders, ...config?.headers },
82
+ ...(proxyAgent && urlWithHost.startsWith('https://') ? { httpsAgent: proxyAgent, proxy: false } : {}),
83
+ ...(proxyAgent && urlWithHost.startsWith('http://') ? { httpAgent: proxyAgent, proxy: false } : {}),
84
+ };
85
+ return axios.post(urlWithHost, data, axiosConfig);
40
86
  }
41
87
  async put(url, data, config) {
42
88
  const baseUrl = await configService.getValueForKey('API_BASE_URL');
43
89
  const urlWithHost = url.startsWith('http') ? url : baseUrl + url;
44
- return axios.put(urlWithHost, data, { ...config, headers: { ...this.baseHeaders, ...config?.headers } });
90
+ const proxyAgent = getProxyAgent(urlWithHost);
91
+ const axiosConfig = {
92
+ ...config,
93
+ headers: { ...this.baseHeaders, ...config?.headers },
94
+ ...(proxyAgent && urlWithHost.startsWith('https://') ? { httpsAgent: proxyAgent, proxy: false } : {}),
95
+ ...(proxyAgent && urlWithHost.startsWith('http://') ? { httpAgent: proxyAgent, proxy: false } : {}),
96
+ };
97
+ return axios.put(urlWithHost, data, axiosConfig);
45
98
  }
46
99
  }
47
100
  let httpClient = new HttpClientImpl();
@@ -1,6 +1,6 @@
1
- import { beforeEach, describe, expect, it, vi } from 'vitest';
2
- import nock from 'nock';
3
1
  import configService from '../services/config.js';
2
+ import nock from 'nock';
3
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
4
4
  // Mock the config service
5
5
  vi.mock('@/services/config.js', () => ({
6
6
  default: {
@@ -8,9 +8,21 @@ vi.mock('@/services/config.js', () => ({
8
8
  },
9
9
  }));
10
10
  describe('http-client', () => {
11
+ let originalEnv;
11
12
  beforeEach(() => {
13
+ // Save original environment variables
14
+ originalEnv = { ...process.env };
12
15
  nock.cleanAll();
13
16
  vi.clearAllMocks();
17
+ // Clear proxy environment variables
18
+ delete process.env.HTTP_PROXY;
19
+ delete process.env.http_proxy;
20
+ delete process.env.HTTPS_PROXY;
21
+ delete process.env.https_proxy;
22
+ });
23
+ afterEach(() => {
24
+ // Restore original environment variables
25
+ process.env = originalEnv;
14
26
  });
15
27
  it('should retry requests on 5xx status codes', async () => {
16
28
  // Mock the API_BASE_URL
@@ -69,4 +81,19 @@ describe('http-client', () => {
69
81
  expect(response.data).toEqual({ recovered: true });
70
82
  expect(nock.isDone()).toBe(true);
71
83
  });
84
+ it('should work without proxy when no environment variables are set', async () => {
85
+ vi.mocked(configService.getValueForKey).mockResolvedValue('https://api.example.com');
86
+ nock('https://api.example.com').get('/no-proxy').reply(200, { success: true });
87
+ const { default: httpClient } = await import('./http-client.js');
88
+ const response = await httpClient.get('/no-proxy');
89
+ expect(response.status).toBe(200);
90
+ expect(response.data).toEqual({ success: true });
91
+ });
92
+ // Note: Testing actual proxy behavior with nock is not reliable as nock intercepts
93
+ // requests at a different level than proxy agents. The proxy functionality is handled
94
+ // by the http-proxy-agent and https-proxy-agent libraries which are well-tested.
95
+ // The implementation ensures that:
96
+ // - HTTPS requests use HttpsProxyAgent when https_proxy/HTTPS_PROXY is set
97
+ // - HTTP requests use HttpProxyAgent when http_proxy/HTTP_PROXY is set
98
+ // - HTTP proxies (http://) work correctly for HTTPS targets (https://)
72
99
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capawesome/cli",
3
- "version": "3.5.0",
3
+ "version": "3.6.0",
4
4
  "description": "The Capawesome Cloud Command Line Interface (CLI) to manage Live Updates and more.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -13,7 +13,7 @@
13
13
  "fmt": "npm run prettier -- --write",
14
14
  "prettier": "prettier \"**/*.{css,html,ts,js}\"",
15
15
  "sentry:releases:new": "sentry-cli releases new capawesome-team-cli@$npm_package_version --org genz-it-solutions-gmbh --project capawesome-team-cli",
16
- "sentry:releases:set-commits": "sentry-cli releases set-commits capawesome-team-cli@$npm_package_version --auto --org genz-it-solutions-gmbh --project capawesome-team-cli",
16
+ "sentry:releases:set-commits": "sentry-cli releases set-commits capawesome-team-cli@$npm_package_version --auto --org genz-it-solutions-gmbh --project capawesome-team-cli --ignore-missing",
17
17
  "sentry:releases:finalize": "sentry-cli releases finalize capawesome-team-cli@$npm_package_version --org genz-it-solutions-gmbh --project capawesome-team-cli",
18
18
  "release": "commit-and-tag-version",
19
19
  "prepublishOnly": "npm run build && npm run sentry:releases:new && npm run sentry:releases:set-commits",
@@ -61,6 +61,8 @@
61
61
  "c12": "2.0.1",
62
62
  "consola": "3.3.0",
63
63
  "form-data": "4.0.4",
64
+ "http-proxy-agent": "7.0.2",
65
+ "https-proxy-agent": "7.0.6",
64
66
  "mime": "4.0.7",
65
67
  "open": "10.2.0",
66
68
  "rc9": "2.1.2",