Repository navigation
Conversation
There was a problem hiding this comment.
All reported issues were addressed across 6 files
Reply to a comment to ask cubic a question or push back. It learns from your replies.
Re-trigger cubic
commit: |
|
We've been moving the component's config to component env vars (#165), so we took your change in that direction in #168: an optional For your emulator setup, declare and bind it in const app = defineApp({
env: {
RESEND_API_KEY: v.string(),
RESEND_BASE_URL: v.optional(v.string()),
},
});
app.use(resend, {
env: {
RESEND_API_KEY: app.env.RESEND_API_KEY,
RESEND_BASE_URL: app.env.RESEND_BASE_URL,
},
});Then set |
* Add optional RESEND_BASE_URL component env var Lets the component send batches to a Resend-compatible API, such as a local emulator in end-to-end tests, instead of https://api.resend.com. Based on #130, which added a baseUrl client option; this reads it from component env instead, so the app opts in by binding it in convex.config.ts. Trailing slashes are stripped. Co-authored-by: heracek <tomas.horacek@gmail.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Show the app env declaration in the RESEND_BASE_URL changeset Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Format the RESEND_BASE_URL changeset Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Will Stockwell <will@Wills-MacBook-Pro.local> Co-authored-by: heracek <tomas.horacek@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* Add optional RESEND_BASE_URL component env var Lets the component send batches to a Resend-compatible API, such as a local emulator in end-to-end tests, instead of https://api.resend.com. Based on #130, which added a baseUrl client option; this reads it from component env instead, so the app opts in by binding it in convex.config.ts. Trailing slashes are stripped. Co-authored-by: heracek <tomas.horacek@gmail.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Show the app env declaration in the RESEND_BASE_URL changeset Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Format the RESEND_BASE_URL changeset Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Declare RESEND_WEBHOOK_SECRET optional in the README Deployments that don't receive webhooks shouldn't need the secret to deploy. Matches the example app and the changeset. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Bind RESEND_BASE_URL in the example app config Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Add PR numbers to the changesets Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Note that RESEND_BASE_URL should omit the trailing slash Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Revert "Note that RESEND_BASE_URL should omit the trailing slash" The component supports a trailing slash. The resend SDK is the app's own client, outside what this component controls. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Drop the resend SDK note from the RESEND_BASE_URL docs Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Document that the resend SDK also reads RESEND_BASE_URL The component strips a trailing slash, but the SDK appends paths to the value as is, so manual sends need it without one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Regenerate example code for RESEND_BASE_URL Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Will Stockwell <will@Wills-MacBook-Pro.local> Co-authored-by: heracek <tomas.horacek@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
|
Closing as #169 implemented this in a better way. Thanks! |
Summary
Adds an optional
baseUrltoResendOptions, so queued batches can go to a Resend-compatible API other thanhttps://api.resend.com. Unset, nothing changes.new Resend(components.resend, { apiKey, baseUrl }) sendEmail # options stored in lastOptions, baseUrl included makeBatch callResendAPIWithBatch({ apiKey, baseUrl, emails }) - fetch("https://api.resend.com/emails/batch") + fetch(`${baseUrl?.replace(/\/+$/, "") ?? "https://api.resend.com"}/emails/batch`)baseUrlfollowsapiKeyeverywhere:vOptions, themakeBatch→callResendAPIWithBatchworkpool args, and the generatedComponentApi. Docstring and README list it.Why
We run browser end-to-end tests against a disposable local stack: a Convex local backend on loopback, our functions deployed to it, and
@emulators/resend(on@emulators/core) as a fake Resend HTTP server. The tests read sign-up OTPs and notification emails from the emulator'sGET /emails. Nothing leaves the machine, and CI needs no Resend credentials.Both of our send paths have to reach the emulator:
sendEmailManually: covered already, since theresendSDK has a publicbaseUrloption.sendEmail(queued batches): the component hard-codeshttps://api.resend.com/emails/batch. Because it ships bundled fromdist/, an app can't redirect it. There's no bundler alias hook. Mounting the component conditionally breaks the committed_generatedtypes. A MITM proxy or/etc/hostschange is far heavier than this option.So we've carried this as a
pnpm patchagainstdist/since 0.2.8 and re-rolled it on every release. This PR is that patch, moved intosrc/.Design choices
resendSDK falls back toRESEND_BASE_URL. This option deliberately doesn't, so a stray environment variable can't silently send production mail somewhere else. The app decides where mail goes. We, for example, accept only a loopback emulator URL, and only on a loopback Convex backend. Easy to add a fallback if you'd prefer parity with the SDK.baseUrllives inlastOptionsand in the workpool action's args, likeapiKey, so retries use the destination that was current when the batch was made.http://127.0.0.1:4100/andhttp://127.0.0.1:4100behave the same; otherwise the request goes to//emails/batch, which@emulators/resendanswers with 404.I left
CHANGELOG.mdalone since versions look maintainer-managed. Happy to add an entry.Evidence
New test in
src/client/index.test.ts,sends batches to the configured baseUrl %s, run with and without a trailing slash:main'ssrc/): the option is silently dropped.npm run build,typecheck,lintandtest(35/35) are green. The existing test still asserts the defaulthttps://api.resend.com/emails/batch.@emulators/resend.src/component/_generated/component.tswas edited by hand:convex codegen --component-dirneeds a deployment. The edit is a singlebaseUrl?: string;line, in codegen's alphabetical order.Merge Danger
Door: two-way
Opt-in and additive. Existing
lastOptionsrows and queued workpool jobs have nobaseUrland keep usinghttps://api.resend.com. One caveat: if a deployment has stored abaseUrland then downgrades the component, itslastOptionsrow no longer matches the old schema until it's rewritten.Blast Radius: opt-in
Only apps that pass
baseUrlsee different behaviour. The public type gains one optional field.