@shoppexio/storefront 1.0.74 → 1.0.75

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/dist/index.js CHANGED
@@ -3371,6 +3371,15 @@ function appendQueryParam(url2, key, value) {
3371
3371
  const separator = url2.includes("?") ? "&" : "?";
3372
3372
  return `${url2}${separator}${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
3373
3373
  }
3374
+ function forwardFailure(response, overrides = {}) {
3375
+ const { success: _success, data: _data, ...failure } = response;
3376
+ return {
3377
+ ...failure,
3378
+ success: false,
3379
+ message: overrides.message ?? response.message,
3380
+ ...overrides.data !== void 0 ? { data: overrides.data } : {}
3381
+ };
3382
+ }
3374
3383
  async function request(endpoint, options = {}) {
3375
3384
  const config = options.baseUrl ? null : getConfig();
3376
3385
  const audience = config ?? (isInitialized() ? getConfig() : null);
@@ -3605,10 +3614,7 @@ async function getStore() {
3605
3614
  data: response.data.shop
3606
3615
  };
3607
3616
  }
3608
- return {
3609
- success: false,
3610
- message: response.message
3611
- };
3617
+ return forwardFailure(response);
3612
3618
  }
3613
3619
  async function resolveStoreByDomain(domain, apiBaseUrl) {
3614
3620
  const resolvedDomain = domain ?? (typeof window !== "undefined" ? window.location.hostname : "");
@@ -3643,10 +3649,7 @@ async function resolveStoreByDomain(domain, apiBaseUrl) {
3643
3649
  data: response.data.shop
3644
3650
  };
3645
3651
  }
3646
- return {
3647
- success: false,
3648
- message: response.message ?? "Failed to resolve store"
3649
- };
3652
+ return forwardFailure(response, { message: response.message ?? "Failed to resolve store" });
3650
3653
  }
3651
3654
  async function getStorefront(options) {
3652
3655
  const config = getConfig();
@@ -3688,10 +3691,7 @@ async function getStorefront(options) {
3688
3691
  }
3689
3692
  };
3690
3693
  }
3691
- return {
3692
- success: false,
3693
- message: response.message
3694
- };
3694
+ return forwardFailure(response);
3695
3695
  }
3696
3696
  async function getStoreLogoUrl() {
3697
3697
  const response = await getStore();
@@ -3775,11 +3775,7 @@ async function getProducts() {
3775
3775
  data: getMergedStorefrontProducts(response.data.products.map(normalizeProduct))
3776
3776
  };
3777
3777
  }
3778
- return {
3779
- success: false,
3780
- message: response.message,
3781
- data: []
3782
- };
3778
+ return forwardFailure(response, { data: [] });
3783
3779
  }
3784
3780
  async function getStorefrontProductsPage(options) {
3785
3781
  const config = getConfig();
@@ -3822,16 +3818,16 @@ async function getStorefrontProductsPage(options) {
3822
3818
  }
3823
3819
  };
3824
3820
  }
3825
- return {
3826
- success: false,
3827
- message: response.message
3828
- };
3821
+ return forwardFailure(response);
3829
3822
  }
3830
3823
  async function getProduct(idOrSlug) {
3831
3824
  let shopId = getShopId();
3832
3825
  if (!shopId) {
3833
3826
  const store = await getStore();
3834
- shopId = store.success ? store.data?.id ?? null : null;
3827
+ if (!store.success) {
3828
+ return forwardFailure(store);
3829
+ }
3830
+ shopId = store.data?.id ?? null;
3835
3831
  }
3836
3832
  const queryParams = shopId ? `?slug_shop_id=${encodeURIComponent(shopId)}` : "";
3837
3833
  const response = await get(
@@ -3851,18 +3847,12 @@ async function getProduct(idOrSlug) {
3851
3847
  data: normalizeProduct(response.data.product)
3852
3848
  };
3853
3849
  }
3854
- return {
3855
- success: false,
3856
- message: response.message
3857
- };
3850
+ return forwardFailure(response);
3858
3851
  }
3859
3852
  async function getCategories() {
3860
3853
  const products = await getProducts();
3861
3854
  if (!products.success || !products.data) {
3862
- return {
3863
- success: false,
3864
- message: products.message
3865
- };
3855
+ return forwardFailure(products);
3866
3856
  }
3867
3857
  const categories = /* @__PURE__ */ new Set();
3868
3858
  for (const product of products.data) {