@reportportal/client-javascript 5.4.3 → 5.5.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/README.md CHANGED
@@ -52,7 +52,7 @@ rpClient.checkConnect().then(() => {
52
52
 
53
53
  When creating a client instance, you need to specify the following options.
54
54
 
55
- ### Authentication Options
55
+ ### Authentication options
56
56
 
57
57
  The client supports two authentication methods:
58
58
  1. **API Key Authentication** (default)
@@ -67,7 +67,7 @@ Either API key or complete OAuth 2.0 configuration is required to connect to Rep
67
67
  | apiKey | Conditional | | User's ReportPortal API key from which you want to send requests. It can be found on the profile page of this user. *Required only if OAuth is not configured. |
68
68
  | oauth | Conditional | | OAuth 2.0 configuration object. When provided, OAuth authentication will be used instead of API key. See OAuth Configuration below. |
69
69
 
70
- #### OAuth Configuration
70
+ #### OAuth configuration
71
71
 
72
72
  The `oauth` object supports the following properties:
73
73
 
@@ -109,7 +109,7 @@ rpClient.checkConnect().then(() => {
109
109
  });
110
110
  ```
111
111
 
112
- ### General Options
112
+ ### General options
113
113
 
114
114
  | Option | Necessity | Default | Description |
115
115
  |-----------------------|------------|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
@@ -119,7 +119,7 @@ rpClient.checkConnect().then(() => {
119
119
  | headers | Optional | {} | The object with custom headers for internal http client. |
120
120
  | debug | Optional | false | This flag allows seeing the logs of the client. Useful for debugging. |
121
121
  | isLaunchMergeRequired | Optional | false | Allows client to merge launches into one at the end of the run via saving their UUIDs to the temp files at filesystem. At the end of the run launches can be merged using `mergeLaunches` method. Temp file format: `rplaunch-${launch_uuid}.tmp`. |
122
- | restClientConfig | Optional | Not set | `axios` like http client [config](https://github.com/axios/axios#request-config). May contain `agent` property for configure [http(s)](https://nodejs.org/api/https.html#https_https_request_url_options_callback) client, and other client options eg. `timeout`. For debugging and displaying logs you can set `debug: true`. Use the `retry` property (number or [`axios-retry`](https://github.com/softonic/axios-retry#options) config) to customise automatic retries. |
122
+ | restClientConfig | Optional | Not set | `axios` like http client [config](https://github.com/axios/axios#request-config). Supports `proxy` and `noProxy` for proxy configuration (see [Proxy configuration](#proxy-configuration)), `agent` property for [http(s)](https://nodejs.org/api/https.html#https_https_request_url_options_callback) client options, `timeout`, `debug: true` for debugging, and `retry` property (number or [`axios-retry`](https://github.com/softonic/axios-retry#options) config) for automatic retries. |
123
123
  | launchUuidPrint | Optional | false | Whether to print the current launch UUID. |
124
124
  | launchUuidPrintOutput | Optional | 'STDOUT' | Launch UUID printing output. Possible values: 'STDOUT', 'STDERR', 'FILE', 'ENVIRONMENT'. Works only if `launchUuidPrint` set to `true`. File format: `rp-launch-uuid-${launch_uuid}.tmp`. Env variable: `RP_LAUNCH_UUID`. |
125
125
  | token | Deprecated | Not set | Use `apiKey` or `oauth` instead. |
@@ -166,6 +166,169 @@ const client = new RPClient({
166
166
 
167
167
  Setting `retry: 0` disables automatic retries.
168
168
 
169
+ ### Proxy configuration
170
+
171
+ The client supports comprehensive proxy configuration for both HTTP and HTTPS requests, including ReportPortal API calls and OAuth token requests. Proxy settings can be configured via `restClientConfig` or environment variables.
172
+
173
+ #### Basic proxy configuration
174
+
175
+ ##### Via configuration object
176
+
177
+ ```javascript
178
+ const RPClient = require('@reportportal/client-javascript');
179
+
180
+ const rpClient = new RPClient({
181
+ apiKey: 'your_api_key',
182
+ endpoint: 'http://your-instance.com:8080/api/v1',
183
+ launch: 'LAUNCH_NAME',
184
+ project: 'PROJECT_NAME',
185
+ restClientConfig: {
186
+ proxy: {
187
+ protocol: 'https', // 'http' or 'https'
188
+ host: '127.0.0.1',
189
+ port: 8080,
190
+ // Optional authentication
191
+ auth: {
192
+ username: 'proxy-user',
193
+ password: 'proxy-password'
194
+ }
195
+ }
196
+ }
197
+ });
198
+ ```
199
+
200
+ ##### Via proxy URL string
201
+
202
+ ```javascript
203
+ const rpClient = new RPClient({
204
+ // ... other options
205
+ restClientConfig: {
206
+ proxy: 'https://127.0.0.1:8080'
207
+ }
208
+ });
209
+ ```
210
+
211
+ ##### Via environment variables
212
+
213
+ The client automatically detects and uses proxy environment variables:
214
+
215
+ ```bash
216
+ export HTTPS_PROXY=https://127.0.0.1:8080
217
+ export HTTP_PROXY=http://127.0.0.1:8080
218
+ export NO_PROXY=localhost,127.0.0.1,.local
219
+ ```
220
+
221
+ #### Bypassing proxy for specific domains (noProxy)
222
+
223
+ Use the `noProxy` option to exclude specific domains from being proxied. This is useful when some services are accessible directly while others require a proxy.
224
+
225
+ ```javascript
226
+ const rpClient = new RPClient({
227
+ // ... other options
228
+ restClientConfig: {
229
+ proxy: {
230
+ protocol: 'https',
231
+ host: '127.0.0.1',
232
+ port: 8080
233
+ },
234
+ // Bypass proxy for these domains
235
+ noProxy: 'localhost,127.0.0.1,internal.company.com,.local.domain'
236
+ }
237
+ });
238
+ ```
239
+
240
+ **noProxy format:**
241
+ - Exact hostname: `example.com` - matches `example.com` and `sub.example.com`
242
+ - Leading dot: `.example.com` - matches only subdomains like `sub.example.com` (not `example.com` itself)
243
+ - Wildcard: `*` - bypass proxy for all requests
244
+ - Multiple entries: Comma-separated list
245
+
246
+ **Priority:** Configuration `noProxy` takes precedence over `NO_PROXY` environment variable.
247
+
248
+ #### Proxy with OAuth authentication
249
+
250
+ When using OAuth authentication, the proxy configuration is automatically applied to both:
251
+ - OAuth token endpoint requests
252
+ - ReportPortal API requests
253
+
254
+ ```javascript
255
+ const rpClient = new RPClient({
256
+ endpoint: 'http://your-instance.com:8080/api/v1',
257
+ project: 'PROJECT_NAME',
258
+ oauth: {
259
+ tokenEndpoint: 'https://login.microsoftonline.com/.../oauth2/v2.0/token',
260
+ username: 'your-username',
261
+ password: 'your-password',
262
+ clientId: 'your-client-id'
263
+ },
264
+ restClientConfig: {
265
+ proxy: {
266
+ protocol: 'https',
267
+ host: '127.0.0.1',
268
+ port: 8080
269
+ },
270
+ // Example: Use proxy for OAuth, bypass for ReportPortal
271
+ noProxy: 'your-instance.com'
272
+ }
273
+ });
274
+ ```
275
+
276
+ #### Advanced proxy scenarios
277
+
278
+ ##### Disable proxy explicitly
279
+
280
+ ```javascript
281
+ restClientConfig: {
282
+ proxy: false // Disable proxy even if environment variables are set
283
+ }
284
+ ```
285
+
286
+ ##### Debug proxy configuration
287
+
288
+ Enable debug mode to see detailed proxy decision logs:
289
+
290
+ ```javascript
291
+ restClientConfig: {
292
+ proxy: { /* ... */ },
293
+ noProxy: 'localhost,.local',
294
+ debug: true // See proxy-related logs
295
+ }
296
+ ```
297
+
298
+ Debug output example:
299
+ ```
300
+ [ProxyHelper] getProxyConfig called:
301
+ URL: https://login.microsoftonline.com/oauth2/v2.0/token
302
+ Hostname: login.microsoftonline.com
303
+ noProxy from config: localhost,.local
304
+ Should bypass proxy: false
305
+ [ProxyHelper] Creating proxy agent:
306
+ URL: https://login.microsoftonline.com/oauth2/v2.0/token
307
+ Protocol: https:
308
+ Proxy URL: https://127.0.0.1:8080
309
+ ```
310
+
311
+ #### Proxy configuration options
312
+
313
+ | Option | Type | Description |
314
+ |---------------------|------------------------------|-------------------------------------------------------------------------------------------------|
315
+ | `proxy` | `false \| string \| object` | Proxy configuration. Can be `false` (disable), URL string, or configuration object (see below) |
316
+ | `proxy.protocol` | `string` | Proxy protocol: `'http'` or `'https'` |
317
+ | `proxy.host` | `string` | Proxy host address |
318
+ | `proxy.port` | `number` | Proxy port number |
319
+ | `proxy.auth` | `object` | Optional proxy authentication |
320
+ | `proxy.auth.username` | `string` | Proxy username |
321
+ | `proxy.auth.password` | `string` | Proxy password |
322
+ | `noProxy` | `string` | Comma-separated list of domains to bypass proxy |
323
+
324
+ #### How proxy handling works
325
+
326
+ 1. **Per-request proxy decision:** Each request (API or OAuth) determines its proxy configuration based on the target URL
327
+ 2. **noProxy checking:** URLs matching `noProxy` patterns bypass the proxy and connect directly
328
+ 3. **Default agents for bypassed URLs:** When a URL bypasses proxy, a default HTTP/HTTPS agent is used to prevent automatic proxy detection
329
+ 4. **Environment variable support:** `HTTP_PROXY`, `HTTPS_PROXY`, and `NO_PROXY` are automatically detected and used if no explicit configuration is provided
330
+ 5. **Priority:** Explicit configuration takes precedence over environment variables
331
+
169
332
  ### checkConnect
170
333
 
171
334
  `checkConnect` - asynchronous method for verifying the correctness of the client connection
package/VERSION CHANGED
@@ -1 +1 @@
1
- 5.4.4-SNAPSHOT
1
+ 5.5.1-SNAPSHOT
package/lib/oauth.js CHANGED
@@ -1,4 +1,5 @@
1
1
  const axios = require('axios');
2
+ const { getProxyAgentForUrl } = require('./proxyHelper');
2
3
 
3
4
  const TOKEN_REFRESH_THRESHOLD_MS = 60000;
4
5
  const DEFAULT_TOKEN_EXPIRATION_MS = 3600000; // 1 hour in milliseconds
@@ -17,6 +18,7 @@ class OAuthInterceptor {
17
18
  * @param {string} [config.clientSecret] - OAuth client secret (optional)
18
19
  * @param {string} [config.scope] - OAuth scope (optional)
19
20
  * @param {boolean} [config.debug] - Enable debug logging
21
+ * @param {Object} [config.restClientConfig] - REST client configuration for proxy support
20
22
  */
21
23
  constructor(config) {
22
24
  this.tokenEndpoint = config.tokenEndpoint;
@@ -25,7 +27,8 @@ class OAuthInterceptor {
25
27
  this.clientId = config.clientId;
26
28
  this.clientSecret = config.clientSecret;
27
29
  this.scope = config.scope;
28
- this.debug = config.debug || false;
30
+ this.restClientConfig = config.restClientConfig || {};
31
+ this.debug = this.restClientConfig.debug || false;
29
32
 
30
33
  this.accessToken = null;
31
34
  this.refreshToken = null;
@@ -145,10 +148,25 @@ class OAuthInterceptor {
145
148
  params.append('scope', this.scope);
146
149
  }
147
150
 
151
+ // Get proxy agent for token endpoint
152
+ // Only apply if custom agents are not explicitly provided
153
+ const hasCustomAgents = this.restClientConfig.httpsAgent || this.restClientConfig.httpAgent;
154
+ const proxyAgents = hasCustomAgents
155
+ ? {}
156
+ : getProxyAgentForUrl(this.tokenEndpoint, this.restClientConfig);
157
+
158
+ if (this.debug && Object.keys(proxyAgents).length > 0) {
159
+ this.logDebug(`Making token request to ${this.tokenEndpoint} with proxy agent`);
160
+ }
161
+
148
162
  const response = await axios.post(this.tokenEndpoint, params, {
149
163
  headers: {
150
164
  'Content-Type': 'application/x-www-form-urlencoded',
151
165
  },
166
+ ...proxyAgents,
167
+ // Custom agents from restClientConfig (if provided) take precedence
168
+ ...(this.restClientConfig.httpsAgent && { httpsAgent: this.restClientConfig.httpsAgent }),
169
+ ...(this.restClientConfig.httpAgent && { httpAgent: this.restClientConfig.httpAgent }),
152
170
  });
153
171
 
154
172
  const {
@@ -0,0 +1,205 @@
1
+ const { getProxyForUrl } = require('proxy-from-env');
2
+ const { HttpsProxyAgent } = require('https-proxy-agent');
3
+ const { HttpProxyAgent } = require('http-proxy-agent');
4
+ const http = require('http');
5
+ const https = require('https');
6
+
7
+ /**
8
+ * Sanitizes a URL by removing credentials (username/password) for safe logging
9
+ * @param {string} urlString - The URL to sanitize
10
+ * @returns {string} - Sanitized URL with credentials replaced by [REDACTED]
11
+ */
12
+ function sanitizeUrlForLogging(urlString) {
13
+ try {
14
+ const urlObj = new URL(urlString);
15
+ if (urlObj.username || urlObj.password) {
16
+ // Replace credentials with [REDACTED]
17
+ urlObj.username = '[REDACTED]';
18
+ urlObj.password = '';
19
+ return urlObj.toString();
20
+ }
21
+ return urlString;
22
+ } catch (error) {
23
+ // If URL parsing fails, return as-is (likely not a URL)
24
+ return urlString;
25
+ }
26
+ }
27
+
28
+ /**
29
+ * Checks if a URL should bypass proxy based on NO_PROXY patterns
30
+ * @param {string} url - The URL to check
31
+ * @param {string} noProxy - Comma-separated list of domains/patterns to bypass
32
+ * @returns {boolean} - True if proxy should be bypassed
33
+ */
34
+ function shouldBypassProxy(url, noProxy) {
35
+ if (!noProxy) return false;
36
+
37
+ try {
38
+ const urlObj = new URL(url);
39
+ const hostname = urlObj.hostname.toLowerCase();
40
+
41
+ // Split NO_PROXY entries and clean them
42
+ const patterns = noProxy
43
+ .split(',')
44
+ .map((entry) => entry.trim().toLowerCase())
45
+ .filter(Boolean);
46
+
47
+ return patterns.some((pattern) => {
48
+ // Special case: * means bypass all
49
+ if (pattern === '*') return true;
50
+
51
+ // Pattern with leading dot (.example.com) - only matches subdomains
52
+ if (pattern.startsWith('.')) {
53
+ const cleanPattern = pattern.slice(1);
54
+ // Should match sub.example.com but NOT example.com
55
+ return hostname.endsWith(`.${cleanPattern}`);
56
+ }
57
+
58
+ // Pattern without leading dot (example.com) - matches domain and subdomains
59
+ // Exact match
60
+ if (hostname === pattern) return true;
61
+
62
+ // Suffix match (example.com matches sub.example.com)
63
+ if (hostname.endsWith(`.${pattern}`)) return true;
64
+
65
+ return false;
66
+ });
67
+ } catch (error) {
68
+ // If URL parsing fails, don't bypass proxy
69
+ return false;
70
+ }
71
+ }
72
+
73
+ /**
74
+ * Gets proxy configuration for a given URL
75
+ * Checks both environment variables and explicit config
76
+ * @param {string} url - The target URL
77
+ * @param {object} proxyConfig - Explicit proxy configuration from restClientConfig
78
+ * @returns {object|null} - Proxy URL and bypass info, or null if no proxy
79
+ */
80
+ function getProxyConfig(url, proxyConfig = {}) {
81
+ const urlObj = new URL(url);
82
+
83
+ // Check NO_PROXY from config or environment
84
+ const noProxyFromConfig = proxyConfig.noProxy;
85
+ const noProxyFromEnv = process.env.NO_PROXY || process.env.no_proxy || '';
86
+ const noProxy = noProxyFromConfig || noProxyFromEnv;
87
+
88
+ if (proxyConfig.debug) {
89
+ console.log('[ProxyHelper] getProxyConfig called:');
90
+ console.log(' URL:', url);
91
+ console.log(' Hostname:', urlObj.hostname);
92
+ console.log(' noProxy from config:', noProxyFromConfig);
93
+ console.log(' noProxy from env:', noProxyFromEnv);
94
+ console.log(' Final noProxy:', noProxy);
95
+ }
96
+
97
+ // Check if URL should bypass proxy
98
+ const shouldBypass = shouldBypassProxy(url, noProxy);
99
+ if (proxyConfig.debug) {
100
+ console.log(' Should bypass proxy:', shouldBypass);
101
+ }
102
+
103
+ if (shouldBypass) {
104
+ return null;
105
+ }
106
+
107
+ // If proxy is explicitly disabled
108
+ if (proxyConfig.proxy === false) {
109
+ return null;
110
+ }
111
+
112
+ // Priority 1: Explicit proxy configuration object
113
+ if (proxyConfig.proxy && typeof proxyConfig.proxy === 'object') {
114
+ const { protocol: proxyProtocol, host, port, auth } = proxyConfig.proxy;
115
+ if (host && port) {
116
+ let proxyUrl = `${proxyProtocol || 'http'}://${host}:${port}`;
117
+ if (auth) {
118
+ const { username, password } = auth;
119
+ proxyUrl = `${proxyProtocol || 'http'}://${username}:${password}@${host}:${port}`;
120
+ }
121
+ return { proxyUrl };
122
+ }
123
+ }
124
+
125
+ // Priority 2: Explicit proxy URL string
126
+ if (typeof proxyConfig.proxy === 'string') {
127
+ return { proxyUrl: proxyConfig.proxy };
128
+ }
129
+
130
+ // Priority 3: Environment variables (with NO_PROXY support via proxy-from-env)
131
+ const proxyUrlFromEnv = getProxyForUrl(url);
132
+ if (proxyUrlFromEnv) {
133
+ return { proxyUrl: proxyUrlFromEnv };
134
+ }
135
+
136
+ return null;
137
+ }
138
+
139
+ /**
140
+ * Creates an HTTP/HTTPS agent with proxy configuration for a specific URL
141
+ * @param {string} url - The target URL for the request
142
+ * @param {object} restClientConfig - The rest client configuration
143
+ * @returns {object} - Object with httpAgent and/or httpsAgent
144
+ */
145
+ function createProxyAgents(url, restClientConfig = {}) {
146
+ const urlObj = new URL(url);
147
+ const isHttps = urlObj.protocol === 'https:';
148
+ const proxyConfig = getProxyConfig(url, restClientConfig);
149
+
150
+ if (!proxyConfig) {
151
+ if (restClientConfig.debug) {
152
+ console.log('[ProxyHelper] No proxy for URL (bypassed or not configured):', url);
153
+ console.log(' Using default agent to prevent axios from using env proxy');
154
+ }
155
+ // Return a default agent to prevent axios from using HTTP_PROXY/HTTPS_PROXY env vars
156
+ // This ensures that URLs in noProxy truly bypass the proxy
157
+ if (isHttps) {
158
+ return {
159
+ httpsAgent: new https.Agent(),
160
+ };
161
+ } else {
162
+ return {
163
+ httpAgent: new http.Agent(),
164
+ };
165
+ }
166
+ }
167
+
168
+ const { proxyUrl } = proxyConfig;
169
+
170
+ if (restClientConfig.debug) {
171
+ console.log('[ProxyHelper] Creating proxy agent:');
172
+ console.log(' URL:', url);
173
+ console.log(' Protocol:', urlObj.protocol);
174
+ console.log(' Proxy URL:', sanitizeUrlForLogging(proxyUrl));
175
+ }
176
+
177
+ // Create appropriate agent based on target protocol
178
+ if (isHttps) {
179
+ return {
180
+ httpsAgent: new HttpsProxyAgent(proxyUrl),
181
+ };
182
+ } else {
183
+ return {
184
+ httpAgent: new HttpProxyAgent(proxyUrl),
185
+ };
186
+ }
187
+ }
188
+
189
+ /**
190
+ * Gets proxy agent for a specific request URL
191
+ * This is the main function to be used in axios requests
192
+ * @param {string} url - The target URL for the request
193
+ * @param {object} restClientConfig - The rest client configuration
194
+ * @returns {object} - Object with agent configuration for axios
195
+ */
196
+ function getProxyAgentForUrl(url, restClientConfig = {}) {
197
+ return createProxyAgents(url, restClientConfig);
198
+ }
199
+
200
+ module.exports = {
201
+ shouldBypassProxy,
202
+ getProxyConfig,
203
+ createProxyAgents,
204
+ getProxyAgentForUrl,
205
+ };
package/lib/rest.js CHANGED
@@ -4,6 +4,7 @@ const http = require('http');
4
4
  const https = require('https');
