# White-Label System API Reference Complete API documentation for the nself White-Label & Customization system. **Version:** 0.9.0 **Sprint:** 14 - White-Label & Customization (60pts) --- ## Table of Contents 1. [Overview](#overview) 2. [Branding Commands](#branding-commands) 3. [Logo & Assets](#logo--assets) 4. [Custom Domains](#custom-domains) 5. [Email Templates](#email-templates) 6. [Theme System](#theme-system) 7. [Configuration Management](#configuration-management) 8. [Error Handling](#error-handling) 9. [Function Reference](#function-reference) --- ## Overview The white-label system provides comprehensive customization capabilities including branding, custom domains, email templates, and theme management. ### System Architecture ``` branding/ ├── config.json # Main branding configuration ├── logos/ # Logo assets ├── css/ # Generated CSS variables ├── fonts/ # Custom fonts ├── assets/ # Additional assets ├── domains/ # Domain configurations │ ├── domains.json │ ├── ssl/ # SSL certificates │ └── dns-challenges/ # DNS verification tokens ├── email-templates/ # Email templates │ ├── languages/ # Multi-language support │ │ ├── en/ # English templates │ │ └── [lang]/ # Other languages │ └── previews/ # Template previews └── themes/ # Theme definitions ├── .active # Active theme marker ├── light/ # Light theme ├── dark/ # Dark theme └── [custom]/ # Custom themes ``` ### Configuration Files **Branding Config** (`branding/config.json`): ```json { "version": "1.0.0", "brand": { "name": "nself", "tagline": "Powerful Backend for Modern Applications", "description": "Open-source backend infrastructure platform" }, "colors": { "primary": "#0066cc", "secondary": "#ff6600", "accent": "#00cc66" }, "fonts": { "primary": "Inter, system-ui, sans-serif", "secondary": "Georgia, serif" }, "logos": { "main": "logo-main.png", "icon": "logo-icon.png", "email": "logo-email.png", "favicon": "logo-favicon.png" }, "customCSS": "custom.css", "theme": "light" } ``` **Domain Config** (`branding/domains/domains.json`): ```json { "version": "1.0.0", "domains": [ { "domain": "app.example.com", "status": "active", "verified": true, "sslEnabled": true, "sslIssuer": "letsencrypt", "sslExpiryDate": "2026-04-30T00:00:00Z", "healthStatus": "healthy" } ], "defaultDomain": "app.example.com", "sslProvider": "letsencrypt", "autoRenew": true } ``` --- ## Branding Commands ### `nself whitelabel branding create ` Create a new brand configuration. **Syntax:** ```bash nself whitelabel branding create [tenant-id] ``` **Parameters:** - `brand-name` (required): Name of the brand - `tenant-id` (optional): Tenant ID for multi-tenant setups (default: "default") **Example:** ```bash # Create single-tenant brand nself whitelabel branding create "My Company" # Create brand for specific tenant nself whitelabel branding create "Acme Corp" tenant-123 ``` **Output:** ``` Creating brand: My Company ✓ Brand 'My Company' created successfully Next steps: 1. Set brand colors: nself whitelabel branding set-colors 2. Upload logo: nself whitelabel logo upload 3. Customize fonts: nself whitelabel branding set-fonts ``` **Function Reference:** - Implementation: `src/lib/whitelabel/branding.sh::create_brand()` - Calls: `initialize_branding_system()`, `jq` for JSON manipulation - Config File: `branding/config.json` **Error Codes:** - `0`: Success - `1`: Invalid brand name or configuration error --- ### `nself whitelabel branding set-colors` Configure brand color palette. **Syntax:** ```bash nself whitelabel branding set-colors [options] ``` **Options:** - `--primary `: Primary brand color (hex format) - `--secondary `: Secondary brand color (hex format) - `--accent `: Accent color (hex format) - `--background `: Background color (hex format) - `--text `: Text color (hex format) **Color Format:** - Hex colors: `#RRGGBB` or `#RGB` - Examples: `#0066cc`, `#f00` **Example:** ```bash # Set primary and secondary colors nself whitelabel branding set-colors \ --primary #0066cc \ --secondary #ff6600 # Set complete color scheme nself whitelabel branding set-colors \ --primary #2563eb \ --secondary #7c3aed \ --accent #10b981 \ --background #ffffff \ --text #1f2937 ``` **Output:** ``` Updating brand colors... ✓ Brand colors updated successfully Primary: #0066cc Secondary: #ff6600 Accent: #00cc66 ``` **Side Effects:** - Updates `branding/config.json` - Regenerates `branding/css/variables.css` - Auto-generates CSS custom properties **Generated CSS Variables:** ```css :root { --color-primary: #0066cc; --color-secondary: #ff6600; --color-accent: #00cc66; /* ... */ } ``` **Function Reference:** - Implementation: `src/lib/whitelabel/branding.sh::set_brand_colors()` - Validator: `validate_hex_color()` - CSS Generator: `generate_css_variables()` **Error Codes:** - `0`: Success - `1`: Invalid color format or branding not initialized --- ### `nself whitelabel branding set-fonts` Configure brand typography. **Syntax:** ```bash nself whitelabel branding set-fonts [options] ``` **Options:** - `--primary `: Primary font family - `--secondary `: Secondary font family (headings) - `--code `: Monospace font for code **Font Format:** - CSS font-family syntax - Include fallbacks: `"Inter, system-ui, sans-serif"` - Web fonts or system fonts **Example:** ```bash # Set primary font nself whitelabel branding set-fonts \ --primary "Inter, system-ui, sans-serif" # Set complete font stack nself whitelabel branding set-fonts \ --primary "Helvetica Neue, Arial, sans-serif" \ --secondary "Georgia, Times, serif" \ --code "Fira Code, Consolas, monospace" ``` **Output:** ``` Updating brand fonts... ✓ Brand fonts updated successfully Primary: Helvetica Neue, Arial, sans-serif Secondary: Georgia, Times, serif ``` **Generated CSS:** ```css :root { --font-primary: "Helvetica Neue, Arial, sans-serif"; --font-secondary: "Georgia, Times, serif"; --font-code: "Fira Code, Consolas, monospace"; } body { font-family: var(--font-primary); } ``` **Function Reference:** - Implementation: `src/lib/whitelabel/branding.sh::set_brand_fonts()` - CSS Generator: `generate_css_variables()` **Notes:** - Web fonts must be loaded separately via `@font-face` or external CSS - Custom fonts can be placed in `branding/fonts/` --- ### `nself whitelabel branding set-css ` Add custom CSS overrides. **Syntax:** ```bash nself whitelabel branding set-css ``` **Parameters:** - `path-to-css-file` (required): Path to custom CSS file **Example:** ```bash # Set custom CSS nself whitelabel branding set-css ./custom-styles.css # Example custom CSS file cat > custom.css << EOF /* Custom brand styles */ .btn-primary { background-color: var(--color-primary); border-radius: 8px; font-weight: 600; } .hero-section { background-image: url('/assets/hero-bg.jpg'); } EOF nself whitelabel branding set-css custom.css ``` **Output:** ``` Setting custom CSS... ✓ Custom CSS set successfully: /path/to/branding/css/custom.css ``` **Function Reference:** - Implementation: `src/lib/whitelabel/branding.sh::set_custom_css()` - Destination: `branding/css/custom.css` **Best Practices:** - Use CSS custom properties for colors: `var(--color-primary)` - Avoid `!important` when possible - Keep specificity low for easier overrides --- ### `nself whitelabel branding preview` Preview current branding configuration. **Syntax:** ```bash nself whitelabel branding preview ``` **Example:** ```bash nself whitelabel branding preview ``` **Output:** ``` Branding Preview ============================================================ Brand: My Company Primary Color: #0066cc Secondary Color: #ff6600 Primary Font: Inter, system-ui, sans-serif Logos: main: logo-main.png icon: logo-icon.png email: not set favicon: not set Updated: 2026-01-30T12:34:56Z ``` **Function Reference:** - Implementation: `src/lib/whitelabel/branding.sh::preview_branding()` - Data Source: `branding/config.json` --- ## Logo & Assets ### `nself whitelabel logo upload ` Upload brand logo. **Syntax:** ```bash nself whitelabel logo upload [--type ] ``` **Parameters:** - `path` (required): Path to logo file - `--type ` (optional): Logo type (default: `main`) **Logo Types:** - `main`: Primary logo (header, homepage) - `icon`: Small icon/favicon (16x16 to 64x64) - `email`: Email header logo (optimized for email clients) - `favicon`: Browser favicon **Supported Formats:** - PNG (recommended) - JPG/JPEG - SVG (vector, scalable) - WebP (modern browsers) **Example:** ```bash # Upload main logo nself whitelabel logo upload ./logo.png # Upload specific logo types nself whitelabel logo upload ./logo-main.svg --type main nself whitelabel logo upload ./icon-64x64.png --type icon nself whitelabel logo upload ./email-logo.png --type email nself whitelabel logo upload ./favicon.ico --type favicon ``` **Output:** ``` Uploading main logo... ✓ Logo uploaded successfully: /path/to/branding/logos/logo-main.png ``` **Function Reference:** - Implementation: `src/lib/whitelabel/branding.sh::upload_logo()` - Called Function: `upload_brand_logo()` - Destination: `branding/logos/logo-{type}.{ext}` **Logo Recommendations:** | Type | Size | Format | Usage | |------|------|--------|-------| | main | 200x60px | SVG/PNG | Header, navigation | | icon | 64x64px | PNG/ICO | Favicon, app icon | | email | 600x200px | PNG | Email headers | | favicon | 32x32px | ICO/PNG | Browser tab | **Error Codes:** - `0`: Success - `1`: File not found or unsupported format --- ### `nself whitelabel logo list` List all configured logos. **Syntax:** ```bash nself whitelabel logo list ``` **Example:** ```bash nself whitelabel logo list ``` **Output:** ``` Configured Logos: main: logo-main.png icon: logo-icon.png email: logo-email.png favicon: not set ``` **Function Reference:** - Implementation: `src/lib/whitelabel/branding.sh::list_logos()` --- ### `nself whitelabel logo remove ` Remove a logo. **Syntax:** ```bash nself whitelabel logo remove ``` **Parameters:** - `logo-type` (required): Type of logo to remove (main, icon, email, favicon) **Example:** ```bash # Remove email logo nself whitelabel logo remove email ``` **Output:** ``` Removing email logo... ✓ Logo removed successfully ``` **Function Reference:** - Implementation: `src/lib/whitelabel/branding.sh::remove_logo()` - Deletes: Logo file and config reference --- ## Custom Domains ### `nself whitelabel domain add ` Add a custom domain. **Syntax:** ```bash nself whitelabel domain add [--primary] ``` **Parameters:** - `domain` (required): Domain name (e.g., app.example.com) - `--primary` (optional): Set as primary domain **Domain Validation:** - Valid format: `subdomain.domain.tld` - Examples: `app.example.com`, `api.mycompany.io` - Invalid: `localhost`, `192.168.1.1`, `example` **Example:** ```bash # Add custom domain nself whitelabel domain add app.mycompany.com # Add as primary domain nself whitelabel domain add app.mycompany.com --primary ``` **Output:** ``` Adding custom domain: app.mycompany.com ✓ Domain added: app.mycompany.com Next steps: 1. Configure DNS: Point app.mycompany.com to your server IP 2. Verify domain: nself whitelabel domain verify app.mycompany.com 3. Provision SSL: nself whitelabel domain ssl app.mycompany.com ``` **Domain Record:** ```json { "domain": "app.mycompany.com", "status": "pending", "verified": false, "sslEnabled": false, "sslIssuer": null, "dnsVerified": false, "healthStatus": "unknown", "isPrimary": false, "createdAt": "2026-01-30T12:34:56Z" } ``` **Function Reference:** - Implementation: `src/lib/whitelabel/domains.sh::add_custom_domain()` - Validator: `validate_domain_format()` - Config File: `branding/domains/domains.json` **Error Codes:** - `0`: Success - `1`: Invalid domain format or already exists --- ### `nself whitelabel domain verify ` Verify domain ownership. **Syntax:** ```bash nself whitelabel domain verify ``` **Parameters:** - `domain` (required): Domain to verify **Verification Methods:** **Method 1: DNS TXT Record** ``` Name: _nself-verification.app.example.com Type: TXT Value: ``` **Method 2: DNS A/CNAME Record** ``` Name: app.example.com Type: A (or CNAME) Value: ``` **Example:** ```bash nself whitelabel domain verify app.mycompany.com ``` **Output:** ``` Verifying domain: app.mycompany.com DNS Verification Instructions: ------------------------------------------------------------ Add this TXT record to your DNS: Name: _nself-verification.app.mycompany.com Type: TXT Value: a3f8d92e4c1b5a6f7e8d9c0b1a2f3e4d5c6b7a8f9e0d1c2b3a4f5e6d7c8b9a0f Or configure A/CNAME record: Name: app.mycompany.com Type: A (or CNAME) Value: Checking DNS propagation... Attempt 1/30 - waiting for DNS propagation... Attempt 2/30 - waiting for DNS propagation... ✓ Domain verified successfully: app.mycompany.com ``` **DNS Propagation:** - Timeout: 300 seconds (5 minutes) - Check interval: 10 seconds - Max attempts: 30 **Function Reference:** - Implementation: `src/lib/whitelabel/domains.sh::verify_domain()` - DNS Checker: `check_dns_propagation()` - Token Generator: `generate_verification_token()` - Challenge File: `branding/domains/dns-challenges/{domain}.txt` **Tools Used:** - `dig` (preferred) - `nslookup` (fallback) - `host` (fallback) **Error Codes:** - `0`: Domain verified - `1`: Verification timeout or failed --- ### `nself whitelabel domain ssl ` Provision SSL certificate for domain. **Syntax:** ```bash nself whitelabel domain ssl [--auto-renew] ``` **Parameters:** - `domain` (required): Domain for SSL certificate - `--auto-renew` (optional): Enable automatic renewal **SSL Providers:** **Let's Encrypt** (default, production): ```bash # Set provider (in .env) SSL_PROVIDER=letsencrypt # Provision certificate nself whitelabel domain ssl app.example.com --auto-renew ``` **Self-Signed** (development): ```bash SSL_PROVIDER=selfsigned nself whitelabel domain ssl app.example.com ``` **Custom** (bring your own): ```bash SSL_PROVIDER=custom nself whitelabel domain ssl app.example.com # Then manually copy certificates to: # branding/domains/ssl/app.example.com/cert.pem # branding/domains/ssl/app.example.com/key.pem # branding/domains/ssl/app.example.com/chain.pem ``` **Example:** ```bash # Provision Let's Encrypt SSL nself whitelabel domain ssl app.mycompany.com --auto-renew ``` **Output (Let's Encrypt):** ``` Provisioning SSL certificate for: app.mycompany.com Using Let's Encrypt for SSL... Requesting certificate from Let's Encrypt... ✓ SSL certificate provisioned successfully Issuer: Let's Encrypt Expires: 2026-04-30T00:00:00Z ✓ Auto-renewal configured Add to crontab: 0 0 * * * /path/to/ssl/renew-app.mycompany.com.sh ``` **Output (Self-Signed):** ``` Provisioning SSL certificate for: app.mycompany.com Generating self-signed certificate... ✓ Self-signed certificate generated Note: Self-signed certificates are not trusted by browsers For production, use Let's Encrypt or a commercial CA ``` **Certificate Files:** ``` branding/domains/ssl/app.mycompany.com/ ├── cert.pem # Public certificate ├── key.pem # Private key └── chain.pem # Certificate chain ``` **Auto-Renewal:** - Generates renewal script: `ssl/renew-{domain}.sh` - Cron schedule: Daily at midnight (`0 0 * * *`) - Uses `certbot renew` command **Function Reference:** - Implementation: `src/lib/whitelabel/domains.sh::provision_ssl()` - Let's Encrypt: `provision_letsencrypt_ssl()` - Self-Signed: `provision_selfsigned_ssl()` - Renewal: `setup_ssl_auto_renewal()` **Prerequisites:** - Domain verified (recommended) - `certbot` installed (for Let's Encrypt) - `openssl` installed (for self-signed) **Error Codes:** - `0`: Success - `1`: Domain not found, provisioning failed, or missing tools --- ### `nself whitelabel domain health ` Check domain health status. **Syntax:** ```bash nself whitelabel domain health ``` **Parameters:** - `domain` (required): Domain to check **Health Checks:** 1. **DNS Resolution**: Domain resolves to IP 2. **SSL Certificate**: Valid and not expired 3. **HTTP Response**: Server responds to requests **Example:** ```bash nself whitelabel domain health app.mycompany.com ``` **Output:** ``` Checking domain health: app.mycompany.com ============================================================ 1. DNS Resolution: ✓ Resolved 2. SSL Certificate: ✓ Valid 3. HTTP Response: ✓ Responding Health Status: Healthy ``` **Degraded Output:** ``` Checking domain health: app.mycompany.com ============================================================ 1. DNS Resolution: ✓ Resolved 2. SSL Certificate: ! No SSL 3. HTTP Response: ✓ Responding Health Status: Degraded Issues Found: - No SSL certificate ``` **Unhealthy Output:** ``` Checking domain health: app.mycompany.com ============================================================ 1. DNS Resolution: ✗ Not resolved 2. SSL Certificate: ✗ Expired 3. HTTP Response: ✗ Not responding Health Status: Unhealthy Issues Found: - DNS not resolving - SSL certificate expired - HTTP not responding ``` **Health Status Values:** - `healthy`: All checks passed - `degraded`: Minor issues (missing SSL, warnings) - `unhealthy`: Critical issues (DNS failed, not responding) **Function Reference:** - Implementation: `src/lib/whitelabel/domains.sh::check_domain_health()` - DNS Check: `check_dns_propagation()` - SSL Check: `has_ssl_certificate()`, `is_ssl_expired()` - HTTP Check: `check_http_response()` **Tools Used:** - DNS: `dig`, `nslookup`, or `host` - HTTP: `curl` or `wget` --- ### `nself whitelabel domain remove ` Remove a custom domain. **Syntax:** ```bash nself whitelabel domain remove ``` **Parameters:** - `domain` (required): Domain to remove **Example:** ```bash nself whitelabel domain remove app.mycompany.com ``` **Output:** ``` Removing custom domain: app.mycompany.com Removing SSL certificates... ✓ Domain removed: app.mycompany.com ``` **Side Effects:** - Removes domain from `domains.json` - Deletes SSL certificates from `ssl/{domain}/` - Removes DNS challenge files **Function Reference:** - Implementation: `src/lib/whitelabel/domains.sh::remove_custom_domain()` **Warning:** This operation is permanent and cannot be undone. SSL certificates will be deleted. --- ## Email Templates ### `nself whitelabel email list` List available email templates. **Syntax:** ```bash nself whitelabel email list [language] ``` **Parameters:** - `language` (optional): Language code (default: `en`) **Available Templates:** - `welcome`: New user welcome email - `password-reset`: Password reset with secure link - `verify-email`: Email verification - `invite`: User invitation - `password-change`: Password change confirmation - `account-update`: Account information update - `notification`: Generic notification - `alert`: Alert/warning notification **Example:** ```bash # List English templates nself whitelabel email list # List Spanish templates nself whitelabel email list es ``` **Output:** ``` Email Templates (Language: en) ============================================================ welcome New user welcome email upon registration Subject: Welcome to {{BRAND_NAME}}! password-reset Password reset email with secure reset link Subject: Reset Your Password verify-email Email verification with confirmation link Subject: Verify Your Email Address invite User invitation email Subject: You're invited to {{BRAND_NAME}} password-change Password change confirmation Subject: Your password has been changed account-update General account update notification Subject: Account Update Notification notification Generic notification template Subject: {{NOTIFICATION_TITLE}} alert Alert/warning notification template Subject: ⚠️ {{ALERT_TITLE}} ``` **Function Reference:** - Implementation: `src/lib/whitelabel/email-templates.sh::list_email_templates()` - Template Directory: `branding/email-templates/languages/{lang}/` --- ### `nself whitelabel email edit