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.

Refactor webhook handling in integrations

Kiran Ke0a1c0a1355b
diff --git a/apps/web/app/api/integrations/uninstall/route.ts b/apps/web/app/api/integrations/uninstall/route.ts
index 34cff4857b..63672ef6bf 100644
--- a/apps/web/app/api/integrations/uninstall/route.ts
+++ b/apps/web/app/api/integrations/uninstall/route.ts
@@ -35,14 +35,14 @@ export const DELETE = withWorkspace(
});
}
- const { integrationId, webhook } = await prisma.installedIntegration.delete(
+ const { integrationId, webhooks } = await prisma.installedIntegration.delete(
{
where: {
id: installationId,
},
select: {
integrationId: true,
- webhook: {
+ webhooks: {
select: {
id: true,
triggers: true,
@@ -52,15 +52,16 @@ export const DELETE = withWorkspace(
},
);
+
waitUntil(
Promise.all([
...(integrationId === SLACK_INTEGRATION_ID
? [uninstallSlackIntegration({ installation })]
: []),
- ...(webhook && isLinkLevelWebhook(webhook)
- ? [webhookCache.delete(webhook.id)]
- : []),
+ ...(webhooks.map((webhook) => isLinkLevelWebhook(webhook)
+ ? [webhookCache.delete(webhook.id)]
+ : []),
]),
);
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/integrations/[integrationSlug]/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/integrations/[integrationSlug]/page.tsx
index 454d246729..240b1da62f 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/integrations/[integrationSlug]/page.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/integrations/[integrationSlug]/page.tsx
@@ -34,7 +34,7 @@ export default async function IntegrationPage({
image: true,
},
},
- webhook: {
+ webhooks: {
select: {
id: true,
},
@@ -62,8 +62,10 @@ export default async function IntegrationPage({
? integration.installations[0]?.credentials
: undefined;
+ // TODO:
+ // Fix this, we only displaying the first webhook only
const webhookId = installed
- ? integration.installations[0]?.webhook?.id
+ ? integration.installations[0]?.webhooks[0]?.id
: undefined;
return (
diff --git a/packages/prisma/schema/integration.prisma b/packages/prisma/schema/integration.prisma
index 76e4203f37..3b80ec2cd9 100644
--- a/packages/prisma/schema/integration.prisma
+++ b/packages/prisma/schema/integration.prisma
@@ -41,7 +41,7 @@ model InstalledIntegration {
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
refreshTokens OAuthRefreshToken[]
accessTokens RestrictedToken[]
- webhook Webhook?
+ webhooks Webhook[]
@@unique([userId, integrationId, projectId])
@@index([projectId])
diff --git a/packages/prisma/schema/webhook.prisma b/packages/prisma/schema/webhook.prisma
index e1b345e9a5..33575dcb0c 100644
--- a/packages/prisma/schema/webhook.prisma
+++ b/packages/prisma/schema/webhook.prisma
@@ -9,7 +9,7 @@ enum WebhookReceiver {
model Webhook {
id String @id @default(cuid())
projectId String
- installationId String? @unique // indicates which integration installation added the webhook
+ installationId String? // indicates which integration installation added the webhook
receiver WebhookReceiver @default(user)
name String
url String @db.LongText
@@ -25,7 +25,8 @@ model Webhook {
installedIntegration InstalledIntegration? @relation(fields: [installationId], references: [id], onDelete: Cascade)
links LinkWebhook[]
- @@index([projectId])
+ @@index(projectId)
+ @@index(installationId)
}
model LinkWebhook {