contact.ts 1.1 KB

1234567891011121314151617181920212223242526
  1. import { z } from "zod";
  2. export const contactSchema = z.object({
  3. name: z.string().min(2).max(80).transform((v) => v.replace(/[\r\n]+/g, " ").trim()),
  4. email: z.string().email().max(254),
  5. topic: z.enum(["general", "honey-bees", "personal-training", "sourdough", "farm-to-table", "recreation-apps", "laser-engraving", "3d-printing"]).default("general"),
  6. message: z.string().min(10).max(5000),
  7. phone: z.string().optional().default(""),
  8. });
  9. export const contactBodySchema = contactSchema.extend({
  10. website: z.string().optional().default(""),
  11. company: z.string().optional().default(""),
  12. });
  13. export type ContactInput = z.infer<typeof contactSchema>;
  14. export type ContactBody = z.infer<typeof contactBodySchema>;
  15. export function isHoneypotTriggered(body: { website?: string; company?: string }): boolean {
  16. const filled = (v?: string) => typeof v === "string" && v.trim().length > 0;
  17. return filled(body.website) || filled(body.company);
  18. }
  19. export function sanitizeHeaderValue(value: string): string {
  20. return value.replace(/[\r\n]+/g, " ").trim().slice(0, 200);
  21. }