Accounts: deploy hooks, env template, export, docs
scripts/products/accounts.sh (backup with pg_dump, build with the shared packages, PM2, export, keep, failed-migration recovery); accounts in SUPPORTED_PRODUCTS so deploy updates it where a church has it. Env template in both places, PM2 example, export script, /api/health version from package.json. README, CHANGELOG, WHATS-NEW; the plan's changes while building and what's still to do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
# Changelog — Accounts
|
||||
|
||||
## [1.0.0] - unreleased
|
||||
|
||||
The first release (docs/ACCOUNTS-1.0-PLAN.md). Not tagged yet: needs Hub 2.3.0, `crosscode
|
||||
install`/`add` for Accounts, a Playwright run of the pages and the VM test first.
|
||||
|
||||
### Added
|
||||
|
||||
- OpenID Connect provider (oidc-provider 9.13.3): authorization code with PKCE (S256) required,
|
||||
ES256 keys made on first start, `crosscode.identity/1` claims in the ID token, no refresh tokens,
|
||||
RP-initiated logout and OIDC Back-Channel Logout. Clients are the linked products (Connect,
|
||||
`crosscode.link/1`), with exact redirect addresses and the client secret derived from the link.
|
||||
- Sign-in steps that all return to the product and page they started from: password, sign-up with
|
||||
an emailed code, two-step sign-in (authenticator app, email, WhatsApp, recovery codes) and setting
|
||||
it up when a product asks (`acr_values=mfa`) or for admins, privacy notice (asked again when a new
|
||||
version is published), news question, forgot / reset password.
|
||||
- The account page: details, email change by link, password, two-step sign-in, recovery codes,
|
||||
news consent, recent activity, sign out everywhere, download my data (bundled from every linked
|
||||
product), delete my account (approved by an admin, then every product, retried when a product
|
||||
says "not yet").
|
||||
- Admin: people (access-logged), deletion requests, the church profile (`crosscode.church/1`,
|
||||
served at `/api/church/v1`, `church.changed` to products), linked products, sign-in settings,
|
||||
email and WhatsApp, privacy notice versions, licence, audit log. First-run `/setup`.
|
||||
- Hub protocol v2 (product `accounts`, `CCA-` licence; never read-only), registering by itself from
|
||||
`HUB_LICENCE_KEY`.
|
||||
- `crosscode` hooks (`scripts/products/accounts.sh`), `env.template.json`, PM2 example.
|
||||
+18
-1
@@ -1,3 +1,20 @@
|
||||
# Accounts
|
||||
|
||||
Placeholder: the per-church sign-in (OpenID Connect). Built in phase 3 of ROADMAP-v3 (see §3 there).
|
||||
The church's sign-in for every Cross Code product (ROADMAP-v3 §3, phase 3; plan and decisions in
|
||||
[docs/ACCOUNTS-1.0-PLAN.md](../../docs/ACCOUNTS-1.0-PLAN.md)). A small OpenID Connect provider per
|
||||
church at `accounts.<address>`: people sign in once and are signed in to all the church's products,
|
||||
coming back to the page they started on. Members never see it as a product; admins manage people,
|
||||
sign-in settings, linked products and the church profile here.
|
||||
|
||||
- `backend/`: Express + oidc-provider 9 + Prisma (ES modules). `npm run dev`, `npm test` (Node's test
|
||||
runner through tsx: the whole app against an in-memory database, with a test product on
|
||||
openid-client), `npm run build`.
|
||||
- `frontend/`: Next.js 16 pages (sign-in steps, account page, admin, setup), strict CSP with a nonce
|
||||
per page, the church's colours from its profile.
|
||||
- Roles stay in each product: Accounts only knows who someone is (plan §2, "Roles stay in each
|
||||
product").
|
||||
- Products sign in with `@crosscode/auth-client` (packages/auth-client).
|
||||
|
||||
Local development: Postgres in `backend/.env` (`DATABASE_URL`, `ACCOUNTS_URL=http://localhost:3200`,
|
||||
`LINKS_ALLOW_PRIVATE=true`), `npx prisma migrate deploy`, then `npm run dev` in both folders (the
|
||||
frontend runs on 3200 with `next dev -p 3200` and sends /api to the backend on 5200).
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
# What's new in Accounts
|
||||
|
||||
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.0.0
|
||||
|
||||
- **One sign-in for all your church's sites and apps.** People sign in once with their own account
|
||||
and are signed in to the church website, the app and Cross Events, and come back to the page they
|
||||
were on.
|
||||
- **Secure by default:** two-step sign-in with an authenticator app, email or WhatsApp, recovery
|
||||
codes, and required for admins.
|
||||
- **People control their own information:** they change their details, choose their news, download
|
||||
their data or ask for their account to be deleted, all in one place.
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Accounts' part of a church's export when it leaves (`crosscode export` / uninstall, AGENT-1.0-PLAN
|
||||
* §9): `accounts.json` in --out-dir, with the church profile and the people in plain terms (the
|
||||
* same person fields as `crosscode.church-export/1`; no passwords, 2FA secrets or sign-in logs).
|
||||
*
|
||||
* npx tsx scripts/export-church.ts --out-dir <dir>
|
||||
*/
|
||||
import 'dotenv/config';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { PrismaPg } from '@prisma/adapter-pg';
|
||||
import { PrismaClient } from '../src/generated/prisma/client.js';
|
||||
import { createCtx } from '../src/context.js';
|
||||
import { loadConfig } from '../src/lib/config.js';
|
||||
import { church } from '../src/church/profile.js';
|
||||
|
||||
const i = process.argv.indexOf('--out-dir');
|
||||
const out = i > 0 ? process.argv[i + 1] : null;
|
||||
if (!out) {
|
||||
console.error('Usage: export-church.ts --out-dir <dir>');
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
const db = new PrismaClient({ adapter: new PrismaPg({ connectionString: process.env.DATABASE_URL! }) });
|
||||
const ctx = createCtx(loadConfig(), db);
|
||||
const people = await db.account.findMany({ where: { status: { not: 'deleted' } }, orderBy: { name: 'asc' } });
|
||||
const acceptances = await db.noticeAcceptance.findMany({ orderBy: { acceptedAt: 'asc' } });
|
||||
const accepted = new Map(acceptances.map((a) => [a.accountId, a.acceptedAt]));
|
||||
const data = {
|
||||
product: 'accounts',
|
||||
generatedAt: new Date().toISOString(),
|
||||
church: await church(ctx),
|
||||
people: people.map((p, n) => ({
|
||||
ref: `p${n + 1}`, name: p.name, email: p.email, phone: p.phone, role: p.role === 'admin' ? 'accounts admin' : 'member',
|
||||
createdAt: p.createdAt.toISOString(),
|
||||
consent: { email: p.newsEmail, whatsapp: p.newsWhatsApp, privacyNoticeAcceptedAt: accepted.get(p.id)?.toISOString() ?? null },
|
||||
})),
|
||||
};
|
||||
fs.mkdirSync(out, { recursive: true });
|
||||
fs.writeFileSync(path.join(out, 'accounts.json'), JSON.stringify(data, null, 2), { mode: 0o600 });
|
||||
console.log(` accounts.json: ${data.people.length} people`);
|
||||
await db.$disconnect();
|
||||
@@ -19,6 +19,7 @@ import { LOGOUT_JS } from './oidc/pages.js';
|
||||
import { publicRouter } from './public/routes.js';
|
||||
import { setupRouter } from './setup/routes.js';
|
||||
import { health } from './hub/client.js';
|
||||
import { appVersion } from './lib/version.js';
|
||||
|
||||
export function createApp(ctx: Ctx, provider: Provider) {
|
||||
const app = express();
|
||||
@@ -35,7 +36,7 @@ export function createApp(ctx: Ctx, provider: Provider) {
|
||||
|
||||
app.get('/api/health', async (_req, res) => {
|
||||
const h = await health(ctx);
|
||||
res.status(h.db ? 200 : 503).json({ status: h.db ? 'ok' : 'error', product: 'accounts', version: process.env.npm_package_version || '1.0.0', db: h.db });
|
||||
res.status(h.db ? 200 : 503).json({ status: h.db ? 'ok' : 'error', product: 'accounts', version: appVersion(), db: h.db });
|
||||
});
|
||||
|
||||
app.get('/api/static/logout.js', (_req, res) => {
|
||||
|
||||
@@ -9,6 +9,7 @@ import { hub } from '@crosscode/contracts';
|
||||
import type { Ctx } from '../context.js';
|
||||
import { hubPublicKey, verifyToken } from './licence.js';
|
||||
import { keyPair, saveLinkedProducts } from '../links/store.js';
|
||||
import { appVersion } from '../lib/version.js';
|
||||
|
||||
export const PROTOCOL_VERSION = 2;
|
||||
const TIMEOUT_MS = 15000;
|
||||
@@ -41,9 +42,7 @@ async function post(ctx: Ctx, path: string, body: unknown, sign?: { installId: s
|
||||
return data;
|
||||
}
|
||||
|
||||
function version(): string {
|
||||
return process.env.npm_package_version || '1.0.0';
|
||||
}
|
||||
const version = appVersion;
|
||||
|
||||
export async function health(ctx: Ctx) {
|
||||
let db = true;
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* The running version, from the backend's package.json (src/lib → ../../package.json in development,
|
||||
* dist/lib → ../../package.json when built), so /api/health tells `crosscode deploy` the truth
|
||||
* however the process was started (PM2 doesn't set npm_package_version).
|
||||
*/
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
let cached: string | null = null;
|
||||
|
||||
export function appVersion(): string {
|
||||
if (!cached) {
|
||||
try {
|
||||
const file = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..', 'package.json');
|
||||
cached = (JSON.parse(fs.readFileSync(file, 'utf8')) as { version: string }).version;
|
||||
} catch {
|
||||
cached = '0.0.0';
|
||||
}
|
||||
}
|
||||
return cached;
|
||||
}
|
||||
@@ -17,5 +17,5 @@
|
||||
"outDir": "dist",
|
||||
"types": ["node"]
|
||||
},
|
||||
"include": ["src", "tests", "prisma.config.ts"]
|
||||
"include": ["src", "tests", "scripts", "prisma.config.ts"]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// PM2 config template. Each install keeps its own copy as ecosystem.config.cjs (not in git, so
|
||||
// deploys never change it); crosscode creates it from this file the first time with the church's
|
||||
// PM2 names and ports.
|
||||
module.exports = {
|
||||
apps: [
|
||||
{
|
||||
name: 'accounts-backend',
|
||||
cwd: __dirname + '/backend',
|
||||
script: 'dist/index.js',
|
||||
env: { NODE_ENV: 'production' },
|
||||
max_memory_restart: '400M',
|
||||
},
|
||||
{
|
||||
name: 'accounts-frontend',
|
||||
cwd: __dirname + '/frontend',
|
||||
script: 'npm',
|
||||
args: 'start -- -p 3200',
|
||||
env: { NODE_ENV: 'production' },
|
||||
max_memory_restart: '400M',
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"schema": "crosscode.env-template/1",
|
||||
"product": "accounts",
|
||||
"files": {
|
||||
"backend/.env": [
|
||||
{ "name": "NODE_ENV", "layer": "generated", "required": true, "description": "production" },
|
||||
{ "name": "PORT", "layer": "install", "from": "{apiPort}", "required": true, "description": "The backend's port (from the Hub's port list)" },
|
||||
{ "name": "DATABASE_URL", "layer": "generated", "required": true, "description": "Made on the server with a new password; never leaves it" },
|
||||
{ "name": "ACCOUNTS_SECRET", "layer": "generated", "required": true, "description": "Encrypts stored secrets (signing keys, 2FA secrets, link secrets) and signs cookies: never change it" },
|
||||
{ "name": "ACCOUNTS_URL", "layer": "install", "from": "https://{domain}", "required": true, "description": "The public address; the OIDC issuer is <this>/api/oidc" },
|
||||
{ "name": "TRUST_PROXY", "layer": "server", "required": true, "description": "Behind frp: loopback" },
|
||||
{ "name": "APP_TIMEZONE", "layer": "install", "default": "Africa/Johannesburg" },
|
||||
{ "name": "HUB_URL", "layer": "defaults", "default": "https://hub.crosscode.co.za" },
|
||||
{ "name": "HUB_PUBLIC_KEY", "layer": "defaults", "description": "Only for a Hub other than production" },
|
||||
{ "name": "HUB_LICENCE_KEY", "layer": "install", "description": "A Hub install registers by itself with this (CCA-…)" },
|
||||
{ "name": "HUB_ADMIN_NAME", "layer": "install" },
|
||||
{ "name": "HUB_ADMIN_EMAIL", "layer": "install", "description": "Setup only lets this address become the first admin" },
|
||||
{ "name": "JOBS_ENABLED", "layer": "defaults", "default": "true" }
|
||||
],
|
||||
"frontend/.env.production": [
|
||||
{ "name": "ACCOUNTS_API_URL", "layer": "install", "from": "http://127.0.0.1:{apiPort}", "required": true, "description": "Where the pages reach the backend on this server" }
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user