@ecom-micro/common 2.0.12 → 2.0.14

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,33 +1,15 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
2
  Object.defineProperty(exports, "__esModule", { value: true });
18
3
  exports.BadRequestError = void 0;
19
- var baseError_1 = require("./baseError");
20
- var BadRequestError = /** @class */ (function (_super) {
21
- __extends(BadRequestError, _super);
22
- function BadRequestError(message) {
23
- var _this = _super.call(this, message) || this;
24
- _this.statusCode = 400;
25
- Object.setPrototypeOf(_this, BadRequestError.prototype);
26
- return _this;
4
+ const baseError_1 = require("./baseError");
5
+ class BadRequestError extends baseError_1.BaseError {
6
+ constructor(message) {
7
+ super(message);
8
+ this.statusCode = 400;
9
+ Object.setPrototypeOf(this, BadRequestError.prototype);
27
10
  }
28
- BadRequestError.prototype.serializeErrors = function () {
11
+ serializeErrors() {
29
12
  return [{ message: this.message }];
30
- };
31
- return BadRequestError;
32
- }(baseError_1.BaseError));
13
+ }
14
+ }
33
15
  exports.BadRequestError = BadRequestError;
@@ -1,29 +1,11 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
2
  Object.defineProperty(exports, "__esModule", { value: true });
18
3
  exports.BaseError = void 0;
19
- var BaseError = /** @class */ (function (_super) {
20
- __extends(BaseError, _super);
21
- function BaseError(message) {
22
- var _this = _super.call(this, message) || this;
23
- _this.name = _this.constructor.name;
24
- Error.captureStackTrace(_this, _this.constructor);
25
- return _this;
4
+ class BaseError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ this.name = this.constructor.name;
8
+ Error.captureStackTrace(this, this.constructor);
26
9
  }
27
- return BaseError;
28
- }(Error));
10
+ }
29
11
  exports.BaseError = BaseError;
@@ -1,33 +1,15 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
2
  Object.defineProperty(exports, "__esModule", { value: true });
18
3
  exports.NotAuthorizedError = void 0;
