bdi-exchange-rate 1.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AllRatesToday (https://allratestoday.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,249 @@
1
+ # Banca d'Italia Exchange Rate API โ€” bdi-exchange-rate
2
+
3
+ [![npm version](https://img.shields.io/npm/v/bdi-exchange-rate.svg)](https://www.npmjs.com/package/bdi-exchange-rate)
4
+ [![license](https://img.shields.io/npm/l/bdi-exchange-rate.svg)](https://github.com/AllRates-Today/bdi-exchange-rate/blob/main/LICENSE)
5
+ [![zero dependencies](https://img.shields.io/badge/dependencies-0-brightgreen.svg)](https://www.npmjs.com/package/bdi-exchange-rate)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-types%20included-3178C6.svg)](https://www.typescriptlang.org/)
7
+
8
+ **Official Banca d'Italia (Italy) daily exchange rates for Node.js and TypeScript. The published central bank rates behind tax filings, customs valuations, audits, and compliant invoicing โ€” not market estimates, but the numbers Banca d'Italia itself prints, every business day.**
9
+
10
+ ## ๐Ÿš€ Why this client?
11
+
12
+ - ๐Ÿ›๏ธ **Official published rates** โ€” Banca d'Italia's own table, with the publisher's own `rate_date` on every response
13
+ - ๐Ÿ“… **History back to 2016** โ€” point-in-time tables and daily series for any past date
14
+ - ๐Ÿ”€ **Published vs derived, always flagged** โ€” computed inverse/cross pairs carry `derived: true`, never mixed with official prints
15
+ - โšก **Zero dependencies** โ€” pure ESM + CJS over global `fetch`; Node 18+, Bun, Deno, and edge runtimes
16
+ - ๐Ÿ”ท **Type-safe** โ€” full TypeScript definitions shipped with the package
17
+ - ๐Ÿงพ **Compliance-grade metadata** โ€” `rate_type`, publication date, and source disclaimer on every response
18
+
19
+ > **Official rate, not mid-market:** every value here is a number Banca d'Italia itself published, fixed once printed and carrying the central bank's own `rate_date` โ€” what filings and audits require. Need the live interbank midpoint for pricing or display instead? Use the [mid-market API](https://allratestoday.com/docs/) or [`@allratestoday/sdk`](https://www.npmjs.com/package/@allratestoday/sdk). The two can diverge by several percent.
20
+
21
+ ## ๐Ÿ”‘ Get your API key
22
+
23
+ Get a free API key at [allratestoday.com/register](https://allratestoday.com/register) โ€” no credit card required. Latest rates are on every plan, including free.
24
+
25
+ ## ๐Ÿ“ฆ Installation
26
+
27
+ ```bash
28
+ npm install bdi-exchange-rate
29
+ ```
30
+
31
+ ```bash
32
+ yarn add bdi-exchange-rate
33
+ ```
34
+
35
+ ```bash
36
+ pnpm add bdi-exchange-rate
37
+ ```
38
+
39
+ Also published under the org scope as [`@allratestoday/bdi-exchange-rate`](https://www.npmjs.com/package/@allratestoday/bdi-exchange-rate) โ€” same code, same versions.
40
+
41
+ ## ๐Ÿ Quick start
42
+
43
+ ```js
44
+ import { getRate } from 'bdi-exchange-rate';
45
+
46
+ const pair = await getRate('USD', 'EUR', { apiKey: 'art_live_...' });
47
+ console.log(pair.rate, pair.rate_date); // the official Banca d'Italia rate, on the central bank's own date
48
+ ```
49
+
50
+ ## ๐Ÿ“š API reference
51
+
52
+ - [Latest pair rate](#latest-pair-rate) โ€” one pair from the latest published table
53
+ - [Full published table](#full-published-table) โ€” everything the central bank printed, in one call
54
+ - [Table for a date](#table-for-a-date) โ€” the official table for an invoice or filing date
55
+ - [Daily time series](#daily-time-series) โ€” one pair across a date range
56
+
57
+ ---
58
+
59
+ ### Latest pair rate
60
+
61
+ Free plan and up. Pairs the central bank does not print directly are resolved from its table and flagged (see *Published vs derived rates* below).
62
+
63
+ ```js
64
+ const pair = await getRate('USD', 'EUR', { apiKey: 'art_live_...' });
65
+ ```
66
+
67
+ **Response:**
68
+
69
+ ```javascript
70
+ {
71
+ bank: 'bdi',
72
+ name: 'Banca d\'Italia',
73
+ rate_date: '2026-08-11', // Banca d'Italia's own publication date
74
+ source: 'USD',
75
+ target: 'EUR',
76
+ rate: 0.866551,
77
+ rate_type: 'reference',
78
+ derived: true,
79
+ method: 'inverse', // computed from the published EUR/USD print
80
+ disclaimer: 'โ€ฆ'
81
+ }
82
+ ```
83
+
84
+ ### Full published table
85
+
86
+ Free plan and up. The complete table for the latest publication date.
87
+
88
+ ```js
89
+ import { getLatestRates } from 'bdi-exchange-rate';
90
+
91
+ const table = await getLatestRates({ apiKey: 'art_live_...' });
92
+ console.log(table.rate_date, table.rates.length);
93
+ ```
94
+
95
+ **Response:**
96
+
97
+ ```javascript
98
+ {
99
+ bank: 'bdi',
100
+ name: 'Banca d\'Italia',
101
+ rate_date: '2026-08-11',
102
+ rates: [
103
+ { "base": "EUR", "quote": "USD", "type": "reference", "value": 1.154 },
104
+ // โ€ฆ the rest of the published table (150 currencies vs EUR)
105
+ ],
106
+ disclaimer: 'โ€ฆ'
107
+ }
108
+ ```
109
+
110
+ ### Table for a date
111
+
112
+ Paid plans. The official table for any date since 2016 โ€” weekends and holidays return the most recent published date, flagged via `published_on_requested_date`, which is exactly the in-force rate a filing needs.
113
+
114
+ ```js
115
+ import { getRatesForDate } from 'bdi-exchange-rate';
116
+
117
+ const day = await getRatesForDate('2026-06-30', { apiKey: 'art_live_...' });
118
+ // Optionally narrow to one pair:
119
+ const one = await getRatesForDate('2026-06-30', { apiKey: 'art_live_...', source: 'USD', target: 'EUR' });
120
+ ```
121
+
122
+ **Response:**
123
+
124
+ ```javascript
125
+ {
126
+ bank: 'bdi',
127
+ requested_date: '2026-06-30',
128
+ rate_date: '2026-06-30', // the date actually published
129
+ published_on_requested_date: true, // false when a weekend/holiday fell back
130
+ rates: [ /* the full table for that date */ ],
131
+ disclaimer: 'โ€ฆ'
132
+ }
133
+ ```
134
+
135
+ ### Daily time series
136
+
137
+ Paid plans. One resolved rate per publication date โ€” ready for charting, revaluation runs, or audit workpapers.
138
+
139
+ ```js
140
+ import { getHistory } from 'bdi-exchange-rate';
141
+
142
+ const series = await getHistory(
143
+ { source: 'USD', target: 'EUR', from: '2026-01-01', to: '2026-08-11' },
144
+ { apiKey: 'art_live_...' }
145
+ );
146
+ ```
147
+
148
+ **Response:**
149
+
150
+ ```javascript
151
+ {
152
+ bank: 'bdi',
153
+ source: 'USD',
154
+ target: 'EUR',
155
+ from: '2026-01-01',
156
+ to: '2026-08-11',
157
+ count: 152,
158
+ rates: [
159
+ // one entry per publication date
160
+ { date: '2026-08-11', rate: 0.866551, rate_type: 'reference', derived: true, method: 'inverse' },
161
+ // โ€ฆ
162
+ ],
163
+ disclaimer: 'โ€ฆ'
164
+ }
165
+ ```
166
+
167
+ Pass `{ symbol: 'USD' }` instead of `source`/`target` to get the raw published rows for one currency (all rate types, no pair resolution).
168
+
169
+ ---
170
+
171
+ ## ๐Ÿ—บ๏ธ Currencies covered
172
+
173
+ Banca d'Italia currently publishes rates covering **150 currencies** (as of the latest table):
174
+
175
+ `AED` ยท `AFN` ยท `ALL` ยท `AMD` ยท `AOA` ยท `ARS` ยท `AUD` ยท `AWG` ยท `AZN` ยท `BAM` ยท `BBD` ยท `BDT` ยท `BHD` ยท `BIF` ยท `BMD` ยท `BND` ยท `BOB` ยท `BRL` ยท `BSD` ยท `BTN` ยท `BWP` ยท `BZD` ยท `CAD` ยท `CDF` ยท `CHF` ยท `CLP` ยท `CNY` ยท `COP` ยท `CRC` ยท `CUP` ยท `CVE` ยท `CZK` ยท `DJF` ยท `DKK` ยท `DOP` ยท `DZD` ยท `EGP` ยท `ERN` ยท `ETB` ยท `FJD` ยท `FKP` ยท `GBP` ยท `GEL` ยท `GHS` ยท `GIP` ยท `GMD` ยท `GNF` ยท `GTQ` ยท `GYD` ยท `HKD` ยท `HNL` ยท `HTG` ยท `HUF` ยท `IDR` ยท `ILS` ยท `INR` ยท `IQD` ยท `ISK` ยท `JMD` ยท `JOD` ยท `JPY` ยท `KES` ยท `KGS` ยท `KHR` ยท `KMF` ยท `KRW` ยท `KWD` ยท `KYD` ยท `KZT` ยท `LAK` ยท `LBP` ยท `LKR` ยท `LRD` ยท `LSL` ยท `LYD` ยท `MAD` ยท `MDL` ยท `MGA` ยท `MKD` ยท `MMK` ยท `MNT` ยท `MOP` ยท `MRU` ยท `MUR` ยท `MVR` ยท `MWK` ยท `MXN` ยท `MYR` ยท `MZN` ยท `NAD` ยท `NGN` ยท `NIO` ยท `NOK` ยท `NPR` ยท `NZD` ยท `OMR` ยท `PAB` ยท `PEN` ยท `PGK` ยท `PHP` ยท `PKR` ยท `PLN` ยท `PYG` ยท `QAR` ยท `RON` ยท `RSD` ยท `RWF` ยท `SAR` ยท `SBD` ยท `SCR` ยท `SDG` ยท `SEK` ยท `SGD` ยท `SHP` ยท `SLE` ยท `SOS` ยท `SRD` ยท `SSP` ยท `STN` ยท `SVC` ยท `SYP` ยท `SZL` ยท `THB` ยท `TJS` ยท `TMT` ยท `TND` ยท `TOP` ยท `TRY` ยท `TTD` ยท `TWD` ยท `TZS` ยท `UAH` ยท `UGX` ยท `USD` ยท `UYU` ยท `UZS` ยท `VES` ยท `VND` ยท `VUV` ยท `WST` ยท `XAF` ยท `XCD` ยท `XCG` ยท `XDR` ยท `XOF` ยท `XPF` ยท `YER` ยท `ZAR` ยท `ZMW` ยท `ZWG`
176
+
177
+ ## โš–๏ธ Published vs derived rates
178
+
179
+ If Banca d'Italia does not print a pair directly, the API resolves it from the central bank's own table and says so โ€” official and computed values are never confused:
180
+
181
+ | `method` | `derived` | Meaning |
182
+ | --- | --- | --- |
183
+ | `published` | `false` | The central bank printed this pair directly |
184
+ | `inverse` | `true` | Computed as 1 รท the published opposite direction |
185
+ | `cross` | `true` | Computed via EUR from two published rates |
186
+
187
+ ## ๐Ÿ›ก๏ธ Error handling
188
+
189
+ Errors are thrown as `Error` with `status` (HTTP code) and `body` (the API's JSON error) attached:
190
+
191
+ ```js
192
+ try {
193
+ const pair = await getRate('USD', 'XXX', { apiKey: 'art_live_...' });
194
+ } catch (err) {
195
+ console.log(err.message); // human-readable reason
196
+ console.log(err.status); // e.g. 404
197
+ }
198
+ ```
199
+
200
+ | Status | Meaning |
201
+ | ------ | ------- |
202
+ | โ€” | Missing `apiKey` (thrown before any request) |
203
+ | `400` | Malformed date or parameters |
204
+ | `401` | Invalid API key |
205
+ | `403` | Endpoint needs a [paid plan](https://allratestoday.com/pricing/) (historical dates & series) |
206
+ | `404` | Pair or date range not covered by Banca d'Italia |
207
+ | `429` | Monthly quota exceeded |
208
+
209
+ ## ๐Ÿ”ท TypeScript
210
+
211
+ Full definitions ship with the package โ€” no `@types` install:
212
+
213
+ ```ts
214
+ import type { LatestRates, PairRate, DatedRates, RateEntry, HistoryQuery, RequestOptions } from 'bdi-exchange-rate';
215
+ ```
216
+
217
+ ## ๐Ÿ“ฆ CommonJS
218
+
219
+ ```javascript
220
+ const { getRate } = require('bdi-exchange-rate');
221
+
222
+ getRate('USD', 'EUR', { apiKey: 'art_live_...' }).then((pair) => console.log(pair.rate));
223
+ ```
224
+
225
+ ## ๐Ÿ’ก Quota tips
226
+
227
+ - Rates change once per business day โ€” cache the published table locally and a small monthly quota goes a long way.
228
+ - Every request counts toward your AllRatesToday quota, shared across all AllRatesToday endpoints on your key.
229
+
230
+ ## ๐Ÿ“– Methods reference
231
+
232
+ | Method | Plan | Description |
233
+ | ------ | ---- | ----------- |
234
+ | `getRate(source, target, { apiKey })` | Free | Latest rate for one pair, resolved from the published table |
235
+ | `getLatestRates({ apiKey })` | Free | The central bank's full latest published table |
236
+ | `getRatesForDate(date, { apiKey, source?, target? })` | Paid | The official table (or one pair) for a YYYY-MM-DD date |
237
+ | `getHistory({ symbol \| source+target, from?, to? }, { apiKey })` | Paid | Daily series since 2016 |
238
+
239
+ ## ๐Ÿ”— Links
240
+
241
+ - [Banca d'Italia rates page](https://allratestoday.com/central-bank-rates-api/bdi/) โ€” live table, publication cadence, FAQ
242
+ - [All central bank sources](https://allratestoday.com/central-bank-rates-api/)
243
+ - [API documentation](https://allratestoday.com/docs/#central-bank) ยท [Interactive reference](https://allratestoday.com/api-reference/)
244
+ - [Register (free)](https://allratestoday.com/register) ยท [Pricing](https://allratestoday.com/pricing/)
245
+ - [GitHub](https://github.com/AllRates-Today/bdi-exchange-rate)
246
+
247
+ ## ๐Ÿ“œ License
248
+
249
+ MIT
package/index.cjs ADDED
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+ // Banca d'Italia exchange rates via the AllRatesToday API.
3
+ const BASE = 'https://allratestoday.com/api/v1/central-bank/bdi';
4
+ const KEY_HINT = 'An apiKey is required โ€” get a free key at https://allratestoday.com/register (no credit card required).';
5
+
6
+ async function request(path, params, options) {
7
+ const apiKey = options && options.apiKey;
8
+ if (!apiKey) throw new Error(KEY_HINT);
9
+ const url = new URL(BASE + path);
10
+ for (const [k, v] of Object.entries(params || {})) {
11
+ if (v !== undefined && v !== null) url.searchParams.set(k, v);
12
+ }
13
+ const res = await fetch(url, { headers: { Authorization: 'Bearer ' + apiKey } });
14
+ let body;
15
+ try { body = await res.json(); } catch { body = {}; }
16
+ if (!res.ok) {
17
+ const err = new Error(body.error || ('Request failed: HTTP ' + res.status));
18
+ err.status = res.status;
19
+ err.body = body;
20
+ throw err;
21
+ }
22
+ return body;
23
+ }
24
+
25
+ /** Latest published table (all plans, including free). */
26
+ async function getLatestRates(options) {
27
+ return request('/latest', {}, options);
28
+ }
29
+
30
+ /** Latest rate for one pair, e.g. getRate('USD', 'EUR', { apiKey }). */
31
+ async function getRate(source, target, options) {
32
+ return request('/latest', { source, target }, options);
33
+ }
34
+
35
+ /** Published table for a date (YYYY-MM-DD). Paid plans. Weekends/holidays return the most recent published date. */
36
+ async function getRatesForDate(date, options) {
37
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(String(date))) throw new Error('date must be YYYY-MM-DD');
38
+ return request('/' + date, options && options.source ? { source: options.source, target: options.target } : {}, options);
39
+ }
40
+
41
+ /** Daily time series. Pass { symbol } or { source, target }, optional from/to (YYYY-MM-DD). Paid plans. */
42
+ async function getHistory(query, options) {
43
+ const { symbol, source, target, from, to } = query || {};
44
+ return request('/history', { symbol, source, target, from, to }, options);
45
+ }
46
+
47
+ module.exports = { getLatestRates, getRate, getRatesForDate, getHistory };
package/index.d.ts ADDED
@@ -0,0 +1,52 @@
1
+ export interface RequestOptions {
2
+ /** AllRatesToday API key โ€” free at https://allratestoday.com/register */
3
+ apiKey: string;
4
+ }
5
+
6
+ export interface RateEntry {
7
+ base: string;
8
+ quote: string;
9
+ type: string;
10
+ value: number;
11
+ }
12
+
13
+ export interface LatestRates {
14
+ bank: 'bdi';
15
+ name: string;
16
+ rate_date: string;
17
+ rates: RateEntry[];
18
+ disclaimer: string;
19
+ }
20
+
21
+ export interface PairRate {
22
+ bank: 'bdi';
23
+ name: string;
24
+ rate_date: string;
25
+ source: string;
26
+ target: string;
27
+ rate: number;
28
+ rate_type: string;
29
+ /** true when the pair was computed (inverse/cross) rather than published directly */
30
+ derived: boolean;
31
+ method: 'published' | 'inverse' | 'cross';
32
+ disclaimer: string;
33
+ }
34
+
35
+ export interface DatedRates extends Omit<LatestRates, 'rate_date'> {
36
+ requested_date: string;
37
+ rate_date: string;
38
+ published_on_requested_date: boolean;
39
+ }
40
+
41
+ export interface HistoryQuery {
42
+ symbol?: string;
43
+ source?: string;
44
+ target?: string;
45
+ from?: string;
46
+ to?: string;
47
+ }
48
+
49
+ export declare function getLatestRates(options: RequestOptions): Promise<LatestRates>;
50
+ export declare function getRate(source: string, target: string, options: RequestOptions): Promise<PairRate>;
51
+ export declare function getRatesForDate(date: string, options: RequestOptions & { source?: string; target?: string }): Promise<DatedRates>;
52
+ export declare function getHistory(query: HistoryQuery, options: RequestOptions): Promise<unknown>;
package/index.mjs ADDED
@@ -0,0 +1,44 @@
1
+ // Banca d'Italia exchange rates via the AllRatesToday API.
2
+ const BASE = 'https://allratestoday.com/api/v1/central-bank/bdi';
3
+ const KEY_HINT = 'An apiKey is required โ€” get a free key at https://allratestoday.com/register (no credit card required).';
4
+
5
+ async function request(path, params, options) {
6
+ const apiKey = options && options.apiKey;
7
+ if (!apiKey) throw new Error(KEY_HINT);
8
+ const url = new URL(BASE + path);
9
+ for (const [k, v] of Object.entries(params || {})) {
10
+ if (v !== undefined && v !== null) url.searchParams.set(k, v);
11
+ }
12
+ const res = await fetch(url, { headers: { Authorization: 'Bearer ' + apiKey } });
13
+ let body;
14
+ try { body = await res.json(); } catch { body = {}; }
15
+ if (!res.ok) {
16
+ const err = new Error(body.error || ('Request failed: HTTP ' + res.status));
17
+ err.status = res.status;
18
+ err.body = body;
19
+ throw err;
20
+ }
21
+ return body;
22
+ }
23
+
24
+ /** Latest published table (all plans, including free). */
25
+ export async function getLatestRates(options) {
26
+ return request('/latest', {}, options);
27
+ }
28
+
29
+ /** Latest rate for one pair, e.g. getRate('USD', 'EUR', { apiKey }). */
30
+ export async function getRate(source, target, options) {
31
+ return request('/latest', { source, target }, options);
32
+ }
33
+
34
+ /** Published table for a date (YYYY-MM-DD). Paid plans. Weekends/holidays return the most recent published date. */
35
+ export async function getRatesForDate(date, options) {
36
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(String(date))) throw new Error('date must be YYYY-MM-DD');
37
+ return request('/' + date, options && options.source ? { source: options.source, target: options.target } : {}, options);
38
+ }
39
+
40
+ /** Daily time series. Pass { symbol } or { source, target }, optional from/to (YYYY-MM-DD). Paid plans. */
41
+ export async function getHistory(query, options) {
42
+ const { symbol, source, target, from, to } = query || {};
43
+ return request('/history', { symbol, source, target, from, to }, options);
44
+ }
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "bdi-exchange-rate",
3
+ "version": "1.2.2",
4
+ "description": "Official Banca d'Italia (Italy) daily exchange rates โ€” 150 currencies vs EUR, history since 2016. Zero-dependency Node.js/TypeScript client.",
5
+ "keywords": [
6
+ "bdi",
7
+ "banca",
8
+ "d'italia",
9
+ "exchange-rate",
10
+ "exchange-rates",
11
+ "currency",
12
+ "forex",
13
+ "fx",
14
+ "eur",
15
+ "central-bank",
16
+ "official-rates",
17
+ "italy",
18
+ "api",
19
+ "typescript"
20
+ ],
21
+ "homepage": "https://allratestoday.com/central-bank-rates-api/bdi/",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/AllRates-Today/bdi-exchange-rate.git"
25
+ },
26
+ "bugs": {
27
+ "url": "https://github.com/AllRates-Today/bdi-exchange-rate/issues"
28
+ },
29
+ "license": "MIT",
30
+ "author": "AllRatesToday <hello@allratestoday.com> (https://allratestoday.com)",
31
+ "type": "module",
32
+ "main": "./index.cjs",
33
+ "module": "./index.mjs",
34
+ "types": "./index.d.ts",
35
+ "exports": {
36
+ ".": {
37
+ "types": "./index.d.ts",
38
+ "import": "./index.mjs",
39
+ "require": "./index.cjs"
40
+ }
41
+ },
42
+ "files": [
43
+ "index.mjs",
44
+ "index.cjs",
45
+ "index.d.ts",
46
+ "README.md",
47
+ "LICENSE"
48
+ ],
49
+ "engines": {
50
+ "node": ">=18"
51
+ },
52
+ "sideEffects": false
53
+ }