The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Include webhooks in link info response
Kiran Kb564072f46a8
diff --git a/apps/web/app/api/links/info/route.ts b/apps/web/app/api/links/info/route.tsindex 3e6540eead..835d183cb6 100644--- a/apps/web/app/api/links/info/route.ts+++ b/apps/web/app/api/links/info/route.ts@@ -3,15 +3,15 @@ import { transformLink } from "@/lib/api/links";import { getLinkOrThrow } from "@/lib/api/links/get-link-or-throw";import { withWorkspace } from "@/lib/auth";import { verifyFolderAccess } from "@/lib/folder/permissions";-import { getLinkInfoQuerySchema } from "@/lib/zod/schemas/links";+import { getLinkInfoQuerySchemaExtended } from "@/lib/zod/schemas/links";import { prisma } from "@dub/prisma";import { NextResponse } from "next/server";// GET /api/links/info – get the info for a linkexport const GET = withWorkspace(async ({ headers, searchParams, workspace, session }) => {- const { domain, key, linkId, externalId } =- getLinkInfoQuerySchema.parse(searchParams);+ const { domain, key, linkId, externalId, includeWebhooks } =+ getLinkInfoQuerySchemaExtended.parse(searchParams);if (!domain && !key && !linkId && !externalId) {throw new DubApiError({@@ -28,6 +28,7 @@ export const GET = withWorkspace(externalId,domain,key,+ includeWebhooks,});if (link.folderId) {diff --git a/apps/web/lib/api/links/get-link-or-throw.ts b/apps/web/lib/api/links/get-link-or-throw.tsindex 8865a1100f..a492caeec5 100644--- a/apps/web/lib/api/links/get-link-or-throw.ts+++ b/apps/web/lib/api/links/get-link-or-throw.ts@@ -13,11 +13,18 @@ interface GetLinkParams {externalId?: string;domain?: string;key?: string;+ includeWebhooks?: boolean;}// Get link or throw error if not found or doesn't belong to workspaceexport const getLinkOrThrow = async (params: GetLinkParams) => {- let { workspaceId, domain, key, externalId } = params;+ let {+ workspaceId,+ domain,+ key,+ externalId,+ includeWebhooks = false,+ } = params;let link: Link | null = null;const linkId = params.linkId || params.externalId || undefined;@@ -39,6 +46,9 @@ export const getLinkOrThrow = async (params: GetLinkParams) => {}: { id: linkId }),},+ include: {+ webhooks: includeWebhooks,+ },});}@@ -56,6 +66,9 @@ export const getLinkOrThrow = async (params: GetLinkParams) => {key,},},+ include: {+ webhooks: includeWebhooks,+ },});}diff --git a/apps/web/lib/swr/use-link-info.ts b/apps/web/lib/swr/use-link-info.tsdeleted file mode 100644index e69de29bb2..0000000000diff --git a/apps/web/lib/swr/use-link.ts b/apps/web/lib/swr/use-link.tsindex e69f4d0020..3f2c64916d 100644--- a/apps/web/lib/swr/use-link.ts+++ b/apps/web/lib/swr/use-link.ts@@ -14,7 +14,12 @@ export default function useLink(linkIdOrLink &&(typeof linkIdOrLink === "string"? `/api/links/${linkIdOrLink}?workspaceId=${workspaceId}`- : `/api/links/info?domain=${linkIdOrLink.domain}&key=${linkIdOrLink.slug}&workspaceId=${workspaceId}`),+ : `/api/links/info?${new URLSearchParams({+ workspaceId,+ domain: linkIdOrLink.domain,+ key: linkIdOrLink.slug,+ includeWebhooks: "true",+ })}`),fetcher,swrOptions,);diff --git a/apps/web/lib/zod/schemas/links.ts b/apps/web/lib/zod/schemas/links.tsindex bb749573a3..9a903ed292 100644--- a/apps/web/lib/zod/schemas/links.ts+++ b/apps/web/lib/zod/schemas/links.ts@@ -713,6 +713,7 @@ export const getLinkInfoQuerySchema = domainKeySchema.partial().merge(.openapi({ example: "123456" }),}),);+export const getLinksQuerySchemaExtended = getLinksQuerySchemaBase.merge(z.object({// Only Dub UI uses the following query parameters@@ -732,6 +733,12 @@ export const getLinksQuerySchemaExtended = getLinksQuerySchemaBase.merge(}),);+export const getLinkInfoQuerySchemaExtended = getLinkInfoQuerySchema.merge(+ z.object({+ includeWebhooks: booleanQuerySchema.default("false"),+ }),+);+export const linkEventSchema = LinkSchema.extend({// here we use string because url can be emptyurl: z.string(),