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
+10 -4
View File
@@ -17,6 +17,7 @@ const { sendMail } = require('../utils/mail');
const { releasesForInstall } = require('../utils/releases');
const { noticesForInstall } = require('../utils/notices');
const ai = require('../utils/ai');
const { PRODUCT_NAMES } = require('../utils/products');
const router = express.Router();
@@ -91,6 +92,11 @@ router.post('/installs/register', registerLimiter, async (req, res) => {
const licence = await prisma.licence.findUnique({ where: { key: normaliseLicenceKey(body.licenceKey) }, include: { install: true, customer: true } });
if (!licence) return fail(res, 404, 'LICENCE_NOT_FOUND', 'That licence key was not found. Check it, or ask your provider for your key.');
if (licence.status === 'revoked') return fail(res, 403, 'LICENCE_REVOKED', 'This licence has been revoked.');
// Protocol v1 is Cross Events only; other products register with v2 (Hub 2.0 step 2).
const product = 'events';
if (licence.product !== product) {
return fail(res, 409, 'WRONG_PRODUCT', `This is a ${PRODUCT_NAMES[licence.product]} licence key, not a ${PRODUCT_NAMES[product]} one. Check you copied the right key.`);
}
if (licence.install && licence.install.url !== url) {
return fail(res, 409, 'LICENCE_IN_USE', 'This licence is already used by another site. Ask your provider to release it if you have moved.');
}
@@ -111,7 +117,7 @@ router.post('/installs/register', registerLimiter, async (req, res) => {
// Same licence, same site → re-register (new secret, same id).
const install = licence.install
? await prisma.install.update({ where: { id: licence.install.id }, data })
: await prisma.install.create({ data: { ...data, customerId: licence.customerId, licenceId: licence.id } });
: await prisma.install.create({ data: { ...data, product: licence.product, customerId: licence.customerId, licenceId: licence.id } });
await prisma.installEvent.create({ data: { installId: install.id, type: 'registered', level: 'info', message: `${licence.install ? 'Re-registered' : 'Registered'} from ${url} (version ${install.version || '?'})`, resolvedAt: new Date() } });
const settings = await getSettings();
@@ -197,7 +203,7 @@ router.post('/installs/update-request', updateRequestLimiter, async (req, res) =
const name = await customerName();
await sendMail({
to: settings.alert_email,
subject: `Cross Events Hub: update request changed by ${name}`,
subject: `Cross Code Hub: update request changed by ${name}`,
text: `${name} (${install.url}) now asks to be updated from ${current} to ${latest}${previous ? ` instead of ${previous}` : ''}.\n\n${link}`,
}).catch(e => console.warn('[update-request] email failed:', e?.message));
}
@@ -209,7 +215,7 @@ router.post('/installs/update-request', updateRequestLimiter, async (req, res) =
const name = await customerName();
await sendMail({
to: settings.alert_email,
subject: `Cross Events Hub: update requested by ${name}`,
subject: `Cross Code Hub: update requested by ${name}`,
text: `${name} (${install.url}) would like to be updated from ${current} to ${latest}.\n\n${link}`,
}).catch(e => console.warn('[update-request] email failed:', e?.message));
}
@@ -238,7 +244,7 @@ router.post('/installs/update-request/cancel', updateRequestLimiter, async (req,
const customer = await prisma.customer.findUnique({ where: { id: install.customerId }, select: { name: true } });
await sendMail({
to: settings.alert_email,
subject: `Cross Events Hub: update request withdrawn by ${customer?.name || install.name}`,
subject: `Cross Code Hub: update request withdrawn by ${customer?.name || install.name}`,
text: `${customer?.name || install.name} (${install.url}) withdrew their update request. No need to update the site for now.\n\n${(process.env.FRONTEND_URL || '').replace(/\/$/, '')}/installs/${install.id}`,
}).catch(e => console.warn('[update-request] email failed:', e?.message));
}