# CLAUDE.md This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. ## Project Overview A Cloudflare Workers **Scheduled Worker** that fetches exchange rates from Open Exchange Rates API and updates a Notion database hourly. ## Commands ```bash npm run dev # Start local dev server with scheduled trigger testing npm run deploy # Deploy to Cloudflare Workers npm run cf-typegen # Regenerate TypeScript types after changing bindings ``` ### Testing Locally After `npm run dev`, test the cron handler: ```bash curl "http://localhost:8787/__scheduled?cron=0+*+*+*+*" ``` Or use the manual sync endpoint: ```bash curl "http://localhost:8787/sync" ``` ## Architecture - **Entry Point**: `src/index.ts` - exports an `ExportedHandler` with `fetch` and `scheduled` handlers - **Configuration**: `wrangler.jsonc` - defines cron triggers and compatibility flags - **TypeScript**: ES2024 target, strict mode, types in `worker-configuration.d.ts` and `src/env.d.ts` ### Cron Schedule Hourly at minute 0 (`0 * * * *`). ### API Endpoints | Endpoint | Description | |----------|-------------| | `/sync` | Manually trigger exchange rate sync (returns JSON result) | | `/` | Info page | ### Environment Variables (Secrets) Set via `wrangler secret put ` or `.dev.vars` for local development: | Variable | Description | |----------|-------------| | `OXR_APP_ID` | Open Exchange Rates API App ID | | `NOTION_TOKEN` | Notion Integration Token | | `NOTION_DATABASE_ID` | Notion Database ID | ### Notion Database Structure | Property | Type | Description | |----------|------|-------------| | `Code` | Title | Currency code (e.g., USD, EUR, CNY) | | `Rate` | Number | Exchange rate against USD | | `Updated At` | Date | Last update timestamp | ## Node.js Compatibility The `nodejs_compat` flag is enabled, allowing use of Node.js runtime APIs in the worker. ## Reference See `AGENTS.md` for Cloudflare Workers documentation links and error handling guidance.