@vpmedia/simplify 1.25.0 → 1.26.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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @vpmedia/simplify
2
2
 
3
- [![npm version](https://badge.fury.io/js/@vpmedia%2Fsimplify.svg?v=1.25.0)](https://badge.fury.io/js/@vpmedia%2Fsimplify)
3
+ [![npm version](https://badge.fury.io/js/@vpmedia%2Fsimplify.svg?v=1.26.0)](https://badge.fury.io/js/@vpmedia%2Fsimplify)
4
4
  [![Node.js CI](https://github.com/vpmedia/simplify/actions/workflows/ci.yml/badge.svg)](https://github.com/vpmedia/simplify/actions/workflows/ci.yml)
5
5
 
6
6
  @vpmedia/simplify TBD
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vpmedia/simplify",
3
- "version": "1.25.0",
3
+ "version": "1.26.0",
4
4
  "description": "@vpmedia/simplify",
5
5
  "author": "Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)",
6
6
  "license": "MIT",
@@ -33,11 +33,12 @@ export class FetchError extends Error {
33
33
  * Fetch with retry.
34
34
  * @param {string | URL | Request} resource - Fetch URL.
35
35
  * @param {RequestInit} [fetchOptions] - Fetch options.
36
- * @param {{delay?: number, numTries?: number, statusExcludes?: number[]}} [retryOptions] - Retry options.
36
+ * @param {{delay?: number, numTries?: number, statusExcludes?: number[], timeout?: number}} [retryOptions] - Retry options.
37
37
  * @returns {Promise<Response>} Fetch result.
38
38
  */
39
39
  export const fetchRetry = async (resource, fetchOptions, retryOptions) => {
40
40
  retryOptions = retryOptions ?? {};
41
+ retryOptions.timeout = Math.max(retryOptions.timeout ?? 10000, 1000);
41
42
  retryOptions.delay = Math.max(retryOptions.delay ?? 500, 1);
42
43
  retryOptions.numTries = Math.max(retryOptions.numTries ?? 3, 1);
43
44
  retryOptions.statusExcludes = retryOptions.statusExcludes ?? [
@@ -48,6 +49,9 @@ export const fetchRetry = async (resource, fetchOptions, retryOptions) => {
48
49
  ];
49
50
  while (retryOptions.numTries > 0) {
50
51
  logger.info('request', { resource, fetchOptions, retryOptions });
52
+ const controller = new AbortController();
53
+ const timeoutId = setTimeout(() => controller.abort(), retryOptions.timeout);
54
+ fetchOptions.signal = controller.signal;
51
55
  try {
52
56
  const response = await fetch(resource, fetchOptions);
53
57
  if (!response.ok) {
@@ -76,6 +80,8 @@ export const fetchRetry = async (resource, fetchOptions, retryOptions) => {
76
80
  }
77
81
  await delayPromise(retryOptions.delay);
78
82
  retryOptions.delay *= 2;
83
+ } finally {
84
+ clearTimeout(timeoutId);
79
85
  }
80
86
  }
81
87
  };
@@ -16,5 +16,6 @@ export function fetchRetry(resource: string | URL | Request, fetchOptions?: Requ
16
16
  delay?: number;
17
17
  numTries?: number;
18
18
  statusExcludes?: number[];
19
+ timeout?: number;
19
20
  }): Promise<Response>;
20
21
  //# sourceMappingURL=fetchRetry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetchRetry.d.ts","sourceRoot":"","sources":["../../src/util/fetchRetry.js"],"names":[],"mappings":"AAYA,yBAA0B,CAAC,CAAC;AAE5B;IACE;;;;;;OAMG;IACH,qBALW,MAAM,YACN,MAAM,GAAG,GAAG,GAAG,OAAO,gBACtB,WAAW,YACX,QAAQ,EAQlB;IAHC,iCAAwB;IACxB,0BAAgC;IAChC,mBAAwB;CAE3B;AASM,qCALI,MAAM,GAAG,GAAG,GAAG,OAAO,iBACtB,WAAW,iBACX;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;CAAC,GAC5D,OAAO,CAAC,QAAQ,CAAC,CA4C7B"}
1
+ {"version":3,"file":"fetchRetry.d.ts","sourceRoot":"","sources":["../../src/util/fetchRetry.js"],"names":[],"mappings":"AAYA,yBAA0B,CAAC,CAAC;AAE5B;IACE;;;;;;OAMG;IACH,qBALW,MAAM,YACN,MAAM,GAAG,GAAG,GAAG,OAAO,gBACtB,WAAW,YACX,QAAQ,EAQlB;IAHC,iCAAwB;IACxB,0BAAgC;IAChC,mBAAwB;CAE3B;AASM,qCALI,MAAM,GAAG,GAAG,GAAG,OAAO,iBACtB,WAAW,iBACX;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAC,GAC9E,OAAO,CAAC,QAAQ,CAAC,CAkD7B"}