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:
1 parent
4def31e98f
commit
dda4b17a7c
47 files changed
+1199
-68
No files matched your search
@@ -932,6 +932,7 @@ async function handler(
|
||||
triggerEvent: WebhookTriggerEvents.BOOKING_CREATED,
|
||||
teamId,
|
||||
orgId,
|
||||
oAuthClientId: platformClientId,
|
||||
};
|
||||
|
||||
const eventTrigger: WebhookTriggerEvents = rescheduleUid
|
||||
@@ -1601,6 +1602,7 @@ async function handler(
|
||||
triggerEvent: WebhookTriggerEvents.BOOKING_PAYMENT_INITIATED,
|
||||
teamId,
|
||||
orgId,
|
||||
oAuthClientId: platformClientId,
|
||||
};
|
||||
await handleWebhookTrigger({
|
||||
subscriberOptions: subscriberOptionsPaymentInitiated,
|
||||
|
||||
@@ -54,15 +54,18 @@ const WEBHOOK_TRIGGER_EVENTS_GROUPED_BY_APP_V2: Record<string, WebhookTriggerEve
|
||||
const WebhookForm = (props: {
|
||||
webhook?: WebhookFormData;
|
||||
apps?: (keyof typeof WEBHOOK_TRIGGER_EVENTS_GROUPED_BY_APP_V2)[];
|
||||
overrideTriggerOptions?: (typeof WEBHOOK_TRIGGER_EVENTS_GROUPED_BY_APP_V2)["core"];
|
||||
onSubmit: (event: WebhookFormSubmitData) => void;
|
||||
onCancel?: () => void;
|
||||
noRoutingFormTriggers: boolean;
|
||||
selectOnlyInstantMeetingOption?: boolean;
|
||||
}) => {
|
||||
const { apps = [], selectOnlyInstantMeetingOption = false } = props;
|
||||
const { apps = [], selectOnlyInstantMeetingOption = false, overrideTriggerOptions } = props;
|
||||
const { t } = useLocale();
|
||||
|
||||
const triggerOptions = [...WEBHOOK_TRIGGER_EVENTS_GROUPED_BY_APP_V2["core"]];
|
||||
const triggerOptions = overrideTriggerOptions
|
||||
? [...overrideTriggerOptions]
|
||||
: [...WEBHOOK_TRIGGER_EVENTS_GROUPED_BY_APP_V2["core"]];
|
||||
if (apps) {
|
||||
for (const app of apps) {
|
||||
if (app === "routing-forms" && props.noRoutingFormTriggers) continue;
|
||||
|
||||
@@ -8,6 +8,7 @@ export type GetSubscriberOptions = {
|
||||
triggerEvent: WebhookTriggerEvents;
|
||||
teamId?: number | null;
|
||||
orgId?: number | null;
|
||||
oAuthClientId?: string | null;
|
||||
};
|
||||
|
||||
const getWebhooks = async (options: GetSubscriberOptions, prisma: PrismaClient = defaultPrisma) => {
|
||||
@@ -15,6 +16,7 @@ const getWebhooks = async (options: GetSubscriberOptions, prisma: PrismaClient =
|
||||
const eventTypeId = options.eventTypeId ?? 0;
|
||||
const teamId = options.teamId ?? 0;
|
||||
const orgId = options.orgId ?? 0;
|
||||
const oAuthClientId = options.oAuthClientId ?? "";
|
||||
|
||||
// if we have userId and teamId it is a managed event type and should trigger for team and user
|
||||
const allWebhooks = await prisma.webhook.findMany({
|
||||
@@ -34,6 +36,7 @@ const getWebhooks = async (options: GetSubscriberOptions, prisma: PrismaClient =
|
||||
in: [teamId, orgId],
|
||||
},
|
||||
},
|
||||
{ platformOAuthClientId: oAuthClientId },
|
||||
],
|
||||
AND: {
|
||||
eventTriggers: {
|
||||
|
||||
@@ -142,6 +142,7 @@ export const buildWebhook = (webhook?: Partial<Webhook>): Webhook => {
|
||||
active: true,
|
||||
eventTriggers: [],
|
||||
teamId: null,
|
||||
platformOAuthClientId: null,
|
||||
...webhook,
|
||||
platform: false,
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
@@ -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?
|
||||
|
||||
@@ -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(),
|
||||
}))
|
||||
Reference in new issue
Block a user