2022-05-11 13:57:00 +00:00
|
|
|
import { z } from "zod";
|
|
|
|
|
2022-10-19 18:26:12 +00:00
|
|
|
import { WEBHOOK_TRIGGER_EVENTS } from "@calcom/features/webhooks/lib/constants";
|
2022-05-26 06:46:51 +00:00
|
|
|
import { _WebhookModel as Webhook } from "@calcom/prisma/zod";
|
|
|
|
|
2022-05-11 13:57:00 +00:00
|
|
|
const schemaWebhookBaseBodyParams = Webhook.pick({
|
|
|
|
userId: true,
|
|
|
|
eventTypeId: true,
|
|
|
|
eventTriggers: true,
|
|
|
|
active: true,
|
|
|
|
subscriberUrl: true,
|
|
|
|
payloadTemplate: true,
|
2022-10-19 18:26:12 +00:00
|
|
|
});
|
2022-05-11 13:57:00 +00:00
|
|
|
|
2022-05-25 08:53:43 +00:00
|
|
|
export const schemaWebhookCreateParams = z
|
|
|
|
.object({
|
2022-10-19 18:26:12 +00:00
|
|
|
// subscriberUrl: z.string().url(),
|
|
|
|
// eventTriggers: z.enum(WEBHOOK_TRIGGER_EVENTS).array(),
|
|
|
|
// active: z.boolean(),
|
2022-05-26 06:42:13 +00:00
|
|
|
payloadTemplate: z.string().optional().nullable(),
|
|
|
|
eventTypeId: z.number().optional(),
|
2022-10-19 18:26:12 +00:00
|
|
|
userId: z.number().optional(),
|
|
|
|
// API shouldn't mess with Apps webhooks yet (ie. Zapier)
|
|
|
|
// appId: z.string().optional().nullable(),
|
2022-05-11 13:57:00 +00:00
|
|
|
})
|
2022-05-25 08:53:43 +00:00
|
|
|
.strict();
|
2022-05-11 13:57:00 +00:00
|
|
|
|
2022-05-26 06:46:51 +00:00
|
|
|
export const schemaWebhookCreateBodyParams = schemaWebhookBaseBodyParams.merge(schemaWebhookCreateParams);
|
2022-05-11 13:57:00 +00:00
|
|
|
|
2022-10-19 18:26:12 +00:00
|
|
|
export const schemaWebhookEditBodyParams = schemaWebhookBaseBodyParams
|
|
|
|
.merge(
|
|
|
|
z.object({
|
|
|
|
eventTriggers: z.enum(WEBHOOK_TRIGGER_EVENTS).array().optional(),
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.partial()
|
|
|
|
.strict();
|
2022-03-30 15:37:51 +00:00
|
|
|
|
2022-05-11 13:57:00 +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,
|
2022-10-19 18:26:12 +00:00
|
|
|
// FIXME: We have some invalid urls saved in the DB
|
|
|
|
// subscriberUrl: true,
|
2022-06-01 15:08:01 +00:00
|
|
|
/** @todo: find out how to properly add back and validate those. */
|
2022-05-19 23:45:54 +00:00
|
|
|
// eventType: true,
|
|
|
|
// app: true,
|
2022-05-19 11:05:25 +00:00
|
|
|
appId: true,
|
2022-10-19 18:26:12 +00:00
|
|
|
}).merge(
|
|
|
|
z.object({
|
|
|
|
subscriberUrl: z.string(),
|
|
|
|
})
|
|
|
|
);
|