@rwojpromise/common 1.0.9 → 1.1.1
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 +16 -32
- package/build/errors/custom-error.js +10 -26
- package/build/errors/database-connection-error.js +16 -32
- package/build/errors/not-authorized-error.js +15 -31
- package/build/errors/not-found-error.js +15 -31
- package/build/errors/request-validation-error.js +19 -35
- package/build/events/base-listener.js +33 -35
- package/build/events/base-publisher.js +20 -22
- package/build/events/invest-created-event.js +2 -2
- package/build/events/subjects.js +9 -8
- package/build/events/token-created-event.js +2 -0
- package/build/events/user-created-event.js +2 -2
- package/build/index.js +29 -28
- package/build/middlewares/current-user.js +20 -19
- package/build/middlewares/error-handler.js +14 -13
- package/build/middlewares/require-auth.js +11 -10
- package/build/middlewares/validate-request.js +13 -12
- package/package.json +11 -12
- package/build/errors/bad-request-error.d.ts +0 -9
- package/build/errors/custom-error.d.ts +0 -8
- package/build/errors/database-connection-error.d.ts +0 -9
- package/build/errors/not-authorized-error.d.ts +0 -8
- package/build/errors/not-found-error.d.ts +0 -8
- package/build/errors/request-validation-error.d.ts +0 -11
- package/build/events/base-listener.d.ts +0 -18
- package/build/events/base-publisher.d.ts +0 -13
- package/build/events/invest-created-event.d.ts +0 -11
- package/build/events/subjects.d.ts +0 -4
- package/build/events/user-created-event.d.ts +0 -11
- package/build/index.d.ts +0 -15
- package/build/middlewares/current-user.d.ts +0 -14
- package/build/middlewares/error-handler.d.ts +0 -2
- package/build/middlewares/require-auth.d.ts +0 -2
- package/build/middlewares/validate-request.d.ts +0 -2
|
@@ -1,32 +1,16 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
exports.BadRequestError =
|
|
17
|
-
var custom_error_1 = require("./custom-error");
|
|
18
|
-
var BadRequestError = /** @class */ (function (_super) {
|
|
19
|
-
__extends(BadRequestError, _super);
|
|
20
|
-
function BadRequestError(message) {
|
|
21
|
-
var _this = _super.call(this, message) || this;
|
|
22
|
-
_this.message = message;
|
|
23
|
-
_this.statusCode = 400;
|
|
24
|
-
Object.setPrototypeOf(_this, BadRequestError.prototype);
|
|
25
|
-
return _this;
|
|
26
|
-
}
|
|
27
|
-
BadRequestError.prototype.serializeErrors = function () {
|
|
28
|
-
return [{ message: this.message }];
|
|
29
|
-
};
|
|
30
|
-
return BadRequestError;
|
|
31
|
-
}(custom_error_1.CustomError));
|
|
32
|
-
exports.BadRequestError = BadRequestError;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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);
|
|
11
|
+
}
|
|
12
|
+
serializeErrors() {
|
|
13
|
+
return [{ message: this.message }];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.BadRequestError = BadRequestError;
|
|
@@ -1,26 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
function __() { this.constructor = d; }
|
|
12
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.CustomError = void 0;
|
|
17
|
-
var CustomError = /** @class */ (function (_super) {
|
|
18
|
-
__extends(CustomError, _super);
|
|
19
|
-
function CustomError(message) {
|
|
20
|
-
var _this = _super.call(this, message) || this;
|
|
21
|
-
Object.setPrototypeOf(_this, CustomError.prototype);
|
|
22
|
-
return _this;
|
|
23
|
-
}
|
|
24
|
-
return CustomError;
|
|
25
|
-
}(Error));
|
|
26
|
-
exports.CustomError = CustomError;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CustomError = void 0;
|
|
4
|
+
class CustomError extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
Object.setPrototypeOf(this, CustomError.prototype);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.CustomError = CustomError;
|
|
@@ -1,32 +1,16 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
exports.DatabaseConnectionError =
|
|
17
|
-
var custom_error_1 = require("./custom-error");
|
|
18
|
-
var DatabaseConnectionError = /** @class */ (function (_super) {
|
|
19
|
-
__extends(DatabaseConnectionError, _super);
|
|
20
|
-
function DatabaseConnectionError() {
|
|
21
|
-
var _this = _super.call(this, 'Error connecting to db') || this;
|
|
22
|
-
_this.statusCode = 500;
|
|
23
|
-
_this.reason = 'Error connecting to database';
|
|
24
|
-
Object.setPrototypeOf(_this, DatabaseConnectionError.prototype);
|
|
25
|
-
return _this;
|
|
26
|
-
}
|
|
27
|
-
DatabaseConnectionError.prototype.serializeErrors = function () {
|
|
28
|
-
return [{ message: this.reason }];
|
|
29
|
-
};
|
|
30
|
-
return DatabaseConnectionError;
|
|
31
|
-
}(custom_error_1.CustomError));
|
|
32
|
-
exports.DatabaseConnectionError = DatabaseConnectionError;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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);
|
|
11
|
+
}
|
|
12
|
+
serializeErrors() {
|
|
13
|
+
return [{ message: this.reason }];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.DatabaseConnectionError = DatabaseConnectionError;
|
|
@@ -1,31 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
exports.NotAuthorizedError = void 0;
|
|
17
|
-
var custom_error_1 = require("./custom-error");
|
|
18
|
-
var NotAuthorizedError = /** @class */ (function (_super) {
|
|
19
|
-
__extends(NotAuthorizedError, _super);
|
|
20
|
-
function NotAuthorizedError() {
|
|
21
|
-
var _this = _super.call(this, 'Not Authorized') || this;
|
|
22
|
-
_this.statusCode = 401;
|
|
23
|
-
Object.setPrototypeOf(_this, NotAuthorizedError.prototype);
|
|
24
|
-
return _this;
|
|
25
|
-
}
|
|
26
|
-
NotAuthorizedError.prototype.serializeErrors = function () {
|
|
27
|
-
return [{ message: 'Not authorized' }];
|
|
28
|
-
};
|
|
29
|
-
return NotAuthorizedError;
|
|
30
|
-
}(custom_error_1.CustomError));
|
|
31
|
-
exports.NotAuthorizedError = NotAuthorizedError;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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);
|
|
10
|
+
}
|
|
11
|
+
serializeErrors() {
|
|
12
|
+
return [{ message: 'Not authorized' }];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.NotAuthorizedError = NotAuthorizedError;
|
|
@@ -1,31 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
exports.NotFoundError = void 0;
|
|
17
|
-
var custom_error_1 = require("./custom-error");
|
|
18
|
-
var NotFoundError = /** @class */ (function (_super) {
|
|
19
|
-
__extends(NotFoundError, _super);
|
|
20
|
-
function NotFoundError() {
|
|
21
|
-
var _this = _super.call(this, 'Route not found') || this;
|
|
22
|
-
_this.statusCode = 404;
|
|
23
|
-
Object.setPrototypeOf(_this, NotFoundError.prototype);
|
|
24
|
-
return _this;
|
|
25
|
-
}
|
|
26
|
-
NotFoundError.prototype.serializeErrors = function () {
|
|
27
|
-
return [{ message: 'Not Found' }];
|
|
28
|
-
};
|
|
29
|
-
return NotFoundError;
|
|
30
|
-
}(custom_error_1.CustomError));
|
|
31
|
-
exports.NotFoundError = NotFoundError;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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);
|
|
10
|
+
}
|
|
11
|
+
serializeErrors() {
|
|
12
|
+
return [{ message: 'Not Found' }];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.NotFoundError = NotFoundError;
|
|
@@ -1,35 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
function RequestValidationError(errors) {
|
|
21
|
-
var _this = _super.call(this, 'Invalid request parameters') || this;
|
|
22
|
-
_this.errors = errors;
|
|
23
|
-
_this.statusCode = 400;
|
|
24
|
-
// Only because we are extending a built in class
|
|
25
|
-
Object.setPrototypeOf(_this, RequestValidationError.prototype);
|
|
26
|
-
return _this;
|
|
27
|
-
}
|
|
28
|
-
RequestValidationError.prototype.serializeErrors = function () {
|
|
29
|
-
return this.errors.map(function (err) {
|
|
30
|
-
return { message: err.msg, field: err.param };
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
return RequestValidationError;
|
|
34
|
-
}(custom_error_1.CustomError));
|
|
35
|
-
exports.RequestValidationError = RequestValidationError;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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;
|
|
10
|
+
// Only because we are extending a built in class
|
|
11
|
+
Object.setPrototypeOf(this, RequestValidationError.prototype);
|
|
12
|
+
}
|
|
13
|
+
serializeErrors() {
|
|
14
|
+
return this.errors.map(err => {
|
|
15
|
+
return { message: err.msg, field: err.param };
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.RequestValidationError = RequestValidationError;
|
|
@@ -1,35 +1,33 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Listener = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
this.ackWait = 5 * 1000;
|
|
7
|
-
this.client = client;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
return this.client
|
|
11
|
-
.subscriptionOptions()
|
|
12
|
-
.setDeliverAllAvailable()
|
|
13
|
-
.setManualAckMode(true)
|
|
14
|
-
.setAckWait(this.ackWait)
|
|
15
|
-
.setDurableName(this.queueGroupName);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}());
|
|
35
|
-
exports.Listener = Listener;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Listener = void 0;
|
|
4
|
+
class Listener {
|
|
5
|
+
constructor(client) {
|
|
6
|
+
this.ackWait = 5 * 1000;
|
|
7
|
+
this.client = client;
|
|
8
|
+
}
|
|
9
|
+
subscriptionOptions() {
|
|
10
|
+
return this.client
|
|
11
|
+
.subscriptionOptions()
|
|
12
|
+
.setDeliverAllAvailable()
|
|
13
|
+
.setManualAckMode(true)
|
|
14
|
+
.setAckWait(this.ackWait)
|
|
15
|
+
.setDurableName(this.queueGroupName);
|
|
16
|
+
}
|
|
17
|
+
listen() {
|
|
18
|
+
console.log("I am starting to listen...");
|
|
19
|
+
const subscription = this.client.subscribe(this.subject, this.queueGroupName, this.subscriptionOptions());
|
|
20
|
+
subscription.on("message", (msg) => {
|
|
21
|
+
console.log(`New Message received ${this.subject} / ${this.queueGroupName}`);
|
|
22
|
+
const parsedData = this.parseMessage(msg);
|
|
23
|
+
this.onMessage(parsedData, msg);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
parseMessage(msg) {
|
|
27
|
+
const data = msg.getData();
|
|
28
|
+
return typeof data === "string"
|
|
29
|
+
? JSON.parse(data)
|
|
30
|
+
: JSON.parse(data.toString("utf-8"));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.Listener = Listener;
|
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Publisher = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
this.client = client;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}());
|
|
22
|
-
exports.Publisher = Publisher;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Publisher = void 0;
|
|
4
|
+
class Publisher {
|
|
5
|
+
constructor(client) {
|
|
6
|
+
this.client = client;
|
|
7
|
+
}
|
|
8
|
+
publish(data) {
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
this.client.publish(this.subject, JSON.stringify(data), (err) => {
|
|
11
|
+
if (err) {
|
|
12
|
+
return reject(err);
|
|
13
|
+
}
|
|
14
|
+
console.log(`event published to subject ${this.subject}`);
|
|
15
|
+
resolve();
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.Publisher = Publisher;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/build/events/subjects.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Subjects = void 0;
|
|
4
|
-
var Subjects;
|
|
5
|
-
(function (Subjects) {
|
|
6
|
-
Subjects["UserCreated"] = "user:created";
|
|
7
|
-
Subjects["InvestCreated"] = "invest:created";
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Subjects = void 0;
|
|
4
|
+
var Subjects;
|
|
5
|
+
(function (Subjects) {
|
|
6
|
+
Subjects["UserCreated"] = "user:created";
|
|
7
|
+
Subjects["InvestCreated"] = "invest:created";
|
|
8
|
+
Subjects["TokenCreated"] = "token:created";
|
|
9
|
+
})(Subjects = exports.Subjects || (exports.Subjects = {}));
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/build/index.js
CHANGED
|
@@ -1,28 +1,29 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
// Re-export stuff from errors and middlewares
|
|
14
|
-
__exportStar(require("./errors/bad-request-error"), exports);
|
|
15
|
-
__exportStar(require("./errors/custom-error"), exports);
|
|
16
|
-
__exportStar(require("./errors/database-connection-error"), exports);
|
|
17
|
-
__exportStar(require("./errors/not-authorized-error"), exports);
|
|
18
|
-
__exportStar(require("./errors/not-found-error"), exports);
|
|
19
|
-
__exportStar(require("./errors/request-validation-error"), exports);
|
|
20
|
-
__exportStar(require("./middlewares/current-user"), exports);
|
|
21
|
-
__exportStar(require("./middlewares/error-handler"), exports);
|
|
22
|
-
__exportStar(require("./middlewares/require-auth"), exports);
|
|
23
|
-
__exportStar(require("./middlewares/validate-request"), exports);
|
|
24
|
-
__exportStar(require("./events/base-listener"), exports);
|
|
25
|
-
__exportStar(require("./events/base-publisher"), exports);
|
|
26
|
-
__exportStar(require("./events/subjects"), exports);
|
|
27
|
-
__exportStar(require("./events/user-created-event"), exports);
|
|
28
|
-
__exportStar(require("./events/invest-created-event"), exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
// Re-export stuff from errors and middlewares
|
|
14
|
+
__exportStar(require("./errors/bad-request-error"), exports);
|
|
15
|
+
__exportStar(require("./errors/custom-error"), exports);
|
|
16
|
+
__exportStar(require("./errors/database-connection-error"), exports);
|
|
17
|
+
__exportStar(require("./errors/not-authorized-error"), exports);
|
|
18
|
+
__exportStar(require("./errors/not-found-error"), exports);
|
|
19
|
+
__exportStar(require("./errors/request-validation-error"), exports);
|
|
20
|
+
__exportStar(require("./middlewares/current-user"), exports);
|
|
21
|
+
__exportStar(require("./middlewares/error-handler"), exports);
|
|
22
|
+
__exportStar(require("./middlewares/require-auth"), exports);
|
|
23
|
+
__exportStar(require("./middlewares/validate-request"), exports);
|
|
24
|
+
__exportStar(require("./events/base-listener"), exports);
|
|
25
|
+
__exportStar(require("./events/base-publisher"), exports);
|
|
26
|
+
__exportStar(require("./events/subjects"), exports);
|
|
27
|
+
__exportStar(require("./events/user-created-event"), exports);
|
|
28
|
+
__exportStar(require("./events/invest-created-event"), exports);
|
|
29
|
+
__exportStar(require("./events/token-created-event"), exports);
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.currentUser = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var _a;
|
|
10
|
-
if (!((_a = req.session) === null || _a === void 0 ? void 0 : _a.jwt)) {
|
|
11
|
-
return next();
|
|
12
|
-
}
|
|
13
|
-
try {
|
|
14
|
-
|
|
15
|
-
req.currentUser = payload;
|
|
16
|
-
}
|
|
17
|
-
catch (err) { }
|
|
18
|
-
next();
|
|
19
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.currentUser = void 0;
|
|
7
|
+
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
8
|
+
const currentUser = (req, res, next) => {
|
|
9
|
+
var _a;
|
|
10
|
+
if (!((_a = req.session) === null || _a === void 0 ? void 0 : _a.jwt)) {
|
|
11
|
+
return next();
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
const payload = jsonwebtoken_1.default.verify(req.session.jwt, process.env.JWT_KEY);
|
|
15
|
+
req.currentUser = payload;
|
|
16
|
+
}
|
|
17
|
+
catch (err) { }
|
|
18
|
+
next();
|
|
19
|
+
};
|
|
20
|
+
exports.currentUser = currentUser;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.errorHandler = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (err instanceof custom_error_1.CustomError) {
|
|
7
|
-
return res.status(err.statusCode).send({ errors: err.serializeErrors() });
|
|
8
|
-
}
|
|
9
|
-
console.error(err);
|
|
10
|
-
res.status(400).send({
|
|
11
|
-
errors: [{ message: "Something went wrong" }],
|
|
12
|
-
});
|
|
13
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.errorHandler = void 0;
|
|
4
|
+
const custom_error_1 = require("../errors/custom-error");
|
|
5
|
+
const errorHandler = (err, req, res, next) => {
|
|
6
|
+
if (err instanceof custom_error_1.CustomError) {
|
|
7
|
+
return res.status(err.statusCode).send({ errors: err.serializeErrors() });
|
|
8
|
+
}
|
|
9
|
+
console.error(err);
|
|
10
|
+
res.status(400).send({
|
|
11
|
+
errors: [{ message: "Something went wrong" }],
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
exports.errorHandler = errorHandler;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.requireAuth = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (!req.currentUser) {
|
|
7
|
-
throw new not_authorized_error_1.NotAuthorizedError();
|
|
8
|
-
}
|
|
9
|
-
next();
|
|
10
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.requireAuth = void 0;
|
|
4
|
+
const not_authorized_error_1 = require("../errors/not-authorized-error");
|
|
5
|
+
const requireAuth = (req, res, next) => {
|
|
6
|
+
if (!req.currentUser) {
|
|
7
|
+
throw new not_authorized_error_1.NotAuthorizedError();
|
|
8
|
+
}
|
|
9
|
+
next();
|
|
10
|
+
};
|
|
11
|
+
exports.requireAuth = requireAuth;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateRequest = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (!errors.isEmpty()) {
|
|
9
|
-
throw new request_validation_error_1.RequestValidationError(errors.array());
|
|
10
|
-
}
|
|
11
|
-
next();
|
|
12
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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);
|
|
8
|
+
if (!errors.isEmpty()) {
|
|
9
|
+
throw new request_validation_error_1.RequestValidationError(errors.array());
|
|
10
|
+
}
|
|
11
|
+
next();
|
|
12
|
+
};
|
|
13
|
+
exports.validateRequest = validateRequest;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rwojpromise/common",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -12,21 +12,20 @@
|
|
|
12
12
|
"build": "npm run clean && tsc",
|
|
13
13
|
"pub": "git add . && git commit -m \"Updates\" && npm version patch && npm run build && npm publish"
|
|
14
14
|
},
|
|
15
|
+
"keywords": [],
|
|
15
16
|
"author": "",
|
|
16
17
|
"license": "ISC",
|
|
17
|
-
"devDependencies": {
|
|
18
|
-
"del-cli": "^3.0.1",
|
|
19
|
-
"typescript": "^4.0.3"
|
|
20
|
-
},
|
|
21
18
|
"dependencies": {
|
|
22
|
-
"@types/cookie-session": "^2.0.
|
|
23
|
-
"@types/express": "^4.17.
|
|
24
|
-
"@types/jsonwebtoken": "^8.5.
|
|
25
|
-
"
|
|
26
|
-
"express": "^
|
|
27
|
-
"express-validator": "^6.6.1",
|
|
19
|
+
"@types/cookie-session": "^2.0.43",
|
|
20
|
+
"@types/express": "^4.17.13",
|
|
21
|
+
"@types/jsonwebtoken": "^8.5.6",
|
|
22
|
+
"express": "^4.17.2",
|
|
23
|
+
"express-validator": "^6.14.0",
|
|
28
24
|
"jsonwebtoken": "^8.5.1",
|
|
29
25
|
"node-nats-streaming": "^0.3.2",
|
|
30
|
-
"patch": "0.0.1"
|
|
26
|
+
"patch": "^0.0.1"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"typescript": "^4.5.4"
|
|
31
30
|
}
|
|
32
31
|
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { ValidationError } from 'express-validator';
|
|
2
|
-
import { CustomError } from './custom-error';
|
|
3
|
-
export declare class RequestValidationError extends CustomError {
|
|
4
|
-
errors: ValidationError[];
|
|
5
|
-
statusCode: number;
|
|
6
|
-
constructor(errors: ValidationError[]);
|
|
7
|
-
serializeErrors(): {
|
|
8
|
-
message: any;
|
|
9
|
-
field: string;
|
|
10
|
-
}[];
|
|
11
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Message, Stan } from "node-nats-streaming";
|
|
2
|
-
import { Subjects } from "./subjects";
|
|
3
|
-
interface Event {
|
|
4
|
-
subject: Subjects;
|
|
5
|
-
data: any;
|
|
6
|
-
}
|
|
7
|
-
export declare abstract class Listener<T extends Event> {
|
|
8
|
-
abstract subject: T["subject"];
|
|
9
|
-
abstract queueGroupName: string;
|
|
10
|
-
abstract onMessage(data: T["data"], msg: Message): void;
|
|
11
|
-
protected client: Stan;
|
|
12
|
-
protected ackWait: number;
|
|
13
|
-
constructor(client: Stan);
|
|
14
|
-
subscriptionOptions(): import("node-nats-streaming").SubscriptionOptions;
|
|
15
|
-
listen(): void;
|
|
16
|
-
parseMessage(msg: Message): any;
|
|
17
|
-
}
|
|
18
|
-
export {};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Stan } from "node-nats-streaming";
|
|
2
|
-
import { Subjects } from "./subjects";
|
|
3
|
-
interface Event {
|
|
4
|
-
subject: Subjects;
|
|
5
|
-
data: any;
|
|
6
|
-
}
|
|
7
|
-
export declare abstract class Publisher<T extends Event> {
|
|
8
|
-
abstract subject: T["subject"];
|
|
9
|
-
protected client: Stan;
|
|
10
|
-
constructor(client: Stan);
|
|
11
|
-
publish(data: T["data"]): Promise<void>;
|
|
12
|
-
}
|
|
13
|
-
export {};
|
package/build/index.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export * from "./errors/bad-request-error";
|
|
2
|
-
export * from "./errors/custom-error";
|
|
3
|
-
export * from "./errors/database-connection-error";
|
|
4
|
-
export * from "./errors/not-authorized-error";
|
|
5
|
-
export * from "./errors/not-found-error";
|
|
6
|
-
export * from "./errors/request-validation-error";
|
|
7
|
-
export * from "./middlewares/current-user";
|
|
8
|
-
export * from "./middlewares/error-handler";
|
|
9
|
-
export * from "./middlewares/require-auth";
|
|
10
|
-
export * from "./middlewares/validate-request";
|
|
11
|
-
export * from "./events/base-listener";
|
|
12
|
-
export * from "./events/base-publisher";
|
|
13
|
-
export * from "./events/subjects";
|
|
14
|
-
export * from "./events/user-created-event";
|
|
15
|
-
export * from "./events/invest-created-event";
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Request, Response, NextFunction } from "express";
|
|
2
|
-
interface UserPayload {
|
|
3
|
-
id: string;
|
|
4
|
-
email: string;
|
|
5
|
-
}
|
|
6
|
-
declare global {
|
|
7
|
-
namespace Express {
|
|
8
|
-
interface Request {
|
|
9
|
-
currentUser?: UserPayload;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
export declare const currentUser: (req: Request, res: Response, next: NextFunction) => void;
|
|
14
|
-
export {};
|