@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/CHANGELOG.md +6 -0
- package/dist/index.cjs +12 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +12 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.0.74
|
|
4
|
+
|
|
5
|
+
- 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.
|
|
6
|
+
- `shoppex.invalidateCache(prefixOrKey)` matches the bare key again across every locale/currency namespace (1.0.73 keys are `<locale>|<currency>|<key>`, which made prefix invalidation a no-op).
|
|
7
|
+
- A rejected `init()` (invalid currency) leaves the previous configuration, including the cached shop id, untouched.
|
|
8
|
+
|
|
3
9
|
## 1.0.73
|
|
4
10
|
|
|
5
11
|
- `init({ currency })` is now enforced on every priced read (ADR-0066). `getStorefront`, `getStore`, `resolveStoreByDomain`, `getProducts`, `getStorefrontProductsPage` and `getProduct` send it as `?currency=`; before, only cart quotes and checkout used it, so a catalog could show one currency and the checkout price in another.
|
package/dist/index.cjs
CHANGED
|
@@ -18074,6 +18074,9 @@ function normalizeRequestedCurrency(value) {
|
|
|
18074
18074
|
const normalized = value?.trim().toUpperCase();
|
|
18075
18075
|
return normalized && /^[A-Z]{3}$/.test(normalized) ? normalized : null;
|
|
18076
18076
|
}
|
|
18077
|
+
function resolveBuyerCurrency(configCurrency) {
|
|
18078
|
+
return getRequestedCurrencyFromLocation() ?? normalizeRequestedCurrency(configCurrency);
|
|
18079
|
+
}
|
|
18077
18080
|
function getRequestedCurrencyFromLocation() {
|
|
18078
18081
|
if (typeof window === "undefined" || !window.location) {
|
|
18079
18082
|
return null;
|
|
@@ -18101,12 +18104,13 @@ var currentConfig = null;
|
|
|
18101
18104
|
var cachedShopId = null;
|
|
18102
18105
|
var DEFAULT_CHECKOUT_BASE_URL = "https://checkout.shoppex.io";
|
|
18103
18106
|
function initConfig(storeSlug, options) {
|
|
18107
|
+
const currency = normalizeInitCurrency(options?.currency);
|
|
18104
18108
|
const normalizedShopId = options?.shopId?.trim();
|
|
18105
18109
|
cachedShopId = normalizedShopId ? normalizedShopId : null;
|
|
18106
18110
|
currentConfig = {
|
|
18107
18111
|
storeSlug,
|
|
18108
18112
|
locale: options?.locale,
|
|
18109
|
-
currency
|
|
18113
|
+
currency,
|
|
18110
18114
|
apiBaseUrl: options?.apiBaseUrl ?? DEFAULT_API_BASE_URL,
|
|
18111
18115
|
checkoutBaseUrl: options?.checkoutBaseUrl ?? DEFAULT_CHECKOUT_BASE_URL
|
|
18112
18116
|
};
|
|
@@ -18559,9 +18563,11 @@ function clearCache() {
|
|
|
18559
18563
|
cache.clear();
|
|
18560
18564
|
pending.clear();
|
|
18561
18565
|
}
|
|
18566
|
+
var AUDIENCE_PREFIX = /^[^|]*\|[^|]*\|/;
|
|
18562
18567
|
function invalidateCache(prefixOrKey) {
|
|
18563
18568
|
for (const key of cache.keys()) {
|
|
18564
|
-
|
|
18569
|
+
const bareKey = key.replace(AUDIENCE_PREFIX, "");
|
|
18570
|
+
if (key === prefixOrKey || key.startsWith(prefixOrKey) || bareKey === prefixOrKey || bareKey.startsWith(prefixOrKey)) {
|
|
18565
18571
|
cache.delete(key);
|
|
18566
18572
|
}
|
|
18567
18573
|
}
|
|
@@ -18775,7 +18781,7 @@ async function request(endpoint, options = {}) {
|
|
|
18775
18781
|
} = options;
|
|
18776
18782
|
const retryCount = retries ?? (method === "GET" ? MAX_RETRIES : 0);
|
|
18777
18783
|
const apiBaseUrl = baseUrl ?? config2?.apiBaseUrl ?? "";
|
|
18778
|
-
const buyerCurrency = pricesInBuyerCurrency
|
|
18784
|
+
const buyerCurrency = pricesInBuyerCurrency ? resolveBuyerCurrency(audience?.currency) : null;
|
|
18779
18785
|
const url2 = buyerCurrency ? appendQueryParam(`${apiBaseUrl}${endpoint}`, "currency", buyerCurrency) : `${apiBaseUrl}${endpoint}`;
|
|
18780
18786
|
const headers = {
|
|
18781
18787
|
"Content-Type": "application/json",
|
|
@@ -20088,7 +20094,7 @@ function clearLatestQuoteToken() {
|
|
|
20088
20094
|
async function quoteCart(coupon, currency) {
|
|
20089
20095
|
const sequence = quoteSequence += 1;
|
|
20090
20096
|
const payload = getCartPayload(coupon);
|
|
20091
|
-
const normalizedCurrency = normalizeRequestedCurrency(currency) ??
|
|
20097
|
+
const normalizedCurrency = normalizeRequestedCurrency(currency) ?? resolveBuyerCurrency(getConfig().currency);
|
|
20092
20098
|
const response = await post("/v1/storefront/cart/quote", {
|
|
20093
20099
|
shop_slug: payload.store_slug,
|
|
20094
20100
|
cart: payload.items,
|
|
@@ -20175,10 +20181,10 @@ function resolveRequestedCheckoutCurrency(options) {
|
|
|
20175
20181
|
if (options.currency !== void 0) {
|
|
20176
20182
|
return normalizeRequestedCurrency(options.currency);
|
|
20177
20183
|
}
|
|
20178
|
-
return
|
|
20184
|
+
return resolveBuyerCurrency(getConfig().currency);
|
|
20179
20185
|
}
|
|
20180
20186
|
function getRequestedCheckoutCurrency() {
|
|
20181
|
-
return
|
|
20187
|
+
return resolveBuyerCurrency(getConfig().currency);
|
|
20182
20188
|
}
|
|
20183
20189
|
function normalizeCheckoutFailureMessage(rawMessage) {
|
|
20184
20190
|
const message = rawMessage?.trim() ?? "";
|