@bloggie/library 1.0.0 → 1.0.2
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-errors.d.ts +9 -0
- package/build/errors/bad-request-errors.js +20 -0
- package/build/errors/bad-request-errors.js.map +1 -0
- package/build/errors/custom-errors.d.ts +8 -0
- package/build/errors/custom-errors.js +11 -0
- package/build/errors/custom-errors.js.map +1 -0
- package/build/errors/database-connection-error.d.ts +10 -0
- package/build/errors/database-connection-error.js +21 -0
- package/build/errors/database-connection-error.js.map +1 -0
- package/build/errors/not-authorized-errors.d.ts +9 -0
- package/build/errors/not-authorized-errors.js +20 -0
- package/build/errors/not-authorized-errors.js.map +1 -0
- package/build/errors/not-found-error.d.ts +9 -0
- package/build/errors/not-found-error.js +20 -0
- package/build/errors/not-found-error.js.map +1 -0
- package/build/errors/request-validation-error.d.ts +11 -0
- package/build/errors/request-validation-error.js +22 -0
- package/build/errors/request-validation-error.js.map +1 -0
- package/build/events/base-listener.d.ts +18 -0
- package/build/events/base-listener.js +33 -0
- package/build/events/base-listener.js.map +1 -0
- package/build/events/base-publisher.d.ts +13 -0
- package/build/events/base-publisher.js +21 -0
- package/build/events/base-publisher.js.map +1 -0
- package/build/events/otp-verification-event.d.ts +8 -0
- package/build/events/otp-verification-event.js +3 -0
- package/build/events/otp-verification-event.js.map +1 -0
- package/build/events/resend-otp-event.d.ts +8 -0
- package/build/events/resend-otp-event.js +3 -0
- package/build/events/resend-otp-event.js.map +1 -0
- package/build/events/subjects.d.ts +5 -0
- package/build/events/subjects.js +10 -0
- package/build/events/subjects.js.map +1 -0
- package/build/index.d.ts +15 -0
- package/build/index.js +32 -0
- package/build/index.js.map +1 -0
- package/build/middleware/current-user.d.ts +15 -0
- package/build/middleware/current-user.js +22 -0
- package/build/middleware/current-user.js.map +1 -0
- package/build/middleware/error-handler.d.ts +2 -0
- package/build/middleware/error-handler.js +19 -0
- package/build/middleware/error-handler.js.map +1 -0
- package/build/middleware/require-auth.d.ts +2 -0
- package/build/middleware/require-auth.js +12 -0
- package/build/middleware/require-auth.js.map +1 -0
- package/build/middleware/validate-request.d.ts +2 -0
- package/build/middleware/validate-request.js +13 -0
- package/build/middleware/validate-request.js.map +1 -0
- package/package.json +12 -3
- package/index.ts +0 -0
- package/src/events/base-listener.ts +0 -51
- package/src/events/otp-verification-event.ts +0 -9
- package/src/events/resend-otp-event.ts +0 -9
- package/src/events/subjects.ts +0 -5
- package/tsconfig.json +0 -20
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BadRequestError = void 0;
|
|
4
|
+
const custom_errors_1 = require("./custom-errors");
|
|
5
|
+
class BadRequestError extends custom_errors_1.CustomError {
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.statusCode = 400;
|
|
9
|
+
Object.setPrototypeOf(this, BadRequestError.prototype);
|
|
10
|
+
}
|
|
11
|
+
serializeError() {
|
|
12
|
+
return [
|
|
13
|
+
{
|
|
14
|
+
message: this.message,
|
|
15
|
+
},
|
|
16
|
+
];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.BadRequestError = BadRequestError;
|
|
20
|
+
//# sourceMappingURL=bad-request-errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bad-request-errors.js","sourceRoot":"","sources":["../../src/errors/bad-request-errors.ts"],"names":[],"mappings":";;;AAAA,mDAA8C;AAE9C,qBAA6B,SAAQ,2BAAW;IAG9C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QAHjB,eAAU,GAAW,GAAG,CAAC;QAIvB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;IACzD,CAAC;IAED,cAAc;QACZ,OAAO;YACL;gBACE,OAAO,EAAE,IAAI,CAAC,OAAO;aACtB;SACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
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;
|
|
11
|
+
//# sourceMappingURL=custom-errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom-errors.js","sourceRoot":"","sources":["../../src/errors/custom-errors.ts"],"names":[],"mappings":";;;AAAA,iBAAkC,SAAQ,KAAK;IAG7C,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IACrD,CAAC;CAGF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DatabaseConnectionError = void 0;
|
|
4
|
+
const custom_errors_1 = require("./custom-errors");
|
|
5
|
+
class DatabaseConnectionError extends custom_errors_1.CustomError {
|
|
6
|
+
constructor() {
|
|
7
|
+
super('Error connecting to the database');
|
|
8
|
+
this.statusCode = 500;
|
|
9
|
+
this.reason = 'Error connecting to the database';
|
|
10
|
+
Object.setPrototypeOf(this, DatabaseConnectionError.prototype);
|
|
11
|
+
}
|
|
12
|
+
serializeError() {
|
|
13
|
+
return [
|
|
14
|
+
{
|
|
15
|
+
message: this.reason,
|
|
16
|
+
},
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.DatabaseConnectionError = DatabaseConnectionError;
|
|
21
|
+
//# sourceMappingURL=database-connection-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database-connection-error.js","sourceRoot":"","sources":["../../src/errors/database-connection-error.ts"],"names":[],"mappings":";;;AAAA,mDAA8C;AAE9C,6BAAqC,SAAQ,2BAAW;IAKtD;QACE,KAAK,CAAC,kCAAkC,CAAC,CAAC;QAL5C,eAAU,GAAG,GAAG,CAAC;QAEjB,WAAM,GAAG,kCAAkC,CAAC;QAK1C,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,uBAAuB,CAAC,SAAS,CAAC,CAAC;IACjE,CAAC;IAED,cAAc;QACZ,OAAO;YACL;gBACE,OAAO,EAAE,IAAI,CAAC,MAAM;aACrB;SACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NotAuthorizedError = void 0;
|
|
4
|
+
const custom_errors_1 = require("./custom-errors");
|
|
5
|
+
class NotAuthorizedError extends custom_errors_1.CustomError {
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(message || 'Not Authorized to Perform this Task');
|
|
8
|
+
this.statusCode = 401;
|
|
9
|
+
Object.setPrototypeOf(this, NotAuthorizedError.prototype);
|
|
10
|
+
}
|
|
11
|
+
serializeError() {
|
|
12
|
+
return [
|
|
13
|
+
{
|
|
14
|
+
message: this.message,
|
|
15
|
+
},
|
|
16
|
+
];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.NotAuthorizedError = NotAuthorizedError;
|
|
20
|
+
//# sourceMappingURL=not-authorized-errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"not-authorized-errors.js","sourceRoot":"","sources":["../../src/errors/not-authorized-errors.ts"],"names":[],"mappings":";;;AAAA,mDAA8C;AAE9C,wBAAgC,SAAQ,2BAAW;IAGjD,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,IAAI,qCAAqC,CAAC,CAAC;QAH1D,eAAU,GAAW,GAAG,CAAC;QAIvB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAC5D,CAAC;IAED,cAAc;QACZ,OAAO;YACL;gBACE,OAAO,EAAE,IAAI,CAAC,OAAO;aACtB;SACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NotFoundError = void 0;
|
|
4
|
+
const custom_errors_1 = require("./custom-errors");
|
|
5
|
+
class NotFoundError extends custom_errors_1.CustomError {
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(message || 'Route Not Found');
|
|
8
|
+
this.statusCode = 404;
|
|
9
|
+
Object.setPrototypeOf(this, NotFoundError.prototype);
|
|
10
|
+
}
|
|
11
|
+
serializeError() {
|
|
12
|
+
return [
|
|
13
|
+
{
|
|
14
|
+
message: this.message,
|
|
15
|
+
},
|
|
16
|
+
];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.NotFoundError = NotFoundError;
|
|
20
|
+
//# sourceMappingURL=not-found-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"not-found-error.js","sourceRoot":"","sources":["../../src/errors/not-found-error.ts"],"names":[],"mappings":";;;AAAA,mDAA8C;AAE9C,mBAA2B,SAAQ,2BAAW;IAG5C,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,IAAI,iBAAiB,CAAC,CAAC;QAHtC,eAAU,GAAW,GAAG,CAAC;QAIvB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;IACvD,CAAC;IAED,cAAc;QACZ,OAAO;YACL;gBACE,OAAO,EAAE,IAAI,CAAC,OAAO;aACtB;SACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ValidationError } from 'express-validator';
|
|
2
|
+
import { CustomError } from './custom-errors';
|
|
3
|
+
export declare class RequestValidationError extends CustomError {
|
|
4
|
+
errors: ValidationError[];
|
|
5
|
+
statusCode: number;
|
|
6
|
+
constructor(errors: ValidationError[]);
|
|
7
|
+
serializeError(): {
|
|
8
|
+
message: string;
|
|
9
|
+
field?: string;
|
|
10
|
+
}[];
|
|
11
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RequestValidationError = void 0;
|
|
4
|
+
const custom_errors_1 = require("./custom-errors");
|
|
5
|
+
class RequestValidationError extends custom_errors_1.CustomError {
|
|
6
|
+
constructor(errors) {
|
|
7
|
+
super('Invalid Request Parameter');
|
|
8
|
+
this.errors = errors;
|
|
9
|
+
this.statusCode = 400;
|
|
10
|
+
Object.setPrototypeOf(this, RequestValidationError.prototype);
|
|
11
|
+
}
|
|
12
|
+
serializeError() {
|
|
13
|
+
return this.errors.map((err) => {
|
|
14
|
+
if (err.type === 'field') {
|
|
15
|
+
return { message: err.msg, field: err.path };
|
|
16
|
+
}
|
|
17
|
+
return { message: err.msg };
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.RequestValidationError = RequestValidationError;
|
|
22
|
+
//# sourceMappingURL=request-validation-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-validation-error.js","sourceRoot":"","sources":["../../src/errors/request-validation-error.ts"],"names":[],"mappings":";;;AACA,mDAA8C;AAE9C,4BAAoC,SAAQ,2BAAW;IAGrD,YAAmB,MAAyB;QAC1C,KAAK,CAAC,2BAA2B,CAAC,CAAC;QADlB,WAAM,GAAN,MAAM,CAAmB;QAF5C,eAAU,GAAG,GAAG,CAAC;QAKf,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,sBAAsB,CAAC,SAAS,CAAC,CAAC;IAChE,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;YAC7B,IAAI,GAAG,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;gBACzB,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC;YAC/C,CAAC;YACD,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,GAAG,EAAE,CAAC;QAC9B,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Message, Stan } from 'node-nats-streaming';
|
|
2
|
+
import { Subjects } from './subjects';
|
|
3
|
+
interface Events {
|
|
4
|
+
subject: Subjects;
|
|
5
|
+
data: any;
|
|
6
|
+
}
|
|
7
|
+
export declare abstract class Listener<T extends Events> {
|
|
8
|
+
abstract subject: T['subject'];
|
|
9
|
+
private client;
|
|
10
|
+
readonly ackWait: number;
|
|
11
|
+
abstract onMessage(data: T['data'], msg: Message): void;
|
|
12
|
+
abstract queueGroupName: string;
|
|
13
|
+
constructor(client: Stan);
|
|
14
|
+
subscriptionOptions(): import("node-nats-streaming").SubscriptionOptions;
|
|
15
|
+
listen(): void;
|
|
16
|
+
parsedData(msg: Message): any;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
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 * 60; // 5 mins
|
|
7
|
+
this.client = client;
|
|
8
|
+
}
|
|
9
|
+
subscriptionOptions() {
|
|
10
|
+
return this.client
|
|
11
|
+
.subscriptionOptions()
|
|
12
|
+
.setDeliverAllAvailable()
|
|
13
|
+
.setManualAckMode(true)
|
|
14
|
+
.setDurableName(this.queueGroupName)
|
|
15
|
+
.setAckWait(this.ackWait);
|
|
16
|
+
}
|
|
17
|
+
listen() {
|
|
18
|
+
const subscriptions = this.client.subscribe(this.subject, this.queueGroupName, this.subscriptionOptions());
|
|
19
|
+
subscriptions.on('message', (msg) => {
|
|
20
|
+
console.log(`Message received: ${this.subject}/${this.queueGroupName}`);
|
|
21
|
+
const parsedData = this.parsedData(msg);
|
|
22
|
+
this.onMessage(parsedData, msg);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
parsedData(msg) {
|
|
26
|
+
const data = msg.getData();
|
|
27
|
+
return typeof data === 'string'
|
|
28
|
+
? JSON.parse(data)
|
|
29
|
+
: JSON.parse(data.toString('utf-8'));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.Listener = Listener;
|
|
33
|
+
//# sourceMappingURL=base-listener.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-listener.js","sourceRoot":"","sources":["../../src/events/base-listener.ts"],"names":[],"mappings":";;;AAQA;IAOE,YAAY,MAAY;QAJf,YAAO,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,SAAS;QAKlC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,mBAAmB;QACjB,OAAO,IAAI,CAAC,MAAM;aACf,mBAAmB,EAAE;aACrB,sBAAsB,EAAE;aACxB,gBAAgB,CAAC,IAAI,CAAC;aACtB,cAAc,CAAC,IAAI,CAAC,cAAc,CAAC;aACnC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC9B,CAAC;IAED,MAAM;QACJ,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CACzC,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,cAAc,EACnB,IAAI,CAAC,mBAAmB,EAAE,CAC3B,CAAC;QAEF,aAAa,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,GAAY,EAAE,EAAE;YAC3C,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;YACxE,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;YAExC,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;QAClC,CAAC,CAAC,CAAC;IACL,CAAC;IAED,UAAU,CAAC,GAAY;QACrB,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC;QAE3B,OAAO,OAAO,IAAI,KAAK,QAAQ;YAC7B,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;YAClB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;IACzC,CAAC;CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Stan } from 'node-nats-streaming';
|
|
2
|
+
import { Subjects } from './subjects';
|
|
3
|
+
interface Events {
|
|
4
|
+
subject: Subjects;
|
|
5
|
+
data: any;
|
|
6
|
+
}
|
|
7
|
+
export declare abstract class Publisher<T extends Events> {
|
|
8
|
+
abstract subject: T['subject'];
|
|
9
|
+
protected client: Stan;
|
|
10
|
+
constructor(client: Stan);
|
|
11
|
+
publish(data: T['data']): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
console.log(err);
|
|
13
|
+
reject();
|
|
14
|
+
}
|
|
15
|
+
resolve();
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.Publisher = Publisher;
|
|
21
|
+
//# sourceMappingURL=base-publisher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-publisher.js","sourceRoot":"","sources":["../../src/events/base-publisher.ts"],"names":[],"mappings":";;;AAQA;IAIE,YAAY,MAAY;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,OAAO,CAAC,IAAe;QACrB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE;gBAC9D,IAAI,GAAG,EAAE,CAAC;oBACR,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;oBACjB,MAAM,EAAE,CAAC;gBACX,CAAC;gBACD,OAAO,EAAE,CAAC;YACZ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otp-verification-event.js","sourceRoot":"","sources":["../../src/events/otp-verification-event.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resend-otp-event.js","sourceRoot":"","sources":["../../src/events/resend-otp-event.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Subjects = void 0;
|
|
4
|
+
var Subjects;
|
|
5
|
+
(function (Subjects) {
|
|
6
|
+
Subjects["UserVerificationOtp"] = "user:pending";
|
|
7
|
+
Subjects["UserVerified"] = "user:verified";
|
|
8
|
+
Subjects["UserResendOtp"] = "user:retry";
|
|
9
|
+
})(Subjects || (exports.Subjects = Subjects = {}));
|
|
10
|
+
//# sourceMappingURL=subjects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subjects.js","sourceRoot":"","sources":["../../src/events/subjects.ts"],"names":[],"mappings":";;;AAAA,IAAY,QAIX;AAJD,WAAY,QAAQ;IAClB,gDAAoC,CAAA;IACpC,0CAA8B,CAAA;IAC9B,wCAA4B,CAAA;AAC9B,CAAC,EAJW,QAAQ,aAAR,QAAQ,GAAR,QAAQ,QAInB"}
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from './events/base-listener';
|
|
2
|
+
export * from './events/otp-verification-event';
|
|
3
|
+
export * from './events/subjects';
|
|
4
|
+
export * from './events/resend-otp-event';
|
|
5
|
+
export * from './events/base-publisher';
|
|
6
|
+
export * from './errors/bad-request-errors';
|
|
7
|
+
export * from './errors/custom-errors';
|
|
8
|
+
export * from './errors/database-connection-error';
|
|
9
|
+
export * from './errors/not-authorized-errors';
|
|
10
|
+
export * from './errors/not-found-error';
|
|
11
|
+
export * from './errors/request-validation-error';
|
|
12
|
+
export * from './middleware/current-user';
|
|
13
|
+
export * from './middleware/error-handler';
|
|
14
|
+
export * from './middleware/require-auth';
|
|
15
|
+
export * from './middleware/validate-request';
|
package/build/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
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
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./events/base-listener"), exports);
|
|
18
|
+
__exportStar(require("./events/otp-verification-event"), exports);
|
|
19
|
+
__exportStar(require("./events/subjects"), exports);
|
|
20
|
+
__exportStar(require("./events/resend-otp-event"), exports);
|
|
21
|
+
__exportStar(require("./events/base-publisher"), exports);
|
|
22
|
+
__exportStar(require("./errors/bad-request-errors"), exports);
|
|
23
|
+
__exportStar(require("./errors/custom-errors"), exports);
|
|
24
|
+
__exportStar(require("./errors/database-connection-error"), exports);
|
|
25
|
+
__exportStar(require("./errors/not-authorized-errors"), exports);
|
|
26
|
+
__exportStar(require("./errors/not-found-error"), exports);
|
|
27
|
+
__exportStar(require("./errors/request-validation-error"), exports);
|
|
28
|
+
__exportStar(require("./middleware/current-user"), exports);
|
|
29
|
+
__exportStar(require("./middleware/error-handler"), exports);
|
|
30
|
+
__exportStar(require("./middleware/require-auth"), exports);
|
|
31
|
+
__exportStar(require("./middleware/validate-request"), exports);
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAuC;AACvC,kEAAgD;AAChD,oDAAkC;AAClC,4DAA0C;AAC1C,0DAAwC;AAExC,8DAA4C;AAC5C,yDAAuC;AACvC,qEAAmD;AACnD,iEAA+C;AAC/C,2DAAyC;AACzC,oEAAkD;AAElD,4DAA0C;AAC1C,6DAA2C;AAC3C,4DAA0C;AAC1C,gEAA8C"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { NextFunction, Request, Response } from 'express';
|
|
2
|
+
interface UserPayload {
|
|
3
|
+
id: string;
|
|
4
|
+
email: string;
|
|
5
|
+
verified: boolean;
|
|
6
|
+
}
|
|
7
|
+
declare global {
|
|
8
|
+
namespace Express {
|
|
9
|
+
interface Request {
|
|
10
|
+
user?: UserPayload;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export declare const currentUser: (req: Request, res: Response, next: NextFunction) => void;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
if (!req.cookies.accessToken) {
|
|
10
|
+
return next();
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
const user = jsonwebtoken_1.default.verify(req.cookies.accessToken, process.env.ACCESS_TOKEN_SECRET);
|
|
14
|
+
req.user = user;
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
console.log(error);
|
|
18
|
+
}
|
|
19
|
+
next();
|
|
20
|
+
};
|
|
21
|
+
exports.currentUser = currentUser;
|
|
22
|
+
//# sourceMappingURL=current-user.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"current-user.js","sourceRoot":"","sources":["../../src/middleware/current-user.ts"],"names":[],"mappings":";;;;;;AAAA,gEAA+B;AAiBxB,MAAM,WAAW,GAAG,CACzB,GAAY,EACZ,GAAa,EACb,IAAkB,EAClB,EAAE;IACF,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;QAC7B,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC;IACD,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,sBAAG,CAAC,MAAM,CACrB,GAAG,CAAC,OAAO,CAAC,WAAW,EACvB,OAAO,CAAC,GAAG,CAAC,mBAAoB,CAClB,CAAC;QAEjB,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;IAED,IAAI,EAAE,CAAC;AACT,CAAC,CAAC;AApBW,QAAA,WAAW,GAAX,WAAW,CAoBtB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ErrorHandler = void 0;
|
|
4
|
+
const custom_errors_1 = require("../errors/custom-errors");
|
|
5
|
+
const ErrorHandler = (err, req, res, next) => {
|
|
6
|
+
if (err instanceof custom_errors_1.CustomError) {
|
|
7
|
+
return res.status(err.statusCode).send({ errors: err.serializeError() });
|
|
8
|
+
}
|
|
9
|
+
console.log(err);
|
|
10
|
+
res.status(400).send({
|
|
11
|
+
errors: [
|
|
12
|
+
{
|
|
13
|
+
message: 'Something went very wrong',
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
exports.ErrorHandler = ErrorHandler;
|
|
19
|
+
//# sourceMappingURL=error-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handler.js","sourceRoot":"","sources":["../../src/middleware/error-handler.ts"],"names":[],"mappings":";;;AACA,2DAAsD;AAE/C,MAAM,YAAY,GAAG,CAC1B,GAAU,EACV,GAAY,EACZ,GAAa,EACb,IAAkB,EAClB,EAAE;IACF,IAAI,GAAG,YAAY,2BAAW,EAAE,CAAC;QAC/B,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;IAC3E,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAEjB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;QACnB,MAAM,EAAE;YACN;gBACE,OAAO,EAAE,2BAA2B;aACrC;SACF;KACF,CAAC,CAAC;AACL,CAAC,CAAC;AAlBW,QAAA,YAAY,GAAZ,YAAY,CAkBvB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RequireAuth = void 0;
|
|
4
|
+
const not_authorized_errors_1 = require("../errors/not-authorized-errors");
|
|
5
|
+
const RequireAuth = (req, res, next) => {
|
|
6
|
+
if (!req.user || !req.user.verified) {
|
|
7
|
+
throw new not_authorized_errors_1.NotAuthorizedError();
|
|
8
|
+
}
|
|
9
|
+
next();
|
|
10
|
+
};
|
|
11
|
+
exports.RequireAuth = RequireAuth;
|
|
12
|
+
//# sourceMappingURL=require-auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"require-auth.js","sourceRoot":"","sources":["../../src/middleware/require-auth.ts"],"names":[],"mappings":";;;AACA,2EAAqE;AAE9D,MAAM,WAAW,GAAG,CACzB,GAAY,EACZ,GAAa,EACb,IAAkB,EAClB,EAAE;IACF,IAAI,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACpC,MAAM,IAAI,0CAAkB,EAAE,CAAC;IACjC,CAAC;IACD,IAAI,EAAE,CAAC;AACT,CAAC,CAAC;AATW,QAAA,WAAW,GAAX,WAAW,CAStB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValidateRequest = ValidateRequest;
|
|
4
|
+
const express_validator_1 = require("express-validator");
|
|
5
|
+
const request_validation_error_1 = require("../errors/request-validation-error");
|
|
6
|
+
function 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
|
+
//# sourceMappingURL=validate-request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-request.js","sourceRoot":"","sources":["../../src/middleware/validate-request.ts"],"names":[],"mappings":";;;AACA,yDAAqD;AACrD,iFAA4E;AAE5E,yBACE,GAAY,EACZ,GAAa,EACb,IAAkB;IAElB,MAAM,MAAM,GAAG,IAAA,oCAAgB,EAAC,GAAG,CAAC,CAAC;IAErC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;QACtB,MAAM,IAAI,iDAAsB,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IACnD,CAAC;IACD,IAAI,EAAE,CAAC;AACT,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bloggie/library",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "",
|
|
5
|
-
"main": "index.js",
|
|
5
|
+
"main": "./build/index.js",
|
|
6
|
+
"types": "./build/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"build/**/*"
|
|
9
|
+
],
|
|
6
10
|
"scripts": {
|
|
7
|
-
"
|
|
11
|
+
"clean": "del-cli ./build/*",
|
|
12
|
+
"build": "npm run clean && tsc",
|
|
13
|
+
"pub": "git add . && git commit -m \"Updates\" && npm version patch && npm run build && npm publish "
|
|
8
14
|
},
|
|
9
15
|
"keywords": [],
|
|
10
16
|
"type": "commonjs",
|
|
@@ -19,5 +25,8 @@
|
|
|
19
25
|
"node-nats-streaming": "^0.3.2",
|
|
20
26
|
"ts-node-dev": "^2.0.0",
|
|
21
27
|
"typescript": "^7.0.2"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"del-cli": "^7.0.0"
|
|
22
31
|
}
|
|
23
32
|
}
|
package/index.ts
DELETED
|
File without changes
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { Message, Stan } from 'node-nats-streaming';
|
|
2
|
-
import { Subjects } from './subjects';
|
|
3
|
-
|
|
4
|
-
interface Events {
|
|
5
|
-
subject: Subjects;
|
|
6
|
-
data: any;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export abstract class Listener<T extends Events> {
|
|
10
|
-
abstract subject: T['subject'];
|
|
11
|
-
private client: Stan;
|
|
12
|
-
readonly ackWait = 5 * 60; // 5 mins
|
|
13
|
-
abstract onMessage(data: T['data'], msg: Message): void;
|
|
14
|
-
abstract queueGroupName: string;
|
|
15
|
-
|
|
16
|
-
constructor(client: Stan) {
|
|
17
|
-
this.client = client;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
subscriptionOptions() {
|
|
21
|
-
return this.client
|
|
22
|
-
.subscriptionOptions()
|
|
23
|
-
.setDeliverAllAvailable()
|
|
24
|
-
.setManualAckMode(true)
|
|
25
|
-
.setDurableName(this.queueGroupName)
|
|
26
|
-
.setAckWait(this.ackWait);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
listen() {
|
|
30
|
-
const subscriptions = this.client.subscribe(
|
|
31
|
-
this.subject,
|
|
32
|
-
this.queueGroupName,
|
|
33
|
-
this.subscriptionOptions(),
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
subscriptions.on('message', (msg: Message) => {
|
|
37
|
-
console.log(`Message received: ${this.subject}/${this.queueGroupName}`);
|
|
38
|
-
const parsedData = this.parsedData(msg);
|
|
39
|
-
|
|
40
|
-
this.onMessage(parsedData, msg);
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
parsedData(msg: Message) {
|
|
45
|
-
const data = msg.getData();
|
|
46
|
-
|
|
47
|
-
return typeof data === 'string'
|
|
48
|
-
? JSON.parse(data)
|
|
49
|
-
: JSON.parse(data.toString('utf-8'));
|
|
50
|
-
}
|
|
51
|
-
}
|
package/src/events/subjects.ts
DELETED
package/tsconfig.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// tsconfig.json
|
|
2
|
-
{
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"rootDir": "./src",
|
|
5
|
-
"outDir": "./build",
|
|
6
|
-
"module": "nodenext",
|
|
7
|
-
"moduleResolution": "nodenext",
|
|
8
|
-
"target": "es2020",
|
|
9
|
-
"esModuleInterop": true,
|
|
10
|
-
"strict": true,
|
|
11
|
-
"skipLibCheck": true,
|
|
12
|
-
"sourceMap": true,
|
|
13
|
-
"declaration": true,
|
|
14
|
-
"moduleDetection": "force",
|
|
15
|
-
"isolatedModules": true,
|
|
16
|
-
"types": ["node"]
|
|
17
|
-
},
|
|
18
|
-
"include": ["src/**/*"],
|
|
19
|
-
"exclude": ["node_modules", "build"]
|
|
20
|
-
}
|