@robylon/web-react-sdk 1.1.28-staging.17 → 1.1.28-staging.19

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/README.md CHANGED
@@ -13,7 +13,7 @@ npm install @robylon/web-react-sdk
13
13
  ### Vanilla JavaScript
14
14
 
15
15
  ```html
16
- <script src="https://staging-cdn.robylon.com/1.1.28-staging.16/robylon.min.js"></script>
16
+ <script src="https://staging-cdn.robylon.com/1.1.28-staging.18/robylon.min.js"></script>
17
17
  ```
18
18
 
19
19
  Or via npm:
package/dist/cjs/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var jsxRuntime = require('react/jsx-runtime');
6
- var React = require('react');
6
+ var react = require('react');
7
7
 
8
8
  /******************************************************************************
9
9
  Copyright (c) Microsoft Corporation.
@@ -847,7 +847,7 @@ var Logger = /** @class */ (function () {
847
847
  /**
848
848
  * Singleton logger instance
849
849
  */
850
- var logger$1 = new Logger();
850
+ var logger = new Logger();
851
851
 
852
852
  /**
853
853
  * Error codes for API operations
@@ -897,7 +897,7 @@ var fetchChatbotConfig = function (chatbotId, userId, token) { return __awaiter(
897
897
  _b.label = 1;
898
898
  case 1:
899
899
  _b.trys.push([1, 6, , 7]);
900
- logger$1.log("Fetching chatbot config from ".concat(endpointUrl));
900
+ logger.log("Fetching chatbot config from ".concat(endpointUrl));
901
901
  return [4 /*yield*/, fetch(endpointUrl, {
902
902
  method: "POST",
903
903
  headers: {
@@ -1066,7 +1066,7 @@ function init(config) {
1066
1066
  defaultApiUrls[currentEnv], copilotUrl: config.copilotUrl ||
1067
1067
  defaultCopilotUrls[currentEnv], environment: config.environment || currentEnv });
1068
1068
  setEnvironmentConfig(configWithDefaults);
1069
- logger$1.log("Robylon SDK environment initialized with custom config", configWithDefaults);
1069
+ logger.log("Robylon SDK environment initialized with custom config", configWithDefaults);
1070
1070
  }
1071
1071
  }
1072
1072
  /**
@@ -1150,7 +1150,7 @@ function create(config) {
1150
1150
  }];
1151
1151
  case 3:
1152
1152
  error_1 = _h.sent();
1153
- logger$1.error("Failed to create chatbot instance:", error_1);
1153
+ logger.error("Failed to create chatbot instance:", error_1);
1154
1154
  if (error_1 instanceof ApiError) {
1155
1155
  throw new Error("Robylon SDK initialization failed: ".concat(error_1.message, " (").concat(error_1.code, ")"));
1156
1156
  }
@@ -1161,79 +1161,42 @@ function create(config) {
1161
1161
  });
1162
1162
  }
1163
1163
 
1164
- // Create a dummy logger in case the real one isn't available
1165
- var safeLogger = {
1166
- error: function () {
1167
- var args = [];
1168
- for (var _i = 0; _i < arguments.length; _i++) {
1169
- args[_i] = arguments[_i];
1170
- }
1171
- if (typeof console !== "undefined") {
1172
- console.error.apply(console, __spreadArray(["[Robylon Error]"], args, false));
1173
- }
1174
- },
1175
- };
1176
- // Use a function to create the component only when needed
1177
- // This prevents any reference to React.Component during module evaluation
1178
- var createErrorBoundary = function () {
1179
- // Only create the real component if React is available
1180
- if (typeof React === "undefined" || typeof React.Component === "undefined") {
1181
- // Return a simple function component that just renders children
1182
- return function SimpleErrorBoundary(props) {
1183
- return props.children;
1164
+ /**
1165
+ * Error Boundary component to catch and handle React rendering errors
1166
+ */
1167
+ var ErrorBoundary = /** @class */ (function (_super) {
1168
+ __extends(ErrorBoundary, _super);
1169
+ function ErrorBoundary(props) {
1170
+ var _this = _super.call(this, props) || this;
1171
+ _this.state = {
1172
+ hasError: false,
1173
+ error: null,
1184
1174
  };
1175
+ return _this;
1185
1176
  }
1186
- // If React is available, create a proper error boundary
1187
- var ErrorBoundaryComponent = /** @class */ (function (_super) {
1188
- __extends(ErrorBoundaryComponent, _super);
1189
- function ErrorBoundaryComponent(props) {
1190
- var _this = _super.call(this, props) || this;
1191
- _this.state = {
1192
- hasError: false,
1193
- error: null,
1194
- };
1195
- return _this;
1196
- }
1197
- ErrorBoundaryComponent.getDerivedStateFromError = function (error) {
1198
- return {
1199
- hasError: true,
1200
- error: error,
1201
- };
1202
- };
1203
- ErrorBoundaryComponent.prototype.componentDidCatch = function (error, errorInfo) {
1204
- var componentName = this.props.componentName;
1205
- // Use the safe logger to avoid errors
1206
- try {
1207
- if (logger$1 && typeof logger$1.error === "function") {
1208
- logger$1.error("Error in ".concat(componentName, " component:"), error, errorInfo);
1209
- }
1210
- else {
1211
- safeLogger.error("Error in ".concat(componentName, " component:"), error, errorInfo);
1212
- }
1213
- }
1214
- catch (e) {
1215
- // Last resort fallback
1216
- console.error("[Robylon]", "Error in ".concat(componentName, " component:"), error);
1217
- }
1218
- };
1219
- ErrorBoundaryComponent.prototype.render = function () {
1220
- if (this.state.hasError) {
1221
- return null; // Silently fail to not disrupt the user experience
1222
- }
1223
- return this.props.children;
1177
+ ErrorBoundary.getDerivedStateFromError = function (error) {
1178
+ return {
1179
+ hasError: true,
1180
+ error: error,
1224
1181
  };
1225
- return ErrorBoundaryComponent;
1226
- }(React.Component));
1227
- return ErrorBoundaryComponent;
1228
- };
1229
- // Create the component outside of the export to avoid immediate evaluation
1230
- var ErrorBoundaryImpl = createErrorBoundary();
1231
- /**
1232
- * Safe ErrorBoundary that works even when React isn't available
1233
- */
1234
- var ErrorBoundary = function (props) {
1235
- return React.createElement(ErrorBoundaryImpl, props);
1236
- };
1182
+ };
1183
+ ErrorBoundary.prototype.componentDidCatch = function (error, errorInfo) {
1184
+ var componentName = this.props.componentName;
1185
+ logger.error("[Robylon Error] Error in ".concat(componentName, " component:"), error, errorInfo);
1186
+ // You could also log to an error reporting service here
1187
+ console.error({
1188
+ componentStack: errorInfo.componentStack,
1189
+ });
1190
+ };
1191
+ ErrorBoundary.prototype.render = function () {
1192
+ if (this.state.hasError) {
1193
+ // You can render any custom fallback UI
1194
+ return null; // Silently fail to not disrupt the user experience
1195
+ }
1196
+ return this.props.children;
1197
+ };
1198
+ return ErrorBoundary;
1199
+ }(react.Component));
1237
1200
 
1238
1201
  var ChatbotEventType;
1239
1202
  (function (ChatbotEventType) {
@@ -1256,13 +1219,13 @@ var InternalEventType;
1256
1219
  function useChatbotState(props) {
1257
1220
  var _this = this;
1258
1221
  var api_key = props.api_key, user_id = props.user_id, user_token = props.user_token, user_profile = props.user_profile;
1259
- var _a = React.useState(false), isInitializing = _a[0], setIsInitializing = _a[1];
1260
- var _b = React.useState(false), isInitialized = _b[0], setIsInitialized = _b[1];
1261
- var _c = React.useState(null), error = _c[0], setError = _c[1];
1262
- var _d = React.useState(null), chatbotConfig = _d[0], setChatbotConfig = _d[1];
1263
- var _e = React.useState(false), isIframeVisible = _e[0], setIsIframeVisible = _e[1];
1222
+ var _a = react.useState(false), isInitializing = _a[0], setIsInitializing = _a[1];
1223
+ var _b = react.useState(false), isInitialized = _b[0], setIsInitialized = _b[1];
1224
+ var _c = react.useState(null), error = _c[0], setError = _c[1];
1225
+ var _d = react.useState(null), chatbotConfig = _d[0], setChatbotConfig = _d[1];
1226
+ var _e = react.useState(false), isIframeVisible = _e[0], setIsIframeVisible = _e[1];
1264
1227
  // Initialize the chatbot
1265
- React.useEffect(function () {
1228
+ react.useEffect(function () {
1266
1229
  var initChatbot = function () { return __awaiter(_this, void 0, void 0, function () {
1267
1230
  var userId, isAnonymous, apiResponse, systemInfo, finalUserProfile, config, err_1, errorMessage;
1268
1231
  var _a, _b, _c, _d, _e, _f, _g;
@@ -1318,7 +1281,7 @@ function useChatbotState(props) {
1318
1281
  err_1 = _h.sent();
1319
1282
  errorMessage = err_1 instanceof Error ? err_1.message : "Failed to initialize chatbot";
1320
1283
  setError(errorMessage);
1321
- logger$1.error("Chatbot initialization failed:", err_1);
1284
+ logger.error("Chatbot initialization failed:", err_1);
1322
1285
  return [3 /*break*/, 5];
1323
1286
  case 4:
1324
1287
  setIsInitializing(false);
@@ -1348,7 +1311,7 @@ function useChatbotState(props) {
1348
1311
 
1349
1312
  function useChatbotEvents(props) {
1350
1313
  var onEvent = props.onEvent;
1351
- var emitEvent = React.useCallback(function (type, data) {
1314
+ var emitEvent = react.useCallback(function (type, data) {
1352
1315
  var event = {
1353
1316
  type: type,
1354
1317
  timestamp: Date.now(),
@@ -1356,7 +1319,7 @@ function useChatbotEvents(props) {
1356
1319
  };
1357
1320
  onEvent === null || onEvent === void 0 ? void 0 : onEvent(event);
1358
1321
  }, [onEvent]);
1359
- var onInternalEvent = React.useCallback(function (eventType, additionalData) {
1322
+ var onInternalEvent = react.useCallback(function (eventType, additionalData) {
1360
1323
  // Handle internal events if needed
1361
1324
  // This can be expanded based on requirements
1362
1325
  }, []);
@@ -1371,9 +1334,9 @@ var ChatbotFloatingButton = function (_a) {
1371
1334
  // If config is null, don't render anything
1372
1335
  if (!config)
1373
1336
  return null;
1374
- var buttonRef = React.useRef(null);
1337
+ var buttonRef = react.useRef(null);
1375
1338
  var copilotUrl = getEnvironmentConfig().copilotUrl;
1376
- React.useEffect(function () {
1339
+ react.useEffect(function () {
1377
1340
  if (buttonRef.current) {
1378
1341
  requestAnimationFrame(function () {
1379
1342
  onEvent === null || onEvent === void 0 ? void 0 : onEvent({
@@ -1397,7 +1360,7 @@ var ChatbotFloatingButton = function (_a) {
1397
1360
  height: "100%",
1398
1361
  } }));
1399
1362
  };
1400
- logger$1.log("config chatbotfloatingbutton", config);
1363
+ logger.log("config chatbotfloatingbutton", config);
1401
1364
  return (jsxRuntime.jsx("div", { ref: buttonRef, className: "message-bubble-container", style: {
1402
1365
  position: "fixed",
1403
1366
  bottom: "1.5rem",
@@ -1416,18 +1379,18 @@ var ChatbotFloatingButton = function (_a) {
1416
1379
  overflow: "hidden",
1417
1380
  }, onClick: toggleIframe, children: renderIcon() }));
1418
1381
  };
1419
- var ChatbotFloatingButton$1 = React.memo(ChatbotFloatingButton);
1382
+ var ChatbotFloatingButton$1 = react.memo(ChatbotFloatingButton);
1420
1383
 
1421
1384
  var ChatbotIframe = function (_a) {
1422
1385
  var config = _a.config, isVisible = _a.isVisible, onClose = _a.onClose, onEvent = _a.onEvent, onInternalEvent = _a.onInternalEvent;
1423
1386
  // If config is null, don't render anything
1424
1387
  if (!config)
1425
1388
  return null;
1426
- var iframeRef = React.useRef(null);
1427
- var isInitializedRef = React.useRef(false);
1428
- var hasRegisteredRef = React.useRef(false);
1389
+ var iframeRef = react.useRef(null);
1390
+ var isInitializedRef = react.useRef(false);
1391
+ var hasRegisteredRef = react.useRef(false);
1429
1392
  // Add responsive styles handler
1430
- var applyResponsiveStyles = React.useCallback(function () {
1393
+ var applyResponsiveStyles = react.useCallback(function () {
1431
1394
  var iframe = iframeRef.current;
1432
1395
  if (!iframe)
1433
1396
  return;
@@ -1457,13 +1420,13 @@ var ChatbotIframe = function (_a) {
1457
1420
  }
1458
1421
  }, []);
1459
1422
  // Add resize listener
1460
- React.useEffect(function () {
1423
+ react.useEffect(function () {
1461
1424
  window === null || window === void 0 ? void 0 : window.addEventListener("resize", applyResponsiveStyles);
1462
1425
  applyResponsiveStyles(); // Apply initial styles
1463
1426
  return function () { return window === null || window === void 0 ? void 0 : window.removeEventListener("resize", applyResponsiveStyles); };
1464
1427
  }, [applyResponsiveStyles]);
1465
1428
  // Initialize iframe only once
1466
- React.useEffect(function () {
1429
+ react.useEffect(function () {
1467
1430
  var iframe = iframeRef.current;
1468
1431
  if (!iframe || isInitializedRef.current)
1469
1432
  return;
@@ -1482,7 +1445,7 @@ var ChatbotIframe = function (_a) {
1482
1445
  return function () { return iframe.removeEventListener("load", handleIframeLoad); };
1483
1446
  }, [config.chatbotId]);
1484
1447
  // Handle visibility changes in separate effect
1485
- React.useEffect(function () {
1448
+ react.useEffect(function () {
1486
1449
  var _a, _b, _c, _d;
1487
1450
  var iframe = iframeRef.current;
1488
1451
  if (!iframe || !isInitializedRef.current)
@@ -1510,7 +1473,7 @@ var ChatbotIframe = function (_a) {
1510
1473
  }
1511
1474
  }
1512
1475
  }, [isVisible, config.userId, config.token, config.userProfile]);
1513
- React.useEffect(function () {
1476
+ react.useEffect(function () {
1514
1477
  var iframe = iframeRef.current;
1515
1478
  if (!iframe || !isInitializedRef.current)
1516
1479
  return;
@@ -1579,7 +1542,7 @@ var ChatbotIframe = function (_a) {
1579
1542
  return function () { return window === null || window === void 0 ? void 0 : window.removeEventListener("message", handleMessage); };
1580
1543
  }, [onClose, onEvent, onInternalEvent, config.chatbotId, isVisible]);
1581
1544
  // Update iframe when user profile changes
1582
- React.useEffect(function () {
1545
+ react.useEffect(function () {
1583
1546
  var _a;
1584
1547
  if (!iframeRef.current || !config || !isVisible)
1585
1548
  return;
@@ -1600,26 +1563,26 @@ var ChatbotIframe = function (_a) {
1600
1563
  display: isVisible ? "block" : "none",
1601
1564
  } }));
1602
1565
  };
1603
- var ChatbotIframe$1 = React.memo(ChatbotIframe);
1566
+ var ChatbotIframe$1 = react.memo(ChatbotIframe);
1604
1567
 
1605
1568
  /**
1606
1569
  * Main Chatbot component that renders the chatbot UI
1607
1570
  */
1608
- var RobylonChatbot = React.memo(function (_a) {
1571
+ var RobylonChatbot = react.memo(function (_a) {
1609
1572
  var api_key = _a.api_key, user_id = _a.user_id, user_token = _a.user_token, user_profile = _a.user_profile, onEvent = _a.onEvent;
1610
- React.useEffect(function () {
1573
+ react.useEffect(function () {
1611
1574
  });
1612
- var stateProps = React.useMemo(function () { return ({
1575
+ var stateProps = react.useMemo(function () { return ({
1613
1576
  api_key: api_key,
1614
1577
  user_id: user_id,
1615
1578
  user_token: user_token,
1616
1579
  user_profile: user_profile,
1617
1580
  }); }, [api_key, user_id, user_token, user_profile]);
1618
- var stableOnEvent = React.useCallback(function (event) {
1581
+ var stableOnEvent = react.useCallback(function (event) {
1619
1582
  onEvent === null || onEvent === void 0 ? void 0 : onEvent(event);
1620
1583
  }, [onEvent]);
1621
1584
  var _b = useChatbotState(stateProps), isInitialized = _b.isInitialized, error = _b.error, chatbotConfig = _b.chatbotConfig, isIframeVisible = _b.isIframeVisible, toggleIframeVisibility = _b.toggleIframeVisibility, closeIframe = _b.closeIframe;
1622
- var eventProps = React.useMemo(function () { return ({
1585
+ var eventProps = react.useMemo(function () { return ({
1623
1586
  api_key: api_key,
1624
1587
  user_profile: stateProps.user_profile,
1625
1588
  onEvent: stableOnEvent,
@@ -1639,17 +1602,17 @@ var RobylonChatbot = React.memo(function (_a) {
1639
1602
  chatbotConfig === null || chatbotConfig === void 0 ? void 0 : chatbotConfig.userId,
1640
1603
  ]);
1641
1604
  var _c = useChatbotEvents(__assign({}, eventProps)), emitEvent = _c.emitEvent, onInternalEvent = _c.onInternalEvent;
1642
- var handleClose = React.useCallback(function () {
1605
+ var handleClose = react.useCallback(function () {
1643
1606
  closeIframe();
1644
1607
  emitEvent(ChatbotEventType.CHATBOT_CLOSED);
1645
1608
  }, [closeIframe, emitEvent]);
1646
- var handleButtonClick = React.useCallback(function () {
1609
+ var handleButtonClick = react.useCallback(function () {
1647
1610
  toggleIframeVisibility();
1648
1611
  emitEvent(isIframeVisible
1649
1612
  ? ChatbotEventType.CHATBOT_CLOSED
1650
1613
  : ChatbotEventType.CHATBOT_BUTTON_CLICKED);
1651
1614
  }, [toggleIframeVisibility, emitEvent, isIframeVisible]);
1652
- var floatingButtonProps = React.useMemo(function () { return ({
1615
+ var floatingButtonProps = react.useMemo(function () { return ({
1653
1616
  config: chatbotConfig,
1654
1617
  toggleIframe: handleButtonClick,
1655
1618
  isIframeVisible: isIframeVisible,
@@ -1662,7 +1625,7 @@ var RobylonChatbot = React.memo(function (_a) {
1662
1625
  stableOnEvent,
1663
1626
  onInternalEvent,
1664
1627
  ]);
1665
- var iframeProps = React.useMemo(function () { return ({
1628
+ var iframeProps = react.useMemo(function () { return ({
1666
1629
  config: chatbotConfig,
1667
1630
  isVisible: isIframeVisible,
1668
1631
  onClose: handleClose,
@@ -1691,124 +1654,16 @@ var RobylonChatbot = React.memo(function (_a) {
1691
1654
  */
1692
1655
  var ChatbotWithErrorBoundary = function (props) { return (jsxRuntime.jsx(ErrorBoundary, { componentName: "RobylonChatbot", children: jsxRuntime.jsx(RobylonChatbot, __assign({}, props)) })); };
1693
1656
 
1694
- // Check if React is available in UMD/global environments
1695
- var isReactAvailable = typeof window !== "undefined" &&
1696
- typeof window.React !== "undefined" &&
1697
- typeof window.React.Component !== "undefined";
1698
- // Create a safe logger that won't throw errors
1699
- var logger = (function () {
1700
- // Default no-op implementation
1701
- var noopLogger = {
1702
- setEnabled: function (_enabled) { },
1703
- setLevel: function (_level) { },
1704
- debug: function () {
1705
- },
1706
- log: function () {
1707
- },
1708
- warn: function () {
1709
- },
1710
- error: function () {
1711
- },
1712
- };
1713
- // Try to use the original logger if available
1714
- if (typeof logger$1 !== "undefined" && logger$1) {
1715
- return {
1716
- setEnabled: function (enabled) {
1717
- try {
1718
- if (typeof logger$1.setEnabled === "function") {
1719
- logger$1.setEnabled(enabled);
1720
- }
1721
- }
1722
- catch (e) {
1723
- console.warn("[Robylon] Failed to set logging enabled state");
1724
- }
1725
- },
1726
- setLevel: function (level) {
1727
- try {
1728
- if (typeof logger$1.setLevel === "function") {
1729
- logger$1.setLevel(level);
1730
- }
1731
- }
1732
- catch (e) {
1733
- console.warn("[Robylon] Failed to set logging level");
1734
- }
1735
- },
1736
- debug: function () {
1737
- var args = [];
1738
- for (var _i = 0; _i < arguments.length; _i++) {
1739
- args[_i] = arguments[_i];
1740
- }
1741
- try {
1742
- if (typeof logger$1.debug === "function") {
1743
- logger$1.debug.apply(logger$1, args);
1744
- }
1745
- }
1746
- catch (e) {
1747
- // Silent fail
1748
- }
1749
- },
1750
- log: function () {
1751
- var args = [];
1752
- for (var _i = 0; _i < arguments.length; _i++) {
1753
- args[_i] = arguments[_i];
1754
- }
1755
- try {
1756
- if (typeof logger$1.log === "function") {
1757
- logger$1.log.apply(logger$1, args);
1758
- }
1759
- }
1760
- catch (e) {
1761
- // Silent fail
1762
- }
1763
- },
1764
- warn: function () {
1765
- var args = [];
1766
- for (var _i = 0; _i < arguments.length; _i++) {
1767
- args[_i] = arguments[_i];
1768
- }
1769
- try {
1770
- if (typeof logger$1.warn === "function") {
1771
- logger$1.warn.apply(logger$1, args);
1772
- }
1773
- else {
1774
- console.warn.apply(console, __spreadArray(["[Robylon]"], args, false));
1775
- }
1776
- }
1777
- catch (e) {
1778
- console.warn.apply(console, __spreadArray(["[Robylon]"], args, false));
1779
- }
1780
- },
1781
- error: function () {
1782
- var args = [];
1783
- for (var _i = 0; _i < arguments.length; _i++) {
1784
- args[_i] = arguments[_i];
1785
- }
1786
- try {
1787
- if (typeof logger$1.error === "function") {
1788
- logger$1.error.apply(logger$1, args);
1789
- }
1790
- else {
1791
- console.error.apply(console, __spreadArray(["[Robylon]"], args, false));
1792
- }
1793
- }
1794
- catch (e) {
1795
- console.error.apply(console, __spreadArray(["[Robylon]"], args, false));
1796
- }
1797
- },
1798
- };
1799
- }
1800
- return noopLogger;
1801
- })();
1802
1657
  // Expose the public API
1803
- var Robylon = __assign({
1658
+ var Robylon = {
1804
1659
  /**
1805
1660
  * Create a new Robylon chatbot instance
1806
1661
  */
1807
- create: create,
1662
+ create: create,
1808
1663
  /**
1809
1664
  * Initialize the SDK with custom environment settings
1810
1665
  */
1811
- init: init,
1666
+ init: init,
1812
1667
  /**
1813
1668
  * Configure logging
1814
1669
  */
@@ -1823,7 +1678,8 @@ var Robylon = __assign({
1823
1678
  setLevel: function (level) {
1824
1679
  return logger.setLevel(level);
1825
1680
  },
1826
- } }, (isReactAvailable ? { Chatbot: ChatbotWithErrorBoundary } : {}));
1681
+ },
1682
+ };
1827
1683
  // For UMD/global environments
1828
1684
  if (typeof window !== "undefined") {
1829
1685
  window.Robylon = Robylon;