The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fix email.opened webhook
Steven Tey633a8527c4ca
diff --git a/apps/web/app/(ee)/api/cron/messages/notify-partner/route.ts b/apps/web/app/(ee)/api/cron/messages/notify-partner/route.tsindex dbc5d20949..ff64d232d5 100644--- a/apps/web/app/(ee)/api/cron/messages/notify-partner/route.ts+++ b/apps/web/app/(ee)/api/cron/messages/notify-partner/route.ts@@ -128,7 +128,7 @@ export async function POST(req: Request) {})),email,}),- tags: [{ name: "type", value: "message-notification" }],+ tags: [{ name: "type", value: "notification-email" }],})),);diff --git a/apps/web/app/(ee)/api/cron/messages/notify-program/route.ts b/apps/web/app/(ee)/api/cron/messages/notify-program/route.tsindex 84502eb7aa..4589ec58d0 100644--- a/apps/web/app/(ee)/api/cron/messages/notify-program/route.ts+++ b/apps/web/app/(ee)/api/cron/messages/notify-program/route.ts@@ -129,7 +129,7 @@ export async function POST(req: Request) {})),email,}),- tags: [{ name: "type", value: "message-notification" }],+ tags: [{ name: "type", value: "notification-email" }],})),);diff --git a/apps/web/app/(ee)/api/cron/payouts/charge-succeeded/send-stripe-payouts.ts b/apps/web/app/(ee)/api/cron/payouts/charge-succeeded/send-stripe-payouts.tsindex 348517704f..ce333d7e36 100644--- a/apps/web/app/(ee)/api/cron/payouts/charge-succeeded/send-stripe-payouts.ts+++ b/apps/web/app/(ee)/api/cron/payouts/charge-succeeded/send-stripe-payouts.ts@@ -94,19 +94,17 @@ export async function sendStripePayouts({ invoiceId }: { invoiceId: string }) {const resendBatch = await sendBatchEmail(currentInvoicePayouts.filter((p) => p.partner.email)- .map((p) => {- return {- variant: "notifications",- to: p.partner.email!,- subject: "You've been paid!",- react: PartnerPayoutProcessed({- email: p.partner.email!,- program: p.program,- payout: p,- variant: "stripe",- }),- };- }),+ .map((p) => ({+ variant: "notifications",+ to: p.partner.email!,+ subject: "You've been paid!",+ react: PartnerPayoutProcessed({+ email: p.partner.email!,+ program: p.program,+ payout: p,+ variant: "stripe",+ }),+ })),);console.log("Sent Resend batch emails", JSON.stringify(resendBatch, null, 2));diff --git a/apps/web/app/api/resend/webhook/email-opened.ts b/apps/web/app/api/resend/webhook/email-opened.tsindex 9df9282a5d..86d04c627a 100644--- a/apps/web/app/api/resend/webhook/email-opened.ts+++ b/apps/web/app/api/resend/webhook/email-opened.ts@@ -1,16 +1,46 @@import { prisma } from "@dub/prisma";+const NOTIFICATION_EMAIL_SUBJECT_PREFIXES = [+ "New message from",+ "New bounty available",+];+export async function emailOpened({email_id: emailId,- tags,+ subject,}: {email_id: string;- tags?: Record<string, string>;+ subject?: string;}) {- // Ignore if not a message notification- if (!tags || tags.type !== "message-notification") {+ // TODO: Ignore if not a message notification (when sendBatchEmail supports tags)+ // if (!tags || tags.type !== "notification-email") {+ // console.log(+ // `Ignoring email.opened webhook for email ${emailId} because it's not a notification-email...`,+ // );+ // return;+ // }++ if (+ !subject ||+ !NOTIFICATION_EMAIL_SUBJECT_PREFIXES.some((prefix) =>+ subject.startsWith(prefix),+ )+ ) {+ console.log(+ `Ignoring email.opened webhook for email ${emailId} because it's not a notification email. Subject: ${subject}`,+ );+ return;+ }++ const notificationEmail = await prisma.notificationEmail.findUnique({+ where: {+ emailId,+ },+ });++ if (!notificationEmail) {console.log(- `Ignoring email.opened webhook for email ${emailId} because it's not a message-notification...`,+ `Ignoring email.opened webhook for email ${emailId} because it's not a notification email...`,);return;}diff --git a/apps/web/lib/actions/send-otp.ts b/apps/web/lib/actions/send-otp.tsindex eb85df6264..2d66740fc0 100644--- a/apps/web/lib/actions/send-otp.ts+++ b/apps/web/lib/actions/send-otp.ts@@ -9,7 +9,7 @@ import { flattenValidationErrors } from "next-safe-action";import { getIP } from "../api/utils";import { generateOTP } from "../auth";import { EMAIL_OTP_EXPIRY_IN } from "../auth/constants";-import { isGenericEmail } from "../emails";+import { isGenericEmail } from "../is-generic-email";import z from "../zod";import { emailSchema, passwordSchema } from "../zod/schemas/auth";import { throwIfAuthenticated } from "./auth/throw-if-authenticated";diff --git a/apps/web/lib/emails.ts b/apps/web/lib/is-generic-email.tssimilarity index 100%rename from apps/web/lib/emails.tsrename to apps/web/lib/is-generic-email.tsdiff --git a/apps/web/ui/workspaces/create-workspace-form.tsx b/apps/web/ui/workspaces/create-workspace-form.tsxindex 367970d0b8..8c18ade5f9 100644--- a/apps/web/ui/workspaces/create-workspace-form.tsx+++ b/apps/web/ui/workspaces/create-workspace-form.tsx@@ -1,6 +1,6 @@"use client";-import { isGenericEmail } from "@/lib/emails";+import { isGenericEmail } from "@/lib/is-generic-email";import { AlertCircleFill } from "@/ui/shared/icons";import { Button, buttonVariants, FileUpload, useMediaQuery } from "@dub/ui";import { cn } from "@dub/utils";