@allratestoday/sdk 1.4.6 → 1.4.8

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
@@ -95,6 +95,8 @@ console.log(data);
95
95
 
96
96
  ### Historical Exchange Rates
97
97
 
98
+ > Historical methods (`forDate`, `timeSeries`, `getHistoricalRates` and `convert` with a `date`) need a paid plan from €4.99/month. Free and trial keys get latest rates only and receive a 403 `historical_requires_paid_plan` for history.
99
+
98
100
  Travel back in time to get rates from any date:
99
101
 
100
102
  ```typescript
@@ -282,8 +284,8 @@ console.log(sources.map((s) => `${s.code} ${s.latest}${s.stale ? ' (stale)' : ''
282
284
  ```
283
285
 
284
286
  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
+ not the time of your call. Dated tables and history need a paid plan and use
288
+ `/api/v1/central-bank/{bank}/{date}`; publication calendars work on any key. See the
287
289
  [central bank rates API](https://allratestoday.com/central-bank-rates-api/).
288
290
 
289
291
  ### Historical Rates by Period
package/dist/index.js CHANGED
@@ -303,7 +303,18 @@ var AllRatesToday = class {
303
303
  const key = this.resolveKey(options.apiKey);
304
304
  const params = { source: from, target: to };
305
305
  if (amount !== void 0) params.amount = String(amount);
306
- return this.request("/api/v1/rates", params, key);
306
+ const raw = await this.request("/api/v1/rates", params, key);
307
+ if (Array.isArray(raw) || !("from" in raw)) {
308
+ const r = Array.isArray(raw) ? raw[0] : raw;
309
+ if (!r) throw new AllRatesTodayError(`No rate returned for ${from}/${to}`);
310
+ return {
311
+ from: { currency: r.source, amount: 1 },
312
+ to: { currency: r.target, amount: r.rate },
313
+ rate: r.rate,
314
+ source: "mid-market"
315
+ };
316
+ }
317
+ return raw;
307
318
  }
308
319
  /**
309
320
  * Get authenticated exchange rates with metadata.
@@ -329,11 +340,15 @@ var AllRatesToday = class {
329
340
  */
330
341
  async getHistoricalRates(source, target, period = "7d", options = {}) {
331
342
  const key = this.resolveKey(options.apiKey);
332
- return this.request(
333
- "/api/historical-rates",
334
- { source, target, period },
335
- key
336
- );
343
+ const points = await this.historyPoints(source, target, period, key);
344
+ const rates = points.map((p) => ({ rate: p.rate, time: p.date }));
345
+ return {
346
+ source,
347
+ target,
348
+ period,
349
+ current: rates[rates.length - 1] ?? { rate: 0, time: "" },
350
+ rates
351
+ };
337
352
  }
338
353
  /**
339
354
  * Convert an amount between two currencies.
package/dist/index.mjs CHANGED
@@ -277,7 +277,18 @@ var AllRatesToday = class {
277
277
  const key = this.resolveKey(options.apiKey);
278
278
  const params = { source: from, target: to };
279
279
  if (amount !== void 0) params.amount = String(amount);
280
- return this.request("/api/v1/rates", params, key);
280
+ const raw = await this.request("/api/v1/rates", params, key);
281
+ if (Array.isArray(raw) || !("from" in raw)) {
282
+ const r = Array.isArray(raw) ? raw[0] : raw;
283
+ if (!r) throw new AllRatesTodayError(`No rate returned for ${from}/${to}`);
284
+ return {
285
+ from: { currency: r.source, amount: 1 },
286
+ to: { currency: r.target, amount: r.rate },
287
+ rate: r.rate,
288
+ source: "mid-market"
289
+ };
290
+ }
291
+ return raw;
281
292
  }
282
293
  /**
283
294
  * Get authenticated exchange rates with metadata.
@@ -303,11 +314,15 @@ var AllRatesToday = class {
303
314
  */
304
315
  async getHistoricalRates(source, target, period = "7d", options = {}) {
305
316
  const key = this.resolveKey(options.apiKey);
306
- return this.request(
307
- "/api/historical-rates",
308
- { source, target, period },
309
- key
310
- );
317
+ const points = await this.historyPoints(source, target, period, key);
318
+ const rates = points.map((p) => ({ rate: p.rate, time: p.date }));
319
+ return {
320
+ source,
321
+ target,
322
+ period,
323
+ current: rates[rates.length - 1] ?? { rate: 0, time: "" },
324
+ rates
325
+ };
311
326
  }
312
327
  /**
313
328
  * Convert an amount between two currencies.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allratestoday/sdk",
3
- "version": "1.4.6",
3
+ "version": "1.4.8",
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",