Files
accounted/lib/branding/service.ts
T
Jakob Wennberg c74b19df1b Accounted rebrand + swarm-skill cleanup + bank-reconciliation fixes (#643)
* feat(reconciliation): close the bank-feed loop on voucher links and re-tag mis-typed opening balances

Two related fixes to bank reconciliation correctness:

1. Auto-reconcile on voucher link. Linking an invoice or supplier invoice to
   an existing voucher previously advanced only the invoice — the bank
   transaction that paid it kept sitting in the Transactions inbox with a null
   journal_entry_id. linkInvoiceToVoucher / linkSupplierInvoiceToVoucher now
   call autoReconcileTransactionForLinkedVoucher (lib/reconciliation), which
   links the bank transaction to the same verifikat when exactly one unbooked
   line matches it. Best-effort and post-commit: a failure here never fails the
   link. The result surfaces reconciledTransactionId; the inbox row leaves the
   list and the UI shows link_success_tx_reconciled.

2. Re-tag mis-typed opening balances. getReconciliationStatus and the GL-line
   matching RPCs identify a cash account's ingående balans solely by
   journal_entries.source_type='opening_balance'. Companies migrated from other
   systems often booked the bank IB as an ordinary voucher (source_type
   'import' or 'manual'), so it was never excluded and surfaced as a phantom
   reconciliation difference equal to the opening balance. Adds:
   - migration mark_entry_as_opening_balance: a GUC-gated carve-out in the
     immutability trigger plus a SECURITY DEFINER RPC that validates the entry
     (balance-sheet lines only, dated on a fiscal-period boundary), flips the
     source_type, and writes an audit row — no blanket data sweep.
   - POST /api/reconciliation/bank/mark-opening-balance + MarkOpeningBalanceSchema.
   - BankReconciliationView action to trigger it from the IB diff.

The gnubok_create_voucher executor now accepts a typed is_opening_balance flag
and derives source_type='opening_balance' only after validating class 1/2 lines
on the period start, so new IBs land correctly typed.

Covered by lib/reconciliation auto-reconcile tests, voucher-executors tests,
and a mark-entry-as-opening-balance pg-real test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* chore: rebrand gnubok → Accounted and prune swarm agent skills

Product rebrand and skills housekeeping. No runtime behaviour change.

Rebrand: replace user-visible "gnubok" with "Accounted" across docs, READMEs,
in-code comments, doc-site content, MCP skill/resource prose, and the
gnubok-mcp package description. The MCP resource URI scheme is moved gnubok://
→ Accounted:// consistently across resource registrations, the event-type
comment, and the resource/skill tests. Deliberately preserved as stable
identifiers (NOT rebranded): the gnubok-company-id cookie, gnubok_sk_ / gnubok_inv_
token prefixes, the gnubok-mcp npm bridge name, and the AGI <gem:Programnamn>
value (kept 'gnubok' per its source comment — it is the software identifier sent
to Skatteverket and must not churn across visual rebrands).

Skills: remove the 27 swarm-* agent SKILL.md atoms (no longer used; already
absent from the agent_atom_registry in prod), refresh the remaining skill docs,
add the .claude/rules/ path-scoped rule set, and regenerate the
seed_agent_atom_bodies migration + .skill-body-manifest.json via
`npm run skills:generate` so the DB-backed skill bodies match the trimmed set.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-03 10:52:01 +02:00

126 lines
4.9 KiB
TypeScript

/**
* Branding Service
*
* Provides whitelabel-friendly branding values (app name, support emails,
* asset paths, theme colors) with three-tier resolution:
*
* defaults < env vars < extension override
*
* If nothing is set, Accounted defaults are returned — production behaviour
* is unchanged. A whitelabel sets env vars (NEXT_PUBLIC_BRANDING_* for
* client-readable, BRANDING_* for server-only) or registers a branding
* extension via registerBrandingService().
*
* See WHITELABEL.md for the full env var reference and fork checklist.
*/
export interface BrandingConfig {
// Identity
appName: string
appDescription: string
legalEntity: string
// Contact
supportEmail: string
privacyEmail: string
securityEmail: string
// Address Supabase Auth sends verification / reset emails from. Used to build
// the `from:` query on the "check your email" screen's Gmail deep link.
// Must match the From in your Supabase Auth SMTP config.
authEmailFrom: string
// URLs
appUrl: string
// Asset paths
logoPath: string
faviconPath: string
appleTouchIconPath: string
pwaIconBasePath: string
// Colors
themeColor: string
manifestThemeColor: string
manifestBackgroundColor: string
// Navigation
hiddenNavHrefs: string[]
/**
* Sidebar density. `'standard'` renders the original full sidebar with
* every nav group at equal weight. `'slim'` renders an AI-first layout:
* four primary destinations (Översikt, Transaktioner, Fakturor, Anna)
* are visible at full weight, every other group is collapsed and muted,
* and Inställningar/Hjälp/Logga ut move into a profile dropdown.
* Set per-brand; default `'standard'` so self-hosted is unchanged.
*/
navDensity: 'standard' | 'slim'
}
const DEFAULT_BRANDING: BrandingConfig = {
appName: 'Accounted',
appDescription: 'Ekonomihantering',
legalEntity: 'Arcim Technology AB',
// Emails and URLs intentionally keep the gnubok.se hostname — the rebrand is
// visual only; we don't churn the support inbox or app domain alongside it.
supportEmail: 'support@gnubok.se',
privacyEmail: 'privacy@gnubok.se',
securityEmail: 'security@arcim.io',
authEmailFrom: 'noreply@gnubok.se',
appUrl: process.env.NEXT_PUBLIC_APP_URL || 'https://app.gnubok.se',
// The visible brand mark now renders as text via <BrandWordmark>; this
// image path is kept as a fallback for any surface still using <Image>
// (e.g. PWA-style metadata that demands a concrete file).
logoPath: '/accounted-icon.png',
faviconPath: '/favicon.ico',
appleTouchIconPath: '/icons/icon-192.png',
pwaIconBasePath: '/icons',
themeColor: '#304D83',
manifestThemeColor: '#1a1a1a',
manifestBackgroundColor: '#ffffff',
hiddenNavHrefs: [],
navDensity: 'standard',
}
let _override: Partial<BrandingConfig> = {}
export function registerBrandingService(partial: Partial<BrandingConfig>): void {
_override = { ...partial }
}
export function getBranding(): BrandingConfig {
return {
...DEFAULT_BRANDING,
...readEnvOverrides(),
..._override,
}
}
function readEnvOverrides(): Partial<BrandingConfig> {
const env = process.env
const o: Partial<BrandingConfig> = {}
if (env.NEXT_PUBLIC_BRANDING_APP_NAME) o.appName = env.NEXT_PUBLIC_BRANDING_APP_NAME
if (env.NEXT_PUBLIC_BRANDING_APP_DESCRIPTION) o.appDescription = env.NEXT_PUBLIC_BRANDING_APP_DESCRIPTION
if (env.BRANDING_LEGAL_ENTITY) o.legalEntity = env.BRANDING_LEGAL_ENTITY
if (env.BRANDING_SUPPORT_EMAIL) o.supportEmail = env.BRANDING_SUPPORT_EMAIL
if (env.BRANDING_PRIVACY_EMAIL) o.privacyEmail = env.BRANDING_PRIVACY_EMAIL
if (env.BRANDING_SECURITY_EMAIL) o.securityEmail = env.BRANDING_SECURITY_EMAIL
if (env.NEXT_PUBLIC_BRANDING_AUTH_EMAIL_FROM) o.authEmailFrom = env.NEXT_PUBLIC_BRANDING_AUTH_EMAIL_FROM
if (env.NEXT_PUBLIC_APP_URL) o.appUrl = env.NEXT_PUBLIC_APP_URL
if (env.NEXT_PUBLIC_BRANDING_LOGO_PATH) o.logoPath = env.NEXT_PUBLIC_BRANDING_LOGO_PATH
if (env.NEXT_PUBLIC_BRANDING_FAVICON_PATH) o.faviconPath = env.NEXT_PUBLIC_BRANDING_FAVICON_PATH
if (env.NEXT_PUBLIC_BRANDING_APPLE_ICON_PATH) o.appleTouchIconPath = env.NEXT_PUBLIC_BRANDING_APPLE_ICON_PATH
if (env.NEXT_PUBLIC_BRANDING_PWA_ICON_BASE) o.pwaIconBasePath = env.NEXT_PUBLIC_BRANDING_PWA_ICON_BASE
if (env.NEXT_PUBLIC_BRANDING_THEME_COLOR) o.themeColor = env.NEXT_PUBLIC_BRANDING_THEME_COLOR
if (env.NEXT_PUBLIC_BRANDING_MANIFEST_THEME_COLOR) o.manifestThemeColor = env.NEXT_PUBLIC_BRANDING_MANIFEST_THEME_COLOR
if (env.NEXT_PUBLIC_BRANDING_MANIFEST_BG_COLOR) o.manifestBackgroundColor = env.NEXT_PUBLIC_BRANDING_MANIFEST_BG_COLOR
if (env.NEXT_PUBLIC_BRANDING_HIDDEN_NAV) {
const hrefs = env.NEXT_PUBLIC_BRANDING_HIDDEN_NAV.split(',').map(s => s.trim()).filter(Boolean)
if (hrefs.length > 0) o.hiddenNavHrefs = hrefs
}
if (env.NEXT_PUBLIC_BRANDING_NAV_DENSITY === 'slim' || env.NEXT_PUBLIC_BRANDING_NAV_DENSITY === 'standard') {
o.navDensity = env.NEXT_PUBLIC_BRANDING_NAV_DENSITY
}
return o
}