import { z } from "zod"; import type React from "react"; import { IPV4_REGEX } from "@lib/constants"; import { NextApiRequest as TNextApiRequest } from "next/dist/shared/lib/utils"; export const WgKeySchema = z.object({ privateKey: z.string(), publicKey: z.string(), }) export type WgKey = z.infer export interface WgPeerConfig { publicKey: string preSharedKey: string endpoint: string allowedIps: string[] persistentKeepalive: number | null } const WgPeerSchema = z.object({ id: z.string().uuid(), name: z.string().regex(/^[A-Za-z\d\s]{3,32}$/), preSharedKey: z.string(), endpoint: z.string(), address: z.string().regex(IPV4_REGEX), latestHandshakeAt: z.string().nullable(), transferRx: z.number().nullable(), transferTx: z.number().nullable(), persistentKeepalive: z.number().nullable(), createdAt: z.string().datetime(), updatedAt: z.string().datetime(), enabled: z.boolean(), }) .merge(WgKeySchema) export type WgPeer = z.infer export const WgServerSchema = z.object({ id: z.string().uuid(), confId: z.number(), type: z.enum([ 'default', 'bridge', 'tor' ]), name: z.string().regex(/^[A-Za-z\d\s]{3,32}$/), address: z.string().regex(IPV4_REGEX), listen: z.number(), preUp: z.string().nullable(), postUp: z.string().nullable(), preDown: z.string().nullable(), postDown: z.string().nullable(), dns: z.string().regex(IPV4_REGEX).nullable(), peers: z.array(WgPeerSchema), createdAt: z.string().datetime(), updatedAt: z.string().datetime(), status: z.enum([ 'up', 'down' ]), }) .merge(WgKeySchema) export type WgServer = z.infer export type ReactHTMLProps = React.DetailedHTMLProps, T> export type APIErrorResponse = { ok: false details: string } export type APISuccessResponse = { ok: true result: D } export type APIResponse = N extends true ? D : APIErrorResponse | APISuccessResponse export type NextApiRequest< P = Record, Q = Record > = Omit & { query: Partial & P } export type LeastOne }> = Partial & U[keyof U];