@shoppexio/storefront 1.0.74 → 1.0.76

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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.75
4
+
5
+ - `getStore`, `getStorefront`, `resolveStoreByDomain`, `getProducts`, `getStorefrontProductsPage`, `getProduct` and `getCategories` now forward the full failure contract (`code`, `errorParams`, `status`, `responseReceived`, `responseDefinitive`) instead of rebuilding `{ success: false, message }`, so `code === 'errors.storefront.currency_unavailable'` is branchable through every catalog read. A slug `getProduct()` whose store lookup failed returns that failure instead of a misleading not-found.
6
+
3
7
  ## 1.0.74
4
8
 
5
9
  - Catalog reads now resolve the buyer currency with the same rule as cart quotes and checkout: a `?currency=` on the page URL wins, then `init({ currency })`. Before, a merchant-hosted page with `?currency=` priced the catalog in the init currency and the cart in the URL currency.
package/dist/index.cjs CHANGED
@@ -18766,6 +18766,15 @@ function appendQueryParam(url2, key, value) {
18766
18766
  const separator = url2.includes("?") ? "&" : "?";
18767
18767
  return `${url2}${separator}${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
18768
18768
  }
18769
+ function forwardFailure(response, overrides = {}) {
18770
+ const { success: _success2, data: _data, ...failure } = response;
18771
+ return {
18772
+ ...failure,
18773
+ success: false,
18774
+ message: overrides.message ?? response.message,
18775
+ ...overrides.data !== void 0 ? { data: overrides.data } : {}
18776
+ };
18777
+ }
18769
18778
  async function request(endpoint, options = {}) {
18770
18779
  const config2 = options.baseUrl ? null : getConfig();
18771
18780
  const audience = config2 ?? (isInitialized() ? getConfig() : null);
@@ -19000,10 +19009,7 @@ async function getStore() {
19000
19009
  data: response.data.shop
19001
19010
  };
19002
19011
  }
19003
- return {
19004
- success: false,
19005
- message: response.message
19006
- };
19012
+ return forwardFailure(response);
19007
19013
  }
19008
19014
  async function resolveStoreByDomain(domain2, apiBaseUrl) {
19009
19015
  const resolvedDomain = domain2 ?? (typeof window !== "undefined" ? window.location.hostname : "");
@@ -19038,10 +19044,7 @@ async function resolveStoreByDomain(domain2, apiBaseUrl) {
19038
19044
  data: response.data.shop
19039
19045
  };
19040
19046
  }
19041
- return {
19042
- success: false,
19043
- message: response.message ?? "Failed to resolve store"
19044
- };
19047
+ return forwardFailure(response, { message: response.message ?? "Failed to resolve store" });
19045
19048
  }
19046
19049
  async function getStorefront(options) {
19047
19050
  const config2 = getConfig();
@@ -19083,10 +19086,7 @@ async function getStorefront(options) {
19083
19086
  }
19084
19087
  };
19085
19088
  }
19086
- return {
19087
- success: false,
19088
- message: response.message
19089
- };
19089
+ return forwardFailure(response);
19090
19090
  }
19091
19091
  async function getStoreLogoUrl() {
19092
19092
  const response = await getStore();
@@ -19170,11 +19170,7 @@ async function getProducts() {
19170
19170
  data: getMergedStorefrontProducts(response.data.products.map(normalizeProduct))
19171
19171
  };
19172
19172
  }
19173
- return {
19174
- success: false,
19175
- message: response.message,
19176
- data: []
19177
- };
19173
+ return forwardFailure(response, { data: [] });
19178
19174
  }
19179
19175
  async function getStorefrontProductsPage(options) {
19180
19176
  const config2 = getConfig();
@@ -19217,16 +19213,16 @@ async function getStorefrontProductsPage(options) {
19217
19213
  }
19218
19214
  };
19219
19215
  }
19220
- return {
19221
- success: false,
19222
- message: response.message
19223
- };
19216
+ return forwardFailure(response);
19224
19217
  }
19225
19218
  async function getProduct(idOrSlug) {
19226
19219
  let shopId = getShopId();
19227
19220
  if (!shopId) {
19228
19221
  const store = await getStore();
19229
- shopId = store.success ? store.data?.id ?? null : null;
19222
+ if (!store.success) {
19223
+ return forwardFailure(store);
19224
+ }
19225
+ shopId = store.data?.id ?? null;
19230
19226
  }
19231
19227
  const queryParams = shopId ? `?slug_shop_id=${encodeURIComponent(shopId)}` : "";
19232
19228
  const response = await get(
@@ -19246,18 +19242,12 @@ async function getProduct(idOrSlug) {
19246
19242
  data: normalizeProduct(response.data.product)
19247
19243
  };
19248
19244
  }
19249
- return {
19250
- success: false,
19251
- message: response.message
19252
- };
19245
+ return forwardFailure(response);
19253
19246
  }
19254
19247
  async function getCategories() {
19255
19248
  const products = await getProducts();
19256
19249
  if (!products.success || !products.data) {
19257
- return {
19258
- success: false,
19259
- message: products.message
19260
- };
19250
+ return forwardFailure(products);
19261
19251
  }
19262
19252
  const categories = /* @__PURE__ */ new Set();
19263
19253
  for (const product of products.data) {