Test
Merged
SW
4mo ago+703+703+012345678901234567890123456789-74-74-01234567890123456789
Summary by cubic
Adds POST /api/emails to send account‑scoped emails and unifies auth so recoup_sk_ keys work via Authorization: Bearer and x-api-key, with recipient limits unless a payment method is on file.
-
New Features
POST /api/emails: send via Resend from “Agent by Recoup agent@recoupable.com”.- Validates body (
to, optionalcc,subject,text/html,headers,chat_id). - Enforces recipient gate: without a card on file,
to/ccmust be the account’s own email (403 otherwise). - CORS preflight (
OPTIONS) and no-cache response.
-
Refactors
- Auth:
getAuthenticatedAccountIdacceptsrecoup_sk_via Bearer;getApiKeyAccountIddelegates to sharedgetAccountIdByApiKey(includesexpires_atTTL check). - Stripe: new
accountHasPaymentMethodhelper; reused in Songstats gate. - Agent env: tests ensure the access token (JWT or
recoup_sk_) surfaces asRECOUP_ACCESS_TOKEN.
- Auth:
Summary by CodeRabbit
- New Features
- Added a new email-sending endpoint with support for request validation and reliable success/error responses.
- Improved API access handling so valid API keys can be used for authenticated requests.
- Bug Fixes
- Tightened email recipient checks to prevent sending to unauthorized addresses when no payment method is on file.
- Improved handling of different token types for authenticated requests.
- Chores
- Updated developer-facing documentation for credential handling.