Skip to content

Commit ab8c881

Browse files
committed
Merge branch 'master' of github.com:profullstack/generate-pdf-api
2 parents c3495cb + 2f140c7 commit ab8c881

11 files changed

+1481
-11
lines changed

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ PORT=3000
44
# API configuration
55
API_BASE_URL=https://profullstack.com/pdf
66

7+
# Tatum API configuration
8+
TATUM_API_KEY=your-tatum-api-key
9+
710
# Puppeteer configuration
811
# If not set, the application will try to auto-detect the Chrome path based on the environment
912
# Production path example:

README-exchange-rates.md

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
# Exchange Rates API
2+
3+
This document describes the exchange rate endpoints that provide crypto/fiat currency exchange rates using the Tatum API.
4+
5+
## Endpoints
6+
7+
### GET /api/exchange-rates/:crypto/:fiat
8+
9+
Get a single exchange rate for a specific crypto/fiat pair.
10+
11+
**Parameters:**
12+
- `crypto` (string): Cryptocurrency symbol (e.g., BTC, ETH, ADA)
13+
- `fiat` (string): Fiat currency symbol (e.g., USD, EUR, GBP)
14+
15+
**Example Request:**
16+
```bash
17+
GET /api/exchange-rates/BTC/USD
18+
```
19+
20+
**Example Response:**
21+
```json
22+
{
23+
"crypto": "BTC",
24+
"fiat": "USD",
25+
"rate": 88375.98,
26+
"timestamp": "2025-01-01T00:00:00.000Z"
27+
}
28+
```
29+
30+
### POST /api/exchange-rates
31+
32+
Get multiple exchange rates for an array of crypto/fiat pairs.
33+
34+
**Request Body:**
35+
```json
36+
{
37+
"pairs": [
38+
{ "crypto": "BTC", "fiat": "USD" },
39+
{ "crypto": "ETH", "fiat": "EUR" },
40+
{ "crypto": "ADA", "fiat": "GBP" }
41+
]
42+
}
43+
```
44+
45+
**Example Response:**
46+
```json
47+
{
48+
"rates": [
49+
{
50+
"crypto": "BTC",
51+
"fiat": "USD",
52+
"rate": 88375.98,
53+
"timestamp": "2025-01-01T00:00:00.000Z"
54+
},
55+
{
56+
"crypto": "ETH",
57+
"fiat": "EUR",
58+
"rate": 3245.67,
59+
"timestamp": "2025-01-01T00:00:00.000Z"
60+
},
61+
{
62+
"crypto": "ADA",
63+
"fiat": "GBP",
64+
"rate": 0.85,
65+
"timestamp": "2025-01-01T00:00:00.000Z"
66+
}
67+
],
68+
"timestamp": "2025-01-01T00:00:00.000Z"
69+
}
70+
```
71+
72+
**Constraints:**
73+
- Maximum 10 currency pairs per batch request
74+
- At least 1 currency pair is required
75+
76+
### GET /api/exchange-rates/supported
77+
78+
Get lists of supported cryptocurrencies and fiat currencies.
79+
80+
**Example Response:**
81+
```json
82+
{
83+
"cryptos": [
84+
"BTC", "ETH", "ADA", "DOT", "LTC", "XRP", "BCH", "EOS", "TRX", "XLM",
85+
"LINK", "UNI", "AAVE", "COMP", "MKR", "SNX", "YFI", "SUSHI", "CRV",
86+
"BAL", "MATIC", "AVAX", "SOL", "LUNA", "FTT", "SRM", "RAY"
87+
],
88+
"fiats": [
89+
"USD", "EUR", "GBP", "JPY", "AUD", "CAD", "CHF", "CNY", "SEK", "NZD",
90+
"MXN", "SGD", "HKD", "NOK", "TRY", "ZAR", "BRL", "INR", "KRW", "PLN",
91+
"CZK", "HUF", "RON", "BGN", "HRK", "RUB", "UAH", "AED", "SAR"
92+
]
93+
}
94+
```
95+
96+
## Error Handling
97+
98+
All endpoints return appropriate HTTP status codes and error messages:
99+
100+
### 400 Bad Request
101+
- Missing required parameters
102+
- Invalid currency symbols
103+
- Empty pairs array
104+
- Too many pairs (>10)
105+
106+
**Example Error Response:**
107+
```json
108+
{
109+
"error": "Invalid parameters",
110+
"message": "Invalid crypto symbol: must be a non-empty string"
111+
}
112+
```
113+
114+
### 500 Internal Server Error
115+
- Tatum API errors
116+
- Network connectivity issues
117+
- Server-side processing errors
118+
119+
**Example Error Response:**
120+
```json
121+
{
122+
"error": "Failed to fetch exchange rate",
123+
"message": "Tatum API error: 404 Not Found"
124+
}
125+
```
126+
127+
## Environment Variables
128+
129+
Make sure to set the following environment variable:
130+
131+
```bash
132+
TATUM_API_KEY=your_tatum_api_key_here
133+
```
134+
135+
## Testing
136+
137+
To test the exchange rate endpoints, you can use the provided test script:
138+
139+
```bash
140+
# Start the server first
141+
pnpm dev
142+
143+
# In another terminal, run the exchange rate tests
144+
node test-exchange-rates.js
145+
```
146+
147+
## Implementation Details
148+
149+
- **Service Layer**: [`src/services/exchange-rate-service.js`](src/services/exchange-rate-service.js)
150+
- **Routes**: [`src/routes/exchange-rates.js`](src/routes/exchange-rates.js)
151+
- **Tatum Integration**: [`src/utils/tatum.js`](src/utils/tatum.js)
152+
153+
The implementation follows the existing project patterns:
154+
- Clean separation of concerns
155+
- Comprehensive error handling
156+
- Input validation
157+
- Consistent API response format
158+
- ESM module structure

