Daily European Central Bank web‑scraper that extracts FX rates, computes cross rates, and stores them in Firestore. Exposed as an HTTP Cloud Function (main).
- Node.js 22 (see
.nvmrc). If your shell selects a different version, runnvm use. - PNPM as the package manager (recommend
corepack enable && corepack install).
pnpm install- Build:
pnpm compile(TypeScript →index.js). - Lint/format:
pnpm lint,pnpm format(usepnpm lint --fixto auto‑fix). - Start locally:
GCP_PROJECT_ID=forex-api-daily pnpm start(Functions Framework onhttp://localhost:8081/main). - Test:
pnpm test(runs Vitest; may use Firestore emulator if configured). If you hit PNPM migration issues with lifecycle scripts, run build/lint directly and let us know to update scripts. - Start Firestore emulator:
pnpm start-db(runs onhttp://localhost:8080).
- Fetch: Scrapes ECB RSS endpoints to gather daily EUR base rates.
- Process: Combines latest day’s rates and derives cross rates for other bases.
- Store: Writes documents to the
exchange_ratescollection; periodically removes stale dates. After storing new rates, writes the list of available currency symbols to per-date documents under thesymbolscollection (e.g.symbols/2025-12-05) for efficient client lookups.
Each run stores a symbols/{YYYY-MM-DD} document (e.g. symbols/2025-12-05) containing the base currency codes available for that date:
{ "date": "2025-12-05", "symbols": ["AUD", "BGN", "BRL", "..."] }To retrieve the latest available symbols, query the symbols collection ordered by date descending and take the first document:
const snapshot = await db.collection('symbols').orderBy('date', 'desc').limit(1).get();
if (!snapshot.empty) {
const { date, symbols } = snapshot.docs[0].data();
}- GitHub Actions (
.github/workflows/ci.yml) runs tests on push. Deploys frommainto Cloud Functions using repo secrets for GCP.
- Do not commit credentials. Files like
.envandservice-account.jsonare ignored by Git. - The compiled
index.jsis generated; avoid committing build artifacts.