diff --git a/CHANGELOG.md b/CHANGELOG.md index e7d7ee7..4d4b44b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,24 @@ versions follow [Semantic Versioning](https://semver.org/). ## [Unreleased] +## [2.5.0] - unreleased + +For Cross Events 3.0 (crosscode-platform `docs/EVENTS-3.0-PLAN.md` §9), which signs in through the +church's Accounts. Contracts 1.8.0 (`backend/vendor/`). + +### Added + +- **New install meets the release's requirements.** A release that needs Accounts ("— requires + accounts 1.1.0" in its notes, as Cross Events 3.0) installs the church's Accounts first when it + has none: two installs in one batch, Accounts (an `install` job, or `add-product` next to the + church's other products) and then the product (`add-product`), which only runs once Accounts + succeeded. If Accounts fails, the product's record fails and its ports are freed. Accounts goes + on `accounts.` (`events.grace.co.za` → `accounts.grace.co.za`) unless the + form's new **Accounts domain** says otherwise. A church whose Accounts is older than required is + refused ("Update its Accounts first"), as is a release no Accounts release is new enough for. + Cross Events 3.0 connects itself to the church's Accounts once both are listed, so no one has to + press Connect. + ## [2.4.0] - 2026-11-19 ### Added diff --git a/backend/package-lock.json b/backend/package-lock.json index e248c1e..ea0ccb9 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -1,16 +1,16 @@ { "name": "events-hub-backend", - "version": "2.4.0", + "version": "2.5.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "events-hub-backend", - "version": "2.4.0", + "version": "2.5.0", "hasInstallScript": true, "dependencies": { "@anthropic-ai/sdk": "^1.3.0", - "@crosscode/contracts": "file:vendor/crosscode-contracts-1.7.0.tgz", + "@crosscode/contracts": "file:vendor/crosscode-contracts-1.8.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.7.0", - "resolved": "file:vendor/crosscode-contracts-1.7.0.tgz", - "integrity": "sha512-s/c7s6nMhsBnnePV8PN4HBvx8Hg4bSA/OpHtJF5musTPixpNjP4XG8xGAwYtHtyRjGrT5zdgpRppattbqhEJeg==", + "version": "1.8.0", + "resolved": "file:vendor/crosscode-contracts-1.8.0.tgz", + "integrity": "sha512-V/yoNYh7u2wemUeigEfAPkoJ3MSJxtp/57AtFXkUc1tSXQljLXI/I6wZ30inamKR9gfK23JCohoTIz1ncBGl+Q==", "license": "UNLICENSED", "dependencies": { "zod": "^4.6.7" diff --git a/backend/package.json b/backend/package.json index f06d46d..13ea089 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "events-hub-backend", - "version": "2.4.0", + "version": "2.5.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.7.0.tgz", + "@crosscode/contracts": "file:vendor/crosscode-contracts-1.8.0.tgz", "@prisma/adapter-pg": "^7.10.1", "@prisma/client": "^7.10.1", "bcryptjs": "^2.4.3", diff --git a/backend/src/utils/jobs.js b/backend/src/utils/jobs.js index dffc13b..eac9799 100644 --- a/backend/src/utils/jobs.js +++ b/backend/src/utils/jobs.js @@ -232,6 +232,11 @@ async function advanceBatch(job, now) { if (j.deployment && j.type === 'uninstall') { await prisma.deployment.update({ where: { id: j.deployment.id }, data: { status: statusBeforeUninstall(j.deployment) } }); } + // Hub 2.5.0: the product after a failed Accounts install never ran: its record fails and its ports are freed. + if (j.deployment && (j.type === 'install' || j.type === 'add-product')) { + await prisma.deployment.update({ where: { id: j.deployment.id }, data: { status: 'failed' } }); + await prisma.port.deleteMany({ where: { port: { in: [j.deployment.webPort, j.deployment.apiPort] } } }); + } if (j.deployment && j.scheduled && j.type === 'deploy') { await emailSiteAdmin(j.deployment, `${PRODUCT_NAMES[j.deployment.product]} update postponed`, `The planned update of ${PRODUCT_NAMES[j.deployment.product]} at ${j.deployment.domain} has been postponed. Your site keeps running as it is; we'll let you know the new time.`); } @@ -423,7 +428,11 @@ async function newInstall(input, admin, now = new Date()) { if (siblings.some(s => s.customerId !== customer.id)) throw fail(409, 'SHORT_NAME_TAKEN', `The short name ${shortName} is already used by another customer.`); if (siblings.some(s => s.serverId !== server.id)) throw fail(409, 'OTHER_SERVER', `${shortName}'s other products are on another server; a church's products go on one server.`); if (siblings.some(s => s.status !== 'live' && s.status !== 'waiting_for_proxy')) throw fail(409, 'BUSY', `Wait until ${shortName}'s other install has finished.`); - const add = siblings.length > 0; + // Hub 2.5.0: a release that needs a sibling (Cross Events 3.0: "— requires accounts 1.1.0") gets + // it. A church without Accounts has it installed first, in the same batch; one with an older + // Accounts is refused until it's updated. + const first = await requiredFirst({ release, product, siblings, input, domain, server, now }); + const add = siblings.length > 0 || !!first; // The name is free again after a failed install (its ports were already freed) or an uninstall. // A failed install's record goes; a removed one keeps its history under another name (the // database allows one install per short name and product). Found in the VM test. @@ -435,18 +444,39 @@ async function newInstall(input, admin, now = new Date()) { const dnsOk = await dnsPointsAtCentral(domain); if (dnsOk === false) warnings.push(`${domain} doesn't point at the central server yet (the install still runs).`); + if (first) { + const dnsFirst = await dnsPointsAtCentral(first.domain); + if (dnsFirst === false) warnings.push(`${first.domain} doesn't point at the central server yet (the install still runs).`); + } + const deployment = await prisma.$transaction(async tx => { - let licence = await tx.licence.findFirst({ where: { customerId: customer.id, product, status: { not: 'revoked' } }, include: { install: true } }); - if (licence?.install && !licence.install.releasedAt) throw fail(409, 'LICENCE_IN_USE', `${customer.name}'s ${PRODUCT_NAMES[product]} licence is already used by ${licence.install.url}.`); - if (!licence) licence = (await generateLicence(tx, { customerId: customer.id, product, now })).licence; - const ports = await servers.allocatePorts(tx, server.id, now); - const d = await tx.deployment.create({ - data: { serverId: server.id, customerId: customer.id, licenceId: licence.id, product, shortName, domain, webPort: ports.web, apiPort: ports.api, timezone: input.timezone || null, adminName: input.adminName || null, adminEmail: adminEmail || null, status: 'installing' }, - }); - await tx.port.updateMany({ where: { port: { in: [ports.web, ports.api] } }, data: { deploymentId: d.id } }); + const make = async (p, dom) => { + let licence = await tx.licence.findFirst({ where: { customerId: customer.id, product: p, status: { not: 'revoked' } }, include: { install: true } }); + if (licence?.install && !licence.install.releasedAt) throw fail(409, 'LICENCE_IN_USE', `${customer.name}'s ${PRODUCT_NAMES[p]} licence is already used by ${licence.install.url}.`); + if (!licence) licence = (await generateLicence(tx, { customerId: customer.id, product: p, now })).licence; + const ports = await servers.allocatePorts(tx, server.id, now); + const d = await tx.deployment.create({ + data: { serverId: server.id, customerId: customer.id, licenceId: licence.id, product: p, shortName, domain: dom, webPort: ports.web, apiPort: ports.api, timezone: input.timezone || null, adminName: input.adminName || null, adminEmail: adminEmail || null, status: 'installing' }, + }); + await tx.port.updateMany({ where: { port: { in: [ports.web, ports.api] } }, data: { deploymentId: d.id } }); + return { d, ports }; + }; + // Accounts first (an install job), then the product next to it once that succeeded (a batch). + const batchId = first ? servers.newId('batch') : null; + if (first) { + const a = await make('accounts', first.domain); + await makeJob(tx, { + serverId: server.id, type: siblings.length ? 'add-product' : 'install', deploymentId: a.d.id, createdById: admin?.id || null, notBefore: now, batchId, batchOrder: 0, + args: siblings.length + ? { church: shortName, product: 'accounts', version: `accounts@${first.release.version}`, domain: first.domain, ports: a.ports } + : { church: shortName, products: ['accounts'], versions: { accounts: `accounts@${first.release.version}` }, domains: { accounts: first.domain }, ports: { accounts: a.ports } }, + }); + } + const { d, ports } = await make(product, domain); await makeJob(tx, add ? { serverId: server.id, type: 'add-product', deploymentId: d.id, createdById: admin?.id || null, notBefore: now, + ...(batchId ? { batchId, batchOrder: 1, status: 'scheduled' } : {}), args: { church: shortName, product, version: `${product}@${release.version}`, domain, ports }, } : { @@ -455,7 +485,39 @@ async function newInstall(input, admin, now = new Date()) { }); return d; }); - return { deployment, warnings }; + return { deployment, warnings, ...(first ? { alsoInstalling: { product: 'accounts', domain: first.domain, version: first.release.version } } : {}) }; +} + +/** `events.hope.co.za` → `accounts.hope.co.za`: the first label swapped (ROADMAP-v3 decision 6). */ +function accountsDomainFor(domain) { + const parts = domain.split('.'); + return parts.length > 2 ? ['accounts', ...parts.slice(1)].join('.') : `accounts.${domain}`; +} + +/** + * What a release needs installed first (Hub 2.5.0): its required Accounts, when the church has none. + * Null when nothing is needed; refused when the church's Accounts is older than required, or no + * Accounts release is new enough. + */ +async function requiredFirst({ release, product, siblings, input, domain, server, now }) { + if (product === 'accounts') return null; + const need = (Array.isArray(release.requires) ? release.requires : []).find(q => q && q.product === 'accounts'); + if (!need) return null; + const have = siblings.find(s => s.product === 'accounts'); + if (have) { + if (have.version && compareVersions(have.version, need.version) < 0) { + throw fail(409, 'REQUIREMENT_NOT_MET', `${PRODUCT_NAMES[product]} ${release.version} needs Accounts ${need.version} or later; this church has ${have.version}. Update its Accounts first.`); + } + return null; + } + const accountsRelease = await releaseFor('accounts', null); + if (compareVersions(accountsRelease.version, need.version) < 0) { + throw fail(409, 'REQUIREMENT_NOT_MET', `${PRODUCT_NAMES[product]} ${release.version} needs Accounts ${need.version}; the newest Accounts release is ${accountsRelease.version}.`); + } + const accountsDomain = String(input.accountsDomain || accountsDomainFor(domain)).trim().toLowerCase(); + if (!DOMAIN.test(accountsDomain) || accountsDomain === domain) throw fail(400, 'BAD_REQUEST', 'Give Accounts its own domain, like accounts.hope.co.za.'); + await preflight(server, 'accounts', accountsRelease.version, now); + return { release: accountsRelease, domain: accountsDomain }; } /** Proxy done (§7.8): check the public addresses, then Live and the welcome email. */ diff --git a/backend/tests/servers.test.js b/backend/tests/servers.test.js index c0a6662..f073b5f 100644 --- a/backend/tests/servers.test.js +++ b/backend/tests/servers.test.js @@ -397,6 +397,69 @@ describe('Accounts from the Hub (2.3.0)', () => { }); }); +describe('Cross Events 3.0 brings its Accounts (2.5.0)', () => { + const poll = (server) => jobs.poll(server, { agentApiVersion: 1, agentVersion: '1.1.0', mode: 'church', runningJobId: null }, NOW); + beforeEach(async () => { + await db.release.create({ data: { id: 'r3', product: 'events', version: '3.0.0', notes: '- Sign-in through Accounts', requires: [{ product: 'accounts', version: '1.1.0' }], releasedAt: NOW } }); + await db.release.create({ data: { id: 'ra1', product: 'accounts', version: '1.0.0', notes: '- First release', releasedAt: NOW } }); + await db.release.create({ data: { id: 'ra2', product: 'accounts', version: '1.1.0', notes: '- For Events 3.0', releasedAt: NOW } }); + }); + + test('a new church gets Accounts installed first, then Events next to it once that succeeded', async () => { + const { server } = await joinServer(); + await servers.setServerConfig(server.id, { TRUST_PROXY: 'loopback' }); + const out = await jobs.newInstall({ customerId: 'cust-1', serverId: server.id, shortName: 'grace', domain: 'events.grace.co.za' }, admin, NOW); + expect(out.alsoInstalling).toEqual({ product: 'accounts', domain: 'accounts.grace.co.za', version: '1.1.0' }); + const accounts = await db.deployment.findFirst({ where: { shortName: 'grace', product: 'accounts' } }); + expect(accounts).toMatchObject({ status: 'installing', domain: 'accounts.grace.co.za' }); + // Only Accounts runs now. + const [first] = (await poll(server)).jobs; + expect(first).toMatchObject({ type: 'install', args: { products: ['accounts'], versions: { accounts: 'accounts@1.1.0' } } }); + expect(signing.openConfig(first.config, keys.x.privateKeyPem).install.accounts.HUB_LICENCE_KEY).toMatch(/^CCA-/); + expect((await poll(server)).jobs).toEqual([]); + await jobs.receiveReport(server, signedReport(first, 'succeeded', { result: { versions: { accounts: 'accounts@1.1.0' } } }), NOW); + // Then Events, added next to it. + const [second] = (await poll(server)).jobs; + expect(second).toMatchObject({ type: 'add-product', args: { church: 'grace', product: 'events', version: 'events@3.0.0', domain: 'events.grace.co.za' } }); + expect(agent.agentJobSchema.safeParse(second).success).toBe(true); + }); + + test('when Accounts fails, Events never runs and its ports are freed', async () => { + const { server } = await joinServer(); + await servers.setServerConfig(server.id, { TRUST_PROXY: 'loopback' }); + const out = await jobs.newInstall({ customerId: 'cust-1', serverId: server.id, shortName: 'grace', domain: 'events.grace.co.za', accountsDomain: 'login.grace.co.za' }, admin, NOW); + expect(out.alsoInstalling.domain).toBe('login.grace.co.za'); + const [first] = (await poll(server)).jobs; + await jobs.receiveReport(server, signedReport(first, 'failed'), NOW); + expect(await db.deployment.findUnique({ where: { id: out.deployment.id } })).toMatchObject({ status: 'failed' }); + expect(await db.port.findMany({ where: { port: { in: [out.deployment.webPort, out.deployment.apiPort] } } })).toEqual([]); + expect((await poll(server)).jobs).toEqual([]); + }); + + test("a church whose Accounts is older than Events 3.0 needs is refused; a new enough one isn't installed again", async () => { + const { server } = await joinServer(); + await servers.setServerConfig(server.id, { TRUST_PROXY: 'loopback' }); + const a = await jobs.newInstall({ product: 'accounts', customerId: 'cust-1', serverId: server.id, shortName: 'hope', domain: 'accounts.hope.co.za', version: '1.0.0' }, admin, NOW); + await db.deployment.update({ where: { id: a.deployment.id }, data: { status: 'live', version: '1.0.0' } }); + await db.job.updateMany({ where: { deploymentId: a.deployment.id }, data: { status: 'succeeded' } }); + await expect(jobs.newInstall({ customerId: 'cust-1', serverId: server.id, shortName: 'hope', domain: 'events.hope.co.za' }, admin, NOW)).rejects.toMatchObject({ code: 'REQUIREMENT_NOT_MET' }); + await db.deployment.update({ where: { id: a.deployment.id }, data: { version: '1.1.0' } }); + const out = await jobs.newInstall({ customerId: 'cust-1', serverId: server.id, shortName: 'hope', domain: 'events.hope.co.za' }, admin, NOW); + expect(out.alsoInstalling).toBeUndefined(); + const [job] = (await poll(server)).jobs; + expect(job).toMatchObject({ type: 'add-product', args: { product: 'events', version: 'events@3.0.0' } }); + }); + + test('Events 2.x installs as before, without Accounts', async () => { + const { server } = await joinServer(); + await servers.setServerConfig(server.id, { TRUST_PROXY: 'loopback' }); + const out = await jobs.newInstall({ customerId: 'cust-1', serverId: server.id, shortName: 'old', domain: 'events.old.co.za', version: '2.4.0' }, admin, NOW); + expect(out.alsoInstalling).toBeUndefined(); + expect(await db.deployment.findFirst({ where: { shortName: 'old', product: 'accounts' } })).toBeNull(); + }); +}); + + describe('settings for servers (found in the VM test)', () => { test('install defaults, the port range and the central IP are saved', async () => { const { setSettings } = require('../src/utils/settings'); diff --git a/backend/vendor/crosscode-contracts-1.7.0.tgz b/backend/vendor/crosscode-contracts-1.7.0.tgz deleted file mode 100644 index cfeb210..0000000 Binary files a/backend/vendor/crosscode-contracts-1.7.0.tgz and /dev/null differ diff --git a/backend/vendor/crosscode-contracts-1.8.0.tgz b/backend/vendor/crosscode-contracts-1.8.0.tgz new file mode 100644 index 0000000..b47486d Binary files /dev/null and b/backend/vendor/crosscode-contracts-1.8.0.tgz differ diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 031c9fc..d9776c8 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -1,12 +1,12 @@ { "name": "events-hub-frontend", - "version": "2.4.0", + "version": "2.5.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "events-hub-frontend", - "version": "2.4.0", + "version": "2.5.0", "dependencies": { "lucide-react": "^0.536.0", "next": "^15.5.24", diff --git a/frontend/package.json b/frontend/package.json index 949775e..adf248c 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,6 +1,6 @@ { "name": "events-hub-frontend", - "version": "2.4.0", + "version": "2.5.0", "private": true, "scripts": { "dev": "next dev -p 3200", diff --git a/frontend/src/app/(hub)/servers/installs/page.tsx b/frontend/src/app/(hub)/servers/installs/page.tsx index c3d3da9..e71c0ad 100644 --- a/frontend/src/app/(hub)/servers/installs/page.tsx +++ b/frontend/src/app/(hub)/servers/installs/page.tsx @@ -13,7 +13,7 @@ type Msg = { type: "ok" | "err"; text: string } | null; type Customer = { id: string; name: string; domain?: string | null }; type InstallRow = { id: string; name: string; url: string; customer: { id: string; name: string } | null; version: string | null }; -const emptyNew = { product: "events", customerId: "", serverId: "", shortName: "", domain: "", timezone: "", adminName: "", adminEmail: "", version: "" }; +const emptyNew = { product: "events", customerId: "", serverId: "", shortName: "", domain: "", accountsDomain: "", timezone: "", adminName: "", adminEmail: "", version: "" }; const emptyLink = { installId: "", serverId: "", shortName: "", webPort: "", apiPort: "" }; /** Installs on servers: New install (§7) and linking existing installs (§14). */ @@ -44,8 +44,10 @@ export default function InstallsPage() { setBusy(true); setMsg(null); try { - const r = await api<{ deployment: Deployment; warnings: string[] }>("/api/admin/deployments", { method: "POST", body: { ...form, version: form.version || undefined } }); - router.push(`/servers/installs/${r.deployment.id}${r.warnings.length ? `?warn=${encodeURIComponent(r.warnings.join(" "))}` : ""}`); + const r = await api<{ deployment: Deployment; warnings: string[]; alsoInstalling?: { product: string; domain: string; version: string } }>("/api/admin/deployments", { method: "POST", body: { ...form, version: form.version || undefined, accountsDomain: form.accountsDomain || undefined } }); + // Hub 2.5.0: Cross Events 3.x for a church without Accounts installs Accounts first. + const notes = [...(r.alsoInstalling ? [`Accounts ${r.alsoInstalling.version} is installed first at ${r.alsoInstalling.domain}; Cross Events follows when it has finished.`] : []), ...r.warnings]; + router.push(`/servers/installs/${r.deployment.id}${notes.length ? `?warn=${encodeURIComponent(notes.join(" "))}` : ""}`); } catch (err) { setMsg({ type: "err", text: errorText(err) }); } setBusy(false); }; @@ -87,6 +89,9 @@ export default function InstallsPage() {

Folders, database and tunnels: a-z, 0-9 and -.

+ {form.product === "events" && ( +

Cross Events 3 signs in through the church's Accounts: a church without it gets it installed first, here.

+ )}

Gets the welcome email and update notices.