From bae52888302b8c477637d1dba07e8f58703be8e9 Mon Sep 17 00:00:00 2001 From: Miles Zimmerman Date: Sat, 31 May 2025 21:11:33 -0700 Subject: [PATCH 1/4] add type declaration --- index.d.ts | 186 +++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 187 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..c87f36b --- /dev/null +++ b/index.d.ts @@ -0,0 +1,186 @@ +import { AxiosResponse } from 'axios'; + +declare module 'forexrateapi' { + // Base response structure for all API endpoints + interface BaseResponse { + success: boolean; + error?: { + code: number; + info: string; + }; + } + + // Symbols response + interface SymbolsResponse extends BaseResponse { + symbols: { + [currencyCode: string]: string; + }; + } + + // Live rates response + interface LiveRatesResponse extends BaseResponse { + base: string; + timestamp: number; + rates: { + [currencyCode: string]: number; + }; + } + + // Historical rates response (same structure as live rates) + interface HistoricalRatesResponse extends BaseResponse { + base: string; + timestamp: number; + rates: { + [currencyCode: string]: number; + }; + } + + // OHLC response + interface OHLCResponse extends BaseResponse { + base: string; + currency: string; + timestamp: number; + ohlc: { + open: number; + high: number; + low: number; + close: number; + }; + } + + // Convert response + interface ConvertResponse extends BaseResponse { + base: string; + query: { + from: string; + to: string; + amount: number; + }; + info: { + quote: number; + timestamp: number + } + result: number; + } + + // Timeframe response + interface TimeframeResponse extends BaseResponse { + base: string; + start_date: string; + end_date: string; + rates: { + [date: string]: { + [currencyCode: string]: number; + }; + }; + } + + // Change response + interface ChangeResponse extends BaseResponse { + base: string; + start_date: string; + end_date: string; + change: { + [currencyCode: string]: { + start_rate: number; + end_rate: number; + change: number; + change_pct: number; + }; + }; + } + + // Usage response + interface UsageResponse extends BaseResponse { + result: { + plan: string; + used: number; + total: number; + remaining: number; + } + } + + // Date type options for OHLC endpoint + type DateType = 'recent' | 'yesterday' | 'week' | 'month' | 'year'; + + // Main module interface + interface ForexRateAPI { + /** + * Set the API key for authentication + * @param apiKey Your ForexRateAPI.com API key + */ + setAPIKey(apiKey: string): void; + + /** + * Fetch all supported currency symbols + * @returns Promise resolving to axios response with symbols data + */ + fetchSymbols(): Promise>; + + /** + * Fetch live exchange rates + * @param base Optional base currency (defaults to USD) + * @param currencies Optional array of currencies to return rates for + * @returns Promise resolving to axios response with live rates data + */ + fetchLive(base?: string, currencies?: string[]): Promise>; + + /** + * Fetch historical exchange rates for a specific date + * @param date Date in YYYY-MM-DD format + * @param base Optional base currency (defaults to USD) + * @param currencies Optional array of currencies to return rates for + * @returns Promise resolving to axios response with historical rates data + */ + fetchHistorical(date: string, base?: string, currencies?: string[]): Promise>; + + /** + * Fetch Open, High, Low, Close (OHLC) data for a currency pair + * @param base Base currency (defaults to USD) + * @param currency Target currency for OHLC data + * @param date Date in YYYY-MM-DD format + * @param dateType Optional date type that overrides the date parameter + * @returns Promise resolving to axios response with OHLC data + */ + ohlc(base?: string, currency?: string, date?: string, dateType?: DateType): Promise>; + + /** + * Convert amount from one currency to another + * @param from Source currency (defaults to USD) + * @param to Target currency + * @param amount Amount to convert + * @param date Optional date for historical conversion (YYYY-MM-DD format) + * @returns Promise resolving to axios response with conversion data + */ + convert(from?: string, to?: string, amount?: number, date?: string): Promise>; + + /** + * Get exchange rates for a specific time period + * @param startDate Start date in YYYY-MM-DD format + * @param endDate End date in YYYY-MM-DD format + * @param base Optional base currency (defaults to USD) + * @param currencies Optional array of currencies to return rates for + * @returns Promise resolving to axios response with timeframe data + */ + timeframe(startDate: string, endDate: string, base?: string, currencies?: string[]): Promise>; + + /** + * Get exchange rate changes between two dates + * @param startDate Start date in YYYY-MM-DD format + * @param endDate End date in YYYY-MM-DD format + * @param base Optional base currency (defaults to USD) + * @param currencies Optional array of currencies to return changes for + * @returns Promise resolving to axios response with change data + */ + change(startDate: string, endDate: string, base?: string, currencies?: string[]): Promise>; + + /** + * Get current API usage statistics + * @returns Promise resolving to axios response with usage data + */ + usage(): Promise>; + } + + const api: ForexRateAPI; + export = api; +} \ No newline at end of file diff --git a/package.json b/package.json index 902c43e..f4fe80c 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "1.1.2", "description": "Official Node.js Library for ForexRateAPI", "main": "index.js", + "types": "index.d.ts", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, From ddb54e98b83f04da60176390470ead0c2bc36a1b Mon Sep 17 00:00:00 2001 From: Miles Zimmerman Date: Mon, 16 Jun 2025 17:25:24 -0700 Subject: [PATCH 2/4] working typechecks --- index.d.ts | 356 ++++++++++++++++++++++++++--------------------------- 1 file changed, 177 insertions(+), 179 deletions(-) diff --git a/index.d.ts b/index.d.ts index c87f36b..93492d1 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,186 +1,184 @@ import { AxiosResponse } from 'axios'; -declare module 'forexrateapi' { - // Base response structure for all API endpoints - interface BaseResponse { - success: boolean; - error?: { - code: number; - info: string; - }; - } - - // Symbols response - interface SymbolsResponse extends BaseResponse { - symbols: { - [currencyCode: string]: string; - }; +// Base response structure for all API endpoints +interface BaseResponse { + success: boolean; + error?: { + code: number; + info: string; + }; +} + +// Symbols response +interface SymbolsResponse extends BaseResponse { + symbols: { + [currencyCode: string]: string; + }; +} + +// Live rates response +interface LiveRatesResponse extends BaseResponse { + base: string; + timestamp: number; + rates: { + [currencyCode: string]: number; + }; +} + +// Historical rates response (same structure as live rates) +interface HistoricalRatesResponse extends BaseResponse { + base: string; + timestamp: number; + rates: { + [currencyCode: string]: number; + }; +} + +// OHLC response +interface OHLCResponse extends BaseResponse { + base: string; + currency: string; + timestamp: number; + ohlc: { + open: number; + high: number; + low: number; + close: number; + }; +} + +// Convert response +interface ConvertResponse extends BaseResponse { + base: string; + query: { + from: string; + to: string; + amount: number; + }; + info: { + quote: number; + timestamp: number } - - // Live rates response - interface LiveRatesResponse extends BaseResponse { - base: string; - timestamp: number; - rates: { + result: number; +} + +// Timeframe response +interface TimeframeResponse extends BaseResponse { + base: string; + start_date: string; + end_date: string; + rates: { + [date: string]: { [currencyCode: string]: number; }; - } - - // Historical rates response (same structure as live rates) - interface HistoricalRatesResponse extends BaseResponse { - base: string; - timestamp: number; - rates: { - [currencyCode: string]: number; - }; - } - - // OHLC response - interface OHLCResponse extends BaseResponse { - base: string; - currency: string; - timestamp: number; - ohlc: { - open: number; - high: number; - low: number; - close: number; + }; +} + +// Change response +interface ChangeResponse extends BaseResponse { + base: string; + start_date: string; + end_date: string; + change: { + [currencyCode: string]: { + start_rate: number; + end_rate: number; + change: number; + change_pct: number; }; + }; +} + +// Usage response +interface UsageResponse extends BaseResponse { + result: { + plan: string; + used: number; + total: number; + remaining: number; } - - // Convert response - interface ConvertResponse extends BaseResponse { - base: string; - query: { - from: string; - to: string; - amount: number; - }; - info: { - quote: number; - timestamp: number - } - result: number; - } - - // Timeframe response - interface TimeframeResponse extends BaseResponse { - base: string; - start_date: string; - end_date: string; - rates: { - [date: string]: { - [currencyCode: string]: number; - }; - }; - } - - // Change response - interface ChangeResponse extends BaseResponse { - base: string; - start_date: string; - end_date: string; - change: { - [currencyCode: string]: { - start_rate: number; - end_rate: number; - change: number; - change_pct: number; - }; - }; - } - - // Usage response - interface UsageResponse extends BaseResponse { - result: { - plan: string; - used: number; - total: number; - remaining: number; - } - } - - // Date type options for OHLC endpoint - type DateType = 'recent' | 'yesterday' | 'week' | 'month' | 'year'; - - // Main module interface - interface ForexRateAPI { - /** - * Set the API key for authentication - * @param apiKey Your ForexRateAPI.com API key - */ - setAPIKey(apiKey: string): void; - - /** - * Fetch all supported currency symbols - * @returns Promise resolving to axios response with symbols data - */ - fetchSymbols(): Promise>; - - /** - * Fetch live exchange rates - * @param base Optional base currency (defaults to USD) - * @param currencies Optional array of currencies to return rates for - * @returns Promise resolving to axios response with live rates data - */ - fetchLive(base?: string, currencies?: string[]): Promise>; - - /** - * Fetch historical exchange rates for a specific date - * @param date Date in YYYY-MM-DD format - * @param base Optional base currency (defaults to USD) - * @param currencies Optional array of currencies to return rates for - * @returns Promise resolving to axios response with historical rates data - */ - fetchHistorical(date: string, base?: string, currencies?: string[]): Promise>; - - /** - * Fetch Open, High, Low, Close (OHLC) data for a currency pair - * @param base Base currency (defaults to USD) - * @param currency Target currency for OHLC data - * @param date Date in YYYY-MM-DD format - * @param dateType Optional date type that overrides the date parameter - * @returns Promise resolving to axios response with OHLC data - */ - ohlc(base?: string, currency?: string, date?: string, dateType?: DateType): Promise>; - - /** - * Convert amount from one currency to another - * @param from Source currency (defaults to USD) - * @param to Target currency - * @param amount Amount to convert - * @param date Optional date for historical conversion (YYYY-MM-DD format) - * @returns Promise resolving to axios response with conversion data - */ - convert(from?: string, to?: string, amount?: number, date?: string): Promise>; - - /** - * Get exchange rates for a specific time period - * @param startDate Start date in YYYY-MM-DD format - * @param endDate End date in YYYY-MM-DD format - * @param base Optional base currency (defaults to USD) - * @param currencies Optional array of currencies to return rates for - * @returns Promise resolving to axios response with timeframe data - */ - timeframe(startDate: string, endDate: string, base?: string, currencies?: string[]): Promise>; - - /** - * Get exchange rate changes between two dates - * @param startDate Start date in YYYY-MM-DD format - * @param endDate End date in YYYY-MM-DD format - * @param base Optional base currency (defaults to USD) - * @param currencies Optional array of currencies to return changes for - * @returns Promise resolving to axios response with change data - */ - change(startDate: string, endDate: string, base?: string, currencies?: string[]): Promise>; - - /** - * Get current API usage statistics - * @returns Promise resolving to axios response with usage data - */ - usage(): Promise>; - } - - const api: ForexRateAPI; - export = api; -} \ No newline at end of file +} + +// Date type options for OHLC endpoint +type DateType = 'recent' | 'yesterday' | 'week' | 'month' | 'year'; + +// Main module interface +interface ForexRateAPI { + /** + * Set the API key for authentication + * @param apiKey Your ForexRateAPI.com API key + */ + setAPIKey(apiKey: string): void; + + /** + * Fetch all supported currency symbols + * @returns Promise resolving to axios response with symbols data + */ + fetchSymbols(): Promise>; + + /** + * Fetch live exchange rates + * @param base Optional base currency (defaults to USD) + * @param currencies Optional array of currencies to return rates for + * @returns Promise resolving to axios response with live rates data + */ + fetchLive(base?: string, currencies?: string[]): Promise>; + + /** + * Fetch historical exchange rates for a specific date + * @param date Date in YYYY-MM-DD format + * @param base Optional base currency (defaults to USD) + * @param currencies Optional array of currencies to return rates for + * @returns Promise resolving to axios response with historical rates data + */ + fetchHistorical(date: string, base?: string, currencies?: string[]): Promise>; + + /** + * Fetch Open, High, Low, Close (OHLC) data for a currency pair + * @param base Base currency (defaults to USD) + * @param currency Target currency for OHLC data + * @param date Date in YYYY-MM-DD format + * @param dateType Optional date type that overrides the date parameter + * @returns Promise resolving to axios response with OHLC data + */ + ohlc(base?: string, currency?: string, date?: string, dateType?: DateType): Promise>; + + /** + * Convert amount from one currency to another + * @param from Source currency (defaults to USD) + * @param to Target currency + * @param amount Amount to convert + * @param date Optional date for historical conversion (YYYY-MM-DD format) + * @returns Promise resolving to axios response with conversion data + */ + convert(from?: string, to?: string, amount?: number, date?: string): Promise>; + + /** + * Get exchange rates for a specific time period + * @param startDate Start date in YYYY-MM-DD format + * @param endDate End date in YYYY-MM-DD format + * @param base Optional base currency (defaults to USD) + * @param currencies Optional array of currencies to return rates for + * @returns Promise resolving to axios response with timeframe data + */ + timeframe(startDate: string, endDate: string, base?: string, currencies?: string[]): Promise>; + + /** + * Get exchange rate changes between two dates + * @param startDate Start date in YYYY-MM-DD format + * @param endDate End date in YYYY-MM-DD format + * @param base Optional base currency (defaults to USD) + * @param currencies Optional array of currencies to return changes for + * @returns Promise resolving to axios response with change data + */ + change(startDate: string, endDate: string, base?: string, currencies?: string[]): Promise>; + + /** + * Get current API usage statistics + * @returns Promise resolving to axios response with usage data + */ + usage(): Promise>; +} + +declare const api: ForexRateAPI; +export = api; \ No newline at end of file From 21f79a17363e49a56307204f8531255020075682 Mon Sep 17 00:00:00 2001 From: Miles Zimmerman Date: Wed, 20 Aug 2025 17:08:09 -0700 Subject: [PATCH 3/4] update axios to 1.11.0 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f4fe80c..2e04e23 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "forexrateapi", + "name": "@mileszim/forexrateapi", "version": "1.1.2", "description": "Official Node.js Library for ForexRateAPI", "main": "index.js", @@ -10,7 +10,7 @@ "author": "ForexRateAPI", "license": "MIT", "dependencies": { - "axios": "^1.6.7" + "axios": "^1.11.0" }, "homepage": "https://forexrateapi.com", "repository": { From e81c8702faeadf2df7ae9baf81f7eca898e0417a Mon Sep 17 00:00:00 2001 From: Miles Zimmerman Date: Wed, 20 Aug 2025 17:09:15 -0700 Subject: [PATCH 4/4] bump version --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 2e04e23..e91df08 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@mileszim/forexrateapi", - "version": "1.1.2", + "version": "1.1.3", "description": "Official Node.js Library for ForexRateAPI", "main": "index.js", "types": "index.d.ts", @@ -15,7 +15,7 @@ "homepage": "https://forexrateapi.com", "repository": { "type": "git", - "url": "https://github.com/forexrateapi/forexrateapi-nodejs.git" + "url": "https://github.com/mileszim/forexrateapi-nodejs.git" }, "keywords": [ "foreign exchange rates",