oidc-provider 9.13.3 with PKCE, ES256, crosscode.identity/1 claims and back-channel logout; clients are the linked products (Connect). Sign-in steps (password, sign-up, email check, 2FA and its setup, privacy notice, news question, password reset) survive to the product. Account page and admin API, church profile, export and deletion fan-out, Hub v2 client, jobs. End-to-end tests with a test product on openid-client. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
119 lines
5.0 KiB
TypeScript
119 lines
5.0 KiB
TypeScript
import { z } from "zod";
|
||
import { dateTimeSchema, emailSchema, hexColourSchema, idSchema, phoneSchema, slugSchema, timeOfDaySchema, timezoneSchema, urlSchema } from "./common";
|
||
import { schemaName } from "./schema-name";
|
||
|
||
/**
|
||
* `crosscode.church/1` — the church profile, set once and shared by every product of a church
|
||
* (ROADMAP-v3 §2): name, logo, colours, campuses, service times and contact details. The Website,
|
||
* App and Accounts' sign-in page are branded from it.
|
||
*
|
||
* Public information only: the church's own contact details, never a person's.
|
||
*/
|
||
|
||
export const CHURCH_SCHEMA = schemaName("church", 1);
|
||
|
||
export const WEEKDAYS = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"] as const;
|
||
export const SOCIAL_NETWORKS = ["facebook", "instagram", "youtube", "tiktok", "x", "spotify", "whatsapp-channel", "other"] as const;
|
||
|
||
export const addressSchema = z.object({
|
||
line1: z.string().trim().min(1).max(200),
|
||
line2: z.string().trim().max(200).nullable(),
|
||
suburb: z.string().trim().max(100).nullable(),
|
||
city: z.string().trim().min(1).max(100),
|
||
province: z.string().trim().max(100).nullable(),
|
||
postalCode: z.string().trim().max(20).nullable(),
|
||
/** ISO 3166-1 alpha-2, e.g. `ZA`. */
|
||
country: z.string().regex(/^[A-Z]{2}$/, "Expected an ISO 3166-1 alpha-2 code"),
|
||
/** For a map pin. */
|
||
geo: z.object({ lat: z.number().min(-90).max(90), lng: z.number().min(-180).max(180) }).nullable(),
|
||
});
|
||
export type Address = z.infer<typeof addressSchema>;
|
||
|
||
export const campusSchema = z.object({
|
||
slug: slugSchema,
|
||
name: z.string().trim().min(1).max(200),
|
||
address: addressSchema.nullable(),
|
||
});
|
||
|
||
export const serviceTimeSchema = z.object({
|
||
day: z.enum(WEEKDAYS),
|
||
/** Local time in the church's timezone. */
|
||
time: timeOfDaySchema,
|
||
/** E.g. "Morning service", "Afrikaans service". */
|
||
label: z.string().trim().max(100).nullable(),
|
||
/** The campus's slug, or `null` when the church has no campuses. */
|
||
campus: slugSchema.nullable(),
|
||
/** E.g. "Kids church during the service". */
|
||
note: z.string().trim().max(300).nullable(),
|
||
});
|
||
|
||
/** The profile's fields without the cross-field checks, for building forms that edit part of it (contracts 1.5.0). */
|
||
export const churchObjectSchema = z
|
||
.object({
|
||
schema: z.literal(CHURCH_SCHEMA),
|
||
/** The Hub customer id: the same for every product of the church. */
|
||
customerId: idSchema,
|
||
updatedAt: dateTimeSchema,
|
||
name: z.string().trim().min(1).max(200),
|
||
/** For tight spaces (app icon label, sign-in page title). */
|
||
shortName: z.string().trim().max(30).nullable(),
|
||
timezone: timezoneSchema,
|
||
/** BCP 47, e.g. `en-ZA`. */
|
||
locale: z.string().regex(/^[a-z]{2,3}(-[A-Z]{2})?$/, "Expected a BCP 47 locale like en-ZA"),
|
||
branding: z.object({
|
||
logoUrl: urlSchema.nullable(),
|
||
/** Square, at least 512×512: app icon and favicon. */
|
||
iconUrl: urlSchema.nullable(),
|
||
colours: z.object({
|
||
primary: hexColourSchema,
|
||
accent: hexColourSchema.nullable(),
|
||
}),
|
||
}),
|
||
/** Empty when campuses are off. */
|
||
campuses: z.array(campusSchema).max(50),
|
||
serviceTimes: z.array(serviceTimeSchema).max(100),
|
||
contact: z.object({
|
||
email: emailSchema.nullable(),
|
||
phone: phoneSchema.nullable(),
|
||
whatsapp: phoneSchema.nullable(),
|
||
address: addressSchema.nullable(),
|
||
}),
|
||
social: z.array(z.object({ network: z.enum(SOCIAL_NETWORKS), url: urlSchema })).max(20),
|
||
/** The church's products, so each can link to the others. */
|
||
links: z.object({
|
||
website: urlSchema.nullable(),
|
||
events: urlSchema.nullable(),
|
||
app: urlSchema.nullable(),
|
||
accounts: urlSchema,
|
||
}),
|
||
});
|
||
|
||
export const churchSchema = churchObjectSchema.superRefine((church, ctx) => {
|
||
const slugs = new Set(church.campuses.map((c) => c.slug));
|
||
if (slugs.size !== church.campuses.length) ctx.addIssue({ code: "custom", path: ["campuses"], message: "Campus slugs must be unique" });
|
||
church.serviceTimes.forEach((s, i) => {
|
||
if (s.campus !== null && !slugs.has(s.campus)) ctx.addIssue({ code: "custom", path: ["serviceTimes", i, "campus"], message: `Unknown campus "${s.campus}"` });
|
||
});
|
||
});
|
||
|
||
export type Church = z.infer<typeof churchSchema>;
|
||
export type Campus = z.infer<typeof campusSchema>;
|
||
export type ServiceTime = z.infer<typeof serviceTimeSchema>;
|
||
|
||
/**
|
||
* Where the church profile lives (contracts 1.5.0): **Accounts owns it** (docs/ACCOUNTS-1.0-PLAN.md
|
||
* §7, decision 1) and serves it publicly at `profile`; products read it from there. When it
|
||
* changes, Accounts sends `church.changed` (signed with the link's secret, `LINK_HEADERS`) to
|
||
* each linked product at `changed`, which then fetches the profile again.
|
||
*/
|
||
export const CHURCH_PATHS = { profile: "/api/church/v1", changed: "/api/church/v1/changed" } as const;
|
||
|
||
/** The `church.changed` webhook: a hint to fetch `GET /api/church/v1` again. */
|
||
export const churchChangedSchema = z.object({
|
||
schema: z.literal(CHURCH_SCHEMA),
|
||
type: z.literal("church.changed"),
|
||
occurredAt: dateTimeSchema,
|
||
updatedAt: dateTimeSchema,
|
||
});
|
||
export type ChurchChanged = z.infer<typeof churchChangedSchema>;
|