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