@percy/client 1.0.0-beta.75 → 1.0.0-beta.76

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
@@ -113,19 +113,19 @@ class PercyClient {
113
113
 
114
114
  get(path) {
115
115
  return (0, _request.default)(`${this.apiUrl}/${path}`, {
116
- method: 'GET',
117
- headers: this.headers()
116
+ headers: this.headers(),
117
+ method: 'GET'
118
118
  });
119
119
  } // Performs a POST request to a JSON API endpoint with appropriate headers.
120
120
 
121
121
 
122
122
  post(path, body = {}) {
123
123
  return (0, _request.default)(`${this.apiUrl}/${path}`, {
124
- method: 'POST',
125
- body: JSON.stringify(body),
126
124
  headers: this.headers({
127
125
  'Content-Type': 'application/vnd.api+json'
128
- })
126
+ }),
127
+ method: 'POST',
128
+ body
129
129
  });
130
130
  } // Creates a build with optional build resources. Only one build can be
131
131
  // created at a time per instance so snapshots and build finalization can be
package/dist/request.js CHANGED
@@ -217,18 +217,17 @@ function proxyAgentFor(url, options) {
217
217
 
218
218
  function request(url, options = {}, callback) {
219
219
  // accept `request(url, callback)`
220
- if (typeof options === 'function') [options, callback] = [{}, options];
220
+ if (typeof options === 'function') [options, callback] = [{}, options]; // gather request options
221
+
221
222
  let {
222
223
  body,
224
+ headers,
223
225
  retries,
224
226
  retryNotFound,
225
227
  interval,
226
228
  noProxy,
227
229
  ...requestOptions
228
- } = options; // allow bypassing proxied requests entirely
229
-
230
- if (!noProxy) requestOptions.agent || (requestOptions.agent = proxyAgentFor(url)); // parse the requested URL into request options
231
-
230
+ } = options;
232
231
  let {
233
232
  protocol,
234
233
  hostname,
@@ -236,13 +235,31 @@ function request(url, options = {}, callback) {
236
235
  pathname,
237
236
  search,
238
237
  hash
239
- } = new URL(url);
238
+ } = new URL(url); // automatically stringify body content
239
+
240
+ if (body && typeof body !== 'string') {
241
+ headers = {
242
+ 'Content-Type': 'application/json',
243
+ ...headers
244
+ };
245
+ body = JSON.stringify(body);
246
+ } // combine request options
247
+
248
+
249
+ Object.assign(requestOptions, {
250
+ agent: requestOptions.agent || !noProxy && proxyAgentFor(url) || null,
251
+ path: pathname + search + hash,
252
+ protocol,
253
+ hostname,
254
+ headers,
255
+ port
256
+ });
240
257
  return (0, _utils.retry)((resolve, reject, retry) => {
241
258
  let handleError = error => {
242
259
  if (handleError.handled) return;
243
260
  handleError.handled = true;
244
261
  let shouldRetry = error.response // maybe retry 404s and always retry 500s
245
- ? retryNotFound && error.response.status === 404 || error.response.status >= 500 && error.response.status < 600 // retry specific error codes
262
+ ? retryNotFound && error.response.statusCode === 404 || error.response.statusCode >= 500 && error.response.statusCode < 600 // retry specific error codes
246
263
  : !!error.code && RETRY_ERROR_CODES.includes(error.code);
247
264
  return shouldRetry ? retry(error) : reject(error);
248
265
  };
@@ -269,7 +286,8 @@ function request(url, options = {}, callback) {
269
286
  } catch (error) {
270
287
  handleError(Object.assign(error, {
271
288
  response: {
272
- status: res.statusCode,
289
+ statusCode: res.statusCode,
290
+ headers: res.headers,
273
291
  body
274
292
  }
275
293
  }));
@@ -284,12 +302,7 @@ function request(url, options = {}, callback) {
284
302
  res.on('error', handleError);
285
303
  };
286
304
 
287
- let req = (protocol === 'https:' ? _https.default : _http.default).request({ ...requestOptions,
288
- path: pathname + search + hash,
289
- protocol,
290
- hostname,
291
- port
292
- });
305
+ let req = (protocol === 'https:' ? _https.default : _http.default).request(requestOptions);
293
306
  req.on('response', handleResponse);
294
307
  req.on('error', handleError);
295
308
  req.end(body);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percy/client",
3
- "version": "1.0.0-beta.75",
3
+ "version": "1.0.0-beta.76",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,11 +25,11 @@
25
25
  "test:coverage": "yarn test --coverage"
26
26
  },
27
27
  "dependencies": {
28
- "@percy/env": "1.0.0-beta.75",
29
- "@percy/logger": "1.0.0-beta.75"
28
+ "@percy/env": "1.0.0-beta.76",
29
+ "@percy/logger": "1.0.0-beta.76"
30
30
  },
31
31
  "devDependencies": {
32
32
  "mock-require": "^3.0.3"
33
33
  },
34
- "gitHead": "3b778a9c0b72dcbf113910227f1a073a2714042a"
34
+ "gitHead": "445af68d8e270e2a35fc74e26422ed5d3c91d2ae"
35
35
  }