cba-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 +249 -0
- package/index.cjs +47 -0
- package/index.d.ts +52 -0
- package/index.mjs +44 -0
- package/package.json +55 -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,249 @@
|
|
|
1
|
+
# Central Bank of Armenia Exchange Rate API โ cba-exchange-rate
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/cba-exchange-rate)
|
|
4
|
+
[](https://github.com/AllRates-Today/cba-exchange-rate/blob/main/LICENSE)
|
|
5
|
+
[](https://www.npmjs.com/package/cba-exchange-rate)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
|
|
8
|
+
**Official Central Bank of Armenia (Armenia) 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 Central Bank of Armenia itself prints, every business day.**
|
|
9
|
+
|
|
10
|
+
## ๐ Why this client?
|
|
11
|
+
|
|
12
|
+
- ๐๏ธ **Official published rates** โ Central Bank of Armenia's own table, with the publisher's own `rate_date` on every response
|
|
13
|
+
- ๐
**History back to 2000** โ 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 Central Bank of Armenia 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 cba-exchange-rate
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
yarn add cba-exchange-rate
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pnpm add cba-exchange-rate
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Also published under the org scope as [`@allratestoday/cba-exchange-rate`](https://www.npmjs.com/package/@allratestoday/cba-exchange-rate) โ same code, same versions.
|
|
40
|
+
|
|
41
|
+
## ๐ Quick start
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
import { getRate } from 'cba-exchange-rate';
|
|
45
|
+
|
|
46
|
+
const pair = await getRate('USD', 'AMD', { apiKey: 'art_live_...' });
|
|
47
|
+
console.log(pair.rate, pair.rate_date); // the official Central Bank of Armenia 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', 'AMD', { apiKey: 'art_live_...' });
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**Response:**
|
|
68
|
+
|
|
69
|
+
```javascript
|
|
70
|
+
{
|
|
71
|
+
bank: 'cba',
|
|
72
|
+
name: 'Central Bank of Armenia',
|
|
73
|
+
rate_date: '2026-08-21', // Central Bank of Armenia's own publication date
|
|
74
|
+
source: 'USD',
|
|
75
|
+
target: 'AMD',
|
|
76
|
+
rate: 365.16,
|
|
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 'cba-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: 'cba',
|
|
100
|
+
name: 'Central Bank of Armenia',
|
|
101
|
+
rate_date: '2026-08-21',
|
|
102
|
+
rates: [
|
|
103
|
+
{ "base": "USD", "quote": "AMD", "type": "reference", "value": 365.16 },
|
|
104
|
+
// โฆ the rest of the published table (30 currencies vs AMD)
|
|
105
|
+
],
|
|
106
|
+
disclaimer: 'โฆ'
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Table for a date
|
|
111
|
+
|
|
112
|
+
Paid plans. The official table for any date since 2000 โ 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 'cba-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: 'AMD' });
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
**Response:**
|
|
123
|
+
|
|
124
|
+
```javascript
|
|
125
|
+
{
|
|
126
|
+
bank: 'cba',
|
|
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 'cba-exchange-rate';
|
|
141
|
+
|
|
142
|
+
const series = await getHistory(
|
|
143
|
+
{ source: 'USD', target: 'AMD', from: '2026-01-01', to: '2026-08-21' },
|
|
144
|
+
{ apiKey: 'art_live_...' }
|
|
145
|
+
);
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
**Response:**
|
|
149
|
+
|
|
150
|
+
```javascript
|
|
151
|
+
{
|
|
152
|
+
bank: 'cba',
|
|
153
|
+
source: 'USD',
|
|
154
|
+
target: 'AMD',
|
|
155
|
+
from: '2026-01-01',
|
|
156
|
+
to: '2026-08-21',
|
|
157
|
+
count: 152,
|
|
158
|
+
rates: [
|
|
159
|
+
// one entry per publication date
|
|
160
|
+
{ date: '2026-08-21', rate: 365.16, rate_type: 'reference', derived: false, method: 'published' },
|
|
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
|
+
Central Bank of Armenia currently publishes rates covering **30 currencies** against the AMD (as of the latest table):
|
|
174
|
+
|
|
175
|
+
๐ฆ๐ช `AED` ยท ๐ฆ๐บ `AUD` ยท ๐ง๐ท `BRL` ยท ๐ง๐พ `BYN` ยท ๐จ๐ฆ `CAD` ยท ๐จ๐ญ `CHF` ยท ๐จ๐ณ `CNY` ยท ๐จ๐ฟ `CZK` ยท ๐ช๐บ `EUR` ยท ๐ฌ๐ง `GBP` ยท ๐ฌ๐ช `GEL` ยท ๐ญ๐ฐ `HKD` ยท ๐ฎ๐ณ `INR` ยท ๐ฎ๐ท `IRR` ยท ๐ฏ๐ต `JPY` ยท ๐ฐ๐ฌ `KGS` ยท ๐ฐ๐ฟ `KZT` ยท ๐ณ๐ด `NOK` ยท ๐ณ๐ฟ `NZD` ยท ๐ต๐ฑ `PLN` ยท ๐ท๐บ `RUB` ยท ๐ธ๐ช `SEK` ยท ๐ธ๐ฌ `SGD` ยท ๐น๐ฏ `TJS` ยท ๐บ๐ฆ `UAH` ยท ๐บ๐ธ `USD` ยท ๐บ๐ฟ `UZS` ยท `XAG` ยท `XAU` ยท `XDR`
|
|
176
|
+
|
|
177
|
+
## โ๏ธ Published vs derived rates
|
|
178
|
+
|
|
179
|
+
If Central Bank of Armenia 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 AMD 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 Central Bank of Armenia |
|
|
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 'cba-exchange-rate';
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## ๐ฆ CommonJS
|
|
218
|
+
|
|
219
|
+
```javascript
|
|
220
|
+
const { getRate } = require('cba-exchange-rate');
|
|
221
|
+
|
|
222
|
+
getRate('USD', 'AMD', { 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 2000 |
|
|
238
|
+
|
|
239
|
+
## ๐ Links
|
|
240
|
+
|
|
241
|
+
- [Central Bank of Armenia rates page](https://allratestoday.com/central-bank-rates-api/cba/) โ 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/cba-exchange-rate)
|
|
246
|
+
|
|
247
|
+
## ๐ License
|
|
248
|
+
|
|
249
|
+
MIT
|
package/index.cjs
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Central Bank of Armenia exchange rates via the AllRatesToday API.
|
|
3
|
+
const BASE = 'https://allratestoday.com/api/v1/central-bank/cba';
|
|
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', 'AMD', { 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: 'cba';
|
|
15
|
+
name: string;
|
|
16
|
+
rate_date: string;
|
|
17
|
+
rates: RateEntry[];
|
|
18
|
+
disclaimer: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface PairRate {
|
|
22
|
+
bank: 'cba';
|
|
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
|
+
// Central Bank of Armenia exchange rates via the AllRatesToday API.
|
|
2
|
+
const BASE = 'https://allratestoday.com/api/v1/central-bank/cba';
|
|
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', 'AMD', { 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,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cba-exchange-rate",
|
|
3
|
+
"version": "1.2.7",
|
|
4
|
+
"description": "Official Central Bank of Armenia (Armenia) daily exchange rates โ 30 currencies vs AMD, history since 2000. Zero-dependency Node.js/TypeScript client.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"cba",
|
|
7
|
+
"central",
|
|
8
|
+
"bank",
|
|
9
|
+
"of",
|
|
10
|
+
"armenia",
|
|
11
|
+
"exchange-rate",
|
|
12
|
+
"exchange-rates",
|
|
13
|
+
"currency",
|
|
14
|
+
"forex",
|
|
15
|
+
"fx",
|
|
16
|
+
"amd",
|
|
17
|
+
"central-bank",
|
|
18
|
+
"official-rates",
|
|
19
|
+
"armenia",
|
|
20
|
+
"api",
|
|
21
|
+
"typescript"
|
|
22
|
+
],
|
|
23
|
+
"homepage": "https://allratestoday.com/central-bank-rates-api/cba/",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/AllRates-Today/cba-exchange-rate.git"
|
|
27
|
+
},
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/AllRates-Today/cba-exchange-rate/issues"
|
|
30
|
+
},
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"author": "AllRatesToday <hello@allratestoday.com> (https://allratestoday.com)",
|
|
33
|
+
"type": "module",
|
|
34
|
+
"main": "./index.cjs",
|
|
35
|
+
"module": "./index.mjs",
|
|
36
|
+
"types": "./index.d.ts",
|
|
37
|
+
"exports": {
|
|
38
|
+
".": {
|
|
39
|
+
"types": "./index.d.ts",
|
|
40
|
+
"import": "./index.mjs",
|
|
41
|
+
"require": "./index.cjs"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"index.mjs",
|
|
46
|
+
"index.cjs",
|
|
47
|
+
"index.d.ts",
|
|
48
|
+
"README.md",
|
|
49
|
+
"LICENSE"
|
|
50
|
+
],
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=18"
|
|
53
|
+
},
|
|
54
|
+
"sideEffects": false
|
|
55
|
+
}
|