2026-03-02 17:29:48 +00:00
|
|
|
import { z } from "zod";
|
2026-03-01 17:35:00 +00:00
|
|
|
|
|
|
|
|
//****************************************
|
|
|
|
|
// Notification Validations
|
|
|
|
|
//****************************************
|
|
|
|
|
|
2026-03-02 19:42:47 +00:00
|
|
|
export const createNotificationBodyValidation = z.discriminatedUnion("type", [
|
|
|
|
|
// Email notification
|
|
|
|
|
z.object({
|
|
|
|
|
notificationName: z.string().min(1, "Notification name is required"),
|
|
|
|
|
type: z.literal("email"),
|
|
|
|
|
address: z.email("Please enter a valid e-mail address"),
|
|
|
|
|
homeserverUrl: z.union([z.string(), z.literal("")]).optional(),
|
|
|
|
|
roomId: z.union([z.string(), z.literal("")]).optional(),
|
|
|
|
|
accessToken: z.union([z.string(), z.literal("")]).optional(),
|
2026-03-01 17:35:00 +00:00
|
|
|
}),
|
2026-03-02 19:42:47 +00:00
|
|
|
// Webhook notification
|
|
|
|
|
z.object({
|
|
|
|
|
notificationName: z.string().min(1, "Notification name is required"),
|
|
|
|
|
type: z.literal("webhook"),
|
2026-03-09 08:43:14 +11:00
|
|
|
address: z.url({ message: "Please enter a valid Webhook URL" }),
|
2026-03-02 19:42:47 +00:00
|
|
|
homeserverUrl: z.union([z.string(), z.literal("")]).optional(),
|
|
|
|
|
roomId: z.union([z.string(), z.literal("")]).optional(),
|
|
|
|
|
accessToken: z.union([z.string(), z.literal("")]).optional(),
|
2026-03-01 17:35:00 +00:00
|
|
|
}),
|
2026-03-02 19:42:47 +00:00
|
|
|
// Slack notification
|
|
|
|
|
z.object({
|
|
|
|
|
notificationName: z.string().min(1, "Notification name is required"),
|
|
|
|
|
type: z.literal("slack"),
|
2026-03-09 08:43:14 +11:00
|
|
|
address: z.url({ message: "Please enter a valid Webhook URL" }),
|
2026-03-02 19:42:47 +00:00
|
|
|
homeserverUrl: z.union([z.string(), z.literal("")]).optional(),
|
|
|
|
|
roomId: z.union([z.string(), z.literal("")]).optional(),
|
|
|
|
|
accessToken: z.union([z.string(), z.literal("")]).optional(),
|
2026-03-01 17:35:00 +00:00
|
|
|
}),
|
2026-03-02 19:42:47 +00:00
|
|
|
// Discord notification
|
|
|
|
|
z.object({
|
|
|
|
|
notificationName: z.string().min(1, "Notification name is required"),
|
|
|
|
|
type: z.literal("discord"),
|
2026-03-09 08:43:14 +11:00
|
|
|
address: z.url({ message: "Please enter a valid Webhook URL" }),
|
2026-03-02 19:42:47 +00:00
|
|
|
homeserverUrl: z.union([z.string(), z.literal("")]).optional(),
|
|
|
|
|
roomId: z.union([z.string(), z.literal("")]).optional(),
|
|
|
|
|
accessToken: z.union([z.string(), z.literal("")]).optional(),
|
2026-03-01 17:35:00 +00:00
|
|
|
}),
|
2026-03-02 19:42:47 +00:00
|
|
|
// PagerDuty notification
|
|
|
|
|
z.object({
|
|
|
|
|
notificationName: z.string().min(1, "Notification name is required"),
|
|
|
|
|
type: z.literal("pager_duty"),
|
|
|
|
|
address: z.string().min(1, "PagerDuty integration key is required"),
|
|
|
|
|
homeserverUrl: z.union([z.string(), z.literal("")]).optional(),
|
|
|
|
|
roomId: z.union([z.string(), z.literal("")]).optional(),
|
|
|
|
|
accessToken: z.union([z.string(), z.literal("")]).optional(),
|
2026-03-01 17:35:00 +00:00
|
|
|
}),
|
2026-03-02 19:42:47 +00:00
|
|
|
// Matrix notification
|
|
|
|
|
z.object({
|
|
|
|
|
notificationName: z.string().min(1, "Notification name is required"),
|
|
|
|
|
type: z.literal("matrix"),
|
|
|
|
|
address: z.union([z.string(), z.literal("")]).optional(),
|
2026-03-09 08:43:14 +11:00
|
|
|
homeserverUrl: z.url({ message: "Please enter a valid Homeserver URL" }),
|
2026-03-02 19:42:47 +00:00
|
|
|
roomId: z.string().min(1, "Room ID is required"),
|
|
|
|
|
accessToken: z.string().min(1, "Access Token is required"),
|
2026-03-01 17:35:00 +00:00
|
|
|
}),
|
2026-03-05 19:16:08 +11:00
|
|
|
// Teams notification
|
|
|
|
|
z.object({
|
|
|
|
|
notificationName: z.string().min(1, "Notification name is required"),
|
|
|
|
|
type: z.literal("teams"),
|
2026-03-09 08:43:14 +11:00
|
|
|
address: z.url({ message: "Please enter a valid Webhook URL" }),
|
2026-03-05 19:16:08 +11:00
|
|
|
}),
|
2026-03-24 10:15:46 -04:00
|
|
|
// Telegram notification
|
|
|
|
|
z.object({
|
|
|
|
|
notificationName: z.string().min(1, "Notification name is required"),
|
|
|
|
|
type: z.literal("telegram"),
|
|
|
|
|
address: z.string().min(1, "Chat ID is required"),
|
|
|
|
|
accessToken: z.string().min(1, "Bot token is required"),
|
|
|
|
|
}),
|
2026-03-02 19:42:47 +00:00
|
|
|
]);
|
2026-03-02 17:29:48 +00:00
|
|
|
|
2026-03-11 13:28:48 -07:00
|
|
|
export const testNotificationBodyValidation = createNotificationBodyValidation;
|
|
|
|
|
|
|
|
|
|
export const deleteNotificationParamValidation = z.object({
|
|
|
|
|
id: z.string().min(1, "Notification ID is required"),
|
|
|
|
|
});
|
|
|
|
|
export const getNotificationByIdParamValidation = z.object({
|
|
|
|
|
id: z.string().min(1, "Notification ID is required"),
|
|
|
|
|
});
|
|
|
|
|
export const editNotificationParamValidation = z.object({
|
|
|
|
|
id: z.string().min(1, "Notification ID is required"),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const testAllNotificationsBodyValidation = z.object({
|
|
|
|
|
monitorId: z.string().min(1, "Monitor ID is required"),
|
|
|
|
|
});
|
|
|
|
|
|
2026-03-02 17:29:48 +00:00
|
|
|
export const sendTestEmailBodyValidation = z.object({
|
|
|
|
|
to: z.string().min(1, "To field is required"),
|
|
|
|
|
systemEmailHost: z.string().optional(),
|
|
|
|
|
systemEmailPort: z.number().optional(),
|
|
|
|
|
systemEmailSecure: z.boolean().optional(),
|
|
|
|
|
systemEmailPool: z.boolean().optional(),
|
|
|
|
|
systemEmailAddress: z.string().optional(),
|
|
|
|
|
systemEmailPassword: z.string().optional(),
|
|
|
|
|
systemEmailUser: z.string().optional(),
|
|
|
|
|
systemEmailConnectionHost: z.union([z.string(), z.literal("")]).optional(),
|
|
|
|
|
systemEmailIgnoreTLS: z.boolean().optional(),
|
|
|
|
|
systemEmailRequireTLS: z.boolean().optional(),
|
|
|
|
|
systemEmailRejectUnauthorized: z.boolean().optional(),
|
|
|
|
|
systemEmailTLSServername: z.union([z.string(), z.literal("")]).optional(),
|
|
|
|
|
});
|
2026-03-05 23:40:49 +05:30
|
|
|
|
2026-03-21 00:52:36 +05:30
|
|
|
export const updateNotificationsValidation = z
|
|
|
|
|
.object({
|
2026-03-23 10:13:43 -07:00
|
|
|
monitorIds: z.array(z.string()).min(1, "At least one monitor ID is required").max(100, "Cannot update more than 100 monitors at once"),
|
|
|
|
|
notificationIds: z.array(z.string()).max(100, "Cannot specify more than 100 notification IDs at once"),
|
2026-03-21 00:52:36 +05:30
|
|
|
action: z.enum(["add", "remove", "set"] as const),
|
|
|
|
|
})
|
|
|
|
|
.refine(
|
|
|
|
|
(data) => {
|
|
|
|
|
if (data.action !== "set" && data.notificationIds.length === 0) return false;
|
|
|
|
|
return true;
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
message: "Notification IDs cannot be empty unless action is 'set'",
|
|
|
|
|
path: ["notificationIds"],
|
|
|
|
|
}
|
|
|
|
|
);
|