Add a supplementary rate feed for currencies the ECB lacks (e.g. ALL)

The server also fetches ExchangeRate-API's free EUR-based endpoint
(RATES_EXTRA_URL, empty = off), stored apart from ECB rates; ECB always wins
for a currency both publish. /api/rates returns sources for supplementary
rates, expenses record them as xr:<date>, and the editor shows the required
attribution link. Snapshots older than a week before the requested date are
not used.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HA82gVKYyo9BHLHPW4qr4x
This commit is contained in:
agent 2026-11-06 18:13:31 +00:00
parent 6b0c80bb50
commit 62c19192a7
13 changed files with 160 additions and 27 deletions

22
SPEC.md
View file

@ -156,7 +156,7 @@ entity fully defines it. Conflicts resolve **last-writer-wins by server
"currency": "EUR",
"amount": 12050, // 120.50 EUR
"rate": "25.214", // decimal string: 1 EUR = 25.214 base; "1" if same currency
"rateSource": "ecb:2026-10-08", // or "manual"
"rateSource": "ecb:2026-10-08", // or "xr:<date>", "manual" (see 8.2)
"payers": [ { "member": "m1", "amount": 12050 } ], // sums to amount
"split": {
"mode": "equal", // equal | shares | exact | percent
@ -370,9 +370,27 @@ which group ids exist.
ECB's own XML feed) every 6 hours and caches them in SQLite. The first run
loads the full history (back to 1999) for back-dated expenses; later runs
fetch the last 90 days.
- For currencies the ECB doesn't publish (e.g. ALL), the server also fetches
a **supplementary EUR-based feed** on the same schedule: ExchangeRate-API's
free endpoint (`RATES_EXTRA_URL`, default
`https://open.er-api.com/v6/latest/EUR`; empty turns it off). It has no
history, so its daily snapshots accumulate from when the server starts
fetching them; one older than a week before the requested date is not
used. It is stored apart from the ECB rates, and **the ECB rate always wins**
for a currency both publish. `GET /api/rates` merges the two and returns
`sources: { CODE: "xr:<date>" }` for every supplementary rate.
- An expense's `rateSource` is `ecb:<date>`, or `xr:<date>` when either side
of the conversion came from the supplementary feed. The editor labels `xr:`
rates with a link to exchangerate-api.com (the free tier's attribution
requirement).
- Clients fetch from our server only, so third parties don't learn users' IPs
or currency usage. Clients cache rates offline.
- Currencies outside the ECB set can be used with a manually entered rate.
- The currency picker offers only **ISO 4217 currencies in circulation**
(`ACTIVE_CURRENCIES` in `packages/core/src/currencies.ts`, hand-maintained;
browsers' `Intl.supportedValuesOf('currency')` includes long-gone codes).
Those with a daily rate come first; the rest can be used with a manually
entered rate. A group or recent currency that has since been withdrawn
stays selectable.
- Behind an interface so a paid intraday provider can be swapped in later.
### 8.3 Storage and limits