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.

hasPartnersTriggers check

Steven Tey41d6dfef28e5
diff --git a/apps/web/app/api/webhooks/[webhookId]/route.ts b/apps/web/app/api/webhooks/[webhookId]/route.ts
index 7498a72587..bd7dad36e1 100644
--- a/apps/web/app/api/webhooks/[webhookId]/route.ts
+++ b/apps/web/app/api/webhooks/[webhookId]/route.ts
@@ -134,7 +134,7 @@ export const PATCH = withWorkspace(
throw new DubApiError({
code: "bad_request",
message:
- "Partners are not enabled on this workspace to use the following triggers: " +
+ "Dub Partners is not enabled on this workspace, which is required to use the following webhook triggers: " +
PARTNERS_WEBHOOK_TRIGGERS.join(", "),
});
}
diff --git a/apps/web/app/api/webhooks/route.ts b/apps/web/app/api/webhooks/route.ts
index 14d6fc9976..4aca1c877e 100644
--- a/apps/web/app/api/webhooks/route.ts
+++ b/apps/web/app/api/webhooks/route.ts
@@ -4,6 +4,7 @@ import { parseRequestBody } from "@/lib/api/utils";
import { withWorkspace } from "@/lib/auth";
import { getFolders } from "@/lib/folder/get-folders";
import { webhookCache } from "@/lib/webhook/cache";
+import { PARTNERS_WEBHOOK_TRIGGERS } from "@/lib/webhook/constants";
import { createWebhook } from "@/lib/webhook/create-webhook";
import { transformWebhook } from "@/lib/webhook/transform";
import { toggleWebhooksForWorkspace } from "@/lib/webhook/update-webhook";
@@ -65,6 +66,21 @@ export const POST = withWorkspace(
await parseRequestBody(req),
);
+ if (triggers) {
+ const hasPartnersTriggers = PARTNERS_WEBHOOK_TRIGGERS.some((trigger) =>
+ triggers.includes(trigger),
+ );
+
+ if (hasPartnersTriggers && !workspace.partnersEnabled) {
+ throw new DubApiError({
+ code: "bad_request",
+ message:
+ "Dub Partners is not enabled on this workspace, which is required to use the following webhook triggers: " +
+ PARTNERS_WEBHOOK_TRIGGERS.join(", "),
+ });
+ }
+ }
+
const existingWebhook = await prisma.webhook.findFirst({
where: {
url,