|
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" | "ar" | "en" |
|
12
|
|
|
13
|
export const LOCALES = { |
|
14
|
"fa-IR": { language: "fa", direction: "rtl" }, |
|
15
|
ar: { language: "ar", direction: "rtl" }, |
|
16
|
en: { language: "en", direction: "ltr" }, |
|
17
|
} as const |
|
18
|
|
|
19
|
export function isMarketCode(value: string): value is MarketCode { |
|
20
|
return Object.prototype.hasOwnProperty.call(MARKETS, value) |
|
21
|
} |
|
22
|
|
|
23
|
export function isStoreLocale(value: string): value is StoreLocale { |
|
24
|
return Object.prototype.hasOwnProperty.call(LOCALES, value) |
|
25
|
} |
|
26
|
|
|
27
|
/** |
|
28
|
* Converts a whole-number amount in Iranian rials to toman for display. |
|
29
|
* Fractional toman values are preserved; UI rounding policy is a separate decision. |
|
30
|
* This function does not perform currency exchange. |
|
31
|
*/ |
|
32
|
export function rialToToman(rials: number): number { |
|
33
|
if (!Number.isFinite(rials)) { |
|
34
|
throw new TypeError("Rial amount must be a finite number") |
|
35
|
} |
|
36
|
return rials / 10 |
|
37
|
} |
|
38
|
|
|
39
|
/** Product origin is independent of market, warehouse and dispatch country. */ |
|
40
|
export type CommerceProductPolicy = { |
|
41
|
sku: string |
|
42
|
originCountryCode: string |
|
43
|
allowedMarketCodes: MarketCode[] |
|
44
|
} |