@mimik/request-retry 4.0.7 → 4.0.8

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/.husky/pre-commit CHANGED
@@ -1,4 +1,2 @@
1
1
  #!/bin/sh
2
- . "$(dirname "$0")/_/husky.sh"
3
-
4
2
  npm run commit-ready
package/.husky/pre-push CHANGED
@@ -1,4 +1,2 @@
1
1
  #!/bin/sh
2
- . "$(dirname "$0")/_/husky.sh"
3
-
4
2
  npm run test
package/README.md CHANGED
@@ -9,10 +9,11 @@ import rp from '@mimik/request-retry';
9
9
  ```
10
10
  <a name="module_request-retry..rpRetry"></a>
11
11
 
12
- ### request-retry~rpRetry(options) ⇒ <code>Promise</code>
12
+ ### request-retry~rpRetry(options) ⇒ <code>Promise.&lt;object&gt;</code>
13
13
  Make a request with retries.
14
14
 
15
15
  **Kind**: inner method of [<code>request-retry</code>](#module_request-retry)
16
+ **Returns**: <code>Promise.&lt;object&gt;</code> - A bluebird promise (supports cancellation).
16
17
  **Category**: async
17
18
  **Throws**:
18
19
 
package/eslint.config.js CHANGED
@@ -1,3 +1,4 @@
1
+ import globals from 'globals';
1
2
  import importPlugin from 'eslint-plugin-import';
2
3
  import js from '@eslint/js';
3
4
  import processDoc from '@mimik/eslint-plugin-document-env';
@@ -10,13 +11,13 @@ const MAX_LINES_IN_FUNCTION = 150;
10
11
  const MAX_STATEMENTS_IN_FUNCTION = 45;
11
12
  const MIN_KEYS_IN_OBJECT = 10;
12
13
  const MAX_COMPLEXITY = 30;
13
- const ECMA_VERSION = 2022;
14
+ const ECMA_VERSION = 'latest';
14
15
  const MAX_DEPTH = 6;
15
16
  const ALLOWED_CONSTANTS = [0, 1, -1];
16
17
 
17
18
  export default [
18
19
  {
19
- ignores: ['mochawesome-report/**', 'node_modules/**', 'dist/**'],
20
+ ignores: ['coverage/**', 'mochawesome-report/**', 'node_modules/**', 'dist/**'],
20
21
  },
21
22
  importPlugin.flatConfigs.recommended,
22
23
  stylistic.configs.recommended,
@@ -28,10 +29,8 @@ export default [
28
29
  languageOptions: {
29
30
  ecmaVersion: ECMA_VERSION,
30
31
  globals: {
31
- console: 'readonly',
32
- describe: 'readonly',
33
- it: 'readonly',
34
- require: 'readonly',
32
+ ...globals.mocha,
33
+ ...globals.nodeBuiltin,
35
34
  },
36
35
  sourceType: 'module',
37
36
  },
@@ -39,6 +38,7 @@ export default [
39
38
  '@stylistic/brace-style': ['warn', 'stroustrup', { allowSingleLine: true }],
40
39
  '@stylistic/line-comment-position': ['off'],
41
40
  '@stylistic/max-len': ['warn', MAX_LENGTH_LINE, { ignoreComments: true, ignoreStrings: true, ignoreRegExpLiterals: true }],
41
+ '@stylistic/quotes': ['warn', 'single'],
42
42
  '@stylistic/semi': ['error', 'always'],
43
43
  'capitalized-comments': ['off'],
44
44
  'complexity': ['error', MAX_COMPLEXITY],
@@ -49,19 +49,20 @@ export default [
49
49
  'init-declarations': ['off'],
50
50
  'linebreak-style': ['off'],
51
51
  'max-depth': ['error', MAX_DEPTH],
52
+ 'max-len': ['off'],
52
53
  'max-lines': ['warn', { max: MAX_LINES_IN_FILES, skipComments: true, skipBlankLines: true }],
53
54
  'max-lines-per-function': ['warn', { max: MAX_LINES_IN_FUNCTION, skipComments: true, skipBlankLines: true }],
54
55
  'max-params': ['error', MAX_FUNCTION_PARAMETERS],
55
56
  'max-statements': ['warn', MAX_STATEMENTS_IN_FUNCTION],
56
57
  'no-confusing-arrow': ['off'],
57
58
  'no-inline-comments': ['off'],
58
- 'no-magic-numbers': ['error', { ignore: ALLOWED_CONSTANTS, enforceConst: true, detectObjects: true }],
59
+ 'no-magic-numbers': ['error', { ignore: ALLOWED_CONSTANTS, enforceConst: true, detectObjects: false }],
59
60
  'no-process-env': ['error'],
60
61
  'no-ternary': ['off'],
61
62
  'no-undefined': ['off'],
62
63
  'one-var': ['error', 'never'],
63
64
  'processDoc/validate-document-env': ['error'],
64
- 'quotes': ['warn', 'single'],
65
+ 'quotes': ['off'],
65
66
  'sort-imports': ['error', { allowSeparatedGroups: true }],
66
67
  'sort-keys': ['error', 'asc', { caseSensitive: true, minKeys: MIN_KEYS_IN_OBJECT, natural: false, allowLineSeparatedGroups: true }],
67
68
  },
package/index.js CHANGED
@@ -49,7 +49,7 @@ Promise.config({ cancellation: true });
49
49
  * The `validateStatus` option is disabled: an error is thrown for status codes outside **[200, 300)**.
50
50
  * An additional option, `resolveWithFullResponse`, controls the return shape:
51
51
  * when `true`, the full Axios response object is returned; when `false` or omitted, only `response.data` is returned.
52
- * @return {Promise}
52
+ * @return {Promise<object>} A bluebird promise (supports cancellation).
53
53
  * @fulfil {object} - The Axios response when `resolveWithFullResponse` is `true`; otherwise `response.data`.
54
54
  * @throws {Error} An error produced by `getRichError`, wrapping an
55
55
  * [Axios](https://www.npmjs.com/package/axios) error or a `TimeoutError`.
@@ -32,9 +32,9 @@ app.use(bodyParser.json());
32
32
  app.get(`${config.base}${config.path}`, (req, res) => {
33
33
  if (nbRequest === 0) message = 'Received first request';
34
34
  else {
35
- const timeLap = Date.now() - time;
35
+ const timeLapse = Date.now() - time;
36
36
 
37
- message = `Received ${nbRequest} retry with timelapse ${timeLap}`;
37
+ message = `Received ${nbRequest} retry with timelapse ${timeLapse}`;
38
38
  }
39
39
  console.log('----->', message);
40
40
  time = Date.now();
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@mimik/request-retry",
3
- "version": "4.0.7",
3
+ "version": "4.0.8",
4
4
  "description": "Request retry wrapping axios",
5
5
  "main": "./index.js",
6
6
  "type": "module",
7
7
  "scripts": {
8
8
  "lint": "eslint . --no-error-on-unmatched-pattern",
9
9
  "docs": "jsdoc2md index.js > README.md",
10
- "test": "mocha --reporter mochawesome --bail --check-leaks test/",
11
- "test-ci": "c8 --reporter=lcov --reporter=text npm test --exit",
10
+ "test": "mocha --reporter mochawesome --bail --check-leaks --exit test/",
11
+ "test-ci": "c8 --reporter=lcov --reporter=text npm test",
12
12
  "prepublishOnly": "npm run docs && npm run lint && npm run test-ci",
13
13
  "commit-ready": "npm run docs && npm run lint && npm run test-ci"
14
14
  },
@@ -29,23 +29,23 @@
29
29
  "url": "https://bitbucket.org/mimiktech/request-retry"
30
30
  },
31
31
  "dependencies": {
32
- "@mimik/request-helper": "^2.0.3",
33
- "@mimik/response-helper": "^4.0.9",
34
- "@mimik/sumologic-winston-logger": "^2.1.10",
32
+ "@mimik/request-helper": "^2.0.5",
33
+ "@mimik/response-helper": "^4.0.10",
34
+ "@mimik/sumologic-winston-logger": "^2.1.12",
35
35
  "axios": "1.13.5",
36
36
  "bluebird": "3.7.2"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@eslint/js": "9.39.2",
40
40
  "@mimik/eslint-plugin-document-env": "^2.0.8",
41
- "@stylistic/eslint-plugin": "5.8.0",
42
- "acorn": "8.15.0",
41
+ "@stylistic/eslint-plugin": "5.9.0",
43
42
  "body-parser": "2.2.2",
44
43
  "c8": "10.1.3",
45
44
  "chai": "6.2.2",
46
45
  "eslint": "9.39.2",
47
46
  "eslint-plugin-import": "2.32.0",
48
47
  "express": "5.2.1",
48
+ "globals": "17.3.0",
49
49
  "husky": "9.1.7",
50
50
  "jsdoc-to-markdown": "9.1.3",
51
51
  "mocha": "11.7.5",
package/test/retryMock.js CHANGED
@@ -32,9 +32,9 @@ app.use(bodyParser.json());
32
32
  app.get(`${config.base}${config.path}`, (req, res) => {
33
33
  if (nbRequest === 0) message = 'Received first request';
34
34
  else {
35
- const timeLap = Date.now() - time;
35
+ const timeLapse = Date.now() - time;
36
36
 
37
- message = `Received ${nbRequest} retry with timelapse ${timeLap}`;
37
+ message = `Received ${nbRequest} retry with timelapse ${timeLapse}`;
38
38
  }
39
39
  console.log('----->', message);
40
40
  time = Date.now();
@@ -172,7 +172,7 @@ describe('request-retry Unit Tests', () => {
172
172
  expect(callArgs[CALL_ARG_MESSAGE]).to.equal('invalid retryStrategy, ignoring');
173
173
  });
174
174
  });
175
- it('should generate warning: invalid delayStrategy: "notANumber" becoming delay or default', () => {
175
+ it('should generate warning: invalid delayStrategy: "notAFunction" becoming delay or default', () => {
176
176
  options.retry.delayStrategy = 'notAFunction';
177
177
  return rpRetry(options).then(() => {
178
178
  assert.calledOnce(loggerSpyWarn);
@@ -252,6 +252,63 @@ describe('request-retry Unit Tests', () => {
252
252
  });
253
253
  });
254
254
  });
255
+ describe('rpRetry(options) request mapping and response details', () => {
256
+ it('should succeed with body mapped to axios data', () => rpRetry({
257
+ method: 'POST',
258
+ headers: { 'x-correlation-id': correlationId },
259
+ url: 'http://localhost:9070/test/retry',
260
+ body: { test: 'data' },
261
+ retry: {},
262
+ }).then((response) => {
263
+ expect(response).to.have.property('statusCode');
264
+ }));
265
+ it('should succeed with json object mapped to axios data', () => rpRetry({
266
+ method: 'POST',
267
+ headers: { 'x-correlation-id': correlationId },
268
+ url: 'http://localhost:9070/test/retry',
269
+ json: { test: 'data' },
270
+ retry: {},
271
+ }).then((response) => {
272
+ expect(response).to.have.property('statusCode');
273
+ }));
274
+ it('should succeed with qs mapped to axios params', () => rpRetry({
275
+ method: 'POST',
276
+ headers: { 'x-correlation-id': correlationId },
277
+ url: 'http://localhost:9070/test/retry',
278
+ json: true,
279
+ qs: { key: 'value' },
280
+ retry: {},
281
+ }).then((response) => {
282
+ expect(response).to.have.property('statusCode');
283
+ }));
284
+ it('should throw a System error on network failure', () => rpRetry({
285
+ method: 'GET',
286
+ headers: { 'x-correlation-id': correlationId },
287
+ url: 'http://localhost:1/unreachable',
288
+ retry: { retries: 0, timeout: 10 },
289
+ }).catch((err) => {
290
+ expect(err.name).to.be.a('string');
291
+ }));
292
+ it('should log response with count details', () => {
293
+ const loggerSpySilly = spy(logger, 'silly');
294
+
295
+ return rpRetry({
296
+ method: 'POST',
297
+ headers: { 'x-correlation-id': correlationId },
298
+ url: 'http://localhost:9070/test/retry',
299
+ json: true,
300
+ retry: {
301
+ logLevel: {
302
+ response: 'silly',
303
+ responseDetails: 'count',
304
+ },
305
+ },
306
+ }).then(() => {
307
+ assert.calledOnce(loggerSpySilly);
308
+ loggerSpySilly.restore();
309
+ });
310
+ });
311
+ });
255
312
  describe('rpRetry(options) options validation run', function Test() {
256
313
  this.timeout(TIMEOUT);
257
314
  const options = {
@@ -294,7 +351,7 @@ describe('request-retry Unit Tests', () => {
294
351
  expect(callArgs[CALL_ARG_MESSAGE]).to.equal('bad retry strategy');
295
352
  });
296
353
  });
297
- it('should not generate warning: retry strategy returning a boolean', () => {
354
+ it('should not generate warning for retry strategy, but warn on request error', () => {
298
355
  options.retry.retryStrategy = () => false;
299
356
  options.retry.retries = RETRY_RETRIES;
300
357
  return rpRetry(options)
@@ -337,7 +394,7 @@ describe('request-retry Unit Tests', () => {
337
394
  expect(callArgs[CALL_ARG_MESSAGE]).to.equal('calculated delay out of scope: using delay or default');
338
395
  });
339
396
  });
340
- it('should not generate warning: delay strategy returning an in scope number', () => {
397
+ it('should not generate warning for delay strategy, but warn on request error', () => {
341
398
  options.retry.delayStrategy = () => DELAY_STRATEGY_RESPONSE_2;
342
399
  options.retry.retries = RETRY_RETRIES;
343
400
  return rpRetry(options)
package/.nycrc DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "exclude": ["gulpfile.js"],
3
- "reporter": ["lcov", "text"]
4
- }