@shoppexio/storefront 1.0.73 → 1.0.74

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.d.cts CHANGED
@@ -116,7 +116,10 @@ interface Shop {
116
116
  * payload is denominated in it.
117
117
  */
118
118
  currency: string;
119
- /** The merchant's configured default currency. */
119
+ /**
120
+ * The currency the shop prices in when nothing is requested. Always one of
121
+ * `available_currencies`, so it is always a valid `init({ currency })`.
122
+ */
120
123
  default_currency?: string;
121
124
  /**
122
125
  * Currencies the merchant enabled, exactly as stored (an array, or the
package/dist/index.d.ts CHANGED
@@ -116,7 +116,10 @@ interface Shop {
116
116
  * payload is denominated in it.
117
117
  */
118
118
  currency: string;
119
- /** The merchant's configured default currency. */
119
+ /**
120
+ * The currency the shop prices in when nothing is requested. Always one of
121
+ * `available_currencies`, so it is always a valid `init({ currency })`.
122
+ */
120
123
  default_currency?: string;
121
124
  /**
122
125
  * Currencies the merchant enabled, exactly as stored (an array, or the
package/dist/index.js CHANGED
@@ -2679,6 +2679,9 @@ function normalizeRequestedCurrency(value) {
2679
2679
  const normalized = value?.trim().toUpperCase();
2680
2680
  return normalized && /^[A-Z]{3}$/.test(normalized) ? normalized : null;
2681
2681
  }
2682
+ function resolveBuyerCurrency(configCurrency) {
2683
+ return getRequestedCurrencyFromLocation() ?? normalizeRequestedCurrency(configCurrency);
2684
+ }
2682
2685
  function getRequestedCurrencyFromLocation() {
2683
2686
  if (typeof window === "undefined" || !window.location) {
2684
2687
  return null;
@@ -2706,12 +2709,13 @@ var currentConfig = null;
2706
2709
  var cachedShopId = null;
2707
2710
  var DEFAULT_CHECKOUT_BASE_URL = "https://checkout.shoppex.io";
2708
2711
  function initConfig(storeSlug, options) {
2712
+ const currency = normalizeInitCurrency(options?.currency);
2709
2713
  const normalizedShopId = options?.shopId?.trim();
2710
2714
  cachedShopId = normalizedShopId ? normalizedShopId : null;
2711
2715
  currentConfig = {
2712
2716
  storeSlug,
2713
2717
  locale: options?.locale,
2714
- currency: normalizeInitCurrency(options?.currency),
2718
+ currency,
2715
2719
  apiBaseUrl: options?.apiBaseUrl ?? DEFAULT_API_BASE_URL,
2716
2720
  checkoutBaseUrl: options?.checkoutBaseUrl ?? DEFAULT_CHECKOUT_BASE_URL
2717
2721
  };
@@ -3164,9 +3168,11 @@ function clearCache() {
3164
3168
  cache.clear();
3165
3169
  pending.clear();
3166
3170
  }
3171
+ var AUDIENCE_PREFIX = /^[^|]*\|[^|]*\|/;
3167
3172
  function invalidateCache(prefixOrKey) {
3168
3173
  for (const key of cache.keys()) {
3169
- if (key === prefixOrKey || key.startsWith(prefixOrKey)) {
3174
+ const bareKey = key.replace(AUDIENCE_PREFIX, "");
3175
+ if (key === prefixOrKey || key.startsWith(prefixOrKey) || bareKey === prefixOrKey || bareKey.startsWith(prefixOrKey)) {
3170
3176
  cache.delete(key);
3171
3177
  }
3172
3178
  }
@@ -3380,7 +3386,7 @@ async function request(endpoint, options = {}) {
3380
3386
  } = options;
3381
3387
  const retryCount = retries ?? (method === "GET" ? MAX_RETRIES : 0);
3382
3388
  const apiBaseUrl = baseUrl ?? config?.apiBaseUrl ?? "";
3383
- const buyerCurrency = pricesInBuyerCurrency && audience?.currency ? audience.currency : null;
3389
+ const buyerCurrency = pricesInBuyerCurrency ? resolveBuyerCurrency(audience?.currency) : null;
3384
3390
  const url2 = buyerCurrency ? appendQueryParam(`${apiBaseUrl}${endpoint}`, "currency", buyerCurrency) : `${apiBaseUrl}${endpoint}`;
3385
3391
  const headers = {
3386
3392
  "Content-Type": "application/json",
@@ -4693,7 +4699,7 @@ function clearLatestQuoteToken() {
4693
4699
  async function quoteCart(coupon, currency) {
4694
4700
  const sequence = quoteSequence += 1;
4695
4701
  const payload = getCartPayload(coupon);
4696
- const normalizedCurrency = normalizeRequestedCurrency(currency) ?? getRequestedCurrencyFromLocation() ?? normalizeRequestedCurrency(getConfig().currency);
4702
+ const normalizedCurrency = normalizeRequestedCurrency(currency) ?? resolveBuyerCurrency(getConfig().currency);
4697
4703
  const response = await post("/v1/storefront/cart/quote", {
4698
4704
  shop_slug: payload.store_slug,
4699
4705
  cart: payload.items,
@@ -4780,10 +4786,10 @@ function resolveRequestedCheckoutCurrency(options) {
4780
4786
  if (options.currency !== void 0) {
4781
4787
  return normalizeRequestedCurrency(options.currency);
4782
4788
  }
4783
- return getRequestedCurrencyFromLocation() ?? normalizeRequestedCurrency(getConfig().currency);
4789
+ return resolveBuyerCurrency(getConfig().currency);
4784
4790
  }
4785
4791
  function getRequestedCheckoutCurrency() {
4786
- return getRequestedCurrencyFromLocation() ?? normalizeRequestedCurrency(getConfig().currency);
4792
+ return resolveBuyerCurrency(getConfig().currency);
4787
4793
  }
4788
4794
  function normalizeCheckoutFailureMessage(rawMessage) {
4789
4795
  const message = rawMessage?.trim() ?? "";