Releases with what's new, notices to churches, withdrawn update requests

- Releases page: each Cross Events version with notes and an urgent flag; the
  newest is the latest version (moved off Settings; the old setting becomes the
  first release). Installs get the notes for every newer version.
- Notices page: a banner for site admins and supervisors (with a time window),
  an email to the customer and admin contact, or both; for every install or
  chosen ones.
- POST /api/installs/update-request/cancel resolves the request and emails Joshua.
- Protocol doc: releases and notices in the heartbeat/register replies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-28 08:54:35 +02:00
co-authored by Claude Opus 5.5
parent 26e12a199a
commit 1449e5046e
18 changed files with 900 additions and 12 deletions
+42 -2
View File
@@ -1,5 +1,6 @@
/**
* The API installs call (docs/hub-protocol.md): public key, register, heartbeat, update request.
* The API installs call (docs/hub-protocol.md): public key, register, heartbeat, update request
* (and withdrawing it).
* Install → Hub only; these are the only endpoints that aren't behind an admin login.
*/
@@ -12,6 +13,8 @@ const { checkSignature } = require('../utils/signing');
const { getSettings } = require('../utils/settings');
const { compareVersions } = require('../utils/alerts');
const { sendMail } = require('../utils/mail');
const { releasesForInstall } = require('../utils/releases');
const { noticesForInstall } = require('../utils/notices');
const router = express.Router();
@@ -114,6 +117,8 @@ router.post('/installs/register', registerLimiter, async (req, res) => {
licence: await tokenFor(install),
heartbeatIntervalMinutes: HEARTBEAT_MINUTES,
latestVersion: settings.latest_version || null,
releases: await releasesForInstall(install.version),
notices: await noticesForInstall(install.id),
});
} catch (e) {
console.error('[register]', e);
@@ -144,7 +149,13 @@ router.post('/installs/heartbeat', heartbeatLimiter, async (req, res) => {
}
const settings = await getSettings();
res.json({ licence: await tokenFor(install), latestVersion: settings.latest_version || null, serverTime: now.toISOString() });
res.json({
licence: await tokenFor(install),
latestVersion: settings.latest_version || null,
releases: await releasesForInstall(version || install.version),
notices: await noticesForInstall(install.id, now),
serverTime: now.toISOString(),
});
} catch (e) {
console.error('[heartbeat]', e);
fail(res, 500, 'SERVER_ERROR', 'The Hub could not record this heartbeat.');
@@ -184,5 +195,34 @@ router.post('/installs/update-request', updateRequestLimiter, async (req, res) =
}
});
// A site admin withdrew their update request: resolve the open request, and tell Joshua if he was
// emailed about it, so he doesn't update the site after all.
router.post('/installs/update-request/cancel', updateRequestLimiter, async (req, res) => {
try {
const install = await signedInstall(req, res);
if (!install) return;
const now = new Date();
const open = await prisma.installEvent.findMany({ where: { installId: install.id, type: 'update_requested', resolvedAt: null } });
if (!open.length) return res.json({ cancelled: false });
await prisma.installEvent.updateMany({ where: { id: { in: open.map(e => e.id) } }, data: { resolvedAt: now } });
await prisma.installEvent.create({ data: { installId: install.id, type: 'update_request_withdrawn', level: 'info', message: 'Update request withdrawn by the site', resolvedAt: now } });
const settings = await getSettings();
if (settings.alert_email) {
const customer = await prisma.customer.findUnique({ where: { id: install.customerId }, select: { name: true } });
await sendMail({
to: settings.alert_email,
subject: `Cross Events Hub: update request withdrawn by ${customer?.name || install.name}`,
text: `${customer?.name || install.name} (${install.url}) withdrew their update request. No need to update the site for now.\n\n${(process.env.FRONTEND_URL || '').replace(/\/$/, '')}/installs/${install.id}`,
}).catch(e => console.warn('[update-request] email failed:', e?.message));
}
res.json({ cancelled: true });
} catch (e) {
console.error('[update-request/cancel]', e);
fail(res, 500, 'SERVER_ERROR', 'The Hub could not withdraw the update request. Try again later.');
}
});
module.exports = router;
module.exports.PROTOCOL_VERSIONS = PROTOCOL_VERSIONS;