1- import { Resend } from "resend " ;
1+ import { createEmailer , type Emailer } from "@profullstack/stack/email " ;
22import { env } from "./env" ;
33
4- let cached : Resend | null = null ;
4+ let cached : Emailer | null = null ;
55function client ( ) {
66 if ( cached ) return cached ;
77 if ( ! env . resendApiKey ) return null ;
8- cached = new Resend ( env . resendApiKey ) ;
8+ cached = createEmailer ( {
9+ resendApiKey : env . resendApiKey ,
10+ defaultFrom : env . resendFrom ,
11+ } ) ;
912 return cached ;
1013}
1114
@@ -309,7 +312,7 @@ export async function sendAuditReadyEmail(input: {
309312} ) {
310313 const c = client ( ) ;
311314 if ( ! c ) return ;
312- await c . emails . send ( {
315+ await c . send ( {
313316 from : env . resendFrom ,
314317 to : input . to ,
315318 subject : `Your AEO audit for ${ input . targetUrl } is ready (${ input . score } /100)` ,
@@ -337,7 +340,7 @@ export async function sendAuditReportPdfEmail(input: {
337340 return input . targetUrl ;
338341 }
339342 } ) ( ) ;
340- const res = await c . emails . send ( {
343+ const res = await c . send ( {
341344 from : env . resendFrom ,
342345 to : input . to ,
343346 subject : `Your CrawlProof audit for ${ host } (${ input . score } /100)` ,
@@ -349,7 +352,7 @@ export async function sendAuditReportPdfEmail(input: {
349352 } ) ,
350353 attachments : [ { filename : `crawlproof-${ host } .pdf` , content : input . pdf . toString ( "base64" ) } ] ,
351354 } ) ;
352- if ( res . error ) return { sent : false , error : String ( res . error ) } ;
355+ if ( ! res . sent ) return { sent : false , error : res . error } ;
353356 return { sent : true } ;
354357}
355358
@@ -365,7 +368,7 @@ export async function sendDigestEmail(input: {
365368 `<li><a href="${ r . url } ">${ r . target } </a> — <strong>${ r . score } /100</strong></li>` ,
366369 )
367370 . join ( "" ) ;
368- await c . emails . send ( {
371+ await c . send ( {
369372 from : env . resendFrom ,
370373 to : input . to ,
371374 subject : `Your weekly CrawlProof digest` ,
@@ -392,7 +395,7 @@ export async function sendMarketingEmail(input: {
392395 <a href="${ unsubUrl } " style="color:#888">Unsubscribe</a>.
393396 </p>` ;
394397
395- const res = await c . emails . send ( {
398+ const res = await c . send ( {
396399 from : env . resendFrom ,
397400 to : input . to ,
398401 subject : input . subject ,
@@ -402,7 +405,7 @@ export async function sendMarketingEmail(input: {
402405 "List-Unsubscribe-Post" : "List-Unsubscribe=One-Click" ,
403406 } ,
404407 } ) ;
405- if ( res . error ) return { sent : false , error : String ( res . error ) } ;
408+ if ( ! res . sent ) return { sent : false , error : res . error } ;
406409 return { sent : true } ;
407410}
408411
@@ -425,7 +428,7 @@ export async function sendPurchaseReceiptEmail(input: {
425428 } ) } `;
426429 const filename = `crawlproof-receipt-${ input . paymentId . slice ( 0 , 12 ) } .pdf` ;
427430
428- const res = await c . emails . send ( {
431+ const res = await c . send ( {
429432 from : env . resendFrom ,
430433 to : input . to ,
431434 subject : `Your CrawlProof receipt — ${ input . creditsAdded } credit${ input . creditsAdded === 1 ? "" : "s" } ` ,
@@ -439,7 +442,7 @@ export async function sendPurchaseReceiptEmail(input: {
439442 } ) ,
440443 attachments : [ { filename, content : input . pdf . toString ( "base64" ) } ] ,
441444 } ) ;
442- if ( res . error ) return { sent : false , error : String ( res . error ) } ;
445+ if ( ! res . sent ) return { sent : false , error : res . error } ;
443446 return { sent : true } ;
444447}
445448
@@ -487,7 +490,7 @@ export async function sendPremiumDeckEmail(input: {
487490 if ( ! c ) return { sent : false , error : "RESEND_API_KEY not set" } ;
488491
489492 const deckUrl = `${ env . siteUrl } /pdfs/CrawlProof_Premium_Deck.pdf` ;
490- const res = await c . emails . send ( {
493+ const res = await c . send ( {
491494 from : env . resendFrom ,
492495 to : input . to ,
493496 subject : "Your CrawlProof premium deck" ,
@@ -499,7 +502,7 @@ export async function sendPremiumDeckEmail(input: {
499502 } ,
500503 ] ,
501504 } ) ;
502- if ( res . error ) return { sent : false , error : String ( res . error ) } ;
505+ if ( ! res . sent ) return { sent : false , error : res . error } ;
503506 return { sent : true } ;
504507}
505508
@@ -537,14 +540,14 @@ export async function sendHireInquiryEmail(input: {
537540 ${ input . message ? `<p style="margin-top:16px"><strong>Message</strong><br/><pre style="white-space:pre-wrap;font-family:inherit;background:#f6f8fa;padding:12px;border-radius:6px">${ esc ( input . message ) } </pre></p>` : "" }
538541 </body></html>` ;
539542
540- const res = await c . emails . send ( {
543+ const res = await c . send ( {
541544 from : env . resendFrom ,
542545 to : "hello@crawlproof.com" ,
543546 replyTo : input . email ,
544547 subject : `Hire-us inquiry: ${ input . name } (${ input . website } )` ,
545548 html,
546549 } ) ;
547- if ( res . error ) return { sent : false , error : String ( res . error ) } ;
550+ if ( ! res . sent ) return { sent : false , error : res . error } ;
548551 return { sent : true } ;
549552}
550553
@@ -595,13 +598,13 @@ export async function sendProjectInviteEmail(input: {
595598 footerNote : "If you weren't expecting this invitation, you can safely ignore this email." ,
596599 } ) ;
597600
598- const res = await c . emails . send ( {
601+ const res = await c . send ( {
599602 from : env . resendFrom ,
600603 to : input . to ,
601604 subject : `${ escapeHtml ( input . invitedBy ) } invited you to ${ escapeHtml ( input . projectName ) } on CrawlProof` ,
602605 html,
603606 } ) ;
604- if ( res . error ) return { sent : false , error : String ( res . error ) } ;
607+ if ( ! res . sent ) return { sent : false , error : res . error } ;
605608 return { sent : true } ;
606609}
607610
@@ -644,12 +647,12 @@ export async function sendOrgInviteEmail(input: {
644647 footerNote : "If you weren't expecting this invitation, you can safely ignore this email." ,
645648 } ) ;
646649
647- const res = await c . emails . send ( {
650+ const res = await c . send ( {
648651 from : env . resendFrom ,
649652 to : input . to ,
650653 subject : `${ escapeHtml ( input . invitedBy ) } invited you to ${ escapeHtml ( input . orgName ) } on CrawlProof` ,
651654 html,
652655 } ) ;
653- if ( res . error ) return { sent : false , error : String ( res . error ) } ;
656+ if ( ! res . sent ) return { sent : false , error : res . error } ;
654657 return { sent : true } ;
655658}
0 commit comments