contracts 1.17.0: brand style, church.update, the Website's export, licence storage limit

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-24 16:25:20 +02:00
co-authored by Claude Opus 5.5
parent 9954e66c33
commit 0e3534f29f
24 changed files with 2326 additions and 12 deletions
+76 -2
View File
@@ -1,5 +1,6 @@
import { z } from "zod";
import { dateTimeSchema, productSchema, timezoneSchema } from "./common";
import { dateTimeSchema, productSchema, timezoneSchema, urlSchema } from "./common";
import { websiteTemplateSchema } from "./style";
/**
* crosscode.church-export/1: a church's data when it leaves (docs/AGENT-1.0-PLAN.md §9). Written
@@ -14,6 +15,7 @@ const ref = (prefix: string) => z.string().regex(new RegExp(`^${prefix}[0-9]+$`)
const text = (max = 20000) => z.string().max(max);
const when = dateTimeSchema.nullable();
const cents = z.int();
const uploadPath = z.string().regex(/^uploads\/[A-Za-z0-9._/-]+$/);
export const exportPersonSchema = z.object({
ref: ref("p"),
@@ -62,6 +64,76 @@ export const exportCheckInSchema = z.object({ eventRef: ref("e"), personRef: ref
export const exportRosterSchema = z.object({ eventRef: ref("e").nullable(), role: text(200), personRef: ref("p").nullable(), startsAt: when, endsAt: when });
// The Website's part (contracts 1.17.0, WEBSITE-1.0-PLAN §11): its content as the admins left it
// (the working copy, including changes not yet published), the publish history's notes, messages,
// simple events and the media library. Images are files in `uploads/`, listed in `files`.
/** A section of a page: its type and layout, and what the admin filled in (text, links, image paths). */
export const exportWebsiteSectionSchema = z.object({
/** E.g. `hero`, `service-times`, `ministries`, `text`, `gallery`. */
type: text(60),
/** E.g. `photo`, `cards`. */
variant: text(60),
hidden: z.boolean(),
content: z.record(z.string().max(100), z.json()),
});
export const exportWebsitePageSchema = z.object({
ref: ref("g"),
title: text(300),
/** The page's path on the site: `/` for home, `/about`, `/youth-camp`. */
path: z.string().regex(/^\/[a-z0-9/-]*$/).max(300),
/** `home`, `about`, `visit`, `contact`, `give`, … or `custom` for a page the church added. */
kind: text(40),
inNavigation: z.boolean(),
seo: z.object({ title: text(300).nullable(), description: text(500).nullable() }),
sections: z.array(exportWebsiteSectionSchema),
});
export const exportWebsiteMessageSchema = z.object({
ref: ref("m"),
title: text(500),
date: when,
speaker: text(300).nullable(),
series: text(300).nullable(),
passage: text(300).nullable(),
notes: text().nullable(),
/** The YouTube or Spotify link (audio and video are never uploaded). */
url: urlSchema,
/** `youtube-feed` when it came in from the channel or playlist by itself. */
source: z.enum(["youtube-feed", "manual"]),
hidden: z.boolean(),
});
/** A simple event made in the Website (Cross Events' own events are in its export's `events`). */
export const exportWebsiteEventSchema = z.object({
ref: ref("w"),
title: text(500),
description: text().nullable(),
startsAt: when,
endsAt: when,
location: text(500).nullable(),
link: urlSchema.nullable(),
image: uploadPath.nullable(),
published: z.boolean(),
});
export const exportWebsiteSchema = z.object({
template: websiteTemplateSchema,
/** Null when the site was never published (it showed Coming soon). */
firstPublishedAt: when,
/** The Website-only style settings (section colour, spacing, buttons, image treatment, header). */
style: z.record(z.string().max(100), z.string().max(200)),
pages: z.array(exportWebsitePageSchema),
messages: z.array(exportWebsiteMessageSchema),
events: z.array(exportWebsiteEventSchema),
/** Every publish, oldest first. The snapshots aren't exported: `pages` is the content. */
versions: z.array(z.object({ number: z.int().positive(), publishedAt: when, by: text(300).nullable(), note: text(1000).nullable() })),
/** The media library: alt text and captions of the files in `uploads/`. */
media: z.array(z.object({ path: uploadPath, alt: text(500).nullable(), caption: text(1000).nullable() })),
});
export type ExportWebsite = z.infer<typeof exportWebsiteSchema>;
export const churchExportSchema = z.object({
schema: z.literal("crosscode.church-export/1"),
exportedAt: dateTimeSchema,
@@ -77,7 +149,9 @@ export const churchExportSchema = z.object({
/** The site's own settings that matter to a church (name, contact, branding), never secrets. */
settings: z.record(z.string().max(100), z.string().max(5000)),
/** Uploaded files in the ZIP's `uploads/` folder. */
files: z.array(z.object({ path: z.string().regex(/^uploads\/[A-Za-z0-9._/-]+$/), bytes: z.int().nonnegative() })),
files: z.array(z.object({ path: uploadPath, bytes: z.int().nonnegative() })),
/** Only in the Website's export (contracts 1.17.0). Its editors are in `people`, with their roles. */
website: exportWebsiteSchema.optional(),
});
export type ChurchExport = z.infer<typeof churchExportSchema>;
+6
View File
@@ -1,6 +1,7 @@
import { z } from "zod";
import { dateTimeSchema, emailSchema, hexColourSchema, idSchema, phoneSchema, slugSchema, timeOfDaySchema, timezoneSchema, urlSchema } from "./common";
import { schemaName } from "./schema-name";
import { brandStyleSchema } from "./style";
/**
* `crosscode.church/1` — the church profile, set once and shared by every product of a church
@@ -68,6 +69,11 @@ export const churchObjectSchema = z
primary: hexColourSchema,
accent: hexColourSchema.nullable(),
}),
/**
* Font pairing and corners, shared by every product (contracts 1.17.0, `./style`). Optional:
* a profile from an Accounts before 1.7.0 has none, which means the defaults.
*/
style: brandStyleSchema.optional(),
}),
/** Empty when campuses are off. */
campuses: z.array(campusSchema).max(50),
+9 -1
View File
@@ -355,6 +355,14 @@ export const licencePayloadSchema = z.object({
graceDays: z.int().nonnegative(),
issuedAt: dateTimeSchema,
validUntil: dateTimeSchema,
limits: z.object({ aiMonthlyCapCents: z.number().nonnegative() }),
limits: z.object({
aiMonthlyCapCents: z.number().nonnegative(),
/**
* The Website's storage limit in bytes: what's included plus any storage add-ons
* (WEBSITE-1.0-PLAN §10, decision 12). Uploads stop when it's full. Only on a Website licence,
* from Hub 2.21.0 (contracts 1.17.0); a Website without it uses its own included amount.
*/
storageBytes: z.int().nonnegative().optional(),
}),
});
export type LicencePayload = z.infer<typeof licencePayloadSchema>;
+40 -1
View File
@@ -2,6 +2,7 @@ import { z } from "zod";
import { dateTimeSchema, emailSchema, idSchema, phoneSchema } from "./common";
import { profileSchema, twoFactorMethodSchema } from "./identity";
import { schemaName } from "./schema-name";
import { churchObjectSchema, churchSchema } from "./church";
/**
* `crosscode.identity-request/1` (contracts 1.8.0, docs/EVENTS-3.0-PLAN.md §4 and §8): what a
@@ -21,6 +22,8 @@ import { schemaName } from "./schema-name";
* unsubscribe link). Accounts only acts on people the product knows (signed in through it or
* imported by it), and audits each with the product and the admin's `sub`. 1.11.0 adds
* `people.removeDemo`: new demo data in a product removes the old demo people's accounts.
* - **`church.*`**: the church profile from a product. `church.branding` (1.9.0) fills in the
* look; `church.update` (1.17.0) changes shared facts from the Website's admin.
*/
export const IDENTITY_REQUEST_SCHEMA = schemaName("identity-request", 1);
@@ -240,10 +243,40 @@ export const messagingSetSchema = messagingTestSchema.extend({ type: z.literal("
*/
export const churchBrandingSchema = base.extend({ type: z.literal("church.branding"), church: churchLookSchema, overwrite: z.boolean() });
/**
* The profile fields a product may change: the profile without what Accounts fills in itself
* (`customerId`, `updatedAt`, `links`).
*/
export const churchEditableSchema = churchObjectSchema.omit({ schema: true, customerId: true, updatedAt: true, links: true });
/**
* 1.17.0: change shared profile facts from a product's admin (the Website's, WEBSITE-1.0-PLAN
* decision 10). The product checks the person may do it (its own roles: Accounts doesn't know
* them) and sends it with them as `actor`; Accounts audits it with the product and the actor.
*
* Only the fields given change. A given field replaces Accounts' value as a whole (a list, an
* address, `branding.colours`), except `branding`, whose own fields can be given one at a time
* (only `style`, say). It goes live at once (shared facts aren't drafts) and Accounts sends
* `church.changed` to every linked product. With `ifUpdatedAt`, Accounts refuses with
* `PROFILE_CHANGED` when the profile changed since (someone saved in between).
*
* Accounts takes it from the Website only (`WRONG_PRODUCT` otherwise) and needs an `actor`
* (`NOT_ALLOWED`). The reply is the profile after the change.
*/
export const churchUpdateSchema = base.extend({
type: z.literal("church.update"),
actor: idSchema,
ifUpdatedAt: dateTimeSchema.optional(),
church: churchEditableSchema
.extend({ branding: churchEditableSchema.shape.branding.partial() })
.partial()
.refine((c) => Object.keys(c).length > 0, "Nothing to change"),
});
export const identityRequestSchema = z.discriminatedUnion("type", [
importBeginSchema, importBatchSchema, importFinishSchema, importAbortSchema,
peopleEnsureSchema, peopleUpdateSchema, peopleResetTwoFactorSchema, peopleUnlockSchema, peopleSetActiveSchema, peopleNewsOffSchema,
peopleRemoveDemoSchema, peopleCheckSchema, messagingStatusSchema, messagingTestSchema, messagingSetSchema, churchBrandingSchema,
peopleRemoveDemoSchema, peopleCheckSchema, messagingStatusSchema, messagingTestSchema, messagingSetSchema, churchBrandingSchema, churchUpdateSchema,
]);
export type IdentityRequest = z.infer<typeof identityRequestSchema>;
export type IdentityRequestType = IdentityRequest["type"];
@@ -323,7 +356,13 @@ export const messagingTestReplySchema = z.object({
});
export type MessagingTestReply = z.infer<typeof messagingTestReplySchema>;
/** church.update: the profile after the change. */
export const churchUpdateReplySchema = z.object({ schema: z.literal(IDENTITY_REQUEST_SCHEMA), church: churchSchema });
export type ChurchUpdateReply = z.infer<typeof churchUpdateReplySchema>;
/** Errors: `{ message, code }` as the other link calls. */
export const IDENTITY_REQUEST_ERROR_CODES = [
"NOT_LINKED", "BAD_SIGNATURE", "STALE_REQUEST", "INVALID_REQUEST", "NOT_MOVING", "WRONG_PRODUCT", "UNKNOWN_PERSON", "EMAIL_TAKEN", "NOT_ALLOWED",
/** 1.17.0, church.update with `ifUpdatedAt`: the profile changed since. */
"PROFILE_CHANGED",
] as const;
+1
View File
@@ -6,6 +6,7 @@ export * from "./schema-name";
export * from "./common";
export * from "./event";
export * from "./church";
export * from "./style";
export * from "./identity";
export * from "./identity-request";
export * from "./return-to";
+73
View File
@@ -0,0 +1,73 @@
import { z } from "zod";
/**
* The church's brand style (contracts 1.17.0, WEBSITE-1.0-PLAN §3 "Font pairings", decision 15):
* a font pairing and a corner style, kept in the church profile (`branding.style`) and used by the
* Website, Accounts' pages, Cross Events' public pages and later the App, so they feel like one
* church. Colours are already in the profile.
*
* The ids are stored in every church's profile, so **an id never changes or goes away** once
* released. Names shown to churches, and the fonts behind an id, may.
*/
/** How a font falls back while it loads, and which metric-matched fallback `@crosscode/ui` uses. */
export const FONT_CATEGORIES = ["serif", "sans-serif"] as const;
export type FontCategory = (typeof FONT_CATEGORIES)[number];
export type FontFace = { family: string; category: FontCategory };
export type FontPairingInfo = { name: string; heading: FontFace; body: FontFace; feel: string };
const serif = (family: string): FontFace => ({ family, category: "serif" });
const sans = (family: string): FontFace => ({ family, category: "sans-serif" });
/** The 8 font pairings, all SIL Open Font License, variable and with Latin Extended. Self-hosted only. */
export const FONT_PAIRINGS = {
classic: { name: "Classic", heading: serif("Lora"), body: sans("Source Sans 3"), feel: "Traditional serif headings, a plain readable body" },
scholarly: { name: "Scholarly", heading: serif("EB Garamond"), body: serif("EB Garamond"), feel: "Old-style book type throughout; dignified" },
editorial: { name: "Editorial", heading: serif("Playfair Display"), body: sans("Inter"), feel: "High-contrast magazine headlines over a neutral body" },
impact: { name: "Impact", heading: sans("Oswald"), body: sans("Source Sans 3"), feel: "Tall condensed headlines; loud over photos" },
contemporary: { name: "Contemporary", heading: sans("Outfit"), body: sans("DM Sans"), feel: "Geometric, modern, light-handed" },
friendly: { name: "Friendly", heading: sans("Nunito"), body: sans("Nunito"), feel: "Rounded ends throughout; warm and informal" },
warm: { name: "Warm", heading: serif("Fraunces"), body: sans("Nunito Sans"), feel: "A soft, characterful serif with a gentle sans" },
modern: { name: "Modern", heading: sans("Inter"), body: sans("Inter"), feel: "One neutral sans; lets colour and photos lead" },
} as const satisfies Record<string, FontPairingInfo>;
export const FONT_PAIRING_IDS = Object.keys(FONT_PAIRINGS) as [keyof typeof FONT_PAIRINGS, ...(keyof typeof FONT_PAIRINGS)[]];
export const fontPairingSchema = z.enum(FONT_PAIRING_IDS);
export type FontPairing = z.infer<typeof fontPairingSchema>;
/** Corner style: the radius of cards, buttons, images and fields. */
export const CORNERS = ["sharp", "soft", "round"] as const;
export const cornersSchema = z.enum(CORNERS);
export type Corners = z.infer<typeof cornersSchema>;
/** What a profile without `corners` means. */
export const DEFAULT_CORNERS: Corners = "soft";
/** The Website's four templates (ROADMAP-v3 decision 19). */
export const WEBSITE_TEMPLATES = ["heritage", "bold", "community", "clean"] as const;
export const websiteTemplateSchema = z.enum(WEBSITE_TEMPLATES);
export type WebsiteTemplate = z.infer<typeof websiteTemplateSchema>;
/**
* The three pairings each template recommends; the first is its default. Every pairing works in
* every template: the others are shown under "More".
*/
export const TEMPLATE_FONT_PAIRINGS: Record<WebsiteTemplate, readonly [FontPairing, FontPairing, FontPairing]> = {
heritage: ["classic", "scholarly", "editorial"],
bold: ["impact", "contemporary", "editorial"],
community: ["friendly", "warm", "contemporary"],
clean: ["modern", "classic", "contemporary"],
};
/**
* `branding.style` in `crosscode.church/1`. Both fields are null until an admin picks one; then
* the Website uses its template's default pairing, and Events and Accounts keep their system fonts.
*
* An id this version doesn't know (from a newer Accounts) reads as null, so a profile with a newer
* pairing never fails to parse: the product just shows its default.
*/
export const brandStyleSchema = z.object({
fontPairing: fontPairingSchema.nullable().catch(null),
corners: cornersSchema.nullable().catch(null),
});
export type BrandStyle = z.infer<typeof brandStyleSchema>;