@reportportal/client-javascript 5.5.12 → 5.6.1

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.
Files changed (107) hide show
  1. package/README.md +22 -0
  2. package/VERSION +1 -1
  3. package/build/commons/config.d.ts +5 -0
  4. package/build/commons/config.js +125 -0
  5. package/build/commons/config.js.map +1 -0
  6. package/build/commons/errors.d.ts +9 -0
  7. package/build/commons/errors.js +28 -0
  8. package/build/commons/errors.js.map +1 -0
  9. package/build/constants/events.d.ts +9 -0
  10. package/build/constants/events.js +14 -0
  11. package/build/constants/events.js.map +1 -0
  12. package/build/constants/index.d.ts +7 -0
  13. package/build/constants/index.js +19 -0
  14. package/build/constants/index.js.map +1 -0
  15. package/build/constants/launchModes.d.ts +4 -0
  16. package/build/constants/launchModes.js +9 -0
  17. package/build/constants/launchModes.js.map +1 -0
  18. package/build/constants/logLevels.d.ts +9 -0
  19. package/build/constants/logLevels.js +13 -0
  20. package/build/constants/logLevels.js.map +1 -0
  21. package/build/constants/mergeTypes.d.ts +4 -0
  22. package/build/constants/mergeTypes.js +9 -0
  23. package/build/constants/mergeTypes.js.map +1 -0
  24. package/build/constants/outputs.d.ts +2 -0
  25. package/build/constants/outputs.js +35 -0
  26. package/build/constants/outputs.js.map +1 -0
  27. package/build/constants/statuses.d.ts +14 -0
  28. package/build/constants/statuses.js +19 -0
  29. package/build/constants/statuses.js.map +1 -0
  30. package/build/constants/testItemTypes.d.ts +17 -0
  31. package/build/constants/testItemTypes.js +22 -0
  32. package/build/constants/testItemTypes.js.map +1 -0
  33. package/build/helpers.d.ts +22 -0
  34. package/build/helpers.js +110 -0
  35. package/build/helpers.js.map +1 -0
  36. package/build/logger.d.ts +2 -0
  37. package/build/logger.js +28 -0
  38. package/build/logger.js.map +1 -0
  39. package/build/models/common.d.ts +37 -0
  40. package/build/models/common.js +3 -0
  41. package/build/models/common.js.map +1 -0
  42. package/build/models/config.d.ts +97 -0
  43. package/build/models/config.js +3 -0
  44. package/build/models/config.js.map +1 -0
  45. package/build/models/index.d.ts +5 -0
  46. package/build/models/index.js +22 -0
  47. package/build/models/index.js.map +1 -0
  48. package/build/models/reporting.d.ts +11 -0
  49. package/build/models/reporting.js +3 -0
  50. package/build/models/reporting.js.map +1 -0
  51. package/build/models/requests.d.ts +84 -0
  52. package/build/models/requests.js +3 -0
  53. package/build/models/requests.js.map +1 -0
  54. package/build/models/responses.d.ts +87 -0
  55. package/build/models/responses.js +3 -0
  56. package/build/models/responses.js.map +1 -0
  57. package/build/oauth.d.ts +42 -0
  58. package/build/oauth.js +182 -0
  59. package/build/oauth.js.map +1 -0
  60. package/build/pjson.d.ts +2 -0
  61. package/build/pjson.js +28 -0
  62. package/build/pjson.js.map +1 -0
  63. package/build/proxyHelper.d.ts +28 -0
  64. package/build/proxyHelper.js +173 -0
  65. package/build/proxyHelper.js.map +1 -0
  66. package/build/publicReportingAPI.d.ts +37 -0
  67. package/build/publicReportingAPI.js +56 -0
  68. package/build/publicReportingAPI.js.map +1 -0
  69. package/build/report-portal-client.d.ts +99 -0
  70. package/build/report-portal-client.js +607 -0
  71. package/build/report-portal-client.js.map +1 -0
  72. package/build/rest.d.ts +23 -0
  73. package/build/rest.js +205 -0
  74. package/build/rest.js.map +1 -0
  75. package/build/statistics/client-id.d.ts +1 -0
  76. package/build/statistics/client-id.js +73 -0
  77. package/build/statistics/client-id.js.map +1 -0
  78. package/build/statistics/constants.d.ts +11 -0
  79. package/build/statistics/constants.js +52 -0
  80. package/build/statistics/constants.js.map +1 -0
  81. package/build/statistics/statistics.d.ts +19 -0
  82. package/build/statistics/statistics.js +57 -0
  83. package/build/statistics/statistics.js.map +1 -0
  84. package/constants.d.ts +1 -0
  85. package/constants.js +1 -0
  86. package/helpers.d.ts +2 -0
  87. package/helpers.js +1 -0
  88. package/models.d.ts +1 -0
  89. package/package.json +82 -16
  90. package/publicReportingAPI.d.ts +2 -0
  91. package/publicReportingAPI.js +1 -0
  92. package/index.d.ts +0 -443
  93. package/lib/commons/config.js +0 -133
  94. package/lib/commons/errors.js +0 -29
  95. package/lib/constants/events.js +0 -11
  96. package/lib/constants/outputs.js +0 -13
  97. package/lib/constants/statuses.js +0 -12
  98. package/lib/helpers.js +0 -111
  99. package/lib/logger.js +0 -41
  100. package/lib/oauth.js +0 -226
  101. package/lib/proxyHelper.js +0 -232
  102. package/lib/publicReportingAPI.js +0 -92
  103. package/lib/report-portal-client.js +0 -905
  104. package/lib/rest.js +0 -218
  105. package/statistics/client-id.js +0 -46
  106. package/statistics/constants.js +0 -49
  107. package/statistics/statistics.js +0 -63
