@kinotic-ai/core 5.0.0-beta.26 → 5.0.0-beta.28

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/dist/index.cjs CHANGED
@@ -194,14 +194,19 @@ class StompActivation {
194
194
  preparedSocket = null;
195
195
  attempt = null;
196
196
  failPending = null;
197
+ abortController = new AbortController;
197
198
  subscriptions = [];
198
199
  get ended() {
199
200
  return this._ended;
200
201
  }
202
+ get signal() {
203
+ return this.abortController.signal;
204
+ }
201
205
  end() {
202
206
  this._ended = true;
203
207
  this.wake?.();
204
208
  this.wake = null;
209
+ this.abortController.abort();
205
210
  }
206
211
  delay(ms) {
207
212
  return new Promise((resolve) => {
@@ -250,6 +255,7 @@ class StompConnectionManager {
250
255
  INITIAL_RECONNECT_DELAY = 2000;
251
256
  JITTER_MAX = 5000;
252
257
  MAX_RECONNECT_DELAY = 120000;
258
+ CONNECTION_TIMEOUT = 1e4;
253
259
  connectionAttempts = 0;
254
260
  debugLogger = import_debug2.default("kinotic:stomp");
255
261
  connectionEstablishedSubject = new import_rxjs.Subject;
@@ -327,6 +333,7 @@ class StompConnectionManager {
327
333
  },
328
334
  heartbeatIncoming: 30000,
329
335
  heartbeatOutgoing: 30000,
336
+ connectionTimeout: this.CONNECTION_TIMEOUT,
330
337
  reconnectDelay: this.INITIAL_RECONNECT_DELAY,
331
338
  maxReconnectDelay: this.MAX_RECONNECT_DELAY,
332
339
  reconnectTimeMode: import_stompjs.ReconnectionTimeMode.EXPONENTIAL,
@@ -347,9 +354,9 @@ class StompConnectionManager {
347
354
  activation.own(this.rxStomp.webSocketErrors$.subscribe((value) => {
348
355
  this.lastWebsocketError = value;
349
356
  }));
350
- activation.own(this.rxStomp.stompErrors$.subscribe(async (frame) => {
357
+ activation.own(this.rxStomp.stompErrors$.subscribe((frame) => {
351
358
  const stompError = new Error(frame.headers["message"], { cause: frame });
352
- await this.failConnection(activation, new Error("STOMP connection error", { cause: stompError }));
359
+ this.failConnection(activation, new Error("STOMP connection error", { cause: stompError }));
353
360
  }));
354
361
  activation.own(this.rxStomp.connected$.subscribe(() => {
355
362
  activation.established();
@@ -357,19 +364,19 @@ class StompConnectionManager {
357
364
  this.connectionAttempts = 0;
358
365
  }));
359
366
  activation.pending(reject);
360
- activation.own(this.rxStomp.serverHeaders$.pipe(import_operators.skip(this.rxStompHasConnected ? 1 : 0)).subscribe(async (value) => {
367
+ activation.own(this.rxStomp.serverHeaders$.pipe(import_operators.skip(this.rxStompHasConnected ? 1 : 0)).subscribe((value) => {
361
368
  this.rxStompHasConnected = true;
362
369
  const connectedInfoJson = value["connected-info" /* CONNECTED_INFO_HEADER */];
363
370
  if (connectedInfoJson == null) {
364
371
  if (!this.initialConnectionSuccessful) {
365
- await this.deactivate(undefined, new Error("Server did not return proper data for successful login"));
372
+ this.failConnection(activation, new Error("Server did not return proper data for successful login"));
366
373
  }
367
374
  return;
368
375
  }
369
376
  const connectedInfo = JSON.parse(connectedInfoJson);
370
377
  if (connectedInfo.replyToId == null) {
371
378
  if (!this.initialConnectionSuccessful) {
372
- await this.deactivate(undefined, new Error("Server did not return a replyToId for successful login"));
379
+ this.failConnection(activation, new Error("Server did not return a replyToId for successful login"));
373
380
  }
374
381
  return;
375
382
  }
@@ -407,9 +414,12 @@ class StompConnectionManager {
407
414
  if (!usesPreparedSocket) {
408
415
  const sessionCheckUrl = buildServerUrl(server, "http") + SESSION_CHECK_PATH;
409
416
  try {
410
- const res = await fetch(sessionCheckUrl, { credentials: "include" });
417
+ const res = await fetch(sessionCheckUrl, {
418
+ credentials: "include",
419
+ signal: AbortSignal.any([activation.signal, AbortSignal.timeout(this.CONNECTION_TIMEOUT)])
420
+ });
411
421
  if (res.status === 401) {
412
- await this.failConnection(activation, new Error("Authentication required"));
422
+ this.failConnection(activation, new Error("Authentication required"));
413
423
  return;
414
424
  }
415
425
  } catch (e) {
@@ -427,19 +437,19 @@ class StompConnectionManager {
427
437
  try {
428
438
  activation.preparedSocket = await userWebSocketFactory();
429
439
  } catch (e) {
430
- await this.failConnection(activation, new Error("WebSocket factory failed", { cause: e }));
440
+ this.failConnection(activation, new Error("WebSocket factory failed", { cause: e }));
431
441
  }
432
442
  } else if (headerAuth) {
433
443
  try {
434
444
  const resolved = await credentialsResolver.resolve(server);
435
445
  if (resolved?.authHeaders == null) {
436
- await this.failConnection(activation, new Error("Credentials resolver no longer supplies auth headers: " + credentialsResolver.name));
446
+ this.failConnection(activation, new Error("Credentials resolver no longer supplies auth headers: " + credentialsResolver.name));
437
447
  } else {
438
448
  const WS = WebSocket;
439
449
  activation.preparedSocket = new WS(url, { headers: resolved.authHeaders });
440
450
  }
441
451
  } catch (e) {
442
- await this.failConnection(activation, new Error("Credential resolution failed", { cause: e }));
452
+ this.failConnection(activation, new Error("Credential resolution failed", { cause: e }));
443
453
  }
444
454
  }
445
455
  if (activation.ended && activation.preparedSocket) {
@@ -479,10 +489,10 @@ class StompConnectionManager {
479
489
  await activation.delay(randomJitter);
480
490
  }
481
491
  }
482
- async failConnection(activation, err) {
492
+ failConnection(activation, err) {
483
493
  if (!activation.ended) {
484
494
  this.debugLogger("Connection failed, ending it: %O", err);
485
- await this.deactivate(undefined, err);
495
+ this.deactivate(undefined, err).catch((e) => this.debugLogger("Closing the failed connection failed: %O", e));
486
496
  }
487
497
  }
488
498
  }
@@ -1304,7 +1314,7 @@ var import_api2 = __toESM(require("@opentelemetry/api"), 1);
1304
1314
  // packages/core/package.json
1305
1315
  var package_default = {
1306
1316
  name: "@kinotic-ai/core",
1307
- version: "5.0.0-beta.26",
1317
+ version: "5.0.0-beta.28",
1308
1318
  type: "module",
1309
1319
  files: [
1310
1320
  "dist"
package/dist/index.d.cts CHANGED
@@ -238,7 +238,8 @@ interface IEventBus {
238
238
  connectionEstablished: Observable<ConnectedInfo>;
239
239
  /**
240
240
  * Emits each time an attempt to connect fails before the server accepts the connection and the client
241
- * will try again: the server could not be reached, or it closed the socket before answering. This
241
+ * will try again: the server could not be reached, it closed the socket before answering, or it had not
242
+ * answered within 10 seconds of the socket being opened. This
242
243
  * covers the attempts of a pending {@link connect} as well as the reconnects after a connection ends.
243
244
  * An attempt that ends the connection for good is reported by {@link connectionEnded} instead.
244
245
  */
package/dist/index.d.ts CHANGED
@@ -238,7 +238,8 @@ interface IEventBus {
238
238
  connectionEstablished: Observable<ConnectedInfo>;
239
239
  /**
240
240
  * Emits each time an attempt to connect fails before the server accepts the connection and the client
241
- * will try again: the server could not be reached, or it closed the socket before answering. This
241
+ * will try again: the server could not be reached, it closed the socket before answering, or it had not
242
+ * answered within 10 seconds of the socket being opened. This
242
243
  * covers the attempts of a pending {@link connect} as well as the reconnects after a connection ends.
243
244
  * An attempt that ends the connection for good is reported by {@link connectionEnded} instead.
244
245
  */
package/dist/index.js CHANGED
@@ -75,14 +75,19 @@ class StompActivation {
75
75
  preparedSocket = null;
76
76
  attempt = null;
77
77
  failPending = null;
78
+ abortController = new AbortController;
78
79
  subscriptions = [];
79
80
  get ended() {
80
81
  return this._ended;
81
82
  }
83
+ get signal() {
84
+ return this.abortController.signal;
85
+ }
82
86
  end() {
83
87
  this._ended = true;
84
88
  this.wake?.();
85
89
  this.wake = null;
90
+ this.abortController.abort();
86
91
  }
87
92
  delay(ms) {
88
93
  return new Promise((resolve) => {
@@ -131,6 +136,7 @@ class StompConnectionManager {
131
136
  INITIAL_RECONNECT_DELAY = 2000;
132
137
  JITTER_MAX = 5000;
133
138
  MAX_RECONNECT_DELAY = 120000;
139
+ CONNECTION_TIMEOUT = 1e4;
134
140
  connectionAttempts = 0;
135
141
  debugLogger = debug2("kinotic:stomp");
136
142
  connectionEstablishedSubject = new Subject;
@@ -208,6 +214,7 @@ class StompConnectionManager {
208
214
  },
209
215
  heartbeatIncoming: 30000,
210
216
  heartbeatOutgoing: 30000,
217
+ connectionTimeout: this.CONNECTION_TIMEOUT,
211
218
  reconnectDelay: this.INITIAL_RECONNECT_DELAY,
212
219
  maxReconnectDelay: this.MAX_RECONNECT_DELAY,
213
220
  reconnectTimeMode: ReconnectionTimeMode.EXPONENTIAL,
@@ -228,9 +235,9 @@ class StompConnectionManager {
228
235
  activation.own(this.rxStomp.webSocketErrors$.subscribe((value) => {
229
236
  this.lastWebsocketError = value;
230
237
  }));
231
- activation.own(this.rxStomp.stompErrors$.subscribe(async (frame) => {
238
+ activation.own(this.rxStomp.stompErrors$.subscribe((frame) => {
232
239
  const stompError = new Error(frame.headers["message"], { cause: frame });
233
- await this.failConnection(activation, new Error("STOMP connection error", { cause: stompError }));
240
+ this.failConnection(activation, new Error("STOMP connection error", { cause: stompError }));
234
241
  }));
235
242
  activation.own(this.rxStomp.connected$.subscribe(() => {
236
243
  activation.established();
@@ -238,19 +245,19 @@ class StompConnectionManager {
238
245
  this.connectionAttempts = 0;
239
246
  }));
240
247
  activation.pending(reject);
241
- activation.own(this.rxStomp.serverHeaders$.pipe(skip(this.rxStompHasConnected ? 1 : 0)).subscribe(async (value) => {
248
+ activation.own(this.rxStomp.serverHeaders$.pipe(skip(this.rxStompHasConnected ? 1 : 0)).subscribe((value) => {
242
249
  this.rxStompHasConnected = true;
243
250
  const connectedInfoJson = value["connected-info" /* CONNECTED_INFO_HEADER */];
244
251
  if (connectedInfoJson == null) {
245
252
  if (!this.initialConnectionSuccessful) {
246
- await this.deactivate(undefined, new Error("Server did not return proper data for successful login"));
253
+ this.failConnection(activation, new Error("Server did not return proper data for successful login"));
247
254
  }
248
255
  return;
249
256
  }
250
257
  const connectedInfo = JSON.parse(connectedInfoJson);
251
258
  if (connectedInfo.replyToId == null) {
252
259
  if (!this.initialConnectionSuccessful) {
253
- await this.deactivate(undefined, new Error("Server did not return a replyToId for successful login"));
260
+ this.failConnection(activation, new Error("Server did not return a replyToId for successful login"));
254
261
  }
255
262
  return;
256
263
  }
@@ -288,9 +295,12 @@ class StompConnectionManager {
288
295
  if (!usesPreparedSocket) {
289
296
  const sessionCheckUrl = buildServerUrl(server, "http") + SESSION_CHECK_PATH;
290
297
  try {
291
- const res = await fetch(sessionCheckUrl, { credentials: "include" });
298
+ const res = await fetch(sessionCheckUrl, {
299
+ credentials: "include",
300
+ signal: AbortSignal.any([activation.signal, AbortSignal.timeout(this.CONNECTION_TIMEOUT)])
301
+ });
292
302
  if (res.status === 401) {
293
- await this.failConnection(activation, new Error("Authentication required"));
303
+ this.failConnection(activation, new Error("Authentication required"));
294
304
  return;
295
305
  }
296
306
  } catch (e) {
@@ -308,19 +318,19 @@ class StompConnectionManager {
308
318
  try {
309
319
  activation.preparedSocket = await userWebSocketFactory();
310
320
  } catch (e) {
311
- await this.failConnection(activation, new Error("WebSocket factory failed", { cause: e }));
321
+ this.failConnection(activation, new Error("WebSocket factory failed", { cause: e }));
312
322
  }
313
323
  } else if (headerAuth) {
314
324
  try {
315
325
  const resolved = await credentialsResolver.resolve(server);
316
326
  if (resolved?.authHeaders == null) {
317
- await this.failConnection(activation, new Error("Credentials resolver no longer supplies auth headers: " + credentialsResolver.name));
327
+ this.failConnection(activation, new Error("Credentials resolver no longer supplies auth headers: " + credentialsResolver.name));
318
328
  } else {
319
329
  const WS = WebSocket;
320
330
  activation.preparedSocket = new WS(url, { headers: resolved.authHeaders });
321
331
  }
322
332
  } catch (e) {
323
- await this.failConnection(activation, new Error("Credential resolution failed", { cause: e }));
333
+ this.failConnection(activation, new Error("Credential resolution failed", { cause: e }));
324
334
  }
325
335
  }
326
336
  if (activation.ended && activation.preparedSocket) {
@@ -360,10 +370,10 @@ class StompConnectionManager {
360
370
  await activation.delay(randomJitter);
361
371
  }
362
372
  }
363
- async failConnection(activation, err) {
373
+ failConnection(activation, err) {
364
374
  if (!activation.ended) {
365
375
  this.debugLogger("Connection failed, ending it: %O", err);
366
- await this.deactivate(undefined, err);
376
+ this.deactivate(undefined, err).catch((e) => this.debugLogger("Closing the failed connection failed: %O", e));
367
377
  }
368
378
  }
369
379
  }
@@ -1185,7 +1195,7 @@ import opentelemetry, { context as context2, propagation as propagation2, trace,
1185
1195
  // packages/core/package.json
1186
1196
  var package_default = {
1187
1197
  name: "@kinotic-ai/core",
1188
- version: "5.0.0-beta.26",
1198
+ version: "5.0.0-beta.28",
1189
1199
  type: "module",
1190
1200
  files: [
1191
1201
  "dist"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kinotic-ai/core",
3
- "version": "5.0.0-beta.26",
3
+ "version": "5.0.0-beta.28",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"