Change an open update request to a newer version (1.5.0)
When a site asks again after a newer version came out, the open
update_requested alert moves on to the latest version ("changed from
...") and the alert address is emailed once; the response says
changed: true with previousVersion (protocol §3a). Needs Cross Events
1.47.4 for the button.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,16 @@ versions follow [Semantic Versioning](https://semver.org/).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [1.5.0] - 2026-10-28
|
||||
|
||||
### Added
|
||||
|
||||
- **Changing an update request** — when a site asked for a version that has since been overtaken and
|
||||
asks again, the open request moves on to the latest version instead of being ignored: the alert
|
||||
reads "latest is 1.47.3 (changed from 1.47.0)" and the alert address gets one email about the
|
||||
change. The response says `changed: true` and gives `previousVersion` (protocol §3a). Needs Cross
|
||||
Events 1.47.4 for the button; older sites keep working as before.
|
||||
|
||||
## [1.4.1] - 2026-10-28
|
||||
|
||||
### Changed
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "events-hub-backend",
|
||||
"version": "1.4.1",
|
||||
"version": "1.5.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "events-hub-backend",
|
||||
"version": "1.4.1",
|
||||
"version": "1.5.0",
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
"@prisma/adapter-pg": "^7.10.1",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "events-hub-backend",
|
||||
"version": "1.4.1",
|
||||
"version": "1.5.0",
|
||||
"private": true,
|
||||
"description": "Cross Events Hub — API for managing Cross Events installs, licences and heartbeats",
|
||||
"main": "src/index.js",
|
||||
|
||||
@@ -12,6 +12,7 @@ const licenceToken = require('../utils/licenceToken');
|
||||
const { checkSignature } = require('../utils/signing');
|
||||
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 { noticesForInstall } = require('../utils/notices');
|
||||
@@ -176,19 +177,40 @@ router.post('/installs/update-request', updateRequestLimiter, async (req, res) =
|
||||
return fail(res, 409, 'UP_TO_DATE', 'This site already runs the latest version.');
|
||||
}
|
||||
|
||||
const open = await prisma.installEvent.findFirst({ where: { installId: install.id, type: 'update_requested', resolvedAt: null }, orderBy: { createdAt: 'desc' } });
|
||||
if (open) return res.json({ requestedAt: open.createdAt.toISOString(), version: latest, alreadyRequested: true });
|
||||
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}`;
|
||||
|
||||
const event = await prisma.installEvent.create({ data: { installId: install.id, type: 'update_requested', level: 'warning', message: `Update requested: runs ${current}, latest is ${latest}` } });
|
||||
const open = await prisma.installEvent.findFirst({ where: { installId: install.id, type: 'update_requested', resolvedAt: null }, orderBy: { createdAt: 'desc' } });
|
||||
if (open) {
|
||||
// Asked for a version that has since been overtaken: the request moves on to the latest one
|
||||
// (Joshua is told once). Otherwise nothing changes and nobody is emailed again.
|
||||
if (!isOutdated(open.message, latest)) {
|
||||
return res.json({ requestedAt: open.createdAt.toISOString(), version: latest, alreadyRequested: true, changed: false });
|
||||
}
|
||||
const previous = requestedVersionOf(open.message);
|
||||
const now = new Date();
|
||||
await prisma.installEvent.update({ where: { id: open.id }, data: { message: requestMessage(current, latest, previous) } });
|
||||
if (settings.alert_email) {
|
||||
const name = await customerName();
|
||||
await sendMail({
|
||||
to: settings.alert_email,
|
||||
subject: `Cross Events Hub: update request changed by ${name}`,
|
||||
text: `${name} (${install.url}) now asks to be updated from ${current} to ${latest}${previous ? ` instead of ${previous}` : ''}.\n\n${link}`,
|
||||
}).catch(e => console.warn('[update-request] email failed:', e?.message));
|
||||
}
|
||||
return res.json({ requestedAt: now.toISOString(), version: latest, alreadyRequested: true, changed: true, previousVersion: previous });
|
||||
}
|
||||
|
||||
const event = await prisma.installEvent.create({ data: { installId: install.id, type: 'update_requested', level: 'warning', message: requestMessage(current, latest) } });
|
||||
if (settings.alert_email) {
|
||||
const customer = await prisma.customer.findUnique({ where: { id: install.customerId }, select: { name: true } });
|
||||
const name = await customerName();
|
||||
await sendMail({
|
||||
to: settings.alert_email,
|
||||
subject: `Cross Events Hub: update requested by ${customer?.name || install.name}`,
|
||||
text: `${customer?.name || install.name} (${install.url}) would like to be updated from ${current} to ${latest}.\n\n${(process.env.FRONTEND_URL || '').replace(/\/$/, '')}/installs/${install.id}`,
|
||||
subject: `Cross Events Hub: update requested by ${name}`,
|
||||
text: `${name} (${install.url}) would like to be updated from ${current} to ${latest}.\n\n${link}`,
|
||||
}).catch(e => console.warn('[update-request] email failed:', e?.message));
|
||||
}
|
||||
res.status(201).json({ requestedAt: event.createdAt.toISOString(), version: latest, alreadyRequested: false });
|
||||
res.status(201).json({ requestedAt: event.createdAt.toISOString(), version: latest, alreadyRequested: false, changed: false });
|
||||
} catch (e) {
|
||||
console.error('[update-request]', e);
|
||||
fail(res, 500, 'SERVER_ERROR', 'The Hub could not record the update request. Try again later.');
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Update requests (protocol §3a). The version a request asks for lives in its alert message
|
||||
* ("Update requested: runs 1.46.2, latest is 1.47.0"), so a request made before a newer version
|
||||
* came out can be moved on to it when the site asks again.
|
||||
*/
|
||||
|
||||
const { compareVersions } = require('./alerts');
|
||||
|
||||
/** The alert message for a request from `current` to `latest`. */
|
||||
function requestMessage(current, latest, previous = null) {
|
||||
return `Update requested: runs ${current}, latest is ${latest}${previous ? ` (changed from ${previous})` : ''}`;
|
||||
}
|
||||
|
||||
/** The version an open request asks for, read from its message, or null. */
|
||||
function requestedVersionOf(message) {
|
||||
const m = /latest is (\d+\.\d+\.\d+)/.exec(String(message || ''));
|
||||
return m ? m[1] : null;
|
||||
}
|
||||
|
||||
/** Whether an open request asks for an older version than `latest` (so asking again changes it). */
|
||||
function isOutdated(message, latest) {
|
||||
const asked = requestedVersionOf(message);
|
||||
return !!latest && (!asked || compareVersions(asked, latest) < 0);
|
||||
}
|
||||
|
||||
module.exports = { requestMessage, requestedVersionOf, isOutdated };
|
||||
@@ -133,3 +133,21 @@ describe('alerts', () => {
|
||||
expect(compareVersions('2.0.0', '1.99.9')).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('update requests', () => {
|
||||
const { requestMessage, requestedVersionOf, isOutdated } = require('../src/utils/updateRequests');
|
||||
|
||||
test('the version asked for is read back from the alert message', () => {
|
||||
expect(requestedVersionOf(requestMessage('1.46.2', '1.47.0'))).toBe('1.47.0');
|
||||
expect(requestedVersionOf(requestMessage('1.46.2', '1.47.3', '1.47.0'))).toBe('1.47.3');
|
||||
expect(requestMessage('1.46.2', '1.47.3', '1.47.0')).toBe('Update requested: runs 1.46.2, latest is 1.47.3 (changed from 1.47.0)');
|
||||
});
|
||||
|
||||
test('a request is outdated once a newer version is out', () => {
|
||||
expect(isOutdated(requestMessage('1.46.2', '1.47.0'), '1.47.3')).toBe(true);
|
||||
expect(isOutdated(requestMessage('1.46.2', '1.47.3'), '1.47.3')).toBe(false);
|
||||
expect(isOutdated(requestMessage('1.46.2', '1.47.10'), '1.47.9')).toBe(false);
|
||||
// A message we can't read is treated as outdated, so asking again fixes it.
|
||||
expect(isOutdated('Update requested', '1.47.3')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -144,12 +144,19 @@ Signed exactly like the heartbeat.
|
||||
POST /api/installs/update-request
|
||||
X-Hub-Install / X-Hub-Timestamp / X-Hub-Signature (as in §3)
|
||||
{ "protocolVersion": 1, "version": "1.41.2" }
|
||||
→ 201 { "requestedAt": "2026-10-27T09:00:00.000Z", "version": "1.42.0", "alreadyRequested": false }
|
||||
→ 200 { …, "alreadyRequested": true } // a request is already open: not emailed again
|
||||
→ 201 { "requestedAt": "2026-10-27T09:00:00.000Z", "version": "1.42.0", "alreadyRequested": false, "changed": false }
|
||||
→ 200 { …, "alreadyRequested": true, "changed": false } // a request for the latest is already open: not emailed again
|
||||
→ 200 { …, "alreadyRequested": true, "changed": true, "previousVersion": "1.42.0" }
|
||||
// the open request was for an older version: it now asks for the latest
|
||||
```
|
||||
|
||||
- The Hub opens an `update_requested` alert on the install (shown under Alerts) and emails the
|
||||
alert address once. It is resolved when a heartbeat reports a newer version than before.
|
||||
- **Changing a request (Hub 1.5.0):** when a request is open for a version that has since been
|
||||
overtaken, asking again moves it on to the latest version — the alert says "latest is 1.47.3
|
||||
(changed from 1.47.0)" and the alert address is emailed once about the change. `version` is
|
||||
always the version now asked for. A Hub before 1.5.0 doesn't send `changed`; installs then
|
||||
withdraw the request and ask again (two emails, same result).
|
||||
- `409 UP_TO_DATE` — the install already runs the Hub's latest version (or none is set).
|
||||
- Errors as in §3 (`INSTALL_NOT_FOUND`, `STALE_REQUEST`, `BAD_SIGNATURE`). Rate-limited (10 an
|
||||
hour per IP). A Hub older than this section answers `404 NOT_FOUND`.
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "events-hub-frontend",
|
||||
"version": "1.4.1",
|
||||
"version": "1.5.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "events-hub-frontend",
|
||||
"version": "1.4.1",
|
||||
"version": "1.5.0",
|
||||
"dependencies": {
|
||||
"lucide-react": "^0.536.0",
|
||||
"next": "^15.5.24",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "events-hub-frontend",
|
||||
"version": "1.4.1",
|
||||
"version": "1.5.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev -p 3200",
|
||||
|
||||
Reference in New Issue
Block a user