@riocrypto/common-server 1.0.1493 → 1.0.1495
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.
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.requireMinAdminRole = void 0;
|
|
13
|
+
const common_1 = require("@riocrypto/common");
|
|
14
|
+
const admin_role_1 = require("@riocrypto/common/build/types/admin-role");
|
|
15
|
+
const adminRoleOrder = [
|
|
16
|
+
admin_role_1.AdminRole.Read,
|
|
17
|
+
admin_role_1.AdminRole.Write,
|
|
18
|
+
admin_role_1.AdminRole.SuperAdmin,
|
|
19
|
+
];
|
|
20
|
+
const requireMinAdminRole = (req, res, next, minRole) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
var _a;
|
|
22
|
+
if (!req.admin) {
|
|
23
|
+
throw new common_1.AdminOnlyError();
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
if (adminRoleOrder.indexOf((_a = req.admin) === null || _a === void 0 ? void 0 : _a.role) < adminRoleOrder.indexOf(minRole)) {
|
|
27
|
+
throw new common_1.GenericInputError(`Insufficient permissions. This endpoint requires at least the ${minRole} role. Contact Javier to change your access role.`);
|
|
28
|
+
}
|
|
29
|
+
next();
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
exports.requireMinAdminRole = requireMinAdminRole;
|
package/build/models/admin.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AdminTaskType } from "@riocrypto/common";
|
|
2
|
+
import { AdminRole } from "@riocrypto/common/build/types/admin-role";
|
|
2
3
|
import { Mongoose, Model, Document } from "mongoose";
|
|
3
4
|
interface AdminAttrs {
|
|
4
5
|
createdAt: Date;
|
|
@@ -10,6 +11,7 @@ interface AdminAttrs {
|
|
|
10
11
|
assignedTaskTypes: AdminTaskType[];
|
|
11
12
|
privileges: string[];
|
|
12
13
|
userAuthId?: string;
|
|
14
|
+
role: AdminRole;
|
|
13
15
|
}
|
|
14
16
|
interface AdminModel extends Model<AdminDoc> {
|
|
15
17
|
build(attrs: AdminAttrs): AdminDoc;
|
|
@@ -25,6 +27,7 @@ interface AdminDoc extends Document {
|
|
|
25
27
|
assignedTaskTypes: AdminTaskType[];
|
|
26
28
|
privileges: string[];
|
|
27
29
|
userAuthId?: string;
|
|
30
|
+
role: AdminRole;
|
|
28
31
|
}
|
|
29
32
|
declare const buildAdmin: (mongoose: Mongoose) => AdminModel;
|
|
30
33
|
export { buildAdmin, AdminDoc };
|
package/build/models/admin.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.1495",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@google-cloud/storage": "^6.9.5",
|
|
29
29
|
"@google-cloud/vision": "^4.0.2",
|
|
30
30
|
"@hyperdx/node-opentelemetry": "^0.4.2",
|
|
31
|
-
"@riocrypto/common": "^1.0.
|
|
31
|
+
"@riocrypto/common": "^1.0.1336",
|
|
32
32
|
"@types/express": "^4.17.13",
|
|
33
33
|
"axios": "^0.27.2",
|
|
34
34
|
"ccxt": "^3.0.30",
|