Files
crosscode-platform/packages/contracts/src/common.ts
T
joshuaandClaude Opus 5.5 514a6d8bc0 contracts 1.20.0: devotionals, Bible passages, messaging.get, WhatsApp opt-out, App export
The contracts for Church App 1.0.0 (docs/APP-1.0-PLAN.md §12). Additive.

- crosscode.devotional/1, the Hub's devotionals reply, and the devotionals CSV
  import (parseCsv, checkDevotionalCsv, template), shared by the Hub and the App
- Bible books (USFM, English and Afrikaans), seven translations with YouVersion
  ids and copyright lines, parseBibleReference, youVersionUrl
- messaging.get and the messaging.changed hint; whatsapp.optout and
  whatsapp_opted_out on the profile
- APP_MODULES, hub.DEVOTIONALS_PATH, agent.APP_DEMO_PROFILES, app in DEMO_PRODUCTS
- the app section of the church export, people[].roles
- Accounts refuses the two new requests until 1.9.0

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 09:54:25 +02:00

67 lines
3.0 KiB
TypeScript

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<typeof productSchema>;
/** 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<typeof eventProductSchema>;
/**
* The Church App's modules (contracts 1.20.0, APP-1.0-PLAN §2): each can be switched off. The App
* reports the ones that are on in its heartbeat (`hub.appStatsSchema.modules`, which takes any
* slug so a later module never breaks an older Hub).
*/
export const APP_MODULES = ["house-of-prayer", "prayer-requests", "announcements", "devotionals", "events"] as const;
export const appModuleSchema = z.enum(APP_MODULES);
export type AppModule = z.infer<typeof appModuleSchema>;
/** 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<typeof moneySchema>;
/** 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");