feat: Platform OAuthClient Webhooks (#16134)

* wip

* fixup! Merge branch 'main' into platform-oauth-client-webhooks

* wip

* fixup! Merge branch 'main' into platform-oauth-client-webhooks

* fixup! fixup! Merge branch 'main' into platform-oauth-client-webhooks

* fixup! fixup! fixup! Merge branch 'main' into platform-oauth-client-webhooks

* fixup! fixup! fixup! fixup! Merge branch 'main' into platform-oauth-client-webhooks

* fixup! fixup! fixup! fixup! fixup! Merge branch 'main' into platform-oauth-client-webhooks

* fixup! fixup! fixup! fixup! fixup! fixup! Merge branch 'main' into platform-oauth-client-webhooks

* fixup! fixup! fixup! fixup! fixup! fixup! fixup! Merge branch 'main' into platform-oauth-client-webhooks

* fixup! Merge branch 'platform-oauth-client-webhooks' of github.com:calcom/cal.com into platform-oauth-client-webhooks

* fixup! fixup! Merge branch 'platform-oauth-client-webhooks' of github.com:calcom/cal.com into platform-oauth-client-webhooks

---------

Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
MorganandPeer Richelsen authored and GitHub committed 2024-08-09 17:02:39 +02:00
1 parent 4def31e98f
commit dda4b17a7c
47 files changed
+1199 -68

No files matched your search

@@ -0,0 +1,14 @@
/*
Warnings:
- A unique constraint covering the columns `[platformOAuthClientId,subscriberUrl]` on the table `Webhook` will be added. If there are existing duplicate values, this will fail.
*/
-- AlterTable
ALTER TABLE "Webhook" ADD COLUMN "platformOAuthClientId" TEXT;
-- CreateIndex
CREATE UNIQUE INDEX "Webhook_platformOAuthClientId_subscriberUrl_key" ON "Webhook"("platformOAuthClientId", "subscriberUrl");
-- AddForeignKey
ALTER TABLE "Webhook" ADD CONSTRAINT "Webhook_platformOAuthClientId_fkey" FOREIGN KEY ("platformOAuthClientId") REFERENCES "PlatformOAuthClient"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+21 -17
View File
@@ -727,26 +727,29 @@ enum WebhookTriggerEvents {
}
model Webhook {
id String @id @unique
userId Int?
teamId Int?
eventTypeId Int?
id String @id @unique
userId Int?
teamId Int?
eventTypeId Int?
platformOAuthClientId String?
/// @zod.url()
subscriberUrl String
payloadTemplate String?
createdAt DateTime @default(now())
active Boolean @default(true)
eventTriggers WebhookTriggerEvents[]
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
team Team? @relation(fields: [teamId], references: [id], onDelete: Cascade)
eventType EventType? @relation(fields: [eventTypeId], references: [id], onDelete: Cascade)
app App? @relation(fields: [appId], references: [slug], onDelete: Cascade)
appId String?
secret String?
platform Boolean @default(false)
scheduledTriggers WebhookScheduledTriggers[]
subscriberUrl String
payloadTemplate String?
createdAt DateTime @default(now())
active Boolean @default(true)
eventTriggers WebhookTriggerEvents[]
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
team Team? @relation(fields: [teamId], references: [id], onDelete: Cascade)
eventType EventType? @relation(fields: [eventTypeId], references: [id], onDelete: Cascade)
platformOAuthClient PlatformOAuthClient? @relation(fields: [platformOAuthClientId], references: [id], onDelete: Cascade)
app App? @relation(fields: [appId], references: [slug], onDelete: Cascade)
appId String?
secret String?
platform Boolean @default(false)
scheduledTriggers WebhookScheduledTriggers[]
@@unique([userId, subscriberUrl], name: "courseIdentifier")
@@unique([platformOAuthClientId, subscriberUrl], name: "oauthclientwebhook")
}
model Impersonations {
@@ -1297,6 +1300,7 @@ model PlatformOAuthClient {
accessTokens AccessToken[]
refreshToken RefreshToken[]
authorizationTokens PlatformAuthorizationToken[]
webhook Webhook[]
bookingRedirectUri String?
bookingCancelRedirectUri String?
+4 -1
View File
@@ -1,13 +1,14 @@
import * as z from "zod"
import * as imports from "../zod-utils"
import { WebhookTriggerEvents } from "@prisma/client"
import { CompleteUser, UserModel, CompleteTeam, TeamModel, CompleteEventType, EventTypeModel, CompleteApp, AppModel, CompleteWebhookScheduledTriggers, WebhookScheduledTriggersModel } from "./index"
import { CompleteUser, UserModel, CompleteTeam, TeamModel, CompleteEventType, EventTypeModel, CompletePlatformOAuthClient, PlatformOAuthClientModel, CompleteApp, AppModel, CompleteWebhookScheduledTriggers, WebhookScheduledTriggersModel } from "./index"
export const _WebhookModel = z.object({
id: z.string(),
userId: z.number().int().nullish(),
teamId: z.number().int().nullish(),
eventTypeId: z.number().int().nullish(),
platformOAuthClientId: z.string().nullish(),
subscriberUrl: z.string().url(),
payloadTemplate: z.string().nullish(),
createdAt: z.date(),
@@ -22,6 +23,7 @@ export interface CompleteWebhook extends z.infer<typeof _WebhookModel> {
user?: CompleteUser | null
team?: CompleteTeam | null
eventType?: CompleteEventType | null
platformOAuthClient?: CompletePlatformOAuthClient | null
app?: CompleteApp | null
scheduledTriggers: CompleteWebhookScheduledTriggers[]
}
@@ -35,6 +37,7 @@ export const WebhookModel: z.ZodSchema<CompleteWebhook> = z.lazy(() => _WebhookM
user: UserModel.nullish(),
team: TeamModel.nullish(),
eventType: EventTypeModel.nullish(),
platformOAuthClient: PlatformOAuthClientModel.nullish(),
app: AppModel.nullish(),
scheduledTriggers: WebhookScheduledTriggersModel.array(),
}))