@heritageai/messaging 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.
@@ -1,4 +1,4 @@
1
- import nats from 'node-nats-streaming';
1
+ import nats from "node-nats-streaming";
2
2
  declare class NatsWrapper {
3
3
  private _client?;
4
4
  get client(): nats.Stan;
@@ -8,7 +8,7 @@ const node_nats_streaming_1 = __importDefault(require("node-nats-streaming"));
8
8
  class NatsWrapper {
9
9
  get client() {
10
10
  if (!this._client) {
11
- throw new Error('Cannot access NATS client before connecting');
11
+ throw new Error("Cannot access NATS client before connecting");
12
12
  }
13
13
  return this._client;
14
14
  }
@@ -18,13 +18,15 @@ class NatsWrapper {
18
18
  console.log(`🔌 Connecting to NATS (${remaining} retries left)...`);
19
19
  this._client = node_nats_streaming_1.default.connect(clusterId, clientId, { url });
20
20
  // @ts-ignore
21
- this._client.on('connect', () => {
22
- console.log('✅ Connected to NATS');
21
+ this._client.on("connect", () => {
22
+ console.log("✅ Connected to NATS");
23
23
  resolve();
24
24
  });
25
25
  // @ts-ignore
26
- this._client.on('error', (err) => {
27
- console.error('❌ NATS connection error:', err.message);
26
+ this._client.on("error", (err) => {
27
+ console.error("❌ NATS connection error:", err.message);
28
+ this._client?.close();
29
+ this._client = undefined;
28
30
  if (remaining <= 0) {
29
31
  reject(err);
30
32
  return;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "future_platform",
3
3
  "name": "@heritageai/messaging",
4
4
  "license": "ISC",
5
- "version": "1.0.3",
5
+ "version": "1.0.4",
6
6
  "description": "",
7
7
  "main": "dist/index.js",
8
8
  "types": "dist/index.d.ts",
@@ -1,11 +1,11 @@
1
- import nats, { Stan } from 'node-nats-streaming';
1
+ import nats, { Stan } from "node-nats-streaming";
2
2
 
3
3
  class NatsWrapper {
4
4
  private _client?: Stan;
5
5
 
6
6
  get client() {
7
7
  if (!this._client) {
8
- throw new Error('Cannot access NATS client before connecting');
8
+ throw new Error("Cannot access NATS client before connecting");
9
9
  }
10
10
  return this._client;
11
11
  }
@@ -15,7 +15,7 @@ class NatsWrapper {
15
15
  clientId: string,
16
16
  url: string,
17
17
  retries = 5,
18
- delayMs = 3000
18
+ delayMs = 3000,
19
19
  ): Promise<void> {
20
20
  return new Promise((resolve, reject) => {
21
21
  const attempt = (remaining: number) => {
@@ -24,14 +24,17 @@ class NatsWrapper {
24
24
  this._client = nats.connect(clusterId, clientId, { url });
25
25
 
26
26
  // @ts-ignore
27
- this._client.on('connect', () => {
28
- console.log('✅ Connected to NATS');
27
+ this._client.on("connect", () => {
28
+ console.log("✅ Connected to NATS");
29
29
  resolve();
30
30
  });
31
31
 
32
32
  // @ts-ignore
33
- this._client.on('error', (err) => {
34
- console.error('❌ NATS connection error:', err.message);
33
+ this._client.on("error", (err) => {
34
+ console.error("❌ NATS connection error:", err.message);
35
+
36
+ this._client?.close();
37
+ this._client = undefined;
35
38
 
36
39
  if (remaining <= 0) {
37
40
  reject(err);