1
4
5import { z } from "zod";
6
7
8
9
10
11import { WEBHOOK_EVENTS, type WebhookEventName } from "../webhook-events.js";
12
13
14export const webhookEventSchema = z.enum(WEBHOOK_EVENTS);
15export type { WebhookEventName };
16
17export const createWebhookSchema = z
18 .object({
19 url: z
20 .string()
21 .min(1)
22 .url()
23 .refine((u) => u.startsWith("https://"), { message: "webhook url must be https" }),
24 events: z
25 .array(webhookEventSchema)
26 .min(1, "At least one event is required")
27 .max(WEBHOOK_EVENTS.length),
28 active: z.boolean().default(true),
29 })
30 .strict();
31export type CreateWebhook = z.infer<typeof createWebhookSchema>;
32
33export const updateWebhookSchema = z
34 .object({
35 url: z
36 .string()
37 .url()
38 .refine((u) => u.startsWith("https://"), { message: "webhook url must be https" })
39 .optional(),
40 events: z.array(webhookEventSchema).min(1).max(WEBHOOK_EVENTS.length).optional(),
41 active: z.boolean().optional(),
42 })
43 .strict()
44 .refine((v) => Object.keys(v).length > 0, { message: "No fields to update" });
45export type UpdateWebhook = z.infer<typeof updateWebhookSchema>;
46