Events 3.2.0, contracts 1.10.0: the heartbeat says what's on now

stats.live (eventsNow: a session or a one-day event on now, +/- 30 min;
checkInsLastHour) so Hub 2.7.0 asks again before an emergency update takes
a site with an event on down. Decision 39: emergency updates can run as
soon as possible (decision 30 changed). Tests: liveNow, Events 776.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 22:03:32 +02:00
co-authored by Claude Opus 5.5
parent 88b3e1fb36
commit 621821f5c0
15 changed files with 160 additions and 20 deletions
+9
View File
@@ -5,6 +5,15 @@ All notable changes to this project are documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project follows [Semantic Versioning](https://semver.org/).
## [3.2.0] - 2026-11-19
### Added
- **The heartbeat says what's on now** (`stats.live`, contracts 1.10.0, `hub/report.js liveNow`):
events with a session on now, or a one-day event (no sessions, at most 36 hours) on now, each give
or take 30 minutes, and tickets checked in during the last hour. Hub 2.7.0 asks for a second "yes"
before an emergency update takes a site with an event on down.
## [3.1.0] - 2026-11-19
Found after a church moved sign-in without email set up in Accounts: Accounts couldn't send codes or
+5
View File
@@ -12,6 +12,11 @@ Write for church admins, not developers: no environment variables, endpoints or
developer log is CHANGELOG.md. A tagged version without a section here shows "No details given".
-->
## 3.2.0
- Cross Code now sees when an event is on at your church before an urgent update, so it isn't taken
offline in the middle of your check-in without a good reason.
## 3.1.0 — requires accounts 1.2.0
- **Fix:** moving sign-in to your church's Accounts now needs Accounts' email to work first, so
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@crosscode/events-backend",
"version": "3.1.0",
"version": "3.2.0",
"description": "Event Management System Backend",
"main": "src/index.js",
"scripts": {
+22 -1
View File
@@ -58,6 +58,25 @@ async function pendingMigrations() {
}
}
/**
* 3.2.0: what's happening at the church now (heartbeat `stats.live`), so the Hub warns before an
* emergency update takes the site down: events with a session on now, or a one-day event (no
* sessions, at most 36 hours long) on now, each give or take 30 minutes; and tickets checked in
* during the last hour. A multi-week course without a session today doesn't count.
*/
async function liveNow(now = new Date()) {
const soon = new Date(now.getTime() + 30 * 60e3);
const recent = new Date(now.getTime() - 30 * 60e3);
const [sessions, plain, checkInsLastHour] = await Promise.all([
prisma.eventSession.findMany({ where: { cancelledAt: null, startsAt: { lte: soon }, endsAt: { gte: recent }, event: { isActive: true } }, select: { eventId: true } }),
prisma.event.findMany({ where: { isActive: true, startDate: { lte: soon }, endDate: { gte: recent }, sessions: { none: {} } }, select: { id: true, startDate: true, endDate: true } }),
prisma.ticketUsage.count({ where: { scannedAt: { gte: new Date(now.getTime() - 60 * 60e3) } } }),
]);
const ids = new Set(sessions.map(x => x.eventId));
for (const e of plain) if (new Date(e.endDate) - new Date(e.startDate) <= 36 * 60 * 60e3) ids.add(e.id);
return { eventsNow: ids.size, checkInsLastHour };
}
async function disk() {
try {
const s = await fs.promises.statfs(path.join(__dirname, '..', '..'));
@@ -123,11 +142,13 @@ async function stats(now = new Date()) {
prisma.payment.aggregate({ where: { createdAt: { gte: yearAgo }, ...EVENT_INCOME }, _sum: { amount: true } }),
require('../payments').availableProviders().then(list => list.map(p => p.id)).catch(() => []),
]);
const live = await liveNow(now).catch(() => undefined);
const campusesOn = await campusesEnabled().catch(() => false);
const campusCount = campusesOn ? await prisma.campus.count({ where: { archivedAt: null } }) : 0;
return {
users,
events: { active: activeEvents, upcoming: upcomingEvents, total: totalEvents },
...(live ? { live } : {}),
registrations: { last30d: regs30, total: regsTotal },
tickets: { last30d: tickets30, total: ticketsTotal },
checkIns: { last30d: checkIns30 },
@@ -165,4 +186,4 @@ async function installInfo() {
};
}
module.exports = { APP_VERSION, incomeBand, health, stats, installInfo };
module.exports = { APP_VERSION, incomeBand, health, stats, installInfo, liveNow };
+37
View File
@@ -0,0 +1,37 @@
// 3.2.0: the heartbeat's `stats.live` (what's on now), which the Hub reads before an emergency
// update takes the site down. A session on now, or a one-day event without sessions, counts; a
// multi-week course with no session today doesn't.
const NOW = new Date('2026-11-22T09:00:00.000Z');
const H = 3600e3;
const mockSessions = [];
const mockEvents = [];
let mockCheckIns = 0;
jest.mock('../src/config/db', () => ({
eventSession: {
findMany: async ({ where }) => mockSessions.filter(s => s.cancelledAt === null && s.startsAt <= where.startsAt.lte && s.endsAt >= where.endsAt.gte).map(s => ({ eventId: s.eventId })),
},
event: {
findMany: async ({ where }) => mockEvents.filter(e => !e.hasSessions && e.startDate <= where.startDate.lte && e.endDate >= where.endDate.gte),
},
ticketUsage: { count: async () => mockCheckIns },
}));
const { liveNow } = require('../src/hub/report');
beforeEach(() => { mockSessions.length = 0; mockEvents.length = 0; mockCheckIns = 0; });
test('a session on now and a one-day event on now count; a long course and a later session don\'t', async () => {
mockSessions.push({ eventId: 'course', startsAt: new Date(NOW.getTime() - H), endsAt: new Date(NOW.getTime() + H), cancelledAt: null });
mockSessions.push({ eventId: 'later', startsAt: new Date(NOW.getTime() + 5 * H), endsAt: new Date(NOW.getTime() + 6 * H), cancelledAt: null });
mockSessions.push({ eventId: 'cancelled', startsAt: new Date(NOW.getTime() - H), endsAt: new Date(NOW.getTime() + H), cancelledAt: new Date() });
mockEvents.push({ id: 'breakfast', startDate: new Date(NOW.getTime() - H), endDate: new Date(NOW.getTime() + 2 * H) });
mockEvents.push({ id: 'term', startDate: new Date(NOW.getTime() - 20 * 24 * H), endDate: new Date(NOW.getTime() + 40 * 24 * H) });
mockCheckIns = 12;
expect(await liveNow(NOW)).toEqual({ eventsNow: 2, checkInsLastHour: 12 });
});
test('starting within half an hour counts as on', async () => {
mockEvents.push({ id: 'soon', startDate: new Date(NOW.getTime() + 20 * 60e3), endDate: new Date(NOW.getTime() + 3 * H) });
expect((await liveNow(NOW)).eventsNow).toBe(1);
});
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@crosscode/events-frontend",
"version": "3.1.0",
"version": "3.2.0",
"private": true,
"scripts": {
"dev": "next dev",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@crosscode/events",
"version": "3.1.0",
"version": "3.2.0",
"main": "index.js",
"scripts": {
"dev:backend": "cd backend && npm run dev",