Merge pull request #98 from calcom/fix/debug-webhook

Updated webhook validations
pull/9078/head
Syed Ali Shahbaz 2022-05-26 12:40:08 +05:30 committed by GitHub
commit ed2f42fb01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 11 deletions

View File

@ -2,6 +2,18 @@ import { z } from "zod";
import { _WebhookModel as Webhook } from "@calcom/prisma/zod"; import { _WebhookModel as Webhook } from "@calcom/prisma/zod";
export const WebhookTriggerEvents = {
BOOKING_CREATED: "BOOKING_CREATED",
BOOKING_RESCHEDULED: "BOOKING_RESCHEDULED",
BOOKING_CANCELLED: "BOOKING_CANCELLED",
};
export const WEBHOOK_TRIGGER_EVENTS = [
WebhookTriggerEvents.BOOKING_CANCELLED,
WebhookTriggerEvents.BOOKING_CREATED,
WebhookTriggerEvents.BOOKING_RESCHEDULED,
] as ["BOOKING_CANCELLED", "BOOKING_CREATED", "BOOKING_RESCHEDULED"];
const schemaWebhookBaseBodyParams = Webhook.pick({ const schemaWebhookBaseBodyParams = Webhook.pick({
id: true, id: true,
userId: true, userId: true,
@ -14,24 +26,22 @@ const schemaWebhookBaseBodyParams = Webhook.pick({
export const schemaWebhookCreateParams = z export const schemaWebhookCreateParams = z
.object({ .object({
userId: z.number().or(z.string()).optional(), id: z.string(),
eventTypeId: z.number().or(z.string()).optional(), subscriberUrl: z.string().url(),
eventTriggers: z.any().optional(), eventTriggers: z.enum(WEBHOOK_TRIGGER_EVENTS).array(),
active: z.boolean().optional(), active: z.boolean(),
subscriberUrl: z.string(), payloadTemplate: z.string().optional().nullable(),
payloadTemplate: z.string().optional(), eventTypeId: z.number().optional(),
appId: z.string().optional().nullable(),
}) })
.strict(); .strict();
export const schemaWebhookCreateBodyParams = schemaWebhookBaseBodyParams.merge( export const schemaWebhookCreateBodyParams = schemaWebhookBaseBodyParams.merge(schemaWebhookCreateParams);
schemaWebhookCreateParams
);
export const schemaWebhookEditBodyParams = schemaWebhookBaseBodyParams.merge( export const schemaWebhookEditBodyParams = schemaWebhookBaseBodyParams.merge(
z.object({ z.object({
payloadTemplate: z.string().optional(), payloadTemplate: z.string().optional(),
/** @todo: don't use any here and validate eventTriggers proper */ eventTriggers: z.enum(WEBHOOK_TRIGGER_EVENTS).array().optional(),
eventTriggers: z.any(),
subscriberUrl: z.string().optional(), subscriberUrl: z.string().optional(),
}) })
); );