@prodact.ai/sdk 0.0.7 → 0.0.8

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/react.js CHANGED
@@ -103,7 +103,8 @@ var DEFAULT_CAPTURE_CONFIG = {
103
103
  };
104
104
  function mergeConfig(userConfig) {
105
105
  return {
106
- enabled: userConfig?.enabled ?? false,
106
+ enabled: userConfig?.enabled ?? true,
107
+ // Enabled by default!
107
108
  samplingRate: userConfig?.samplingRate ?? 1,
108
109
  privacy: { ...DEFAULT_PRIVACY_CONFIG, ...userConfig?.privacy },
109
110
  performance: { ...DEFAULT_PERFORMANCE_CONFIG, ...userConfig?.performance },
@@ -1115,7 +1116,8 @@ async function captureElementScreenshot(element, maxSize = 200) {
1115
1116
  }
1116
1117
  function mergeConfig2(config) {
1117
1118
  const defaults = {
1118
- enabled: false,
1119
+ enabled: true,
1120
+ // Enabled by default!
1119
1121
  samplingRate: 1,
1120
1122
  events: {
1121
1123
  clicks: true,
@@ -1586,16 +1588,25 @@ var UserFlowTracker = class {
1586
1588
  // Link to rrweb recording session if available
1587
1589
  linkedRecordingSessionId: this.linkedRecordingSessionId
1588
1590
  };
1589
- const response = await fetch(endpoint, {
1590
- method: "POST",
1591
- headers: {
1592
- "Content-Type": "application/json",
1593
- ...this.sdkKey ? { "X-SDK-Key": this.sdkKey } : {}
1594
- },
1595
- body: JSON.stringify(body)
1596
- });
1597
- if (!response.ok) {
1598
- throw new Error(`Failed to start session: ${response.status}`);
1591
+ try {
1592
+ const response = await fetch(endpoint, {
1593
+ method: "POST",
1594
+ headers: {
1595
+ "Content-Type": "application/json",
1596
+ ...this.sdkKey ? { "X-SDK-Key": this.sdkKey } : {}
1597
+ },
1598
+ body: JSON.stringify(body)
1599
+ });
1600
+ if (!response.ok) {
1601
+ console.error("[UserFlow] Failed to start session:", response.status, response.statusText);
1602
+ console.error("[UserFlow] Endpoint:", endpoint);
1603
+ throw new Error(`Failed to start session: ${response.status}`);
1604
+ }
1605
+ console.log("[UserFlow] Session started successfully:", this.sessionId);
1606
+ } catch (error) {
1607
+ console.error("[UserFlow] Network error starting session:", error);
1608
+ console.error("[UserFlow] Attempted endpoint:", endpoint);
1609
+ throw error;
1599
1610
  }
1600
1611
  }
1601
1612
  /**
@@ -1624,9 +1635,15 @@ var UserFlowTracker = class {
1624
1635
  });
1625
1636
  if (response.ok) {
1626
1637
  this.batchesSent++;
1638
+ console.log(`[UserFlow] Event batch ${this.batchIndex - 1} sent (${eventsToSend.length} events)`);
1639
+ } else {
1640
+ console.error("[UserFlow] Failed to send event batch:", response.status, response.statusText);
1641
+ console.error("[UserFlow] Endpoint:", endpoint);
1642
+ this.events = [...eventsToSend, ...this.events];
1627
1643
  }
1628
1644
  } catch (error) {
1629
- console.error("[UserFlow] Failed to send event batch:", error);
1645
+ console.error("[UserFlow] Network error sending event batch:", error);
1646
+ console.error("[UserFlow] Endpoint:", endpoint);
1630
1647
  this.events = [...eventsToSend, ...this.events];
1631
1648
  }
1632
1649
  }
@@ -1744,9 +1761,32 @@ var ProduckSDK = class {
1744
1761
  /** User flow tracker instance (optional, isolated module) */
1745
1762
  this.userFlowTracker = null;
1746
1763
  let apiUrl = config.apiUrl;
1764
+ let apiUrlAutoDetected = false;
1747
1765
  if (!apiUrl) {
1766
+ apiUrlAutoDetected = true;
1748
1767
  if (typeof window !== "undefined") {
1749
- apiUrl = window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1" ? "http://localhost:4001/api/v1" : `${window.location.protocol}//${window.location.host}/api/v1`;
1768
+ const isLocalhost = window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1";
1769
+ if (isLocalhost) {
1770
+ apiUrl = "http://localhost:4001/api/v1";
1771
+ } else {
1772
+ apiUrl = `${window.location.protocol}//${window.location.host}/api/v1`;
1773
+ console.warn(
1774
+ "%c\u26A0\uFE0F Produck SDK Warning: apiUrl not configured!",
1775
+ "background: #fbbf24; color: #000; padding: 4px 8px; font-weight: bold;"
1776
+ );
1777
+ console.warn(
1778
+ `The SDK is auto-detecting apiUrl as: ${apiUrl}
1779
+ This is likely WRONG for production. Your backend is probably at a different URL.
1780
+
1781
+ To fix this, provide apiUrl in your SDK config:
1782
+
1783
+ createProduck({
1784
+ sdkKey: 'your_sdk_key',
1785
+ apiUrl: 'https://your-backend.com/api/v1', // <-- Add this!
1786
+ })
1787
+ `
1788
+ );
1789
+ }
1750
1790
  } else {
1751
1791
  apiUrl = "http://localhost:4001/api/v1";
1752
1792
  }
@@ -1755,11 +1795,30 @@ var ProduckSDK = class {
1755
1795
  apiUrl,
1756
1796
  ...config
1757
1797
  };
1798
+ if (typeof window !== "undefined") {
1799
+ console.log(
1800
+ "%c\u{1F527} Produck SDK Config",
1801
+ "background: #3b82f6; color: #fff; padding: 2px 6px; border-radius: 3px;",
1802
+ {
1803
+ apiUrl: this.config.apiUrl,
1804
+ apiUrlAutoDetected,
1805
+ sdkKey: this.config.sdkKey ? `${this.config.sdkKey.substring(0, 10)}...` : "not set",
1806
+ guiderId: this.config.guiderId || "not set"
1807
+ }
1808
+ );
1809
+ }
1758
1810
  }
1759
1811
  /**
1760
1812
  * Initialize the SDK and create a chat session
1761
1813
  */
1762
1814
  async init() {
1815
+ if (typeof window !== "undefined") {
1816
+ console.log(
1817
+ "%c\u{1F680} Produck SDK Initializing...",
1818
+ "background: #10b981; color: #fff; padding: 2px 6px; border-radius: 3px;",
1819
+ { endpoint: this.config.apiUrl }
1820
+ );
1821
+ }
1763
1822
  await this.log("info", "SDK Initializing", {
1764
1823
  apiUrl: this.config.apiUrl,
1765
1824
  hasSDKKey: !!this.config.sdkKey,
@@ -1786,20 +1845,43 @@ var ProduckSDK = class {
1786
1845
  headers
1787
1846
  });
1788
1847
  if (!response.ok) {
1789
- await this.log("error", "Failed to create session", { status: response.status });
1848
+ let errorDetail = "";
1849
+ try {
1850
+ errorDetail = await response.text();
1851
+ } catch {
1852
+ errorDetail = "Could not read response body";
1853
+ }
1854
+ console.error(
1855
+ "%c\u274C Produck SDK: Failed to create session",
1856
+ "background: #ef4444; color: #fff; padding: 2px 6px; border-radius: 3px;"
1857
+ );
1858
+ console.error(`Status: ${response.status} ${response.statusText}`);
1859
+ console.error(`Endpoint: ${endpoint}`);
1860
+ console.error(`Response: ${errorDetail}`);
1861
+ if (response.status === 404) {
1862
+ console.error(
1863
+ `
1864
+ \u{1F4A1} Tip: A 404 error usually means the apiUrl is wrong.
1865
+ Current apiUrl: ${this.config.apiUrl}
1866
+ Make sure your backend is running and the URL is correct.`
1867
+ );
1868
+ }
1869
+ await this.log("error", "Failed to create session", { status: response.status, errorDetail });
1790
1870
  throw new Error(`Failed to create session: ${response.status}`);
1791
1871
  }
1792
1872
  const session = await response.json();
1793
1873
  this.sessionToken = session.session_token;
1794
1874
  this.isReady = true;
1795
1875
  await this.log("info", "SDK initialized successfully", { hasSessionToken: !!this.sessionToken });
1796
- if (this.config.recording?.enabled) {
1876
+ const recordingEnabled = this.config.recording?.enabled !== false;
1877
+ if (recordingEnabled) {
1797
1878
  await this.initRecording();
1798
1879
  }
1799
1880
  if (this.config.proactive?.enabled) {
1800
1881
  this.initProactive();
1801
1882
  }
1802
- if (this.config.userFlows?.enabled) {
1883
+ const userFlowsEnabled = this.config.userFlows?.enabled !== false;
1884
+ if (userFlowsEnabled) {
1803
1885
  await this.initUserFlowTracking();
1804
1886
  }
1805
1887
  this.emit("ready", { sessionToken: this.sessionToken });
@@ -1807,7 +1889,27 @@ var ProduckSDK = class {
1807
1889
  await this.sendInitialMessage();
1808
1890
  }
1809
1891
  } catch (error) {
1810
- await this.log("error", "SDK initialization failed", { error: error instanceof Error ? error.message : String(error) });
1892
+ const errorMessage = error instanceof Error ? error.message : String(error);
1893
+ const isNetworkError = errorMessage.includes("fetch") || errorMessage.includes("network") || errorMessage.includes("Failed to fetch") || errorMessage.includes("NetworkError");
1894
+ console.error(
1895
+ "%c\u274C Produck SDK initialization failed",
1896
+ "background: #ef4444; color: #fff; padding: 4px 8px; font-weight: bold;"
1897
+ );
1898
+ console.error(`Error: ${errorMessage}`);
1899
+ console.error(`API URL: ${this.config.apiUrl}`);
1900
+ if (isNetworkError) {
1901
+ console.error(
1902
+ `
1903
+ \u{1F4A1} This looks like a network error. Common causes:
1904
+ 1. The apiUrl is incorrect or the backend is not running
1905
+ 2. CORS is blocking the request
1906
+ 3. The backend server is unreachable
1907
+
1908
+ Current apiUrl: ${this.config.apiUrl}
1909
+ Check the Network tab in DevTools for more details.`
1910
+ );
1911
+ }
1912
+ await this.log("error", "SDK initialization failed", { error: errorMessage });
1811
1913
  this.emit("error", error);
1812
1914
  throw error;
1813
1915
  }