Merge branch 'feat/signin-health'
This commit is contained in:
@@ -5,6 +5,21 @@ versions follow [Semantic Versioning](https://semver.org/).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [2.9.0] - 2026-11-20
|
||||
|
||||
Needs `@crosscode/contracts` 1.13.0 (vendored). The checks need Cross Events 3.5.0 (older ones don't
|
||||
report how they sign in).
|
||||
|
||||
### Added
|
||||
|
||||
- **Whether people can sign in.** A Cross Events install's page shows its sign-in (its own or
|
||||
through Accounts), whether it's linked to the church's Accounts, and the last sign-in that
|
||||
failed. New alerts: **signs in through Accounts but isn't linked** (critical: nobody can sign
|
||||
in), **linked to an Accounts that isn't this church's**, **a sign-in failed** in the last 24
|
||||
hours (with the reason the site saw), and on an Accounts install, **nothing is linked to it**
|
||||
while the church has Cross Events. They show on the dashboard, the install and Alerts, and new
|
||||
ones are emailed as other alerts are.
|
||||
|
||||
## [2.8.0] - 2026-11-20
|
||||
|
||||
Needs `@crosscode/contracts` 1.12.0 (vendored) and, on each server, agent 1.3.0.
|
||||
|
||||
Generated
+6
-6
@@ -1,16 +1,16 @@
|
||||
{
|
||||
"name": "events-hub-backend",
|
||||
"version": "2.8.0",
|
||||
"version": "2.9.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "events-hub-backend",
|
||||
"version": "2.8.0",
|
||||
"version": "2.9.0",
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
"@anthropic-ai/sdk": "^1.3.0",
|
||||
"@crosscode/contracts": "file:vendor/crosscode-contracts-1.12.0.tgz",
|
||||
"@crosscode/contracts": "file:vendor/crosscode-contracts-1.13.0.tgz",
|
||||
"@prisma/adapter-pg": "^7.10.1",
|
||||
"@prisma/client": "^7.10.1",
|
||||
"bcryptjs": "^2.4.3",
|
||||
@@ -609,9 +609,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@crosscode/contracts": {
|
||||
"version": "1.12.0",
|
||||
"resolved": "file:vendor/crosscode-contracts-1.12.0.tgz",
|
||||
"integrity": "sha512-sIf1NJtAskKghZ6D2YqiNf+F+gyZufF+XPy7QAh767+QK5zCkzeYkSPiEwW+yRJXj/R/75X2pcfuqQ0fD0WXkQ==",
|
||||
"version": "1.13.0",
|
||||
"resolved": "file:vendor/crosscode-contracts-1.13.0.tgz",
|
||||
"integrity": "sha512-k5A9HPnwEtk94YPPt3v+8IZeJrg2uLZpd2JoFyogzscq1n7TyQxOsy1IdjJXcYlybQbAE5mBDkOVlqxgdsfghg==",
|
||||
"license": "UNLICENSED",
|
||||
"dependencies": {
|
||||
"zod": "^4.6.7"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "events-hub-backend",
|
||||
"version": "2.8.0",
|
||||
"version": "2.9.0",
|
||||
"private": true,
|
||||
"description": "Cross Events Hub — API for managing Cross Events installs, licences and heartbeats",
|
||||
"main": "src/index.js",
|
||||
@@ -20,7 +20,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@anthropic-ai/sdk": "^1.3.0",
|
||||
"@crosscode/contracts": "file:vendor/crosscode-contracts-1.12.0.tgz",
|
||||
"@crosscode/contracts": "file:vendor/crosscode-contracts-1.13.0.tgz",
|
||||
"@prisma/adapter-pg": "^7.10.1",
|
||||
"@prisma/client": "^7.10.1",
|
||||
"bcryptjs": "^2.4.3",
|
||||
|
||||
@@ -12,7 +12,7 @@ const { ymd, today } = require('../utils/billing/dates');
|
||||
const { linkedProductsFor } = require('../utils/protocol');
|
||||
const { audit } = require('../utils/audit');
|
||||
const { getSettings, setSettings } = require('../utils/settings');
|
||||
const { problems, compareVersions } = require('../utils/alerts');
|
||||
const { problems, compareVersions, churchesOf } = require('../utils/alerts');
|
||||
const licenceToken = require('../utils/licenceToken');
|
||||
const { smtpConfigured, testSmtp } = require('../utils/mail');
|
||||
const { VERSION_RE, sortReleases, syncLatestVersion, latestVersions, unmetRequirementsFor } = require('../utils/releases');
|
||||
@@ -43,8 +43,9 @@ function dateOrNull(v) {
|
||||
}
|
||||
|
||||
// The health of an install at a glance, for lists. `latest` is the latest version per product.
|
||||
function summary(install, settings, latest = {}, now = new Date()) {
|
||||
const current = problems(install, { ...settings, latest_versions: latest }, now);
|
||||
function summary(install, settings, latest = {}, now = new Date(), church = undefined) {
|
||||
// Hub 2.9.0: `church` (churchesOf) lets the sign-in checks compare with the church's Accounts.
|
||||
const current = problems({ ...install, church }, { ...settings, latest_versions: latest }, now);
|
||||
const latestForProduct = latest[install.product] || null;
|
||||
const worst = current.some(p => p.level === 'critical') ? 'critical' : current.some(p => p.level === 'warning') ? 'warning' : 'ok';
|
||||
return {
|
||||
@@ -69,7 +70,8 @@ function summary(install, settings, latest = {}, now = new Date()) {
|
||||
router.get('/dashboard', wrap(async (req, res) => {
|
||||
const [settings, latest] = await Promise.all([getSettings(), latestVersions()]);
|
||||
const installs = await prisma.install.findMany({ where: { releasedAt: null }, include: { licence: true, customer: true }, orderBy: { name: 'asc' } });
|
||||
const rows = installs.map(i => summary(i, settings, latest));
|
||||
const churches = churchesOf(installs);
|
||||
const rows = installs.map(i => summary(i, settings, latest, new Date(), churches.get(i.customerId)));
|
||||
const [customers, licences, openAlerts, billed, sentInvoices] = await Promise.all([
|
||||
prisma.customer.count(),
|
||||
prisma.licence.groupBy({ by: ['product', 'status'], _count: { _all: true } }),
|
||||
@@ -227,7 +229,8 @@ router.post('/licences/:id/release', wrap(async (req, res) => {
|
||||
router.get('/installs', wrap(async (req, res) => {
|
||||
const [settings, latest] = await Promise.all([getSettings(), latestVersions()]);
|
||||
const installs = await prisma.install.findMany({ include: { licence: true, customer: true }, orderBy: { name: 'asc' } });
|
||||
res.json(installs.map(i => summary(i, settings, latest)));
|
||||
const churches = churchesOf(installs.filter(i => !i.releasedAt));
|
||||
res.json(installs.map(i => summary(i, settings, latest, new Date(), churches.get(i.customerId))));
|
||||
}));
|
||||
|
||||
router.get('/installs/:id', wrap(async (req, res) => {
|
||||
@@ -251,12 +254,13 @@ router.get('/installs/:id', wrap(async (req, res) => {
|
||||
}
|
||||
const target = latest[install.product] || null;
|
||||
const behind = !!(target && install.version && compareVersions(install.version, target) < 0);
|
||||
const church = churchesOf(await prisma.install.findMany({ where: { customerId: install.customerId, releasedAt: null }, select: { id: true, product: true, customerId: true } })).get(install.customerId);
|
||||
const [aiStatus, aiMonths, aiHelpers, unmet] = await Promise.all([
|
||||
ai.statusFor(install), ai.usageByMonth(install.id), ai.usageByHelper(install.id),
|
||||
behind ? unmetRequirementsFor(install, target) : [],
|
||||
]);
|
||||
res.json({
|
||||
...safe, licence, summary: summary(install, settings, latest), heartbeats, ai: { status: aiStatus, months: aiMonths, helpers: aiHelpers },
|
||||
...safe, licence, summary: summary(install, settings, latest, new Date(), church), heartbeats, ai: { status: aiStatus, months: aiMonths, helpers: aiHelpers },
|
||||
// What updating to the latest version needs from the church's other products (Hub 2.0).
|
||||
update: { latestVersion: target, behind, unmetRequirements: unmet },
|
||||
// The church's other installs this one is told about (protocol v2), and the ones it isn't.
|
||||
|
||||
@@ -76,6 +76,41 @@ function problems(install, settings, now = new Date()) {
|
||||
if (latest && install.version && compareVersions(install.version, latest) < 0) {
|
||||
out.push({ type: 'behind', level: 'info', message: `Runs ${install.version}; latest is ${latest}` });
|
||||
}
|
||||
if (lastSeen) out.push(...signInProblems(install, now));
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hub 2.9.0: whether people can sign in (contracts 1.13.0). `install.church` (filled in by
|
||||
* runAlerts): { accountsInstallIds, hasEvents } for the install's customer.
|
||||
* - Events (heartbeat `stats.signIn`, Events 3.5.0+): signs in through Accounts but isn't linked
|
||||
* (nobody can sign in), linked to an Accounts that isn't this church's, or a sign-in that failed
|
||||
* in the last 24 hours.
|
||||
* - Accounts: the church has Events but no product is linked to Accounts.
|
||||
*/
|
||||
function signInProblems(install, now = new Date()) {
|
||||
const out = [];
|
||||
const church = install.church || {};
|
||||
if ((install.product || 'events') === 'events') {
|
||||
const s = install.stats?.signIn;
|
||||
if (!s) return out;
|
||||
if (s.mode === 'accounts' && !s.accounts) {
|
||||
out.push({ type: 'signin_not_linked', level: 'critical', message: 'Signs in through Accounts but isn\'t linked to it: nobody can sign in. Connect Accounts under Settings → Linked products (Events 3.5.0+ reconnects by itself at its next heartbeat when the Hub lists the church\'s Accounts).' });
|
||||
} else if (s.accounts && Array.isArray(church.accountsInstallIds) && !church.accountsInstallIds.includes(s.accounts.installId)) {
|
||||
out.push({ type: 'signin_wrong_accounts', level: 'warning', message: church.accountsInstallIds.length
|
||||
? `Linked to an Accounts (${s.accounts.url}) that isn't this church's Accounts on the Hub.`
|
||||
: `Linked to an Accounts (${s.accounts.url}) the Hub doesn't list for this church.` });
|
||||
}
|
||||
const err = s.lastError;
|
||||
if (err && now - new Date(err.at) < DAY) {
|
||||
out.push({ type: 'signin_failing', level: 'warning', message: `A sign-in failed ${new Date(err.at).toISOString()} (${err.code}): ${err.message}` });
|
||||
}
|
||||
} else if (install.product === 'accounts') {
|
||||
const linked = install.stats?.linkedProducts;
|
||||
if (church.hasEvents && linked === 0) {
|
||||
out.push({ type: 'accounts_unlinked', level: 'warning', message: 'No product is linked to this Accounts, though the church has Cross Events: Events can\'t sign anyone in through it.' });
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -89,6 +124,19 @@ async function latestVersionsNow() {
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Per customer: its Accounts install ids, and whether it has Cross Events (for signInProblems). */
|
||||
function churchesOf(installs) {
|
||||
const out = new Map();
|
||||
for (const i of installs) {
|
||||
if (!i.customerId) continue;
|
||||
const c = out.get(i.customerId) || { accountsInstallIds: [], hasEvents: false };
|
||||
if (i.product === 'accounts') c.accountsInstallIds.push(i.id);
|
||||
if ((i.product || 'events') === 'events') c.hasEvents = true;
|
||||
out.set(i.customerId, c);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
async function runAlerts(now = new Date()) {
|
||||
const settings = { ...(await getSettings()), latest_versions: await latestVersionsNow() };
|
||||
const installs = await prisma.install.findMany({
|
||||
@@ -98,8 +146,9 @@ async function runAlerts(now = new Date()) {
|
||||
let opened = 0;
|
||||
let resolved = 0;
|
||||
const newAlerts = [];
|
||||
const churches = churchesOf(installs);
|
||||
for (const install of installs) {
|
||||
const current = problems(install, settings, now);
|
||||
const current = problems({ ...install, church: churches.get(install.customerId) }, settings, now);
|
||||
// Update requests are opened by the install and resolved by its heartbeat, not by these checks.
|
||||
const openByType = new Map(install.events.filter(e => !['registered', 'version', 'update_requested', 'update_request_withdrawn'].includes(e.type)).map(e => [e.type, e]));
|
||||
for (const p of current) {
|
||||
@@ -139,4 +188,4 @@ async function rollupHeartbeats(now = new Date(), db = prisma) {
|
||||
return { deleted: res };
|
||||
}
|
||||
|
||||
module.exports = { compareVersions, problems, runAlerts, rollupHeartbeats };
|
||||
module.exports = { compareVersions, problems, signInProblems, churchesOf, runAlerts, rollupHeartbeats };
|
||||
|
||||
@@ -127,6 +127,24 @@ describe('alerts', () => {
|
||||
expect(types).toEqual(['offline']);
|
||||
});
|
||||
|
||||
test('2.9.0: sign-in through Accounts without a link, linked to the wrong Accounts, failing; an Accounts nothing links to', () => {
|
||||
const { churchesOf } = require('../src/utils/alerts');
|
||||
const church = churchesOf([{ id: 'acc-1', product: 'accounts', customerId: 'c1' }, { id: 'ev-1', product: 'events', customerId: 'c1' }]).get('c1');
|
||||
const signIn = (s) => problems({ ...healthy, product: 'events', church, stats: { signIn: s } }, settings, now);
|
||||
expect(signIn({ mode: 'accounts', accounts: null, lastError: null }).map(p => [p.type, p.level])).toEqual([['signin_not_linked', 'critical']]);
|
||||
expect(signIn({ mode: 'local', accounts: null, lastError: null })).toEqual([]);
|
||||
expect(signIn({ mode: 'accounts', accounts: { installId: 'acc-1', url: 'https://accounts.hope.test' }, lastError: null })).toEqual([]);
|
||||
expect(signIn({ mode: 'accounts', accounts: { installId: 'acc-other', url: 'https://accounts.other.test' }, lastError: null }).map(p => p.type)).toEqual(['signin_wrong_accounts']);
|
||||
const failing = signIn({ mode: 'accounts', accounts: { installId: 'acc-1', url: 'https://accounts.hope.test' }, lastError: { at: '2026-10-24T11:00:00Z', code: 'ACCOUNTS_UNAVAILABLE', message: 'fetch failed' } });
|
||||
expect(failing[0]).toMatchObject({ type: 'signin_failing', message: expect.stringContaining('fetch failed') });
|
||||
// A day-old failure is history, not a problem.
|
||||
expect(signIn({ mode: 'accounts', accounts: { installId: 'acc-1', url: 'x' }, lastError: { at: '2026-10-22T11:00:00Z', code: 'X', message: 'old' } })).toEqual([]);
|
||||
// Older Events (no signIn): nothing to say.
|
||||
expect(problems({ ...healthy, product: 'events', church, stats: {} }, settings, now)).toEqual([]);
|
||||
expect(problems({ ...healthy, product: 'accounts', church, stats: { linkedProducts: 0 } }, { ...settings, latest_versions: {} }, now).map(p => p.type)).toEqual(['accounts_unlinked']);
|
||||
expect(problems({ ...healthy, product: 'accounts', church, stats: { linkedProducts: 1 } }, { ...settings, latest_versions: {} }, now)).toEqual([]);
|
||||
});
|
||||
|
||||
test('version comparison', () => {
|
||||
expect(compareVersions('1.40.2', '1.41.0')).toBeLessThan(0);
|
||||
expect(compareVersions('1.41.0', '1.41.0')).toBe(0);
|
||||
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "events-hub-frontend",
|
||||
"version": "2.8.0",
|
||||
"version": "2.9.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "events-hub-frontend",
|
||||
"version": "2.8.0",
|
||||
"version": "2.9.0",
|
||||
"dependencies": {
|
||||
"lucide-react": "^0.536.0",
|
||||
"next": "^15.5.24",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "events-hub-frontend",
|
||||
"version": "2.8.0",
|
||||
"version": "2.9.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev -p 3200",
|
||||
|
||||
@@ -119,6 +119,27 @@ export default function InstallPage() {
|
||||
<p className="mt-2 text-xs text-slate-500">{d.protocolVersion >= 2 ? "This site is told about the products listed to it in each heartbeat reply (Linked products), so it can connect to them." : "This site uses protocol 1 (Cross Events before 2.4), so it isn't told about the others yet."}</p>
|
||||
</>
|
||||
)}
|
||||
{/* Hub 2.9.0: how people sign in (Events 3.5.0+ heartbeat), checked against the church's Accounts. */}
|
||||
{d.summary.product === "events" && (
|
||||
<div className="mt-3 border-t border-slate-100 pt-3">
|
||||
{s.signIn ? (() => {
|
||||
const si = s.signIn;
|
||||
const accounts = d.siblings.find(x => x.product === "accounts");
|
||||
const linkedOk = si.accounts && accounts && si.accounts.installId === accounts.id;
|
||||
return (
|
||||
<>
|
||||
<Row k="Sign-in" v={si.mode === "accounts" ? "through Accounts" : "Cross Events' own"} />
|
||||
<Row k="Linked to Accounts" v={
|
||||
!si.accounts ? <span className={si.mode === "accounts" ? "font-medium text-red-700" : "text-slate-500"}>not linked{si.mode === "accounts" ? ": nobody can sign in" : ""}</span>
|
||||
: linkedOk ? <span className="text-green-700">yes, the church's Accounts ({si.accounts.url})</span>
|
||||
: <span className="text-amber-700">{si.accounts.url} — {accounts ? "not the church's Accounts on the Hub" : "the Hub has no Accounts for this church"}</span>
|
||||
} />
|
||||
<Row k="Last sign-in problem" v={si.lastError ? <span className="text-amber-800">{fmtDate(si.lastError.at)}: {si.lastError.code} — {si.lastError.message}</span> : "none"} />
|
||||
</>
|
||||
);
|
||||
})() : <Row k="Sign-in" v={<span className="text-slate-500">not reported (Cross Events before 3.5.0)</span>} />}
|
||||
</div>
|
||||
)}
|
||||
<div className="mt-3 border-t border-slate-100 pt-3">
|
||||
<Row k="This site's public key" v={d.publicKey ? "saved" : d.protocolVersion >= 2 ? "none yet (saved with its next heartbeat)" : "none (protocol 1)"} />
|
||||
{d.publicKey && (
|
||||
|
||||
@@ -68,6 +68,10 @@ export type Stats = {
|
||||
campuses?: boolean;
|
||||
campusCount?: number;
|
||||
income?: { last30d?: string; allTime?: string; eventIncome12m?: string };
|
||||
/** Cross Events 3.5.0+ (contracts 1.13.0): how people sign in. */
|
||||
signIn?: { mode: "local" | "accounts"; accounts: { installId: string; url: string } | null; lastError: { at: string; code: string; message: string } | null };
|
||||
/** Accounts: products linked to it. */
|
||||
linkedProducts?: number;
|
||||
};
|
||||
|
||||
export type InstallEvent = { id: string; type: string; level: Problem["level"]; message: string; createdAt: string; resolvedAt: string | null; install?: { id: string; name: string; url: string } };
|
||||
|
||||
Reference in New Issue
Block a user