Add typed market locale currency and product origin configuration
davoodmehraban89 committed
Oct 13, 2026 at 23:02 UTC
f217a8a374ae63153a62a97f0eb0dbb5df47203e
1 file changed
+43
commerce/src/config/markets.ts
new
+43
@@ -0,0 +1,43 @@
1
+/** Canonical market definitions for the proposed storefront. No PSP/shipping integrations are active. */
2
+export const MARKETS = {
3
+ IR: { countryCode: "ir", currencyCode: "irr", defaultLocale: "fa-IR", focus: "electronics" },
4
+ AE: { countryCode: "ae", currencyCode: "aed", defaultLocale: "en", focus: "iran-origin" },
5
+ OM: { countryCode: "om", currencyCode: "omr", defaultLocale: "en", focus: "iran-origin" },
6
+ IQ: { countryCode: "iq", currencyCode: "iqd", defaultLocale: "en", focus: "iran-origin" },
7
+ QA: { countryCode: "qa", currencyCode: "qar", defaultLocale: "en", focus: "iran-origin" },
8
+} as const
9
+
10
+export type MarketCode = keyof typeof MARKETS
11
+export type StoreLocale = "fa-IR" | "en"
12
+
13
+export const LOCALES = {
14
+ "fa-IR": { language: "fa", direction: "rtl" },
15
+ en: { language: "en", direction: "ltr" },
16
+} as const
17
+
18
+export function isMarketCode(value: string): value is MarketCode {
19
+ return Object.prototype.hasOwnProperty.call(MARKETS, value)
20
+}
21
+
22
+export function isStoreLocale(value: string): value is StoreLocale {
23
+ return Object.prototype.hasOwnProperty.call(LOCALES, value)
24
+}
25
+
26
+/**
27
+ * Converts a whole-number amount in Iranian rials to toman for display.
28
+ * Fractional toman values are preserved; UI rounding policy is a separate decision.
29
+ * This function does not perform currency exchange.
30
+ */
31
+export function rialToToman(rials: number): number {
32
+ if (!Number.isFinite(rials)) {
33
+ throw new TypeError("Rial amount must be a finite number")
34
+ }
35
+ return rials / 10
36
+}
37
+
38
+/** Product origin is independent of market, warehouse and dispatch country. */
39
+export type CommerceProductPolicy = {
40
+ sku: string
41
+ originCountryCode: string
42
+ allowedMarketCodes: MarketCode[]
43
+}