@mimik/request-retry 2.0.6 → 2.0.7

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/.eslintrc CHANGED
@@ -12,6 +12,7 @@
12
12
  "extends": "airbnb",
13
13
  "rules": {
14
14
  "import/no-extraneous-dependencies": ["error", {"devDependencies": true}],
15
+ "import/no-unresolved": ["error", { "amd": true, "commonjs": true, "caseSensitiveStrict": true }],
15
16
  "brace-style": [1, "stroustrup", {"allowSingleLine": true}],
16
17
  "no-confusing-arrow": [0], // arrow isnt confusing
17
18
  "max-len": [1, 180, { "ignoreComments": true }],
@@ -22,12 +23,11 @@
22
23
  "@mimik/document-env/validate-document-env": 2,
23
24
  "@mimik/dependencies/case-sensitive": 2,
24
25
  "@mimik/dependencies/no-cycles": 2,
25
- "@mimik/dependencies/no-unresolved": 2,
26
26
  "@mimik/dependencies/require-json-ext": 2
27
27
  },
28
28
  "settings":{
29
29
  "react": {
30
- "version": "latest"
30
+ "version": "detect"
31
31
  }
32
32
  },
33
33
  "globals": {
@@ -5,12 +5,12 @@ const bodyParser = require('body-parser');
5
5
  const app = express();
6
6
 
7
7
  app.use(bodyParser.json());
8
- app.get(`/success`, (req, res) => {
8
+ app.get('/success', (req, res) => {
9
9
  res.statusCode = 200;
10
10
 
11
- res.send({ statusCode: 200});
11
+ res.send({ statusCode: 200 });
12
12
  });
13
13
 
14
14
  app.listen(9000, () => {
15
- console.log('----->', `retry mock at ${9000}`);
16
- });
15
+ console.log('----->', `retry mock at ${9000}`);
16
+ });
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-console */
1
2
  require('../test/testEnv');
2
3
 
3
4
  const { rpRetry } = require('../index');
@@ -5,18 +6,18 @@ const { rpRetry } = require('../index');
5
6
  const correlationId = `--request-retry-test--/${new Date().toISOString()}`;
6
7
 
7
8
  const options = {
8
- method: 'GET',
9
- headers: {
10
- 'x-correlation-id': correlationId,
11
- },
12
- url: 'http://localhost:9080/test/retry',
13
- json: true,
14
- retry: {},
15
- };
9
+ method: 'GET',
10
+ headers: {
11
+ 'x-correlation-id': correlationId,
12
+ },
13
+ url: 'http://localhost:9080/test/retry',
14
+ json: true,
15
+ retry: {},
16
+ };
16
17
 
17
- options.retry.delayStrategy = () => 10000;
18
- options.retry.timeout = 10;
19
- options.retry.retries = 2;
18
+ options.retry.delayStrategy = () => 10000;
19
+ options.retry.timeout = 10;
20
+ options.retry.retries = 2;
20
21
 
21
22
  rpRetry(options)
22
- .catch((err) => console.log(err));
23
+ .catch((err) => console.log(err));
@@ -49,12 +49,12 @@ app.post(`${config.base}${config.path}`, (req, res) => {
49
49
 
50
50
  app.post('/logs/:id', (req, res) => {
51
51
  console.log('--->', 'Recieved a log');
52
- console.log('---> id:', req.params.id)
52
+ console.log('---> id:', req.params.id);
53
53
  console.log('---> body:', req.body);
54
54
  res.statusCode = config.post.success;
55
55
  res.send({ statusCode: config.post.success });
56
- })
56
+ });
57
57
 
58
58
  app.listen(config.port, () => {
59
59
  console.log('----->', `retry mock at ${config.port}`);
60
- });
60
+ });
@@ -1,27 +1,28 @@
1
- const doSomething = () => {
2
- let add = 0;
1
+ /* eslint-disable no-console */
2
+ const doSomething = () => {
3
+ let add = 0;
3
4
 
4
- for (i = 0; i < 100000000; i++) {
5
- add +=1;
6
- console.log(add)
7
- };
8
- return add
5
+ for (let i = 0; i < 100000000; i += 1) {
6
+ add += 1;
7
+ console.log(add);
8
+ }
9
+ return add;
9
10
  };
10
11
  const timeout = 1; // ms
11
12
 
12
13
  const race = () => {
13
- let result;
14
- const mainTimeout = setTimeout(() => {
15
- throw new Error('timeout')
16
- }, timeout);
14
+ let result;
15
+ const mainTimeout = setTimeout(() => {
16
+ throw new Error('timeout');
17
+ }, timeout);
17
18
 
18
- try { result = doSomething() }
19
- catch (err) {
20
- console.log(err);
21
- result = 0;
22
- }
23
- clearTimeout(mainTimeout);
24
- return result;
25
- }
19
+ try { result = doSomething(); }
20
+ catch (err) {
21
+ console.log(err);
22
+ result = 0;
23
+ }
24
+ clearTimeout(mainTimeout);
25
+ return result;
26
+ };
26
27
 
