@percy/client 1.27.7 → 1.28.0-beta.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.
- package/dist/client.js +35 -1
- package/dist/utils.js +3 -1
- package/package.json +5 -5
- package/test/helpers.js +11 -0
package/dist/client.js
CHANGED
|
@@ -11,6 +11,7 @@ const {
|
|
|
11
11
|
const pkg = getPackageJSON(import.meta.url);
|
|
12
12
|
// minimum polling interval milliseconds
|
|
13
13
|
const MIN_POLLING_INTERVAL = 1_000;
|
|
14
|
+
const INVALID_TOKEN_ERROR_MESSAGE = 'Unable to retrieve snapshot details with write access token. Kindly use a full access token for retrieving snapshot details with Synchronous CLI.';
|
|
14
15
|
|
|
15
16
|
// Validate ID arguments
|
|
16
17
|
function validateId(type, id) {
|
|
@@ -179,6 +180,35 @@ export class PercyClient {
|
|
|
179
180
|
this.log.debug(`Get build ${buildId}`);
|
|
180
181
|
return this.get(`builds/${buildId}`);
|
|
181
182
|
}
|
|
183
|
+
async getComparisonDetails(comparisonId) {
|
|
184
|
+
validateId('comparison', comparisonId);
|
|
185
|
+
try {
|
|
186
|
+
return await this.get(`comparisons/${comparisonId}?sync=true&response_format=sync-cli`);
|
|
187
|
+
} catch (error) {
|
|
188
|
+
if (error.response.statusCode === 403) {
|
|
189
|
+
throw new Error(INVALID_TOKEN_ERROR_MESSAGE);
|
|
190
|
+
}
|
|
191
|
+
throw error;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
async getSnapshotDetails(snapshotId) {
|
|
195
|
+
validateId('snapshot', snapshotId);
|
|
196
|
+
try {
|
|
197
|
+
return await this.get(`snapshots/${snapshotId}?sync=true&response_format=sync-cli`);
|
|
198
|
+
} catch (error) {
|
|
199
|
+
if (error.response.statusCode === 403) {
|
|
200
|
+
throw new Error(INVALID_TOKEN_ERROR_MESSAGE);
|
|
201
|
+
}
|
|
202
|
+
throw error;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Retrieves snapshot/comparison data by id. Requires a read access token.
|
|
207
|
+
async getStatus(type, ids) {
|
|
208
|
+
if (!['snapshot', 'comparison'].includes(type)) throw new Error('Invalid type passed');
|
|
209
|
+
this.log.debug(`Getting ${type} status for ids ${ids}`);
|
|
210
|
+
return this.get(`job_status?sync=true&type=${type}&id=${ids.join()}`);
|
|
211
|
+
}
|
|
182
212
|
|
|
183
213
|
// Retrieves project builds optionally filtered. Requires a read access token.
|
|
184
214
|
async getBuilds(project, filters = {}) {
|
|
@@ -306,6 +336,7 @@ export class PercyClient {
|
|
|
306
336
|
enableLayout,
|
|
307
337
|
clientInfo,
|
|
308
338
|
environmentInfo,
|
|
339
|
+
sync,
|
|
309
340
|
resources = []
|
|
310
341
|
} = {}) {
|
|
311
342
|
validateId('build', buildId);
|
|
@@ -326,6 +357,7 @@ export class PercyClient {
|
|
|
326
357
|
name: name || null,
|
|
327
358
|
widths: widths || null,
|
|
328
359
|
scope: scope || null,
|
|
360
|
+
sync: !!sync,
|
|
329
361
|
'scope-options': scopeOptions || {},
|
|
330
362
|
'minimum-height': minHeight || null,
|
|
331
363
|
'enable-javascript': enableJavaScript || null,
|
|
@@ -380,7 +412,8 @@ export class PercyClient {
|
|
|
380
412
|
ignoredElementsData,
|
|
381
413
|
domInfoSha,
|
|
382
414
|
consideredElementsData,
|
|
383
|
-
metadata
|
|
415
|
+
metadata,
|
|
416
|
+
sync
|
|
384
417
|
} = {}) {
|
|
385
418
|
validateId('snapshot', snapshotId);
|
|
386
419
|
// Remove post percy api deploy
|
|
@@ -402,6 +435,7 @@ export class PercyClient {
|
|
|
402
435
|
'ignore-elements-data': ignoredElementsData || null,
|
|
403
436
|
'consider-elements-data': consideredElementsData || null,
|
|
404
437
|
'dom-info-sha': domInfoSha || null,
|
|
438
|
+
sync: !!sync,
|
|
405
439
|
metadata: metadata || null
|
|
406
440
|
},
|
|
407
441
|
relationships: {
|
package/dist/utils.js
CHANGED
|
@@ -193,7 +193,9 @@ export async function request(url, options = {}, callback) {
|
|
|
193
193
|
} else {
|
|
194
194
|
var _body, _body$errors, _body$errors$find;
|
|
195
195
|
let err = (_body = body) === null || _body === void 0 ? void 0 : (_body$errors = _body.errors) === null || _body$errors === void 0 ? void 0 : (_body$errors$find = _body$errors.find(e => e.detail)) === null || _body$errors$find === void 0 ? void 0 : _body$errors$find.detail;
|
|
196
|
-
|
|
196
|
+
let statusMessage = `${statusCode} ${res.statusMessage || ''}`;
|
|
197
|
+
let bodyText = (raw === null || raw === void 0 ? void 0 : raw.length) > 0 && res.statusMessage !== raw ? `\n${raw}` : '';
|
|
198
|
+
throw new Error(err || `${statusMessage}${bodyText}`);
|
|
197
199
|
}
|
|
198
200
|
} catch (error) {
|
|
199
201
|
let response = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percy/client",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.28.0-beta.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public",
|
|
12
|
-
"tag": "
|
|
12
|
+
"tag": "beta"
|
|
13
13
|
},
|
|
14
14
|
"engines": {
|
|
15
15
|
"node": ">=14"
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"test:coverage": "yarn test --coverage"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@percy/env": "1.
|
|
36
|
-
"@percy/logger": "1.
|
|
35
|
+
"@percy/env": "1.28.0-beta.1",
|
|
36
|
+
"@percy/logger": "1.28.0-beta.1"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "726fe9b1688c640a4806623d1d34aaafeb79d8c7"
|
|
39
39
|
}
|
package/test/helpers.js
CHANGED
|
@@ -128,6 +128,17 @@ export const api = {
|
|
|
128
128
|
attributes: body.attributes,
|
|
129
129
|
relationships: body.relationships
|
|
130
130
|
}
|
|
131
|
+
}],
|
|
132
|
+
'/job_status?sync=true&type=snapshot&id=4567': () => [201, {
|
|
133
|
+
4567: {
|
|
134
|
+
status: true,
|
|
135
|
+
nextPoll: 8,
|
|
136
|
+
error: null
|
|
137
|
+
}
|
|
138
|
+
}],
|
|
139
|
+
'/snapshots/4567?sync=true&response_format=sync-cli': () => [201, {
|
|
140
|
+
name: 'test snapshot',
|
|
141
|
+
diff_ratio: 0
|
|
131
142
|
}]
|
|
132
143
|
},
|
|
133
144
|
|