@xpert-ai/chatkit-ui5 0.18.0 → 0.18.1

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.js CHANGED
@@ -270,10 +270,12 @@ class HttpError extends Error {
270
270
  super(message);
271
271
  __publicField(this, "status");
272
272
  __publicField(this, "statusText");
273
+ __publicField(this, "retryAfterMs");
273
274
  __publicField(this, "metadata");
274
275
  this.name = "HttpError";
275
276
  this.statusText = res.statusText;
276
277
  this.status = res.status;
278
+ this.retryAfterMs = res.retryAfterMs;
277
279
  this.metadata = metadata;
278
280
  }
279
281
  static fromPossibleFrameSafeError(error) {
@@ -286,7 +288,8 @@ class HttpError extends Error {
286
288
  safeError.message,
287
289
  {
288
290
  status: safeError.status,
289
- statusText: safeError.statusText
291
+ statusText: safeError.statusText,
292
+ retryAfterMs: safeError.retryAfterMs
290
293
  },
291
294
  safeError.metadata
292
295
  );
@@ -304,11 +307,13 @@ const _FrameSafeHttpError = class _FrameSafeHttpError {
304
307
  __publicField(this, "stack");
305
308
  __publicField(this, "status");
306
309
  __publicField(this, "statusText");
310
+ __publicField(this, "retryAfterMs");
307
311
  __publicField(this, "metadata");
308
312
  this.message = message;
309
313
  this.stack = new Error(message).stack;
310
314
  this.status = res.status;
311
315
  this.statusText = res.statusText;
316
+ this.retryAfterMs = res.retryAfterMs;
312
317
  this.metadata = metadata;
313
318
  }
314
319
  static fromHttpError(error) {
@@ -316,7 +321,8 @@ const _FrameSafeHttpError = class _FrameSafeHttpError {
316
321
  error.message,
317
322
  {
318
323
  status: error.status,
319
- statusText: error.statusText
324
+ statusText: error.statusText,
325
+ retryAfterMs: error.retryAfterMs
320
326
  },
321
327
  error.metadata
322
328
  );
@@ -438,19 +444,42 @@ class FrameSafeIntegrationError {
438
444
  }
439
445
  }
440
446
  function serializeFrameError(error) {
447
+ if (error instanceof HttpError || error instanceof FrameSafeHttpError) {
448
+ try {
449
+ return structuredClone(
450
+ error instanceof HttpError ? FrameSafeHttpError.fromHttpError(error) : error
451
+ );
452
+ } catch {
453
+ }
454
+ }
455
+ if (error && typeof error === "object" && "status" in error && typeof error.status === "number") {
456
+ const message = "message" in error && typeof error.message === "string" ? error.message : "ChatKit host request failed";
457
+ return new FrameSafeHttpError(message, {
458
+ status: error.status,
459
+ statusText: "statusText" in error && typeof error.statusText === "string" ? error.statusText : void 0,
460
+ retryAfterMs: readRetryAfterMs(error)
461
+ });
462
+ }
441
463
  try {
442
464
  return structuredClone(error);
443
465
  } catch {
444
466
  const message = error && typeof error === "object" && "message" in error && typeof error.message === "string" ? error.message : "ChatKit host request failed";
445
- if (error && typeof error === "object" && "status" in error && typeof error.status === "number") {
446
- return new FrameSafeHttpError(message, {
447
- status: error.status,
448
- statusText: "statusText" in error && typeof error.statusText === "string" ? error.statusText : void 0
449
- });
450
- }
451
467
  return new Error(message);
452
468
  }
453
469
  }
470
+ function readRetryAfterMs(error) {
471
+ if ("retryAfterMs" in error && typeof error.retryAfterMs === "number" && Number.isFinite(error.retryAfterMs)) {
472
+ return Math.max(0, error.retryAfterMs);
473
+ }
474
+ if (!("headers" in error) || !error.headers || typeof error.headers !== "object")
475
+ return;
476
+ const headers = error.headers;
477
+ if (!("get" in headers) || typeof headers.get !== "function") return;
478
+ const value = headers.get("Retry-After");
479
+ if (typeof value !== "string" || !value.trim()) return;
480
+ const duration = /^\d+(\.\d+)?$/.test(value.trim()) ? Number(value) * 1e3 : Date.parse(value) - Date.now();
481
+ return Number.isFinite(duration) ? Math.max(0, duration) : void 0;
482
+ }
454
483
  class BaseMessenger {
455
484
  constructor({
456
485
  handlers,