|
@@ -4,7 +4,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
|
|
|
|
|
|
|
|
## Project Overview
|
|
## Project Overview
|
|
|
|
|
|
|
|
-A Cloudflare Workers **Scheduled Worker** that fetches exchange rates from Open Exchange Rates API and updates a Notion database hourly.
|
|
|
|
|
|
|
+A Cloudflare Workers **Scheduled Worker** that fetches exchange rates from Open Exchange Rates API and updates a Notion database hourly. Also provides a currency conversion API.
|
|
|
|
|
|
|
|
## Commands
|
|
## Commands
|
|
|
|
|
|
|
@@ -16,14 +16,16 @@ npm run cf-typegen # Regenerate TypeScript types after changing bindings
|
|
|
|
|
|
|
|
### Testing Locally
|
|
### Testing Locally
|
|
|
|
|
|
|
|
-After `npm run dev`, test the cron handler:
|
|
|
|
|
|
|
+After `npm run dev`:
|
|
|
```bash
|
|
```bash
|
|
|
|
|
+# Test scheduled handler
|
|
|
curl "http://localhost:8787/__scheduled?cron=0+*+*+*+*"
|
|
curl "http://localhost:8787/__scheduled?cron=0+*+*+*+*"
|
|
|
-```
|
|
|
|
|
|
|
|
|
|
-Or use the manual sync endpoint:
|
|
|
|
|
-```bash
|
|
|
|
|
|
|
+# Manual sync
|
|
|
curl "http://localhost:8787/sync"
|
|
curl "http://localhost:8787/sync"
|
|
|
|
|
+
|
|
|
|
|
+# Currency conversion
|
|
|
|
|
+curl "http://localhost:8787/convert?from=USD&to=CNY&amount=100"
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
## Architecture
|
|
## Architecture
|
|
@@ -40,7 +42,8 @@ Hourly at minute 0 (`0 * * * *`).
|
|
|
|
|
|
|
|
| Endpoint | Description |
|
|
| Endpoint | Description |
|
|
|
|----------|-------------|
|
|
|----------|-------------|
|
|
|
-| `/sync` | Manually trigger exchange rate sync (returns JSON result) |
|
|
|
|
|
|
|
+| `/convert?from=USD&to=CNY&amount=100` | Convert currency (data from Notion database) |
|
|
|
|
|
+| `/sync` | Manually trigger exchange rate sync from OXR to Notion |
|
|
|
| `/` | Info page |
|
|
| `/` | Info page |
|
|
|
|
|
|
|
|
### Environment Variables (Secrets)
|
|
### Environment Variables (Secrets)
|
|
@@ -61,6 +64,11 @@ Set via `wrangler secret put <NAME>` or `.dev.vars` for local development:
|
|
|
| `Rate` | Number | Exchange rate against USD |
|
|
| `Rate` | Number | Exchange rate against USD |
|
|
|
| `Updated At` | Date | Last update timestamp |
|
|
| `Updated At` | Date | Last update timestamp |
|
|
|
|
|
|
|
|
|
|
+### Data Flow
|
|
|
|
|
+
|
|
|
|
|
+1. **Sync** (hourly or manual): Fetch rates from OXR API → Update Notion database
|
|
|
|
|
+2. **Convert**: Read rates from Notion database → Calculate conversion
|
|
|
|
|
+
|
|
|
## Node.js Compatibility
|
|
## Node.js Compatibility
|
|
|
|
|
|
|
|
The `nodejs_compat` flag is enabled, allowing use of Node.js runtime APIs in the worker.
|
|
The `nodejs_compat` flag is enabled, allowing use of Node.js runtime APIs in the worker.
|