Hub 2.4.0: demo sites, and demo data loaded from the Hub

Mark a Cross Events install as a demo site, then load a demo set (small,
events, ministry, multicampus) with a seed-demo job (agent 1.2.0+,
crosscode demo: backup, demo data, restart). Typing the short name for both.
Deployment.isDemo (migration), contracts 1.7.0 vendored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 10:41:03 +02:00
co-authored by Claude Opus 5.5
parent 36987a9b69
commit dbfa4116c4
15 changed files with 149 additions and 14 deletions
+14
View File
@@ -5,6 +5,20 @@ versions follow [Semantic Versioning](https://semver.org/).
## [Unreleased]
## [2.4.0] - 2026-11-19
### Added
- **Demo sites.** On a Cross Events install's page: **Mark as a demo site** (typing its short
name), then **Load demo data** with a choice of demo (small church, events and conferences,
weekly ministry, three campuses), typing the short name again. It queues a `seed-demo` job:
the agent runs `crosscode demo`, which takes a backup, replaces the data (keeping the site
settings and the install's admin) and restarts the site. You're emailed the result. Refused for
sites not marked as demo, and for agents before 1.2.0 (`AGENT_TOO_OLD`). Demo sites show a
"demo" tag in the installs list. Audit log: `install_marked_demo`, `install_unmarked_demo`,
`demo_seed_queued`.
- Migration `20261119140000_deployment_demo` (`Deployment.isDemo`). `@crosscode/contracts` 1.7.0.
## [2.3.3] - 2026-11-19
### Fixed
+6 -6
View File
@@ -1,16 +1,16 @@
{
"name": "events-hub-backend",
"version": "2.3.3",
"version": "2.4.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "events-hub-backend",
"version": "2.3.3",
"version": "2.4.0",
"hasInstallScript": true,
"dependencies": {
"@anthropic-ai/sdk": "^1.3.0",
"@crosscode/contracts": "file:vendor/crosscode-contracts-1.6.0.tgz",
"@crosscode/contracts": "file:vendor/crosscode-contracts-1.7.0.tgz",
"@prisma/adapter-pg": "^7.10.1",
"@prisma/client": "^7.10.1",
"bcryptjs": "^2.4.3",
@@ -609,9 +609,9 @@
"license": "MIT"
},
"node_modules/@crosscode/contracts": {
"version": "1.6.0",
"resolved": "file:vendor/crosscode-contracts-1.6.0.tgz",
"integrity": "sha512-uAgoeo0eVUrQtklucztwXxRaawf33ITGqvob7i1C4BcgEkm4hIKbOHWp1qZxW3xT0vkZPfjoeLKtCHp8j1/rSg==",
"version": "1.7.0",
"resolved": "file:vendor/crosscode-contracts-1.7.0.tgz",
"integrity": "sha512-s/c7s6nMhsBnnePV8PN4HBvx8Hg4bSA/OpHtJF5musTPixpNjP4XG8xGAwYtHtyRjGrT5zdgpRppattbqhEJeg==",
"license": "UNLICENSED",
"dependencies": {
"zod": "^4.6.7"
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "events-hub-backend",
"version": "2.3.3",
"version": "2.4.0",
"private": true,
"description": "Cross Events Hub — API for managing Cross Events installs, licences and heartbeats",
"main": "src/index.js",
@@ -20,7 +20,7 @@
},
"dependencies": {
"@anthropic-ai/sdk": "^1.3.0",
"@crosscode/contracts": "file:vendor/crosscode-contracts-1.6.0.tgz",
"@crosscode/contracts": "file:vendor/crosscode-contracts-1.7.0.tgz",
"@prisma/adapter-pg": "^7.10.1",
"@prisma/client": "^7.10.1",
"bcryptjs": "^2.4.3",
@@ -0,0 +1,2 @@
-- Installs marked as demo sites: only these can have their data replaced with demo data.
ALTER TABLE "Deployment" ADD COLUMN "isDemo" BOOLEAN NOT NULL DEFAULT false;
+2
View File
@@ -574,6 +574,8 @@ model Deployment {
// The church's site admin, for the welcome and update emails.
adminName String?
adminEmail String?
// A demo site (2.4.0): only these can have their data replaced with demo data (seed-demo jobs).
isDemo Boolean @default(false)
status DeploymentStatus @default(installing)
// The release it runs (from reports and heartbeats).
version String?
+13
View File
@@ -187,6 +187,19 @@ router.post('/deployments/:id/adopt', wrap(async (req, res) => {
res.status(201).json({ job });
}));
// Demo sites (2.4.0): mark one, then replace its data with a demo set.
router.post('/deployments/:id/demo', wrap(async (req, res) => {
const d = await jobs.setDemo(req.params.id, { isDemo: req.body?.isDemo === true, confirm: req.body?.confirm });
await audit(req, d.isDemo ? 'install_marked_demo' : 'install_unmarked_demo', d.id, {});
res.json({ isDemo: d.isDemo });
}));
router.post('/deployments/:id/seed-demo', wrap(async (req, res) => {
const job = await jobs.seedDemo({ deploymentId: req.params.id, profile: req.body?.profile, confirm: req.body?.confirm }, req.admin);
await audit(req, 'demo_seed_queued', req.params.id, { job: job.id, profile: job.args.profile });
res.status(201).json({ job });
}));
router.post('/deployments/:id/uninstall', wrap(async (req, res) => {
const out = await jobs.scheduleUninstall({ deploymentId: req.params.id, at: req.body?.at, totp: req.body?.totp, confirm: req.body?.confirm }, req.admin);
await audit(req, 'uninstall_scheduled', req.params.id, { at: out.uninstallJob.notBefore });
+36 -1
View File
@@ -168,6 +168,10 @@ async function afterJob(job, { exportKey }, now) {
await emailJoshua(`${job.type === 'adopt' ? 'Adopt' : 'Update'} ${ok ? 'done' : job.status.replace('_', ' ')}: ${deployment.shortName}`, jobReportText(job));
break;
}
case 'seed-demo':
if (!deployment) break;
await emailJoshua(`Demo data ${ok ? `(${job.args.profile}) loaded` : job.status.replace('_', ' ')}: ${deployment.shortName}`, jobReportText(job));
break;
case 'export':
if (!deployment) break;
if (ok && exportKey) {
@@ -677,8 +681,39 @@ async function runNow({ serverId, type, args, deploymentId = null }, admin, now
return makeJob(prisma, { serverId, type, args, deploymentId, createdById: admin?.id || null, notBefore: now });
}
/** Mark or unmark an install as a demo site. Marking it asks for its short name, since a demo site's data can be replaced. */
async function setDemo(deploymentId, { isDemo, confirm }) {
const d = await prisma.deployment.findUnique({ where: { id: deploymentId } });
if (!d) throw fail(404, 'NOT_FOUND', 'Not found.');
if (d.product !== 'events') throw fail(400, 'NOT_EVENTS', 'Only Cross Events installs have demo data.');
if (isDemo && confirm !== d.shortName) throw fail(400, 'CONFIRM', `Type ${d.shortName} to mark it as a demo site.`);
return prisma.deployment.update({ where: { id: d.id }, data: { isDemo: !!isDemo } });
}
/**
* Replace a demo site's data with a demo set (`crosscode demo`, a backup is taken first). Only for
* installs marked as demo sites, typing the short name, on an agent that knows the job (1.2.0+).
*/
async function seedDemo({ deploymentId, profile, confirm }, admin, now = new Date()) {
const d = await prisma.deployment.findUnique({ where: { id: deploymentId }, include: { server: true } });
if (!d) throw fail(404, 'NOT_FOUND', 'Not found.');
if (!d.isDemo) throw fail(409, 'NOT_DEMO', `${d.shortName} isn't marked as a demo site.`);
if (d.product !== 'events') throw fail(400, 'NOT_EVENTS', 'Only Cross Events installs have demo data.');
if (!['live', 'waiting_for_proxy'].includes(d.status)) throw fail(409, 'NOT_LIVE', `It's ${d.status.replace(/_/g, ' ')}; demo data goes on an installed site.`);
if (confirm !== d.shortName) throw fail(400, 'CONFIRM', `Type ${d.shortName} to replace its data.`);
if (!agent.DEMO_PROFILES.includes(profile)) throw fail(400, 'BAD_REQUEST', `Choose one of: ${agent.DEMO_PROFILES.join(', ')}.`);
if (d.server.removedAt) throw fail(409, 'SERVER_REMOVED', 'That server was removed.');
if (compareVersions(d.server.agentVersion || '0.0.0', agent.SEED_DEMO_MIN_AGENT) < 0) {
throw fail(409, 'AGENT_TOO_OLD', `The agent on ${d.server.name} is ${d.server.agentVersion || 'an unknown version'}; demo data needs ${agent.SEED_DEMO_MIN_AGENT} or later (update the agent first).`);
}
const running = await prisma.job.findFirst({ where: { serverId: d.serverId, status: 'delivered' }, orderBy: { deliveredAt: 'desc' } });
if (!agentOnline(d.server, now, running)) throw fail(409, 'AGENT_OFFLINE', `The agent on ${d.server.name} isn't online.`);
const adminEmail = d.adminEmail && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(d.adminEmail) ? d.adminEmail.toLowerCase() : undefined;
return makeJob(prisma, { serverId: d.serverId, type: 'seed-demo', deploymentId: d.id, createdById: admin?.id || null, notBefore: now, args: { church: d.shortName, profile, ...(adminEmail ? { adminEmail } : {}) } });
}
module.exports = {
WINDOW_MIN, SCHEDULE_MIN_HOURS, EMERGENCY_MIN_MINUTES,
WINDOW_MIN, SCHEDULE_MIN_HOURS, EMERGENCY_MIN_MINUTES, setDemo, seedDemo,
makeJob, signedJob, jobConfig, poll, receiveReport, finish, tick, advanceBatch,
newInstall, proxyDone, scheduleUpdate, cancelJob, scheduleUninstall, neverInstalled, removeFailedInstall, receiveExport, linkDeployment, scheduleAdopt, queueCentralCheck, runNow,
fastPanelText, jobReportText, scheduleWarnings, requireTotp, agentOnline, siteAdminEmail,
+38
View File
@@ -455,3 +455,41 @@ describe('adopting an existing install', () => {
expect(job.args.address).toBe('hope.co.za');
});
});
describe('demo sites (2.4.0)', () => {
async function liveDemo({ agentVersion = '1.2.0', isDemo = true, adminEmail = 'Jane@Hope.test' } = {}) {
const { server } = await joinServer();
await db.server.update({ where: { id: server.id }, data: { agentVersion } });
const d = await db.deployment.create({ data: { id: 'dep-demo', serverId: server.id, customerId: 'cust-1', product: 'events', shortName: 'demo2', domain: 'events.demo2.test', webPort: 20000, apiPort: 20001, status: 'live', isDemo, adminEmail } });
return { server, d };
}
test('marking a site as demo asks for its short name; unmarking doesn\'t', async () => {
const { d } = await liveDemo({ isDemo: false });
await expect(jobs.setDemo(d.id, { isDemo: true, confirm: 'nope' })).rejects.toMatchObject({ code: 'CONFIRM' });
expect(await jobs.setDemo(d.id, { isDemo: true, confirm: 'demo2' })).toMatchObject({ isDemo: true });
expect(await jobs.setDemo(d.id, { isDemo: false })).toMatchObject({ isDemo: false });
});
test('a seed-demo job for a demo site: the profile, and its admin kept', async () => {
const { server, d } = await liveDemo();
const job = await jobs.seedDemo({ deploymentId: d.id, profile: 'ministry', confirm: 'demo2' }, admin, NOW);
expect(job).toMatchObject({ type: 'seed-demo', deploymentId: d.id, args: { church: 'demo2', profile: 'ministry', adminEmail: 'jane@hope.test' } });
const polled = await jobs.poll(server, { agentApiVersion: 1, agentVersion: '1.2.0', mode: 'church', runningJobId: null }, NOW);
expect(agent.agentJobSchema.safeParse(polled.jobs[0]).success).toBe(true);
expect(polled.jobs[0].config).toBeNull();
});
test('refused: not a demo site, wrong short name, unknown profile, an agent before 1.2.0', async () => {
let { d } = await liveDemo({ isDemo: false });
await expect(jobs.seedDemo({ deploymentId: d.id, profile: 'small', confirm: 'demo2' }, admin, NOW)).rejects.toMatchObject({ code: 'NOT_DEMO' });
await db.deployment.update({ where: { id: d.id }, data: { isDemo: true } });
await expect(jobs.seedDemo({ deploymentId: d.id, profile: 'small', confirm: 'demo' }, admin, NOW)).rejects.toMatchObject({ code: 'CONFIRM' });
await expect(jobs.seedDemo({ deploymentId: d.id, profile: 'everything', confirm: 'demo2' }, admin, NOW)).rejects.toMatchObject({ code: 'BAD_REQUEST' });
await seed();
({ d } = await liveDemo({ agentVersion: '1.1.1' }));
await expect(jobs.seedDemo({ deploymentId: d.id, profile: 'small', confirm: 'demo2' }, admin, NOW)).rejects.toMatchObject({ code: 'AGENT_TOO_OLD', message: expect.stringContaining('1.2.0') });
expect(await db.job.findMany({})).toEqual([]);
});
});
Binary file not shown.
Binary file not shown.
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "events-hub-frontend",
"version": "2.3.3",
"version": "2.4.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "events-hub-frontend",
"version": "2.3.3",
"version": "2.4.0",
"dependencies": {
"lucide-react": "^0.536.0",
"next": "^15.5.24",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "events-hub-frontend",
"version": "2.3.3",
"version": "2.4.0",
"private": true,
"scripts": {
"dev": "next dev -p 3200",
@@ -28,6 +28,7 @@ export default function DeploymentPage() {
const [upd, setUpd] = useState({ version: "", at: toInput(new Date(Date.now() + 5 * H)), emergency: false, reason: "", totp: "" });
const [adopt, setAdopt] = useState({ eventsDir: "", version: "", address: "", at: toInput(new Date(Date.now() + 5 * H)) });
const [un, setUn] = useState({ at: toInput(new Date(Date.now() + 7 * 24 * H)), totp: "", confirm: "" });
const [demo, setDemo] = useState({ profile: "events", confirm: "", markConfirm: "" });
const load = useCallback(() => api<Detail>(`/api/admin/deployments/${id}`).then(setD).catch(e => setMsg({ type: "err", text: errorText(e) })), [id]);
useEffect(() => { load(); }, [load]);
@@ -107,6 +108,36 @@ export default function DeploymentPage() {
</form>
)}
{x.product === "events" && ["live", "waiting_for_proxy"].includes(x.status) && (
<div className="card space-y-3">
<h2 className="font-medium">Demo site</h2>
{!x.isDemo ? (
<form className="grid gap-3 md:grid-cols-[1fr_auto] md:items-end" onSubmit={e => { e.preventDefault(); act(`/api/admin/deployments/${x.id}/demo`, { isDemo: true, confirm: demo.markConfirm }, "Marked as a demo site."); }}>
<p className="text-sm text-slate-500 md:col-span-2">A demo site&apos;s data can be replaced with demo data from here. Only mark sites used for showing Cross Events, never a church&apos;s real site.</p>
<div><label className="label" htmlFor="d-m">Type {x.shortName}</label><input id="d-m" className="input" value={demo.markConfirm} onChange={e => setDemo({ ...demo, markConfirm: e.target.value })} /></div>
<button className="btn-secondary" disabled={demo.markConfirm !== x.shortName}>Mark as a demo site</button>
</form>
) : (
<>
<form className="grid gap-3 md:grid-cols-3 md:items-end" onSubmit={e => { e.preventDefault(); if (window.confirm(`Replace ALL of ${x.shortName}'s data with the "${demo.profile}" demo? A backup is taken first; one admin account is kept.`)) act(`/api/admin/deployments/${x.id}/seed-demo`, { profile: demo.profile, confirm: demo.confirm }, "Queued: the agent loads the demo data on its next poll (see Jobs below). You get an email when it's done."); }}>
<p className="text-sm text-slate-500 md:col-span-3">Replaces everything (events, people, payments) with a demo set, keeping the site settings and {x.adminEmail || "the site's first admin"}. Demo logins use the password Demo@1234.</p>
<div><label className="label" htmlFor="d-p">Demo</label>
<select id="d-p" className="input" value={demo.profile} onChange={e => setDemo({ ...demo, profile: e.target.value })}>
<option value="small">Small church: the essentials</option>
<option value="events">Events and conferences</option>
<option value="ministry">Weekly ministry: courses, kids, volunteers</option>
<option value="multicampus">Three campuses</option>
</select>
</div>
<div><label className="label" htmlFor="d-c">Type {x.shortName}</label><input id="d-c" className="input" value={demo.confirm} onChange={e => setDemo({ ...demo, confirm: e.target.value })} /></div>
<button className="btn-danger" disabled={demo.confirm !== x.shortName}>Load demo data</button>
</form>
<button type="button" className="text-sm text-slate-500 underline" onClick={() => act(`/api/admin/deployments/${x.id}/demo`, { isDemo: false }, "No longer a demo site.")}>It isn&apos;t a demo site any more</button>
</>
)}
</div>
)}
<div className="card overflow-x-auto">
<h2 className="font-medium">Jobs</h2>
<table className="mt-3 w-full text-sm">
@@ -137,7 +137,7 @@ export default function InstallsPage() {
<table className="w-full text-sm">
<thead><tr className="text-left text-xs text-slate-500"><th className="py-1">Church</th><th>Domain</th><th>Server</th><th>Version</th><th>Last heartbeat</th><th>Status</th></tr></thead>
<tbody>{list.map(d => (
<tr key={d.id} className="border-t"><td className="py-1.5"><Link className="text-indigo-700 hover:underline" href={`/servers/installs/${d.id}`}>{d.customer?.name} ({d.shortName})</Link></td><td>{d.domain}</td><td>{d.server?.name}</td><td>{d.install?.version || d.version || "–"}</td><td>{ago(d.install?.lastHeartbeatAt)}</td><td><StatusPill status={d.status} /></td></tr>
<tr key={d.id} className="border-t"><td className="py-1.5"><Link className="text-indigo-700 hover:underline" href={`/servers/installs/${d.id}`}>{d.customer?.name} ({d.shortName})</Link>{d.isDemo && <span className="ml-1 rounded bg-sky-100 px-1.5 text-xs text-sky-800">demo</span>}</td><td>{d.domain}</td><td>{d.server?.name}</td><td>{d.install?.version || d.version || "–"}</td><td>{ago(d.install?.lastHeartbeatAt)}</td><td><StatusPill status={d.status} /></td></tr>
))}</tbody>
</table>
{!list.length && <p className="mt-2 text-sm text-slate-500">No installs on servers yet.</p>}
+1 -1
View File
@@ -21,7 +21,7 @@ export type ServerSummary = {
export type Deployment = {
id: string; serverId: string; customerId: string; installId: string | null; product: string; shortName: string; domain: string;
webPort: number; apiPort: number; status: string; version: string | null; adminName: string | null; adminEmail: string | null;
webPort: number; apiPort: number; status: string; version: string | null; adminName: string | null; adminEmail: string | null; isDemo?: boolean;
liveAt: string | null; createdAt: string;
server?: { id: string; name: string }; customer?: { id: string; name: string };
install?: { id: string; version: string | null; lastHeartbeatAt: string | null; url: string } | null;