@endge/utils 0.24.4 → 0.24.5

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.d.ts CHANGED
@@ -824,7 +824,7 @@ export declare interface SSEManagerOptions {
824
824
  url: string;
825
825
  retryInterval?: number;
826
826
  headers?: Record<string, string>;
827
- getToken?: () => string | undefined;
827
+ getToken?: () => string | undefined | Promise<string | undefined>;
828
828
  onEvent: (data: any) => void;
829
829
  onError?: (error: Error) => void;
830
830
  onOpen?: () => void;
package/dist/utils.js CHANGED
@@ -1443,9 +1443,9 @@ class Ne {
1443
1443
  _clearReconnect() {
1444
1444
  this._reconnectTimeout && (clearTimeout(this._reconnectTimeout), this._reconnectTimeout = null);
1445
1445
  }
1446
- _buildHeaders() {
1446
+ async _buildHeaders() {
1447
1447
  var n, i;
1448
- const t = { ...this._options.headers }, e = (i = (n = this._options).getToken) == null ? void 0 : i.call(n);
1448
+ const t = { ...this._options.headers }, e = await ((i = (n = this._options).getToken) == null ? void 0 : i.call(n));
1449
1449
  return e && (t.Authorization = `Bearer ${e}`), t;
1450
1450
  }
1451
1451
  async _connect() {
@@ -1453,7 +1453,7 @@ class Ne {
1453
1453
  try {
1454
1454
  await W(this._url, {
1455
1455
  method: "GET",
1456
- headers: this._buildHeaders(),
1456
+ headers: await this._buildHeaders(),
1457
1457
  signal: (t = this._abortController) == null ? void 0 : t.signal,
1458
1458
  openWhenHidden: !0,
1459
1459
  onopen: (i) => {
@@ -1481,7 +1481,8 @@ class Ne {
1481
1481
  }
1482
1482
  });
1483
1483
  } catch (i) {
1484
- console.error("[SSEManager] Fatal error", i), this._isConnected = !1, (n = (e = this._options).onError) == null || n.call(e, i instanceof Error ? i : new Error(String(i))), this._scheduleReconnect();
1484
+ const s = i instanceof Error ? i : new Error(String(i));
1485
+ console.error("[SSEManager] Fatal error:", s.message), this._isConnected = !1, (n = (e = this._options).onError) == null || n.call(e, s), this._scheduleReconnect();
1485
1486
  }
1486
1487
  }
1487
1488
  get isConnected() {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@endge/utils",
3
3
  "private": false,
4
- "version": "0.24.4",
4
+ "version": "0.24.5",
5
5
  "type": "module",
6
6
  "module": "./dist/utils.js",
7
7
  "types": "./dist/index.d.ts",