The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Move link.clicked trigger last and clear scope when removed
Kiran K4fdfe3fde81d
diff --git a/apps/web/app/api/webhooks/[webhookId]/route.ts b/apps/web/app/api/webhooks/[webhookId]/route.tsindex c95118ed03..3ffd15ae10 100644--- a/apps/web/app/api/webhooks/[webhookId]/route.ts+++ b/apps/web/app/api/webhooks/[webhookId]/route.ts@@ -3,7 +3,10 @@ import { parseRequestBody } from "@/lib/api/utils";import { withWorkspace } from "@/lib/auth";import { prisma } from "@/lib/prisma";import { NewWebhook } from "@/lib/types";-import { WebhookTrigger } from "@/lib/webhook/constants";+import {+ LINK_CLICK_WEBHOOK_TRIGGER,+ WebhookTrigger,+} from "@/lib/webhook/constants";import { syncWorkspaceWebhookStatus } from "@/lib/webhook/update-webhook";import { validateWebhook } from "@/lib/webhook/validate-webhook";import { updateWebhookSchema, WebhookSchema } from "@/lib/zod/schemas/webhooks";@@ -67,10 +70,25 @@ export const PATCH = withWorkspace(});}+ const finalTriggers = (+ triggers !== undefined ? triggers : existingWebhook.triggers+ ) as WebhookTrigger[];++ const hasLinkClickedTrigger = finalTriggers.includes(+ LINK_CLICK_WEBHOOK_TRIGGER,+ );++ const nextScope = hasLinkClickedTrigger+ ? scope !== undefined+ ? scope+ : existingWebhook.scope+ : null;+const nextWebhook: Partial<NewWebhook> = {...existingWebhook,...input,- triggers: (triggers ?? existingWebhook.triggers) as WebhookTrigger[],+ triggers: finalTriggers,+ scope: nextScope,};await validateWebhook({@@ -85,9 +103,7 @@ export const PATCH = withWorkspace((folder) => folder.folderId,);- const scopeChanged =- (triggers !== undefined || scope !== undefined) &&- nextWebhook.scope !== existingWebhook.scope;+ const scopeChanged = nextScope !== existingWebhook.scope;const shouldSyncLinks =(nextWebhook.scope !== "links" && existingLinkIds.length > 0) ||diff --git a/apps/web/lib/integrations/common/ui/configure-webhook.tsx b/apps/web/lib/integrations/common/ui/configure-webhook.tsxindex 16b42ec1b1..339b079107 100644--- a/apps/web/lib/integrations/common/ui/configure-webhook.tsx+++ b/apps/web/lib/integrations/common/ui/configure-webhook.tsx@@ -118,6 +118,7 @@ export function ConfigureWebhook({[...WORKSPACE_LEVEL_WEBHOOK_TRIGGERS,...(defaultProgramId ? PROGRAM_LEVEL_WEBHOOK_TRIGGERS : []),+ LINK_CLICK_WEBHOOK_TRIGGER,].filter((trigger) => supportedEvents.includes(trigger)),[defaultProgramId, supportedEvents],);diff --git a/apps/web/lib/webhook/constants.ts b/apps/web/lib/webhook/constants.tsindex 8320373106..9d1d03bffc 100644--- a/apps/web/lib/webhook/constants.ts+++ b/apps/web/lib/webhook/constants.ts@@ -8,13 +8,14 @@ export const WEBHOOK_SECRET_PREFIX = "whsec_";export const WEBHOOK_EVENT_ID_PREFIX = "evt_";+export const LINK_CLICK_WEBHOOK_TRIGGER = "link.clicked" as const;+export const WORKSPACE_LEVEL_WEBHOOK_TRIGGERS = ["link.created","link.updated","link.deleted","lead.created","sale.created",- "link.clicked",] as const;export const PROGRAM_LEVEL_WEBHOOK_TRIGGERS = [@@ -26,8 +27,6 @@ export const PROGRAM_LEVEL_WEBHOOK_TRIGGERS = ["payout.confirmed",] as const;-export const LINK_CLICK_WEBHOOK_TRIGGER = "link.clicked" as const;-export const WEBHOOK_SCOPE_OPTIONS = [{value: "all",@@ -36,14 +35,13 @@ export const WEBHOOK_SCOPE_OPTIONS = [},{value: "folders",- label: "Include all links in a folder",+ label: "Include specific folders",description: "Trigger webhooks for all links from a selected folder",},{value: "links",label: "Include specific links",- description:- "Trigger webhooks for the links you explicitly select (linkIds)",+ description: "Trigger webhooks for the links you explicitly select",},] as const satisfies ReadonlyArray<{value: WebhookScope;@@ -54,6 +52,7 @@ export const WEBHOOK_SCOPE_OPTIONS = [export const WEBHOOK_TRIGGERS = [...WORKSPACE_LEVEL_WEBHOOK_TRIGGERS,...PROGRAM_LEVEL_WEBHOOK_TRIGGERS,+ LINK_CLICK_WEBHOOK_TRIGGER,] as const;export type WebhookTrigger = (typeof WEBHOOK_TRIGGERS)[number];diff --git a/apps/web/ui/webhooks/add-edit-webhook-form.tsx b/apps/web/ui/webhooks/add-edit-webhook-form.tsxindex 6110f8b13f..b885a96002 100644--- a/apps/web/ui/webhooks/add-edit-webhook-form.tsx+++ b/apps/web/ui/webhooks/add-edit-webhook-form.tsx@@ -173,6 +173,7 @@ export default function AddEditWebhookForm({EXTERNAL_PAYOUTS_PROGRAM_IDS.includes(defaultProgramId),): []),+ LINK_CLICK_WEBHOOK_TRIGGER,],[defaultProgramId],);diff --git a/apps/web/ui/webhooks/webhook-trigger-selector.tsx b/apps/web/ui/webhooks/webhook-trigger-selector.tsxindex adc2f9bef1..959c049c82 100644--- a/apps/web/ui/webhooks/webhook-trigger-selector.tsx+++ b/apps/web/ui/webhooks/webhook-trigger-selector.tsx@@ -7,7 +7,7 @@ import {WEBHOOK_TRIGGER_DESCRIPTIONS,WebhookTrigger,} from "@/lib/webhook/constants";-import { Checkbox, CircleCheckFill, RadioGroup, RadioGroupItem } from "@dub/ui";+import { Checkbox, RadioGroup, RadioGroupItem } from "@dub/ui";import { arrayEqual, cn, fetcher } from "@dub/utils";import { WebhookScope } from "@prisma/client";import { useEffect } from "react";@@ -157,11 +157,6 @@ export function WebhookTriggerSelector({className="flex select-none items-center gap-2 text-sm text-neutral-600 group-hover:text-neutral-800">{WEBHOOK_TRIGGER_DESCRIPTIONS[trigger]}- {trigger === LINK_CLICK_WEBHOOK_TRIGGER ? (- <span className="rounded bg-yellow-100 px-1 py-0.5 text-xs font-medium text-yellow-800">- High traffic- </span>- ) : null}</label></div>@@ -182,7 +177,7 @@ export function WebhookTriggerSelector({<div key={option.value}><labelclassName={cn(- "relative flex w-full cursor-pointer items-start gap-3 rounded-md border border-neutral-200 bg-white p-3 text-neutral-600 hover:bg-neutral-50",+ "relative flex w-full cursor-pointer items-start gap-3 rounded-md border border-neutral-200 bg-white p-2 text-neutral-600 hover:bg-neutral-50","transition-all duration-150",isSelected &&"border-black bg-neutral-50 text-neutral-900 ring-1 ring-black",@@ -201,12 +196,6 @@ export function WebhookTriggerSelector({{option.description}</span></div>- <CircleCheckFill- className={cn(- "-mr-px -mt-px flex size-4 scale-75 items-center justify-center rounded-full opacity-0 transition-[transform,opacity] duration-150",- isSelected && "scale-100 opacity-100",- )}- /></label>{isSelected && option.value === "folders" ? (