not-node 4.0.10 → 4.0.11

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.json CHANGED
@@ -18,7 +18,8 @@
18
18
  "extends": [
19
19
  "eslint:recommended",
20
20
  "plugin:node/recommended",
21
- "plugin:sonarjs/recommended"
21
+ "plugin:sonarjs/recommended",
22
+ "plugin:promise/recommended"
22
23
  ],
23
24
  "plugins": ["promise"],
24
25
  "rules": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "not-node",
3
- "version": "4.0.10",
3
+ "version": "4.0.11",
4
4
  "description": "node complimentary part for client side notFramework.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -53,36 +53,36 @@
53
53
  "mongoose": "*",
54
54
  "mongoose-validator": "*",
55
55
  "nconf": "*",
56
- "not-config": "^0.1.3",
57
- "not-error": "^0.2.0",
56
+ "not-config": "^0.1.4",
57
+ "not-error": "^0.2.1",
58
58
  "not-filter": "*",
59
59
  "not-inform": "^0.0.27",
60
60
  "not-locale": "*",
61
61
  "not-log": "^0.0.20",
62
62
  "not-monitor": "^0.0.13",
63
63
  "not-path": "*",
64
- "rate-limiter-flexible": "^2.3.3",
65
- "redis": "^3.1.2",
64
+ "rate-limiter-flexible": "^2.3.6",
65
+ "redis": "^4.0.0",
66
66
  "rmdir": "^1.2.0",
67
67
  "serve-static": "*",
68
68
  "simple-git": "*",
69
69
  "yargs": "*"
70
70
  },
71
71
  "devDependencies": {
72
- "@babel/eslint-parser": "^7.15.8",
72
+ "@babel/eslint-parser": "^7.16.3",
73
73
  "babel-eslint": "^10.1.0",
74
74
  "chai": "*",
75
75
  "chai-as-promised": "*",
76
- "eslint": "^7.32.0",
76
+ "eslint": "^8.3.0",
77
77
  "eslint-plugin-node": "^11.1.0",
78
- "eslint-plugin-promise": "^5.1.1",
79
- "eslint-plugin-sonarjs": "^0.10.0",
78
+ "eslint-plugin-promise": "^5.2.0",
79
+ "eslint-plugin-sonarjs": "^0.11.0",
80
80
  "ink-docstrap": "^1.3.2",
81
- "ioredis": "^4.28.1",
81
+ "ioredis": "^4.28.2",
82
82
  "jsdoc": "^3.6.7",
83
83
  "mocha": "*",
84
84
  "mocha-suppress-logs": "^0.3.1",
85
- "mongodb-memory-server": "^7.5.1",
85
+ "mongodb-memory-server": "^8.0.4",
86
86
  "npm-run-all": "^4.1.5",
87
87
  "nyc": "^15.1.0",
88
88
  "retire": "^3.0.3"
@@ -1,14 +1,18 @@
1
1
  const emit = require('./additional').run;
2
2
  const log = require('not-log')(module, 'RateLimiter');
3
3
 
4
+ const DEFAULT_OPTIONS = {
5
+ keyPrefix: 'rateLimiterMiddleware',
6
+ points: 20,
7
+ duration: 1
8
+ };
9
+
4
10
  module.exports = class InitRateLimiter{
5
11
 
6
12
  static createMiddleware({rateLimiter}){
7
13
  return (req, res, next) => {
8
14
  rateLimiter.consume(req.ip)
9
- .then(() => {
10
- next();
11
- })
15
+ .then(() => next())
12
16
  .catch(() => {
13
17
  log.error('Too many requests by ' + req.ip);
14
18
  res.status(429).send('Too Many Requests');
@@ -24,13 +28,19 @@ module.exports = class InitRateLimiter{
24
28
  await emit('rateLimiter.post', { config, master});
25
29
  }
26
30
 
27
- static createRateLimiter({master}){
31
+
32
+ getOptions({config}){
33
+ return {
34
+ ...DEFAULT_OPTIONS,
35
+ ...config.get('modules.rateLimiter', {})
36
+ };
37
+ }
38
+
39
+ static createRateLimiter({master, config}){
28
40
  const {RateLimiterRedis} = require('rate-limiter-flexible');
29
41
  return new RateLimiterRedis({
30
42
  storeClient: master.getEnv('db.redis'),
31
- keyPrefix: 'middleware',
32
- points: 100, // 10 requests
33
- duration: 1, // per 1 second by IP
43
+ ...this.getOptions({master, config})
34
44
  });
35
45
  }
36
46
  };