@antonymarshal23/common 3.0.0 → 3.2.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/events/base-listener.d.ts +9 -8
- package/build/events/base-listener.js +17 -20
- package/build/events/base-publisher.d.ts +6 -6
- package/build/events/base-publisher.js +6 -7
- package/build/events/user-created-event.d.ts +8 -0
- package/build/events/user-created-event.js +2 -0
- package/build/events/user-deleted-event.d.ts +7 -0
- package/build/events/user-deleted-event.js +2 -0
- package/build/events/user-subjects.d.ts +5 -0
- package/build/events/user-subjects.js +9 -0
- package/build/events/user-updated-event.d.ts +8 -0
- package/build/events/user-updated-event.js +2 -0
- package/build/index.d.ts +24 -20
- package/build/index.js +4 -0
- package/build/middlewares/require-auth.d.ts +1 -1
- package/package.json +2 -3
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Subjects } from
|
|
1
|
+
import { Message, Stan } from 'node-nats-streaming';
|
|
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: Message): void;
|
|
11
|
+
protected client: Stan;
|
|
12
12
|
protected ackWait: number;
|
|
13
|
-
constructor(client:
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
constructor(client: Stan);
|
|
14
|
+
subscriptionOptions(): import("node-nats-streaming").SubscriptionOptions;
|
|
15
|
+
listen(): void;
|
|
16
|
+
parseMessage(msg: Message): any;
|
|
16
17
|
}
|
|
17
18
|
export {};
|
|
@@ -6,30 +6,27 @@ class Listener {
|
|
|
6
6
|
this.ackWait = 5 * 1000;
|
|
7
7
|
this.client = client;
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
+
const subscription = this.client.subscribe(this.subject, this.queueGroupName, this.subscriptionOptions());
|
|
19
|
+
subscription.on('message', (msg) => {
|
|
17
20
|
console.log(`Message received: ${this.subject} / ${this.queueGroupName}`);
|
|
18
|
-
|
|
19
|
-
|
|
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,
|
|
21
|
+
const parsedData = this.parseMessage(msg);
|
|
22
|
+
this.onMessage(parsedData, msg);
|
|
29
23
|
});
|
|
30
24
|
}
|
|
31
25
|
parseMessage(msg) {
|
|
32
|
-
|
|
26
|
+
const data = msg.getData();
|
|
27
|
+
return typeof data === 'string'
|
|
28
|
+
? JSON.parse(data)
|
|
29
|
+
: JSON.parse(data.toString('utf8'));
|
|
33
30
|
}
|
|
34
31
|
}
|
|
35
32
|
exports.Listener = Listener;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Subjects } from
|
|
1
|
+
import { Stan } from 'node-nats-streaming';
|
|
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: Stan;
|
|
10
|
+
constructor(client: Stan);
|
|
11
|
+
publish(data: T['data']): Promise<void>;
|
|
12
12
|
}
|
|
13
13
|
export {};
|
|
@@ -7,14 +7,13 @@ class Publisher {
|
|
|
7
7
|
}
|
|
8
8
|
publish(data) {
|
|
9
9
|
return new Promise((resolve, reject) => {
|
|
10
|
-
|
|
11
|
-
|
|
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();
|
|
12
16
|
});
|
|
13
|
-
if (!published) {
|
|
14
|
-
return reject(new Error("Message was not published"));
|
|
15
|
-
}
|
|
16
|
-
console.log("Event published to subject", this.subject);
|
|
17
|
-
resolve();
|
|
18
17
|
});
|
|
19
18
|
}
|
|
20
19
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UserSubjects = void 0;
|
|
4
|
+
var UserSubjects;
|
|
5
|
+
(function (UserSubjects) {
|
|
6
|
+
UserSubjects["UserCreated"] = "user:created";
|
|
7
|
+
UserSubjects["UserUpdated"] = "user:updated";
|
|
8
|
+
UserSubjects["UserDeleted"] = "user:deleted";
|
|
9
|
+
})(UserSubjects = exports.UserSubjects || (exports.UserSubjects = {}));
|
package/build/index.d.ts
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
10
|
-
export * from
|
|
11
|
-
export * from
|
|
12
|
-
export * from
|
|
13
|
-
export * from
|
|
14
|
-
export * from
|
|
15
|
-
export * from
|
|
16
|
-
export * from
|
|
17
|
-
export * from
|
|
18
|
-
export * from
|
|
19
|
-
export * from
|
|
20
|
-
export * from
|
|
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/ticket-created-event";
|
|
15
|
+
export * from "./events/ticket-updated-event";
|
|
16
|
+
export * from "./events/types/order-status";
|
|
17
|
+
export * from "./events/order-cancelled-event";
|
|
18
|
+
export * from "./events/order-created-event";
|
|
19
|
+
export * from "./events/expiration-complete-event";
|
|
20
|
+
export * from "./events/payment-created-event";
|
|
21
|
+
export * from "./events/user-subjects";
|
|
22
|
+
export * from "./events/user-created-event";
|
|
23
|
+
export * from "./events/user-updated-event";
|
|
24
|
+
export * from "./events/user-deleted-event";
|
package/build/index.js
CHANGED
|
@@ -35,3 +35,7 @@ __exportStar(require("./events/order-cancelled-event"), exports);
|
|
|
35
35
|
__exportStar(require("./events/order-created-event"), exports);
|
|
36
36
|
__exportStar(require("./events/expiration-complete-event"), exports);
|
|
37
37
|
__exportStar(require("./events/payment-created-event"), exports);
|
|
38
|
+
__exportStar(require("./events/user-subjects"), exports);
|
|
39
|
+
__exportStar(require("./events/user-created-event"), exports);
|
|
40
|
+
__exportStar(require("./events/user-updated-event"), exports);
|
|
41
|
+
__exportStar(require("./events/user-deleted-event"), exports);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Request, Response, NextFunction } from
|
|
1
|
+
import { Request, Response, NextFunction } from "express";
|
|
2
2
|
export declare const requireAuth: (req: Request, res: Response, next: NextFunction) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antonymarshal23/common",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -21,13 +21,12 @@
|
|
|
21
21
|
"typescript": "^4.9.5"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@antonymarshal23/common": "^2.0.0",
|
|
25
24
|
"@types/cookie-session": "^2.0.39",
|
|
26
25
|
"@types/express": "^4.17.5",
|
|
27
26
|
"@types/jsonwebtoken": "^8.3.9",
|
|
28
27
|
"amqplib": "^2.0.1",
|
|
29
28
|
"cookie-session": "^1.4.0",
|
|
30
|
-
"express": "^
|
|
29
|
+
"express": "^5.2.1",
|
|
31
30
|
"express-validator": "^6.4.0",
|
|
32
31
|
"jsonwebtoken": "^8.5.1",
|
|
33
32
|
"node-nats-streaming": "^0.2.6"
|