@avelon/resend
@avelon/resend is the Resend mail driver for Avelon. It sends transport-neutral MailMessage values over HTTP and maps malformed recipients to Invalid. Reach for this package when you want transactional mail without importing the Resend SDK in application code.
Installation
bun add @avelon/resend
export RESEND_API_KEY=re_your_key
export RESEND_FROM=mailer@example.test
Basic Usage
import { createResendMail } from '@avelon/resend'
const mail = createResendMail()
await mail.send({
to: 'reader@example.test',
subject: 'Welcome',
text: 'Your account is ready.',
html: '<p>Your account is ready.</p>',
})
Capabilities
| Capability | Value | Notes |
|---|---|---|
templates | true | sendTemplate() posts a hosted template id and variables |
Hosted Templates
import { createResendMail } from '@avelon/resend'
const mail = createResendMail()
await mail.sendTemplate('welcome-message', ['reader@example.test'], { actorName: 'Morgan' })
Method Reference
| Method | Signature | Description | |
|---|---|---|---|
createResendMail | (options?: ResendMailOptions) => ResendMail | Constructs a Resend HTTP mail driver. | |
resendMailCapabilities | { templates: true } | Exact capability declaration for the Resend driver. | |
ResendMailOptions | interface | API key, endpoint, instance, and default sender. | |
ResendMail.send | (message: MailMessage) => Promise<MailReceipt> | Sends one transactional message. | |
ResendMail.sendTemplate | `(template: string, to: string \ | readonly string[], variables: Readonly<Record<string, unknown>>) => Promise<MailReceipt>` | Sends a hosted template. |
ResendMail.raw | () => { endpoint: string } | Returns the API root at the vendor boundary. | |
ResendMail.sent | readonly MailMessage[] | Copies of messages this driver accepted. | |
ResendMail.reset | () => void | Clears recorded messages between tests. | |
LocalResendServer.start | () => Promise<string> | Starts a Resend-shaped HTTP fixture. | |
LocalResendServer.reset | () => void | Clears accepted fixture messages. | |
LocalResendServer.stop | () => Promise<void> | Stops the fixture listener. | |
LocalResendServer.url | string | Base API URL after start(). | |
LocalResendServer.sent | readonly MailMessage[] | Messages the fixture accepted, in send order. |
Testing
Run the shared mail conformance suite against LocalResendServer when RESEND_API_KEY is absent. Live Resend verification requires a real API key and is fail-closed in this environment.
import { mailSuite } from '@avelon/conformance/suites'
import { createResendMail, LocalResendServer } from '@avelon/resend'
const server = new LocalResendServer()
const endpoint = await server.start()
mailSuite({
name: 'resend local fixture',
create: () => createResendMail({ endpoint, defaultFrom: 'mailer@example.test' }),
})