@riocrypto/common-server 1.0.2770 → 1.0.2774

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,3 @@
1
- import { AdminAuthRole } from "@riocrypto/common";
1
+ import { AdminAuthSpecialPermission, AdminAuthRole } from "@riocrypto/common";
2
2
  import { NextFunction, Request, Response } from "express";
3
- export declare const requireMinAdminRole: (req: Request, res: Response, next: NextFunction, minRole: AdminAuthRole) => Promise<void>;
3
+ export declare const requireMinAdminRole: (req: Request, res: Response, next: NextFunction, minRole: AdminAuthRole, requiredSpecialPermissions?: AdminAuthSpecialPermission[]) => Promise<void>;
@@ -16,12 +16,16 @@ const adminRoleOrder = [
16
16
  common_1.AdminAuthRole.CreateAndModify,
17
17
  common_1.AdminAuthRole.SuperAdmin,
18
18
  ];
19
- const requireMinAdminRole = (req, res, next, minRole) => __awaiter(void 0, void 0, void 0, function* () {
19
+ const requireMinAdminRole = (req, res, next, minRole, requiredSpecialPermissions = []) => __awaiter(void 0, void 0, void 0, function* () {
20
20
  var _a;
21
21
  if (req.adminAuth) {
22
- if (adminRoleOrder.indexOf((_a = req.adminAuth) === null || _a === void 0 ? void 0 : _a.role) <
23
- adminRoleOrder.indexOf(minRole)) {
24
- throw new common_1.GenericInputError(`Insufficient permissions. This endpoint requires at least the ${minRole} role. Contact Javier to change your access role.`);
22
+ if (adminRoleOrder.indexOf(req.adminAuth.role) < adminRoleOrder.indexOf(minRole)) {
23
+ throw new common_1.GenericInputError(`Insufficient permissions.`);
24
+ }
25
+ if (requiredSpecialPermissions.length > 0) {
26
+ if (!((_a = req.adminAuth.permissions) === null || _a === void 0 ? void 0 : _a.some((permission) => requiredSpecialPermissions.includes(permission)))) {
27
+ throw new common_1.GenericInputError("Insufficient permissions.");
28
+ }
25
29
  }
26
30
  }
27
31
  next();
@@ -1,4 +1,4 @@
1
- import { APIKey, AdminAuthRole, AdminTaskType } from "@riocrypto/common";
1
+ import { APIKey, AdminAuthRole, AdminAuthSpecialPermission, AdminTaskType } from "@riocrypto/common";
2
2
  import { Mongoose, Model, Document, HydratedDocument } from "mongoose";
3
3
  interface AdminAuthAttrs {
4
4
  password: string;
@@ -18,6 +18,7 @@ interface AdminAuthAttrs {
18
18
  lastName: string;
19
19
  secondLastName?: string;
20
20
  role: AdminAuthRole;
21
+ permissions?: AdminAuthSpecialPermission[];
21
22
  previousPasswords?: string[];
22
23
  authenticatorSecret?: string;
23
24
  apiKeys?: APIKey[];
@@ -37,6 +38,7 @@ interface AdminAuthDoc extends Document {
37
38
  assignedTaskTypes: AdminTaskType[];
38
39
  userAuthId?: string;
39
40
  role: AdminAuthRole;
41
+ permissions?: AdminAuthSpecialPermission[];
40
42
  firstName?: string;
41
43
  middleName?: string;
42
44
  lastName?: string;
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.buildAdminAuth = void 0;
13
+ const common_1 = require("@riocrypto/common");
13
14
  const password_1 = require("../services/password");
14
15
  const buildAdminAuth = (mongoose) => {
15
16
  // if model is already defined, return it
@@ -45,7 +46,14 @@ const buildAdminAuth = (mongoose) => {
45
46
  },
46
47
  role: {
47
48
  type: String,
49
+ enum: Object.values(common_1.AdminAuthRole),
48
50
  },
51
+ permissions: [
52
+ {
53
+ type: String,
54
+ enum: Object.values(common_1.AdminAuthSpecialPermission),
55
+ },
56
+ ],
49
57
  slack: {
50
58
  type: Object,
51
59
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.2770",
3
+ "version": "1.0.2774",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -24,7 +24,7 @@
24
24
  "@google-cloud/secret-manager": "^5.6.0",
25
25
  "@google-cloud/storage": "^7.19.0",
26
26
  "@hyperdx/node-opentelemetry": "^0.10.3",
27
- "@riocrypto/common": "1.0.2566",
27
+ "@riocrypto/common": "1.0.2567",
28
28
  "@slack/web-api": "^7.15.0",
29
29
  "@types/express": "^4.17.25",
30
30
  "axios": "1.13.6",