cbe-exchange-rate 1.1.0 → 1.2.0

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.
Files changed (2) hide show
  1. package/README.md +208 -25
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,65 +1,248 @@
1
- # Central Bank of Egypt Exchange Rate API client
1
+ # Central Bank of Egypt Exchange Rate API — cbe-exchange-rate
2
2
 
3
- Official **Central Bank of Egypt** (Egypt) daily exchange rates in Node.js / TypeScript — 18 currencies against the EGP, with history back to 2026. Zero dependencies, works in Node 18+, Bun, Deno, and edge runtimes (uses global `fetch`).
3
+ [![npm version](https://img.shields.io/npm/v/cbe-exchange-rate.svg)](https://www.npmjs.com/package/cbe-exchange-rate)
4
+ [![license](https://img.shields.io/npm/l/cbe-exchange-rate.svg)](https://github.com/AllRates-Today/cbe-exchange-rate/blob/main/LICENSE)
5
+ [![zero dependencies](https://img.shields.io/badge/dependencies-0-brightgreen.svg)](https://www.npmjs.com/package/cbe-exchange-rate)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-types%20included-3178C6.svg)](https://www.typescriptlang.org/)
4
7
 
5
- These are the *published central bank rates* required for tax filings, customs valuations, audits, and compliant invoicing — not moving market rates. Every response carries the publisher's own publication date.
8
+ **Official Central Bank of Egypt (Egypt) 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 Egypt itself prints, every business day.**
6
9
 
7
- Powered by [AllRatesToday](https://allratestoday.com/central-bank-rates-api/cbe/). Get a free API key at [allratestoday.com/register](https://allratestoday.com/register) — no credit card required.
10
+ ## 🚀 Why this client?
8
11
 
9
- ## Install
12
+ - 🏛️ **Official published rates** — Central Bank of Egypt's own table, with the publisher's own `rate_date` on every response
13
+ - 📅 **History back to 2026** — 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
+ ## 🔑 Get your API key
20
+
21
+ 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.
22
+
23
+ ## 📦 Installation
10
24
 
11
25
  ```bash
12
26
  npm install cbe-exchange-rate
13
27
  ```
14
28
 
15
- ## Quick start
29
+ ```bash
30
+ yarn add cbe-exchange-rate
31
+ ```
32
+
33
+ ```bash
34
+ pnpm add cbe-exchange-rate
35
+ ```
36
+
37
+ Also published under the org scope as [`@allratestoday/cbe-exchange-rate`](https://www.npmjs.com/package/@allratestoday/cbe-exchange-rate) — same code, same versions.
38
+
39
+ ## 🏁 Quick start
16
40
 
17
41
  ```js
18
- import { getRate, getLatestRates } from 'cbe-exchange-rate';
42
+ import { getRate } from 'cbe-exchange-rate';
19
43
 
20
- // One pair at the official Central Bank of Egypt rate
21
44
  const pair = await getRate('USD', 'EGP', { apiKey: 'art_live_...' });
22
- console.log(pair.rate, pair.rate_date); // e.g. USD -> EGP on the bank's own date
45
+ console.log(pair.rate, pair.rate_date); // the official Central Bank of Egypt rate, on the central bank's own date
46
+ ```
47
+
48
+ ## 📚 API reference
49
+
50
+ - [Latest pair rate](#latest-pair-rate) — one pair from the latest published table
51
+ - [Full published table](#full-published-table) — everything the central bank printed, in one call
52
+ - [Table for a date](#table-for-a-date) — the official table for an invoice or filing date
53
+ - [Daily time series](#daily-time-series) — one pair across a date range
54
+
55
+ ---
56
+
57
+ ### Latest pair rate
58
+
59
+ 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).
60
+
61
+ ```js
62
+ const pair = await getRate('USD', 'EGP', { apiKey: 'art_live_...' });
63
+ ```
64
+
65
+ **Response:**
66
+
67
+ ```javascript
68
+ {
69
+ bank: 'cbe',
70
+ name: 'Central Bank of Egypt',
71
+ rate_date: '2026-08-11', // Central Bank of Egypt's own publication date
72
+ source: 'USD',
73
+ target: 'EGP',
74
+ rate: 50.3517,
75
+ rate_type: 'sell',
76
+ derived: false,
77
+ method: 'published',
78
+ disclaimer: '…'
79
+ }
80
+ ```
81
+
82
+ ### Full published table
83
+
84
+ Free plan and up. The complete table for the latest publication date.
85
+
86
+ ```js
87
+ import { getLatestRates } from 'cbe-exchange-rate';
23
88
 
24
- // The bank's full published table
25
89
  const table = await getLatestRates({ apiKey: 'art_live_...' });
26
90
  console.log(table.rate_date, table.rates.length);
27
91
  ```
28
92
 
29
- ## Historical data (paid plans)
93
+ **Response:**
94
+
95
+ ```javascript
96
+ {
97
+ bank: 'cbe',
98
+ name: 'Central Bank of Egypt',
99
+ rate_date: '2026-08-11',
100
+ rates: [
101
+ { "base": "USD", "quote": "EGP", "type": "sell", "value": 50.3517 },
102
+ { "base": "USD", "quote": "EGP", "type": "buy", "value": 50.2154 },
103
+ // … the rest of the published table (18 currencies vs EGP)
104
+ ],
105
+ disclaimer: '…'
106
+ }
107
+ ```
108
+
109
+ ### Table for a date
110
+
111
+ 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.
30
112
 
31
113
  ```js
32
- import { getRatesForDate, getHistory } from 'cbe-exchange-rate';
114
+ import { getRatesForDate } from 'cbe-exchange-rate';
33
115
 
34
- // The official table for an invoice date — weekends/holidays return the
35
- // most recent published date, flagged via published_on_requested_date.
36
116
  const day = await getRatesForDate('2026-06-30', { apiKey: 'art_live_...' });
117
+ // Optionally narrow to one pair:
118
+ const one = await getRatesForDate('2026-06-30', { apiKey: 'art_live_...', source: 'USD', target: 'EGP' });
119
+ ```
120
+
121
+ **Response:**
122
+
123
+ ```javascript
124
+ {
125
+ bank: 'cbe',
126
+ requested_date: '2026-06-30',
127
+ rate_date: '2026-06-30', // the date actually published
128
+ published_on_requested_date: true, // false when a weekend/holiday fell back
129
+ rates: [ /* the full table for that date */ ],
130
+ disclaimer: '…'
131
+ }
132
+ ```
133
+
134
+ ### Daily time series
135
+
136
+ Paid plans. One resolved rate per publication date — ready for charting, revaluation runs, or audit workpapers.
137
+
138
+ ```js
139
+ import { getHistory } from 'cbe-exchange-rate';
37
140
 
38
- // Daily series for one pair
39
141
  const series = await getHistory(
40
- { source: 'USD', target: 'EGP', from: '2026-01-01' },
142
+ { source: 'USD', target: 'EGP', from: '2026-01-01', to: '2026-08-11' },
41
143
  { apiKey: 'art_live_...' }
42
144
  );
43
145
  ```
44
146
 
45
- ## Currencies covered
147
+ **Response:**
148
+
149
+ ```javascript
150
+ {
151
+ bank: 'cbe',
152
+ source: 'USD',
153
+ target: 'EGP',
154
+ from: '2026-01-01',
155
+ to: '2026-08-11',
156
+ count: 152,
157
+ rates: [
158
+ // one entry per publication date
159
+ { date: '2026-08-11', rate: 50.3517, rate_type: 'sell', derived: false, method: 'published' },
160
+ // …
161
+ ],
162
+ disclaimer: '…'
163
+ }
164
+ ```
165
+
166
+ Pass `{ symbol: 'USD' }` instead of `source`/`target` to get the raw published rows for one currency (all rate types, no pair resolution).
167
+
168
+ ---
169
+
170
+ ## 🗺️ Currencies covered
46
171
 
47
172
  Central Bank of Egypt currently publishes rates covering **19 currencies** (as of the latest table):
48
173
 
49
174
  `AED` · `AUD` · `BHD` · `CAD` · `CHF` · `CNY` · `DKK` · `EGP` · `EUR` · `GBP` · `JOD` · `JPY` · `KWD` · `NOK` · `OMR` · `QAR` · `SAR` · `SEK` · `USD`
50
175
 
51
- Pairs the central bank does not print directly are resolved from this table (see below).
176
+ ## ⚖️ Published vs derived rates
177
+
178
+ If Central Bank of Egypt 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:
179
+
180
+ | `method` | `derived` | Meaning |
181
+ | --- | --- | --- |
182
+ | `published` | `false` | The central bank printed this pair directly |
183
+ | `inverse` | `true` | Computed as 1 ÷ the published opposite direction |
184
+ | `cross` | `true` | Computed via EGP from two published rates |
185
+
186
+ ## 🛡️ Error handling
187
+
188
+ Errors are thrown as `Error` with `status` (HTTP code) and `body` (the API's JSON error) attached:
189
+
190
+ ```js
191
+ try {
192
+ const pair = await getRate('USD', 'XXX', { apiKey: 'art_live_...' });
193
+ } catch (err) {
194
+ console.log(err.message); // human-readable reason
195
+ console.log(err.status); // e.g. 404
196
+ }
197
+ ```
198
+
199
+ | Status | Meaning |
200
+ | ------ | ------- |
201
+ | — | Missing `apiKey` (thrown before any request) |
202
+ | `400` | Malformed date or parameters |
203
+ | `401` | Invalid API key |
204
+ | `403` | Endpoint needs a [paid plan](https://allratestoday.com/pricing/) (historical dates & series) |
205
+ | `404` | Pair or date range not covered by Central Bank of Egypt |
206
+ | `429` | Monthly quota exceeded |
207
+
208
+ ## 🔷 TypeScript
209
+
210
+ Full definitions ship with the package — no `@types` install:
211
+
212
+ ```ts
213
+ import type { LatestRates, PairRate, DatedRates, RateEntry, HistoryQuery, RequestOptions } from 'cbe-exchange-rate';
214
+ ```
215
+
216
+ ## 📦 CommonJS
217
+
218
+ ```javascript
219
+ const { getRate } = require('cbe-exchange-rate');
220
+
221
+ getRate('USD', 'EGP', { apiKey: 'art_live_...' }).then((pair) => console.log(pair.rate));
222
+ ```
223
+
224
+ ## 💡 Quota tips
225
+
226
+ - Rates change once per business day — cache the published table locally and a small monthly quota goes a long way.
227
+ - Every request counts toward your AllRatesToday quota, shared across all AllRatesToday endpoints on your key.
52
228
 
53
- ## Published vs derived rates
229
+ ## 📖 Methods reference
54
230
 
55
- If Central Bank of Egypt does not print a pair directly, the API resolves it from the bank's table (inverse, or a cross rate via EGP) and flags it `derived: true` with the `method` — so official and computed values are never confused.
231
+ | Method | Plan | Description |
232
+ | ------ | ---- | ----------- |
233
+ | `getRate(source, target, { apiKey })` | Free | Latest rate for one pair, resolved from the published table |
234
+ | `getLatestRates({ apiKey })` | Free | The central bank's full latest published table |
235
+ | `getRatesForDate(date, { apiKey, source?, target? })` | Paid | The official table (or one pair) for a YYYY-MM-DD date |
236
+ | `getHistory({ symbol \| source+target, from?, to? }, { apiKey })` | Paid | Daily series since 2026 |
56
237
 
57
- ## Notes
238
+ ## 🔗 Links
58
239
 
59
- - Every request counts toward your AllRatesToday monthly quota. Rates change once per business day — cache a day's table locally and a small quota goes a long way.
60
- - Latest rates are on every plan (including free); historical dates and time series need a [paid plan](https://allratestoday.com/pricing/).
61
- - Full API reference: [allratestoday.com/docs#central-bank](https://allratestoday.com/docs/#central-bank) · All covered sources: [central bank rates API](https://allratestoday.com/central-bank-rates-api/)
240
+ - [Central Bank of Egypt rates page](https://allratestoday.com/central-bank-rates-api/cbe/) — live table, publication cadence, FAQ
241
+ - [All central bank sources](https://allratestoday.com/central-bank-rates-api/)
242
+ - [API documentation](https://allratestoday.com/docs/#central-bank) · [Interactive reference](https://allratestoday.com/api-reference/)
243
+ - [Register (free)](https://allratestoday.com/register) · [Pricing](https://allratestoday.com/pricing/)
244
+ - [GitHub](https://github.com/AllRates-Today/cbe-exchange-rate)
62
245
 
63
- ## License
246
+ ## 📜 License
64
247
 
65
248
  MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cbe-exchange-rate",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Official Central Bank of Egypt (Egypt) daily exchange rates — 18 currencies vs EGP, history since 2026. Zero-dependency Node.js/TypeScript client.",
5
5
  "keywords": [
6
6
  "cbe",