/** * @factory/shared — webhook DTOs (PRODUCT-SPEC §22). */ import { z } from "zod"; // Import the §22 catalog from the dependency-free `webhook-events.ts` (NOT // from `../events.js`): this file is part of the browser-safe // `@factory/shared/dto` barrel, and `events.ts` pulls in `node:crypto`, // which would break the web bundle (UnhandledSchemeError). import { WEBHOOK_EVENTS, type WebhookEventName } from "../webhook-events.js"; /** Events a webhook may subscribe to (the §22 catalog). */ export const webhookEventSchema = z.enum(WEBHOOK_EVENTS); export type { WebhookEventName }; export const createWebhookSchema = z .object({ url: z .string() .min(1) .url() .refine((u) => u.startsWith("https://"), { message: "webhook url must be https" }), events: z .array(webhookEventSchema) .min(1, "At least one event is required") .max(WEBHOOK_EVENTS.length), active: z.boolean().default(true), }) .strict(); export type CreateWebhook = z.infer; export const updateWebhookSchema = z .object({ url: z .string() .url() .refine((u) => u.startsWith("https://"), { message: "webhook url must be https" }) .optional(), events: z.array(webhookEventSchema).min(1).max(WEBHOOK_EVENTS.length).optional(), active: z.boolean().optional(), }) .strict() .refine((v) => Object.keys(v).length > 0, { message: "No fields to update" }); export type UpdateWebhook = z.infer;