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:
2026-11-18 14:18:40 +02:00
co-authored by Claude Opus 5.5
parent a3e3921b4f
commit 7f34e184e1
17 changed files with 374 additions and 12 deletions
+2 -1
View File
@@ -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) => {
+2 -3
View File
@@ -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;
+22
View File
@@ -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;
}