@getwidgets/live-chat-widget 1.0.8 → 1.0.9

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.
@@ -19873,6 +19873,7 @@
19873
19873
  } catch (e) {
19874
19874
  }
19875
19875
  setAuthToken(token);
19876
+ setShowContactFields(false);
19876
19877
  }
19877
19878
  } catch (e) {
19878
19879
  console.warn("Failed to create auth token", e);
@@ -20299,12 +20300,17 @@
20299
20300
  const isMobile = windowWidth < 768;
20300
20301
  reactExports.useEffect(() => {
20301
20302
  if (inputAreaConfig == null ? void 0 : inputAreaConfig.allow_chat_with_email) {
20302
- const hasToken = authToken || localStorageToken;
20303
+ let hasToken = false;
20304
+ try {
20305
+ hasToken = !!(authToken || localStorage.getItem("widgetkraft_livechat_authtoken"));
20306
+ } catch (e) {
20307
+ hasToken = !!authToken;
20308
+ }
20303
20309
  setShowContactFields(!hasToken);
20304
20310
  } else {
20305
20311
  setShowContactFields(false);
20306
20312
  }
20307
- }, [inputAreaConfig == null ? void 0 : inputAreaConfig.allow_chat_with_email, authToken, localStorageToken, isOpen]);
20313
+ }, [inputAreaConfig == null ? void 0 : inputAreaConfig.allow_chat_with_email, authToken, isOpen]);
20308
20314
  const isContactValid = !(inputAreaConfig == null ? void 0 : inputAreaConfig.allow_chat_with_email) || (!showContactFields ? true : contactName.trim() && contactEmail.trim());
20309
20315
  const createAndStoreAuthToken = () => {
20310
20316
  const payload = { name: contactName.trim(), email: contactEmail.trim(), unique_id };
@@ -20833,7 +20839,31 @@
20833
20839
  mountPoint.appendChild(errDiv);
20834
20840
  }
20835
20841
  }
20836
- window.LiveChatWidget = { init };
20842
+ function setUser({ name: name2, email, unique_id }) {
20843
+ const container = document.getElementById("livechat-root");
20844
+ if (container && container.__livechat_mounted) {
20845
+ const shadowRoot = container.shadowRoot;
20846
+ if (shadowRoot) {
20847
+ const mountPoint = shadowRoot.getElementById("live-chat-widget-mount") || shadowRoot.querySelector("#live-chat-widget-mount");
20848
+ if (mountPoint) {
20849
+ const root2 = client.createRoot(mountPoint);
20850
+ root2.render(
20851
+ /* @__PURE__ */ React.createElement(React.StrictMode, null, /* @__PURE__ */ React.createElement(
20852
+ LiveChatWidget,
20853
+ {
20854
+ widgetId: container.dataset.widgetId,
20855
+ apiKey: container.dataset.apiKey,
20856
+ name: name2,
20857
+ email,
20858
+ unique_id
20859
+ }
20860
+ ))
20861
+ );
20862
+ }
20863
+ }
20864
+ }
20865
+ }
20866
+ window.LiveChatWidget = { init, setUser };
20837
20867
  exports2.init = init;
20838
20868
  Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
20839
20869
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getwidgets/live-chat-widget",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "main": "dist/live-chat-widget.umd.js",
5
5
  "unpkg": "dist/live-chat-widget.umd.js",
6
6
  "type": "module",