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.

only business users can enable the webhook

Kiran Ka870891768f8
diff --git a/apps/web/app/api/slack/callback/route.ts b/apps/web/app/api/slack/callback/route.ts
index 518586645c..22e91485fa 100644
--- a/apps/web/app/api/slack/callback/route.ts
+++ b/apps/web/app/api/slack/callback/route.ts
@@ -25,7 +25,7 @@ const oAuthCallbackSchema = z.object({
export const GET = async (req: Request) => {
const env = getSlackEnv();
- let workspace: Pick<Project, "id" | "slug"> | null = null;
+ let workspace: Pick<Project, "id" | "slug" | "plan"> | null = null;
try {
const session = await getSession();
@@ -56,6 +56,7 @@ export const GET = async (req: Request) => {
select: {
id: true,
slug: true,
+ plan: true,
},
});
@@ -101,7 +102,7 @@ export const GET = async (req: Request) => {
url: data.incoming_webhook.url,
receiver: WebhookReceiver.slack,
triggers: [],
- workspaceId,
+ workspace,
installationId: installation.id,
});
} catch (e: any) {
diff --git a/apps/web/app/api/webhooks/route.ts b/apps/web/app/api/webhooks/route.ts
index d3e365e26f..71b9a5260f 100644
--- a/apps/web/app/api/webhooks/route.ts
+++ b/apps/web/app/api/webhooks/route.ts
@@ -126,10 +126,17 @@ export const POST = withWorkspace(
triggers,
linkIds,
secret,
- workspaceId: workspace.id,
+ workspace,
installationId: zapierInstallation ? zapierInstallation.id : undefined,
});
+ if (!webhook) {
+ throw new DubApiError({
+ code: "bad_request",
+ message: "Failed to create webhook.",
+ });
+ }
+
waitUntil(
(async () => {
const links = await prisma.link.findMany({
diff --git a/apps/web/lib/integrations/segment/install.ts b/apps/web/lib/integrations/segment/install.ts
index 1a142ac6bb..16ef177ccb 100644
--- a/apps/web/lib/integrations/segment/install.ts
+++ b/apps/web/lib/integrations/segment/install.ts
@@ -33,7 +33,7 @@ export const installSegmentAction = authActionClient
url: "https://api.segment.io/v1/track",
receiver: WebhookReceiver.segment,
triggers: [],
- workspaceId: workspace.id,
+ workspace,
secret: writeKey,
installationId: installation.id,
});
diff --git a/apps/web/lib/webhook/create-webhook.ts b/apps/web/lib/webhook/create-webhook.ts
index ba14da6ce9..59a63816c2 100644
--- a/apps/web/lib/webhook/create-webhook.ts
+++ b/apps/web/lib/webhook/create-webhook.ts
@@ -4,7 +4,7 @@ import { webhookCache } from "@/lib/webhook/cache";
import { WEBHOOK_ID_PREFIX } from "@/lib/webhook/constants";
import { isLinkLevelWebhook } from "@/lib/webhook/utils";
import { prisma } from "@dub/prisma";
-import { WebhookReceiver } from "@dub/prisma/client";
+import { Project, WebhookReceiver } from "@dub/prisma/client";
import { waitUntil } from "@vercel/functions";
import { z } from "zod";
import { createWebhookSchema } from "../zod/schemas/webhooks";
@@ -16,14 +16,19 @@ export async function createWebhook({
secret,
triggers,
linkIds,
- workspaceId,
+ workspace,
receiver,
installationId,
}: z.infer<typeof createWebhookSchema> & {
- workspaceId: string;
+ workspace: Pick<Project, "id" | "plan">;
receiver: WebhookReceiver;
installationId?: string;
}) {
+ // Webhooks are only supported on Business plans and above
+ if (["free", "pro"].includes(workspace.plan)) {
+ return;
+ }
+
const webhook = await prisma.webhook.create({
data: {
id: createId({ prefix: WEBHOOK_ID_PREFIX }),
@@ -32,7 +37,7 @@ export async function createWebhook({
triggers,
receiver,
installationId,
- projectId: workspaceId,
+ projectId: workspace.id,
secret: secret || createWebhookSecret(),
links: {
...(linkIds &&
@@ -57,7 +62,7 @@ export async function createWebhook({
await prisma.project.update({
where: {
- id: workspaceId,
+ id: workspace.id,
},
data: {
webhookEnabled: true,
@@ -69,7 +74,7 @@ export async function createWebhook({
const links = await prisma.link.findMany({
where: {
id: { in: linkIds },
- projectId: workspaceId,
+ projectId: workspace.id,
},
include: {
webhooks: {