not-node 6.3.20 → 6.3.22

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "not-node",
3
- "version": "6.3.20",
3
+ "version": "6.3.22",
4
4
  "description": "node complimentary part for client side notFramework.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/env.js CHANGED
@@ -22,7 +22,7 @@ module.exports = class notEnv {
22
22
  * Setting application environment variable
23
23
  * @param {string} key name of var
24
24
  * @param {object} val value
25
- * @return {notDomain} chainable
25
+ * @return {notEnv} chainable
26
26
  */
27
27
  static setEnv(key, val) {
28
28
  ENVS[key] = val;
@@ -2,12 +2,7 @@
2
2
  const Form = require("../form/form");
3
3
  const { firstLetterToUpper } = require("../common");
4
4
  //form
5
- const FIELDS = [
6
- ["activeUserId", { required: true }, "not-node//objectId"],
7
- ["activeUser", "not-node//requiredObject"],
8
- ["ip", "not-node//ip"],
9
- ["identity", "not-node//requiredObject"],
10
- ];
5
+ const FIELDS = [["identity", "not-node//requiredObject"]];
11
6
 
12
7
  module.exports = ({ MODULE_NAME, MODEL_NAME, actionName }) => {
13
8
  const FORM_NAME = `${MODULE_NAME}:${MODEL_NAME}:${firstLetterToUpper(
@@ -4,9 +4,7 @@ const { firstLetterToUpper } = require("../common");
4
4
  //form
5
5
  const FIELDS = [
6
6
  ["targetID", { required: true }, "not-node//ID"],
7
- ["activeUserId", { required: true }, "not-node//objectId"],
8
- ["activeUser", "not-node//requiredObject"],
9
- ["ip", "not-node//ip"],
7
+
10
8
  ["identity", "not-node//requiredObject"],
11
9
  ];
12
10
 
@@ -5,9 +5,6 @@ const { firstLetterToUpper } = require("../common");
5
5
  //form
6
6
  const FIELDS = [
7
7
  ["targetId", { required: true }, "not-node//objectId"],
8
- ["activeUserId", { required: true }, "not-node//objectId"],
9
- ["activeUser", "not-node//requiredObject"],
10
- ["ip", "not-node//ip"],
11
8
  ["identity", "not-node//requiredObject"],
12
9
  ];
13
10
 
@@ -5,9 +5,6 @@ const notAppIdentity = require("../identity");
5
5
 
6
6
  const FIELDS = [
7
7
  ["query", `not-filter//_filterQuery`],
8
- ["activeUserId", { required: true }, "not-node//objectId"],
9
- ["activeUser", "not-node//requiredObject"],
10
- ["ip", "not-node//ip"],
11
8
  ["identity", "not-node//requiredObject"],
12
9
  ];
13
10
 
@@ -5,9 +5,6 @@ const notAppIdentity = require("../identity");
5
5
 
6
6
  const FIELDS = [
7
7
  ["query", `not-filter//_filterQuery`],
8
- ["activeUserId", { required: true }, "not-node//objectId"],
9
- ["activeUser", "not-node//requiredObject"],
10
- ["ip", "not-node//ip"],
11
8
  ["identity", "not-node//requiredObject"],
12
9
  ];
13
10
 
@@ -1,5 +1,7 @@
1
1
  const log = require("not-log")(module, "RateLimiter");
2
2
  const { partCopyObj } = require("../../common");
3
+ const notEnv = require("../../env");
4
+ const { RateLimiterRedis } = require("rate-limiter-flexible");
3
5
 
4
6
  const DEFAULT_OPTIONS = {
5
7
  keyPrefix: "rateLimiterMiddleware",
@@ -44,15 +46,43 @@ module.exports = class InitRateLimiter {
44
46
  };
45
47
  }
46
48
 
47
- static createRateLimiter({ master, config }) {
48
- const { RateLimiterRedis } = require("rate-limiter-flexible");
49
- const storeClient = config.get(
50
- "modules.rateLimiter.client",
51
- DEFAULT_CLIENT
49
+ static createRateLimiter({ config }) {
50
+ const storeClient = InitRateLimiter.getClient(
51
+ InitRateLimiter.getClientName({ config })
52
52
  );
53
53
  return new RateLimiterRedis({
54
- storeClient: master.getEnv(`db.${storeClient}`),
55
- ...InitRateLimiter.getOptions({ master, config }),
54
+ storeClient,
55
+ ...InitRateLimiter.getOptions({ config }),
56
+ });
57
+ }
58
+
59
+ /**
60
+ * Returns redis client name in "db.*" of notEnv
61
+ *
62
+ * @static
63
+ * @param {object} { config }
64
+ * @return {string}
65
+ */
66
+ static getClientName({ config }) {
67
+ return config.get("modules.rateLimiter.client", DEFAULT_CLIENT);
68
+ }
69
+
70
+ static getClient(storeClient) {
71
+ return notEnv.getEnv(`db.${storeClient}`);
72
+ }
73
+
74
+ static initCustom(
75
+ options = {
76
+ keyPrefix: "rateLimiterCustom",
77
+ points: 20,
78
+ duration: 1,
79
+ },
80
+ storeName = DEFAULT_CLIENT
81
+ ) {
82
+ const storeClient = InitRateLimiter.getClient(storeName);
83
+ return new RateLimiterRedis({
84
+ storeClient,
85
+ ...options,
56
86
  });
57
87
  }
58
88
  };
@@ -4,7 +4,6 @@ module.exports = class InitSecurity {
4
4
  getCSPDirectives({ config }) {
5
5
  try {
6
6
  let corsArr = config.get("cors");
7
- let corsLine = corsArr ? corsArr.join(" ") : "";
8
7
  let CSPDirectives = config.get("CSP");
9
8
  let result = {};
10
9
  Object.keys(CSPDirectives).forEach((nm) => {
@@ -13,7 +12,7 @@ module.exports = class InitSecurity {
13
12
  Array.isArray(corsArr) &&
14
13
  ["default-src", "connect-src"].includes(nm)
15
14
  ) {
16
- result[nm].push(...corsLine);
15
+ result[nm].push(...corsArr);
17
16
  }
18
17
  });
19
18
  return result;
@@ -71,7 +71,7 @@ class notRoute {
71
71
 
72
72
  /**
73
73
  * Select rule from available or return null
74
- * @param {import('../types').ExtendedExpressRequest} req Express Request Object
74
+ * @param {import('../types').notNodeExpressRequest} req Express Request Object
75
75
  * @return {import('../types').notRouteRule | null} rule or null
76
76
  */
77
77
  selectRule(req) {
@@ -85,7 +85,7 @@ class notRoute {
85
85
  /**
86
86
  *
87
87
  *
88
- * @param {import('../types').ExtendedExpressRequest} req
88
+ * @param {import('../types').notNodeExpressRequest} req
89
89
  * @param {import('../types').notRouteData} notRouteData
90
90
  * @memberof notRoute
91
91
  */
@@ -112,7 +112,7 @@ class notRoute {
112
112
 
113
113
  /**
114
114
  * Executes route action if such exist
115
- * @param {import('../types').ExtendedExpressRequest} req Express Request Object
115
+ * @param {import('../types').notNodeExpressRequest} req Express Request Object
116
116
  * @param {import('express').Response} res Express Response Object
117
117
  * @param {function} next
118
118
  * @return {object} result of execution or HttpError