Remove multi-recipient support from Plunk driver

This commit is contained in:
cameronapak
2025-11-11 08:30:26 -06:00
parent e2ebb57564
commit 2885fea077
2 changed files with 3 additions and 64 deletions

View File

@@ -7,7 +7,6 @@ export type PlunkEmailOptions = {
};
export type PlunkEmailSendOptions = {
to?: string | string[];
subscribed?: boolean;
name?: string;
from?: string;
@@ -40,48 +39,25 @@ export const plunkEmail = (
body: string | { text: string; html: string },
options?: PlunkEmailSendOptions,
) => {
// Determine recipients - options.to takes precedence if provided
const recipients = options?.to ?? to;
// Validate recipient count (Plunk max is 5)
const recipientArray = Array.isArray(recipients)
? recipients
: [recipients];
if (recipientArray.length > 5) {
throw new Error(
"Plunk supports a maximum of 5 recipients per email",
);
}
// Build base payload
const payload: any = {
to: recipients,
from,
to,
subject,
};
// Handle body - Plunk only accepts a single body field
if (typeof body === "string") {
payload.body = body;
} else {
// When both text and html are provided, send html (degrades gracefully)
payload.body = body.html;
}
// Add optional fields from config
if (from) {
payload.from = from;
}
// Merge with additional options (excluding 'to' since we already handled it)
const { to: _, ...restOptions } = options ?? {};
const res = await fetch(host, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${config.apiKey}`,
},
body: JSON.stringify({ ...payload, ...restOptions }),
body: JSON.stringify({ ...payload, ...options }),
});
if (!res.ok) {