not-node 5.1.4 → 5.1.7
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 +13 -13
- package/src/auth/exceptions.js +27 -0
- package/src/auth/roles.js +8 -3
- package/src/generic/logic.js +4 -4
- package/src/model/exceptions.js +40 -0
- package/src/model/increment.js +8 -5
- package/src/model/versioning.js +6 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "not-node",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.7",
|
|
4
4
|
"description": "node complimentary part for client side notFramework.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -40,13 +40,13 @@
|
|
|
40
40
|
"cors": "^2.8.5",
|
|
41
41
|
"deep-diff": "*",
|
|
42
42
|
"deepmerge": "^4.2.2",
|
|
43
|
-
"ejs": "^3.1.
|
|
43
|
+
"ejs": "^3.1.8",
|
|
44
44
|
"escape-string-regexp": "*",
|
|
45
|
-
"express": "^4.
|
|
46
|
-
"express-fileupload": "^1.
|
|
47
|
-
"express-session": "^1.17.
|
|
45
|
+
"express": "^4.18.1",
|
|
46
|
+
"express-fileupload": "^1.4.0",
|
|
47
|
+
"express-session": "^1.17.3",
|
|
48
48
|
"fs-extra": "*",
|
|
49
|
-
"helmet": "^5.0
|
|
49
|
+
"helmet": "^5.1.0",
|
|
50
50
|
"lower-case": "*",
|
|
51
51
|
"method-override": "^3.0.0",
|
|
52
52
|
"mock-require": "^3.0.3",
|
|
@@ -61,9 +61,9 @@
|
|
|
61
61
|
"not-log": "^0.0.20",
|
|
62
62
|
"not-monitor": "^0.0.13",
|
|
63
63
|
"not-path": "*",
|
|
64
|
-
"not-validation": "^0.0.
|
|
65
|
-
"rate-limiter-flexible": "^2.3.
|
|
66
|
-
"redis": "^4.
|
|
64
|
+
"not-validation": "^0.0.8",
|
|
65
|
+
"rate-limiter-flexible": "^2.3.7",
|
|
66
|
+
"redis": "^4.1.1",
|
|
67
67
|
"rfdc": "^1.3.0",
|
|
68
68
|
"rmdir": "^1.2.0",
|
|
69
69
|
"serve-static": "*",
|
|
@@ -75,18 +75,18 @@
|
|
|
75
75
|
"babel-eslint": "^10.1.0",
|
|
76
76
|
"chai": "*",
|
|
77
77
|
"chai-as-promised": "*",
|
|
78
|
-
"eslint": "^8.
|
|
78
|
+
"eslint": "^8.18.0",
|
|
79
79
|
"eslint-plugin-node": "^11.1.0",
|
|
80
80
|
"eslint-plugin-sonarjs": "^0.13.0",
|
|
81
81
|
"ink-docstrap": "^1.3.2",
|
|
82
|
-
"ioredis": "^5.0
|
|
82
|
+
"ioredis": "^5.1.0",
|
|
83
83
|
"jsdoc": "^3.6.10",
|
|
84
84
|
"mocha": "*",
|
|
85
85
|
"mocha-suppress-logs": "^0.3.1",
|
|
86
|
-
"mongodb-memory-server": "^8.
|
|
86
|
+
"mongodb-memory-server": "^8.7.2",
|
|
87
87
|
"npm-run-all": "^4.1.5",
|
|
88
88
|
"nyc": "^15.1.0",
|
|
89
|
-
"retire": "^3.0.
|
|
89
|
+
"retire": "^3.0.7"
|
|
90
90
|
},
|
|
91
91
|
"homepage": "https://github.com/interrupter/not-node#readme",
|
|
92
92
|
"nyc": {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const { notError } = require("not-error");
|
|
2
|
+
|
|
3
|
+
class RolesExceptionRoleSetIsNotValid extends notError {
|
|
4
|
+
constructor(name) {
|
|
5
|
+
super("not-node:auth_roles_role_set_is_not_valid", { name });
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
module.exports.RolesExceptionRoleSetIsNotValid =
|
|
9
|
+
RolesExceptionRoleSetIsNotValid;
|
|
10
|
+
|
|
11
|
+
class RolesExceptionNoRolesSupremacyOrder extends notError {
|
|
12
|
+
constructor() {
|
|
13
|
+
super("not-node:auth_roles_no_roles_supremacy_order");
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports.RolesExceptionNoRolesSupremacyOrder =
|
|
18
|
+
RolesExceptionNoRolesSupremacyOrder;
|
|
19
|
+
|
|
20
|
+
class RolesExceptionSupremacyOrderElementIsNotAString extends notError {
|
|
21
|
+
constructor() {
|
|
22
|
+
super("not-node:auth_roles_supremacy_order_element_is_not_a_string");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
module.exports.RolesExceptionSupremacyOrderElementIsNotAString =
|
|
27
|
+
RolesExceptionSupremacyOrderElementIsNotAString;
|
package/src/auth/roles.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
const ABSTRACT = require("./abstract");
|
|
2
|
+
const {
|
|
3
|
+
RolesExceptionRoleSetIsNotValid,
|
|
4
|
+
RolesExceptionNoRolesSupremacyOrder,
|
|
5
|
+
RolesExceptionSupremacyOrderElementIsNotAString,
|
|
6
|
+
} = require("./exceptions.js");
|
|
2
7
|
|
|
3
8
|
function compareRolesArrayAgainstArray(userRoles, actionRoles, strict) {
|
|
4
9
|
if (strict) {
|
|
@@ -48,7 +53,7 @@ function compareRoles(userRoles, actionRoles, strict = true) {
|
|
|
48
53
|
|
|
49
54
|
function sanitizeAndValidateRoleSet(roleSet, name) {
|
|
50
55
|
if (!Array.isArray(roleSet) && !ABSTRACT.isObjectString(roleSet)) {
|
|
51
|
-
throw new
|
|
56
|
+
throw new RolesExceptionRoleSetIsNotValid(name);
|
|
52
57
|
} else {
|
|
53
58
|
if (!Array.isArray(roleSet)) {
|
|
54
59
|
roleSet = [roleSet];
|
|
@@ -70,14 +75,14 @@ function checkSupremacy(base, against, roles) {
|
|
|
70
75
|
against = sanitizeAndValidateRoleSet(against, "Against");
|
|
71
76
|
|
|
72
77
|
if (!Array.isArray(roles)) {
|
|
73
|
-
throw new
|
|
78
|
+
throw new RolesExceptionNoRolesSupremacyOrder();
|
|
74
79
|
}
|
|
75
80
|
|
|
76
81
|
let baseIndex = -1;
|
|
77
82
|
let againstIndex = -1;
|
|
78
83
|
roles.forEach((role, index) => {
|
|
79
84
|
if (!ABSTRACT.isObjectString(role)) {
|
|
80
|
-
throw new
|
|
85
|
+
throw new RolesExceptionSupremacyOrderElementIsNotAString();
|
|
81
86
|
}
|
|
82
87
|
if (baseIndex === -1 && base.indexOf(role) > -1) {
|
|
83
88
|
baseIndex = index;
|
package/src/generic/logic.js
CHANGED
|
@@ -125,7 +125,7 @@ module.exports = ({
|
|
|
125
125
|
});
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
async _updateOne({
|
|
128
|
+
static async _updateOne({
|
|
129
129
|
targetId,
|
|
130
130
|
data,
|
|
131
131
|
activeUser,
|
|
@@ -146,7 +146,7 @@ module.exports = ({
|
|
|
146
146
|
if (shouldOwn) {
|
|
147
147
|
query[ownerFieldName] = activeUser._id;
|
|
148
148
|
}
|
|
149
|
-
const result = await getModel().update(query, data)
|
|
149
|
+
const result = await getModel().update(query, data);
|
|
150
150
|
LogAction(
|
|
151
151
|
{
|
|
152
152
|
action,
|
|
@@ -222,7 +222,7 @@ module.exports = ({
|
|
|
222
222
|
* @param {boolean} prepared.shouldOwn if user should be owner of target
|
|
223
223
|
* @returns {Promise<Object>} requested document
|
|
224
224
|
**/
|
|
225
|
-
async _getOne({
|
|
225
|
+
static async _getOne({
|
|
226
226
|
targetId,
|
|
227
227
|
action,
|
|
228
228
|
ip,
|
|
@@ -312,7 +312,7 @@ module.exports = ({
|
|
|
312
312
|
* @param {boolean} prepared.shouldOwn if user should be owner of target
|
|
313
313
|
* @returns {Promise<Object>} requested document
|
|
314
314
|
**/
|
|
315
|
-
async _getOneRaw({
|
|
315
|
+
static async _getOneRaw({
|
|
316
316
|
targetId,
|
|
317
317
|
activeUser,
|
|
318
318
|
ip,
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const { notError } = require("not-error");
|
|
2
|
+
|
|
3
|
+
class VersioningExceptionSameOldData extends notError {
|
|
4
|
+
constructor() {
|
|
5
|
+
super("not-node:versioning_error_same_old_data");
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
module.exports.VersioningExceptionSameOldData = VersioningExceptionSameOldData;
|
|
9
|
+
|
|
10
|
+
class VersioningExceptionNoPpreviousVersions extends notError {
|
|
11
|
+
constructor() {
|
|
12
|
+
super("not-node:versioning_error_no_previous_versions");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
module.exports.VersioningExceptionNoPpreviousVersions =
|
|
16
|
+
VersioningExceptionNoPpreviousVersions;
|
|
17
|
+
|
|
18
|
+
class IncrementExceptionIDGeneratorRebaseFailed extends notError {
|
|
19
|
+
constructor() {
|
|
20
|
+
super("not-node:increment_id_generator_rebase_failed");
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
module.exports.IncrementExceptionIDGeneratorRebaseFailed =
|
|
24
|
+
IncrementExceptionIDGeneratorRebaseFailed;
|
|
25
|
+
|
|
26
|
+
class IncrementExceptionIDGenerationFailed extends notError {
|
|
27
|
+
constructor() {
|
|
28
|
+
super("not-node:increment_id_generation_failed");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
module.exports.IncrementExceptionIDGenerationFailed =
|
|
32
|
+
IncrementExceptionIDGenerationFailed;
|
|
33
|
+
|
|
34
|
+
class IncrementExceptionFieldsNotExistInDataObject extends notError {
|
|
35
|
+
constructor(miss) {
|
|
36
|
+
super("not-node:increment_fields_not_exist_in_data_object", { miss });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
module.exports.IncrementExceptionFieldsNotExistInDataObject =
|
|
40
|
+
IncrementExceptionFieldsNotExistInDataObject;
|
package/src/model/increment.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
/** @module Model/Increment */
|
|
2
2
|
|
|
3
3
|
const { updateResponseSuccess } = require("./utils.js");
|
|
4
|
+
const {
|
|
5
|
+
IncrementExceptionIDGeneratorRebaseFailed,
|
|
6
|
+
IncrementExceptionIDGenerationFailed,
|
|
7
|
+
IncrementExceptionFieldsNotExistInDataObject,
|
|
8
|
+
} = require("./exceptions.js");
|
|
4
9
|
|
|
5
10
|
const thisSchema = {
|
|
6
11
|
id: {
|
|
@@ -84,9 +89,7 @@ function newGetNext() {
|
|
|
84
89
|
if (miss.length === 0) {
|
|
85
90
|
id = formId(modelName, filterFields, data);
|
|
86
91
|
} else {
|
|
87
|
-
throw new
|
|
88
|
-
"Fields not exist in data object: " + miss.join(", ")
|
|
89
|
-
);
|
|
92
|
+
throw new IncrementExceptionFieldsNotExistInDataObject(miss);
|
|
90
93
|
}
|
|
91
94
|
}
|
|
92
95
|
let which = {
|
|
@@ -106,7 +109,7 @@ function newGetNext() {
|
|
|
106
109
|
const doc = await thisModel.findOne({ id });
|
|
107
110
|
return doc.seq;
|
|
108
111
|
} else {
|
|
109
|
-
throw new
|
|
112
|
+
throw new IncrementExceptionIDGenerationFailed();
|
|
110
113
|
}
|
|
111
114
|
};
|
|
112
115
|
}
|
|
@@ -136,7 +139,7 @@ function newRebase() {
|
|
|
136
139
|
if (updateResponseSuccess(res)) {
|
|
137
140
|
return ID;
|
|
138
141
|
} else {
|
|
139
|
-
throw new
|
|
142
|
+
throw new IncrementExceptionIDGeneratorRebaseFailed();
|
|
140
143
|
}
|
|
141
144
|
};
|
|
142
145
|
}
|
package/src/model/versioning.js
CHANGED
|
@@ -11,8 +11,10 @@ const TECH_FIELDS = [
|
|
|
11
11
|
"__closed",
|
|
12
12
|
];
|
|
13
13
|
|
|
14
|
-
const
|
|
15
|
-
|
|
14
|
+
const {
|
|
15
|
+
VersioningExceptioNoPpreviousVersions,
|
|
16
|
+
VersioningExceptionSameOldData,
|
|
17
|
+
} = require("./exceptions.js");
|
|
16
18
|
|
|
17
19
|
class ModelVersioning {
|
|
18
20
|
static versionsHistoryExists(data) {
|
|
@@ -72,7 +74,7 @@ class ModelVersioning {
|
|
|
72
74
|
previous.toObject()
|
|
73
75
|
);
|
|
74
76
|
} else {
|
|
75
|
-
throw new
|
|
77
|
+
throw new VersioningExceptioNoPpreviousVersions();
|
|
76
78
|
}
|
|
77
79
|
}
|
|
78
80
|
|
|
@@ -103,7 +105,7 @@ class ModelVersioning {
|
|
|
103
105
|
versionDoc
|
|
104
106
|
);
|
|
105
107
|
}
|
|
106
|
-
throw new
|
|
108
|
+
throw new VersioningExceptionSameOldData();
|
|
107
109
|
}
|
|
108
110
|
|
|
109
111
|
/**
|
|
@@ -162,7 +164,4 @@ class ModelVersioning {
|
|
|
162
164
|
}
|
|
163
165
|
}
|
|
164
166
|
|
|
165
|
-
ModelVersioning.ERR_NO_PREVIOUS_VERSIONS = ERR_NO_PREVIOUS_VERSIONS;
|
|
166
|
-
ModelVersioning.ERR_SAME_OLD_DATA = ERR_SAME_OLD_DATA;
|
|
167
|
-
|
|
168
167
|
module.exports = ModelVersioning;
|