Hub 2.9.0: whether people can sign in

- An Events install's page shows its sign-in mode, whether it's linked to the church's Accounts,
  and the last sign-in failure (Events 3.5.0 heartbeat, contracts 1.13.0 vendored).
- Alerts: signs in through Accounts but isn't linked (critical), linked to the wrong Accounts, a
  sign-in failed in the last 24 hours, an Accounts nothing is linked to while the church has Events.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-20 12:56:41 +02:00
co-authored by Claude Opus 5.5
parent 1150a82ecc
commit 894f2b2771
12 changed files with 130 additions and 19 deletions
+51 -2
View File
@@ -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 };