@customerhero/js 2.4.0 → 2.4.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.cjs CHANGED
@@ -1438,12 +1438,14 @@ var CustomerHeroChat = class {
1438
1438
  });
1439
1439
  const { chatbotId, apiBase } = this.state.config;
1440
1440
  let botMessageCreated = false;
1441
+ const continuationReadToken = this.state.conversationId ? this.storage?.getItem(`ch_conv_token_${chatbotId}`) : null;
1441
1442
  try {
1442
1443
  const response = await fetch(`${apiBase}/api/chat/${chatbotId}`, {
1443
1444
  method: "POST",
1444
1445
  headers: {
1445
1446
  "Content-Type": "application/json",
1446
- Accept: "text/event-stream"
1447
+ Accept: "text/event-stream",
1448
+ ...continuationReadToken ? { "X-CH-Read-Token": continuationReadToken } : {}
1447
1449
  },
1448
1450
  body: JSON.stringify({
1449
1451
  message: trimmed,
@@ -1623,7 +1625,9 @@ var CustomerHeroChat = class {
1623
1625
  this.setState({ messages, error: null });
1624
1626
  const { chatbotId, apiBase } = this.state.config;
1625
1627
  const href = decision === "approve" ? decisionBlock?.approveHref : decisionBlock?.cancelHref;
1626
- const url = href ? `${apiBase}${href}` : `${apiBase}/api/chat/${chatbotId}/tool-calls/${pendingId}/decision`;
1628
+ const baseUrl = href ? `${apiBase}${href}` : `${apiBase}/api/chat/${chatbotId}/tool-calls/${pendingId}/decision`;
1629
+ const readToken = this.storage?.getItem(`ch_conv_token_${chatbotId}`);
1630
+ const url = readToken ? `${baseUrl}${baseUrl.includes("?") ? "&" : "?"}t=${encodeURIComponent(readToken)}` : baseUrl;
1627
1631
  try {
1628
1632
  const response = await fetch(url, {
1629
1633
  method: "POST",
@@ -1741,8 +1745,10 @@ var CustomerHeroChat = class {
1741
1745
  const { chatbotId, apiBase } = this.state.config;
1742
1746
  const { conversationId } = this.state;
1743
1747
  if (!conversationId) return;
1748
+ const readToken = this.storage?.getItem(`ch_conv_token_${chatbotId}`);
1749
+ const url = readToken ? `${apiBase}/api/chat/${chatbotId}/feedback?t=${encodeURIComponent(readToken)}` : `${apiBase}/api/chat/${chatbotId}/feedback`;
1744
1750
  try {
1745
- await fetch(`${apiBase}/api/chat/${chatbotId}/rate`, {
1751
+ await fetch(url, {
1746
1752
  method: "POST",
1747
1753
  headers: { "Content-Type": "application/json" },
1748
1754
  body: JSON.stringify({ conversationId, messageId, rating })
package/dist/index.js CHANGED
@@ -1393,12 +1393,14 @@ var CustomerHeroChat = class {
1393
1393
  });
1394
1394
  const { chatbotId, apiBase } = this.state.config;
1395
1395
  let botMessageCreated = false;
1396
+ const continuationReadToken = this.state.conversationId ? this.storage?.getItem(`ch_conv_token_${chatbotId}`) : null;
1396
1397
  try {
1397
1398
  const response = await fetch(`${apiBase}/api/chat/${chatbotId}`, {
1398
1399
  method: "POST",
1399
1400
  headers: {
1400
1401
  "Content-Type": "application/json",
1401
- Accept: "text/event-stream"
1402
+ Accept: "text/event-stream",
1403
+ ...continuationReadToken ? { "X-CH-Read-Token": continuationReadToken } : {}
1402
1404
  },
1403
1405
  body: JSON.stringify({
1404
1406
  message: trimmed,
@@ -1578,7 +1580,9 @@ var CustomerHeroChat = class {
1578
1580
  this.setState({ messages, error: null });
1579
1581
  const { chatbotId, apiBase } = this.state.config;
1580
1582
  const href = decision === "approve" ? decisionBlock?.approveHref : decisionBlock?.cancelHref;
1581
- const url = href ? `${apiBase}${href}` : `${apiBase}/api/chat/${chatbotId}/tool-calls/${pendingId}/decision`;
1583
+ const baseUrl = href ? `${apiBase}${href}` : `${apiBase}/api/chat/${chatbotId}/tool-calls/${pendingId}/decision`;
1584
+ const readToken = this.storage?.getItem(`ch_conv_token_${chatbotId}`);
1585
+ const url = readToken ? `${baseUrl}${baseUrl.includes("?") ? "&" : "?"}t=${encodeURIComponent(readToken)}` : baseUrl;
1582
1586
  try {
1583
1587
  const response = await fetch(url, {
1584
1588
  method: "POST",
@@ -1696,8 +1700,10 @@ var CustomerHeroChat = class {
1696
1700
  const { chatbotId, apiBase } = this.state.config;
1697
1701
  const { conversationId } = this.state;
1698
1702
  if (!conversationId) return;
1703
+ const readToken = this.storage?.getItem(`ch_conv_token_${chatbotId}`);
1704
+ const url = readToken ? `${apiBase}/api/chat/${chatbotId}/feedback?t=${encodeURIComponent(readToken)}` : `${apiBase}/api/chat/${chatbotId}/feedback`;
1699
1705
  try {
1700
- await fetch(`${apiBase}/api/chat/${chatbotId}/rate`, {
1706
+ await fetch(url, {
1701
1707
  method: "POST",
1702
1708
  headers: { "Content-Type": "application/json" },
1703
1709
  body: JSON.stringify({ conversationId, messageId, rating })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@customerhero/js",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "private": false,
5
5
  "description": "Framework-agnostic JavaScript client for the CustomerHero chat widget.",
6
6
  "keywords": [