The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
add skipDecodeKey
Kiran K9f33d780c469
diff --git a/apps/web/app/api/links/[linkId]/route.ts b/apps/web/app/api/links/[linkId]/route.tsindex 053f4a7db0..93e791009e 100644--- a/apps/web/app/api/links/[linkId]/route.ts+++ b/apps/web/app/api/links/[linkId]/route.ts@@ -49,12 +49,15 @@ export const GET = withWorkspace(},});- const response = transformLink({- ...link,- tags: tags.map((tag) => {- return { tag };- }),- });+ const response = transformLink(+ {+ ...link,+ tags: tags.map((tag) => {+ return { tag };+ }),+ },+ { skipDecodeKey: true },+ );return NextResponse.json(response, { headers });},diff --git a/apps/web/app/api/links/info/route.ts b/apps/web/app/api/links/info/route.tsindex 107bc90e4e..3e6540eead 100644--- a/apps/web/app/api/links/info/route.ts+++ b/apps/web/app/api/links/info/route.ts@@ -54,12 +54,15 @@ export const GET = withWorkspace(},});- const response = transformLink({- ...link,- tags: tags.map((tag) => {- return { tag };- }),- });+ const response = transformLink(+ {+ ...link,+ tags: tags.map((tag) => {+ return { tag };+ }),+ },+ { skipDecodeKey: true },+ );return NextResponse.json(response, {headers,diff --git a/apps/web/lib/analytics/get-events.ts b/apps/web/lib/analytics/get-events.tsindex b507706c0c..318bdb99aa 100644--- a/apps/web/lib/analytics/get-events.ts+++ b/apps/web/lib/analytics/get-events.ts@@ -132,7 +132,7 @@ export const getEvents = async (params: EventsFilters) => {refererUrl: evt.referer_url_processed ?? "",}),// transformLink -> add shortLink, qrCode, workspaceId, etc.- link: transformLink(link),+ link: transformLink(link, { skipDecodeKey: true }),...(evt.event === "lead" || evt.event === "sale"? {eventId: evt.event_id,diff --git a/apps/web/lib/api/links/cache.ts b/apps/web/lib/api/links/cache.tsindex 7f9cdcc3d6..d697cdeab1 100644--- a/apps/web/lib/api/links/cache.ts+++ b/apps/web/lib/api/links/cache.ts@@ -22,19 +22,18 @@ class LinkCache {const pipeline = redis.pipeline();const redisLinks = await Promise.all(- links.map(async (link) => ({+ links.map((link) => ({...formatRedisLink(link),- key: link.key.toLowerCase(),- domain: link.domain.toLowerCase(),+ cacheKey: this._createKey({ domain: link.domain, key: link.key }),})),);- redisLinks.map(({ domain, key, ...redisLink }) => {+ redisLinks.map(({ cacheKey, ...redisLink }) => {const hasWebhooks =redisLink.webhookIds && redisLink.webhookIds.length > 0;pipeline.set(- this._createKey({ domain, key }),+ cacheKey,redisLink,hasWebhooks ? undefined : { ex: CACHE_EXPIRATION },);@@ -116,8 +115,8 @@ class LinkCache {_createKey({ domain, key }: Pick<LinkProps, "domain" | "key">) {const caseSensitive = isCaseSensitiveDomain(domain);- const newKey = caseSensitive ? decodeKey(key) : key;- const cacheKey = `linkcache:${domain}:${newKey}`;+ const originalKey = caseSensitive ? decodeKey(key) : key;+ const cacheKey = `linkcache:${domain}:${originalKey}`;return caseSensitive ? cacheKey : cacheKey.toLowerCase();}diff --git a/apps/web/lib/api/links/get-links-for-workspace.ts b/apps/web/lib/api/links/get-links-for-workspace.tsindex 87fb4d45bd..99a106d20d 100644--- a/apps/web/lib/api/links/get-links-for-workspace.ts+++ b/apps/web/lib/api/links/get-links-for-workspace.ts@@ -1,7 +1,6 @@import z from "@/lib/zod";import { getLinksQuerySchemaExtended } from "@/lib/zod/schemas/links";import { prisma } from "@dub/prisma";-import { decodeIfCaseSensitive } from "../case-sensitive-short-links";import { combineTagIds } from "../tags/combine-tag-ids";import { transformLink } from "./utils";@@ -139,5 +138,5 @@ export async function getLinksForWorkspace({skip: (page - 1) * pageSize,});- return links.map((link) => transformLink(decodeIfCaseSensitive(link)));+ return links.map((link) => transformLink(link));}diff --git a/apps/web/lib/api/links/utils/transform-link.ts b/apps/web/lib/api/links/utils/transform-link.tsindex 3f41872fa7..2f58ec857e 100644--- a/apps/web/lib/api/links/utils/transform-link.ts+++ b/apps/web/lib/api/links/utils/transform-link.ts@@ -1,4 +1,5 @@import { Dashboard, Link, Tag } from "@dub/prisma/client";+import { decodeIfCaseSensitive } from "../../case-sensitive-short-links";// used in API (e.g. transformLink)// TODO: standardize this with ExpandedLinkProps@@ -9,10 +10,17 @@ export type ExpandedLink = Link & {};// Transform link with additional properties-export const transformLink = (link: ExpandedLink) => {+export const transformLink = (+ link: ExpandedLink,+ { skipDecodeKey = false }: { skipDecodeKey?: boolean } = {},+) => {const tags = (link.tags || []).map(({ tag }) => tag);const webhookIds = link.webhooks?.map(({ webhookId }) => webhookId) ?? [];+ if (!skipDecodeKey) {+ link = decodeIfCaseSensitive(link);+ }+// remove webhooks array, dashboard from linkconst { webhooks, dashboard, ...rest } = link;