// White-label resolution — BY HOSTNAME, never per deployment. // // One image, many brands. Brand, gui theme row, IAM client id and OIDC issuer // are all a pure function of the Host header, so the same container serves // lux.cloud, zoo.network, hanzo.ai and pars.id without a rebuild, an env var or // a per-deployment override. Nothing here reads process.env. // // This module is VALUES ONLY (no React, no DOM) so it resolves identically in // three places that must agree: // - the Next/SSR server, from `req.headers.host` // - the browser, from `location.host` // - an edge/middleware rewrite, from the incoming URL // // Logos, SEO copy and marketing palettes live in @luxfi/brand. This is the // runtime identity the UI layer needs and nothing more. // --------------------------------------------------------------------------- // Branding = VALUE, not place. // The ONE spot brand hex is allowed to live (project rule: never hardcode hex // in components). It lives HERE, beside the identity table it colours, rather // than in ./lux.config — that module builds the gui engine, and an identity // value that drags a Tamagui config behind it cannot be read by a server // component, a route handler or the `@luxfi/ui/iam` client. lux.config imports // these; nothing imports lux.config to get them. // --------------------------------------------------------------------------- export const LUX_BRAND = { lux: '#7000FF', zoo: '#6C5EFB', hanzo: '#EA580C', pars: '#1C3879', // bootno.de is its own white label with its own IdP (id.bootno.de) — accent // taken from the bootnode console's own brand default, not invented here. bootnode: '#3B82F6', } as const; export const PARS_GOLD = '#C8A45C'; export type LuxBrand = keyof typeof LUX_BRAND; export type Org = LuxBrand; export interface OrgIdentity { /** Org id — also the gui child-theme suffix (`dark_lux`, `dark_zoo`, …). */ readonly org: Org; /** Display name for chrome (header, title, sign-in copy). */ readonly name: string; /** Canonical apex domain. */ readonly domain: string; /** IAM/OIDC host. The issuer is `https://` + this. */ readonly iamDomain: string; /** Brand accent hex — the same value the gui child-theme row is built from. */ readonly accent: string; /** Foreground used on top of the accent. */ readonly accentForeground: string; } // The ONE table. Every hostname in the fleet resolves into one of these rows. const ORGS: Readonly> = { lux: { org: 'lux', name: 'Lux', domain: 'lux.network', iamDomain: 'lux.id', accent: LUX_BRAND.lux, accentForeground: '#FFFFFF', }, zoo: { org: 'zoo', name: 'Zoo', domain: 'zoo.ngo', // Zoo's issuer is `zoolabs.id` — the one row where it is not `.id`, // and the one every hand-rolled branding map gets wrong. `id.zoo.network` // ANSWERS, which is why it keeps being copied around, but it is an alias: // its own discovery document advertises // issuer https://zoolabs.id // authorization_endpoint https://zoolabs.id/v1/iam/oauth/authorize // jwks_uri https://zoolabs.id/v1/iam/.well-known/jwks // so a client configured on the alias validates `iss` against a string the // IdP never emits and rejects every token it is given — the exact shape of // the lux.id outage. `zoo.id` is not an IdP at all (no discovery document). iamDomain: 'zoolabs.id', accent: LUX_BRAND.zoo, accentForeground: '#FFFFFF', }, bootnode: { org: 'bootnode', name: 'Bootnode', domain: 'bootno.de', iamDomain: 'id.bootno.de', accent: LUX_BRAND.lux, accentForeground: '#FFFFFF', }, hanzo: { org: 'hanzo', name: 'Hanzo', domain: 'hanzo.ai', iamDomain: 'hanzo.id', accent: LUX_BRAND.hanzo, accentForeground: '#FFFFFF', }, pars: { org: 'pars', name: 'Pars', domain: 'pars.id', iamDomain: 'pars.id', accent: LUX_BRAND.pars, accentForeground: PARS_GOLD, }, }; // Registrable domains that belong to each org. Matched against the hostname // SUFFIX on a label boundary, so `mpc.lux.cloud` and `lux.cloud` both hit `lux` // while `notlux.cloud` does not. // // The third slot PINS the registered app slug for every host under the domain. // Most brands register one client per app and the slug is derivable from the // hostname — `lux.cloud` → `cloud` → `lux-cloud`, `mpc.lux.network` → `lux-mpc`, // both verified 302 against the live authorize endpoint. Some register ONE // client for the whole brand, and then the derivation is a guess that 400s: // `bootno.de` is `bootnode-platform`, and Pars is `pars-app` on every host // (`pars-cloud` answers 400 where `pars-app` answers 302). A client id is a // registration, not a guess — so where it is not derivable it is written down. const DOMAIN_ORG: ReadonlyArray = [ [ 'lux.network', 'lux' ], [ 'lux.cloud', 'lux' ], [ 'lux.id', 'lux' ], [ 'lux.finance', 'lux' ], [ 'lux.market', 'lux' ], [ 'lux.exchange', 'lux' ], [ 'zoo.ngo', 'zoo' ], [ 'zoo.network', 'zoo' ], [ 'zoo.cloud', 'zoo' ], [ 'zoolabs.id', 'zoo' ], [ 'hanzo.ai', 'hanzo' ], [ 'hanzo.cloud', 'hanzo' ], [ 'hanzo.id', 'hanzo' ], [ 'pars.id', 'pars', 'app' ], [ 'pars.network', 'pars', 'app' ], [ 'parsdao.org', 'pars', 'app' ], [ 'bootno.de', 'bootnode', 'platform' ], ]; export const DEFAULT_ORG: Org = 'lux'; export interface WhiteLabel extends OrgIdentity { /** Hostname the identity was resolved from, port stripped, lowercased. */ readonly host: string; /** App slug taken from the hostname — `mpc.lux.cloud` → `mpc`. */ readonly app: string; /** gui child-theme row to hand GuiProvider — `dark_lux`, `dark_zoo`, … */ readonly theme: string; /** OIDC issuer — `https://lux.id`. */ readonly issuer: string; /** IAM client id, `-` per the fleet naming scheme — `lux-mpc`. */ readonly clientId: string; } /** Strip the port and any trailing dot, lowercase. `LUX.cloud:3000` → `lux.cloud`. */ function normalizeHost(host: string): string { const noPort = host.trim().toLowerCase().split(':')[0] ?? ''; return noPort.replace(/\.$/, ''); } /** true when `host` is `domain` or a subdomain of it (label boundary respected). */ function isUnder(host: string, domain: string): boolean { return host === domain || host.endsWith(`.${ domain }`); } /** The registrable domain this host sits under, or undefined for unknown hosts. */ function matchDomain(host: string): readonly [string, Org, string?] | undefined { // Longest domain first so `zoo.network` wins over a hypothetical `network`. let best: readonly [string, Org, string?] | undefined; for (const entry of DOMAIN_ORG) { if (isUnder(host, entry[0]) && (!best || entry[0].length > best[0].length)) { best = entry; } } return best; } /** * App slug for the IAM client id. * * `mpc.lux.cloud` → `mpc` (leftmost label) * `lux.cloud` → `cloud` (apex: the service name, not the org) * `www.lux.network`→ `network` (www is chrome, not an app) * `bootno.de` → `platform` (pinned: a registration, not a guess) * `localhost` → `local` */ function appSlug(host: string, domain: string, pinned?: string): string { if (pinned) return pinned; const sub = host === domain ? '' : host.slice(0, -(domain.length + 1)); const leftmost = sub.split('.')[0] ?? ''; if (leftmost && leftmost !== 'www') return leftmost; // Apex (or www) — the domain's own service label. const label = domain.split('.')[0] ?? ''; const tld = domain.split('.').slice(1).join('.'); // `lux.network` → `network`, `lux.cloud` → `cloud`, `pars.id` → `id`. return tld.split('.')[0] || label; } /** Loopback / LAN / *.local hosts a developer actually types. */ function isLocal(host: string): boolean { return ( host === 'localhost' || host.endsWith('.localhost') || host === '127.0.0.1' || host === '0.0.0.0' || host === '[::1]' || host.endsWith('.local') ); } /** * Resolve the full white-label identity from a Host header value. * * Pure and total: an unknown or missing host falls back to the Lux row rather * than throwing, so a preview URL or a health probe never blanks the UI. * * resolveWhiteLabel('mpc.lux.network') // org lux, clientId lux-mpc, issuer https://lux.id * resolveWhiteLabel('zoo.cloud') // org zoo, clientId zoo-cloud, issuer https://zoolabs.id * resolveWhiteLabel('cloud.pars.network') // org pars, clientId pars-app, issuer https://pars.id */ export function resolveWhiteLabel(host?: string | null): WhiteLabel { const h = normalizeHost(host ?? ''); const match = h ? matchDomain(h) : undefined; const org = match ? match[1] : DEFAULT_ORG; const identity = ORGS[org]; const app = match ? appSlug(h, match[0], match[2]) : (h && isLocal(h) ? 'local' : 'app'); return { ...identity, host: h, app, theme: `dark_${ org }`, issuer: `https://${ identity.iamDomain }`, clientId: `${ org }-${ app }`, }; } /** * The current host in a browser, or '' during SSR / prerender. * Server code must pass `req.headers.host` to resolveWhiteLabel explicitly — * there is no ambient request here, and guessing would bake in a brand. */ export function currentHost(): string { return typeof window === 'undefined' ? '' : window.location.host; } /** Identity for the org id itself, for the rare surface that is not host-routed. */ export function orgIdentity(org: Org): OrgIdentity { return ORGS[org]; } export { ORGS as orgs };