説明なし

kotoyuuko 8e79055e15 feat: add token authentication for /sync endpoint 3 日 前
.vscode 629dbb45c1 style: change indentation from tabs to 2 spaces 3 日 前
src 8e79055e15 feat: add token authentication for /sync endpoint 3 日 前
.dev.vars.example 8e79055e15 feat: add token authentication for /sync endpoint 3 日 前
.editorconfig 629dbb45c1 style: change indentation from tabs to 2 spaces 3 日 前
.gitignore 5e2ef53199 Initial commit (by create-cloudflare CLI) 3 日 前
.prettierrc 629dbb45c1 style: change indentation from tabs to 2 spaces 3 日 前
AGENTS.md 5e2ef53199 Initial commit (by create-cloudflare CLI) 3 日 前
CLAUDE.md 8e79055e15 feat: add token authentication for /sync endpoint 3 日 前
README.md 7dea087d80 refactor: return 418 on root endpoint instead of API guide 3 日 前
package-lock.json 5e2ef53199 Initial commit (by create-cloudflare CLI) 3 日 前
package.json 629dbb45c1 style: change indentation from tabs to 2 spaces 3 日 前
tsconfig.json 629dbb45c1 style: change indentation from tabs to 2 spaces 3 日 前
worker-configuration.d.ts 5e2ef53199 Initial commit (by create-cloudflare CLI) 3 日 前
wrangler.jsonc 629dbb45c1 style: change indentation from tabs to 2 spaces 3 日 前

README.md

Notion Exchange Rate Worker

A Cloudflare Workers Scheduled Worker that automatically fetches exchange rates from Open Exchange Rates API and updates a Notion database.

Features

  • 🔄 Hourly automatic sync via Cron trigger
  • 🔌 Manual sync via HTTP endpoint
  • 💱 Supports 170+ currencies
  • 🧮 Currency conversion API
  • ⚡ Fast and serverless

Setup

Prerequisites

Notion Setup

Create a Notion database with the following properties:

Property Type
Code Title
Rate Number
Updated At Date

Then:

  1. Create a Notion Integration at https://www.notion.so/my-integrations
  2. Share your database with the integration

Installation

# Clone the repository
git clone git@ssh.git.ac:kotoyuuko/notion-exrate-worker.git
cd notion-exrate-worker

# Install dependencies
npm install

Configuration

  1. Copy the example environment file:

    cp .dev.vars.example .dev.vars
    
  2. Fill in your credentials in .dev.vars:

    OXR_APP_ID=your_open_exchange_rates_app_id
    NOTION_TOKEN=your_notion_integration_token
    NOTION_DATABASE_ID=your_notion_database_id
    

Local Development

# Start development server
npm run dev

# Test scheduled handler
curl "http://localhost:8787/__scheduled?cron=0+*+*+*+*"

# Or use manual sync endpoint
curl "http://localhost:8787/sync"

Deploy

# Deploy to Cloudflare Workers
npm run deploy

# Set production secrets
wrangler secret put OXR_APP_ID
wrangler secret put NOTION_TOKEN
wrangler secret put NOTION_DATABASE_ID

API Reference

Endpoints

Endpoint Method Description
/convert GET Convert currency
/sync GET Sync rates to Notion

Convert Currency

GET /convert?from=USD&to=CNY&amount=100

Parameters:

  • from - Source currency code (e.g., USD, EUR, JPY)
  • to - Target currency code
  • amount - Amount to convert

Response:

{
  "success": true,
  "from": "USD",
  "to": "CNY",
  "amount": 100,
  "rate": 6.9002,
  "result": 690.02,
  "timestamp": 1773900000000
}

Manual Sync to Notion

GET /sync

Response:

{
  "success": true,
  "currenciesFound": 173,
  "ratesFetched": 172,
  "succeeded": 172,
  "failed": 0,
  "errors": []
}

Tech Stack

License

MIT