Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 | 21x 28x 28x 4x 4x 1x 1x 1x 1x 1x 1x 3x 3x 2x 2x 2x 2x 2x 2x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 3x 3x 3x 1x 56x 56x 4x 4x 3x 3x 3x 3x 5x 1x 1x 4x 8x 8x 8x 8x 4x 2x 2x 2x 4x 4x 3x 3x 3x 3x 3x 3x 5x 1x 1x 4x 8x 8x 8x 8x 4x 2x 2x 2x 4x 4x 3x 3x 6x 1x 1x 5x 6x 9x 9x 9x 9x 5x 2x 2x 2x 5x 5x 6x 1x 1x 5x 6x 9x 9x 9x 9x 5x 2x 2x 2x 5x 5x 2x 2x 1x 1x 3x 3x 3x 1x | import { render } from "@react-email/render";
import { PasswordResetEmail } from "../emails/password-reset";
import { EmailVerificationEmail } from "../emails/email-verification";
import { WelcomeEmail } from "../emails/welcome";
import {
NewInquiryEmail,
type NewInquiryEmailProps,
} from "../emails/new-inquiry";
import {
TeamInvitationEmail,
type TeamInvitationEmailProps,
} from "../emails/team-invitation";
import {
BlogApprovalRequestEmail,
type BlogApprovalRequestEmailProps,
} from "../emails/blog-approval-request";
import {
BlogApprovalReminderEmail,
type BlogApprovalReminderEmailProps,
} from "../emails/blog-approval-reminder";
import {
BlogPublishedEmail,
type BlogPublishedEmailProps,
} from "../emails/blog-published";
import {
EmailVerifiedEmail,
type EmailVerifiedProps,
} from "../emails/email-verified";
import {
ProAccountStatusEmail,
type ProAccountStatusProps,
} from "../emails/pro-account-status";
import {
WebsiteBuildResultEmail,
type WebsiteBuildResultProps,
} from "../emails/website-build-result";
import {
ReminderDueEmail,
type ReminderDueEmailProps,
} from "../emails/reminder-due";
import { MagicLinkEmail } from "../emails/magic-link";
import { createEmailProvider } from "./email/email-provider.factory";
export type EmailService = ReturnType<typeof createEmailService>;
export type RenderedEmailMessage = {
subject: string;
html: string;
};
function escapeHtml(str: string): string {
return str
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """);
}
export async function renderEmailTemplate(params: {
template: string;
props: Record<string, unknown>;
recipientName?: string;
}): Promise<RenderedEmailMessage> {
const { template, props, recipientName } = params;
switch (template) {
case "new-inquiry": {
const html = await render(
NewInquiryEmail({
...(props as Omit<NewInquiryEmailProps, "proName" | "portalUrl">),
proName: recipientName ?? "",
}),
);
return {
subject: `New inquiry from ${escapeHtml(String(props.customerName ?? ""))}`,
html,
};
}
case "password-reset": {
const html = await render(
PasswordResetEmail({
resetLink: props.resetLink as string,
userName: props.userName as string | undefined,
}),
);
return { subject: "Reset your Interioring password", html };
}
case "email-verification": {
const html = await render(
EmailVerificationEmail({
verificationLink: props.verificationLink as string,
userName: props.userName as string | undefined,
}),
);
return { subject: "Verify your Interioring email", html };
}
case "welcome": {
const html = await render(
WelcomeEmail({
userName: props.userName as string,
loginUrl: props.loginUrl as string | undefined,
}),
);
return { subject: "Welcome to Interioring!", html };
}
case "team-invitation": {
const html = await render(TeamInvitationEmail(props as TeamInvitationEmailProps));
return {
subject: `You've been invited to join ${escapeHtml(String(props.proName ?? ""))} on Interioring`,
html,
};
}
case "blog-approval-request": {
const html = await render(
BlogApprovalRequestEmail(props as BlogApprovalRequestEmailProps),
);
return {
subject: `Review Required: ${String(props.blogTitle ?? "")}`,
html,
};
}
case "blog-approval-reminder": {
const html = await render(
BlogApprovalReminderEmail(props as BlogApprovalReminderEmailProps),
);
return {
subject: `Reminder: Blog approval needed - ${String(props.blogTitle ?? "")}`,
html,
};
}
case "blog-published": {
const html = await render(
BlogPublishedEmail({
...(props as Omit<BlogPublishedEmailProps, "proName">),
proName: recipientName ?? "",
}),
);
return {
subject: `Your blog is live: ${String(props.blogTitle ?? "")}`,
html,
};
}
case "email-verified": {
const html = await render(EmailVerifiedEmail(props as EmailVerifiedProps));
return { subject: "Email Verified — You're In!", html };
}
case "pro-account-status": {
const typedProps = props as Omit<ProAccountStatusProps, "proName"> & {
status: ProAccountStatusProps["status"];
};
const html = await render(
ProAccountStatusEmail({
...typedProps,
proName: recipientName ?? "",
}),
);
const subject =
typedProps.status === "published"
? `${typedProps.businessName} is now live on Interioring!`
: "Your Interioring account has been archived";
return { subject, html };
}
case "website-build-result": {
const typedProps = props as Omit<WebsiteBuildResultProps, "proName">;
const html = await render(
WebsiteBuildResultEmail({
...typedProps,
proName: recipientName ?? "",
}),
);
const subject = typedProps.success
? `Your website for ${typedProps.businessName} is live!`
: `Website build failed for ${typedProps.businessName}`;
return { subject, html };
}
case "reminder-due": {
const html = await render(ReminderDueEmail(props as ReminderDueEmailProps));
return {
subject: `Reminder due: ${String(props.reminderTitle ?? "")}`,
html,
};
}
case "magic-link": {
const html = await render(
MagicLinkEmail(props as { magicLinkUrl: string }),
);
return { subject: "Sign in to Interioring", html };
}
case "email-otp": {
const greeting = props.userName
? `Hi ${escapeHtml(String(props.userName))},`
: "Hi,";
const html = `
<div style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; max-width: 480px; margin: 0 auto; padding: 24px;">
<p style="margin: 0 0 16px; color: #333;">${greeting}</p>
<p style="margin: 0 0 16px; color: #333;">Your verification code is:</p>
<div style="background: #f4f4f5; border-radius: 8px; padding: 20px; text-align: center; margin: 0 0 16px;">
<span style="font-size: 32px; font-weight: 700; letter-spacing: 6px; color: #111;">${String(props.code ?? "")}</span>
</div>
<p style="margin: 0 0 16px; color: #666; font-size: 14px;">This code expires in 5 minutes.</p>
<p style="margin: 0; color: #666; font-size: 14px;">If you didn't request this, you can safely ignore this email.</p>
<hr style="border: none; border-top: 1px solid #eee; margin: 24px 0;" />
<p style="margin: 0; color: #999; font-size: 12px;">Interioring — Interior Design Marketplace</p>
</div>
`;
return {
subject: "Your Interioring verification code",
html,
};
}
default:
throw new Error(`Unknown email template: ${template}`);
}
}
export function createEmailService(env: CloudflareBindings) {
// Create the appropriate email provider based on configuration
const provider = createEmailProvider({
mailtrapApiToken: env.MAILTRAP_API_TOKEN,
mailtrapInboxId: env.MAILTRAP_INBOX_ID,
resendApiKey: env.RESEND_API_KEY,
mailpitHost: env.MAILPIT_HOST,
fromEmail: env.RESEND_FROM_EMAIL || "onboarding@resend.dev",
});
return {
async sendPasswordReset(to: string, resetLink: string, userName?: string) {
const html = await render(PasswordResetEmail({ resetLink, userName }));
return provider.sendEmail({
to,
subject: "Reset your Interioring password",
html,
});
},
async sendEmailVerification(
to: string,
verificationLink: string,
userName?: string,
) {
const html = await render(
EmailVerificationEmail({ verificationLink, userName }),
);
return provider.sendEmail({
to,
subject: "Verify your Interioring email",
html,
});
},
async sendWelcome(to: string, userName: string, loginUrl?: string) {
const html = await render(WelcomeEmail({ userName, loginUrl }));
return provider.sendEmail({
to,
subject: "Welcome to Interioring!",
html,
});
},
async sendNewInquiry(
recipients: { email: string; name: string }[],
inquiryDetails: Omit<NewInquiryEmailProps, "proName" | "portalUrl">,
) {
if (recipients.length === 0) {
console.warn("[EMAIL] No recipients for new inquiry email");
return { id: null, count: 0 };
}
const results = await Promise.allSettled(
recipients.map(async (recipient) => {
const html = await render(
NewInquiryEmail({
...inquiryDetails,
proName: recipient.name,
}),
);
return provider.sendEmail({
to: recipient.email,
subject: `New inquiry from ${escapeHtml(inquiryDetails.customerName)}`,
html,
});
}),
);
const successful = results.filter((r) => r.status === "fulfilled");
const failed = results.filter((r) => r.status === "rejected");
if (failed.length > 0) {
console.error(
"[EMAIL] Some inquiry emails failed:",
failed
.filter((r): r is PromiseRejectedResult => r.status === "rejected")
.map((f) => f.reason),
);
}
console.log("[EMAIL] New inquiry emails sent:", {
total: recipients.length,
successful: successful.length,
failed: failed.length,
});
return {
id: successful.length > 0 ? "batch-email" : null,
count: successful.length,
};
},
async sendTeamInvitation(
to: string,
invitationDetails: TeamInvitationEmailProps,
) {
const html = await render(TeamInvitationEmail(invitationDetails));
return provider.sendEmail({
to,
subject: `You've been invited to join ${escapeHtml(invitationDetails.proName)} on Interioring`,
html,
});
},
async sendBlogApprovalRequest(
to: string,
details: BlogApprovalRequestEmailProps,
) {
const html = await render(BlogApprovalRequestEmail(details));
return provider.sendEmail({
to,
subject: `Review Required: ${details.blogTitle}`,
html,
});
},
async sendBlogApprovalReminder(
to: string,
details: BlogApprovalReminderEmailProps,
) {
const html = await render(BlogApprovalReminderEmail(details));
return provider.sendEmail({
to,
subject: `Reminder: Blog approval needed - ${details.blogTitle}`,
html,
});
},
async sendBlogPublished(
recipients: { email: string; name: string }[],
details: Omit<BlogPublishedEmailProps, "proName">,
) {
if (recipients.length === 0) {
console.warn("[EMAIL] No recipients for blog published email");
return { id: null, count: 0 };
}
const results = await Promise.allSettled(
recipients.map(async (recipient) => {
const html = await render(
BlogPublishedEmail({
...details,
proName: recipient.name,
}),
);
return provider.sendEmail({
to: recipient.email,
subject: `Your blog is live: ${details.blogTitle}`,
html,
});
}),
);
const successful = results.filter((r) => r.status === "fulfilled");
const failed = results.filter((r) => r.status === "rejected");
if (failed.length > 0) {
console.error(
"[EMAIL] Some blog published emails failed:",
failed
.filter((r): r is PromiseRejectedResult => r.status === "rejected")
.map((f) => f.reason),
);
}
console.log("[EMAIL] Blog published emails sent:", {
total: recipients.length,
successful: successful.length,
failed: failed.length,
});
return {
id: successful.length > 0 ? "batch-email" : null,
count: successful.length,
};
},
async sendEmailVerified(to: string, props: EmailVerifiedProps) {
const html = await render(EmailVerifiedEmail(props));
return provider.sendEmail({
to,
subject: "Email Verified — You're In!",
html,
});
},
async sendProAccountStatus(
recipients: { email: string; name: string }[],
details: Omit<ProAccountStatusProps, "proName">,
) {
if (recipients.length === 0) {
console.warn("[EMAIL] No recipients for pro account status email");
return { id: null, count: 0 };
}
const subject =
details.status === "published"
? `${details.businessName} is now live on Interioring!`
: `Your Interioring account has been archived`;
const results = await Promise.allSettled(
recipients.map(async (recipient) => {
const html = await render(
ProAccountStatusEmail({
...details,
proName: recipient.name,
}),
);
return provider.sendEmail({
to: recipient.email,
subject,
html,
});
}),
);
const successful = results.filter((r) => r.status === "fulfilled");
const failed = results.filter((r) => r.status === "rejected");
if (failed.length > 0) {
console.error(
"[EMAIL] Some pro account status emails failed:",
failed
.filter((r): r is PromiseRejectedResult => r.status === "rejected")
.map((f) => f.reason),
);
}
console.log("[EMAIL] Pro account status emails sent:", {
total: recipients.length,
successful: successful.length,
failed: failed.length,
});
return {
id: successful.length > 0 ? "batch-email" : null,
count: successful.length,
};
},
async sendWebsiteBuildResult(
recipients: { email: string; name: string }[],
details: Omit<WebsiteBuildResultProps, "proName">,
) {
if (recipients.length === 0) {
console.warn("[EMAIL] No recipients for website build result email");
return { id: null, count: 0 };
}
const subject = details.success
? `Your website for ${details.businessName} is live!`
: `Website build failed for ${details.businessName}`;
const results = await Promise.allSettled(
recipients.map(async (recipient) => {
const html = await render(
WebsiteBuildResultEmail({
...details,
proName: recipient.name,
}),
);
return provider.sendEmail({
to: recipient.email,
subject,
html,
});
}),
);
const successful = results.filter((r) => r.status === "fulfilled");
const failed = results.filter((r) => r.status === "rejected");
if (failed.length > 0) {
console.error(
"[EMAIL] Some website build result emails failed:",
failed
.filter((r): r is PromiseRejectedResult => r.status === "rejected")
.map((f) => f.reason),
);
}
console.log("[EMAIL] Website build result emails sent:", {
total: recipients.length,
successful: successful.length,
failed: failed.length,
});
return {
id: successful.length > 0 ? "batch-email" : null,
count: successful.length,
};
},
async sendReminderDue(to: string, details: ReminderDueEmailProps) {
const html = await render(ReminderDueEmail(details));
return provider.sendEmail({
to,
subject: `Reminder due: ${details.reminderTitle}`,
html,
});
},
async sendMagicLink(to: string, props: { magicLinkUrl: string }) {
const html = await render(MagicLinkEmail(props));
return provider.sendEmail({
to,
subject: "Sign in to Interioring",
html,
});
},
async sendOtpCode(to: string, code: string, userName?: string) {
const greeting = userName ? `Hi ${escapeHtml(userName)},` : "Hi,";
const html = `
<div style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; max-width: 480px; margin: 0 auto; padding: 24px;">
<p style="margin: 0 0 16px; color: #333;">${greeting}</p>
<p style="margin: 0 0 16px; color: #333;">Your verification code is:</p>
<div style="background: #f4f4f5; border-radius: 8px; padding: 20px; text-align: center; margin: 0 0 16px;">
<span style="font-size: 32px; font-weight: 700; letter-spacing: 6px; color: #111;">${code}</span>
</div>
<p style="margin: 0 0 16px; color: #666; font-size: 14px;">This code expires in 5 minutes.</p>
<p style="margin: 0; color: #666; font-size: 14px;">If you didn't request this, you can safely ignore this email.</p>
<hr style="border: none; border-top: 1px solid #eee; margin: 24px 0;" />
<p style="margin: 0; color: #999; font-size: 12px;">Interioring — Interior Design Marketplace</p>
</div>
`;
return provider.sendEmail({
to,
subject: "Your Interioring verification code",
html,
});
},
async sendRawEmail(to: string, subject: string, html: string) {
return provider.sendEmail({ to, subject, html });
},
};
}
|