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.

Merge branch 'main' into tim/multiple-tags-cleanup

Tim Wilson693468b5cee9
diff --cc apps/web/app/api/links/[linkId]/route.ts
index 3f91ac12e7,0e58921952..6506574813
--- a/apps/web/app/api/links/[linkId]/route.ts
+++ b/apps/web/app/api/links/[linkId]/route.ts
@@@ -2,8 -2,8 +2,8 @@@ import { DubApiError, ErrorCodes } fro
import { deleteLink, editLink, processLink } from "@/lib/api/links";
import { withAuth } from "@/lib/auth";
import prisma from "@/lib/prisma";
-import { LinkWithTagIdsProps } from "@/lib/types";
+import { NewLinkProps } from "@/lib/types";
- import { updateLinkBodySchema } from "@/lib/zod/schemas/links";
+ import { updateLinkBodySchema } from "@/lib/zod/schemas";
import { NextResponse } from "next/server";
// GET /api/links/[linkId] – get a link
diff --cc apps/web/app/api/links/bulk/route.ts
index 006dd66c01,6b42df5063..66e3b31d8c
--- a/apps/web/app/api/links/bulk/route.ts
+++ b/apps/web/app/api/links/bulk/route.ts
@@@ -2,8 -2,8 +2,8 @@@ import { DubApiError, exceededLimitErro
import { bulkCreateLinks, combineTagIds, processLink } from "@/lib/api/links";
import { withAuth } from "@/lib/auth";
import prisma from "@/lib/prisma";
-import { LinkWithTagIdsProps } from "@/lib/types";
+import { ProcessedLinkProps } from "@/lib/types";
- import { bulkCreateLinksBodySchema } from "@/lib/zod/schemas/links";
+ import { bulkCreateLinksBodySchema } from "@/lib/zod/schemas";
import { NextResponse } from "next/server";
// POST /api/links/bulk – bulk create up to 100 links
diff --cc apps/web/app/api/links/route.ts
index 9604d0a9f4,9f4629bb9e..c7d8aaf82b
--- a/apps/web/app/api/links/route.ts
+++ b/apps/web/app/api/links/route.ts
@@@ -1,11 -1,9 +1,8 @@@
import { DubApiError, ErrorCodes } from "@/lib/api/errors";
import { createLink, getLinksForWorkspace, processLink } from "@/lib/api/links";
import { withAuth } from "@/lib/auth";
-import { LinkWithTagIdsProps } from "@/lib/types";
import { ratelimit } from "@/lib/upstash";
- import {
- createLinkBodySchema,
- getLinksQuerySchema,
- } from "@/lib/zod/schemas/links";
+ import { createLinkBodySchema, getLinksQuerySchema } from "@/lib/zod/schemas";
import { LOCALHOST_IP } from "@dub/utils";
import { NextResponse } from "next/server";
diff --cc apps/web/lib/api/links/process-link.ts
index 7078d227ed,c5d21a86e6..f7b0a38732
--- a/apps/web/lib/api/links/process-link.ts
+++ b/apps/web/lib/api/links/process-link.ts
@@@ -80,11 -66,24 +80,24 @@@ export async function processLink<T ext
(!workspace || workspace.plan === "free") &&
(!createdAt || new Date(createdAt) > new Date("2024-01-19"))
) {
- if (proxy || password || rewrite || expiresAt || ios || android || geo) {
+ if (proxy || password || rewrite || expiresAtRaw || ios || android || geo) {
+ const proFeaturesString = [
+ proxy && "custom social media cards",
+ password && "password protection",
+ rewrite && "link cloaking",
- expiresAt && "link expiration",
++ expiresAtRaw && "link expiration",
+ ios && "iOS targeting",
+ android && "Android targeting",
+ geo && "geo targeting",
+ ]
+ .filter(Boolean)
+ .join(", ")
+ // final one should be "and" instead of comma
+ .replace(/, ([^,]*)$/, " and $1");
+
return {
link: payload,
- error:
- "You can only use custom social media cards, password-protection, link cloaking, link expiration, device and geo targeting on a Pro plan and above. Upgrade to Pro to use these features.",
+ error: `You can only use ${proFeaturesString} on a Pro plan and above. Upgrade to Pro to use these features.`,
code: "forbidden",
};
}
diff --cc apps/web/lib/zod/schemas/links.ts
index 64e579a6e2,0f86edb48c..bfe566ae69
--- a/apps/web/lib/zod/schemas/links.ts
+++ b/apps/web/lib/zod/schemas/links.ts
@@@ -132,6 -135,24 +142,31 @@@ export const createLinkBodySchema = z.o
.optional()
.default(false)
.describe("Whether the short link is archived."),
+ publicStats: z
+ .boolean()
+ .optional()
+ .default(false)
+ .describe("Whether the short link's stats are publicly accessible."),
+ tagId: z
+ .string()
+ .nullish()
+ .describe(
+ "The unique ID of the tag assigned to the short link. This field is deprecated – use `tagIds` instead.",
+ )
+ .openapi({ deprecated: true }),
+ tagIds: z
+ .union([z.string(), z.array(z.string())])
+ .transform((v) => (Array.isArray(v) ? v : v.split(",")))
+ .optional()
+ .describe("The unique IDs of the tags assigned to the short link."),
++ tagNames: z
++ .union([z.string(), z.array(z.string())])
++ .transform((v) => (Array.isArray(v) ? v : v.split(",")))
++ .optional()
++ .describe(
++ "The unique name of the tags assigned to the short link (case insensitive).",
++ ),
+ comments: z.string().nullish().describe("The comments for the short link."),
expiresAt: z
.string()
.nullish()