@amboras-dev/money 0.0.0-stage → 0.2.0
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/README.md +401 -2
- package/dist/ai.cjs +185 -0
- package/dist/ai.d.cts +97 -0
- package/dist/ai.d.ts +97 -0
- package/dist/ai.js +175 -0
- package/dist/allocate-CZRg4TOP.cjs +222 -0
- package/dist/allocate-X7_jAtOj.js +199 -0
- package/dist/amount-BV0O-aN8.cjs +241 -0
- package/dist/amount-BoYBMgK9.js +200 -0
- package/dist/arithmetic-BhNwisjb.js +132 -0
- package/dist/arithmetic-DjT4Kzgt.cjs +233 -0
- package/dist/billing.cjs +184 -0
- package/dist/billing.d.cts +81 -0
- package/dist/billing.d.ts +81 -0
- package/dist/billing.js +175 -0
- package/dist/commerce.cjs +536 -0
- package/dist/commerce.d.cts +293 -0
- package/dist/commerce.d.ts +293 -0
- package/dist/commerce.js +516 -0
- package/dist/format-BdPnijvn.js +99 -0
- package/dist/format-DLhno7eX.cjs +128 -0
- package/dist/fx.cjs +407 -0
- package/dist/fx.d.cts +157 -0
- package/dist/fx.d.ts +157 -0
- package/dist/fx.js +374 -0
- package/dist/index.cjs +352 -0
- package/dist/index.d.cts +300 -0
- package/dist/index.d.ts +300 -0
- package/dist/index.js +276 -0
- package/dist/input.cjs +163 -0
- package/dist/input.d.cts +203 -0
- package/dist/input.d.ts +203 -0
- package/dist/input.js +153 -0
- package/dist/iso-minor-CqkWDxHS.js +48 -0
- package/dist/iso-minor-wSwJN57T.cjs +65 -0
- package/dist/medusa-4K8N1pUc.d.cts +87 -0
- package/dist/medusa-DBXJXXvF.d.ts +87 -0
- package/dist/medusa-DqJY1qpj.js +116 -0
- package/dist/medusa-lRY9xlsf.cjs +175 -0
- package/dist/money-B-3aFjNJ.d.cts +248 -0
- package/dist/money-B-3aFjNJ.d.ts +248 -0
- package/dist/money-B3wH_Z4S.cjs +3990 -0
- package/dist/money-WhnGiI00.js +3583 -0
- package/dist/number-text-BWu67jUq.cjs +145 -0
- package/dist/number-text-DE-q4jO5.js +134 -0
- package/dist/own-D7544D3k.js +4 -0
- package/dist/own-oP9DXFWv.cjs +9 -0
- package/dist/percent-C0InC2t2.cjs +43 -0
- package/dist/percent-D1VB9xXG.js +20 -0
- package/dist/rate-CVeMii4a.cjs +217 -0
- package/dist/rate-DBPiYgT1.d.ts +63 -0
- package/dist/rate-DicStBue.js +152 -0
- package/dist/rate-tqK8ijG0.d.cts +63 -0
- package/dist/reporting-CG-ai2sM.d.cts +31 -0
- package/dist/reporting-tpGJbqYp.d.ts +31 -0
- package/dist/retail-1mu888J1.js +69 -0
- package/dist/retail-C_BPLvMj.d.cts +31 -0
- package/dist/retail-Cml8YSKg.cjs +86 -0
- package/dist/retail-DRUTTQoJ.d.ts +31 -0
- package/dist/rounding-DHBtNCHG.cjs +79 -0
- package/dist/rounding-g9rvye0k.js +50 -0
- package/dist/sql.cjs +290 -0
- package/dist/sql.d.cts +147 -0
- package/dist/sql.d.ts +147 -0
- package/dist/sql.js +271 -0
- package/dist/testing.cjs +61995 -0
- package/dist/testing.d.cts +125 -0
- package/dist/testing.d.ts +125 -0
- package/dist/testing.js +61986 -0
- package/dist/wire-Bhuut8cW.cjs +2097 -0
- package/dist/wire-CaUN9Vf_.d.ts +309 -0
- package/dist/wire-sW0yzqth.js +1888 -0
- package/dist/wire-xjYXv4go.d.cts +309 -0
- package/dist/wire.cjs +37 -0
- package/dist/wire.d.cts +2 -0
- package/dist/wire.d.ts +2 -0
- package/dist/wire.js +2 -0
- package/package.json +158 -3
package/dist/fx.d.cts
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { R as DecimalText, i as Money, z as RoundingMode } from "./money-B-3aFjNJ.cjs";
|
|
2
|
+
import { n as priceRoundingParams, r as roundRetail, t as RetailRounding } from "./retail-C_BPLvMj.cjs";
|
|
3
|
+
import { a as RateRow, c as rate, d as rateFromRow, f as rateToDecimal, i as RateFromDecimalOptions, l as rateEquals, n as RATE_REF, o as crossRate, p as rateToNumber, r as Rate, s as invertRate, t as RATE_BOUNDS, u as rateFromDecimal } from "./rate-tqK8ijG0.cjs";
|
|
4
|
+
import { i as toReporting, n as ReportingTotal, r as storeFactors, t as FactorTable } from "./reporting-CG-ai2sM.cjs";
|
|
5
|
+
import { n as MoneyByCurrency } from "./medusa-4K8N1pUc.cjs";
|
|
6
|
+
//#region src/fx/convert.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* The factor taking a stored `from` amount to a stored `to` amount for the major rate `r`
|
|
9
|
+
* (1 from = r to): `{ r.n x storageScale(to), r.d x storageScale(from) }`. Replaces Medusa
|
|
10
|
+
* `storedRateFactor`, `regionSwitchFactor`, `conversionFactor`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function convertFactor(from: string, to: string, r: Rate): Rate;
|
|
13
|
+
interface ConvertOptions {
|
|
14
|
+
/** Default `'currency'` (whole yen for JPY, a cent for USD): the one rounding (D6). */
|
|
15
|
+
unit?: 'currency' | 'storage';
|
|
16
|
+
/** Default `'half-up'`. */
|
|
17
|
+
rounding?: RoundingMode;
|
|
18
|
+
/**
|
|
19
|
+
* Applied after the unit rounding, only when given (so `unit: 'storage'` keeps a sub-unit
|
|
20
|
+
* JPY amount; an explicit `'none'` rounds a zero-decimal currency to a whole unit, as Medusa).
|
|
21
|
+
*/
|
|
22
|
+
retail?: RetailRounding;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* `m` in `to` at the major rate `r` (1 m.currency = r to): exact `m x convertFactor`, rounded
|
|
26
|
+
* once to `unit`, then `retail`. The same currency returns `m` unchanged.
|
|
27
|
+
*/
|
|
28
|
+
export declare function convert(m: Money, to: string, r: Rate, options?: ConvertOptions): Money;
|
|
29
|
+
/**
|
|
30
|
+
* The major rate two prices imply, `major(b) / major(a)`, exactly and in lowest terms (JPY
|
|
31
|
+
* 150000 against USD 1000 gives 150). Both must be positive, else `rate_invalid`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function impliedRate(a: Money, b: Money): Rate;
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/fx/format-rate.d.ts
|
|
36
|
+
/**
|
|
37
|
+
* `'1 USD = 83.42 INR'`. `decimals: 'auto'` (default) shows 4 significant digits with at
|
|
38
|
+
* least 2 and at most 8 fraction digits; a number fixes them. Rounded half-up exactly, then
|
|
39
|
+
* grouped for `locale` (default `'en-US'`).
|
|
40
|
+
*/
|
|
41
|
+
export declare function formatRate(r: Rate, from: string, to: string, options?: {
|
|
42
|
+
decimals?: 'auto' | number;
|
|
43
|
+
locale?: string;
|
|
44
|
+
}): string;
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/fx/plausibility.d.ts
|
|
47
|
+
/** Medusa PRICE_SEED_RATE_MAX_DEVIATION's default. */
|
|
48
|
+
export declare const DEFAULT_RATE_MAX_DEVIATION = 2;
|
|
49
|
+
/** chooseFactor's tolerance between the conventional factor and the observed median. */
|
|
50
|
+
export declare const FACTOR_TOLERANCE = 0.02;
|
|
51
|
+
/** How far apart two positive rates are, as a factor >= 1 (2 = one is double the other). */
|
|
52
|
+
export declare function deviationFactor(stored: number, reference: number): number;
|
|
53
|
+
interface RateReference {
|
|
54
|
+
/** Units of quote per one unit of the default currency, lower-case codes. */
|
|
55
|
+
readonly rates: Readonly<Record<string, number>>;
|
|
56
|
+
readonly source: string;
|
|
57
|
+
}
|
|
58
|
+
type RateClassification = {
|
|
59
|
+
readonly status: 'plausible';
|
|
60
|
+
readonly currency: string;
|
|
61
|
+
readonly stored: number;
|
|
62
|
+
} | {
|
|
63
|
+
readonly status: 'unverifiable';
|
|
64
|
+
readonly reason: 'no_reference' | 'no_pair';
|
|
65
|
+
readonly currency: string;
|
|
66
|
+
readonly stored: number;
|
|
67
|
+
} | {
|
|
68
|
+
readonly status: 'refused';
|
|
69
|
+
readonly reason: 'invalid';
|
|
70
|
+
readonly currency: string;
|
|
71
|
+
readonly stored: number;
|
|
72
|
+
} | {
|
|
73
|
+
readonly status: 'refused';
|
|
74
|
+
readonly reason: 'implausible';
|
|
75
|
+
readonly currency: string;
|
|
76
|
+
readonly stored: number;
|
|
77
|
+
readonly reference: number;
|
|
78
|
+
readonly factor: number;
|
|
79
|
+
readonly source: string;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* One locked rate against the reference, in Medusa `classifyRates` order: invalid (null or not
|
|
83
|
+
* a rate) is refused `invalid`; no reference is unverifiable `no_reference`; no positive
|
|
84
|
+
* reference for the currency is unverifiable `no_pair`; a deviation strictly above
|
|
85
|
+
* `maxDeviation` (default 2) is refused `implausible`; else plausible.
|
|
86
|
+
*/
|
|
87
|
+
export declare function classifyRate(r: Rate | null, code: string, reference: RateReference | null, options?: {
|
|
88
|
+
maxDeviation?: number;
|
|
89
|
+
}): RateClassification;
|
|
90
|
+
/**
|
|
91
|
+
* The storage factor confirmed by the store's own prices (Medusa `chooseFactor`): the
|
|
92
|
+
* candidates `[c, c / 100, c x 100]` against the upper median of the finite positive observed
|
|
93
|
+
* ratios; the first within `tolerance` (default 0.02) wins, none gives null. No observations
|
|
94
|
+
* trusts `conventional`.
|
|
95
|
+
*/
|
|
96
|
+
export declare function confirmStoredFactor(conventional: Rate, observedRatios: readonly number[], options?: {
|
|
97
|
+
tolerance?: number;
|
|
98
|
+
}): Rate | null;
|
|
99
|
+
/**
|
|
100
|
+
* The upper median of `rates` and which of them lie within `tolerance` (default 0.01) of it:
|
|
101
|
+
* accepted iff `|r / median - 1| <= tolerance`, exactly. No rates: `{ median: null, accepted: [] }`.
|
|
102
|
+
*/
|
|
103
|
+
export declare function rateConsensus(rates: readonly Rate[], options?: {
|
|
104
|
+
tolerance?: number;
|
|
105
|
+
}): {
|
|
106
|
+
median: Rate | null;
|
|
107
|
+
accepted: boolean[];
|
|
108
|
+
};
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/fx/settings.d.ts
|
|
111
|
+
export declare const RATE_MODES: readonly ["manual", "dynamic"];
|
|
112
|
+
export declare const PRICE_ROUNDINGS: readonly ["none", "nearest"];
|
|
113
|
+
/** `store_currency_rate.rate_mode` as readers coerce it: `'manual'` exactly, else `'dynamic'`. */
|
|
114
|
+
export declare function parseRateMode(value: unknown): (typeof RATE_MODES)[number];
|
|
115
|
+
/** `store_currency_rate.rounding` as readers coerce it: `'nearest'` exactly, else `'none'`. */
|
|
116
|
+
export declare function parsePriceRounding(value: unknown): (typeof PRICE_ROUNDINGS)[number];
|
|
117
|
+
type MoneyByCurrencyFallback = {
|
|
118
|
+
readonly kind: 'refuse';
|
|
119
|
+
} | {
|
|
120
|
+
readonly kind: 'major';
|
|
121
|
+
readonly amount: DecimalText | number;
|
|
122
|
+
} | {
|
|
123
|
+
readonly kind: 'convert';
|
|
124
|
+
readonly from: string;
|
|
125
|
+
readonly rate: Rate;
|
|
126
|
+
readonly retail?: RetailRounding;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* The amount a per-currency setting holds for `currency`: the listed entry, else the explicit
|
|
130
|
+
* fallback: `'refuse'` gives null; `'major'` is that many major units of `currency` itself
|
|
131
|
+
* (the store-credit cap `{ kind: 'major', amount: '15000' }`); `'convert'` converts the
|
|
132
|
+
* `from` entry at `rate` (null when there is no `from` entry). Never a silent default.
|
|
133
|
+
*/
|
|
134
|
+
export declare function resolveMoneyByCurrency(setting: MoneyByCurrency, currency: string, options: {
|
|
135
|
+
fallback: MoneyByCurrencyFallback;
|
|
136
|
+
}): {
|
|
137
|
+
money: Money;
|
|
138
|
+
source: 'listed' | 'fallback';
|
|
139
|
+
} | null;
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region src/fx/tables.d.ts
|
|
142
|
+
/** 1 USD = rate units of the currency, exact (see data/pegs.ts for the sources). Upper-case keys. */
|
|
143
|
+
export declare const USD_PEGS: Readonly<Record<string, Rate>>;
|
|
144
|
+
/** A feed's rate table with lower-case keys and only finite positive numbers kept (Medusa `lowerKeys`). Never throws. */
|
|
145
|
+
export declare function sanitizeRateTable(raw: unknown): Record<string, number>;
|
|
146
|
+
/** `{ ...fallback, ...primary }`: the primary feed (ECB) wins every currency it publishes. */
|
|
147
|
+
export declare function mergeRateTables(primary: Readonly<Record<string, number>>, fallback: Readonly<Record<string, number>>): Record<string, number>;
|
|
148
|
+
/**
|
|
149
|
+
* The rate 1 `from` = ? `to` when the live pair is unavailable, through the USD pegs
|
|
150
|
+
* (orch `resolveRateMajor`): a pegged `to` gives the peg from USD, else `(from -> USD) x peg`
|
|
151
|
+
* with `from -> USD` read from `ratesPerUsd` (units per 1 USD, any key case) or from `from`'s
|
|
152
|
+
* own peg; a pegged `from` into USD gives the inverse peg (new, symmetric). The same code
|
|
153
|
+
* gives 1/1; anything else null.
|
|
154
|
+
*/
|
|
155
|
+
export declare function pegFallback(from: string, to: string, ratesPerUsd: Readonly<Record<string, number>>, pegs?: Readonly<Record<string, Rate>>): Rate | null;
|
|
156
|
+
//#endregion
|
|
157
|
+
export { type ConvertOptions, type FactorTable, type MoneyByCurrencyFallback, RATE_BOUNDS, RATE_REF, type Rate, type RateClassification, type RateFromDecimalOptions, type RateReference, type RateRow, type ReportingTotal, type RetailRounding, crossRate, invertRate, priceRoundingParams, rate, rateEquals, rateFromDecimal, rateFromRow, rateToDecimal, rateToNumber, roundRetail, storeFactors, toReporting };
|
package/dist/fx.d.ts
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { R as DecimalText, i as Money, z as RoundingMode } from "./money-B-3aFjNJ.js";
|
|
2
|
+
import { n as priceRoundingParams, r as roundRetail, t as RetailRounding } from "./retail-DRUTTQoJ.js";
|
|
3
|
+
import { a as RateRow, c as rate, d as rateFromRow, f as rateToDecimal, i as RateFromDecimalOptions, l as rateEquals, n as RATE_REF, o as crossRate, p as rateToNumber, r as Rate, s as invertRate, t as RATE_BOUNDS, u as rateFromDecimal } from "./rate-DBPiYgT1.js";
|
|
4
|
+
import { i as toReporting, n as ReportingTotal, r as storeFactors, t as FactorTable } from "./reporting-tpGJbqYp.js";
|
|
5
|
+
import { n as MoneyByCurrency } from "./medusa-DBXJXXvF.js";
|
|
6
|
+
//#region src/fx/convert.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* The factor taking a stored `from` amount to a stored `to` amount for the major rate `r`
|
|
9
|
+
* (1 from = r to): `{ r.n x storageScale(to), r.d x storageScale(from) }`. Replaces Medusa
|
|
10
|
+
* `storedRateFactor`, `regionSwitchFactor`, `conversionFactor`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function convertFactor(from: string, to: string, r: Rate): Rate;
|
|
13
|
+
interface ConvertOptions {
|
|
14
|
+
/** Default `'currency'` (whole yen for JPY, a cent for USD): the one rounding (D6). */
|
|
15
|
+
unit?: 'currency' | 'storage';
|
|
16
|
+
/** Default `'half-up'`. */
|
|
17
|
+
rounding?: RoundingMode;
|
|
18
|
+
/**
|
|
19
|
+
* Applied after the unit rounding, only when given (so `unit: 'storage'` keeps a sub-unit
|
|
20
|
+
* JPY amount; an explicit `'none'` rounds a zero-decimal currency to a whole unit, as Medusa).
|
|
21
|
+
*/
|
|
22
|
+
retail?: RetailRounding;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* `m` in `to` at the major rate `r` (1 m.currency = r to): exact `m x convertFactor`, rounded
|
|
26
|
+
* once to `unit`, then `retail`. The same currency returns `m` unchanged.
|
|
27
|
+
*/
|
|
28
|
+
export declare function convert(m: Money, to: string, r: Rate, options?: ConvertOptions): Money;
|
|
29
|
+
/**
|
|
30
|
+
* The major rate two prices imply, `major(b) / major(a)`, exactly and in lowest terms (JPY
|
|
31
|
+
* 150000 against USD 1000 gives 150). Both must be positive, else `rate_invalid`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function impliedRate(a: Money, b: Money): Rate;
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/fx/format-rate.d.ts
|
|
36
|
+
/**
|
|
37
|
+
* `'1 USD = 83.42 INR'`. `decimals: 'auto'` (default) shows 4 significant digits with at
|
|
38
|
+
* least 2 and at most 8 fraction digits; a number fixes them. Rounded half-up exactly, then
|
|
39
|
+
* grouped for `locale` (default `'en-US'`).
|
|
40
|
+
*/
|
|
41
|
+
export declare function formatRate(r: Rate, from: string, to: string, options?: {
|
|
42
|
+
decimals?: 'auto' | number;
|
|
43
|
+
locale?: string;
|
|
44
|
+
}): string;
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/fx/plausibility.d.ts
|
|
47
|
+
/** Medusa PRICE_SEED_RATE_MAX_DEVIATION's default. */
|
|
48
|
+
export declare const DEFAULT_RATE_MAX_DEVIATION = 2;
|
|
49
|
+
/** chooseFactor's tolerance between the conventional factor and the observed median. */
|
|
50
|
+
export declare const FACTOR_TOLERANCE = 0.02;
|
|
51
|
+
/** How far apart two positive rates are, as a factor >= 1 (2 = one is double the other). */
|
|
52
|
+
export declare function deviationFactor(stored: number, reference: number): number;
|
|
53
|
+
interface RateReference {
|
|
54
|
+
/** Units of quote per one unit of the default currency, lower-case codes. */
|
|
55
|
+
readonly rates: Readonly<Record<string, number>>;
|
|
56
|
+
readonly source: string;
|
|
57
|
+
}
|
|
58
|
+
type RateClassification = {
|
|
59
|
+
readonly status: 'plausible';
|
|
60
|
+
readonly currency: string;
|
|
61
|
+
readonly stored: number;
|
|
62
|
+
} | {
|
|
63
|
+
readonly status: 'unverifiable';
|
|
64
|
+
readonly reason: 'no_reference' | 'no_pair';
|
|
65
|
+
readonly currency: string;
|
|
66
|
+
readonly stored: number;
|
|
67
|
+
} | {
|
|
68
|
+
readonly status: 'refused';
|
|
69
|
+
readonly reason: 'invalid';
|
|
70
|
+
readonly currency: string;
|
|
71
|
+
readonly stored: number;
|
|
72
|
+
} | {
|
|
73
|
+
readonly status: 'refused';
|
|
74
|
+
readonly reason: 'implausible';
|
|
75
|
+
readonly currency: string;
|
|
76
|
+
readonly stored: number;
|
|
77
|
+
readonly reference: number;
|
|
78
|
+
readonly factor: number;
|
|
79
|
+
readonly source: string;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* One locked rate against the reference, in Medusa `classifyRates` order: invalid (null or not
|
|
83
|
+
* a rate) is refused `invalid`; no reference is unverifiable `no_reference`; no positive
|
|
84
|
+
* reference for the currency is unverifiable `no_pair`; a deviation strictly above
|
|
85
|
+
* `maxDeviation` (default 2) is refused `implausible`; else plausible.
|
|
86
|
+
*/
|
|
87
|
+
export declare function classifyRate(r: Rate | null, code: string, reference: RateReference | null, options?: {
|
|
88
|
+
maxDeviation?: number;
|
|
89
|
+
}): RateClassification;
|
|
90
|
+
/**
|
|
91
|
+
* The storage factor confirmed by the store's own prices (Medusa `chooseFactor`): the
|
|
92
|
+
* candidates `[c, c / 100, c x 100]` against the upper median of the finite positive observed
|
|
93
|
+
* ratios; the first within `tolerance` (default 0.02) wins, none gives null. No observations
|
|
94
|
+
* trusts `conventional`.
|
|
95
|
+
*/
|
|
96
|
+
export declare function confirmStoredFactor(conventional: Rate, observedRatios: readonly number[], options?: {
|
|
97
|
+
tolerance?: number;
|
|
98
|
+
}): Rate | null;
|
|
99
|
+
/**
|
|
100
|
+
* The upper median of `rates` and which of them lie within `tolerance` (default 0.01) of it:
|
|
101
|
+
* accepted iff `|r / median - 1| <= tolerance`, exactly. No rates: `{ median: null, accepted: [] }`.
|
|
102
|
+
*/
|
|
103
|
+
export declare function rateConsensus(rates: readonly Rate[], options?: {
|
|
104
|
+
tolerance?: number;
|
|
105
|
+
}): {
|
|
106
|
+
median: Rate | null;
|
|
107
|
+
accepted: boolean[];
|
|
108
|
+
};
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/fx/settings.d.ts
|
|
111
|
+
export declare const RATE_MODES: readonly ["manual", "dynamic"];
|
|
112
|
+
export declare const PRICE_ROUNDINGS: readonly ["none", "nearest"];
|
|
113
|
+
/** `store_currency_rate.rate_mode` as readers coerce it: `'manual'` exactly, else `'dynamic'`. */
|
|
114
|
+
export declare function parseRateMode(value: unknown): (typeof RATE_MODES)[number];
|
|
115
|
+
/** `store_currency_rate.rounding` as readers coerce it: `'nearest'` exactly, else `'none'`. */
|
|
116
|
+
export declare function parsePriceRounding(value: unknown): (typeof PRICE_ROUNDINGS)[number];
|
|
117
|
+
type MoneyByCurrencyFallback = {
|
|
118
|
+
readonly kind: 'refuse';
|
|
119
|
+
} | {
|
|
120
|
+
readonly kind: 'major';
|
|
121
|
+
readonly amount: DecimalText | number;
|
|
122
|
+
} | {
|
|
123
|
+
readonly kind: 'convert';
|
|
124
|
+
readonly from: string;
|
|
125
|
+
readonly rate: Rate;
|
|
126
|
+
readonly retail?: RetailRounding;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* The amount a per-currency setting holds for `currency`: the listed entry, else the explicit
|
|
130
|
+
* fallback: `'refuse'` gives null; `'major'` is that many major units of `currency` itself
|
|
131
|
+
* (the store-credit cap `{ kind: 'major', amount: '15000' }`); `'convert'` converts the
|
|
132
|
+
* `from` entry at `rate` (null when there is no `from` entry). Never a silent default.
|
|
133
|
+
*/
|
|
134
|
+
export declare function resolveMoneyByCurrency(setting: MoneyByCurrency, currency: string, options: {
|
|
135
|
+
fallback: MoneyByCurrencyFallback;
|
|
136
|
+
}): {
|
|
137
|
+
money: Money;
|
|
138
|
+
source: 'listed' | 'fallback';
|
|
139
|
+
} | null;
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region src/fx/tables.d.ts
|
|
142
|
+
/** 1 USD = rate units of the currency, exact (see data/pegs.ts for the sources). Upper-case keys. */
|
|
143
|
+
export declare const USD_PEGS: Readonly<Record<string, Rate>>;
|
|
144
|
+
/** A feed's rate table with lower-case keys and only finite positive numbers kept (Medusa `lowerKeys`). Never throws. */
|
|
145
|
+
export declare function sanitizeRateTable(raw: unknown): Record<string, number>;
|
|
146
|
+
/** `{ ...fallback, ...primary }`: the primary feed (ECB) wins every currency it publishes. */
|
|
147
|
+
export declare function mergeRateTables(primary: Readonly<Record<string, number>>, fallback: Readonly<Record<string, number>>): Record<string, number>;
|
|
148
|
+
/**
|
|
149
|
+
* The rate 1 `from` = ? `to` when the live pair is unavailable, through the USD pegs
|
|
150
|
+
* (orch `resolveRateMajor`): a pegged `to` gives the peg from USD, else `(from -> USD) x peg`
|
|
151
|
+
* with `from -> USD` read from `ratesPerUsd` (units per 1 USD, any key case) or from `from`'s
|
|
152
|
+
* own peg; a pegged `from` into USD gives the inverse peg (new, symmetric). The same code
|
|
153
|
+
* gives 1/1; anything else null.
|
|
154
|
+
*/
|
|
155
|
+
export declare function pegFallback(from: string, to: string, ratesPerUsd: Readonly<Record<string, number>>, pegs?: Readonly<Record<string, Rate>>): Rate | null;
|
|
156
|
+
//#endregion
|
|
157
|
+
export { type ConvertOptions, type FactorTable, type MoneyByCurrencyFallback, RATE_BOUNDS, RATE_REF, type Rate, type RateClassification, type RateFromDecimalOptions, type RateReference, type RateRow, type ReportingTotal, type RetailRounding, crossRate, invertRate, priceRoundingParams, rate, rateEquals, rateFromDecimal, rateFromRow, rateToDecimal, rateToNumber, roundRetail, storeFactors, toReporting };
|