The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fix logs
Steven Teya6d477830fd8
diff --git a/apps/web/app/api/cron/links/event/route.ts b/apps/web/app/api/cron/links/event/route.tsindex f172eddbed..2ef675fdc1 100644--- a/apps/web/app/api/cron/links/event/route.ts+++ b/apps/web/app/api/cron/links/event/route.ts@@ -112,6 +112,13 @@ export async function POST(req: Request) {}),);}),+ log({+ message: `*${+ project.slug+ }* has used ${percentage.toString()}% of its links limit for the month.`,+ type: project.plan === "free" ? "cron" : "alerts",+ mention: project.plan !== "free",+ }),]);}}diff --git a/apps/web/app/api/cron/usage/utils.ts b/apps/web/app/api/cron/usage/utils.tsindex fbcef3c8c2..2966e14c2e 100644--- a/apps/web/app/api/cron/usage/utils.ts+++ b/apps/web/app/api/cron/usage/utils.ts@@ -4,6 +4,7 @@ import { getStats } from "@/lib/stats";import { ProjectProps } from "@/lib/types";import {APP_DOMAIN_WITH_NGROK,+ capitalize,getAdjustedBillingCycleStart,linkConstructor,log,@@ -71,15 +72,17 @@ export const updateUsage = async (skip?: number) => {// Send email to notify overagesawait Promise.allSettled(exceedingUsage.map(async (project) => {- const { name, usage, usageLimit, users, sentEmails } = project;+ const { slug, plan, usage, usageLimit, users, sentEmails } = project;const emails = users.map((user) => user.user.email) as string[];await log({- message: `${name} is over usage limit. Usage: ${usage}, Limit: ${usageLimit}, Email: ${emails.join(+ message: `*${slug}* is over their *${capitalize(+ plan,+ )} Plan* usage limit. Usage: ${usage}, Limit: ${usageLimit}, Email: ${emails.join(", ",)}`,- type: "cron",- mention: true,+ type: plan === "free" ? "cron" : "alerts",+ mention: plan !== "free",});const sentFirstUsageLimitEmail = sentEmails.some((email) => email.type === "firstUsageLimitEmail",diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/page-client.tsxindex 7820c79d07..3ec9f0b7a9 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/page-client.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/page-client.tsx@@ -48,12 +48,12 @@ const AddLinkOptions = () => {content={<div className="w-full divide-y divide-gray-200 md:w-52"><div className="p-2">- {slug && exceededLinks ? (+ {exceededLinks ? (<Tooltipcontent={<TooltipContenttitle="Your project has exceeded its monthly links limit. We're still collecting data on your existing links, but you need to upgrade to add more links."- cta="Upgrade"+ cta={`Upgrade to ${plan === "free" ? "Pro" : "Business"}`}onClick={() => {setOpenPopover(false);queryParams({@@ -98,12 +98,12 @@ const AddLinkOptions = () => {/></button>)}- {slug && exceededLinks ? (+ {exceededLinks ? (<Tooltipcontent={<TooltipContenttitle="Your project has exceeded its monthly links limit. We're still collecting data on your existing links, but you need to upgrade to add more links."- cta="Upgrade to Pro"+ cta={`Upgrade to ${plan === "free" ? "Pro" : "Business"}`}onClick={() => {setOpenPopover(false);queryParams({@@ -148,12 +148,12 @@ const AddLinkOptions = () => {/></button>)}- {slug && exceededLinks ? (+ {exceededLinks ? (<Tooltipcontent={<TooltipContenttitle="Your project has exceeded its monthly links limit. We're still collecting data on your existing links, but you need to upgrade to add more links."- cta="Upgrade to Pro"+ cta={`Upgrade to ${plan === "free" ? "Pro" : "Business"}`}onClick={() => {setOpenPopover(false);queryParams({diff --git a/apps/web/scripts/get-projects-by-clicks.ts b/apps/web/scripts/get-projects-by-clicks.tsindex 769289a836..2103c9b2eb 100644--- a/apps/web/scripts/get-projects-by-clicks.ts+++ b/apps/web/scripts/get-projects-by-clicks.ts@@ -7,14 +7,8 @@ async function main() {slug: true,plan: true,usage: true,- domains: {- select: {- slug: true,- },- },_count: {select: {- links: true,domains: true,},},@@ -24,24 +18,7 @@ async function main() {},take: 100,});- console.table(- // sort by links count- projects- // .sort((a, b) => b._count.links - a._count.links)- .map((project) => ({- ...project,- domains: `${- project.domains- .slice(0, 2)- .map((domain) => domain.slug)- .join(", ") +- (project.domains.length > 2- ? `... ${project._count.domains - 2}+`- : "")- }`,- })),- ["slug", "plan", "usage", "_count"],- );+ console.table(projects, ["slug", "plan", "usage", "_count"]);}main();diff --git a/apps/web/scripts/get-projects-by-links.ts b/apps/web/scripts/get-projects-by-links.tsindex 9084756b8a..40f2b0a1b5 100644--- a/apps/web/scripts/get-projects-by-links.ts+++ b/apps/web/scripts/get-projects-by-links.ts@@ -2,45 +2,19 @@ import "dotenv-flow/config";import prisma from "@/lib/prisma";async function main() {- const projects = await prisma.link- .groupBy({- by: ["projectId"],- _count: {- id: true,- },- orderBy: {- _count: {- id: "desc",- },- },- take: 100,- })- .then(- async (projects) =>- await Promise.all(- projects.map(async ({ _count, projectId }) => {- if (!projectId) {- return;- }- const project = await prisma.project.findUnique({- where: {- id: projectId,- },- select: {- slug: true,- plan: true,- },- });- return {- project: project?.slug,- plan: project?.plan,- links: _count.id,- };- }),- ),- );-- console.table(projects);+ const projects = await prisma.project.findMany({+ select: {+ slug: true,+ plan: true,+ linksUsage: true,+ linksLimit: true,+ },+ orderBy: {+ linksUsage: "desc",+ },+ take: 100,+ });+ console.table(projects, ["slug", "plan", "linksUsage", "linksLimit"]);}main();diff --git a/apps/web/scripts/sync-limits.ts b/apps/web/scripts/sync-limits.tsindex eb852016b3..377177c2ef 100644--- a/apps/web/scripts/sync-limits.ts+++ b/apps/web/scripts/sync-limits.ts@@ -7,7 +7,7 @@ async function main() {plan: "pro",},data: {- linksLimit: 250,+ linksLimit: 1000,domainsLimit: 10,tagsLimit: 25,usersLimit: 5,diff --git a/apps/web/ui/modals/add-edit-link-modal/index.tsx b/apps/web/ui/modals/add-edit-link-modal/index.tsxindex 805c029208..d401bcf20a 100644--- a/apps/web/ui/modals/add-edit-link-modal/index.tsx+++ b/apps/web/ui/modals/add-edit-link-modal/index.tsx@@ -611,7 +611,7 @@ function AddEditLinkButton({}: {setShowAddEditLinkModal: Dispatch<SetStateAction<boolean>>;}) {- const { slug, plan, exceededLinks } = useProject();+ const { plan, exceededLinks } = useProject();const { queryParams } = useRouterStuff();const onKeyDown = useCallback((e: KeyboardEvent) => {@@ -674,10 +674,10 @@ function AddEditLinkButton({text="Create link"shortcut="C"disabledTooltip={- slug && exceededLinks ? (+ exceededLinks ? (<TooltipContenttitle="Your project has exceeded its monthly links limit. We're still collecting data on your existing links, but you need to upgrade to add more links."- cta="Upgrade"+ cta={`Upgrade to ${plan === "free" ? "Pro" : "Business"}`}onClick={() => {queryParams({set: {diff --git a/packages/utils/src/functions/log.ts b/packages/utils/src/functions/log.tsindex 48aaf8f2d5..32f720dc3f 100644--- a/packages/utils/src/functions/log.ts+++ b/packages/utils/src/functions/log.ts@@ -1,4 +1,5 @@const logTypeToEnv = {+ alerts: process.env.DUB_SLACK_HOOK_ALERTS,cron: process.env.DUB_SLACK_HOOK_CRON,links: process.env.DUB_SLACK_HOOK_LINKS,errors: process.env.DUB_SLACK_HOOK_ERRORS,@@ -10,16 +11,18 @@ export const log = async ({mention = false,}: {message: string;- type: "cron" | "links" | "errors";+ type: "alerts" | "cron" | "links" | "errors";mention?: boolean;}) => {if (process.env.NODE_ENV === "development" ||+ !process.env.DUB_SLACK_HOOK_ALERTS ||!process.env.DUB_SLACK_HOOK_CRON ||!process.env.DUB_SLACK_HOOK_LINKS ||!process.env.DUB_SLACK_HOOK_ERRORS- )+ ) {console.log(message);+ }/* Log a message to the console */const HOOK = logTypeToEnv[type];if (!HOOK) return;@@ -35,13 +38,8 @@ export const log = async ({type: "section",text: {type: "mrkdwn",- text: `${- mention- ? "<@U0404G6J3NJ> "- : type === "errors"- ? ":alert: "- : ""- }${message}`,+ // prettier-ignore+ text: `${mention && "<@U0404G6J3NJ> "}${(type === "alerts" || type === "errors") && ":alert: "}${message}`,},},],