Events 3.0: auto-connect, demo people in Accounts, e2e; import.finish checks the subs

- contracts 1.8.0 / Accounts 1.1.0: import.finish lists the subs the product
  relies on; Accounts checks each is held, not deleted and known to it (the
  count+hash failed a second move after Undo once someone had joined
  through Accounts).
- Events: connects to the church's Accounts once the Hub lists it;
  moveNewPeople (demo data, people added after the move); set-demo moves
  demo people; e2e/sign-in-accounts.spec.ts with Accounts in memory and an
  e2e-only /api rewrite. test:accounts 14/14; Jest auto-connect tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 14:28:54 +02:00
co-authored by Claude Opus 5.5
parent c627c61de1
commit 63d36c3ecf
24 changed files with 466 additions and 63 deletions
+2 -1
View File
@@ -14,7 +14,8 @@ For Cross Events 3.0 (docs/EVENTS-3.0-PLAN.md §8), with contracts 1.8.0.
Accounts' key at rest), lockout, news consent and its history, notice acceptance, last sign-in
and status; ticked Events admins become Accounts admins. An email that already has an account is
**linked** (that account and its password stay). A check (`check: true`) writes nothing.
`import.finish` compares the count and a hash of the subs. Events' privacy notice versions are
`import.finish` checks every sub the product relies on is an account here, not deleted, and
known to that product, and lists the ones that aren't. Events' privacy notice versions are
taken when Accounts has published none; an empty church name and colour are filled from Events.
- **New recovery codes after the first sign-in** for people moved in with 2FA (their Events codes
can't move): shown once after the second step, whatever step comes next.
+9 -6
View File
@@ -18,7 +18,7 @@ import {
ACCOUNTS_REQUEST_PATH, IDENTITY_REQUEST_SCHEMA, identityRequestSchema,
type IdentityRequest, type ImportPerson, type ImportResult,
} from '@crosscode/contracts';
import { importIdsHash, LINK_HEADERS, openLinkValue, verify } from '@crosscode/contracts/signing';
import { LINK_HEADERS, openLinkValue, verify } from '@crosscode/contracts/signing';
import type { Ctx } from '../context.js';
import type { ProductLink } from '../generated/prisma/client.js';
import { limit } from '../http.js';
@@ -196,12 +196,15 @@ async function handle(ctx: Ctx, provider: Provider, link: ProductLink, secret: s
}
case 'import.finish': {
if (!link.importStartedAt) throw new RequestError('There\'s no move under way.', 'NOT_MOVING', 409);
const rows = await ctx.db.productPerson.findMany({ where: { linkId: link.installId, via: 'import' } });
const subs = rows.map((x) => x.accountId);
const matched = subs.length === r.count && importIdsHash(subs) === r.idsHash;
// Every account the product relies on must be here, not deleted, and known to it.
const wanted = [...new Set(r.subs)];
const known = new Set((await ctx.db.productPerson.findMany({ where: { linkId: link.installId, accountId: { in: wanted } } })).map((x) => x.accountId));
const live = new Set((await ctx.db.account.findMany({ where: { id: { in: wanted }, status: { not: 'deleted' } }, select: { id: true } })).map((x) => x.id as string));
const missing = wanted.filter((s) => !known.has(s) || !live.has(s));
const matched = missing.length === 0;
if (matched) await ctx.db.productLink.update({ where: { installId: link.installId }, data: { importStartedAt: null } });
await logRequest(ctx, link, r, matched ? 'import_finished' : 'import_mismatch', null, req, { count: subs.length, expected: r.count });
return reply({ matched, count: subs.length });
await logRequest(ctx, link, r, matched ? 'import_finished' : 'import_mismatch', null, req, { count: wanted.length - missing.length, expected: wanted.length });
return reply({ matched, count: wanted.length - missing.length, missing: missing.slice(0, 100) });
}
case 'import.abort': {
await ctx.db.productLink.update({ where: { installId: link.installId }, data: { importStartedAt: null } });
+8 -2
View File
@@ -6,7 +6,7 @@ import crypto from 'node:crypto';
import { after, before, describe, test } from 'node:test';
import bcrypt from 'bcryptjs';
import { ACCOUNTS_REQUEST_PATH, IDENTITY_REQUEST_SCHEMA, type ImportPerson } from '@crosscode/contracts';
import { ed25519PublicToPem, generateEd25519, importIdsHash, LINK_HEADERS, newLinkSecret, sealLinkValue, signedHeaders } from '@crosscode/contracts/signing';
import { ed25519PublicToPem, generateEd25519, LINK_HEADERS, newLinkSecret, sealLinkValue, signedHeaders } from '@crosscode/contracts/signing';
import { Browser, PRODUCT_ID, startHarness, type Harness } from './support/harness.js';
import { codeAt, generateSecret } from '../src/lib/totp.js';
@@ -86,7 +86,13 @@ describe('moving Cross Events\' users in', () => {
// bcrypt is replaced with Argon2id at the first sign-in.
assert.match(String((await h.db.account.findUnique({ where: { id: thandi.id } }))!.passwordHash), /^\$argon2id\$/);
const finish = await ask({ type: 'import.finish', count: 2, idsHash: importIdsHash([thandi.id, sipho.id]) });
// A sub Accounts doesn't hold for this product keeps the move open.
const stranger = crypto.randomUUID();
const short = await ask({ type: 'import.finish', subs: [thandi.id, sipho.id, stranger] });
assert.equal(short.body.matched, false);
assert.deepEqual(short.body.missing, [stranger]);
assert.ok((await h.db.productLink.findUnique({ where: { installId: EVENTS_ID } }))!.importStartedAt);
const finish = await ask({ type: 'import.finish', subs: [thandi.id, sipho.id] });
assert.equal(finish.body.matched, true, JSON.stringify(finish.body));
assert.equal((await h.db.productLink.findUnique({ where: { installId: EVENTS_ID } }))!.importStartedAt, null);
});