Hub 2.0 step 1: products foundation

- Product enum (events, accounts, website, app) on Licence and Install,
  Install.publicKey; existing rows are events
- One open licence per product per customer: partial unique index, with a
  migration guard that names customers with duplicates (npm run check:hub2
  lists them beforehand)
- Licence keys per product (CEH-, CCA-, CCW-, CCP-); free Accounts licence
  created with the first other product licence
- Protocol v1 registers Events licences only (409 WRONG_PRODUCT); only Events
  licences can be invoiced until billing per customer
- Cross Code Hub in the UI, emails and PDFs
- @crosscode/contracts 1.0.0 vendored (backend/vendor)
- Steps merge into release/2.0, not main (plan updated)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-04 15:28:06 +02:00
co-authored by Claude Opus 5.5
parent fe0f2638c6
commit ad602b2846
30 changed files with 544 additions and 49 deletions
+42 -11
View File
@@ -7,6 +7,7 @@ import { ArrowLeft, Copy, KeyRound } from "lucide-react";
import { api, errorText } from "@/lib/api";
import { ago, fmtDate } from "@/lib/format";
import { PLANS } from "@/lib/tiers";
import { KEY_WHERE, PRODUCTS, PRODUCT_NAMES, byProduct, type Product } from "@/lib/products";
import type { Customer, Licence, LicenceStatus } from "@/lib/types";
import { Badge, Loading, Message, PageTitle } from "@/components/ui";
import { CustomerBilling } from "@/components/billing/CustomerBilling";
@@ -62,6 +63,7 @@ function LicenceCard({ licence, onSaved, setMsg }: { licence: Licence; onSaved:
<div className="card space-y-3">
<div className="flex flex-wrap items-center gap-2">
<KeyRound className="h-4 w-4 text-slate-400" />
<span className="font-semibold">{PRODUCT_NAMES[licence.product]}</span>
<code className="text-sm font-semibold tracking-wide">{licence.key}</code>
<button className="text-xs text-indigo-600 hover:underline" onClick={() => navigator.clipboard?.writeText(licence.key)} aria-label="Copy key"><Copy className="inline h-3.5 w-3.5" /> Copy</button>
<span className="ml-auto"><Badge value={licence.status} /></span>
@@ -69,16 +71,26 @@ function LicenceCard({ licence, onSaved, setMsg }: { licence: Licence; onSaved:
<div className="text-sm text-slate-600">
{licence.install
? <>Used by <Link href={`/installs/${licence.install.id}`} className="text-indigo-600 hover:underline">{licence.install.url}</Link> · last heartbeat {ago(licence.install.lastHeartbeatAt)}</>
: "Not used yet — enter this key in the church's Cross Events setup (or Site settings → Licence)."}
: `Not used yet — enter this key in ${KEY_WHERE[licence.product]}.`}
</div>
<div className="grid gap-3 sm:grid-cols-6">
<div>
<label className="label" htmlFor={`plan-${licence.id}`}>Plan</label>
<select id={`plan-${licence.id}`} className="input" value={form.plan} onChange={e => setForm({ ...form, plan: e.target.value })}>
{!PLANS.includes(form.plan) && <option value={form.plan}>{form.plan}</option>}
{PLANS.map(p => <option key={p} value={p}>{p}</option>)}
</select>
<p className="mt-1 text-xs text-slate-500">Shown on the church&apos;s Licence page. Billing and founding status are under Billing below.</p>
{licence.product === "events" ? (
<select id={`plan-${licence.id}`} className="input" value={form.plan} onChange={e => setForm({ ...form, plan: e.target.value })}>
{!PLANS.includes(form.plan) && <option value={form.plan}>{form.plan}</option>}
{PLANS.map(p => <option key={p} value={p}>{p}</option>)}
</select>
) : licence.product === "accounts" ? (
<input id={`plan-${licence.id}`} className="input" value="Included" disabled />
) : (
<input id={`plan-${licence.id}`} className="input" value={form.plan} onChange={e => setForm({ ...form, plan: e.target.value })} />
)}
<p className="mt-1 text-xs text-slate-500">
{licence.product === "accounts"
? "Free: comes with the church's other products."
: "Shown on the church's Licence page. Billing and founding status are under Billing below."}
</p>
</div>
<div>
<label className="label">Status</label>
@@ -125,7 +137,7 @@ export default function CustomerPage() {
const { id } = useParams<{ id: string }>();
const [c, setC] = useState<Customer | null>(null);
const [form, setForm] = useState({ name: "", contactName: "", email: "", phone: "", notes: "" });
const [newLicence, setNewLicence] = useState({ expiresAt: "", graceDays: "14" });
const [newLicence, setNewLicence] = useState<{ product: Product | ""; expiresAt: string; graceDays: string }>({ product: "", expiresAt: "", graceDays: "14" });
const [msg, setMsg] = useState<Msg>(null);
const load = useCallback(() => api<Customer>(`/api/admin/customers/${id}`).then(x => {
@@ -136,6 +148,12 @@ export default function CustomerPage() {
if (!c) return msg ? <Message msg={msg} /> : <Loading />;
// One open (not revoked) licence per product; Accounts comes with the first other product.
const taken = new Set(c.licences.filter(l => l.status !== "revoked").map(l => l.product));
const available = PRODUCTS.filter(p => !taken.has(p));
const product: Product | undefined = newLicence.product && available.includes(newLicence.product) ? newLicence.product : available.find(p => p !== "accounts") || available[0];
const licences = [...c.licences].sort((a, b) => byProduct(a, b) || (a.status === "revoked" ? 1 : 0) - (b.status === "revoked" ? 1 : 0));
const saveDetails = async (e: React.FormEvent) => {
e.preventDefault();
try {
@@ -148,11 +166,15 @@ export default function CustomerPage() {
const generate = async (e: React.FormEvent) => {
e.preventDefault();
try {
const l = await api<Licence>(`/api/admin/customers/${id}/licences`, {
const l = await api<Licence & { accountsLicence: Licence | null }>(`/api/admin/customers/${id}/licences`, {
method: "POST",
body: { expiresAt: newLicence.expiresAt ? `${newLicence.expiresAt}T23:59:59+02:00` : null, graceDays: newLicence.graceDays },
body: { product, expiresAt: newLicence.expiresAt ? `${newLicence.expiresAt}T23:59:59+02:00` : null, graceDays: newLicence.graceDays },
});
setMsg({
type: "ok",
text: `${PRODUCT_NAMES[l.product]} licence ${l.key} created. Send it to the church for their setup.`
+ (l.accountsLicence ? ` Their Accounts licence (free) was created too: ${l.accountsLicence.key}.` : ""),
});
setMsg({ type: "ok", text: `Licence ${l.key} created. Send it to the church for their setup.` });
load();
} catch (err) { setMsg({ type: "err", text: errorText(err) }); }
};
@@ -176,12 +198,21 @@ export default function CustomerPage() {
<div className="space-y-4">
<h2 className="font-semibold">Licences</h2>
{c.licences.map(l => <LicenceCard key={`${l.id}-${l.status}-${l.expiresAt}`} licence={l} onSaved={load} setMsg={setMsg} />)}
{licences.map(l => <LicenceCard key={`${l.id}-${l.status}-${l.expiresAt}`} licence={l} onSaved={load} setMsg={setMsg} />)}
{product ? (
<form onSubmit={generate} className="card flex flex-wrap items-end gap-3">
<div>
<label className="label" htmlFor="new-product">Product</label>
<select id="new-product" className="input" value={product} onChange={e => setNewLicence({ ...newLicence, product: e.target.value as Product })}>
{available.map(p => <option key={p} value={p}>{PRODUCT_NAMES[p]}</option>)}
</select>
</div>
<div><label className="label">Expires (optional)</label><input type="date" className="input" value={newLicence.expiresAt} onChange={e => setNewLicence({ ...newLicence, expiresAt: e.target.value })} /></div>
<div><label className="label">Grace (days)</label><input type="number" min={0} max={90} className="input w-24" value={newLicence.graceDays} onChange={e => setNewLicence({ ...newLicence, graceDays: e.target.value })} /></div>
<button className="btn-primary"><KeyRound className="h-4 w-4" /> Generate licence</button>
<p className="w-full text-xs text-slate-500">One licence per product (revoke one to replace it). Accounts is free and is created with the first other product.</p>
</form>
) : <p className="text-sm text-slate-500">This customer has a licence for every product.</p>}
</div>
</div>
+3 -2
View File
@@ -8,6 +8,7 @@ import { api, errorText } from "@/lib/api";
import { ago } from "@/lib/format";
import { matches, usePaged } from "@/lib/paging";
import type { Customer } from "@/lib/types";
import { PRODUCT_NAMES, byProduct } from "@/lib/products";
import { Badge, Loading, Message, PageTitle, Pager, SearchInput } from "@/components/ui";
export default function CustomersPage() {
@@ -56,8 +57,8 @@ export default function CustomersPage() {
{paged.rows.map(c => (
<tr key={c.id} className="border-t hover:bg-slate-50">
<td className="p-3"><Link href={`/customers/${c.id}`} className="font-medium text-indigo-700 hover:underline">{c.name}</Link><div className="text-xs text-slate-500">{[c.contactName, c.email].filter(Boolean).join(" · ")}</div></td>
<td className="p-3">{c.licences.length ? c.licences.map(l => <span key={l.id} className="mr-1"><Badge value={l.status} /></span>) : <span className="text-xs text-slate-400">none</span>}</td>
<td className="p-3">{c.installs.length ? c.installs.map(i => <div key={i.id} className="text-xs">{i.url} <span className="text-slate-400">· {ago(i.lastHeartbeatAt)}</span></div>) : <span className="text-xs text-slate-400">not connected</span>}</td>
<td className="p-3">{c.licences.length ? [...c.licences].sort(byProduct).map(l => <span key={l.id} className="mr-2 inline-flex items-center gap-1 text-xs">{PRODUCT_NAMES[l.product]} <Badge value={l.status} /></span>) : <span className="text-xs text-slate-400">none</span>}</td>
<td className="p-3">{c.installs.length ? c.installs.map(i => <div key={i.id} className="text-xs"><span className="text-slate-500">{PRODUCT_NAMES[i.product]}:</span> {i.url} <span className="text-slate-400">· {ago(i.lastHeartbeatAt)}</span></div>) : <span className="text-xs text-slate-400">not connected</span>}</td>
</tr>
))}
</tbody>
@@ -8,6 +8,7 @@ import { api, errorText } from "@/lib/api";
import { ago, bytes, fmtDate, rand, randFine } from "@/lib/format";
import { usePaged } from "@/lib/paging";
import { tierForBand, tierPrice } from "@/lib/tiers";
import { PRODUCT_NAMES } from "@/lib/products";
import type { AiHelperUse, AiMonth, AiStatus, Health, InstallEvent, InstallSummary, Licence, Stats } from "@/lib/types";
import { Badge, Loading, Message, PageTitle, Pager } from "@/components/ui";
@@ -63,7 +64,7 @@ export default function InstallPage() {
<>
<Link href="/" className="mb-2 inline-flex items-center gap-1 text-sm text-slate-500 hover:underline"><ArrowLeft className="h-4 w-4" /> Installs</Link>
<PageTitle
title={d.customer.name}
title={`${d.customer.name}: ${PRODUCT_NAMES[d.summary.product]}`}
subtitle={<a href={d.url} target="_blank" rel="noopener noreferrer" className="text-indigo-600 hover:underline">{d.url}</a>}
actions={<Badge value={d.summary.status} />}
/>
+2 -1
View File
@@ -6,6 +6,7 @@ import { api, errorText } from "@/lib/api";
import { ago, fmtDate } from "@/lib/format";
import { matches, usePaged } from "@/lib/paging";
import type { InstallSummary } from "@/lib/types";
import { PRODUCT_NAMES } from "@/lib/products";
import { Badge, Loading, PageTitle, Pager, SearchInput, Stat } from "@/components/ui";
type Dashboard = {
@@ -81,7 +82,7 @@ export default function OverviewPage() {
<tr key={i.id} className="border-t align-top hover:bg-slate-50">
<td className="p-3">
<Link href={`/installs/${i.id}`} className="font-medium text-indigo-700 hover:underline">{i.customer?.name || i.name}</Link>
<div className="text-xs text-slate-500">{i.url}</div>
<div className="text-xs text-slate-500">{PRODUCT_NAMES[i.product]} · {i.url}</div>
</td>
<td className="p-3">
<Badge value={i.status} />
+1 -1
View File
@@ -290,7 +290,7 @@ export default function SettingsPage() {
<label className="mt-1 flex items-center gap-2 text-xs text-slate-600"><input type="checkbox" checked={smtpPass.clear} onChange={e => setSmtpPass({ value: "", clear: e.target.checked })} /> Remove the saved password</label>
)}
</div>
<div><label className="label" htmlFor="smtp_from">From address</label><input id="smtp_from" className="input" placeholder="Cross Events Hub <hub@crosscode.co.za>" value={settings.smtp_from ?? ""} onChange={e => setSettings({ ...settings, smtp_from: e.target.value })} /><p className="mt-1 text-xs text-slate-500">Blank uses the username.</p></div>
<div><label className="label" htmlFor="smtp_from">From address</label><input id="smtp_from" className="input" placeholder="Cross Code Hub <hub@crosscode.co.za>" value={settings.smtp_from ?? ""} onChange={e => setSettings({ ...settings, smtp_from: e.target.value })} /><p className="mt-1 text-xs text-slate-500">Blank uses the username.</p></div>
<button className="btn-primary">Save email settings</button>
<div className="border-t border-slate-100 pt-3">
<label className="label" htmlFor="smtp_test_to">Send a test email to</label>
+1 -1
View File
@@ -2,7 +2,7 @@ import type { Metadata } from "next";
import "./globals.css";
export const metadata: Metadata = {
title: "Cross Events Hub",
title: "Cross Code Hub",
description: "Installs, licences and health for Cross Events",
robots: { index: false, follow: false },
};
+1 -1
View File
@@ -57,7 +57,7 @@ export default function LoginPage() {
<div className="flex min-h-screen items-center justify-center p-4">
<div className="card w-full max-w-sm">
<Logo markOnly className="mb-3 h-10 w-10" />
<h1 className="text-xl font-semibold">Cross Events Hub</h1>
<h1 className="text-xl font-semibold">Cross Code Hub</h1>
{step === "password" && (
<form onSubmit={submitPassword} className="mt-5 space-y-4">
<div>
+2 -2
View File
@@ -13,7 +13,7 @@ const STATUS_TONE: Record<string, string> = {
};
const STATUS_LABEL: Record<string, string> = { ok: "Healthy", warning: "Warning", critical: "Critical", info: "Info" };
/** The Cross Events Hub mark (same artwork as app/icon.svg), with the name beside it unless markOnly. */
/** The Cross Code Hub mark (same artwork as app/icon.svg), with the name beside it unless markOnly. */
export function Logo({ className = "h-8 w-8", markOnly }: { className?: string; markOnly?: boolean }) {
const mark = (
<svg viewBox="0 0 64 64" className={`${className} shrink-0`} aria-hidden="true">
@@ -25,7 +25,7 @@ export function Logo({ className = "h-8 w-8", markOnly }: { className?: string;
return (
<span className="flex items-center gap-2.5">
{mark}
<span className="font-semibold leading-tight">Cross Events Hub</span>
<span className="font-semibold leading-tight">Cross Code Hub</span>
</span>
);
}
+23
View File
@@ -0,0 +1,23 @@
// The Cross Code products (Hub 2.0). The same list as backend/src/utils/products.js.
export type Product = "events" | "accounts" | "website" | "app";
export const PRODUCTS: Product[] = ["events", "accounts", "website", "app"];
export const PRODUCT_NAMES: Record<Product, string> = {
events: "Cross Events",
accounts: "Accounts",
website: "Church Website",
app: "Church App",
};
/** Where the church enters a licence key, per product. */
export const KEY_WHERE: Record<Product, string> = {
events: "the church's Cross Events setup (or Site settings → Licence)",
accounts: "the church's Accounts setup",
website: "the church's Website setup",
app: "the church's App setup",
};
/** Product order for lists: Events, Accounts, Website, App. */
export const byProduct = <T extends { product: Product }>(a: T, b: T) => PRODUCTS.indexOf(a.product) - PRODUCTS.indexOf(b.product);
+5 -1
View File
@@ -1,8 +1,11 @@
import type { Product } from "./products";
export type Problem = { type: string; level: "info" | "warning" | "critical"; message: string };
export type LicenceStatus = "active" | "suspended" | "revoked";
export type InstallSummary = {
id: string;
product: Product;
name: string;
url: string;
customer: { id: string; name: string } | null;
@@ -18,6 +21,7 @@ export type InstallSummary = {
export type Licence = {
id: string;
key: string;
product: Product;
plan: string;
status: LicenceStatus;
expiresAt: string | null;
@@ -38,7 +42,7 @@ export type Customer = {
notes: string | null;
createdAt: string;
licences: Licence[];
installs: { id: string; url: string; name?: string; lastHeartbeatAt: string | null; releasedAt?: string | null; version?: string | null }[];
installs: { id: string; product: Product; url: string; name?: string; lastHeartbeatAt: string | null; releasedAt?: string | null; version?: string | null }[];
};
export type Health = {