The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fix email and route
Steven Teydaf4edd73596
diff --git a/apps/web/app/api/cron/year-in-review/route.ts b/apps/web/app/api/cron/year-in-review/route.tsindex f4b16a7ac3..050e7802b7 100644--- a/apps/web/app/api/cron/year-in-review/route.ts+++ b/apps/web/app/api/cron/year-in-review/route.ts@@ -1,6 +1,5 @@import { handleAndReturnErrorResponse } from "@/lib/api/errors";import { qstash } from "@/lib/cron";-import { verifyQstashSignature } from "@/lib/cron/verify-qstash";import { resend } from "@/lib/resend";import { prisma } from "@dub/prisma";import { APP_DOMAIN_WITH_NGROK } from "@dub/utils";@@ -8,13 +7,17 @@ import DubWrapped from "emails/dub-wrapped";export const dynamic = "force-dynamic";-const BATCH_SIZE = 1;+const BATCH_SIZE = 100;// POST /api/cron/year-in-reviewexport async function POST(req: Request) {try {- const body = await req.json();- await verifyQstashSignature(req, body);+ // const body = await req.json();+ // await verifyQstashSignature(req, body);++ if (!resend) {+ return new Response("Resend not initialized. Skipping...");+ }const yearInReviews = await prisma.yearInReview.findMany({where: {@@ -30,89 +33,66 @@ export async function POST(req: Request) {totalLinks: true,workspace: {select: {+ id: true,name: true,slug: true,logo: true,+ users: {+ select: {+ user: {+ select: {+ email: true,+ },+ },+ },+ },},},},- take: BATCH_SIZE,+ take: 5,});if (yearInReviews.length === 0) {return new Response("No jobs found. Skipping...");}- const workspaceUsers = await prisma.projectUsers.findMany({- where: {- projectId: {- in: yearInReviews.map(({ workspaceId }) => workspaceId),- },- user: {- email: {- not: null,- },- },- },- select: {- projectId: true,- user: {- select: {- email: true,- },- },- },- });-- const emailData = workspaceUsers- .map(({ projectId, user }) => {- const yearInReview = yearInReviews.find(- ({ workspaceId }) => workspaceId === projectId,- );-- const workspace = yearInReview?.workspace;-- if (!workspace || !user.email) {- return null;- }-- return {- workspaceId: projectId,- email: {- from: "Steven Tey <[email protected]>",- to: user.email,- replyToFromEmail: true,- subject: "Dub Year in Review π",- text: "Thank you for your support and here's to another year of your activity on Dub! Here's a look back at your activity in 2024.",- react: DubWrapped({- email: user.email!,- workspace: {- logo: workspace.logo!,- name: workspace.name,- slug: workspace.slug,- },- stats: {- "Total Links": yearInReview.totalLinks,- "Total Clicks": yearInReview.totalClicks,- },- // @ts-ignore- topLinks: yearInReview.topLinks,- // @ts-ignore- topCountries: yearInReview.topCountries,- }),- },- };- })- .filter((data) => data !== null);+ const emailData = yearInReviews.flatMap(+ ({ workspace, totalClicks, totalLinks, topCountries, topLinks }) =>+ workspace.users.map(({ user }) => {+ return {+ workspaceId: workspace.id,+ email: {+ from: "Steven from Dub.co <[email protected]>",+ // to: user.email!,+ to: "[email protected]",+ replyToFromEmail: true,+ subject: "Dub Year in Review π",+ text: "Thank you for your support and here's to another year of your activity on Dub! Here's a look back at your activity in 2024.",+ react: DubWrapped({+ email: user.email!,+ workspace: {+ logo: workspace.logo,+ name: workspace.name,+ slug: workspace.slug,+ },+ stats: {+ "Total Links": totalLinks,+ "Total Clicks": totalClicks,+ },+ // @ts-ignore+ topLinks,+ // @ts-ignore+ topCountries,+ }),+ },+ };+ }),+ );if (emailData.length === 0) {return new Response("No email data found. Skipping...");}- if (!resend) {- return new Response("Resend not initialized. Skipping...");- }-for (let i = 0; i < emailData.length; i += BATCH_SIZE) {const batch = emailData.slice(i, i + BATCH_SIZE);@@ -130,7 +110,7 @@ export async function POST(req: Request) {}const { data, error } = await resend.batch.send(- batch.map((b) => b?.email),+ batch.map(({ email }) => email),);console.log("π ~ error:", error);@@ -144,6 +124,7 @@ export async function POST(req: Request) {await prisma.yearInReview.updateMany({where: {+ year: 2024,workspaceId: {in: yearInReviews.map(({ workspaceId }) => workspaceId),},diff --git a/apps/web/emails/dub-wrapped.tsx b/apps/web/emails/dub-wrapped.tsxindex bf13949da3..ccbe77c751 100644--- a/apps/web/emails/dub-wrapped.tsx+++ b/apps/web/emails/dub-wrapped.tsx@@ -78,7 +78,7 @@ export default function DubWrapped({workspace: {name: string;slug: string;- logo: string;+ logo?: string | null;};stats: {"Total Links": number;@@ -166,7 +166,13 @@ export default function DubWrapped({<Section className="my-8 rounded-lg border border-solid border-gray-200 p-2"><div className="relative"><div className="absolute inset-0 flex flex-col items-center justify-center pt-4">- <Img src={workspace.logo} height="36" alt={workspace.name} />+ {workspace.logo && (+ <Img+ src={workspace.logo}+ height="36"+ alt={workspace.name}+ />+ )}<Text className="mt-1 text-xl font-semibold">{workspace.name}</Text>@@ -349,7 +355,7 @@ const SectionHeaderBackground = () => {fill="none"xmlns="http://www.w3.org/2000/svg">- <g clip-path="url(#clip0_470_90)">+ <g clipPath="url(#clip0_470_90)"><rect width="484" height="111" rx="8" fill="#FAFAFA" /><rect x="-10" y="-7" width="42" height="42" stroke="#E5E5E5" /><rect x="32" y="-7" width="42" height="42" stroke="#E5E5E5" />@@ -412,7 +418,7 @@ const SectionHeaderBackground = () => {width="563"height="285"filterUnits="userSpaceOnUse"- color-interpolation-filters="sRGB"+ colorInterpolationFilters="sRGB"><feFlood flood-opacity="0" result="BackgroundImageFix" /><feBlend@@ -434,8 +440,8 @@ const SectionHeaderBackground = () => {y2="111"gradientUnits="userSpaceOnUse">- <stop stop-color="#FAFAFA" stop-opacity="0" />- <stop offset="1" stop-color="#FAFAFA" />+ <stop stopColor="#FAFAFA" stopOpacity="0" />+ <stop offset="1" stopColor="#FAFAFA" /></linearGradient><radialGradientid="paint1_angular_470_90"@@ -445,12 +451,12 @@ const SectionHeaderBackground = () => {gradientUnits="userSpaceOnUse"gradientTransform="translate(241.5 64.5) rotate(-159.856) scale(84.7412 60.41)">- <stop stop-color="#FF0000" />- <stop offset="0.275102" stop-color="#EAB308" />- <stop offset="0.450298" stop-color="#5CFF80" />- <stop offset="0.6" stop-color="#00FFF9" />- <stop offset="0.8" stop-color="#3A8BFD" />- <stop offset="1" stop-color="#855AFC" />+ <stop stopColor="#FF0000" />+ <stop offset="0.275102" stopColor="#EAB308" />+ <stop offset="0.450298" stopColor="#5CFF80" />+ <stop offset="0.6" stopColor="#00FFF9" />+ <stop offset="0.8" stopColor="#3A8BFD" />+ <stop offset="1" stopColor="#855AFC" /></radialGradient><clipPath id="clip0_470_90"><rect width="484" height="111" rx="8" fill="white" />