@antonymarshal23/common 1.0.24 → 2.0.0
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/bad-request-error.js +11 -26
- package/build/errors/custom-error.js +6 -21
- package/build/errors/database-connection-error.js +11 -26
- package/build/errors/not-authorized-error.js +10 -25
- package/build/errors/not-found-error.js +10 -25
- package/build/errors/request-validation-error.js +12 -27
- package/build/events/base-listener.d.ts +8 -9
- package/build/events/base-listener.js +28 -26
- package/build/events/base-publisher.d.ts +6 -6
- package/build/events/base-publisher.js +14 -14
- package/build/events/subjects.js +1 -0
- package/build/events/types/order-status.js +1 -0
- package/build/index.js +34 -17
- package/build/middlewares/current-user.d.ts +2 -2
- package/build/middlewares/current-user.js +5 -3
- package/build/middlewares/error-handler.d.ts +1 -1
- package/build/middlewares/error-handler.js +4 -2
- package/build/middlewares/require-auth.d.ts +1 -1
- package/build/middlewares/require-auth.js +4 -2
- package/build/middlewares/validate-request.d.ts +1 -1
- package/build/middlewares/validate-request.js +6 -4
- package/package.json +5 -3
|
@@ -1,31 +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 (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
extendStatics(d, b);
|
|
11
|
-
function __() { this.constructor = d; }
|
|
12
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
Object.setPrototypeOf(
|
|
24
|
-
return _this;
|
|
3
|
+
exports.BadRequestError = void 0;
|
|
4
|
+
const custom_error_1 = require("./custom-error");
|
|
5
|
+
class BadRequestError extends custom_error_1.CustomError {
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.message = message;
|
|
9
|
+
this.statusCode = 400;
|
|
10
|
+
Object.setPrototypeOf(this, BadRequestError.prototype);
|
|
25
11
|
}
|
|
26
|
-
|
|
12
|
+
serializeErrors() {
|
|
27
13
|
return [{ message: this.message }];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
}(custom_error_1.CustomError));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
31
16
|
exports.BadRequestError = BadRequestError;
|
|
@@ -1,25 +1,10 @@
|
|
|
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 (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
extendStatics(d, b);
|
|
11
|
-
function __() { this.constructor = d; }
|
|
12
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
Object.setPrototypeOf(
|
|
21
|
-
return _this;
|
|
3
|
+
exports.CustomError = void 0;
|
|
4
|
+
class CustomError extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
Object.setPrototypeOf(this, CustomError.prototype);
|
|
22
8
|
}
|
|
23
|
-
|
|
24
|
-
}(Error));
|
|
9
|
+
}
|
|
25
10
|
exports.CustomError = CustomError;
|
|
@@ -1,31 +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 (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
extendStatics(d, b);
|
|
11
|
-
function __() { this.constructor = d; }
|
|
12
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
Object.setPrototypeOf(
|
|
24
|
-
return _this;
|
|
3
|
+
exports.DatabaseConnectionError = void 0;
|
|
4
|
+
const custom_error_1 = require("./custom-error");
|
|
5
|
+
class DatabaseConnectionError extends custom_error_1.CustomError {
|
|
6
|
+
constructor() {
|
|
7
|
+
super('Error connecting to db');
|
|
8
|
+
this.statusCode = 500;
|
|
9
|
+
this.reason = 'Error connecting to database';
|
|
10
|
+
Object.setPrototypeOf(this, DatabaseConnectionError.prototype);
|
|
25
11
|
}
|
|
26
|
-
|
|
12
|
+
serializeErrors() {
|
|
27
13
|
return [{ message: this.reason }];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
}(custom_error_1.CustomError));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
31
16
|
exports.DatabaseConnectionError = DatabaseConnectionError;
|
|
@@ -1,30 +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 (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
extendStatics(d, b);
|
|
11
|
-
function __() { this.constructor = d; }
|
|
12
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
Object.setPrototypeOf(
|
|
23
|
-
return _this;
|
|
3
|
+
exports.NotAuthorizedError = void 0;
|
|
4
|
+
const custom_error_1 = require("./custom-error");
|
|
5
|
+
class NotAuthorizedError extends custom_error_1.CustomError {
|
|
6
|
+
constructor() {
|
|
7
|
+
super('Not Authorized');
|
|
8
|
+
this.statusCode = 401;
|
|
9
|
+
Object.setPrototypeOf(this, NotAuthorizedError.prototype);
|
|
24
10
|
}
|
|
25
|
-
|
|
11
|
+
serializeErrors() {
|
|
26
12
|
return [{ message: 'Not authorized' }];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
}(custom_error_1.CustomError));
|
|
13
|
+
}
|
|
14
|
+
}
|
|
30
15
|
exports.NotAuthorizedError = NotAuthorizedError;
|
|
@@ -1,30 +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 (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
extendStatics(d, b);
|
|
11
|
-
function __() { this.constructor = d; }
|
|
12
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
Object.setPrototypeOf(
|
|
23
|
-
return _this;
|
|
3
|
+
exports.NotFoundError = void 0;
|
|
4
|
+
const custom_error_1 = require("./custom-error");
|
|
5
|
+
class NotFoundError extends custom_error_1.CustomError {
|
|
6
|
+
constructor() {
|
|
7
|
+
super('Route not found');
|
|
8
|
+
this.statusCode = 404;
|
|
9
|
+
Object.setPrototypeOf(this, NotFoundError.prototype);
|
|
24
10
|
}
|
|
25
|
-
|
|
11
|
+
serializeErrors() {
|
|
26
12
|
return [{ message: 'Not Found' }];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
}(custom_error_1.CustomError));
|
|
13
|
+
}
|
|
14
|
+
}
|
|
30
15
|
exports.NotFoundError = NotFoundError;
|
|
@@ -1,34 +1,19 @@
|
|
|
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 (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
extendStatics(d, b);
|
|
11
|
-
function __() { this.constructor = d; }
|
|
12
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
3
|
+
exports.RequestValidationError = void 0;
|
|
4
|
+
const custom_error_1 = require("./custom-error");
|
|
5
|
+
class RequestValidationError extends custom_error_1.CustomError {
|
|
6
|
+
constructor(errors) {
|
|
7
|
+
super('Invalid request parameters');
|
|
8
|
+
this.errors = errors;
|
|
9
|
+
this.statusCode = 400;
|
|
23
10
|
// Only because we are extending a built in class
|
|
24
|
-
Object.setPrototypeOf(
|
|
25
|
-
return _this;
|
|
11
|
+
Object.setPrototypeOf(this, RequestValidationError.prototype);
|
|
26
12
|
}
|
|
27
|
-
|
|
28
|
-
return this.errors.map(
|
|
13
|
+
serializeErrors() {
|
|
14
|
+
return this.errors.map(err => {
|
|
29
15
|
return { message: err.msg, field: err.param };
|
|
30
16
|
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
}(custom_error_1.CustomError));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
34
19
|
exports.RequestValidationError = RequestValidationError;
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Subjects } from
|
|
1
|
+
import { Channel, ConsumeMessage } from "amqplib";
|
|
2
|
+
import { Subjects } from "./subjects";
|
|
3
3
|
interface Event {
|
|
4
4
|
subject: Subjects;
|
|
5
5
|
data: any;
|
|
6
6
|
}
|
|
7
7
|
export declare abstract class Listener<T extends Event> {
|
|
8
|
-
abstract subject: T[
|
|
8
|
+
abstract subject: T["subject"];
|
|
9
9
|
abstract queueGroupName: string;
|
|
10
|
-
abstract onMessage(data: T[
|
|
11
|
-
protected client:
|
|
10
|
+
abstract onMessage(data: T["data"], msg: ConsumeMessage, channel: Channel): void;
|
|
11
|
+
protected client: Channel;
|
|
12
12
|
protected ackWait: number;
|
|
13
|
-
constructor(client:
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
parseMessage(msg: Message): any;
|
|
13
|
+
constructor(client: Channel);
|
|
14
|
+
listen(): Promise<void>;
|
|
15
|
+
parseMessage(msg: ConsumeMessage): any;
|
|
17
16
|
}
|
|
18
17
|
export {};
|
|
@@ -1,33 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
exports.Listener = void 0;
|
|
4
|
+
class Listener {
|
|
5
|
+
constructor(client) {
|
|
5
6
|
this.ackWait = 5 * 1000;
|
|
6
7
|
this.client = client;
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
9
|
+
async listen() {
|
|
10
|
+
await this.client.assertExchange("ticketing", "topic", { durable: true });
|
|
11
|
+
await this.client.assertQueue(this.queueGroupName, { durable: true });
|
|
12
|
+
await this.client.bindQueue(this.queueGroupName, "ticketing", this.subject);
|
|
13
|
+
this.client.consume(this.queueGroupName, (msg) => {
|
|
14
|
+
if (!msg) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
console.log(`Message received: ${this.subject} / ${this.queueGroupName}`);
|
|
18
|
+
try {
|
|
19
|
+
const parsedData = this.parseMessage(msg);
|
|
20
|
+
this.onMessage(parsedData, msg, this.client);
|
|
21
|
+
}
|
|
22
|
+
catch (err) {
|
|
23
|
+
console.error("Error processing message:", err);
|
|
24
|
+
// Reject message
|
|
25
|
+
this.client.nack(msg, false, false);
|
|
26
|
+
}
|
|
27
|
+
}, {
|
|
28
|
+
noAck: false,
|
|
23
29
|
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
: JSON.parse(data.toString('utf8'));
|
|
30
|
-
};
|
|
31
|
-
return Listener;
|
|
32
|
-
}());
|
|
30
|
+
}
|
|
31
|
+
parseMessage(msg) {
|
|
32
|
+
return JSON.parse(msg.content.toString("utf8"));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
33
35
|
exports.Listener = Listener;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Subjects } from
|
|
1
|
+
import { Channel } from "amqplib";
|
|
2
|
+
import { Subjects } from "./subjects";
|
|
3
3
|
interface Event {
|
|
4
4
|
subject: Subjects;
|
|
5
5
|
data: any;
|
|
6
6
|
}
|
|
7
7
|
export declare abstract class Publisher<T extends Event> {
|
|
8
|
-
abstract subject: T[
|
|
9
|
-
protected client:
|
|
10
|
-
constructor(client:
|
|
11
|
-
publish(data: T[
|
|
8
|
+
abstract subject: T["subject"];
|
|
9
|
+
protected client: Channel;
|
|
10
|
+
constructor(client: Channel);
|
|
11
|
+
publish(data: T["data"]): Promise<void>;
|
|
12
12
|
}
|
|
13
13
|
export {};
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
exports.Publisher = void 0;
|
|
4
|
+
class Publisher {
|
|
5
|
+
constructor(client) {
|
|
5
6
|
this.client = client;
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (err) {
|
|
12
|
-
return reject(err);
|
|
13
|
-
}
|
|
14
|
-
console.log('Event published to subject', _this.subject);
|
|
15
|
-
resolve();
|
|
8
|
+
publish(data) {
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
const published = this.client.publish("ticketing", this.subject, Buffer.from(JSON.stringify(data)), {
|
|
11
|
+
persistent: true,
|
|
16
12
|
});
|
|
13
|
+
if (!published) {
|
|
14
|
+
return reject(new Error("Message was not published"));
|
|
15
|
+
}
|
|
16
|
+
console.log("Event published to subject", this.subject);
|
|
17
|
+
resolve();
|
|
17
18
|
});
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
}());
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
21
|
exports.Publisher = Publisher;
|
package/build/events/subjects.js
CHANGED
package/build/index.js
CHANGED
|
@@ -1,20 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
5
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
17
|
// Re-export stuff from errors and middlewares
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
__exportStar(require("./errors/bad-request-error"), exports);
|
|
19
|
+
__exportStar(require("./errors/custom-error"), exports);
|
|
20
|
+
__exportStar(require("./errors/database-connection-error"), exports);
|
|
21
|
+
__exportStar(require("./errors/not-authorized-error"), exports);
|
|
22
|
+
__exportStar(require("./errors/not-found-error"), exports);
|
|
23
|
+
__exportStar(require("./errors/request-validation-error"), exports);
|
|
24
|
+
__exportStar(require("./middlewares/current-user"), exports);
|
|
25
|
+
__exportStar(require("./middlewares/error-handler"), exports);
|
|
26
|
+
__exportStar(require("./middlewares/require-auth"), exports);
|
|
27
|
+
__exportStar(require("./middlewares/validate-request"), exports);
|
|
28
|
+
__exportStar(require("./events/base-listener"), exports);
|
|
29
|
+
__exportStar(require("./events/base-publisher"), exports);
|
|
30
|
+
__exportStar(require("./events/subjects"), exports);
|
|
31
|
+
__exportStar(require("./events/ticket-created-event"), exports);
|
|
32
|
+
__exportStar(require("./events/ticket-updated-event"), exports);
|
|
33
|
+
__exportStar(require("./events/types/order-status"), exports);
|
|
34
|
+
__exportStar(require("./events/order-cancelled-event"), exports);
|
|
35
|
+
__exportStar(require("./events/order-created-event"), exports);
|
|
36
|
+
__exportStar(require("./events/expiration-complete-event"), exports);
|
|
37
|
+
__exportStar(require("./events/payment-created-event"), exports);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Request, Response, NextFunction } from
|
|
1
|
+
import { Request, Response, NextFunction } from "express";
|
|
2
2
|
interface UserPayload {
|
|
3
3
|
id: string;
|
|
4
4
|
email: string;
|
|
@@ -10,5 +10,5 @@ declare global {
|
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
export declare const currentUser: (req: Request
|
|
13
|
+
export declare const currentUser: (req: Request, res: Response, next: NextFunction) => void;
|
|
14
14
|
export {};
|
|
@@ -3,16 +3,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
exports.currentUser = void 0;
|
|
7
|
+
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
8
|
+
const currentUser = (req, res, next) => {
|
|
8
9
|
var _a;
|
|
9
10
|
if (!((_a = req.session) === null || _a === void 0 ? void 0 : _a.jwt)) {
|
|
10
11
|
return next();
|
|
11
12
|
}
|
|
12
13
|
try {
|
|
13
|
-
|
|
14
|
+
const payload = jsonwebtoken_1.default.verify(req.session.jwt, process.env.JWT_KEY);
|
|
14
15
|
req.currentUser = payload;
|
|
15
16
|
}
|
|
16
17
|
catch (err) { }
|
|
17
18
|
next();
|
|
18
19
|
};
|
|
20
|
+
exports.currentUser = currentUser;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Request, Response, NextFunction } from 'express';
|
|
2
|
-
export declare const errorHandler: (err: Error, req: Request
|
|
2
|
+
export declare const errorHandler: (err: Error, req: Request, res: Response, next: NextFunction) => Response<any, Record<string, any>> | undefined;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
exports.errorHandler = void 0;
|
|
4
|
+
const custom_error_1 = require("../errors/custom-error");
|
|
5
|
+
const errorHandler = (err, req, res, next) => {
|
|
5
6
|
if (err instanceof custom_error_1.CustomError) {
|
|
6
7
|
return res.status(err.statusCode).send({ errors: err.serializeErrors() });
|
|
7
8
|
}
|
|
@@ -10,3 +11,4 @@ exports.errorHandler = function (err, req, res, next) {
|
|
|
10
11
|
errors: [{ message: 'Something went wrong' }],
|
|
11
12
|
});
|
|
12
13
|
};
|
|
14
|
+
exports.errorHandler = errorHandler;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Request, Response, NextFunction } from 'express';
|
|
2
|
-
export declare const requireAuth: (req: Request
|
|
2
|
+
export declare const requireAuth: (req: Request, res: Response, next: NextFunction) => void;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
exports.requireAuth = void 0;
|
|
4
|
+
const not_authorized_error_1 = require("../errors/not-authorized-error");
|
|
5
|
+
const requireAuth = (req, res, next) => {
|
|
5
6
|
if (!req.currentUser) {
|
|
6
7
|
throw new not_authorized_error_1.NotAuthorizedError();
|
|
7
8
|
}
|
|
8
9
|
next();
|
|
9
10
|
};
|
|
11
|
+
exports.requireAuth = requireAuth;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Request, Response, NextFunction } from 'express';
|
|
2
|
-
export declare const validateRequest: (req: Request
|
|
2
|
+
export declare const validateRequest: (req: Request, res: Response, next: NextFunction) => void;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
exports.validateRequest = void 0;
|
|
4
|
+
const express_validator_1 = require("express-validator");
|
|
5
|
+
const request_validation_error_1 = require("../errors/request-validation-error");
|
|
6
|
+
const validateRequest = (req, res, next) => {
|
|
7
|
+
const errors = (0, express_validator_1.validationResult)(req);
|
|
7
8
|
if (!errors.isEmpty()) {
|
|
8
9
|
throw new request_validation_error_1.RequestValidationError(errors.array());
|
|
9
10
|
}
|
|
10
11
|
next();
|
|
11
12
|
};
|
|
13
|
+
exports.validateRequest = validateRequest;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antonymarshal23/common",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -16,17 +16,19 @@
|
|
|
16
16
|
"author": "",
|
|
17
17
|
"license": "ISC",
|
|
18
18
|
"devDependencies": {
|
|
19
|
+
"@types/node": "^18.19.130",
|
|
19
20
|
"del-cli": "^3.0.0",
|
|
20
|
-
"typescript": "^
|
|
21
|
+
"typescript": "^4.9.5"
|
|
21
22
|
},
|
|
22
23
|
"dependencies": {
|
|
23
24
|
"@types/cookie-session": "^2.0.39",
|
|
24
25
|
"@types/express": "^4.17.5",
|
|
25
26
|
"@types/jsonwebtoken": "^8.3.9",
|
|
27
|
+
"amqplib": "^2.0.1",
|
|
26
28
|
"cookie-session": "^1.4.0",
|
|
27
29
|
"express": "^4.17.1",
|
|
28
30
|
"express-validator": "^6.4.0",
|
|
29
31
|
"jsonwebtoken": "^8.5.1",
|
|
30
32
|
"node-nats-streaming": "^0.2.6"
|
|
31
33
|
}
|
|
32
|
-
}
|
|
34
|
+
}
|