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.

Premium domain :star:

Steven Tey09f5a1a258be
diff --git a/apps/web/app/api/domains/default/route.ts b/apps/web/app/api/domains/default/route.ts
index 8c25d19629..d4cb494733 100644
--- a/apps/web/app/api/domains/default/route.ts
+++ b/apps/web/app/api/domains/default/route.ts
@@ -1,3 +1,4 @@
+import { DubApiError } from "@/lib/api/errors";
import { withWorkspace } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
import z from "@/lib/zod";
@@ -13,6 +14,7 @@ export const GET = withWorkspace(
},
select: {
dubsh: true,
+ dublink: true,
chatgpt: true,
sptifi: true,
gitnew: true,
@@ -50,12 +52,21 @@ export const PUT = withWorkspace(
await req.json(),
);
+ if (workspace.plan === "free" && defaultDomains.includes("dub.link")) {
+ throw new DubApiError({
+ code: "forbidden",
+ message:
+ "You can only use dub.link on a Pro plan and above. Upgrade to Pro to use this domain.",
+ });
+ }
+
const response = await prisma.defaultDomains.update({
where: {
projectId: workspace.id,
},
data: {
dubsh: defaultDomains.includes("dub.sh"),
+ dublink: defaultDomains.includes("dub.link"),
chatgpt: defaultDomains.includes("chatg.pt"),
sptifi: defaultDomains.includes("spti.fi"),
gitnew: defaultDomains.includes("git.new"),
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/domains/default-domains.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/domains/default-domains.tsx
index 13680d43f5..8538f6d880 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/domains/default-domains.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/domains/default-domains.tsx
@@ -4,7 +4,8 @@ import { clientAccessCheck } from "@/lib/api/tokens/permissions";
import useDefaultDomains from "@/lib/swr/use-default-domains";
import useWorkspace from "@/lib/swr/use-workspace";
import { DomainCardTitleColumn } from "@/ui/domains/domain-card-title-column";
-import { Logo, Switch } from "@dub/ui";
+import { UpgradeRequiredToast } from "@/ui/shared/upgrade-required-toast";
+import { Logo, Switch, useRouterStuff } from "@dub/ui";
import {
Amazon,
ChatGPT,
@@ -13,6 +14,7 @@ import {
GoogleEnhanced,
Spotify,
} from "@dub/ui/src/icons";
+import { TooltipContent } from "@dub/ui/src/tooltip";
import { DUB_DOMAINS } from "@dub/utils";
import Link from "next/link";
import { useEffect, useState } from "react";
@@ -38,7 +40,7 @@ function DubDomainsIcon(domain: string) {
}
export function DefaultDomains() {
- const { id, role } = useWorkspace();
+ const { id, plan, role, flags } = useWorkspace();
const permissionsError = clientAccessCheck({
action: "domains.write",
role,
@@ -53,6 +55,7 @@ export function DefaultDomains() {
}
}, [initialDefaultDomains]);
const [submitting, setSubmitting] = useState(false);
+ const { queryParams } = useRouterStuff();
return (
<div className="my-10 grid gap-5 border-t border-gray-200 py-10">
@@ -72,52 +75,85 @@ export function DefaultDomains() {
</p>
</div>
<div className="mt-2 grid grid-cols-1 gap-3">
- {DUB_DOMAINS.map(({ slug, description }) => (
- <div
- key={slug}
- className="flex items-center justify-between gap-4 rounded-xl border border-gray-200 bg-white p-5"
- >
- <DomainCardTitleColumn
- domain={slug}
- icon={DubDomainsIcon(slug)}
- description={description}
- defaultDomain
- />
- <Switch
- disabled={submitting}
- disabledTooltip={permissionsError || undefined}
- checked={defaultDomains?.includes(slug)}
- fn={() => {
- const oldDefaultDomains = defaultDomains.slice();
- const newDefaultDomains = defaultDomains.includes(slug)
- ? defaultDomains.filter((d) => d !== slug)
- : [...defaultDomains, slug];
+ {DUB_DOMAINS.filter(({ slug }) => {
+ if (slug === "dub.link") {
+ return flags?.dublink;
+ }
+ return true;
+ }).map(({ slug, description }) => {
+ return (
+ <div
+ key={slug}
+ className="flex items-center justify-between gap-4 rounded-xl border border-gray-200 bg-white p-5"
+ >
+ <DomainCardTitleColumn
+ domain={slug}
+ icon={DubDomainsIcon(slug)}
+ description={description}
+ defaultDomain
+ />
+ <Switch
+ disabled={submitting}
+ disabledTooltip={
+ permissionsError ||
+ (slug === "dub.link" && plan === "free" ? (
+ <TooltipContent
+ title="You can only use dub.link on a Pro plan and above. Upgrade to Pro to use this domain."
+ cta="Upgrade to Pro"
+ onClick={() => {
+ queryParams({
+ set: {
+ upgrade: "pro",
+ },
+ });
+ }}
+ />
+ ) : undefined)
+ }
+ checked={defaultDomains?.includes(slug)}
+ fn={() => {
+ const oldDefaultDomains = defaultDomains.slice();
+ const newDefaultDomains = defaultDomains.includes(slug)
+ ? defaultDomains.filter((d) => d !== slug)
+ : [...defaultDomains, slug];
- setDefaultDomains(newDefaultDomains);
- setSubmitting(true);
- fetch(`/api/domains/default?workspaceId=${id}`, {
- method: "PUT",
- body: JSON.stringify({
- defaultDomains: newDefaultDomains.filter((d) => d !== null),
- }),
- })
- .then(async (res) => {
- if (res.ok) {
- toast.success(
- `${slug} ${newDefaultDomains.includes(slug) ? "added to" : "removed from"} default domains.`,
- );
- await mutate();
- } else {
- const error = await res.text();
- toast.error(error);
- setDefaultDomains(oldDefaultDomains);
- }
+ setDefaultDomains(newDefaultDomains);
+ setSubmitting(true);
+ fetch(`/api/domains/default?workspaceId=${id}`, {
+ method: "PUT",
+ body: JSON.stringify({
+ defaultDomains: newDefaultDomains.filter(
+ (d) => d !== null,
+ ),
+ }),
})
- .finally(() => setSubmitting(false));
- }}
- />
- </div>
- ))}
+ .then(async (res) => {
+ if (res.ok) {
+ toast.success(
+ `${slug} ${newDefaultDomains.includes(slug) ? "added to" : "removed from"} default domains.`,
+ );
+ await mutate();
+ } else {
+ const { error } = await res.json();
+ if (error.message.includes("Upgrade to Pro")) {
+ toast.custom(() => (
+ <UpgradeRequiredToast
+ title="You've discovered a Pro feature!"
+ message={error.message}
+ />
+ ));
+ } else {
+ toast.error(error.message);
+ }
+ setDefaultDomains(oldDefaultDomains);
+ }
+ })
+ .finally(() => setSubmitting(false));
+ }}
+ />
+ </div>
+ );
+ })}
</div>
</div>
);
diff --git a/apps/web/lib/api/links/process-link.ts b/apps/web/lib/api/links/process-link.ts
index 45098fd3b2..09de0967fd 100644
--- a/apps/web/lib/api/links/process-link.ts
+++ b/apps/web/lib/api/links/process-link.ts
@@ -166,6 +166,24 @@ export async function processLink<T extends Record<string, any>>({
code: "unprocessable_entity",
};
}
+ } else if (domain === "dub.link") {
+ if (!workspace || workspace.plan === "free") {
+ return {
+ link: payload,
+ error:
+ "You can only use dub.link on a Pro plan and above. Upgrade to Pro to use this domain.",
+ code: "forbidden",
+ };
+ }
+ const flags = await getFeatureFlags(workspace.id);
+ if (!flags.dublink) {
+ return {
+ link: payload,
+ error:
+ "dub.link is still currently in beta. Please contact [email protected] if you need access.",
+ code: "forbidden",
+ };
+ }
// checks for other Dub-owned domains (chatg.pt, spti.fi, etc.)
} else if (isDubDomain(domain)) {
diff --git a/apps/web/lib/edge-config/get-feature-flags.ts b/apps/web/lib/edge-config/get-feature-flags.ts
index 0ca6584d1a..05de0fcf73 100644
--- a/apps/web/lib/edge-config/get-feature-flags.ts
+++ b/apps/web/lib/edge-config/get-feature-flags.ts
@@ -7,6 +7,7 @@ export const getFeatureFlags = async (workspaceId: string) => {
const workspaceFeatures: Record<BetaFeatures, boolean> = {
conversions: false,
integrations: false,
+ dublink: false,
};
workspaceId = workspaceId.startsWith("ws_")
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index d8130db1c1..e748b5e39d 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -68,7 +68,7 @@ export type PlanProps = (typeof plans)[number];
export type RoleProps = (typeof roles)[number];
-export type BetaFeatures = "conversions" | "integrations";
+export type BetaFeatures = "conversions" | "integrations" | "dublink";
export interface WorkspaceProps {
id: string;
diff --git a/apps/web/ui/domains/domain-card-title-column.tsx b/apps/web/ui/domains/domain-card-title-column.tsx
index 751097ff5c..dfbd9496e5 100644
--- a/apps/web/ui/domains/domain-card-title-column.tsx
+++ b/apps/web/ui/domains/domain-card-title-column.tsx
@@ -1,5 +1,6 @@
import { ArrowTurnRight2, Flag2, Globe } from "@dub/ui/src/icons";
-import { cn, punycode } from "@dub/utils";
+import { cn, getPrettyUrl, punycode } from "@dub/utils";
+import { Star } from "lucide-react";
export function DomainCardTitleColumn({
domain,
@@ -41,12 +42,17 @@ export function DomainCardTitleColumn({
{punycode(domain)}
</a>
- {primary && (
+ {primary ? (
<span className="xs:px-3 xs:py-1 flex items-center gap-1 rounded-full bg-sky-400/[.15] px-1.5 py-0.5 text-xs font-medium text-sky-600">
<Flag2 className="hidden h-3 w-3 sm:block" />
Primary
</span>
- )}
+ ) : defaultDomain && domain === "dub.link" ? (
+ <span className="xs:px-3 xs:py-1 flex items-center gap-1 rounded-full bg-yellow-400/[.25] px-1.5 py-0.5 text-xs font-medium text-yellow-600">
+ <Star className="h-3 w-3" />
+ Premium
+ </span>
+ ) : null}
</div>
{(!defaultDomain || description) && (
<div className="mt-1 flex items-center gap-1 text-xs">
@@ -62,9 +68,14 @@ export function DomainCardTitleColumn({
<ArrowTurnRight2 className="h-3 w-3 text-gray-400" />
{url !== undefined ? (
url ? (
- <span className="truncate text-gray-500" title={url}>
- {url}
- </span>
+ <a
+ href={url}
+ target="_blank"
+ rel="noreferrer"
+ className="truncate text-gray-500 transition-all hover:text-gray-700 hover:underline hover:underline-offset-2"
+ >
+ {getPrettyUrl(url)}
+ </a>
) : (
<span className="truncate text-gray-400">
No redirect configured
diff --git a/packages/utils/src/constants/dub-domains.ts b/packages/utils/src/constants/dub-domains.ts
index d32ec947d5..c055c901f4 100644
--- a/packages/utils/src/constants/dub-domains.ts
+++ b/packages/utils/src/constants/dub-domains.ts
@@ -14,6 +14,18 @@ export const DUB_DOMAINS = [
},
...(process.env.NEXT_PUBLIC_IS_DUB
? [
+ {
+ id: "clxp3lfsb00011na8tfs7t0lx",
+ slug: "dub.link",
+ verified: true,
+ primary: false,
+ archived: false,
+ placeholder: "https://dub.co/help/article/what-is-dub",
+ allowedHostnames: [],
+ description:
+ "Premium short domain on Dub – only available on our Pro plan and above.",
+ projectId: DUB_WORKSPACE_ID,
+ },
{
id: "clce1z7cs00y8rbstk4xtnj0k",
slug: "chatg.pt",
diff --git a/packages/utils/src/functions/urls.ts b/packages/utils/src/functions/urls.ts
index b89ed2c207..4e495eb9ff 100644
--- a/packages/utils/src/functions/urls.ts
+++ b/packages/utils/src/functions/urls.ts
@@ -97,3 +97,7 @@ export const getUrlWithoutUTMParams = (url: string) => {
return url;
}
};
+
+export const getPrettyUrl = (url: string) => {
+ return url.replace(/(^\w+:|^)\/\//, "").replace("www.", "");
+};