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.

update openAPI description + webhook payload

Steven Tey8249f8b9ced2
diff --git a/apps/web/app/(ee)/api/workflows/merge-partner-accounts/route.ts b/apps/web/app/(ee)/api/workflows/merge-partner-accounts/route.ts
index fda726434e..cbee3e044d 100644
--- a/apps/web/app/(ee)/api/workflows/merge-partner-accounts/route.ts
+++ b/apps/web/app/(ee)/api/workflows/merge-partner-accounts/route.ts
@@ -585,18 +585,17 @@ async function mergeSingleEnrollment({
workspace: sourceEnrollment.program.workspace,
trigger: "partner.merged",
data: partnerMergedWebhookSchema.parse({
- programId,
- targetAlreadyEnrolled: Boolean(targetEnrollment),
- source: {
+ sourcePartner: {
id: sourcePartnerId,
tenantId: sourceEnrollment.tenantId,
email: sourceEmail,
},
- target: {
+ targetPartner: {
id: targetPartnerId,
- tenantId: targetEnrollment?.tenantId ?? sourceEnrollment.tenantId,
+ tenantId: targetEnrollment?.tenantId ?? null,
email: targetEmail,
},
+ targetAlreadyEnrolled: Boolean(targetEnrollment),
}),
});
diff --git a/apps/web/lib/integrations/slack/transform.ts b/apps/web/lib/integrations/slack/transform.ts
index d3af84ff73..202e45e2c1 100644
--- a/apps/web/lib/integrations/slack/transform.ts
+++ b/apps/web/lib/integrations/slack/transform.ts
@@ -542,8 +542,8 @@ const partnerMergedTemplate = ({
}: {
data: PartnerMergedWebhookPayload;
}) => {
- const { targetAlreadyEnrolled, source, target } = data;
- const hrefToPartnerPage = `${APP_DOMAIN}/program/partners/${target.id}`;
+ const { targetAlreadyEnrolled, sourcePartner, targetPartner } = data;
+ const hrefToPartnerPage = `${APP_DOMAIN}/program/partners/${targetPartner.id}`;
const outcomeLabel = targetAlreadyEnrolled
? "Target was already enrolled"
: "Target was not enrolled";
@@ -562,11 +562,11 @@ const partnerMergedTemplate = ({
fields: [
{
type: "mrkdwn",
- text: `*Source*\n\`${source.id}\`${source.email ? ` (${source.email})` : ""}`,
+ text: `*Source*\n\`${sourcePartner.id}\`${sourcePartner.email ? ` (${sourcePartner.email})` : ""}`,
},
{
type: "mrkdwn",
- text: `*Target*\n<${hrefToPartnerPage}|\`${target.id}\`>${target.email ? ` (${target.email})` : ""}`,
+ text: `*Target*\n<${hrefToPartnerPage}|\`${targetPartner.id}\`>${targetPartner.email ? ` (${targetPartner.email})` : ""}`,
},
],
},
@@ -577,11 +577,11 @@ const partnerMergedTemplate = ({
type: "mrkdwn",
text: `*Outcome*\n${outcomeLabel}`,
},
- ...(source.tenantId || target.tenantId
+ ...(sourcePartner.tenantId || targetPartner.tenantId
? [
{
type: "mrkdwn",
- text: `*Tenant ID*\n${source.tenantId ?? "—"} → ${target.tenantId ?? "—"}`,
+ text: `*Tenant ID*\n${sourcePartner.tenantId ?? "—"} → ${targetPartner.tenantId ?? "—"}`,
},
]
: []),
diff --git a/apps/web/lib/webhook/sample-events/partner-merged.json b/apps/web/lib/webhook/sample-events/partner-merged.json
index d9e3d8e722..79a5e8bbf5 100644
--- a/apps/web/lib/webhook/sample-events/partner-merged.json
+++ b/apps/web/lib/webhook/sample-events/partner-merged.json
@@ -1,14 +1,13 @@
{
- "programId": "prog_CYCu7IMAapjkRpTnr8F1azjN",
- "targetAlreadyEnrolled": false,
- "source": {
+ "sourcePartner": {
"id": "pn_1K9BZE1K285BSTX4W6MPKXJFZ",
"tenantId": "64dc9a8c-5cf9-4446-b53b-cdc15199fafc",
"email": "[email protected]"
},
- "target": {
+ "targetPartner": {
"id": "pn_1K06X6FX2GRB31NCM2VVCGJ72",
- "tenantId": "64dc9a8c-5cf9-4446-b53b-cdc15199fafc",
+ "tenantId": null,
"email": "[email protected]"
- }
+ },
+ "targetAlreadyEnrolled": false
}
diff --git a/apps/web/lib/zod/schemas/partners.ts b/apps/web/lib/zod/schemas/partners.ts
index 7f09442ba9..3ac7c8e794 100644
--- a/apps/web/lib/zod/schemas/partners.ts
+++ b/apps/web/lib/zod/schemas/partners.ts
@@ -629,30 +629,6 @@ export const WebhookPartnerSchema = PartnerSchema.pick({
totalCommissions: centsSchema,
});
-const partnerMergedAccountSchema = z.object({
- id: z.string().describe("The partner's unique ID on Dub."),
- tenantId: z
- .string()
- .nullable()
- .describe("The partner's unique ID within your database for this program."),
- email: z.string().nullable().describe("The partner's email address."),
-});
-
-export const partnerMergedWebhookSchema = z.object({
- programId: z.string().describe("The program's unique ID on Dub."),
- targetAlreadyEnrolled: z
- .boolean()
- .describe(
- "Whether the surviving partner was already enrolled in this program before the merge. If `true`, the workspace had both partners and should collapse the source into the target. If `false`, only the source was enrolled and its Dub partner ID changed.",
- ),
- source: partnerMergedAccountSchema.describe(
- "The partner account that was merged away. Its enrollment in this program no longer exists; use `target.id` instead.",
- ),
- target: partnerMergedAccountSchema.describe(
- "The surviving partner account. `tenantId` is the post-merge value for this program.",
- ),
-});
-
export const LeaderboardPartnerSchema = z.object({
id: z.string(),
totalCommissions: centsSchemaWithDefault,
@@ -1094,3 +1070,30 @@ export const partnerSharedPlatformSchema = z.object({
}),
),
});
+
+const partnerMergedAccountSchema = z.object({
+ id: z.string().describe("The partner's unique ID on Dub."),
+ tenantId: z
+ .string()
+ .nullable()
+ .describe("The partner's unique ID in your system"),
+ email: z.string().nullable().describe("The partner's email address."),
+});
+
+export const partnerMergedWebhookSchema = z.object({
+ sourcePartner: partnerMergedAccountSchema.describe(
+ "The source partner account that was merged away. Its enrollment in this program no longer exists; use `target.id` instead.",
+ ),
+ targetPartner: partnerMergedAccountSchema.describe(
+ "The target partner account that the source account was merged into.",
+ ),
+ targetAlreadyEnrolled: z
+ .boolean()
+ .describe(
+ [
+ "Whether the target partner account was already enrolled in this program before the merge.",
+ "If `true`, both partners were already enrolled in the program and the merge process will collapse the source account into the target account.",
+ "If `false`, only the source partner account was enrolled in the program, which means the partner's ID in your program will be updated to the target partner's ID.",
+ ].join("\n"),
+ ),
+});