not-node 6.5.35 → 6.5.36
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 +2 -1
- package/src/common.js +40 -0
- package/src/core/fields/ID.js +7 -0
- package/src/core/fields/__version.js +7 -1
- package/src/core/fields/__versions.js +3 -1
- package/src/core/fields/_id.js +3 -2
- package/src/core/fields/boolean.js +3 -0
- package/src/core/fields/boolean.system.js +5 -2
- package/src/core/fields/codeName.js +3 -0
- package/src/core/fields/createdAt.js +3 -1
- package/src/core/fields/description.js +6 -0
- package/src/core/fields/email.js +3 -0
- package/src/core/fields/expiredAt.js +3 -1
- package/src/core/fields/height.js +6 -1
- package/src/core/fields/identity.js +2 -0
- package/src/core/fields/ip.js +3 -0
- package/src/core/fields/objectId.js +2 -0
- package/src/core/fields/ownerModel.js +3 -1
- package/src/core/fields/price.js +6 -1
- package/src/core/fields/requiredObject.js +2 -0
- package/src/core/fields/session.js +3 -0
- package/src/core/fields/size.js +6 -1
- package/src/core/fields/title.js +3 -0
- package/src/core/fields/updatedAt.js +3 -1
- package/src/core/fields/uuid.js +3 -0
- package/src/core/fields/width.js +6 -1
- package/src/core/index.js +2 -1
- package/src/core/validators/boolean.false.js +8 -0
- package/src/core/validators/boolean.js +8 -0
- package/src/core/validators/boolean.true.js +8 -0
- package/src/core/validators/date.js +11 -0
- package/src/core/validators/index.js +33 -0
- package/src/core/validators/number.int.js +9 -0
- package/src/core/validators/number.js +8 -0
- package/src/core/validators/number.positive.js +9 -0
- package/src/core/validators/number.positive.or.zero.js +9 -0
- package/src/core/validators/object.identity.js +110 -0
- package/src/core/validators/object.js +10 -0
- package/src/core/validators/objectId.js +13 -0
- package/src/core/{fields/validators → validators}/objectId.list.js +6 -1
- package/src/core/validators/string.10-10000.js +32 -0
- package/src/core/{fields/validators/email.js → validators/string.email.js} +1 -0
- package/src/core/{fields/validators/ip.js → validators/string.ip.js} +3 -2
- package/src/core/validators/string.js +8 -0
- package/src/core/{fields/validators/title.js → validators/string.not.empty.js} +4 -3
- package/src/core/{fields/validators/telephone.js → validators/string.telephone.js} +2 -1
- package/src/core/{fields/validators/uuid.js → validators/string.uuid.js} +2 -1
- package/src/form/form.js +4 -0
- package/src/form/transformers/parseNumber.js +1 -1
- package/src/identity/index.js +9 -2
- package/test/core.validators.js +790 -0
- package/src/core/fields/validators/ID.js +0 -20
- package/src/core/fields/validators/boolean.js +0 -1
- package/src/core/fields/validators/boolean.system.js +0 -8
- package/src/core/fields/validators/codeName.js +0 -16
- package/src/core/fields/validators/date.js +0 -8
- package/src/core/fields/validators/description.js +0 -33
- package/src/core/fields/validators/identity.js +0 -68
- package/src/core/fields/validators/modelName.js +0 -16
- package/src/core/fields/validators/objectId.js +0 -12
- package/src/core/fields/validators/owner.js +0 -8
- package/src/core/fields/validators/positive.or.zero.number.js +0 -14
- package/src/core/fields/validators/requiredObject.js +0 -10
- package/src/core/fields/validators/session.js +0 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "not-node",
|
|
3
|
-
"version": "6.5.
|
|
3
|
+
"version": "6.5.36",
|
|
4
4
|
"description": "node complimentary part for client side notFramework.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"url": "https://github.com/interrupter/not-node/issues"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
+
"ajv": "^8.17.1",
|
|
39
40
|
"body-parser": "^1.20.2",
|
|
40
41
|
"commander": "^12.1.0",
|
|
41
42
|
"compression": "^1.7.4",
|
package/src/common.js
CHANGED
|
@@ -496,3 +496,43 @@ module.exports.isAction = isAction;
|
|
|
496
496
|
const isArrayOfActions = (list) => list.every(isAction);
|
|
497
497
|
|
|
498
498
|
module.exports.isArrayOfActions = isArrayOfActions;
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* Creates functions that executes validator function from array of objects
|
|
502
|
+
* {validator:function, message:string}
|
|
503
|
+
* If validator returns false - it throws message from object, if all validator returns true -
|
|
504
|
+
* function returns true
|
|
505
|
+
* @param {Array<Object>} validators
|
|
506
|
+
* @param {any} val
|
|
507
|
+
* @param {Object} envs
|
|
508
|
+
* @return {function}
|
|
509
|
+
*/
|
|
510
|
+
const createValidatorsRunner = (validators, val, envs) => {
|
|
511
|
+
return () => {
|
|
512
|
+
for (let { message, validator } of validators) {
|
|
513
|
+
if (!validator(val, envs)) {
|
|
514
|
+
throw new Error(message);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
return true;
|
|
518
|
+
};
|
|
519
|
+
};
|
|
520
|
+
module.exports.createValidatorsRunner = createValidatorsRunner;
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* Changes default message if custom set to true, by replacing part of it with another string
|
|
524
|
+
*
|
|
525
|
+
* @param {string} message
|
|
526
|
+
* @param {boolean} custom
|
|
527
|
+
* @param {string} find
|
|
528
|
+
* @param {string} replace
|
|
529
|
+
* @return {string}
|
|
530
|
+
*/
|
|
531
|
+
const createCustomMessage = (message, custom, find, replace) => {
|
|
532
|
+
if (custom) {
|
|
533
|
+
return message.replace(find, replace);
|
|
534
|
+
} else {
|
|
535
|
+
return message;
|
|
536
|
+
}
|
|
537
|
+
};
|
|
538
|
+
module.exports.createCustomMessage = createCustomMessage;
|
package/src/core/fields/ID.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const Validators = require("../validators");
|
|
2
|
+
|
|
1
3
|
module.exports = {
|
|
2
4
|
ui: {
|
|
3
5
|
component: "UITextfield",
|
|
@@ -9,5 +11,10 @@ module.exports = {
|
|
|
9
11
|
type: Number,
|
|
10
12
|
required: true,
|
|
11
13
|
safe: require("../safety.protocols").ownerRootAdmin,
|
|
14
|
+
validate: [
|
|
15
|
+
...Validators.Number.type,
|
|
16
|
+
...Validators.Number.int,
|
|
17
|
+
...Validators.Number.positive,
|
|
18
|
+
],
|
|
12
19
|
},
|
|
13
20
|
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const Validators = require("../validators");
|
|
2
|
+
|
|
1
3
|
module.exports = {
|
|
2
4
|
ui: {
|
|
3
5
|
component: "UIHidden",
|
|
@@ -7,6 +9,10 @@ module.exports = {
|
|
|
7
9
|
type: Number,
|
|
8
10
|
default: 0,
|
|
9
11
|
required: true,
|
|
10
|
-
validate:
|
|
12
|
+
validate: [
|
|
13
|
+
...Validators.Number.type,
|
|
14
|
+
...Validators.Number.int,
|
|
15
|
+
...Validators.Number.positiveOrZero,
|
|
16
|
+
],
|
|
11
17
|
},
|
|
12
18
|
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
const Validators = require("../validators");
|
|
2
|
+
|
|
1
3
|
module.exports = {
|
|
2
4
|
ui: {
|
|
3
5
|
component: "UIHidden",
|
|
4
6
|
},
|
|
5
7
|
model: {
|
|
6
8
|
safe: require("../safety.protocols").systemManageable,
|
|
7
|
-
validate:
|
|
9
|
+
validate: Validators.ObjectId.list,
|
|
8
10
|
},
|
|
9
11
|
};
|
package/src/core/fields/_id.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
const
|
|
1
|
+
const Validators = require("../validators");
|
|
2
|
+
const ObjectId = require("mongoose").SchemaTypes.ObjectId;
|
|
2
3
|
|
|
3
4
|
module.exports = {
|
|
4
5
|
ui: {
|
|
@@ -10,6 +11,6 @@ module.exports = {
|
|
|
10
11
|
model: {
|
|
11
12
|
type: ObjectId,
|
|
12
13
|
safe: require("../safety.protocols").systemManageable,
|
|
13
|
-
validate:
|
|
14
|
+
validate: Validators.ObjectId.type,
|
|
14
15
|
},
|
|
15
16
|
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const Validators = require("../validators");
|
|
2
|
+
|
|
1
3
|
module.exports = {
|
|
2
4
|
ui: {
|
|
3
5
|
component: "UISwitch",
|
|
@@ -9,5 +11,6 @@ module.exports = {
|
|
|
9
11
|
default: false,
|
|
10
12
|
required: true,
|
|
11
13
|
safe: require("../safety.protocols").ownerRootAdmin,
|
|
14
|
+
validate: Validators.Boolean.type,
|
|
12
15
|
},
|
|
13
16
|
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
const Validators = require("../validators");
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
2
4
|
ui: {
|
|
3
5
|
component: "UIHidden",
|
|
4
6
|
},
|
|
@@ -6,6 +8,7 @@ module.exports = {
|
|
|
6
8
|
type: Boolean,
|
|
7
9
|
default: false,
|
|
8
10
|
required: true,
|
|
9
|
-
safe: require("
|
|
11
|
+
safe: require("../safety.protocols").systemManageable,
|
|
12
|
+
validate: Validators.Boolean.type,
|
|
10
13
|
},
|
|
11
14
|
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const Validators = require("../validators");
|
|
2
|
+
|
|
1
3
|
module.exports = {
|
|
2
4
|
ui: {
|
|
3
5
|
component: "UITextfield",
|
|
@@ -10,5 +12,6 @@ module.exports = {
|
|
|
10
12
|
required: true,
|
|
11
13
|
transformers: ["xss"],
|
|
12
14
|
safe: require("../safety.protocols").ownerRootAdmin,
|
|
15
|
+
validate: [...Validators.String.type, ...Validators.String.notEmpty],
|
|
13
16
|
},
|
|
14
17
|
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const Validators = require("../validators");
|
|
2
|
+
|
|
1
3
|
module.exports = {
|
|
2
4
|
ui: {
|
|
3
5
|
component: "UIDate",
|
|
@@ -12,6 +14,6 @@ module.exports = {
|
|
|
12
14
|
searchable: true,
|
|
13
15
|
sortable: true,
|
|
14
16
|
safe: require("../safety.protocols").systemManageable,
|
|
15
|
-
validate:
|
|
17
|
+
validate: [...Validators.Date.type],
|
|
16
18
|
},
|
|
17
19
|
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const Validators = require("../validators");
|
|
2
|
+
|
|
1
3
|
module.exports = {
|
|
2
4
|
ui: {
|
|
3
5
|
component: "UITextarea",
|
|
@@ -12,5 +14,9 @@ module.exports = {
|
|
|
12
14
|
sortable: true,
|
|
13
15
|
transformers: ["xss"],
|
|
14
16
|
safe: require("../safety.protocols").ownerRootAdmin,
|
|
17
|
+
validate: [
|
|
18
|
+
...Validators.String.type,
|
|
19
|
+
...Validators.String.from10to10000,
|
|
20
|
+
],
|
|
15
21
|
},
|
|
16
22
|
};
|
package/src/core/fields/email.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const Validators = require("../validators");
|
|
2
|
+
|
|
1
3
|
module.exports = {
|
|
2
4
|
ui: {
|
|
3
5
|
component: "UIEmail",
|
|
@@ -10,5 +12,6 @@ module.exports = {
|
|
|
10
12
|
required: true,
|
|
11
13
|
transformers: ["xss"],
|
|
12
14
|
safe: require("../safety.protocols").ownerRootAdmin,
|
|
15
|
+
validate: [...Validators.String.type, ...Validators.String.email],
|
|
13
16
|
},
|
|
14
17
|
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const Validators = require("../validators");
|
|
2
|
+
|
|
1
3
|
module.exports = {
|
|
2
4
|
ui: {
|
|
3
5
|
component: "UITextfield",
|
|
@@ -11,6 +13,6 @@ module.exports = {
|
|
|
11
13
|
searchable: true,
|
|
12
14
|
sortable: true,
|
|
13
15
|
safe: require("../safety.protocols").ownerRootAdmin,
|
|
14
|
-
validate:
|
|
16
|
+
validate: Validators.Date.type,
|
|
15
17
|
},
|
|
16
18
|
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const Validators = require("../validators");
|
|
2
|
+
|
|
1
3
|
module.exports = {
|
|
2
4
|
ui: {
|
|
3
5
|
component: "UITextfield",
|
|
@@ -11,6 +13,9 @@ module.exports = {
|
|
|
11
13
|
searchable: true,
|
|
12
14
|
sortable: true,
|
|
13
15
|
safe: require("../safety.protocols").ownerRootAdmin,
|
|
14
|
-
validate:
|
|
16
|
+
validate: [
|
|
17
|
+
...Validators.Number.type,
|
|
18
|
+
...Validators.Number.positiveOrZero,
|
|
19
|
+
],
|
|
15
20
|
},
|
|
16
21
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const Validators = require("../validators");
|
|
1
2
|
const Schema = require("mongoose").Schema;
|
|
2
3
|
|
|
3
4
|
module.exports = {
|
|
@@ -5,5 +6,6 @@ module.exports = {
|
|
|
5
6
|
type: Schema.Types.Mixed,
|
|
6
7
|
required: true,
|
|
7
8
|
safe: require("../safety.protocols").ownerRootAdmin,
|
|
9
|
+
validate: Validators.Object.identity,
|
|
8
10
|
},
|
|
9
11
|
};
|
package/src/core/fields/ip.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const Validators = require("../validators");
|
|
2
|
+
|
|
1
3
|
module.exports = {
|
|
2
4
|
ui: {
|
|
3
5
|
component: "UITextfield",
|
|
@@ -11,5 +13,6 @@ module.exports = {
|
|
|
11
13
|
required: true,
|
|
12
14
|
safe: require("../safety.protocols").ownerRootAdmin,
|
|
13
15
|
transformers: ["xss"],
|
|
16
|
+
validate: [...Validators.String.type, ...Validators.String.ip],
|
|
14
17
|
},
|
|
15
18
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const Validators = require("../validators");
|
|
1
2
|
const ObjectId = require("mongoose").Schema.Types.ObjectId;
|
|
2
3
|
|
|
3
4
|
module.exports = {
|
|
@@ -7,6 +8,7 @@ module.exports = {
|
|
|
7
8
|
default: null,
|
|
8
9
|
transformers: ["xss", "__CLEAR__"],
|
|
9
10
|
safe: require("../safety.protocols").ownerRootAdmin,
|
|
11
|
+
validate: Validators.ObjectId.type,
|
|
10
12
|
},
|
|
11
13
|
ui: {
|
|
12
14
|
default: null,
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
const Validators = require("../validators");
|
|
2
|
+
|
|
1
3
|
module.exports = {
|
|
2
4
|
model: {
|
|
3
5
|
type: String,
|
|
4
6
|
required: false,
|
|
5
7
|
safe: require("../safety.protocols").ownerRootAdmin,
|
|
6
8
|
transformers: ["xss"],
|
|
7
|
-
validate:
|
|
9
|
+
validate: [...Validators.String.type, ...Validators.String.notEmpty],
|
|
8
10
|
},
|
|
9
11
|
ui: {
|
|
10
12
|
component: "UIHidden",
|
package/src/core/fields/price.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const Validators = require("../validators");
|
|
2
|
+
|
|
1
3
|
module.exports = {
|
|
2
4
|
ui: {
|
|
3
5
|
component: "UITextfield",
|
|
@@ -11,6 +13,9 @@ module.exports = {
|
|
|
11
13
|
searchable: true,
|
|
12
14
|
sortable: true,
|
|
13
15
|
safe: require("../safety.protocols").ownerRootAdmin,
|
|
14
|
-
validate:
|
|
16
|
+
validate: [
|
|
17
|
+
...Validators.Number.type,
|
|
18
|
+
...Validators.Number.positiveOrZero,
|
|
19
|
+
],
|
|
15
20
|
},
|
|
16
21
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const Schema = require("mongoose").Schema;
|
|
2
|
+
const Validators = require("../validators");
|
|
2
3
|
|
|
3
4
|
module.exports = {
|
|
4
5
|
model: {
|
|
@@ -6,6 +7,7 @@ module.exports = {
|
|
|
6
7
|
required: true,
|
|
7
8
|
default: {},
|
|
8
9
|
safe: require("../safety.protocols").ownerRootAdmin,
|
|
10
|
+
validate: Validators.Object.type,
|
|
9
11
|
},
|
|
10
12
|
ui: {
|
|
11
13
|
default: {},
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const Validators = require("../validators");
|
|
2
|
+
|
|
1
3
|
module.exports = {
|
|
2
4
|
ui: {
|
|
3
5
|
component: "UITextfield",
|
|
@@ -11,5 +13,6 @@ module.exports = {
|
|
|
11
13
|
required: true,
|
|
12
14
|
transformers: ["xss"],
|
|
13
15
|
safe: require("../safety.protocols").systemManageable,
|
|
16
|
+
validate: [...Validators.String.type, ...Validators.String.notEmpty],
|
|
14
17
|
},
|
|
15
18
|
};
|
package/src/core/fields/size.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const Validators = require("../validators");
|
|
2
|
+
|
|
1
3
|
module.exports = {
|
|
2
4
|
ui: {
|
|
3
5
|
component: "UINumber",
|
|
@@ -11,6 +13,9 @@ module.exports = {
|
|
|
11
13
|
searchable: true,
|
|
12
14
|
sortable: true,
|
|
13
15
|
safe: require("../safety.protocols").ownerRootAdmin,
|
|
14
|
-
validate:
|
|
16
|
+
validate: [
|
|
17
|
+
...Validators.Number.type,
|
|
18
|
+
...Validators.Number.positiveOrZero,
|
|
19
|
+
],
|
|
15
20
|
},
|
|
16
21
|
};
|
package/src/core/fields/title.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const Validators = require("../validators");
|
|
2
|
+
|
|
1
3
|
module.exports = {
|
|
2
4
|
ui: {
|
|
3
5
|
component: "UITextfield",
|
|
@@ -12,5 +14,6 @@ module.exports = {
|
|
|
12
14
|
sortable: true,
|
|
13
15
|
safe: require("../safety.protocols").ownerRootAdmin,
|
|
14
16
|
transformers: ["xss"],
|
|
17
|
+
validate: [...Validators.String.type, ...Validators.String.notEmpty],
|
|
15
18
|
},
|
|
16
19
|
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const Validators = require("../validators");
|
|
2
|
+
|
|
1
3
|
module.exports = {
|
|
2
4
|
ui: {
|
|
3
5
|
component: "UIDate",
|
|
@@ -11,7 +13,7 @@ module.exports = {
|
|
|
11
13
|
type: Date,
|
|
12
14
|
required: true,
|
|
13
15
|
default: Date.now,
|
|
14
|
-
validate:
|
|
16
|
+
validate: [...Validators.Date.type],
|
|
15
17
|
safe: require("../safety.protocols").systemManageable,
|
|
16
18
|
},
|
|
17
19
|
};
|
package/src/core/fields/uuid.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const Validators = require("../validators");
|
|
2
|
+
|
|
1
3
|
module.exports = {
|
|
2
4
|
ui: {
|
|
3
5
|
component: "UITextfield",
|
|
@@ -12,5 +14,6 @@ module.exports = {
|
|
|
12
14
|
required: true,
|
|
13
15
|
transformers: ["xss"],
|
|
14
16
|
safe: require("../safety.protocols").ownerRootAdmin,
|
|
17
|
+
validate: [...Validators.String.type, ...Validators.String.uuid],
|
|
15
18
|
},
|
|
16
19
|
};
|
package/src/core/fields/width.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const Validators = require("../validators");
|
|
2
|
+
|
|
1
3
|
module.exports = {
|
|
2
4
|
ui: {
|
|
3
5
|
component: "UITextfield",
|
|
@@ -11,6 +13,9 @@ module.exports = {
|
|
|
11
13
|
searchable: true,
|
|
12
14
|
sortable: true,
|
|
13
15
|
safe: require("../safety.protocols").ownerRootAdmin,
|
|
14
|
-
validate:
|
|
16
|
+
validate: [
|
|
17
|
+
...Validators.Number.type,
|
|
18
|
+
...Validators.Number.positiveOrZero,
|
|
19
|
+
],
|
|
15
20
|
},
|
|
16
21
|
};
|
package/src/core/index.js
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module.exports = Object.freeze({
|
|
2
|
+
Boolean: {
|
|
3
|
+
type: require("./boolean"),
|
|
4
|
+
true: require("./boolean.true"),
|
|
5
|
+
false: require("./boolean.false"),
|
|
6
|
+
},
|
|
7
|
+
Date: {
|
|
8
|
+
type: require("./date"),
|
|
9
|
+
},
|
|
10
|
+
Number: {
|
|
11
|
+
type: require("./number"),
|
|
12
|
+
int: require("./number.int"),
|
|
13
|
+
positive: require("./number.positive"),
|
|
14
|
+
positiveOrZero: require("./number.positive.or.zero"),
|
|
15
|
+
},
|
|
16
|
+
Object: {
|
|
17
|
+
type: require("./object"),
|
|
18
|
+
identity: require("./object.identity"),
|
|
19
|
+
},
|
|
20
|
+
ObjectId: {
|
|
21
|
+
type: require("./objectId"),
|
|
22
|
+
list: require("./objectId.list"),
|
|
23
|
+
},
|
|
24
|
+
String: {
|
|
25
|
+
type: require("./string"),
|
|
26
|
+
from10to10000: require("./string.10-10000"),
|
|
27
|
+
email: require("./string.email"),
|
|
28
|
+
ip: require("./string.ip"),
|
|
29
|
+
notEmpty: require("./string.not.empty"),
|
|
30
|
+
telephone: require("./string.telephone"),
|
|
31
|
+
uuid: require("./string.uuid"),
|
|
32
|
+
},
|
|
33
|
+
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
//const { objHas } = require("../../common");
|
|
2
|
+
const {
|
|
3
|
+
DEFAULT_USER_ROLE_FOR_ROOT,
|
|
4
|
+
DEFAULT_USER_ROLE_FOR_ADMIN,
|
|
5
|
+
DEFAULT_USER_ROLE_FOR_GUEST,
|
|
6
|
+
} = require("../../auth/const");
|
|
7
|
+
const notValidationError = require("not-error/src/validation.error.node.cjs");
|
|
8
|
+
|
|
9
|
+
const schema = {
|
|
10
|
+
type: "object",
|
|
11
|
+
properties: {
|
|
12
|
+
root: { type: "boolean" },
|
|
13
|
+
admin: { type: "boolean" },
|
|
14
|
+
auth: { type: "boolean" },
|
|
15
|
+
role: {
|
|
16
|
+
type: "array",
|
|
17
|
+
items: { type: "string" },
|
|
18
|
+
},
|
|
19
|
+
primaryRole: {
|
|
20
|
+
type: "string",
|
|
21
|
+
enum: ["root", "admin", "client", "user", "guest"],
|
|
22
|
+
},
|
|
23
|
+
uid: { type: "string" },
|
|
24
|
+
sid: { type: "string" },
|
|
25
|
+
ip: { type: "string" },
|
|
26
|
+
provider: { type: "string" },
|
|
27
|
+
},
|
|
28
|
+
required: [
|
|
29
|
+
"root",
|
|
30
|
+
"admin",
|
|
31
|
+
"auth",
|
|
32
|
+
"role",
|
|
33
|
+
"primaryRole",
|
|
34
|
+
"uid",
|
|
35
|
+
"sid",
|
|
36
|
+
"provider",
|
|
37
|
+
],
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
module.exports = [
|
|
41
|
+
{
|
|
42
|
+
validator(val, { ajv }) {
|
|
43
|
+
const validate = ajv.compile(schema);
|
|
44
|
+
if (validate(val)) {
|
|
45
|
+
return true;
|
|
46
|
+
} else {
|
|
47
|
+
const fields = {};
|
|
48
|
+
validate.errors.forEach((error) => {
|
|
49
|
+
const propName = error.instancePath.replaceAll("/", ".");
|
|
50
|
+
fields[propName] = [error.message];
|
|
51
|
+
});
|
|
52
|
+
throw new notValidationError(
|
|
53
|
+
"not-node:identity_object_is_not_valid",
|
|
54
|
+
fields
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
validator(val) {
|
|
61
|
+
const superuser = val.root || val.admin;
|
|
62
|
+
if (superuser) {
|
|
63
|
+
return val.auth;
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
66
|
+
},
|
|
67
|
+
message: "not-node:identity_root_and_admin_should_be_auth",
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
validator(val) {
|
|
71
|
+
return !(val.admin && val.root);
|
|
72
|
+
},
|
|
73
|
+
message: "not-node:identity_root_and_admin_cant_be_both_true",
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
validator(val) {
|
|
77
|
+
if (val.root) {
|
|
78
|
+
return val.primaryRole === DEFAULT_USER_ROLE_FOR_ROOT;
|
|
79
|
+
}
|
|
80
|
+
return true;
|
|
81
|
+
},
|
|
82
|
+
message: "not-node:identity_root_should_have_primaryRole_root",
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
validator(val) {
|
|
86
|
+
if (val.admin) {
|
|
87
|
+
return val.primaryRole === DEFAULT_USER_ROLE_FOR_ADMIN;
|
|
88
|
+
} else {
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
message: "not-node:identity_admin_should_have_primaryRole_admin",
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
validator(val) {
|
|
96
|
+
if (!val.auth) {
|
|
97
|
+
return val.primaryRole === DEFAULT_USER_ROLE_FOR_GUEST;
|
|
98
|
+
}
|
|
99
|
+
return true;
|
|
100
|
+
},
|
|
101
|
+
message: "not-node:identity_guest_should_have_primaryRole_guest",
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
{
|
|
105
|
+
validator(val) {
|
|
106
|
+
return val.role.includes(val.primaryRole);
|
|
107
|
+
},
|
|
108
|
+
message: "not-node:identity_role_should_contain_primaryRole",
|
|
109
|
+
},
|
|
110
|
+
];
|