- Added `accountSid` and `twilioPhoneNumber` fields to Notification type, MongoDB model, and frontend type instead of reusing `address` and `homeserverUrl` - Updated provider, validation, form hook, and form UI to use new fields - Added Pushover and Twilio to notificationsService routing tests (both handleNotifications and sendTestNotification) - All 59 tests passing Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
87 lines
2.4 KiB
TypeScript
87 lines
2.4 KiB
TypeScript
import { z } from "zod";
|
|
|
|
const baseSchema = z.object({
|
|
notificationName: z
|
|
.string()
|
|
.min(1, "Notification name is required")
|
|
.max(100, "Notification name must be at most 100 characters"),
|
|
});
|
|
|
|
const emailSchema = baseSchema.extend({
|
|
type: z.literal("email"),
|
|
address: z
|
|
.string()
|
|
.min(1, "Email is required")
|
|
.email("Please enter a valid email address"),
|
|
});
|
|
|
|
const slackSchema = baseSchema.extend({
|
|
type: z.literal("slack"),
|
|
address: z.string().min(1, "Webhook URL is required").url("Please enter a valid URL"),
|
|
});
|
|
|
|
const discordSchema = baseSchema.extend({
|
|
type: z.literal("discord"),
|
|
address: z.string().min(1, "Webhook URL is required").url("Please enter a valid URL"),
|
|
});
|
|
|
|
const webhookSchema = baseSchema.extend({
|
|
type: z.literal("webhook"),
|
|
address: z.string().min(1, "Webhook URL is required").url("Please enter a valid URL"),
|
|
});
|
|
|
|
const pagerDutySchema = baseSchema.extend({
|
|
type: z.literal("pager_duty"),
|
|
address: z.string().min(1, "Integration key is required"),
|
|
});
|
|
|
|
const matrixSchema = baseSchema.extend({
|
|
type: z.literal("matrix"),
|
|
homeserverUrl: z
|
|
.string()
|
|
.min(1, "Homeserver URL is required")
|
|
.url("Please enter a valid URL"),
|
|
roomId: z.string().min(1, "Room ID is required"),
|
|
accessToken: z.string().min(1, "Access token is required"),
|
|
});
|
|
|
|
const teamsSchema = baseSchema.extend({
|
|
type: z.literal("teams"),
|
|
address: z.string().min(1, "Webhook URL is required").url("Please enter a valid URL"),
|
|
});
|
|
|
|
const telegramSchema = baseSchema.extend({
|
|
type: z.literal("telegram"),
|
|
address: z.string().min(1, "Chat ID is required"),
|
|
accessToken: z.string().min(1, "Bot token is required"),
|
|
});
|
|
|
|
const pushoverSchema = baseSchema.extend({
|
|
type: z.literal("pushover"),
|
|
address: z.string().min(1, "User key is required"),
|
|
accessToken: z.string().min(1, "App token is required"),
|
|
});
|
|
|
|
const twilioSchema = baseSchema.extend({
|
|
type: z.literal("twilio"),
|
|
accountSid: z.string().min(1, "Account SID is required"),
|
|
accessToken: z.string().min(1, "Auth token is required"),
|
|
phone: z.string().min(1, "Recipient phone number is required"),
|
|
twilioPhoneNumber: z.string().min(1, "Twilio phone number is required"),
|
|
});
|
|
|
|
export const notificationSchema = z.discriminatedUnion("type", [
|
|
emailSchema,
|
|
slackSchema,
|
|
discordSchema,
|
|
webhookSchema,
|
|
pagerDutySchema,
|
|
matrixSchema,
|
|
teamsSchema,
|
|
telegramSchema,
|
|
pushoverSchema,
|
|
twilioSchema,
|
|
]);
|
|
|
|
export type NotificationFormData = z.infer<typeof notificationSchema>;
|