@ecom-micro/common 2.0.9 → 2.0.12
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.
|
@@ -21,12 +21,12 @@ var NotAuthorizedError = /** @class */ (function (_super) {
|
|
|
21
21
|
__extends(NotAuthorizedError, _super);
|
|
22
22
|
function NotAuthorizedError() {
|
|
23
23
|
var _this = _super.call(this, 'Not authorized') || this;
|
|
24
|
-
_this.statusCode =
|
|
24
|
+
_this.statusCode = 403;
|
|
25
25
|
Object.setPrototypeOf(_this, NotAuthorizedError.prototype);
|
|
26
26
|
return _this;
|
|
27
27
|
}
|
|
28
28
|
NotAuthorizedError.prototype.serializeErrors = function () {
|
|
29
|
-
return [{ message: '
|
|
29
|
+
return [{ message: 'Oops! You are not authorized to access this route' }];
|
|
30
30
|
};
|
|
31
31
|
return NotAuthorizedError;
|
|
32
32
|
}(baseError_1.BaseError));
|
package/build/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from './errors/notFoundError';
|
|
|
5
5
|
export * from './errors/requestValidationError';
|
|
6
6
|
export * from './middleware/errorHandler';
|
|
7
7
|
export * from './middleware/protect';
|
|
8
|
+
export * from './middleware/restrictTo';
|
|
8
9
|
export * from './middleware/requestValidation';
|
|
9
10
|
export * from './events/baseListener';
|
|
10
11
|
export * from './events/basePublisher';
|
package/build/index.js
CHANGED
|
@@ -21,6 +21,7 @@ __exportStar(require("./errors/notFoundError"), exports);
|
|
|
21
21
|
__exportStar(require("./errors/requestValidationError"), exports);
|
|
22
22
|
__exportStar(require("./middleware/errorHandler"), exports);
|
|
23
23
|
__exportStar(require("./middleware/protect"), exports);
|
|
24
|
+
__exportStar(require("./middleware/restrictTo"), exports);
|
|
24
25
|
__exportStar(require("./middleware/requestValidation"), exports);
|
|
25
26
|
__exportStar(require("./events/baseListener"), exports);
|
|
26
27
|
__exportStar(require("./events/basePublisher"), exports);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.restrictTo = void 0;
|
|
4
|
+
var notAuthorized_1 = require("../errors/notAuthorized");
|
|
5
|
+
var restrictTo = function () {
|
|
6
|
+
var roles = [];
|
|
7
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
8
|
+
roles[_i] = arguments[_i];
|
|
9
|
+
}
|
|
10
|
+
return function (req, res, next) {
|
|
11
|
+
if (!roles.includes(req.user.role)) {
|
|
12
|
+
return next(new notAuthorized_1.NotAuthorizedError());
|
|
13
|
+
}
|
|
14
|
+
next();
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
exports.restrictTo = restrictTo;
|