Jobs of fixed types with strict argument schemas, signed by the Hub with Ed25519 over canonical JSON. Agent requests signed with the server's Ed25519 key. Config sealed to the server's X25519 key (X25519 + HKDF + AES-256-GCM; Node has no XSalsa20). Exports encrypted with a key that only travels in the download link. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
86 lines
3.4 KiB
TypeScript
86 lines
3.4 KiB
TypeScript
import { z } from "zod";
|
|
import { dateTimeSchema, productSchema, timezoneSchema } from "./common";
|
|
|
|
/**
|
|
* crosscode.church-export/1: a church's data when it leaves (docs/AGENT-1.0-PLAN.md §9). Written
|
|
* for people, in plain terms with our own field names: no database tables, Prisma models or
|
|
* internal ids. Records point at each other with references made for the export (`p12`, `e3`,
|
|
* `r40`), which mean nothing outside the file.
|
|
*
|
|
* Shipped as a ZIP: `export.json` (this), `uploads/` (the files in `files`) and `README.txt`.
|
|
*/
|
|
|
|
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();
|
|
|
|
export const exportPersonSchema = z.object({
|
|
ref: ref("p"),
|
|
name: text(300),
|
|
email: text(254).nullable(),
|
|
phone: text(40).nullable(),
|
|
role: text(40),
|
|
createdAt: when,
|
|
consent: z.object({ email: z.boolean().nullable(), whatsapp: z.boolean().nullable(), privacyNoticeAcceptedAt: when }),
|
|
});
|
|
|
|
export const exportEventSchema = z.object({
|
|
ref: ref("e"),
|
|
title: text(500),
|
|
description: text().nullable(),
|
|
startsAt: when,
|
|
endsAt: when,
|
|
location: text(500).nullable(),
|
|
sessions: z.array(z.object({ label: text(300).nullable(), startsAt: when, endsAt: when })),
|
|
ticketTypes: z.array(z.object({ ref: ref("t"), name: text(300), priceCents: cents, currency: z.string().length(3) })),
|
|
capacity: z.int().nullable(),
|
|
published: z.boolean(),
|
|
});
|
|
|
|
export const exportRegistrationSchema = z.object({
|
|
ref: ref("r"),
|
|
eventRef: ref("e"),
|
|
personRef: ref("p").nullable(),
|
|
status: text(40),
|
|
createdAt: when,
|
|
attendees: z.array(z.object({ name: text(300), email: text(254).nullable(), ticketTypeRef: ref("t").nullable(), checkedInAt: when })),
|
|
answers: z.array(z.object({ question: text(500), answer: text(5000) })).default([]),
|
|
});
|
|
|
|
export const exportPaymentSchema = z.object({
|
|
registrationRef: ref("r").nullable(),
|
|
amountCents: cents,
|
|
currency: z.string().length(3),
|
|
method: text(40),
|
|
status: text(40),
|
|
paidAt: when,
|
|
reference: text(200).nullable(),
|
|
});
|
|
|
|
export const exportCheckInSchema = z.object({ eventRef: ref("e"), personRef: ref("p").nullable(), name: text(300).nullable(), at: when });
|
|
|
|
export const exportRosterSchema = z.object({ eventRef: ref("e").nullable(), role: text(200), personRef: ref("p").nullable(), startsAt: when, endsAt: when });
|
|
|
|
export const churchExportSchema = z.object({
|
|
schema: z.literal("crosscode.church-export/1"),
|
|
exportedAt: dateTimeSchema,
|
|
product: productSchema,
|
|
productVersion: z.string().max(40),
|
|
church: z.object({ name: text(300), timezone: timezoneSchema.nullable() }),
|
|
people: z.array(exportPersonSchema),
|
|
events: z.array(exportEventSchema),
|
|
registrations: z.array(exportRegistrationSchema),
|
|
payments: z.array(exportPaymentSchema),
|
|
checkIns: z.array(exportCheckInSchema),
|
|
rosters: z.array(exportRosterSchema),
|
|
/** 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() })),
|
|
});
|
|
export type ChurchExport = z.infer<typeof churchExportSchema>;
|
|
|
|
/** Keys that look like internal ids anywhere in an export (the export test fails on any). */
|
|
export const INTERNAL_ID_KEYS = /^(id|.*Id|uuid|_id)$/;
|