@percy/client 1.31.1-beta.1 → 1.31.1-beta.2
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/dist/client.js +58 -5
- package/package.json +4 -4
package/dist/client.js
CHANGED
|
@@ -119,9 +119,9 @@ export class PercyClient {
|
|
|
119
119
|
// Returns common headers used for each request with additional
|
|
120
120
|
// headers. Throws an error when the token is missing, which is a required
|
|
121
121
|
// authorization header.
|
|
122
|
-
headers(headers) {
|
|
122
|
+
headers(headers, raiseIfMissing = true) {
|
|
123
123
|
return Object.assign({
|
|
124
|
-
Authorization: `Token token=${this.getToken()}`,
|
|
124
|
+
Authorization: `Token token=${this.getToken(raiseIfMissing)}`,
|
|
125
125
|
'User-Agent': this.userAgent()
|
|
126
126
|
}, headers);
|
|
127
127
|
}
|
|
@@ -144,12 +144,13 @@ export class PercyClient {
|
|
|
144
144
|
// Performs a POST request to a JSON API endpoint with appropriate headers.
|
|
145
145
|
post(path, body = {}, {
|
|
146
146
|
...meta
|
|
147
|
-
} = {}) {
|
|
147
|
+
} = {}, customHeaders = {}, raiseIfMissing = true) {
|
|
148
148
|
return logger.measure('client:post', meta.identifier || 'Unknown', meta, () => {
|
|
149
149
|
return request(`${this.apiUrl}/${path}`, {
|
|
150
150
|
headers: this.headers({
|
|
151
|
-
'Content-Type': 'application/vnd.api+json'
|
|
152
|
-
|
|
151
|
+
'Content-Type': 'application/vnd.api+json',
|
|
152
|
+
...customHeaders
|
|
153
|
+
}, raiseIfMissing),
|
|
153
154
|
method: 'POST',
|
|
154
155
|
body,
|
|
155
156
|
meta
|
|
@@ -735,6 +736,58 @@ export class PercyClient {
|
|
|
735
736
|
...meta
|
|
736
737
|
});
|
|
737
738
|
}
|
|
739
|
+
|
|
740
|
+
// Performs a review action (approve, unapprove, reject) on a specific build.
|
|
741
|
+
// This function handles the common logic for sending review requests.
|
|
742
|
+
async reviewBuild(buildId, action, username, accessKey) {
|
|
743
|
+
validateId('build', buildId);
|
|
744
|
+
this.log.debug(`Sending ${action} action for build ${buildId}...`);
|
|
745
|
+
const requestBody = {
|
|
746
|
+
data: {
|
|
747
|
+
attributes: {
|
|
748
|
+
action: action
|
|
749
|
+
},
|
|
750
|
+
relationships: {
|
|
751
|
+
build: {
|
|
752
|
+
data: {
|
|
753
|
+
type: 'builds',
|
|
754
|
+
id: buildId
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
},
|
|
758
|
+
type: 'reviews'
|
|
759
|
+
}
|
|
760
|
+
};
|
|
761
|
+
|
|
762
|
+
// For the review action, we use accessKey and username in custom headers
|
|
763
|
+
// and do not require a project token.
|
|
764
|
+
return this.post('reviews', requestBody, {
|
|
765
|
+
identifier: `build.${action}`
|
|
766
|
+
}, {
|
|
767
|
+
Authorization: `Basic ${base64encode(`${username}:${accessKey}`)}`
|
|
768
|
+
}, false);
|
|
769
|
+
}
|
|
770
|
+
async approveBuild(buildId, username, accessKey) {
|
|
771
|
+
return this.reviewBuild(buildId, 'approve', username, accessKey);
|
|
772
|
+
}
|
|
773
|
+
async unapproveBuild(buildId, username, accessKey) {
|
|
774
|
+
return this.reviewBuild(buildId, 'unapprove', username, accessKey);
|
|
775
|
+
}
|
|
776
|
+
async rejectBuild(buildId, username, accessKey) {
|
|
777
|
+
return this.reviewBuild(buildId, 'reject', username, accessKey);
|
|
778
|
+
}
|
|
779
|
+
async deleteBuild(buildId, username, accessKey) {
|
|
780
|
+
validateId('build', buildId);
|
|
781
|
+
this.log.debug(`Sending Delete action for build ${buildId}...`);
|
|
782
|
+
|
|
783
|
+
// For the delete action, we use accessKey and username in custom headers
|
|
784
|
+
// and do not require a project token.
|
|
785
|
+
return this.post(`builds/${buildId}/delete`, {}, {
|
|
786
|
+
identifier: 'build.delete'
|
|
787
|
+
}, {
|
|
788
|
+
Authorization: `Basic ${base64encode(`${username}:${accessKey}`)}`
|
|
789
|
+
}, false);
|
|
790
|
+
}
|
|
738
791
|
mayBeLogUploadSize(contentSize, meta = {}) {
|
|
739
792
|
if (contentSize >= 25 * 1024 * 1024) {
|
|
740
793
|
this.log.error('Uploading resource above 25MB might fail the build...', meta);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percy/client",
|
|
3
|
-
"version": "1.31.1-beta.
|
|
3
|
+
"version": "1.31.1-beta.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"test:coverage": "yarn test --coverage"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@percy/env": "1.31.1-beta.
|
|
37
|
-
"@percy/logger": "1.31.1-beta.
|
|
36
|
+
"@percy/env": "1.31.1-beta.2",
|
|
37
|
+
"@percy/logger": "1.31.1-beta.2",
|
|
38
38
|
"pac-proxy-agent": "^7.0.2",
|
|
39
39
|
"pako": "^2.1.0"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "809b770761a7a5ad0044e462218452e920a4d1f0"
|
|
42
42
|
}
|