not-node 6.5.32 → 6.5.33

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.5.32",
3
+ "version": "6.5.33",
4
4
  "description": "node complimentary part for client side notFramework.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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 objHas(val, "ip") && typeof val.ip === "string";
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 validator.isMongoId(val);
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
- validator(val, { validator }) {
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
  ];
@@ -4,10 +4,10 @@ module.exports = [
4
4
  return !isNaN(val);
5
5
  },
6
6
  message: "not-node:value_is_not_number",
7
- },
7
+ },
8
8
  {
9
9
  validator(val) {
10
- return (val > 0) && (val === 0);
10
+ return val >= 0;
11
11
  },
12
12
  message: "not-node:value_should_be_greater_than_zero",
13
13
  },
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 { createSchemaFromFields, normalizeFieldsDescriptionsList } = require("../fields");
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
- return () => {
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
- validator,
436
- env: true, //some env variables for validators
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
  }
@@ -6,5 +6,6 @@ module.exports = {
6
6
  stringToJSON: require("./stringToJSON.js"),
7
7
  xss: require("./xss.js"),
8
8
  boolean: require("./boolean.js"),
9
+ parseNumber: require("./parseNumber.js"),
9
10
  __CLEAR__: require("./__CLEAR__.js"),
10
11
  };
@@ -0,0 +1,3 @@
1
+ module.exports = (input) => {
2
+ return ~~input;
3
+ };