The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
client switch
Steven Teyfb5c5d5cb7d7
diff --git a/README.md b/README.mdindex 41f7c3a62d..2c9c1eb4f2 100644--- a/README.md+++ b/README.md@@ -50,7 +50,7 @@ Dub.co is the open-source link management infrastructure for modern marketing te- [BoxyHQ](https://boxyhq.com/enterprise-sso) – SSO/SAML- [Turborepo](https://turbo.build/repo) – monorepo- [Stripe](https://stripe.com/) – payments-- [Resend](https://resend.com/) – emails+- [Postmark](https://postmarkapp.com/) – emails- [Vercel](https://vercel.com/) – deployments## Self-Hostingdiff --git a/apps/docs/introduction.mdx b/apps/docs/introduction.mdxindex 7d9de18065..37f292e38c 100644--- a/apps/docs/introduction.mdx+++ b/apps/docs/introduction.mdx@@ -1,6 +1,6 @@---title: Introduction-'og:title': "Getting Started with Dub.co - Documentation"+"og:title": "Getting Started with Dub.co - Documentation"description: "Dub.co is the open-source link management infrastructure for modern marketing teams."---@@ -36,7 +36,7 @@ Dub's codebase is [fully open-source](https://dub.sh/github) and is built on top- [BoxyHQ](https://boxyhq.com/enterprise-sso) – SSO/SAML- [Turborepo](https://turbo.build/repo) – monorepo- [Stripe](https://stripe.com/) – payments-- [Resend](https://resend.com/) – emails+- [Postmark](https://postmarkapp.com/) – emails- [Vercel](https://vercel.com/) – deployments## Getting Starteddiff --git a/apps/docs/self-hosting.mdx b/apps/docs/self-hosting.mdxindex 1d78daf99a..3a0c3eb7e8 100644--- a/apps/docs/self-hosting.mdx+++ b/apps/docs/self-hosting.mdx@@ -248,17 +248,17 @@ Don't forget to set the following Callback URLs:Once your GitHub App is created, copy the `Client ID` and `Client Secret` into your `.env` file as the `GITHUB_CLIENT_ID` and `GITHUB_CLIENT_SECRET` environment variables.-## Step 6: Set up Resend (optional)+## Step 6: Set up Postmark (optional)<Note>Note that if you want to use magic link sign-in, this is a required step.</Note>-Next, you'll need to set up Resend for transactional emails (e.g. magic link emails):+Next, you'll need to set up Postmark for transactional emails (e.g. magic link emails):-1. In your [Resend account](https://resend.com/overview), create a new API key.-2. Copy the API key into your `.env` file as the `RESEND_API_KEY` environment variable.-3. You'll then need to set up MX records for your domain to start working. You can follow this guide to learn [how to set up MX records with Resend](https://resend.com/docs/dashboard/domains/introduction).+1. Follow [this guide](https://postmarkapp.com/support/article/1008-what-are-the-account-and-server-api-tokens) to create a new API token.+2. Copy the API key into your `.env` file as the `POSTMARK_API_KEY` environment variable.+3. You'll then need to set up DKIM records and for your domain to start working. You can [follow this guide](https://postmarkapp.com/support/article/1002-getting-started-with-postmark) to learn how to do so.## Step 7: Set up Cloudinary & Unsplash (optional)diff --git a/apps/web/.env.example b/apps/web/.env.exampleindex 55fe606568..23ed8dc924 100644--- a/apps/web/.env.example+++ b/apps/web/.env.example@@ -38,8 +38,8 @@ NEXTAUTH_SECRET=NEXTAUTH_URL=http://localhost:8888 # (only needed for localhost)# Required for email login-# Get your Resend API Key here: https://resend.com/docs/send-with-nextjs-RESEND_API_KEY=+# Get your Postmark API Key here: https://postmarkapp.com/support/article/1008-what-are-the-account-and-server-api-tokens+POSTMARK_API_KEY=##################################### OPTIONAL ENV VARS ######diff --git a/apps/web/app/api/callback/postmark/route.ts b/apps/web/app/api/callback/postmark/route.tsnew file mode 100644index 0000000000..281e23918b--- /dev/null+++ b/apps/web/app/api/callback/postmark/route.ts@@ -0,0 +1,36 @@+import { unsubscribe } from "@/lib/flodesk";+import prisma from "@/lib/prisma";+import { log } from "@dub/utils";+import { NextRequest, NextResponse } from "next/server";++export async function POST(req: NextRequest) {+ // authenticate webhook X-Postmark-Webhook-Secret+ const token = req.headers.get("X-Postmark-Webhook-Secret");+ if (token !== process.env.POSTMARK_WEBHOOK_SECRET) {+ return new Response("Unauthorized", { status: 401 });+ }++ const payload = await req.json();++ // parse the payload+ const { Recipient: email, SuppressSending: unsub } = payload;++ await Promise.all([+ prisma.user.update({+ where: {+ email,+ },+ data: {+ subscribed: !unsub,+ },+ }),+ unsub+ ? unsubscribe(email)+ : log({+ message: `*${email}* resubscribed to the newsletter. Manual addition required.`,+ type: "alerts",+ }),+ ]);++ return NextResponse.json({ success: true });+}diff --git a/apps/web/app/api/callback/stripe/route.ts b/apps/web/app/api/callback/stripe/route.tsindex 4ce82484eb..8eb834652d 100644--- a/apps/web/app/api/callback/stripe/route.ts+++ b/apps/web/app/api/callback/stripe/route.ts@@ -3,7 +3,7 @@ import prisma from "@/lib/prisma";import { stripe } from "@/lib/stripe";import { redis } from "@/lib/upstash";import { FREE_PLAN, getPlanFromPriceId, log } from "@dub/utils";-import { resend, sendEmail } from "emails";+import { sendEmail } from "emails";import UpgradeEmail from "emails/upgrade-email";import { NextResponse } from "next/server";import Stripe from "stripe";@@ -256,12 +256,13 @@ export const POST = async (req: Request) => {type: "cron",mention: true,}),- resend.emails.send({- from: "Steven from Dub.co <[email protected]>",- to: projectUsers,- subject: "Feedback on your Dub.co experience?",- text: "Hey!\n\nI noticed you recently cancelled your Dub.co subscription – we're sorry to see you go!\n\nI'd love to hear your feedback on your experience with Dub – what could we have done better?\n\nThanks!\n\nSteven Tey\nFounder, Dub.co",- }),+ projectUsers.map((email) =>+ sendEmail({+ email,+ subject: "Feedback on your Dub.co experience?",+ text: "Hey!\n\nI noticed you recently cancelled your Dub.co subscription – we're sorry to see you go!\n\nI'd love to hear your feedback on your experience with Dub – what could we have done better?\n\nThanks!\n\nSteven Tey\nFounder, Dub.co",+ }),+ ),]);}} catch (error) {diff --git a/apps/web/app/app.dub.co/(auth)/layout.tsx b/apps/web/app/app.dub.co/(auth)/layout.tsxindex 337d1548bd..df7a5ad971 100644--- a/apps/web/app/app.dub.co/(auth)/layout.tsx+++ b/apps/web/app/app.dub.co/(auth)/layout.tsx@@ -5,9 +5,11 @@ export const runtime = "edge";export default function AuthLayout({ children }: { children: ReactNode }) {return (- <div className="flex h-screen w-screen justify-center">+ <><Background />- {children}- </div>+ <div className="relative z-10 flex h-screen w-screen justify-center">+ {children}+ </div>+ </>);}diff --git a/apps/web/emails/components/footer.tsx b/apps/web/emails/components/footer.tsxindex d3caf67f70..483baeaa3d 100644--- a/apps/web/emails/components/footer.tsx+++ b/apps/web/emails/components/footer.tsx@@ -7,31 +7,19 @@ export default function Footer({email: string;marketing?: boolean;}) {+ if (marketing) {+ return null;+ }+return (<Tailwind><Hr className="mx-0 my-6 w-full border border-gray-200" />- {marketing ? (- <Text className="text-[12px] leading-6 text-gray-500">- This email was intended for{" "}- <span className="text-black">{email}</span>. If you were not expecting- this email, you can ignore this email. If you don't want to receive- emails like this in the future, you can{" "}- <a- href="https://app.dub.co/settings/unsubscribe"- className="text-gray-600"- >- unsubscribe here- </a>- .- </Text>- ) : (- <Text className="text-[12px] leading-6 text-gray-500">- This email was intended for{" "}- <span className="text-black">{email}</span>. If you were not expecting- this email, you can ignore this email. If you are concerned about your- account's safety, please reply to this email to get in touch with us.- </Text>- )}+ <Text className="text-[12px] leading-6 text-gray-500">+ This email was intended for <span className="text-black">{email}</span>.+ If you were not expecting this email, you can ignore this email. If you+ are concerned about your account's safety, please reply to this email to+ get in touch with us.+ </Text></Tailwind>);}diff --git a/apps/web/emails/index.ts b/apps/web/emails/index.tsindex dfc5efef47..9158e33e6d 100644--- a/apps/web/emails/index.ts+++ b/apps/web/emails/index.ts@@ -1,39 +1,41 @@-import { nanoid } from "@dub/utils";+import { render } from "@react-email/render";+import { Client } from "postmark";import { JSXElementConstructor, ReactElement } from "react";-import { Resend } from "resend";-export const resend = new Resend(process.env.RESEND_API_KEY);+export const client = new Client(process.env.POSTMARK_API_KEY as string);export const sendEmail = async ({email,subject,+ text,react,marketing,- test,}: {email: string;subject: string;- react: ReactElement<any, string | JSXElementConstructor<any>>;+ text?: string;+ react?: ReactElement<any, string | JSXElementConstructor<any>>;marketing?: boolean;- test?: boolean;}) => {- if (!process.env.RESEND_API_KEY) {+ if (!process.env.POSTMARK_API_KEY) {console.log(- "Resend is not configured. You need to add a RESEND_API_KEY in your .env file for emails to work.",+ "Postmark is not configured. You need to add a POSTMARK_API_KEY in your .env file for emails to work.",);return Promise.resolve();}- return resend.emails.send({- from: marketing- ? "Steven from Dub.co <[email protected]>"++ return client.sendEmail({+ From: marketing+ ? "[email protected]": process.env.NEXT_PUBLIC_IS_DUB- ? "Dub.co <[email protected]>"- : `system@${process.env.NEXT_PUBLIC_APP_DOMAIN}`,- to: test ? "[email protected]" : email,- subject,- react,- headers: {- "X-Entity-Ref-ID": nanoid(),- },+ ? "[email protected]"+ : `${process.env.NEXT_PUBLIC_APP_NAME} <system@${process.env.NEXT_PUBLIC_APP_DOMAIN}>`,+ To: email,+ Subject: subject,+ ...(text && { TextBody: text }),+ ...(react && { HtmlBody: render(react) }),+ ...(marketing && {+ MessageStream: "broadcast",+ }),});};diff --git a/apps/web/lib/cron.ts b/apps/web/lib/cron.tsindex 2a62836994..f2cc694b81 100644--- a/apps/web/lib/cron.ts+++ b/apps/web/lib/cron.ts@@ -1,7 +1,6 @@import { Client, Receiver } from "@upstash/qstash";import Bottleneck from "bottleneck";-// we're using Bottleneck to avoid running into Resend's rate limit of 10 req/sexport const limiter = new Bottleneck({maxConcurrent: 1, // maximum concurrent requestsminTime: 100, // minimum time between requests in msdiff --git a/apps/web/package.json b/apps/web/package.jsonindex 093d77648c..83b5eb1dfd 100644--- a/apps/web/package.json+++ b/apps/web/package.json@@ -60,6 +60,7 @@"nodemailer": "^6.9.3","npm": "^9.1.2","openapi-types": "^12.1.3",+ "postmark": "^4.0.2","prisma": "^5.2.0","punycode": "^2.3.0","react": "^18.2.0",@@ -77,7 +78,6 @@"rehype-pretty-code": "^0.9.5","rehype-slug": "^5.1.0","remark-gfm": "^3.0.1",- "resend": "3.2.0","shiki": "^0.14.1","sonner": "^0.5.0","stripe": "^12.12.0",diff --git a/apps/web/scripts/send-emails.tsx b/apps/web/scripts/send-emails.tsxdeleted file mode 100644index 6bc9db5f4a..0000000000--- a/apps/web/scripts/send-emails.tsx+++ /dev/null@@ -1,42 +0,0 @@-import prisma from "@/lib/prisma";-import "dotenv-flow/config";--async function main() {- const users = await prisma.user.findMany({- where: {- projects: {- some: {- project: {- slug: "steven",- },- },- },- },- select: {- name: true,- email: true,- },- });-- const response = await fetch("https://api.resend.com/emails/batch", {- method: "POST",- headers: {- "Content-Type": "application/json",- Authorization: `Bearer ${process.env.RESEND_API_KEY}`,- },- body: JSON.stringify(- users.map(({ name, email }) => {- return {- from: "Steven from Dub <[email protected]>",- to: email,- subject: "Hello from Dub",- text: `Hi ${name},\n\nThis is a test email from Dub.\n\nBest,\nSteven`,- };- }),- ),- }).then((res) => res.json());-- console.log(response);-}--main();diff --git a/apps/web/scripts/utils.ts b/apps/web/scripts/utils.tsindex 47a0dcd592..1faf2cb9e7 100644--- a/apps/web/scripts/utils.ts+++ b/apps/web/scripts/utils.ts@@ -1,6 +1,5 @@import { Redis } from "@upstash/redis";import { customAlphabet } from "nanoid";-import { Resend } from "resend";// Initiate Redis instance by connecting to REST URLexport const redis = new Redis({@@ -8,29 +7,6 @@ export const redis = new Redis({token: process.env.UPSTASH_REDIS_REST_TOKEN || "",});-export const resend = new Resend(process.env.RESEND_API_KEY);--export function linkConstructor({- key,- domain = "dub.sh",- localhost,- pretty,- noDomain,-}: {- key: string;- domain?: string;- localhost?: boolean;- pretty?: boolean;- noDomain?: boolean;-}) {- const link = `${- localhost ? "http://home.localhost:8888" : `https://${domain}`- }${key !== "_root" ? `/${key}` : ""}`;-- if (noDomain) return `/${key}`;- return pretty ? link.replace(/^https?:\/\//, "") : link;-}-export const chunk = <T>(array: T[], chunk_size: number): T[][] => {return array.reduce((resultArray, item, index) => {const chunkIndex = Math.floor(index / chunk_size);diff --git a/apps/web/ui/analytics/feedback/action.ts b/apps/web/ui/analytics/feedback/action.tsindex 0e6fa26e4e..fcf46ba1f8 100644--- a/apps/web/ui/analytics/feedback/action.ts+++ b/apps/web/ui/analytics/feedback/action.ts@@ -1,24 +1,20 @@"use server";-import { nanoid } from "@dub/utils";-import { resend } from "emails";+import { render } from "@react-email/render";+import { client } from "emails";import FeedbackEmail from "emails/feedback-email";export async function submitFeedback(data: FormData) {const email = data.get("email") as string;const feedback = data.get("feedback") as string;- return await resend?.emails.send({- from: "[email protected]",- to: ["[email protected]"],- ...(email && { reply_to: email }),- subject: "🎉 New Feedback Received!",- react: FeedbackEmail({- email,- feedback,- }),- headers: {- "X-Entity-Ref-ID": nanoid(),- },+ const emailHtml = render(FeedbackEmail({ email, feedback }));++ return await client.sendEmail({+ From: "[email protected]",+ To: "[email protected]",+ ...(email && { ReplyTo: email }),+ Subject: "🎉 New Feedback Received!",+ HtmlBody: emailHtml,});}diff --git a/apps/web/ui/analytics/index.tsx b/apps/web/ui/analytics/index.tsxindex f95b8b1b55..fd6f62ff2d 100644--- a/apps/web/ui/analytics/index.tsx+++ b/apps/web/ui/analytics/index.tsx@@ -123,6 +123,7 @@ export default function Analytics({<Devices /><Referer />{isPublicStatsPage && <TopLinks />}+ {/* <Feedback /> */}</div></div></div>diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 64b91945f5..af22dcb419 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -181,6 +181,9 @@ importers:openapi-types:specifier: ^12.1.3version: 12.1.3+ postmark:+ specifier: ^4.0.2+ version: 4.0.2prisma:specifier: ^5.2.0version: 5.2.0@@ -232,9 +235,6 @@ importers:remark-gfm:specifier: ^3.0.1version: 3.0.1- resend:- specifier: 3.2.0- version: 3.2.0shiki:specifier: ^0.14.1version: 0.14.1@@ -7625,6 +7625,16 @@ packages:- debugdev: false+ resolution: {integrity: sha512-/hDJGff6/c7u0hDkvkGxR/oy6CbCs8ziCsC7SqmhjfozqiJGc8Z11wrv9z9lYfY4K8l+H9TpjcMDX0xOZmx+RA==}+ dependencies:+ follow-redirects: 1.15.5+ form-data: 4.0.0+ proxy-from-env: 1.1.0+ transitivePeerDependencies:+ - debug+ dev: false+/[email protected](@babel/[email protected]):resolution: {integrity: sha512-poPX9mZH/5CSanm50Q+1toVci6pv5KSRv/5TWCwtzQS5XEwn40BcCrgIeMFWP9CKKIniKXNxoIOnOq4VVlGXhg==}peerDependencies:@@ -9527,6 +9537,16 @@ packages:optional: truedev: false+ resolution: {integrity: sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==}+ engines: {node: '>=4.0'}+ peerDependencies:+ debug: '*'+ peerDependenciesMeta:+ debug:+ optional: true+ dev: false+resolution: {integrity: sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==}dependencies:@@ -12809,6 +12829,14 @@ packages:xtend: 4.0.2dev: false+ resolution: {integrity: sha512-2zlCv+KVVQ0KoamXZHE7d+gXzLlr8tPE+PxQmtUaIZhbHzZAq4D6yH2b+ykhA8wYCc5ISodcx8U1aNLenXBs9g==}+ dependencies:+ axios: 1.6.7+ transitivePeerDependencies:+ - debug+ dev: false+resolution: {integrity: sha512-JyhErpYOvBV1hEPwIxc/fHWXPfnEGdRKxc8gFdAZ7XV4tlzyzG847XAyEZqoDnynP88akM4eaHcSOzNcLWFguw==}peerDependencies:@@ -13714,13 +13742,6 @@ packages:resolution: {integrity: sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==}dev: false- resolution: {integrity: sha512-lDHhexiFYPoLXy7zRlJ8D5eKxoXy6Tr9/elN3+Vv7PkUoYuSSD1fpiIfa/JYXEWyiyN2UczkCTLpkT8dDPJ4Pg==}- engines: {node: '>=18'}- dependencies:- '@react-email/render': 0.0.12- dev: false-resolution: {integrity: sha512-LwZrotdHOo12nQuZlHEmtuXdqGoOD0OhaxopaNFxWzInpEgaLWoVuAMbTzixuosCx2nEG58ngzW3vxdWoxIgdg==}dev: false