@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.
- package/build/errors/badRequestError.js +9 -27
- package/build/errors/baseError.js +6 -24
- package/build/errors/notAuthorized.js +9 -27
- package/build/errors/notFoundError.js +10 -28
- package/build/errors/requestValidationError.js +11 -29
- package/build/events/baseListener.js +15 -17
- package/build/events/basePublisher.js +8 -10
- package/build/middleware/errorHandler.js +10 -40
- package/build/middleware/protect.d.ts +1 -1
- package/build/middleware/protect.js +14 -45
- package/build/middleware/requestValidation.js +9 -40
- package/build/middleware/restrictTo.js +3 -7
- package/package.json +1 -1
|
@@ -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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
11
|
+
serializeErrors() {
|
|
29
12
|
return [{ message: this.message }];
|
|
30
|
-
}
|
|
31
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
11
|
+
serializeErrors() {
|
|
29
12
|
return [{ message: 'Oops! You are not authorized to access this route' }];
|
|
30
|
-
}
|
|
31
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
12
|
+
serializeErrors() {
|
|
30
13
|
return [{ message: this.message }];
|
|
31
|
-
}
|
|
32
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
30
|
-
return this.error.map(
|
|
12
|
+
serializeErrors() {
|
|
13
|
+
return this.error.map((err) => {
|
|
31
14
|
return { message: err.msg, field: err.param };
|
|
32
15
|
});
|
|
33
|
-
}
|
|
34
|
-
|
|
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
|
-
|
|
5
|
-
|
|
4
|
+
class Listener {
|
|
5
|
+
constructor(client) {
|
|
6
6
|
this.ackWait = 5 * 1000;
|
|
7
7
|
this.client = client;
|
|
8
8
|
}
|
|
9
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
27
|
-
|
|
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
|
-
|
|
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
|
-
|
|
5
|
-
|
|
4
|
+
class Publisher {
|
|
5
|
+
constructor(client) {
|
|
6
6
|
this.client = client;
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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',
|
|
14
|
+
console.log('Event published to subject', this.subject);
|
|
16
15
|
resolve();
|
|
17
16
|
});
|
|
18
17
|
});
|
|
19
|
-
}
|
|
20
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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;
|
|
@@ -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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
60
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
}
|