@aptly-sdk/hq 0.0.4 → 0.0.5

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.
Files changed (2) hide show
  1. package/dist/index.js +15 -9
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -562,7 +562,9 @@ function useProject() {
562
562
  const useConversation$1 = () => {
563
563
  const project = useProject();
564
564
  const [conversation, setConversation] = useState(null);
565
+ const hasStorage = typeof window !== "undefined" && typeof window.localStorage !== "undefined";
565
566
  useOnMount(() => {
567
+ if (!hasStorage) return;
566
568
  const cache = localStorage.getItem("conversation");
567
569
  if (cache) setConversation(JSON.parse(cache));
568
570
  });
@@ -573,19 +575,23 @@ const useConversation$1 = () => {
573
575
  response.initialMessage = values?.message;
574
576
  if (response) {
575
577
  setConversation(response);
576
- localStorage.setItem("conversation", JSON.stringify({
577
- id: response.id,
578
- context: {
579
- id: response?.context?.id
580
- }
581
- }));
578
+ if (hasStorage) {
579
+ localStorage.setItem("conversation", JSON.stringify({
580
+ id: response.id,
581
+ context: {
582
+ id: response?.context?.id
583
+ }
584
+ }));
585
+ }
582
586
  }
583
- }, [project]);
587
+ }, [hasStorage, project]);
584
588
  const close = useCallback(() => {
585
589
  // todo: update status in BE
586
590
  setConversation(null);
587
- localStorage.removeItem("conversation");
588
- }, [project]);
591
+ if (hasStorage) {
592
+ localStorage.removeItem("conversation");
593
+ }
594
+ }, [hasStorage, project]);
589
595
  return {
590
596
  start,
591
597
  data: conversation,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aptly-sdk/hq",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Chat support widget SDK for NextJS applications powered by Aptly.",
5
5
  "exports": {
6
6
  ".": {