2026-03-05 23:40:49 +05:30
|
|
|
import { error } from "node:console";
|
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"),
|
|
|
|
|
address: z.string().url("Please enter a valid Webhook URL"),
|
|
|
|
|
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"),
|
|
|
|
|
address: z.string().url("Please enter a valid Webhook URL"),
|
|
|
|
|
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"),
|
|
|
|
|
address: z.string().url("Please enter a valid Webhook URL"),
|
|
|
|
|
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(),
|
|
|
|
|
homeserverUrl: z.string().url("Please enter a valid Homeserver URL"),
|
|
|
|
|
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-02 19:42:47 +00:00
|
|
|
]);
|
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
|
|
|
|
|
|
|
|
export const bulkEditNotificationBodyValidation = z.object({
|
|
|
|
|
monitorIds: z.array(z.string()).min(1, "At least one monitor ID is required"),
|
|
|
|
|
notificationIds: z.array(z.string()),
|
|
|
|
|
action: z.enum(["add", "remove", "set"], {
|
2026-03-06 13:22:32 +05:30
|
|
|
message: "Action must be 'add', 'remove', or 'set'",
|
2026-03-05 23:40:49 +05:30
|
|
|
}),
|
2026-03-06 13:22:32 +05:30
|
|
|
});
|