| 1 | import { z } from "zod"; |
| 2 | |
| 3 | export const urlSchema = z.object({ |
| 4 | url: z.string().url("Please enter a valid URL"), |
| 5 | customCode: z |
| 6 | .string() |
| 7 | .max(20, "Custom code must be less than 255 characters") |
| 8 | .regex(/^[a-zA-Z0-9_-]+$/, "Custom code must be alphanumeric or hyphen") |
| 9 | .optional() |
| 10 | .or(z.literal("")) |
| 11 | .nullable() |
| 12 | .transform((val) => (val === null || val === "" ? undefined : val)), |
| 13 | }); |
| 14 | |
| 15 | export type UrlFormData = z.infer<typeof urlSchema>; |
| 16 | |
| 17 | export type ApiResponse<T> = { |
| 18 | success: boolean; |
| 19 | data?: T; |
| 20 | error?: string; |
| 21 | }; |
| 22 | |
| 23 | export type Url = { |
| 24 | id: number; |
| 25 | originalUrl: string; |
| 26 | shortCode: string; |
| 27 | createdAt: string; |
| 28 | updatedAt: string; |
| 29 | clicks: number; |
| 30 | }; |