@bolt.tech/kafka-utils 1.0.2 → 1.0.4
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/app.d.ts +14 -0
- package/build/app.js +63 -0
- package/build/index.js +8 -1
- package/build/kafkaServer.js +2 -0
- 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/schemaRegistry/registry.util.d.ts +1 -0
- package/build/utils/schemaRegistry/registry.util.js +3 -0
- package/package.json +2 -2
package/build/app.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare const initialiseNotification: any, sendNotification: any;
|
|
2
|
+
declare const KafkaServer: any;
|
|
3
|
+
declare const notificationMessage: {
|
|
4
|
+
user: {
|
|
5
|
+
phoneNumbers: string[];
|
|
6
|
+
};
|
|
7
|
+
message: {
|
|
8
|
+
body: string;
|
|
9
|
+
};
|
|
10
|
+
smsObj: {
|
|
11
|
+
smsType: string;
|
|
12
|
+
templateId: string;
|
|
13
|
+
};
|
|
14
|
+
};
|
package/build/app.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
const { initialiseNotification, sendNotification } = require('./index');
|
|
11
|
+
const KafkaServer = require('./kafkaServer');
|
|
12
|
+
// Example notification message
|
|
13
|
+
const notificationMessage = {
|
|
14
|
+
user: {
|
|
15
|
+
// inAppNotificationUserId: '66222b43527f81ea8e2f0ea3',
|
|
16
|
+
// pushNotificationUserId: '66222b43527f81ea8e2f0ea3',
|
|
17
|
+
//emailIds: ["monakundnani113@gmail.com"],
|
|
18
|
+
phoneNumbers: ["+917850855689"],
|
|
19
|
+
},
|
|
20
|
+
message: {
|
|
21
|
+
body: "Dear Bolt.Earth Host, We have updated our Bank settlement cycle to a Weekly basis. These changes will be effective from September 6th, 2024 and you'll now receive settlements for bookings made on your charger on a weekly basis. Have Questions? Email us at support@bolt.earth"
|
|
22
|
+
//subject: 'Test',
|
|
23
|
+
// priority: 1,
|
|
24
|
+
// attachments: [],
|
|
25
|
+
// html: '<h1>This is a test message</h1>'
|
|
26
|
+
},
|
|
27
|
+
// appId: 'e5feb55e-ac98-4a16-a5d6-3675c3edb591',
|
|
28
|
+
smsObj: {
|
|
29
|
+
smsType: 'MKT',
|
|
30
|
+
templateId: '1307172536061229921'
|
|
31
|
+
}
|
|
32
|
+
// oneSignalPayload: {
|
|
33
|
+
// alert: 'This is a test message',
|
|
34
|
+
// sos: false,
|
|
35
|
+
// vin: '123'
|
|
36
|
+
// },
|
|
37
|
+
// Attachment: {
|
|
38
|
+
// filename: 'test.txt',
|
|
39
|
+
// filetype: 'text/plain',
|
|
40
|
+
// content: new Uint8Array([1, 2, 3, 4])
|
|
41
|
+
// }
|
|
42
|
+
};
|
|
43
|
+
(function testKafkaUtils() {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
try {
|
|
46
|
+
console.log('🟡 Initialising Kafka Notification Utility...');
|
|
47
|
+
// Step 1: Initialise the notification system
|
|
48
|
+
yield initialiseNotification("dev", "TRUE", "common", "common");
|
|
49
|
+
console.log('🟢 Kafka Notification Utility Initialised.');
|
|
50
|
+
// Step 2: Send a notification
|
|
51
|
+
console.log('🟡 Sending Notification...');
|
|
52
|
+
yield sendNotification(notificationMessage.user.phoneNumbers[0], notificationMessage);
|
|
53
|
+
console.log('🟢 Notification Sent Successfully.');
|
|
54
|
+
// Clean up (if any shutdown handling or disconnect required)
|
|
55
|
+
const kafkaServerInstance = new KafkaServer();
|
|
56
|
+
kafkaServerInstance.handleShutdown();
|
|
57
|
+
console.log('🟢 Test Completed Successfully.');
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
console.error('🔴 Test Error:', error);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
})();
|
package/build/index.js
CHANGED
|
@@ -31,16 +31,23 @@ function initialiseNotification(paramStorePath, nodeEnvLocal, serviceName, notif
|
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
const notificationSchema_registry_1 = require("./utils/schemaRegistry/notificationSchema.registry");
|
|
34
|
+
const registry_util_1 = require("./utils/schemaRegistry/registry.util");
|
|
34
35
|
const publishToKafka = require('./utils/kafka/publisher.kafka');
|
|
35
36
|
function sendNotification(userId, message) {
|
|
36
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
38
|
try {
|
|
39
|
+
const instance = notificationSchema_registry_1.NotificationSchema.getInstance();
|
|
40
|
+
if (!instance) {
|
|
41
|
+
throw new Error("Notification schema is not initialised or Schema Registry is not connected.");
|
|
42
|
+
}
|
|
43
|
+
if (!registry_util_1.SchemaRegistryS.isConnected()) {
|
|
44
|
+
yield registry_util_1.SchemaRegistryS.connect(process.env.SCHEMA_REGISTRY_URL);
|
|
45
|
+
}
|
|
38
46
|
if (!notificationSchema_registry_1.NotificationSchema) {
|
|
39
47
|
throw new Error("Notification schema is not initialised");
|
|
40
48
|
}
|
|
41
49
|
const topic = getTopic(currentNotificationType);
|
|
42
50
|
let key = userId;
|
|
43
|
-
const instance = notificationSchema_registry_1.NotificationSchema.getInstance();
|
|
44
51
|
const schemaId = yield instance.getSchemaId();
|
|
45
52
|
yield publishToKafka(topic, schemaId, { key, value: message });
|
|
46
53
|
}
|
package/build/kafkaServer.js
CHANGED
|
@@ -67,6 +67,8 @@ class KafkaServer {
|
|
|
67
67
|
// Connect to Schema Registry
|
|
68
68
|
registry_util_1.SchemaRegistryS.connect(process.env.SCHEMA_REGISTRY_URL);
|
|
69
69
|
this.schemaRegistry = registry_util_1.SchemaRegistryS.getInstance();
|
|
70
|
+
console.log(`Schema url:- ${process.env.SCHEMA_REGISTRY_URL}`);
|
|
71
|
+
console.log(this.schemaRegistry = registry_util_1.SchemaRegistryS.getInstance());
|
|
70
72
|
// Register Notification schema
|
|
71
73
|
this.notificationSchema = notificationSchema_registry_1.NotificationSchema.getInstance();
|
|
72
74
|
yield this.notificationSchema.register(notificationType);
|
|
@@ -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.4",
|
|
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": [],
|