not-node 6.3.59 → 6.3.61

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.59",
3
+ "version": "6.3.61",
4
4
  "description": "node complimentary part for client side notFramework.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -36,24 +36,24 @@
36
36
  "url": "https://github.com/interrupter/not-node/issues"
37
37
  },
38
38
  "dependencies": {
39
- "body-parser": "^1.20.1",
40
- "commander": "^9.5.0",
39
+ "body-parser": "^1.20.2",
40
+ "commander": "^12.0.0",
41
41
  "compression": "^1.7.4",
42
- "connect-mongodb-session": "^3.1.1",
43
- "connect-redis": "^6.1.3",
42
+ "connect-mongodb-session": "^5.0.0",
43
+ "connect-redis": "^7.1.1",
44
44
  "cors": "^2.8.5",
45
45
  "deep-diff": "*",
46
- "deepmerge": "^4.2.2",
47
- "ejs": "^3.1.8",
46
+ "deepmerge": "^4.3.1",
47
+ "ejs": "^3.1.9",
48
48
  "escape-string-regexp": "*",
49
- "express": "^4.18.2",
50
- "express-fileupload": "^1.4.0",
51
- "express-session": "^1.17.3",
49
+ "express": "^4.19.1",
50
+ "express-fileupload": "^1.5.0",
51
+ "express-session": "^1.18.0",
52
52
  "fs-extra": "*",
53
- "generate-password": "^1.7.0",
54
- "helmet": "^6.0.1",
55
- "inquirer": "^9.1.4",
56
- "jsonwebtoken": "^9.0.0",
53
+ "generate-password": "^1.7.1",
54
+ "helmet": "^7.1.0",
55
+ "inquirer": "^9.2.16",
56
+ "jsonwebtoken": "^9.0.2",
57
57
  "lower-case": "*",
58
58
  "method-override": "^3.0.0",
59
59
  "mongoose-validator": "*",
@@ -65,10 +65,10 @@
65
65
  "not-log": "*",
66
66
  "not-monitor": "*",
67
67
  "not-path": "*",
68
- "rate-limiter-flexible": "^2.4.1",
69
- "redis": "^4.5.1",
68
+ "rate-limiter-flexible": "^5.0.0",
69
+ "redis": "^4.6.13",
70
70
  "redlock": "^5.0.0-beta.2",
71
- "rfdc": "^1.3.0",
71
+ "rfdc": "^1.3.1",
72
72
  "rimraf": "^5.0.5",
73
73
  "serve-static": "*",
74
74
  "simple-git": "*",
@@ -80,23 +80,23 @@
80
80
  "babel-eslint": "^10.1.0",
81
81
  "chai": "*",
82
82
  "chai-as-promised": "*",
83
- "eslint": "^8.31.0",
83
+ "eslint": "^8.57.0",
84
84
  "eslint-plugin-node": "^11.1.0",
85
- "eslint-plugin-sonarjs": "^0.17.0",
86
- "husky": "^8.0.3",
85
+ "eslint-plugin-sonarjs": "^0.24.0",
86
+ "husky": "^9.0.11",
87
87
  "ink-docstrap": "^1.3.2",
88
- "ioredis": "^5.2.4",
89
- "jsdoc": "^4.0.0",
88
+ "ioredis": "^5.3.2",
89
+ "jsdoc": "^4.0.2",
90
90
  "mocha": "*",
91
- "mocha-suppress-logs": "^0.3.1",
91
+ "mocha-suppress-logs": "^0.5.1",
92
92
  "mock-require": "^3.0.3",
93
- "mongodb-memory-server": "^9.1.6",
94
- "mongoose": "^8.1.1",
93
+ "mongodb-memory-server": "^9.1.7",
94
+ "mongoose": "^8.2.3",
95
95
  "not-error": "^0.2.9",
96
96
  "not-validation": "^0.0.9",
97
97
  "npm-run-all": "^4.1.5",
98
98
  "nyc": "^15.1.0",
99
- "retire": "^3.2.1"
99
+ "retire": "^4.4.2"
100
100
  },
101
101
  "homepage": "https://github.com/interrupter/not-node#readme",
