@bolt.tech/kafka-utils 1.0.1 → 1.0.3
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/index.d.ts +0 -2
- package/build/index.js +7 -7
- package/build/kafkaServer.js +3 -1
- package/build/store/schemas/proto/assetTriggersNotification.proto +30 -0
- package/build/store/schemas/proto/boltNotification.proto +23 -0
- package/build/store/schemas/proto/commonNotification.proto +36 -0
- package/build/utils/kafka/brokers.kafka.js +1 -1
- package/build/utils/schemaRegistry/pickSchema.js +1 -1
- package/package.json +2 -2
package/build/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
import { notificationType } from './store/types/notification.type';
|
|
2
|
-
declare let notificationType: notificationType;
|
|
3
2
|
export declare function initialiseNotification(paramStorePath: "dev" | "prod", nodeEnvLocal: "TRUE" | "FALSE", serviceName: string, notificationType: notificationType): Promise<void>;
|
|
4
3
|
export declare function sendNotification(userId: string, message: any): Promise<void>;
|
|
5
|
-
export {};
|
package/build/index.js
CHANGED
|
@@ -12,15 +12,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.initialiseNotification = initialiseNotification;
|
|
13
13
|
exports.sendNotification = sendNotification;
|
|
14
14
|
const getTopic = require('./utils/kafka/topicMap.kafka');
|
|
15
|
-
let
|
|
15
|
+
let currentNotificationType;
|
|
16
16
|
function initialiseNotification(paramStorePath, nodeEnvLocal, serviceName, notificationType) {
|
|
17
17
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
18
|
try {
|
|
19
|
-
|
|
19
|
+
currentNotificationType = notificationType;
|
|
20
20
|
const KafkaServer = require('./kafkaServer');
|
|
21
21
|
const kafkaInstance = new KafkaServer();
|
|
22
22
|
yield kafkaInstance.setupKafka(paramStorePath, nodeEnvLocal, serviceName, notificationType);
|
|
23
|
-
|
|
23
|
+
yield kafkaInstance.setupShutdownHandlers();
|
|
24
24
|
console.log("---------------------------------------------");
|
|
25
25
|
console.log("Notification utility is ready.");
|
|
26
26
|
console.log("---------------------------------------------");
|
|
@@ -30,17 +30,17 @@ function initialiseNotification(paramStorePath, nodeEnvLocal, serviceName, notif
|
|
|
30
30
|
}
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
|
-
const
|
|
33
|
+
const notificationSchema_registry_1 = require("./utils/schemaRegistry/notificationSchema.registry");
|
|
34
34
|
const publishToKafka = require('./utils/kafka/publisher.kafka');
|
|
35
35
|
function sendNotification(userId, message) {
|
|
36
36
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
37
|
try {
|
|
38
|
-
if (!
|
|
38
|
+
if (!notificationSchema_registry_1.NotificationSchema) {
|
|
39
39
|
throw new Error("Notification schema is not initialised");
|
|
40
40
|
}
|
|
41
|
-
const topic = getTopic(
|
|
41
|
+
const topic = getTopic(currentNotificationType);
|
|
42
42
|
let key = userId;
|
|
43
|
-
const instance = NotificationSchema.getInstance();
|
|
43
|
+
const instance = notificationSchema_registry_1.NotificationSchema.getInstance();
|
|
44
44
|
const schemaId = yield instance.getSchemaId();
|
|
45
45
|
yield publishToKafka(topic, schemaId, { key, value: message });
|
|
46
46
|
}
|
package/build/kafkaServer.js
CHANGED
|
@@ -47,7 +47,9 @@ class KafkaServer {
|
|
|
47
47
|
this.notificationSchema = null;
|
|
48
48
|
this.handleShutdown = () => __awaiter(this, void 0, void 0, function* () {
|
|
49
49
|
console.log('Shutting down Kafka Server...');
|
|
50
|
-
|
|
50
|
+
if (producer_kafka_1.KafkaProducer) {
|
|
51
|
+
yield producer_kafka_1.KafkaProducer.shutdown();
|
|
52
|
+
}
|
|
51
53
|
process.exit(0);
|
|
52
54
|
});
|
|
53
55
|
dotenv.config();
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
|
|
3
|
+
message AssetsTriggerNotification {
|
|
4
|
+
optional User user = 1;
|
|
5
|
+
optional Message message = 2;
|
|
6
|
+
optional string appId = 3;
|
|
7
|
+
optional SmsObj smsObj = 4;
|
|
8
|
+
optional OneSignalPayload oneSignalPayload = 6;
|
|
9
|
+
|
|
10
|
+
message User {
|
|
11
|
+
optional string inAppNotificationUserId = 1;
|
|
12
|
+
optional string pushNotificationUserId = 2;
|
|
13
|
+
repeated string emailIds = 3;
|
|
14
|
+
repeated string phoneNumbers = 4;
|
|
15
|
+
}
|
|
16
|
+
message Message {
|
|
17
|
+
optional string body = 1;
|
|
18
|
+
optional string subject = 2;
|
|
19
|
+
optional int32 priority = 3;
|
|
20
|
+
}
|
|
21
|
+
message SmsObj {
|
|
22
|
+
optional string smsType = 1;
|
|
23
|
+
optional string templateId = 2;
|
|
24
|
+
}
|
|
25
|
+
message OneSignalPayload {
|
|
26
|
+
optional string alert = 1;
|
|
27
|
+
optional bool sos = 2;
|
|
28
|
+
optional string vin = 3;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
|
|
3
|
+
message BoltNotification {
|
|
4
|
+
optional User user = 1;
|
|
5
|
+
optional Message message = 2;
|
|
6
|
+
optional string appId = 4;
|
|
7
|
+
optional SmsObj smsObj = 5;
|
|
8
|
+
|
|
9
|
+
message User {
|
|
10
|
+
optional string pushNotificationUserId = 3;
|
|
11
|
+
optional string inAppNotificationUserId = 4;
|
|
12
|
+
repeated string phoneNumbers = 5;
|
|
13
|
+
repeated string emailIds = 6;
|
|
14
|
+
}
|
|
15
|
+
message Message {
|
|
16
|
+
optional string body = 1;
|
|
17
|
+
optional string subject = 2;
|
|
18
|
+
}
|
|
19
|
+
message SmsObj {
|
|
20
|
+
optional string smsType = 1;
|
|
21
|
+
optional string templateId = 2;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
|
|
3
|
+
message Notification {
|
|
4
|
+
message User {
|
|
5
|
+
string inAppNotificationUserId = 1;
|
|
6
|
+
string pushNotificationUserId = 2;
|
|
7
|
+
repeated string emailIds = 3;
|
|
8
|
+
repeated string phoneNumbers = 4;
|
|
9
|
+
}
|
|
10
|
+
message Message {
|
|
11
|
+
string body = 1;
|
|
12
|
+
string subject = 2;
|
|
13
|
+
int32 priority = 3;
|
|
14
|
+
repeated bytes attachments = 4;
|
|
15
|
+
string html = 5;
|
|
16
|
+
}
|
|
17
|
+
message SmsObj {
|
|
18
|
+
string smsType = 1;
|
|
19
|
+
string templateId = 2;
|
|
20
|
+
}
|
|
21
|
+
message OneSignalPayload {
|
|
22
|
+
string alert = 1;
|
|
23
|
+
bool sos = 2;
|
|
24
|
+
string vin = 3;
|
|
25
|
+
}
|
|
26
|
+
message Attachment {
|
|
27
|
+
string filename = 1;
|
|
28
|
+
string filetype = 2;
|
|
29
|
+
bytes content = 3;
|
|
30
|
+
}
|
|
31
|
+
User user = 1;
|
|
32
|
+
Message message = 2;
|
|
33
|
+
string appId = 3;
|
|
34
|
+
SmsObj smsObj = 4;
|
|
35
|
+
OneSignalPayload oneSignalPayload = 6;
|
|
36
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bolt.tech/kafka-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
],
|
|
10
10
|
"scripts": {
|
|
11
11
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
12
|
-
"build": "rm -rf ./build/ && tsc",
|
|
12
|
+
"build": "rm -rf ./build/ && tsc && cp -R ./src/store/schemas ./build/store/schemas",
|
|
13
13
|
"pub": "rm -rf build/ && npm run build && npm publish --access=public"
|
|
14
14
|
},
|
|
15
15
|
"keywords": [],
|