@allratestoday/sdk 1.3.10 โ†’ 1.4.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/README.md CHANGED
@@ -15,6 +15,7 @@
15
15
  - ๐Ÿ“ก **Real-Time Data** โ€” Rates updated every 60 seconds
16
16
  - ๐Ÿ’น **Mid-Market Rates** โ€” No retail spread or markup baked in
17
17
  - ๐ŸŒ **160+ Currencies** โ€” Major, minor, and exotic currency pairs
18
+ - ๐Ÿ›๏ธ **Official Rates Too** โ€” latest tables from 121 central banks + 3 tax authorities via `officialRates()`, no key needed
18
19
  - ๐Ÿ”ท **Type-Safe** โ€” Full TypeScript support with intelligent autocomplete
19
20
  - ๐ŸŒ **Universal** โ€” Works seamlessly in Node.js 18+ and modern browsers
20
21
  - ๐Ÿง‘โ€๐Ÿ’ป **Developer-Friendly** โ€” Simple API, extensive documentation, and great DX
@@ -257,6 +258,34 @@ const rate = await client.getRate('USD', 'EUR', 500);
257
258
  console.log(`$500 = โ‚ฌ${rate.to.amount}`);
258
259
  ```
259
260
 
261
+ ### Official Central-Bank & Tax-Authority Rates (no key needed)
262
+
263
+ The methods above return live mid-market rates. For the **official rate an
264
+ institution published** โ€” what invoices, VAT returns, customs declarations and
265
+ audits require โ€” use `officialRates()`. It covers 121 central banks plus HMRC,
266
+ the US Treasury and Swiss BAZG, and the latest table needs **no API key**:
267
+
268
+ ```typescript
269
+ const client = new AllRatesToday(); // no key
270
+
271
+ // Full ECB reference table
272
+ const table = await client.officialRates('ecb');
273
+ console.log(table.rate_date, table.rates); // [{ base: 'EUR', quote: 'USD', type: 'reference', value: 1.17 }, โ€ฆ]
274
+
275
+ // One pair (cross-computed inside the bank's own table if not published directly โ†’ `derived: true`)
276
+ const usd = await client.officialRates('ecb', { source: 'EUR', target: 'USD' });
277
+ console.log(`ECB ${usd.rate_date}: 1 EUR = ${usd.rate} USD`);
278
+
279
+ // Which sources exist, and which are behind their publication schedule
280
+ const { sources } = await client.officialSources();
281
+ console.log(sources.map((s) => `${s.code} ${s.latest}${s.stale ? ' (stale)' : ''}`));
282
+ ```
283
+
284
+ Always cite the returned `rate_date` โ€” it is the institution's publication date,
285
+ not the time of your call. Dated tables, history and publication calendars sit
286
+ behind the free key on `/api/v1/central-bank/{bank}/{date}`; see the
287
+ [central bank rates API](https://allratestoday.com/central-bank-rates-api/).
288
+
260
289
  ### Historical Rates by Period
261
290
 
262
291
  Get historical rates using preset periods โ€” no date math needed:
@@ -470,6 +499,8 @@ console.log({ labels, values });
470
499
  | `getRate(from, to, amount?, options?)` | Get a single exchange rate |
471
500
  | `getRates(source, target, options?)` | Get rates with full metadata |
472
501
  | `getHistoricalRates(source, target, period?, options?)` | Historical rates by preset period (1d/7d/30d/1y) |
502
+ | `officialRates(bank, options?)` | Latest official table (or one pair) published by a central bank / tax authority โ€” **keyless** |
503
+ | `officialSources(options?)` | Every covered official source with latest publication date and freshness โ€” **keyless** |
473
504
 
474
505
  ---
475
506
 
@@ -495,6 +526,15 @@ npm run test:watch
495
526
 
496
527
  ---
497
528
 
529
+ ## ๐Ÿค– Use it from an AI agent
530
+
531
+ The same rates are available to coding agents and LLM tools without a second integration:
532
+
533
+ - **Claude Code plugin** (no key): `/plugin marketplace add AllRates-Today/claude-code-plugin` then `/plugin install allratestoday@allratestoday`
534
+ - **Hosted MCP endpoint**: `https://allratestoday.com/api/mcp` โ€” Streamable HTTP, keyless, nothing to install
535
+ - **Local MCP servers**: `npx -y @allratestoday/mcp-server` (live mid-market rates) ยท `npx -y @allratestoday/central-bank-mcp` (official central-bank rates)
536
+ - Machine-readable site guide: [llms.txt](https://allratestoday.com/llms.txt)
537
+
498
538
  ## ๐Ÿ”— Links
499
539
 
500
540
  - [API Documentation](https://allratestoday.com/developers)
package/dist/index.d.mts CHANGED
@@ -90,6 +90,60 @@ interface HistoricalRateResponse {
90
90
  interface SymbolsResponse {
91
91
  symbols: Record<string, string>;
92
92
  }
93
+ interface OfficialRateOptions extends RequestOptions {
94
+ /** Base currency of the pair, e.g. `USD`. Give together with `target` to narrow to one pair. */
95
+ source?: string;
96
+ /** Quote currency of the pair, e.g. `EUR`. Give together with `source` to narrow to one pair. */
97
+ target?: string;
98
+ }
99
+ interface OfficialRateEntry {
100
+ base: string;
101
+ quote: string;
102
+ /** Rate type as the institution labels it, e.g. `reference`, `buy`, `sell`, `mid`. */
103
+ type: string;
104
+ value: number;
105
+ }
106
+ interface OfficialRateAttribution {
107
+ source: string;
108
+ url: string;
109
+ terms: string;
110
+ }
111
+ interface OfficialRatesResponse {
112
+ /** Source code, e.g. `ecb`, `fed`, `hmrc`. */
113
+ bank: string;
114
+ /** Publication date of the table (YYYY-MM-DD) โ€” cite this, not today's date. */
115
+ rate_date: string;
116
+ /** Full published table. Present when no pair was requested. */
117
+ rates?: OfficialRateEntry[];
118
+ /** Pair fields. Present when `source` and `target` were given. */
119
+ source?: string;
120
+ target?: string;
121
+ rate?: number;
122
+ rate_type?: string;
123
+ /** True when the pair was cross-computed inside the bank's own table rather than published directly. */
124
+ derived?: boolean;
125
+ method?: 'published' | 'inverse';
126
+ /** True when the institution is behind its own publication schedule. */
127
+ stale?: boolean;
128
+ attribution: OfficialRateAttribution;
129
+ free_key: string;
130
+ }
131
+ interface OfficialSource {
132
+ /** Pass this as `bank` to `officialRates()`. */
133
+ code: string;
134
+ name: string;
135
+ /** Latest publication date, or null if never ingested. */
136
+ latest: string | null;
137
+ stale?: boolean;
138
+ [extra: string]: unknown;
139
+ }
140
+ interface OfficialSourcesResponse {
141
+ sources: OfficialSource[];
142
+ stale_count: number;
143
+ checked_at: string;
144
+ docs: string;
145
+ free_key: string;
146
+ }
93
147
  declare class AllRatesTodayError extends Error {
94
148
  /** HTTP status code (when available). */
95
149
  status?: number;
@@ -166,6 +220,35 @@ declare class AllRatesToday {
166
220
  * ```
167
221
  */
168
222
  symbols(options?: RequestOptions): Promise<SymbolsResponse>;
223
+ /**
224
+ * Latest table of OFFICIAL rates published by a central bank or tax
225
+ * authority (121 central banks + HMRC, US Treasury, Swiss BAZG). These are
226
+ * the fixed, citable rates for invoicing, tax, customs and accounting โ€” not
227
+ * live market rates. **No API key needed.**
228
+ *
229
+ * ```ts
230
+ * // Full ECB reference table
231
+ * const table = await client.officialRates('ecb');
232
+ * console.log(table.rate_date, table.rates);
233
+ *
234
+ * // One pair โ€” cross-computed inside the bank's table when not published directly
235
+ * const usd = await client.officialRates('ecb', { source: 'EUR', target: 'USD' });
236
+ * console.log(`ECB ${usd.rate_date}: 1 EUR = ${usd.rate} USD`);
237
+ * ```
238
+ *
239
+ * Dated tables and history need a free key: see `/api/v1/central-bank/{bank}/{date}`.
240
+ */
241
+ officialRates(bank: string, options?: OfficialRateOptions): Promise<OfficialRatesResponse>;
242
+ /**
243
+ * Every covered official source with its code, name, latest publication
244
+ * date and whether it is behind schedule. **No API key needed.**
245
+ *
246
+ * ```ts
247
+ * const { sources } = await client.officialSources();
248
+ * const behind = sources.filter((s) => s.stale).map((s) => s.code);
249
+ * ```
250
+ */
251
+ officialSources(options?: RequestOptions): Promise<OfficialSourcesResponse>;
169
252
  /**
170
253
  * Get exchange rate between two currencies.
171
254
  *
@@ -215,4 +298,4 @@ declare class AllRatesToday {
215
298
  convert(from: string, to: string, amount: number, options?: ConvertOptions): Promise<ConvertResponse>;
216
299
  }
217
300
 
218
- export { AllRatesToday, AllRatesTodayError, type AllRatesTodayOptions, type AuthRateResponse, type ConvertOptions, type ConvertResponse, type ForDateOptions, type ForDateResponse, type HistoricalRateResponse, type LatestOptions, type LatestResponse, type RateResponse, type RequestOptions, type SymbolsResponse, type TimeSeriesOptions, type TimeSeriesResponse, AllRatesToday as default };
301
+ export { AllRatesToday, AllRatesTodayError, type AllRatesTodayOptions, type AuthRateResponse, type ConvertOptions, type ConvertResponse, type ForDateOptions, type ForDateResponse, type HistoricalRateResponse, type LatestOptions, type LatestResponse, type OfficialRateAttribution, type OfficialRateEntry, type OfficialRateOptions, type OfficialRatesResponse, type OfficialSource, type OfficialSourcesResponse, type RateResponse, type RequestOptions, type SymbolsResponse, type TimeSeriesOptions, type TimeSeriesResponse, AllRatesToday as default };
package/dist/index.d.ts CHANGED
@@ -90,6 +90,60 @@ interface HistoricalRateResponse {
90
90
  interface SymbolsResponse {
91
91
  symbols: Record<string, string>;
92
92
  }
93
+ interface OfficialRateOptions extends RequestOptions {
94
+ /** Base currency of the pair, e.g. `USD`. Give together with `target` to narrow to one pair. */
95
+ source?: string;
96
+ /** Quote currency of the pair, e.g. `EUR`. Give together with `source` to narrow to one pair. */
97
+ target?: string;
98
+ }
99
+ interface OfficialRateEntry {
100
+ base: string;
101
+ quote: string;
102
+ /** Rate type as the institution labels it, e.g. `reference`, `buy`, `sell`, `mid`. */
103
+ type: string;
104
+ value: number;
105
+ }
106
+ interface OfficialRateAttribution {
107
+ source: string;
108
+ url: string;
109
+ terms: string;
110
+ }
111
+ interface OfficialRatesResponse {
112
+ /** Source code, e.g. `ecb`, `fed`, `hmrc`. */
113
+ bank: string;
114
+ /** Publication date of the table (YYYY-MM-DD) โ€” cite this, not today's date. */
115
+ rate_date: string;
116
+ /** Full published table. Present when no pair was requested. */
117
+ rates?: OfficialRateEntry[];
118
+ /** Pair fields. Present when `source` and `target` were given. */
119
+ source?: string;
120
+ target?: string;
121
+ rate?: number;
122
+ rate_type?: string;
123
+ /** True when the pair was cross-computed inside the bank's own table rather than published directly. */
124
+ derived?: boolean;
125
+ method?: 'published' | 'inverse';
126
+ /** True when the institution is behind its own publication schedule. */
127
+ stale?: boolean;
128
+ attribution: OfficialRateAttribution;
129
+ free_key: string;
130
+ }
131
+ interface OfficialSource {
132
+ /** Pass this as `bank` to `officialRates()`. */
133
+ code: string;
134
+ name: string;
135
+ /** Latest publication date, or null if never ingested. */
136
+ latest: string | null;
137
+ stale?: boolean;
138
+ [extra: string]: unknown;
139
+ }
140
+ interface OfficialSourcesResponse {
141
+ sources: OfficialSource[];
142
+ stale_count: number;
143
+ checked_at: string;
144
+ docs: string;
145
+ free_key: string;
146
+ }
93
147
  declare class AllRatesTodayError extends Error {
94
148
  /** HTTP status code (when available). */
95
149
  status?: number;
@@ -166,6 +220,35 @@ declare class AllRatesToday {
166
220
  * ```
167
221
  */
168
222
  symbols(options?: RequestOptions): Promise<SymbolsResponse>;
223
+ /**
224
+ * Latest table of OFFICIAL rates published by a central bank or tax
225
+ * authority (121 central banks + HMRC, US Treasury, Swiss BAZG). These are
226
+ * the fixed, citable rates for invoicing, tax, customs and accounting โ€” not
227
+ * live market rates. **No API key needed.**
228
+ *
229
+ * ```ts
230
+ * // Full ECB reference table
231
+ * const table = await client.officialRates('ecb');
232
+ * console.log(table.rate_date, table.rates);
233
+ *
234
+ * // One pair โ€” cross-computed inside the bank's table when not published directly
235
+ * const usd = await client.officialRates('ecb', { source: 'EUR', target: 'USD' });
236
+ * console.log(`ECB ${usd.rate_date}: 1 EUR = ${usd.rate} USD`);
237
+ * ```
238
+ *
239
+ * Dated tables and history need a free key: see `/api/v1/central-bank/{bank}/{date}`.
240
+ */
241
+ officialRates(bank: string, options?: OfficialRateOptions): Promise<OfficialRatesResponse>;
242
+ /**
243
+ * Every covered official source with its code, name, latest publication
244
+ * date and whether it is behind schedule. **No API key needed.**
245
+ *
246
+ * ```ts
247
+ * const { sources } = await client.officialSources();
248
+ * const behind = sources.filter((s) => s.stale).map((s) => s.code);
249
+ * ```
250
+ */
251
+ officialSources(options?: RequestOptions): Promise<OfficialSourcesResponse>;
169
252
  /**
170
253
  * Get exchange rate between two currencies.
171
254
  *
@@ -215,4 +298,4 @@ declare class AllRatesToday {
215
298
  convert(from: string, to: string, amount: number, options?: ConvertOptions): Promise<ConvertResponse>;
216
299
  }
217
300
 
218
- export { AllRatesToday, AllRatesTodayError, type AllRatesTodayOptions, type AuthRateResponse, type ConvertOptions, type ConvertResponse, type ForDateOptions, type ForDateResponse, type HistoricalRateResponse, type LatestOptions, type LatestResponse, type RateResponse, type RequestOptions, type SymbolsResponse, type TimeSeriesOptions, type TimeSeriesResponse, AllRatesToday as default };
301
+ export { AllRatesToday, AllRatesTodayError, type AllRatesTodayOptions, type AuthRateResponse, type ConvertOptions, type ConvertResponse, type ForDateOptions, type ForDateResponse, type HistoricalRateResponse, type LatestOptions, type LatestResponse, type OfficialRateAttribution, type OfficialRateEntry, type OfficialRateOptions, type OfficialRatesResponse, type OfficialSource, type OfficialSourcesResponse, type RateResponse, type RequestOptions, type SymbolsResponse, type TimeSeriesOptions, type TimeSeriesResponse, AllRatesToday as default };
package/dist/index.js CHANGED
@@ -225,6 +225,55 @@ var AllRatesToday = class {
225
225
  const key = this.resolveKey(options.apiKey);
226
226
  return this.request("/api/v1/symbols", {}, key);
227
227
  }
228
+ /**
229
+ * Latest table of OFFICIAL rates published by a central bank or tax
230
+ * authority (121 central banks + HMRC, US Treasury, Swiss BAZG). These are
231
+ * the fixed, citable rates for invoicing, tax, customs and accounting โ€” not
232
+ * live market rates. **No API key needed.**
233
+ *
234
+ * ```ts
235
+ * // Full ECB reference table
236
+ * const table = await client.officialRates('ecb');
237
+ * console.log(table.rate_date, table.rates);
238
+ *
239
+ * // One pair โ€” cross-computed inside the bank's table when not published directly
240
+ * const usd = await client.officialRates('ecb', { source: 'EUR', target: 'USD' });
241
+ * console.log(`ECB ${usd.rate_date}: 1 EUR = ${usd.rate} USD`);
242
+ * ```
243
+ *
244
+ * Dated tables and history need a free key: see `/api/v1/central-bank/{bank}/{date}`.
245
+ */
246
+ async officialRates(bank, options = {}) {
247
+ const code = bank.trim().toLowerCase();
248
+ if (!/^[a-z0-9_-]{2,20}$/.test(code)) {
249
+ throw new AllRatesTodayError(`Invalid source code: ${bank}. Call officialSources() for the list.`);
250
+ }
251
+ if (Boolean(options.source) !== Boolean(options.target)) {
252
+ throw new AllRatesTodayError("Provide both source and target, or neither.");
253
+ }
254
+ const params = {};
255
+ if (options.source && options.target) {
256
+ params.source = options.source.toUpperCase();
257
+ params.target = options.target.toUpperCase();
258
+ }
259
+ return this.request(
260
+ `/api/open/central-bank/${encodeURIComponent(code)}`,
261
+ params,
262
+ options.apiKey
263
+ );
264
+ }
265
+ /**
266
+ * Every covered official source with its code, name, latest publication
267
+ * date and whether it is behind schedule. **No API key needed.**
268
+ *
269
+ * ```ts
270
+ * const { sources } = await client.officialSources();
271
+ * const behind = sources.filter((s) => s.stale).map((s) => s.code);
272
+ * ```
273
+ */
274
+ async officialSources(options = {}) {
275
+ return this.request("/api/open/central-banks", {}, options.apiKey);
276
+ }
228
277
  /**
229
278
  * Get exchange rate between two currencies.
230
279
  *
package/dist/index.mjs CHANGED
@@ -199,6 +199,55 @@ var AllRatesToday = class {
199
199
  const key = this.resolveKey(options.apiKey);
200
200
  return this.request("/api/v1/symbols", {}, key);
201
201
  }
202
+ /**
203
+ * Latest table of OFFICIAL rates published by a central bank or tax
204
+ * authority (121 central banks + HMRC, US Treasury, Swiss BAZG). These are
205
+ * the fixed, citable rates for invoicing, tax, customs and accounting โ€” not
206
+ * live market rates. **No API key needed.**
207
+ *
208
+ * ```ts
209
+ * // Full ECB reference table
210
+ * const table = await client.officialRates('ecb');
211
+ * console.log(table.rate_date, table.rates);
212
+ *
213
+ * // One pair โ€” cross-computed inside the bank's table when not published directly
214
+ * const usd = await client.officialRates('ecb', { source: 'EUR', target: 'USD' });
215
+ * console.log(`ECB ${usd.rate_date}: 1 EUR = ${usd.rate} USD`);
216
+ * ```
217
+ *
218
+ * Dated tables and history need a free key: see `/api/v1/central-bank/{bank}/{date}`.
219
+ */
220
+ async officialRates(bank, options = {}) {
221
+ const code = bank.trim().toLowerCase();
222
+ if (!/^[a-z0-9_-]{2,20}$/.test(code)) {
223
+ throw new AllRatesTodayError(`Invalid source code: ${bank}. Call officialSources() for the list.`);
224
+ }
225
+ if (Boolean(options.source) !== Boolean(options.target)) {
226
+ throw new AllRatesTodayError("Provide both source and target, or neither.");
227
+ }
228
+ const params = {};
229
+ if (options.source && options.target) {
230
+ params.source = options.source.toUpperCase();
231
+ params.target = options.target.toUpperCase();
232
+ }
233
+ return this.request(
234
+ `/api/open/central-bank/${encodeURIComponent(code)}`,
235
+ params,
236
+ options.apiKey
237
+ );
238
+ }
239
+ /**
240
+ * Every covered official source with its code, name, latest publication
241
+ * date and whether it is behind schedule. **No API key needed.**
242
+ *
243
+ * ```ts
244
+ * const { sources } = await client.officialSources();
245
+ * const behind = sources.filter((s) => s.stale).map((s) => s.code);
246
+ * ```
247
+ */
248
+ async officialSources(options = {}) {
249
+ return this.request("/api/open/central-banks", {}, options.apiKey);
250
+ }
202
251
  /**
203
252
  * Get exchange rate between two currencies.
204
253
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allratestoday/sdk",
3
- "version": "1.3.10",
3
+ "version": "1.4.1",
4
4
  "description": "Exchange Rate API โ€” Real-time mid-market currency exchange rates for Node.js and browsers. 160+ currencies, zero dependencies, free tier.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",