@reportportal/client-javascript 5.0.11 → 5.0.12

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
@@ -1,9 +1,11 @@
1
1
  # ReportPortal js client
2
+
2
3
  This Client is to communicate with the Report Portal on Node.js.
3
4
 
4
5
  Library is used only for implementors of custom listeners for ReportPortal.
5
6
 
6
7
  ## Already implemented listeners:
8
+
7
9
  * [Jest integration](https://github.com/reportportal/agent-js-jest)
8
10
  * [Cypress integration](https://github.com/reportportal/agent-js-cypress)
9
11
  * [Mocha integration](https://github.com/reportportal/agent-js-mocha)
@@ -19,21 +21,22 @@ Library is used only for implementors of custom listeners for ReportPortal.
19
21
  Examples for test framework integrations from the list above described in [examples](https://github.com/reportportal/examples-js) repository.
20
22
 
21
23
  ## Installation
24
+
22
25
  The latest version is available on npm:
23
26
  ```cmd
24
27
  npm install @reportportal/client-javascript
25
28
  ```
26
29
 
27
- ## Example
30
+ ## Usage example
28
31
 
29
32
  ```javascript
30
33
  const RPClient = require('@reportportal/client-javascript');
31
34
 
32
35
  const rpClient = new RPClient({
33
- token: "00000000-0000-0000-0000-000000000000",
34
- endpoint: "http://your-instance.com:8080/api/v1",
35
- launch: "LAUNCH_NAME",
36
- project: "PROJECT_NAME"
36
+ apiKey: 'reportportalApiKey',
37
+ endpoint: 'http://your-instance.com:8080/api/v1',
38
+ launch: 'LAUNCH_NAME',
39
+ project: 'PROJECT_NAME'
37
40
  });
38
41
 
39
42
  rpClient.checkConnect().then((response) => {
@@ -45,25 +48,29 @@ rpClient.checkConnect().then((response) => {
45
48
  });
46
49
  ```
47
50
 
48
- ## Settings
49
- When creating a client instance, you need to specify the following parameters:
51
+ ## Configuration
52
+
53
+ When creating a client instance, you need to specify the following options:
50
54
 
51
- | Parameter | Description |
52
- |-----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
53
- | token | User's token Report Portal from which you want to send requests. It can be found on the profile page of this user. |
54
- | endpoint | URL of your server. For example, if you visit the page at 'https://server:8080/ui', then endpoint will be equal to 'https://server:8080/api/v1'. |
55
- | launch | Name of launch at creation. |
56
- | project | The name of the project in which the launches will be created. |
57
- | headers | (optional) The object with custom headers for internal http client. |
58
- | debug | (optional) *Default: false.* This flag allows seeing the logs of the client. Useful for debugging. |
59
- | isLaunchMergeRequired | (optional) *Default: false.* Allows client to merge launches into one at the end of the run via saving their UUIDs to the file system. At the end of the run launches can be merged using `mergeLaunches` method. |
60
- | restClientConfig | (optional) The object with `agent` property for configure [http(s)](https://nodejs.org/api/https.html#https_https_request_url_options_callback) client, may contain other client options eg. `timeout`. |
55
+ | Option | Necessity | Default | Description |
56
+ |-----------------------|------------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
57
+ | apiKey | Required | | User's reportportal token from which you want to send requests. It can be found on the profile page of this user. |
58
+ | endpoint | Required | | URL of your server. For example, if you visit the page at 'https://server:8080/ui', then endpoint will be equal to 'https://server:8080/api/v1'. |
59
+ | launch | Required | | Name of launch at creation. |
60
+ | project | Required | | The name of the project in which the launches will be created. |
61
+ | headers | Optional | {} | The object with custom headers for internal http client. |
62
+ | debug | Optional | false | This flag allows seeing the logs of the client. Useful for debugging. |
63
+ | isLaunchMergeRequired | Optional | false | Allows client to merge launches into one at the end of the run via saving their UUIDs to the file system. At the end of the run launches can be merged using `mergeLaunches` method. |
64
+ | restClientConfig | Optional | Not set | The object with `agent` property for configure [http(s)](https://nodejs.org/api/https.html#https_https_request_url_options_callback) client, may contain other client options eg. `timeout`. |
65
+ | token | Deprecated | Not set | Use `apiKey` instead. |
61
66
 
62
67
  ## Asynchronous reporting
68
+
63
69
  The client supports an asynchronous reporting.
64
- If you want the client to work asynchronously change v1 to v2 in addresses in endpoint.
70
+ If you want the client to work asynchronously change `v1` to `v2` in addresses in endpoint.
71
+
72
+ ## API
65
73
 
66
- ## Api
67
74
  Each method (except checkConnect) returns an object in a specific format:
68
75
  ```javascript
69
76
  {
@@ -74,12 +81,15 @@ Each method (except checkConnect) returns an object in a specific format:
74
81
  The client works synchronously, so it is not necessary to wait for the end of the previous requests to send following ones.
75
82
 
76
83
  ### Timeout (30000ms) on axios requests
77
- 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".
84
+
85
+ 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'.
78
86
 
79
87
  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.
80
88
 
81
89
  ### checkConnect
82
- checkConnect - asynchronous method for verifying the correctness of the client connection
90
+
91
+ `checkConnect` - asynchronous method for verifying the correctness of the client connection
92
+
83
93
  ```javascript
84
94
  rpClient.checkConnect().then((response) => {
85
95
  console.log('You have successfully connected to the server.');
@@ -91,19 +101,21 @@ rpClient.checkConnect().then((response) => {
91
101
  ```
92
102
 
93
103
  ### startLaunch
94
- startLaunch - starts a new launch, return temp id that you want to use for all of the items within this launch.
104
+
105
+ `startLaunch` - starts a new launch, return temp id that you want to use for the all items within this launch.
106
+
95
107
  ```javascript
96
108
  const launchObj = rpClient.startLaunch({
97
- name: "Client test",
109
+ name: 'Client test',
98
110
  startTime: rpClient.helpers.now(),
99
- description: "description of the launch",
111
+ description: 'description of the launch',
100
112
  attributes: [
101
113
  {
102
- "key": "yourKey",
103
- "value": "yourValue"
114
+ 'key': 'yourKey',
115
+ 'value': 'yourValue'
104
116
  },
105
117
  {
106
- "value": "yourValue"
118
+ 'value': 'yourValue'
107
119
  }
108
120
  ],
109
121
  //this param used only when you need client to send data into the existing launch
@@ -114,16 +126,17 @@ console.log(launchObj.tempId);
114
126
  The method takes one argument:
115
127
  * launch data object:
116
128
 
117
- Parameter | Description
118
- --------- | -----------
119
- startTime | (optional) start time launch(unix time). Default: rpClient.helpers.now()
120
- name | (optional) launch name. Default: parameter 'launch' specified when creating the client instance
121
- mode | (optional) "DEFAULT" or "DEBUG". Default: "DEFAULT"
122
- description | (optional) description of the launch (supports markdown syntax)
123
- attributes | (optional) array of launch tags
124
- id | id of the existing launch in which tests data would be sent, without this param new launch instance would be created
129
+ | Option | Necessity | Default | Description |
130
+ |-------------|-----------|----------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------|
131
+ | startTime | Optional | rpClient.helpers.now() | (optional) start time launch(unix time). |
132
+ | name | Optional | parameter 'launch' specified when creating the client instance | Name of the launch. |
133
+ | mode | Optional | 'DEFAULT' | 'DEFAULT' - results will be submitted to Launches page, 'DEBUG' - results will be submitted to Debug page. |
134
+ | description | Optional | '' | Description of the launch (supports markdown syntax). |
135
+ | attributes | Optional | [] | Array of launch attributes (tags). |
136
+ | id | Optional | Not set | `ID` of the existing launch in which tests data would be sent, without this param new launch instance will be created. |
137
+
138
+ To get the real launch `ID` (also known as launch `UUID` from database) wait for the returned promise to finish.
125
139
 
126
- To know the real launch id wait for the method to finish. The real id is used by the client in asynchronous reporting.
127
140
  ```javascript
128
141
  const launchObj = rpClient.startLaunch();
129
142
  launchObj.promise.then((response) => {
@@ -149,49 +162,57 @@ If you still want to switch Off Google Analytics, please change env variable.
149
162
  'REPORTPORTAL_CLIENT_JS_NO_ANALYTICS=true'
150
163
 
151
164
  ### finishLaunch
152
- finishLaunch - finish of the launch. After calling this method, you can not add items to the launch.
165
+
166
+ `finishLaunch` - finish of the launch. After calling this method, you can not add items to the launch.
153
167
  The request to finish the launch will be sent only after all items within it have finished.
168
+
154
169
  ```javascript
155
170
  // launchObj - object returned by method 'startLaunch'
156
171
  const launchFinishObj = rpClient.finishLaunch(launchObj.tempId, {
157
172
  endTime: rpClient.helpers.now()
158
173
  });
159
174
  ```
175
+
160
176
  The method takes two arguments:
161
- * id launch (returned by method 'startLaunch')
177
+ * launch `tempId` (returned by the method `startLaunch`)
162
178
  * data object:
163
179
 
164
- Parameter | Description
165
- --------- | -----------
166
- endTime | (optional) end time of launch. Default: rpClient.helpers.now()
167
- status | (optional) status of launch, one of "", "PASSED", "FAILED", "STOPPED", "SKIPPED", "INTERRUPTED", "CANCELLED".
180
+ |Option | Necessity | Default | Description |
181
+ |--------- |-----------|---------|---------------------------------------------------------------------------------------------------|
182
+ |endTime | Optional | rpClient.helpers.now() | End time of the launch. |
183
+ |status | Optional | '' | Status of launch, one of '', 'PASSED', 'FAILED', 'STOPPED', 'SKIPPED', 'INTERRUPTED', 'CANCELLED'. |
168
184
 
169
185
  ### getPromiseFinishAllItems
170
- getPromiseFinishAllItems - returns promise that contains status about all data has been sent to the Report Protal.
171
- This method needed when test frameworks don't wait for async methods and stop processed.
186
+
187
+ `getPromiseFinishAllItems` - returns promise that contains status about all data has been sent to the reportportal.
188
+ This method needed when test frameworks don't wait for async methods until finished.
172
189
 
173
190
  ```javascript
174
- // jasmine example. tempLaunchId - id of the client's process
175
- agent.getPromiseFinishAllItems(agent.tempLaunchId).then(()=> done());
191
+ // jasmine example. tempLaunchId - tempId of the launch started by the current client process
192
+ agent.getPromiseFinishAllItems(agent.tempLaunchId).then(() => done());
176
193
  ```
177
- Parameter | Description
178
- --------- | -----------
179
- tempLaunchId | id of the client's process
194
+
195
+ | Option | Necessity | Default | Description |
196
+ |--------------|-----------|---------|----------------------------|
197
+ | tempLaunchId | Required | | `tempId` of the launch started by the current client process |
180
198
 
181
199
  ### updateLaunch
182
- updateLaunch - updates launch data. Will send a request to the server only after finishing the launch.
200
+
201
+ `updateLaunch` - updates the launch data. Will send a request to the server only after finishing the launch.
202
+
183
203
  ```javascript
184
204
  // launchObj - object returned by method 'startLaunch'
185
205
  rpClient.updateLaunch(
186
- launchObj.tempId, {
206
+ launchObj.tempId,
207
+ {
187
208
  description: 'new launch description',
188
209
  attributes: [
189
210
  {
190
- "key": "yourKey",
191
- "value": "yourValue"
211
+ key: 'yourKey',
212
+ value: 'yourValue'
192
213
  },
193
214
  {
194
- "value": "yourValue"
215
+ value: 'yourValue'
195
216
  }
196
217
  ],
197
218
  mode: 'DEBUG'
@@ -199,18 +220,20 @@ rpClient.updateLaunch(
199
220
  );
200
221
  ```
201
222
  The method takes two arguments:
202
- * id launch (returned by method 'startLaunch')
203
- * data object - may contain the following fields: description, tags, mode. These fields can be looked up in the method "startLaunch".
223
+ * launch `tempId` (returned by the method 'startLaunch')
224
+ * data object - may contain the following fields: `description`, `attributes`, `mode`. These fields can be looked up in the method `startLaunch`.
204
225
 
205
226
  ### startTestItem
206
- startTestItem - starts a new test item.
227
+
228
+ `startTestItem` - starts a new test item.
229
+
207
230
  ```javascript
208
231
  // launchObj - object returned by method 'startLaunch'
209
232
  const suiteObj = rpClient.startTestItem({
210
233
  description: makeid(),
211
234
  name: makeid(),
212
235
  startTime: rpClient.helpers.now(),
213
- type: "SUITE"
236
+ type: 'SUITE'
214
237
  }, launchObj.tempId);
215
238
  const stepObj = rpClient.startTestItem({
216
239
  description: makeid(),
@@ -219,97 +242,101 @@ const stepObj = rpClient.startTestItem({
219
242
  attributes: [
220
243
 
221
244
  {
222
- "key": "yourKey",
223
- "value": "yourValue"
245
+ key: 'yourKey',
246
+ value: 'yourValue'
224
247
  },
225
248
  {
226
- "value": "yourValue"
249
+ value: 'yourValue'
227
250
  }
228
251
  ],
229
- type: "STEP"
252
+ type: 'STEP'
230
253
  }, launchObj.tempId, suiteObj.tempId);
231
254
 
232
255
  ```
233
256
  The method takes three arguments:
234
257
  * test item data object:
235
258
 
236
- Parameter | Description
237
- --------- | -----------
238
- name | item name
239
- type | Item type, one of 'SUITE', 'STORY', 'TEST', 'SCENARIO', 'STEP', 'BEFORE_CLASS', 'BEFORE_GROUPS','BEFORE_METHOD', 'BEFORE_SUITE', 'BEFORE_TEST', 'AFTER_CLASS', 'AFTER_GROUPS', 'AFTER_METHOD', 'AFTER_SUITE', 'AFTER_TEST'
240
- hasStats | (optional) Changes behavior for item of type 'STEP'. When set to true, step is treaten as a test case (entity containig statistics). When false, step becomes a nested step. Default: true
241
- description | (optional) description of the launch (supports markdown syntax)
242
- startTime | (optional) start time item(unix time). Default: rpClient.helpers.now()
243
- attributes | (optional) array of item attributes
244
-
245
- * id launch (returned by method 'startLaunch')
246
- * id parent item (optional) (returned by method 'startTestItem')
259
+ |Option | Necessity | Default | Description |
260
+ |--------- |-----------|------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
261
+ |name | Required | | Test item name |
262
+ |type | Required | | Test item type, one of 'SUITE', 'STORY', 'TEST', 'SCENARIO', 'STEP', 'BEFORE_CLASS', 'BEFORE_GROUPS','BEFORE_METHOD', 'BEFORE_SUITE', 'BEFORE_TEST', 'AFTER_CLASS', 'AFTER_GROUPS', 'AFTER_METHOD', 'AFTER_SUITE', 'AFTER_TEST' |
263
+ |hasStats | Optional | true | Changes behavior for test item of type 'STEP'. When set to `true`, step is treaten as a test case (entity containig statistics). When false, step becomes a nested step. |
264
+ |description | Optional | '' | Description of the test item (supports markdown syntax). |
265
+ |startTime | Optional | rpClient.helpers.now() | Start time of the test item (unix time). |
266
+ |attributes | Optional | [] | Array of the test item attributes. |
247
267
 
268
+ * launch `tempId` (returned by the method `startLaunch`)
269
+ * parent test item `tempId` (*optional*) (returned by method `startTestItem`)
248
270
 
249
271
  ### finishTestItem
250
- finishTestItem - finish of the item. After calling this method, you can not add items to the item.
251
- The request to finish the item will be sent only after all items within it have finished.
272
+
273
+ `finishTestItem` - finish of the test item. After calling this method, you can not add items to the test item.
274
+ The request to finish the test item will be sent only after all test items within it have finished.
275
+
252
276
  ```javascript
253
277
  // itemObj - object returned by method 'startTestItem'
254
278
  rpClient.finishTestItem(itemObj.tempId, {
255
- status: "failed"
279
+ status: 'failed'
256
280
  })
257
281
  ```
258
282
  The method takes two arguments:
259
- * id item (returned by method 'startTestItem')
283
+ * test item `tempId` (returned by the method `startTestItem`)
260
284
  * data object:
261
285
 
262
- Parameter | Description
263
- --------- | -----------
264
- endTime | (optional) end time of launch. Default: rpClient.helpers.now()
265
- status | (optional) item status, one of "", "PASSED", "FAILED", "STOPPED", "SKIPPED", "INTERRUPTED", "CANCELLED". Default: "PASSED".
266
- issue | (optional) object issue. IssueType is required, allowable values: "pb***", "ab***", "si***", "ti***", "nd001". Where *** is locator id
286
+ | Option | Necessity | Default | Description |
287
+ |---------|-----------|------------------------|------------------------------------------------------------------------------------------------------------------------------------------|
288
+ | issue | Optional | true | Test item issue object. `issueType` is required, allowable values: 'pb***', 'ab***', 'si***', 'ti***', 'nd001'. Where `***` is locator id |
289
+ | status | Optional | 'PASSED' | Test item status, one of '', 'PASSED', 'FAILED', 'STOPPED', 'SKIPPED', 'INTERRUPTED', 'CANCELLED'. |
290
+ | endTime | Optional | rpClient.helpers.now() | End time of the launch (unix time). |
267
291
 
268
292
  Example issue object:
269
293
  ```
270
294
  {
271
- issueType: "string",
272
- comment: "string",
295
+ issueType: 'string',
296
+ comment: 'string',
273
297
  externalSystemIssues: [
274
298
  {
275
299
  submitDate: 0,
276
- submitter: "string",
277
- systemId: "string",
278
- ticketId: "string",
279
- url: "string"
300
+ submitter: 'string',
301
+ systemId: 'string',
302
+ ticketId: 'string',
303
+ url: 'string'
280
304
  }
281
305
  ]
282
306
  }
283
307
  ```
284
308
 
285
309
  ### sendLog
286
- sendLog - adds a log to the item
310
+
311
+ `sendLog` - adds a log to the test item.
312
+
287
313
  ```javascript
288
314
  // stepObj - object returned by method 'startTestItem'
289
315
  rpClient.sendLog(stepObj.tempId, {
290
- level: "INFO",
291
- message: makeid(),
316
+ level: 'INFO',
317
+ message: 'User clicks login button',
292
318
  time: rpClient.helpers.now()
293
319
  })
294
320
  ```
295
321
  The method takes three arguments:
296
- * id item (returned by method 'startTestItem')
322
+ * test item `tempId` (returned by method `startTestItem`)
297
323
  * data object:
298
324
 
299
- Parameter | Description
300
- --------- | -----------
301
- time | (optional) time of log. Default: rpClient.helpers.now()
302
- message | (optional) log message. Default: ''.
303
- status | (optional) log status, one of 'trace', 'debug', 'info', 'warn', 'error', ''. Default "".
325
+ | Option | Necessity | Default | Description |
326
+ |---------|-----------|------------------------|----------------------------------------------------------------------|
327
+ | message | Optional | '' | The log message. |
328
+ | level | Optional | '' | The log level, one of 'trace', 'debug', 'info', 'warn', 'error', ''. |
329
+ | time | Optional | rpClient.helpers.now() | The time of the log. |
304
330
 
305
331
  * file object (optional):
306
332
 
307
- Parameter | Description
308
- --------- | -----------
309
- name | file name
310
- type | file mimeType, example "image/png" (support types: 'image/*', application/ ['xml', 'javascript', 'json', 'css', 'php'] , another format will be opened in a new browser tab ),
311
- content | file
333
+ | Option | Necessity | Default | Description |
334
+ |---------|-----------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
335
+ | name | Required | | The name of the file. |
336
+ | type | Required | | The file mimeType, example 'image/png' (support types: 'image/*', application/['xml', 'javascript', 'json', 'css', 'php'], other formats will be opened in reportportal in a new browser tab only). |
337
+ | content | Required | | base64 encoded file content. |
312
338
 
313
339
  # Copyright Notice
340
+
314
341
  Licensed under the [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0.html)
315
342
  license (see the LICENSE.txt file).
package/VERSION CHANGED
@@ -1 +1 @@
1
- 5.0.12-SNAPSHOT
1
+ 5.0.13-SNAPSHOT
@@ -0,0 +1,61 @@
1
+ const { ReportPortalRequiredOptionError, ReportPortalValidationError } = require('./errors');
2
+
3
+ const getRequiredOption = (options, optionName) => {
4
+ if (!Object.prototype.hasOwnProperty.call(options, optionName) || !options[optionName]) {
5
+ throw new ReportPortalRequiredOptionError(optionName);
6
+ }
7
+
8
+ return options[optionName];
9
+ };
10
+
11
+ const getApiKey = ({ apiKey, token }) => {
12
+ let calculatedApiKey = apiKey;
13
+ if (!calculatedApiKey) {
14
+ calculatedApiKey = token;
15
+ if (!calculatedApiKey) {
16
+ throw new ReportPortalRequiredOptionError('apiKey');
17
+ } else {
18
+ console.warn(`Option 'token' is deprecated. Use 'apiKey' instead.`);
19
+ }
20
+ }
21
+
22
+ return calculatedApiKey;
23
+ };
24
+
25
+ const getClientConfig = (options) => {
26
+ let calculatedOptions = options;
27
+ try {
28
+ if (typeof options !== 'object') {
29
+ throw new ReportPortalValidationError('`options` must be an object.');
30
+ }
31
+ const apiKey = getApiKey(options);
32
+ const project = getRequiredOption(options, 'project');
33
+ const endpoint = getRequiredOption(options, 'endpoint');
34
+
35
+ calculatedOptions = {
36
+ apiKey,
37
+ project,
38
+ endpoint,
39
+ launch: options.launch,
40
+ debug: options.debug,
41
+ isLaunchMergeRequired:
42
+ options.isLaunchMergeRequired === undefined ? false : options.isLaunchMergeRequired,
43
+ headers: options.headers,
44
+ restClientConfig: options.restClientConfig,
45
+ attributes: options.attributes,
46
+ mode: options.mode,
47
+ description: options.description,
48
+ };
49
+ } catch (error) {
50
+ // don't throw the error up to not break the entire process
51
+ console.dir(error);
52
+ }
53
+
54
+ return calculatedOptions;
55
+ };
56
+
57
+ module.exports = {
58
+ getClientConfig,
59
+ getRequiredOption,
60
+ getApiKey,
61
+ };
@@ -0,0 +1,29 @@
1
+ class ReportPortalError extends Error {
2
+ constructor(message) {
3
+ const basicMessage = `\nReportPortal client error: ${message}`;
4
+ super(basicMessage);
5
+ this.name = 'ReportPortalError';
6
+ }
7
+ }
8
+
9
+ class ReportPortalValidationError extends ReportPortalError {
10
+ constructor(message) {
11
+ const basicMessage = `\nValidation failed. Please, check the specified parameters: ${message}`;
12
+ super(basicMessage);
13
+ this.name = 'ReportPortalValidationError';
14
+ }
15
+ }
16
+
17
+ class ReportPortalRequiredOptionError extends ReportPortalValidationError {
18
+ constructor(propertyName) {
19
+ const basicMessage = `\nProperty '${propertyName}' must not be empty.`;
20
+ super(basicMessage);
21
+ this.name = 'ReportPortalRequiredOptionError';
22
+ }
23
+ }
24
+
25
+ module.exports = {
26
+ ReportPortalError,
27
+ ReportPortalValidationError,
28
+ ReportPortalRequiredOptionError,
29
+ };
@@ -3,6 +3,7 @@ const UniqId = require('uniqid');
3
3
  const { URLSearchParams } = require('url');
4
4
  const helpers = require('./helpers');
5
5
  const RestClient = require('./rest');
6
+ const { getClientConfig } = require('./commons/config');
6
7
  const Statistics = require('../statistics/statistics');
7
8
  const { EVENT_NAME } = require('../statistics/constants');
8
9
  const { RP_STATUSES } = require('./constants/statuses');
@@ -12,10 +13,10 @@ const MULTIPART_BOUNDARY = Math.floor(Math.random() * 10000000000).toString();
12
13
  class RPClient {
13
14
  /**
14
15
  * Create a client for RP.
15
- * @param {Object} params - config object.
16
- * params should look like this
16
+ * @param {Object} options - config object.
17
+ * options should look like this
17
18
  * {
18
- * token: "00000000-0000-0000-0000-000000000000",
19
+ * apiKey: "reportportalApiKey",
19
20
  * endpoint: "http://localhost:8080/api/v1",
20
21
  * launch: "YOUR LAUNCH NAME",
21
22
  * project: "PROJECT NAME",
@@ -28,24 +29,26 @@ class RPClient {
28
29
  * version: "AGENT VERSION",
29
30
  * }
30
31
  */
31
- constructor(params, agentParams) {
32
- this.debug = params.debug;
33
- this.isLaunchMergeRequired =
34
- params.isLaunchMergeRequired === undefined ? false : params.isLaunchMergeRequired;
32
+ constructor(options, agentParams) {
33
+ this.config = getClientConfig(options);
34
+ this.debug = this.config.debug;
35
+ this.isLaunchMergeRequired = this.config.isLaunchMergeRequired;
36
+ this.apiKey = this.config.apiKey;
37
+ // deprecated
38
+ this.token = this.apiKey;
39
+
35
40
  this.map = {};
36
- this.baseURL = [params.endpoint, params.project].join('/');
41
+ this.baseURL = [this.config.endpoint, this.config.project].join('/');
37
42
  this.headers = {
38
43
  'User-Agent': 'NodeJS',
39
- Authorization: `bearer ${params.token}`,
40
- ...(params.headers || {}),
44
+ Authorization: `bearer ${this.apiKey}`,
45
+ ...(this.config.headers || {}),
41
46
  };
42
- this.token = params.token;
43
- this.config = params;
44
47
  this.helpers = helpers;
45
48
  this.restClient = new RestClient({
46
49
  baseURL: this.baseURL,
47
50
  headers: this.headers,
48
- restClientConfig: params.restClientConfig,
51
+ restClientConfig: this.config.restClientConfig,
49
52
  });
50
53
  this.statistics = new Statistics(EVENT_NAME, agentParams);
51
54
  this.launchUuid = '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reportportal/client-javascript",
3
- "version": "5.0.11",
3
+ "version": "5.0.12",
4
4
  "description": "ReportPortal client for Node.js",
5
5
  "author": "ReportPortal.io",
6
6
  "scripts": {