27
28
  console.log(race());
@@ -1,4 +1,5 @@
1
- const { rpRetry } = require('../../../common/rp-retry-34/index.js');
1
+ /* eslint-disable no-console */
2
+ const { rpRetry } = require('../index');
2
3
 
3
4
  const options = {
4
5
  method: 'GET',
@@ -9,49 +10,50 @@ const options = {
9
10
  json: true,
10
11
  timeout: 200,
11
12
  // retry: {
12
- // all default: maxRetry: 2, retryDelay: 1000ms, maxTimeout: 50s, logLevel: 3 silly, type response, retryDelayStrategy: setDelay, retryStrategy: defaultRetry
13
- // retries: -1, // => 0
14
- // retries: 20, // => 15
15
- // retries: 'joe', // => 2
16
- // retries: 0, // OK
17
- // delay: 0, // => 20ms
18
- // delay: 100000, // => 30000ms
19
- // delay: 'joe', // => 1000ms
20
- // delay: 1, // => 20ms
21
- // delayStrategy: 'joe', // => setDelay returning retryDelay
22
- // delayStrategy: function badDelay() { return 'joe' }, // => no change then bad delay strategy => retryDelay
23
- // delayStrategy: function userDelay(...args) { return (Math.pow(2, args[0]) * 100) + Math.floor(Math.random() * 50) }, // OK
24
- // retryStrategy: 'joe', // => unknowRetry returning false
25
- // retryStrategy: function badRetry() { return 'joe' }, // => no change then bad retry strategy => false
26
- // retryStrategy: function userRetry(...args) { // OK
27
- // const { statusCode } = args[1]; // err
28
- //
29
- // return statusCode && (Math.floor(statusCode/100) !== 5 || statusCode !== 429); // retry if there is no statusCode or if there is 500 range statucCode or 429
30
- // },
31
- // retryStrategy: function invalidRetry(...args) { // defaultRetry
32
- // const { statusCode } = args[34]; // null value
33
- //
34
- // return true // no retry
35
- // },
36
- // timeout: 0, // => 10s
37
- // timeout: 150, // => 120s
38
- // timeout: 'joe', // => 50s
39
- // logLevel: {
40
- // response: 'test', // silly with warning
41
- // error: 1234, // => silly with warning
42
- // request: null, // => silly no warning
43
- // responseDetails: 'test', // => type with warning
44
- // responseName: '', // => response with warning
45
- // },
46
- // logLevel: {
47
- // response: 'info', // ok all the other value to default no warning
48
- // },
49
- //}
13
+ // all default: maxRetry: 2, retryDelay: 1000ms, maxTimeout: 50s, logLevel: 3 silly, type response, retryDelayStrategy: setDelay, retryStrategy: defaultRetry
14
+ // retries: -1, // => 0
15
+ // retries: 20, // => 15
16
+ // retries: 'joe', // => 2
17
+ // retries: 0, // OK
18
+ // delay: 0, // => 20ms
19
+ // delay: 100000, // => 30000ms
20
+ // delay: 'joe', // => 1000ms
21
+ // delay: 1, // => 20ms
22
+ // delayStrategy: 'joe', // => setDelay returning retryDelay
23
+ // delayStrategy: function badDelay() { return 'joe' }, // => no change then bad delay strategy => retryDelay
24
+ // delayStrategy: function userDelay(...args) { return (Math.pow(2, args[0]) * 100) + Math.floor(Math.random() * 50) }, // OK
25
+ // retryStrategy: 'joe', // => unknowRetry returning false
26
+ // retryStrategy: function badRetry() { return 'joe' }, // => no change then bad retry strategy => false
27
+ // retryStrategy: function userRetry(...args) { // OK
28
+ // const { statusCode } = args[1]; // err
29
+ //
30
+ // return statusCode && (Math.floor(statusCode/100) !== 5 || statusCode !== 429); // retry if there is no statusCode or if there is 500 range statucCode or 429
31
+ // },
32
+ // retryStrategy: function invalidRetry(...args) { // defaultRetry
33
+ // const { statusCode } = args[34]; // null value
34
+ //
35
+ // return true // no retry
36
+ // },
37
+ // timeout: 0, // => 10s
38
+ // timeout: 150, // => 120s
39
+ // timeout: 'joe', // => 50s
40
+ // logLevel: {
41
+ // response: 'test', // silly with warning
42
+ // error: 1234, // => silly with warning
43
+ // request: null, // => silly no warning
44
+ // responseDetails: 'test', // => type with warning
45
+ // responseName: '', // => response with warning
46
+ // },
47
+ // logLevel: {
48
+ // response: 'info', // ok all the other value to default no warning
49
+ // },
50
+ // }
50
51
  };
51
52
 
52
53
  const sDate = Date.now();
53
54
 
54
55
  rpRetry(options)
55
- .then(response => console.log('success', { response: typeof response }, Date.now() - sDate))
56
- .catch(err => { console.log('failure', { error: err, info: err.info }, Date.now() - sDate);
57
- })
56
+ .then((response) => console.log('success', { response: typeof response }, Date.now() - sDate))
57
+ .catch((err) => {
58
+ console.log('failure', { error: err, info: err.info }, Date.now() - sDate);
59
+ });
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@mimik/request-retry",
3
- "version": "2.0.6",
3
+ "version": "2.0.7",
4
4
  "description": "Request retry wrapping axios",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
- "lint": "gulp lint",
8
- "docs": "gulp docs",
9
- "test": "nyc gulp test",
10
- "prepublishOnly": "gulp docs; gulp lint; npm run test",
11
- "commit-ready": "gulp docs; gulp lint; npm run test",
7
+ "lint": "eslint --ignore-path .gitignore .",
8
+ "docs": "jsdoc2md index.js > README.md",
9
+ "test": "mocha --reporter mochawesome --bail --check-leaks test/",
10
+ "test-ci": "nyc --reporter=lcov --reporter=text npm test",
11
+ "prepublishOnly": "npm run docs && npm run lint && npm run test-ci",
12
+ "commit-ready": "npm run docs && npm run lint && npm run test-ci",
12
13
  "prepare": "husky install"
13
14
  },
