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
+40
View File
@@ -0,0 +1,40 @@
/**
* The Cross Code products a church can have (Hub 2.0, ROADMAP-v3 §5). The same names as the
* `Product` enum in schema.prisma and `productSchema` in @crosscode/contracts.
*
* - A customer has at most one licence per product that isn't revoked (a partial unique index).
* - Accounts is free and comes with any other product: its licence is created with the first one.
*/
const PRODUCTS = ['events', 'accounts', 'website', 'app'];
const PRODUCT_NAMES = {
events: 'Cross Events',
accounts: 'Accounts',
website: 'Church Website',
app: 'Church App',
};
/** Licence key prefixes. CEH- (Cross Events Hub) predates 2.0 and stays for Events. */
const KEY_PREFIXES = {
events: 'CEH',
accounts: 'CCA',
website: 'CCW',
app: 'CCP',
};
/** The product a licence key is for, from its prefix, or null. */
function productOfKey(key) {
const prefix = String(key || '').slice(0, 3).toUpperCase();
return PRODUCTS.find(p => KEY_PREFIXES[p] === prefix) || null;
}
const isProduct = p => PRODUCTS.includes(p);
/**
* Products that can be invoiced. Until billing per customer (Hub 2.0 step 4) only Events has
* prices; Accounts is never invoiced.
*/
const BILLABLE = ['events'];
module.exports = { PRODUCTS, PRODUCT_NAMES, KEY_PREFIXES, BILLABLE, productOfKey, isProduct };