@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/react.mjs
CHANGED
|
@@ -59,7 +59,8 @@ var DEFAULT_CAPTURE_CONFIG = {
|
|
|
59
59
|
};
|
|
60
60
|
function mergeConfig(userConfig) {
|
|
61
61
|
return {
|
|
62
|
-
enabled: userConfig?.enabled ??
|
|
62
|
+
enabled: userConfig?.enabled ?? true,
|
|
63
|
+
// Enabled by default!
|
|
63
64
|
samplingRate: userConfig?.samplingRate ?? 1,
|
|
64
65
|
privacy: { ...DEFAULT_PRIVACY_CONFIG, ...userConfig?.privacy },
|
|
65
66
|
performance: { ...DEFAULT_PERFORMANCE_CONFIG, ...userConfig?.performance },
|
|
@@ -1071,7 +1072,8 @@ async function captureElementScreenshot(element, maxSize = 200) {
|
|
|
1071
1072
|
}
|
|
1072
1073
|
function mergeConfig2(config) {
|
|
1073
1074
|
const defaults = {
|
|
1074
|
-
enabled:
|
|
1075
|
+
enabled: true,
|
|
1076
|
+
// Enabled by default!
|
|
1075
1077
|
samplingRate: 1,
|
|
1076
1078
|
events: {
|
|
1077
1079
|
clicks: true,
|
|
@@ -1542,16 +1544,25 @@ var UserFlowTracker = class {
|
|
|
1542
1544
|
// Link to rrweb recording session if available
|
|
1543
1545
|
linkedRecordingSessionId: this.linkedRecordingSessionId
|
|
1544
1546
|
};
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1547
|
+
try {
|
|
1548
|
+
const response = await fetch(endpoint, {
|
|
1549
|
+
method: "POST",
|
|
1550
|
+
headers: {
|
|
1551
|
+
"Content-Type": "application/json",
|
|
1552
|
+
...this.sdkKey ? { "X-SDK-Key": this.sdkKey } : {}
|
|
1553
|
+
},
|
|
1554
|
+
body: JSON.stringify(body)
|
|
1555
|
+
});
|
|
1556
|
+
if (!response.ok) {
|
|
1557
|
+
console.error("[UserFlow] Failed to start session:", response.status, response.statusText);
|
|
1558
|
+
console.error("[UserFlow] Endpoint:", endpoint);
|
|
1559
|
+
throw new Error(`Failed to start session: ${response.status}`);
|
|
1560
|
+
}
|
|
1561
|
+
console.log("[UserFlow] Session started successfully:", this.sessionId);
|
|
1562
|
+
} catch (error) {
|
|
1563
|
+
console.error("[UserFlow] Network error starting session:", error);
|
|
1564
|
+
console.error("[UserFlow] Attempted endpoint:", endpoint);
|
|
1565
|
+
throw error;
|
|
1555
1566
|
}
|
|
1556
1567
|
}
|
|
1557
1568
|
/**
|
|
@@ -1580,9 +1591,15 @@ var UserFlowTracker = class {
|
|
|
1580
1591
|
});
|
|
1581
1592
|
if (response.ok) {
|
|
1582
1593
|
this.batchesSent++;
|
|
1594
|
+
console.log(`[UserFlow] Event batch ${this.batchIndex - 1} sent (${eventsToSend.length} events)`);
|
|
1595
|
+
} else {
|
|
1596
|
+
console.error("[UserFlow] Failed to send event batch:", response.status, response.statusText);
|
|
1597
|
+
console.error("[UserFlow] Endpoint:", endpoint);
|
|
1598
|
+
this.events = [...eventsToSend, ...this.events];
|
|
1583
1599
|
}
|
|
1584
1600
|
} catch (error) {
|
|
1585
|
-
console.error("[UserFlow]
|
|
1601
|
+
console.error("[UserFlow] Network error sending event batch:", error);
|
|
1602
|
+
console.error("[UserFlow] Endpoint:", endpoint);
|
|
1586
1603
|
this.events = [...eventsToSend, ...this.events];
|
|
1587
1604
|
}
|
|
1588
1605
|
}
|
|
@@ -1700,9 +1717,32 @@ var ProduckSDK = class {
|
|
|
1700
1717
|
/** User flow tracker instance (optional, isolated module) */
|
|
1701
1718
|
this.userFlowTracker = null;
|
|
1702
1719
|
let apiUrl = config.apiUrl;
|
|
1720
|
+
let apiUrlAutoDetected = false;
|
|
1703
1721
|
if (!apiUrl) {
|
|
1722
|
+
apiUrlAutoDetected = true;
|
|
1704
1723
|
if (typeof window !== "undefined") {
|
|
1705
|
-
|
|
1724
|
+
const isLocalhost = window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1";
|
|
1725
|
+
if (isLocalhost) {
|
|
1726
|
+
apiUrl = "http://localhost:4001/api/v1";
|
|
1727
|
+
} else {
|
|
1728
|
+
apiUrl = `${window.location.protocol}//${window.location.host}/api/v1`;
|
|
1729
|
+
console.warn(
|
|
1730
|
+
"%c\u26A0\uFE0F Produck SDK Warning: apiUrl not configured!",
|
|
1731
|
+
"background: #fbbf24; color: #000; padding: 4px 8px; font-weight: bold;"
|
|
1732
|
+
);
|
|
1733
|
+
console.warn(
|
|
1734
|
+
`The SDK is auto-detecting apiUrl as: ${apiUrl}
|
|
1735
|
+
This is likely WRONG for production. Your backend is probably at a different URL.
|
|
1736
|
+
|
|
1737
|
+
To fix this, provide apiUrl in your SDK config:
|
|
1738
|
+
|
|
1739
|
+
createProduck({
|
|
1740
|
+
sdkKey: 'your_sdk_key',
|
|
1741
|
+
apiUrl: 'https://your-backend.com/api/v1', // <-- Add this!
|
|
1742
|
+
})
|
|
1743
|
+
`
|
|
1744
|
+
);
|
|
1745
|
+
}
|
|
1706
1746
|
} else {
|
|
1707
1747
|
apiUrl = "http://localhost:4001/api/v1";
|
|
1708
1748
|
}
|
|
@@ -1711,11 +1751,30 @@ var ProduckSDK = class {
|
|
|
1711
1751
|
apiUrl,
|
|
1712
1752
|
...config
|
|
1713
1753
|
};
|
|
1754
|
+
if (typeof window !== "undefined") {
|
|
1755
|
+
console.log(
|
|
1756
|
+
"%c\u{1F527} Produck SDK Config",
|
|
1757
|
+
"background: #3b82f6; color: #fff; padding: 2px 6px; border-radius: 3px;",
|
|
1758
|
+
{
|
|
1759
|
+
apiUrl: this.config.apiUrl,
|
|
1760
|
+
apiUrlAutoDetected,
|
|
1761
|
+
sdkKey: this.config.sdkKey ? `${this.config.sdkKey.substring(0, 10)}...` : "not set",
|
|
1762
|
+
guiderId: this.config.guiderId || "not set"
|
|
1763
|
+
}
|
|
1764
|
+
);
|
|
1765
|
+
}
|
|
1714
1766
|
}
|
|
1715
1767
|
/**
|
|
1716
1768
|
* Initialize the SDK and create a chat session
|
|
1717
1769
|
*/
|
|
1718
1770
|
async init() {
|
|
1771
|
+
if (typeof window !== "undefined") {
|
|
1772
|
+
console.log(
|
|
1773
|
+
"%c\u{1F680} Produck SDK Initializing...",
|
|
1774
|
+
"background: #10b981; color: #fff; padding: 2px 6px; border-radius: 3px;",
|
|
1775
|
+
{ endpoint: this.config.apiUrl }
|
|
1776
|
+
);
|
|
1777
|
+
}
|
|
1719
1778
|
await this.log("info", "SDK Initializing", {
|
|
1720
1779
|
apiUrl: this.config.apiUrl,
|
|
1721
1780
|
hasSDKKey: !!this.config.sdkKey,
|
|
@@ -1742,20 +1801,43 @@ var ProduckSDK = class {
|
|
|
1742
1801
|
headers
|
|
1743
1802
|
});
|
|
1744
1803
|
if (!response.ok) {
|
|
1745
|
-
|
|
1804
|
+
let errorDetail = "";
|
|
1805
|
+
try {
|
|
1806
|
+
errorDetail = await response.text();
|
|
1807
|
+
} catch {
|
|
1808
|
+
errorDetail = "Could not read response body";
|
|
1809
|
+
}
|
|
1810
|
+
console.error(
|
|
1811
|
+
"%c\u274C Produck SDK: Failed to create session",
|
|
1812
|
+
"background: #ef4444; color: #fff; padding: 2px 6px; border-radius: 3px;"
|
|
1813
|
+
);
|
|
1814
|
+
console.error(`Status: ${response.status} ${response.statusText}`);
|
|
1815
|
+
console.error(`Endpoint: ${endpoint}`);
|
|
1816
|
+
console.error(`Response: ${errorDetail}`);
|
|
1817
|
+
if (response.status === 404) {
|
|
1818
|
+
console.error(
|
|
1819
|
+
`
|
|
1820
|
+
\u{1F4A1} Tip: A 404 error usually means the apiUrl is wrong.
|
|
1821
|
+
Current apiUrl: ${this.config.apiUrl}
|
|
1822
|
+
Make sure your backend is running and the URL is correct.`
|
|
1823
|
+
);
|
|
1824
|
+
}
|
|
1825
|
+
await this.log("error", "Failed to create session", { status: response.status, errorDetail });
|
|
1746
1826
|
throw new Error(`Failed to create session: ${response.status}`);
|
|
1747
1827
|
}
|
|
1748
1828
|
const session = await response.json();
|
|
1749
1829
|
this.sessionToken = session.session_token;
|
|
1750
1830
|
this.isReady = true;
|
|
1751
1831
|
await this.log("info", "SDK initialized successfully", { hasSessionToken: !!this.sessionToken });
|
|
1752
|
-
|
|
1832
|
+
const recordingEnabled = this.config.recording?.enabled !== false;
|
|
1833
|
+
if (recordingEnabled) {
|
|
1753
1834
|
await this.initRecording();
|
|
1754
1835
|
}
|
|
1755
1836
|
if (this.config.proactive?.enabled) {
|
|
1756
1837
|
this.initProactive();
|
|
1757
1838
|
}
|
|
1758
|
-
|
|
1839
|
+
const userFlowsEnabled = this.config.userFlows?.enabled !== false;
|
|
1840
|
+
if (userFlowsEnabled) {
|
|
1759
1841
|
await this.initUserFlowTracking();
|
|
1760
1842
|
}
|
|
1761
1843
|
this.emit("ready", { sessionToken: this.sessionToken });
|
|
@@ -1763,7 +1845,27 @@ var ProduckSDK = class {
|
|
|
1763
1845
|
await this.sendInitialMessage();
|
|
1764
1846
|
}
|
|
1765
1847
|
} catch (error) {
|
|
1766
|
-
|
|
1848
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1849
|
+
const isNetworkError = errorMessage.includes("fetch") || errorMessage.includes("network") || errorMessage.includes("Failed to fetch") || errorMessage.includes("NetworkError");
|
|
1850
|
+
console.error(
|
|
1851
|
+
"%c\u274C Produck SDK initialization failed",
|
|
1852
|
+
"background: #ef4444; color: #fff; padding: 4px 8px; font-weight: bold;"
|
|
1853
|
+
);
|
|
1854
|
+
console.error(`Error: ${errorMessage}`);
|
|
1855
|
+
console.error(`API URL: ${this.config.apiUrl}`);
|
|
1856
|
+
if (isNetworkError) {
|
|
1857
|
+
console.error(
|
|
1858
|
+
`
|
|
1859
|
+
\u{1F4A1} This looks like a network error. Common causes:
|
|
1860
|
+
1. The apiUrl is incorrect or the backend is not running
|
|
1861
|
+
2. CORS is blocking the request
|
|
1862
|
+
3. The backend server is unreachable
|
|
1863
|
+
|
|
1864
|
+
Current apiUrl: ${this.config.apiUrl}
|
|
1865
|
+
Check the Network tab in DevTools for more details.`
|
|
1866
|
+
);
|
|
1867
|
+
}
|
|
1868
|
+
await this.log("error", "SDK initialization failed", { error: errorMessage });
|
|
1767
1869
|
this.emit("error", error);
|
|
1768
1870
|
throw error;
|
|
1769
1871
|
}
|