5
5
  const logger = require('./logger');
6
6
  const OAuthInterceptor = require('./oauth');
7
+ const { getProxyAgentForUrl } = require('./proxyHelper');
7
8
 
8
9
  const DEFAULT_MAX_CONNECTION_TIME_MS = 30000;
9
10
  const DEFAULT_RETRY_ATTEMPTS = 6;
@@ -16,7 +17,7 @@ const DEFAULT_RETRY_CONFIG = {
16
17
  retryCondition: axiosRetry.isRetryableError,
17
18
  shouldResetTimeout: true,
18
19
  };
19
- const SKIPPED_REST_CONFIG_KEYS = ['agent', 'retry'];
20
+ const SKIPPED_REST_CONFIG_KEYS = ['agent', 'retry', 'proxy', 'noProxy'];
20
21
 
21
22
  class RestClient {
22
23
  constructor(options) {
@@ -39,6 +40,7 @@ class RestClient {
39
40
  const oauthInterceptor = new OAuthInterceptor({
40
41
  ...this.oauthConfig,
41
42
  debug: this.debug,
43
+ restClientConfig: this.restClientConfig,
42
44
  });
43
45
  oauthInterceptor.attach(this.axiosInstance);
44
46
  } catch (error) {
@@ -62,12 +64,19 @@ class RestClient {
62
64
  }
63
65
 
64
66
  request(method, url, data, options = {}) {
67
+ // Only apply proxy agents if custom agents are not explicitly provided
68
+ // Priority: explicit httpsAgent/httpAgent > proxy config > default
69
+ const hasCustomAgents =
70
+ 'httpsAgent' in this.restClientConfig || 'httpAgent' in this.restClientConfig;
71
+ const proxyAgents = hasCustomAgents ? {} : getProxyAgentForUrl(url, this.restClientConfig);
72
+
65
73
  return this.axiosInstance
66
74
  .request({
67
75
  method,
68
76
  url,
69
77
  data,
70
78
  ...options,
79
+ ...proxyAgents,
71
80
  headers: {
72
81
  HOST: new URL(url).host,
73
82
  ...options.headers,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reportportal/client-javascript",
3
- "version": "5.4.3",
3
+ "version": "5.5.0",
4
4
  "description": "ReportPortal client for Node.js",
5
5
  "author": "ReportPortal.io",
6
6
  "scripts": {
@@ -28,7 +28,10 @@
28
28
  "axios": "^1.12.2",
29
29
  "axios-retry": "^4.5.0",
30
30
  "glob": "^8.1.0",
31
+ "http-proxy-agent": "^7.0.2",
32
+ "https-proxy-agent": "^7.0.6",
31
33
  "ini": "^2.0.0",
34
+ "proxy-from-env": "^1.1.0",
32
35
  "uniqid": "^5.4.0",
33
36
  "uuid": "^9.0.1"
34
37
  },