@allratestoday/exchange-plugins 1.0.1 → 1.0.2
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 +1 -1
- package/dist/allratestoday-exchange-plugins.global.js.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ Please see [src/index.ts](./src/index.ts) for the list of plugins in this repo.
|
|
|
17
17
|
|
|
18
18
|
- **One interface, many sources** — `fetchRates(hints)` on every plugin; unanswered pairs are left out, never thrown.
|
|
19
19
|
- **Keyless by default** — the reference rate and every central-bank table work without an API key.
|
|
20
|
-
- **Live rates with a key** — `allratestoday` adds real-time mid-market rates (free tier
|
|
20
|
+
- **Live rates with a key** — `allratestoday` adds real-time mid-market rates (free tier, no card).
|
|
21
21
|
- **Pairs the institution never published** — inverted or crossed through its home currency, and the answer says which (`method: 'published' | 'inverse' | 'cross'`).
|
|
22
22
|
- **Ordered fallback** — `makeRateEngine([...])` asks plugins in order and stops at the first answer per pair.
|
|
23
23
|
- **Zero runtime dependencies**, ESM + CommonJS + a self-registering browser bundle, strict TypeScript types.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/browser.ts","../src/http.ts","../src/plugins/allratestoday.ts","../src/table.ts","../src/plugins/centralBank.ts","../src/plugins/referenceRate.ts","../src/engine.ts","../src/index.ts"],"sourcesContent":["import * as api from './index';\n\n/**\n * Browser bundle. Loading `dist/allratestoday-exchange-plugins.global.js` exposes\n * `window.allratestodayExchangePlugins` and, if the page defined\n * `window.addAllRatesTodayPlugins` before the script ran, calls it with the\n * plugin map (the same hand-off edge-exchange-plugins makes to edge-core-js).\n */\ndeclare global {\n interface Window {\n addAllRatesTodayPlugins?: (plugins: typeof api.plugins) => void;\n }\n}\n\nif (typeof window !== 'undefined' && typeof window.addAllRatesTodayPlugins === 'function') {\n window.addAllRatesTodayPlugins(api.plugins);\n}\n\nexport * from './index';\n","import type { PluginOptions } from './types';\n\nexport const DEFAULT_BASE_URL = 'https://allratestoday.com';\n\nexport class ExchangePluginError extends Error {\n readonly status: number;\n readonly body: unknown;\n constructor(message: string, status: number, body: unknown) {\n super(message);\n this.name = 'ExchangePluginError';\n this.status = status;\n this.body = body;\n }\n}\n\nexport interface Http {\n getJson: (path: string, params?: Record<string, string>, requireKey?: boolean) => Promise<unknown>;\n hasKey: boolean;\n}\n\nexport function makeHttp(options: PluginOptions = {}): Http {\n const base = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/$/, '');\n const doFetch = options.fetch ?? globalThis.fetch;\n if (typeof doFetch !== 'function') {\n throw new Error('No fetch available: pass { fetch } in the plugin options');\n }\n const timeoutMs = options.timeoutMs ?? 10_000;\n const apiKey = options.apiKey;\n\n return {\n hasKey: typeof apiKey === 'string' && apiKey.length > 0,\n async getJson(path, params = {}, requireKey = false) {\n if (requireKey && !apiKey) {\n throw new ExchangePluginError(`${path} needs an API key`, 401, null);\n }\n const url = new URL(base + path);\n for (const [k, v] of Object.entries(params)) if (v !== '') url.searchParams.set(k, v);\n const headers: Record<string, string> = {\n Accept: 'application/json',\n 'User-Agent': '@allratestoday/exchange-plugins',\n };\n if (apiKey) headers.Authorization = `Bearer ${apiKey}`;\n const controller = typeof AbortController === 'function' ? new AbortController() : undefined;\n const timer = controller ? setTimeout(() => controller.abort(), timeoutMs) : undefined;\n try {\n const res = await doFetch(url.toString(), { headers, signal: controller?.signal });\n const text = await res.text();\n let body: unknown = null;\n try {\n body = text ? JSON.parse(text) : null;\n } catch {\n body = text;\n }\n if (!res.ok) {\n const msg =\n body && typeof body === 'object' && 'error' in body\n ? String((body as { error: unknown }).error)\n : `HTTP ${res.status}`;\n throw new ExchangePluginError(msg, res.status, body);\n }\n return body;\n } finally {\n if (timer) clearTimeout(timer);\n }\n },\n };\n}\n","import { makeHttp } from '../http';\nimport type { PluginOptions, RatePair, RatePlugin } from '../types';\n\ninterface LiveRate {\n rate: number;\n source: string;\n target: string;\n time: string;\n}\n\n/**\n * Live mid-market rates from `GET /api/v1/rates`. Needs an API key (the free\n * tier is 300 requests, no card). Answers only undated hints; dated hints are\n * left for the reference-rate or central-bank plugins.\n */\nexport const makeAllRatesTodayPlugin = (options: PluginOptions = {}): RatePlugin => {\n const http = makeHttp(options);\n return {\n rateInfo: {\n pluginId: 'allratestoday',\n displayName: 'AllRatesToday live mid-market',\n keyless: false,\n homepage: 'https://allratestoday.com/docs/',\n },\n async fetchRates(hints) {\n if (!http.hasKey) return [];\n const bySource = new Map<string, Set<string>>();\n for (const h of hints) {\n if (h.date) continue;\n const from = h.fromCurrency.toUpperCase();\n const to = h.toCurrency.toUpperCase();\n if (from === to) continue;\n const set = bySource.get(from) ?? new Set<string>();\n set.add(to);\n bySource.set(from, set);\n }\n const out: RatePair[] = [];\n await Promise.all(\n [...bySource].map(async ([source, targets]) => {\n let raw: unknown;\n try {\n raw = await http.getJson('/api/v1/rates', { source, target: [...targets].join(',') }, true);\n } catch {\n return;\n }\n const rows: LiveRate[] = Array.isArray(raw) ? raw : raw ? [raw as LiveRate] : [];\n for (const r of rows) {\n if (typeof r?.rate !== 'number' || !r.target) continue;\n out.push({\n fromCurrency: source,\n toCurrency: r.target.toUpperCase(),\n rate: r.rate,\n date: (r.time ?? new Date().toISOString()).slice(0, 10),\n pluginId: 'allratestoday',\n rateType: 'mid-market',\n method: 'published',\n });\n }\n }),\n );\n for (const h of hints) {\n if (h.date) continue;\n const from = h.fromCurrency.toUpperCase();\n if (from === h.toCurrency.toUpperCase()) {\n out.push({ fromCurrency: from, toCurrency: from, rate: 1, date: new Date().toISOString().slice(0, 10), pluginId: 'allratestoday', rateType: 'mid-market', method: 'published' });\n }\n }\n return out;\n },\n };\n};\n","import type { RateHint, RateMethod, RatePair } from './types';\n\n/** One row of a published table: `value` units of `quote` per 1 `base`. */\nexport interface TableRow {\n base: string;\n quote: string;\n value: number;\n type: string;\n}\n\nconst round = (n: number): number => Number(n.toPrecision(12));\n\n/**\n * Resolve a pair from a full table: direct row, inverted row, or a cross\n * through a currency both sides are quoted against. Returns null when the\n * table does not cover the pair.\n */\nexport function resolvePair(\n rows: TableRow[],\n from: string,\n to: string,\n): { rate: number; method: RateMethod; type: string } | null {\n if (from === to) return { rate: 1, method: 'published', type: rows[0]?.type ?? 'reference' };\n const direct = rows.find((r) => r.base === from && r.quote === to && r.value > 0);\n if (direct) return { rate: direct.value, method: 'published', type: direct.type };\n const inverse = rows.find((r) => r.base === to && r.quote === from && r.value > 0);\n if (inverse) return { rate: round(1 / inverse.value), method: 'inverse', type: inverse.type };\n\n // Cross: find a base B with rows B->from and B->to (the usual table shape),\n // or any mix of directions through B.\n const perBase = new Map<string, number>(); // B -> units of `from` per 1 B\n const perBaseTo = new Map<string, number>(); // B -> units of `to` per 1 B\n for (const r of rows) {\n if (r.value <= 0) continue;\n if (r.quote === from) perBase.set(r.base, r.value);\n if (r.base === from) perBase.set(r.quote, round(1 / r.value));\n if (r.quote === to) perBaseTo.set(r.base, r.value);\n if (r.base === to) perBaseTo.set(r.quote, round(1 / r.value));\n }\n for (const [b, fromPerB] of perBase) {\n const toPerB = perBaseTo.get(b);\n if (toPerB !== undefined) {\n const type = rows.find((r) => r.base === b || r.quote === b)?.type ?? 'reference';\n return { rate: round(toPerB / fromPerB), method: 'cross', type };\n }\n }\n return null;\n}\n\nexport function answerFromTable(\n rows: TableRow[],\n hints: RateHint[],\n date: string,\n pluginId: string,\n rateType?: string,\n): RatePair[] {\n const out: RatePair[] = [];\n for (const h of hints) {\n const from = h.fromCurrency.toUpperCase();\n const to = h.toCurrency.toUpperCase();\n const hit = resolvePair(rows, from, to);\n if (!hit) continue;\n out.push({\n fromCurrency: from,\n toCurrency: to,\n rate: hit.rate,\n date,\n pluginId,\n rateType: rateType ?? hit.type,\n method: hit.method,\n });\n }\n return out;\n}\n\n/** Group hints by requested date; `''` holds the \"latest\" hints. */\nexport function groupByDate(hints: RateHint[]): Map<string, RateHint[]> {\n const m = new Map<string, RateHint[]>();\n for (const h of hints) {\n const key = h.date ?? '';\n const list = m.get(key) ?? [];\n list.push(h);\n m.set(key, list);\n }\n return m;\n}\n","import { makeHttp } from '../http';\nimport { answerFromTable, groupByDate, type TableRow } from '../table';\nimport type { PluginOptions, RatePair, RatePlugin } from '../types';\n\ninterface TableResponse {\n bank: string;\n rate_date: string;\n rates: Array<{ base: string; quote: string; type: string; value: number }>;\n}\n\n/**\n * Official exchange-rate tables published by a central bank or tax authority,\n * served by AllRatesToday. The latest table is keyless\n * (`/api/open/central-bank/{bank}`); dated tables\n * (`/api/v1/central-bank/{bank}/{date}`) need a paid key. Pairs the\n * institution does not publish directly are inverted or crossed through its\n * home currency, and the answer says so in `method`.\n *\n * `bank` is an AllRatesToday source code, e.g. `ecb`, `boe`, `rbi`, `hmrc`.\n * The full list is `GET https://allratestoday.com/api/open/central-banks`.\n */\n/** Tax authorities live under a different page base on allratestoday.com. */\nconst TAX_AUTHORITIES = new Set(['hmrc', 'bazg', 'ustreasury']);\n\nexport const makeCentralBankPlugin = (bank: string, options: PluginOptions = {}): RatePlugin => {\n const code = bank.toLowerCase();\n const pageBase = TAX_AUTHORITIES.has(code) ? 'tax-authority-rates-api' : 'central-bank-rates-api';\n const http = makeHttp(options);\n const toRows = (r: TableResponse): TableRow[] =>\n r.rates.map((x) => ({ base: x.base, quote: x.quote, value: x.value, type: x.type }));\n return {\n rateInfo: {\n pluginId: code,\n displayName: `Official rates: ${code.toUpperCase()}`,\n keyless: true,\n homepage: `https://allratestoday.com/${pageBase}/${code}/`,\n },\n async fetchRates(hints) {\n const out: RatePair[] = [];\n await Promise.all(\n [...groupByDate(hints)].map(async ([date, group]) => {\n let raw: TableResponse;\n try {\n raw = (\n date\n ? await http.getJson(`/api/v1/central-bank/${code}/${date}`, {}, true)\n : await http.getJson(`/api/open/central-bank/${code}`)\n ) as TableResponse;\n } catch {\n return;\n }\n if (!raw?.rates?.length) return;\n out.push(...answerFromTable(toRows(raw), group, raw.rate_date, code));\n }),\n );\n return out;\n },\n };\n};\n\n/**\n * Source codes served by AllRatesToday on 2026-10-19 (125). `composite` is the\n * cross-bank USD table. Refresh with `GET /api/open/central-banks`.\n */\nexport const CENTRAL_BANK_CODES = [\n 'amcm', 'bam', 'banguat', 'banxico', 'bazg', 'bb', 'bcb', 'bcbol', 'bcc', 'bcch', 'bccr', 'bccu', 'bceao', 'bch',\n 'bcm', 'bcn', 'bcp', 'bcra', 'bcrd', 'bcrp', 'bcstp', 'bct', 'bcu', 'bcv', 'bda', 'bdi', 'bdm', 'beac', 'bfm', 'bi',\n 'bmu', 'bna', 'bnb', 'bnm', 'bnr', 'bnrw', 'boa', 'bob', 'boc', 'boe', 'bog', 'bogy', 'boi', 'boj', 'bojm', 'bok',\n 'bol', 'bom', 'bon', 'bot', 'botz', 'bou', 'boz', 'brh', 'bsl', 'bsp', 'cba', 'cbar', 'cbb', 'cbbd', 'cbbh', 'cbbz',\n 'cbc', 'cbe', 'cbg', 'cbi', 'cbiq', 'cbj', 'cbk', 'cbke', 'cbl', 'cbm', 'cbn', 'cbo', 'cbr', 'cbsl', 'cbt', 'cbtt',\n 'cbu', 'cbuae', 'cbvs', 'cnb', 'composite', 'dnb', 'ecb', 'fed', 'hkma', 'hmrc', 'lb', 'mas', 'mma', 'mnb', 'nbc',\n 'nbe', 'nbg', 'nbk', 'nbkr', 'nbm', 'nbp', 'nbrb', 'nbrm', 'nbs', 'nbt', 'nbu', 'norges', 'nrb', 'pboc', 'pma',\n 'qcb', 'rba', 'rbf', 'rbi', 'rbm', 'rbnz', 'rbz', 'riksbank', 'rma', 'sama', 'sarb', 'sbp', 'sbv', 'sfc', 'snb',\n 'tcmb', 'ustreasury',\n] as const;\n\nexport type CentralBankCode = (typeof CENTRAL_BANK_CODES)[number];\n\n/** One factory per source, keyed by code: `centralBanks.ecb()`, `centralBanks.boe()`, ... */\nexport const centralBanks = Object.fromEntries(\n CENTRAL_BANK_CODES.map((code) => [code, (options?: PluginOptions) => makeCentralBankPlugin(code, options)]),\n) as Record<CentralBankCode, (options?: PluginOptions) => RatePlugin>;\n","import { makeHttp } from '../http';\nimport { answerFromTable, groupByDate, type TableRow } from '../table';\nimport type { PluginOptions, RatePair, RatePlugin } from '../types';\n\ninterface ReferenceResponse {\n rate_date: string;\n base: string;\n rates: Array<{ base: string; quote: string; value: number }>;\n}\n\n/**\n * The AllRatesToday daily reference rate: one USD-based table a day, fixed at\n * 16:00 London. The latest table is keyless (`/api/open/reference-rate`);\n * dated tables (`/api/v1/reference-rate/{date}`) need an API key. Any pair is\n * crossed through USD.\n */\nexport const makeReferenceRatePlugin = (options: PluginOptions = {}): RatePlugin => {\n const http = makeHttp(options);\n const toRows = (r: ReferenceResponse): TableRow[] =>\n r.rates.map((x) => ({ base: x.base, quote: x.quote, value: x.value, type: 'reference' }));\n return {\n rateInfo: {\n pluginId: 'referenceRate',\n displayName: 'AllRatesToday daily reference rate (16:00 London)',\n keyless: true,\n homepage: 'https://allratestoday.com/reference-rate/',\n },\n async fetchRates(hints) {\n const out: RatePair[] = [];\n await Promise.all(\n [...groupByDate(hints)].map(async ([date, group]) => {\n let raw: ReferenceResponse;\n try {\n raw = (\n date\n ? await http.getJson(`/api/v1/reference-rate/${date}`, {}, true)\n : await http.getJson('/api/open/reference-rate')\n ) as ReferenceResponse;\n } catch {\n return;\n }\n if (!raw?.rates?.length) return;\n out.push(...answerFromTable(toRows(raw), group, raw.rate_date, 'referenceRate', 'reference'));\n }),\n );\n return out;\n },\n };\n};\n","import type { RateHint, RatePair, RatePlugin } from './types';\n\nexport interface RateEngine {\n readonly plugins: RatePlugin[];\n /** Ask each plugin in order; a hint answered by an earlier plugin is not asked again. */\n fetchRates: (hints: RateHint[]) => Promise<RatePair[]>;\n /** One pair, or null when no plugin covers it. */\n getRate: (fromCurrency: string, toCurrency: string, date?: string) => Promise<RatePair | null>;\n /** Convert an amount; throws when no plugin covers the pair. */\n convert: (amount: number, fromCurrency: string, toCurrency: string, date?: string) => Promise<{ amount: number; result: number; pair: RatePair }>;\n}\n\nconst key = (h: RateHint): string =>\n `${h.fromCurrency.toUpperCase()}_${h.toCurrency.toUpperCase()}_${h.date ?? ''}`;\n\n/**\n * Ordered fallback over plugins. Pass the plugins in preference order, e.g.\n * live first, then the daily reference rate, then an official table.\n */\nexport function makeRateEngine(plugins: RatePlugin[] | Record<string, RatePlugin>): RateEngine {\n const list = Array.isArray(plugins) ? plugins : Object.values(plugins);\n return {\n plugins: list,\n async fetchRates(hints) {\n const answered = new Map<string, RatePair>();\n let remaining = hints.slice();\n for (const plugin of list) {\n if (remaining.length === 0) break;\n let pairs: RatePair[] = [];\n try {\n pairs = await plugin.fetchRates(remaining);\n } catch {\n continue;\n }\n for (const p of pairs) {\n const k = `${p.fromCurrency}_${p.toCurrency}_`;\n // Match on the requested date, not the answered one (weekends\n // resolve to the previous business day).\n for (const h of remaining) {\n if (key(h).startsWith(k) && !answered.has(key(h))) answered.set(key(h), p);\n }\n }\n remaining = remaining.filter((h) => !answered.has(key(h)));\n }\n return hints.map((h) => answered.get(key(h))).filter((p): p is RatePair => p != null);\n },\n async getRate(fromCurrency, toCurrency, date) {\n const [pair] = await this.fetchRates([{ fromCurrency, toCurrency, date }]);\n return pair ?? null;\n },\n async convert(amount, fromCurrency, toCurrency, date) {\n const pair = await this.getRate(fromCurrency, toCurrency, date);\n if (!pair) throw new Error(`No plugin covers ${fromCurrency}/${toCurrency}${date ? ` on ${date}` : ''}`);\n return { amount, result: Number((amount * pair.rate).toPrecision(12)), pair };\n },\n };\n}\n","import { makeAllRatesTodayPlugin } from './plugins/allratestoday';\nimport { centralBanks, makeCentralBankPlugin } from './plugins/centralBank';\nimport { makeReferenceRatePlugin } from './plugins/referenceRate';\nimport type { PluginOptions, RatePlugin } from './types';\n\nexport * from './types';\nexport { ExchangePluginError, DEFAULT_BASE_URL } from './http';\nexport { resolvePair, answerFromTable } from './table';\nexport type { TableRow } from './table';\nexport { makeRateEngine } from './engine';\nexport type { RateEngine } from './engine';\nexport { makeAllRatesTodayPlugin } from './plugins/allratestoday';\nexport { makeReferenceRatePlugin } from './plugins/referenceRate';\nexport { makeCentralBankPlugin, centralBanks, CENTRAL_BANK_CODES } from './plugins/centralBank';\nexport type { CentralBankCode } from './plugins/centralBank';\n\n/**\n * Every plugin factory in this package, keyed by pluginId. Mirrors the\n * `plugins` export of edge-exchange-plugins: pick the ones you want, or\n * register them all.\n */\nexport const plugins = {\n // Live:\n allratestoday: makeAllRatesTodayPlugin,\n // Daily reference:\n referenceRate: makeReferenceRatePlugin,\n // Official tables (125 sources):\n ...centralBanks,\n};\n\nexport type PluginId = keyof typeof plugins;\n\n/**\n * Instantiate a set of plugins with shared options. Pass ids in preference\n * order; the result is ready for `makeRateEngine`.\n */\nexport function makePlugins(ids: PluginId[], options: PluginOptions = {}): RatePlugin[] {\n return ids.map((id) => {\n const factory = plugins[id];\n if (!factory) throw new Error(`Unknown plugin: ${id}`);\n return factory(options);\n });\n}\n\n/** The recommended default stack: live when a key is set, then reference rate, then the composite table. */\nexport function makeDefaultPlugins(options: PluginOptions = {}): RatePlugin[] {\n const list: RatePlugin[] = [];\n if (options.apiKey) list.push(makeAllRatesTodayPlugin(options));\n list.push(makeReferenceRatePlugin(options), makeCentralBankPlugin('composite', options));\n return list;\n}\n\nexport default plugins;\n"],"mappings":"gdAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wBAAAE,EAAA,qBAAAC,EAAA,wBAAAC,EAAA,oBAAAC,EAAA,iBAAAC,EAAA,4BAAAC,EAAA,0BAAAC,EAAA,uBAAAC,EAAA,gBAAAC,EAAA,mBAAAC,EAAA,4BAAAC,EAAA,YAAAC,EAAA,gBAAAC,ICEO,IAAMC,EAAmB,4BAEnBC,EAAN,cAAkC,KAAM,CAG7C,YAAYC,EAAiBC,EAAgBC,EAAe,CAC1D,MAAMF,CAAO,EACb,KAAK,KAAO,sBACZ,K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QH,EAAcC,EAAYC,CAAI,EAC9D,GAAI,CAACC,EAAM,MAAM,IAAI,MAAM,oBAAoBH,CAAY,IAAIC,CAAU,GAAGC,EAAO,OAAOA,CAAI,GAAK,EAAE,EAAE,EACvG,MAAO,CAAE,OAAAE,EAAQ,OAAQ,QAAQA,EAASD,EAAK,MAAM,YAAY,EAAE,CAAC,EAAG,KAAAA,CAAK,CAC9E,CACF,CACF,CCnCO,IAAME,EAAU,CAErB,cAAeC,EAEf,cAAeC,EAEf,GAAGC,CACL,EAQO,SAASC,EAAYC,EAAiBC,EAAyB,CAAC,EAAiB,CACtF,OAAOD,EAAI,IAAKE,GAAO,CACrB,IAAMC,EAAUR,EAAQO,CAAE,EAC1B,GAAI,CAACC,EAAS,MAAM,IAAI,MAAM,mBAAmBD,CAAE,EAAE,EACrD,OAAOC,EAAQF,CAAO,CACxB,CAAC,CACH,CAGO,SAASG,EAAmBH,EAAyB,CAAC,EAAiB,CAC5E,IAAMI,EAAqB,CAAC,EAC5B,OAAIJ,EAAQ,QAAQI,EAAK,KAAKT,EAAwBK,CAAO,CAAC,EAC9DI,EAAK,KAAKR,EAAwBI,CAAO,EAAGK,EAAsB,YAAaL,CAAO,CAAC,EAChFI,CACT,CPpCI,OAAO,OAAW,KAAe,OAAO,OAAO,yBAA4B,YAC7E,OAAO,wBAA4BE,CAAO","names":["browser_exports","__export","CENTRAL_BANK_CODES","DEFAULT_BASE_URL","ExchangePluginError","answerFromTable","centralBanks","makeAllRatesTodayPlugin","makeCentralBankPlugin","makeDefaultPlugins","makePlugins","makeRateEngine","makeReferenceRatePlugin","plugins","resolvePair","DEFAULT_BASE_URL","ExchangePluginError","message","status","body","makeHttp","options","base","doFetch","timeoutMs","apiKey","path","params","requireKey","url","k","v","headers","controller","timer","res","text","msg","makeAllRatesTodayPlugin","options","http","makeHttp","hints","bySource","h","from","to","set","out","source","targets","raw","rows","r","round","n","resolvePair","rows","from","to","direct","r","inverse","perBase","perBaseTo","b","fromPerB","toPerB","type","answerFromTable","hints","date","pluginId","rateType","out","h","hit","groupByDate","m","key","list","TAX_AUTHORITIES","makeCentralBankPlugin","bank","options","code","pageBase","http","makeHttp","toRows","r","x","hints","out","groupByDate","date","group","raw","answerFromTable","CENTRAL_BANK_CODES","centralBanks","makeReferenceRatePlugin","options","http","makeHttp","toRows","r","x","hints","out","groupByDate","date","group","raw","answerFromTable","key","h","makeRateEngine","plugins","list","hints","answered","remaining","plugin","pairs","p","k","fromCurrency","toCurrency","date","pair","amount","plugins","makeAllRatesTodayPlugin","makeReferenceRatePlugin","centralBanks","makePlugins","ids","options","id","factory","makeDefaultPlugins","list","makeCentralBankPlugin","plugins"]}
|
|
1
|
+
{"version":3,"sources":["../src/browser.ts","../src/http.ts","../src/plugins/allratestoday.ts","../src/table.ts","../src/plugins/centralBank.ts","../src/plugins/referenceRate.ts","../src/engine.ts","../src/index.ts"],"sourcesContent":["import * as api from './index';\n\n/**\n * Browser bundle. Loading `dist/allratestoday-exchange-plugins.global.js` exposes\n * `window.allratestodayExchangePlugins` and, if the page defined\n * `window.addAllRatesTodayPlugins` before the script ran, calls it with the\n * plugin map (the same hand-off edge-exchange-plugins makes to edge-core-js).\n */\ndeclare global {\n interface Window {\n addAllRatesTodayPlugins?: (plugins: typeof api.plugins) => void;\n }\n}\n\nif (typeof window !== 'undefined' && typeof window.addAllRatesTodayPlugins === 'function') {\n window.addAllRatesTodayPlugins(api.plugins);\n}\n\nexport * from './index';\n","import type { PluginOptions } from './types';\n\nexport const DEFAULT_BASE_URL = 'https://allratestoday.com';\n\nexport class ExchangePluginError extends Error {\n readonly status: number;\n readonly body: unknown;\n constructor(message: string, status: number, body: unknown) {\n super(message);\n this.name = 'ExchangePluginError';\n this.status = status;\n this.body = body;\n }\n}\n\nexport interface Http {\n getJson: (path: string, params?: Record<string, string>, requireKey?: boolean) => Promise<unknown>;\n hasKey: boolean;\n}\n\nexport function makeHttp(options: PluginOptions = {}): Http {\n const base = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/$/, '');\n const doFetch = options.fetch ?? globalThis.fetch;\n if (typeof doFetch !== 'function') {\n throw new Error('No fetch available: pass { fetch } in the plugin options');\n }\n const timeoutMs = options.timeoutMs ?? 10_000;\n const apiKey = options.apiKey;\n\n return {\n hasKey: typeof apiKey === 'string' && apiKey.length > 0,\n async getJson(path, params = {}, requireKey = false) {\n if (requireKey && !apiKey) {\n throw new ExchangePluginError(`${path} needs an API key`, 401, null);\n }\n const url = new URL(base + path);\n for (const [k, v] of Object.entries(params)) if (v !== '') url.searchParams.set(k, v);\n const headers: Record<string, string> = {\n Accept: 'application/json',\n 'User-Agent': '@allratestoday/exchange-plugins',\n };\n if (apiKey) headers.Authorization = `Bearer ${apiKey}`;\n const controller = typeof AbortController === 'function' ? new AbortController() : undefined;\n const timer = controller ? setTimeout(() => controller.abort(), timeoutMs) : undefined;\n try {\n const res = await doFetch(url.toString(), { headers, signal: controller?.signal });\n const text = await res.text();\n let body: unknown = null;\n try {\n body = text ? JSON.parse(text) : null;\n } catch {\n body = text;\n }\n if (!res.ok) {\n const msg =\n body && typeof body === 'object' && 'error' in body\n ? String((body as { error: unknown }).error)\n : `HTTP ${res.status}`;\n throw new ExchangePluginError(msg, res.status, body);\n }\n return body;\n } finally {\n if (timer) clearTimeout(timer);\n }\n },\n };\n}\n","import { makeHttp } from '../http';\nimport type { PluginOptions, RatePair, RatePlugin } from '../types';\n\ninterface LiveRate {\n rate: number;\n source: string;\n target: string;\n time: string;\n}\n\n/**\n * Live mid-market rates from `GET /api/v1/rates`. Needs an API key (the free\n * tier needs no card). Answers only undated hints; dated hints are\n * left for the reference-rate or central-bank plugins.\n */\nexport const makeAllRatesTodayPlugin = (options: PluginOptions = {}): RatePlugin => {\n const http = makeHttp(options);\n return {\n rateInfo: {\n pluginId: 'allratestoday',\n displayName: 'AllRatesToday live mid-market',\n keyless: false,\n homepage: 'https://allratestoday.com/docs/',\n },\n async fetchRates(hints) {\n if (!http.hasKey) return [];\n const bySource = new Map<string, Set<string>>();\n for (const h of hints) {\n if (h.date) continue;\n const from = h.fromCurrency.toUpperCase();\n const to = h.toCurrency.toUpperCase();\n if (from === to) continue;\n const set = bySource.get(from) ?? new Set<string>();\n set.add(to);\n bySource.set(from, set);\n }\n const out: RatePair[] = [];\n await Promise.all(\n [...bySource].map(async ([source, targets]) => {\n let raw: unknown;\n try {\n raw = await http.getJson('/api/v1/rates', { source, target: [...targets].join(',') }, true);\n } catch {\n return;\n }\n const rows: LiveRate[] = Array.isArray(raw) ? raw : raw ? [raw as LiveRate] : [];\n for (const r of rows) {\n if (typeof r?.rate !== 'number' || !r.target) continue;\n out.push({\n fromCurrency: source,\n toCurrency: r.target.toUpperCase(),\n rate: r.rate,\n date: (r.time ?? new Date().toISOString()).slice(0, 10),\n pluginId: 'allratestoday',\n rateType: 'mid-market',\n method: 'published',\n });\n }\n }),\n );\n for (const h of hints) {\n if (h.date) continue;\n const from = h.fromCurrency.toUpperCase();\n if (from === h.toCurrency.toUpperCase()) {\n out.push({ fromCurrency: from, toCurrency: from, rate: 1, date: new Date().toISOString().slice(0, 10), pluginId: 'allratestoday', rateType: 'mid-market', method: 'published' });\n }\n }\n return out;\n },\n };\n};\n","import type { RateHint, RateMethod, RatePair } from './types';\n\n/** One row of a published table: `value` units of `quote` per 1 `base`. */\nexport interface TableRow {\n base: string;\n quote: string;\n value: number;\n type: string;\n}\n\nconst round = (n: number): number => Number(n.toPrecision(12));\n\n/**\n * Resolve a pair from a full table: direct row, inverted row, or a cross\n * through a currency both sides are quoted against. Returns null when the\n * table does not cover the pair.\n */\nexport function resolvePair(\n rows: TableRow[],\n from: string,\n to: string,\n): { rate: number; method: RateMethod; type: string } | null {\n if (from === to) return { rate: 1, method: 'published', type: rows[0]?.type ?? 'reference' };\n const direct = rows.find((r) => r.base === from && r.quote === to && r.value > 0);\n if (direct) return { rate: direct.value, method: 'published', type: direct.type };\n const inverse = rows.find((r) => r.base === to && r.quote === from && r.value > 0);\n if (inverse) return { rate: round(1 / inverse.value), method: 'inverse', type: inverse.type };\n\n // Cross: find a base B with rows B->from and B->to (the usual table shape),\n // or any mix of directions through B.\n const perBase = new Map<string, number>(); // B -> units of `from` per 1 B\n const perBaseTo = new Map<string, number>(); // B -> units of `to` per 1 B\n for (const r of rows) {\n if (r.value <= 0) continue;\n if (r.quote === from) perBase.set(r.base, r.value);\n if (r.base === from) perBase.set(r.quote, round(1 / r.value));\n if (r.quote === to) perBaseTo.set(r.base, r.value);\n if (r.base === to) perBaseTo.set(r.quote, round(1 / r.value));\n }\n for (const [b, fromPerB] of perBase) {\n const toPerB = perBaseTo.get(b);\n if (toPerB !== undefined) {\n const type = rows.find((r) => r.base === b || r.quote === b)?.type ?? 'reference';\n return { rate: round(toPerB / fromPerB), method: 'cross', type };\n }\n }\n return null;\n}\n\nexport function answerFromTable(\n rows: TableRow[],\n hints: RateHint[],\n date: string,\n pluginId: string,\n rateType?: string,\n): RatePair[] {\n const out: RatePair[] = [];\n for (const h of hints) {\n const from = h.fromCurrency.toUpperCase();\n const to = h.toCurrency.toUpperCase();\n const hit = resolvePair(rows, from, to);\n if (!hit) continue;\n out.push({\n fromCurrency: from,\n toCurrency: to,\n rate: hit.rate,\n date,\n pluginId,\n rateType: rateType ?? hit.type,\n method: hit.method,\n });\n }\n return out;\n}\n\n/** Group hints by requested date; `''` holds the \"latest\" hints. */\nexport function groupByDate(hints: RateHint[]): Map<string, RateHint[]> {\n const m = new Map<string, RateHint[]>();\n for (const h of hints) {\n const key = h.date ?? '';\n const list = m.get(key) ?? [];\n list.push(h);\n m.set(key, list);\n }\n return m;\n}\n","import { makeHttp } from '../http';\nimport { answerFromTable, groupByDate, type TableRow } from '../table';\nimport type { PluginOptions, RatePair, RatePlugin } from '../types';\n\ninterface TableResponse {\n bank: string;\n rate_date: string;\n rates: Array<{ base: string; quote: string; type: string; value: number }>;\n}\n\n/**\n * Official exchange-rate tables published by a central bank or tax authority,\n * served by AllRatesToday. The latest table is keyless\n * (`/api/open/central-bank/{bank}`); dated tables\n * (`/api/v1/central-bank/{bank}/{date}`) need a paid key. Pairs the\n * institution does not publish directly are inverted or crossed through its\n * home currency, and the answer says so in `method`.\n *\n * `bank` is an AllRatesToday source code, e.g. `ecb`, `boe`, `rbi`, `hmrc`.\n * The full list is `GET https://allratestoday.com/api/open/central-banks`.\n */\n/** Tax authorities live under a different page base on allratestoday.com. */\nconst TAX_AUTHORITIES = new Set(['hmrc', 'bazg', 'ustreasury']);\n\nexport const makeCentralBankPlugin = (bank: string, options: PluginOptions = {}): RatePlugin => {\n const code = bank.toLowerCase();\n const pageBase = TAX_AUTHORITIES.has(code) ? 'tax-authority-rates-api' : 'central-bank-rates-api';\n const http = makeHttp(options);\n const toRows = (r: TableResponse): TableRow[] =>\n r.rates.map((x) => ({ base: x.base, quote: x.quote, value: x.value, type: x.type }));\n return {\n rateInfo: {\n pluginId: code,\n displayName: `Official rates: ${code.toUpperCase()}`,\n keyless: true,\n homepage: `https://allratestoday.com/${pageBase}/${code}/`,\n },\n async fetchRates(hints) {\n const out: RatePair[] = [];\n await Promise.all(\n [...groupByDate(hints)].map(async ([date, group]) => {\n let raw: TableResponse;\n try {\n raw = (\n date\n ? await http.getJson(`/api/v1/central-bank/${code}/${date}`, {}, true)\n : await http.getJson(`/api/open/central-bank/${code}`)\n ) as TableResponse;\n } catch {\n return;\n }\n if (!raw?.rates?.length) return;\n out.push(...answerFromTable(toRows(raw), group, raw.rate_date, code));\n }),\n );\n return out;\n },\n };\n};\n\n/**\n * Source codes served by AllRatesToday on 2026-10-19 (125). `composite` is the\n * cross-bank USD table. Refresh with `GET /api/open/central-banks`.\n */\nexport const CENTRAL_BANK_CODES = [\n 'amcm', 'bam', 'banguat', 'banxico', 'bazg', 'bb', 'bcb', 'bcbol', 'bcc', 'bcch', 'bccr', 'bccu', 'bceao', 'bch',\n 'bcm', 'bcn', 'bcp', 'bcra', 'bcrd', 'bcrp', 'bcstp', 'bct', 'bcu', 'bcv', 'bda', 'bdi', 'bdm', 'beac', 'bfm', 'bi',\n 'bmu', 'bna', 'bnb', 'bnm', 'bnr', 'bnrw', 'boa', 'bob', 'boc', 'boe', 'bog', 'bogy', 'boi', 'boj', 'bojm', 'bok',\n 'bol', 'bom', 'bon', 'bot', 'botz', 'bou', 'boz', 'brh', 'bsl', 'bsp', 'cba', 'cbar', 'cbb', 'cbbd', 'cbbh', 'cbbz',\n 'cbc', 'cbe', 'cbg', 'cbi', 'cbiq', 'cbj', 'cbk', 'cbke', 'cbl', 'cbm', 'cbn', 'cbo', 'cbr', 'cbsl', 'cbt', 'cbtt',\n 'cbu', 'cbuae', 'cbvs', 'cnb', 'composite', 'dnb', 'ecb', 'fed', 'hkma', 'hmrc', 'lb', 'mas', 'mma', 'mnb', 'nbc',\n 'nbe', 'nbg', 'nbk', 'nbkr', 'nbm', 'nbp', 'nbrb', 'nbrm', 'nbs', 'nbt', 'nbu', 'norges', 'nrb', 'pboc', 'pma',\n 'qcb', 'rba', 'rbf', 'rbi', 'rbm', 'rbnz', 'rbz', 'riksbank', 'rma', 'sama', 'sarb', 'sbp', 'sbv', 'sfc', 'snb',\n 'tcmb', 'ustreasury',\n] as const;\n\nexport type CentralBankCode = (typeof CENTRAL_BANK_CODES)[number];\n\n/** One factory per source, keyed by code: `centralBanks.ecb()`, `centralBanks.boe()`, ... */\nexport const centralBanks = Object.fromEntries(\n CENTRAL_BANK_CODES.map((code) => [code, (options?: PluginOptions) => makeCentralBankPlugin(code, options)]),\n) as Record<CentralBankCode, (options?: PluginOptions) => RatePlugin>;\n","import { makeHttp } from '../http';\nimport { answerFromTable, groupByDate, type TableRow } from '../table';\nimport type { PluginOptions, RatePair, RatePlugin } from '../types';\n\ninterface ReferenceResponse {\n rate_date: string;\n base: string;\n rates: Array<{ base: string; quote: string; value: number }>;\n}\n\n/**\n * The AllRatesToday daily reference rate: one USD-based table a day, fixed at\n * 16:00 London. The latest table is keyless (`/api/open/reference-rate`);\n * dated tables (`/api/v1/reference-rate/{date}`) need an API key. Any pair is\n * crossed through USD.\n */\nexport const makeReferenceRatePlugin = (options: PluginOptions = {}): RatePlugin => {\n const http = makeHttp(options);\n const toRows = (r: ReferenceResponse): TableRow[] =>\n r.rates.map((x) => ({ base: x.base, quote: x.quote, value: x.value, type: 'reference' }));\n return {\n rateInfo: {\n pluginId: 'referenceRate',\n displayName: 'AllRatesToday daily reference rate (16:00 London)',\n keyless: true,\n homepage: 'https://allratestoday.com/reference-rate/',\n },\n async fetchRates(hints) {\n const out: RatePair[] = [];\n await Promise.all(\n [...groupByDate(hints)].map(async ([date, group]) => {\n let raw: ReferenceResponse;\n try {\n raw = (\n date\n ? await http.getJson(`/api/v1/reference-rate/${date}`, {}, true)\n : await http.getJson('/api/open/reference-rate')\n ) as ReferenceResponse;\n } catch {\n return;\n }\n if (!raw?.rates?.length) return;\n out.push(...answerFromTable(toRows(raw), group, raw.rate_date, 'referenceRate', 'reference'));\n }),\n );\n return out;\n },\n };\n};\n","import type { RateHint, RatePair, RatePlugin } from './types';\n\nexport interface RateEngine {\n readonly plugins: RatePlugin[];\n /** Ask each plugin in order; a hint answered by an earlier plugin is not asked again. */\n fetchRates: (hints: RateHint[]) => Promise<RatePair[]>;\n /** One pair, or null when no plugin covers it. */\n getRate: (fromCurrency: string, toCurrency: string, date?: string) => Promise<RatePair | null>;\n /** Convert an amount; throws when no plugin covers the pair. */\n convert: (amount: number, fromCurrency: string, toCurrency: string, date?: string) => Promise<{ amount: number; result: number; pair: RatePair }>;\n}\n\nconst key = (h: RateHint): string =>\n `${h.fromCurrency.toUpperCase()}_${h.toCurrency.toUpperCase()}_${h.date ?? ''}`;\n\n/**\n * Ordered fallback over plugins. Pass the plugins in preference order, e.g.\n * live first, then the daily reference rate, then an official table.\n */\nexport function makeRateEngine(plugins: RatePlugin[] | Record<string, RatePlugin>): RateEngine {\n const list = Array.isArray(plugins) ? plugins : Object.values(plugins);\n return {\n plugins: list,\n async fetchRates(hints) {\n const answered = new Map<string, RatePair>();\n let remaining = hints.slice();\n for (const plugin of list) {\n if (remaining.length === 0) break;\n let pairs: RatePair[] = [];\n try {\n pairs = await plugin.fetchRates(remaining);\n } catch {\n continue;\n }\n for (const p of pairs) {\n const k = `${p.fromCurrency}_${p.toCurrency}_`;\n // Match on the requested date, not the answered one (weekends\n // resolve to the previous business day).\n for (const h of remaining) {\n if (key(h).startsWith(k) && !answered.has(key(h))) answered.set(key(h), p);\n }\n }\n remaining = remaining.filter((h) => !answered.has(key(h)));\n }\n return hints.map((h) => answered.get(key(h))).filter((p): p is RatePair => p != null);\n },\n async getRate(fromCurrency, toCurrency, date) {\n const [pair] = await this.fetchRates([{ fromCurrency, toCurrency, date }]);\n return pair ?? null;\n },\n async convert(amount, fromCurrency, toCurrency, date) {\n const pair = await this.getRate(fromCurrency, toCurrency, date);\n if (!pair) throw new Error(`No plugin covers ${fromCurrency}/${toCurrency}${date ? ` on ${date}` : ''}`);\n return { amount, result: Number((amount * pair.rate).toPrecision(12)), pair };\n },\n };\n}\n","import { makeAllRatesTodayPlugin } from './plugins/allratestoday';\nimport { centralBanks, makeCentralBankPlugin } from './plugins/centralBank';\nimport { makeReferenceRatePlugin } from './plugins/referenceRate';\nimport type { PluginOptions, RatePlugin } from './types';\n\nexport * from './types';\nexport { ExchangePluginError, DEFAULT_BASE_URL } from './http';\nexport { resolvePair, answerFromTable } from './table';\nexport type { TableRow } from './table';\nexport { makeRateEngine } from './engine';\nexport type { RateEngine } from './engine';\nexport { makeAllRatesTodayPlugin } from './plugins/allratestoday';\nexport { makeReferenceRatePlugin } from './plugins/referenceRate';\nexport { makeCentralBankPlugin, centralBanks, CENTRAL_BANK_CODES } from './plugins/centralBank';\nexport type { CentralBankCode } from './plugins/centralBank';\n\n/**\n * Every plugin factory in this package, keyed by pluginId. Mirrors the\n * `plugins` export of edge-exchange-plugins: pick the ones you want, or\n * register them all.\n */\nexport const plugins = {\n // Live:\n allratestoday: makeAllRatesTodayPlugin,\n // Daily reference:\n referenceRate: makeReferenceRatePlugin,\n // Official tables (125 sources):\n ...centralBanks,\n};\n\nexport type PluginId = keyof typeof plugins;\n\n/**\n * Instantiate a set of plugins with shared options. Pass ids in preference\n * order; the result is ready for `makeRateEngine`.\n */\nexport function makePlugins(ids: PluginId[], options: PluginOptions = {}): RatePlugin[] {\n return ids.map((id) => {\n const factory = plugins[id];\n if (!factory) throw new Error(`Unknown plugin: ${id}`);\n return factory(options);\n });\n}\n\n/** The recommended default stack: live when a key is set, then reference rate, then the composite table. */\nexport function makeDefaultPlugins(options: PluginOptions = {}): RatePlugin[] {\n const list: RatePlugin[] = [];\n if (options.apiKey) list.push(makeAllRatesTodayPlugin(options));\n list.push(makeReferenceRatePlugin(options), makeCentralBankPlugin('composite', options));\n return list;\n}\n\nexport default plugins;\n"],"mappings":"gdAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wBAAAE,EAAA,qBAAAC,EAAA,wBAAAC,EAAA,oBAAAC,EAAA,iBAAAC,EAAA,4BAAAC,EAAA,0BAAAC,EAAA,uBAAAC,EAAA,gBAAAC,EAAA,mBAAAC,EAAA,4BAAAC,EAAA,YAAAC,EAAA,gBAAAC,ICEO,IAAMC,EAAmB,4BAEnBC,EAAN,cAAkC,KAAM,CAG7C,YAAYC,EAAiBC,EAAgBC,EAAe,CAC1D,MAAMF,CAAO,EACb,KAAK,KAAO,sBACZ,KAAK,OAASC,EACd,KAAK,KAAOC,CACd,CACF,EAOO,SAASC,EAASC,EAAyB,CAAC,EAAS,CAC1D,IAAMC,GAAQD,EAAQ,SAAWN,GAAkB,QAAQ,MAAO,EAAE,EAC9DQ,EAAUF,EAAQ,OAAS,WAAW,MAC5C,GAAI,OAAOE,GAAY,WACrB,MAAM,IAAI,MAAM,0DAA0D,EAE5E,IAAMC,EAAYH,EAAQ,WAAa,IACjCI,EAASJ,EAAQ,OAEvB,MAAO,CACL,OAAQ,OAAOI,GAAW,UAAYA,EAAO,OAAS,EACtD,MAAM,QAAQC,EAAMC,EAAS,CAAC,EAAGC,EAAa,GAAO,C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rB,IAAMC,EAAUR,EAAQO,CAAE,EAC1B,GAAI,CAACC,EAAS,MAAM,IAAI,MAAM,mBAAmBD,CAAE,EAAE,EACrD,OAAOC,EAAQF,CAAO,CACxB,CAAC,CACH,CAGO,SAASG,EAAmBH,EAAyB,CAAC,EAAiB,CAC5E,IAAMI,EAAqB,CAAC,EAC5B,OAAIJ,EAAQ,QAAQI,EAAK,KAAKT,EAAwBK,CAAO,CAAC,EAC9DI,EAAK,KAAKR,EAAwBI,CAAO,EAAGK,EAAsB,YAAaL,CAAO,CAAC,EAChFI,CACT,CPpCI,OAAO,OAAW,KAAe,OAAO,OAAO,yBAA4B,YAC7E,OAAO,wBAA4BE,CAAO","names":["browser_exports","__export","CENTRAL_BANK_CODES","DEFAULT_BASE_URL","ExchangePluginError","answerFromTable","centralBanks","makeAllRatesTodayPlugin","makeCentralBankPlugin","makeDefaultPlugins","makePlugins","makeRateEngine","makeReferenceRatePlugin","plugins","resolvePair","DEFAULT_BASE_URL","ExchangePluginError","message","status","body","makeHttp","options","base","doFetch","timeoutMs","apiKey","path","params","requireKey","url","k","v","headers","controller","timer","res","text","msg","makeAllRatesTodayPlugin","options","http","makeHttp","hints","bySource","h","from","to","set","out","source","targets","raw","rows","r","round","n","resolvePair","rows","from","to","direct","r","inverse","perBase","perBaseTo","b","fromPerB","toPerB","type","answerFromTable","hints","date","pluginId","rateType","out","h","hit","groupByDate","m","key","list","TAX_AUTHORITIES","makeCentralBankPlugin","bank","options","code","pageBase","http","makeHttp","toRows","r","x","hints","out","groupByDate","date","group","raw","answerFromTable","CENTRAL_BANK_CODES","centralBanks","makeReferenceRatePlugin","options","http","makeHttp","toRows","r","x","hints","out","groupByDate","date","group","raw","answerFromTable","key","h","makeRateEngine","plugins","list","hints","answered","remaining","plugin","pairs","p","k","fromCurrency","toCurrency","date","pair","amount","plugins","makeAllRatesTodayPlugin","makeReferenceRatePlugin","centralBanks","makePlugins","ids","options","id","factory","makeDefaultPlugins","list","makeCentralBankPlugin","plugins"]}
|
package/dist/index.d.mts
CHANGED
|
@@ -97,7 +97,7 @@ declare function makeRateEngine(plugins: RatePlugin[] | Record<string, RatePlugi
|
|
|
97
97
|
|
|
98
98
|
/**
|
|
99
99
|
* Live mid-market rates from `GET /api/v1/rates`. Needs an API key (the free
|
|
100
|
-
* tier
|
|
100
|
+
* tier needs no card). Answers only undated hints; dated hints are
|
|
101
101
|
* left for the reference-rate or central-bank plugins.
|
|
102
102
|
*/
|
|
103
103
|
declare const makeAllRatesTodayPlugin: (options?: PluginOptions) => RatePlugin;
|
package/dist/index.d.ts
CHANGED
|
@@ -97,7 +97,7 @@ declare function makeRateEngine(plugins: RatePlugin[] | Record<string, RatePlugi
|
|
|
97
97
|
|
|
98
98
|
/**
|
|
99
99
|
* Live mid-market rates from `GET /api/v1/rates`. Needs an API key (the free
|
|
100
|
-
* tier
|
|
100
|
+
* tier needs no card). Answers only undated hints; dated hints are
|
|
101
101
|
* left for the reference-rate or central-bank plugins.
|
|
102
102
|
*/
|
|
103
103
|
declare const makeAllRatesTodayPlugin: (options?: PluginOptions) => RatePlugin;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/http.ts","../src/plugins/allratestoday.ts","../src/table.ts","../src/plugins/centralBank.ts","../src/plugins/referenceRate.ts","../src/engine.ts"],"sourcesContent":["import { makeAllRatesTodayPlugin } from './plugins/allratestoday';\nimport { centralBanks, makeCentralBankPlugin } from './plugins/centralBank';\nimport { makeReferenceRatePlugin } from './plugins/referenceRate';\nimport type { PluginOptions, RatePlugin } from './types';\n\nexport * from './types';\nexport { ExchangePluginError, DEFAULT_BASE_URL } from './http';\nexport { resolvePair, answerFromTable } from './table';\nexport type { TableRow } from './table';\nexport { makeRateEngine } from './engine';\nexport type { RateEngine } from './engine';\nexport { makeAllRatesTodayPlugin } from './plugins/allratestoday';\nexport { makeReferenceRatePlugin } from './plugins/referenceRate';\nexport { makeCentralBankPlugin, centralBanks, CENTRAL_BANK_CODES } from './plugins/centralBank';\nexport type { CentralBankCode } from './plugins/centralBank';\n\n/**\n * Every plugin factory in this package, keyed by pluginId. Mirrors the\n * `plugins` export of edge-exchange-plugins: pick the ones you want, or\n * register them all.\n */\nexport const plugins = {\n // Live:\n allratestoday: makeAllRatesTodayPlugin,\n // Daily reference:\n referenceRate: makeReferenceRatePlugin,\n // Official tables (125 sources):\n ...centralBanks,\n};\n\nexport type PluginId = keyof typeof plugins;\n\n/**\n * Instantiate a set of plugins with shared options. Pass ids in preference\n * order; the result is ready for `makeRateEngine`.\n */\nexport function makePlugins(ids: PluginId[], options: PluginOptions = {}): RatePlugin[] {\n return ids.map((id) => {\n const factory = plugins[id];\n if (!factory) throw new Error(`Unknown plugin: ${id}`);\n return factory(options);\n });\n}\n\n/** The recommended default stack: live when a key is set, then reference rate, then the composite table. */\nexport function makeDefaultPlugins(options: PluginOptions = {}): RatePlugin[] {\n const list: RatePlugin[] = [];\n if (options.apiKey) list.push(makeAllRatesTodayPlugin(options));\n list.push(makeReferenceRatePlugin(options), makeCentralBankPlugin('composite', options));\n return list;\n}\n\nexport default plugins;\n","import type { PluginOptions } from './types';\n\nexport const DEFAULT_BASE_URL = 'https://allratestoday.com';\n\nexport class ExchangePluginError extends Error {\n readonly status: number;\n readonly body: unknown;\n constructor(message: string, status: number, body: unknown) {\n super(message);\n this.name = 'ExchangePluginError';\n this.status = status;\n this.body = body;\n }\n}\n\nexport interface Http {\n getJson: (path: string, params?: Record<string, string>, requireKey?: boolean) => Promise<unknown>;\n hasKey: boolean;\n}\n\nexport function makeHttp(options: PluginOptions = {}): Http {\n const base = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/$/, '');\n const doFetch = options.fetch ?? globalThis.fetch;\n if (typeof doFetch !== 'function') {\n throw new Error('No fetch available: pass { fetch } in the plugin options');\n }\n const timeoutMs = options.timeoutMs ?? 10_000;\n const apiKey = options.apiKey;\n\n return {\n hasKey: typeof apiKey === 'string' && apiKey.length > 0,\n async getJson(path, params = {}, requireKey = false) {\n if (requireKey && !apiKey) {\n throw new ExchangePluginError(`${path} needs an API key`, 401, null);\n }\n const url = new URL(base + path);\n for (const [k, v] of Object.entries(params)) if (v !== '') url.searchParams.set(k, v);\n const headers: Record<string, string> = {\n Accept: 'application/json',\n 'User-Agent': '@allratestoday/exchange-plugins',\n };\n if (apiKey) headers.Authorization = `Bearer ${apiKey}`;\n const controller = typeof AbortController === 'function' ? new AbortController() : undefined;\n const timer = controller ? setTimeout(() => controller.abort(), timeoutMs) : undefined;\n try {\n const res = await doFetch(url.toString(), { headers, signal: controller?.signal });\n const text = await res.text();\n let body: unknown = null;\n try {\n body = text ? JSON.parse(text) : null;\n } catch {\n body = text;\n }\n if (!res.ok) {\n const msg =\n body && typeof body === 'object' && 'error' in body\n ? String((body as { error: unknown }).error)\n : `HTTP ${res.status}`;\n throw new ExchangePluginError(msg, res.status, body);\n }\n return body;\n } finally {\n if (timer) clearTimeout(timer);\n }\n },\n };\n}\n","import { makeHttp } from '../http';\nimport type { PluginOptions, RatePair, RatePlugin } from '../types';\n\ninterface LiveRate {\n rate: number;\n source: string;\n target: string;\n time: string;\n}\n\n/**\n * Live mid-market rates from `GET /api/v1/rates`. Needs an API key (the free\n * tier is 300 requests, no card). Answers only undated hints; dated hints are\n * left for the reference-rate or central-bank plugins.\n */\nexport const makeAllRatesTodayPlugin = (options: PluginOptions = {}): RatePlugin => {\n const http = makeHttp(options);\n return {\n rateInfo: {\n pluginId: 'allratestoday',\n displayName: 'AllRatesToday live mid-market',\n keyless: false,\n homepage: 'https://allratestoday.com/docs/',\n },\n async fetchRates(hints) {\n if (!http.hasKey) return [];\n const bySource = new Map<string, Set<string>>();\n for (const h of hints) {\n if (h.date) continue;\n const from = h.fromCurrency.toUpperCase();\n const to = h.toCurrency.toUpperCase();\n if (from === to) continue;\n const set = bySource.get(from) ?? new Set<string>();\n set.add(to);\n bySource.set(from, set);\n }\n const out: RatePair[] = [];\n await Promise.all(\n [...bySource].map(async ([source, targets]) => {\n let raw: unknown;\n try {\n raw = await http.getJson('/api/v1/rates', { source, target: [...targets].join(',') }, true);\n } catch {\n return;\n }\n const rows: LiveRate[] = Array.isArray(raw) ? raw : raw ? [raw as LiveRate] : [];\n for (const r of rows) {\n if (typeof r?.rate !== 'number' || !r.target) continue;\n out.push({\n fromCurrency: source,\n toCurrency: r.target.toUpperCase(),\n rate: r.rate,\n date: (r.time ?? new Date().toISOString()).slice(0, 10),\n pluginId: 'allratestoday',\n rateType: 'mid-market',\n method: 'published',\n });\n }\n }),\n );\n for (const h of hints) {\n if (h.date) continue;\n const from = h.fromCurrency.toUpperCase();\n if (from === h.toCurrency.toUpperCase()) {\n out.push({ fromCurrency: from, toCurrency: from, rate: 1, date: new Date().toISOString().slice(0, 10), pluginId: 'allratestoday', rateType: 'mid-market', method: 'published' });\n }\n }\n return out;\n },\n };\n};\n","import type { RateHint, RateMethod, RatePair } from './types';\n\n/** One row of a published table: `value` units of `quote` per 1 `base`. */\nexport interface TableRow {\n base: string;\n quote: string;\n value: number;\n type: string;\n}\n\nconst round = (n: number): number => Number(n.toPrecision(12));\n\n/**\n * Resolve a pair from a full table: direct row, inverted row, or a cross\n * through a currency both sides are quoted against. Returns null when the\n * table does not cover the pair.\n */\nexport function resolvePair(\n rows: TableRow[],\n from: string,\n to: string,\n): { rate: number; method: RateMethod; type: string } | null {\n if (from === to) return { rate: 1, method: 'published', type: rows[0]?.type ?? 'reference' };\n const direct = rows.find((r) => r.base === from && r.quote === to && r.value > 0);\n if (direct) return { rate: direct.value, method: 'published', type: direct.type };\n const inverse = rows.find((r) => r.base === to && r.quote === from && r.value > 0);\n if (inverse) return { rate: round(1 / inverse.value), method: 'inverse', type: inverse.type };\n\n // Cross: find a base B with rows B->from and B->to (the usual table shape),\n // or any mix of directions through B.\n const perBase = new Map<string, number>(); // B -> units of `from` per 1 B\n const perBaseTo = new Map<string, number>(); // B -> units of `to` per 1 B\n for (const r of rows) {\n if (r.value <= 0) continue;\n if (r.quote === from) perBase.set(r.base, r.value);\n if (r.base === from) perBase.set(r.quote, round(1 / r.value));\n if (r.quote === to) perBaseTo.set(r.base, r.value);\n if (r.base === to) perBaseTo.set(r.quote, round(1 / r.value));\n }\n for (const [b, fromPerB] of perBase) {\n const toPerB = perBaseTo.get(b);\n if (toPerB !== undefined) {\n const type = rows.find((r) => r.base === b || r.quote === b)?.type ?? 'reference';\n return { rate: round(toPerB / fromPerB), method: 'cross', type };\n }\n }\n return null;\n}\n\nexport function answerFromTable(\n rows: TableRow[],\n hints: RateHint[],\n date: string,\n pluginId: string,\n rateType?: string,\n): RatePair[] {\n const out: RatePair[] = [];\n for (const h of hints) {\n const from = h.fromCurrency.toUpperCase();\n const to = h.toCurrency.toUpperCase();\n const hit = resolvePair(rows, from, to);\n if (!hit) continue;\n out.push({\n fromCurrency: from,\n toCurrency: to,\n rate: hit.rate,\n date,\n pluginId,\n rateType: rateType ?? hit.type,\n method: hit.method,\n });\n }\n return out;\n}\n\n/** Group hints by requested date; `''` holds the \"latest\" hints. */\nexport function groupByDate(hints: RateHint[]): Map<string, RateHint[]> {\n const m = new Map<string, RateHint[]>();\n for (const h of hints) {\n const key = h.date ?? '';\n const list = m.get(key) ?? [];\n list.push(h);\n m.set(key, list);\n }\n return m;\n}\n","import { makeHttp } from '../http';\nimport { answerFromTable, groupByDate, type TableRow } from '../table';\nimport type { PluginOptions, RatePair, RatePlugin } from '../types';\n\ninterface TableResponse {\n bank: string;\n rate_date: string;\n rates: Array<{ base: string; quote: string; type: string; value: number }>;\n}\n\n/**\n * Official exchange-rate tables published by a central bank or tax authority,\n * served by AllRatesToday. The latest table is keyless\n * (`/api/open/central-bank/{bank}`); dated tables\n * (`/api/v1/central-bank/{bank}/{date}`) need a paid key. Pairs the\n * institution does not publish directly are inverted or crossed through its\n * home currency, and the answer says so in `method`.\n *\n * `bank` is an AllRatesToday source code, e.g. `ecb`, `boe`, `rbi`, `hmrc`.\n * The full list is `GET https://allratestoday.com/api/open/central-banks`.\n */\n/** Tax authorities live under a different page base on allratestoday.com. */\nconst TAX_AUTHORITIES = new Set(['hmrc', 'bazg', 'ustreasury']);\n\nexport const makeCentralBankPlugin = (bank: string, options: PluginOptions = {}): RatePlugin => {\n const code = bank.toLowerCase();\n const pageBase = TAX_AUTHORITIES.has(code) ? 'tax-authority-rates-api' : 'central-bank-rates-api';\n const http = makeHttp(options);\n const toRows = (r: TableResponse): TableRow[] =>\n r.rates.map((x) => ({ base: x.base, quote: x.quote, value: x.value, type: x.type }));\n return {\n rateInfo: {\n pluginId: code,\n displayName: `Official rates: ${code.toUpperCase()}`,\n keyless: true,\n homepage: `https://allratestoday.com/${pageBase}/${code}/`,\n },\n async fetchRates(hints) {\n const out: RatePair[] = [];\n await Promise.all(\n [...groupByDate(hints)].map(async ([date, group]) => {\n let raw: TableResponse;\n try {\n raw = (\n date\n ? await http.getJson(`/api/v1/central-bank/${code}/${date}`, {}, true)\n : await http.getJson(`/api/open/central-bank/${code}`)\n ) as TableResponse;\n } catch {\n return;\n }\n if (!raw?.rates?.length) return;\n out.push(...answerFromTable(toRows(raw), group, raw.rate_date, code));\n }),\n );\n return out;\n },\n };\n};\n\n/**\n * Source codes served by AllRatesToday on 2026-10-19 (125). `composite` is the\n * cross-bank USD table. Refresh with `GET /api/open/central-banks`.\n */\nexport const CENTRAL_BANK_CODES = [\n 'amcm', 'bam', 'banguat', 'banxico', 'bazg', 'bb', 'bcb', 'bcbol', 'bcc', 'bcch', 'bccr', 'bccu', 'bceao', 'bch',\n 'bcm', 'bcn', 'bcp', 'bcra', 'bcrd', 'bcrp', 'bcstp', 'bct', 'bcu', 'bcv', 'bda', 'bdi', 'bdm', 'beac', 'bfm', 'bi',\n 'bmu', 'bna', 'bnb', 'bnm', 'bnr', 'bnrw', 'boa', 'bob', 'boc', 'boe', 'bog', 'bogy', 'boi', 'boj', 'bojm', 'bok',\n 'bol', 'bom', 'bon', 'bot', 'botz', 'bou', 'boz', 'brh', 'bsl', 'bsp', 'cba', 'cbar', 'cbb', 'cbbd', 'cbbh', 'cbbz',\n 'cbc', 'cbe', 'cbg', 'cbi', 'cbiq', 'cbj', 'cbk', 'cbke', 'cbl', 'cbm', 'cbn', 'cbo', 'cbr', 'cbsl', 'cbt', 'cbtt',\n 'cbu', 'cbuae', 'cbvs', 'cnb', 'composite', 'dnb', 'ecb', 'fed', 'hkma', 'hmrc', 'lb', 'mas', 'mma', 'mnb', 'nbc',\n 'nbe', 'nbg', 'nbk', 'nbkr', 'nbm', 'nbp', 'nbrb', 'nbrm', 'nbs', 'nbt', 'nbu', 'norges', 'nrb', 'pboc', 'pma',\n 'qcb', 'rba', 'rbf', 'rbi', 'rbm', 'rbnz', 'rbz', 'riksbank', 'rma', 'sama', 'sarb', 'sbp', 'sbv', 'sfc', 'snb',\n 'tcmb', 'ustreasury',\n] as const;\n\nexport type CentralBankCode = (typeof CENTRAL_BANK_CODES)[number];\n\n/** One factory per source, keyed by code: `centralBanks.ecb()`, `centralBanks.boe()`, ... */\nexport const centralBanks = Object.fromEntries(\n CENTRAL_BANK_CODES.map((code) => [code, (options?: PluginOptions) => makeCentralBankPlugin(code, options)]),\n) as Record<CentralBankCode, (options?: PluginOptions) => RatePlugin>;\n","import { makeHttp } from '../http';\nimport { answerFromTable, groupByDate, type TableRow } from '../table';\nimport type { PluginOptions, RatePair, RatePlugin } from '../types';\n\ninterface ReferenceResponse {\n rate_date: string;\n base: string;\n rates: Array<{ base: string; quote: string; value: number }>;\n}\n\n/**\n * The AllRatesToday daily reference rate: one USD-based table a day, fixed at\n * 16:00 London. The latest table is keyless (`/api/open/reference-rate`);\n * dated tables (`/api/v1/reference-rate/{date}`) need an API key. Any pair is\n * crossed through USD.\n */\nexport const makeReferenceRatePlugin = (options: PluginOptions = {}): RatePlugin => {\n const http = makeHttp(options);\n const toRows = (r: ReferenceResponse): TableRow[] =>\n r.rates.map((x) => ({ base: x.base, quote: x.quote, value: x.value, type: 'reference' }));\n return {\n rateInfo: {\n pluginId: 'referenceRate',\n displayName: 'AllRatesToday daily reference rate (16:00 London)',\n keyless: true,\n homepage: 'https://allratestoday.com/reference-rate/',\n },\n async fetchRates(hints) {\n const out: RatePair[] = [];\n await Promise.all(\n [...groupByDate(hints)].map(async ([date, group]) => {\n let raw: ReferenceResponse;\n try {\n raw = (\n date\n ? await http.getJson(`/api/v1/reference-rate/${date}`, {}, true)\n : await http.getJson('/api/open/reference-rate')\n ) as ReferenceResponse;\n } catch {\n return;\n }\n if (!raw?.rates?.length) return;\n out.push(...answerFromTable(toRows(raw), group, raw.rate_date, 'referenceRate', 'reference'));\n }),\n );\n return out;\n },\n };\n};\n","import type { RateHint, RatePair, RatePlugin } from './types';\n\nexport interface RateEngine {\n readonly plugins: RatePlugin[];\n /** Ask each plugin in order; a hint answered by an earlier plugin is not asked again. */\n fetchRates: (hints: RateHint[]) => Promise<RatePair[]>;\n /** One pair, or null when no plugin covers it. */\n getRate: (fromCurrency: string, toCurrency: string, date?: string) => Promise<RatePair | null>;\n /** Convert an amount; throws when no plugin covers the pair. */\n convert: (amount: number, fromCurrency: string, toCurrency: string, date?: string) => Promise<{ amount: number; result: number; pair: RatePair }>;\n}\n\nconst key = (h: RateHint): string =>\n `${h.fromCurrency.toUpperCase()}_${h.toCurrency.toUpperCase()}_${h.date ?? ''}`;\n\n/**\n * Ordered fallback over plugins. Pass the plugins in preference order, e.g.\n * live first, then the daily reference rate, then an official table.\n */\nexport function makeRateEngine(plugins: RatePlugin[] | Record<string, RatePlugin>): RateEngine {\n const list = Array.isArray(plugins) ? plugins : Object.values(plugins);\n return {\n plugins: list,\n async fetchRates(hints) {\n const answered = new Map<string, RatePair>();\n let remaining = hints.slice();\n for (const plugin of list) {\n if (remaining.length === 0) break;\n let pairs: RatePair[] = [];\n try {\n pairs = await plugin.fetchRates(remaining);\n } catch {\n continue;\n }\n for (const p of pairs) {\n const k = `${p.fromCurrency}_${p.toCurrency}_`;\n // Match on the requested date, not the answered one (weekends\n // resolve to the previous business day).\n for (const h of remaining) {\n if (key(h).startsWith(k) && !answered.has(key(h))) answered.set(key(h), p);\n }\n }\n remaining = remaining.filter((h) => !answered.has(key(h)));\n }\n return hints.map((h) => answered.get(key(h))).filter((p): p is RatePair => p != null);\n },\n async getRate(fromCurrency, toCurrency, date) {\n const [pair] = await this.fetchRates([{ fromCurrency, toCurrency, date }]);\n return pair ?? null;\n },\n async convert(amount, fromCurrency, toCurrency, date) {\n const pair = await this.getRate(fromCurrency, toCurrency, date);\n if (!pair) throw new Error(`No plugin covers ${fromCurrency}/${toCurrency}${date ? ` on ${date}` : ''}`);\n return { amount, result: Number((amount * pair.rate).toPrecision(12)), pair };\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAM,mBAAmB;AAEzB,IAAM,sBAAN,cAAkC,MAAM;AAAA,EAG7C,YAAY,SAAiB,QAAgB,MAAe;AAC1D,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO;AAAA,EACd;AACF;AAOO,SAAS,SAAS,UAAyB,CAAC,GAAS;AAC1D,QAAM,QAAQ,QAAQ,WAAW,kBAAkB,QAAQ,OAAO,EAAE;AACpE,QAAM,UAAU,QAAQ,SAAS,WAAW;AAC5C,MAAI,OAAO,YAAY,YAAY;AACjC,UAAM,IAAI,MAAM,0DAA0D;AAAA,EAC5E;AACA,QAAM,YAAY,QAAQ,aAAa;AACvC,QAAM,SAAS,QAAQ;AAEvB,SAAO;AAAA,IACL,QAAQ,OAAO,WAAW,YAAY,OAAO,SAAS;AAAA,IACtD,MAAM,QAAQ,MAAM,SAAS,CAAC,GAAG,aAAa,OAAO;AACnD,UAAI,cAAc,CAAC,QAAQ;AACzB,cAAM,IAAI,oBAAoB,GAAG,IAAI,qBAAqB,KAAK,IAAI;AAAA,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IAAI,CAAC,OAAO;AACrB,UAAM,UAAU,QAAQ,EAAE;AAC1B,QAAI,CAAC,QAAS,OAAM,IAAI,MAAM,mBAAmB,EAAE,EAAE;AACrD,WAAO,QAAQ,OAAO;AAAA,EACxB,CAAC;AACH;AAGO,SAAS,mBAAmB,UAAyB,CAAC,GAAiB;AAC5E,QAAM,OAAqB,CAAC;AAC5B,MAAI,QAAQ,OAAQ,MAAK,KAAK,wBAAwB,OAAO,CAAC;AAC9D,OAAK,KAAK,wBAAwB,OAAO,GAAG,sBAAsB,aAAa,OAAO,CAAC;AACvF,SAAO;AACT;AAEA,IAAO,cAAQ;","names":["key","plugins"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/http.ts","../src/plugins/allratestoday.ts","../src/table.ts","../src/plugins/centralBank.ts","../src/plugins/referenceRate.ts","../src/engine.ts"],"sourcesContent":["import { makeAllRatesTodayPlugin } from './plugins/allratestoday';\nimport { centralBanks, makeCentralBankPlugin } from './plugins/centralBank';\nimport { makeReferenceRatePlugin } from './plugins/referenceRate';\nimport type { PluginOptions, RatePlugin } from './types';\n\nexport * from './types';\nexport { ExchangePluginError, DEFAULT_BASE_URL } from './http';\nexport { resolvePair, answerFromTable } from './table';\nexport type { TableRow } from './table';\nexport { makeRateEngine } from './engine';\nexport type { RateEngine } from './engine';\nexport { makeAllRatesTodayPlugin } from './plugins/allratestoday';\nexport { makeReferenceRatePlugin } from './plugins/referenceRate';\nexport { makeCentralBankPlugin, centralBanks, CENTRAL_BANK_CODES } from './plugins/centralBank';\nexport type { CentralBankCode } from './plugins/centralBank';\n\n/**\n * Every plugin factory in this package, keyed by pluginId. Mirrors the\n * `plugins` export of edge-exchange-plugins: pick the ones you want, or\n * register them all.\n */\nexport const plugins = {\n // Live:\n allratestoday: makeAllRatesTodayPlugin,\n // Daily reference:\n referenceRate: makeReferenceRatePlugin,\n // Official tables (125 sources):\n ...centralBanks,\n};\n\nexport type PluginId = keyof typeof plugins;\n\n/**\n * Instantiate a set of plugins with shared options. Pass ids in preference\n * order; the result is ready for `makeRateEngine`.\n */\nexport function makePlugins(ids: PluginId[], options: PluginOptions = {}): RatePlugin[] {\n return ids.map((id) => {\n const factory = plugins[id];\n if (!factory) throw new Error(`Unknown plugin: ${id}`);\n return factory(options);\n });\n}\n\n/** The recommended default stack: live when a key is set, then reference rate, then the composite table. */\nexport function makeDefaultPlugins(options: PluginOptions = {}): RatePlugin[] {\n const list: RatePlugin[] = [];\n if (options.apiKey) list.push(makeAllRatesTodayPlugin(options));\n list.push(makeReferenceRatePlugin(options), makeCentralBankPlugin('composite', options));\n return list;\n}\n\nexport default plugins;\n","import type { PluginOptions } from './types';\n\nexport const DEFAULT_BASE_URL = 'https://allratestoday.com';\n\nexport class ExchangePluginError extends Error {\n readonly status: number;\n readonly body: unknown;\n constructor(message: string, status: number, body: unknown) {\n super(message);\n this.name = 'ExchangePluginError';\n this.status = status;\n this.body = body;\n }\n}\n\nexport interface Http {\n getJson: (path: string, params?: Record<string, string>, requireKey?: boolean) => Promise<unknown>;\n hasKey: boolean;\n}\n\nexport function makeHttp(options: PluginOptions = {}): Http {\n const base = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/$/, '');\n const doFetch = options.fetch ?? globalThis.fetch;\n if (typeof doFetch !== 'function') {\n throw new Error('No fetch available: pass { fetch } in the plugin options');\n }\n const timeoutMs = options.timeoutMs ?? 10_000;\n const apiKey = options.apiKey;\n\n return {\n hasKey: typeof apiKey === 'string' && apiKey.length > 0,\n async getJson(path, params = {}, requireKey = false) {\n if (requireKey && !apiKey) {\n throw new ExchangePluginError(`${path} needs an API key`, 401, null);\n }\n const url = new URL(base + path);\n for (const [k, v] of Object.entries(params)) if (v !== '') url.searchParams.set(k, v);\n const headers: Record<string, string> = {\n Accept: 'application/json',\n 'User-Agent': '@allratestoday/exchange-plugins',\n };\n if (apiKey) headers.Authorization = `Bearer ${apiKey}`;\n const controller = typeof AbortController === 'function' ? new AbortController() : undefined;\n const timer = controller ? setTimeout(() => controller.abort(), timeoutMs) : undefined;\n try {\n const res = await doFetch(url.toString(), { headers, signal: controller?.signal });\n const text = await res.text();\n let body: unknown = null;\n try {\n body = text ? JSON.parse(text) : null;\n } catch {\n body = text;\n }\n if (!res.ok) {\n const msg =\n body && typeof body === 'object' && 'error' in body\n ? String((body as { error: unknown }).error)\n : `HTTP ${res.status}`;\n throw new ExchangePluginError(msg, res.status, body);\n }\n return body;\n } finally {\n if (timer) clearTimeout(timer);\n }\n },\n };\n}\n","import { makeHttp } from '../http';\nimport type { PluginOptions, RatePair, RatePlugin } from '../types';\n\ninterface LiveRate {\n rate: number;\n source: string;\n target: string;\n time: string;\n}\n\n/**\n * Live mid-market rates from `GET /api/v1/rates`. Needs an API key (the free\n * tier needs no card). Answers only undated hints; dated hints are\n * left for the reference-rate or central-bank plugins.\n */\nexport const makeAllRatesTodayPlugin = (options: PluginOptions = {}): RatePlugin => {\n const http = makeHttp(options);\n return {\n rateInfo: {\n pluginId: 'allratestoday',\n displayName: 'AllRatesToday live mid-market',\n keyless: false,\n homepage: 'https://allratestoday.com/docs/',\n },\n async fetchRates(hints) {\n if (!http.hasKey) return [];\n const bySource = new Map<string, Set<string>>();\n for (const h of hints) {\n if (h.date) continue;\n const from = h.fromCurrency.toUpperCase();\n const to = h.toCurrency.toUpperCase();\n if (from === to) continue;\n const set = bySource.get(from) ?? new Set<string>();\n set.add(to);\n bySource.set(from, set);\n }\n const out: RatePair[] = [];\n await Promise.all(\n [...bySource].map(async ([source, targets]) => {\n let raw: unknown;\n try {\n raw = await http.getJson('/api/v1/rates', { source, target: [...targets].join(',') }, true);\n } catch {\n return;\n }\n const rows: LiveRate[] = Array.isArray(raw) ? raw : raw ? [raw as LiveRate] : [];\n for (const r of rows) {\n if (typeof r?.rate !== 'number' || !r.target) continue;\n out.push({\n fromCurrency: source,\n toCurrency: r.target.toUpperCase(),\n rate: r.rate,\n date: (r.time ?? new Date().toISOString()).slice(0, 10),\n pluginId: 'allratestoday',\n rateType: 'mid-market',\n method: 'published',\n });\n }\n }),\n );\n for (const h of hints) {\n if (h.date) continue;\n const from = h.fromCurrency.toUpperCase();\n if (from === h.toCurrency.toUpperCase()) {\n out.push({ fromCurrency: from, toCurrency: from, rate: 1, date: new Date().toISOString().slice(0, 10), pluginId: 'allratestoday', rateType: 'mid-market', method: 'published' });\n }\n }\n return out;\n },\n };\n};\n","import type { RateHint, RateMethod, RatePair } from './types';\n\n/** One row of a published table: `value` units of `quote` per 1 `base`. */\nexport interface TableRow {\n base: string;\n quote: string;\n value: number;\n type: string;\n}\n\nconst round = (n: number): number => Number(n.toPrecision(12));\n\n/**\n * Resolve a pair from a full table: direct row, inverted row, or a cross\n * through a currency both sides are quoted against. Returns null when the\n * table does not cover the pair.\n */\nexport function resolvePair(\n rows: TableRow[],\n from: string,\n to: string,\n): { rate: number; method: RateMethod; type: string } | null {\n if (from === to) return { rate: 1, method: 'published', type: rows[0]?.type ?? 'reference' };\n const direct = rows.find((r) => r.base === from && r.quote === to && r.value > 0);\n if (direct) return { rate: direct.value, method: 'published', type: direct.type };\n const inverse = rows.find((r) => r.base === to && r.quote === from && r.value > 0);\n if (inverse) return { rate: round(1 / inverse.value), method: 'inverse', type: inverse.type };\n\n // Cross: find a base B with rows B->from and B->to (the usual table shape),\n // or any mix of directions through B.\n const perBase = new Map<string, number>(); // B -> units of `from` per 1 B\n const perBaseTo = new Map<string, number>(); // B -> units of `to` per 1 B\n for (const r of rows) {\n if (r.value <= 0) continue;\n if (r.quote === from) perBase.set(r.base, r.value);\n if (r.base === from) perBase.set(r.quote, round(1 / r.value));\n if (r.quote === to) perBaseTo.set(r.base, r.value);\n if (r.base === to) perBaseTo.set(r.quote, round(1 / r.value));\n }\n for (const [b, fromPerB] of perBase) {\n const toPerB = perBaseTo.get(b);\n if (toPerB !== undefined) {\n const type = rows.find((r) => r.base === b || r.quote === b)?.type ?? 'reference';\n return { rate: round(toPerB / fromPerB), method: 'cross', type };\n }\n }\n return null;\n}\n\nexport function answerFromTable(\n rows: TableRow[],\n hints: RateHint[],\n date: string,\n pluginId: string,\n rateType?: string,\n): RatePair[] {\n const out: RatePair[] = [];\n for (const h of hints) {\n const from = h.fromCurrency.toUpperCase();\n const to = h.toCurrency.toUpperCase();\n const hit = resolvePair(rows, from, to);\n if (!hit) continue;\n out.push({\n fromCurrency: from,\n toCurrency: to,\n rate: hit.rate,\n date,\n pluginId,\n rateType: rateType ?? hit.type,\n method: hit.method,\n });\n }\n return out;\n}\n\n/** Group hints by requested date; `''` holds the \"latest\" hints. */\nexport function groupByDate(hints: RateHint[]): Map<string, RateHint[]> {\n const m = new Map<string, RateHint[]>();\n for (const h of hints) {\n const key = h.date ?? '';\n const list = m.get(key) ?? [];\n list.push(h);\n m.set(key, list);\n }\n return m;\n}\n","import { makeHttp } from '../http';\nimport { answerFromTable, groupByDate, type TableRow } from '../table';\nimport type { PluginOptions, RatePair, RatePlugin } from '../types';\n\ninterface TableResponse {\n bank: string;\n rate_date: string;\n rates: Array<{ base: string; quote: string; type: string; value: number }>;\n}\n\n/**\n * Official exchange-rate tables published by a central bank or tax authority,\n * served by AllRatesToday. The latest table is keyless\n * (`/api/open/central-bank/{bank}`); dated tables\n * (`/api/v1/central-bank/{bank}/{date}`) need a paid key. Pairs the\n * institution does not publish directly are inverted or crossed through its\n * home currency, and the answer says so in `method`.\n *\n * `bank` is an AllRatesToday source code, e.g. `ecb`, `boe`, `rbi`, `hmrc`.\n * The full list is `GET https://allratestoday.com/api/open/central-banks`.\n */\n/** Tax authorities live under a different page base on allratestoday.com. */\nconst TAX_AUTHORITIES = new Set(['hmrc', 'bazg', 'ustreasury']);\n\nexport const makeCentralBankPlugin = (bank: string, options: PluginOptions = {}): RatePlugin => {\n const code = bank.toLowerCase();\n const pageBase = TAX_AUTHORITIES.has(code) ? 'tax-authority-rates-api' : 'central-bank-rates-api';\n const http = makeHttp(options);\n const toRows = (r: TableResponse): TableRow[] =>\n r.rates.map((x) => ({ base: x.base, quote: x.quote, value: x.value, type: x.type }));\n return {\n rateInfo: {\n pluginId: code,\n displayName: `Official rates: ${code.toUpperCase()}`,\n keyless: true,\n homepage: `https://allratestoday.com/${pageBase}/${code}/`,\n },\n async fetchRates(hints) {\n const out: RatePair[] = [];\n await Promise.all(\n [...groupByDate(hints)].map(async ([date, group]) => {\n let raw: TableResponse;\n try {\n raw = (\n date\n ? await http.getJson(`/api/v1/central-bank/${code}/${date}`, {}, true)\n : await http.getJson(`/api/open/central-bank/${code}`)\n ) as TableResponse;\n } catch {\n return;\n }\n if (!raw?.rates?.length) return;\n out.push(...answerFromTable(toRows(raw), group, raw.rate_date, code));\n }),\n );\n return out;\n },\n };\n};\n\n/**\n * Source codes served by AllRatesToday on 2026-10-19 (125). `composite` is the\n * cross-bank USD table. Refresh with `GET /api/open/central-banks`.\n */\nexport const CENTRAL_BANK_CODES = [\n 'amcm', 'bam', 'banguat', 'banxico', 'bazg', 'bb', 'bcb', 'bcbol', 'bcc', 'bcch', 'bccr', 'bccu', 'bceao', 'bch',\n 'bcm', 'bcn', 'bcp', 'bcra', 'bcrd', 'bcrp', 'bcstp', 'bct', 'bcu', 'bcv', 'bda', 'bdi', 'bdm', 'beac', 'bfm', 'bi',\n 'bmu', 'bna', 'bnb', 'bnm', 'bnr', 'bnrw', 'boa', 'bob', 'boc', 'boe', 'bog', 'bogy', 'boi', 'boj', 'bojm', 'bok',\n 'bol', 'bom', 'bon', 'bot', 'botz', 'bou', 'boz', 'brh', 'bsl', 'bsp', 'cba', 'cbar', 'cbb', 'cbbd', 'cbbh', 'cbbz',\n 'cbc', 'cbe', 'cbg', 'cbi', 'cbiq', 'cbj', 'cbk', 'cbke', 'cbl', 'cbm', 'cbn', 'cbo', 'cbr', 'cbsl', 'cbt', 'cbtt',\n 'cbu', 'cbuae', 'cbvs', 'cnb', 'composite', 'dnb', 'ecb', 'fed', 'hkma', 'hmrc', 'lb', 'mas', 'mma', 'mnb', 'nbc',\n 'nbe', 'nbg', 'nbk', 'nbkr', 'nbm', 'nbp', 'nbrb', 'nbrm', 'nbs', 'nbt', 'nbu', 'norges', 'nrb', 'pboc', 'pma',\n 'qcb', 'rba', 'rbf', 'rbi', 'rbm', 'rbnz', 'rbz', 'riksbank', 'rma', 'sama', 'sarb', 'sbp', 'sbv', 'sfc', 'snb',\n 'tcmb', 'ustreasury',\n] as const;\n\nexport type CentralBankCode = (typeof CENTRAL_BANK_CODES)[number];\n\n/** One factory per source, keyed by code: `centralBanks.ecb()`, `centralBanks.boe()`, ... */\nexport const centralBanks = Object.fromEntries(\n CENTRAL_BANK_CODES.map((code) => [code, (options?: PluginOptions) => makeCentralBankPlugin(code, options)]),\n) as Record<CentralBankCode, (options?: PluginOptions) => RatePlugin>;\n","import { makeHttp } from '../http';\nimport { answerFromTable, groupByDate, type TableRow } from '../table';\nimport type { PluginOptions, RatePair, RatePlugin } from '../types';\n\ninterface ReferenceResponse {\n rate_date: string;\n base: string;\n rates: Array<{ base: string; quote: string; value: number }>;\n}\n\n/**\n * The AllRatesToday daily reference rate: one USD-based table a day, fixed at\n * 16:00 London. The latest table is keyless (`/api/open/reference-rate`);\n * dated tables (`/api/v1/reference-rate/{date}`) need an API key. Any pair is\n * crossed through USD.\n */\nexport const makeReferenceRatePlugin = (options: PluginOptions = {}): RatePlugin => {\n const http = makeHttp(options);\n const toRows = (r: ReferenceResponse): TableRow[] =>\n r.rates.map((x) => ({ base: x.base, quote: x.quote, value: x.value, type: 'reference' }));\n return {\n rateInfo: {\n pluginId: 'referenceRate',\n displayName: 'AllRatesToday daily reference rate (16:00 London)',\n keyless: true,\n homepage: 'https://allratestoday.com/reference-rate/',\n },\n async fetchRates(hints) {\n const out: RatePair[] = [];\n await Promise.all(\n [...groupByDate(hints)].map(async ([date, group]) => {\n let raw: ReferenceResponse;\n try {\n raw = (\n date\n ? await http.getJson(`/api/v1/reference-rate/${date}`, {}, true)\n : await http.getJson('/api/open/reference-rate')\n ) as ReferenceResponse;\n } catch {\n return;\n }\n if (!raw?.rates?.length) return;\n out.push(...answerFromTable(toRows(raw), group, raw.rate_date, 'referenceRate', 'reference'));\n }),\n );\n return out;\n },\n };\n};\n","import type { RateHint, RatePair, RatePlugin } from './types';\n\nexport interface RateEngine {\n readonly plugins: RatePlugin[];\n /** Ask each plugin in order; a hint answered by an earlier plugin is not asked again. */\n fetchRates: (hints: RateHint[]) => Promise<RatePair[]>;\n /** One pair, or null when no plugin covers it. */\n getRate: (fromCurrency: string, toCurrency: string, date?: string) => Promise<RatePair | null>;\n /** Convert an amount; throws when no plugin covers the pair. */\n convert: (amount: number, fromCurrency: string, toCurrency: string, date?: string) => Promise<{ amount: number; result: number; pair: RatePair }>;\n}\n\nconst key = (h: RateHint): string =>\n `${h.fromCurrency.toUpperCase()}_${h.toCurrency.toUpperCase()}_${h.date ?? ''}`;\n\n/**\n * Ordered fallback over plugins. Pass the plugins in preference order, e.g.\n * live first, then the daily reference rate, then an official table.\n */\nexport function makeRateEngine(plugins: RatePlugin[] | Record<string, RatePlugin>): RateEngine {\n const list = Array.isArray(plugins) ? plugins : Object.values(plugins);\n return {\n plugins: list,\n async fetchRates(hints) {\n const answered = new Map<string, RatePair>();\n let remaining = hints.slice();\n for (const plugin of list) {\n if (remaining.length === 0) break;\n let pairs: RatePair[] = [];\n try {\n pairs = await plugin.fetchRates(remaining);\n } catch {\n continue;\n }\n for (const p of pairs) {\n const k = `${p.fromCurrency}_${p.toCurrency}_`;\n // Match on the requested date, not the answered one (weekends\n // resolve to the previous business day).\n for (const h of remaining) {\n if (key(h).startsWith(k) && !answered.has(key(h))) answered.set(key(h), p);\n }\n }\n remaining = remaining.filter((h) => !answered.has(key(h)));\n }\n return hints.map((h) => answered.get(key(h))).filter((p): p is RatePair => p != null);\n },\n async getRate(fromCurrency, toCurrency, date) {\n const [pair] = await this.fetchRates([{ fromCurrency, toCurrency, date }]);\n return pair ?? null;\n },\n async convert(amount, fromCurrency, toCurrency, date) {\n const pair = await this.getRate(fromCurrency, toCurrency, date);\n if (!pair) throw new Error(`No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O,GAAG,sBAAsB,aAAa,OAAO,CAAC;AACvF,SAAO;AACT;AAEA,IAAO,cAAQ;","names":["key","plugins"]}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/http.ts","../src/plugins/allratestoday.ts","../src/table.ts","../src/plugins/centralBank.ts","../src/plugins/referenceRate.ts","../src/engine.ts","../src/index.ts"],"sourcesContent":["import type { PluginOptions } from './types';\n\nexport const DEFAULT_BASE_URL = 'https://allratestoday.com';\n\nexport class ExchangePluginError extends Error {\n readonly status: number;\n readonly body: unknown;\n constructor(message: string, status: number, body: unknown) {\n super(message);\n this.name = 'ExchangePluginError';\n this.status = status;\n this.body = body;\n }\n}\n\nexport interface Http {\n getJson: (path: string, params?: Record<string, string>, requireKey?: boolean) => Promise<unknown>;\n hasKey: boolean;\n}\n\nexport function makeHttp(options: PluginOptions = {}): Http {\n const base = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/$/, '');\n const doFetch = options.fetch ?? globalThis.fetch;\n if (typeof doFetch !== 'function') {\n throw new Error('No fetch available: pass { fetch } in the plugin options');\n }\n const timeoutMs = options.timeoutMs ?? 10_000;\n const apiKey = options.apiKey;\n\n return {\n hasKey: typeof apiKey === 'string' && apiKey.length > 0,\n async getJson(path, params = {}, requireKey = false) {\n if (requireKey && !apiKey) {\n throw new ExchangePluginError(`${path} needs an API key`, 401, null);\n }\n const url = new URL(base + path);\n for (const [k, v] of Object.entries(params)) if (v !== '') url.searchParams.set(k, v);\n const headers: Record<string, string> = {\n Accept: 'application/json',\n 'User-Agent': '@allratestoday/exchange-plugins',\n };\n if (apiKey) headers.Authorization = `Bearer ${apiKey}`;\n const controller = typeof AbortController === 'function' ? new AbortController() : undefined;\n const timer = controller ? setTimeout(() => controller.abort(), timeoutMs) : undefined;\n try {\n const res = await doFetch(url.toString(), { headers, signal: controller?.signal });\n const text = await res.text();\n let body: unknown = null;\n try {\n body = text ? JSON.parse(text) : null;\n } catch {\n body = text;\n }\n if (!res.ok) {\n const msg =\n body && typeof body === 'object' && 'error' in body\n ? String((body as { error: unknown }).error)\n : `HTTP ${res.status}`;\n throw new ExchangePluginError(msg, res.status, body);\n }\n return body;\n } finally {\n if (timer) clearTimeout(timer);\n }\n },\n };\n}\n","import { makeHttp } from '../http';\nimport type { PluginOptions, RatePair, RatePlugin } from '../types';\n\ninterface LiveRate {\n rate: number;\n source: string;\n target: string;\n time: string;\n}\n\n/**\n * Live mid-market rates from `GET /api/v1/rates`. Needs an API key (the free\n * tier is 300 requests, no card). Answers only undated hints; dated hints are\n * left for the reference-rate or central-bank plugins.\n */\nexport const makeAllRatesTodayPlugin = (options: PluginOptions = {}): RatePlugin => {\n const http = makeHttp(options);\n return {\n rateInfo: {\n pluginId: 'allratestoday',\n displayName: 'AllRatesToday live mid-market',\n keyless: false,\n homepage: 'https://allratestoday.com/docs/',\n },\n async fetchRates(hints) {\n if (!http.hasKey) return [];\n const bySource = new Map<string, Set<string>>();\n for (const h of hints) {\n if (h.date) continue;\n const from = h.fromCurrency.toUpperCase();\n const to = h.toCurrency.toUpperCase();\n if (from === to) continue;\n const set = bySource.get(from) ?? new Set<string>();\n set.add(to);\n bySource.set(from, set);\n }\n const out: RatePair[] = [];\n await Promise.all(\n [...bySource].map(async ([source, targets]) => {\n let raw: unknown;\n try {\n raw = await http.getJson('/api/v1/rates', { source, target: [...targets].join(',') }, true);\n } catch {\n return;\n }\n const rows: LiveRate[] = Array.isArray(raw) ? raw : raw ? [raw as LiveRate] : [];\n for (const r of rows) {\n if (typeof r?.rate !== 'number' || !r.target) continue;\n out.push({\n fromCurrency: source,\n toCurrency: r.target.toUpperCase(),\n rate: r.rate,\n date: (r.time ?? new Date().toISOString()).slice(0, 10),\n pluginId: 'allratestoday',\n rateType: 'mid-market',\n method: 'published',\n });\n }\n }),\n );\n for (const h of hints) {\n if (h.date) continue;\n const from = h.fromCurrency.toUpperCase();\n if (from === h.toCurrency.toUpperCase()) {\n out.push({ fromCurrency: from, toCurrency: from, rate: 1, date: new Date().toISOString().slice(0, 10), pluginId: 'allratestoday', rateType: 'mid-market', method: 'published' });\n }\n }\n return out;\n },\n };\n};\n","import type { RateHint, RateMethod, RatePair } from './types';\n\n/** One row of a published table: `value` units of `quote` per 1 `base`. */\nexport interface TableRow {\n base: string;\n quote: string;\n value: number;\n type: string;\n}\n\nconst round = (n: number): number => Number(n.toPrecision(12));\n\n/**\n * Resolve a pair from a full table: direct row, inverted row, or a cross\n * through a currency both sides are quoted against. Returns null when the\n * table does not cover the pair.\n */\nexport function resolvePair(\n rows: TableRow[],\n from: string,\n to: string,\n): { rate: number; method: RateMethod; type: string } | null {\n if (from === to) return { rate: 1, method: 'published', type: rows[0]?.type ?? 'reference' };\n const direct = rows.find((r) => r.base === from && r.quote === to && r.value > 0);\n if (direct) return { rate: direct.value, method: 'published', type: direct.type };\n const inverse = rows.find((r) => r.base === to && r.quote === from && r.value > 0);\n if (inverse) return { rate: round(1 / inverse.value), method: 'inverse', type: inverse.type };\n\n // Cross: find a base B with rows B->from and B->to (the usual table shape),\n // or any mix of directions through B.\n const perBase = new Map<string, number>(); // B -> units of `from` per 1 B\n const perBaseTo = new Map<string, number>(); // B -> units of `to` per 1 B\n for (const r of rows) {\n if (r.value <= 0) continue;\n if (r.quote === from) perBase.set(r.base, r.value);\n if (r.base === from) perBase.set(r.quote, round(1 / r.value));\n if (r.quote === to) perBaseTo.set(r.base, r.value);\n if (r.base === to) perBaseTo.set(r.quote, round(1 / r.value));\n }\n for (const [b, fromPerB] of perBase) {\n const toPerB = perBaseTo.get(b);\n if (toPerB !== undefined) {\n const type = rows.find((r) => r.base === b || r.quote === b)?.type ?? 'reference';\n return { rate: round(toPerB / fromPerB), method: 'cross', type };\n }\n }\n return null;\n}\n\nexport function answerFromTable(\n rows: TableRow[],\n hints: RateHint[],\n date: string,\n pluginId: string,\n rateType?: string,\n): RatePair[] {\n const out: RatePair[] = [];\n for (const h of hints) {\n const from = h.fromCurrency.toUpperCase();\n const to = h.toCurrency.toUpperCase();\n const hit = resolvePair(rows, from, to);\n if (!hit) continue;\n out.push({\n fromCurrency: from,\n toCurrency: to,\n rate: hit.rate,\n date,\n pluginId,\n rateType: rateType ?? hit.type,\n method: hit.method,\n });\n }\n return out;\n}\n\n/** Group hints by requested date; `''` holds the \"latest\" hints. */\nexport function groupByDate(hints: RateHint[]): Map<string, RateHint[]> {\n const m = new Map<string, RateHint[]>();\n for (const h of hints) {\n const key = h.date ?? '';\n const list = m.get(key) ?? [];\n list.push(h);\n m.set(key, list);\n }\n return m;\n}\n","import { makeHttp } from '../http';\nimport { answerFromTable, groupByDate, type TableRow } from '../table';\nimport type { PluginOptions, RatePair, RatePlugin } from '../types';\n\ninterface TableResponse {\n bank: string;\n rate_date: string;\n rates: Array<{ base: string; quote: string; type: string; value: number }>;\n}\n\n/**\n * Official exchange-rate tables published by a central bank or tax authority,\n * served by AllRatesToday. The latest table is keyless\n * (`/api/open/central-bank/{bank}`); dated tables\n * (`/api/v1/central-bank/{bank}/{date}`) need a paid key. Pairs the\n * institution does not publish directly are inverted or crossed through its\n * home currency, and the answer says so in `method`.\n *\n * `bank` is an AllRatesToday source code, e.g. `ecb`, `boe`, `rbi`, `hmrc`.\n * The full list is `GET https://allratestoday.com/api/open/central-banks`.\n */\n/** Tax authorities live under a different page base on allratestoday.com. */\nconst TAX_AUTHORITIES = new Set(['hmrc', 'bazg', 'ustreasury']);\n\nexport const makeCentralBankPlugin = (bank: string, options: PluginOptions = {}): RatePlugin => {\n const code = bank.toLowerCase();\n const pageBase = TAX_AUTHORITIES.has(code) ? 'tax-authority-rates-api' : 'central-bank-rates-api';\n const http = makeHttp(options);\n const toRows = (r: TableResponse): TableRow[] =>\n r.rates.map((x) => ({ base: x.base, quote: x.quote, value: x.value, type: x.type }));\n return {\n rateInfo: {\n pluginId: code,\n displayName: `Official rates: ${code.toUpperCase()}`,\n keyless: true,\n homepage: `https://allratestoday.com/${pageBase}/${code}/`,\n },\n async fetchRates(hints) {\n const out: RatePair[] = [];\n await Promise.all(\n [...groupByDate(hints)].map(async ([date, group]) => {\n let raw: TableResponse;\n try {\n raw = (\n date\n ? await http.getJson(`/api/v1/central-bank/${code}/${date}`, {}, true)\n : await http.getJson(`/api/open/central-bank/${code}`)\n ) as TableResponse;\n } catch {\n return;\n }\n if (!raw?.rates?.length) return;\n out.push(...answerFromTable(toRows(raw), group, raw.rate_date, code));\n }),\n );\n return out;\n },\n };\n};\n\n/**\n * Source codes served by AllRatesToday on 2026-10-19 (125). `composite` is the\n * cross-bank USD table. Refresh with `GET /api/open/central-banks`.\n */\nexport const CENTRAL_BANK_CODES = [\n 'amcm', 'bam', 'banguat', 'banxico', 'bazg', 'bb', 'bcb', 'bcbol', 'bcc', 'bcch', 'bccr', 'bccu', 'bceao', 'bch',\n 'bcm', 'bcn', 'bcp', 'bcra', 'bcrd', 'bcrp', 'bcstp', 'bct', 'bcu', 'bcv', 'bda', 'bdi', 'bdm', 'beac', 'bfm', 'bi',\n 'bmu', 'bna', 'bnb', 'bnm', 'bnr', 'bnrw', 'boa', 'bob', 'boc', 'boe', 'bog', 'bogy', 'boi', 'boj', 'bojm', 'bok',\n 'bol', 'bom', 'bon', 'bot', 'botz', 'bou', 'boz', 'brh', 'bsl', 'bsp', 'cba', 'cbar', 'cbb', 'cbbd', 'cbbh', 'cbbz',\n 'cbc', 'cbe', 'cbg', 'cbi', 'cbiq', 'cbj', 'cbk', 'cbke', 'cbl', 'cbm', 'cbn', 'cbo', 'cbr', 'cbsl', 'cbt', 'cbtt',\n 'cbu', 'cbuae', 'cbvs', 'cnb', 'composite', 'dnb', 'ecb', 'fed', 'hkma', 'hmrc', 'lb', 'mas', 'mma', 'mnb', 'nbc',\n 'nbe', 'nbg', 'nbk', 'nbkr', 'nbm', 'nbp', 'nbrb', 'nbrm', 'nbs', 'nbt', 'nbu', 'norges', 'nrb', 'pboc', 'pma',\n 'qcb', 'rba', 'rbf', 'rbi', 'rbm', 'rbnz', 'rbz', 'riksbank', 'rma', 'sama', 'sarb', 'sbp', 'sbv', 'sfc', 'snb',\n 'tcmb', 'ustreasury',\n] as const;\n\nexport type CentralBankCode = (typeof CENTRAL_BANK_CODES)[number];\n\n/** One factory per source, keyed by code: `centralBanks.ecb()`, `centralBanks.boe()`, ... */\nexport const centralBanks = Object.fromEntries(\n CENTRAL_BANK_CODES.map((code) => [code, (options?: PluginOptions) => makeCentralBankPlugin(code, options)]),\n) as Record<CentralBankCode, (options?: PluginOptions) => RatePlugin>;\n","import { makeHttp } from '../http';\nimport { answerFromTable, groupByDate, type TableRow } from '../table';\nimport type { PluginOptions, RatePair, RatePlugin } from '../types';\n\ninterface ReferenceResponse {\n rate_date: string;\n base: string;\n rates: Array<{ base: string; quote: string; value: number }>;\n}\n\n/**\n * The AllRatesToday daily reference rate: one USD-based table a day, fixed at\n * 16:00 London. The latest table is keyless (`/api/open/reference-rate`);\n * dated tables (`/api/v1/reference-rate/{date}`) need an API key. Any pair is\n * crossed through USD.\n */\nexport const makeReferenceRatePlugin = (options: PluginOptions = {}): RatePlugin => {\n const http = makeHttp(options);\n const toRows = (r: ReferenceResponse): TableRow[] =>\n r.rates.map((x) => ({ base: x.base, quote: x.quote, value: x.value, type: 'reference' }));\n return {\n rateInfo: {\n pluginId: 'referenceRate',\n displayName: 'AllRatesToday daily reference rate (16:00 London)',\n keyless: true,\n homepage: 'https://allratestoday.com/reference-rate/',\n },\n async fetchRates(hints) {\n const out: RatePair[] = [];\n await Promise.all(\n [...groupByDate(hints)].map(async ([date, group]) => {\n let raw: ReferenceResponse;\n try {\n raw = (\n date\n ? await http.getJson(`/api/v1/reference-rate/${date}`, {}, true)\n : await http.getJson('/api/open/reference-rate')\n ) as ReferenceResponse;\n } catch {\n return;\n }\n if (!raw?.rates?.length) return;\n out.push(...answerFromTable(toRows(raw), group, raw.rate_date, 'referenceRate', 'reference'));\n }),\n );\n return out;\n },\n };\n};\n","import type { RateHint, RatePair, RatePlugin } from './types';\n\nexport interface RateEngine {\n readonly plugins: RatePlugin[];\n /** Ask each plugin in order; a hint answered by an earlier plugin is not asked again. */\n fetchRates: (hints: RateHint[]) => Promise<RatePair[]>;\n /** One pair, or null when no plugin covers it. */\n getRate: (fromCurrency: string, toCurrency: string, date?: string) => Promise<RatePair | null>;\n /** Convert an amount; throws when no plugin covers the pair. */\n convert: (amount: number, fromCurrency: string, toCurrency: string, date?: string) => Promise<{ amount: number; result: number; pair: RatePair }>;\n}\n\nconst key = (h: RateHint): string =>\n `${h.fromCurrency.toUpperCase()}_${h.toCurrency.toUpperCase()}_${h.date ?? ''}`;\n\n/**\n * Ordered fallback over plugins. Pass the plugins in preference order, e.g.\n * live first, then the daily reference rate, then an official table.\n */\nexport function makeRateEngine(plugins: RatePlugin[] | Record<string, RatePlugin>): RateEngine {\n const list = Array.isArray(plugins) ? plugins : Object.values(plugins);\n return {\n plugins: list,\n async fetchRates(hints) {\n const answered = new Map<string, RatePair>();\n let remaining = hints.slice();\n for (const plugin of list) {\n if (remaining.length === 0) break;\n let pairs: RatePair[] = [];\n try {\n pairs = await plugin.fetchRates(remaining);\n } catch {\n continue;\n }\n for (const p of pairs) {\n const k = `${p.fromCurrency}_${p.toCurrency}_`;\n // Match on the requested date, not the answered one (weekends\n // resolve to the previous business day).\n for (const h of remaining) {\n if (key(h).startsWith(k) && !answered.has(key(h))) answered.set(key(h), p);\n }\n }\n remaining = remaining.filter((h) => !answered.has(key(h)));\n }\n return hints.map((h) => answered.get(key(h))).filter((p): p is RatePair => p != null);\n },\n async getRate(fromCurrency, toCurrency, date) {\n const [pair] = await this.fetchRates([{ fromCurrency, toCurrency, date }]);\n return pair ?? null;\n },\n async convert(amount, fromCurrency, toCurrency, date) {\n const pair = await this.getRate(fromCurrency, toCurrency, date);\n if (!pair) throw new Error(`No plugin covers ${fromCurrency}/${toCurrency}${date ? ` on ${date}` : ''}`);\n return { amount, result: Number((amount * pair.rate).toPrecision(12)), pair };\n },\n };\n}\n","import { makeAllRatesTodayPlugin } from './plugins/allratestoday';\nimport { centralBanks, makeCentralBankPlugin } from './plugins/centralBank';\nimport { makeReferenceRatePlugin } from './plugins/referenceRate';\nimport type { PluginOptions, RatePlugin } from './types';\n\nexport * from './types';\nexport { ExchangePluginError, DEFAULT_BASE_URL } from './http';\nexport { resolvePair, answerFromTable } from './table';\nexport type { TableRow } from './table';\nexport { makeRateEngine } from './engine';\nexport type { RateEngine } from './engine';\nexport { makeAllRatesTodayPlugin } from './plugins/allratestoday';\nexport { makeReferenceRatePlugin } from './plugins/referenceRate';\nexport { makeCentralBankPlugin, centralBanks, CENTRAL_BANK_CODES } from './plugins/centralBank';\nexport type { CentralBankCode } from './plugins/centralBank';\n\n/**\n * Every plugin factory in this package, keyed by pluginId. Mirrors the\n * `plugins` export of edge-exchange-plugins: pick the ones you want, or\n * register them all.\n */\nexport const plugins = {\n // Live:\n allratestoday: makeAllRatesTodayPlugin,\n // Daily reference:\n referenceRate: makeReferenceRatePlugin,\n // Official tables (125 sources):\n ...centralBanks,\n};\n\nexport type PluginId = keyof typeof plugins;\n\n/**\n * Instantiate a set of plugins with shared options. Pass ids in preference\n * order; the result is ready for `makeRateEngine`.\n */\nexport function makePlugins(ids: PluginId[], options: PluginOptions = {}): RatePlugin[] {\n return ids.map((id) => {\n const factory = plugins[id];\n if (!factory) throw new Error(`Unknown plugin: ${id}`);\n return factory(options);\n });\n}\n\n/** The recommended default stack: live when a key is set, then reference rate, then the composite table. */\nexport function makeDefaultPlugins(options: PluginOptions = {}): RatePlugin[] {\n const list: RatePlugin[] = [];\n if (options.apiKey) list.push(makeAllRatesTodayPlugin(options));\n list.push(makeReferenceRatePlugin(options), makeCentralBankPlugin('composite', options));\n return list;\n}\n\nexport default plugins;\n"],"mappings":";AAEO,IAAM,mBAAmB;AAEzB,IAAM,sBAAN,cAAkC,MAAM;AAAA,EAG7C,YAAY,SAAiB,QAAgB,MAAe;AAC1D,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,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;AAAA,IACjB;AAAA,IACA,MAAM,QAAQ,QAAQ,cAAc,YAAY,MAAM;AACpD,YAAM,OAAO,MAAM,KAAK,QAAQ,cAAc,YAAY,IAAI;AAC9D,UAAI,CAAC,KAAM,OAAM,IAAI,MAAM,oBAAoB,YAAY,IAAI,UAAU,GAAG,OAAO,OAAO,IAAI,KAAK,EAAE,EAAE;AACvG,aAAO,EAAE,QAAQ,QAAQ,QAAQ,SAAS,KAAK,MAAM,YAAY,EAAE,CAAC,GAAG,KAAK;AAAA,IAC9E;AAAA,EACF;AACF;;;ACnCO,IAAM,UAAU;AAAA;AAAA,EAErB,eAAe;AAAA;AAAA,EAEf,eAAe;AAAA;AAAA,EAEf,GAAG;AACL;AAQO,SAAS,YAAY,KAAiB,UAAyB,CAAC,GAAiB;AACtF,SAAO,IAAI,IAAI,CAAC,OAAO;AACrB,UAAM,UAAU,QAAQ,EAAE;AAC1B,QAAI,CAAC,QAAS,OAAM,IAAI,MAAM,mBAAmB,EAAE,EAAE;AACrD,WAAO,QAAQ,OAAO;AAAA,EACxB,CAAC;AACH;AAGO,SAAS,mBAAmB,UAAyB,CAAC,GAAiB;AAC5E,QAAM,OAAqB,CAAC;AAC5B,MAAI,QAAQ,OAAQ,MAAK,KAAK,wBAAwB,OAAO,CAAC;AAC9D,OAAK,KAAK,wBAAwB,OAAO,GAAG,sBAAsB,aAAa,OAAO,CAAC;AACvF,SAAO;AACT;AAEA,IAAO,cAAQ;","names":["key","plugins"]}
|
|
1
|
+
{"version":3,"sources":["../src/http.ts","../src/plugins/allratestoday.ts","../src/table.ts","../src/plugins/centralBank.ts","../src/plugins/referenceRate.ts","../src/engine.ts","../src/index.ts"],"sourcesContent":["import type { PluginOptions } from './types';\n\nexport const DEFAULT_BASE_URL = 'https://allratestoday.com';\n\nexport class ExchangePluginError extends Error {\n readonly status: number;\n readonly body: unknown;\n constructor(message: string, status: number, body: unknown) {\n super(message);\n this.name = 'ExchangePluginError';\n this.status = status;\n this.body = body;\n }\n}\n\nexport interface Http {\n getJson: (path: string, params?: Record<string, string>, requireKey?: boolean) => Promise<unknown>;\n hasKey: boolean;\n}\n\nexport function makeHttp(options: PluginOptions = {}): Http {\n const base = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/$/, '');\n const doFetch = options.fetch ?? globalThis.fetch;\n if (typeof doFetch !== 'function') {\n throw new Error('No fetch available: pass { fetch } in the plugin options');\n }\n const timeoutMs = options.timeoutMs ?? 10_000;\n const apiKey = options.apiKey;\n\n return {\n hasKey: typeof apiKey === 'string' && apiKey.length > 0,\n async getJson(path, params = {}, requireKey = false) {\n if (requireKey && !apiKey) {\n throw new ExchangePluginError(`${path} needs an API key`, 401, null);\n }\n const url = new URL(base + path);\n for (const [k, v] of Object.entries(params)) if (v !== '') url.searchParams.set(k, v);\n const headers: Record<string, string> = {\n Accept: 'application/json',\n 'User-Agent': '@allratestoday/exchange-plugins',\n };\n if (apiKey) headers.Authorization = `Bearer ${apiKey}`;\n const controller = typeof AbortController === 'function' ? new AbortController() : undefined;\n const timer = controller ? setTimeout(() => controller.abort(), timeoutMs) : undefined;\n try {\n const res = await doFetch(url.toString(), { headers, signal: controller?.signal });\n const text = await res.text();\n let body: unknown = null;\n try {\n body = text ? JSON.parse(text) : null;\n } catch {\n body = text;\n }\n if (!res.ok) {\n const msg =\n body && typeof body === 'object' && 'error' in body\n ? String((body as { error: unknown }).error)\n : `HTTP ${res.status}`;\n throw new ExchangePluginError(msg, res.status, body);\n }\n return body;\n } finally {\n if (timer) clearTimeout(timer);\n }\n },\n };\n}\n","import { makeHttp } from '../http';\nimport type { PluginOptions, RatePair, RatePlugin } from '../types';\n\ninterface LiveRate {\n rate: number;\n source: string;\n target: string;\n time: string;\n}\n\n/**\n * Live mid-market rates from `GET /api/v1/rates`. Needs an API key (the free\n * tier needs no card). Answers only undated hints; dated hints are\n * left for the reference-rate or central-bank plugins.\n */\nexport const makeAllRatesTodayPlugin = (options: PluginOptions = {}): RatePlugin => {\n const http = makeHttp(options);\n return {\n rateInfo: {\n pluginId: 'allratestoday',\n displayName: 'AllRatesToday live mid-market',\n keyless: false,\n homepage: 'https://allratestoday.com/docs/',\n },\n async fetchRates(hints) {\n if (!http.hasKey) return [];\n const bySource = new Map<string, Set<string>>();\n for (const h of hints) {\n if (h.date) continue;\n const from = h.fromCurrency.toUpperCase();\n const to = h.toCurrency.toUpperCase();\n if (from === to) continue;\n const set = bySource.get(from) ?? new Set<string>();\n set.add(to);\n bySource.set(from, set);\n }\n const out: RatePair[] = [];\n await Promise.all(\n [...bySource].map(async ([source, targets]) => {\n let raw: unknown;\n try {\n raw = await http.getJson('/api/v1/rates', { source, target: [...targets].join(',') }, true);\n } catch {\n return;\n }\n const rows: LiveRate[] = Array.isArray(raw) ? raw : raw ? [raw as LiveRate] : [];\n for (const r of rows) {\n if (typeof r?.rate !== 'number' || !r.target) continue;\n out.push({\n fromCurrency: source,\n toCurrency: r.target.toUpperCase(),\n rate: r.rate,\n date: (r.time ?? new Date().toISOString()).slice(0, 10),\n pluginId: 'allratestoday',\n rateType: 'mid-market',\n method: 'published',\n });\n }\n }),\n );\n for (const h of hints) {\n if (h.date) continue;\n const from = h.fromCurrency.toUpperCase();\n if (from === h.toCurrency.toUpperCase()) {\n out.push({ fromCurrency: from, toCurrency: from, rate: 1, date: new Date().toISOString().slice(0, 10), pluginId: 'allratestoday', rateType: 'mid-market', method: 'published' });\n }\n }\n return out;\n },\n };\n};\n","import type { RateHint, RateMethod, RatePair } from './types';\n\n/** One row of a published table: `value` units of `quote` per 1 `base`. */\nexport interface TableRow {\n base: string;\n quote: string;\n value: number;\n type: string;\n}\n\nconst round = (n: number): number => Number(n.toPrecision(12));\n\n/**\n * Resolve a pair from a full table: direct row, inverted row, or a cross\n * through a currency both sides are quoted against. Returns null when the\n * table does not cover the pair.\n */\nexport function resolvePair(\n rows: TableRow[],\n from: string,\n to: string,\n): { rate: number; method: RateMethod; type: string } | null {\n if (from === to) return { rate: 1, method: 'published', type: rows[0]?.type ?? 'reference' };\n const direct = rows.find((r) => r.base === from && r.quote === to && r.value > 0);\n if (direct) return { rate: direct.value, method: 'published', type: direct.type };\n const inverse = rows.find((r) => r.base === to && r.quote === from && r.value > 0);\n if (inverse) return { rate: round(1 / inverse.value), method: 'inverse', type: inverse.type };\n\n // Cross: find a base B with rows B->from and B->to (the usual table shape),\n // or any mix of directions through B.\n const perBase = new Map<string, number>(); // B -> units of `from` per 1 B\n const perBaseTo = new Map<string, number>(); // B -> units of `to` per 1 B\n for (const r of rows) {\n if (r.value <= 0) continue;\n if (r.quote === from) perBase.set(r.base, r.value);\n if (r.base === from) perBase.set(r.quote, round(1 / r.value));\n if (r.quote === to) perBaseTo.set(r.base, r.value);\n if (r.base === to) perBaseTo.set(r.quote, round(1 / r.value));\n }\n for (const [b, fromPerB] of perBase) {\n const toPerB = perBaseTo.get(b);\n if (toPerB !== undefined) {\n const type = rows.find((r) => r.base === b || r.quote === b)?.type ?? 'reference';\n return { rate: round(toPerB / fromPerB), method: 'cross', type };\n }\n }\n return null;\n}\n\nexport function answerFromTable(\n rows: TableRow[],\n hints: RateHint[],\n date: string,\n pluginId: string,\n rateType?: string,\n): RatePair[] {\n const out: RatePair[] = [];\n for (const h of hints) {\n const from = h.fromCurrency.toUpperCase();\n const to = h.toCurrency.toUpperCase();\n const hit = resolvePair(rows, from, to);\n if (!hit) continue;\n out.push({\n fromCurrency: from,\n toCurrency: to,\n rate: hit.rate,\n date,\n pluginId,\n rateType: rateType ?? hit.type,\n method: hit.method,\n });\n }\n return out;\n}\n\n/** Group hints by requested date; `''` holds the \"latest\" hints. */\nexport function groupByDate(hints: RateHint[]): Map<string, RateHint[]> {\n const m = new Map<string, RateHint[]>();\n for (const h of hints) {\n const key = h.date ?? '';\n const list = m.get(key) ?? [];\n list.push(h);\n m.set(key, list);\n }\n return m;\n}\n","import { makeHttp } from '../http';\nimport { answerFromTable, groupByDate, type TableRow } from '../table';\nimport type { PluginOptions, RatePair, RatePlugin } from '../types';\n\ninterface TableResponse {\n bank: string;\n rate_date: string;\n rates: Array<{ base: string; quote: string; type: string; value: number }>;\n}\n\n/**\n * Official exchange-rate tables published by a central bank or tax authority,\n * served by AllRatesToday. The latest table is keyless\n * (`/api/open/central-bank/{bank}`); dated tables\n * (`/api/v1/central-bank/{bank}/{date}`) need a paid key. Pairs the\n * institution does not publish directly are inverted or crossed through its\n * home currency, and the answer says so in `method`.\n *\n * `bank` is an AllRatesToday source code, e.g. `ecb`, `boe`, `rbi`, `hmrc`.\n * The full list is `GET https://allratestoday.com/api/open/central-banks`.\n */\n/** Tax authorities live under a different page base on allratestoday.com. */\nconst TAX_AUTHORITIES = new Set(['hmrc', 'bazg', 'ustreasury']);\n\nexport const makeCentralBankPlugin = (bank: string, options: PluginOptions = {}): RatePlugin => {\n const code = bank.toLowerCase();\n const pageBase = TAX_AUTHORITIES.has(code) ? 'tax-authority-rates-api' : 'central-bank-rates-api';\n const http = makeHttp(options);\n const toRows = (r: TableResponse): TableRow[] =>\n r.rates.map((x) => ({ base: x.base, quote: x.quote, value: x.value, type: x.type }));\n return {\n rateInfo: {\n pluginId: code,\n displayName: `Official rates: ${code.toUpperCase()}`,\n keyless: true,\n homepage: `https://allratestoday.com/${pageBase}/${code}/`,\n },\n async fetchRates(hints) {\n const out: RatePair[] = [];\n await Promise.all(\n [...groupByDate(hints)].map(async ([date, group]) => {\n let raw: TableResponse;\n try {\n raw = (\n date\n ? await http.getJson(`/api/v1/central-bank/${code}/${date}`, {}, true)\n : await http.getJson(`/api/open/central-bank/${code}`)\n ) as TableResponse;\n } catch {\n return;\n }\n if (!raw?.rates?.length) return;\n out.push(...answerFromTable(toRows(raw), group, raw.rate_date, code));\n }),\n );\n return out;\n },\n };\n};\n\n/**\n * Source codes served by AllRatesToday on 2026-10-19 (125). `composite` is the\n * cross-bank USD table. Refresh with `GET /api/open/central-banks`.\n */\nexport const CENTRAL_BANK_CODES = [\n 'amcm', 'bam', 'banguat', 'banxico', 'bazg', 'bb', 'bcb', 'bcbol', 'bcc', 'bcch', 'bccr', 'bccu', 'bceao', 'bch',\n 'bcm', 'bcn', 'bcp', 'bcra', 'bcrd', 'bcrp', 'bcstp', 'bct', 'bcu', 'bcv', 'bda', 'bdi', 'bdm', 'beac', 'bfm', 'bi',\n 'bmu', 'bna', 'bnb', 'bnm', 'bnr', 'bnrw', 'boa', 'bob', 'boc', 'boe', 'bog', 'bogy', 'boi', 'boj', 'bojm', 'bok',\n 'bol', 'bom', 'bon', 'bot', 'botz', 'bou', 'boz', 'brh', 'bsl', 'bsp', 'cba', 'cbar', 'cbb', 'cbbd', 'cbbh', 'cbbz',\n 'cbc', 'cbe', 'cbg', 'cbi', 'cbiq', 'cbj', 'cbk', 'cbke', 'cbl', 'cbm', 'cbn', 'cbo', 'cbr', 'cbsl', 'cbt', 'cbtt',\n 'cbu', 'cbuae', 'cbvs', 'cnb', 'composite', 'dnb', 'ecb', 'fed', 'hkma', 'hmrc', 'lb', 'mas', 'mma', 'mnb', 'nbc',\n 'nbe', 'nbg', 'nbk', 'nbkr', 'nbm', 'nbp', 'nbrb', 'nbrm', 'nbs', 'nbt', 'nbu', 'norges', 'nrb', 'pboc', 'pma',\n 'qcb', 'rba', 'rbf', 'rbi', 'rbm', 'rbnz', 'rbz', 'riksbank', 'rma', 'sama', 'sarb', 'sbp', 'sbv', 'sfc', 'snb',\n 'tcmb', 'ustreasury',\n] as const;\n\nexport type CentralBankCode = (typeof CENTRAL_BANK_CODES)[number];\n\n/** One factory per source, keyed by code: `centralBanks.ecb()`, `centralBanks.boe()`, ... */\nexport const centralBanks = Object.fromEntries(\n CENTRAL_BANK_CODES.map((code) => [code, (options?: PluginOptions) => makeCentralBankPlugin(code, options)]),\n) as Record<CentralBankCode, (options?: PluginOptions) => RatePlugin>;\n","import { makeHttp } from '../http';\nimport { answerFromTable, groupByDate, type TableRow } from '../table';\nimport type { PluginOptions, RatePair, RatePlugin } from '../types';\n\ninterface ReferenceResponse {\n rate_date: string;\n base: string;\n rates: Array<{ base: string; quote: string; value: number }>;\n}\n\n/**\n * The AllRatesToday daily reference rate: one USD-based table a day, fixed at\n * 16:00 London. The latest table is keyless (`/api/open/reference-rate`);\n * dated tables (`/api/v1/reference-rate/{date}`) need an API key. Any pair is\n * crossed through USD.\n */\nexport const makeReferenceRatePlugin = (options: PluginOptions = {}): RatePlugin => {\n const http = makeHttp(options);\n const toRows = (r: ReferenceResponse): TableRow[] =>\n r.rates.map((x) => ({ base: x.base, quote: x.quote, value: x.value, type: 'reference' }));\n return {\n rateInfo: {\n pluginId: 'referenceRate',\n displayName: 'AllRatesToday daily reference rate (16:00 London)',\n keyless: true,\n homepage: 'https://allratestoday.com/reference-rate/',\n },\n async fetchRates(hints) {\n const out: RatePair[] = [];\n await Promise.all(\n [...groupByDate(hints)].map(async ([date, group]) => {\n let raw: ReferenceResponse;\n try {\n raw = (\n date\n ? await http.getJson(`/api/v1/reference-rate/${date}`, {}, true)\n : await http.getJson('/api/open/reference-rate')\n ) as ReferenceResponse;\n } catch {\n return;\n }\n if (!raw?.rates?.length) return;\n out.push(...answerFromTable(toRows(raw), group, raw.rate_date, 'referenceRate', 'reference'));\n }),\n );\n return out;\n },\n };\n};\n","import type { RateHint, RatePair, RatePlugin } from './types';\n\nexport interface RateEngine {\n readonly plugins: RatePlugin[];\n /** Ask each plugin in order; a hint answered by an earlier plugin is not asked again. */\n fetchRates: (hints: RateHint[]) => Promise<RatePair[]>;\n /** One pair, or null when no plugin covers it. */\n getRate: (fromCurrency: string, toCurrency: string, date?: string) => Promise<RatePair | null>;\n /** Convert an amount; throws when no plugin covers the pair. */\n convert: (amount: number, fromCurrency: string, toCurrency: string, date?: string) => Promise<{ amount: number; result: number; pair: RatePair }>;\n}\n\nconst key = (h: RateHint): string =>\n `${h.fromCurrency.toUpperCase()}_${h.toCurrency.toUpperCase()}_${h.date ?? ''}`;\n\n/**\n * Ordered fallback over plugins. Pass the plugins in preference order, e.g.\n * live first, then the daily reference rate, then an official table.\n */\nexport function makeRateEngine(plugins: RatePlugin[] | Record<string, RatePlugin>): RateEngine {\n const list = Array.isArray(plugins) ? plugins : Object.values(plugins);\n return {\n plugins: list,\n async fetchRates(hints) {\n const answered = new Map<string, RatePair>();\n let remaining = hints.slice();\n for (const plugin of list) {\n if (remaining.length === 0) break;\n let pairs: RatePair[] = [];\n try {\n pairs = await plugin.fetchRates(remaining);\n } catch {\n continue;\n }\n for (const p of pairs) {\n const k = `${p.fromCurrency}_${p.toCurrency}_`;\n // Match on the requested date, not the answered one (weekends\n // resolve to the previous business day).\n for (const h of remaining) {\n if (key(h).startsWith(k) && !answered.has(key(h))) answered.set(key(h), p);\n }\n }\n remaining = remaining.filter((h) => !answered.has(key(h)));\n }\n return hints.map((h) => answered.get(key(h))).filter((p): p is RatePair => p != null);\n },\n async getRate(fromCurrency, toCurrency, date) {\n const [pair] = await this.fetchRates([{ fromCurrency, toCurrency, date }]);\n return pair ?? null;\n },\n async convert(amount, fromCurrency, toCurrency, date) {\n const pair = await this.getRate(fromCurrency, toCurrency, date);\n if (!pair) throw new Error(`No plugin covers ${fromCurrency}/${toCurrency}${date ? ` on ${date}` : ''}`);\n return { amount, result: Number((amount * pair.rate).toPrecision(12)), pair };\n },\n };\n}\n","import { makeAllRatesTodayPlugin } from './plugins/allratestoday';\nimport { centralBanks, makeCentralBankPlugin } from './plugins/centralBank';\nimport { makeReferenceRatePlugin } from './plugins/referenceRate';\nimport type { PluginOptions, RatePlugin } from './types';\n\nexport * from './types';\nexport { ExchangePluginError, DEFAULT_BASE_URL } from './http';\nexport { resolvePair, answerFromTable } from './table';\nexport type { TableRow } from './table';\nexport { makeRateEngine } from './engine';\nexport type { RateEngine } from './engine';\nexport { makeAllRatesTodayPlugin } from './plugins/allratestoday';\nexport { makeReferenceRatePlugin } from './plugins/referenceRate';\nexport { makeCentralBankPlugin, centralBanks, CENTRAL_BANK_CODES } from './plugins/centralBank';\nexport type { CentralBankCode } from './plugins/centralBank';\n\n/**\n * Every plugin factory in this package, keyed by pluginId. Mirrors the\n * `plugins` export of edge-exchange-plugins: pick the ones you want, or\n * register them all.\n */\nexport const plugins = {\n // Live:\n allratestoday: makeAllRatesTodayPlugin,\n // Daily reference:\n referenceRate: makeReferenceRatePlugin,\n // Official tables (125 sources):\n ...centralBanks,\n};\n\nexport type PluginId = keyof typeof plugins;\n\n/**\n * Instantiate a set of plugins with shared options. Pass ids in preference\n * order; the result is ready for `makeRateEngine`.\n */\nexport function makePlugins(ids: PluginId[], options: PluginOptions = {}): RatePlugin[] {\n return ids.map((id) => {\n const factory = plugins[id];\n if (!factory) throw new Error(`Unknown plugin: ${id}`);\n return factory(options);\n });\n}\n\n/** The recommended default stack: live when a key is set, then reference rate, then the composite table. */\nexport function makeDefaultPlugins(options: PluginOptions = {}): RatePlugin[] {\n const list: RatePlugin[] = [];\n if (options.apiKey) list.push(makeAllRatesTodayPlugin(options));\n list.push(makeReferenceRatePlugin(options), makeCentralBankPlugin('composite', options));\n return list;\n}\n\nexport default plugins;\n"],"mappings":";AAEO,IAAM,mBAAmB;AAEzB,IAAM,sBAAN,cAAkC,MAAM;AAAA,EAG7C,YAAY,SAAiB,QAAgB,MAAe;AAC1D,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO;AAAA,EACd;AACF;AAOO,SAAS,SAAS,UAAyB,CAAC,GAAS;AAC1D,QAAM,QAAQ,QAAQ,WAAW,kBAAkB,QAAQ,OAAO,EAAE;AACpE,QAAM,UAAU,QAAQ,SAAS,WAAW;AAC5C,MAAI,OAAO,YAAY,YAAY;AACjC,UAAM,IAAI,MAAM,0DAA0D;AAAA,EAC5E;AACA,QAAM,YAAY,QAAQ,aAAa;AACvC,QAAM,SAAS,QAAQ;AAEvB,SAAO;AAAA,IACL,QAAQ,OAAO,WAAW,YAAY,OAAO,SAAS;AAAA,IACtD,MAAM,QAAQ,MAAM,SAAS,CAAC,GAAG,aAAa,OAAO;AACnD,UAAI,cAAc,CAAC,QAAQ;AACzB,cAA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AS,YAAY,KAAiB,UAAyB,CAAC,GAAiB;AACtF,SAAO,IAAI,IAAI,CAAC,OAAO;AACrB,UAAM,UAAU,QAAQ,EAAE;AAC1B,QAAI,CAAC,QAAS,OAAM,IAAI,MAAM,mBAAmB,EAAE,EAAE;AACrD,WAAO,QAAQ,OAAO;AAAA,EACxB,CAAC;AACH;AAGO,SAAS,mBAAmB,UAAyB,CAAC,GAAiB;AAC5E,QAAM,OAAqB,CAAC;AAC5B,MAAI,QAAQ,OAAQ,MAAK,KAAK,wBAAwB,OAAO,CAAC;AAC9D,OAAK,KAAK,wBAAwB,OAAO,GAAG,sBAAsB,aAAa,OAAO,CAAC;AACvF,SAAO;AACT;AAEA,IAAO,cAAQ;","names":["key","plugins"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@allratestoday/exchange-plugins",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Exchange-rate source plugins for AllRatesToday: live mid-market rates, the daily 16:00 London reference rate and official central-bank tables, behind one plugin interface with ordered fallback. Includes a drop-in provider for edge-rates-server.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|