From 8f78fcc75c543f05648073de4405069e12db3f26 Mon Sep 17 00:00:00 2001 From: Joshua Oosthuizen Date: Fri, 20 Nov 2026 13:26:50 +0200 Subject: [PATCH] Events 3.6.0, Accounts 1.5.0, contracts 1.14.0: the nightly people check - Contracts 1.14.0: people.check in crosscode.identity-request/1 (500 subs) and its reply (active / deactivated / deleted / unknown, profile for the first two). - Accounts 1.5.0: answers people.check with profiles only for people the product knows; the reply isn't stored. - Events 3.6.0: accounts-people-check job (04:30): fixes out-of-date copies, handles deleted accounts as user.deleted, counts unknown people and stops (changing nothing) when most of a page is unknown; skipped with an Accounts older than 1.5.0. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 12 ++ apps/accounts/CHANGELOG.md | 11 ++ apps/accounts/WHATS-NEW.md | 6 + apps/accounts/backend/package.json | 2 +- apps/accounts/backend/src/links/requests.ts | 21 ++- apps/accounts/backend/tests/requests.test.ts | 23 ++++ apps/accounts/frontend/package.json | 2 +- apps/events/CHANGELOG.md | 15 ++ apps/events/WHATS-NEW.md | 7 + apps/events/backend/package.json | 2 +- .../backend/src/accounts/peopleCheck.ts | 102 ++++++++++++++ apps/events/backend/src/jobs/index.js | 5 + .../backend/tests/accountsPeopleCheck.test.ts | 83 +++++++++++ apps/events/frontend/package.json | 2 +- apps/events/package.json | 2 +- docs/VERSIONS.md | 11 +- package-lock.json | 10 +- packages/contracts/package.json | 2 +- .../contracts/samples/people-check-reply.json | 32 +++++ packages/contracts/samples/people-check.json | 11 ++ .../contracts/schemas/identity-request.json | 47 +++++++ .../contracts/schemas/people-check-reply.json | 130 ++++++++++++++++++ packages/contracts/scripts/json-schemas.cjs | 1 + packages/contracts/src/identity-request.ts | 31 ++++- packages/contracts/tests/json-schemas.test.ts | 2 + packages/contracts/tests/samples.test.ts | 4 +- 26 files changed, 557 insertions(+), 19 deletions(-) create mode 100644 apps/events/backend/src/accounts/peopleCheck.ts create mode 100644 apps/events/backend/tests/accountsPeopleCheck.test.ts create mode 100644 packages/contracts/samples/people-check-reply.json create mode 100644 packages/contracts/samples/people-check.json create mode 100644 packages/contracts/schemas/people-check-reply.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 494d871..d1241af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,18 @@ Each package and app has its own section and its own tags (`contracts@1.0.0`, `accounts@1.0.0`, …). +## events@3.6.0, accounts@1.5.0, contracts@1.14.0 - 2026-11-20 + +A nightly check that each site's copies of people match their church accounts, for changes that +never arrived. + +- **Contracts 1.14.0:** `people.check` in `crosscode.identity-request/1` (`PEOPLE_CHECK_MAX` 500) + and `peopleCheckReplySchema` (each sub `active` / `deactivated` / `deleted` / `unknown`, with the + profile for the first two). Samples and JSON Schema `people-check-reply`. +- **Accounts 1.5.0:** answers it, only with profiles of people the product knows. +- **Events 3.6.0:** the `accounts-people-check` job (04:30): fixes out-of-date copies, handles + deleted accounts as `user.deleted`, and stops if most people are unknown (wrong Accounts?). + ## events@3.5.0, contracts@1.13.0, agent@1.3.1 - 2026-11-20 - **Agent 1.3.1:** agent 1.3.0 still reported itself as 1.2.0 (`AGENT_VERSION` in `src/stats.ts` diff --git a/apps/accounts/CHANGELOG.md b/apps/accounts/CHANGELOG.md index 724a3ca..7303d34 100644 --- a/apps/accounts/CHANGELOG.md +++ b/apps/accounts/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog — Accounts +## [1.5.0] - 2026-11-20 + +Needs contracts 1.14.0. + +### Added + +- `people.check` (contracts 1.14.0): for up to 500 subs, the current profile of each person the + product knows (`active` / `deactivated`), `deleted` for a deleted account, `unknown` for anyone + else (no profile). Audited once per request (`people_checked_by_product`, counts only); the reply + isn't stored for retries, since it holds profiles. Cross Events 3.6.0 asks nightly. + ## [1.4.0] - 2026-11-20 Works with every Cross Events 3.x and contracts 1.11.0 or later. diff --git a/apps/accounts/WHATS-NEW.md b/apps/accounts/WHATS-NEW.md index 4917442..2c9f973 100644 --- a/apps/accounts/WHATS-NEW.md +++ b/apps/accounts/WHATS-NEW.md @@ -3,6 +3,12 @@ What each version changes for the church, in plain language (read by the Hub like Cross Events' WHATS-NEW.md; a section shows once its version is tagged). +## 1.5.0 + +- Your church's sites can now check every night that the details they keep for each person match + their church account (Cross Events 3.6.0 does), so a change that didn't reach a site is fixed the + next morning. + ## 1.4.0 - **Better-looking emails.** Sign-in codes, password links, "your account is ready" and the other diff --git a/apps/accounts/backend/package.json b/apps/accounts/backend/package.json index ae68b53..7acd4c4 100644 --- a/apps/accounts/backend/package.json +++ b/apps/accounts/backend/package.json @@ -1,6 +1,6 @@ { "name": "@crosscode/accounts-backend", - "version": "1.4.0", + "version": "1.5.0", "description": "Cross Code Accounts: the church's sign-in (OpenID Connect provider), account pages API and admin API", "private": true, "type": "module", diff --git a/apps/accounts/backend/src/links/requests.ts b/apps/accounts/backend/src/links/requests.ts index 4109f31..c004411 100644 --- a/apps/accounts/backend/src/links/requests.ts +++ b/apps/accounts/backend/src/links/requests.ts @@ -27,7 +27,7 @@ import { newAccountEmail, testEmail } from '../lib/emails.js'; import { hashToken, randomToken } from '../lib/crypto.js'; import { appVersion } from '../lib/version.js'; import { BUILT_IN_VERSION } from '../privacy/notice.js'; -import { emailProblem, normaliseEmail, profileChanged, setNewsConsent } from '../accounts/service.js'; +import { emailProblem, normaliseEmail, profileChanged, profileOf, setNewsConsent } from '../accounts/service.js'; import { turnOff } from '../accounts/twoFactor.js'; import { signOutEverywhere } from '../oidc/sessions.js'; import { anonymise } from '../privacy/deletion.js'; @@ -303,6 +303,22 @@ async function handle(ctx: Ctx, provider: Provider, link: ProductLink, secret: s await logRequest(ctx, link, r, 'demo_people_removed_by_product', null, req, { removed, kept: kept.length }); return reply({ removed, kept }); } + case 'people.check': { + // 1.5.0: the product's regular check that its copies are current. Profiles only for people + // this product knows; a deleted account is said to be deleted (its sub was that person's). + const subs = [...new Set(r.subs)]; + const known = new Set((await ctx.db.productPerson.findMany({ where: { linkId: link.installId, accountId: { in: subs } }, select: { accountId: true } })).map((p) => p.accountId)); + const accounts = new Map((await ctx.db.account.findMany({ where: { id: { in: subs } } })).map((a) => [a.id, a])); + const people = subs.map((sub) => { + const a = accounts.get(sub); + if (a?.status === 'deleted') return { sub, status: 'deleted' as const, profile: null }; + if (!a || !known.has(sub)) return { sub, status: 'unknown' as const, profile: null }; + return { sub, status: a.status === 'deactivated' ? 'deactivated' as const : 'active' as const, profile: profileOf(a) }; + }); + const count = (s: string) => people.filter((p) => p.status === s).length; + await logRequest(ctx, link, r, 'people_checked_by_product', null, req, { checked: people.length, deleted: count('deleted'), unknown: count('unknown') }); + return reply({ people }); + } case 'church.branding': { const changed = await applyLook(ctx, r.church, r.overwrite); await logRequest(ctx, link, r, 'church_look_from_product', null, req, { changed, overwrite: r.overwrite }); @@ -382,7 +398,8 @@ export function requestsRouter(ctx: Ctx, provider: Provider) { } const out = await handle(ctx, provider, link, secret, request, req); // Checks write nothing, so they needn't be remembered. - const isCheck = 'check' in request && request.check; + // people.check (1.5.0) only reads, and its reply holds profiles: never kept. + const isCheck = ('check' in request && request.check) || request.type === 'people.check'; if (!isCheck) { await ctx.db.productRequest.create({ data: { requestId: request.requestId, linkId: link.installId, type: request.type, reply: out as never, createdAt: ctx.now() } }).catch(() => {}); } diff --git a/apps/accounts/backend/tests/requests.test.ts b/apps/accounts/backend/tests/requests.test.ts index 4ff5468..4434aa4 100644 --- a/apps/accounts/backend/tests/requests.test.ts +++ b/apps/accounts/backend/tests/requests.test.ts @@ -199,6 +199,29 @@ describe('people.* from a product', () => { assert.equal(again.body.created, true); }); + test('1.5.0 people.check: profiles of the product\'s people, deleted accounts, and unknown for the rest; never stored', async () => { + const ensure = (name: string, email: string) => ask({ type: 'people.ensure', name, email, phone: null, returnUrl: 'https://events.hope.test/' }).then((r) => r.body.sub as string); + const known = await ensure('Check Known', 'check.known@hope.test'); + const gone = await ensure('Check Gone', 'check.gone@hope.test'); + await h.db.account.update({ where: { id: gone }, data: { status: 'deleted' } }); + const off = await ensure('Check Off', 'check.off@hope.test'); + await h.db.account.update({ where: { id: off }, data: { status: 'deactivated' } }); + const stranger = (await h.makeAccount({ email: 'check.stranger@hope.test' })).id as string; + const nobody = crypto.randomUUID(); + const requestId = crypto.randomUUID(); + const res = await ask({ type: 'people.check', subs: [known, gone, off, stranger, nobody] }, { requestId }); + assert.equal(res.status, 200, JSON.stringify(res.body)); + const bySub = Object.fromEntries((res.body.people as { sub: string; status: string; profile: { name: string } | null }[]).map((p) => [p.sub, p])); + assert.equal(bySub[known]!.status, 'active'); + assert.equal(bySub[known]!.profile!.name, 'Check Known'); + assert.equal(bySub[gone]!.status, 'deleted'); + assert.equal(bySub[gone]!.profile, null); + assert.equal(bySub[off]!.status, 'deactivated'); + assert.deepEqual([bySub[stranger]!.status, bySub[stranger]!.profile], ['unknown', null], 'not known through this product: no profile'); + assert.equal(bySub[nobody]!.status, 'unknown'); + assert.equal(await h.db.productRequest.findUnique({ where: { requestId } }), null, 'the reply holds profiles: not kept'); + }); + test('a retry with the same request id gets the same answer; a bad signature is refused', async () => { const requestId = crypto.randomUUID(); const body = { type: 'people.ensure', name: 'Retry', email: 'retry@hope.test', phone: null, returnUrl: 'https://events.hope.test/' }; diff --git a/apps/accounts/frontend/package.json b/apps/accounts/frontend/package.json index c5c55f9..a362374 100644 --- a/apps/accounts/frontend/package.json +++ b/apps/accounts/frontend/package.json @@ -1,6 +1,6 @@ { "name": "@crosscode/accounts-frontend", - "version": "1.4.0", + "version": "1.5.0", "private": true, "description": "Cross Code Accounts: the church's sign-in pages, the account page and admin", "scripts": { diff --git a/apps/events/CHANGELOG.md b/apps/events/CHANGELOG.md index 4dad74b..464ee12 100644 --- a/apps/events/CHANGELOG.md +++ b/apps/events/CHANGELOG.md @@ -5,6 +5,21 @@ 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.6.0] - 2026-11-20 + +Works with any Accounts; the people check needs Accounts 1.5.0 (with an older one it's skipped). + +### Added + +- **The nightly people check** (`accounts-people-check`, 04:30, `ACCOUNTS_PEOPLE_CHECK_ENABLED`, + `src/accounts/peopleCheck.ts`). In Accounts mode it sends every linked person's `sub` to + Accounts, 500 at a time (`people.check`, contracts 1.14.0), and: updates the local copy where the + name, email, phone or news choices differ (as `user.updated`); handles deleted accounts as + `user.deleted` (anonymised, or deferred while there's a registration for an event that hasn't + ended); counts deactivated and unknown people. When more than half a page (10+) is unknown, the + site is probably linked to the wrong Accounts: the check stops, changes nothing for them, fails + (Background jobs, the Hub's "jobs failing") and records why (the Hub's "sign-in failed" alert). + ## [3.5.0] - 2026-11-20 ### Fixed diff --git a/apps/events/WHATS-NEW.md b/apps/events/WHATS-NEW.md index e2f472d..adc31e6 100644 --- a/apps/events/WHATS-NEW.md +++ b/apps/events/WHATS-NEW.md @@ -12,6 +12,13 @@ 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.6.0 + +- **People's details are checked every night.** Cross Events compares everyone's name, email, + phone and news choices with their church account and fixes any that are out of date, and handles + accounts that were deleted, in case a change never reached this site. You can see it, run it or + switch it off under Settings → Background jobs. It needs Accounts 1.5.0. + ## 3.5.0 - **Fix:** after loading demo data, nobody could sign in: the site forgot its link to the church's diff --git a/apps/events/backend/package.json b/apps/events/backend/package.json index 2e4b2c0..444f1e5 100644 --- a/apps/events/backend/package.json +++ b/apps/events/backend/package.json @@ -1,6 +1,6 @@ { "name": "@crosscode/events-backend", - "version": "3.5.0", + "version": "3.6.0", "description": "Event Management System Backend", "main": "src/index.js", "scripts": { diff --git a/apps/events/backend/src/accounts/peopleCheck.ts b/apps/events/backend/src/accounts/peopleCheck.ts new file mode 100644 index 0000000..9957d73 --- /dev/null +++ b/apps/events/backend/src/accounts/peopleCheck.ts @@ -0,0 +1,102 @@ +/** + * The nightly people check (3.6.0, contracts 1.14.0 `people.check`, Accounts 1.5.0): Accounts tells + * Events about every change (`user.updated`, `user.deleted`), retried for about a week; this catches + * whatever never arrived (a link that was down, as after a demo load before 3.5.0). For everyone here + * with an account it asks Accounts, a page at a time, and: + * + * - updates the local copy when the profile differs (as `user.updated` does); + * - handles a deleted account as `user.deleted` does (anonymised, or deferred while the person has a + * registration for an event that hasn't ended); + * - only counts people Accounts doesn't know through this site (`unknown`). When most of a page is + * unknown, Events is probably linked to the wrong Accounts: the check stops and fails, so it + * shows on Background jobs and the Hub, and nothing is changed for those people. + */ +import { PEOPLE_CHECK_MAX, peopleCheckReplySchema, type PeopleCheckReply, type Profile } from '@crosscode/contracts'; +import { accounts, accountsLink } from './client'; +import { handleAccountsCall } from './calls'; +import { viaAccounts } from './mode'; +import { recordSignInError } from './status'; +import { updateLocalCopy } from './signin'; + +/* eslint-disable @typescript-eslint/no-require-imports -- CommonJS */ +const prisma = require('../config/db'); +/* eslint-enable @typescript-eslint/no-require-imports */ + +type Local = { id: string; accountId: string; name: string; email: string; phoneNumber: string | null; newsEmail: boolean; newsWhatsApp: boolean }; +export type PeopleCheckResult = { checked: number; updated: number; deleted: number; deferred: number; deactivated: number; unknown: number } | { skipped: string }; + +/** Asks Accounts about these subs (tests replace it). */ +export type Ask = (subs: string[]) => Promise; + +const defaultAsk: Ask = async (subs) => { + const auth = await accounts(); + const raw = await auth.request({ type: 'people.check', actor: null, subs }, { timeoutMs: 120000 }); + return peopleCheckReplySchema.parse(raw); +}; + +/** Whether the local copy already says what the profile says (only what Events keeps). */ +export function sameAsLocal(u: Local, p: Profile): boolean { + return u.name === p.name + && u.email.toLowerCase() === p.email.toLowerCase() + && (u.phoneNumber ?? null) === (p.phone_number ?? null) + && u.newsEmail === p.news_consent.email + && u.newsWhatsApp === p.news_consent.whatsapp; +} + +/** More than this share of a page unknown (with at least MIN_FOR_ALARM people) stops the check. */ +const UNKNOWN_ALARM = 0.5; +const MIN_FOR_ALARM = 10; + +export async function runPeopleCheck(opts: { ask?: Ask; pageSize?: number } = {}): Promise { + if (!(await viaAccounts())) return { skipped: 'This site uses its own sign-in.' }; + if (!(await accountsLink())) return { skipped: 'Accounts isn\'t linked.' }; + const ask = opts.ask ?? defaultAsk; + const size = Math.min(opts.pageSize ?? PEOPLE_CHECK_MAX, PEOPLE_CHECK_MAX); + const out = { checked: 0, updated: 0, deleted: 0, deferred: 0, deactivated: 0, unknown: 0 }; + let cursor: string | undefined; + for (;;) { + const page: Local[] = await prisma.user.findMany({ + where: { accountId: { not: null } }, + select: { id: true, accountId: true, name: true, email: true, phoneNumber: true, newsEmail: true, newsWhatsApp: true }, + orderBy: { id: 'asc' }, + take: size, + ...(cursor ? { cursor: { id: cursor }, skip: 1 } : {}), + }); + if (!page.length) break; + cursor = page[page.length - 1]!.id; + const bySub = new Map(page.map((u) => [u.accountId, u])); + let reply: PeopleCheckReply; + try { + reply = await ask(page.map((u) => u.accountId)); + } catch (e) { + // Accounts before 1.5.0 doesn't know people.check: nothing to do until it's updated. + const err = e as { code?: string; message?: string }; + if (err.code === 'INVALID_REQUEST' && /\btype\b/.test(err.message ?? '')) return { skipped: 'The church\'s Accounts is older than 1.5.0, which this check needs.' }; + throw e; + } + const unknown = reply.people.filter((p) => p.status === 'unknown').length; + if (page.length >= MIN_FOR_ALARM && unknown / page.length > UNKNOWN_ALARM) { + const message = `Accounts doesn't know ${unknown} of ${page.length} people here: is this site linked to the church's own Accounts? Nothing was changed for them.`; + await recordSignInError('PEOPLE_UNKNOWN', message); + throw new Error(message); + } + for (const p of reply.people) { + const u = bySub.get(p.sub); + if (!u) continue; // not one we asked about + out.checked++; + if (p.status === 'unknown') { out.unknown++; continue; } + if (p.status === 'deleted') { + const r = await handleAccountsCall({ type: 'user.deleted', sub: p.sub } as never) as { status?: string }; + if (r.status === 'deferred') out.deferred++; else out.deleted++; + continue; + } + if (p.status === 'deactivated') out.deactivated++; + if (p.profile && !sameAsLocal(u, p.profile)) { + await updateLocalCopy(u.id, p.profile); + out.updated++; + } + } + if (page.length < size) break; + } + return out; +} diff --git a/apps/events/backend/src/jobs/index.js b/apps/events/backend/src/jobs/index.js index ed46078..180cb9d 100644 --- a/apps/events/backend/src/jobs/index.js +++ b/apps/events/backend/src/jobs/index.js @@ -98,6 +98,11 @@ const JOBS = [ name: 'backup', label: 'Database backup', cron: '0 2 * * *', env: 'BACKUP_ENABLED', run: async () => ({ file: (await require('../utils/backupUtils').runBackup()).filename }), }, + { + // 3.6.0: catch any change from Accounts that never arrived (accounts/peopleCheck.ts). + name: 'accounts-people-check', label: 'Accounts: check everyone\'s details here match their church account', cron: '30 4 * * *', env: 'ACCOUNTS_PEOPLE_CHECK_ENABLED', + run: () => require('../accounts/peopleCheck').runPeopleCheck(), + }, { // 3.0.0 (docs/EVENTS-3.0-PLAN.md §5): 14 days after sign-in moved to Accounts, Events' old // passwords and 2FA secrets go; sign-in records (for signing out of Accounts) after 40 days. diff --git a/apps/events/backend/tests/accountsPeopleCheck.test.ts b/apps/events/backend/tests/accountsPeopleCheck.test.ts new file mode 100644 index 0000000..6ea799a --- /dev/null +++ b/apps/events/backend/tests/accountsPeopleCheck.test.ts @@ -0,0 +1,83 @@ +// 3.6.0: the nightly people check against Accounts (contracts 1.14.0 people.check). +type U = { id: string; accountId: string; name: string; email: string; phoneNumber: string | null; newsEmail: boolean; newsWhatsApp: boolean }; +let mockUsers: U[] = []; +const mockUpdated: string[] = []; +const mockCalls: { type: string; sub: string }[] = []; +const mockErrors: string[] = []; +let mockMode = true; +let mockLinked = true; +let mockDeferred = new Set(); + +jest.mock('../src/config/db', () => ({ + user: { + findMany: async ({ take, cursor }: { take: number; cursor?: { id: string } }) => { + const sorted = [...mockUsers].sort((a, b) => a.id.localeCompare(b.id)); + const start = cursor ? sorted.findIndex((u) => u.id === cursor.id) + 1 : 0; + return sorted.slice(start, start + take); + }, + }, +})); +jest.mock('../src/accounts/mode', () => ({ viaAccounts: async () => mockMode })); +jest.mock('../src/accounts/client', () => ({ accountsLink: async () => (mockLinked ? { installId: 'acc-1' } : null), accounts: async () => { throw new Error('not in tests'); } })); +jest.mock('../src/accounts/signin', () => ({ updateLocalCopy: async (id: string) => { mockUpdated.push(id); } })); +jest.mock('../src/accounts/calls', () => ({ + handleAccountsCall: async (c: { type: string; sub: string }) => { mockCalls.push(c); return { status: mockDeferred.has(c.sub) ? 'deferred' : 'deleted' }; }, +})); +jest.mock('../src/accounts/status', () => ({ recordSignInError: async (_c: string, m: string) => { mockErrors.push(m); } })); + +import type { PeopleCheckReply, Profile } from '@crosscode/contracts'; +import { runPeopleCheck, sameAsLocal } from '../src/accounts/peopleCheck'; + +const sub = (n: number) => `00000000-0000-4000-8000-${String(n).padStart(12, '0')}`; +const user = (n: number, over: Partial = {}): U => ({ id: `u${String(n).padStart(3, '0')}`, accountId: sub(n), name: `Person ${n}`, email: `p${n}@hope.test`, phoneNumber: null, newsEmail: false, newsWhatsApp: false, ...over }); +const profile = (u: U, over: Partial = {}): Profile => ({ name: u.name, given_name: null, family_name: null, email: u.email, email_verified: true, phone_number: u.phoneNumber, phone_number_verified: false, news_consent: { email: u.newsEmail, whatsapp: u.newsWhatsApp }, ...over }); + +beforeEach(() => { + mockUsers = []; mockUpdated.length = 0; mockCalls.length = 0; mockErrors.length = 0; + mockMode = true; mockLinked = true; mockDeferred = new Set(); +}); + +test('updates only copies that differ, handles deleted accounts as user.deleted does, counts the rest', async () => { + mockUsers = [user(1), user(2), user(3), user(4), user(5)]; + mockDeferred = new Set([sub(4)]); + const ask = async (subs: string[]): Promise => ({ + schema: 'crosscode.identity-request/1', + people: subs.map((s) => { + const u = mockUsers.find((x) => x.accountId === s)!; + if (s === sub(1)) return { sub: s, status: 'active' as const, profile: profile(u) }; + if (s === sub(2)) return { sub: s, status: 'active' as const, profile: profile(u, { name: 'New Name', news_consent: { email: true, whatsapp: false } }) }; + if (s === sub(3) || s === sub(4)) return { sub: s, status: 'deleted' as const, profile: null }; + return { sub: s, status: 'unknown' as const, profile: null }; + }), + }); + expect(await runPeopleCheck({ ask, pageSize: 2 })).toEqual({ checked: 5, updated: 1, deleted: 1, deferred: 1, deactivated: 0, unknown: 1 }); + expect(mockUpdated).toEqual(['u002']); + expect(mockCalls.map((c) => [c.type, c.sub])).toEqual([['user.deleted', sub(3)], ['user.deleted', sub(4)]]); +}); + +test('stops, changing nothing, when Accounts knows hardly anyone (linked to the wrong Accounts?)', async () => { + mockUsers = Array.from({ length: 12 }, (_, i) => user(i + 1)); + const ask = async (subs: string[]): Promise => ({ schema: 'crosscode.identity-request/1', people: subs.map((s) => ({ sub: s, status: 'unknown' as const, profile: null })) }); + await expect(runPeopleCheck({ ask })).rejects.toThrow(/doesn't know 12 of 12/); + expect(mockCalls).toEqual([]); + expect(mockErrors).toHaveLength(1); +}); + +test('skipped on its own sign-in, or without a link', async () => { + mockMode = false; + expect(await runPeopleCheck({ ask: async () => { throw new Error('asked'); } })).toEqual({ skipped: expect.any(String) }); + mockMode = true; mockLinked = false; + expect(await runPeopleCheck({ ask: async () => { throw new Error('asked'); } })).toEqual({ skipped: expect.any(String) }); +}); + +test('sameAsLocal ignores email case and what Events doesn\'t keep', () => { + const u = user(1, { email: 'Jane@Hope.test' }); + expect(sameAsLocal(u, profile(u, { email: 'jane@hope.test', email_verified: false, given_name: 'Jane' }))).toBe(true); + expect(sameAsLocal(u, profile(u, { phone_number: '+27821234567' }))).toBe(false); +}); + +test('an Accounts before 1.5.0 (people.check unknown there) skips the check instead of failing every night', async () => { + mockUsers = [user(1)]; + const ask = async () => { throw Object.assign(new Error('Not a crosscode.identity-request/1 request: type Invalid input'), { code: 'INVALID_REQUEST' }); }; + expect(await runPeopleCheck({ ask })).toEqual({ skipped: expect.stringContaining('1.5.0') }); +}); diff --git a/apps/events/frontend/package.json b/apps/events/frontend/package.json index e3c12ea..41b4dbe 100644 --- a/apps/events/frontend/package.json +++ b/apps/events/frontend/package.json @@ -1,6 +1,6 @@ { "name": "@crosscode/events-frontend", - "version": "3.5.0", + "version": "3.6.0", "private": true, "scripts": { "dev": "next dev", diff --git a/apps/events/package.json b/apps/events/package.json index 412ca48..dc0e396 100644 --- a/apps/events/package.json +++ b/apps/events/package.json @@ -1,6 +1,6 @@ { "name": "@crosscode/events", - "version": "3.5.0", + "version": "3.6.0", "main": "index.js", "scripts": { "dev:backend": "cd backend && npm run dev", diff --git a/docs/VERSIONS.md b/docs/VERSIONS.md index 761f993..8433721 100644 --- a/docs/VERSIONS.md +++ b/docs/VERSIONS.md @@ -10,10 +10,10 @@ separately below; the two often differ. | What | Repo | Latest | Tag | Released | |------|------|--------|-----|----------| -| Cross Events | `crosscode-platform` (`apps/events`) | **3.5.0** | `events@3.5.0` | 2026-11-20 | -| Accounts | `crosscode-platform` (`apps/accounts`) | **1.4.0** | `accounts@1.4.0` | 2026-11-20 | +| Cross Events | `crosscode-platform` (`apps/events`) | **3.6.0** | `events@3.6.0` | 2026-11-20 | +| Accounts | `crosscode-platform` (`apps/accounts`) | **1.5.0** | `accounts@1.5.0` | 2026-11-20 | | Server agent | `crosscode-platform` (`apps/agent`) | **1.3.1** | `agent@1.3.1` | 2026-11-20 | -| Contracts | `crosscode-platform` (`packages/contracts`) | **1.13.0** | `contracts@1.13.0` | 2026-11-20 | +| Contracts | `crosscode-platform` (`packages/contracts`) | **1.14.0** | `contracts@1.14.0` | 2026-11-20 | | Cross Code Hub | `events-hub` | **2.9.0** | `v2.9.0` | 2026-11-20 | | crosscode.co.za | `crosscode-site` | **1.6.0** | `v1.6.0` | 2026-11-19 | | `crosscode` script | `crosscode-platform` (`scripts/`) | `main` | none | 2026-11-20 (last change: `crosscode env`) | @@ -37,6 +37,11 @@ need their own tags until something outside this repo depends on them. ## What each latest release was for +- **Events 3.6.0 + Accounts 1.5.0 + contracts 1.14.0:** a nightly people check (Events asks Accounts + about everyone with an account, 500 at a time, `people.check`): out-of-date copies are fixed, + deleted accounts handled as `user.deleted`, and it stops if most people are unknown. Update + Accounts first (Events skips the check with an older one). No migrations; the Hub is unchanged. + - **Events 3.5.0 + contracts 1.13.0 + agent 1.3.1 + Hub 2.9.0:** loading demo data no longer deletes the Accounts link (on events-demo nobody could sign in); a site in Accounts mode without a link reconnects at its next heartbeat; the heartbeat says how the site signs in and the last failure, diff --git a/package-lock.json b/package-lock.json index e40f401..3d6dd46 100644 --- a/package-lock.json +++ b/package-lock.json @@ -46,7 +46,7 @@ }, "apps/accounts/backend": { "name": "@crosscode/accounts-backend", - "version": "1.4.0", + "version": "1.5.0", "hasInstallScript": true, "dependencies": { "@crosscode/contracts": "*", @@ -83,7 +83,7 @@ }, "apps/accounts/frontend": { "name": "@crosscode/accounts-frontend", - "version": "1.4.0", + "version": "1.5.0", "dependencies": { "@crosscode/contracts": "*", "@crosscode/ui": "*", @@ -128,7 +128,7 @@ }, "apps/events/backend": { "name": "@crosscode/events-backend", - "version": "3.5.0", + "version": "3.6.0", "hasInstallScript": true, "dependencies": { "@cj-tech-master/excelts": "^10.2.0", @@ -178,7 +178,7 @@ }, "apps/events/frontend": { "name": "@crosscode/events-frontend", - "version": "3.5.0", + "version": "3.6.0", "dependencies": { "@crosscode/contracts": "*", "@crosscode/seo": "*", @@ -21276,7 +21276,7 @@ }, "packages/contracts": { "name": "@crosscode/contracts", - "version": "1.13.0", + "version": "1.14.0", "license": "UNLICENSED", "dependencies": { "zod": "^4.6.7" diff --git a/packages/contracts/package.json b/packages/contracts/package.json index 7c83f98..468749d 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -1,6 +1,6 @@ { "name": "@crosscode/contracts", - "version": "1.13.0", + "version": "1.14.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", diff --git a/packages/contracts/samples/people-check-reply.json b/packages/contracts/samples/people-check-reply.json new file mode 100644 index 0000000..ab73e54 --- /dev/null +++ b/packages/contracts/samples/people-check-reply.json @@ -0,0 +1,32 @@ +{ + "schema": "crosscode.identity-request/1", + "people": [ + { + "sub": "6b2c3d4e-5f6a-4b7c-9d8e-0f1a2b3c4d5e", + "status": "active", + "profile": { + "name": "Thandi Mokoena", + "given_name": "Thandi", + "family_name": "Mokoena", + "email": "thandi@example.com", + "email_verified": true, + "phone_number": "+27821234567", + "phone_number_verified": false, + "news_consent": { + "email": true, + "whatsapp": false + } + } + }, + { + "sub": "7c3d4e5f-6a7b-4c8d-8e9f-1a2b3c4d5e6f", + "status": "deleted", + "profile": null + }, + { + "sub": "8d4e5f6a-7b8c-4d9e-9f0a-2b3c4d5e6f7a", + "status": "unknown", + "profile": null + } + ] +} diff --git a/packages/contracts/samples/people-check.json b/packages/contracts/samples/people-check.json new file mode 100644 index 0000000..4b51c71 --- /dev/null +++ b/packages/contracts/samples/people-check.json @@ -0,0 +1,11 @@ +{ + "schema": "crosscode.identity-request/1", + "actor": null, + "requestId": "9e4f5a6b-7c8d-4e9f-8a0b-2c3d4e5f6a7b", + "type": "people.check", + "subs": [ + "6b2c3d4e-5f6a-4b7c-9d8e-0f1a2b3c4d5e", + "7c3d4e5f-6a7b-4c8d-8e9f-1a2b3c4d5e6f", + "8d4e5f6a-7b8c-4d9e-9f0a-2b3c4d5e6f7a" + ] +} diff --git a/packages/contracts/schemas/identity-request.json b/packages/contracts/schemas/identity-request.json index fa5e004..fd22c8f 100644 --- a/packages/contracts/schemas/identity-request.json +++ b/packages/contracts/schemas/identity-request.json @@ -856,6 +856,53 @@ "subs" ] }, + { + "type": "object", + "properties": { + "schema": { + "type": "string", + "const": "crosscode.identity-request/1" + }, + "requestId": { + "type": "string", + "format": "uuid", + "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$" + }, + "actor": { + "anyOf": [ + { + "type": "string", + "format": "uuid", + "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$" + }, + { + "type": "null" + } + ] + }, + "type": { + "type": "string", + "const": "people.check" + }, + "subs": { + "minItems": 1, + "maxItems": 500, + "type": "array", + "items": { + "type": "string", + "format": "uuid", + "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$" + } + } + }, + "required": [ + "schema", + "requestId", + "actor", + "type", + "subs" + ] + }, { "type": "object", "properties": { diff --git a/packages/contracts/schemas/people-check-reply.json b/packages/contracts/schemas/people-check-reply.json new file mode 100644 index 0000000..b27d0d0 --- /dev/null +++ b/packages/contracts/schemas/people-check-reply.json @@ -0,0 +1,130 @@ +{ + "$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/people-check-reply.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "schema": { + "type": "string", + "const": "crosscode.identity-request/1" + }, + "people": { + "maxItems": 500, + "type": "array", + "items": { + "type": "object", + "properties": { + "sub": { + "type": "string", + "format": "uuid", + "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$" + }, + "status": { + "type": "string", + "enum": [ + "active", + "deactivated", + "deleted", + "unknown" + ] + }, + "profile": { + "anyOf": [ + { + "type": "object", + "properties": { + "name": { + "type": "string", + "minLength": 1, + "maxLength": 200 + }, + "given_name": { + "anyOf": [ + { + "type": "string", + "maxLength": 100 + }, + { + "type": "null" + } + ] + }, + "family_name": { + "anyOf": [ + { + "type": "string", + "maxLength": 100 + }, + { + "type": "null" + } + ] + }, + "email": { + "type": "string", + "maxLength": 254, + "format": "email", + "pattern": "^(?:[A-Za-z0-9_'+\\-]+\\.)*[A-Za-z0-9_'+\\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$" + }, + "email_verified": { + "type": "boolean" + }, + "phone_number": { + "anyOf": [ + { + "type": "string", + "pattern": "^\\+[1-9]\\d{6,14}$" + }, + { + "type": "null" + } + ] + }, + "phone_number_verified": { + "type": "boolean" + }, + "news_consent": { + "type": "object", + "properties": { + "email": { + "type": "boolean" + }, + "whatsapp": { + "type": "boolean" + } + }, + "required": [ + "email", + "whatsapp" + ] + } + }, + "required": [ + "name", + "given_name", + "family_name", + "email", + "email_verified", + "phone_number", + "phone_number_verified", + "news_consent" + ] + }, + { + "type": "null" + } + ] + } + }, + "required": [ + "sub", + "status", + "profile" + ] + } + } + }, + "required": [ + "schema", + "people" + ] +} diff --git a/packages/contracts/scripts/json-schemas.cjs b/packages/contracts/scripts/json-schemas.cjs index 09cabca..e24d4fe 100644 --- a/packages/contracts/scripts/json-schemas.cjs +++ b/packages/contracts/scripts/json-schemas.cjs @@ -67,6 +67,7 @@ function contracts(c) { "messaging-status-reply": c.messagingStatusReplySchema, "messaging-test-reply": c.messagingTestReplySchema, "people-remove-demo-reply": c.peopleRemoveDemoReplySchema, + "people-check-reply": c.peopleCheckReplySchema, }; } diff --git a/packages/contracts/src/identity-request.ts b/packages/contracts/src/identity-request.ts index fc3e924..33a7dfa 100644 --- a/packages/contracts/src/identity-request.ts +++ b/packages/contracts/src/identity-request.ts @@ -1,6 +1,6 @@ import { z } from "zod"; import { dateTimeSchema, emailSchema, idSchema, phoneSchema } from "./common"; -import { twoFactorMethodSchema } from "./identity"; +import { profileSchema, twoFactorMethodSchema } from "./identity"; import { schemaName } from "./schema-name"; /** @@ -171,6 +171,33 @@ export const peopleRemoveDemoSchema = base.extend({ subs: z.array(idSchema).max(REMOVE_DEMO_MAX), }); +/** Subs per `people.check`. */ +export const PEOPLE_CHECK_MAX = 500; + +/** + * 1.14.0: the product's regular check that its copies of people are current (Cross Events does it + * nightly), in case a `user.updated` or `user.deleted` never arrived. Accounts answers for each sub + * with the current profile, or says the account was deleted, or that it doesn't know the person + * through this product (`unknown`; never a reason to delete anything). + */ +export const peopleCheckSchema = base.extend({ + type: z.literal("people.check"), + subs: z.array(idSchema).min(1).max(PEOPLE_CHECK_MAX), +}); + +export const PEOPLE_CHECK_STATUSES = ["active", "deactivated", "deleted", "unknown"] as const; + +export const peopleCheckReplySchema = z.object({ + schema: z.literal(IDENTITY_REQUEST_SCHEMA), + people: z.array(z.object({ + sub: idSchema, + status: z.enum(PEOPLE_CHECK_STATUSES), + /** The profile as `user.updated` sends it; null for `deleted` and `unknown`. */ + profile: profileSchema.nullable(), + })).max(PEOPLE_CHECK_MAX), +}); +export type PeopleCheckReply = z.infer; + // ─── messaging.* (contracts 1.9.0) ─────────────────────────────────────────── /** SMTP settings as Cross Events and Accounts both keep them (`smtp_*`). `pass` sealed; null: keep the saved one. */ @@ -216,7 +243,7 @@ export const churchBrandingSchema = base.extend({ type: z.literal("church.brandi export const identityRequestSchema = z.discriminatedUnion("type", [ importBeginSchema, importBatchSchema, importFinishSchema, importAbortSchema, peopleEnsureSchema, peopleUpdateSchema, peopleResetTwoFactorSchema, peopleUnlockSchema, peopleSetActiveSchema, peopleNewsOffSchema, - peopleRemoveDemoSchema, messagingStatusSchema, messagingTestSchema, messagingSetSchema, churchBrandingSchema, + peopleRemoveDemoSchema, peopleCheckSchema, messagingStatusSchema, messagingTestSchema, messagingSetSchema, churchBrandingSchema, ]); export type IdentityRequest = z.infer; export type IdentityRequestType = IdentityRequest["type"]; diff --git a/packages/contracts/tests/json-schemas.test.ts b/packages/contracts/tests/json-schemas.test.ts index 6b2ebfb..af7d762 100644 --- a/packages/contracts/tests/json-schemas.test.ts +++ b/packages/contracts/tests/json-schemas.test.ts @@ -50,6 +50,8 @@ const SAMPLE_SCHEMA: Record = { "messaging-test-reply.json": "messaging-test-reply", "people-remove-demo.json": "identity-request", "people-remove-demo-reply.json": "people-remove-demo-reply", + "people-check.json": "identity-request", + "people-check-reply.json": "people-check-reply", }; describe("JSON Schema (schemas/)", () => { diff --git a/packages/contracts/tests/samples.test.ts b/packages/contracts/tests/samples.test.ts index 8351255..ce8a3bc 100644 --- a/packages/contracts/tests/samples.test.ts +++ b/packages/contracts/tests/samples.test.ts @@ -17,7 +17,7 @@ import { importBatchReplySchema, peopleEnsureReplySchema, messagingTestReplySchema, - peopleRemoveDemoReplySchema, + peopleRemoveDemoReplySchema, peopleCheckReplySchema, userDeletedReplySchema, userExportReplySchema, } from "../src"; @@ -59,6 +59,8 @@ const SCHEMAS: Record = { "messaging-test-reply.json": messagingTestReplySchema, "people-remove-demo.json": identityRequestSchema, "people-remove-demo-reply.json": peopleRemoveDemoReplySchema, + "people-check.json": identityRequestSchema, + "people-check-reply.json": peopleCheckReplySchema, }; describe("samples", () => {