not-node 5.1.6 → 5.1.9
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/auth/exceptions.js +27 -0
- package/src/auth/roles.js +8 -3
- package/src/exceptions/db.js +2 -2
- package/src/exceptions/http.js +5 -5
- package/src/generic/logic.js +2 -2
- 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
|
@@ -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/exceptions/db.js
CHANGED
|
@@ -2,7 +2,7 @@ const { notRequestError } = require("not-error");
|
|
|
2
2
|
|
|
3
3
|
//delete wasnt successful, or error, or count of deleted documents dont match requested
|
|
4
4
|
class DBExceptionDeleteWasNotSuccessful extends notRequestError {
|
|
5
|
-
constructor({ params = {}, cause = null }) {
|
|
5
|
+
constructor({ params = {}, cause = null } = {}) {
|
|
6
6
|
super("DB Delete Was Not Successful", { code: 505, ...params }, cause);
|
|
7
7
|
}
|
|
8
8
|
}
|
|
@@ -11,7 +11,7 @@ module.exports.DBExceptionDeleteWasNotSuccessful =
|
|
|
11
11
|
|
|
12
12
|
//delete wasnt successful, bc document is owned by another user
|
|
13
13
|
class DBExceptionDocumentIsNotOwnerByActiveUser extends notRequestError {
|
|
14
|
-
constructor({ params = {}, cause = null }) {
|
|
14
|
+
constructor({ params = {}, cause = null } = {}) {
|
|
15
15
|
super(
|
|
16
16
|
"DB Only Owners Could Delete their documents",
|
|
17
17
|
{ code: 403, ...params },
|
package/src/exceptions/http.js
CHANGED
|
@@ -4,7 +4,7 @@ const { notRequestError } = require("not-error");
|
|
|
4
4
|
|
|
5
5
|
//form of request is not valid
|
|
6
6
|
class HttpExceptionBadRequest extends notRequestError {
|
|
7
|
-
constructor({ params = {}, cause = null }) {
|
|
7
|
+
constructor({ params = {}, cause = null } = {}) {
|
|
8
8
|
super("Bad Request", { code: 400, ...params }, cause);
|
|
9
9
|
}
|
|
10
10
|
}
|
|
@@ -12,7 +12,7 @@ module.exports.HttpExceptionBadRequest = HttpExceptionBadRequest;
|
|
|
12
12
|
|
|
13
13
|
//user is not authenticated
|
|
14
14
|
class HttpExceptionUnauthorized extends notRequestError {
|
|
15
|
-
constructor({ params = {}, cause = null }) {
|
|
15
|
+
constructor({ params = {}, cause = null } = {}) {
|
|
16
16
|
super("Unauthorized", { code: 401, ...params }, cause);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -20,7 +20,7 @@ module.exports.HttpExceptionUnauthorized = HttpExceptionUnauthorized;
|
|
|
20
20
|
|
|
21
21
|
//user is too poor to go there
|
|
22
22
|
class HttpExceptionPaymentRequired extends notRequestError {
|
|
23
|
-
constructor({ params = {}, cause = null }) {
|
|
23
|
+
constructor({ params = {}, cause = null } = {}) {
|
|
24
24
|
super("Payment Required", { code: 402, ...params }, cause);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -28,7 +28,7 @@ module.exports.HttpExceptionPaymentRequired = HttpExceptionPaymentRequired;
|
|
|
28
28
|
|
|
29
29
|
//user identity is known, but he has no right to go there
|
|
30
30
|
class HttpExceptionForbidden extends notRequestError {
|
|
31
|
-
constructor({ params = {}, cause = null }) {
|
|
31
|
+
constructor({ params = {}, cause = null } = {}) {
|
|
32
32
|
super("Forbidden", { code: 403, ...params }, cause);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
@@ -36,7 +36,7 @@ module.exports.HttpExceptionForbidden = HttpExceptionForbidden;
|
|
|
36
36
|
|
|
37
37
|
//requested address is not exists
|
|
38
38
|
class HttpExceptionNotFound extends notRequestError {
|
|
39
|
-
constructor({ params = {}, cause = null }) {
|
|
39
|
+
constructor({ params = {}, cause = null } = {}) {
|
|
40
40
|
super("Not Found", { code: 404, ...params }, cause);
|
|
41
41
|
}
|
|
42
42
|
}
|
package/src/generic/logic.js
CHANGED
|
@@ -7,7 +7,7 @@ const {
|
|
|
7
7
|
} = require("../exceptions/http");
|
|
8
8
|
const isOwnerImported = require("../auth/fields.js").isOwner;
|
|
9
9
|
const { DOCUMENT_OWNER_FIELD_NAME } = require("../auth/const.js");
|
|
10
|
-
const notFilter = require("not-filter")
|
|
10
|
+
const notFilter = require("not-filter");
|
|
11
11
|
|
|
12
12
|
module.exports = ({
|
|
13
13
|
MODEL_NAME,
|
|
@@ -547,7 +547,7 @@ module.exports = ({
|
|
|
547
547
|
ip,
|
|
548
548
|
});
|
|
549
549
|
if (shouldOwn) {
|
|
550
|
-
notFilter.
|
|
550
|
+
notFilter.filter.modifyRules(filter, {
|
|
551
551
|
[ownerFieldName]: activeUser._id,
|
|
552
552
|
});
|
|
553
553
|
}
|
|
@@ -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;
|