@riocrypto/common-server 1.0.2381 → 1.0.2383
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.
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { AuthRole } from "@riocrypto/common";
|
|
2
|
+
import { AuthPermission } from "@riocrypto/common/build/types/auth-permission";
|
|
2
3
|
import { NextFunction, Request, Response } from "express";
|
|
3
|
-
export declare const
|
|
4
|
+
export declare const requireMinRoleOrPermissions: (req: Request, res: Response, next: NextFunction, minRole: AuthRole, requiredPermissions: AuthPermission[]) => Promise<void>;
|
|
@@ -9,20 +9,33 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.requireMinRoleOrPermissions = void 0;
|
|
13
13
|
const common_1 = require("@riocrypto/common");
|
|
14
14
|
const authRoleOrder = [
|
|
15
15
|
common_1.AuthRole.ViewOnly,
|
|
16
16
|
common_1.AuthRole.CreateAndModify,
|
|
17
17
|
common_1.AuthRole.Owner,
|
|
18
18
|
];
|
|
19
|
-
const
|
|
19
|
+
const requireMinRoleOrPermissions = (req, res, next, minRole, requiredPermissions) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
20
|
var _a;
|
|
21
21
|
if (!req.adminAuth && !req.validClusterApiKey) {
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
const auth = req.auth;
|
|
23
|
+
if (!auth) {
|
|
24
|
+
throw new common_1.NotAuthorizedError();
|
|
25
|
+
}
|
|
26
|
+
if (auth.permissions && auth.permissions.length > 0) {
|
|
27
|
+
// Permission based requirements
|
|
28
|
+
if (!auth.permissions.some((permission) => requiredPermissions.includes(permission))) {
|
|
29
|
+
throw new common_1.GenericInputError(`Insufficient permissions. Contact your account owner to change your access permissions.`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
// Role based requirements
|
|
34
|
+
if (authRoleOrder.indexOf((_a = req.auth) === null || _a === void 0 ? void 0 : _a.role) < authRoleOrder.indexOf(minRole)) {
|
|
35
|
+
throw new common_1.GenericInputError(`Incompatible role. Contact your account owner to change your access role.`);
|
|
36
|
+
}
|
|
24
37
|
}
|
|
25
38
|
}
|
|
26
39
|
next();
|
|
27
40
|
});
|
|
28
|
-
exports.
|
|
41
|
+
exports.requireMinRoleOrPermissions = requireMinRoleOrPermissions;
|
package/build/models/auth.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { APIKey, AuthRole, SecurityQuestion } from "@riocrypto/common";
|
|
2
2
|
import { Mongoose, Model, Document } from "mongoose";
|
|
3
|
+
import { AuthPermission } from "@riocrypto/common/build/types/auth-permission";
|
|
3
4
|
interface AuthAttrs {
|
|
4
5
|
phoneNumber: string;
|
|
5
6
|
password?: string;
|
|
@@ -22,7 +23,8 @@ interface AuthAttrs {
|
|
|
22
23
|
middleName?: string;
|
|
23
24
|
lastName?: string;
|
|
24
25
|
secondLastName?: string;
|
|
25
|
-
role
|
|
26
|
+
role?: AuthRole;
|
|
27
|
+
permissions?: AuthPermission[];
|
|
26
28
|
}
|
|
27
29
|
interface AuthDoc extends Document {
|
|
28
30
|
phoneNumber: string;
|
|
@@ -46,7 +48,8 @@ interface AuthDoc extends Document {
|
|
|
46
48
|
middleName?: string;
|
|
47
49
|
lastName?: string;
|
|
48
50
|
secondLastName?: string;
|
|
49
|
-
role
|
|
51
|
+
role?: AuthRole;
|
|
52
|
+
permissions?: AuthPermission[];
|
|
50
53
|
}
|
|
51
54
|
interface AuthModel extends Model<AuthDoc> {
|
|
52
55
|
build(attrs: AuthAttrs): AuthDoc;
|
package/build/models/auth.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riocrypto/common-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2383",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@google-cloud/secret-manager": "^5.3.0",
|
|
29
29
|
"@google-cloud/storage": "^6.9.5",
|
|
30
30
|
"@hyperdx/node-opentelemetry": "^0.7.0",
|
|
31
|
-
"@riocrypto/common": "^1.0.
|
|
31
|
+
"@riocrypto/common": "^1.0.2107",
|
|
32
32
|
"@types/express": "^4.17.13",
|
|
33
33
|
"axios": "^1.7.4",
|
|
34
34
|
"crypto-js": "^4.2.0",
|