@sledge-app/react-instant-search 0.0.104 → 0.0.106

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.
@@ -636,6 +636,8 @@ const addToCart = async (data) => {
636
636
  quantity
637
637
  });
638
638
  });
639
+ if (typeof window === "undefined" || !((_a = window == null ? void 0 : window.Shopify) == null ? void 0 : _a.routes))
640
+ return;
639
641
  let url = `${window.Shopify.routes.root}cart/add.js`;
640
642
  let headers = {
641
643
  "Content-Type": "application/json"
@@ -643,8 +645,6 @@ const addToCart = async (data) => {
643
645
  let payload = {
644
646
  items
645
647
  };
646
- if (!((_a = window == null ? void 0 : window.Shopify) == null ? void 0 : _a.routes))
647
- return;
648
648
  return await fetchApi(url, "POST", null, payload, headers, false).then((result) => {
649
649
  return result;
650
650
  }).catch(() => {
@@ -760,7 +760,7 @@ const BadgeHeaderMenu = (props) => {
760
760
  };
761
761
  const addWishlist = async (data) => {
762
762
  const { productId, productVariantId, productName, productVendor, productSku, productVariantName, productLink, productImage, productCurrency, productPrice } = data;
763
- let sledgeAuthApp = localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP);
763
+ let sledgeAuthApp = typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP) || "" : "";
764
764
  let url = `${API_URL}/wishlist`;
765
765
  let payload = {
766
766
  product: JSON.stringify({
@@ -783,7 +783,7 @@ const addWishlist = async (data) => {
783
783
  });
784
784
  };
785
785
  const bulkAddWishlist = async (data) => {
786
- let sledgeAuthApp = localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP);
786
+ let sledgeAuthApp = typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP) || "" : "";
787
787
  let products = data.map((item) => {
788
788
  const { productId, productVariantId, productName, productVariantName, productLink, productImage, productCurrency, productPrice } = item;
789
789
  return {
@@ -811,7 +811,7 @@ const bulkAddWishlist = async (data) => {
811
811
  });
812
812
  };
813
813
  const getWishlistInfo = async (token) => {
814
- let sledgeAuthApp = token || localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP);
814
+ let sledgeAuthApp = token || typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP) || "" : "";
815
815
  let url = `${API_URL}/wishlist/info`;
816
816
  return await fetchApi(url, "GET", sledgeAuthApp).then((result) => {
817
817
  return result;
@@ -822,7 +822,7 @@ const getWishlistInfo = async (token) => {
822
822
  const checkWishlist = async (id, variantId) => {
823
823
  let convertId = sanitizeDataId(id);
824
824
  let convertVariantId = variantId ? sanitizeDataId(variantId) : "";
825
- let sledgeAuthApp = localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP) || "";
825
+ let sledgeAuthApp = typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP) || "" : "";
826
826
  let queryParams = "?" + new URLSearchParams({
827
827
  variant_id: convertVariantId
828
828
  }).toString();
@@ -835,7 +835,7 @@ const checkWishlist = async (id, variantId) => {
835
835
  };
836
836
  const addToCartTrigger$1 = async (data) => {
837
837
  const { productId } = data;
838
- let sledgeAuthApp = localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP);
838
+ let sledgeAuthApp = typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP) || "" : "";
839
839
  let url = `${API_URL}/wishlist/cart`;
840
840
  return await fetchApi(url, "POST", sledgeAuthApp, {
841
841
  product: JSON.stringify({
@@ -886,7 +886,7 @@ const BadgeRoot = (props) => {
886
886
  React__default.useEffect(() => {
887
887
  if (!isRenderAppWishlist)
888
888
  return;
889
- handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.WISHLIST_SETTING) || "");
889
+ handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.WISHLIST_SETTING) || null);
890
890
  }, [isRenderAppWishlist, triggerRenderMultipleComponent]);
891
891
  return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: React__default.Children.count(children) && React__default.Children.map(
892
892
  children,
@@ -1116,7 +1116,7 @@ const Trigger = (props) => {
1116
1116
  handleCheckWishlist();
1117
1117
  };
1118
1118
  }
1119
- handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.WISHLIST_SETTING) || "");
1119
+ handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.WISHLIST_SETTING) || null);
1120
1120
  }, [isRenderAppWishlist]);
1121
1121
  React__default.useEffect(() => {
1122
1122
  setIsRequiredLogin(sledgeAnonymId && is_required_login);
@@ -1528,7 +1528,7 @@ const usePrevious = (value) => {
1528
1528
  };
1529
1529
  const getReviewInfo = async (id) => {
1530
1530
  let convertId = sanitizeDataId(id);
1531
- let sledgeAuthApp = localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP);
1531
+ let sledgeAuthApp = typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP) || "" : "";
1532
1532
  let url = `${API_URL}/review/info/${convertId}`;
1533
1533
  return await fetchApi(url, "GET", sledgeAuthApp).then((result) => {
1534
1534
  return result;
@@ -1538,7 +1538,7 @@ const getReviewInfo = async (id) => {
1538
1538
  };
1539
1539
  const getProductsReviewInfo = async (ids, token) => {
1540
1540
  let convertIds = ids.map((v) => sanitizeDataId(v));
1541
- let sledgeAuthApp = token || localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP);
1541
+ let sledgeAuthApp = token || typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP) || "" : "";
1542
1542
  let url = `${API_URL}/review/info/ids/${convertIds.join(",")}`;
1543
1543
  return await fetchApi(url, "GET", sledgeAuthApp).then((result) => {
1544
1544
  return result;
@@ -1645,7 +1645,7 @@ const Rating = (props) => {
1645
1645
  let isProductIdChanged = Boolean(previousState && (previousState == null ? void 0 : previousState.productId) !== productId);
1646
1646
  if (isProductIdChanged)
1647
1647
  setIsFirstLoading(true);
1648
- handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.PRODUCT_REVIEW_SETTING) || "");
1648
+ handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.PRODUCT_REVIEW_SETTING) || null);
1649
1649
  }, [isRenderAppProductReview, productId]);
