Compare commits

...
Author SHA1 Message Date
joshua 293a9b73e5 Merge branch 'feat/emergency-now' 2026-11-19 22:04:05 +02:00
joshuaandClaude Opus 5.5 621821f5c0 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>
2026-11-19 22:03:32 +02:00
15 changed files with 160 additions and 20 deletions
+8
View File
@@ -2,6 +2,14 @@
Each package and app has its own section and its own tags (`contracts@1.0.0`, `accounts@1.0.0`, …).
## events@3.2.0, contracts@1.10.0 - 2026-11-19
Emergency updates can run as soon as possible (Hub 2.7.0); the Hub asks again when an event is on.
- **Contracts 1.10.0:** `stats.live` in the Cross Events heartbeat (`eventsNow`, `checkInsLastHour`;
optional).
- **Events 3.2.0:** sends it (sessions or one-day events on now, check-ins in the last hour).
## events@3.1.0, accounts@1.2.0, contracts@1.9.0 - 2026-11-19
A church moved Cross Events' sign-in to Accounts without email set up in Accounts: Accounts couldn't
+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",
+2 -1
View File
@@ -843,7 +843,7 @@ ranking.
| 27 | Deploying from the Hub | A **server agent** on every server runs installs, updates and uninstalls on **signed jobs of fixed types** from the Hub, always through the `crosscode` script (which still works by hand). Changes decisions 10 and 23; rule 2 (§1) reworded |
| 28 | The agent's exposure | **It has no URL or listening port.** It only polls the Hub over outgoing HTTPS |
| 29 | Confirming risky jobs | Uninstall and emergency updates need **2FA again** in the Hub; uninstall also needs the short name typed |
| 30 | Notice before updates | **Scheduled: at least 4 hours**; **emergency: at least 15 minutes**, with a reason. The site admin gets an email and a banner straight away. Joshua picks the time. A job the agent misses doesn't run late |
| 30 | Notice before updates | **Scheduled: at least 4 hours**; **emergency: at least 15 minutes**, with a reason. The site admin gets an email and a banner straight away. Joshua picks the time. A job the agent misses doesn't run late. **Changed 2026-11-19** (decision 39): an emergency can also run as soon as possible |
| 31 | Uninstall | The church gets a **JSON export in our own format** (`crosscode.church-export/1`, no internal tables or ids), encrypted so the Hub can't read it, downloadable for **30 days**. The final backup is kept 30 days, then deleted (Joshua emailed 3 days before) |
| 32 | frp | Every church server is behind frp to **one central FastPanel server**. The Hub keeps the **port list** (unique across servers, same number local and remote), tunnels are named `<church>-<product>-web/-api` |
| 33 | frpc.ini | **Only appended to**, in marked blocks, checked with `frpc verify`, with a backup first; uninstall removes only its own block. `admin_addr = 127.0.0.1` / `admin_port = 7400` added once to `[common]` so frpc reloads without dropping other sites |
@@ -857,6 +857,7 @@ ranking.
| # | Question | Decision |
|---|----------|----------|
| 38 | Order after Accounts | **Cross Events 3.0.0 (sign-in through Accounts) is phase 4, the Church Website phase 5** (swapped). Events is what churches use today, so Accounts is proven on real users and their migrated passwords and 2FA first; the Website then starts with a church whose people already have accounts |
| 39 | Emergency updates now | An emergency update (reason and 2FA, as before) can run **as soon as possible**, at the agent's next poll (within a minute), as well as at a time at least 15 minutes away. The church is told it's happening now. When the church's Events heartbeat shows an event on now (a session or a one-day event, or check-ins in the last hour), the Hub names it and needs a second "yes". Hub 2.7.0, Events 3.2.0 |
## Still open
+8 -3
View File
@@ -10,11 +10,11 @@ separately below; the two often differ.
| What | Repo | Latest | Tag | Released |
|------|------|--------|-----|----------|
| Cross Events | `crosscode-platform` (`apps/events`) | **3.1.0** | `events@3.1.0` | 2026-11-19 |
| Cross Events | `crosscode-platform` (`apps/events`) | **3.2.0** | `events@3.2.0` | 2026-11-19 |
| Accounts | `crosscode-platform` (`apps/accounts`) | **1.2.0** | `accounts@1.2.0` | 2026-11-19 |
| Server agent | `crosscode-platform` (`apps/agent`) | **1.2.0** | `agent@1.2.0` | 2026-11-19 |
| Contracts | `crosscode-platform` (`packages/contracts`) | **1.9.0** | `contracts@1.9.0` | 2026-11-19 |
| Cross Code Hub | `events-hub` | **2.6.0** | `v2.6.0` | 2026-11-19 |
| Contracts | `crosscode-platform` (`packages/contracts`) | **1.10.0** | `contracts@1.10.0` | 2026-11-19 |
| Cross Code Hub | `events-hub` | **2.7.0** | `v2.7.0` | 2026-11-19 |
| crosscode.co.za | `crosscode-site` | **1.6.0** | `v1.6.0` | 2026-11-19 |
| `crosscode` script | `crosscode-platform` (`scripts/`) | `main` | none | 2026-11-19 (last change) |
@@ -37,6 +37,11 @@ need their own tags until something outside this repo depends on them.
## What each latest release was for
- **Hub 2.7.0:** emergency updates "as soon as possible" (the agent's next poll), and a second "yes"
when the church has an event on now (from Events 3.2.0's heartbeat). 2.6.1: the Failed jobs filter
and alert search answered 500. No migration; deploy it.
- **Events 3.2.0 + contracts 1.10.0:** the heartbeat says what's on now (`stats.live`).
- **Events 3.1.0 + Accounts 1.2.0 + contracts 1.9.0:** the move to Accounts needs Accounts' email
(Settings → Sign-in sets it up by copying Events' SMTP / WAWP, tests, then saves); Accounts shows a
message instead of a 500 when a code can't be sent. **Use these instead of 3.0.0 / 1.1.0.**
+3 -3
View File
@@ -127,7 +127,7 @@
},
"apps/events/backend": {
"name": "@crosscode/events-backend",
"version": "3.1.0",
"version": "3.2.0",
"hasInstallScript": true,
"dependencies": {
"@cj-tech-master/excelts": "^10.2.0",
@@ -177,7 +177,7 @@
},
"apps/events/frontend": {
"name": "@crosscode/events-frontend",
"version": "3.1.0",
"version": "3.2.0",
"dependencies": {
"@crosscode/contracts": "*",
"@crosscode/seo": "*",
@@ -21275,7 +21275,7 @@
},
"packages/contracts": {
"name": "@crosscode/contracts",
"version": "1.9.0",
"version": "1.10.0",
"license": "UNLICENSED",
"dependencies": {
"zod": "^4.6.7"
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@crosscode/contracts",
"version": "1.9.0",
"version": "1.10.0",
"description": "The shared JSON formats used by every Cross Code product: zod schemas, JSON Schema, TypeScript types and sample payloads",
"license": "UNLICENSED",
"type": "commonjs",
@@ -5,22 +5,51 @@
"health": {
"uptimeSeconds": 86400,
"db": true,
"jobs": { "mode": "queue", "failedLast24h": 0 },
"jobs": {
"mode": "queue",
"failedLast24h": 0
},
"lastBackupAt": "2026-11-03T00:00:12.000Z",
"disk": { "freeBytes": 21474836480, "totalBytes": 53687091200 },
"disk": {
"freeBytes": 21474836480,
"totalBytes": 53687091200
},
"errorsLast24h": 0,
"pendingMigrations": 0
},
"stats": {
"users": 412,
"events": { "active": 3, "upcoming": 5, "total": 61 },
"registrations": { "last30d": 88, "total": 2310 },
"tickets": { "last30d": 140, "total": 3901 },
"checkIns": { "last30d": 96 },
"events": {
"active": 3,
"upcoming": 5,
"total": 61
},
"registrations": {
"last30d": 88,
"total": 2310
},
"tickets": {
"last30d": 140,
"total": 3901
},
"checkIns": {
"last30d": 96
},
"messages": null,
"paymentProviders": ["yoco", "payfast"],
"paymentProviders": [
"yoco",
"payfast"
],
"campuses": true,
"campusCount": 2,
"income": { "last30d": "R5 001–R20 000", "allTime": "R150 001–R250 000", "eventIncome12m": "R100 001–R150 000" }
"income": {
"last30d": "R5 001–R20 000",
"allTime": "R150 001–R250 000",
"eventIncome12m": "R100 001–R150 000"
},
"live": {
"eventsNow": 1,
"checkInsLastHour": 42
}
}
}
@@ -305,6 +305,25 @@
"allTime",
"eventIncome12m"
]
},
"live": {
"type": "object",
"properties": {
"eventsNow": {
"type": "integer",
"minimum": 0,
"maximum": 9007199254740991
},
"checkInsLastHour": {
"type": "integer",
"minimum": 0,
"maximum": 9007199254740991
}
},
"required": [
"eventsNow",
"checkInsLastHour"
]
}
},
"required": [
+6
View File
@@ -190,6 +190,12 @@ export const eventsStatsSchema = z.object({
/** What the Events licence tier is billed on. */
eventIncome12m: incomeBandSchema,
}),
/**
* 1.10.0: what's happening now, so the Hub can warn before taking the site down (an emergency
* update "as soon as possible"): events with a session or a one-day event on now (give or take
* 30 minutes), and tickets checked in during the last hour. Optional: older installs don't send it.
*/
live: z.object({ eventsNow: count, checkInsLastHour: count }).optional(),
});
/** Church Website. `storage` is what the extra-storage add-on is billed on (ROADMAP-v3 §10). */