package/lib/rest.js DELETED
@@ -1,218 +0,0 @@
1
- const axios = require('axios');
2
- const axiosRetry = require('axios-retry').default;
3
- const http = require('http');
4
- const https = require('https');
5
- const logger = require('./logger');
6
- const OAuthInterceptor = require('./oauth');
7
- const { getProxyAgentForUrl } = require('./proxyHelper');
8
-
9
- const DEFAULT_MAX_CONNECTION_TIME_MS = 30000;
10
- const DEFAULT_RETRY_ATTEMPTS = 6;
11
- const RETRY_BASE_DELAY_MS = 200;
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
-
31
- const DEFAULT_RETRY_CONFIG = {
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
- },
37
- retries: DEFAULT_RETRY_ATTEMPTS,
38
- retryCondition,
39
- shouldResetTimeout: true,
40
- };
41
- const SKIPPED_REST_CONFIG_KEYS = ['agent', 'retry', 'proxy', 'noProxy'];
42
-
43
- class RestClient {
44
- constructor(options) {
45
- this.baseURL = options.baseURL;
46
- this.headers = options.headers;
47
- this.restClientConfig = options.restClientConfig;
48
- this.oauthConfig = options.oauthConfig;
49
- this.debug = options.debug;
50
-
51
- this.axiosInstance = axios.create({
52
- timeout: DEFAULT_MAX_CONNECTION_TIME_MS,
53
- headers: this.headers,
54
- ...this.getRestConfig(this.restClientConfig),
55
- });
56
-
57
- // Create and attach OAuth interceptor if OAuth config is provided
58
- // Must be before retry to ensure token is fresh on each retry
59
- if (this.oauthConfig) {
60
- try {
61
- const oauthInterceptor = new OAuthInterceptor({
62
- ...this.oauthConfig,
63
- debug: this.debug,
64
- restClientConfig: this.restClientConfig,
65
- });
66
- oauthInterceptor.attach(this.axiosInstance);
67
- } catch (error) {
68
- console.error('[RestClient] Failed to initialize OAuth interceptor:', error.message);
69
- }
70
- }
71
-
72
- axiosRetry(this.axiosInstance, this.getRetryConfig());
73
-
74
- if (this.restClientConfig?.debug) {
75
- logger.addLogger(this.axiosInstance);
76
- }
77
- }
78
-
79
- buildPath(path) {
80
- return [this.baseURL, path].join('/');
81
- }
82
-
83
- buildPathToSyncAPI(path) {
84
- return [this.baseURL.replace('/v2', '/v1'), path].join('/');
85
- }
86
-
87
- request(method, url, data, options = {}) {
88
- // Only apply proxy agents if custom agents are not explicitly provided
89
- // Priority: explicit httpsAgent/httpAgent/agent > proxy config > default
90
- const hasCustomAgents =
91
- this.restClientConfig &&
92
- ('httpsAgent' in this.restClientConfig ||
93
- 'httpAgent' in this.restClientConfig ||
94
- 'agent' in this.restClientConfig);
95
- const proxyAgents = hasCustomAgents ? {} : getProxyAgentForUrl(url, this.restClientConfig);
96
- const usingProxyAgent = Object.keys(proxyAgents).length > 0;
97
-
98
- return this.axiosInstance
99
- .request({
100
- method,
101
- url,
102
- data,
103
- ...options,
104
- ...proxyAgents,
105
- // Explicitly disable axios built-in proxy when using custom agents
106
- ...(usingProxyAgent && { proxy: false }),
107
- headers: {
108
- HOST: new URL(url).host,
109
- ...options.headers,
110
- },
111
- })
112
- .then((response) => response.data)
113
- .catch((error) => {
114
- const errorMessage = error.message;
115
- const responseData = error.response && error.response.data;
116
- throw new Error(
117
- `${errorMessage}${
118
- responseData && typeof responseData === 'object'
119
- ? `: ${JSON.stringify(responseData)}`
120
- : ''
121
- }
122
- URL: ${url}
123
- method: ${method}`,
124
- );
125
- });
126
- }
127
-
128
- getRestConfig() {
129
- if (!this.restClientConfig) return {};
130
-
131
- const config = Object.keys(this.restClientConfig).reduce((acc, key) => {
132
- if (!SKIPPED_REST_CONFIG_KEYS.includes(key)) {
133
- acc[key] = this.restClientConfig[key];
134
- }
135
- return acc;
136
- }, {});
137
-
138
- if ('agent' in this.restClientConfig) {
139
- const { protocol } = new URL(this.baseURL);
140
- const isHttps = /https:?/;
141
- const isHttpsRequest = isHttps.test(protocol);
142
- config[isHttpsRequest ? 'httpsAgent' : 'httpAgent'] = isHttpsRequest
143
- ? new https.Agent(this.restClientConfig.agent)
144
- : new http.Agent(this.restClientConfig.agent);
145
- }
146
-
147
- return config;
148
- }
149
-
150
- getRetryConfig() {
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
- };
157
-
158
- if (typeof retryOption === 'number') {
159
- return {
160
- onRetry,
161
- ...DEFAULT_RETRY_CONFIG,
162
- retries: retryOption,
163
- };
164
- }
165
-
166
- if (retryOption && typeof retryOption === 'object') {
167
- return {
168
- onRetry,
169
- ...DEFAULT_RETRY_CONFIG,
170
- ...retryOption,
171
- };
172
- }
173
-
174
- return { onRetry, ...DEFAULT_RETRY_CONFIG };
175
- }
176
-
177
- create(path, data, options = {}) {
178
- return this.request('POST', this.buildPath(path), data, {
179
- ...options,
180
- });
181
- }
182
-
183
- retrieve(path, options = {}) {
184
- return this.request(
185
- 'GET',
186
- this.buildPath(path),
187
- {},
188
- {
189
- ...options,
190
- },
191
- );
192
- }
193
-
194
- update(path, data, options = {}) {
195
- return this.request('PUT', this.buildPath(path), data, {
196
- ...options,
197
- });
198
- }
199
-
200
- delete(path, data, options = {}) {
201
- return this.request('DELETE', this.buildPath(path), data, {
202
- ...options,
203
- });
204
- }
205
-
206
- retrieveSyncAPI(path, options = {}) {
207
- return this.request(
208
- 'GET',
209
- this.buildPathToSyncAPI(path),
210
- {},
211
- {
212
- ...options,
213
- },
214
- );
215
- }
216
- }
217
-
218
- module.exports = RestClient;
@@ -1,46 +0,0 @@
1
- const fs = require('fs');
2
- const util = require('util');
3
- const ini = require('ini');
4
- const { randomUUID } = require('crypto');
5
- const { ENCODING, CLIENT_ID_KEY, RP_FOLDER_PATH, RP_PROPERTIES_FILE_PATH } = require('./constants');
6
-
7
- const exists = util.promisify(fs.exists);
8
- const readFile = util.promisify(fs.readFile);
9
- const mkdir = util.promisify(fs.mkdir);
10
- const writeFile = util.promisify(fs.writeFile);
11
-
12
- async function readClientId() {
13
- if (await exists(RP_PROPERTIES_FILE_PATH)) {
14
- const propertiesContent = await readFile(RP_PROPERTIES_FILE_PATH, ENCODING);
15
- const properties = ini.parse(propertiesContent);
16
- return properties[CLIENT_ID_KEY];
17
- }
18
- return null;
19
- }
20
-
21
- async function storeClientId(clientId) {
22
- const properties = {};
23
- if (await exists(RP_PROPERTIES_FILE_PATH)) {
24
- const propertiesContent = await readFile(RP_PROPERTIES_FILE_PATH, ENCODING);
25
- Object.assign(properties, ini.parse(propertiesContent));
26
- }
27
- properties[CLIENT_ID_KEY] = clientId;
28
- const propertiesContent = ini.stringify(properties);
29
- await mkdir(RP_FOLDER_PATH, { recursive: true });
30
- await writeFile(RP_PROPERTIES_FILE_PATH, propertiesContent, ENCODING);
31
- }
32
-
33
- async function getClientId() {
34
- let clientId = await readClientId();
35
- if (!clientId) {
36
- clientId = randomUUID();
37
- try {
38
- await storeClientId(clientId);
39
- } catch (ignore) {
40
- // do nothing on saving error, client ID will be always new
41
- }
42
- }
43
- return clientId;
44
- }
45
-
46
- module.exports = { getClientId };
@@ -1,49 +0,0 @@
1
- const os = require('os');
2
- const path = require('path');
3
- const pjson = require('../package.json');
4
-
5
- const ENCODING = 'utf-8';
6
- const PJSON_VERSION = pjson.version;
7
- const PJSON_NAME = pjson.name;
8
- const CLIENT_ID_KEY = 'client.id';
9
- const RP_FOLDER = '.rp';
10
- const RP_PROPERTIES_FILE = 'rp.properties';
11
- const HOME_DIRECTORY = process.env.RP_CLIENT_JS_HOME || os.homedir();
12
- const RP_FOLDER_PATH = path.join(HOME_DIRECTORY, RP_FOLDER);
13
- const RP_PROPERTIES_FILE_PATH = path.join(RP_FOLDER_PATH, RP_PROPERTIES_FILE);
14
- const CLIENT_INFO = Buffer.from(
15
- 'Ry1XUDU3UlNHOFhMOmVFazhPMGJ0UXZ5MmI2VXVRT19TOFE=',
16
- 'base64',
17
- ).toString('binary');
18
- const [MEASUREMENT_ID, API_KEY] = CLIENT_INFO.split(':');
19
- const EVENT_NAME = 'start_launch';
20
-
21
- function getNodeVersion() {
22
- // A workaround to avoid reference error in case this is not a Node.js application
23
- if (typeof process !== 'undefined') {
24
- if (process.versions) {
25
- const version = process.versions.node;
26
- if (version) {
27
- return `Node.js ${version}`;
28
- }
29
- }
30
- }
31
- return null;
32
- }
33
-
34
- const INTERPRETER = getNodeVersion();
35
-
36
- module.exports = {
37
- ENCODING,
38
- EVENT_NAME,
39
- PJSON_VERSION,
40
- PJSON_NAME,
41
- CLIENT_ID_KEY,
42
- RP_FOLDER,
43
- RP_FOLDER_PATH,
44
- RP_PROPERTIES_FILE,
45
- RP_PROPERTIES_FILE_PATH,
46
- MEASUREMENT_ID,
47
- API_KEY,
48
- INTERPRETER,
49
- };
@@ -1,63 +0,0 @@
1
- const axios = require('axios');
2
- const { MEASUREMENT_ID, API_KEY, PJSON_NAME, PJSON_VERSION, INTERPRETER } = require('./constants');
3
- const { getClientId } = require('./client-id');
4
-
5
- const hasOption = (options, optionName) => {
6
- return Object.prototype.hasOwnProperty.call(options, optionName);
7
- };
8
-
9
- class Statistics {
10
- constructor(eventName, agentParams) {
11
- this.eventName = eventName;
12
- this.eventParams = this.getEventParams(agentParams);
13
- }
14
-
15
- getEventParams(agentParams) {
16
- const params = {
17
- interpreter: INTERPRETER,
18
- client_name: PJSON_NAME,
19
- client_version: PJSON_VERSION,
20
- };
21
- if (agentParams && hasOption(agentParams, 'name') && agentParams.name) {
22
- params.agent_name = agentParams.name;
23
- }
24
- if (agentParams && hasOption(agentParams, 'version') && agentParams.version) {
25
- params.agent_version = agentParams.version;
26
- }
27
- if (
28
- agentParams &&
29
- hasOption(agentParams, 'framework_version') &&
30
- agentParams.framework_version
31
- ) {
32
- params.framework_version = agentParams.framework_version;
33
- }
34
- return params;
35
- }
36
-
37
- setInstanceID(instanceID) {
38
- this.eventParams.instanceID = instanceID;
39
- }
40
-
41
- async trackEvent() {
42
- try {
43
- const requestBody = {
44
- client_id: await getClientId(),
45
- events: [
46
- {
47
- name: this.eventName,
48
- params: this.eventParams,
49
- },
50
- ],
51
- };
52
-
53
- await axios.post(
54
- `https://www.google-analytics.com/mp/collect?measurement_id=${MEASUREMENT_ID}&api_secret=${API_KEY}`,
55
- requestBody,
56
- );
57
- } catch (error) {
58
- console.error(error.message);
59
- }
60
- }
61
- }
62
-
63
- module.exports = Statistics;