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.

Split program application webhook payload and flag deprecated triggers

Kiran Kc2400be4ef63
diff --git a/apps/web/app/(ee)/api/partners/[partnerId]/network-activity/route.ts b/apps/web/app/(ee)/api/partners/[partnerId]/network-activity/route.ts
index c0d61fa173..d2ea3dc4ba 100644
--- a/apps/web/app/(ee)/api/partners/[partnerId]/network-activity/route.ts
+++ b/apps/web/app/(ee)/api/partners/[partnerId]/network-activity/route.ts
@@ -14,21 +14,35 @@ export const GET = withWorkspace(
const { partnerId } = params;
const programId = getDefaultProgramIdOrThrow(workspace);
- const programApplication = await prisma.programApplication.findFirst({
- where: {
- programId,
- partnerId,
- },
- select: {
- id: true,
- },
- });
+ const [programApplication, programEnrollment] = await Promise.all([
+ prisma.programApplication.findFirst({
+ where: {
+ programId,
+ partnerId,
+ },
+ select: {
+ id: true,
+ },
+ }),
+
+ prisma.programEnrollment.findUnique({
+ where: {
+ partnerId_programId: {
+ partnerId,
+ programId,
+ },
+ },
+ select: {
+ id: true,
+ },
+ }),
+ ]);
- // Prevent fetching the network activity summary if the partner has not applied to the program
- if (!programApplication) {
+ // Prevent fetching the network activity summary if the partner has neither applied to nor enrolled in the program
+ if (!programApplication && !programEnrollment) {
throw new DubApiError({
code: "not_found",
- message: `Partner ${partnerId} has not applied to program.`,
+ message: `Partner ${partnerId} has not applied to or enrolled in program.`,
});
}
diff --git a/apps/web/lib/actions/partners/create-program-application.ts b/apps/web/lib/actions/partners/create-program-application.ts
index 6d883fd801..39cd904380 100644
--- a/apps/web/lib/actions/partners/create-program-application.ts
+++ b/apps/web/lib/actions/partners/create-program-application.ts
@@ -26,12 +26,16 @@ import {
import { assertRateLimit } from "@/lib/upstash/assert-rate-limit";
import { RATELIMIT_POLICIES } from "@/lib/upstash/ratelimit-policies";
import { sendWorkspaceWebhook } from "@/lib/webhook/publish";
-import { programApplicationWebhookSchema } from "@/lib/zod/schemas/program-application";
+import {
+ partnerApplicationWebhookSchema,
+ programApplicationWebhookSchema,
+} from "@/lib/zod/schemas/program-application";
import { programApplicationFormWebsiteAndSocialsFieldWithValueSchema } from "@/lib/zod/schemas/program-application-form";
import { createProgramApplicationSchema } from "@/lib/zod/schemas/programs";
import {
Partner,
PartnerGroup,
+ PartnerPlatform,
Program,
ProgramEnrollment,
Project,
@@ -250,7 +254,10 @@ async function createApplicationAndEnrollment({
}: {
workspace: Pick<Project, "id" | "webhookEnabled">;
program: Program;
- partner: Partner & { programs: ProgramEnrollment[] };
+ partner: Partner & {
+ programs: ProgramEnrollment[];
+ platforms: PartnerPlatform[];
+ };
group: PartnerGroup;
data: z.infer<typeof createProgramApplicationSchema>;
inAppApplication?: boolean;
@@ -331,7 +338,7 @@ async function createApplicationAndEnrollment({
}),
);
- const webhookPayload = programApplicationWebhookSchema.parse({
+ const webhookData = {
id: application.id,
createdAt: application.createdAt,
applicationFormData,
@@ -341,7 +348,7 @@ async function createApplicationAndEnrollment({
id: partner.id,
...formatWebsiteAndSocialsFields(application),
},
- });
+ };
await Promise.allSettled([
notifyProgramApplication({
@@ -368,14 +375,14 @@ async function createApplicationAndEnrollment({
sendWorkspaceWebhook({
workspace,
trigger: "partner.application_submitted",
- data: webhookPayload,
+ data: partnerApplicationWebhookSchema.parse(webhookData),
}),
// Send "program_application.created" webhook
sendWorkspaceWebhook({
workspace,
trigger: "program_application.created",
- data: webhookPayload,
+ data: programApplicationWebhookSchema.parse(webhookData),
}),
// Detect and record fraud events for the partner when they apply to a program
diff --git a/apps/web/lib/integrations/slack/transform.ts b/apps/web/lib/integrations/slack/transform.ts
index 1e99154cc9..1db5cc89fd 100644
--- a/apps/web/lib/integrations/slack/transform.ts
+++ b/apps/web/lib/integrations/slack/transform.ts
@@ -12,10 +12,10 @@ import {
CommissionEventWebhookPayload,
DiscountCodeEventWebhookPayload,
LeadEventWebhookPayload,
+ PartnerApplicationWebhookPayload,
PartnerEventWebhookPayload,
PartnerMergedWebhookPayload,
PayoutEventWebhookPayload,
- ProgramApplicationWebhookPayload,
SaleEventWebhookPayload,
} from "../../webhook/types";
@@ -311,7 +311,7 @@ const partnerEnrolledTemplate = ({
const programApplicationSubmittedTemplate = ({
data,
}: {
- data: ProgramApplicationWebhookPayload;
+ data: PartnerApplicationWebhookPayload;
}) => {
const { partner } = data;
const hrefToApplicationPage = `${APP_DOMAIN}/program/partners/applications?partnerId=${partner.id}`;
diff --git a/apps/web/lib/partners/complete-program-applications.ts b/apps/web/lib/partners/complete-program-applications.ts
index 9c5fb059d8..cb4906586f 100644
--- a/apps/web/lib/partners/complete-program-applications.ts
+++ b/apps/web/lib/partners/complete-program-applications.ts
@@ -10,7 +10,10 @@ import { autoApprovePartnerJob } from "../jobs/handlers/auto-approve-partner-job
import { autoRejectPartnerJob } from "../jobs/handlers/auto-reject-partner-job";
import { buildSocialPlatformLookup } from "../social-utils";
import { sendWorkspaceWebhook } from "../webhook/publish";
-import { programApplicationWebhookSchema } from "../zod/schemas/program-application";
+import {
+ partnerApplicationWebhookSchema,
+ programApplicationWebhookSchema,
+} from "../zod/schemas/program-application";
import { evaluateApplicationRequirements } from "./evaluate-application-requirements";
import {
formatApplicationFormData,
@@ -214,7 +217,7 @@ export async function completeProgramApplications(userEmail: string) {
},
});
- const webhookPayload = programApplicationWebhookSchema.parse({
+ const webhookData = {
id: application.id,
createdAt: application.createdAt,
applicationFormData,
@@ -225,7 +228,7 @@ export async function completeProgramApplications(userEmail: string) {
status: "pending",
...formatWebsiteAndSocialsFields(application),
},
- });
+ };
await Promise.allSettled([
...(validApplication
@@ -255,7 +258,7 @@ export async function completeProgramApplications(userEmail: string) {
sendWorkspaceWebhook({
workspace: workspacesByProgramId.get(program.id)!,
trigger: "partner.application_submitted",
- data: webhookPayload,
+ data: partnerApplicationWebhookSchema.parse(webhookData),
}),
// Send "program_application.created" webhook
@@ -263,7 +266,7 @@ export async function completeProgramApplications(userEmail: string) {
sendWorkspaceWebhook({
workspace: workspacesByProgramId.get(program.id)!,
trigger: "program_application.created",
- data: webhookPayload,
+ data: programApplicationWebhookSchema.parse(webhookData),
}),
]
: [
diff --git a/apps/web/lib/webhook/constants.ts b/apps/web/lib/webhook/constants.ts
index 55e474ff9b..ae128817f3 100644
--- a/apps/web/lib/webhook/constants.ts
+++ b/apps/web/lib/webhook/constants.ts
@@ -47,6 +47,16 @@ export const LEGACY_WEBHOOK_TRIGGER_REPLACEMENTS = [
current: WebhookTrigger;
}[];
+export const DEPRECATED_WEBHOOK_TRIGGERS = new Map<
+ WebhookTrigger,
+ WebhookTrigger
+>(
+ LEGACY_WEBHOOK_TRIGGER_REPLACEMENTS.map(({ legacy, current }) => [
+ legacy,
+ current,
+ ]),
+);
+
export const WEBHOOK_TRIGGER_DESCRIPTIONS: Record<WebhookTrigger, string> = {
"link.created": "Occurs whenever a link is created",
"link.updated": "Occurs whenever a link is updated",
diff --git a/apps/web/lib/webhook/sample-events/program-application-created.json b/apps/web/lib/webhook/sample-events/program-application-created.json
index 8cba09d8f8..d252b4b33f 100644
--- a/apps/web/lib/webhook/sample-events/program-application-created.json
+++ b/apps/web/lib/webhook/sample-events/program-application-created.json
@@ -10,7 +10,22 @@
"description": "I'm a content creator who works with brands to grow their business.",
"country": "US",
"groupId": "grp_1K9BZE1K2RWYAWB2K1YN5TY7F",
- "status": "pending"
+ "status": "pending",
+ "networkStatus": "approved",
+ "defaultPayoutMethod": "connect",
+ "payoutsEnabledAt": "2025-10-01T09:12:45.000Z",
+ "platforms": [
+ {
+ "type": "website",
+ "identifier": "https://example.com",
+ "verifiedAt": "2025-10-02T14:03:11.000Z"
+ },
+ {
+ "type": "twitter",
+ "identifier": "matthewhayden",
+ "verifiedAt": null
+ }
+ ]
},
"applicationFormData": [
{
diff --git a/apps/web/lib/webhook/schemas.ts b/apps/web/lib/webhook/schemas.ts
index 401f39adf3..b6f6a7a3c6 100644
--- a/apps/web/lib/webhook/schemas.ts
+++ b/apps/web/lib/webhook/schemas.ts
@@ -9,7 +9,10 @@ import {
partnerMergedWebhookSchema,
WebhookPartnerSchema,
} from "../zod/schemas/partners";
-import { programApplicationWebhookSchema } from "../zod/schemas/program-application";
+import {
+ partnerApplicationWebhookSchema,
+ programApplicationWebhookSchema,
+} from "../zod/schemas/program-application";
import { WEBHOOK_TRIGGERS } from "./constants";
const webhookSaleSchema = z.object({
@@ -149,7 +152,7 @@ export const webhookEventSchema = z
id: z.string(),
event: z.literal("partner.application_submitted"),
createdAt: z.string(),
- data: programApplicationWebhookSchema,
+ data: partnerApplicationWebhookSchema,
})
.meta({
description:
diff --git a/apps/web/lib/webhook/types.ts b/apps/web/lib/webhook/types.ts
index 954618ec3b..7a2e5da098 100644
--- a/apps/web/lib/webhook/types.ts
+++ b/apps/web/lib/webhook/types.ts
@@ -8,7 +8,10 @@ import {
partnerMergedWebhookSchema,
} from "../zod/schemas/partners";
import { payoutWebhookEventSchema } from "../zod/schemas/payouts";
-import { programApplicationWebhookSchema } from "../zod/schemas/program-application";
+import {
+ partnerApplicationWebhookSchema,
+ programApplicationWebhookSchema,
+} from "../zod/schemas/program-application";
import { WEBHOOK_TRIGGERS } from "./constants";
import {
clickWebhookEventSchema,
@@ -26,6 +29,10 @@ export type SaleEventWebhookPayload = z.infer<typeof saleWebhookEventSchema>;
export type PartnerEventWebhookPayload = z.infer<typeof EnrolledPartnerSchema>;
+export type PartnerApplicationWebhookPayload = z.infer<
+ typeof partnerApplicationWebhookSchema
+>;
+
export type ProgramApplicationWebhookPayload = z.infer<
typeof programApplicationWebhookSchema
>;
@@ -54,6 +61,7 @@ export type WebhookEventPayload =
| LeadEventWebhookPayload
| SaleEventWebhookPayload
| PartnerEventWebhookPayload
+ | PartnerApplicationWebhookPayload
| ProgramApplicationWebhookPayload
| PartnerMergedWebhookPayload
| CommissionEventWebhookPayload
diff --git a/apps/web/lib/webhook/utils.ts b/apps/web/lib/webhook/utils.ts
index 83e4054e62..965400278c 100644
--- a/apps/web/lib/webhook/utils.ts
+++ b/apps/web/lib/webhook/utils.ts
@@ -28,8 +28,9 @@ export const identifyWebhookReceiver = (url: string): WebhookReceiver => {
*
* `subscribedTriggers` is the saved webhook's events:
* - `null` (creating a new webhook): show the current event, hide the legacy one.
- * - array (editing): show the legacy event if the webhook is already subscribed
- * to it, otherwise show the current event.
+ * - array (editing): show both events if the webhook is already subscribed to
+ * the legacy one (so it can migrate in a single edit), otherwise show only
+ * the current event.
* - `undefined` (saved webhook still loading): hide both until it's known.
*
* Hidden events that are already subscribed stay in the webhook's saved
@@ -47,7 +48,7 @@ export function getVisibleWebhookTriggers(
const showLegacy = subscribedTriggers?.includes(legacy) ?? false;
- return [showLegacy ? current : legacy];
+ return showLegacy ? [] : [legacy];
}),
);
diff --git a/apps/web/lib/zod/schemas/program-application.ts b/apps/web/lib/zod/schemas/program-application.ts
index 929d141362..9e5b6a5852 100644
--- a/apps/web/lib/zod/schemas/program-application.ts
+++ b/apps/web/lib/zod/schemas/program-application.ts
@@ -70,7 +70,18 @@ export const ProgramApplicationSchema = PartnerApplicationSchema.extend({
}),
});
-export const programApplicationWebhookSchema = PartnerApplicationSchema;
+// @deprecated Use programApplicationWebhookSchema instead. Kept for backward compatibility.
+export const partnerApplicationWebhookSchema = PartnerApplicationSchema;
+export const programApplicationWebhookSchema = ProgramApplicationSchema.extend({
+ partner: ProgramApplicationSchema.shape.partner.omit({
+ website: true,
+ youtube: true,
+ twitter: true,
+ linkedin: true,
+ instagram: true,
+ tiktok: true,
+ }),
+});
export const getProgramApplicationsQuerySchema = getPartnersQuerySchema
.pick({
diff --git a/apps/web/ui/partners/fraud-risks/partner-network-activity-summary.tsx b/apps/web/ui/partners/fraud-risks/partner-network-activity-summary.tsx
index 57ef45232b..1fcc003c2b 100644
--- a/apps/web/ui/partners/fraud-risks/partner-network-activity-summary.tsx
+++ b/apps/web/ui/partners/fraud-risks/partner-network-activity-summary.tsx
@@ -36,10 +36,10 @@ function usePartnerNetworkActivitySummary(
},
);
- const isMissingApplication = error?.status === 404;
+ const isUnrelatedPartner = error?.status === 404;
- // A partner without an application to the program 404s. Missing data here is an empty result, not a request still loading.
- if (!partnerId || isMissingApplication) {
+ // A partner with neither an application nor an enrollment in the program 404s. Missing data here is an empty result, not a request still loading.
+ if (!partnerId || isUnrelatedPartner) {
return {
status: "empty",
};
diff --git a/apps/web/ui/webhooks/webhook-trigger-selector.tsx b/apps/web/ui/webhooks/webhook-trigger-selector.tsx
index 2d43f05d64..998187bcbd 100644
--- a/apps/web/ui/webhooks/webhook-trigger-selector.tsx
+++ b/apps/web/ui/webhooks/webhook-trigger-selector.tsx
@@ -2,11 +2,12 @@
import useWorkspace from "@/lib/swr/use-workspace";
import {
+ DEPRECATED_WEBHOOK_TRIGGERS,
LINK_CLICK_WEBHOOK_TRIGGER,
WEBHOOK_TRIGGER_DESCRIPTIONS,
} from "@/lib/webhook/constants";
import type { WebhookTrigger } from "@/lib/webhook/types";
-import { Checkbox, RadioGroup, RadioGroupItem } from "@dub/ui";
+import { Badge, Checkbox, RadioGroup, RadioGroupItem } from "@dub/ui";
import { arrayEqual, cn, fetcher } from "@dub/utils";
import { LinkScope } from "@prisma/client";
import { useEffect } from "react";
@@ -163,111 +164,124 @@ export function WebhookTriggerSelector({
return (
<div className="flex flex-col gap-3">
- {availableTriggers.map((trigger) => (
- <div key={trigger}>
- <div className="group flex items-start gap-2">
- <Checkbox
- value={trigger}
- id={trigger}
- checked={triggers.includes(trigger)}
- disabled={disabled}
- onCheckedChange={(checked) => toggleTrigger(trigger, checked)}
- />
- <label
- htmlFor={trigger}
- className={cn(
- "flex min-w-0 select-none flex-col",
- disabled ? "cursor-not-allowed" : "cursor-pointer",
- )}
- >
- <span className="font-mono text-sm font-medium leading-5 text-neutral-800 group-hover:text-neutral-900">
- {trigger}
- </span>
- <span className="text-[11px] leading-snug text-neutral-500">
- {WEBHOOK_TRIGGER_DESCRIPTIONS[trigger]}
- </span>
- </label>
- </div>
+ {availableTriggers.map((trigger) => {
+ const replacement = DEPRECATED_WEBHOOK_TRIGGERS.get(trigger);
- {trigger === LINK_CLICK_WEBHOOK_TRIGGER && hasLinkClicked ? (
- <div className="ml-6 mt-3 rounded-md border border-neutral-200 bg-neutral-50 p-4">
- <RadioGroup
- value={linkScope}
- onValueChange={(nextValue) =>
- handleLinkScopeChange(nextValue as LinkScope)
- }
- className="flex flex-col gap-2"
+ return (
+ <div key={trigger}>
+ <div className="group flex items-start gap-2">
+ <Checkbox
+ value={trigger}
+ id={trigger}
+ checked={triggers.includes(trigger)}
disabled={disabled}
+ onCheckedChange={(checked) => toggleTrigger(trigger, checked)}
+ />
+ <label
+ htmlFor={trigger}
+ className={cn(
+ "flex min-w-0 select-none flex-col",
+ disabled ? "cursor-not-allowed" : "cursor-pointer",
+ )}
>
- {CLICK_WEBHOOK_LINK_TARGET_OPTIONS.map((option) => {
- const isSelected = linkScope === option.value;
+ <span className="flex items-center gap-1.5">
+ <span className="font-mono text-sm font-medium leading-5 text-neutral-800 group-hover:text-neutral-900">
+ {trigger}
+ </span>
+ {replacement && <Badge variant="amber">Deprecated</Badge>}
+ </span>
+ <span className="text-[11px] leading-snug text-neutral-500">
+ {WEBHOOK_TRIGGER_DESCRIPTIONS[trigger]}
+ {replacement && (
+ <>
+ . Use <code className="font-mono">{replacement}</code>{" "}
+ instead.
+ </>
+ )}
+ </span>
+ </label>
+ </div>
- return (
- <div key={option.value}>
- <label
- className={cn(
- "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",
- disabled && "cursor-not-allowed opacity-60",
- )}
- >
- <RadioGroupItem
- value={option.value}
- id={`linkScope-${option.value}`}
- className="mt-0.5"
- disabled={disabled}
- />
- <div className="flex grow flex-col text-sm">
- <span className="font-medium">{option.label}</span>
- <span className="text-neutral-500">
- {option.description}
- </span>
- </div>
- </label>
+ {trigger === LINK_CLICK_WEBHOOK_TRIGGER && hasLinkClicked ? (
+ <div className="ml-6 mt-3 rounded-md border border-neutral-200 bg-neutral-50 p-4">
+ <RadioGroup
+ value={linkScope}
+ onValueChange={(nextValue) =>
+ handleLinkScopeChange(nextValue as LinkScope)
+ }
+ className="flex flex-col gap-2"
+ disabled={disabled}
+ >
+ {CLICK_WEBHOOK_LINK_TARGET_OPTIONS.map((option) => {
+ const isSelected = linkScope === option.value;
- {isSelected && option.value === "folders" ? (
- <div className="mt-3 pl-7">
- <h3 className="text-sm font-medium text-neutral-900">
- Included folders
- </h3>
- <div className="mt-2">
- <FoldersSelector
- selectedFolderIds={folderIds}
- setSelectedFolderIds={(ids) =>
- onChange({ ...value, folderIds: ids })
- }
- disabled={disabled}
- />
+ return (
+ <div key={option.value}>
+ <label
+ className={cn(
+ "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",
+ disabled && "cursor-not-allowed opacity-60",
+ )}
+ >
+ <RadioGroupItem
+ value={option.value}
+ id={`linkScope-${option.value}`}
+ className="mt-0.5"
+ disabled={disabled}
+ />
+ <div className="flex grow flex-col text-sm">
+ <span className="font-medium">{option.label}</span>
+ <span className="text-neutral-500">
+ {option.description}
+ </span>
</div>
- </div>
- ) : null}
+ </label>
- {isSelected && option.value === "links" ? (
- <div className="mt-3 pl-7">
- <h3 className="text-sm font-medium text-neutral-900">
- Included links
- </h3>
- <div className="mt-2">
- <LinksSelector
- selectedLinkIds={linkIds}
- setSelectedLinkIds={(ids) =>
- onChange({ ...value, linkIds: ids })
- }
- disabled={disabled}
- />
+ {isSelected && option.value === "folders" ? (
+ <div className="mt-3 pl-7">
+ <h3 className="text-sm font-medium text-neutral-900">
+ Included folders
+ </h3>
+ <div className="mt-2">
+ <FoldersSelector
+ selectedFolderIds={folderIds}
+ setSelectedFolderIds={(ids) =>
+ onChange({ ...value, folderIds: ids })
+ }
+ disabled={disabled}
+ />
+ </div>
</div>
- </div>
- ) : null}
- </div>
- );
- })}
- </RadioGroup>
- </div>
- ) : null}
- </div>
- ))}
+ ) : null}
+
+ {isSelected && option.value === "links" ? (
+ <div className="mt-3 pl-7">
+ <h3 className="text-sm font-medium text-neutral-900">
+ Included links
+ </h3>
+ <div className="mt-2">
+ <LinksSelector
+ selectedLinkIds={linkIds}
+ setSelectedLinkIds={(ids) =>
+ onChange({ ...value, linkIds: ids })
+ }
+ disabled={disabled}
+ />
+ </div>
+ </div>
+ ) : null}
+ </div>
+ );
+ })}
+ </RadioGroup>
+ </div>
+ ) : null}
+ </div>
+ );
+ })}
</div>
);
}