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.

updated cron jobs

Steven Tey62264702efe4
diff --git a/.gitignore b/.gitignore
index 714d55c33c..2fdf95f790 100644
--- a/.gitignore
+++ b/.gitignore
@@ -37,4 +37,5 @@ yarn-error.log*
next-env.d.ts
/pages/api/scripts*
+deleted-projects.json
.mailing
diff --git a/components/app/domains/no-domains-placeholder.tsx b/components/app/domains/no-domains-placeholder.tsx
new file mode 100644
index 0000000000..8b94f3ba04
--- /dev/null
+++ b/components/app/domains/no-domains-placeholder.tsx
@@ -0,0 +1,23 @@
+import BlurImage from "@/components/shared/blur-image";
+
+export default function NoDomainsPlaceholder({
+ AddEditDomainButton,
+}: {
+ AddEditDomainButton: () => JSX.Element;
+}) {
+ return (
+ <div className="flex flex-col items-center justify-center rounded-md border border-gray-200 bg-white py-12">
+ <h2 className="z-10 text-xl font-semibold text-gray-700">
+ You don't have any domains yet.
+ </h2>
+ <BlurImage
+ src="/_static/illustrations/call-waiting.svg"
+ alt="No domains yet"
+ width={400}
+ height={400}
+ className="pointer-events-none -my-8"
+ />
+ <AddEditDomainButton />
+ </div>
+ );
+}
diff --git a/components/app/settings/plan-badge.tsx b/components/app/settings/plan-badge.tsx
index 165aa18a10..2c4a31c85c 100644
--- a/components/app/settings/plan-badge.tsx
+++ b/components/app/settings/plan-badge.tsx
@@ -1,8 +1,6 @@
-export default function PlanBadge({
- plan,
-}: {
- plan: "free" | "pro" | "enterprise";
-}) {
+import { PlanProps } from "@/lib/types";
+
+export default function PlanBadge({ plan }: { plan: PlanProps }) {
return (
<span
className={`capitalize ${
diff --git a/components/home/pricing.tsx b/components/home/pricing.tsx
index 0eac5d05b3..e0876e4ae7 100644
--- a/components/home/pricing.tsx
+++ b/components/home/pricing.tsx
@@ -38,6 +38,7 @@ const pricingItems = [
negative: true,
},
{ text: "SSO/SAML", negative: true },
+ { text: "Priority support", negative: true },
],
cta: "Start for free",
},
@@ -62,6 +63,7 @@ const pricingItems = [
"Redirect vistors that land on the root of your domain (e.g. yourdomain.com) to a page of your choice.",
},
{ text: "SSO/SAML", negative: true },
+ { text: "Priority support", negative: true },
],
cta: "Get started",
},
@@ -85,7 +87,11 @@ const pricingItems = [
footnote:
"Redirect vistors that land on the root of your domain (e.g. yourdomain.com) to a page of your choice.",
},
- { text: "SSO/SAML" },
+ { text: "SSO/SAML", footnote: "Under development. ETA: Q4 2023" },
+ {
+ text: "Priority support",
+ footnote: "Email & chat support within 24 hours.",
+ },
],
cta: "Get started",
},
diff --git a/components/layout/app/project-select.tsx b/components/layout/app/project-select.tsx
index 6ec117bc91..b12b645e36 100644
--- a/components/layout/app/project-select.tsx
+++ b/components/layout/app/project-select.tsx
@@ -5,7 +5,7 @@ import { useAddProjectModal } from "@/components/app/modals/add-project-modal";
import BlurImage from "@/components/shared/blur-image";
import { ChevronUpDown, PlusCircle, Tick } from "@/components/shared/icons";
import Popover from "@/components/shared/popover";
-import { ProjectWithDomainProps } from "@/lib/types";
+import { PlanProps, ProjectWithDomainProps } from "@/lib/types";
import useProjects from "@/lib/swr/use-projects";
import PlanBadge from "@/components/app/settings/plan-badge";
@@ -45,7 +45,7 @@ export default function ProjectSelect() {
name: string;
slug: string;
image: string;
- plan: "free" | "pro" | "enterprise";
+ plan: PlanProps;
};
const [openPopover, setOpenPopover] = useState(false);
@@ -104,7 +104,7 @@ function ProjectList({
name: string;
slug: string;
image: string;
- plan: "free" | "pro" | "enterprise";
+ plan: PlanProps;
};
projects: ProjectWithDomainProps[];
setShowAddProjectModal?: (show: boolean) => void;
diff --git a/emails/ProjectDeleted.tsx b/emails/DomainDeleted.tsx
similarity index 79%
rename from emails/ProjectDeleted.tsx
rename to emails/DomainDeleted.tsx
index fb9e423af9..3a5ae6bb60 100644
--- a/emails/ProjectDeleted.tsx
+++ b/emails/DomainDeleted.tsx
@@ -13,7 +13,7 @@ import Head from "./components/Head";
import Header from "./components/Header";
import { grayDark, purple } from "./components/theme";
-export default function ProjectDeleted({
+export default function DomainDeleted({
domain,
projectSlug,
}: {
@@ -25,7 +25,7 @@ export default function ProjectDeleted({
<Head />
<MjmlBody width={500}>
<MjmlWrapper cssClass="container">
- <Header title="Project Deleted" />
+ <Header title="Domain Deleted" />
<MjmlSection cssClass="smooth">
<MjmlColumn>
<MjmlText cssClass="paragraph">Hey there!</MjmlText>
@@ -46,20 +46,20 @@ export default function ProjectDeleted({
<a href={`https://app.dub.sh/${projectSlug}`} target="_blank">
{projectSlug}↗
</a>{" "}
- has been invalid for 30 days. As a result, your project has been
- deleted from Dub.
+ has been invalid for 30 days. As a result, it has been deleted
+ from Dub.
</MjmlText>
<MjmlText cssClass="paragraph">
- If you would like to restore the project, you can easily create
+ If you would like to restore the domain, you can easily create
it again on Dub with the link below.
</MjmlText>
<ButtonPrimary
- link={`https://app.dub.sh/`}
- uiText="Create a new project"
+ link={`https://app.dub.sh/${projectSlug}/domains`}
+ uiText="Add a domain"
/>
<MjmlText cssClass="paragraph">
- If you did not want to keep this project on Dub anyway, you can
- simply ignore this email.
+ If you did not want to keep using this domain on Dub anyway, you
+ can simply ignore this email.
</MjmlText>
<MjmlText cssClass="paragraph" color={grayDark}>
Steven from Dub
diff --git a/emails/InvalidDomain.tsx b/emails/InvalidDomain.tsx
index 0e9ca56527..37fc567ab5 100644
--- a/emails/InvalidDomain.tsx
+++ b/emails/InvalidDomain.tsx
@@ -51,18 +51,18 @@ export default function InvalidDomain({
has been invalid for {invalidDays} days.
</MjmlText>
<MjmlText cssClass="paragraph">
- If your domain remains unconfigured for 30 days, your project
- will be automatically deleted. Please click the link below to
+ If your domain remains unconfigured for 30 days, it will be
+ automatically deleted from Dub. Please click the link below to
configure your domain.
</MjmlText>
<ButtonPrimary
- link={`https://app.dub.sh/${projectSlug}/settings`}
+ link={`https://app.dub.sh/${projectSlug}/domains`}
uiText="Configure my domain"
/>
<MjmlText cssClass="paragraph">
- If you do not want to keep this project on Dub, you can{" "}
+ If you do not want to keep this domain on Dub, you can{" "}
<a
- href={`https://app.dub.sh/${projectSlug}/settings`}
+ href={`https://app.dub.sh/${projectSlug}/domains`}
target="_blank"
>
delete it
diff --git a/emails/UsageExceeded.tsx b/emails/UsageExceeded.tsx
index 4913e188e6..e303d08a3d 100644
--- a/emails/UsageExceeded.tsx
+++ b/emails/UsageExceeded.tsx
@@ -6,24 +6,23 @@ import {
MjmlText,
MjmlWrapper,
} from "mjml-react";
-import { getPlanFromUsageLimit } from "@/lib/stripe/constants";
-import { nFormatter } from "@/lib/utils";
+import { capitalize, nFormatter } from "@/lib/utils";
import ButtonPrimary from "./components/ButtonPrimary";
import Divider from "./components/Divider";
import Footer from "./components/Footer";
import Head from "./components/Head";
import Header from "./components/Header";
import { grayDark } from "./components/theme";
+import { ProjectProps } from "@/lib/types";
export default function UsageExceeded({
- usage,
- usageLimit,
+ project,
type,
}: {
- usage: number;
- usageLimit: number;
+ project: ProjectProps;
type: "first" | "second";
}): JSX.Element {
+ const { slug, name, usage, usageLimit, plan } = project;
return (
<Mjml>
<Head />
@@ -34,9 +33,9 @@ export default function UsageExceeded({
<MjmlColumn>
<MjmlText cssClass="paragraph">Hey there!</MjmlText>
<MjmlText cssClass="paragraph">
- Just wanted to reach out and let you know that your account has
- exceeded the
- <strong> {getPlanFromUsageLimit(usageLimit)} Plan </strong>
+ Just wanted to reach out and let you know that your project,{" "}
+ <strong> {name} </strong> has exceeded the
+ <strong> {capitalize(plan)} Plan </strong>
limit of <strong>{nFormatter(usageLimit)} link clicks</strong>.
You have used{" "}
<strong>{nFormatter(usage, 2)} link clicks</strong> across all
@@ -48,14 +47,14 @@ export default function UsageExceeded({
their stats, edit them, or add more links.
</MjmlText>
<ButtonPrimary
- link={`https://app.dub.sh/settings`}
+ link={`https://app.dub.sh/${slug}/settings/billing`}
uiText="Upgrade my plan"
/>
<MjmlText cssClass="paragraph">
To respect your inbox,{" "}
{type === "first"
? "I will only send you one more email about this in 3 days"
- : "this will be the last time I'll email you about this"}
+ : "this will be the last time I'll email you about this for the current billing cycle"}
. Feel free to ignore this email if you don't plan on upgrading,
or reply to let me know if you have any questions!
</MjmlText>
diff --git a/emails/previews/Notifications.tsx b/emails/previews/Notifications.tsx
index 6989fbf60f..3a5d0ee6bc 100644
--- a/emails/previews/Notifications.tsx
+++ b/emails/previews/Notifications.tsx
@@ -1,6 +1,6 @@
import { default as FeedbackEmailChild } from "../FeedbackEmail";
import { default as InvalidDomainEmail } from "../InvalidDomain";
-import { default as ProjectDeletedEmail } from "../ProjectDeleted";
+import { default as DomainDeletedEmail } from "../DomainDeleted";
import { default as UsageExceededEmail } from "../UsageExceeded";
export function InvalidDomain() {
@@ -13,12 +13,24 @@ export function InvalidDomain() {
);
}
-export function ProjectDeleted() {
- return <ProjectDeletedEmail domain="google.com" projectSlug="google" />;
+export function DomainDeleted() {
+ return <DomainDeletedEmail domain="google.com" projectSlug="google" />;
}
export function UsageExceeded() {
- return <UsageExceededEmail usage={2406} usageLimit={1000} type="first" />;
+ return (
+ <UsageExceededEmail
+ project={{
+ id: "123",
+ name: "Steven Tey",
+ slug: "steven",
+ plan: "free",
+ usage: 2406,
+ usageLimit: 1000,
+ }}
+ type="first"
+ />
+ );
}
export function FeedbackEmail() {
diff --git a/lib/auth.ts b/lib/auth.ts
index 5d81f2f4d6..5829f4cae8 100644
--- a/lib/auth.ts
+++ b/lib/auth.ts
@@ -1,7 +1,7 @@
import { NextApiRequest, NextApiResponse } from "next";
import { unstable_getServerSession } from "next-auth/next";
import prisma from "@/lib/prisma";
-import { ProjectProps, UserProps } from "@/lib/types";
+import { PlanProps, ProjectProps, UserProps } from "@/lib/types";
import { authOptions } from "@/pages/api/auth/[...nextauth]";
export interface Session {
@@ -36,7 +36,7 @@ const withProjectAuth =
needNotExceededUsage, // if the action needs the user to not have exceeded their usage
}: {
excludeGet?: boolean;
- requiredPlan?: Array<"free" | "pro" | "enterprise">;
+ requiredPlan?: Array<PlanProps>;
needNotExceededUsage?: boolean;
} = {},
) =>
diff --git a/lib/cron/domains.tsx b/lib/cron/domains.tsx
index 0b502ef3c7..d06ae98559 100644
--- a/lib/cron/domains.tsx
+++ b/lib/cron/domains.tsx
@@ -1,18 +1,24 @@
import sendMail from "emails";
import InvalidDomain from "emails/InvalidDomain";
-import ProjectDeleted from "emails/ProjectDeleted";
+import DomainDeleted from "emails/DomainDeleted";
import { log } from "@/lib/utils";
import { removeDomain } from "@/lib/api/domains";
import prisma from "@/lib/prisma";
-import { deleteProjectLinks } from "@/lib/api/links";
-import { getClicksUsage } from "@/lib/tinybird";
+import { redis } from "../upstash";
-export const handleDomainUpdates = async (
- domain: string,
- createdAt: Date,
- verified: boolean,
- changed: boolean,
-) => {
+export const handleDomainUpdates = async ({
+ domain,
+ createdAt,
+ verified,
+ changed,
+ linksCount,
+}: {
+ domain: string;
+ createdAt: Date;
+ verified: boolean;
+ changed: boolean;
+ linksCount: number;
+}) => {
if (changed) {
await log(`Domain *${domain}* changed status to *${verified}*`, "cron");
}
@@ -23,64 +29,118 @@ export const handleDomainUpdates = async (
(new Date().getTime() - new Date(createdAt).getTime()) / (1000 * 3600 * 24),
);
- if (invalidDays >= 14 && invalidDays < 28) {
- const sentFirstDomainInvalidEmail = sentEmails.includes(
- "firstDomainInvalidEmail",
- );
- if (!sentFirstDomainInvalidEmail) {
- sendDomainInvalidEmail(projectSlug, domain, invalidDays, "first");
- }
- } else if (invalidDays >= 28) {
- const sentSecondDomainInvalidEmail = sentEmails.includes(
- "secondDomainInvalidEmail",
- );
- if (!sentSecondDomainInvalidEmail) {
- sendDomainInvalidEmail(projectSlug, domain, invalidDays, "second");
- }
- }
+ // do nothing if domain is invalid for less than 14 days
+ if (invalidDays < 14) return;
+ const project = await prisma.project.findFirst({
+ where: {
+ domains: {
+ some: {
+ slug: domain,
+ },
+ },
+ },
+ select: {
+ slug: true,
+ sentEmails: true,
+ users: {
+ where: {
+ role: "owner",
+ },
+ select: {
+ user: {
+ select: {
+ email: true,
+ },
+ },
+ },
+ },
+ },
+ });
+ const projectSlug = project.slug;
+ const sentEmails = project.sentEmails.map((email) => email.type);
+ const ownerEmail = project.users[0].user.email;
+
+ // if domain is invalid for more than 30 days, check if we can delete it
if (invalidDays >= 30) {
- const clicks = await getClicksUsage({ domain });
- // only delete if there are no clicks recorded in Tinybird
- if (clicks === 0) {
- const ownerEmail = await getProjectOwnerEmail(projectSlug);
+ // only delete if there are no links associated with the domain
+ if (linksCount === 0) {
return await Promise.all([
- prisma.project.delete({
+ removeDomain(domain), // remove domain from Vercel project
+ redis.del(`root:${domain}`), // there are no links anyway, so you can just delete the root domain from redis if exists
+ prisma.domain.delete({
where: {
- domain,
+ slug: domain,
},
}),
- removeDomain(domain),
- deleteProjectLinks(domain),
log(
`Domain *${domain}* has been invalid for > 30 days, deleting.`,
"cron",
),
sendMail({
- subject: `Your project ${projectSlug} has been deleted`,
+ subject: `Your domain ${domain} has been deleted`,
to: ownerEmail,
component: (
- <ProjectDeleted domain={domain} projectSlug={projectSlug} />
+ <DomainDeleted domain={domain} projectSlug={projectSlug} />
),
}),
]);
} else {
- return await log(
- `Domain *${domain}* has been invalid for > 30 days but has link clicks, not deleting.`,
+ console.log(
+ `Domain *${domain}* has been invalid for > 30 days but has links, not deleting.`,
"cron",
);
}
+ return;
+ }
+
+ if (invalidDays >= 28) {
+ const sentSecondDomainInvalidEmail = sentEmails.includes(
+ "secondDomainInvalidEmail",
+ );
+ if (!sentSecondDomainInvalidEmail) {
+ sendDomainInvalidEmail({
+ projectSlug,
+ domain,
+ invalidDays,
+ ownerEmail,
+ type: "second",
+ });
+ }
+ return;
+ }
+
+ if (invalidDays >= 14) {
+ const sentFirstDomainInvalidEmail = sentEmails.includes(
+ "firstDomainInvalidEmail",
+ );
+ if (!sentFirstDomainInvalidEmail) {
+ sendDomainInvalidEmail({
+ projectSlug,
+ domain,
+ invalidDays,
+ ownerEmail,
+ type: "first",
+ });
+ }
+ return;
}
return;
};
-const sendDomainInvalidEmail = async (
- projectSlug: string,
- domain: string,
- invalidDays: number,
- type: "first" | "second",
-) => {
- const ownerEmail = await getProjectOwnerEmail(projectSlug);
+const sendDomainInvalidEmail = async ({
+ projectSlug,
+ domain,
+ invalidDays,
+ ownerEmail,
+ type,
+}: {
+ projectSlug: string;
+ domain: string;
+ invalidDays: number;
+ ownerEmail: string;
+ type: "first" | "second";
+}) => {
return await Promise.all([
log(
`Domain *${domain}* is invalid for ${invalidDays} days, email sent.`,
@@ -109,24 +169,3 @@ const sendDomainInvalidEmail = async (
}),
]);
};
-
-const getProjectOwnerEmail = async (projectSlug: string) => {
- const owner = await prisma.project.findUnique({
- where: { slug: projectSlug },
- select: {
- users: {
- where: {
- role: "owner",
- },
- select: {
- user: {
- select: {
- email: true,
- },
- },
- },
- },
- },
- });
- return owner?.users[0].user.email;
-};
diff --git a/lib/cron/usage.tsx b/lib/cron/usage.tsx
index 235f777b52..0281b42073 100644
--- a/lib/cron/usage.tsx
+++ b/lib/cron/usage.tsx
@@ -1,8 +1,8 @@
import sendMail from "emails";
import UsageExceeded from "emails/UsageExceeded";
import prisma from "@/lib/prisma";
-import { getClicksUsage } from "@/lib/tinybird";
import { getFirstAndLastDay, log } from "@/lib/utils";
+import { ProjectProps } from "../types";
export const updateUsage = async () => {
const projects = await prisma.project.findMany({
@@ -14,7 +14,12 @@ export const updateUsage = async () => {
},
},
select: {
+ id: true,
+ name: true,
+ slug: true,
+ usage: true,
usageLimit: true,
+ plan: true,
billingCycleStart: true,
users: {
where: {
@@ -24,127 +29,96 @@ export const updateUsage = async () => {
user: true,
},
},
- domains: {
- where: {
- verified: true,
- },
- },
sentEmails: true,
},
- orderBy: {
- usageUpdatedAt: "asc",
- },
});
- // const response = await Promise.all(
- // projects.map(
- // async ({
- // id,
- // email,
- // usageLimit,
- // billingCycleStart,
- // projects,
- // sentEmails,
- // }) => {
- // const usageArr = await Promise.all(
- // projects.map(async ({ project: { id, domain } }) => {
- // return {
- // id,
- // usage: await getUsageForProject(domain, billingCycleStart),
- // };
- // }),
- // );
- // let totalUsage = usageArr.reduce((acc, { usage }) => acc + usage, 0);
- // let ownerExceededUsage = totalUsage > usageLimit;
+ // Get all projects that have billingCycleStart today
+ const billingReset = projects.filter(
+ ({ billingCycleStart }) => billingCycleStart === new Date().getDate(),
+ );
- // if (ownerExceededUsage) {
- // await log(
- // `${email} is over usage limit. Usage: ${totalUsage}, Limit: ${usageLimit}`,
- // "cron",
- // );
- // const sentFirstUsageLimitEmail = sentEmails.some(
- // (email) => email.type === "firstUsageLimitEmail",
- // );
- // if (!sentFirstUsageLimitEmail) {
- // sendUsageLimitEmail(email, totalUsage, usageLimit, "first");
- // } else {
- // const sentSecondUsageLimitEmail = sentEmails.some(
- // (email) => email.type === "secondUsageLimitEmail",
- // );
- // if (!sentSecondUsageLimitEmail) {
- // const daysSinceFirstEmail = Math.floor(
- // (new Date().getTime() -
- // new Date(sentEmails[0].createdAt).getTime()) /
- // (1000 * 3600 * 24),
- // );
- // if (daysSinceFirstEmail >= 3) {
- // sendUsageLimitEmail(email, totalUsage, usageLimit, "second");
- // }
- // }
- // }
- // }
+ // Get all projects that have exceeded usage
+ const exceedingUsage = projects.filter(
+ ({ usage, usageLimit }) => usage > usageLimit,
+ );
- // const newBillingCycle = new Date().getDate() === billingCycleStart;
+ // Send email to notify overages
+ const notifyOveragesResponse = await Promise.allSettled(
+ exceedingUsage.map(async (project) => {
+ const { name, usage, usageLimit, users, sentEmails } = project;
+ const email = users[0].user.email;
- // const [updateUser, updateProjects] = await Promise.all([
- // prisma.user.update({
- // where: {
- // id,
- // },
- // data: {
- // usage: totalUsage,
- // usageUpdatedAt: new Date(),
- // // reset usage email warnings if it's a new billing cycle
- // ...(newBillingCycle && {
- // sentEmails: {
- // deleteMany: {
- // type: {
- // in: ["firstUsageLimitEmail", "secondUsageLimitEmail"],
- // },
- // },
- // },
- // }),
- // },
- // }),
- // Promise.all(
- // usageArr.map(async ({ id, usage }) => {
- // return await prisma.project.update({
- // where: {
- // id,
- // },
- // data: {
- // usage,
- // ownerExceededUsage,
- // },
- // });
- // }),
- // ),
- // ]);
+ await log(
+ `${name} is over usage limit. Usage: ${usage}, Limit: ${usageLimit}`,
+ "cron",
+ );
+ const sentFirstUsageLimitEmail = sentEmails.some(
+ (email) => email.type === "firstUsageLimitEmail",
+ );
+ if (!sentFirstUsageLimitEmail) {
+ // @ts-ignore
+ sendUsageLimitEmail(email, project, "first");
+ } else {
+ const sentSecondUsageLimitEmail = sentEmails.some(
+ (email) => email.type === "secondUsageLimitEmail",
+ );
+ if (!sentSecondUsageLimitEmail) {
+ const daysSinceFirstEmail = Math.floor(
+ (new Date().getTime() -
+ new Date(sentEmails[0].createdAt).getTime()) /
+ (1000 * 3600 * 24),
+ );
+ if (daysSinceFirstEmail >= 3) {
+ // @ts-ignore
+ sendUsageLimitEmail(email, project, "second");
+ }
+ }
+ }
+ }),
+ );
- // return {
- // updateUser,
- // updateProjects,
- // };
- // },
- // ),
- // );
+ // Reset usage for projects that have billingCycleStart today
+ // also delete sentEmails for those projects
+ // TODO: Monthly summary emails (total clicks, best performing links, etc.)
+ const resetBillingResponse = await Promise.allSettled(
+ billingReset.map(async (project) => {
+ return await prisma.project.update({
+ where: {
+ id: project.id,
+ },
+ data: {
+ usage: 0,
+ sentEmails: {
+ deleteMany: {
+ type: {
+ in: ["firstUsageLimitEmail", "secondUsageLimitEmail"],
+ },
+ },
+ },
+ },
+ });
+ }),
+ );
- return projects;
+ return {
+ billingReset,
+ exceedingUsage,
+ notifyOveragesResponse,
+ resetBillingResponse,
+ };
};
const sendUsageLimitEmail = async (
email: string,
- usage: number,
- usageLimit: number,
+ project: ProjectProps,
type: "first" | "second",
) => {
return await Promise.all([
sendMail({
subject: `You have exceeded your Dub usage limit`,
to: email,
- component: (
- <UsageExceeded usage={usage} usageLimit={usageLimit} type={type} />
- ),
+ component: <UsageExceeded project={project} type={type} />,
}),
prisma.sentEmail.create({
data: {
diff --git a/lib/types.ts b/lib/types.ts
index 0807e9e064..af19094348 100644
--- a/lib/types.ts
+++ b/lib/types.ts
@@ -28,6 +28,8 @@ export interface LinkProps {
updatedAt?: Date;
}
+export type PlanProps = "free" | "pro" | "enterprise";
+
export interface ProjectProps {
id: string;
name: string;
@@ -35,7 +37,7 @@ export interface ProjectProps {
logo?: string;
usage: number;
usageLimit: number;
- plan: "free" | "pro" | "enterprise";
+ plan: PlanProps;
stripeId?: string;
billingCycleStart?: number;
diff --git a/pages/api/cron/domains.ts b/pages/api/cron/domains.ts
index e77cdbdf5a..3a41f381f7 100644
--- a/pages/api/cron/domains.ts
+++ b/pages/api/cron/domains.ts
@@ -11,21 +11,37 @@ import prisma from "@/lib/prisma";
/**
* Cron to check if domains are verified.
* Runs every 3 hours
- * TODO: If a domain is invalid for more than 7 days, we send an email to the project owner.
- * If a domain is invalid for more than 30 days, we delete it and the associating project from the database.
+ * If a domain is invalid for more than 14 days, we send a reminder email to the project owner.
+ * If a domain is invalid for more than 28 days, we send a second and final reminder email to the project owner.
+ * If a domain is invalid for more than 30 days, we delete it from the database.
**/
async function handler(_req: NextApiRequest, res: NextApiResponse) {
try {
const domains = await prisma.domain.findMany({
+ where: {
+ slug: {
+ // exclude domains that belong to us
+ notIn: [
+ "dub.sh",
+ "stey.me",
+ "steven.yt",
+ "vercel.fyi",
+ "vercel.link",
+ "owd.li",
+ "chatg.pt",
+ "elegance.ai",
+ ],
+ },
+ },
select: {
slug: true,
verified: true,
createdAt: true,
projectId: true,
- project: {
+ _count: {
select: {
- createdAt: true,
+ links: true,
},
},
},
@@ -37,27 +53,27 @@ async function handler(_req: NextApiRequest, res: NextApiResponse) {
const results = await Promise.allSettled(
domains.map(async (domain) => {
- const { slug, verified, createdAt, projectId } = domain;
+ const { slug, verified, createdAt, _count } = domain;
const [domainJson, configJson] = await Promise.all([
getDomainResponse(slug),
getConfigResponse(slug),
]);
- let newDomainVerified;
+ let newVerified;
if (domainJson?.error?.code === "not_found") {
- newDomainVerified = false;
+ newVerified = false;
} else if (!domainJson.verified) {
const verificationJson = await verifyDomain(slug);
if (verificationJson && verificationJson.verified) {
- newDomainVerified = true;
+ newVerified = true;
} else {
- newDomainVerified = false;
+ newVerified = false;
}
} else if (!configJson.misconfigured) {
- newDomainVerified = true;
+ newVerified = true;
} else {
- newDomainVerified = false;
+ newVerified = false;
}
const prismaResponse = await prisma.domain.update({
@@ -65,24 +81,25 @@ async function handler(_req: NextApiRequest, res: NextApiResponse) {
slug,
},
data: {
- verified: newDomainVerified,
+ verified: newVerified,
lastChecked: new Date(),
},
});
- const changed = newDomainVerified !== verified;
+ const changed = newVerified !== verified;
- const updates = await handleDomainUpdates(
- slug,
+ const updates = await handleDomainUpdates({
+ domain: slug,
createdAt,
- newDomainVerified,
+ verified: newVerified,
changed,
- );
+ linksCount: _count.links,
+ });
return {
domain,
previousStatus: verified,
- currentStatus: newDomainVerified,
+ currentStatus: newVerified,
changed,
updates,
prismaResponse,
diff --git a/pages/api/cron/usage.ts b/pages/api/cron/usage.ts
index 05253296cf..ddaf5f7d81 100644
--- a/pages/api/cron/usage.ts
+++ b/pages/api/cron/usage.ts
@@ -4,7 +4,7 @@ import { updateUsage } from "@/lib/cron/usage";
/**
* Cron to update the usage stats of each project.
- * Runs every 6 hours (might need to change this if we have more users).
+ * Runs once every day at 7AM PST.
**/
async function handler(_req: NextApiRequest, res: NextApiResponse) {
diff --git a/pages/app/[slug]/domains.tsx b/pages/app/[slug]/domains.tsx
index bec161755b..6a0f659105 100644
--- a/pages/app/[slug]/domains.tsx
+++ b/pages/app/[slug]/domains.tsx
@@ -6,6 +6,7 @@ import useProject from "@/lib/swr/use-project";
import DomainCard from "@/components/app/domains/domain-card";
import useDomains from "@/lib/swr/use-domains";
import DomainCardPlaceholder from "@/components/app/domains/domain-card-placeholder";
+import NoDomainsPlaceholder from "@/components/app/domains/no-domains-placeholder";
export default function ProjectDomains() {
const { id: projectId, error } = useProject();
@@ -31,13 +32,17 @@ export default function ProjectDomains() {
</div>
<MaxWidthWrapper className="py-10">
{domains ? (
- <ul className="grid grid-cols-1 gap-3">
- {domains.map((domain) => (
- <li key={domain.slug}>
- <DomainCard props={domain} />
- </li>
- ))}
- </ul>
+ domains.length > 0 ? (
+ <ul className="grid grid-cols-1 gap-3">
+ {domains.map((domain) => (
+ <li key={domain.slug}>
+ <DomainCard props={domain} />
+ </li>
+ ))}
+ </ul>
+ ) : (
+ <NoDomainsPlaceholder AddEditDomainButton={AddEditDomainButton} />
+ )
) : (
<DomainCardPlaceholder />
)}