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; /** 1.1.0: for products that seat or group people (Cross Events' men's breakfast, camp cabins). */ gender: "female" | "male"; /** 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 = { "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 = { "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"]; /** The given names that are women's; every other given name here is a man's. */ const FEMALE = new Set([ "Margaret", "Gillian", "Rosemary", "Joyce", "Nomvula", "Abigail", "Clara", "Thembeka", "Zinhle", "Ayanda", "Jade", "Precious", "Tumi", "Megan", "Lerato", "Amahle", "Linda", "Lindiwe", "Grace", "Naledi", "Annatjie", "Magda", "Elize", "Sarah", "Nandi", "Kayla", "Palesa", "Hannah", "Mia", "Refilwe", "Aisha", "Anele", "Bianca", "Busisiwe", "Charlotte", "Dineo", "Emma", "Fatima", "Gugu", "Hlengiwe", "Isabel", "Karabo", "Lebo", "Lize", "Lungile", "Mpho", "Nadia", "Nicole", "Olwethu", "Pumla", "Simone", "Tarryn", "Thandeka", "Unathi", "Zanele", ]); const genderOf = (given: string): "female" | "male" => (FEMALE.has(given) ? "female" : "male"); 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, gender: genderOf(givenName), 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(); 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 { const church = demoChurch(scenario); const parts = new Map(); 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;