Accounts 1.9.0, @crosscode/demo 1.0.0: messaging.get, WhatsApp opt-out, demo scenarios
Accounts 1.9.0 (one migration): - messaging.get (sealed settings) and the messaging.changed hint to products that asked, on admin or product changes - the WhatsApp opt-out for every product: whatsapp.optout, Accounts' own WAWP webhook, WhatsAppOptOut kept per number, whatsapp_opted_out in user.updated, no WhatsApp from Accounts to an opted-out person, "Turn WhatsApp back on" - demo scenarios: npm run demo -- --profile <scenario> --force replaces the church profile (with an SVG logo and icon at /api/demo-assets/) and the demo people, ids kept across loads @crosscode/demo 1.0.0 (new): the eight scenarios' churches, people and logos. crosscode script: crosscode demo <church> accounts, --scenario on every demo, Accounts installs and builds packages/demo. Checked on PostgreSQL 18: migrations, scenario loads, opt-out, npm run demo. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,166 @@
|
||||
import type { BrandStyle, Church, agent } from "@crosscode/contracts";
|
||||
|
||||
/**
|
||||
* Each demo scenario's church (APP-1.0-PLAN §12, "Demo scenarios"; the list is
|
||||
* `agent.DEMO_SCENARIOS` in the contracts). Loading a scenario puts this profile into Accounts, so
|
||||
* Cross Events, the Website and the App all show the same church. Every name, address and number is
|
||||
* made up: contact addresses are at example.com, social links at example.com, and there are no
|
||||
* phone numbers (nothing a demo sends can reach a real person).
|
||||
*/
|
||||
|
||||
/** The simple mark each church's logo and icon are drawn with (`./logo`). */
|
||||
export type DemoMark = "arch" | "cross" | "flame" | "wave" | "tree" | "sun" | "north" | "river";
|
||||
|
||||
/** The profile fields Accounts takes from a scenario (it fills in the rest: ids, links, logo addresses). */
|
||||
export type DemoChurchProfile = Pick<Church, "name" | "shortName" | "timezone" | "locale" | "campuses" | "serviceTimes" | "social"> & {
|
||||
colours: { primary: string; accent: string };
|
||||
style: { fontPairing: NonNullable<BrandStyle["fontPairing"]>; corners: NonNullable<BrandStyle["corners"]> };
|
||||
contact: Omit<Church["contact"], "phone" | "whatsapp">;
|
||||
};
|
||||
|
||||
export interface DemoChurch {
|
||||
scenario: agent.DemoScenarioKey;
|
||||
/** Used in demo addresses: `office.<slug>@example.com`. */
|
||||
slug: string;
|
||||
mark: DemoMark;
|
||||
profile: DemoChurchProfile;
|
||||
}
|
||||
|
||||
const ZA = "Africa/Johannesburg";
|
||||
const address = (line1: string, suburb: string | null, city: string, province: string, postalCode: string) =>
|
||||
({ line1, line2: null, suburb, city, province, postalCode, country: "ZA", geo: null });
|
||||
const social = (slug: string, networks: ("facebook" | "instagram" | "youtube" | "spotify")[]) =>
|
||||
networks.map((network) => ({ network, url: `https://example.com/${network}/${slug}` }));
|
||||
const contact = (slug: string, addr: ReturnType<typeof address>) => ({ email: `office.${slug}@example.com`, address: addr });
|
||||
|
||||
export const DEMO_CHURCHES: readonly DemoChurch[] = [
|
||||
{
|
||||
scenario: "heritage-parish", slug: "stcolumbas", mark: "arch",
|
||||
profile: {
|
||||
name: "St Columba's Church", shortName: "St Columba's", timezone: ZA, locale: "en-ZA",
|
||||
colours: { primary: "#5b2333", accent: "#c9a227" }, style: { fontPairing: "classic", corners: "sharp" },
|
||||
campuses: [],
|
||||
serviceTimes: [
|
||||
{ day: "sunday", time: "09:00", label: "Sung Eucharist", campus: null, note: "Sunday school in the hall during the service" },
|
||||
{ day: "wednesday", time: "10:00", label: "Midweek communion", campus: null, note: null },
|
||||
],
|
||||
contact: contact("stcolumbas", address("3 Glebe Lane", "Old Town", "Grahamstown", "Eastern Cape", "6139")),
|
||||
social: social("stcolumbas", ["facebook"]),
|
||||
},
|
||||
},
|
||||
{
|
||||
scenario: "heritage-city", slug: "gracecathedral", mark: "cross",
|
||||
profile: {
|
||||
name: "Grace Cathedral", shortName: "Grace", timezone: ZA, locale: "en-ZA",
|
||||
colours: { primary: "#1d3557", accent: "#e09f3e" }, style: { fontPairing: "editorial", corners: "sharp" },
|
||||
campuses: [],
|
||||
serviceTimes: [
|
||||
{ day: "sunday", time: "07:30", label: "Early communion", campus: null, note: null },
|
||||
{ day: "sunday", time: "09:30", label: "Cathedral Eucharist", campus: null, note: "Choir and children's church" },
|
||||
{ day: "sunday", time: "18:00", label: "Choral evensong", campus: null, note: null },
|
||||
{ day: "wednesday", time: "12:30", label: "Lunchtime prayer", campus: null, note: "Thirty minutes, then soup in the crypt" },
|
||||
],
|
||||
contact: contact("gracecathedral", address("1 Cathedral Square", "City Centre", "Cape Town", "Western Cape", "8001")),
|
||||
social: social("gracecathedral", ["facebook", "youtube", "spotify"]),
|
||||
},
|
||||
},
|
||||
{
|
||||
scenario: "bold-youth", slug: "ignite", mark: "flame",
|
||||
profile: {
|
||||
name: "Ignite Church", shortName: "Ignite", timezone: ZA, locale: "en-ZA",
|
||||
colours: { primary: "#e4572e", accent: "#17bebb" }, style: { fontPairing: "impact", corners: "round" },
|
||||
campuses: [],
|
||||
serviceTimes: [
|
||||
{ day: "sunday", time: "10:00", label: "Sunday gathering", campus: null, note: "Kids zone for ages 3 to 11" },
|
||||
{ day: "sunday", time: "17:30", label: "Ignite Night", campus: null, note: "Worship night for students and young adults" },
|
||||
{ day: "friday", time: "19:00", label: "Youth", campus: null, note: "Grades 8 to 12" },
|
||||
],
|
||||
contact: contact("ignite", address("48 Factory Road", "Maboneng", "Johannesburg", "Gauteng", "2094")),
|
||||
social: social("ignite", ["instagram", "youtube", "spotify"]),
|
||||
},
|
||||
},
|
||||
{
|
||||
scenario: "bold-plant", slug: "harbourcity", mark: "wave",
|
||||
profile: {
|
||||
name: "Harbour City Church", shortName: "Harbour City", timezone: ZA, locale: "en-ZA",
|
||||
colours: { primary: "#0b6e99", accent: "#f4b942" }, style: { fontPairing: "contemporary", corners: "round" },
|
||||
campuses: [],
|
||||
serviceTimes: [
|
||||
{ day: "sunday", time: "09:30", label: "Sunday service", campus: null, note: "In the hall of Seaview Primary School" },
|
||||
],
|
||||
contact: contact("harbourcity", address("Seaview Primary School, 12 Marine Drive", "Humewood", "Gqeberha", "Eastern Cape", "6001")),
|
||||
social: social("harbourcity", ["instagram", "facebook"]),
|
||||
},
|
||||
},
|
||||
{
|
||||
scenario: "community-family", slug: "acaciahill", mark: "tree",
|
||||
profile: {
|
||||
name: "Acacia Hill Church", shortName: "Acacia Hill", timezone: ZA, locale: "en-ZA",
|
||||
colours: { primary: "#2f6f4f", accent: "#e9a23b" }, style: { fontPairing: "warm", corners: "soft" },
|
||||
campuses: [],
|
||||
serviceTimes: [
|
||||
{ day: "sunday", time: "08:30", label: "Early service", campus: null, note: null },
|
||||
{ day: "sunday", time: "10:30", label: "Family service", campus: null, note: "Kids' church for ages 2 to 12" },
|
||||
{ day: "wednesday", time: "18:30", label: "Prayer evening", campus: null, note: null },
|
||||
],
|
||||
contact: contact("acaciahill", address("27 Acacia Avenue", "Lynnwood", "Pretoria", "Gauteng", "0081")),
|
||||
social: social("acaciahill", ["facebook", "instagram", "youtube"]),
|
||||
},
|
||||
},
|
||||
{
|
||||
scenario: "community-town", slug: "karoo", mark: "sun",
|
||||
profile: {
|
||||
name: "Karoo Gemeenskapskerk", shortName: "Karoo Kerk", timezone: ZA, locale: "af-ZA",
|
||||
colours: { primary: "#9c4a1a", accent: "#d9b44a" }, style: { fontPairing: "friendly", corners: "soft" },
|
||||
campuses: [],
|
||||
serviceTimes: [
|
||||
{ day: "sunday", time: "09:00", label: "Erediens", campus: null, note: "Kinderkerk tydens die diens" },
|
||||
{ day: "sunday", time: "18:00", label: "Aanddiens (English)", campus: null, note: null },
|
||||
{ day: "wednesday", time: "19:00", label: "Bidstond", campus: null, note: null },
|
||||
],
|
||||
contact: contact("karoo", address("14 Kerkstraat", null, "Graaff-Reinet", "Eastern Cape", "6280")),
|
||||
social: social("karoo", ["facebook"]),
|
||||
},
|
||||
},
|
||||
{
|
||||
scenario: "clean-modern", slug: "northpoint", mark: "north",
|
||||
profile: {
|
||||
name: "Northpoint Church", shortName: "Northpoint", timezone: ZA, locale: "en-ZA",
|
||||
colours: { primary: "#22313f", accent: "#3fb68b" }, style: { fontPairing: "modern", corners: "soft" },
|
||||
campuses: [],
|
||||
serviceTimes: [
|
||||
{ day: "sunday", time: "08:30", label: "First service", campus: null, note: null },
|
||||
{ day: "sunday", time: "10:30", label: "Second service", campus: null, note: "Kids and youth during the service" },
|
||||
{ day: "sunday", time: "18:00", label: "Evening service", campus: null, note: null },
|
||||
],
|
||||
contact: contact("northpoint", address("200 Northpoint Boulevard", "Umhlanga Ridge", "Durban", "KwaZulu-Natal", "4319")),
|
||||
social: social("northpoint", ["facebook", "instagram", "youtube", "spotify"]),
|
||||
},
|
||||
},
|
||||
{
|
||||
scenario: "clean-campus", slug: "riverside", mark: "river",
|
||||
profile: {
|
||||
name: "Riverside Church", shortName: "Riverside", timezone: ZA, locale: "en-ZA",
|
||||
colours: { primary: "#264653", accent: "#2a9d8f" }, style: { fontPairing: "modern", corners: "sharp" },
|
||||
campuses: [
|
||||
{ slug: "stellenbosch", name: "Stellenbosch", address: address("5 Riverbank Road", "Die Boord", "Stellenbosch", "Western Cape", "7600") },
|
||||
{ slug: "paarl", name: "Paarl", address: address("88 Main Road", "Paarl Central", "Paarl", "Western Cape", "7646") },
|
||||
{ slug: "somerset-west", name: "Somerset West", address: address("12 Lourens Street", null, "Somerset West", "Western Cape", "7130") },
|
||||
],
|
||||
serviceTimes: [
|
||||
{ day: "sunday", time: "09:00", label: "Morning service", campus: "stellenbosch", note: null },
|
||||
{ day: "sunday", time: "18:30", label: "Students' service", campus: "stellenbosch", note: "Supper afterwards in the courtyard" },
|
||||
{ day: "sunday", time: "09:30", label: "Morning service", campus: "paarl", note: "Kids' church during the service" },
|
||||
{ day: "sunday", time: "10:00", label: "Morning service", campus: "somerset-west", note: null },
|
||||
],
|
||||
contact: contact("riverside", address("5 Riverbank Road", "Die Boord", "Stellenbosch", "Western Cape", "7600")),
|
||||
social: social("riverside", ["instagram", "youtube"]),
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export function demoChurch(scenario: agent.DemoScenarioKey): DemoChurch {
|
||||
const c = DEMO_CHURCHES.find((x) => x.scenario === scenario);
|
||||
if (!c) throw new Error(`No demo church for ${scenario}`);
|
||||
return c;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* @crosscode/demo: the demo scenarios' churches and people (docs/APP-1.0-PLAN.md §12, "Demo
|
||||
* scenarios"), so Accounts, Cross Events, the Church Website and the App load the same church.
|
||||
* The scenario list itself is `agent.DEMO_SCENARIOS` in @crosscode/contracts. Fictional only.
|
||||
*/
|
||||
export * from "./churches";
|
||||
export * from "./people";
|
||||
export * from "./logo";
|
||||
@@ -0,0 +1,47 @@
|
||||
import { FONT_PAIRINGS, type agent } from "@crosscode/contracts";
|
||||
import { demoChurch, type DemoMark } from "./churches";
|
||||
|
||||
/**
|
||||
* Each demo church's logo and icon, drawn for the demo (never a real church's): a simple mark in
|
||||
* white on the church's colour, and the mark beside the church's name. SVG, so they're crisp at
|
||||
* any size; Accounts serves them (`/api/demo-assets/<scenario>/icon.svg`, `logo.svg`).
|
||||
*/
|
||||
|
||||
/** The marks, drawn in white on a 512 × 512 square. */
|
||||
const MARKS: Record<DemoMark, string> = {
|
||||
// A church window: a pointed arch with a sill.
|
||||
arch: '<path d="M176 400V236c0-56 36-100 80-124 44 24 80 68 80 124v164z" fill="none" stroke="#fff" stroke-width="28" stroke-linejoin="round"/><path d="M256 168v232M176 272h160" stroke="#fff" stroke-width="20"/>',
|
||||
cross: '<rect x="232" y="96" width="48" height="320" rx="6" fill="#fff"/><rect x="152" y="176" width="208" height="48" rx="6" fill="#fff"/>',
|
||||
flame: '<path d="M256 88c24 72 104 112 104 200a104 104 0 0 1-208 0c0-48 24-80 48-104 0 40 16 64 40 72-8-64 0-112 16-168z" fill="#fff"/>',
|
||||
wave: '<path d="M96 300c40-40 80-40 120 0s80 40 120 0 80-40 80 0M96 372c40-40 80-40 120 0s80 40 120 0 80-40 80 0" fill="none" stroke="#fff" stroke-width="28" stroke-linecap="round"/><path d="M256 108v120M216 148h80" stroke="#fff" stroke-width="24" stroke-linecap="round"/>',
|
||||
// An acacia: a flat crown on a thin trunk.
|
||||
tree: '<path d="M112 220c0-36 64-64 144-64s144 28 144 64-64 44-144 44-144-8-144-44z" fill="#fff"/><path d="M256 260v156M256 316l-56-52M256 300l52-40" stroke="#fff" stroke-width="22" stroke-linecap="round"/>',
|
||||
sun: '<circle cx="256" cy="300" r="72" fill="#fff"/><path d="M256 156v-48M156 204l-34-34M356 204l34-34M120 300H72M392 300h48" stroke="#fff" stroke-width="24" stroke-linecap="round"/><path d="M96 404h320" stroke="#fff" stroke-width="24" stroke-linecap="round"/>',
|
||||
// A compass point.
|
||||
north: '<path d="M256 88l88 296-88-56-88 56z" fill="#fff"/><circle cx="256" cy="420" r="16" fill="#fff"/>',
|
||||
// A river through three points (three campuses).
|
||||
river: '<path d="M120 120c120 40 40 140 136 168s48 112 136 104" fill="none" stroke="#fff" stroke-width="32" stroke-linecap="round"/><circle cx="148" cy="360" r="28" fill="#fff"/><circle cx="380" cy="160" r="28" fill="#fff"/><circle cx="256" cy="200" r="20" fill="#fff"/>',
|
||||
};
|
||||
|
||||
const escapeXml = (s: string) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
||||
|
||||
/** The square icon (app icon, favicon): the mark on the church's primary colour. */
|
||||
export function demoIconSvg(scenario: agent.DemoScenarioKey): string {
|
||||
const c = demoChurch(scenario);
|
||||
const radius = c.profile.style.corners === "sharp" ? 48 : c.profile.style.corners === "round" ? 160 : 96;
|
||||
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="512" height="512" role="img" aria-label="${escapeXml(c.profile.name)}"><rect width="512" height="512" rx="${radius}" fill="${c.profile.colours.primary}"/>${MARKS[c.mark]}</svg>`;
|
||||
}
|
||||
|
||||
/** The logo: the icon and the church's name in its heading font (a font stack, with a fallback). */
|
||||
export function demoLogoSvg(scenario: agent.DemoScenarioKey): string {
|
||||
const c = demoChurch(scenario);
|
||||
const pairing = FONT_PAIRINGS[c.profile.style.fontPairing];
|
||||
const font = `${pairing.heading.family}, ${pairing.heading.category === "serif" ? "Georgia, serif" : "Helvetica, Arial, sans-serif"}`;
|
||||
const name = c.profile.name;
|
||||
const size = name.length > 20 ? 64 : 76;
|
||||
const width = Math.round(240 + name.length * size * 0.56);
|
||||
const icon = demoIconSvg(scenario).replace(/^<svg[^>]*>/, "").replace(/<\/svg>$/, "");
|
||||
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} 200" width="${width}" height="200" role="img" aria-label="${escapeXml(name)}">`
|
||||
+ `<svg x="16" y="16" width="168" height="168" viewBox="0 0 512 512">${icon}</svg>`
|
||||
+ `<text x="208" y="${100 + size * 0.35}" font-family="${escapeXml(font)}" font-size="${size}" font-weight="700" fill="${c.profile.colours.primary}">${escapeXml(name)}</text></svg>`;
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
import { agent, DEMO_EMAIL_DOMAIN } from "@crosscode/contracts";
|
||||
import { demoChurch } from "./churches";
|
||||
|
||||
/**
|
||||
* Each scenario's people (APP-1.0-PLAN §12): a handful with parts to play in every product (the
|
||||
* pastor, the office, the prayer coordinator…) and members enough to put the App in the scenario's
|
||||
* active-member band. All at example.com (`DEMO_EMAIL_DOMAIN`, reserved: no real person has one), no
|
||||
* phone numbers, password `Demo@1234`. Ids are worked out from the email, so a person keeps the
|
||||
* same account (`sub`) every time a scenario is loaded, in every product.
|
||||
*/
|
||||
|
||||
export const DEMO_PASSWORD = "Demo@1234";
|
||||
|
||||
/** What someone does at the church; each product turns it into its own roles. */
|
||||
export const DEMO_PARTS = ["pastor", "office", "prayer-coordinator", "devotional-writer", "worship", "kids", "youth", "member"] as const;
|
||||
export type DemoPart = (typeof DEMO_PARTS)[number];
|
||||
|
||||
export interface DemoPerson {
|
||||
/** The account id (`sub`): the same on every load. */
|
||||
id: string;
|
||||
name: string;
|
||||
givenName: string;
|
||||
familyName: string;
|
||||
email: string;
|
||||
part: DemoPart;
|
||||
/** The campus they belong to (multi-campus scenarios), or null. */
|
||||
campus: string | null;
|
||||
}
|
||||
|
||||
type Lead = [part: DemoPart, given: string, family: string];
|
||||
|
||||
/** The people with parts, per scenario. */
|
||||
const LEADS: Record<agent.DemoScenarioKey, Lead[]> = {
|
||||
"heritage-parish": [["pastor", "Margaret", "Ashworth"], ["office", "Gillian", "Fortuin"], ["prayer-coordinator", "Desmond", "Botha"], ["devotional-writer", "Rosemary", "Kleinhans"], ["worship", "Edward", "Mbeki"], ["kids", "Joyce", "Petersen"]],
|
||||
"heritage-city": [["pastor", "Jonathan", "Hartley"], ["office", "Nomvula", "Dube"], ["prayer-coordinator", "Abigail", "Jacobs"], ["devotional-writer", "Samuel", "Okafor"], ["worship", "Clara", "Van Wyk"], ["kids", "Thembeka", "Mthembu"], ["youth", "Daniel", "Pillay"]],
|
||||
"bold-youth": [["pastor", "Kagiso", "Molefe"], ["office", "Zinhle", "Khumalo"], ["prayer-coordinator", "Liam", "Fourie"], ["devotional-writer", "Ayanda", "Ngcobo"], ["worship", "Jade", "Adams"], ["kids", "Precious", "Mokoena"], ["youth", "Tumi", "Sithole"]],
|
||||
"bold-plant": [["pastor", "Sipho", "Mahlangu"], ["office", "Megan", "Coetzee"], ["prayer-coordinator", "Lerato", "Mashaba"], ["devotional-writer", "Sipho", "Mahlangu"], ["worship", "Ruan", "Steyn"], ["kids", "Amahle", "Zulu"]],
|
||||
"community-family": [["pastor", "Thabo", "Nkosi"], ["office", "Linda", "Venter"], ["prayer-coordinator", "Lindiwe", "Mabaso"], ["devotional-writer", "Grace", "Naidoo"], ["worship", "Pieter", "Du Toit"], ["kids", "Naledi", "Radebe"], ["youth", "Johan", "Botes"]],
|
||||
"community-town": [["pastor", "Hendrik", "Lombard"], ["office", "Annatjie", "Smit"], ["prayer-coordinator", "Magda", "Vermeulen"], ["devotional-writer", "Hendrik", "Lombard"], ["worship", "Wilhelm", "Kruger"], ["kids", "Elize", "Nel"], ["youth", "Dewald", "Jansen"]],
|
||||
"clean-modern": [["pastor", "Michael", "Reddy"], ["office", "Sarah", "Govender"], ["prayer-coordinator", "Nandi", "Cele"], ["devotional-writer", "Chris", "Marais"], ["worship", "Kayla", "Moodley"], ["kids", "Bongani", "Shabalala"], ["youth", "Ethan", "Brink"]],
|
||||
"clean-campus": [["pastor", "David", "Le Roux"], ["office", "Palesa", "Mofokeng"], ["prayer-coordinator", "Hannah", "Swart"], ["devotional-writer", "Lwazi", "Mkhize"], ["worship", "Mia", "Engelbrecht"], ["kids", "Refilwe", "Tau"], ["youth", "Josh", "Pretorius"]],
|
||||
};
|
||||
|
||||
/** How many members each scenario has besides its leads: inside its App band (`appActiveMembers`). */
|
||||
const MEMBERS: Record<agent.DemoScenarioKey, number> = {
|
||||
"heritage-parish": 48, "heritage-city": 520, "bold-youth": 1180, "bold-plant": 64,
|
||||
"community-family": 210, "community-town": 160, "clean-modern": 610, "clean-campus": 2450,
|
||||
};
|
||||
|
||||
const GIVEN = ["Aisha", "Andile", "Anele", "Bianca", "Busisiwe", "Carel", "Charlotte", "Craig", "Dineo", "Elias", "Emma", "Fatima", "Francois", "Gugu", "Hlengiwe", "Imran", "Isabel", "Jabu", "Jacques", "Karabo", "Keegan", "Lebo", "Lize", "Lungile", "Marco", "Mpho", "Nadia", "Neo", "Nicole", "Olwethu", "Pumla", "Riaan", "Sanele", "Shaun", "Simone", "Tarryn", "Thandeka", "Unathi", "Vusi", "Zanele"];
|
||||
const FAMILY = ["Abrahams", "Bester", "Cloete", "Daniels", "Dlamini", "Erasmus", "February", "Gumede", "Hendricks", "Isaacs", "Joubert", "Kekana", "Lategan", "Maseko", "Moloi", "Ndlovu", "Ntuli", "Olivier", "Phiri", "Qwabe", "Roberts", "Snyman", "Tshabalala", "Uys", "Viljoen", "Williams", "Xaba", "Yende", "Zondo", "Van der Merwe"];
|
||||
|
||||
const slugOf = (s: string) => s.normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "");
|
||||
|
||||
/**
|
||||
* A UUID worked out from text (FNV-1a over 128 bits, shaped as version 5), so a demo person's id
|
||||
* is the same in every product and on every load, without Node's crypto (it runs in browsers too).
|
||||
*/
|
||||
export function demoId(text: string): string {
|
||||
let h = 0x6c62272e07bb014262b821756295c58dn;
|
||||
const prime = 0x0000000001000000000000000000013bn;
|
||||
const mask = (1n << 128n) - 1n;
|
||||
for (const byte of new TextEncoder().encode(`crosscode-demo:${text}`)) h = ((h ^ BigInt(byte)) * prime) & mask;
|
||||
const hex = h.toString(16).padStart(32, "0").split("");
|
||||
hex[12] = "5";
|
||||
hex[16] = ((parseInt(hex[16]!, 16) & 0x3) | 0x8).toString(16);
|
||||
const s = hex.join("");
|
||||
return `${s.slice(0, 8)}-${s.slice(8, 12)}-${s.slice(12, 16)}-${s.slice(16, 20)}-${s.slice(20)}`;
|
||||
}
|
||||
|
||||
function person(scenario: agent.DemoScenarioKey, part: DemoPart, givenName: string, familyName: string, email: string, campus: string | null): DemoPerson {
|
||||
return { id: demoId(`${scenario}:${email}`), name: `${givenName} ${familyName}`, givenName, familyName, email, part, campus };
|
||||
}
|
||||
|
||||
/** Everyone in a scenario: the leads first, then the members (deterministic: the same every time). */
|
||||
export function demoPeople(scenario: agent.DemoScenarioKey): DemoPerson[] {
|
||||
const church = demoChurch(scenario);
|
||||
const campuses = church.profile.campuses.map((c) => c.slug);
|
||||
const campusFor = (n: number) => (campuses.length ? campuses[n % campuses.length]! : null);
|
||||
const seen = new Set<string>();
|
||||
const out: DemoPerson[] = [];
|
||||
LEADS[scenario].forEach(([part, given, family], n) => {
|
||||
const email = `${slugOf(given)}.${slugOf(family)}.${church.slug}@${DEMO_EMAIL_DOMAIN}`;
|
||||
// One person can have two parts (the pastor who writes the devotionals): one account.
|
||||
const existing = out.find((p) => p.email === email);
|
||||
if (existing) return;
|
||||
seen.add(email);
|
||||
out.push(person(scenario, part, given, family, email, campusFor(n)));
|
||||
});
|
||||
for (let n = 0; n < MEMBERS[scenario]; n++) {
|
||||
const given = GIVEN[n % GIVEN.length]!;
|
||||
const family = FAMILY[Math.floor(n / GIVEN.length) % FAMILY.length]!;
|
||||
const email = `${slugOf(given)}.${slugOf(family)}.${n + 1}.${church.slug}@${DEMO_EMAIL_DOMAIN}`;
|
||||
if (seen.has(email)) continue;
|
||||
seen.add(email);
|
||||
out.push(person(scenario, "member", given, family, email, campusFor(n)));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** The parts each lead plays (a person may have two: the pastor who writes the devotionals). */
|
||||
export function demoParts(scenario: agent.DemoScenarioKey): Map<string, DemoPart[]> {
|
||||
const church = demoChurch(scenario);
|
||||
const parts = new Map<string, DemoPart[]>();
|
||||
for (const [part, given, family] of LEADS[scenario]) {
|
||||
const email = `${slugOf(given)}.${slugOf(family)}.${church.slug}@${DEMO_EMAIL_DOMAIN}`;
|
||||
parts.set(email, [...(parts.get(email) ?? []), part]);
|
||||
}
|
||||
return parts;
|
||||
}
|
||||
|
||||
/** Whether an address belongs to a demo person (any scenario). */
|
||||
export const isDemoAddress = (email: string) => email.toLowerCase().endsWith(`@${DEMO_EMAIL_DOMAIN}`);
|
||||
|
||||
/** The scenarios in the contracts' order. */
|
||||
export const DEMO_SCENARIO_KEYS = agent.DEMO_SCENARIO_KEYS;
|
||||
Reference in New Issue
Block a user