@percy/client
Advanced tools
Comparing version 1.30.0 to 1.30.1
@@ -108,6 +108,13 @@ import fs from 'fs'; | ||
// Performs a GET request for an API endpoint with appropriate headers. | ||
get(path) { | ||
return request(`${this.apiUrl}/${path}`, { | ||
headers: this.headers(), | ||
method: 'GET' | ||
// we create a copy of meta as we update it in request and we wont want those updates | ||
// to go back to caller - should be only limited to current function | ||
get(path, { | ||
...meta | ||
} = {}) { | ||
return logger.measure('client:get', meta.identifier, meta, () => { | ||
return request(`${this.apiUrl}/${path}`, { | ||
headers: this.headers(), | ||
method: 'GET', | ||
meta | ||
}); | ||
}); | ||
@@ -117,9 +124,14 @@ } | ||
// Performs a POST request to a JSON API endpoint with appropriate headers. | ||
post(path, body = {}) { | ||
return request(`${this.apiUrl}/${path}`, { | ||
headers: this.headers({ | ||
'Content-Type': 'application/vnd.api+json' | ||
}), | ||
method: 'POST', | ||
body | ||
post(path, body = {}, { | ||
...meta | ||
} = {}) { | ||
return logger.measure('client:post', meta.identifier || 'Unknown', meta, () => { | ||
return request(`${this.apiUrl}/${path}`, { | ||
headers: this.headers({ | ||
'Content-Type': 'application/vnd.api+json' | ||
}), | ||
method: 'POST', | ||
body, | ||
meta | ||
}); | ||
}); | ||
@@ -190,3 +202,5 @@ } | ||
this.log.debug(`Finalizing build ${buildId}...`); | ||
return this.post(`builds/${buildId}/finalize?${qs}`); | ||
return this.post(`builds/${buildId}/finalize?${qs}`, {}, { | ||
identifier: 'build.finalze' | ||
}); | ||
} | ||
@@ -333,3 +347,3 @@ | ||
content | ||
} = {}) { | ||
} = {}, meta = {}) { | ||
validateId('build', buildId); | ||
@@ -343,4 +357,4 @@ if (filepath) { | ||
let encodedContent = base64encode(content); | ||
this.log.debug(`Uploading ${formatBytes(encodedContent.length)} resource: ${url}...`); | ||
this.mayBeLogUploadSize(encodedContent.length); | ||
this.log.debug(`Uploading ${formatBytes(encodedContent.length)} resource: ${url}`, meta); | ||
this.mayBeLogUploadSize(encodedContent.length, meta); | ||
return this.post(`builds/${buildId}/resources`, { | ||
@@ -354,2 +368,5 @@ data: { | ||
} | ||
}, { | ||
identifier: 'resource.post', | ||
...meta | ||
}); | ||
@@ -359,8 +376,14 @@ } | ||
// Uploads resources to the active build concurrently, two at a time. | ||
async uploadResources(buildId, resources) { | ||
async uploadResources(buildId, resources, meta = {}) { | ||
validateId('build', buildId); | ||
this.log.debug(`Uploading resources for ${buildId}...`); | ||
this.log.debug(`Uploading resources for ${buildId}...`, meta); | ||
return pool(function* () { | ||
for (let resource of resources) { | ||
yield this.uploadResource(buildId, resource); | ||
let resourceMeta = { | ||
url: resource.url, | ||
sha: resource.sha, | ||
...meta | ||
}; | ||
yield this.uploadResource(buildId, resource, resourceMeta); | ||
this.log.debug(`Uploaded resource ${resource.url}`, resourceMeta); | ||
} | ||
@@ -385,3 +408,4 @@ }, this, 2); | ||
thTestCaseExecutionId, | ||
resources = [] | ||
resources = [], | ||
meta | ||
} = {}) { | ||
@@ -392,6 +416,6 @@ validateId('build', buildId); | ||
if (!this.clientInfo.size || !this.environmentInfo.size) { | ||
this.log.warn('Warning: Missing `clientInfo` and/or `environmentInfo` properties'); | ||
this.log.warn('Warning: Missing `clientInfo` and/or `environmentInfo` properties', meta); | ||
} | ||
let tagsArr = tagsList(labels); | ||
this.log.debug(`Creating snapshot: ${name}...`); | ||
this.log.debug(`Validating resources: ${name}...`, meta); | ||
for (let resource of resources) { | ||
@@ -401,2 +425,3 @@ if (resource.sha || resource.content || !resource.filepath) continue; | ||
} | ||
this.log.debug(`Creating snapshot: ${name}...`, meta); | ||
return this.post(`builds/${buildId}/snapshots`, { | ||
@@ -433,2 +458,5 @@ data: { | ||
} | ||
}, { | ||
identifier: 'snapshot.post', | ||
...meta | ||
}); | ||
@@ -438,6 +466,9 @@ } | ||
// Finalizes a snapshot. | ||
async finalizeSnapshot(snapshotId) { | ||
async finalizeSnapshot(snapshotId, meta = {}) { | ||
validateId('snapshot', snapshotId); | ||
this.log.debug(`Finalizing snapshot ${snapshotId}...`); | ||
return this.post(`snapshots/${snapshotId}/finalize`); | ||
this.log.debug(`Finalizing snapshot ${snapshotId}...`, meta); | ||
return this.post(`snapshots/${snapshotId}/finalize`, {}, { | ||
identifier: 'snapshot.finalze', | ||
...meta | ||
}); | ||
} | ||
@@ -449,4 +480,9 @@ | ||
var _snapshot$data$relati; | ||
let { | ||
meta = {} | ||
} = options; | ||
let snapshot = await this.createSnapshot(buildId, options); | ||
meta.snapshotId = snapshot.data.id; | ||
let missing = (_snapshot$data$relati = snapshot.data.relationships) === null || _snapshot$data$relati === void 0 || (_snapshot$data$relati = _snapshot$data$relati['missing-resources']) === null || _snapshot$data$relati === void 0 ? void 0 : _snapshot$data$relati.data; | ||
this.log.debug(`${(missing === null || missing === void 0 ? void 0 : missing.length) || 0} Missing resources: ${options.name}...`, meta); | ||
if (missing !== null && missing !== void 0 && missing.length) { | ||
@@ -458,5 +494,7 @@ let resources = options.resources.reduce((acc, r) => Object.assign(acc, { | ||
id | ||
}) => resources[id])); | ||
}) => resources[id]), meta); | ||
} | ||
await this.finalizeSnapshot(snapshot.data.id); | ||
this.log.debug(`Resources uploaded: ${options.name}...`, meta); | ||
await this.finalizeSnapshot(snapshot.data.id, meta); | ||
this.log.debug(`Finalized snapshot: ${options.name}...`, meta); | ||
return snapshot; | ||
@@ -472,7 +510,8 @@ } | ||
metadata, | ||
sync | ||
sync, | ||
meta = {} | ||
} = {}) { | ||
validateId('snapshot', snapshotId); | ||
// Remove post percy api deploy | ||
this.log.debug(`Creating comparision: ${tag.name}...`); | ||
this.log.debug(`Creating comparision: ${tag.name}...`, meta); | ||
for (let tile of tiles) { | ||
@@ -487,2 +526,3 @@ if (tile.sha) continue; | ||
} | ||
this.log.debug(`${tiles.length} tiles for comparision: ${tag.name}...`, meta); | ||
return this.post(`snapshots/${snapshotId}/comparisons`, { | ||
@@ -531,2 +571,5 @@ data: { | ||
} | ||
}, { | ||
identifier: 'comparison.post', | ||
...meta | ||
}); | ||
@@ -540,3 +583,3 @@ } | ||
sha | ||
} = {}) { | ||
} = {}, meta = {}) { | ||
validateId('comparison', comparisonId); | ||
@@ -548,3 +591,3 @@ if (sha) { | ||
let encodedContent = base64encode(content); | ||
this.log.debug(`Uploading ${formatBytes(encodedContent.length)} comparison tile: ${index + 1}/${total} (${comparisonId})...`); | ||
this.log.debug(`Uploading ${formatBytes(encodedContent.length)} comparison tile: ${index + 1}/${total} (${comparisonId})...`, meta); | ||
this.mayBeLogUploadSize(encodedContent.length); | ||
@@ -559,2 +602,5 @@ return this.post(`comparisons/${comparisonId}/tiles`, { | ||
} | ||
}, { | ||
identifier: 'comparison.tile.post', | ||
...meta | ||
}); | ||
@@ -582,5 +628,5 @@ } | ||
} | ||
async verifyComparisonTile(comparisonId, sha) { | ||
async verifyComparisonTile(comparisonId, sha, meta = {}) { | ||
validateId('comparison', comparisonId); | ||
this.log.debug(`Verifying comparison tile with sha: ${sha}`); | ||
this.log.debug(`Verifying comparison tile with sha: ${sha}`, meta); | ||
try { | ||
@@ -594,2 +640,5 @@ return await this.post(`comparisons/${comparisonId}/tiles/verify`, { | ||
} | ||
}, { | ||
identifier: 'comparison.tile.verify', | ||
...meta | ||
}); | ||
@@ -617,8 +666,14 @@ } catch (error) { | ||
} | ||
async finalizeComparison(comparisonId) { | ||
async finalizeComparison(comparisonId, meta = {}) { | ||
validateId('comparison', comparisonId); | ||
this.log.debug(`Finalizing comparison ${comparisonId}...`); | ||
return this.post(`comparisons/${comparisonId}/finalize`); | ||
return this.post(`comparisons/${comparisonId}/finalize`, {}, { | ||
identifier: 'comparison.finalize', | ||
...meta | ||
}); | ||
} | ||
async sendComparison(buildId, options) { | ||
let { | ||
meta | ||
} = options; | ||
if (!validateTiles(options.tiles)) { | ||
@@ -630,6 +685,8 @@ throw new Error('sha, filepath or content should be present in tiles object'); | ||
await this.uploadComparisonTiles(comparison.data.id, options.tiles); | ||
this.log.debug(`Created comparison: ${comparison.data.id} ${options.tag.name}`, meta); | ||
await this.finalizeComparison(comparison.data.id); | ||
this.log.debug(`Finalized comparison: ${comparison.data.id} ${options.tag.name}`, meta); | ||
return comparison; | ||
} | ||
async sendBuildEvents(buildId, body) { | ||
async sendBuildEvents(buildId, body, meta = {}) { | ||
validateId('build', buildId); | ||
@@ -639,22 +696,31 @@ this.log.debug('Sending Build Events'); | ||
data: body | ||
}, { | ||
identifier: 'build.send_events', | ||
...meta | ||
}); | ||
} | ||
async sendBuildLogs(body) { | ||
this.log.debug('Sending Build Logs'); | ||
async sendBuildLogs(body, meta = {}) { | ||
this.log.debug('Sending Build Logs', meta); | ||
return this.post('logs', { | ||
data: body | ||
}, { | ||
identifier: 'build.send_logs', | ||
...meta | ||
}); | ||
} | ||
async getErrorAnalysis(errors) { | ||
async getErrorAnalysis(errors, meta = {}) { | ||
const errorLogs = formatLogErrors(errors); | ||
this.log.debug('Sending error logs for analysis'); | ||
this.log.debug('Sending error logs for analysis', meta); | ||
return this.post('suggestions/from_logs', { | ||
data: errorLogs | ||
}, { | ||
identifier: 'error.analysis.get', | ||
...meta | ||
}); | ||
} | ||
mayBeLogUploadSize(contentSize) { | ||
mayBeLogUploadSize(contentSize, meta = {}) { | ||
if (contentSize >= 25 * 1024 * 1024) { | ||
this.log.error('Uploading resource above 25MB might fail the build...'); | ||
this.log.error('Uploading resource above 25MB might fail the build...', meta); | ||
} else if (contentSize >= 20 * 1024 * 1024) { | ||
this.log.warn('Uploading resource above 20MB might slow the build...'); | ||
this.log.warn('Uploading resource above 20MB might slow the build...', meta); | ||
} | ||
@@ -661,0 +727,0 @@ } |
@@ -131,2 +131,3 @@ import os from 'os'; | ||
buffer, | ||
meta = {}, | ||
...requestOptions | ||
@@ -173,5 +174,13 @@ } = options; | ||
handleError.handled = true; | ||
const response = error.response; | ||
meta.responseCode = error.code; | ||
meta.errorCount = (meta.errorCount || 0) + 1; | ||
if (response) { | ||
meta.responseCode = response.statusCode; | ||
meta.xRequestId = response.headers['x-request-id']; | ||
meta.cfRay = response.headers['cf-ray']; | ||
} | ||
// maybe retry 404s, always retry 500s, or retry specific errors | ||
let shouldRetry = error.response ? retryNotFound && error.response.statusCode === 404 || error.response.statusCode >= 500 && error.response.statusCode < 600 : !!error.code && RETRY_ERROR_CODES.includes(error.code); | ||
let shouldRetry = response ? retryNotFound && response.statusCode === 404 || response.statusCode >= 500 && response.statusCode < 600 : !!error.code && RETRY_ERROR_CODES.includes(error.code); | ||
return shouldRetry ? retry(error) : reject(error); | ||
@@ -188,2 +197,5 @@ }; | ||
if (buffer !== true) body = raw; | ||
meta.responseCode = statusCode; | ||
meta.xRequestId = headers['x-request-id']; | ||
meta.cfRay = headers['cf-ray']; | ||
@@ -190,0 +202,0 @@ // attempt to parse the body as json |
{ | ||
"name": "@percy/client", | ||
"version": "1.30.0", | ||
"version": "1.30.1", | ||
"license": "MIT", | ||
@@ -36,7 +36,7 @@ "repository": { | ||
"dependencies": { | ||
"@percy/env": "1.30.0", | ||
"@percy/logger": "1.30.0", | ||
"@percy/env": "1.30.1", | ||
"@percy/logger": "1.30.1", | ||
"pako": "^2.1.0" | ||
}, | ||
"gitHead": "0f9c627b5100eaf4d7262c6671764ffb38d23d33" | ||
"gitHead": "2f8fc42f57c3989de0c5ceca207854d8f66272d3" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57475
1396
+ Added@percy/env@1.30.1(transitive)
+ Added@percy/logger@1.30.1(transitive)
- Removed@percy/env@1.30.0(transitive)
- Removed@percy/logger@1.30.0(transitive)
Updated@percy/env@1.30.1
Updated@percy/logger@1.30.1