14
15
  "husky": {
@@ -22,43 +23,38 @@
22
23
  "microservice"
23
24
  ],
24
25
  "author": "mimik technology inc <support@mimik.com> (https://developer.mimik.com/)",
25
- "license": "Apache-2.0",
26
+ "license": "MIT",
26
27
  "repository": {
27
28
  "type": "git",
28
29
  "url": "https://bitbucket.org/mimiktech/request-retry"
29
30
  },
30
31
  "dependencies": {
31
- "@mimik/request-helper": "^1.7.3",
32
- "@mimik/response-helper": "^2.6.0",
33
- "@mimik/sumologic-winston-logger": "^1.6.6",
34
- "axios": "0.24.0",
32
+ "@mimik/request-helper": "^1.7.4",
33
+ "@mimik/response-helper": "^2.6.1",
34
+ "@mimik/sumologic-winston-logger": "^1.6.8",
35
+ "axios": "0.27.2",
35
36
  "bluebird": "3.7.2",
36
37
  "lodash": "4.17.21"
37
38
  },
38
39
  "devDependencies": {
39
- "@mimik/eslint-plugin-dependencies": "^2.4.1",
40
- "@mimik/eslint-plugin-document-env": "^1.0.0",
41
- "acorn": "8.6.0",
42
- "body-parser": "1.19.1",
43
- "chai": "4.3.4",
44
- "eslint": "8.4.1",
45
- "eslint-config-airbnb": "18.2.1",
46
- "eslint-plugin-import": "2.25.3",
40
+ "@mimik/eslint-plugin-dependencies": "^2.4.3",
41
+ "@mimik/eslint-plugin-document-env": "^1.0.3",
42
+ "acorn": "8.7.1",
43
+ "body-parser": "1.20.0",
44
+ "chai": "4.3.6",
45
+ "eslint": "8.15.0",
46
+ "eslint-config-airbnb": "19.0.4",
47
+ "eslint-plugin-import": "2.26.0",
47
48
  "eslint-plugin-jsx-a11y": "6.5.1",
48
- "eslint-plugin-react": "7.27.1",
49
- "eslint-plugin-react-hooks": "4.3.0",
50
- "express": "4.17.1",
51
- "fancy-log": "1.3.3",
52
- "gulp": "4.0.2",
53
- "gulp-eslint": "6.0.0",
54
- "gulp-git": "2.10.1",
55
- "gulp-spawn-mocha": "6.0.0",
56
- "husky": "7.0.4",
57
- "jsdoc-to-markdown": "7.1.0",
58
- "mocha": "9.1.3",
59
- "mochawesome": "7.0.1",
49
+ "eslint-plugin-react": "7.29.4",
50
+ "eslint-plugin-react-hooks": "4.5.0",
51
+ "express": "4.18.1",
52
+ "husky": "8.0.1",
53
+ "jsdoc-to-markdown": "7.1.1",
54
+ "mocha": "10.0.0",
55
+ "mochawesome": "7.1.3",
60
56
  "nyc": "15.1.0",
61
- "sinon": "12.0.1",
57
+ "sinon": "14.0.0",
62
58
  "verror": "1.10.1"
63
59
  }
