@misalon/common 1.0.12 → 1.0.15

Sign up to get free protection for your applications and to get access to all the features.
package/build/index.d.ts CHANGED
@@ -8,7 +8,7 @@ export * from './middlewares/current-user';
8
8
  export * from './middlewares/error-handler';
9
9
  export * from './middlewares/require-auth';
10
10
  export * from './middlewares/validate-request';
11
- export * from './middlewares/admin-auth';
11
+ export * from './middlewares/restrict-by-role';
12
12
  export * from './events/base-listener';
13
13
  export * from './events/base-publisher';
14
14
  export * from './events/subjects';
@@ -18,3 +18,4 @@ export * from "./events/appointment--created-event";
18
18
  export * from "./events/appointment-cancelled-event";
19
19
  export * from './events/type/service-category';
20
20
  export * from './events/type/status';
21
+ export * from './permissions/index';
package/build/index.js CHANGED
@@ -24,7 +24,7 @@ __exportStar(require("./middlewares/current-user"), exports);
24
24
  __exportStar(require("./middlewares/error-handler"), exports);
25
25
  __exportStar(require("./middlewares/require-auth"), exports);
26
26
  __exportStar(require("./middlewares/validate-request"), exports);
27
- __exportStar(require("./middlewares/admin-auth"), exports);
27
+ __exportStar(require("./middlewares/restrict-by-role"), exports);
28
28
  __exportStar(require("./events/base-listener"), exports);
29
29
  __exportStar(require("./events/base-publisher"), exports);
30
30
  __exportStar(require("./events/subjects"), exports);
@@ -34,3 +34,4 @@ __exportStar(require("./events/appointment--created-event"), exports);
34
34
  __exportStar(require("./events/appointment-cancelled-event"), exports);
35
35
  __exportStar(require("./events/type/service-category"), exports);
36
36
  __exportStar(require("./events/type/status"), exports);
37
+ __exportStar(require("./permissions/index"), exports);
@@ -0,0 +1,2 @@
1
+ import { Request, Response, NextFunction } from 'express';
2
+ export declare const restrictByRole: (restrictedRoles: string[]) => (req: Request, res: Response, next: NextFunction) => void;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ // common/src/middlewares/restrict-by-role.ts
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.restrictByRole = void 0;
5
+ var not_authorized_error_1 = require("../errors/not-authorized-error"); // Adjust path as needed
6
+ var restrictByRole = function (restrictedRoles) {
7
+ return function (req, res, next) {
8
+ if (!req.currentUser) {
9
+ // If user is not authenticated, return a 401 error
10
+ res.status(401).send({ error: 'User not authenticated' });
11
+ return;
12
+ }
13
+ if (restrictedRoles.includes(req.currentUser.role)) {
14
+ throw new not_authorized_error_1.NotAuthorizedError();
15
+ }
16
+ next();
17
+ };
18
+ };
19
+ exports.restrictByRole = restrictByRole;
@@ -0,0 +1,9 @@
1
+ export declare const Roles: {
2
+ ADMIN: string;
3
+ USER: string;
4
+ };
5
+ export declare const RestrictedActions: {
6
+ CREATE_APPOINTMENT: string[];
7
+ CANCEL_APPOINTMENT: string[];
8
+ MANAGE_SERVICES: string[];
9
+ };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RestrictedActions = exports.Roles = void 0;
4
+ exports.Roles = {
5
+ ADMIN: 'admin',
6
+ USER: 'user',
7
+ };
8
+ exports.RestrictedActions = {
9
+ CREATE_APPOINTMENT: [exports.Roles.ADMIN], // Admins restricted from creating appointments
10
+ CANCEL_APPOINTMENT: [exports.Roles.ADMIN], // Admins restricted from canceling appointments
11
+ MANAGE_SERVICES: [exports.Roles.USER], // Users restricted from managing salon services
12
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@misalon/common",
3
- "version": "1.0.12",
3
+ "version": "1.0.15",
4
4
  "main": "./build/index.js",
5
5
  "types": "./build/index.d.ts",
6
6
  "files": [