@percy/client 1.27.7 → 1.28.0-beta.0

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 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percy/client",
3
- "version": "1.27.7",
3
+ "version": "1.28.0-beta.0",
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": "latest"
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.27.7",
36
- "@percy/logger": "1.27.7"
35
+ "@percy/env": "1.28.0-beta.0",
36
+ "@percy/logger": "1.28.0-beta.0"
37
37
  },
38
- "gitHead": "eba048142b27b317491f15364b34764371fc0670"
38
+ "gitHead": "d188893f1b45f6e4a1b3196b326a47174340c6ce"
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