import { z } from 'zod' /** * Validation schemas for API routes * Implements input validation to prevent injection attacks and invalid data */ export const siteIdSchema = z.object({ siteId: z.string() .transform((val) => parseInt(val, 10)) .pipe( z.number() .int('Site ID must be an integer') .positive('Site ID must be positive') ) }) export const periodSchema = z.object({ period: z.string() .regex(/^\d+d$/, 'Period must be in format: 30d, 90d, etc') .transform((val) => parseInt(val.replace('d', ''), 10)) .pipe( z.number() .int('Days must be an integer') .min(1, 'Period must be at least 1 day') .max(365, 'Period cannot exceed 365 days') ) .optional() .default(30) }) export type SiteIdInput = z.input export type SiteIdOutput = z.output export type PeriodInput = z.input export type PeriodOutput = z.output