not-node 6.5.32 → 6.5.34
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 +1 -1
- package/src/core/fields/validators/identity.js +6 -2
- package/src/core/fields/validators/objectId.js +5 -1
- package/src/core/fields/validators/objectId.list.js +3 -6
- package/src/core/fields/validators/owner.js +3 -11
- package/src/core/fields/validators/positive.or.zero.number.js +2 -2
- package/src/form/form.js +29 -6
- package/src/form/transformers/index.js +1 -0
- package/src/form/transformers/parseNumber.js +3 -0
package/package.json
CHANGED
|
@@ -50,8 +50,12 @@ module.exports = [
|
|
|
50
50
|
message: "not-node:identity_field_sid_is_undefined",
|
|
51
51
|
},
|
|
52
52
|
{
|
|
53
|
-
validator(val) {
|
|
54
|
-
return
|
|
53
|
+
validator(val, { validator }) {
|
|
54
|
+
return (
|
|
55
|
+
objHas(val, "ip") &&
|
|
56
|
+
typeof val.ip === "string" &&
|
|
57
|
+
validator.isIP(val.ip)
|
|
58
|
+
);
|
|
55
59
|
},
|
|
56
60
|
message: "not-node:identity_field_ip_is_not_valid",
|
|
57
61
|
},
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
module.exports = [
|
|
2
2
|
{
|
|
3
3
|
validator: (val, { validator }) => {
|
|
4
|
-
return
|
|
4
|
+
return (
|
|
5
|
+
(typeof val === "string" && validator.isMongoId(val)) ||
|
|
6
|
+
(typeof val.toString === "function" &&
|
|
7
|
+
validator.isMongoId(val.toString()))
|
|
8
|
+
);
|
|
5
9
|
},
|
|
6
10
|
message: `not-node:value_item_format_is_not_objectId`,
|
|
7
11
|
},
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
+
const objectId = require("./objectId.js");
|
|
2
|
+
|
|
1
3
|
module.exports = [
|
|
2
4
|
{
|
|
3
5
|
validator: (val) => {
|
|
4
6
|
return Array.isArray(val);
|
|
5
7
|
},
|
|
6
8
|
message: `not-node:value_is_not_array`,
|
|
7
|
-
},
|
|
8
|
-
{
|
|
9
|
-
validator: (val, { validator }) => {
|
|
10
|
-
return val.every((itm) => validator.isMongoId(itm));
|
|
11
|
-
},
|
|
12
|
-
message: `not-node:value_item_format_is_not_objectId`,
|
|
13
9
|
},
|
|
10
|
+
...objectId,
|
|
14
11
|
];
|
|
@@ -1,16 +1,8 @@
|
|
|
1
|
+
const objectId = require("./objectId");
|
|
2
|
+
|
|
1
3
|
module.exports = [
|
|
2
4
|
{
|
|
3
|
-
|
|
4
|
-
if (typeof val === "string") {
|
|
5
|
-
return validator.isMongoId(val);
|
|
6
|
-
} else {
|
|
7
|
-
return (
|
|
8
|
-
val &&
|
|
9
|
-
typeof val === "object" &&
|
|
10
|
-
val.constructor.name === "ObjectId"
|
|
11
|
-
);
|
|
12
|
-
}
|
|
13
|
-
},
|
|
5
|
+
...objectId[0],
|
|
14
6
|
message: "not-node:owner_is_not_valid",
|
|
15
7
|
},
|
|
16
8
|
];
|
package/src/form/form.js
CHANGED
|
@@ -3,8 +3,12 @@ const validator = require("validator");
|
|
|
3
3
|
const notPath = require("not-path");
|
|
4
4
|
const notConfig = require("not-config");
|
|
5
5
|
const FormFabric = require("./fabric");
|
|
6
|
+
const notEnv = require("../env.js");
|
|
6
7
|
const Auth = require("../auth");
|
|
7
|
-
const {
|
|
8
|
+
const {
|
|
9
|
+
createSchemaFromFields,
|
|
10
|
+
normalizeFieldsDescriptionsList,
|
|
11
|
+
} = require("../fields");
|
|
8
12
|
const notFieldsFilter = require("../fields/filter.js");
|
|
9
13
|
const getApp = require("../getApp.js");
|
|
10
14
|
const {
|
|
@@ -36,6 +40,11 @@ const DEFAULT_AFTER_EXTRACT_TRANSFORMERS = [];
|
|
|
36
40
|
const notAppIdentity = require("../identity/index.js");
|
|
37
41
|
const { ACTION_DATA_TYPES } = require("../const.js");
|
|
38
42
|
|
|
43
|
+
const DEFAULT_VALIDATOR_ENVS = {
|
|
44
|
+
validator,
|
|
45
|
+
env: true, //some env variables for validators
|
|
46
|
+
};
|
|
47
|
+
|
|
39
48
|
/**
|
|
40
49
|
* Generic form validation class
|
|
41
50
|
* @class Form
|
|
@@ -427,15 +436,27 @@ class Form {
|
|
|
427
436
|
* Returns function that works as a getter for additional environment variables for
|
|
428
437
|
* validators.
|
|
429
438
|
* validationFunction(value, additionalEnvVars = {}){}
|
|
439
|
+
* @return {function} getter of validator envs
|
|
430
440
|
**/
|
|
431
441
|
getValidatorEnvGetter() {
|
|
432
|
-
|
|
442
|
+
//app wide validation envs
|
|
443
|
+
const appLevelValidationEnvsGetter = notEnv.get("validationEnv");
|
|
444
|
+
if (typeof appLevelValidationEnvsGetter === "function") {
|
|
433
445
|
//should be sync function
|
|
434
|
-
return {
|
|
435
|
-
|
|
436
|
-
|
|
446
|
+
return () => {
|
|
447
|
+
return Object.freeze({
|
|
448
|
+
...DEFAULT_VALIDATOR_ENVS,
|
|
449
|
+
...appLevelValidationEnvsGetter(),
|
|
450
|
+
});
|
|
437
451
|
};
|
|
438
|
-
}
|
|
452
|
+
} else {
|
|
453
|
+
return () => {
|
|
454
|
+
//should be sync function
|
|
455
|
+
return Object.freeze({
|
|
456
|
+
...DEFAULT_VALIDATOR_ENVS,
|
|
457
|
+
});
|
|
458
|
+
};
|
|
459
|
+
}
|
|
439
460
|
}
|
|
440
461
|
|
|
441
462
|
/**
|
|
@@ -743,6 +764,8 @@ class Form {
|
|
|
743
764
|
case String:
|
|
744
765
|
case Schema.Types.String:
|
|
745
766
|
return ["xss"];
|
|
767
|
+
case Schema.Types.Number:
|
|
768
|
+
return ["parseNumber"];
|
|
746
769
|
default:
|
|
747
770
|
return [];
|
|
748
771
|
}
|