2026-03-02 17:46:33 +00:00
|
|
|
import { z } from "zod";
|
2026-03-02 19:25:34 +00:00
|
|
|
import { booleanCoercion } from "./shared.js";
|
2026-03-01 17:35:00 +00:00
|
|
|
import { GeoContinents } from "@/types/geoCheck.js";
|
2026-03-11 12:41:27 -07:00
|
|
|
import { MonitorMatchMethods, MonitorTypes } from "@/types/monitor.js";
|
2026-03-01 17:35:00 +00:00
|
|
|
|
2026-03-02 17:46:33 +00:00
|
|
|
export const getMonitorByIdParamValidation = z.object({
|
|
|
|
|
monitorId: z.string().min(1, "Monitor ID is required"),
|
2026-03-01 17:35:00 +00:00
|
|
|
});
|
|
|
|
|
|
2026-03-02 17:46:33 +00:00
|
|
|
export const getMonitorByIdQueryValidation = z.object({
|
2026-03-02 19:25:34 +00:00
|
|
|
status: booleanCoercion.optional(),
|
2026-03-02 17:46:33 +00:00
|
|
|
sortOrder: z.enum(["asc", "desc"]).optional(),
|
|
|
|
|
limit: z.coerce.number().optional(),
|
|
|
|
|
dateRange: z.enum(["recent", "hour", "day", "week", "month", "all"]).optional(),
|
|
|
|
|
numToDisplay: z.coerce.number().optional(),
|
2026-03-02 19:25:34 +00:00
|
|
|
normalize: booleanCoercion.optional(),
|
2026-03-02 17:46:33 +00:00
|
|
|
continent: z.enum(GeoContinents).optional(),
|
2026-03-01 17:35:00 +00:00
|
|
|
});
|
|
|
|
|
|
2026-03-02 17:46:33 +00:00
|
|
|
export const getMonitorsByTeamIdParamValidation = z.object({});
|
2026-03-01 17:35:00 +00:00
|
|
|
|
2026-03-02 17:46:33 +00:00
|
|
|
export const getMonitorsByTeamIdQueryValidation = z.object({
|
|
|
|
|
type: z
|
|
|
|
|
.union([
|
2026-03-07 00:59:39 +05:30
|
|
|
z.enum(["http", "ping", "pagespeed", "docker", "hardware", "port", "game", "grpc", "websocket"]),
|
|
|
|
|
z.array(z.enum(["http", "ping", "pagespeed", "docker", "hardware", "port", "game", "grpc", "websocket"])),
|
2026-03-02 17:46:33 +00:00
|
|
|
])
|
|
|
|
|
.optional(),
|
2026-03-11 12:41:27 -07:00
|
|
|
filter: z.union([z.string(), z.literal("")]).optional(),
|
2026-03-01 17:35:00 +00:00
|
|
|
});
|
|
|
|
|
|
2026-03-02 17:46:33 +00:00
|
|
|
export const getMonitorsWithChecksQueryValidation = z.object({
|
|
|
|
|
limit: z.coerce.number().int().min(1).max(100).optional(),
|
|
|
|
|
page: z.coerce.number().int().min(0).optional(),
|
|
|
|
|
rowsPerPage: z.coerce.number().int().min(1).max(100).optional(),
|
2026-03-11 12:41:27 -07:00
|
|
|
filter: z.union([z.string(), z.literal("")]).optional(),
|
2026-03-02 17:46:33 +00:00
|
|
|
field: z.string().optional(),
|
|
|
|
|
order: z.enum(["asc", "desc"]).optional(),
|
|
|
|
|
type: z
|
|
|
|
|
.union([
|
2026-03-07 00:59:39 +05:30
|
|
|
z.enum(["http", "ping", "pagespeed", "docker", "hardware", "port", "game", "grpc", "websocket"]),
|
|
|
|
|
z.array(z.enum(["http", "ping", "pagespeed", "docker", "hardware", "port", "game", "grpc", "websocket"])),
|
2026-03-02 17:46:33 +00:00
|
|
|
])
|
2026-03-01 17:35:00 +00:00
|
|
|
.optional(),
|
2026-03-02 19:25:34 +00:00
|
|
|
explain: booleanCoercion.optional(),
|
2026-03-01 17:35:00 +00:00
|
|
|
});
|
|
|
|
|
|
2026-03-02 17:46:33 +00:00
|
|
|
export const getCertificateParamValidation = z.object({
|
|
|
|
|
monitorId: z.string().min(1, "Monitor ID is required"),
|
2026-03-01 17:35:00 +00:00
|
|
|
});
|
|
|
|
|
|
2026-03-02 17:46:33 +00:00
|
|
|
export const createMonitorBodyValidation = z.object({
|
|
|
|
|
_id: z.string().optional(),
|
|
|
|
|
name: z.string().min(1, "Name is required"),
|
2026-03-11 12:41:27 -07:00
|
|
|
description: z.union([z.string(), z.literal("")]).optional(),
|
|
|
|
|
type: z.enum(MonitorTypes, "Invalid monitor type"),
|
2026-03-02 17:46:33 +00:00
|
|
|
statusWindowSize: z.number().min(1).max(20).default(5),
|
|
|
|
|
statusWindowThreshold: z.number().min(1).max(100).default(60),
|
|
|
|
|
url: z.string().min(1, "URL is required"),
|
|
|
|
|
ignoreTlsErrors: z.boolean().default(false),
|
|
|
|
|
useAdvancedMatching: z.boolean().default(false),
|
|
|
|
|
port: z.number().optional(),
|
|
|
|
|
isActive: z.boolean().optional(),
|
|
|
|
|
interval: z.number().optional(),
|
|
|
|
|
cpuAlertThreshold: z.number().optional(),
|
|
|
|
|
memoryAlertThreshold: z.number().optional(),
|
|
|
|
|
diskAlertThreshold: z.number().optional(),
|
|
|
|
|
tempAlertThreshold: z.number().optional(),
|
|
|
|
|
notifications: z.array(z.string()).optional(),
|
|
|
|
|
secret: z.string().optional(),
|
|
|
|
|
jsonPath: z.union([z.string(), z.literal("")]).optional(),
|
|
|
|
|
expectedValue: z.union([z.string(), z.literal("")]).optional(),
|
2026-03-11 12:41:27 -07:00
|
|
|
matchMethod: z.union([z.enum(MonitorMatchMethods), z.literal("")]).optional(),
|
2026-03-02 17:46:33 +00:00
|
|
|
gameId: z.union([z.string(), z.literal("")]).optional(),
|
|
|
|
|
grpcServiceName: z.union([z.string(), z.literal("")]).default(""),
|
|
|
|
|
selectedDisks: z.array(z.string()).optional(),
|
|
|
|
|
group: z.union([z.string().max(50).trim(), z.null(), z.literal("")]).optional(),
|
|
|
|
|
geoCheckEnabled: z.boolean().optional(),
|
|
|
|
|
geoCheckLocations: z.array(z.enum(GeoContinents)).optional(),
|
|
|
|
|
geoCheckInterval: z.number().min(300000).optional(),
|
2026-03-01 17:35:00 +00:00
|
|
|
});
|
|
|
|
|
|
2026-03-02 21:35:08 +00:00
|
|
|
export const editMonitorBodyValidation = z.object({
|
|
|
|
|
name: z.string().optional(),
|
2026-03-11 12:41:27 -07:00
|
|
|
type: z.enum(MonitorTypes).optional(),
|
2026-03-02 21:35:08 +00:00
|
|
|
url: z.string().optional(),
|
|
|
|
|
statusWindowSize: z.number().min(1).max(20).default(5),
|
|
|
|
|
statusWindowThreshold: z.number().min(1).max(100).default(60),
|
2026-03-11 12:41:27 -07:00
|
|
|
description: z.union([z.string(), z.literal("")]).optional(),
|
2026-03-02 21:35:08 +00:00
|
|
|
interval: z.number().optional(),
|
|
|
|
|
notifications: z.array(z.string()).optional(),
|
|
|
|
|
secret: z.string().optional(),
|
|
|
|
|
ignoreTlsErrors: z.boolean().optional(),
|
|
|
|
|
useAdvancedMatching: z.boolean().optional(),
|
|
|
|
|
jsonPath: z.union([z.string(), z.literal("")]).optional(),
|
|
|
|
|
expectedValue: z.union([z.string(), z.literal("")]).optional(),
|
2026-03-11 12:41:27 -07:00
|
|
|
matchMethod: z.union([z.enum(MonitorMatchMethods), z.literal("")]).optional(),
|
2026-03-02 21:35:08 +00:00
|
|
|
port: z.number().min(1).max(65535).optional(),
|
|
|
|
|
cpuAlertThreshold: z.number().optional(),
|
|
|
|
|
memoryAlertThreshold: z.number().optional(),
|
|
|
|
|
diskAlertThreshold: z.number().optional(),
|
|
|
|
|
tempAlertThreshold: z.number().optional(),
|
|
|
|
|
gameId: z.union([z.string(), z.literal("")]).optional(),
|
|
|
|
|
grpcServiceName: z.union([z.string(), z.literal("")]).optional(),
|
|
|
|
|
selectedDisks: z.array(z.string()).optional(),
|
|
|
|
|
group: z.union([z.string().max(50).trim(), z.null(), z.literal("")]).optional(),
|
|
|
|
|
geoCheckEnabled: z.boolean().optional(),
|
|
|
|
|
geoCheckLocations: z.array(z.enum(GeoContinents)).optional(),
|
|
|
|
|
geoCheckInterval: z.number().min(300000).optional(),
|
|
|
|
|
});
|
2026-03-01 17:35:00 +00:00
|
|
|
|
2026-03-11 12:41:27 -07:00
|
|
|
export const sendTestEmailBodyValidation = z.object({
|
|
|
|
|
to: z.string().email("Invalid 'to' email address"),
|
|
|
|
|
});
|
|
|
|
|
|
2026-03-02 17:46:33 +00:00
|
|
|
export const pauseMonitorParamValidation = z.object({
|
|
|
|
|
monitorId: z.string().min(1, "Monitor ID is required"),
|
2026-03-01 17:35:00 +00:00
|
|
|
});
|
|
|
|
|
|
2026-03-11 12:41:27 -07:00
|
|
|
export const getUptimeDetailsByIdParamValidation = z.object({
|
|
|
|
|
monitorId: z.string().min(1, "Monitor ID is required"),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const getUptimeDetailsByIdQueryValidation = z.object({
|
|
|
|
|
dateRange: z.enum(["recent", "hour", "day", "week", "month", "all"]),
|
|
|
|
|
normalize: booleanCoercion.optional(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const importedMonitorSchema = z.object({
|
|
|
|
|
id: z.string().optional(),
|
|
|
|
|
userId: z.string().optional(),
|
|
|
|
|
teamId: z.string().optional(),
|
|
|
|
|
name: z.string().min(1, "Name is required"),
|
|
|
|
|
description: z.union([z.string(), z.literal("")]).optional(),
|
|
|
|
|
status: z.enum(["up", "down", "paused", "initializing", "maintenance", "breached"]).optional(),
|
|
|
|
|
statusWindow: z.array(z.boolean()).optional(),
|
|
|
|
|
statusWindowSize: z.number().optional(),
|
|
|
|
|
statusWindowThreshold: z.number().optional(),
|
|
|
|
|
type: z.enum(MonitorTypes, "Invalid monitor type"),
|
|
|
|
|
ignoreTlsErrors: z.boolean().optional(),
|
|
|
|
|
useAdvancedMatching: z.boolean().optional(),
|
|
|
|
|
jsonPath: z.union([z.string(), z.literal("")]).optional(),
|
|
|
|
|
expectedValue: z.union([z.string(), z.literal("")]).optional(),
|
|
|
|
|
matchMethod: z.union([z.enum(MonitorMatchMethods), z.literal("")]).optional(),
|
|
|
|
|
url: z.string().min(1, "URL is required"),
|
|
|
|
|
port: z.number().optional(),
|
|
|
|
|
isActive: z.boolean().optional(),
|
|
|
|
|
interval: z.number().optional(),
|
|
|
|
|
uptimePercentage: z.number().optional(),
|
|
|
|
|
notifications: z.array(z.string()).optional(),
|
|
|
|
|
secret: z.string().optional(),
|
|
|
|
|
cpuAlertThreshold: z.number().optional(),
|
|
|
|
|
cpuAlertCounter: z.number().optional(),
|
|
|
|
|
memoryAlertThreshold: z.number().optional(),
|
|
|
|
|
memoryAlertCounter: z.number().optional(),
|
|
|
|
|
diskAlertThreshold: z.number().optional(),
|
|
|
|
|
diskAlertCounter: z.number().optional(),
|
|
|
|
|
tempAlertThreshold: z.number().optional(),
|
|
|
|
|
tempAlertCounter: z.number().optional(),
|
|
|
|
|
selectedDisks: z.array(z.string()).optional(),
|
|
|
|
|
gameId: z.union([z.string(), z.literal("")]).optional(),
|
|
|
|
|
grpcServiceName: z.union([z.string(), z.literal("")]).optional(),
|
|
|
|
|
group: z.union([z.string(), z.null()]).optional(),
|
|
|
|
|
geoCheckEnabled: z.boolean().optional(),
|
|
|
|
|
geoCheckLocations: z.array(z.enum(GeoContinents)).optional(),
|
|
|
|
|
geoCheckInterval: z.number().optional(),
|
|
|
|
|
recentChecks: z.array(z.unknown()).optional(),
|
|
|
|
|
createdAt: z.string().optional(),
|
|
|
|
|
updatedAt: z.string().optional(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const importMonitorsBodyValidation = z.object({
|
|
|
|
|
monitors: z.array(importedMonitorSchema).min(1, "At least one monitor is required"),
|
|
|
|
|
});
|
|
|
|
|
|
2026-03-02 17:46:33 +00:00
|
|
|
export const getHardwareDetailsByIdParamValidation = z.object({
|
|
|
|
|
monitorId: z.string().min(1, "Monitor ID is required"),
|
2026-03-01 17:35:00 +00:00
|
|
|
});
|
|
|
|
|
|
2026-03-02 17:46:33 +00:00
|
|
|
export const getHardwareDetailsByIdQueryValidation = z.object({
|
|
|
|
|
dateRange: z.enum(["recent", "hour", "day", "week", "month", "all"]).optional(),
|
2026-03-01 17:35:00 +00:00
|
|
|
});
|