Files
events-hub/backend/src/utils/releases.js
T
joshuaandClaude Opus 5.5 1449e5046e 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>
2026-10-28 08:54:35 +02:00

42 lines
1.5 KiB
JavaScript

/**
* Cross Events releases and their notes (Releases page). The highest version is the latest one,
* kept in the latest_version setting so alerts and the install API read it as before.
*/
const prisma = require('../config/db');
const { compareVersions } = require('./alerts');
const { setSettings } = require('./settings');
const VERSION_RE = /^\d+\.\d+\.\d+$/;
const MAX_SENT = 20;
/** Newest first. */
function sortReleases(releases) {
return [...releases].sort((a, b) => compareVersions(b.version, a.version));
}
/**
* What an install on `version` is told (§3): every release newer than it, newest first — at most
* 20, so a long-neglected install still gets a reply of sensible size.
*/
function releasesFor(releases, version) {
return sortReleases(releases)
.filter(r => !version || compareVersions(r.version, version) > 0)
.slice(0, MAX_SENT)
.map(r => ({ version: r.version, releasedAt: new Date(r.releasedAt).toISOString(), urgent: !!r.urgent, notes: r.notes || '' }));
}
/** Point latest_version at the highest release (blank when there are none). */
async function syncLatestVersion() {
const releases = await prisma.release.findMany({ select: { version: true } });
const latest = sortReleases(releases)[0]?.version || '';
await setSettings({ latest_version: latest });
return latest;
}
async function releasesForInstall(version) {
return releasesFor(await prisma.release.findMany(), version);
}
module.exports = { VERSION_RE, sortReleases, releasesFor, releasesForInstall, syncLatestVersion };