102
102
  "nyc": {
@@ -0,0 +1,16 @@
1
+ const USER_MODEL_NAME = "User";
2
+ const notError = require("not-error/src/error.node.cjs");
3
+
4
+ module.exports = (prepared /*, req*/) => {
5
+ if (!prepared?.identity?.root && !prepared?.identity?.admin) {
6
+ if (prepared.identity?.uid) {
7
+ prepared.data.owner = prepared.identity?.uid;
8
+ prepared.data.ownerModel = USER_MODEL_NAME;
9
+ } else {
10
+ throw new notError("User identity has no uid in it", {
11
+ sid: prepared.identity?.sid,
12
+ });
13
+ }
14
+ }
15
+ return prepared;
16
+ };
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ addOwnerFieldsToDataIfNotRootOrAdmin: require("./addOwnerFieldsToDataIfNotRootOrAdmin.js"),
3
+ };
package/src/form/form.js CHANGED
@@ -30,6 +30,7 @@ const {
30
30
  const DEFAULT_EXTRACTORS = require("./extractors");
31
31
  const DEFAULT_ID_EXTRACTORS = require("./env_extractors");
32
32
  const DEFAULT_TRANSFORMERS = require("./transformers");
33
+ const DEFAULT_AFTER_EXTRACT_TRANSFORMERS = [];
33
34
  const notAppIdentity = require("../identity/index.js");
34
35
 
35
36
  /**
@@ -67,6 +68,10 @@ class Form {
67
68
  ...DEFAULT_TRANSFORMERS,
68
69
  };
69
70
 
71
+ #AFTER_EXTRACT_TRANSFORMERS = {
72
+ ...DEFAULT_AFTER_EXTRACT_TRANSFORMERS,
73
+ };
74
+
70
75
  #rateLimiter = null;
71
76
  #rateLimiterIdGetter = (data) => data.identity.sid;
72
77
  #rateLimiterException = FormExceptionTooManyRequests;
@@ -82,6 +87,7 @@ class Form {
82
87
  * @param {import('../app.js')} options.app
83
88
  * @param {Object.<string, Function>} options.EXTRACTORS
84
89
  * @param {Object.<string, Function>} options.TRANSFORMERS
90
+ * @param {Array<Function>} options.AFTER_EXTRACT_TRANSFORMERS
85
91
  * @param {Object.<string, import('../types.js').notAppFormEnvExtractor>} options.ENV_EXTRACTORS
86
92
  * @param {import('../types.js').notAppFormRateLimiterOptions} options.rate
87
93
  */
@@ -94,6 +100,7 @@ class Form {
94
100
  EXTRACTORS = {},
95
101
  ENV_EXTRACTORS = {},
96
102
  TRANSFORMERS = {},
103
+ AFTER_EXTRACT_TRANSFORMERS = [],
97
104
  rate,
98
105
  }) {
99
106
  this.#FORM_NAME = FORM_NAME;
@@ -105,6 +112,7 @@ class Form {
105
112
  this.#addExtractors(EXTRACTORS);
106
113
  this.#addEnvExtractors(ENV_EXTRACTORS);
107
114
  this.#addTransformers(TRANSFORMERS);
115
+ this.#addAfterExtractTransformers(AFTER_EXTRACT_TRANSFORMERS);
108
116
  this.#createRateLimiter(rate);
109
117
  }
110
118
 
@@ -224,6 +232,11 @@ class Form {
224
232
  */
225
233
  //eslint-disable-next-line no-unused-vars
226
234
  async afterExtract(value, req) {
235
+ if (this.#AFTER_EXTRACT_TRANSFORMERS) {
236
+ this.#AFTER_EXTRACT_TRANSFORMERS.forEach((aeTransformer) => {
237
+ aeTransformer(value, req);
238
+ });
239
+ }
227
240
  return value;
228
241
  }
229
242
 
@@ -684,6 +697,12 @@ class Form {
684
697
  }
685
698
  }
686
699
 
700
+ #addAfterExtractTransformers(transformers = []) {
701
+ if (transformers && Array.isArray(transformers)) {
702
+ this.#AFTER_EXTRACT_TRANSFORMERS = [...transformers];
703
+ }
704
+ }
705
+
687
706
  #createRateLimiter(rate) {
688
707
  if (rate && rate.options && typeof rate.options == "object") {
689
708
  if (typeof rate.idGetter === "function") {
@@ -4,7 +4,7 @@ const Form = require("../form/form");
4
4
  //form
5
5
  const FIELDS = [
6
6
  ["targetID", { required: true }, "not-node//ID"],
7
- ["identity", "not-node//requiredObject"],
7
+ ["identity", "not-node//identity"],
8
8
  ];
9
9
 
10
10
  module.exports = ({ MODULE_NAME, MODEL_NAME, actionName = "getByID" }) => {
@@ -4,7 +4,7 @@ const Form = require("../form/form");
4
4
  //form
5
5
  const FIELDS = [
6
6
  ["targetId", { required: true }, "not-node//objectId"],
7
- ["identity", "not-node//requiredObject"],
7
+ ["identity", "not-node//identity"],
8
8
  ];
9
9
 
10
10
  module.exports = ({ MODULE_NAME, MODEL_NAME, actionName = "getById" }) => {
@@ -5,7 +5,7 @@ const notAppIdentity = require("../identity");
5
5
 
6
6
  const FIELDS = [
7
7
  ["query", `not-filter//_filterQuery`],
8
- ["identity", "not-node//requiredObject"],
8
+ ["identity", "not-node//identity"],
9
9
  ];
10
10
 
11
11
  /**
@@ -5,7 +5,7 @@ const notAppIdentity = require("../identity");
5
5
 
6
6
  const FIELDS = [
7
7
  ["query", `not-filter//_filterQuery`],
8
- ["identity", "not-node//requiredObject"],
8
+ ["identity", "not-node//identity"],
9
9
  ];
10
10
 
11
11
  /**
@@ -9,7 +9,7 @@ module.exports = class InitSessionsRedis {
9
9
  const expressSession = require("express-session");
10
10
  const storeClient = config.get("session.client", DEFAULT_CLIENT);
11
11
  const redisClient = master.getEnv(`db.${storeClient}`);
12
- const redisStore = require("connect-redis")(expressSession);
12
+ const redisStore = require("connect-redis").default;
13
13
  master.getServer().use(
14
14
  expressSession({
15
15
  secret: config.get("session.secret"),
@@ -29,10 +29,7 @@ module.exports = ({ expect }) => {
29
29
  ]);
30
30
  return () => {};
31
31
  });
32
- mock("connect-redis", (inpt) => {
33
- expect(typeof inpt).to.be.equal("function");
34
- return class FakeRedis {};
35
- });
32
+ mock("connect-redis", { default: class FakeRedis {} });
36
33
 
37
34
  const config = {
38
35
  get(str) {