* feat(branding): add BrandingService with default-preserving env layer Introduce lib/branding/service.ts mirroring lib/email/service.ts. Defaults match current gnubok values exactly, so production behaviour is unchanged unless an env var (NEXT_PUBLIC_BRANDING_*, BRANDING_*) or extension override (via registerBrandingService) is set. Resolution order: defaults < env vars < extension override. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(branding): route root layout, manifest, and PWA assets through branding service - app/layout.tsx now reads title, description, themeColor, and apple-touch-icon from getBranding() instead of hardcoded values. - public/manifest.json replaced by dynamic app/manifest.ts so PWA name, short_name, description, theme_color, background_color, and icon paths are resolved at request time. The manifest now serves at /manifest.webmanifest (Next.js convention for the metadata file route). The previous /manifest.json URL is no longer populated; nothing in core references it after this commit. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(branding): route email service and templates through branding service - resend-service.ts: From line uses getBranding().appName instead of hardcoded "Gnubok" in both the with-fromName and bare cases. - invite-templates.ts: subject, HTML header, body, plain text, and the team-invite variants all read from branding (sentence case in prose, uppercased for the styled <p> header). - consent-notification-templates.ts: signature fallback (companyName || branding) for both HTML and plain text variants. Defaults preserve the exact current strings ("Gnubok", "GNUBOK", "gnubok" in their respective contexts) so no email content changes for production. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(branding): route OAuth consent page through branding service The MCP OAuth consent page rendered for Claude Desktop / Claude.ai connector flows now reads the app name from getBranding() for both the HTML <title> and the body copy. Default still produces "gnubok" in lowercase prose, matching current behaviour. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(branding): route auth, dashboard, and onboarding text through branding service Replace user-visible "gnubok" / "Gnubok" references with calls to getBranding(). Touches: - Auth pages (login, register, mfa/enroll): logo src/alt, MFA TOTP friendlyName. - Onboarding (companies/new, invite, sandbox, WelcomeOnboarding, Step2CompanyDetails, NewUserChecklist, BankIdCompanyPicker, ArcimMigrationWorkspace): logo, headings, error/help text. - Dashboard fallback (companyName="gnubok") and settings (backup copy, ApiKeysPanel MCP connector name + login note, CompanyDangerZone, retention-notice). - API routes (support contact subject prefix, enable-banking consent email companyName fallback, AI inbox receipt-request appUrl, pain001 messageId prefix). - MCP server "open the gnubok web app" review message. - Salary/reports filings (AGI Programnamn, KU10 Programnamn, payslip footer, full-archive system metadata, SRU #PROGRAM line). Internal identifiers (cookie names gnubok-company-id / gnubok-invite-token, API key prefix gnubok_sk_, invite token prefix gnubok_inv_, MCP tool names, npm package gnubok-mcp, GNUBOK_API_KEY env name) are deliberately left unchanged — they're stable contracts that whitelabels must not break. Defaults match current behaviour exactly. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(branding): support legal page field-level swaps for entity and contact Privacy and DPA pages now interpolate appName, legalEntity, and privacyEmail from the branding service instead of hardcoding "Gnubok", "Arcim", and "privacy@gnubok.se". Page metadata uses generateMetadata() so titles also reflect the brand. lib/support.ts now falls back to getBranding().supportEmail when SUPPORT_RECIPIENT_EMAIL is unset, so a single BRANDING_SUPPORT_EMAIL env var configures both the support form recipient and the displayed support address. Whitelabels with a different legal jurisdiction or entirely different DPA text should override the page route from an extension. Phase 1 intentionally only supports field-level swaps. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * docs(branding): add WHITELABEL.md and example branding extension WHITELABEL.md: fork checklist, env var reference, the "do not change" list (cookies, API key prefixes, invite token prefixes, MCP tool names, gnubok-mcp npm package, GNUBOK_API_KEY env name), out-of-scope items, the upstream sync workflow YAML to copy into a fork, conflict avoidance guidance, and a verification checklist. extensions/general/_example-branding/: copy-paste starter extension with index.ts (commented placeholder values for registerBrandingService), manifest.json, and README.md. Disabled by default (not added to extensions.config.json); whitelabels cp the folder, edit, and enable. sectors.test.ts: bumped expected extension count 12 -> 13 to account for the new starter extension on disk. The generated registry is unchanged because the example is disabled. The sync workflow YAML is documented inline in WHITELABEL.md rather than checked in as a workflow file. It's only meaningful in a fork -- gnubok itself has nothing to sync from. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(branding): address PR review — lazy support email + escape brand in HTML/XML Three issues from code review: P1 — lib/support.ts: SUPPORT_RECIPIENT_EMAIL was a module-level const, evaluated at import time before extensions register branding overrides via ensureInitialized(). Convert to getSupportRecipientEmail() lazy accessor; update the only caller in app/api/support/contact/route.ts. Extension-supplied supportEmail values now route correctly. P2 — app/api/mcp-oauth/authorize/route.ts: appName was interpolated into the consent page HTML without escapeHtml(), inconsistent with the existing escaping of companyName. Wrap appName.toLowerCase() in escapeHtml() at use sites in <title> and the body paragraph. P2 — lib/salary/agi/xml-generator.ts and lib/salary/ku/ku10-generator.ts: appName placed inside <gem:Programnamn> / <Programnamn> XML elements without escapeXml(), the helper already used for other admin-controlled fields in the same files. Wrap accordingly to prevent malformed XML if a brand name contains XML reserved characters. All admin-controlled inputs only — no user-exploitable path. Defense in depth, not a known incident. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(branding): security follow-up — lazy metadata, SRU/email header sanitization Self-audit after the PR review surfaced four more concerns. Fixes them with the same defense-in-depth posture as the prior review fixes. 1. app/layout.tsx — same eager-evaluation class as P1 support.ts. The module-level `const branding = getBranding()` froze branding before extensions registered, so extension-based overrides for title, description, themeColor, and apple-touch-icon silently never applied. - Convert to generateMetadata() / generateViewport() (lazy, run per request, see extension-registered overrides). - Inline getBranding() inside RootLayout for the apple-touch-icon href so it picks up overrides too. - Add ensureInitialized() at module level so extensions are loaded before the first metadata call. Mirrors the API route pattern. 2. app/manifest.ts — same class. The dynamic manifest function reads getBranding() per request, but if the manifest is requested before any other module has triggered ensureInitialized(), extensions are still unloaded. Add ensureInitialized() at module level. 3. lib/reports/ink2/sru-generator.ts — appName interpolated into the SRU `#PROGRAM` directive without sanitization. SRU's reserved char is `#` (directive marker) and CRLF injects new directives. Wrap in the existing sanitizeString() helper to match the pattern used for other admin-controlled fields in this file (#NAMN, #ADRESS, etc.). 4. extensions/general/email/lib/resend-service.ts — appName and the user-controlled fromName both flow into the From header. Resend's API does its own validation, but defense in depth: strip CRLF and angle brackets via a small sanitizeHeaderPart() helper before building the header string. fromName was a pre-existing surface; appName is new with this whitelabel work. All four are admin-controlled inputs (env vars or extension code), not user-exploitable. No known incidents — defense in depth, and correctness for extension-based whitelabels. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
8.1 KiB
Whitelabel fork checklist
gnubok is whitelabel-friendly: every user-visible brand reference reads from a single BrandingService (lib/branding/service.ts). If you don't override anything, the app behaves exactly like upstream gnubok. To run your own brand on top of gnubok, fork the repo and override the values you care about.
Quick start
# 1. Fork erp-mafia/gnubok on GitHub → you/your-brand
# 2. Clone and add upstream remote (one-time)
git clone https://github.com/you/your-brand
cd your-brand
git remote add upstream https://github.com/erp-mafia/gnubok
# 3. Copy the example branding extension
cp -r extensions/general/_example-branding extensions/general/your-brand
# Edit extensions/general/your-brand/index.ts with your brand values
# 4. (Optional) Set env vars instead of / in addition to the extension. See "Env vars" below.
# 5. Enable the extension
# Edit extensions.config.json and add "your-brand" to the array.
# 6. Run locally
npm run setup:extensions
npm run dev
# 7. Deploy to your hosting (Vercel, Docker, etc.)
Env vars
All branding can be set via env vars. Public ones use NEXT_PUBLIC_BRANDING_* (build-time inlined, available in client components). Server-only ones use BRANDING_*.
| Env var | Field | Default |
|---|---|---|
NEXT_PUBLIC_BRANDING_APP_NAME |
appName |
Gnubok |
NEXT_PUBLIC_BRANDING_APP_DESCRIPTION |
appDescription |
Ekonomihantering |
BRANDING_LEGAL_ENTITY |
legalEntity |
Arcim |
BRANDING_SUPPORT_EMAIL |
supportEmail |
support@gnubok.se |
BRANDING_PRIVACY_EMAIL |
privacyEmail |
privacy@gnubok.se |
BRANDING_SECURITY_EMAIL |
securityEmail |
security@arcim.io |
NEXT_PUBLIC_APP_URL |
appUrl |
https://app.gnubok.se |
NEXT_PUBLIC_BRANDING_LOGO_PATH |
logoPath |
/gnubokiceon-removebg-preview.png |
NEXT_PUBLIC_BRANDING_FAVICON_PATH |
faviconPath |
/favicon.ico |
NEXT_PUBLIC_BRANDING_APPLE_ICON_PATH |
appleTouchIconPath |
/icons/icon-192.png |
NEXT_PUBLIC_BRANDING_PWA_ICON_BASE |
pwaIconBasePath |
/icons |
NEXT_PUBLIC_BRANDING_THEME_COLOR |
themeColor |
#304D83 |
NEXT_PUBLIC_BRANDING_MANIFEST_THEME_COLOR |
manifestThemeColor |
#1a1a1a |
NEXT_PUBLIC_BRANDING_MANIFEST_BG_COLOR |
manifestBackgroundColor |
#ffffff |
Resolution order (last wins): defaults → env vars → extension override.
NEXT_PUBLIC_* env vars are inlined at build time. Changing them requires a fresh npm run build to propagate.
Things you MUST NOT change
These are stable contracts. Renaming them breaks existing data, sessions, or external clients (npm package consumers, MCP connectors, browser sessions, invite links). Leave them alone in your fork:
| Identifier | Where | Why |
|---|---|---|
gnubok-company-id |
cookie | Active company context — renaming breaks logged-in sessions |
gnubok-invite-token |
cookie | Pre-auth invite token holding — renaming drops in-flight invites |
gnubok_sk_ |
API key prefix | All issued API keys; existing clients fail validation |
gnubok_inv_ |
invite token prefix | All sent invite links break |
gnubok_* |
MCP tool names (gnubok_list_invoices, etc.) |
Published MCP API — Claude clients have these cached |
gnubok-mcp |
npm package name | Whitelabel users still install npx gnubok-mcp. Document GNUBOK_URL=https://app.your-brand.se/api/extensions/ext/mcp-server/mcp so they hit your endpoint |
GNUBOK_API_KEY |
env var read by gnubok-mcp package |
Same reason — npm consumer expects this name |
What's outside this branding service
A few things that look brand-related but are configured elsewhere:
- Supabase auth emails (password reset, magic link) — set in the Supabase dashboard for your project, not in code.
- Resend sending domain — verify
noreply@your-brand.se(or wherever) in Resend, setRESEND_FROM_EMAIL. - DNS / domain — point
app.your-brand.seat your Vercel deployment. - OAuth redirect allowlist for MCP —
app/api/mcp-oauth/authorize/route.tslistsclaude.ai/api/*,claude.com/api/*, and localhost. Your domain is the OAuth issuer, not a redirect target — no change needed unless you're integrating with new MCP clients. - Service worker push notification fallback title (
public/sw.js) — currently hardcoded as'Ekonomi'. Service workers can't read env vars at runtime; change the file directly in your fork if it matters. - iCal feed PRODID (
lib/calendar/ics-generator.ts) — defaults toerp-base.se, callers may pass their domain. NEXT_PUBLIC_APP_URL— used as the OAuth issuer. Set this to your domain (e.g.https://app.your-brand.se).
Staying in sync with upstream
Add this workflow at .github/workflows/sync-upstream.yml to your fork. It runs weekly and opens a PR with upstream changes:
name: Sync from upstream
on:
schedule:
- cron: '0 3 * * 1' # Mondays 03:00 UTC
workflow_dispatch:
jobs:
sync:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Add upstream and fetch
run: |
git remote add upstream https://github.com/erp-mafia/gnubok
git fetch upstream main
- name: Create sync branch and merge
id: merge
run: |
BRANCH="sync/upstream-$(date +%Y-%m-%d)"
git checkout -b "$BRANCH"
if git merge --no-edit upstream/main; then
echo "status=clean" >> "$GITHUB_OUTPUT"
else
echo "status=conflict" >> "$GITHUB_OUTPUT"
git merge --abort || true
fi
echo "branch=$BRANCH" >> "$GITHUB_OUTPUT"
- name: Push and open PR (clean merge)
if: steps.merge.outputs.status == 'clean'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if git diff --quiet origin/main..HEAD; then
echo "Up to date with upstream — nothing to do."
exit 0
fi
git push origin "${{ steps.merge.outputs.branch }}"
gh pr create \
--base main \
--head "${{ steps.merge.outputs.branch }}" \
--title "Sync from upstream gnubok" \
--body "Automated weekly sync from \`erp-mafia/gnubok@main\`."
- name: Report conflict
if: steps.merge.outputs.status == 'conflict'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh issue create \
--title "Upstream sync conflict ($(date +%Y-%m-%d))" \
--label sync-conflict \
--body "Automated upstream merge hit a conflict. Resolve manually: \`git fetch upstream && git merge upstream/main\`."
Conflict avoidance
The fork-friendliness of this design depends on you keeping changes confined to your branding extension folder. Every file you edit in lib/, app/, or components/ becomes a potential conflict on the next upstream merge. If you find yourself wanting to override something the branding service doesn't expose, prefer:
- Open an upstream issue — the branding service is intentionally minimal; missing fields can be added.
- PR a hook upstream — extending the service or adding a registry pattern keeps your fork clean.
Verifying your whitelabel
After deploying:
- Visit
/— browser tab title shows your brand. - Visit
/loginand/register— your logo renders. - View source of
/manifest.webmanifest—name,short_name,theme_colorreflect your overrides. - Trigger an invite email — From line says
<your-brand> <noreply@...>, body uses your name. - Visit
/dpaand/privacy— legal entity and contact email are yours. - Open OAuth flow (
/api/mcp-oauth/authorize?...) from a test MCP client — consent page references your brand. - Submit support form (Settings → Support) — internal subject prefix is
[<your-brand> support].