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.

Remove webhook

Kiran K7c82d1427a5a
diff --git a/apps/web/app/api/links/route.ts b/apps/web/app/api/links/route.ts
index 1e7bcd9769..1a41392b10 100644
--- a/apps/web/app/api/links/route.ts
+++ b/apps/web/app/api/links/route.ts
@@ -1,7 +1,6 @@
import { getDomainOrThrow } from "@/lib/api/domains/get-domain-or-throw";
import { DubApiError, ErrorCodes } from "@/lib/api/errors";
import { createLink, getLinksForWorkspace, processLink } from "@/lib/api/links";
-import { sendToZapier } from "@/lib/api/links/send-to-zapier";
import { throwIfLinksUsageExceeded } from "@/lib/api/links/usage-checks";
import { parseRequestBody } from "@/lib/api/utils";
import { withWorkspace } from "@/lib/auth";
@@ -11,7 +10,6 @@ import {
getLinksQuerySchemaExtended,
} from "@/lib/zod/schemas/links";
import { LOCALHOST_IP, getSearchParamsWithArray } from "@dub/utils";
-import { waitUntil } from "@vercel/functions";
import { NextResponse } from "next/server";
// GET /api/links – get all links for a workspace
@@ -99,10 +97,6 @@ export const POST = withWorkspace(
try {
const response = await createLink(link);
- if (workspace && workspace.zapierHookEnabled) {
- waitUntil(sendToZapier(response));
- }
-
return NextResponse.json(response, { headers });
} catch (error) {
if (error.code === "P2002") {
diff --git a/apps/web/app/api/zapier/subscribe/route.ts b/apps/web/app/api/zapier/subscribe/route.ts
deleted file mode 100644
index 4fbc7ba893..0000000000
--- a/apps/web/app/api/zapier/subscribe/route.ts
+++ /dev/null
@@ -1,67 +0,0 @@
-import { parseRequestBody } from "@/lib/api/utils";
-import { withWorkspace } from "@/lib/auth";
-import { prisma } from "@/lib/prisma";
-import z from "@/lib/zod";
-import { NextResponse } from "next/server";
-
-const subscribeSchema = z.object({
- url: z.string(),
-});
-
-const unsubscribeSchema = z.object({
- id: z.string(),
-});
-
-// GET /api/zapier/subscribe - Subscribe to a Zapier hook
-export const POST = withWorkspace(async ({ workspace, req }) => {
- const { url } = subscribeSchema.parse(await parseRequestBody(req));
-
- // Create a new Zapier hook for the workspace
- const hook = await prisma.zapierHook.create({
- data: {
- projectId: workspace.id,
- url,
- },
- });
-
- if (!workspace.zapierHookEnabled) {
- await prisma.project.update({
- where: { id: workspace.id },
- data: { zapierHookEnabled: true },
- });
- }
-
- console.info(`[Zapier] Workspace ${workspace.id} subscribed to ${hook}`);
-
- return NextResponse.json({ id: hook.id }, { status: 201 });
-});
-
-// DELETE /api/zapier/unsubscribe - Unsubscribe from a Zapier hook
-export const DELETE = withWorkspace(async ({ workspace, searchParams }) => {
- const { id } = unsubscribeSchema.parse(searchParams);
-
- const hook = await prisma.zapierHook.delete({
- where: {
- projectId: workspace.id,
- id,
- },
- });
-
- // Check if there are any hooks left for the workspace
- const hooks = await prisma.zapierHook.count({
- where: {
- projectId: workspace.id,
- },
- });
-
- if (hooks === 0) {
- await prisma.project.update({
- where: { id: workspace.id },
- data: { zapierHookEnabled: false },
- });
- }
-
- console.info(`[Zapier] Workspace ${workspace.id} unsubscribed from ${hook}`);
-
- return NextResponse.json({ status: "OK" });
-});
diff --git a/apps/web/lib/api/links/send-to-zapier.ts b/apps/web/lib/api/links/send-to-zapier.ts
deleted file mode 100644
index ba0a2e234a..0000000000
--- a/apps/web/lib/api/links/send-to-zapier.ts
+++ /dev/null
@@ -1,45 +0,0 @@
-import { prisma } from "@/lib/prisma";
-import { LinkProps } from "@/lib/types";
-
-export const sendToZapier = async (link: LinkProps) => {
- if (!link.projectId) {
- return;
- }
-
- const zapierHooks = await prisma.zapierHook.findMany({
- where: {
- projectId: link.projectId,
- },
- });
-
- if (zapierHooks.length === 0) {
- return;
- }
-
- // Send the response to each Zapier hook
- for (const hook of zapierHooks) {
- const response = await fetch(hook.url, {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify(link),
- });
-
- const json = await response.json();
-
- console.info(
- `[Zapier] Webhook to ${hook.url} for link ${link.id} responded with ${response.status}`,
- json,
- );
-
- // Zap has unsubscribed
- if (response.status === 401) {
- await prisma.zapierHook.delete({
- where: {
- id: hook.id,
- },
- });
- }
- }
-};
diff --git a/apps/web/prisma/schema/workspace.prisma b/apps/web/prisma/schema/workspace.prisma
index 87190671a9..d77edca92b 100644
--- a/apps/web/prisma/schema/workspace.prisma
+++ b/apps/web/prisma/schema/workspace.prisma
@@ -36,8 +36,6 @@ model Project {
oAuthCodes OAuthCode[]
oAuthApps OAuthApp[] // OAuth apps workspace published
oAuthAuthorizedApps OAuthAuthorizedApp[] // OAuth apps workspace authorized
- zapierHooks ZapierHook[]
- zapierHookEnabled Boolean @default(false)
@@index(usageLastChecked(sort: Asc))
}
diff --git a/apps/web/prisma/schema/zapier.prisma b/apps/web/prisma/schema/zapier.prisma
deleted file mode 100644
index e94f6cdfa7..0000000000
--- a/apps/web/prisma/schema/zapier.prisma
+++ /dev/null
@@ -1,11 +0,0 @@
-model ZapierHook {
- id String @id @default(cuid())
- projectId String
- url String @unique
- createdAt DateTime @default(now())
- updatedAt DateTime @updatedAt
-
- project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
-
- @@index(projectId)
-}