@zenofolio/hyper-decor 1.0.56 → 1.0.57
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.
|
@@ -7,19 +7,19 @@ const constants_1 = require("../constants");
|
|
|
7
7
|
function roleTransform(list, callback) {
|
|
8
8
|
const { roles, names, isEmtpy } = resolveRoles(list);
|
|
9
9
|
const middleware = (req, res, next) => {
|
|
10
|
-
|
|
10
|
+
var _a;
|
|
11
11
|
if (isEmtpy)
|
|
12
12
|
return next();
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (requestRoles === null || requestRoles === void 0 ? void 0 : requestRoles.includes(constants_1.FULL_ACCESS))
|
|
13
|
+
const requestRoles = new Set((_a = (0, helpers_1.getRoles)(req)) !== null && _a !== void 0 ? _a : []);
|
|
14
|
+
if (requestRoles.size === 0 && isEmtpy)
|
|
16
15
|
return next();
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
if (requestRoles.has(constants_1.FULL_ACCESS))
|
|
17
|
+
return next();
|
|
18
|
+
const role = roles.some((scope) => requestRoles.has(scope.role));
|
|
19
19
|
if (role) {
|
|
20
20
|
return next();
|
|
21
21
|
}
|
|
22
|
-
return next(new exeptions_1.NotRoleException(`Only ${Array.from(names).join(", ")} can access this resource`, requestRoles, Array.from(names)));
|
|
22
|
+
return next(new exeptions_1.NotRoleException(`Only ${Array.from(names).join(", ")} can access this resource`, Array.from(requestRoles), Array.from(names)));
|
|
23
23
|
};
|
|
24
24
|
if (names.size > 0 && callback) {
|
|
25
25
|
callback(middleware, roles, names);
|
|
@@ -7,19 +7,19 @@ const constants_1 = require("../constants");
|
|
|
7
7
|
function scopeTransfrom(listScopes, ...callback) {
|
|
8
8
|
const { scopes, scopeNames, isEmtpy } = resolveScopes(listScopes);
|
|
9
9
|
const middleware = (req, res, next) => {
|
|
10
|
-
var _a;
|
|
11
|
-
// if scopes is empty, then we don't need to check for scopes
|
|
10
|
+
var _a, _b;
|
|
12
11
|
if (isEmtpy)
|
|
13
12
|
return next();
|
|
14
13
|
// get the user scopes
|
|
15
|
-
const userScopes = (0, helpers_1.getScopes)(req);
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
const userScopes = new Set((_a = (0, helpers_1.getScopes)(req)) !== null && _a !== void 0 ? _a : []);
|
|
15
|
+
if (userScopes.size === 0 && isEmtpy)
|
|
16
|
+
return next();
|
|
17
|
+
if (userScopes.has(constants_1.FULL_ACCESS))
|
|
18
18
|
return next();
|
|
19
19
|
// find the first scope that is not in the userScopes
|
|
20
|
-
const error = scopes.find((scope) => !
|
|
20
|
+
const error = scopes.find((scope) => !userScopes.has(scope.scope));
|
|
21
21
|
if (error) {
|
|
22
|
-
return next(new exeptions_1.NotScopeException((
|
|
22
|
+
return next(new exeptions_1.NotScopeException((_b = error.message) !== null && _b !== void 0 ? _b : `You don't have the required scopes to access this resource`, Array.from(userScopes), Array.from(scopeNames)));
|
|
23
23
|
}
|
|
24
24
|
return next();
|
|
25
25
|
};
|