64
60
  }
package/test/retryMock.js CHANGED
@@ -46,6 +46,14 @@ app.post(`${config.base}${config.path}`, (req, res) => {
46
46
  res.statusCode = config.post.success;
47
47
  res.send({ statusCode: config.post.success });
48
48
  });
49
+ app.get('/stop', (req, res) => {
50
+ console.log('----->', 'Received a stop');
51
+ res.statusCode = config.get.success;
52
+ res.send({ statusCode: config.get.success });
53
+ setTimeout(() => {
54
+ process.exit(0);
55
+ }, 3000);
56
+ });
49
57
 
50
58
  const listen = () => {
51
59
  app.listen(config.port, () => {
@@ -339,5 +339,20 @@ describe('request-retry Unit Tests', () => {
339
339
  // sinon.assert.called(loggerSpyWarn);
340
340
  });
341
341
  });
342
+ it('should stop mock server', () => rpRetry({
343
+ method: 'GET',
344
+ headers: {
345
+ 'x-correlation-id': correlationId,
346
+ },
347
+ url: 'http://localhost:9070/stop',
348
+ retry: {
349
+ delayStrategy: () => 100,
350
+ retries: 1,
351
+ },
352
+ })
353
+ .catch((err) => {
354
+ expect(err.name).to.equal('System');
355
+ expect(VError.cause(err).name).to.equal('TimeoutError');
356
+ }));
342
357
  });
343
358
  });
package/Gulpfile.js DELETED
@@ -1,41 +0,0 @@
1
- /* eslint-disable import/no-extraneous-dependencies */
2
- const fs = require('fs');
3
- const log = require('fancy-log');
4
- const gulp = require('gulp');
5
- const eslint = require('gulp-eslint');
6
- const git = require('gulp-git');
7
- const jsdoc2md = require('jsdoc-to-markdown');
8
- const mocha = require('gulp-spawn-mocha');
9
-
10
- const files = [
11
- 'index.js',
12
- 'Gulpfile.js',
13
- 'test/**.js',
14
- 'lib/**.js',
15
- ];
16
-
17
- const createDocs = (done) => {
18
- jsdoc2md.render({ files: 'index.js' })
19
- .then((output) => fs.writeFileSync('README.md', output))
20
- .catch((err) => log.error('docs creation failed:', err.message))
21
- .finally(() => done());
22
- };
23
-
24
- const lint = () => gulp.src(files)
25
- .pipe(eslint({}))
26
- .pipe(eslint.format());
27
-
28
- const add = () => gulp.src('README.md')
29
- .pipe(git.add({ quiet: true }));
30
-
31
- const test = () => gulp.src(['test/*.spec.js'])
32
- .pipe(mocha({
33
- reporter: 'mochawesome',
34
- exit: true,
35
- }));
36
-
37
- const docs = gulp.series(createDocs, add);
38
-
39
- gulp.task('lint', lint);
40
- gulp.task('docs', docs);
41
- gulp.task('test', test);