@percy/client 1.31.9-beta.3 → 1.31.9-beta.5

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
@@ -158,6 +158,23 @@ export class PercyClient {
158
158
  });
159
159
  }
160
160
 
161
+ // Performs a PATCH request to a JSON API endpoint with appropriate headers.
162
+ patch(path, body = {}, {
163
+ ...meta
164
+ } = {}, customHeaders = {}, raiseIfMissing = true) {
165
+ return logger.measure('client:patch', meta.identifier || 'Unknown', meta, () => {
166
+ return request(`${this.apiUrl}/${path}`, {
167
+ headers: this.headers({
168
+ 'Content-Type': 'application/vnd.api+json',
169
+ ...customHeaders
170
+ }, raiseIfMissing),
171
+ method: 'PATCH',
172
+ body,
173
+ meta
174
+ });
175
+ });
176
+ }
177
+
161
178
  // Creates a build with optional build resources. Only one build can be
162
179
  // created at a time per instance so snapshots and build finalization can be
163
180
  // done more seamlessly without manually tracking build ids
@@ -792,6 +809,80 @@ export class PercyClient {
792
809
  Authorization: `Basic ${base64encode(`${username}:${accessKey}`)}`
793
810
  }, false);
794
811
  }
812
+
813
+ // Updates project domain configuration
814
+ async updateProjectDomainConfig({
815
+ buildId,
816
+ allowedDomains = [],
817
+ errorDomains = []
818
+ } = {}) {
819
+ this.log.debug('Updating domain config');
820
+ // Authentication happens on Project Token so id is not used
821
+ return this.patch('project-domain-configs/cli-test-id', {
822
+ data: {
823
+ type: 'projects',
824
+ attributes: {
825
+ 'domain-config': {
826
+ build_id: buildId,
827
+ allowed_domains: allowedDomains,
828
+ error_domains: errorDomains
829
+ }
830
+ }
831
+ }
832
+ }, {
833
+ identifier: 'project.updateDomainConfig'
834
+ });
835
+ }
836
+
837
+ // Gets project domain configuration including worker URL and allowed/blocked domains
838
+ async getProjectDomainConfig() {
839
+ this.log.debug('Fetching project domain config');
840
+ try {
841
+ var _projectData$attribut, _projectData$attribut2;
842
+ // Authentication happens on Project Token so id is not used
843
+ const response = await this.get('project-domain-configs/cli-test-id');
844
+ const projectData = response === null || response === void 0 ? void 0 : response.data;
845
+ return {
846
+ workerUrl: (projectData === null || projectData === void 0 || (_projectData$attribut = projectData.attributes) === null || _projectData$attribut === void 0 ? void 0 : _projectData$attribut['domain-validator-worker-url']) || null,
847
+ domainConfig: (projectData === null || projectData === void 0 || (_projectData$attribut2 = projectData.attributes) === null || _projectData$attribut2 === void 0 ? void 0 : _projectData$attribut2['domain-config']) || null
848
+ };
849
+ } catch (error) {
850
+ this.log.debug(`Failed to fetch project domain config: ${error.message}`);
851
+ return {
852
+ workerUrl: null,
853
+ domainConfig: null
854
+ };
855
+ }
856
+ }
857
+
858
+ // Validates a domain with the Cloudflare worker endpoint
859
+ async validateDomain(url, options = {}) {
860
+ const {
861
+ validationEndpoint,
862
+ timeout = 5000
863
+ } = options;
864
+ if (!validationEndpoint) {
865
+ throw new Error('Domain validation endpoint URL is required');
866
+ }
867
+ this.log.debug(`Validating domain: ${url} via ${validationEndpoint}`);
868
+ try {
869
+ const response = await request(validationEndpoint, {
870
+ method: 'POST',
871
+ headers: this.headers({
872
+ 'Content-Type': 'application/json'
873
+ }),
874
+ body: JSON.stringify({
875
+ url
876
+ }),
877
+ timeout,
878
+ retries: 0 // Don't retry validation requests
879
+ });
880
+ return response;
881
+ } catch (error) {
882
+ this.log.debug(`Domain validation failed for ${url}: ${error.message}`);
883
+ throw error;
884
+ }
885
+ }
795
886
  mayBeLogUploadSize(contentSize, meta = {}) {
796
887
  if (contentSize >= 25 * 1024 * 1024) {
797
888
  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.9-beta.3",
3
+ "version": "1.31.9-beta.5",
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.31.9-beta.3",
37
- "@percy/env": "1.31.9-beta.3",
38
- "@percy/logger": "1.31.9-beta.3",
36
+ "@percy/config": "1.31.9-beta.5",
37
+ "@percy/env": "1.31.9-beta.5",
38
+ "@percy/logger": "1.31.9-beta.5",
39
39
  "pac-proxy-agent": "^7.0.2",
40
40
  "pako": "^2.1.0"
41
41
  },
42
- "gitHead": "38b33a40a51939de5d35df38b7652840e2bd6d9c"
42
+ "gitHead": "0fa4c3c4560b63cf50ed61a93a8772c745c70b6e"
43
43
  }
package/test/helpers.js CHANGED
@@ -146,6 +146,16 @@ export const api = {
146
146
  '/discovery/device-details': () => [201, {
147
147
  data: []
148
148
  }],
149
+ '/project-domain-configs/cli-test-id': () => [200, {
150
+ data: {
151
+ id: 'domain-config',
152
+ type: 'projects',
153
+ attributes: {
154
+ 'allowed-domains': [],
155
+ 'domain-validator-worker-url': 'https://domain-validator-worker.percy.workers.dev'
156
+ }
157
+ }
158
+ }],
149
159
  '/logs': () => [200, 'random_sha']
150
160
  },
151
161