@percy/client 1.32.0-beta.5 → 1.32.0-beta.7

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.
Files changed (2) hide show
  1. package/dist/client.js +51 -1
  2. package/package.json +5 -5
package/dist/client.js CHANGED
@@ -364,12 +364,62 @@ export class PercyClient {
364
364
  }
365
365
 
366
366
  // Retrieves snapshot/comparison data by id. Requires a read access token.
367
+ // For `smartsnap_graph`, the API blocks (sync=true) until the graph job
368
+ // finishes and returns the graph payload directly in the response — there
369
+ // is no separate "data" endpoint to fetch after polling.
367
370
  async getStatus(type, ids) {
368
- if (!['snapshot', 'comparison'].includes(type)) throw new Error('Invalid type passed');
371
+ if (!['snapshot', 'comparison', 'smartsnap_graph'].includes(type)) throw new Error('Invalid type passed');
369
372
  this.log.debug(`Getting ${type} status for ids ${ids}`);
370
373
  return this.get(`job_status?sync=true&type=${type}&id=${ids.join()}`);
371
374
  }
372
375
 
376
+ // SmartSnap endpoints authenticate against the project attached to the
377
+ // current Percy token (via the Authorization header). `generate-graph`
378
+ // takes a `build_id` (sourced from the bundler-emitted stats file) so
379
+ // multiple concurrent storybook builds for the same project don't share
380
+ // Redis state. `snapshot-name-to-commit` is project-scoped only.
381
+ // Graph status is polled through the shared `getStatus()` helper with
382
+ // type `smartsnap_graph` — the sync response returns the graph payload
383
+ // directly on completion.
384
+
385
+ async getSmartsnapSnapshotNameToCommit() {
386
+ var _this$env$git, _this$env$target, _this$env$git2, _this$env$target2;
387
+ this.log.debug('Smartsnap: looking up baselines...');
388
+ const qs = new URLSearchParams();
389
+
390
+ // Same git/PR context `createBuild` sends — the API uses these to predict
391
+ // the base build that *would* be selected if we called createBuild now,
392
+ // without actually creating one. Any missing field means the API falls
393
+ // back through the same strategy chain it would on real build creation.
394
+ if ((_this$env$git = this.env.git) !== null && _this$env$git !== void 0 && _this$env$git.branch) qs.append('branch', this.env.git.branch);
395
+ if ((_this$env$target = this.env.target) !== null && _this$env$target !== void 0 && _this$env$target.branch) qs.append('target_branch', this.env.target.branch);
396
+ if ((_this$env$git2 = this.env.git) !== null && _this$env$git2 !== void 0 && _this$env$git2.sha) qs.append('commit_sha', this.env.git.sha);
397
+ if ((_this$env$target2 = this.env.target) !== null && _this$env$target2 !== void 0 && _this$env$target2.commit) qs.append('target_commit_sha', this.env.target.commit);
398
+ if (this.env.pullRequest != null) qs.append('pull_request_number', String(this.env.pullRequest));
399
+ if (this.env.partial) qs.append('partial', 'true');
400
+ const query = qs.toString();
401
+ return this.get(query ? `smartsnap/snapshot-name-to-commit?${query}` : 'smartsnap/snapshot-name-to-commit', {
402
+ identifier: 'smartsnap.snapshot_name_to_commit'
403
+ });
404
+ }
405
+ async generateSmartsnapGraph(buildId, {
406
+ files,
407
+ modules,
408
+ storybookPaths,
409
+ affectedNodes
410
+ } = {}) {
411
+ this.log.debug(`Smartsnap: enqueueing graph build for build ${buildId}...`);
412
+ return this.post('smartsnap/generate-graph', {
413
+ build_id: buildId,
414
+ files,
415
+ modules,
416
+ storybook_paths: storybookPaths,
417
+ affected_nodes: affectedNodes
418
+ }, {
419
+ identifier: 'smartsnap.generate_graph'
420
+ });
421
+ }
422
+
373
423
  // Returns device details enabled on project associated with given token
374
424
  async getDeviceDetails(buildId) {
375
425
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percy/client",
3
- "version": "1.32.0-beta.5",
3
+ "version": "1.32.0-beta.7",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,11 +33,11 @@
33
33
  "test:coverage": "yarn test --coverage"
34
34
  },
35
35
  "dependencies": {
36
- "@percy/config": "1.32.0-beta.5",
37
- "@percy/env": "1.32.0-beta.5",
38
- "@percy/logger": "1.32.0-beta.5",
36
+ "@percy/config": "1.32.0-beta.7",
37
+ "@percy/env": "1.32.0-beta.7",
38
+ "@percy/logger": "1.32.0-beta.7",
39
39
  "pac-proxy-agent": "^7.0.2",
40
40
  "pako": "^2.1.0"
41
41
  },
42
- "gitHead": "d93415f2cc83533c9c037579e440c6e2a5119920"
42
+ "gitHead": "9f25a93344237c69c9b0d104de0208857d4c8981"
43
43
  }