import { z } from "zod"; /** * Building blocks shared by the contracts. Objects strip fields they don't know instead of * failing, so a newer producer that adds an optional field never breaks an older consumer * (ROADMAP-v3 §2, "Versioning"). */ /** The products of a church stack (ROADMAP-v3 §1). */ export const PRODUCTS = ["events", "website", "app", "accounts"] as const; export const productSchema = z.enum(PRODUCTS); export type Product = z.infer; /** The products that publish and show events (Accounts has none). */ export const EVENT_PRODUCTS = ["events", "website", "app"] as const; export const eventProductSchema = z.enum(EVENT_PRODUCTS); export type EventProduct = z.infer; /** Ids are UUIDs everywhere: records, installs, licences, customers and account `sub`s. */ export const idSchema = z.uuid(); /** An ISO 8601 date-time in UTC, as sent by every product (`2026-11-03T10:00:00.000Z`). */ export const dateTimeSchema = z.iso.datetime(); /** A calendar date (`2026-12-01`). */ export const dateSchema = z.iso.date(); /** A 24-hour clock time (`09:30`). */ export const timeOfDaySchema = z.string().regex(/^([01]\d|2[0-3]):[0-5]\d$/, "Expected HH:MM (24-hour)"); /** An IANA timezone name, e.g. `Africa/Johannesburg`. */ export const timezoneSchema = z.string().regex(/^[A-Za-z_]+(\/[A-Za-z0-9_+-]+){0,2}$|^UTC$/, "Expected an IANA timezone"); /** An absolute http(s) URL. Production URLs are https; http is allowed for local development. */ export const urlSchema = z.url({ protocol: /^https?$/ }).max(2048); /** A web colour: `#rrggbb`. */ export const hexColourSchema = z.string().regex(/^#[0-9a-fA-F]{6}$/, "Expected #rrggbb"); /** A slug: lower-case letters, digits and dashes (`meyerton`, `youth-camp`). */ export const slugSchema = z.string().regex(/^[a-z0-9]+(-[a-z0-9]+)*$/, "Expected a lower-case slug").max(100); /** An amount of money in the smallest unit (cents) with its ISO 4217 currency. */ export const moneySchema = z.object({ amountCents: z.int().nonnegative(), currency: z.string().regex(/^[A-Z]{3}$/, "Expected an ISO 4217 code"), }); export type Money = z.infer; /** A semantic version (`2.3.0`, `1.0.0-beta.1`). */ export const semverSchema = z.string().regex(/^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/, "Expected a semantic version"); /** An email address. */ export const emailSchema = z.email().max(254); /** A phone number in E.164 form (`+27821234567`). */ export const phoneSchema = z.string().regex(/^\+[1-9]\d{6,14}$/, "Expected an E.164 phone number");