@sledge-app/react-instant-search 0.0.105 → 0.0.107

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.
@@ -627,7 +627,7 @@ const SelectField = (props) => {
627
627
  };
628
628
  const ProductGrid$1 = "";
629
629
  const addToCart = async (data) => {
630
- var _a;
630
+ var _a, _b;
631
631
  let items = [];
632
632
  data.map((item) => {
633
633
  const { id, quantity } = item;
@@ -636,6 +636,8 @@ const addToCart = async (data) => {
636
636
  quantity
637
637
  });
638
638
  });
639
+ if (typeof window === "undefined" || !((_b = (_a = window == null ? void 0 : window.Shopify) == null ? void 0 : _a.routes) == null ? void 0 : _b.root))
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 ? 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({
@@ -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 ? token : typeof localStorage !== "undefined" ? (localStorage == null ? void 0 : 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;
@@ -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 ? 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"
@@ -2222,7 +2222,7 @@ const ProductGrid = ({
2222
2222
  wishlistChecked: dataWishlists == null ? void 0 : dataWishlists[id]
2223
2223
  }
2224
2224
  ),
2225
- /* @__PURE__ */ jsxRuntimeExports.jsx("img", { src: (image == null ? void 0 : image.src) || "", alt: "sledge-product-card-image", loading: "lazy", onError: (event) => event.currentTarget.src = `${API_URL}/img/blank-image.png` })
2225
+ /* @__PURE__ */ jsxRuntimeExports.jsx("img", { src: (image == null ? void 0 : image.src) || `${API_URL}/img/blank-image.png`, alt: "sledge-product-card-image", loading: "lazy" })
2226
2226
  ]
2227
2227
  }
2228
2228
  ),
@@ -2321,8 +2321,7 @@ const CollectionGrid = ({ className = "", data }) => {
2321
2321
  {
2322
2322
  src: image || `${API_URL}/img/blank-image.png`,
2323
2323
  alt: "sledge-product-card-image",
2324
- loading: "lazy",
2325
- onError: (event) => event.currentTarget.src = `${API_URL}/img/blank-image.png`
2324
+ loading: "lazy"
2326
2325
  }
2327
2326
  ) }),
2328
2327
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge__collection-grid-card-content", children: [
@@ -2345,8 +2344,7 @@ const PageGrid = ({ className = "", data }) => {
2345
2344
  {
2346
2345
  src: image || `${API_URL}/img/blank-image.png`,
2347
2346
  alt: "sledge-product-card-image",
2348
- loading: "lazy",
2349
- onError: (event) => event.currentTarget.src = `${API_URL}/img/blank-image.png`
2347
+ loading: "lazy"
2350
2348
  }
2351
2349
  ) }),
2352
2350
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge__page-grid-card-content", children: [
@@ -2367,8 +2365,7 @@ const BlogGrid = ({ className = "", data }) => {
2367
2365
  {
2368
2366
  src: image || `${API_URL}/img/blank-image.png`,
2369
2367
  alt: "sledge-blog-card-image",
2370
- loading: "lazy",
2371
- onError: (event) => event.currentTarget.src = `${API_URL}/img/blank-image.png`
2368
+ loading: "lazy"
2372
2369
  }
2373
2370
  ) }) }),
2374
2371
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge__blog-grid-card-desc", children: [