@otters.ai/common-backend 1.0.4 → 1.0.6
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/enum/index.d.ts +2 -0
- package/build/enum/index.js +18 -0
- package/build/enum/subjects.d.ts +4 -0
- package/build/enum/subjects.js +8 -0
- package/build/events/base-listener.d.ts +18 -0
- package/build/events/base-listener.js +32 -0
- package/build/events/base-publisher.d.ts +13 -0
- package/build/events/base-publisher.js +20 -0
- package/build/events/index.d.ts +2 -0
- package/build/events/index.js +18 -0
- package/build/index.d.ts +3 -1
- package/build/index.js +3 -1
- package/build/interface/index.d.ts +1 -0
- package/build/interface/index.js +17 -0
- package/build/interface/loginLogCreatedStruct.d.ts +9 -0
- package/build/interface/loginLogCreatedStruct.js +2 -0
- package/build/interface/loginLogUpdatedStruct.d.ts +9 -0
- package/build/interface/loginLogUpdatedStruct.js +2 -0
- package/package.json +6 -3
|
@@ -0,0 +1,18 @@
|
|
|
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("./subjects"), exports);
|
|
18
|
+
__exportStar(require("./currency"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Subjects = void 0;
|
|
4
|
+
var Subjects;
|
|
5
|
+
(function (Subjects) {
|
|
6
|
+
Subjects["LoginLogCreated"] = "loginLog:created";
|
|
7
|
+
Subjects["LoginLogUpdated"] = "loginLog:updated";
|
|
8
|
+
})(Subjects || (exports.Subjects = Subjects = {}));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Message, Stan } from 'node-nats-streaming';
|
|
2
|
+
import { Subjects } from "../enum";
|
|
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 {};
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
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);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
parseMessage(msg) {
|
|
26
|
+
const data = msg.getData();
|
|
27
|
+
return typeof data === 'string'
|
|
28
|
+
? JSON.parse(data)
|
|
29
|
+
: JSON.parse(data.toString('utf8'));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.Listener = Listener;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Stan } from 'node-nats-streaming';
|
|
2
|
+
import { Subjects } from "../enum";
|
|
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 {};
|
|
@@ -0,0 +1,20 @@
|
|
|
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;
|
|
@@ -0,0 +1,18 @@
|
|
|
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("./base-listener"), exports);
|
|
18
|
+
__exportStar(require("./base-publisher"), exports);
|
package/build/index.d.ts
CHANGED
package/build/index.js
CHANGED
|
@@ -14,4 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./enum
|
|
17
|
+
__exportStar(require("./enum"), exports);
|
|
18
|
+
__exportStar(require("./events"), exports);
|
|
19
|
+
__exportStar(require("./interface"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './loginLogCreatedStruct';
|
|
@@ -0,0 +1,17 @@
|
|
|
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("./loginLogCreatedStruct"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@otters.ai/common-backend",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -17,8 +17,11 @@
|
|
|
17
17
|
"license": "ISC",
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@types/node": "^22.7.0",
|
|
20
|
+
"del-cli": "^5.0.0",
|
|
20
21
|
"ts-node": "^10.9.2",
|
|
21
|
-
"typescript": "^5.6.2"
|
|
22
|
-
|
|
22
|
+
"typescript": "^5.6.2"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"node-nats-streaming": "^0.3.2"
|
|
23
26
|
}
|
|
24
27
|
}
|