28 lines
1.0 KiB
TypeScript
28 lines
1.0 KiB
TypeScript
import { z } from 'zod';
|
|
|
|
// Regex basique IPv4 ; on peut étendre à IPv6 avec la lib `ip-address`
|
|
const ipv4Regex = /^(25[0-5]|2[0-4]\d|[01]?\d\d?)(\.(25[0-5]|2[0-4]\d|[01]?\d\d?)){3}$/;
|
|
|
|
export const hostStatusSchema = z.enum(['UP', 'DOWN', 'UNKNOWN']);
|
|
export const hostSourceSchema = z.enum(['MANUAL', 'DISCOVERED', 'IMPORTED']);
|
|
|
|
export const createHostSchema = z.object({
|
|
ipAddress: z.string().regex(ipv4Regex, 'IP invalide (IPv4 attendu)'),
|
|
hostname: z.string().min(1).max(255).optional(),
|
|
macAddress: z
|
|
.string()
|
|
.regex(/^([0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2}$/, 'MAC invalide')
|
|
.optional(),
|
|
description: z.string().max(2000).optional(),
|
|
networkId: z.string().cuid().optional(),
|
|
status: hostStatusSchema.optional(),
|
|
source: hostSourceSchema.optional(),
|
|
vendor: z.string().optional(),
|
|
osGuess: z.string().optional(),
|
|
});
|
|
|
|
export const updateHostSchema = createHostSchema.partial();
|
|
|
|
export type CreateHostInput = z.infer<typeof createHostSchema>;
|
|
export type UpdateHostInput = z.infer<typeof updateHostSchema>;
|