Version 3 of the kit: - Radix UI replaced with Base UI (using the Shadcn UI patterns) - next-intl replaces react-i18next - enhanceAction deprecated; usage moved to next-safe-action - main layout now wrapped with [locale] path segment - Teams only mode - Layout updates - Zod v4 - Next.js 16.2 - Typescript 6 - All other dependencies updated - Removed deprecated Edge CSRF - Dynamic Github Action runner
52 lines
1.1 KiB
TypeScript
52 lines
1.1 KiB
TypeScript
import 'server-only';
|
|
import * as z from 'zod';
|
|
|
|
import { Mailer, MailerSchema } from '@kit/mailers-shared';
|
|
|
|
type Config = z.output<typeof MailerSchema>;
|
|
|
|
const RESEND_API_KEY = z
|
|
.string({
|
|
error: 'Please provide the API key for the Resend API',
|
|
})
|
|
.parse(process.env.RESEND_API_KEY);
|
|
|
|
export function createResendMailer() {
|
|
return new ResendMailer();
|
|
}
|
|
|
|
/**
|
|
* A class representing a mailer using the Resend HTTP API.
|
|
* @implements {Mailer}
|
|
*/
|
|
class ResendMailer implements Mailer {
|
|
async sendEmail(config: Config) {
|
|
const contentObject =
|
|
'text' in config
|
|
? {
|
|
text: config.text,
|
|
}
|
|
: {
|
|
html: config.html,
|
|
};
|
|
|
|
const res = await fetch('https://api.resend.com/emails', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Authorization: `Bearer ${RESEND_API_KEY}`,
|
|
},
|
|
body: JSON.stringify({
|
|
from: config.from,
|
|
to: [config.to],
|
|
subject: config.subject,
|
|
...contentObject,
|
|
}),
|
|
});
|
|
|
|
if (!res.ok) {
|
|
throw new Error(`Failed to send email: ${res.statusText}`);
|
|
}
|
|
}
|
|
}
|