@aichatwar/shared 1.0.86 → 1.0.88

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.
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Listener = void 0;
13
- // Updated event to base event
13
+ // Updated event to base
14
14
  class Listener {
15
15
  constructor(kafka) {
16
16
  this.kafka = kafka;
@@ -1,15 +1,8 @@
1
- import { Kafka, Producer } from "kafkajs";
1
+ import { Producer } from "kafkajs";
2
2
  import { BaseEvent } from '../baseEvent';
3
3
  export declare abstract class Publisher<T extends BaseEvent> {
4
4
  abstract topic: T['subject'];
5
5
  protected producer: Producer;
6
- constructor(kafka: Kafka);
7
- /**
8
- * Connect this producer once, typically during service startup
9
- */
10
- connect(): Promise<void>;
11
- /**
12
- * Publish an event to Kafka with retry-on-disconnect logic
13
- */
6
+ constructor(producer: Producer);
14
7
  publish(data: T['data']): Promise<void>;
15
8
  }
@@ -11,47 +11,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Publisher = void 0;
13
13
  class Publisher {
14
- constructor(kafka) {
15
- // Each Publisher gets its own producer from injected Kafka instance
16
- this.producer = kafka.producer();
14
+ constructor(producer) {
15
+ this.producer = producer;
17
16
  }
18
- /**
19
- * Connect this producer once, typically during service startup
20
- */
21
- connect() {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- if (!this.producer)
24
- throw new Error('Producer not initialized');
25
- yield this.producer.connect();
26
- console.log(`✅ Kafka Producer connected for topic "${this.topic}"`);
27
- });
28
- }
29
- /**
30
- * Publish an event to Kafka with retry-on-disconnect logic
31
- */
32
17
  publish(data) {
33
18
  return __awaiter(this, void 0, void 0, function* () {
19
+ if (!this.producer)
20
+ throw new Error('Producer not defined');
34
21
  try {
35
22
  yield this.producer.send({
36
23
  topic: this.topic,
37
24
  messages: [{ value: JSON.stringify(data) }],
38
25
  });
39
- console.log(`📤 Event published to "${this.topic}"`, data);
40
26
  }
41
27
  catch (err) {
42
- console.error(`❌ Failed to publish to ${this.topic}`, err);
43
- if (err.message.includes('not connected') || err.message.includes('disconnected')) {
44
- console.warn('⚠ Producer disconnected — retrying connection...');
45
- yield this.producer.connect();
46
- yield this.producer.send({
47
- topic: this.topic,
48
- messages: [{ value: JSON.stringify(data) }],
49
- });
50
- console.log(`📤 Event republished to "${this.topic}" after reconnect`);
51
- }
52
- else {
53
- throw err;
54
- }
28
+ console.error(`❌ Publish failed on first try for ${this.topic}`, err);
29
+ throw err;
55
30
  }
56
31
  });
57
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aichatwar/shared",
3
- "version": "1.0.86",
3
+ "version": "1.0.88",
4
4
  "main": "./build/index.js",
5
5
  "typs": "./build/index.d.ts",
6
6
  "files": [