@bolt.tech/kafka-utils 1.0.10 → 1.0.11
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.js +0 -15
- package/build/utils/kafka/publisher.kafka.js +0 -2
- package/package.json +1 -1
- package/build/app.d.ts +0 -14
- package/build/app.js +0 -63
package/build/index.js
CHANGED
|
@@ -19,10 +19,6 @@ let currentNotificationType;
|
|
|
19
19
|
function initialiseNotification(paramStorePath, nodeEnvLocal, serviceName, notificationType) {
|
|
20
20
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
21
|
try {
|
|
22
|
-
registry_util_1.SchemaRegistryS.connect(process.env.SCHEMA_REGISTRY_URL);
|
|
23
|
-
console.log('🔵 Connecting to Schema Registry...');
|
|
24
|
-
registry_util_1.SchemaRegistryS.getInstance();
|
|
25
|
-
console.log('✅ Schema Registry connected.');
|
|
26
22
|
currentNotificationType = notificationType;
|
|
27
23
|
const KafkaServer = require('./kafkaServer');
|
|
28
24
|
const kafkaInstance = new KafkaServer();
|
|
@@ -38,22 +34,11 @@ function initialiseNotification(paramStorePath, nodeEnvLocal, serviceName, notif
|
|
|
38
34
|
});
|
|
39
35
|
}
|
|
40
36
|
const notificationSchema_registry_1 = require("./utils/schemaRegistry/notificationSchema.registry");
|
|
41
|
-
const registry_util_1 = require("./utils/schemaRegistry/registry.util");
|
|
42
37
|
const publishToKafka = require('./utils/kafka/publisher.kafka');
|
|
43
|
-
/* initialize schema registry if not initialized */
|
|
44
|
-
function initSchemaRegistry() {
|
|
45
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
console.log('🔵 Connecting to Schema Registry...');
|
|
47
|
-
registry_util_1.SchemaRegistryS.connect(process.env.SCHEMA_REGISTRY_URL);
|
|
48
|
-
registry_util_1.SchemaRegistryS.getInstance();
|
|
49
|
-
console.log('✅ Schema Registry connected successfully.');
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
38
|
/* publish notifications to kafka */
|
|
53
39
|
function sendNotificationToKafka(userId, payload) {
|
|
54
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
55
41
|
try {
|
|
56
|
-
yield initSchemaRegistry();
|
|
57
42
|
const instance = notificationSchema_registry_1.NotificationSchema.getInstance();
|
|
58
43
|
if (!instance) {
|
|
59
44
|
throw new Error("Notification schema is not initialised or Schema Registry is not connected.");
|
|
@@ -14,8 +14,6 @@ const producer_kafka_1 = require("./producer.kafka");
|
|
|
14
14
|
function publishToKafka(topic, schemaId, message) {
|
|
15
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
16
|
try {
|
|
17
|
-
registry_util_1.SchemaRegistryS.connect(process.env.SCHEMA_REGISTRY_URL);
|
|
18
|
-
registry_util_1.SchemaRegistryS.getInstance();
|
|
19
17
|
const encodedMessage = yield registry_util_1.SchemaRegistryS.getInstance().encode(schemaId, message.value);
|
|
20
18
|
const payload = { topic, messages: [{ key: message.key, value: encodedMessage }] };
|
|
21
19
|
const producer = yield producer_kafka_1.KafkaProducer.getProducer();
|
package/package.json
CHANGED
package/build/app.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
declare const initialiseNotification: any, sendSmsNotifications: 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
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
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, sendSmsNotifications } = 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 sendSmsNotifications(notificationMessage.user, notificationMessage.message, notificationMessage.smsObj);
|
|
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
|
-
})();
|