@allratestoday/sdk 1.4.6 → 1.4.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/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: "interbank"
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: "interbank"
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.7",
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",