@allratestoday/sdk 1.2.1 → 1.3.1

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.d.mts CHANGED
@@ -1,3 +1,15 @@
1
+ interface AllRatesTodayOptions {
2
+ /** API key. Register for free at https://allratestoday.com/register */
3
+ apiKey?: string;
4
+ /** API base URL. Default: `https://allratestoday.com` */
5
+ baseUrl?: string;
6
+ /** Request timeout in milliseconds. Default: `10000` */
7
+ timeout?: number;
8
+ }
9
+ interface RequestOptions {
10
+ /** Override the API key for this request only. */
11
+ apiKey?: string;
12
+ }
1
13
  interface RateResponse {
2
14
  from: {
3
15
  currency: string;
@@ -16,6 +28,52 @@ interface AuthRateResponse {
16
28
  target: string;
17
29
  time: string;
18
30
  }
31
+ interface LatestOptions extends RequestOptions {
32
+ /** Base currency code. Default: `USD` */
33
+ base?: string;
34
+ /** Array of target currency codes. If omitted, returns all available. */
35
+ symbols?: string[];
36
+ }
37
+ interface LatestResponse {
38
+ base: string;
39
+ date: string;
40
+ rates: Record<string, number>;
41
+ }
42
+ interface ForDateOptions extends RequestOptions {
43
+ /** Base currency code. Default: `USD` */
44
+ base?: string;
45
+ /** Array of target currency codes. */
46
+ symbols?: string[];
47
+ }
48
+ interface ForDateResponse {
49
+ base: string;
50
+ date: string;
51
+ rates: Record<string, number>;
52
+ }
53
+ interface ConvertOptions extends RequestOptions {
54
+ /** Historical date for conversion (YYYY-MM-DD or Date object). */
55
+ date?: string | Date;
56
+ }
57
+ interface ConvertResponse {
58
+ from: string;
59
+ to: string;
60
+ amount: number;
61
+ result: number;
62
+ rate: number;
63
+ date?: string;
64
+ }
65
+ interface TimeSeriesOptions extends RequestOptions {
66
+ /** Base currency code. Default: `USD` */
67
+ base?: string;
68
+ /** Array of target currency codes. */
69
+ symbols?: string[];
70
+ }
71
+ interface TimeSeriesResponse {
72
+ base: string;
73
+ startDate: string;
74
+ endDate: string;
75
+ rates: Record<string, Record<string, number>>;
76
+ }
19
77
  interface HistoricalRateResponse {
20
78
  source: string;
21
79
  target: string;
@@ -29,10 +87,13 @@ interface HistoricalRateResponse {
29
87
  time: string;
30
88
  }>;
31
89
  }
32
- interface AllRatesTodayOptions {
33
- apiKey?: string;
34
- baseUrl?: string;
35
- timeout?: number;
90
+ interface SymbolsResponse {
91
+ symbols: Record<string, string>;
92
+ }
93
+ declare class AllRatesTodayError extends Error {
94
+ /** HTTP status code (when available). */
95
+ status?: number;
96
+ constructor(message: string, status?: number);
36
97
  }
37
98
  declare class AllRatesToday {
38
99
  private apiKey?;
@@ -40,36 +101,118 @@ declare class AllRatesToday {
40
101
  private timeout;
41
102
  /**
42
103
  * Create an AllRatesToday client.
43
- * @param options - API key is required. Register for free at https://allratestoday.com/register
104
+ *
105
+ * ```ts
106
+ * const client = new AllRatesToday({ apiKey: 'art_live_...' });
107
+ * ```
108
+ *
109
+ * @param options - Configuration. Get a free API key at https://allratestoday.com/register
44
110
  */
45
111
  constructor(options?: AllRatesTodayOptions);
112
+ private resolveKey;
46
113
  private request;
114
+ private formatDate;
47
115
  /**
48
- * Get exchange rate between two currencies (requires API key)
116
+ * Get the latest exchange rates.
117
+ *
118
+ * ```ts
119
+ * // All rates from USD
120
+ * const data = await client.latest();
121
+ *
122
+ * // Specific symbols with EUR base
123
+ * const data = await client.latest({ base: 'EUR', symbols: ['USD', 'GBP', 'JPY'] });
124
+ * ```
49
125
  */
50
- getRate(from: string, to: string, amount?: number): Promise<RateResponse>;
126
+ latest(options?: LatestOptions): Promise<LatestResponse>;
51
127
  /**
52
- * Get authenticated exchange rate (requires API key)
128
+ * Get exchange rates for a specific historical date.
129
+ *
130
+ * ```ts
131
+ * // Using a string
132
+ * const data = await client.forDate('2026-01-15');
133
+ *
134
+ * // Using a Date object
135
+ * const data = await client.forDate(new Date('2026-01-15'));
136
+ *
137
+ * // With options
138
+ * const data = await client.forDate('2026-01-15', { base: 'EUR', symbols: ['USD', 'GBP'] });
139
+ * ```
53
140
  */
54
- getRates(source: string, target: string): Promise<AuthRateResponse[]>;
141
+ forDate(date: string | Date, options?: ForDateOptions): Promise<ForDateResponse>;
55
142
  /**
56
- * Get historical rates (requires API key)
143
+ * Get exchange rate time series between two dates.
144
+ *
145
+ * ```ts
146
+ * const data = await client.timeSeries('2026-01-01', '2026-03-31', {
147
+ * base: 'USD',
148
+ * symbols: ['EUR', 'GBP'],
149
+ * });
150
+ *
151
+ * // Access rates by date
152
+ * console.log(data.rates['2026-01-15']); // { EUR: 0.92, GBP: 0.78 }
153
+ * ```
57
154
  */
58
- getHistoricalRates(source: string, target: string, period?: '1d' | '7d' | '30d' | '1y'): Promise<HistoricalRateResponse>;
155
+ timeSeries(startDate: string | Date, endDate: string | Date, options?: TimeSeriesOptions): Promise<TimeSeriesResponse>;
59
156
  /**
60
- * Convert an amount from one currency to another
157
+ * Get all supported currency symbols.
158
+ *
159
+ * ```ts
160
+ * const { symbols } = await client.symbols();
161
+ * console.log(symbols);
162
+ * // { USD: 'United States Dollar', EUR: 'Euro', GBP: 'British Pound', ... }
163
+ *
164
+ * // Build a currency dropdown
165
+ * const options = Object.entries(symbols).map(([code, name]) => ({ code, name }));
166
+ * ```
61
167
  */
62
- convert(from: string, to: string, amount: number): Promise<{
63
- from: string;
64
- to: string;
65
- amount: number;
66
- result: number;
67
- rate: number;
68
- }>;
69
- }
70
- declare class AllRatesTodayError extends Error {
71
- status?: number;
72
- constructor(message: string, status?: number);
168
+ symbols(options?: RequestOptions): Promise<SymbolsResponse>;
169
+ /**
170
+ * Get exchange rate between two currencies.
171
+ *
172
+ * ```ts
173
+ * const rate = await client.getRate('USD', 'EUR');
174
+ * console.log(`1 USD = ${rate.rate} EUR`);
175
+ *
176
+ * // With amount
177
+ * const rate = await client.getRate('USD', 'EUR', 1000);
178
+ * console.log(`$1,000 = €${rate.to.amount}`);
179
+ * ```
180
+ */
181
+ getRate(from: string, to: string, amount?: number, options?: RequestOptions): Promise<RateResponse>;
182
+ /**
183
+ * Get authenticated exchange rates with metadata.
184
+ *
185
+ * ```ts
186
+ * const rates = await client.getRates('USD', 'EUR');
187
+ * rates.forEach(r => console.log(`${r.source}/${r.target}: ${r.rate} at ${r.time}`));
188
+ * ```
189
+ */
190
+ getRates(source: string, target: string, options?: RequestOptions): Promise<AuthRateResponse[]>;
191
+ /**
192
+ * Get historical rates by period.
193
+ *
194
+ * ```ts
195
+ * const history = await client.getHistoricalRates('USD', 'EUR', '30d');
196
+ * history.rates.forEach(point => {
197
+ * console.log(`${point.time}: ${point.rate}`);
198
+ * });
199
+ * ```
200
+ */
201
+ getHistoricalRates(source: string, target: string, period?: '1d' | '7d' | '30d' | '1y', options?: RequestOptions): Promise<HistoricalRateResponse>;
202
+ /**
203
+ * Convert an amount between two currencies.
204
+ *
205
+ * ```ts
206
+ * // Current rate
207
+ * const result = await client.convert('USD', 'EUR', 1000);
208
+ * console.log(`$1,000 = €${result.result}`);
209
+ *
210
+ * // Historical conversion
211
+ * const result = await client.convert('USD', 'EUR', 1000, { date: '2026-01-15' });
212
+ * console.log(`Rate on Jan 15: ${result.rate}`);
213
+ * ```
214
+ */
215
+ convert(from: string, to: string, amount: number, options?: ConvertOptions): Promise<ConvertResponse>;
73
216
  }
74
217
 
75
- export { AllRatesToday, AllRatesTodayError, type AllRatesTodayOptions, type AuthRateResponse, type HistoricalRateResponse, type RateResponse, AllRatesToday as default };
218
+ export { AllRatesToday, AllRatesTodayError, type AllRatesTodayOptions, type AuthRateResponse, type ConvertOptions, type ConvertResponse, type ForDateOptions, type ForDateResponse, type HistoricalRateResponse, type LatestOptions, type LatestResponse, type RateResponse, type RequestOptions, type SymbolsResponse, type TimeSeriesOptions, type TimeSeriesResponse, AllRatesToday as default };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,15 @@
1
+ interface AllRatesTodayOptions {
2
+ /** API key. Register for free at https://allratestoday.com/register */
3
+ apiKey?: string;
4
+ /** API base URL. Default: `https://allratestoday.com` */
5
+ baseUrl?: string;
6
+ /** Request timeout in milliseconds. Default: `10000` */
7
+ timeout?: number;
8
+ }
9
+ interface RequestOptions {
10
+ /** Override the API key for this request only. */
11
+ apiKey?: string;
12
+ }
1
13
  interface RateResponse {
2
14
  from: {
3
15
  currency: string;
@@ -16,6 +28,52 @@ interface AuthRateResponse {
16
28
  target: string;
17
29
  time: string;
18
30
  }
31
+ interface LatestOptions extends RequestOptions {
32
+ /** Base currency code. Default: `USD` */
33
+ base?: string;
34
+ /** Array of target currency codes. If omitted, returns all available. */
35
+ symbols?: string[];
36
+ }
37
+ interface LatestResponse {
38
+ base: string;
39
+ date: string;
40
+ rates: Record<string, number>;
41
+ }
42
+ interface ForDateOptions extends RequestOptions {
43
+ /** Base currency code. Default: `USD` */
44
+ base?: string;
45
+ /** Array of target currency codes. */
46
+ symbols?: string[];
47
+ }
48
+ interface ForDateResponse {
49
+ base: string;
50
+ date: string;
51
+ rates: Record<string, number>;
52
+ }
53
+ interface ConvertOptions extends RequestOptions {
54
+ /** Historical date for conversion (YYYY-MM-DD or Date object). */
55
+ date?: string | Date;
56
+ }
57
+ interface ConvertResponse {
58
+ from: string;
59
+ to: string;
60
+ amount: number;
61
+ result: number;
62
+ rate: number;
63
+ date?: string;
64
+ }
65
+ interface TimeSeriesOptions extends RequestOptions {
66
+ /** Base currency code. Default: `USD` */
67
+ base?: string;
68
+ /** Array of target currency codes. */
69
+ symbols?: string[];
70
+ }
71
+ interface TimeSeriesResponse {
72
+ base: string;
73
+ startDate: string;
74
+ endDate: string;
75
+ rates: Record<string, Record<string, number>>;
76
+ }
19
77
  interface HistoricalRateResponse {
20
78
  source: string;
21
79
  target: string;
@@ -29,10 +87,13 @@ interface HistoricalRateResponse {
29
87
  time: string;
30
88
  }>;
31
89
  }
32
- interface AllRatesTodayOptions {
33
- apiKey?: string;
34
- baseUrl?: string;
35
- timeout?: number;
90
+ interface SymbolsResponse {
91
+ symbols: Record<string, string>;
92
+ }
93
+ declare class AllRatesTodayError extends Error {
94
+ /** HTTP status code (when available). */
95
+ status?: number;
96
+ constructor(message: string, status?: number);
36
97
  }
37
98
  declare class AllRatesToday {
38
99
  private apiKey?;
@@ -40,36 +101,118 @@ declare class AllRatesToday {
40
101
  private timeout;
41
102
  /**
42
103
  * Create an AllRatesToday client.
43
- * @param options - API key is required. Register for free at https://allratestoday.com/register
104
+ *
105
+ * ```ts
106
+ * const client = new AllRatesToday({ apiKey: 'art_live_...' });
107
+ * ```
108
+ *
109
+ * @param options - Configuration. Get a free API key at https://allratestoday.com/register
44
110
  */
45
111
  constructor(options?: AllRatesTodayOptions);
112
+ private resolveKey;
46
113
  private request;
114
+ private formatDate;
47
115
  /**
48
- * Get exchange rate between two currencies (requires API key)
116
+ * Get the latest exchange rates.
117
+ *
118
+ * ```ts
119
+ * // All rates from USD
120
+ * const data = await client.latest();
121
+ *
122
+ * // Specific symbols with EUR base
123
+ * const data = await client.latest({ base: 'EUR', symbols: ['USD', 'GBP', 'JPY'] });
124
+ * ```
49
125
  */
50
- getRate(from: string, to: string, amount?: number): Promise<RateResponse>;
126
+ latest(options?: LatestOptions): Promise<LatestResponse>;
51
127
  /**
52
- * Get authenticated exchange rate (requires API key)
128
+ * Get exchange rates for a specific historical date.
129
+ *
130
+ * ```ts
131
+ * // Using a string
132
+ * const data = await client.forDate('2026-01-15');
133
+ *
134
+ * // Using a Date object
135
+ * const data = await client.forDate(new Date('2026-01-15'));
136
+ *
137
+ * // With options
138
+ * const data = await client.forDate('2026-01-15', { base: 'EUR', symbols: ['USD', 'GBP'] });
139
+ * ```
53
140
  */
54
- getRates(source: string, target: string): Promise<AuthRateResponse[]>;
141
+ forDate(date: string | Date, options?: ForDateOptions): Promise<ForDateResponse>;
55
142
  /**
56
- * Get historical rates (requires API key)
143
+ * Get exchange rate time series between two dates.
144
+ *
145
+ * ```ts
146
+ * const data = await client.timeSeries('2026-01-01', '2026-03-31', {
147
+ * base: 'USD',
148
+ * symbols: ['EUR', 'GBP'],
149
+ * });
150
+ *
151
+ * // Access rates by date
152
+ * console.log(data.rates['2026-01-15']); // { EUR: 0.92, GBP: 0.78 }
153
+ * ```
57
154
  */
58
- getHistoricalRates(source: string, target: string, period?: '1d' | '7d' | '30d' | '1y'): Promise<HistoricalRateResponse>;
155
+ timeSeries(startDate: string | Date, endDate: string | Date, options?: TimeSeriesOptions): Promise<TimeSeriesResponse>;
59
156
  /**
60
- * Convert an amount from one currency to another
157
+ * Get all supported currency symbols.
158
+ *
159
+ * ```ts
160
+ * const { symbols } = await client.symbols();
161
+ * console.log(symbols);
162
+ * // { USD: 'United States Dollar', EUR: 'Euro', GBP: 'British Pound', ... }
163
+ *
164
+ * // Build a currency dropdown
165
+ * const options = Object.entries(symbols).map(([code, name]) => ({ code, name }));
166
+ * ```
61
167
  */
62
- convert(from: string, to: string, amount: number): Promise<{
63
- from: string;
64
- to: string;
65
- amount: number;
66
- result: number;
67
- rate: number;
68
- }>;
69
- }
70
- declare class AllRatesTodayError extends Error {
71
- status?: number;
72
- constructor(message: string, status?: number);
168
+ symbols(options?: RequestOptions): Promise<SymbolsResponse>;
169
+ /**
170
+ * Get exchange rate between two currencies.
171
+ *
172
+ * ```ts
173
+ * const rate = await client.getRate('USD', 'EUR');
174
+ * console.log(`1 USD = ${rate.rate} EUR`);
175
+ *
176
+ * // With amount
177
+ * const rate = await client.getRate('USD', 'EUR', 1000);
178
+ * console.log(`$1,000 = €${rate.to.amount}`);
179
+ * ```
180
+ */
181
+ getRate(from: string, to: string, amount?: number, options?: RequestOptions): Promise<RateResponse>;
182
+ /**
183
+ * Get authenticated exchange rates with metadata.
184
+ *
185
+ * ```ts
186
+ * const rates = await client.getRates('USD', 'EUR');
187
+ * rates.forEach(r => console.log(`${r.source}/${r.target}: ${r.rate} at ${r.time}`));
188
+ * ```
189
+ */
190
+ getRates(source: string, target: string, options?: RequestOptions): Promise<AuthRateResponse[]>;
191
+ /**
192
+ * Get historical rates by period.
193
+ *
194
+ * ```ts
195
+ * const history = await client.getHistoricalRates('USD', 'EUR', '30d');
196
+ * history.rates.forEach(point => {
197
+ * console.log(`${point.time}: ${point.rate}`);
198
+ * });
199
+ * ```
200
+ */
201
+ getHistoricalRates(source: string, target: string, period?: '1d' | '7d' | '30d' | '1y', options?: RequestOptions): Promise<HistoricalRateResponse>;
202
+ /**
203
+ * Convert an amount between two currencies.
204
+ *
205
+ * ```ts
206
+ * // Current rate
207
+ * const result = await client.convert('USD', 'EUR', 1000);
208
+ * console.log(`$1,000 = €${result.result}`);
209
+ *
210
+ * // Historical conversion
211
+ * const result = await client.convert('USD', 'EUR', 1000, { date: '2026-01-15' });
212
+ * console.log(`Rate on Jan 15: ${result.rate}`);
213
+ * ```
214
+ */
215
+ convert(from: string, to: string, amount: number, options?: ConvertOptions): Promise<ConvertResponse>;
73
216
  }
74
217
 
75
- export { AllRatesToday, AllRatesTodayError, type AllRatesTodayOptions, type AuthRateResponse, type HistoricalRateResponse, type RateResponse, AllRatesToday as default };
218
+ export { AllRatesToday, AllRatesTodayError, type AllRatesTodayOptions, type AuthRateResponse, type ConvertOptions, type ConvertResponse, type ForDateOptions, type ForDateResponse, type HistoricalRateResponse, type LatestOptions, type LatestResponse, type RateResponse, type RequestOptions, type SymbolsResponse, type TimeSeriesOptions, type TimeSeriesResponse, AllRatesToday as default };