Repository navigation
Read RESEND_API_KEY and RESEND_WEBHOOK_SECRET from component env - #165
Conversation
The component declares an optional RESEND_API_KEY env var and prefers it over the key forwarded by the client. The client's apiKey option is deprecated but keeps working as a fallback, with a warning. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
commit: |
There was a problem hiding this comment.
All reported issues were addressed across 11 files
Reply to a comment to ask cubic a question or push back. It learns from your replies.
Re-trigger cubic
The example declares RESEND_API_KEY as a required app env var, and example.ts already built a Resend SDK client from it at module load, so `npm run dev` failed on a fresh deployment before the key was set. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The client's handleResendEventWebhook now passes the raw body and svix headers to a new component mutation, handleEmailEventWebhook, which verifies the signature with the component's RESEND_WEBHOOK_SECRET env var. The client's webhookSecret option is deprecated but keeps working as a fallback, with a warning. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ianmacartney
left a comment
There was a problem hiding this comment.
Nice! Approving here, with the understanding that you'll respond to the comments I led. If anything seems controversial or you want eyes on another pass, feel free to re-request review. We generally go with a high-trust mode for reviews, where the trust is that you're personally vouching for the code, and the reviewer isn't responsible for testing everything. And we do the eager approve when any follow-on work seems straightforward & doesn't need a performative stamp.
And assume that cubic feedback is ~always worth following up on. if you don't think the bot's feedback is correct, respond to it and explain why. I think it will get smarter over time. I usually try to get to 0 outstanding cubic comments before landing
- Inline the env var hints in the component's error and warning messages. - Drop the deprecated option bullets and the migration section from the README; the migration notes now live in the changeset. - Construct the client before stubbing the env in the env-only tests, so the client has nothing to forward and the tests check the component env. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
All reported issues were addressed across 4 files (changes from recent commits).
Tip: Get a Slack DM when cubic finishes reviewing your PRs. Connect Slack
Re-trigger cubic
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
- New src/component/upgrade.test.ts covers data older versions stored: a lastOptions row and a queued callResendAPIWithBatch job that carry apiKey, with and without the component env bound. - Client tests cover the old process.env default (no option, env not bound) for both the API key and the webhook secret, and assert no deprecation warning once the component env wins. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It's backward compatible; the minor bump (0.3.0) is for removing the deprecated apiKey and webhookSecret options. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Part of API-223: move first-party component credentials to component env vars, following expo-push-notifications#89. Resend goes first so we can get feedback on the pattern before Twilio, R2, Polar, LaunchDarkly and WorkOS.
What changes
The component declares two optional env vars,
RESEND_API_KEYandRESEND_WEBHOOK_SECRET. Apps bind them inconvex/convex.config.ts:For each value, the component uses:
apiKey/webhookSecretoption, or the app'sprocess.env. It logs a deprecation warning when it does this.RESEND_API_KEY is not set/RESEND_WEBHOOK_SECRET is not set. These replace the client's "API key is not set" and "Webhook secret is not set" checks, since the client can no longer tell whether the component has a value.API key
callResendAPIWithBatchresolves the key when it sends.sendEmailfails right away if no key is available.Webhook verification moves into the component
The webhook HTTP route stays in the app. Moving the endpoint into the component is blocked on function-handle support in component env.
handleResendEventWebhookno longer verifies the signature itself. It passes the raw body and svix headers to a new component mutation,lib.handleEmailEventWebhook. That mutation verifies with svix and then runs the same logic aslib.handleEmailEvent. svix verifies with a pure-JS HMAC, so it runs inside a mutation. The secret is only a mutation arg; it isn't stored or scheduled.Compatibility
Nothing breaks on upgrade:
app.use(resend)withoutenvstill type-checks and deploys. convex 1.43.0 madeenvoptional inapp.usewhen all of a component's env vars are optional, and the existing^1.43.0peer range covers that.ResendOptions.apiKeyandResendOptions.webhookSecretare marked@deprecatedand still work as fallbacks.config.webhookSecretkeeps itsstringtype.apiKeyis now optional invOptionsand in thecallResendAPIWithBatchargs. ExistinglastOptionsrows and queued workpool jobs still validate.lib.handleEmailEventis unchanged.Until a later major version removes forwarding, the client still sends both values. The component ignores them once its env vars are set.
Out of scope:
baseUrl(API-89 / #130).Testing
src/client/index.test.ts, for both the API key and the webhook secret:process.envand forwards the value, and the component uses it with a warningsrc/component/upgrade.test.tscovers the data older versions stored, with and without the env bound:lastOptionsrow that includesapiKeycallResendAPIWithBatchjob with{ apiKey, emails }argsapiKeydropped from the validatorsnpm test(50 passing),npm run lint,npm run typecheck,npm run build._generatedfiles were regenerated withconvex codegenandconvex dev --onceagainst a local deployment.Upgrade on a real (local) deployment
main, then enqueued an email through the old code.lastOptionswithapiKey.{ apiKey, emails }args.convex.config.ts.api.resend.com. It got a 401 for the fake key, as expected.convex.config.ts./resend-webhookreturned 201.🤖 Generated with Claude Code