Notification

Resend

Email notification provider powered by Resend.

Email notification provider for CommerceJS, powered by Resend.

Installation

pnpm add @commercejs/notification-resend resend

Quick Start

import { createCommerce } from '@commercejs/core'
import { createResendProvider } from '@commercejs/notification-resend'

const resend = createResendProvider({
  apiKey: 're_...',
  from: 'My Store <noreply@mystore.com>',
  replyTo: 'support@mystore.com', // optional
})

const commerce = createCommerce({
  adapter,
  notifications: { resend },
  notificationRules: [
    {
      event: 'order.created',
      channel: 'email',
      provider: 'resend',
      template: 'order_confirmation',
      buildMessage: (payload) => ({
        to: payload.order.customer.email,
        subject: `Order #${payload.order.id} confirmed`,
        data: { order: payload.order },
      }),
    },
  ],
})

Configuration

OptionTypeRequiredDescription
apiKeystringResend API key
fromstringDefault sender (e.g. "Store <noreply@example.com>")
replyTostringReply-to address for all emails
clientResendCustom Resend client instance (overrides apiKey)

Supported Channels

ChannelSupported
email
sms
push_web
push_mobile
whatsapp
telegram

How It Works

  1. Register the provider in createCommerce() under notifications
  2. Define notification rules that map commerce events to email deliveries
  3. When an event fires (e.g. order.created), the rule's buildMessage() builds the email
  4. The provider sends via Resend's API and returns { success, messageId } or { success: false, error }

Templates

Pass a template field in your notification rule to use Resend template IDs. The template ID is sent as a custom X-Template-Id header.

Error Handling

The provider never throws — all errors are caught and returned as { success: false, error: string }:

  • Invalid channel → immediately rejected
  • Missing recipient → immediately rejected
  • Resend API error → error message from Resend
  • Network error → exception message