Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Enable open tracking for email domains (#3055)

Kiran Kb4cdafce46dd
diff --git a/apps/web/app/(ee)/api/email-domains/[domain]/route.ts b/apps/web/app/(ee)/api/email-domains/[domain]/route.ts
index 9510ba6baf..0ec7082bc2 100644
--- a/apps/web/app/(ee)/api/email-domains/[domain]/route.ts
+++ b/apps/web/app/(ee)/api/email-domains/[domain]/route.ts
@@ -30,6 +30,8 @@ export const PATCH = withWorkspace(
const domainChanged = slug && slug !== emailDomain.slug;
+ let resendDomainId: string | undefined;
+
if (domainChanged) {
if (!resend) {
throw new DubApiError({
@@ -53,34 +55,53 @@ export const PATCH = withWorkspace(
});
}
+ resendDomainId = resendDomain.id;
+
waitUntil(
- Promise.allSettled([
- prisma.emailDomain.update({
- where: {
- id: emailDomain.id,
- },
- data: {
- resendDomainId: resendDomain.id,
- status: "pending",
- },
- }),
+ (async () => {
+ // Verify an existing domain
+ const { error: resendVerifyError } = await resend.domains.verify(
+ resendDomain.id,
+ );
+
+ if (resendVerifyError) {
+ console.error(
+ `Resend domain verify failed - ${resendVerifyError.message}`,
+ );
+ }
+
+ // Enable open tracking for the domain
+ const { error: resendUpdateError } = await resend.domains.update({
+ id: resendDomain.id,
+ openTracking: true,
+ clickTracking: false,
+ tls: "opportunistic",
+ });
- resend.domains.verify(resendDomain.id),
- ]),
+ if (resendUpdateError) {
+ console.error(
+ `Resend domain update failed - ${resendUpdateError.message}`,
+ );
+ }
+ })(),
);
}
try {
- await prisma.emailDomain.update({
+ const updatedEmailDomain = await prisma.emailDomain.update({
where: {
id: emailDomain.id,
},
data: {
slug,
+ ...(domainChanged && {
+ resendDomainId,
+ status: "pending",
+ }),
},
});
- return NextResponse.json(EmailDomainSchema.parse(emailDomain));
+ return NextResponse.json(EmailDomainSchema.parse(updatedEmailDomain));
} catch (error) {
console.error(error);
diff --git a/apps/web/app/(ee)/api/email-domains/route.ts b/apps/web/app/(ee)/api/email-domains/route.ts
index 8fbcae85ef..3808a4c5a4 100644
--- a/apps/web/app/(ee)/api/email-domains/route.ts
+++ b/apps/web/app/(ee)/api/email-domains/route.ts
@@ -88,13 +88,28 @@ export const POST = withWorkspace(
waitUntil(
(async () => {
- const { error: resendError } = await resend.domains.verify(
+ // Verify an existing domain
+ const { error: resendVerifyError } = await resend.domains.verify(
resendDomain.id,
);
- if (resendError) {
+ if (resendVerifyError) {
console.error(
- `Resend domain verify failed - ${resendError.message}`,
+ `Resend domain verify failed - ${resendVerifyError.message}`,
+ );
+ }
+
+ // Enable open tracking for the domain
+ const { error: resendUpdateError } = await resend.domains.update({
+ id: resendDomain.id,
+ openTracking: true,
+ clickTracking: false,
+ tls: "opportunistic",
+ });
+
+ if (resendUpdateError) {
+ console.error(
+ `Resend domain update failed - ${resendUpdateError.message}`,
);
}
})(),