bou-exchange-rate 1.2.7
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 +21 -0
- package/README.md +251 -0
- package/index.cjs +47 -0
- package/index.d.ts +52 -0
- package/index.mjs +44 -0
- package/package.json +54 -0
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,251 @@
|
|
|
1
|
+
# Bank of Uganda Exchange Rate API โ bou-exchange-rate
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/bou-exchange-rate)
|
|
4
|
+
[](https://github.com/AllRates-Today/bou-exchange-rate/blob/main/LICENSE)
|
|
5
|
+
[](https://www.npmjs.com/package/bou-exchange-rate)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
|
|
8
|
+
**Official Bank of Uganda (Uganda) 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 Bank of Uganda itself prints, every business day.**
|
|
9
|
+
|
|
10
|
+
## ๐ Why this client?
|
|
11
|
+
|
|
12
|
+
- ๐๏ธ **Official published rates** โ Bank of Uganda's own table, with the publisher's own `rate_date` on every response
|
|
13
|
+
- ๐
**History from 2026** โ this source publishes only its current table, so the archive builds forward from the day we started collecting
|
|
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 Bank of Uganda 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 bou-exchange-rate
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
yarn add bou-exchange-rate
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pnpm add bou-exchange-rate
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Also published under the org scope as [`@allratestoday/bou-exchange-rate`](https://www.npmjs.com/package/@allratestoday/bou-exchange-rate) โ same code, same versions.
|
|
40
|
+
|
|
41
|
+
## ๐ Quick start
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
import { getRate } from 'bou-exchange-rate';
|
|
45
|
+
|
|
46
|
+
const pair = await getRate('USD', 'UGX', { apiKey: 'art_live_...' });
|
|
47
|
+
console.log(pair.rate, pair.rate_date); // the official Bank of Uganda 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', 'UGX', { apiKey: 'art_live_...' });
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**Response:**
|
|
68
|
+
|
|
69
|
+
```javascript
|
|
70
|
+
{
|
|
71
|
+
bank: 'bou',
|
|
72
|
+
name: 'Bank of Uganda',
|
|
73
|
+
rate_date: '2026-08-24', // Bank of Uganda's own publication date
|
|
74
|
+
source: 'USD',
|
|
75
|
+
target: 'UGX',
|
|
76
|
+
rate: 3722.38,
|
|
77
|
+
rate_type: 'reference',
|
|
78
|
+
derived: false,
|
|
79
|
+
method: 'published',
|
|
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 'bou-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: 'bou',
|
|
100
|
+
name: 'Bank of Uganda',
|
|
101
|
+
rate_date: '2026-08-24',
|
|
102
|
+
rates: [
|
|
103
|
+
{ "base": "USD", "quote": "UGX", "type": "reference", "value": 3722.38 },
|
|
104
|
+
{ "base": "USD", "quote": "UGX", "type": "sell", "value": 3727.38 },
|
|
105
|
+
{ "base": "USD", "quote": "UGX", "type": "buy", "value": 3717.38 },
|
|
106
|
+
// โฆ the rest of the published table (33 currencies vs UGX)
|
|
107
|
+
],
|
|
108
|
+
disclaimer: 'โฆ'
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Table for a date
|
|
113
|
+
|
|
114
|
+
Paid plans. The official table for any date since 2026 โ 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.
|
|
115
|
+
|
|
116
|
+
```js
|
|
117
|
+
import { getRatesForDate } from 'bou-exchange-rate';
|
|
118
|
+
|
|
119
|
+
const day = await getRatesForDate('2026-06-30', { apiKey: 'art_live_...' });
|
|
120
|
+
// Optionally narrow to one pair:
|
|
121
|
+
const one = await getRatesForDate('2026-06-30', { apiKey: 'art_live_...', source: 'USD', target: 'UGX' });
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Response:**
|
|
125
|
+
|
|
126
|
+
```javascript
|
|
127
|
+
{
|
|
128
|
+
bank: 'bou',
|
|
129
|
+
requested_date: '2026-06-30',
|
|
130
|
+
rate_date: '2026-06-30', // the date actually published
|
|
131
|
+
published_on_requested_date: true, // false when a weekend/holiday fell back
|
|
132
|
+
rates: [ /* the full table for that date */ ],
|
|
133
|
+
disclaimer: 'โฆ'
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Daily time series
|
|
138
|
+
|
|
139
|
+
Paid plans. One resolved rate per publication date โ ready for charting, revaluation runs, or audit workpapers.
|
|
140
|
+
|
|
141
|
+
```js
|
|
142
|
+
import { getHistory } from 'bou-exchange-rate';
|
|
143
|
+
|
|
144
|
+
const series = await getHistory(
|
|
145
|
+
{ source: 'USD', target: 'UGX', from: '2026-01-01', to: '2026-08-24' },
|
|
146
|
+
{ apiKey: 'art_live_...' }
|
|
147
|
+
);
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
**Response:**
|
|
151
|
+
|
|
152
|
+
```javascript
|
|
153
|
+
{
|
|
154
|
+
bank: 'bou',
|
|
155
|
+
source: 'USD',
|
|
156
|
+
target: 'UGX',
|
|
157
|
+
from: '2026-01-01',
|
|
158
|
+
to: '2026-08-24',
|
|
159
|
+
count: 152,
|
|
160
|
+
rates: [
|
|
161
|
+
// one entry per publication date
|
|
162
|
+
{ date: '2026-08-24', rate: 3722.38, rate_type: 'reference', derived: false, method: 'published' },
|
|
163
|
+
// โฆ
|
|
164
|
+
],
|
|
165
|
+
disclaimer: 'โฆ'
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Pass `{ symbol: 'USD' }` instead of `source`/`target` to get the raw published rows for one currency (all rate types, no pair resolution).
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## ๐บ๏ธ Currencies covered
|
|
174
|
+
|
|
175
|
+
Bank of Uganda currently publishes rates covering **33 currencies** against the UGX (as of the latest table):
|
|
176
|
+
|
|
177
|
+
๐ฆ๐ช `AED` ยท ๐ฆ๐บ `AUD` ยท ๐ง๐ฎ `BIF` ยท ๐จ๐ฆ `CAD` ยท ๐จ๐ญ `CHF` ยท ๐จ๐ณ `CNY` ยท ๐ฉ๐ฏ `DJF` ยท ๐ฉ๐ฐ `DKK` ยท ๐ช๐น `ETB` ยท ๐ช๐บ `EUR` ยท ๐ฌ๐ง `GBP` ยท ๐ฎ๐ณ `INR` ยท ๐ฏ๐ต `JPY` ยท ๐ฐ๐ช `KES` ยท ๐ฐ๐ฒ `KMF` ยท ๐ฐ๐ท `KRW` ยท ๐ฐ๐ผ `KWD` ยท ๐ฑ๐ธ `LSL` ยท ๐ฒ๐บ `MUR` ยท ๐ฒ๐ผ `MWK` ยท ๐ณ๐ด `NOK` ยท ๐ณ๐ฟ `NZD` ยท ๐ท๐ผ `RWF` ยท ๐ธ๐ฆ `SAR` ยท ๐ธ๐ช `SEK` ยท ๐ธ๐ธ `SSP` ยท ๐ธ๐ฟ `SZL` ยท ๐น๐ฟ `TZS` ยท ๐บ๐ธ `USD` ยท `XAU` ยท `XDR` ยท ๐ฟ๐ฆ `ZAR` ยท ๐ฟ๐ผ `ZWG`
|
|
178
|
+
|
|
179
|
+
## โ๏ธ Published vs derived rates
|
|
180
|
+
|
|
181
|
+
If Bank of Uganda 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:
|
|
182
|
+
|
|
183
|
+
| `method` | `derived` | Meaning |
|
|
184
|
+
| --- | --- | --- |
|
|
185
|
+
| `published` | `false` | The central bank printed this pair directly |
|
|
186
|
+
| `inverse` | `true` | Computed as 1 รท the published opposite direction |
|
|
187
|
+
| `cross` | `true` | Computed via UGX from two published rates |
|
|
188
|
+
|
|
189
|
+
## ๐ก๏ธ Error handling
|
|
190
|
+
|
|
191
|
+
Errors are thrown as `Error` with `status` (HTTP code) and `body` (the API's JSON error) attached:
|
|
192
|
+
|
|
193
|
+
```js
|
|
194
|
+
try {
|
|
195
|
+
const pair = await getRate('USD', 'XXX', { apiKey: 'art_live_...' });
|
|
196
|
+
} catch (err) {
|
|
197
|
+
console.log(err.message); // human-readable reason
|
|
198
|
+
console.log(err.status); // e.g. 404
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
| Status | Meaning |
|
|
203
|
+
| ------ | ------- |
|
|
204
|
+
| โ | Missing `apiKey` (thrown before any request) |
|
|
205
|
+
| `400` | Malformed date or parameters |
|
|
206
|
+
| `401` | Invalid API key |
|
|
207
|
+
| `403` | Endpoint needs a [paid plan](https://allratestoday.com/pricing/) (historical dates & series) |
|
|
208
|
+
| `404` | Pair or date range not covered by Bank of Uganda |
|
|
209
|
+
| `429` | Monthly quota exceeded |
|
|
210
|
+
|
|
211
|
+
## ๐ท TypeScript
|
|
212
|
+
|
|
213
|
+
Full definitions ship with the package โ no `@types` install:
|
|
214
|
+
|
|
215
|
+
```ts
|
|
216
|
+
import type { LatestRates, PairRate, DatedRates, RateEntry, HistoryQuery, RequestOptions } from 'bou-exchange-rate';
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## ๐ฆ CommonJS
|
|
220
|
+
|
|
221
|
+
```javascript
|
|
222
|
+
const { getRate } = require('bou-exchange-rate');
|
|
223
|
+
|
|
224
|
+
getRate('USD', 'UGX', { apiKey: 'art_live_...' }).then((pair) => console.log(pair.rate));
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## ๐ก Quota tips
|
|
228
|
+
|
|
229
|
+
- Rates change once per business day โ cache the published table locally and a small monthly quota goes a long way.
|
|
230
|
+
- Every request counts toward your AllRatesToday quota, shared across all AllRatesToday endpoints on your key.
|
|
231
|
+
|
|
232
|
+
## ๐ Methods reference
|
|
233
|
+
|
|
234
|
+
| Method | Plan | Description |
|
|
235
|
+
| ------ | ---- | ----------- |
|
|
236
|
+
| `getRate(source, target, { apiKey })` | Free | Latest rate for one pair, resolved from the published table |
|
|
237
|
+
| `getLatestRates({ apiKey })` | Free | The central bank's full latest published table |
|
|
238
|
+
| `getRatesForDate(date, { apiKey, source?, target? })` | Paid | The official table (or one pair) for a YYYY-MM-DD date |
|
|
239
|
+
| `getHistory({ symbol \| source+target, from?, to? }, { apiKey })` | Paid | Daily series since 2026 |
|
|
240
|
+
|
|
241
|
+
## ๐ Links
|
|
242
|
+
|
|
243
|
+
- [Bank of Uganda rates page](https://allratestoday.com/central-bank-rates-api/bou/) โ live table, publication cadence, FAQ
|
|
244
|
+
- [All central bank sources](https://allratestoday.com/central-bank-rates-api/)
|
|
245
|
+
- [API documentation](https://allratestoday.com/docs/#central-bank) ยท [Interactive reference](https://allratestoday.com/api-reference/)
|
|
246
|
+
- [Register (free)](https://allratestoday.com/register) ยท [Pricing](https://allratestoday.com/pricing/)
|
|
247
|
+
- [GitHub](https://github.com/AllRates-Today/bou-exchange-rate)
|
|
248
|
+
|
|
249
|
+
## ๐ License
|
|
250
|
+
|
|
251
|
+
MIT
|
package/index.cjs
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Bank of Uganda exchange rates via the AllRatesToday API.
|
|
3
|
+
const BASE = 'https://allratestoday.com/api/v1/central-bank/bou';
|
|
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', 'UGX', { 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: 'bou';
|
|
15
|
+
name: string;
|
|
16
|
+
rate_date: string;
|
|
17
|
+
rates: RateEntry[];
|
|
18
|
+
disclaimer: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface PairRate {
|
|
22
|
+
bank: 'bou';
|
|
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
|
+
// Bank of Uganda exchange rates via the AllRatesToday API.
|
|
2
|
+
const BASE = 'https://allratestoday.com/api/v1/central-bank/bou';
|
|
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', 'UGX', { 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,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "bou-exchange-rate",
|
|
3
|
+
"version": "1.2.7",
|
|
4
|
+
"description": "Official Bank of Uganda (Uganda) daily exchange rates โ 33 currencies vs UGX, current table, archive from 2026. Zero-dependency Node.js/TypeScript client.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"bou",
|
|
7
|
+
"bank",
|
|
8
|
+
"of",
|
|
9
|
+
"uganda",
|
|
10
|
+
"exchange-rate",
|
|
11
|
+
"exchange-rates",
|
|
12
|
+
"currency",
|
|
13
|
+
"forex",
|
|
14
|
+
"fx",
|
|
15
|
+
"ugx",
|
|
16
|
+
"central-bank",
|
|
17
|
+
"official-rates",
|
|
18
|
+
"uganda",
|
|
19
|
+
"api",
|
|
20
|
+
"typescript"
|
|
21
|
+
],
|
|
22
|
+
"homepage": "https://allratestoday.com/central-bank-rates-api/bou/",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/AllRates-Today/bou-exchange-rate.git"
|
|
26
|
+
},
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/AllRates-Today/bou-exchange-rate/issues"
|
|
29
|
+
},
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"author": "AllRatesToday <hello@allratestoday.com> (https://allratestoday.com)",
|
|
32
|
+
"type": "module",
|
|
33
|
+
"main": "./index.cjs",
|
|
34
|
+
"module": "./index.mjs",
|
|
35
|
+
"types": "./index.d.ts",
|
|
36
|
+
"exports": {
|
|
37
|
+
".": {
|
|
38
|
+
"types": "./index.d.ts",
|
|
39
|
+
"import": "./index.mjs",
|
|
40
|
+
"require": "./index.cjs"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"files": [
|
|
44
|
+
"index.mjs",
|
|
45
|
+
"index.cjs",
|
|
46
|
+
"index.d.ts",
|
|
47
|
+
"README.md",
|
|
48
|
+
"LICENSE"
|
|
49
|
+
],
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=18"
|
|
52
|
+
},
|
|
53
|
+
"sideEffects": false
|
|
54
|
+
}
|