TODO-exchange-rates.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Exchange Rates API Implementation
2+
3+
## Requirements
4+
- Create GET endpoint for retrieving crypto/fiat exchange rates
5+
- Create POST endpoint for retrieving multiple exchange rates or with custom parameters
6+
- Use existing Tatum API integration
7+
- Follow project patterns for routes, services, and error handling
8+
- Implement comprehensive test coverage
9+
10+
## Tasks
11+
12+
### 1. Create Exchange Rate Service
13+
- [x] Create `src/services/exchange-rate-service.js`
14+
- [x] Implement functions for single and batch rate retrieval
15+
- [x] Add proper error handling and validation
16+
- [x] Write comprehensive tests
17+
18+
### 2. Create Exchange Rate Routes
19+
- [x] Create `src/routes/exchange-rates.js`
20+
- [x] Implement GET `/api/exchange-rates/:crypto/:fiat` endpoint
21+
- [x] Implement POST `/api/exchange-rates` endpoint for batch requests
22+
- [x] Add input validation middleware
23+
- [x] Write route tests
24+
25+
### 3. Integration
26+
- [x] Add routes to main routes index
27+
- [x] Update environment variables if needed
28+
- [x] Test endpoints manually
29+
- [x] Document API endpoints
30+
31+
## API Design
32+
33+
### GET /api/exchange-rates/:crypto/:fiat
34+
- Returns single exchange rate
35+
- Example: GET /api/exchange-rates/BTC/USD
36+
- Response: `{ "crypto": "BTC", "fiat": "USD", "rate": 88375.98, "timestamp": "..." }`
37+
38+
### POST /api/exchange-rates
39+
- Accepts array of crypto/fiat pairs
40+
- Request body: `{ "pairs": [{"crypto": "BTC", "fiat": "USD"}, {"crypto": "ETH", "fiat": "EUR"}] }`
41+
- Response: `{ "rates": [...], "timestamp": "..." }`

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@
4949
"xlsx": "^0.18.5"
5050
},
5151
"devDependencies": {
52-
"nodemon": "^3.1.0"
52+
"chai": "^5.2.0",
53+
"mocha": "^11.7.0",
54+
"nodemon": "^3.1.0",
55+
"sinon": "^21.0.0"
5356
},
5457
"optionalDependencies": {
5558
"bufferutil": "^4.0.9"

0 commit comments

Comments
 (0)