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.

add table LinkWebhook

Kiran K1d016b21fbfa
diff --git a/apps/web/app/api/webhooks/[webhookId]/events/route.ts b/apps/web/app/api/webhooks/[webhookId]/events/route.ts
index 2186e70dd4..31649831e0 100644
--- a/apps/web/app/api/webhooks/[webhookId]/events/route.ts
+++ b/apps/web/app/api/webhooks/[webhookId]/events/route.ts
@@ -31,5 +31,12 @@ export const GET = withWorkspace(
{
requiredPermissions: ["webhooks.read"],
featureFlag: "webhooks",
+ requiredPlan: [
+ "business",
+ "business plus",
+ "business extra",
+ "business max",
+ "enterprise",
+ ],
},
);
diff --git a/apps/web/app/api/webhooks/[webhookId]/route.ts b/apps/web/app/api/webhooks/[webhookId]/route.ts
index aaea027307..e0457243a2 100644
--- a/apps/web/app/api/webhooks/[webhookId]/route.ts
+++ b/apps/web/app/api/webhooks/[webhookId]/route.ts
@@ -22,6 +22,13 @@ export const GET = withWorkspace(
{
requiredPermissions: ["webhooks.read"],
featureFlag: "webhooks",
+ requiredPlan: [
+ "business",
+ "business plus",
+ "business extra",
+ "business max",
+ "enterprise",
+ ],
},
);
@@ -68,6 +75,13 @@ export const PATCH = withWorkspace(
{
requiredPermissions: ["webhooks.write"],
featureFlag: "webhooks",
+ requiredPlan: [
+ "business",
+ "business plus",
+ "business extra",
+ "business max",
+ "enterprise",
+ ],
},
);
@@ -108,5 +122,12 @@ export const DELETE = withWorkspace(
{
requiredPermissions: ["webhooks.write"],
featureFlag: "webhooks",
+ requiredPlan: [
+ "business",
+ "business plus",
+ "business extra",
+ "business max",
+ "enterprise",
+ ],
},
);
diff --git a/apps/web/app/api/webhooks/route.ts b/apps/web/app/api/webhooks/route.ts
index b4c2113f29..d05f26ce13 100644
--- a/apps/web/app/api/webhooks/route.ts
+++ b/apps/web/app/api/webhooks/route.ts
@@ -22,6 +22,13 @@ export const GET = withWorkspace(
{
requiredPermissions: ["webhooks.read"],
featureFlag: "webhooks",
+ requiredPlan: [
+ "business",
+ "business plus",
+ "business extra",
+ "business max",
+ "enterprise",
+ ],
},
);
@@ -92,5 +99,12 @@ export const POST = withWorkspace(
{
requiredPermissions: ["webhooks.write"],
featureFlag: "webhooks",
+ requiredPlan: [
+ "business",
+ "business plus",
+ "business extra",
+ "business max",
+ "enterprise",
+ ],
},
);
diff --git a/apps/web/lib/zod/schemas/webhooks.ts b/apps/web/lib/zod/schemas/webhooks.ts
index c9fcd4c5fa..fba7500759 100644
--- a/apps/web/lib/zod/schemas/webhooks.ts
+++ b/apps/web/lib/zod/schemas/webhooks.ts
@@ -6,7 +6,7 @@ import { z } from "zod";
export const webhookSchema = z.object({
id: z.string(),
- linkId: z.string().optional(),
+ // linkId: z.string().optional(),
name: z.string(),
url: z.string(),
secret: z.string(),
@@ -20,7 +20,7 @@ export const createWebhookSchema = z.object({
url: z.string().url().max(190),
secret: z.string().startsWith(WEBHOOK_SECRET_PREFIX),
triggers: z.array(z.enum(WEBHOOK_TRIGGERS)),
- linkId: z.string().nullable().optional(),
+ // linkId: z.string().nullable().optional(),
});
export const updateWebhookSchema = createWebhookSchema.partial();
diff --git a/apps/web/prisma/schema/link.prisma b/apps/web/prisma/schema/link.prisma
index bcb7d0446e..d961278c37 100644
--- a/apps/web/prisma/schema/link.prisma
+++ b/apps/web/prisma/schema/link.prisma
@@ -55,9 +55,11 @@ model Link {
// Link tags
tags LinkTag[]
+ // Link webhooks
+ linkWebhooks LinkWebhook[]
+
// Comments on the particular shortlink
- comments String? @db.LongText
- webhooks Webhook[]
+ comments String? @db.LongText
@@unique([domain, key])
@@unique([projectId, externalId])
diff --git a/apps/web/prisma/schema/webhook.prisma b/apps/web/prisma/schema/webhook.prisma
index b1dfcf3c55..e88a93aae9 100644
--- a/apps/web/prisma/schema/webhook.prisma
+++ b/apps/web/prisma/schema/webhook.prisma
@@ -8,7 +8,6 @@ model Webhook {
id String @id @default(cuid())
receiver WebhookReceiver
projectId String
- linkId String?
name String
url String
secret String
@@ -16,9 +15,21 @@ model Webhook {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
- Project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
- Link Link? @relation(fields: [linkId], references: [id], onDelete: Cascade)
+ project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
+ linkWebhooks LinkWebhook[]
@@index([projectId])
+}
+
+model LinkWebhook {
+ id String @id @default(cuid())
+ linkId String
+ webhookId String
+
+ link Link @relation(fields: [linkId], references: [id], onUpdate: Cascade, onDelete: Cascade)
+ webhook Webhook @relation(fields: [webhookId], references: [id], onUpdate: Cascade, onDelete: Cascade)
+
+ @@unique([linkId, webhookId])
@@index([linkId])
+ @@index([webhookId])
}