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.

stashed some changes

Steven Tey574c41915ab5
diff --git a/emails/DomainInvalid.tsx b/emails/DomainInvalid.tsx
new file mode 100644
index 0000000000..680d209738
--- /dev/null
+++ b/emails/DomainInvalid.tsx
@@ -0,0 +1,60 @@
+import Head from "./components/Head";
+import Header from "./components/Header";
+import Footer from "./components/Footer";
+import ButtonPrimary from "./components/ButtonPrimary";
+import { leadingRelaxed, textBase, textLg, textSm } from "./components/theme";
+
+import {
+ Mjml,
+ MjmlBody,
+ MjmlSection,
+ MjmlColumn,
+ MjmlText,
+ MjmlSpacer,
+ MjmlDivider,
+} from "mjml-react";
+
+const DomainInvalid = ({
+ domain,
+ projectSlug,
+}: {
+ domain: string;
+ projectSlug: string;
+}): JSX.Element => {
+ return (
+ <Mjml>
+ <Head />
+ <MjmlBody width={500}>
+ <Header title="Invalid Domain Configuration" />
+ <MjmlSection cssClass="smooth">
+ <MjmlColumn>
+ <MjmlText cssClass="paragraph">Hey there!</MjmlText>
+ <MjmlText cssClass="paragraph">
+ We noticed that your domain <code>{domain}</code> for your Dub
+ project{" "}
+ <a href={`https://app.dub.sh/${projectSlug}`} target="_blank">
+ {projectSlug}↗
+ </a>{" "}
+ has been invalid for 25 days.
+ </MjmlText>
+ <MjmlText cssClass="paragraph">
+ If your domain remains unconfigured for 30 days, your project will
+ be automatically deleted.
+ </MjmlText>
+ <ButtonPrimary
+ link={`https://app.dub.sh/${projectSlug}/settings`}
+ uiText="Configure my domain"
+ />
+ <MjmlText cssClass="paragraph">
+ If you do not want to keep this project on Dub, you can safely
+ ignore this email.
+ </MjmlText>
+ </MjmlColumn>
+ </MjmlSection>
+ <Footer />
+ </MjmlBody>
+ </Mjml>
+ );
+};
+
+export default DomainInvalid;
diff --git a/emails/LoginLink.tsx b/emails/LoginLink.tsx
new file mode 100644
index 0000000000..a08d44fd05
--- /dev/null
+++ b/emails/LoginLink.tsx
@@ -0,0 +1,80 @@
+import Head from "./components/Head";
+import Header from "./components/Header";
+import Footer from "./components/Footer";
+import ButtonPrimary from "./components/ButtonPrimary";
+import { leadingRelaxed, textBase, textSm } from "./components/theme";
+
+import {
+ Mjml,
+ MjmlBody,
+ MjmlSection,
+ MjmlColumn,
+ MjmlText,
+ MjmlSpacer,
+ MjmlDivider,
+} from "mjml-react";
+
+const LoginLink = ({ url }: { url: string }): JSX.Element => {
+ return (
+ <Mjml>
+ <Head />
+ <MjmlBody width={400}>
+ <Header title="Your Login Link" />
+ <MjmlSection padding="0" cssClass="smooth">
+ <MjmlColumn>
+ <MjmlText
+ padding="8px 0"
+ fontSize={textSm}
+ lineHeight={leadingRelaxed}
+ >
+ Welcome to Dub!
+ </MjmlText>
+ <MjmlText
+ padding="8px 0"
+ fontSize={textSm}
+ lineHeight={leadingRelaxed}
+ >
+ Please click the magic link below to sign in to your account.
+ </MjmlText>
+ <ButtonPrimary link={url} uiText="Sign In" />
+ <MjmlText
+ cssClass="paragraph"
+ padding="8px 0"
+ fontSize={textSm}
+ lineHeight={leadingRelaxed}
+ >
+ You can also copy the link below and paste it into the browser of
+ your choice.
+ </MjmlText>
+ <MjmlSpacer height="8px" />
+ <MjmlText
+ cssClass="paragraph"
+ padding="10px 0"
+ fontSize={textSm}
+ lineHeight={leadingRelaxed}
+ >
+ {url.replace(/^https?:\/\//, "")}
+ </MjmlText>
+ <MjmlDivider
+ borderColor="#666"
+ borderStyle="dotted"
+ borderWidth="1px"
+ padding="16px 0 0"
+ ></MjmlDivider>
+ <MjmlText
+ padding="16px 0"
+ fontSize={textSm}
+ lineHeight={leadingRelaxed}
+ cssClass="paragraph"
+ >
+ If you did not request this email you can safely ignore it.
+ </MjmlText>
+ </MjmlColumn>
+ </MjmlSection>
+ <Footer />
+ </MjmlBody>
+ </Mjml>
+ );
+};
+
+export default LoginLink;
diff --git a/emails/components/ButtonPrimary.tsx b/emails/components/ButtonPrimary.tsx
index 08ff8fbbbc..21f9cfefd7 100644
--- a/emails/components/ButtonPrimary.tsx
+++ b/emails/components/ButtonPrimary.tsx
@@ -1,6 +1,6 @@
import { MjmlButton } from "mjml-react";
-import { black, gold, grayLight } from "./theme";
-import { leadingTight, textBase, borderBase } from "./theme";
+import { black, white, grayLight } from "./theme";
+import { leadingTight, textSm, borderBase } from "./theme";
type ButtonPrimaryProps = {
link: string;
@@ -9,36 +9,9 @@ type ButtonPrimaryProps = {
const ButtonPrimary: React.FC<ButtonPrimaryProps> = ({ link, uiText }) => {
return (
- <>
- <MjmlButton
- lineHeight={leadingTight}
- fontSize={textBase}
- height={32}
- padding="0"
- align="left"
- href={link}
- backgroundColor={black}
- color={grayLight}
- borderRadius={borderBase}
- cssClass="light-mode"
- >
- {uiText}
- </MjmlButton>
- <MjmlButton
- lineHeight={leadingTight}
- fontSize={textBase}
- height={32}
- padding="0"
- align="left"
- href={link}
- backgroundColor={gold}
- color={black}
- borderRadius={borderBase}
- cssClass="dark-mode"
- >
- {uiText}
- </MjmlButton>
- </>
+ <MjmlButton href={link} cssClass="button">
+ {uiText}
+ </MjmlButton>
);
};
diff --git a/emails/components/Footer.tsx b/emails/components/Footer.tsx
index ec0f23c3bb..7f43ef7744 100644
--- a/emails/components/Footer.tsx
+++ b/emails/components/Footer.tsx
@@ -1,20 +1,20 @@
import { MjmlSection, MjmlColumn, MjmlText } from "mjml-react";
import { grayDark, textSm } from "./theme";
-export default function Footer() {
+export default function Footer({ unsubscribe }: { unsubscribe?: boolean }) {
return (
<MjmlSection cssClass="smooth">
<MjmlColumn>
- <MjmlText
- cssClass="footer"
- padding="24px 24px 48px"
- fontSize={textSm}
- color={grayDark}
- >
- © 2022 BookBook&nbsp;&nbsp;·&nbsp;&nbsp;
- <a href="#" target="_blank">
- Unsubscribe
- </a>
+ <MjmlText cssClass="footer" fontSize={textSm} color={grayDark}>
+ © {new Date().getFullYear()} Dub.sh
+ {unsubscribe && (
+ <>
+ &nbsp;&nbsp;·&nbsp;&nbsp;
+ <a href="{{{ pm:unsubscribe }}}" target="_blank">
+ Unsubscribe
+ </a>
+ </>
+ )}
</MjmlText>
</MjmlColumn>
</MjmlSection>
diff --git a/emails/components/Head.tsx b/emails/components/Head.tsx
index 06f7d81428..6653bcca38 100644
--- a/emails/components/Head.tsx
+++ b/emails/components/Head.tsx
@@ -7,7 +7,15 @@ import {
MjmlStyle,
MjmlRaw,
} from "mjml-react";
-import { black, grayDark } from "./theme";
+import {
+ black,
+ blue,
+ borderBase,
+ grayDark,
+ grayLight,
+ purple,
+ textSm,
+} from "./theme";
type HeadProps = { children?: ReactElement };
@@ -21,7 +29,7 @@ const Head: React.FC<HeadProps> = ({ children }) => {
</MjmlRaw>
<MjmlFont
name="Inter"
- href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700"
+ href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700"
/>
<MjmlStyle>{`
strong {
@@ -30,20 +38,41 @@ const Head: React.FC<HeadProps> = ({ children }) => {
.smooth {
-webkit-font-smoothing: antialiased;
}
+ .title > * {
+ font-weight: 400 !important;
+ font-size: 24px !important;
+ }
+ .paragraph > * {
+ font-size: 14px !important;
+ line-height: 24px !important;
+ }
.paragraph a {
- color: ${black} !important;
+ color: ${blue} !important;
+ text-decoration: none;
+ }
+ .paragraph code {
+ color: ${purple} !important;
}
.li {
text-indent: -18px;
margin-left: 24px;
display: inline-block;
}
+ .footer {
+ padding: 24px 24px 48px !important;
+ border-top: 1px solid ${grayDark};
+ }
.footer a {
text-decoration: none !important;
color: ${grayDark} !important;
}
- .dark-mode {
- display: none;
+ .button {
+ border-radius: 3rem !important;
+ color: ${black} !important;
+ align-items: left !important;
+ height: 32px !important;
+ font-weight: 600 !important;
+ font-size: ${textSm} !important;
}
@media (min-width:480px) {
td.hero {
@@ -58,7 +87,10 @@ const Head: React.FC<HeadProps> = ({ children }) => {
.logo > * {
filter: invert(1) !important;
}
- .paragraph > *, .paragraph a, .li > div {
+ .title > * {
+ color: #fff !important;
+ }
+ .paragraph > * {
color: #fff !important;
}
.dark-mode {
@@ -70,10 +102,7 @@ const Head: React.FC<HeadProps> = ({ children }) => {
}
`}</MjmlStyle>
<MjmlAttributes>
- <MjmlAll
- font-family='Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'
- font-weight="400"
- />
+ <MjmlAll font-family='Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif' />
</MjmlAttributes>
{children}
</>
diff --git a/emails/components/Header.tsx b/emails/components/Header.tsx
index bdacc61fe7..67aeafdaa8 100644
--- a/emails/components/Header.tsx
+++ b/emails/components/Header.tsx
@@ -1,21 +1,20 @@
-import { MjmlSection, MjmlColumn, MjmlImage } from "mjml-react";
+import { MjmlSection, MjmlColumn, MjmlImage, MjmlText } from "mjml-react";
-type HeaderProps = {
- loose?: boolean;
-};
-
-const Header: React.FC<HeaderProps> = ({ loose }) => {
+const Header = ({ title }: { title: string }) => {
return (
- <MjmlSection padding={loose ? "48px 0 40px" : "48px 0 24px"}>
+ <MjmlSection>
<MjmlColumn>
<MjmlImage
- padding="0 24px 0"
- width="49px"
- height="54px"
+ padding="32px 0"
+ width="44px"
+ height="44px"
align="center"
- src="https://s3.amazonaws.com/lab.campsh.com/bb-transparent%402x.png"
+ src="https://dub.sh/static/logo.png"
cssClass="logo"
/>
+ <MjmlText cssClass="title" align="center">
+ {title}
+ </MjmlText>
</MjmlColumn>
</MjmlSection>
);
diff --git a/emails/components/theme.ts b/emails/components/theme.ts
index 1dadf6af2d..f8ab9bab18 100644
--- a/emails/components/theme.ts
+++ b/emails/components/theme.ts
@@ -1,5 +1,8 @@
// Colors
export const black = "#000";
+export const white = "#fff";
+export const purple = "#bd11e0";
+export const blue = "#2563EB";
export const gold = "#fadf98";
export const grayDark = "#888";
export const grayLight = "#f5f5f5";
diff --git a/emails/index.ts b/emails/index.ts
index bf398f8d38..3aedfa51fe 100644
--- a/emails/index.ts
+++ b/emails/index.ts
@@ -1,19 +1,30 @@
import nodemailer from "nodemailer";
import { buildSendMail } from "mailing-core";
-const transport = nodemailer.createTransport({
- host: process.env.EMAIL_HOST,
+const transportConfig = {
port: 587,
auth: {
- user: process.env.EMAIL_USER,
- pass: process.env.EMAIL_PASS,
+ user: process.env.POSTMARK_API_KEY,
+ pass: process.env.POSTMARK_API_KEY,
},
-});
+};
const sendMail = buildSendMail({
- transport,
- defaultFrom: "[email protected]",
+ transport: nodemailer.createTransport({
+ host: "smtp.postmarkapp.com",
+ ...transportConfig,
+ }),
+ defaultFrom: "[email protected]",
configPath: "./mailing.config.json",
});
export default sendMail;
+
+export const sendMarketingMail = buildSendMail({
+ transport: nodemailer.createTransport({
+ host: "smtp-broadcasts.postmarkapp.com",
+ ...transportConfig,
+ }),
+ defaultFrom: "[email protected]",
+ configPath: "./mailing.config.json",
+});
diff --git a/emails/previews/Account.tsx b/emails/previews/Account.tsx
new file mode 100644
index 0000000000..d60122de3d
--- /dev/null
+++ b/emails/previews/Account.tsx
@@ -0,0 +1,12 @@
+import Login from "../LoginLink";
+import AccountCreated from "../AccountCreated";
+
+export function LoginLink() {
+ return (
+ <Login url="http://app.localhost:3000/api/auth/callback/email?callbackUrl=http%3A%2F%2Fapp.localhost%3A3000%2Flogin&token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&[email protected]" />
+ );
+}
+
+export function accountCreated() {
+ return <AccountCreated name="Steven" />;
+}
diff --git a/emails/previews/AccountCreated.tsx b/emails/previews/AccountCreated.tsx
deleted file mode 100644
index 2d6755ac92..0000000000
--- a/emails/previews/AccountCreated.tsx
+++ /dev/null
@@ -1,5 +0,0 @@
-import AccountCreated from "../AccountCreated";
-
-export function accountCreated() {
- return <AccountCreated name="Steven" />;
-}
diff --git a/emails/previews/NewSignIn.tsx b/emails/previews/NewSignIn.tsx
deleted file mode 100644
index 2930fd10bd..0000000000
--- a/emails/previews/NewSignIn.tsx
+++ /dev/null
@@ -1,29 +0,0 @@
-import NewSignIn from "../NewSignIn";
-import BulletedList from "../components/BulletedList";
-
-export function newSignIn() {
- return (
- <NewSignIn
- headline="Security Alert: New Sign-In"
- name="Amelita"
- body={
- <>
- We noticed a new sign-in to your BookBook account on a Mac device. If
- this was you, you don’t need to do anything. If not, please reply to
- this email and we’ll help you secure your account.
- </>
- }
- bulletedList={
- <BulletedList
- items={[
- "Date: July 14, 2022 4:26 PM PST",
- "Device: Mac",
- "Browser: Safari",
- "Location: Los Angeles, CA",
- "IP Address: XXX.XX.XXX.XX",
- ]}
- />
- }
- />
- );
-}
diff --git a/emails/previews/Notifications.tsx b/emails/previews/Notifications.tsx
new file mode 100644
index 0000000000..bb1705f9ac
--- /dev/null
+++ b/emails/previews/Notifications.tsx
@@ -0,0 +1,5 @@
+import DomainInvalid from "../DomainInvalid";
+
+export function InvalidDomain() {
+ return <DomainInvalid domain="google.com" projectSlug="google" />;
+}
diff --git a/emails/previews/Reservation.tsx b/emails/previews/Reservation.tsx
deleted file mode 100644
index ef8dbee9cc..0000000000
--- a/emails/previews/Reservation.tsx
+++ /dev/null
@@ -1,74 +0,0 @@
-import Reservation from "../Reservation";
-import BulletedList from "../components/BulletedList";
-
-export function reservationCanceled() {
- return (
- <Reservation
- headline="Reservation Canceled"
- bulletedList={
- <BulletedList
- items={[
- "Salazar in Silver Lake",
- "Sunday, Aug 22 at 1:30pm",
- "Party of 4, patio",
- ]}
- />
- }
- body={
- <>
- If this was a mistake or if you changed your mind, you can use the
- link below to rebook your reservation.
- </>
- }
- ctaText={"Rebook Now"}
- />
- );
-}
-
-export function reservationConfirmed() {
- return (
- <Reservation
- headline="Reservation Confirmed"
- bulletedList={
- <BulletedList
- items={[
- "Salazar in Silver Lake",
- "Saturday, Aug 22 at 1:30pm",
- "Party of 4, patio",
- ]}
- />
- }
- body={
- <>
- Thanks for booking your reservation at Salazar with BookBook! If you
- need to cancel or make any changes, just click the link above.
- </>
- }
- ctaText={"View Reservation"}
- />
- );
-}
-
-export function reservationChanged() {
- return (
- <Reservation
- headline="Reservation Changed"
- bulletedList={
- <BulletedList
- items={[
- "Salazar in Silver Lake",
- "Sunday, Aug 22 at 1:30pm",
- "Party of 4, patio",
- ]}
- />
- }
- body={
- <>
- You’re all set! Your reservation at Salazar has been successfully
- changed. If you have any questions, please reply to this email.
- </>
- }
- ctaText={"View Reservation"}
- />
- );
-}
diff --git a/emails/previews/ResetPassword.tsx b/emails/previews/ResetPassword.tsx
deleted file mode 100644
index 6c6e780b75..0000000000
--- a/emails/previews/ResetPassword.tsx
+++ /dev/null
@@ -1,18 +0,0 @@
-import ResetPassword from "../ResetPassword";
-
-export function resetPassword() {
- return (
- <ResetPassword
- name="Amelita"
- body={
- <>
- We’ve received your request to change your password. Use the link
- below to set up a new password for your account. This link is only
- usable once! If you need to, you can reinitiate the password process
- again <a href="#">here</a>.
- </>
- }
- ctaText="Reset Password"
- />
- );
-}
diff --git a/lib/cron.ts b/lib/cron.tsx
similarity index 88%
rename from lib/cron.ts
rename to lib/cron.tsx
index f0b8d1b244..97f6d50c5e 100644
--- a/lib/cron.ts
+++ b/lib/cron.tsx
@@ -1,8 +1,10 @@
import prisma from "@/lib/prisma";
import { redis, deleteProject, getUsage } from "@/lib/upstash";
import { removeDomain } from "./domains";
+import sendMail from "emails";
export const handleDomainUpdates = async (
+ projectId: string,
domain: string,
createdAt: Date,
verified: boolean,
@@ -20,6 +22,27 @@ export const handleDomainUpdates = async (
if (invalidDays > 25) {
await log(`Domain *${domain}* is invalid for ${invalidDays} days`);
+ const owner = await prisma.project.findUnique({
+ where: { id: projectId },
+ select: {
+ users: {
+ where: {
+ role: "owner",
+ },
+ select: {
+ user: {
+ select: {
+ email: true,
+ },
+ },
+ },
+ },
+ },
+ });
+ sendMail({
+ subject: "Your Dub.sh Login Link",
+ to: "email.com",
+ });
}
if (invalidDays > 30) {
diff --git a/pages/api/auth/[...nextauth].ts b/pages/api/auth/[...nextauth].tsx
similarity index 79%
rename from pages/api/auth/[...nextauth].ts
rename to pages/api/auth/[...nextauth].tsx
index 44f5b56d15..4f616c0590 100644
--- a/pages/api/auth/[...nextauth].ts
+++ b/pages/api/auth/[...nextauth].tsx
@@ -2,14 +2,21 @@ import NextAuth, { type NextAuthOptions } from "next-auth";
import EmailProvider from "next-auth/providers/email";
import { PrismaAdapter } from "@next-auth/prisma-adapter";
import prisma from "@/lib/prisma";
+import sendMail from "emails";
+import LoginLink from "emails/LoginLink";
const VERCEL_DEPLOYMENT = !!process.env.VERCEL_URL;
export const authOptions: NextAuthOptions = {
providers: [
EmailProvider({
- server: process.env.EMAIL_SERVER,
- from: process.env.EMAIL_FROM,
+ sendVerificationRequest({ identifier, url }) {
+ sendMail({
+ subject: "Your Dub.sh Login Link",
+ to: identifier,
+ component: <LoginLink url={url} />,
+ });
+ },
}),
],
adapter: PrismaAdapter(prisma),
diff --git a/pages/api/cron/domains.ts b/pages/api/cron/domains.ts
index cb6277ae7c..0c0a57148a 100644
--- a/pages/api/cron/domains.ts
+++ b/pages/api/cron/domains.ts
@@ -19,6 +19,7 @@ async function handler(_req: NextApiRequest, res: NextApiResponse) {
try {
const projects = await prisma.project.findMany({
select: {
+ id: true,
domain: true,
domainVerified: true,
createdAt: true,
@@ -67,6 +68,7 @@ async function handler(_req: NextApiRequest, res: NextApiResponse) {
const changed = newDomainVerified !== domainVerified;
const updates = await handleDomainUpdates(
+ project.id,
domain,
createdAt,
newDomainVerified,