feat: add Chartmetric proxy endpoint with credit deduction
SW
8mo ago+349+349+012345678901234567890123456789-0-0-0123456789
Summary
- Adds
GET/POST /api/chartmetric/[...path]proxy that forwards requests to Chartmetric - Authenticates callers via
validateAuthContext(API key or Bearer token) - Deducts 5 credits per call via
deductCredits - Exchanges server-side
CHARTMETRIC_REFRESH_TOKENfor short-lived access token (key never exposed to clients) - Adds
lib/chartmetric/getChartmetricToken.tsandlib/chartmetric/proxyChartmetricRequest.ts - 5 vitest tests covering 401, 402, 500, GET proxy, and POST proxy paths
Test plan
-
pnpm test lib/chartmetric— all 5 tests pass -
CHARTMETRIC_REFRESH_TOKENenv var set in Vercel/production - Proxy call deducts 5 credits from caller account
🤖 Generated with Claude Code
Summary by CodeRabbit
- New Features
- Added a new API endpoint that forwards requests to an external service with dynamic (no-cache) behavior
- Implements per-request credit deduction to enforce usage limits
- Performs secure server-side token retrieval for upstream authentication
- Returns CORS-compatible proxied responses with robust error handling and status propagation