Files
crosscode-platform/apps/events/backend/src/accounts/autoConnect.ts
T
joshuaandClaude Opus 5.5 63d36c3ecf 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>
2026-11-19 14:28:54 +02:00

26 lines
1.1 KiB
TypeScript

/**
* Cross Events 3.0 connects itself to the church's Accounts (docs/EVENTS-3.0-PLAN.md §9, Hub
* 2.5.0): after a heartbeat, when the Hub lists an Accounts for this church and this site isn't
* linked to one, it connects (as an admin pressing Connect under Linked products would). Once
* only: after it worked (`accounts_auto_connected`), an admin's Disconnect stays as it is.
*/
import { connectTo } from '../links/connect';
import { linkedProducts } from '../links/store';
import { accountsLink } from './client';
import { getSetting, setSetting } from './mode';
export const AUTO_KEY = 'accounts_auto_connected';
export async function connectAccountsIfListed(now = new Date()): Promise<'connected' | 'skipped'> {
if (await getSetting(AUTO_KEY)) return 'skipped';
if (await accountsLink()) {
await setSetting(AUTO_KEY, now.toISOString());
return 'skipped';
}
const listed = (await linkedProducts()).find((p) => p.product === 'accounts');
if (!listed) return 'skipped';
await connectTo(listed.installId, { id: null, role: 'system' }, null, now);
await setSetting(AUTO_KEY, now.toISOString());
return 'connected';
}