1650
1650
  React__default.useEffect(() => {
1651
1651
  var _a2, _b2, _c, _d;
@@ -2008,7 +2008,7 @@ WidgetHeader.Sort = WidgetHeaderSort;
2008
2008
  WidgetHeader.AddTrigger = WidgetHeaderAddTrigger;
2009
2009
  WidgetHeader.Summary = WidgetHeaderSummary;
2010
2010
  const search = async (index, payload) => {
2011
- let sledgeInstantSearchAuthApp = localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_AUTH_APP);
2011
+ let sledgeInstantSearchAuthApp = typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_AUTH_APP) || "" : "";
2012
2012
  let url = `${INSTANT_SEARCH_ENGINE_URL}/indexes/${index}/search`;
2013
2013
  let headers = {
2014
2014
  "Content-Type": "application/json"
@@ -2018,7 +2018,7 @@ const search = async (index, payload) => {
2018
2018
  });
2019
2019
  };
2020
2020
  const multiSearch = async (payload, token) => {
2021
- let sledgeInstantSearchAuthApp = token || localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_AUTH_APP);
2021
+ let sledgeInstantSearchAuthApp = token || typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_AUTH_APP) || "" : "";
2022
2022
  let url = `${INSTANT_SEARCH_ENGINE_URL}/multi-search`;
2023
2023
  let headers = {
2024
2024
  "Content-Type": "application/json"
@@ -2029,7 +2029,7 @@ const multiSearch = async (payload, token) => {
2029
2029
  };
2030
2030
  const searchTrigger = async (data) => {
2031
2031
  const { keyword, resultCount } = data;
2032
- let sledgeAuthApp = localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP);
2032
+ let sledgeAuthApp = typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP) || "" : "";
2033
2033
  let url = `${API_URL}/instantsearch/statistics/search`;
2034
2034
  let headers = {
2035
2035
  "Content-Type": "application/json"
@@ -2046,7 +2046,7 @@ const searchTrigger = async (data) => {
2046
2046
  };
2047
2047
  const productClickTrigger = async (data) => {
2048
2048
  const { productId } = data;
2049
- let sledgeAuthApp = localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP);
2049
+ let sledgeAuthApp = typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP) || "" : "";
2050
2050
  let url = `${API_URL}/instantsearch/statistics/click`;
2051
2051
  let headers = {
2052
2052
  "Content-Type": "application/json"
@@ -2064,7 +2064,7 @@ const productClickTrigger = async (data) => {
2064
2064
  };
2065
2065
  const addToCartTrigger = async (data) => {
2066
2066
  const { productId } = data;
2067
- let sledgeAuthApp = localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP);
2067
+ let sledgeAuthApp = typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP) || "" : "";
2068
2068
  let url = `${API_URL}/instantsearch/statistics/cart`;
2069
2069
  let headers = {
2070
2070
  "Content-Type": "application/json"
@@ -2423,7 +2423,7 @@ const SkeletonItem = ({ width, height, rounded, color, style = {}, className = "
2423
2423
  setDataSettings(response);
2424
2424
  };
2425
2425
  React__default.useEffect(() => {
2426
- handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.GENERAL_SETTING) || "");
2426
+ handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.GENERAL_SETTING) || null);
2427
2427
  }, []);
2428
2428
  return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: ((_a = dataSettings == null ? void 0 : dataSettings.skeleton) == null ? void 0 : _a.enable) ? /* @__PURE__ */ jsxRuntimeExports.jsx(
2429
2429
  "div",
@@ -2911,7 +2911,7 @@ const SearchIconWidgetPopup = () => {
2911
2911
  });
2912
2912
  };
2913
2913
  }
2914
- handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || "");
2914
+ handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null);
2915
2915
  }, [isRenderAppInstantSearch]);
2916
2916
  React__default.useEffect(() => {
2917
2917
  showInfo ? document.body.classList.add("sledge__open-popup-state") : document.body.classList.remove("sledge__open-popup-state");
@@ -3265,7 +3265,7 @@ const SearchResultWidget = (props) => {
3265
3265
  return;
3266
3266
  const searchParams2 = new URLSearchParams(document.location.search);
3267
3267
  setKeyword((searchParams2 == null ? void 0 : searchParams2.get(queryKeyword)) || "");
3268
- handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || "");
3268
+ handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null);
3269
3269
  }, [isRenderAppInstantSearch]);
3270
3270
  React__default.useEffect(() => {
3271
3271
  if (Boolean(previousState && (previousState == null ? void 0 : previousState.keyword) !== keyword) && layoutType === "default") {
@@ -4491,7 +4491,7 @@ const SearchWidget = (props) => {
4491
4491
  React__default.useEffect(() => {
4492
4492
  if (!isRenderAppInstantSearch)
4493
4493
  return;
4494
- handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || "");
4494
+ handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null);
4495
4495
  }, [keyword]);
4496
4496
  React__default.useEffect(() => {
4497
4497
  if (Boolean(previousState && (previousState == null ? void 0 : previousState.keyword) !== keyword)) {