@reportportal/client-javascript
Advanced tools
Comparing version 5.1.4 to 5.2.0
@@ -25,4 +25,5 @@ const fs = require('fs'); | ||
// TODO: deprecate and remove | ||
getServerResult(url, request, options, method) { | ||
return RestClient.request(method, url, request, options); | ||
return new RestClient(options).request(method, url, request, options); | ||
}, | ||
@@ -29,0 +30,0 @@ |
@@ -44,3 +44,4 @@ /* eslint-disable quotes,no-console,class-methods-use-this */ | ||
'User-Agent': 'NodeJS', | ||
Authorization: `bearer ${this.apiKey}`, | ||
'Content-Type': 'application/json; charset=UTF-8', | ||
Authorization: `Bearer ${this.apiKey}`, | ||
...(this.config.headers || {}), | ||
@@ -134,3 +135,3 @@ }; | ||
const url = [this.config.endpoint.replace('/v2', '/v1'), 'user'].join('/'); | ||
return RestClient.request('GET', url, {}, { headers: this.headers }); | ||
return this.restClient.request('GET', url, {}); | ||
} | ||
@@ -206,3 +207,3 @@ | ||
this.logDebug(`Start launch with tempId ${tempId}`, launchDataRQ); | ||
this.restClient.create(url, launchData, { headers: this.headers }).then( | ||
this.restClient.create(url, launchData).then( | ||
(response) => { | ||
@@ -266,3 +267,3 @@ this.map[tempId].realId = response.id; | ||
const url = ['launch', launchObj.realId, 'finish'].join('/'); | ||
this.restClient.update(url, finishExecutionData, { headers: this.headers }).then( | ||
this.restClient.update(url, finishExecutionData).then( | ||
(response) => { | ||
@@ -339,7 +340,9 @@ this.logDebug(`Success finish launch with tempId ${launchTempId}`, response); | ||
}); | ||
const launchSearchUrl = this.config.mode === 'DEBUG' ? | ||
`launch/mode?${params.toString()}` : `launch?${params.toString()}`; | ||
const launchSearchUrl = | ||
this.config.mode === 'DEBUG' | ||
? `launch/mode?${params.toString()}` | ||
: `launch?${params.toString()}`; | ||
this.logDebug(`Find launches with UUIDs to merge: ${launchUUIds}`); | ||
return this.restClient | ||
.retrieveSyncAPI(launchSearchUrl, { headers: this.headers }) | ||
.retrieveSyncAPI(launchSearchUrl) | ||
.then( | ||
@@ -360,3 +363,3 @@ (response) => { | ||
const mergeURL = 'launch/merge'; | ||
return this.restClient.create(mergeURL, request, { headers: this.headers }); | ||
return this.restClient.create(mergeURL, request); | ||
}) | ||
@@ -430,3 +433,3 @@ .then((response) => { | ||
this.logDebug(`Update launch with tempId ${launchTempId}`, launchData); | ||
this.restClient.update(url, launchData, { headers: this.headers }).then( | ||
this.restClient.update(url, launchData).then( | ||
(response) => { | ||
@@ -539,3 +542,3 @@ this.logDebug(`Launch with tempId ${launchTempId} were successfully updated`, response); | ||
this.logDebug(`Start test item with tempId ${tempId}`, testItemData); | ||
this.restClient.create(url, testItemData, { headers: this.headers }).then( | ||
this.restClient.create(url, testItemData).then( | ||
(response) => { | ||
@@ -727,3 +730,2 @@ this.logDebug(`Success start item with tempId ${tempId}`, response); | ||
Object.assign(saveLogRQ, { launchUuid }, isItemUuid && { itemUuid }), | ||
{ headers: this.headers }, | ||
); | ||
@@ -784,3 +786,2 @@ }; | ||
headers: { | ||
...this.headers, | ||
'Content-Type': `multipart/form-data; boundary=${MULTIPART_BOUNDARY}`, | ||
@@ -848,5 +849,3 @@ }, | ||
this.restClient | ||
.update(url, Object.assign(finishTestItemData, { launchUuid: this.launchUuid }), { | ||
headers: this.headers, | ||
}) | ||
.update(url, Object.assign(finishTestItemData, { launchUuid: this.launchUuid })) | ||
.then( | ||
@@ -853,0 +852,0 @@ (response) => { |
103
lib/rest.js
@@ -5,2 +5,3 @@ const axios = require('axios'); | ||
const https = require('https'); | ||
const logger = require('./logger'); | ||
@@ -21,3 +22,11 @@ const DEFAULT_MAX_CONNECTION_TIME_MS = 30000; | ||
addLogger(this.restClientConfig ? this.restClientConfig.debug : false); | ||
this.axiosInstance = axios.create({ | ||
timeout: DEFAULT_MAX_CONNECTION_TIME_MS, | ||
headers: this.headers, | ||
...this.getRestConfig(this.restClientConfig), | ||
}); | ||
if (this.restClientConfig?.debug) { | ||
logger.addLogger(this.axiosInstance); | ||
} | ||
} | ||
@@ -33,10 +42,14 @@ | ||
static request(method, url, data, options = {}) { | ||
return axios({ | ||
method, | ||
url, | ||
data, | ||
timeout: DEFAULT_MAX_CONNECTION_TIME_MS, | ||
...options, | ||
}) | ||
request(method, url, data, options = {}) { | ||
return this.axiosInstance | ||
.request({ | ||
method, | ||
url, | ||
data, | ||
...options, | ||
headers: { | ||
HOST: new URL(url).host, | ||
...options.headers, | ||
}, | ||
}) | ||
.then((response) => response.data) | ||
@@ -80,38 +93,39 @@ .catch((error) => { | ||
create(path, data, options = { headers: this.headers }) { | ||
return RestClient.request('POST', this.buildPath(path), data, { | ||
create(path, data, options = {}) { | ||
return this.request('POST', this.buildPath(path), data, { | ||
...options, | ||
...this.getRestConfig(), | ||
}); | ||
} | ||
retrieve(path, options = { headers: this.headers }) { | ||
return RestClient.request( | ||
retrieve(path, options = {}) { | ||
return this.request( | ||
'GET', | ||
this.buildPath(path), | ||
{}, | ||
{ ...options, ...this.getRestConfig() }, | ||
{ | ||
...options, | ||
}, | ||
); | ||
} | ||
update(path, data, options = { headers: this.headers }) { | ||
return RestClient.request('PUT', this.buildPath(path), data, { | ||
update(path, data, options = {}) { | ||
return this.request('PUT', this.buildPath(path), data, { | ||
...options, | ||
...this.getRestConfig(), | ||
}); | ||
} | ||
delete(path, data, options = { headers: this.headers }) { | ||
return RestClient.request('DELETE', this.buildPath(path), data, { | ||
delete(path, data, options = {}) { | ||
return this.request('DELETE', this.buildPath(path), data, { | ||
...options, | ||
...this.getRestConfig(), | ||
}); | ||
} | ||
retrieveSyncAPI(path, options = { headers: this.headers }) { | ||
return RestClient.request( | ||
retrieveSyncAPI(path, options = {}) { | ||
return this.request( | ||
'GET', | ||
this.buildPathToSyncAPI(path), | ||
{}, | ||
{ ...options, ...this.getRestConfig() }, | ||
{ | ||
...options, | ||
}, | ||
); | ||
@@ -121,43 +135,2 @@ } | ||
const addLogger = (debug) => { | ||
if (debug) { | ||
axios.interceptors.request.use((config) => { | ||
const startDate = new Date(); | ||
config.startTime = startDate.valueOf(); | ||
console.log(`Request method=${config.method} url=${config.url} [${startDate.toISOString()}]`); | ||
return config; | ||
}); | ||
axios.interceptors.response.use( | ||
(response) => { | ||
const date = new Date(); | ||
const { status, config } = response; | ||
console.log( | ||
`Response status=${status} url=${config.url} time=${ | ||
date.valueOf() - config.startTime | ||
}ms [${date.toISOString()}]`, | ||
); | ||
return response; | ||
}, | ||
(error) => { | ||
const date = new Date(); | ||
const { response, config } = error; | ||
const status = response ? response.status : null; | ||
console.log( | ||
`Response ${status ? 'status=' + status : "message='" + error.message + "'"} url=${ | ||
config.url | ||
} time=${date.valueOf() - config.startTime}ms [${date.toISOString()}]`, | ||
); | ||
return Promise.reject(error); | ||
}, | ||
); | ||
} | ||
}; | ||
module.exports = RestClient; |
{ | ||
"name": "@reportportal/client-javascript", | ||
"version": "5.1.4", | ||
"version": "5.2.0", | ||
"description": "ReportPortal client for Node.js", | ||
@@ -9,6 +9,6 @@ "author": "ReportPortal.io", | ||
"clean": "rimraf ./build", | ||
"lint": "eslint ./statistics/**/* ./lib/**/* ./spec/**/*", | ||
"lint": "eslint ./statistics/**/* ./lib/**/* ./__tests__/**/*", | ||
"format": "npm run lint -- --fix", | ||
"test": "nyc ./node_modules/jasmine/bin/jasmine.js", | ||
"test:coverage": "nyc report --reporter=lcov --reporter=text-summary" | ||
"test": "jest", | ||
"test:coverage": "jest --coverage" | ||
}, | ||
@@ -25,6 +25,6 @@ "directories": { | ||
"engines": { | ||
"node": ">=12.x" | ||
"node": ">=14.x" | ||
}, | ||
"dependencies": { | ||
"axios": "^1.6.8", | ||
"axios": "^1.7.7", | ||
"axios-retry": "^4.1.0", | ||
@@ -38,3 +38,3 @@ "glob": "^8.1.0", | ||
"devDependencies": { | ||
"@types/jasmine": "^4.6.4", | ||
"@types/jest": "^29.5.12", | ||
"@types/node": "^18.19.8", | ||
@@ -50,9 +50,8 @@ "@typescript-eslint/eslint-plugin": "5.62.0", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"jasmine": "^3.10.0", | ||
"jasmine-ts": "^0.4.0", | ||
"jest": "^29.7.0", | ||
"lodash": "^4.17.21", | ||
"nock": "^13.5.0", | ||
"nyc": "^15.1.0", | ||
"prettier": "^2.8.8", | ||
"rimraf": "^3.0.2", | ||
"ts-jest": "^29.1.5", | ||
"ts-node": "^10.9.2", | ||
@@ -59,0 +58,0 @@ "typescript": "^4.9.5" |
@@ -56,20 +56,20 @@ # ReportPortal js client | ||
| Option | Necessity | Default | Description | | ||
|-----------------------|------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ||
| apiKey | Required | | User's reportportal token from which you want to send requests. It can be found on the profile page of this user. | | ||
| 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'. | | ||
| launch | Required | | Name of the launch at creation. | | ||
| project | Required | | The name of the project in which the launches will be created. | | ||
| headers | Optional | {} | The object with custom headers for internal http client. | | ||
| debug | Optional | false | This flag allows seeing the logs of the client. Useful for debugging. | | ||
| 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`. | | ||
| 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`. | | ||
| launchUuidPrint | Optional | false | Whether to print the current launch UUID. | | ||
| 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`. | | ||
| token | Deprecated | Not set | Use `apiKey` instead. | | ||
| Option | Necessity | Default | Description | | ||
|-----------------------|------------|----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ||
| apiKey | Required | | User's reportportal token from which you want to send requests. It can be found on the profile page of this user. | | ||
| 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'. | | ||
| launch | Required | | Name of the launch at creation. | | ||
| project | Required | | The name of the project in which the launches will be created. | | ||
| headers | Optional | {} | The object with custom headers for internal http client. | | ||
| debug | Optional | false | This flag allows seeing the logs of the client. Useful for debugging. | | ||
| 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`. | | ||
| 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`. | | ||
| launchUuidPrint | Optional | false | Whether to print the current launch UUID. | | ||
| 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`. | | ||
| token | Deprecated | Not set | Use `apiKey` instead. | | ||
## Asynchronous reporting | ||
The client supports an asynchronous reporting. | ||
If you want the client to work asynchronously change `v1` to `v2` in addresses in endpoint. | ||
The client supports an asynchronous reporting (via the ReportPortal asynchronous API). | ||
If you want the client to report through the asynchronous API, change `v1` to `v2` in the `endpoint` address. | ||
@@ -76,0 +76,0 @@ ## API |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
82183
19
17
1381
Updatedaxios@^1.7.7