2022-05-11 13:57:00 +00:00
|
|
|
import { z } from "zod";
|
|
|
|
|
2022-03-30 15:37:51 +00:00
|
|
|
import { _WebhookModel as Webhook } from "@calcom/prisma/zod";
|
2022-03-26 23:58:22 +00:00
|
|
|
|
2022-05-11 13:57:00 +00:00
|
|
|
const schemaWebhookBaseBodyParams = Webhook.pick({
|
|
|
|
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({
|
|
|
|
userId: z.number().or(z.string()).optional(),
|
|
|
|
eventTypeId: z.number().or(z.string()).optional(),
|
2022-05-25 09:37:19 +00:00
|
|
|
eventTriggers: z.any().optional(),
|
2022-05-25 08:53:43 +00:00
|
|
|
active: z.boolean().optional(),
|
2022-05-11 13:57:00 +00:00
|
|
|
subscriberUrl: z.string(),
|
2022-05-25 08:53:43 +00:00
|
|
|
payloadTemplate: z.string().optional(),
|
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-25 08:53:43 +00:00
|
|
|
export const schemaWebhookCreateBodyParams = schemaWebhookBaseBodyParams.merge(
|
|
|
|
schemaWebhookCreateParams
|
|
|
|
);
|
2022-05-11 13:57:00 +00:00
|
|
|
|
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-19 23:47:17 +00:00
|
|
|
/** @todo: don't use any here and validate eventTriggers proper */
|
2022-05-19 22:58:42 +00:00
|
|
|
eventTriggers: z.any(),
|
2022-05-19 11:10:27 +00:00
|
|
|
subscriberUrl: z.string().optional(),
|
2022-05-11 13:57:00 +00:00
|
|
|
})
|
2022-05-20 19:48:24 +00:00
|
|
|
);
|
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-05-19 23:45:54 +00:00
|
|
|
// eventType: true,
|
|
|
|
// app: true,
|
2022-05-19 11:05:25 +00:00
|
|
|
appId: true,
|
2022-05-11 13:57:00 +00:00
|
|
|
});
|