Hub 2.0 step 3: releases per product, with requirements
- Release.product and requires; unique (product, version); latest version per product (latest_version stays Cross Events' latest) - Release sources per product (Releases page): repository, tag prefix, notes file. Defaults: every product from crosscode-platform plus Cross Events' v1.2.3 tags from hope-events. A product's releases are only removed when all its sources were read and found tags - "— requires accounts 1.2.0" in a notes heading: Request update answers 409 REQUIREMENT_NOT_MET until the church's install of that product is new enough; install page and Releases page show it; v2 replies carry requires - @crosscode/contracts 1.1.0 vendored (optional requires on releases) - Alerts, dashboard and install lists compare against each product's latest Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -18,7 +18,7 @@ const { getSettings } = require('../utils/settings');
|
||||
const { compareVersions } = require('../utils/alerts');
|
||||
const { requestMessage, requestedVersionOf, isOutdated } = require('../utils/updateRequests');
|
||||
const { sendMail } = require('../utils/mail');
|
||||
const { releasesForInstall } = require('../utils/releases');
|
||||
const { releasesForInstall, latestVersions, unmetRequirementsFor, requirementMessage } = require('../utils/releases');
|
||||
const { noticesForInstall } = require('../utils/notices');
|
||||
const ai = require('../utils/ai');
|
||||
const { PRODUCT_NAMES } = require('../utils/products');
|
||||
@@ -55,12 +55,12 @@ function cleanUrl(url) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases and the latest version are Cross Events' until releases per product (Hub 2.0 step 3):
|
||||
* other products are told nothing rather than Events versions.
|
||||
* The install's product's latest version and the releases newer than `version` (Hub 2.0: per
|
||||
* product). v2 replies carry each release's requirements; v1 replies are as before.
|
||||
*/
|
||||
async function releaseInfo(install, version, settings) {
|
||||
if (install.product !== 'events') return { latestVersion: null, releases: [] };
|
||||
return { latestVersion: settings.latest_version || null, releases: await releasesForInstall(version) };
|
||||
async function releaseInfo(install, version, { v2 = false } = {}) {
|
||||
const latest = (await latestVersions())[install.product] || null;
|
||||
return { latestVersion: latest, releases: await releasesForInstall(install.product, version, { withRequires: v2 }) };
|
||||
}
|
||||
|
||||
async function tokenFor(install) {
|
||||
@@ -152,13 +152,12 @@ router.post('/installs/register', registerLimiter, async (req, res) => {
|
||||
: await prisma.install.create({ data: { ...data, product: licence.product, customerId: licence.customerId, licenceId: licence.id } });
|
||||
await prisma.installEvent.create({ data: { installId: install.id, type: 'registered', level: 'info', message: `${licence.install ? 'Re-registered' : 'Registered'} from ${url} (version ${install.version || '?'})`, resolvedAt: new Date() } });
|
||||
|
||||
const settings = await getSettings();
|
||||
res.status(201).json({
|
||||
installId: install.id,
|
||||
installSecret: secret,
|
||||
licence: await tokenFor(install),
|
||||
heartbeatIntervalMinutes: HEARTBEAT_MINUTES,
|
||||
...(await releaseInfo(install, install.version, settings)),
|
||||
...(await releaseInfo(install, install.version, { v2 })),
|
||||
notices: await noticesForInstall(install.id),
|
||||
...(v2 ? { linkedProducts: await linkedProductsFor(install) } : {}),
|
||||
});
|
||||
@@ -193,10 +192,9 @@ router.post('/installs/heartbeat', heartbeatLimiter, async (req, res) => {
|
||||
}
|
||||
}
|
||||
|
||||
const settings = await getSettings();
|
||||
res.json({
|
||||
licence: await tokenFor(install),
|
||||
...(await releaseInfo(install, version || install.version, settings)),
|
||||
...(await releaseInfo(install, version || install.version, { v2 })),
|
||||
notices: await noticesForInstall(install.id, now),
|
||||
...(v2 ? { linkedProducts: await linkedProductsFor(install) } : {}),
|
||||
serverTime: now.toISOString(),
|
||||
@@ -217,11 +215,16 @@ router.post('/installs/update-request', updateRequestLimiter, async (req, res) =
|
||||
if (!body) return;
|
||||
|
||||
const settings = await getSettings();
|
||||
const latest = (await releaseInfo(install, null, settings)).latestVersion;
|
||||
const latest = (await latestVersions())[install.product] || null;
|
||||
const current = str(body.version, 40) || install.version;
|
||||
if (!latest || compareVersions(current, latest) >= 0) {
|
||||
return fail(res, 409, 'UP_TO_DATE', 'This site already runs the latest version.');
|
||||
}
|
||||
// Hub 2.0: the update may need the church's other products updated first.
|
||||
const unmet = await unmetRequirementsFor({ ...install, version: current }, latest);
|
||||
if (unmet.length) {
|
||||
return res.status(409).json({ code: 'REQUIREMENT_NOT_MET', message: `This update needs another product first. ${requirementMessage(unmet)}`, requirements: unmet });
|
||||
}
|
||||
|
||||
const customerName = async () => (await prisma.customer.findUnique({ where: { id: install.customerId }, select: { name: true } }))?.name || install.name;
|
||||
const link = `${(process.env.FRONTEND_URL || '').replace(/\/$/, '')}/installs/${install.id}`;
|
||||
|
||||
Reference in New Issue
Block a user