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
+5
View File
@@ -12,6 +12,7 @@ const billing = require('../utils/billing');
const compute = require('../utils/billing/compute');
const { ymd, day, today } = require('../utils/billing/dates');
const { TIERS } = require('../utils/billing/tiers');
const { BILLABLE, PRODUCT_NAMES } = require('../utils/products');
const router = express.Router();
router.use(protect);
@@ -279,6 +280,10 @@ router.put('/licences/:id', wrap(async (req, res) => {
}
}
const merged = { ...existing, ...data };
// Until billing per customer (Hub 2.0 step 4) only Events has prices; Accounts is never invoiced.
if (merged.billingCycle !== 'none' && !BILLABLE.includes(existing.product)) {
throw bad(`${PRODUCT_NAMES[existing.product]} licences can't be invoiced yet.`);
}
if (merged.billingCycle !== 'none') {
if (!merged.billingStart) throw bad('Set the date billing starts.');
if (!merged.nextInvoiceDate) data.nextInvoiceDate = merged.billingStart;