obi-sdk 0.4.3 → 0.5.0

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 { O as ObiWidget } from "./chunks/obi-widget-ad91b91a.js";
1
+ import { O as ObiWidget } from "./chunks/obi-widget-3bb30929.js";
2
2
  import "./chunks/types-e0297e7b.js";
3
3
  const DEBUG_BUILD$2 = typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__;
4
4
  const SDK_VERSION = "9.23.0";
@@ -5749,7 +5749,7 @@ async function retryOperation(operation, operationName, maxAttempts = RETRY_CONF
5749
5749
  return await operation();
5750
5750
  } catch (error) {
5751
5751
  lastError = error;
5752
- console.warn(`${operationName} failed (attempt ${attempt + 1}/${maxAttempts}):`, error);
5752
+ console.warn(`[obi-sdk] ${operationName} failed (attempt ${attempt + 1}/${maxAttempts}):`, error);
5753
5753
  if (attempt < maxAttempts - 1) {
5754
5754
  const delayMs = getRetryDelay(attempt);
5755
5755
  await delay(delayMs);
@@ -5760,8 +5760,9 @@ async function retryOperation(operation, operationName, maxAttempts = RETRY_CONF
5760
5760
  }
5761
5761
  function mountSDK() {
5762
5762
  const w = window;
5763
+ let q = [];
5763
5764
  if (typeof w.ObiSDK === "function" || typeof w.ObiSDK === "object") {
5764
- return;
5765
+ q = w.ObiSDK.q || [];
5765
5766
  }
5766
5767
  w.ObiSDK = function(command, config) {
5767
5768
  if (command === "update" && config) {
@@ -5769,9 +5770,19 @@ function mountSDK() {
5769
5770
  ...w.obiWidgetConfig,
5770
5771
  ...config
5771
5772
  };
5773
+ const widgets = document.querySelectorAll("obi-widget");
5774
+ widgets.forEach((widget) => {
5775
+ widget.dispatchEvent(
5776
+ new CustomEvent("obi-config-updated", {
5777
+ detail: config,
5778
+ bubbles: true,
5779
+ composed: true
5780
+ })
5781
+ );
5782
+ });
5772
5783
  }
5773
5784
  };
5774
- w.ObiSDK.q = [];
5785
+ w.ObiSDK.q = q;
5775
5786
  }
5776
5787
  async function mountWidget() {
5777
5788
  return retryOperation(async () => {
@@ -5783,20 +5794,14 @@ async function mountWidget() {
5783
5794
  }
5784
5795
  const widget = document.createElement("obi-widget");
5785
5796
  document.body.appendChild(widget);
5786
- console.log("Obi Widget mounted");
5787
- }, "Widget mounting");
5797
+ console.log("[obi-sdk] widget mounted");
5798
+ }, "widget mounting");
5788
5799
  }
5789
5800
  function processQueue() {
5790
5801
  const w = window;
5791
5802
  if (w.ObiSDK && Array.isArray(w.ObiSDK.q)) {
5792
- w.ObiSDK.q.forEach((args) => {
5793
- const [command, config] = args;
5794
- if (command === "update" && config) {
5795
- w.obiWidgetConfig = {
5796
- ...w.obiWidgetConfig,
5797
- ...config
5798
- };
5799
- }
5803
+ (w.ObiSDK.q || []).forEach((args) => {
5804
+ w.ObiSDK(...args);
5800
5805
  });
5801
5806
  w.ObiSDK.q = [];
5802
5807
  }
@@ -5811,57 +5816,37 @@ async function loadFont(fontUrl) {
5811
5816
  throw new Error("document.head not available");
5812
5817
  }
5813
5818
  const link = document.createElement("link");
5814
- document.head.querySelectorAll("link[data-obi-font]").forEach((node) => node.remove());
5815
- link.setAttribute("data-obi-font", "true");
5816
5819
  link.href = fontUrl;
5817
5820
  link.rel = "stylesheet";
5818
- return new Promise((resolve, reject) => {
5819
- const timeout = setTimeout(() => {
5820
- reject(new Error("Font loading timeout"));
5821
- }, 5e3);
5822
- link.onload = () => {
5823
- clearTimeout(timeout);
5824
- resolve();
5825
- };
5826
- link.onerror = () => {
5827
- clearTimeout(timeout);
5828
- reject(new Error("Font loading failed"));
5829
- };
5830
- document.head.appendChild(link);
5831
- });
5832
- }, "Font loading");
5821
+ document.head.appendChild(link);
5822
+ }, "font loading");
5833
5823
  }
5834
5824
  async function safeInitialize() {
5835
- try {
5836
- mountSDK();
5837
- await loadFonts();
5838
- await mountWidget();
5839
- processQueue();
5840
- console.log("Obi Widget initialized successfully");
5841
- } catch (error) {
5842
- console.error("Obi Widget initialization failed:", error);
5843
- try {
5844
- mountSDK();
5845
- processQueue();
5846
- console.log("Obi Widget fallback initialization completed");
5847
- } catch (fallbackError) {
5848
- console.error("Obi Widget fallback initialization failed:", fallbackError);
5849
- }
5850
- }
5825
+ await new Promise((resolve) => setTimeout(resolve, 500));
5826
+ mountSDK();
5827
+ await loadFonts();
5828
+ await mountWidget();
5829
+ processQueue();
5851
5830
  }
5852
- function initializeObiWidget() {
5831
+ async function initializeObiWidget() {
5853
5832
  if (document.readyState === "loading") {
5854
- document.addEventListener("DOMContentLoaded", () => {
5855
- safeInitialize();
5833
+ document.addEventListener("DOMContentLoaded", async () => {
5834
+ try {
5835
+ await safeInitialize();
5836
+ } catch (error) {
5837
+ captureException(error);
5838
+ console.error("[obi-sdk] initialization failed:", error);
5839
+ }
5856
5840
  });
5857
5841
  } else {
5858
- safeInitialize();
5842
+ await safeInitialize();
5859
5843
  }
5860
5844
  }
5861
5845
  try {
5862
5846
  initializeObiWidget();
5863
5847
  } catch (error) {
5864
5848
  captureException(error);
5849
+ console.error("[obi-sdk] initialization failed:", error);
5865
5850
  }
5866
5851
  export {
5867
5852
  ObiWidget