The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Remove LinkWebhook from edge lookup and cap webhook link targets
Kiran K05ad6e428c14
diff --git a/apps/web/lib/planetscale/get-link-via-edge.ts b/apps/web/lib/planetscale/get-link-via-edge.tsindex 9ec1bcdff9..5da1e2f319 100644--- a/apps/web/lib/planetscale/get-link-via-edge.ts+++ b/apps/web/lib/planetscale/get-link-via-edge.ts@@ -5,7 +5,7 @@ import {isCaseSensitiveDomain,} from "../api/links/case-sensitivity";import { conn } from "./connection";-import { EdgeLinkProps, EdgeLinkWithWebhooks } from "./types";+import { EdgeLinkProps } from "./types";const getLinkViaEdgeHelper = async ({domain,@@ -13,7 +13,7 @@ const getLinkViaEdgeHelper = async ({}: {domain: string;key: string;-}): Promise<EdgeLinkWithWebhooks | null> => {+}): Promise<EdgeLinkProps | null> => {const isCaseSensitive = isCaseSensitiveDomain(domain);const keyToQuery = isCaseSensitive? // for case sensitive domains, we need to encode the key@@ -23,27 +23,18 @@ const getLinkViaEdgeHelper = async ({punyEncode(decodeURIComponent(key));const { rows } =- (await conn.execute(- `SELECT Link.*, LinkWebhook.webhookId- FROM Link- LEFT JOIN LinkWebhook ON Link.id = LinkWebhook.linkId- WHERE Link.domain = ? AND Link.\`key\` = ?`,- [domain, keyToQuery],- )) || {};+ (await conn.execute(`SELECT * FROM Link WHERE domain = ? AND \`key\` = ?`, [+ domain,+ keyToQuery,+ ])) || {};if (!rows || !Array.isArray(rows) || rows.length === 0) return null;- const first = rows[0] as EdgeLinkProps & { webhookId: string | null };- const { webhookId: _w, ...link } = first;- const webhooks = (rows as (EdgeLinkProps & { webhookId: string | null })[])- .map((r) => r.webhookId)- .filter((id): id is string => id != null)- .map((webhookId) => ({ webhookId }));+ const link = rows[0] as EdgeLinkProps;return {...link,key: decodeKeyIfCaseSensitive({ domain, key }),- webhooks,};};diff --git a/apps/web/lib/planetscale/types.ts b/apps/web/lib/planetscale/types.tsindex 4f667c2f36..3c1fff5329 100644--- a/apps/web/lib/planetscale/types.ts+++ b/apps/web/lib/planetscale/types.ts@@ -24,11 +24,6 @@ export interface EdgeLinkProps {partnerId: string | null;}-/** Link from edge (getLinkViaEdge) with webhooks, matching ExpandedLink shape */-export type EdgeLinkWithWebhooks = EdgeLinkProps & {- webhooks: { webhookId: string }[];-};-export interface EdgeDomainProps {id: string;slug: string;diff --git a/apps/web/lib/zod/schemas/webhooks.ts b/apps/web/lib/zod/schemas/webhooks.tsindex 723f2d9cb6..f9b5366847 100644--- a/apps/web/lib/zod/schemas/webhooks.ts+++ b/apps/web/lib/zod/schemas/webhooks.ts@@ -71,8 +71,17 @@ export const createWebhookSchemaBase = z.object({url: parseUrlSchema,triggers: z.array(z.enum(WEBHOOK_TRIGGERS)),linkTarget: z.enum(LinkTarget).nullish(),- linkIds: z.array(z.string()).nullish(),- folderIds: z.array(z.string()).nullish(),+ linkIds: z+ .array(z.string())+ .max(1000, {+ error:+ "You can only select up to 1000 links. Recommended to use the 'Include specific folders' option instead.",+ })+ .nullish(),+ folderIds: z+ .array(z.string())+ .max(1000, { error: "You can only select up to 1000 folders." })+ .nullish(),});export const createWebhookSchema =