/** * 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 are invoiced (Accounts is free and never invoiced). */ const BILLABLE = ['events', 'website', 'app']; module.exports = { PRODUCTS, PRODUCT_NAMES, KEY_PREFIXES, BILLABLE, productOfKey, isProduct };