import { z } from "zod"; import { uuid } from "./commerce.ts"; const text = (max: number, min = 1) => z.string().trim().min(min).max(max).regex(/^[^<>\u0000-\u001f\u007f]*$/, "Use plain text"); export const businessProfile = z.object({ legalName: text(160), tradingName: text(160).nullable(), registrationNumber: text(64, 3), taxIdentifier: text(64).nullable(), countryCode: z.string().trim().toUpperCase().regex(/^[A-Z]{2}$/, "Use a two-letter country code"), contactEmail: z.string().trim().email().max(254).toLowerCase(), contactPhone: z.string().trim().regex(/^\+?[0-9 ()-]{7,24}$/, "Enter a valid phone number").nullable(), billingLine1: text(200), billingCity: text(100), billingRegion: text(100), billingPostalCode: text(20), }).strict(); export const businessInput = businessProfile.extend({ code: z.string().trim().toUpperCase().max(32).regex(/^[A-Z0-9][A-Z0-9_-]*$/, "Use letters, numbers, hyphens or underscores"), }); export const profileVersion = z.number().int().positive(); const profileSnapshot = businessProfile.extend({ profileVersion }); export const submissionInput = z.object({ idempotencyKey: uuid }).strict(); export const decisionInput = submissionInput.extend({ decision: z.enum(["APPROVED", "REJECTED"]), note: text(500, 3), }); export const businessEvent = z.object({ id: uuid, actorId: uuid, sequence: z.number().int().positive(), kind: z.enum(["SUBMITTED", "APPROVED", "REJECTED"]), profileSnapshot: profileSnapshot.nullable(), note: z.string().nullable(), createdAt: z.string().datetime(), }); export const businessAccount = businessInput.extend({ id: uuid, profileVersion, status: z.enum(["DRAFT", "PENDING", "VERIFIED", "REJECTED"]), latestEvent: businessEvent.nullable(), }).strip(); export const businessSearch = text(100, 0);