@reportportal/client-javascript 5.5.3 → 5.5.5
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 +42 -29
- package/VERSION +1 -1
- package/lib/proxyHelper.js +47 -20
- package/lib/rest.js +36 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -119,34 +119,31 @@ 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 |
|
|
122
|
+
| restClientConfig | Optional | Not set | Check the details in the [HTTP client config](#http-client-options). |
|
|
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. |
|
|
126
126
|
|
|
127
|
-
|
|
127
|
+
### HTTP client options
|
|
128
128
|
|
|
129
|
-
|
|
130
|
-
If you want the client to report through the asynchronous API, change `v1` to `v2` in the `endpoint` address.
|
|
129
|
+
`axios` like http client [config](https://github.com/axios/axios#request-config).
|
|
131
130
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
Each method (except checkConnect) returns an object in a specific format:
|
|
135
|
-
```javascript
|
|
136
|
-
{
|
|
137
|
-
tempId: '4ds43fs', // generated by the client id for further work with the created item
|
|
138
|
-
promise: Promise // An object indicating the completion of an operation
|
|
139
|
-
}
|
|
140
|
-
```
|
|
141
|
-
The client works synchronously, so it is not necessary to wait for the end of the previous requests to send following ones.
|
|
142
|
-
|
|
143
|
-
### Timeout (30000ms) on axios requests
|
|
131
|
+
#### Timeout (30000ms) on axios requests
|
|
144
132
|
|
|
145
133
|
There is a timeout on axios requests. If for instance the server your making a request to is taking too long to load, then axios timeout will work and you will see the error 'Error: timeout of 30000ms exceeded'.
|
|
146
134
|
|
|
147
135
|
You can simply change this timeout by adding a `timeout` property to `restClientConfig` with your desired numeric value (in _ms_) or *0* to disable it.
|
|
148
136
|
|
|
149
|
-
|
|
137
|
+
#### Debug
|
|
138
|
+
|
|
139
|
+
Use `debug: true` for debugging.
|
|
140
|
+
|
|
141
|
+
#### Agent
|
|
142
|
+
|
|
143
|
+
Use `agent` property to provide [http(s)](https://nodejs.org/api/https.html#https_https_request_url_options_callback) agent options.
|
|
144
|
+
Use this property in case the direct `httpAgent/httpsAgent` instance property cannot be used due to config serializations.
|
|
145
|
+
|
|
146
|
+
#### Retry configuration
|
|
150
147
|
|
|
151
148
|
The client retries failed HTTP calls up to 6 times with an exponential backoff (starting at 200 ms and capping at 5 s) and resets the axios timeout before each retry. Provide a `retry` option in `restClientConfig` to change that behaviour. The value can be either a number (overriding just the retry count) or a full [`axios-retry` configuration object](https://github.com/softonic/axios-retry#options):
|
|
152
149
|
|
|
@@ -166,13 +163,13 @@ const client = new RPClient({
|
|
|
166
163
|
|
|
167
164
|
Setting `retry: 0` disables automatic retries.
|
|
168
165
|
|
|
169
|
-
|
|
166
|
+
#### Proxy configuration
|
|
170
167
|
|
|
171
168
|
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
169
|
|
|
173
|
-
|
|
170
|
+
##### Basic proxy configuration
|
|
174
171
|
|
|
175
|
-
|
|
172
|
+
###### Via configuration object
|
|
176
173
|
|
|
177
174
|
```javascript
|
|
178
175
|
const RPClient = require('@reportportal/client-javascript');
|
|
@@ -197,7 +194,7 @@ const rpClient = new RPClient({
|
|
|
197
194
|
});
|
|
198
195
|
```
|
|
199
196
|
|
|
200
|
-
|
|
197
|
+
###### Via proxy URL string
|
|
201
198
|
|
|
202
199
|
```javascript
|
|
203
200
|
const rpClient = new RPClient({
|
|
@@ -208,7 +205,7 @@ const rpClient = new RPClient({
|
|
|
208
205
|
});
|
|
209
206
|
```
|
|
210
207
|
|
|
211
|
-
|
|
208
|
+
###### Via environment variables
|
|
212
209
|
|
|
213
210
|
The client automatically detects and uses proxy environment variables:
|
|
214
211
|
|
|
@@ -218,7 +215,7 @@ export HTTP_PROXY=http://127.0.0.1:8080
|
|
|
218
215
|
export NO_PROXY=localhost,127.0.0.1,.local
|
|
219
216
|
```
|
|
220
217
|
|
|
221
|
-
|
|
218
|
+
##### Bypassing proxy for specific domains (noProxy)
|
|
222
219
|
|
|
223
220
|
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
221
|
|
|
@@ -245,7 +242,7 @@ const rpClient = new RPClient({
|
|
|
245
242
|
|
|
246
243
|
**Priority:** Configuration `noProxy` takes precedence over `NO_PROXY` environment variable.
|
|
247
244
|
|
|
248
|
-
|
|
245
|
+
##### Proxy with OAuth authentication
|
|
249
246
|
|
|
250
247
|
When using OAuth authentication, the proxy configuration is automatically applied to both:
|
|
251
248
|
- OAuth token endpoint requests
|
|
@@ -273,9 +270,9 @@ const rpClient = new RPClient({
|
|
|
273
270
|
});
|
|
274
271
|
```
|
|
275
272
|
|
|
276
|
-
|
|
273
|
+
##### Advanced proxy scenarios
|
|
277
274
|
|
|
278
|
-
|
|
275
|
+
###### Disable proxy explicitly
|
|
279
276
|
|
|
280
277
|
```javascript
|
|
281
278
|
restClientConfig: {
|
|
@@ -283,7 +280,7 @@ restClientConfig: {
|
|
|
283
280
|
}
|
|
284
281
|
```
|
|
285
282
|
|
|
286
|
-
|
|
283
|
+
###### Debug proxy configuration
|
|
287
284
|
|
|
288
285
|
Enable debug mode to see detailed proxy decision logs:
|
|
289
286
|
|
|
@@ -308,7 +305,7 @@ Debug output example:
|
|
|
308
305
|
Proxy URL: https://127.0.0.1:8080
|
|
309
306
|
```
|
|
310
307
|
|
|
311
|
-
|
|
308
|
+
##### Proxy configuration options
|
|
312
309
|
|
|
313
310
|
| Option | Type | Description |
|
|
314
311
|
|---------------------|------------------------------|-------------------------------------------------------------------------------------------------|
|
|
@@ -321,7 +318,7 @@ Debug output example:
|
|
|
321
318
|
| `proxy.auth.password` | `string` | Proxy password |
|
|
322
319
|
| `noProxy` | `string` | Comma-separated list of domains to bypass proxy |
|
|
323
320
|
|
|
324
|
-
|
|
321
|
+
##### How proxy handling works
|
|
325
322
|
|
|
326
323
|
1. **Per-request proxy decision:** Each request (API or OAuth) determines its proxy configuration based on the target URL
|
|
327
324
|
2. **noProxy checking:** URLs matching `noProxy` patterns bypass the proxy and connect directly
|
|
@@ -329,6 +326,22 @@ Debug output example:
|
|
|
329
326
|
4. **Environment variable support:** `HTTP_PROXY`, `HTTPS_PROXY`, and `NO_PROXY` are automatically detected and used if no explicit configuration is provided
|
|
330
327
|
5. **Priority:** Explicit configuration takes precedence over environment variables
|
|
331
328
|
|
|
329
|
+
## Asynchronous reporting
|
|
330
|
+
|
|
331
|
+
The client supports an asynchronous reporting (via the ReportPortal asynchronous API).
|
|
332
|
+
If you want the client to report through the asynchronous API, change `v1` to `v2` in the `endpoint` address.
|
|
333
|
+
|
|
334
|
+
## API
|
|
335
|
+
|
|
336
|
+
Each method (except checkConnect) returns an object in a specific format:
|
|
337
|
+
```javascript
|
|
338
|
+
{
|
|
339
|
+
tempId: '4ds43fs', // generated by the client id for further work with the created item
|
|
340
|
+
promise: Promise // An object indicating the completion of an operation
|
|
341
|
+
}
|
|
342
|
+
```
|
|
343
|
+
The client works synchronously, so it is not necessary to wait for the end of the previous requests to send following ones.
|
|
344
|
+
|
|
332
345
|
### checkConnect
|
|
333
346
|
|
|
334
347
|
`checkConnect` - asynchronous method for verifying the correctness of the client connection
|
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
5.5.
|
|
1
|
+
5.5.6-SNAPSHOT
|
package/lib/proxyHelper.js
CHANGED
|
@@ -136,8 +136,22 @@ function getProxyConfig(url, proxyConfig = {}) {
|
|
|
136
136
|
return null;
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
+
// Cache for proxy agents to enable connection reuse
|
|
140
|
+
const agentCache = new Map();
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Creates a cache key for proxy agents based on proxy URL and protocol
|
|
144
|
+
* @param {string} proxyUrl - The proxy URL
|
|
145
|
+
* @param {boolean} isHttps - Whether target is HTTPS
|
|
146
|
+
* @returns {string} - Cache key
|
|
147
|
+
*/
|
|
148
|
+
function getAgentCacheKey(proxyUrl, isHttps) {
|
|
149
|
+
return `${isHttps ? 'https' : 'http'}:${proxyUrl}`;
|
|
150
|
+
}
|
|
151
|
+
|
|
139
152
|
/**
|
|
140
153
|
* Creates an HTTP/HTTPS agent with proxy configuration for a specific URL
|
|
154
|
+
* Agents are cached and reused to enable connection pooling and keepAlive
|
|
141
155
|
* @param {string} url - The target URL for the request
|
|
142
156
|
* @param {object} restClientConfig - The rest client configuration
|
|
143
157
|
* @returns {object} - Object with httpAgent and/or httpsAgent
|
|
@@ -147,43 +161,56 @@ function createProxyAgents(url, restClientConfig = {}) {
|
|
|
147
161
|
const isHttps = urlObj.protocol === 'https:';
|
|
148
162
|
const proxyConfig = getProxyConfig(url, restClientConfig);
|
|
149
163
|
|
|
164
|
+
// Agent options for connection reuse and keepAlive
|
|
165
|
+
const agentOptions = {
|
|
166
|
+
keepAlive: true,
|
|
167
|
+
keepAliveMsecs: 3000,
|
|
168
|
+
maxSockets: 50,
|
|
169
|
+
maxFreeSockets: 10,
|
|
170
|
+
};
|
|
171
|
+
|
|
150
172
|
if (!proxyConfig) {
|
|
151
173
|
if (restClientConfig.debug) {
|
|
152
174
|
console.log('[ProxyHelper] No proxy for URL (bypassed or not configured):', url);
|
|
153
175
|
console.log(' Using default agent to prevent axios from using env proxy');
|
|
154
176
|
}
|
|
177
|
+
|
|
178
|
+
const cacheKey = getAgentCacheKey('no-proxy', isHttps);
|
|
179
|
+
if (agentCache.has(cacheKey)) {
|
|
180
|
+
return agentCache.get(cacheKey);
|
|
181
|
+
}
|
|
182
|
+
|
|
155
183
|
// Return a default agent to prevent axios from using HTTP_PROXY/HTTPS_PROXY env vars
|
|
156
184
|
// This ensures that URLs in noProxy truly bypass the proxy
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
return {
|
|
163
|
-
httpAgent: new http.Agent(),
|
|
164
|
-
};
|
|
165
|
-
}
|
|
185
|
+
const agents = isHttps
|
|
186
|
+
? { httpsAgent: new https.Agent(agentOptions) }
|
|
187
|
+
: { httpAgent: new http.Agent(agentOptions) };
|
|
188
|
+
agentCache.set(cacheKey, agents);
|
|
189
|
+
return agents;
|
|
166
190
|
}
|
|
167
191
|
|
|
168
192
|
const { proxyUrl } = proxyConfig;
|
|
169
193
|
|
|
194
|
+
const cacheKey = getAgentCacheKey(proxyUrl, isHttps);
|
|
195
|
+
if (agentCache.has(cacheKey)) {
|
|
196
|
+
if (restClientConfig.debug) {
|
|
197
|
+
console.log('[ProxyHelper] Reusing cached proxy agent:', sanitizeUrlForLogging(proxyUrl));
|
|
198
|
+
}
|
|
199
|
+
return agentCache.get(cacheKey);
|
|
200
|
+
}
|
|
201
|
+
|
|
170
202
|
if (restClientConfig.debug) {
|
|
171
203
|
console.log('[ProxyHelper] Creating proxy agent:');
|
|
172
204
|
console.log(' URL:', url);
|
|
173
|
-
console.log(' Protocol:', urlObj.protocol);
|
|
174
205
|
console.log(' Proxy URL:', sanitizeUrlForLogging(proxyUrl));
|
|
175
206
|
}
|
|
176
207
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
return {
|
|
184
|
-
httpAgent: new HttpProxyAgent(proxyUrl),
|
|
185
|
-
};
|
|
186
|
-
}
|
|
208
|
+
const agents = isHttps
|
|
209
|
+
? { httpsAgent: new HttpsProxyAgent(proxyUrl, agentOptions) }
|
|
210
|
+
: { httpAgent: new HttpProxyAgent(proxyUrl, agentOptions) };
|
|
211
|
+
|
|
212
|
+
agentCache.set(cacheKey, agents);
|
|
213
|
+
return agents;
|
|
187
214
|
}
|
|
188
215
|
|
|
189
216
|
/**
|
package/lib/rest.js
CHANGED
|
@@ -10,11 +10,32 @@ const DEFAULT_MAX_CONNECTION_TIME_MS = 30000;
|
|
|
10
10
|
const DEFAULT_RETRY_ATTEMPTS = 6;
|
|
11
11
|
const RETRY_BASE_DELAY_MS = 200;
|
|
12
12
|
const RETRY_MAX_DELAY_MS = 5000;
|
|
13
|
+
|
|
14
|
+
const isTimeoutError = (error) => {
|
|
15
|
+
if (!error) return false;
|
|
16
|
+
const message = error.message ? error.message.toLowerCase() : '';
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
message.includes(`timeout`) ||
|
|
20
|
+
error.code === 'ECONNABORTED' ||
|
|
21
|
+
error.code === 'ETIMEDOUT' ||
|
|
22
|
+
error?.cause?.code === 'ECONNABORTED' ||
|
|
23
|
+
error?.cause?.code === 'ETIMEDOUT'
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const retryCondition = (error) => {
|
|
28
|
+
return axiosRetry.isRetryableError(error) || isTimeoutError(error);
|
|
29
|
+
};
|
|
30
|
+
|
|
13
31
|
const DEFAULT_RETRY_CONFIG = {
|
|
14
|
-
retryDelay: (retryCount = 1) =>
|
|
15
|
-
Math.min(RETRY_BASE_DELAY_MS * 2 ** Math.max(retryCount - 1, 0), RETRY_MAX_DELAY_MS)
|
|
32
|
+
retryDelay: (retryCount = 1) => {
|
|
33
|
+
const base = Math.min(RETRY_BASE_DELAY_MS * 2 ** Math.max(retryCount - 1, 0), RETRY_MAX_DELAY_MS);
|
|
34
|
+
const jitter = Math.random() * 0.4 * base; // +/-40%
|
|
35
|
+
return base - jitter;
|
|
36
|
+
},
|
|
16
37
|
retries: DEFAULT_RETRY_ATTEMPTS,
|
|
17
|
-
retryCondition
|
|
38
|
+
retryCondition,
|
|
18
39
|
shouldResetTimeout: true,
|
|
19
40
|
};
|
|
20
41
|
const SKIPPED_REST_CONFIG_KEYS = ['agent', 'retry', 'proxy', 'noProxy'];
|
|
@@ -65,10 +86,12 @@ class RestClient {
|
|
|
65
86
|
|
|
66
87
|
request(method, url, data, options = {}) {
|
|
67
88
|
// Only apply proxy agents if custom agents are not explicitly provided
|
|
68
|
-
// Priority: explicit httpsAgent/httpAgent > proxy config > default
|
|
89
|
+
// Priority: explicit httpsAgent/httpAgent/agent > proxy config > default
|
|
69
90
|
const hasCustomAgents =
|
|
70
91
|
this.restClientConfig &&
|
|
71
|
-
('httpsAgent' in this.restClientConfig ||
|
|
92
|
+
('httpsAgent' in this.restClientConfig ||
|
|
93
|
+
'httpAgent' in this.restClientConfig ||
|
|
94
|
+
'agent' in this.restClientConfig);
|
|
72
95
|
const proxyAgents = hasCustomAgents ? {} : getProxyAgentForUrl(url, this.restClientConfig);
|
|
73
96
|
const usingProxyAgent = Object.keys(proxyAgents).length > 0;
|
|
74
97
|
|
|
@@ -126,9 +149,15 @@ method: ${method}`,
|
|
|
126
149
|
|
|
127
150
|
getRetryConfig() {
|
|
128
151
|
const retryOption = this.restClientConfig?.retry;
|
|
152
|
+
const onRetry = (retryCount, error, requestConfig) => {
|
|
153
|
+
if (this.restClientConfig.debug) {
|
|
154
|
+
console.log(`[retry #${retryCount}] ${requestConfig.method?.toUpperCase()} ${requestConfig.url} -> ${error.code || error.message}`);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
129
157
|
|
|
130
158
|
if (typeof retryOption === 'number') {
|
|
131
159
|
return {
|
|
160
|
+
onRetry,
|
|
132
161
|
...DEFAULT_RETRY_CONFIG,
|
|
133
162
|
retries: retryOption,
|
|
134
163
|
};
|
|
@@ -136,12 +165,13 @@ method: ${method}`,
|
|
|
136
165
|
|
|
137
166
|
if (retryOption && typeof retryOption === 'object') {
|
|
138
167
|
return {
|
|
168
|
+
onRetry,
|
|
139
169
|
...DEFAULT_RETRY_CONFIG,
|
|
140
170
|
...retryOption,
|
|
141
171
|
};
|
|
142
172
|
}
|
|
143
173
|
|
|
144
|
-
return { ...DEFAULT_RETRY_CONFIG };
|
|
174
|
+
return { onRetry, ...DEFAULT_RETRY_CONFIG };
|
|
145
175
|
}
|
|
146
176
|
|
|
147
177
|
create(path, data, options = {}) {
|