@allratestoday/exchange-plugins 0.0.0-stage → 1.0.1

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/dist/index.js ADDED
@@ -0,0 +1,479 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key2 of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key2) && key2 !== except)
14
+ __defProp(to, key2, { get: () => from[key2], enumerable: !(desc = __getOwnPropDesc(from, key2)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ CENTRAL_BANK_CODES: () => CENTRAL_BANK_CODES,
24
+ DEFAULT_BASE_URL: () => DEFAULT_BASE_URL,
25
+ ExchangePluginError: () => ExchangePluginError,
26
+ answerFromTable: () => answerFromTable,
27
+ centralBanks: () => centralBanks,
28
+ default: () => src_default,
29
+ makeAllRatesTodayPlugin: () => makeAllRatesTodayPlugin,
30
+ makeCentralBankPlugin: () => makeCentralBankPlugin,
31
+ makeDefaultPlugins: () => makeDefaultPlugins,
32
+ makePlugins: () => makePlugins,
33
+ makeRateEngine: () => makeRateEngine,
34
+ makeReferenceRatePlugin: () => makeReferenceRatePlugin,
35
+ plugins: () => plugins,
36
+ resolvePair: () => resolvePair
37
+ });
38
+ module.exports = __toCommonJS(src_exports);
39
+
40
+ // src/http.ts
41
+ var DEFAULT_BASE_URL = "https://allratestoday.com";
42
+ var ExchangePluginError = class extends Error {
43
+ constructor(message, status, body) {
44
+ super(message);
45
+ this.name = "ExchangePluginError";
46
+ this.status = status;
47
+ this.body = body;
48
+ }
49
+ };
50
+ function makeHttp(options = {}) {
51
+ const base = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "");
52
+ const doFetch = options.fetch ?? globalThis.fetch;
53
+ if (typeof doFetch !== "function") {
54
+ throw new Error("No fetch available: pass { fetch } in the plugin options");
55
+ }
56
+ const timeoutMs = options.timeoutMs ?? 1e4;
57
+ const apiKey = options.apiKey;
58
+ return {
59
+ hasKey: typeof apiKey === "string" && apiKey.length > 0,
60
+ async getJson(path, params = {}, requireKey = false) {
61
+ if (requireKey && !apiKey) {
62
+ throw new ExchangePluginError(`${path} needs an API key`, 401, null);
63
+ }
64
+ const url = new URL(base + path);
65
+ for (const [k, v] of Object.entries(params)) if (v !== "") url.searchParams.set(k, v);
66
+ const headers = {
67
+ Accept: "application/json",
68
+ "User-Agent": "@allratestoday/exchange-plugins"
69
+ };
70
+ if (apiKey) headers.Authorization = `Bearer ${apiKey}`;
71
+ const controller = typeof AbortController === "function" ? new AbortController() : void 0;
72
+ const timer = controller ? setTimeout(() => controller.abort(), timeoutMs) : void 0;
73
+ try {
74
+ const res = await doFetch(url.toString(), { headers, signal: controller?.signal });
75
+ const text = await res.text();
76
+ let body = null;
77
+ try {
78
+ body = text ? JSON.parse(text) : null;
79
+ } catch {
80
+ body = text;
81
+ }
82
+ if (!res.ok) {
83
+ const msg = body && typeof body === "object" && "error" in body ? String(body.error) : `HTTP ${res.status}`;
84
+ throw new ExchangePluginError(msg, res.status, body);
85
+ }
86
+ return body;
87
+ } finally {
88
+ if (timer) clearTimeout(timer);
89
+ }
90
+ }
91
+ };
92
+ }
93
+
94
+ // src/plugins/allratestoday.ts
95
+ var makeAllRatesTodayPlugin = (options = {}) => {
96
+ const http = makeHttp(options);
97
+ return {
98
+ rateInfo: {
99
+ pluginId: "allratestoday",
100
+ displayName: "AllRatesToday live mid-market",
101
+ keyless: false,
102
+ homepage: "https://allratestoday.com/docs/"
103
+ },
104
+ async fetchRates(hints) {
105
+ if (!http.hasKey) return [];
106
+ const bySource = /* @__PURE__ */ new Map();
107
+ for (const h of hints) {
108
+ if (h.date) continue;
109
+ const from = h.fromCurrency.toUpperCase();
110
+ const to = h.toCurrency.toUpperCase();
111
+ if (from === to) continue;
112
+ const set = bySource.get(from) ?? /* @__PURE__ */ new Set();
113
+ set.add(to);
114
+ bySource.set(from, set);
115
+ }
116
+ const out = [];
117
+ await Promise.all(
118
+ [...bySource].map(async ([source, targets]) => {
119
+ let raw;
120
+ try {
121
+ raw = await http.getJson("/api/v1/rates", { source, target: [...targets].join(",") }, true);
122
+ } catch {
123
+ return;
124
+ }
125
+ const rows = Array.isArray(raw) ? raw : raw ? [raw] : [];
126
+ for (const r of rows) {
127
+ if (typeof r?.rate !== "number" || !r.target) continue;
128
+ out.push({
129
+ fromCurrency: source,
130
+ toCurrency: r.target.toUpperCase(),
131
+ rate: r.rate,
132
+ date: (r.time ?? (/* @__PURE__ */ new Date()).toISOString()).slice(0, 10),
133
+ pluginId: "allratestoday",
134
+ rateType: "mid-market",
135
+ method: "published"
136
+ });
137
+ }
138
+ })
139
+ );
140
+ for (const h of hints) {
141
+ if (h.date) continue;
142
+ const from = h.fromCurrency.toUpperCase();
143
+ if (from === h.toCurrency.toUpperCase()) {
144
+ out.push({ fromCurrency: from, toCurrency: from, rate: 1, date: (/* @__PURE__ */ new Date()).toISOString().slice(0, 10), pluginId: "allratestoday", rateType: "mid-market", method: "published" });
145
+ }
146
+ }
147
+ return out;
148
+ }
149
+ };
150
+ };
151
+
152
+ // src/table.ts
153
+ var round = (n) => Number(n.toPrecision(12));
154
+ function resolvePair(rows, from, to) {
155
+ if (from === to) return { rate: 1, method: "published", type: rows[0]?.type ?? "reference" };
156
+ const direct = rows.find((r) => r.base === from && r.quote === to && r.value > 0);
157
+ if (direct) return { rate: direct.value, method: "published", type: direct.type };
158
+ const inverse = rows.find((r) => r.base === to && r.quote === from && r.value > 0);
159
+ if (inverse) return { rate: round(1 / inverse.value), method: "inverse", type: inverse.type };
160
+ const perBase = /* @__PURE__ */ new Map();
161
+ const perBaseTo = /* @__PURE__ */ new Map();
162
+ for (const r of rows) {
163
+ if (r.value <= 0) continue;
164
+ if (r.quote === from) perBase.set(r.base, r.value);
165
+ if (r.base === from) perBase.set(r.quote, round(1 / r.value));
166
+ if (r.quote === to) perBaseTo.set(r.base, r.value);
167
+ if (r.base === to) perBaseTo.set(r.quote, round(1 / r.value));
168
+ }
169
+ for (const [b, fromPerB] of perBase) {
170
+ const toPerB = perBaseTo.get(b);
171
+ if (toPerB !== void 0) {
172
+ const type = rows.find((r) => r.base === b || r.quote === b)?.type ?? "reference";
173
+ return { rate: round(toPerB / fromPerB), method: "cross", type };
174
+ }
175
+ }
176
+ return null;
177
+ }
178
+ function answerFromTable(rows, hints, date, pluginId, rateType) {
179
+ const out = [];
180
+ for (const h of hints) {
181
+ const from = h.fromCurrency.toUpperCase();
182
+ const to = h.toCurrency.toUpperCase();
183
+ const hit = resolvePair(rows, from, to);
184
+ if (!hit) continue;
185
+ out.push({
186
+ fromCurrency: from,
187
+ toCurrency: to,
188
+ rate: hit.rate,
189
+ date,
190
+ pluginId,
191
+ rateType: rateType ?? hit.type,
192
+ method: hit.method
193
+ });
194
+ }
195
+ return out;
196
+ }
197
+ function groupByDate(hints) {
198
+ const m = /* @__PURE__ */ new Map();
199
+ for (const h of hints) {
200
+ const key2 = h.date ?? "";
201
+ const list = m.get(key2) ?? [];
202
+ list.push(h);
203
+ m.set(key2, list);
204
+ }
205
+ return m;
206
+ }
207
+
208
+ // src/plugins/centralBank.ts
209
+ var TAX_AUTHORITIES = /* @__PURE__ */ new Set(["hmrc", "bazg", "ustreasury"]);
210
+ var makeCentralBankPlugin = (bank, options = {}) => {
211
+ const code = bank.toLowerCase();
212
+ const pageBase = TAX_AUTHORITIES.has(code) ? "tax-authority-rates-api" : "central-bank-rates-api";
213
+ const http = makeHttp(options);
214
+ const toRows = (r) => r.rates.map((x) => ({ base: x.base, quote: x.quote, value: x.value, type: x.type }));
215
+ return {
216
+ rateInfo: {
217
+ pluginId: code,
218
+ displayName: `Official rates: ${code.toUpperCase()}`,
219
+ keyless: true,
220
+ homepage: `https://allratestoday.com/${pageBase}/${code}/`
221
+ },
222
+ async fetchRates(hints) {
223
+ const out = [];
224
+ await Promise.all(
225
+ [...groupByDate(hints)].map(async ([date, group]) => {
226
+ let raw;
227
+ try {
228
+ raw = date ? await http.getJson(`/api/v1/central-bank/${code}/${date}`, {}, true) : await http.getJson(`/api/open/central-bank/${code}`);
229
+ } catch {
230
+ return;
231
+ }
232
+ if (!raw?.rates?.length) return;
233
+ out.push(...answerFromTable(toRows(raw), group, raw.rate_date, code));
234
+ })
235
+ );
236
+ return out;
237
+ }
238
+ };
239
+ };
240
+ var CENTRAL_BANK_CODES = [
241
+ "amcm",
242
+ "bam",
243
+ "banguat",
244
+ "banxico",
245
+ "bazg",
246
+ "bb",
247
+ "bcb",
248
+ "bcbol",
249
+ "bcc",
250
+ "bcch",
251
+ "bccr",
252
+ "bccu",
253
+ "bceao",
254
+ "bch",
255
+ "bcm",
256
+ "bcn",
257
+ "bcp",
258
+ "bcra",
259
+ "bcrd",
260
+ "bcrp",
261
+ "bcstp",
262
+ "bct",
263
+ "bcu",
264
+ "bcv",
265
+ "bda",
266
+ "bdi",
267
+ "bdm",
268
+ "beac",
269
+ "bfm",
270
+ "bi",
271
+ "bmu",
272
+ "bna",
273
+ "bnb",
274
+ "bnm",
275
+ "bnr",
276
+ "bnrw",
277
+ "boa",
278
+ "bob",
279
+ "boc",
280
+ "boe",
281
+ "bog",
282
+ "bogy",
283
+ "boi",
284
+ "boj",
285
+ "bojm",
286
+ "bok",
287
+ "bol",
288
+ "bom",
289
+ "bon",
290
+ "bot",
291
+ "botz",
292
+ "bou",
293
+ "boz",
294
+ "brh",
295
+ "bsl",
296
+ "bsp",
297
+ "cba",
298
+ "cbar",
299
+ "cbb",
300
+ "cbbd",
301
+ "cbbh",
302
+ "cbbz",
303
+ "cbc",
304
+ "cbe",
305
+ "cbg",
306
+ "cbi",
307
+ "cbiq",
308
+ "cbj",
309
+ "cbk",
310
+ "cbke",
311
+ "cbl",
312
+ "cbm",
313
+ "cbn",
314
+ "cbo",
315
+ "cbr",
316
+ "cbsl",
317
+ "cbt",
318
+ "cbtt",
319
+ "cbu",
320
+ "cbuae",
321
+ "cbvs",
322
+ "cnb",
323
+ "composite",
324
+ "dnb",
325
+ "ecb",
326
+ "fed",
327
+ "hkma",
328
+ "hmrc",
329
+ "lb",
330
+ "mas",
331
+ "mma",
332
+ "mnb",
333
+ "nbc",
334
+ "nbe",
335
+ "nbg",
336
+ "nbk",
337
+ "nbkr",
338
+ "nbm",
339
+ "nbp",
340
+ "nbrb",
341
+ "nbrm",
342
+ "nbs",
343
+ "nbt",
344
+ "nbu",
345
+ "norges",
346
+ "nrb",
347
+ "pboc",
348
+ "pma",
349
+ "qcb",
350
+ "rba",
351
+ "rbf",
352
+ "rbi",
353
+ "rbm",
354
+ "rbnz",
355
+ "rbz",
356
+ "riksbank",
357
+ "rma",
358
+ "sama",
359
+ "sarb",
360
+ "sbp",
361
+ "sbv",
362
+ "sfc",
363
+ "snb",
364
+ "tcmb",
365
+ "ustreasury"
366
+ ];
367
+ var centralBanks = Object.fromEntries(
368
+ CENTRAL_BANK_CODES.map((code) => [code, (options) => makeCentralBankPlugin(code, options)])
369
+ );
370
+
371
+ // src/plugins/referenceRate.ts
372
+ var makeReferenceRatePlugin = (options = {}) => {
373
+ const http = makeHttp(options);
374
+ const toRows = (r) => r.rates.map((x) => ({ base: x.base, quote: x.quote, value: x.value, type: "reference" }));
375
+ return {
376
+ rateInfo: {
377
+ pluginId: "referenceRate",
378
+ displayName: "AllRatesToday daily reference rate (16:00 London)",
379
+ keyless: true,
380
+ homepage: "https://allratestoday.com/reference-rate/"
381
+ },
382
+ async fetchRates(hints) {
383
+ const out = [];
384
+ await Promise.all(
385
+ [...groupByDate(hints)].map(async ([date, group]) => {
386
+ let raw;
387
+ try {
388
+ raw = date ? await http.getJson(`/api/v1/reference-rate/${date}`, {}, true) : await http.getJson("/api/open/reference-rate");
389
+ } catch {
390
+ return;
391
+ }
392
+ if (!raw?.rates?.length) return;
393
+ out.push(...answerFromTable(toRows(raw), group, raw.rate_date, "referenceRate", "reference"));
394
+ })
395
+ );
396
+ return out;
397
+ }
398
+ };
399
+ };
400
+
401
+ // src/engine.ts
402
+ var key = (h) => `${h.fromCurrency.toUpperCase()}_${h.toCurrency.toUpperCase()}_${h.date ?? ""}`;
403
+ function makeRateEngine(plugins2) {
404
+ const list = Array.isArray(plugins2) ? plugins2 : Object.values(plugins2);
405
+ return {
406
+ plugins: list,
407
+ async fetchRates(hints) {
408
+ const answered = /* @__PURE__ */ new Map();
409
+ let remaining = hints.slice();
410
+ for (const plugin of list) {
411
+ if (remaining.length === 0) break;
412
+ let pairs = [];
413
+ try {
414
+ pairs = await plugin.fetchRates(remaining);
415
+ } catch {
416
+ continue;
417
+ }
418
+ for (const p of pairs) {
419
+ const k = `${p.fromCurrency}_${p.toCurrency}_`;
420
+ for (const h of remaining) {
421
+ if (key(h).startsWith(k) && !answered.has(key(h))) answered.set(key(h), p);
422
+ }
423
+ }
424
+ remaining = remaining.filter((h) => !answered.has(key(h)));
425
+ }
426
+ return hints.map((h) => answered.get(key(h))).filter((p) => p != null);
427
+ },
428
+ async getRate(fromCurrency, toCurrency, date) {
429
+ const [pair] = await this.fetchRates([{ fromCurrency, toCurrency, date }]);
430
+ return pair ?? null;
431
+ },
432
+ async convert(amount, fromCurrency, toCurrency, date) {
433
+ const pair = await this.getRate(fromCurrency, toCurrency, date);
434
+ if (!pair) throw new Error(`No plugin covers ${fromCurrency}/${toCurrency}${date ? ` on ${date}` : ""}`);
435
+ return { amount, result: Number((amount * pair.rate).toPrecision(12)), pair };
436
+ }
437
+ };
438
+ }
439
+
440
+ // src/index.ts
441
+ var plugins = {
442
+ // Live:
443
+ allratestoday: makeAllRatesTodayPlugin,
444
+ // Daily reference:
445
+ referenceRate: makeReferenceRatePlugin,
446
+ // Official tables (125 sources):
447
+ ...centralBanks
448
+ };
449
+ function makePlugins(ids, options = {}) {
450
+ return ids.map((id) => {
451
+ const factory = plugins[id];
452
+ if (!factory) throw new Error(`Unknown plugin: ${id}`);
453
+ return factory(options);
454
+ });
455
+ }
456
+ function makeDefaultPlugins(options = {}) {
457
+ const list = [];
458
+ if (options.apiKey) list.push(makeAllRatesTodayPlugin(options));
459
+ list.push(makeReferenceRatePlugin(options), makeCentralBankPlugin("composite", options));
460
+ return list;
461
+ }
462
+ var src_default = plugins;
463
+ // Annotate the CommonJS export names for ESM import in node:
464
+ 0 && (module.exports = {
465
+ CENTRAL_BANK_CODES,
466
+ DEFAULT_BASE_URL,
467
+ ExchangePluginError,
468
+ answerFromTable,
469
+ centralBanks,
470
+ makeAllRatesTodayPlugin,
471
+ makeCentralBankPlugin,
472
+ makeDefaultPlugins,
473
+ makePlugins,
474
+ makeRateEngine,
475
+ makeReferenceRatePlugin,
476
+ plugins,
477
+ resolvePair
478
+ });
479
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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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