@vpmedia/simplify 1.5.0 → 1.5.1

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/CHANGES.md CHANGED
@@ -3,8 +3,16 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project adheres to [Semantic Versioning](http://semver.org/).
5
5
 
6
+ ## 1.5.1
7
+
8
+ - Bugfixes for fetch retry helper
9
+
6
10
  ## 1.5.0
7
11
 
12
+ - Refactored fetch retry helper
13
+
14
+ ## 1.4.0
15
+
8
16
  - Added fetch retry helper
9
17
 
10
18
  ## 1.3.0
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.5.0)](https://badge.fury.io/js/@vpmedia%2Fsimplify)
3
+ [![npm version](https://badge.fury.io/js/@vpmedia%2Fsimplify.svg?v=1.5.1)](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.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "@vpmedia/simplify",
5
5
  "author": "Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)",
6
6
  "license": "MIT",
@@ -7,18 +7,18 @@ const logger = new Logger('fetchRetry');
7
7
  * Fetch with retry.
8
8
  * @param {string | URL | Request} resource - Fetch URL.
9
9
  * @param {RequestInit} [fetchOptions] - Fetch options.
10
- * @param {{ delay?: number, numRetries?: number, isLog?: boolean}} [retryOptions] - Retry options.
10
+ * @param {{ delay?: number, numTries?: number, isLog?: boolean}} [retryOptions] - Retry options.
11
11
  * @returns {Promise<Response>} Fetch result.
12
12
  */
13
13
  export const fetchRetry = async (resource, fetchOptions, retryOptions) => {
14
14
  retryOptions = retryOptions ?? {};
15
- retryOptions.delay = retryOptions.delay ?? 1000;
16
- retryOptions.numRetries = retryOptions.numRetries ?? 3;
17
- while (retryOptions.numRetries > 0) {
15
+ retryOptions.delay = Math.max(retryOptions.delay ?? 1000, 1);
16
+ retryOptions.numTries = Math.max(retryOptions.numTries ?? 3, 1);
17
+ while (retryOptions.numTries > 0) {
18
18
  logger.info('Fetch request', { resource, fetchOptions, retryOptions });
19
19
  try {
20
20
  const response = await fetch(resource, fetchOptions);
21
- if (!response.ok || retryOptions.numRetries > 3) {
21
+ if (!response.ok) {
22
22
  logger.warn('Fetch response', response);
23
23
  throw new Error(`Network error: ${response.status}`, { cause: response.status });
24
24
  }
@@ -26,11 +26,11 @@ export const fetchRetry = async (resource, fetchOptions, retryOptions) => {
26
26
  return response;
27
27
  } catch (error) {
28
28
  logger.error('Fetch error', error instanceof Error ? error : new Error(String(error)));
29
- if (retryOptions.numRetries === 0) {
29
+ retryOptions.numTries -= 1;
30
+ if (retryOptions.numTries === 0) {
30
31
  throw error;
31
32
  }
32
33
  await delayPromise(retryOptions.delay);
33
- retryOptions.numRetries -= 1;
34
34
  retryOptions.delay *= 2;
35
35
  }
36
36
  }
@@ -1,6 +1,6 @@
1
1
  export function fetchRetry(resource: string | URL | Request, fetchOptions?: RequestInit, retryOptions?: {
2
2
  delay?: number;
3
- numRetries?: number;
3
+ numTries?: number;
4
4
  isLog?: boolean;
5
5
  }): Promise<Response>;
6
6
  //# sourceMappingURL=fetchRetry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetchRetry.d.ts","sourceRoot":"","sources":["../../src/util/fetchRetry.js"],"names":[],"mappings":"AAYO,qCALI,MAAM,GAAG,GAAG,GAAG,OAAO,iBACtB,WAAW,iBACX;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAC,GACrD,OAAO,CAAC,QAAQ,CAAC,CA0B7B"}
1
+ {"version":3,"file":"fetchRetry.d.ts","sourceRoot":"","sources":["../../src/util/fetchRetry.js"],"names":[],"mappings":"AAYO,qCALI,MAAM,GAAG,GAAG,GAAG,OAAO,iBACtB,WAAW,iBACX;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAC,GACnD,OAAO,CAAC,QAAQ,CAAC,CA0B7B"}