The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
add zapierHookEnabled
Kiran Kd45a2fb7f45b
diff --git a/apps/web/app/api/links/route.ts b/apps/web/app/api/links/route.tsindex 1774bc054e..73715cbf90 100644--- a/apps/web/app/api/links/route.ts+++ b/apps/web/app/api/links/route.ts@@ -86,10 +86,8 @@ export const POST = withWorkspace(try {const response = await createLink(link);- // TODO:- // Send only if Zapier is enabled- // How do we optimize this?- if (response.projectId) {+ // Publish to Zapier if the project has a Zapier hook enabled+ if (response.projectId && workspace.zapierHookEnabled) {await qstash.publishJSON({url: `${APP_DOMAIN_WITH_NGROK}/api/zapier/send-webhook`,body: {diff --git a/apps/web/app/api/zapier/subscribe/route.ts b/apps/web/app/api/zapier/subscribe/route.tsindex 06b1587fb7..ae3cffa1da 100644--- a/apps/web/app/api/zapier/subscribe/route.ts+++ b/apps/web/app/api/zapier/subscribe/route.ts@@ -11,6 +11,7 @@ const subscribeSchema = z.object({export const POST = withWorkspace(async ({ workspace, req }) => {const { url } = subscribeSchema.parse(await parseRequestBody(req));+ // Create a new Zapier hook for the workspaceconst hook = await prisma.zapierHook.create({data: {projectId: workspace.id,@@ -18,6 +19,18 @@ export const POST = withWorkspace(async ({ workspace, req }) => {},});+ // Enable the hook on the workspace+ if (hook) {+ 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 });diff --git a/apps/web/app/api/zapier/unsubscribe/route.ts b/apps/web/app/api/zapier/unsubscribe/route.tsindex 7c18cf7ce5..0b211801e9 100644--- a/apps/web/app/api/zapier/unsubscribe/route.ts+++ b/apps/web/app/api/zapier/unsubscribe/route.ts@@ -18,6 +18,25 @@ export const POST = withWorkspace(async ({ workspace, req }) => {},});+ // Check if there are any hooks left for the workspace+ const hooks = await prisma.zapierHook.count({+ where: {+ projectId: workspace.id,+ },+ });++ // Disable the hook on the workspace+ 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/prisma/schema.prisma b/apps/web/prisma/schema.prismaindex 2dcd7f10e4..7f162188f8 100644--- a/apps/web/prisma/schema.prisma+++ b/apps/web/prisma/schema.prisma@@ -103,6 +103,7 @@ model Project {domainsLimit Int @default(3)tagsLimit Int @default(5)usersLimit Int @default(1)+ zapierHookEnabled Boolean @default(false)users ProjectUsers[]invites ProjectInvite[]@@ -114,7 +115,8 @@ model Project {createdAt DateTime @default(now())updatedAt DateTime @updatedAt- inviteCode String? @unique+ inviteCode String? @unique+defaultDomains DefaultDomains[]zapierHooks ZapierHook[]}