@bolt.tech/kafka-utils 1.0.3 → 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 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
  }
@@ -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);
@@ -5,4 +5,5 @@ export declare class SchemaRegistryS extends SchemaRegistry {
5
5
  static connect(url: string): void;
6
6
  static getInstance(): SchemaRegistryS;
7
7
  getRegistry(url: string): SchemaRegistryS;
8
+ static isConnected(): boolean;
8
9
  }
@@ -17,5 +17,8 @@ class SchemaRegistryS extends confluent_schema_registry_1.SchemaRegistry {
17
17
  getRegistry(url) {
18
18
  return SchemaRegistryS.instance;
19
19
  }
20
+ static isConnected() {
21
+ return !!this.instance;
22
+ }
20
23
  }
21
24
  exports.SchemaRegistryS = SchemaRegistryS;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bolt.tech/kafka-utils",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",