19
- var baseError_1 = require("./baseError");
20
- var NotAuthorizedError = /** @class */ (function (_super) {
21
- __extends(NotAuthorizedError, _super);
22
- function NotAuthorizedError() {
23
- var _this = _super.call(this, 'Not authorized') || this;
24
- _this.statusCode = 403;
25
- Object.setPrototypeOf(_this, NotAuthorizedError.prototype);
26
- return _this;
4
+ const baseError_1 = require("./baseError");
5
+ class NotAuthorizedError extends baseError_1.BaseError {
6
+ constructor() {
7
+ super('Not authorized');
8
+ this.statusCode = 403;
9
+ Object.setPrototypeOf(this, NotAuthorizedError.prototype);
27
10
  }
28
- NotAuthorizedError.prototype.serializeErrors = function () {
11
+ serializeErrors() {
29
12
  return [{ message: 'Oops! You are not authorized to access this route' }];
30
- };
31
- return NotAuthorizedError;
32
- }(baseError_1.BaseError));
13
+ }
14
+ }
33
15
  exports.NotAuthorizedError = NotAuthorizedError;
@@ -1,34 +1,16 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
2
  Object.defineProperty(exports, "__esModule", { value: true });
18
3
  exports.NotFoundError = void 0;
19
- var baseError_1 = require("./baseError");
20
- var NotFoundError = /** @class */ (function (_super) {
21
- __extends(NotFoundError, _super);
22
- function NotFoundError(message) {
23
- var _this = _super.call(this, 'Not found error') || this;
24
- _this.message = message;
25
- _this.statusCode = 404;
26
- Object.setPrototypeOf(_this, NotFoundError.prototype);
27
- return _this;
4
+ const baseError_1 = require("./baseError");
5
+ class NotFoundError extends baseError_1.BaseError {
6
+ constructor(message) {
7
+ super('Not found error');
8
+ this.message = message;
9
+ this.statusCode = 404;
10
+ Object.setPrototypeOf(this, NotFoundError.prototype);
28
11
  }
29
- NotFoundError.prototype.serializeErrors = function () {
12
+ serializeErrors() {
30
13
  return [{ message: this.message }];
31
- };
32
- return NotFoundError;
33
- }(baseError_1.BaseError));
14
+ }
15
+ }
34
16
  exports.NotFoundError = NotFoundError;
@@ -1,36 +1,18 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
2
  Object.defineProperty(exports, "__esModule", { value: true });
18
3
  exports.RequestValidationError = void 0;
19
- var baseError_1 = require("./baseError");
20
- var RequestValidationError = /** @class */ (function (_super) {
21
- __extends(RequestValidationError, _super);
22
- function RequestValidationError(error) {
23
- var _this = _super.call(this, 'Request validation error') || this;
24
- _this.error = error;
25
- _this.statusCode = 400;
26
- Object.setPrototypeOf(_this, RequestValidationError.prototype);
27
- return _this;
4
+ const baseError_1 = require("./baseError");
5
+ class RequestValidationError extends baseError_1.BaseError {
6
+ constructor(error) {
7
+ super('Request validation error');
8
+ this.error = error;
9
+ this.statusCode = 400;
10
+ Object.setPrototypeOf(this, RequestValidationError.prototype);
28
11
  }
29
- RequestValidationError.prototype.serializeErrors = function () {
30
- return this.error.map(function (err) {
12
+ serializeErrors() {
13
+ return this.error.map((err) => {
31
14
  return { message: err.msg, field: err.param };
32
15
  });
33
- };
34
- return RequestValidationError;
35
- }(baseError_1.BaseError));
16
+ }
17
+ }
36
18
  exports.RequestValidationError = RequestValidationError;
@@ -1,32 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Listener = void 0;
4
- var Listener = /** @class */ (function () {
5
- function Listener(client) {
4
+ class Listener {
5
+ constructor(client) {
6
6
  this.ackWait = 5 * 1000;
7
7
  this.client = client;
8
8
  }
9
- Listener.prototype.subscriptionOptions = function () {
9
+ subscriptionOptions() {
10
10
  return this.client
11
11
  .subscriptionOptions()
12
12
  .setDeliverAllAvailable()
13
13
  .setManualAckMode(true)
14
14
  .setAckWait(this.ackWait)
15
15
  .setDurableName(this.queueGroupName);
16
- };
17
- Listener.prototype.listen = function () {
18
- var _this = this;
19
- var subscription = this.client.subscribe(this.subject, this.queueGroupName, this.subscriptionOptions());
20
- subscription.on('message', function (msg) {
21
- console.log("Message received: ".concat(_this.subject, " / ").concat(_this.queueGroupName));
22
- var parsedData = _this.parseMessage(msg);
23
- _this.onMessage(parsedData, msg);
16
+ }
17
+ listen() {
18
+ const subscription = this.client.subscribe(this.subject, this.queueGroupName, this.subscriptionOptions());
19
+ subscription.on('message', (msg) => {
20
+ console.log(`Message received: ${this.subject} / ${this.queueGroupName}`);
21
+ const parsedData = this.parseMessage(msg);
22
+ this.onMessage(parsedData, msg);
24
23
  });
25
- };
26
- Listener.prototype.parseMessage = function (msg) {
27
- var data = msg.getData();
24
+ }
25
+ parseMessage(msg) {
26
+ const data = msg.getData();
28
27
  return typeof data === 'string' ? JSON.parse(data) : JSON.parse(data.toString('utf8'));
29
- };
30
- return Listener;
31
- }());
28
+ }
29
+ }
32
30
  exports.Listener = Listener;
@@ -1,22 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Publisher = void 0;
4
- var Publisher = /** @class */ (function () {
5
- function Publisher(client) {
4
+ class Publisher {
5
+ constructor(client) {
6
6
  this.client = client;
7
7
  }
8
- Publisher.prototype.publish = function (data) {
9
- var _this = this;
10
- return new Promise(function (resolve, reject) {
11
- _this.client.publish(_this.subject, JSON.stringify(data), function (err) {
8
+ publish(data) {
9
+ return new Promise((resolve, reject) => {
10
+ this.client.publish(this.subject, JSON.stringify(data), (err) => {
12
11
  if (err) {
13
12
  return reject(err);
14
13
  }
15
- console.log('Event published to subject', _this.subject);
14
+ console.log('Event published to subject', this.subject);
16
15
  resolve();
17
16
  });
18
17
  });
19
- };
20
- return Publisher;
21
- }());
18
+ }
19
+ }
22
20
  exports.Publisher = Publisher;
@@ -8,46 +8,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
11
  Object.defineProperty(exports, "__esModule", { value: true });
39
12
  exports.errorHandler = void 0;
40
- var baseError_1 = require("../errors/baseError");
41
- var errorHandler = function (err, req, res, next) { return __awaiter(void 0, void 0, void 0, function () {
42
- return __generator(this, function (_a) {
43
- if (process.env.NODE_ENV !== 'test') {
44
- console.log(err.stack);
45
- }
46
- if (err instanceof baseError_1.BaseError) {
47
- return [2 /*return*/, res.status(err.statusCode).json({ errors: err.serializeErrors() })];
48
- }
49
- res.status(500).json({ errors: [{ message: 'something went wrong' }] });
50
- return [2 /*return*/];
51
- });
52
- }); };
13
+ const baseError_1 = require("../errors/baseError");
14
+ const errorHandler = (err, req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
15
+ if (process.env.NODE_ENV !== 'test') {
16
+ console.log(err.stack);
17
+ }
18
+ if (err instanceof baseError_1.BaseError) {
19
+ return res.status(err.statusCode).json({ errors: err.serializeErrors() });
20
+ }
21
+ res.status(500).json({ errors: [{ message: 'something went wrong' }] });
22
+ });
53
23
  exports.errorHandler = errorHandler;
@@ -2,7 +2,7 @@ import { NextFunction, Request, Response } from 'express';
2
2
  type UserPayload = {
3
3
  id: string;
4
4
  email: string;
5
- role?: string;
5
+ role: string;
6
6
  };
7
7
  declare global {
8
8
  namespace Express {
@@ -8,56 +8,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
39
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
13
  };
41
14
  Object.defineProperty(exports, "__esModule", { value: true });
42
15
  exports.protect = void 0;
43
- var jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
44
- var badRequestError_1 = require("../errors/badRequestError");
45
- var protect = function (req, res, next) { return __awaiter(void 0, void 0, void 0, function () {
46
- var payload;
16
+ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
17
+ const badRequestError_1 = require("../errors/badRequestError");
18
+ const protect = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
47
19
  var _a;
48
- return __generator(this, function (_b) {
49
- try {
50
- if (!((_a = req.session) === null || _a === void 0 ? void 0 : _a.jwt)) {
51
- return [2 /*return*/, next(new badRequestError_1.BadRequestError('You are not login! Please login first'))];
52
- }
53
- payload = jsonwebtoken_1.default.verify(req.session.jwt, process.env.JWT_KEY);
54
- req.user = payload;
55
- }
56
- catch (err) {
57
- res.send({ currentUser: null });
20
+ try {
21
+ if (!((_a = req.session) === null || _a === void 0 ? void 0 : _a.jwt)) {
22
+ return next(new badRequestError_1.BadRequestError('You are not login! Please login first'));
58
23
  }
59
- next();
60
- return [2 /*return*/];
61
- });
62
- }); };
24
+ const payload = jsonwebtoken_1.default.verify(req.session.jwt, process.env.JWT_KEY);
25
+ req.user = payload;
26
+ }
27
+ catch (err) {
28
+ res.send({ currentUser: null });
29
+ }
30
+ next();
31
+ });
63
32
  exports.protect = protect;
@@ -8,46 +8,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
11
  Object.defineProperty(exports, "__esModule", { value: true });
39
12
  exports.requestValidation = void 0;
40
- var express_validator_1 = require("express-validator");
41
- var requestValidationError_1 = require("../errors/requestValidationError");
42
- var requestValidation = function (req, res, next) { return __awaiter(void 0, void 0, void 0, function () {
43
- var errors;
44
- return __generator(this, function (_a) {
45
- errors = (0, express_validator_1.validationResult)(req);
46
- if (!errors.isEmpty()) {
47
- throw new requestValidationError_1.RequestValidationError(errors.array());
48
- }
49
- next();
50
- return [2 /*return*/];
51
- });
52
- }); };
13
+ const express_validator_1 = require("express-validator");
14
+ const requestValidationError_1 = require("../errors/requestValidationError");
15
+ const requestValidation = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
16
+ const errors = (0, express_validator_1.validationResult)(req);
17
+ if (!errors.isEmpty()) {
18
+ throw new requestValidationError_1.RequestValidationError(errors.array());
19
+ }
20
+ next();
21
+ });
53
22
  exports.requestValidation = requestValidation;
@@ -1,13 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
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) {
4
+ const notAuthorized_1 = require("../errors/notAuthorized");
5
+ const restrictTo = (...roles) => {
6
+ return (req, res, next) => {
11
7
  if (!roles.includes(req.user.role)) {
12
8
  return next(new notAuthorized_1.NotAuthorizedError());
13
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecom-micro/common",
3
- "version": "2.0.12",
3
+ "version": "2.0.14",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",