The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
block geo/device/a-b targeting on dub domains
Pedro Ladeirab84c6273b7f4
diff --git a/apps/web/lib/api/links/process-link.ts b/apps/web/lib/api/links/process-link.tsindex d6e2a0898e..eae223f4bd 100644--- a/apps/web/lib/api/links/process-link.ts+++ b/apps/web/lib/api/links/process-link.ts@@ -72,6 +72,9 @@ export async function processLink<T extends Record<string, any>>({programId,webhookIds,testVariants,+ ios,+ android,+ geo,} = payload;let expiresAt: string | Date | null | undefined = payload.expiresAt;@@ -198,6 +201,15 @@ export async function processLink<T extends Record<string, any>>({} else if (isDubDomain(domain)) {// coerce type with ! cause we already checked if it existsconst { allowedHostnames } = DUB_DOMAINS.find((d) => d.slug === domain)!;++ if (allowedHostnames?.length && (ios || android || geo || testVariants)) {+ return {+ link: payload,+ error: `You cannot use geo targeting, device targeting, or A/B testing on ${domain} links.`,+ code: "unprocessable_entity",+ };+ }+const urlDomain = getDomainWithoutWWW(url) || "";const apexDomain = getApexDomain(url);if (diff --git a/apps/web/scripts/misc/remove-dub-domain-targeting.ts b/apps/web/scripts/misc/remove-dub-domain-targeting.tsnew file mode 100644index 0000000000..04d139b153--- /dev/null+++ b/apps/web/scripts/misc/remove-dub-domain-targeting.ts@@ -0,0 +1,82 @@+import { prisma } from "@/lib/prisma";+import { DUB_DOMAINS } from "@dub/utils";+import { Prisma } from "@prisma/client";+import "dotenv-flow/config";+import { linkCache } from "../../lib/api/links/cache";++const RESTRICTED_DOMAINS = DUB_DOMAINS.filter(+ (d) => d.allowedHostnames.length > 0,+).map((d) => d.slug);++async function main() {+ console.log(+ `Looking for links on [${RESTRICTED_DOMAINS.join(", ")}] with targeting configured...`,+ );++ let totalCleared = 0;++ while (true) {+ const links = await prisma.link.findMany({+ where: {+ domain: { in: RESTRICTED_DOMAINS },+ OR: [+ { ios: { not: null } },+ { android: { not: null } },+ { geo: { not: Prisma.DbNull } },+ { testVariants: { not: Prisma.DbNull } },+ ],+ },+ select: {+ id: true,+ domain: true,+ key: true,+ ios: true,+ android: true,+ geo: true,+ testVariants: true,+ },+ take: 500,+ });++ if (links.length === 0) {+ console.log("No more links to clean up. Exiting...");+ break;+ }++ console.table(+ links.map((link) => ({+ id: link.id,+ domain: link.domain,+ key: link.key,+ ios: Boolean(link.ios),+ android: Boolean(link.android),+ geo: Boolean(link.geo),+ testVariants: Boolean(link.testVariants),+ })),+ );++ const { count } = await prisma.link.updateMany({+ where: {+ id: { in: links.map((link) => link.id) },+ },+ data: {+ ios: null,+ android: null,+ geo: Prisma.DbNull,+ testVariants: Prisma.DbNull,+ testStartedAt: null,+ testCompletedAt: null,+ },+ });++ console.log(`Cleared targeting fields on ${count} links`);+ totalCleared += count;++ const res = await linkCache.expireMany(links);+ console.log("Expired Redis cache:", res);+ }++ console.log(`Done. Cleared targeting on ${totalCleared} links total.`);+}++main();