cal.pub0.org/lib/validations/webhook.ts

54 lines
1.5 KiB
TypeScript
Raw Normal View History

import { z } from "zod";
2022-05-26 06:42:13 +00:00
import { WebhookTriggerEvents } from "@calcom/prisma/client";
2022-05-26 06:46:51 +00:00
import { _WebhookModel as Webhook } from "@calcom/prisma/zod";
2022-05-26 06:42:13 +00:00
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({
2022-05-26 06:42:13 +00:00
id: true,
userId: true,
eventTypeId: true,
eventTriggers: true,
active: true,
subscriberUrl: true,
payloadTemplate: true,
}).partial();
2022-05-25 08:53:43 +00:00
export const schemaWebhookCreateParams = z
.object({
2022-05-26 06:42:13 +00:00
id: z.string(),
2022-05-26 05:50:49 +00:00
subscriberUrl: z.string().url(),
2022-05-26 06:42:13 +00:00
eventTriggers: z.enum(WEBHOOK_TRIGGER_EVENTS).array(),
2022-05-26 05:50:49 +00:00
active: z.boolean(),
2022-05-26 06:42:13 +00:00
payloadTemplate: z.string().optional().nullable(),
eventTypeId: z.number().optional(),
appId: z.string().optional().nullable(),
})
2022-05-25 08:53:43 +00:00
.strict();
2022-05-26 06:46:51 +00:00
export const schemaWebhookCreateBodyParams = schemaWebhookBaseBodyParams.merge(schemaWebhookCreateParams);
2022-05-20 19:48:24 +00:00
export const schemaWebhookEditBodyParams = schemaWebhookBaseBodyParams.merge(
z.object({
2022-05-19 11:08:44 +00:00
payloadTemplate: z.string().optional(),
2022-05-26 06:42:13 +00:00
eventTriggers: z.enum(WEBHOOK_TRIGGER_EVENTS).array().optional(),
2022-05-19 11:10:27 +00:00
subscriberUrl: z.string().optional(),
})
2022-05-20 19:48:24 +00:00
);
export const schemaWebhookReadPublic = Webhook.pick({
id: true,
userId: true,
eventTypeId: true,
2022-05-19 11:05:25 +00:00
payloadTemplate: true,
eventTriggers: true,
// eventType: true,
// app: true,
2022-05-19 11:05:25 +00:00
appId: true,
});