@uploadcare/upload-client 5.1.1 → 5.2.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.
@@ -355,7 +355,7 @@ const defaultSettings = {
355
355
  const defaultContentType = 'application/octet-stream';
356
356
  const defaultFilename = 'original';
357
357
 
358
- var version = '5.1.1';
358
+ var version = '5.2.0';
359
359
 
360
360
  const LIBRARY_NAME = 'UploadcareUploadClient';
361
361
  const LIBRARY_VERSION = version;
@@ -368,13 +368,18 @@ function getUserAgent(options) {
368
368
  }
369
369
 
370
370
  const REQUEST_WAS_THROTTLED_CODE = 'RequestThrottledError';
371
- const DEFAULT_THROTTLED_TIMEOUT = 15000;
371
+ const DEFAULT_RETRY_AFTER_TIMEOUT = 15000;
372
372
  const DEFAULT_NETWORK_ERROR_TIMEOUT = 1000;
373
373
  function getTimeoutFromThrottledRequest(error) {
374
374
  const { headers } = error || {};
375
- return ((headers &&
376
- Number.parseInt(headers['x-throttle-wait-seconds']) * 1000) ||
377
- DEFAULT_THROTTLED_TIMEOUT);
375
+ if (!headers || typeof headers['retry-after'] !== 'string') {
376
+ return DEFAULT_RETRY_AFTER_TIMEOUT;
377
+ }
378
+ const seconds = parseInt(headers['retry-after'], 10);
379
+ if (!Number.isFinite(seconds)) {
380
+ return DEFAULT_RETRY_AFTER_TIMEOUT;
381
+ }
382
+ return seconds * 1000;
378
383
  }
379
384
  function retryIfFailed(fn, options) {
380
385
  const { retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes } = options;
@@ -282,7 +282,7 @@ const defaultSettings = {
282
282
  const defaultContentType = 'application/octet-stream';
283
283
  const defaultFilename = 'original';
284
284
 
285
- var version = '5.1.1';
285
+ var version = '5.2.0';
286
286
 
287
287
  function isObject(o) {
288
288
  return Object.prototype.toString.call(o) === '[object Object]';
@@ -396,13 +396,18 @@ function getUserAgent(options) {
396
396
  }
397
397
 
398
398
  const REQUEST_WAS_THROTTLED_CODE = 'RequestThrottledError';
399
- const DEFAULT_THROTTLED_TIMEOUT = 15000;
399
+ const DEFAULT_RETRY_AFTER_TIMEOUT = 15000;
400
400
  const DEFAULT_NETWORK_ERROR_TIMEOUT = 1000;
401
401
  function getTimeoutFromThrottledRequest(error) {
402
402
  const { headers } = error || {};
403
- return ((headers &&
404
- Number.parseInt(headers['x-throttle-wait-seconds']) * 1000) ||
405
- DEFAULT_THROTTLED_TIMEOUT);
403
+ if (!headers || typeof headers['retry-after'] !== 'string') {
404
+ return DEFAULT_RETRY_AFTER_TIMEOUT;
405
+ }
406
+ const seconds = parseInt(headers['retry-after'], 10);
407
+ if (!Number.isFinite(seconds)) {
408
+ return DEFAULT_RETRY_AFTER_TIMEOUT;
409
+ }
410
+ return seconds * 1000;
406
411
  }
407
412
  function retryIfFailed(fn, options) {
408
413
  const { retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes } = options;
@@ -358,7 +358,7 @@ const defaultSettings = {
358
358
  const defaultContentType = 'application/octet-stream';
359
359
  const defaultFilename = 'original';
360
360
 
361
- var version = '5.1.1';
361
+ var version = '5.2.0';
362
362
 
363
363
  const LIBRARY_NAME = 'UploadcareUploadClient';
364
364
  const LIBRARY_VERSION = version;
@@ -371,13 +371,18 @@ function getUserAgent(options) {
371
371
  }
372
372
 
373
373
  const REQUEST_WAS_THROTTLED_CODE = 'RequestThrottledError';
374
- const DEFAULT_THROTTLED_TIMEOUT = 15000;
374
+ const DEFAULT_RETRY_AFTER_TIMEOUT = 15000;
375
375
  const DEFAULT_NETWORK_ERROR_TIMEOUT = 1000;
376
376
  function getTimeoutFromThrottledRequest(error) {
377
377
  const { headers } = error || {};
378
- return ((headers &&
379
- Number.parseInt(headers['x-throttle-wait-seconds']) * 1000) ||
380
- DEFAULT_THROTTLED_TIMEOUT);
378
+ if (!headers || typeof headers['retry-after'] !== 'string') {
379
+ return DEFAULT_RETRY_AFTER_TIMEOUT;
380
+ }
381
+ const seconds = parseInt(headers['retry-after'], 10);
382
+ if (!Number.isFinite(seconds)) {
383
+ return DEFAULT_RETRY_AFTER_TIMEOUT;
384
+ }
385
+ return seconds * 1000;
381
386
  }
382
387
  function retryIfFailed(fn, options) {
383
388
  const { retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes } = options;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uploadcare/upload-client",
3
- "version": "5.1.1",
3
+ "version": "5.2.0",
4
4
  "description": "Library for work with Uploadcare Upload API",
5
5
  "type": "module",
6
6
  "module": "./dist/index.node.js",
@@ -78,7 +78,7 @@
78
78
  "koa-body": "5.0.0",
79
79
  "mock-socket": "9.0.3",
80
80
  "start-server-and-test": "1.14.0",
81
- "@uploadcare/api-client-utils": "^5.1.1",
81
+ "@uploadcare/api-client-utils": "^5.2.0",
82
82
  "chalk": "^4.1.2"
83
83
  },
84
84
  "dependencies": {