commit
ed2f42fb01
|
@ -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(),
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue