@amboras-dev/storefront-core 2026.11.12 → 2026.11.13
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 +32 -0
- package/core-manifest.json +1 -1
- package/dist/entries/client.d.ts +2 -0
- package/dist/entries/client.d.ts.map +1 -1
- package/dist/entries/client.js.map +1 -1
- package/dist/entries/server.d.ts +2 -1
- package/dist/entries/server.d.ts.map +1 -1
- package/dist/entries/server.js.map +1 -1
- package/dist/lib/brand.d.ts +10 -0
- package/dist/lib/brand.d.ts.map +1 -1
- package/dist/lib/brand.js +10 -0
- package/dist/lib/brand.js.map +1 -1
- package/dist/lib/store-config.d.ts +22 -1
- package/dist/lib/store-config.d.ts.map +1 -1
- package/dist/lib/store-config.js +34 -1
- package/dist/lib/store-config.js.map +1 -1
- package/dist/lib/utils/currency.d.ts +49 -9
- package/dist/lib/utils/currency.d.ts.map +1 -1
- package/dist/lib/utils/currency.js +118 -14
- package/dist/lib/utils/currency.js.map +1 -1
- package/dist/lib/utils/format-price.d.ts +3 -2
- package/dist/lib/utils/format-price.d.ts.map +1 -1
- package/dist/lib/utils/format-price.js +6 -20
- package/dist/lib/utils/format-price.js.map +1 -1
- package/dist/shell/core-provider.d.ts +10 -1
- package/dist/shell/core-provider.d.ts.map +1 -1
- package/dist/shell/core-provider.js +5 -1
- package/dist/shell/core-provider.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,38 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 2026.11.13
|
|
6
|
+
|
|
7
|
+
### Rollout
|
|
8
|
+
|
|
9
|
+
- Any order. A Medusa without `currencies` on `GET /store/config` leaves every price exactly as today (core's fallback
|
|
10
|
+
tables); a Medusa that sends it before this core is ignored by older cores. Stores pass
|
|
11
|
+
`storeCurrencies(await getBrand())` to `CoreProvider` to format the first render with the served values (the
|
|
12
|
+
template does). Do not add a new fetch to the root layout for it: one made the cart and checkout pages dynamic.
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- Money rules come from the backend (AMB-2713). `GET /store/config` now sends `currencies`: per store currency,
|
|
17
|
+
`{ storage_scale, display_digits, locale, stripe_wire_factor }`, every value from `@ecomcoder/money` in Medusa
|
|
18
|
+
(the same map rides on `GET /store/brand`). `CoreProvider`'s `currencies` prop and the client `fetchStoreConfig`
|
|
19
|
+
record it (`getStoreConfig` on the server does not, so server and browser render the same), and `storageScaleFor`, `currencyFractionDigits`,
|
|
20
|
+
`currencyLocale`, `formatPrice`, `formatDay`, `roundToCurrencyPrecision` and `toStripeMinorUnits` answer the served
|
|
21
|
+
value first. `THREE_DECIMAL_CURRENCIES`, the Stripe sets and the locale map are fallbacks only, for a currency the
|
|
22
|
+
backend has not sent (older Medusa, config not read yet, a failed read).
|
|
23
|
+
- **One visible change: IQD shows 0 decimals** (`IQD 25,000`, was `IQD 25,000.000`), as `@ecomcoder/money`, ISO and
|
|
24
|
+
browsers do; its bundle totals round to whole dinars. IQD is still stored x1000. Every other currency is unchanged:
|
|
25
|
+
checked against `main` for all 155 active currencies (prices, rounding, Stripe amounts, dates): IQD is the only
|
|
26
|
+
difference.
|
|
27
|
+
|
|
28
|
+
### Added
|
|
29
|
+
|
|
30
|
+
- `CoreProvider` prop `currencies` (`storeCurrencies(await getBrand())`): recorded before children render.
|
|
31
|
+
- `lib/brand`: `storeCurrencies(brand)` and `BrandResponse.currencies`.
|
|
32
|
+
- `lib/utils/currency`: `registerServedCurrencies`, `servedCurrency`, `parseServedCurrency`, `currencyLocale`,
|
|
33
|
+
`clearServedCurrencies` (tests) and the `ServedCurrency` type.
|
|
34
|
+
- `lib/store-config`: `StoreConfig.currencies`, `parseStoreCurrencies` and the `StoreConfigCurrency` / `StoreConfigCurrencies` types (also on
|
|
35
|
+
the client and server entries).
|
|
36
|
+
|
|
5
37
|
## 2026.11.12
|
|
6
38
|
|
|
7
39
|
### Rollout
|
package/core-manifest.json
CHANGED
package/dist/entries/client.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { CoreProvider, type CoreProviderProps } from '../shell/core-provider.js';
|
|
2
|
+
export type { StoreConfigCurrencies, StoreConfigCurrency } from '../lib/store-config.js';
|
|
3
|
+
export type { ServedCurrency } from '../lib/utils/currency.js';
|
|
2
4
|
export { ClientPluginSlot, type ClientPluginSlotProps } from '../shell/client-plugin-slot.js';
|
|
3
5
|
export { usePluginRegistry } from '../shell/registry-context.js';
|
|
4
6
|
export { type CoreHookOverrides, type HookOverride, type OverridableHook } from '../shell/overrides.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/entries/client.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAChF,OAAO,EAAE,gBAAgB,EAAE,KAAK,qBAAqB,EAAE,MAAM,gCAAgC,CAAA;AAC7F,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AAChE,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,YAAY,EAAE,KAAK,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACvG,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,EAClB,KAAK,0BAA0B,GAChC,MAAM,qCAAqC,CAAA;AAC5C,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,wBAAwB,EAC7B,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,GAC7B,MAAM,gCAAgC,CAAA;AACvC,OAAO,EACL,aAAa,EACb,aAAa,EACb,qBAAqB,EACrB,KAAK,UAAU,EACf,KAAK,eAAe,GACrB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,GAC1B,MAAM,kCAAkC,CAAA"}
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/entries/client.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAChF,YAAY,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AACxF,YAAY,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAE,gBAAgB,EAAE,KAAK,qBAAqB,EAAE,MAAM,gCAAgC,CAAA;AAC7F,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AAChE,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,YAAY,EAAE,KAAK,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACvG,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,EAClB,KAAK,0BAA0B,GAChC,MAAM,qCAAqC,CAAA;AAC5C,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,wBAAwB,EAC7B,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,GAC7B,MAAM,gCAAgC,CAAA;AACvC,OAAO,EACL,aAAa,EACb,aAAa,EACb,qBAAqB,EACrB,KAAK,UAAU,EACf,KAAK,eAAe,GACrB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,GAC1B,MAAM,kCAAkC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/entries/client.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,+EAA+E;AAC/E,wEAAwE;AACxE,OAAO,EAAE,YAAY,EAA0B,MAAM,2BAA2B,CAAA;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/entries/client.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,+EAA+E;AAC/E,wEAAwE;AACxE,OAAO,EAAE,YAAY,EAA0B,MAAM,2BAA2B,CAAA;AAGhF,OAAO,EAAE,gBAAgB,EAA8B,MAAM,gCAAgC,CAAA;AAC7F,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AAEhE,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,GAEnB,MAAM,qCAAqC,CAAA;AAC5C,OAAO,EACL,iBAAiB,EACjB,YAAY,GAMb,MAAM,gCAAgC,CAAA;AACvC,OAAO,EACL,aAAa,EACb,aAAa,EACb,qBAAqB,GAGtB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EACL,mBAAmB,EACnB,wBAAwB,GAGzB,MAAM,kCAAkC,CAAA"}
|
package/dist/entries/server.d.ts
CHANGED
|
@@ -2,5 +2,6 @@ export { createPluginSlot, PluginSlot, type PluginSlotProps } from '../shell/plu
|
|
|
2
2
|
export { getPluginConfigs } from '../lib/plugin-config.js';
|
|
3
3
|
export { configureCore, getCoreConfig, MissingMedusaUrlError, type CoreConfig, type CoreConfigInput, } from '../config/index.js';
|
|
4
4
|
export { medusaFetch, medusaBackendUrl, storeHeaders, storeGetJson, storePostJson } from '../lib/store-api.js';
|
|
5
|
-
export { getStoreConfig, isFeatureOff, isFeatureOn, DEFAULT_STORE_CONFIG, type StoreConfig, type StoreConfigFeatures, type StoreFeature, } from '../lib/store-config.js';
|
|
5
|
+
export { getStoreConfig, isFeatureOff, isFeatureOn, DEFAULT_STORE_CONFIG, type StoreConfig, type StoreConfigCurrencies, type StoreConfigCurrency, type StoreConfigFeatures, type StoreFeature, } from '../lib/store-config.js';
|
|
6
|
+
export type { ServedCurrency } from '../lib/utils/currency.js';
|
|
6
7
|
//# sourceMappingURL=server.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/entries/server.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAC5F,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EACL,aAAa,EACb,aAAa,EACb,qBAAqB,EACrB,KAAK,UAAU,EACf,KAAK,eAAe,GACrB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAC9G,OAAO,EACL,cAAc,EACd,YAAY,EACZ,WAAW,EACX,oBAAoB,EACpB,KAAK,WAAW,EAChB,KAAK,mBAAmB,EACxB,KAAK,YAAY,GAClB,MAAM,wBAAwB,CAAA"}
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/entries/server.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAC5F,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EACL,aAAa,EACb,aAAa,EACb,qBAAqB,EACrB,KAAK,UAAU,EACf,KAAK,eAAe,GACrB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAC9G,OAAO,EACL,cAAc,EACd,YAAY,EACZ,WAAW,EACX,oBAAoB,EACpB,KAAK,WAAW,EAChB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,YAAY,GAClB,MAAM,wBAAwB,CAAA;AAC/B,YAAY,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/entries/server.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,0EAA0E;AAC1E,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAwB,MAAM,yBAAyB,CAAA;AAC5F,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EACL,aAAa,EACb,aAAa,EACb,qBAAqB,GAGtB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAC9G,OAAO,EACL,cAAc,EACd,YAAY,EACZ,WAAW,EACX,oBAAoB,
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/entries/server.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,0EAA0E;AAC1E,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAwB,MAAM,yBAAyB,CAAA;AAC5F,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EACL,aAAa,EACb,aAAa,EACb,qBAAqB,GAGtB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAC9G,OAAO,EACL,cAAc,EACd,YAAY,EACZ,WAAW,EACX,oBAAoB,GAMrB,MAAM,wBAAwB,CAAA"}
|
package/dist/lib/brand.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type StoreConfigCurrencies } from './store-config.js';
|
|
1
2
|
export interface BrandSettings {
|
|
2
3
|
logo_url?: string | null;
|
|
3
4
|
square_logo_url?: string | null;
|
|
@@ -25,8 +26,17 @@ export interface BrandResponse {
|
|
|
25
26
|
resend_after_seconds: number;
|
|
26
27
|
};
|
|
27
28
|
};
|
|
29
|
+
/** How to show and charge each store currency (the same map as /store/config); absent on an older Medusa. */
|
|
30
|
+
currencies?: unknown;
|
|
28
31
|
}
|
|
29
32
|
export declare function storeLanguages(brand: BrandResponse | null): StoreLanguages;
|
|
33
|
+
/**
|
|
34
|
+
* The store currencies GET /store/brand served, well-formed entries only;
|
|
35
|
+
* null on an older Medusa or a failed read. The root layout passes this to
|
|
36
|
+
* CoreProvider (`currencies`), so prices render with the backend's rules from
|
|
37
|
+
* the first render, on the server and in the browser alike.
|
|
38
|
+
*/
|
|
39
|
+
export declare function storeCurrencies(brand: BrandResponse | null): StoreConfigCurrencies | null;
|
|
30
40
|
export declare const brandQuery: import("@tanstack/query-core").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<{
|
|
31
41
|
logoUrl: string | null | undefined;
|
|
32
42
|
squareLogoUrl: string | null | undefined;
|
package/dist/lib/brand.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"brand.d.ts","sourceRoot":"","sources":["../../src/lib/brand.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"brand.d.ts","sourceRoot":"","sources":["../../src/lib/brand.ts"],"names":[],"mappings":"AAEA,OAAO,EAAwB,KAAK,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAEpF,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/B,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/B,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC7B,eAAe,CAAC,EAAE,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YAAY,CAAA;AAE3C,KAAK,GAAG,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAa9C,oGAAoG;AACpG,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,GAAG,GAAG,IAAI,CAoB1E;AAED,4EAA4E;AAC5E,wBAAgB,iBAAiB,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,GAAG,GAAG,MAAM,CAM1D;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAO1E;AAED;;;;;GAKG;AACH,wBAAsB,QAAQ,IAAI,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAa9D"}
|
package/dist/lib/brand.js
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import { queryOptions } from '@tanstack/react-query';
|
|
2
2
|
import { medusaBackendUrl, storeHeaders } from './store-api.js';
|
|
3
|
+
import { parseStoreCurrencies } from './store-config.js';
|
|
3
4
|
const ENGLISH = { default: 'en', enabled: ['en'], dir: 'ltr' };
|
|
4
5
|
export function storeLanguages(brand) {
|
|
5
6
|
return brand?.store?.languages ?? ENGLISH;
|
|
6
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* The store currencies GET /store/brand served, well-formed entries only;
|
|
10
|
+
* null on an older Medusa or a failed read. The root layout passes this to
|
|
11
|
+
* CoreProvider (`currencies`), so prices render with the backend's rules from
|
|
12
|
+
* the first render, on the server and in the browser alike.
|
|
13
|
+
*/
|
|
14
|
+
export function storeCurrencies(brand) {
|
|
15
|
+
return parseStoreCurrencies(brand?.currencies);
|
|
16
|
+
}
|
|
7
17
|
function emailLanguagesOf(value) {
|
|
8
18
|
return Array.isArray(value) && value.every((tag) => typeof tag === 'string') ? value : null;
|
|
9
19
|
}
|
package/dist/lib/brand.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"brand.js","sourceRoot":"","sources":["../../src/lib/brand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"brand.js","sourceRoot":"","sources":["../../src/lib/brand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC/D,OAAO,EAAE,oBAAoB,EAA8B,MAAM,mBAAmB,CAAA;AA+BpF,MAAM,OAAO,GAAmB,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAA;AAE9E,MAAM,UAAU,cAAc,CAAC,KAA2B;IACxD,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,IAAI,OAAO,CAAA;AAC3C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,KAA2B;IACzD,OAAO,oBAAoB,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;AAChD,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAc;IACtC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAA;AAC7F,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IAClC,MAAM,OAAO,GAAI,KAA+D,EAAE,oBAAoB,CAAA;IACtG,OAAO,OAAO,OAAO,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ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CAAC,GAAG,IAAI,CAAA;IAC3C,OAAO,iBAAiB,IAAI,iBAAiB,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,kBAAkB,CAAA;AAC1F,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ;IAC5B,MAAM,OAAO,GAA2B,EAAE,MAAM,EAAE,kBAAkB,EAAE,GAAG,YAAY,CAAC,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,CAAA;IAE/G,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,gBAAgB,EAAE,cAAc,EAAE;YAChE,OAAO;YACP,IAAI,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE;SACzB,CAAC,CAAA;QACF,IAAI,CAAC,QAAQ,CAAC,EAAE;YAAE,OAAO,IAAI,CAAA;QAC7B,OAAO,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAkB,CAAA;IACjD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC"}
|
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import type { CheckoutSettings } from './checkout-config.js';
|
|
2
2
|
import type { BrandSettings } from './brand.js';
|
|
3
|
+
import { type ServedCurrency } from './utils/currency.js';
|
|
3
4
|
/**
|
|
4
5
|
* GET /store/config — Medusa's one-call storefront bootstrap: which features
|
|
5
6
|
* are on, the store-wide checkout settings and the brand.
|
|
6
7
|
*
|
|
7
|
-
* { api_version, features: { store_credit, gift_card_tender, subscriptions, cod }, checkout_settings, brand }
|
|
8
|
+
* { api_version, features: { store_credit, gift_card_tender, subscriptions, cod }, checkout_settings, brand, currencies }
|
|
9
|
+
*
|
|
10
|
+
* `currencies` ({ JPY: { storage_scale: 100, display_digits: 0, locale:
|
|
11
|
+
* 'en-US', stripe_wire_factor: 100 }, ... }, every value from @ecomcoder/money)
|
|
12
|
+
* is how the backend tells the storefront how to show and charge each
|
|
13
|
+
* currency. The client read below hands it to lib/utils/currency.ts, so
|
|
14
|
+
* `formatPrice`, `storageScaleFor`, `currencyFractionDigits` and
|
|
15
|
+
* `toStripeMinorUnits` use the served values; an older Medusa that sends none
|
|
16
|
+
* leaves core's fallback tables in place. The same map rides on GET
|
|
17
|
+
* /store/brand (`storeCurrencies(getBrand())`), which the root layout passes to
|
|
18
|
+
* CoreProvider so the first render already uses it.
|
|
8
19
|
*
|
|
9
20
|
* UNKNOWN IS NOT OFF. Every value that Medusa did not positively answer is
|
|
10
21
|
* `null`:
|
|
@@ -32,6 +43,9 @@ export interface StoreConfigFeatures {
|
|
|
32
43
|
cod: boolean | null;
|
|
33
44
|
}
|
|
34
45
|
export type StoreFeature = keyof StoreConfigFeatures;
|
|
46
|
+
/** One currency's entry in /store/config `currencies` (only the well-formed fields are kept). */
|
|
47
|
+
export type StoreConfigCurrency = ServedCurrency;
|
|
48
|
+
export type StoreConfigCurrencies = Record<string, StoreConfigCurrency>;
|
|
35
49
|
export interface StoreConfig {
|
|
36
50
|
/** The response contract's version (YYYY-MM), or null when the route did not answer. */
|
|
37
51
|
api_version: string | null;
|
|
@@ -40,6 +54,8 @@ export interface StoreConfig {
|
|
|
40
54
|
checkout_settings: CheckoutSettings | null;
|
|
41
55
|
/** Same object as GET /store/brand's `brand` (no store name); null when unknown. */
|
|
42
56
|
brand: BrandSettings | null;
|
|
57
|
+
/** Per upper-case currency code, how Medusa says to show and charge it; null when unknown (older Medusa, failed read). */
|
|
58
|
+
currencies: StoreConfigCurrencies | null;
|
|
43
59
|
/** Medusa's /store/config answered (2xx, well-formed). False on an older backend, a 503, a network error. */
|
|
44
60
|
available: boolean;
|
|
45
61
|
}
|
|
@@ -47,6 +63,11 @@ export interface StoreConfig {
|
|
|
47
63
|
export declare const UNKNOWN_STORE_FEATURES: StoreConfigFeatures;
|
|
48
64
|
/** What a store reads when /store/config did not answer: every part unknown (`null`), `available: false`. */
|
|
49
65
|
export declare const DEFAULT_STORE_CONFIG: StoreConfig;
|
|
66
|
+
/**
|
|
67
|
+
* A served `currencies` map (GET /store/config or GET /store/brand), keeping only
|
|
68
|
+
* well-formed codes and fields; null when absent or not a map.
|
|
69
|
+
*/
|
|
70
|
+
export declare function parseStoreCurrencies(value: unknown): StoreConfigCurrencies | null;
|
|
50
71
|
/** A /store/config body as a `StoreConfig`; unknown (DEFAULT_STORE_CONFIG) when it is not one. Unknown keys are ignored. */
|
|
51
72
|
export declare function parseStoreConfig(body: unknown): StoreConfig;
|
|
52
73
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store-config.d.ts","sourceRoot":"","sources":["../../src/lib/store-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"store-config.d.ts","sourceRoot":"","sources":["../../src/lib/store-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE/C,OAAO,EAAiD,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAExG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,0HAA0H;AAC1H,MAAM,WAAW,mBAAmB;IAClC,2EAA2E;IAC3E,YAAY,EAAE,OAAO,GAAG,IAAI,CAAA;IAC5B,uCAAuC;IACvC,gBAAgB,EAAE,OAAO,GAAG,IAAI,CAAA;IAChC,yCAAyC;IACzC,aAAa,EAAE,OAAO,GAAG,IAAI,CAAA;IAC7B,iHAAiH;IACjH,GAAG,EAAE,OAAO,GAAG,IAAI,CAAA;CACpB;AAED,MAAM,MAAM,YAAY,GAAG,MAAM,mBAAmB,CAAA;AAEpD,iGAAiG;AACjG,MAAM,MAAM,mBAAmB,GAAG,cAAc,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
|
+
import { parseServedCurrency, registerServedCurrencies } from './utils/currency.js';
|
|
2
3
|
/** Every flag unknown. */
|
|
3
4
|
export const UNKNOWN_STORE_FEATURES = {
|
|
4
5
|
store_credit: null,
|
|
@@ -12,10 +13,29 @@ export const DEFAULT_STORE_CONFIG = {
|
|
|
12
13
|
features: UNKNOWN_STORE_FEATURES,
|
|
13
14
|
checkout_settings: null,
|
|
14
15
|
brand: null,
|
|
16
|
+
currencies: null,
|
|
15
17
|
available: false,
|
|
16
18
|
};
|
|
17
19
|
const isObject = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
|
|
18
20
|
const flag = (value) => (typeof value === 'boolean' ? value : null);
|
|
21
|
+
/**
|
|
22
|
+
* A served `currencies` map (GET /store/config or GET /store/brand), keeping only
|
|
23
|
+
* well-formed codes and fields; null when absent or not a map.
|
|
24
|
+
*/
|
|
25
|
+
export function parseStoreCurrencies(value) {
|
|
26
|
+
if (!isObject(value))
|
|
27
|
+
return null;
|
|
28
|
+
const out = {};
|
|
29
|
+
for (const [rawCode, entry] of Object.entries(value)) {
|
|
30
|
+
const code = rawCode.trim().toUpperCase();
|
|
31
|
+
if (!/^[A-Z]{3}$/.test(code))
|
|
32
|
+
continue;
|
|
33
|
+
const spec = parseServedCurrency(entry);
|
|
34
|
+
if (spec)
|
|
35
|
+
out[code] = spec;
|
|
36
|
+
}
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
19
39
|
/** A /store/config body as a `StoreConfig`; unknown (DEFAULT_STORE_CONFIG) when it is not one. Unknown keys are ignored. */
|
|
20
40
|
export function parseStoreConfig(body) {
|
|
21
41
|
if (!isObject(body) || !isObject(body.features))
|
|
@@ -31,6 +51,7 @@ export function parseStoreConfig(body) {
|
|
|
31
51
|
},
|
|
32
52
|
checkout_settings: isObject(body.checkout_settings) ? body.checkout_settings : null,
|
|
33
53
|
brand: isObject(body.brand) ? body.brand : null,
|
|
54
|
+
currencies: parseStoreCurrencies(body.currencies),
|
|
34
55
|
available: true,
|
|
35
56
|
};
|
|
36
57
|
}
|
|
@@ -47,13 +68,25 @@ export function isFeatureOff(config, feature) {
|
|
|
47
68
|
export function isFeatureOn(config, feature) {
|
|
48
69
|
return !!config?.available && config.features[feature] === true;
|
|
49
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Hand the served currencies to the money helpers (lib/utils/currency.ts), then
|
|
73
|
+
* return the config unchanged. CLIENT READ ONLY: the server read below does not
|
|
74
|
+
* record them, because a price the server formats with served values while the
|
|
75
|
+
* browser's first render still uses the fallback would not hydrate (IQD's
|
|
76
|
+
* digits differ). On the server they are recorded by CoreProvider's
|
|
77
|
+
* `currencies` prop (from getBrand), on both sides at the same point.
|
|
78
|
+
*/
|
|
79
|
+
function withServedCurrencies(config) {
|
|
80
|
+
registerServedCurrencies(config.currencies);
|
|
81
|
+
return config;
|
|
82
|
+
}
|
|
50
83
|
/** Client-side read (the hook's queryFn). Never throws: unknown (DEFAULT_STORE_CONFIG) on 404, 503 or a network error. */
|
|
51
84
|
export async function fetchStoreConfig() {
|
|
52
85
|
try {
|
|
53
86
|
const res = await medusaFetch('/store/config', { headers: { accept: 'application/json' } });
|
|
54
87
|
if (!res.ok)
|
|
55
88
|
return DEFAULT_STORE_CONFIG;
|
|
56
|
-
return parseStoreConfig(await res.json());
|
|
89
|
+
return withServedCurrencies(parseStoreConfig(await res.json()));
|
|
57
90
|
}
|
|
58
91
|
catch {
|
|
59
92
|
return DEFAULT_STORE_CONFIG;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store-config.js","sourceRoot":"","sources":["../../src/lib/store-config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"store-config.js","sourceRoot":"","sources":["../../src/lib/store-config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC1D,OAAO,EAAE,m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AU,WAAW,CAAC,MAAsC,EAAE,OAAqB;IACvF,OAAO,CAAC,CAAC,MAAM,EAAE,SAAS,IAAI,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,IAAI,CAAA;AACjE,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,oBAAoB,CAAC,MAAmB;IAC/C,wBAAwB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;IAC3C,OAAO,MAAM,CAAA;AACf,CAAC;AAED,0HAA0H;AAC1H,MAAM,CAAC,KAAK,UAAU,gBAAgB;IACpC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,WAAW,CAAC,eAAe,EAAE,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,kBAAkB,EAAE,EAAE,CAAC,CAAA;QAC3F,IAAI,CAAC,GAAG,CAAC,EAAE;YAAE,OAAO,oBAAoB,CAAA;QACxC,OAAO,oBAAoB,CAAC,gBAAgB,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;IACjE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,oBAAoB,CAAA;IAC7B,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc;IAClC,OAAO,gBAAgB,CAAC,MAAM,YAAY,CAAU,eAAe,EAAE,EAAE,CAAC,CAAC,CAAA;AAC3E,CAAC"}
|
|
@@ -1,17 +1,55 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The storefront's one money module: Medusa's storage scale, the display
|
|
3
|
-
* digits, and the Stripe wire scale.
|
|
4
|
-
* `src/common/utils/money.ts` (storage scale) and
|
|
5
|
-
* `src/payment-seam/adapters/stripe-connect/amount.ts` (Stripe wire scale).
|
|
3
|
+
* digits, the locale prices are formatted in, and the Stripe wire scale.
|
|
6
4
|
*
|
|
7
5
|
* Storage: Medusa stores every currency at x100, zero-decimal ones such as JPY
|
|
8
6
|
* and VND included (JPY 1,200 is stored as 120000), and the three-decimal set
|
|
9
7
|
* at x1000 (KWD 1.250 is stored as 1250). The divisor is never 10 ** digits.
|
|
8
|
+
*
|
|
9
|
+
* THE BACKEND OWNS EVERY RULE HERE. GET /store/config sends, per store
|
|
10
|
+
* currency, the values @ecomcoder/money gives (see store-config.ts):
|
|
11
|
+
* { storage_scale, display_digits, locale, stripe_wire_factor }
|
|
12
|
+
* `registerServedCurrencies` records them, and every function below answers
|
|
13
|
+
* the served value first. The tables in this file (THREE_DECIMAL_CURRENCIES,
|
|
14
|
+
* the Stripe sets, the locale map in format-price) are FALLBACKS only, for a
|
|
15
|
+
* currency the backend has not sent: an older Medusa, /store/config not read
|
|
16
|
+
* yet, or a failed read. They give today's output; delete them once every
|
|
17
|
+
* backend sends the full spec and every store passes it to CoreProvider.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Medusa's x1000 storage set (mirrors the admin's `lib/chat/price-units`).
|
|
21
|
+
* FALLBACK for a currency /store/config has not sent a `storage_scale` for.
|
|
10
22
|
*/
|
|
11
|
-
/** Medusa's x1000 storage set (mirrors the admin's `lib/chat/price-units`). */
|
|
12
23
|
export declare const THREE_DECIMAL_CURRENCIES: ReadonlySet<string>;
|
|
13
|
-
/**
|
|
24
|
+
/** One currency as the backend described it. A field the backend did not send (or sent malformed) is absent. */
|
|
25
|
+
export interface ServedCurrency {
|
|
26
|
+
/** Stored units per major unit: 100, or 1000 for the three-decimal set. */
|
|
27
|
+
storage_scale?: 100 | 1000;
|
|
28
|
+
/** Decimals a price shows (JPY 0, USD 2, KWD 3, IQD 0). */
|
|
29
|
+
display_digits?: number;
|
|
30
|
+
/** The locale prices are formatted in ('de-DE' for EUR, else 'en-US'). */
|
|
31
|
+
locale?: string;
|
|
32
|
+
/** Stored units per Stripe.js amount unit: 100 for zero-decimal currencies, else 1. */
|
|
33
|
+
stripe_wire_factor?: 1 | 100;
|
|
34
|
+
}
|
|
35
|
+
/** One served entry, keeping only well-formed fields; null when nothing usable is left. */
|
|
36
|
+
export declare function parseServedCurrency(entry: unknown): ServedCurrency | null;
|
|
37
|
+
/**
|
|
38
|
+
* Record what GET /store/config served (`currencies`: { USD: { storage_scale:
|
|
39
|
+
* 100, display_digits: 2, locale: 'en-US', stripe_wire_factor: 1 }, ... }).
|
|
40
|
+
* A currency's newest entry replaces its old one. Malformed fields, entries,
|
|
41
|
+
* codes and maps are ignored, and those values keep the fallback. Called by
|
|
42
|
+
* fetchStoreConfig / getStoreConfig and CoreProvider; stores do not call it.
|
|
43
|
+
*/
|
|
44
|
+
export declare function registerServedCurrencies(currencies: unknown): void;
|
|
45
|
+
/** What /store/config served for a currency, or undefined when it sent nothing usable. */
|
|
46
|
+
export declare function servedCurrency(currencyCode?: string | null): ServedCurrency | undefined;
|
|
47
|
+
/** Forget everything served (tests). */
|
|
48
|
+
export declare function clearServedCurrencies(): void;
|
|
49
|
+
/** Divisor that turns a stored amount into a major-unit number: the served scale, else the fallback rule. */
|
|
14
50
|
export declare function storageScaleFor(currencyCode?: string | null): 100 | 1000;
|
|
51
|
+
/** The locale a currency's prices are formatted in: the served locale, else the fallback map, else en-US. */
|
|
52
|
+
export declare function currencyLocale(currencyCode?: string | null): string;
|
|
15
53
|
/**
|
|
16
54
|
* Round a stored amount to the currency's precision (one minor unit of its
|
|
17
55
|
* display digits): float sums such as 1999 × 3 summed in pieces never carry
|
|
@@ -19,12 +57,13 @@ export declare function storageScaleFor(currencyCode?: string | null): 100 | 100
|
|
|
19
57
|
*/
|
|
20
58
|
export declare function roundToCurrencyPrecision(amountInStored: number, currencyCode?: string | null): number;
|
|
21
59
|
/**
|
|
22
|
-
* Display digits:
|
|
23
|
-
*
|
|
24
|
-
*
|
|
60
|
+
* Display digits: the served `display_digits` (JPY 0, USD 2, KWD 3, IQD 0).
|
|
61
|
+
* FALLBACK when none was served: three for the x1000 set, otherwise Intl's
|
|
62
|
+
* currency data (JPY 0, USD 2). Display only: a wire amount must not depend on it.
|
|
25
63
|
*/
|
|
26
64
|
export declare function currencyFractionDigits(currencyCode?: string | null): number;
|
|
27
65
|
/**
|
|
66
|
+
* FALLBACK when /store/config sent no `stripe_wire_factor`.
|
|
28
67
|
* docs.stripe.com/currencies zero-decimal list. A fixed set on purpose: Intl's
|
|
29
68
|
* digit tables vary by ICU build (HUF/IDR), and the amount Stripe charges must
|
|
30
69
|
* not depend on the buyer's browser.
|
|
@@ -38,7 +77,8 @@ export declare const STRIPE_ZERO_DECIMAL_CURRENCIES: ReadonlySet<string>;
|
|
|
38
77
|
export declare const STRIPE_SENT_AS_TWO_DECIMAL: ReadonlySet<string>;
|
|
39
78
|
/**
|
|
40
79
|
* Stored amount -> the integer Stripe.js expects (`amount` on a deferred
|
|
41
|
-
* Elements group, `lineItems[].amount`, `shippingRates[].amount`)
|
|
80
|
+
* Elements group, `lineItems[].amount`, `shippingRates[].amount`): stored /
|
|
81
|
+
* the served `stripe_wire_factor`, else by the fallback tables:
|
|
42
82
|
* 2-decimal (USD 5000 -> 5000), 3-decimal (KWD 1250 -> 1250): unchanged.
|
|
43
83
|
* zero-decimal (JPY 120000 -> 1200): stored / 100.
|
|
44
84
|
* ISK/UGX: unchanged (Stripe reads them as two-decimal).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currency.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/currency.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"currency.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/currency.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH;;;GAGG;AACH,eAAO,MAAM,wBAAwB,EAAE,WAAW,CAAC,MAAM,CAEvD,CAAA;AAKF,gHAAgH;AAChH,MAAM,WAAW,cAAc;IAC7B,2EAA2E;IAC3E,aAAa,CAAC,EAAE,GAAG,GAAG,IAAI,CAAA;IAC1B,2DAA2D;IAC3D,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,0EAA0E;IAC1E,MAAM,CAAC,EAAE,MAAM,CAAA;IACf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ire scale.
|
|
4
|
-
* `src/common/utils/money.ts` (storage scale) and
|
|
5
|
-
* `src/payment-seam/adapters/stripe-connect/amount.ts` (Stripe wire scale).
|
|
3
|
+
* digits, the locale prices are formatted in, and the Stripe wire scale.
|
|
6
4
|
*
|
|
7
5
|
* Storage: Medusa stores every currency at x100, zero-decimal ones such as JPY
|
|
8
6
|
* and VND included (JPY 1,200 is stored as 120000), and the three-decimal set
|
|
9
7
|
* at x1000 (KWD 1.250 is stored as 1250). The divisor is never 10 ** digits.
|
|
8
|
+
*
|
|
9
|
+
* THE BACKEND OWNS EVERY RULE HERE. GET /store/config sends, per store
|
|
10
|
+
* currency, the values @ecomcoder/money gives (see store-config.ts):
|
|
11
|
+
* { storage_scale, display_digits, locale, stripe_wire_factor }
|
|
12
|
+
* `registerServedCurrencies` records them, and every function below answers
|
|
13
|
+
* the served value first. The tables in this file (THREE_DECIMAL_CURRENCIES,
|
|
14
|
+
* the Stripe sets, the locale map in format-price) are FALLBACKS only, for a
|
|
15
|
+
* currency the backend has not sent: an older Medusa, /store/config not read
|
|
16
|
+
* yet, or a failed read. They give today's output; delete them once every
|
|
17
|
+
* backend sends the full spec and every store passes it to CoreProvider.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Medusa's x1000 storage set (mirrors the admin's `lib/chat/price-units`).
|
|
21
|
+
* FALLBACK for a currency /store/config has not sent a `storage_scale` for.
|
|
10
22
|
*/
|
|
11
|
-
/** Medusa's x1000 storage set (mirrors the admin's `lib/chat/price-units`). */
|
|
12
23
|
export const THREE_DECIMAL_CURRENCIES = new Set([
|
|
13
24
|
'KWD', 'BHD', 'OMR', 'TND', 'JOD', 'IQD', 'LYD',
|
|
14
25
|
]);
|
|
15
26
|
const normalize = (currencyCode) => currencyCode && currencyCode.trim() ? currencyCode.trim().toUpperCase() : 'USD';
|
|
16
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* What the backend served, by upper-case ISO code. Module-level on purpose:
|
|
29
|
+
* these are platform rules from @ecomcoder/money (the same for every store and
|
|
30
|
+
* every visitor), so one map per process is safe on the server too.
|
|
31
|
+
*/
|
|
32
|
+
const served = new Map();
|
|
33
|
+
const CODE_RE = /^[A-Z]{3}$/;
|
|
34
|
+
function isUsableLocale(value) {
|
|
35
|
+
if (typeof value !== 'string' || !value.trim())
|
|
36
|
+
return false;
|
|
37
|
+
try {
|
|
38
|
+
return Intl.NumberFormat.supportedLocalesOf([value]).length === 1;
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** One served entry, keeping only well-formed fields; null when nothing usable is left. */
|
|
45
|
+
export function parseServedCurrency(entry) {
|
|
46
|
+
if (!entry || typeof entry !== 'object' || Array.isArray(entry))
|
|
47
|
+
return null;
|
|
48
|
+
const raw = entry;
|
|
49
|
+
const out = {};
|
|
50
|
+
if (raw.storage_scale === 100 || raw.storage_scale === 1000)
|
|
51
|
+
out.storage_scale = raw.storage_scale;
|
|
52
|
+
if (typeof raw.display_digits === 'number' && Number.isInteger(raw.display_digits) && raw.display_digits >= 0 && raw.display_digits <= 4) {
|
|
53
|
+
out.display_digits = raw.display_digits;
|
|
54
|
+
}
|
|
55
|
+
if (isUsableLocale(raw.locale))
|
|
56
|
+
out.locale = raw.locale;
|
|
57
|
+
if (raw.stripe_wire_factor === 1 || raw.stripe_wire_factor === 100)
|
|
58
|
+
out.stripe_wire_factor = raw.stripe_wire_factor;
|
|
59
|
+
return Object.keys(out).length > 0 ? out : null;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Record what GET /store/config served (`currencies`: { USD: { storage_scale:
|
|
63
|
+
* 100, display_digits: 2, locale: 'en-US', stripe_wire_factor: 1 }, ... }).
|
|
64
|
+
* A currency's newest entry replaces its old one. Malformed fields, entries,
|
|
65
|
+
* codes and maps are ignored, and those values keep the fallback. Called by
|
|
66
|
+
* fetchStoreConfig / getStoreConfig and CoreProvider; stores do not call it.
|
|
67
|
+
*/
|
|
68
|
+
export function registerServedCurrencies(currencies) {
|
|
69
|
+
if (!currencies || typeof currencies !== 'object' || Array.isArray(currencies))
|
|
70
|
+
return;
|
|
71
|
+
for (const [rawCode, entry] of Object.entries(currencies)) {
|
|
72
|
+
const code = rawCode.trim().toUpperCase();
|
|
73
|
+
if (!CODE_RE.test(code))
|
|
74
|
+
continue;
|
|
75
|
+
const spec = parseServedCurrency(entry);
|
|
76
|
+
if (spec)
|
|
77
|
+
served.set(code, spec);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/** What /store/config served for a currency, or undefined when it sent nothing usable. */
|
|
81
|
+
export function servedCurrency(currencyCode) {
|
|
82
|
+
return served.get(normalize(currencyCode));
|
|
83
|
+
}
|
|
84
|
+
/** Forget everything served (tests). */
|
|
85
|
+
export function clearServedCurrencies() {
|
|
86
|
+
served.clear();
|
|
87
|
+
}
|
|
88
|
+
/** Divisor that turns a stored amount into a major-unit number: the served scale, else the fallback rule. */
|
|
17
89
|
export function storageScaleFor(currencyCode) {
|
|
18
|
-
|
|
90
|
+
const code = normalize(currencyCode);
|
|
91
|
+
return served.get(code)?.storage_scale ?? (THREE_DECIMAL_CURRENCIES.has(code) ? 1000 : 100);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* FALLBACK locale per currency when /store/config sent none: a European
|
|
95
|
+
* locale for the currencies that put the symbol after the amount ("0,02 €"),
|
|
96
|
+
* else en-US ("$0.02").
|
|
97
|
+
*/
|
|
98
|
+
const FALLBACK_CURRENCY_LOCALE = {
|
|
99
|
+
EUR: 'de-DE',
|
|
100
|
+
PLN: 'pl-PL',
|
|
101
|
+
SEK: 'sv-SE',
|
|
102
|
+
NOK: 'nb-NO',
|
|
103
|
+
DKK: 'da-DK',
|
|
104
|
+
CZK: 'cs-CZ',
|
|
105
|
+
CHF: 'de-CH',
|
|
106
|
+
HUF: 'hu-HU',
|
|
107
|
+
RON: 'ro-RO',
|
|
108
|
+
BGN: 'bg-BG',
|
|
109
|
+
HRK: 'hr-HR',
|
|
110
|
+
TRY: 'tr-TR',
|
|
111
|
+
BRL: 'pt-BR',
|
|
112
|
+
RUB: 'ru-RU',
|
|
113
|
+
};
|
|
114
|
+
/** The locale a currency's prices are formatted in: the served locale, else the fallback map, else en-US. */
|
|
115
|
+
export function currencyLocale(currencyCode) {
|
|
116
|
+
const code = normalize(currencyCode);
|
|
117
|
+
return served.get(code)?.locale ?? FALLBACK_CURRENCY_LOCALE[code] ?? 'en-US';
|
|
19
118
|
}
|
|
20
119
|
/**
|
|
21
120
|
* Round a stored amount to the currency's precision (one minor unit of its
|
|
@@ -27,13 +126,16 @@ export function roundToCurrencyPrecision(amountInStored, currencyCode) {
|
|
|
27
126
|
return step > 0 ? Math.round(amountInStored / step) * step : amountInStored;
|
|
28
127
|
}
|
|
29
128
|
/**
|
|
30
|
-
* Display digits:
|
|
31
|
-
*
|
|
32
|
-
*
|
|
129
|
+
* Display digits: the served `display_digits` (JPY 0, USD 2, KWD 3, IQD 0).
|
|
130
|
+
* FALLBACK when none was served: three for the x1000 set, otherwise Intl's
|
|
131
|
+
* currency data (JPY 0, USD 2). Display only: a wire amount must not depend on it.
|
|
33
132
|
*/
|
|
34
133
|
export function currencyFractionDigits(currencyCode) {
|
|
35
134
|
const code = normalize(currencyCode);
|
|
36
|
-
|
|
135
|
+
const servedDigits = served.get(code)?.display_digits;
|
|
136
|
+
if (servedDigits !== undefined)
|
|
137
|
+
return servedDigits;
|
|
138
|
+
if (storageScaleFor(code) === 1000)
|
|
37
139
|
return 3;
|
|
38
140
|
try {
|
|
39
141
|
return (new Intl.NumberFormat('en-US', { style: 'currency', currency: code }).resolvedOptions()
|
|
@@ -44,6 +146,7 @@ export function currencyFractionDigits(currencyCode) {
|
|
|
44
146
|
}
|
|
45
147
|
}
|
|
46
148
|
/**
|
|
149
|
+
* FALLBACK when /store/config sent no `stripe_wire_factor`.
|
|
47
150
|
* docs.stripe.com/currencies zero-decimal list. A fixed set on purpose: Intl's
|
|
48
151
|
* digit tables vary by ICU build (HUF/IDR), and the amount Stripe charges must
|
|
49
152
|
* not depend on the buyer's browser.
|
|
@@ -60,7 +163,8 @@ export const STRIPE_ZERO_DECIMAL_CURRENCIES = new Set([
|
|
|
60
163
|
export const STRIPE_SENT_AS_TWO_DECIMAL = new Set(['ISK', 'UGX']);
|
|
61
164
|
/**
|
|
62
165
|
* Stored amount -> the integer Stripe.js expects (`amount` on a deferred
|
|
63
|
-
* Elements group, `lineItems[].amount`, `shippingRates[].amount`)
|
|
166
|
+
* Elements group, `lineItems[].amount`, `shippingRates[].amount`): stored /
|
|
167
|
+
* the served `stripe_wire_factor`, else by the fallback tables:
|
|
64
168
|
* 2-decimal (USD 5000 -> 5000), 3-decimal (KWD 1250 -> 1250): unchanged.
|
|
65
169
|
* zero-decimal (JPY 120000 -> 1200): stored / 100.
|
|
66
170
|
* ISK/UGX: unchanged (Stripe reads them as two-decimal).
|
|
@@ -71,9 +175,9 @@ export const STRIPE_SENT_AS_TWO_DECIMAL = new Set(['ISK', 'UGX']);
|
|
|
71
175
|
export function toStripeMinorUnits(storedAmount, currencyCode) {
|
|
72
176
|
const code = normalize(currencyCode);
|
|
73
177
|
const stored = Number(storedAmount) || 0;
|
|
74
|
-
const
|
|
75
|
-
?
|
|
76
|
-
|
|
178
|
+
const factor = served.get(code)?.stripe_wire_factor ??
|
|
179
|
+
(STRIPE_ZERO_DECIMAL_CURRENCIES.has(code) && !STRIPE_SENT_AS_TWO_DECIMAL.has(code) ? 100 : 1);
|
|
180
|
+
const wire = stored / factor;
|
|
77
181
|
return Math.max(Math.round(wire), 0);
|
|
78
182
|
}
|
|
79
183
|
//# sourceMappingURL=currency.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currency.js","sourceRoot":"","sources":["../../../src/lib/utils/currency.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"currency.js","sourceRoot":"","sources":["../../../src/lib/utils/currency.ts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AAC,YAAoB,EAAE,YAA4B;IACnF,MAAM,IAAI,GAAG,SAAS,CAAC,YAAY,CAAC,CAAA;IACpC,MAAM,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAA;IACxC,MAAM,MAAM,GACV,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,kBAAkB;QACpC,CAAC,8BAA8B,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,0BAA0B,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAC/F,MAAM,IAAI,GAAG,MAAM,GAAG,MAAM,CAAA;IAC5B,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAA;AACtC,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Format a Medusa-stored amount with the correct locale for the currency.
|
|
3
|
-
* The storage scale
|
|
4
|
-
* storefront's one money module
|
|
3
|
+
* The storage scale, display digits and locale come from lib/utils/currency.ts,
|
|
4
|
+
* the storefront's one money module, which takes them from the backend
|
|
5
|
+
* (GET /store/config) and keeps core's old tables only as a fallback.
|
|
5
6
|
*
|
|
6
7
|
* Currencies like EUR, PLN, SEK, NOK, DKK, CZK, CHF display the symbol
|
|
7
8
|
* on the right side (e.g. "0,02 €") using a European locale.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format-price.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/format-price.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"format-price.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/format-price.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,sBAAsB,EAAkB,eAAe,EAAE,MAAM,eAAe,CAAA;AAEvF,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,CAAA;AAOlD;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAUnE;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,cAAc,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACzC,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GACtC,MAAM,CAgBR"}
|
|
@@ -1,32 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Format a Medusa-stored amount with the correct locale for the currency.
|
|
3
|
-
* The storage scale
|
|
4
|
-
* storefront's one money module
|
|
3
|
+
* The storage scale, display digits and locale come from lib/utils/currency.ts,
|
|
4
|
+
* the storefront's one money module, which takes them from the backend
|
|
5
|
+
* (GET /store/config) and keeps core's old tables only as a fallback.
|
|
5
6
|
*
|
|
6
7
|
* Currencies like EUR, PLN, SEK, NOK, DKK, CZK, CHF display the symbol
|
|
7
8
|
* on the right side (e.g. "0,02 €") using a European locale.
|
|
8
9
|
* Currencies like USD, GBP, CAD, AUD, JPY display it on the left (e.g. "$0.02").
|
|
9
10
|
*/
|
|
10
|
-
import { currencyFractionDigits, storageScaleFor } from './currency.js';
|
|
11
|
+
import { currencyFractionDigits, currencyLocale, storageScaleFor } from './currency.js';
|
|
11
12
|
export { currencyFractionDigits, storageScaleFor };
|
|
12
|
-
|
|
13
|
-
eur: 'de-DE',
|
|
14
|
-
pln: 'pl-PL',
|
|
15
|
-
sek: 'sv-SE',
|
|
16
|
-
nok: 'nb-NO',
|
|
17
|
-
dkk: 'da-DK',
|
|
18
|
-
czk: 'cs-CZ',
|
|
19
|
-
chf: 'de-CH',
|
|
20
|
-
huf: 'hu-HU',
|
|
21
|
-
ron: 'ro-RO',
|
|
22
|
-
bgn: 'bg-BG',
|
|
23
|
-
hrk: 'hr-HR',
|
|
24
|
-
try: 'tr-TR',
|
|
25
|
-
brl: 'pt-BR',
|
|
26
|
-
rub: 'ru-RU',
|
|
27
|
-
};
|
|
13
|
+
/** The locale prices in this currency are formatted in (served by /store/config, else core's fallback map). */
|
|
28
14
|
function getLocale(currencyCode) {
|
|
29
|
-
return
|
|
15
|
+
return currencyLocale(currencyCode);
|
|
30
16
|
}
|
|
31
17
|
/**
|
|
32
18
|
* A calendar day ("2026-12-31", the way the store reports a store credit
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format-price.js","sourceRoot":"","sources":["../../../src/lib/utils/format-price.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"format-price.js","sourceRoot":"","sources":["../../../src/lib/utils/format-price.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAEvF,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,CAAA;AAElD,+GAA+G;AAC/G,SAAS,SAAS,CAAC,YAAoB;IACrC,OAAO,cAAc,CAAC,YAAY,CAAC,CAAA;AACrC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,GAAW,EAAE,YAAoB;IACzD,MAAM,CAAC,GAAG,0BAA0B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAC9C,IAAI,CAAC,CAAC;QAAE,OAAO,GAAG,CAAA;IAClB,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAC7E,OAAO,IAAI,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE;QACtD,GAAG,EAAE,SAAS;QACd,KAAK,EAAE,OAAO;QACd,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,KAAK;KAChB,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;AACjB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CACzB,cAAyC,EACzC,YAAuC;IAEvC,MAAM,IAAI,GAAG,YAAY,IAAI,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,KAAK,CAAA;IAC5F,MAAM,MAAM,GAAG,sBAAsB,CAAC,IAAI,CAAC,CAAA;IAC3C,MAAM,GAAG,GAAG,MAAM,CAAC,cAAc,CAAC,CAAA;IAClC,MAAM,KAAK,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,IAAI,CAAC,CAAA;IACtE,IAAI,CAAC;QACH,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;YAC5C,KAAK,EAAE,UAAU;YACjB,QAAQ,EAAE,IAAI;YACd,qBAAqB,EAAE,MAAM;YAC7B,qBAAqB,EAAE,MAAM;SAC9B,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAClB,CAAC;IAAC,MAAM,CAAC;QACP,kDAAkD;QAClD,OAAO,GAAG,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAA;IAC3C,CAAC;AACH,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { QueryClient } from '@tanstack/react-query';
|
|
2
2
|
import { type ReactNode } from 'react';
|
|
3
|
+
import type { StoreConfigCurrencies } from '../lib/store-config.js';
|
|
3
4
|
import { type PaymentUiComponents } from '../lib/payment-providers/ui.js';
|
|
4
5
|
import type { PluginConfigs, PluginRegistry } from '../types/plugins.js';
|
|
5
6
|
import { type CoreHookOverrides } from './overrides.js';
|
|
@@ -15,6 +16,14 @@ export interface CoreProviderProps {
|
|
|
15
16
|
queryClient?: QueryClient;
|
|
16
17
|
/** Overrides of the hooks core calls itself; read once, on the first render. */
|
|
17
18
|
overrides?: CoreHookOverrides;
|
|
19
|
+
/**
|
|
20
|
+
* How to show and charge each store currency, from the server's
|
|
21
|
+
* `getStoreConfig()` (`config.currencies`). Recorded before anything below
|
|
22
|
+
* renders, so the first client render formats prices exactly as the server
|
|
23
|
+
* did. Optional: without it prices use the backend values once
|
|
24
|
+
* /store/config is read, and core's fallback tables until then.
|
|
25
|
+
*/
|
|
26
|
+
currencies?: StoreConfigCurrencies | null;
|
|
18
27
|
}
|
|
19
28
|
/**
|
|
20
29
|
* Everything core's client hooks need: the TanStack Query client, the plugin
|
|
@@ -22,5 +31,5 @@ export interface CoreProviderProps {
|
|
|
22
31
|
* providers (theme, motion) wrap or sit inside it in the store's
|
|
23
32
|
* app/providers.tsx.
|
|
24
33
|
*/
|
|
25
|
-
export declare function CoreProvider({ children, registry, pluginConfigs, paymentUi, queryClient, overrides, }: CoreProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
34
|
+
export declare function CoreProvider({ children, registry, pluginConfigs, paymentUi, queryClient, overrides, currencies, }: CoreProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
26
35
|
//# sourceMappingURL=core-provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-provider.d.ts","sourceRoot":"","sources":["../../src/shell/core-provider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAuB,MAAM,uBAAuB,CAAA;AACxE,OAAO,EAAqC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"core-provider.d.ts","sourceRoot":"","sources":["../../src/shell/core-provider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAuB,MAAM,uBAAuB,CAAA;AACxE,OAAO,EAAqC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAGzE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAA;AACnE,OAAO,EAAqB,KAAK,mBAAmB,EAAE,MAAM,gCAAgC,CAAA;AAC5F,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAExE,OAAO,EAAwB,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAE7E,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,SAAS,CAAA;IACnB,yGAAyG;IACzG,QAAQ,EAAE,cAAc,CAAA;IACxB,qFAAqF;IACrF,aAAa,CAAC,EAAE,aAAa,CAAA;IAC7B,qGAAqG;IACrG,SAAS,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAA;IACxC,4EAA4E;IAC5E,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,gFAAgF;IAChF,SAAS,CAAC,EAAE,iBAAiB,CAAA;IAC7B;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,qBAAqB,GAAG,IAAI,CAAA;CAC1C;AAmBD;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,QAAQ,EACR,aAAkB,EAClB,SAAS,EACT,WAAW,EACX,SAAS,EACT,UAAU,GACX,EAAE,iBAAiB,2CAgCnB"}
|
|
@@ -3,6 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
4
4
|
import { useLayoutEffect, useRef, useState } from 'react';
|
|
5
5
|
import { captureOrderViewToken } from '../lib/utils/order-ref.js';
|
|
6
|
+
import { registerServedCurrencies } from '../lib/utils/currency.js';
|
|
6
7
|
import { PaymentUiProvider } from '../lib/payment-providers/ui.js';
|
|
7
8
|
import { PluginRegistryContext } from './registry-context.js';
|
|
8
9
|
import { CoreOverridesContext } from './overrides.js';
|
|
@@ -28,7 +29,10 @@ function makeQueryClient() {
|
|
|
28
29
|
* providers (theme, motion) wrap or sit inside it in the store's
|
|
29
30
|
* app/providers.tsx.
|
|
30
31
|
*/
|
|
31
|
-
export function CoreProvider({ children, registry, pluginConfigs = {}, paymentUi, queryClient, overrides, }) {
|
|
32
|
+
export function CoreProvider({ children, registry, pluginConfigs = {}, paymentUi, queryClient, overrides, currencies, }) {
|
|
33
|
+
// Before children render (this runs during this component's render): every
|
|
34
|
+
// formatPrice below sees the served currencies on the very first render.
|
|
35
|
+
registerServedCurrencies(currencies);
|
|
32
36
|
const [client] = useState(() => queryClient ?? makeQueryClient());
|
|
33
37
|
// Frozen: a changed override would change which hooks run.
|
|
34
38
|
const hookOverrides = useRef(overrides ?? null).current;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-provider.js","sourceRoot":"","sources":["../../src/shell/core-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAA;AACzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAA;AACjE,OAAO,EAAE,iBAAiB,EAA4B,MAAM,gCAAgC,CAAA;AAE5F,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAC7D,OAAO,EAAE,oBAAoB,EAA0B,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"core-provider.js","sourceRoot":"","sources":["../../src/shell/core-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAA;AACzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAA;AACjE,OAAO,EAAE,wBAAwB,EAAE,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AAE,aAAa,YACjD,KAAC,qBAAqB,CAAC,QAAQ,IAAC,KAAK,EAAE,QAAQ,YAC7C,MAAC,iBAAiB,IAAC,UAAU,EAAE,SAAS,aAGrC,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,eAAe,GAAG,EAAE,EAAE,EAAE,EAAE;4BACtE,IAAI,aAAa,CAAC,EAAE,CAAC,EAAE,OAAO,KAAK,KAAK;gCAAE,OAAO,IAAI,CAAA;4BACrD,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAC9B,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,aAAa,CAAC,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CACvF,CAAA;4BACD,OAAO,KAAC,SAAS,OAAc,KAAK,IAAb,EAAE,CAAe,CAAA;wBAC1C,CAAC,CAAC,EACD,QAAQ,IACS,GACW,GACH,GACZ,CACvB,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amboras-dev/storefront-core",
|
|
3
|
-
"version": "2026.11.
|
|
3
|
+
"version": "2026.11.13",
|
|
4
4
|
"description": "The platform half of every Amboras storefront: cart, checkout, payments, auth, orders, subscriptions, catalogue data, analytics, consent, plugin slots, edge proxy and the Next config. Stores keep only design; they import this. ESM, React 19, Next 16.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|