f53725b20a
* fix(sie-import): accept tab as field separator (Bollbok exports) The SIE 4 spec allows either space or tab between fields, but splitSIELine() only treated space (0x20) as a separator. Bollbok exports tab-separated lines for every record except #RAR, which silently swallowed all #IB / #UB / #KONTO / #KTYP / #VER / #TRANS records — imports appeared empty even though the file was well-formed. Also adds a parser-side diagnostic that emits a warning when raw #IB or #VER lines are present in the input but parsing produced none. The previous silent failure is how this bug stayed hidden; the warning gives the import preview something visible to surface next time. Verified against two real reproducer files (Sean / Erik Hellqvist): erik h 2025.SE (UTF-8): 166 accounts, 66 IB, 4 UB, 11 RES, 95 vouchers, 198 TRANS. erik h 2026.SE (CP437): 166 accounts, 66 IB, 4 UB, 0 vouchers. Both now parse with zero warnings/errors. Tests: + 8 Bollbok-shape tab-separated fixtures (2025 + 2026 quoting variants). + 4 silent-failure diagnostic-warning tests. All 74 sie-parser tests pass; 155/155 in lib/import; 64/64 downstream callers. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(sie-import): address PR #513 review — strip #KTYP quotes, suppress redundant aggregate warning Two non-blocking P2 findings from Greptile review on PR #513: 1. #KTYP handler stored fields[2] directly, so Bollbok 2026 exports (#KTYP\t1510\t"T") stored '"T"' with literal quotes instead of 'T'. Latent defect — accountType is unused downstream today, but my tab- separator fix made the quoted-value path reachable. Now routes through parseStringField so both Bollbok 2025 (unquoted T) and 2026 (quoted "T") land as 'T'. 2. The aggregate "kontrollera fältavskiljare och teckenkodning" warning fired alongside per-record 'error'-severity issues for malformed #IB / #VER records, producing a misleading hint when the parser had already pinpointed the structural problem. Now suppressed when an error-severity issue with the same tag already exists. Test coverage: + accountType asserted to be 'T' (not '"T"') in both 2025 + 2026 shapes. + VER aggregate-warning test now uses #VER lines without { } blocks (silent loss, no per-record error) — the canonical case the diagnostic is designed for. + New suppression test: bare #VER produces per-record errors AND the aggregate warning is absent. 75/75 sie-parser tests pass; 156/156 in lib/import. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * wip: agent chat + composer + memory + document extraction In-progress work on this branch beyond the SIE-import fixes: - Specialized accountant agent (composer + intents + chat loop) - Persistent agent_conversations/messages, agent_profiles, agent_memory - /chat surface + /onboarding/agent + /settings/agent-memory - document-extraction extension with status hooks - MCP server staging refactor + new skills (atoms, bank reconciliation, customer onboarding, kreditfaktura) - pending_operations rejection feedback (category + reason) + realtime - TIC company profile cached snapshot on companies - 17 migrations (all additive — see prior conversation analysis) Parked while branch waits for review/merge. Migrations are already applied to prod. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * refactor(tic): migrate company-data client from api-core v1 to Lens v2 Swaps the seven TIC company-data endpoints we call from the api-core paths (`/datasets/companies/{companyId}/...`, `/search/companies`) to the Lens equivalents (`/companies/{id}/...`, `/search-public/companies`). Hard cutover; proxy pattern preserved. Schema shifts handled inside the extension so consumers (TicWorkspace, Step2CompanyDetails) don't need changes: - `/companies/{id}/bank-accounts` now returns Bankgirot only — map to the existing `{ type, accountNumber, bic }` shape, drop terminated. - `/companies/{id}/industries` returns a discriminated array — filter to `companyIndustryCodeType === 'sni2007'` to preserve v1 behavior. - `/companies/{id}/phone-numbers` renamed the field to `phoneNumberFormatted` (fall back to `e164PhoneNumber`). - `/companies/{id}/documents` replaces `/financial-report-summaries`; filter `type === 'annualReport'` and read nested `financialReportMetadata` to rebuild the legacy summary shape. - `isCeased` is now a top-level boolean; `activityStatus` is an enum. Translate enum -> 'ceased' for the workspace's existing check. BankID identity flow (id.tic.io) is untouched — separate TIC product. Note: deploy gated on the TIC proxy being flipped to lens-api.tic.io with an `x-api-key` Lens key. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(tic): expose v2 onboarding & workspace data Adds six new Lens (v2) fetchers on top of the migration that already landed in this branch, surfacing the data through /lookup and /profile. New fetchers in lib/tic-client.ts: - getFiscalYears /companies/{id}/fiscal-years - getAccountingPeriods /companies/{id}/accounting-periods - getPayrolls /companies/{id}/payrolls - getSignatory /companies/{id}/signatory - getRepresentatives /companies/{id}/representatives - getCompanyStatus /companies/{id}/status /lookup gains a fiscalYear field (current fiscal-year configuration) so onboarding Step 2 can skip manual MM-DD entry. CompanyLookupResult extended with optional fiscalYear; consumers without it keep working. /profile gains five new sections on TICCompanyProfile: - fiscalYear + fiscalYearHistory current + deduped period list - signatory firmateckning descriptions - board + representatives board-composition summary + active officers (positionEnd in future) - payrolls payroll2 array newest-first, with deviation vs annual-report - statuses current+historical status entries with red/yellow/green/neutral color TicWorkspace renders the new data as four cards (Status, Fiscal year + Signatory, Board + Representatives, Payroll history) plus a Badge mapping for the traffic-light status color. Tests: 52 -> 60 passing. Added unit tests for the new fetchers' v2 paths, fiscal-year auto-fill in /lookup, and full v2 profile coverage. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(onboarding,agent): lean on TIC v2 to skip Steps 1 & 3 and sharpen Opus Three small wins that unlock more of the v2 cutover. No new endpoints — the data was already in the snapshot, just not flowing where it should. Step 1 (entity_type) — deep-link path only: - /lookup now returns `legalEntityType` and `registrationDate` (added to CompanyLookupResult). - /onboarding/page.tsx does a server-side /lookup prefetch when ?org_number= is present (BankID picker path), maps "AB"/"EF" to the EntityType enum, and seeds Step 1's radio. Falls through silently for unsupported codes (HB, KB, …) and on TIC errors. - WelcomeOnboarding hydrates ticLookup state from the server prefetch so Step 2's debounced client fetch and Step 3's first-year inference both have data on first render — no flash. Step 3 (is_first_fiscal_year) — every path: - deriveFirstYearDefaults() parses ticLookup.registrationDate and returns { isFirstFiscalYear, firstYearStart } when registered <12 months ago. Step 3's initialData picks it up; the user only confirms the end date. - Settings value wins when present so existing users with a saved choice don't get overridden. Composer prompt: - redactTic allowlist was the bottleneck — it stripped beneficialOwners, signatory, board, representatives, payrolls, statuses, fiscalYear before Opus ever saw the JSON. Existing filterRedundantQuestions ownership logic was effectively dead because the data path was severed. Expanded allowlist to include those v2 sections; kept bankAccounts/ email/phone/fiscalYearHistory/financialReports out (token cost > signal). - SYSTEM_PROMPT now documents each v2 section and the rules Opus should apply: payroll signal switches from "registration.payroll" to "actual payrolls[] filings" (kills the false-positive swedish-payroll selection for newly registered employers); beneficialOwners[] becomes the authoritative ownership source (single owner → FMB modifier; multiple → multi-owner); statuses[] isCeased/red triggers an uncertainty_note. Tests: 4112 unchanged. Build: green. No schema or migration changes. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(agent): onboarding polish + composer signal fixes from first-run feedback UX: - AgentOnboarding: drop the 10s "Hoppa över — fortsätt med standardval" escape hatch. The fallback path runs automatically on timeout; the manual skip just teased users into a degraded build. - ReviewCard step 2 title: "Stämma av detaljerna" → "Stäm av detaljerna" (imperative form matches the rest of the steps). - Drop em-dashes from user-visible Swedish strings in AgentOnboarding + ReviewCard (fallback labels, subtitles, placeholder, error message, final CTA). Em-dashes survive in code comments only. - "Fråga min revisor" → "Fråga min assistent" everywhere it surfaced: AgentTrigger, AgentSparkleButton, ReviewCard preview, ReviewCard fallback comment, general.help intent buttonLabel + prompt text. - AgentTrigger / AgentSparkleButton / EmptyState.AgentHelpLink / TransactionInboxCard ask-button all gated on identity.isVerified. Pre-onboarding users no longer see the floating FAB or per-page Sparkle buttons. AgentSheetProvider.identity gained an isVerified field; (dashboard)/layout.tsx selects agent_profiles.verified_at and passes it through. TIC verksamhetsbeskrivning: - tic/index.ts /profile: /companies/{id}/purposes returns every historical verksamhetsföremål filing. Picking [0] was returning the oldest "äga och förvalta" holding-company boilerplate for companies whose later filings narrowed the purpose ("tillhandahålla företagskrediter och finansiella teknologilösningar"). Sort the array by lastUpdatedAtUtc desc and take the most recent non-empty purpose. Composer banking signal: - loadBankingSummary now reads journal_entry_id alongside description/amount/date and returns per-counterparty `direction` ('in' | 'out' | 'mixed') and `has_unbooked` (any row not yet booked). Aggregate `unbooked_count` accompanies the rollup. - buildUserPrompt emits each counterparty as `Name: 12 345 kr (ut, OBOKFÖRD)` so Opus can tell income from cost on sight and tell which counterparties are still open questions. - SYSTEM_PROMPT now explicitly forbids verification questions about counterparties whose direction is unambiguous AND status is 'bokförd'. Should kill the regressions from the first agent build: * "Konsult, J 98 565 kr — intäkt eller kostnad?" when the amount is clearly negative. * "ALMI AB 493 000 kr — lån eller bidrag?" when the transaction is already categorized. Tests: 4112 unchanged. Build: green. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(agent,ui): representation needs deltagare+syfte, drop duplicate doc icon Representation booking: - transaction-categorization prompt now requires the agent to capture participants (name + company) AND purpose before staging a representation categorization. SKV's representationsregler + ML 8 kap require the verifikation to document who attended and what the meeting was about; without that the avdrag is denied and the post should be booked as non-deductible / personalkostnad. - The agent confirms back in plain text (audit trail in the chat), writes the deltagare + syfte to gnubok_remember_fact (long-term), THEN stages. Saknas deltagare/syfte: explicitly tell the user the avdrag won't go through and offer the non-deductible alternative. - Known gap (followup, not this commit): the staged op's journal entry description doesn't yet carry the deltagare text. Until we add a `notes` field to gnubok_categorize_transaction, the audit trail lives in chat + agent_memory only. TransactionInboxCard duplicate attachment indicator: - Drop the FileCheck2 "open document" button from the trailing slot. TransactionAttachmentIndicator (Paperclip) next to the description already opens the underlag on click. Two icons doing the same thing was noise. Cleaned up the unused state (isOpeningDoc, hasAttachment, handleOpenAttachment) and dropped now-unused imports (FileCheck2, useToast). Tests: 4112. Build: green. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(agent,nav): notes on verifikation + redesigned sidebar Audit-trail notes for representation: - gnubok_categorize_transaction gains an optional `notes` string. Threaded through stagePendingOperation → commitCategorizeTransaction → createTransactionJournalEntry, which now appends notes to the entry's description (capped at 500 chars). The verifikation an external auditor reads now carries deltagare + syfte directly — not just chat history / agent_memory. - transaction-categorization prompt updated: representation flow now REQUIRES the agent to pass deltagare+syfte via the notes parameter. Without it the booking is non-deductible / personalkostnad per SKV. DashboardNav redesign: - Top section: flat, no header — Hem (/chat), Underlag (was Dokumentinkorg), Transaktioner, Granskning. Always visible; the inline badge on /pending shows the count when there are pending ops. - Mid section: four collapsible dropdowns (Försäljning, Inköp, Redovisning, Personal). Each auto-expands when the active route lives inside it. KPI moved from main to Redovisning. Extension nav items (TIC workspace, etc.) fold into Redovisning. - Bottom-left: new account popover (DropdownMenu, opens upward) holding CompanySwitcher, Inställningar, Hjälp, Support, Logga ut. Replaces the old top company-switcher card + the bottom Support/Logout block. - Mobile drawer mirrors the new structure: top items as flat list, same four dropdown groups, separate "Tillägg" section when extensions exist, "Mitt konto" section at the bottom. - i18n: invoice_inbox label renamed "Dokumentinkorg" → "Underlag" ("Documents" in en). New keys: mitt_konto, group_extensions. Tests: 4112. Build: green. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(nav): unhide Leverantörer under Inköp The /suppliers entry existed in navItems but was marked hidden — leftover from when the supplier list lived elsewhere in the IA. Removing the hidden flag puts Leverantörer in the Inköp dropdown alongside Leverantörsfakturor. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(nav): CompanySwitcher back to top-left, user account moves bottom-left The previous pass collapsed both concepts into the bottom popover. They mean different things: the company is the org context everything below operates against (top-of-sidebar, scannable); the user is the account-holder (bottom-of-sidebar, where settings/logout live). - (dashboard)/layout.tsx: fetch profiles.full_name alongside the existing identity queries; pass userName + userEmail into DashboardNav. - DashboardNav: restore CompanySwitcher at the top of the sidebar (pre-redesign placement). Bottom-left popover trigger now shows the signed-in user's name + single-letter initial (accountInitial helper falls back to email's first char, then "?"). Popover header carries full name + email; items unchanged (Inställningar, Hjälp, Support, Logga ut). CompanySwitcher removed from inside the popover — nested dropdowns were awkward and the top placement is where it belongs. Tests: 4112. Build: green. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(pending): trim the agent context strip The row-level AgentContextStrip on /pending was rendering the model name (eu.anthropic.claude-sonnet-4-6) and the full atoms array (horizontal/swedish-vat, vertical/konsult-it, …) inline, which made each row 60–80 chars of mostly-the-same metadata. Reviewers never scan that text; they scan amounts and decide approve/reject. Now the strip shows only the conversation deep-link (Konversation #<short id>) — the one piece that's actually useful for diving into context. Model + atoms remain available in agent_metadata for debugging surfaces; they're just not in the list view. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(agent): shared ground rules + paragraph breaks after tool calls Two regressions surfaced in real usage. Both are systemic. Shared agent ground rules: - /chat surface (general.help) was happily inventing four-digit BAS account numbers ("Debet 6212 - Molntjänster…", "Kredit 2614 - Ingående moms…") and proposing booking decisions on invoices it had never seen, with no follow-up questions about currency/scope/etc. - transaction-categorization had those rules baked into its prompt; general-help / bokslut-step / invoice-draft / supplier-invoice-review / verifikation-draft / vat-review never inherited them. - Extracted lib/agent/intents/shared-rules.ts with five cross-cutting rules: underlag first (check inbox + ask user to upload to Dokumentinkorgen when missing), ask follow-ups when ambiguous, never write four-digit BAS account numbers in chat (category names only), cite atoms / load skills (don't guess), check counterparty history before proposing. - Injected renderAgentGroundRules() into all six intents above. transaction-categorization left alone — it has more detailed inline rules tied to its specific underlag-flow. Paragraph break after tool calls: - text_delta from the model often resumes after a tool call without a leading newline ("kategoriseras." → gnubok_query_journal runs → "Inget historik hittades…" appended directly). Markdown rendered the concatenation as one paragraph. - AgentChat text_delta handler now inserts \n\n when (a) the buffer ends with text content, (b) the incoming delta starts with text content, (c) at least one tool call has run, and (d) the buffer doesn't already end with a blank line. Tests: 4112. Build: green. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(nav): default-open dropdown groups; closing is per-user Dropdowns started collapsed which meant first-time users had to open each group to discover what's inside. Inverted the state: default open, user can collapse, active route still forces a group open. - manualExpanded → manualCollapsed (semantics flip) - toggleGroup unchanged externally; flips the bit - isGroupExpanded returns !manualCollapsed[g] || hasActiveChild Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(agent): rate-safe v1→v2 TIC upgrade, counterparty defaults, profile settings Three pre-ship quality wins. Rate-limit-safe TIC v2 upgrade: - The /profile endpoint fans out to ~13 Lens calls; the account has a ~3000/mo ceiling. Force-refreshing every pre-v2 (v1) snapshot across the customer base would blow the budget. - ensureTicSnapshot gains an `upgradeV1` flag. A cached snapshot still inside the 7-day window is re-fetched only when (a) the caller passes upgradeV1 AND (b) the snapshot is v1-shaped (missing the v2-only `statuses` key). Gated to the two agent-onboarding call sites — a deliberate, once-per-company action and the only consumer of the v2 sections. Workspace + signup keep the natural 7-day staleness, so the v1→v2 migration is lazy and bounded to companies actually building an agent. Known-counterparty defaults (shared-rules): - Agent now proposes a sensible default for well-known counterparties instead of asking the same question monthly: Almi → lån, Tillväxtverket/ Vinnova/EU-stöd → bidrag, Skatteverket → skatt/avgift or återbäring, Bolagsverket → avgift, Försäkringskassan → ersättning, EF private withdrawal → eget uttag. Stated as an assumption the user can correct, not a hard rule — underlag/history still wins. Företagsprofil settings page: - New /settings/agent-profile (Företagsprofil / "Company profile"): view + edit the agent's company profile after onboarding — assistant name + avatar, the profile summary the agent reasons from, and a read-only chip view of loaded specialities (atoms). Backed by the existing GET/PATCH /api/agent/profile. - New GET /api/agent/atom-titles?ids= resolves atom slugs → human titles for the chips (registry is globally-readable reference data). - Added to SettingsSidebar; i18n keys agent_profile (sv "Företagsprofil" / en "Company profile"). Note: /chat already redirects unverified users to / (chat layout guard), and / renders WelcomeGate → /onboarding/agent. No redirect work needed. AgentSetupBanner.tsx is orphaned dead code (WelcomeGate superseded it). Tests: 4112. Build: green. Both new routes compile. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(nav,agent): Hem=Översikt + separate Assistent button; memory dedup Nav restructure: - "Hem" now points to / (Översikt dashboard) again, not /chat. The agent chat gets its own top-level nav entry "Assistent" (Sparkles icon) → /chat. Mobile bottom nav mirrors this (Hem / Assistent / Transaktioner). - / restored to render DashboardContent (the Översikt) for built-agent users instead of redirecting to /chat. Users who haven't built their assistant yet still get WelcomeGate (the build-agent checklist); once verified, / shows the dashboard. Chat is reachable anytime via its nav entry. Restored main's dashboard data-fetch; added an agent_profiles verified_at probe to drive the WelcomeGate branch. - i18n: nav.assistant ("Assistent" / "Assistant"). agent_memory dedup (gnubok_remember_fact): - The agent re-remembers the same fact constantly (e.g. "Vercel = omvänd skattskyldighet" on every Vercel categorization), which would bloat agent_memory with paraphrases over months. - Before insert, compare the incoming fact against the 300 most-recent active memories by word-set Jaccard similarity (lowercased, punctuation- stripped, stopwords dropped). A near-duplicate (≥0.82) is treated as already-known: bump its relevance toward the new score + refresh updated_at instead of writing a new row. Embedding-free, zero added latency beyond one bounded SELECT. Tests: 4112. Build: green. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(agent,nav): företagsprofil=Bolagsuppgifter, avatar nav icon, dedupe greeting Företagsprofil settings page (the right content this time): - Replaced the agent atoms/summary panel with CompanyProfileView — a read-only "Bolagsuppgifter" view of the cached TIC company snapshot (name, org-nr, form, address, F-skatt/Moms/Arbetsgivare, SNI, bank, verksamhet, employees, latest financials, status traffic-lights, fiscal year, firmateckning, företrädare). Server component reads the companies.tic_snapshot column directly — no extension import, stays inside the core-build boundary. - Route renamed /settings/agent-profile → /settings/company-profile. Removed the old AgentProfilePanel + the now-unused /api/agent/atom-titles endpoint. "Assistent" nav icon = the agent's chosen avatar: - DashboardNav reads agent identity from AgentSheetProvider and renders the onboarding-chosen avatar for the /chat ("Assistent") entry across desktop sidebar, mobile drawer, and mobile bottom nav. Falls back to the Sparkles glyph pre-onboarding (no avatar yet). Nav cleanup: - Dropped the beta badge from Underlag. - Filtered the TIC workspace (/e/general/tic, "Företagsprofil") out of the nav — the same Bolagsuppgifter now lives under Inställningar → Företagsprofil, so it shouldn't appear in two places. Doubled intake greeting fix: - /chat/intake fires an invoke with no conversation_id, then swaps the URL to /chat/[id] the instant the `conversation` event lands — which can beat the greeting being persisted. /chat/[id] then hydrated with 0 messages and, because the auto-fire guard keyed on (id && messages>0), fired a SECOND invoke on the same conversation → two greetings. Guard now keys on conversation-id presence alone: a set id means resume, never bootstrap. Closes the race. Tests: 4112. Build: green. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(agent): paragraph-break-after-tool split words mid-stream The earlier "insert \n\n when text resumes after a tool call" heuristic re-evaluated on EVERY text_delta (any delta not starting/ending with whitespace, once a tool had run). Streaming deltas arrive in sub-word chunks, so it injected breaks between fragments of the same word: "minnes\n\nno\n\nterna", "kund\n\nrep\n\nresentation". Replace the per-delta heuristic with a consume-once ref: - tool_use sets breakBeforeNextTextRef = true - the next text_delta consumes it: prepends \n\n exactly once (only when the buffer has content, doesn't already end in whitespace, and the delta doesn't start with whitespace), then clears the flag So the break fires once per tool→text resume, never mid-word. Build: green. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(agent): much shorter replies, representation headcount + VAT cap, dot separator Brevity (system-prompt Svarsformat — affects every reply): - Hard "korthet är regel nummer ett": aim for 2-4 sentences, lead with the answer/action, no warm-up ("Här är vad som gäller…"), don't derive VAT in prose, don't restate what the approval card shows, one question at a time. The agent was writing textbook-length essays. Representation rule now in shared-rules (so verifikation-draft, vat-review, etc. all get it — previously only transaction-categorization had it, which is why the verifikation flow guessed 25% VAT and skipped the cap): - Require ANTAL deltagare (headcount), not just one name — the moms deduction is per person (underlag cap 300 kr/person ex moms). - Use the receipt's ACTUAL VAT rate (usually 12% on food), never assume 25%. - Meal representation isn't income-tax deductible (post-2017); whole cost booked as non-deductible representation. Verifikation description separator: - createTransactionJournalEntry appended notes with an em-dash ("Utlägg Eatnam — Deltagare:…"), violating house style. Switched to a middle dot " · ". journal_entries has no separate notes column — the description IS the BFL verifikationstext / audit field, so deltagare + syfte correctly live there. Tests: 4112. Build: green. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(settings): tidy Bolagsuppgifter — no status colours, clean firmateckning From first-look feedback on the Företagsprofil page: - Status: dropped the coloured traffic-light badges (red/yellow/green). Per the design system semantic colour is data-only, never chrome, so status now renders as plain label + date. Also filtered to dated entries only — Bolagsverket emits flags like "Har aldrig varit verksam" with no date that read as noise next to the real status. Ceased status gets muted destructive text (the one chrome colour the system keeps). - Firmateckning: the source text carries ">" list markers and crams several rules onto one line, and repeats "Firman tecknas av styrelsen" across rows. cleanSignatory() strips the markers, normalises whitespace, splits run-on "Firman tecknas …" clauses onto separate lines, and the render dedupes — so each rule reads as its own sentence. Build: green. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(mcp): inbox items expose all terminal links + processed flag The Eatnam receipt was booked against its bank transaction (so the inbox row had matched_transaction_id + created_journal_entry_id set), yet the agent reported it as loose/unmatched and a duplicate risk. Root cause: gnubok_list_inbox_items only selected and returned matched_supplier_id + created_supplier_invoice_id — the supplier-invoice path. The transaction-match and direct-journal-entry paths were invisible, so any receipt cleared via /transactions looked unprocessed. - list_inbox_items now selects + returns matched_transaction_id and created_journal_entry_id alongside the supplier fields, plus a derived `processed` boolean (true when ANY of the three terminal links is set). - New unprocessed_only=true input filters to items with no terminal link — the "what still needs handling" view that prevents the agent from flagging already-booked docs as duplicates. (Fetches a wider window then filters client-side so limit applies post-filter.) - Description updated to document the processed semantics, within the 280-char tool-description budget. The DB linkage itself already worked: /transactions attach-document sets matched_transaction_id, and commitCategorizeTransaction stamps created_journal_entry_id. This was purely a read/surface gap. Tests: 4112 (+ MCP description guard). Build: green. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(mcp): repair stage-but-never-commit tools + consolidate tool surface - post_annual_depreciation AND reverse_entry were never in the pending_operations operation_type CHECK, so both staged then died with check_violation at INSERT. Add the CHECK migration, a commitPostAnnualDepreciation executor (reusing commitAnnualPostings), risk tier, and the PendingOperationType union member. - Salary tools de-risked: calculate_salary_run calls runSalaryCalculation() directly (no self-fetch/forged cookie); create_salary_run uses a transactional create-run helper with compensating delete; generate_agi actually generates + persists the declaration. - import_sie parses + validates at stage time with a content-rich preview (company, fiscal year, voucher/account counts, balance) instead of a blind byte count. - batch-match-invoices passed user.id where companyId was expected (silently matched zero). - VAT report+widget merged behind render_ui; gnubok_search_tools ranks by relevance; gnubok_feedback readOnlyHint corrected; tools/list instruction text fixed; income decision-tree + GL/query_journal cross-refs added. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(agent): load skill atom bodies from the DB so they survive the build Skill bodies were read from disk at runtime (.claude/skills/**/SKILL.md); on Vercel the dynamic readFile path isn't traced into the lambda and on Docker .claude/ is excluded, so atoms loaded EMPTY in production — a despecialized agent. Inline the bodies into agent_atom_registry instead: - Migration adds body + mcp_exposed columns; a build-time generator (scripts/generate-skill-bodies.ts) emits a deterministic dollar-quoted seed migration with a content-hash manifest + --check CI guard. - Read sites (mcp-server atoms.ts, chat system-prompt.ts, composer prewarm) read body from the DB, with a dev-only disk fallback. mcp_exposed curates which atoms the MCP exposes (swarm-* never become atoms). - The seed script + generator share scripts/lib/atom-discovery.ts; estimated_tokens now reflects SKILL.md only. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(agent): safe the in-app assistant — gating, FAB de-confliction, rate limit, friendly errors - Hide all agent entry points until verified_at: the Assistent nav tab (sidebar + mobile) and the agent-memory settings tab now match the floating FAB's gate. - FAB de-confliction: /kpi -> kpi.explain and /bookkeeping/year-end -> bokslut.step so the floating button opens the SAME assistant as the page button (no two-agents-on-one-page). - Generous per-user rate limit (30/min, 1000/day) on /api/agent/invoke, /onboarding/stream, /composer via a new agent_rate_counters table + check_and_increment_agent_quota RPC; fails open. Bounds runaway Bedrock spend without touching normal users. - Friendly errors: Bedrock 429/timeout/5xx normalized to Swedish (friendlyModelError) in run-turn + the invoke route; the chat client surfaces the server's friendly message instead of a raw HTTP status. - /chat/new validates ?intent= against the registry so bad deep-links fall back to general.help instead of rendering a broken-looking error. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(agent): keep /chat read-only — redirect categorization + swap the "categorize" suggestion for a VAT-report question general.help (the /chat assistant) is read-only, but it still gave per-transaction bokföringsförslag in prose and asked "godkänner du dessa?" — an analysis the user can't act on (no write tool, no per-tx underlag). Strengthen the prompt to redirect categorization/bokföring to the per-transaction flow (open the transaction -> "Fråga om denna transaktion", where the agent sees the underlag and stages a real ApprovalCard); a short overview is still allowed. Add a guard test locking in no-write-tools + the redirect language. Swap the /chat empty-state "Hjälp mig kategorisera" chip (which lured users into exactly this dead-end) for a VAT-report question the read-only assistant can actually answer. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * refactor(pending): declutter the review queue rows + header Fold the conversation deep-link onto the actor label (drop the separate "Konversation #xxxx" strip and its icon), hide the quick-pick when there's only one operation type (it duplicated "Markera alla"), and drop the "(0)" from the disabled bulk-approve button. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(vat): enhance VAT handling by integrating document validation and improving error messaging * feat(settings): add assistant knowledge surface + consolidate settings tabs Expose the agent's skill atoms (agent_atom_registry) in a read-only surface beside the existing memory view, and tighten the settings tab bar from 14 to 10 tabs. - New GET /api/agent/skills + AgentSkillsPanel: lists active, mcp_exposed atoms grouped by tier (Kärnkompetens / bransch / bolagssituation), flags which are active for the company from agent_profiles, and lazy-loads each SKILL.md body on expand. - New /settings/assistant tab with a Minne/Kompetens toggle (?view=skills); /settings/agent-memory and /settings/agent-skills redirect into it. - Merge Företagsprofil (TIC snapshot) into the Företag tab via CompanyProfileSection; /settings/company-profile redirects. - Merge Skatteverket-anslutningen into the Skatt tab — OAuth returnTo and the callback toast now target /settings/tax; /settings/skatteverket redirects. - Drop the Säkerhetsbackup tab (already under Importera/Exportera). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(inbox): keep booked underlag out of the unmatched queue + widen match window - categorize: after booking an inbox underlag onto a verifikat, backfill the inbox row's matched_transaction_id + created_journal_entry_id so it stops showing as unmatched (mirrors the /attach-document paperclip path). - TransactionMatchPicker: bias the candidate window forward (60d before → 180d after the invoice date) so late payments aren't dropped before scoring, and widen the ranking date tolerance to 120d so the true match floats to the top instead of collapsing to "Svag match". Fix "okatigoriserade" typo. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * wip: bundle in-progress branch work + agent onboarding chat optimizations Captures the uncommitted work-in-progress on this branch so it lives on the remote. Heterogeneous changeset — bundled as one commit since the work was already entangled across files. Headline change in this commit (from this session): - Remove the double interview in agent onboarding. Phase B's verification- question form stepper is gone — the Phase C chat (onboarding.intake) now owns the entire interview and reads the composer's verification_questions server-side as its question bank. - ReviewCard collapses from 3 steps to 2 (meet → review-and-confirm) with value-first ordering: profile + "vad jag kan hjälpa dig med" + facts + optional seed note. CTA reads "Möt {namn}" to signal the chat follows. - ChatIntakeStarter handoff subcopy updated to match reality (assistant greets first; user can leave anytime). - Stamp agent_profiles.intake_completed_at server-side in app/api/agent/invoke/route.ts on the first user-typed reply in any onboarding.intake conversation (idempotent IS NULL guard, best-effort). Closes the previously dead-write column and unlocks the opportunistic- follow-up hook the migration anticipated. Plus in-progress branch work being carried forward (not introduced here): agent runtime + intent prompts, composer + atom-discovery scripts, MCP server skills surface, onboarding flow components, dashboard/inbox tweaks, two new agent_atom_registry migrations, additional agent-chat tests. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * refactor(agent): drop inline "Fråga assistenten" affordances — rely on the FAB The bottom-right "Fråga {namn}" FAB (AgentTrigger) is already route-aware and picks the right intent per page, so duplicating it as inline page- header buttons and empty-state links is noise. Removed: - EmptyState `agentHelp` link ("Eller fråga {namn} hur du kommer igång") + the AgentHelpLink component + agent_default_name/agent_ask_link i18n keys + the agentHelp props on EmptyInvoices/EmptyCustomers/EmptyTransactions. - AgentSparkleButton on /bookkeeping (verifikation.draft) and /kpi (kpi.explain) page headers. The FAB stays — when verified, it appears on those routes and routes to the right intent automatically. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(agent): gate the last two ungated "Fråga assistenten" affordances Both surfaces previously called useAgentSheet directly without checking identity.isVerified, so they appeared pre-onboarding (everywhere else the FAB / sparkle buttons / /chat / Assistent nav are all gated on verified_at). - Settings page header: remove the "Fråga {namn}" pill entirely. The FAB covers /settings routes route-aware (settings.help) — no need for a duplicate inline trigger. - Invoice inbox transaction picker: hide the "Fråga assistenten" button when the agent isn't built. Done at the parent (InvoiceInboxWorkspace) by passing onAskAssistant only when identity.isVerified is true; the child renders the button only when the callback is present. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(tic,onboarding,agent): single-call TIC lookup + director-aware narrative voice - TIC: collapse the company lookup from 6 endpoint calls to 1 (search-public already exposes sniCodes, bank accounts, emails, phones, and registration flags). Derive fiscal-year MM-DD from mostRecentFinancialSummary; newly-registered companies fall through to the client's first-year defaults. - Onboarding: BankID picker no longer auto-provisions companies. Every pick routes through the wizard with orgnr (and entity_type via the CompanyRoles match) prefilled; F-skatt/VAT/address get confirmed in steps 2-4 instead of being auto-fetched. createCompanyFromOnboarding reuses CompanyLookupResult and adds a defensive top-level catch so server-action errors surface to the UI instead of being redacted. - Agent composer: loadUserDirectorship() checks BankID CompanyRoles for a director-like position (ceo/boardMember/chairman/externalSignatory, active) before the narrative uses second-person ownership voice ("Du driver…"); unknown users get neutral third-person voice so we never put ownership words in the user's mouth. Tests cover loadUserDirectorship, narrative voice, tic-fetch path, onboarding page, and updated TIC client + lookup/profile suites. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(tic): extend agent-onboarding TIC budget to 10s + backfill stranded org_numbers The 5s TIC fetch timeout aborted client-side before the upstream Lens fan-out (~13 calls) could complete, but the in-flight upstream calls still counted against quota — actions.ts already documents ~530 wasted calls from this in May. Same bug still applied to the agent-onboarding stream path. Adds an optional `timeoutMs` to `ensureTicSnapshot` so deliberate wait-screen callers (agent onboarding stream) can run with 10s while background/dev callers stay on the conservative 5s default. Page-level server fetch (page.tsx) intentionally stays at 5s to avoid blocking TTFB without a visible progress affordance. Backfill migration mirrors `company_settings.org_number` to `companies.org_number` for the 105 cases where it's safe (after dedup + conflict filtering). 56 of those are on active companies — unblocks duplicate guards, SIE/SRU exports, and TIC fallback chain. Zero TIC API calls — pure data move. Idempotent. Also sweeps a pre-existing SSRF guard on the stream route's origin derivation that was sitting unstaged in the working tree — it lives in the same diff hunks as the TIC budget change and couldn't be split cleanly. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * wip: bundle in-progress branch work Sweep up uncommitted agent/MCP/RLS work-in-progress so the branch is fully backed up to origin. Not reviewed in detail — committed as-is to preserve working state alongside the TIC fixes in the previous commit. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(agent): tag the "Bygg din bokföringsassistent" CTA as Beta Adds a Beta badge next to the assistant-setup heading on the dashboard banner, dashboard inline card, and onboarding checklist row. Also drops the stale "Gratis i 30 dagar" subline from the dashboard card. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(build,migrations): PendingOperationType salary ops + resolve migration version collisions PR #584 went red on three things: 1. core-only build / Vercel: `lib/pending-operations/commit.ts:2666` switched on 'create_salary_run' and 'generate_agi' but `PendingOperationType` was missing both literals. Add them to the union. 2. Supabase preview: migration version 20260526120000 collided with main's newly-merged 20260526120000_fix_replace_sie_import_hard_delete.sql. Bump the branch's pair to 20260526120050 / 20260526120051 — still ahead of 20260526120100_restvardeavskrivning so ordering is preserved. 3. 20260527170000 was used twice on this branch (_agent_rls_with_check + _journal_entry_no_doc_required). Bump the second to 20260527170100 so the pair stays orderable and Supabase doesn't choke on the duplicate schema_migrations PK. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(ci): reword comment so core-only guard stops flagging it The "Check no core imports from extensions" step greps for the literal \`from '@/extensions/\` across lib/, app/api/, components/. A comment in lib/agent/composer/tic-fetch.ts quoted the exact pattern verbatim to explain *why* the file does a self-fetch instead of importing the TIC extension directly — which the grep matched even though no actual import exists. Rewrite the line to keep the same meaning without the literal pattern. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: Emil <emilmattsson14@gmail.com>
1713 lines
64 KiB
TypeScript
1713 lines
64 KiB
TypeScript
/**
|
||
* Canonical registry of structured error codes used by both REST routes and
|
||
* the MCP server.
|
||
*
|
||
* Each entry defines:
|
||
* - httpStatus: status returned by errorResponse() for this code
|
||
* - message_sv: Swedish user-facing message (consumed by toast)
|
||
* - message_en: English message for agents and developer logs
|
||
* - remediation: optional pointer to a fix (tool/resource/description)
|
||
*
|
||
* Adding a new code = add a row here. The error-code-matrix in
|
||
* `.claude/plans/for-all-of-those-mutable-sunset.md` lists the codes per
|
||
* operation; keep that document and this file in sync.
|
||
*
|
||
* Codes follow `<DOMAIN>_<OPERATION>_<CAUSE>` naming. Stable forever once
|
||
* shipped — agents pattern-match on them.
|
||
*/
|
||
|
||
export interface StructuredErrorRemediation {
|
||
description: string
|
||
tool?: string
|
||
args?: Record<string, unknown>
|
||
resource?: string
|
||
}
|
||
|
||
export interface StructuredErrorEntry {
|
||
httpStatus: number
|
||
message_sv: string
|
||
message_en: string
|
||
remediation?: StructuredErrorRemediation
|
||
/**
|
||
* When true, agents and clients may retry the same request after a short
|
||
* backoff. Set only on truly transient failures (DB blip, external API
|
||
* timeout, rate limit). Permanent failures (validation, not found, period
|
||
* locked) MUST stay false — retrying won't change the outcome.
|
||
*/
|
||
retryable?: boolean
|
||
}
|
||
|
||
// ─────────────────────────────────────────────────────────────────
|
||
// Generic / cross-cutting codes
|
||
// ─────────────────────────────────────────────────────────────────
|
||
|
||
const GENERIC: Record<string, StructuredErrorEntry> = {
|
||
UNKNOWN_ERROR: {
|
||
httpStatus: 500,
|
||
message_sv: 'Något gick fel. Försök igen.',
|
||
message_en: 'An unexpected error occurred.',
|
||
},
|
||
INTERNAL_ERROR: {
|
||
httpStatus: 500,
|
||
message_sv: 'Ett oväntat serverfel uppstod. Försök igen senare.',
|
||
message_en: 'Internal server error.',
|
||
},
|
||
VALIDATION_ERROR: {
|
||
httpStatus: 400,
|
||
message_sv: 'Förfrågan innehåller ogiltiga uppgifter.',
|
||
message_en: 'Validation error.',
|
||
},
|
||
UNAUTHORIZED: {
|
||
httpStatus: 401,
|
||
message_sv: 'Din session har gått ut. Logga in igen.',
|
||
message_en: 'Authentication required.',
|
||
},
|
||
MFA_REQUIRED: {
|
||
httpStatus: 403,
|
||
message_sv: 'Tvåstegsverifiering krävs för att utföra åtgärden.',
|
||
message_en: 'MFA verification required.',
|
||
},
|
||
FORBIDDEN: {
|
||
httpStatus: 403,
|
||
message_sv: 'Du har inte behörighet att utföra denna åtgärd.',
|
||
message_en: 'Insufficient permissions.',
|
||
},
|
||
NOT_FOUND: {
|
||
httpStatus: 404,
|
||
message_sv: 'Resursen kunde inte hittas.',
|
||
message_en: 'Resource not found.',
|
||
},
|
||
CONFLICT: {
|
||
httpStatus: 409,
|
||
message_sv: 'En konflikt uppstod. Ladda om sidan och försök igen.',
|
||
message_en: 'Conflict.',
|
||
},
|
||
RATE_LIMITED: {
|
||
httpStatus: 429,
|
||
message_sv: 'För många förfrågningar. Vänta en stund och försök igen.',
|
||
message_en: 'Rate limit exceeded.',
|
||
retryable: true,
|
||
},
|
||
NOT_IMPLEMENTED: {
|
||
httpStatus: 501,
|
||
message_sv: 'Funktionen är inte implementerad ännu.',
|
||
message_en: 'This feature is accepted by the schema but not yet implemented.',
|
||
},
|
||
COMPANY_CONTEXT_MISSING: {
|
||
httpStatus: 400,
|
||
message_sv: 'Ingen aktiv företagskontext. Välj ett företag och försök igen.',
|
||
message_en: 'No active company context resolved for the request.',
|
||
},
|
||
IDEMPOTENCY_KEY_REUSE: {
|
||
httpStatus: 409,
|
||
message_sv: 'Idempotensnyckeln har redan använts med en annan begäran.',
|
||
message_en: 'Idempotency key was previously used with a different request body.',
|
||
remediation: {
|
||
description:
|
||
'Use a fresh UUID for a new operation, or send the original request body to replay.',
|
||
},
|
||
},
|
||
INSUFFICIENT_SCOPE: {
|
||
httpStatus: 403,
|
||
message_sv: 'API-nyckeln saknar behörighet för denna åtgärd.',
|
||
message_en: 'The current API key does not have the required scope.',
|
||
remediation: {
|
||
description:
|
||
'Mint a new key with the missing scope or grant it through the API key settings.',
|
||
resource: 'gnubok://capabilities',
|
||
},
|
||
},
|
||
}
|
||
|
||
// ─────────────────────────────────────────────────────────────────
|
||
// Bookkeeping engine codes (already used by lib/bookkeeping/errors.ts)
|
||
// ─────────────────────────────────────────────────────────────────
|
||
|
||
const BOOKKEEPING: Record<string, StructuredErrorEntry> = {
|
||
ACCOUNTS_NOT_IN_CHART: {
|
||
httpStatus: 400,
|
||
message_sv: 'Konton saknas i kontoplanen.',
|
||
message_en: 'One or more BAS accounts are not active in the chart of accounts.',
|
||
remediation: {
|
||
description:
|
||
'Activate the missing accounts via bookkeeping settings, or use a different category.',
|
||
resource: 'gnubok://chart-of-accounts',
|
||
},
|
||
},
|
||
JOURNAL_ENTRY_NOT_BALANCED: {
|
||
httpStatus: 400,
|
||
message_sv: 'Verifikationen balanserar inte.',
|
||
message_en: 'Debits and credits do not match.',
|
||
remediation: {
|
||
description: 'Recalculate the lines so totals are equal before retrying.',
|
||
},
|
||
},
|
||
FISCAL_PERIOD_NOT_FOUND: {
|
||
httpStatus: 404,
|
||
message_sv: 'Räkenskapsperioden kunde inte hittas.',
|
||
message_en: 'No fiscal period covers the entry date.',
|
||
remediation: {
|
||
description: 'Create or extend the relevant fiscal period before retrying.',
|
||
resource: 'gnubok://period/active',
|
||
},
|
||
},
|
||
ENTRY_DATE_OUTSIDE_FISCAL_PERIOD: {
|
||
httpStatus: 400,
|
||
message_sv: 'Datumet ligger utanför det valda räkenskapsåret.',
|
||
message_en: 'Entry date is outside the active fiscal period.',
|
||
remediation: {
|
||
description: 'Use a date inside an open period or create one that covers it.',
|
||
resource: 'gnubok://period/active',
|
||
},
|
||
},
|
||
JOURNAL_ENTRY_NOT_FOUND: {
|
||
httpStatus: 404,
|
||
message_sv: 'Verifikationen kunde inte hittas.',
|
||
message_en: 'Journal entry not found.',
|
||
},
|
||
CANNOT_REVERSE_NON_POSTED: {
|
||
httpStatus: 400,
|
||
message_sv: 'Endast bokförda verifikationer kan stornas.',
|
||
message_en: 'Only posted entries can be reversed.',
|
||
},
|
||
CANNOT_CORRECT_NON_POSTED: {
|
||
httpStatus: 400,
|
||
message_sv: 'Endast bokförda verifikationer kan rättas.',
|
||
message_en: 'Only posted entries can be corrected.',
|
||
},
|
||
ENTRY_ALREADY_REVERSED: {
|
||
httpStatus: 409,
|
||
message_sv:
|
||
'Verifikationen har redan stornats av en annan användare. Ladda om sidan och försök igen.',
|
||
message_en: 'Entry was already reversed by a concurrent operation.',
|
||
},
|
||
CURRENCY_REVALUATION_ALREADY_EXISTS: {
|
||
httpStatus: 409,
|
||
message_sv: 'En valutaomvärdering finns redan för denna period.',
|
||
message_en: 'Currency revaluation already exists for this period.',
|
||
},
|
||
INVALID_MAPPING_RESULT: {
|
||
httpStatus: 400,
|
||
message_sv: 'Kontering saknas för transaktionen. Kontrollera bokföringsreglerna.',
|
||
message_en: 'Mapping rules produced an invalid debit/credit account pair.',
|
||
},
|
||
BOOKKEEPING_DATABASE_ERROR: {
|
||
httpStatus: 500,
|
||
message_sv: 'Verifikationen kunde inte sparas. Försök igen.',
|
||
message_en: 'Bookkeeping database operation failed.',
|
||
retryable: true,
|
||
},
|
||
PERIOD_LOCKED: {
|
||
httpStatus: 400,
|
||
message_sv: 'Bokföringen är låst för denna period.',
|
||
message_en: 'Period is locked or closed; entries cannot be added.',
|
||
remediation: {
|
||
description:
|
||
'Either unlock the period via gnubok_unlock_period (if status is "locked", not "closed") or change the entry date to fall inside an open period.',
|
||
tool: 'gnubok_unlock_period',
|
||
},
|
||
},
|
||
PERIOD_NOT_LOCKED: {
|
||
httpStatus: 400,
|
||
message_sv: 'Perioden måste först låsas innan den kan stängas.',
|
||
message_en: 'Period must be locked before it can be closed.',
|
||
remediation: {
|
||
description: 'Call gnubok_lock_period before closing.',
|
||
tool: 'gnubok_lock_period',
|
||
},
|
||
},
|
||
PERIOD_HAS_UNBOOKED_TRANSACTIONS: {
|
||
httpStatus: 400,
|
||
message_sv:
|
||
'Perioden innehåller okategoriserade affärstransaktioner. Bokför eller markera dem som privata innan låsning.',
|
||
message_en: 'The period contains uncategorized business transactions.',
|
||
remediation: {
|
||
description: 'Categorize or mark uncategorized transactions before locking.',
|
||
tool: 'gnubok_list_uncategorized_transactions',
|
||
},
|
||
},
|
||
YEAR_END_NOT_RUN: {
|
||
httpStatus: 400,
|
||
message_sv: 'Bokslutsåtgärder måste utföras innan perioden kan stängas.',
|
||
message_en: 'Year-end closing must be executed before the period can be closed.',
|
||
},
|
||
TRANSACTION_ALREADY_CATEGORIZED: {
|
||
httpStatus: 409,
|
||
message_sv:
|
||
'Transaktionen är redan bokförd. Ångra kategoriseringen om du vill ändra den.',
|
||
message_en: 'The transaction already has a journal entry.',
|
||
remediation: {
|
||
description:
|
||
'Use gnubok_uncategorize_transaction first if you need to recategorize.',
|
||
tool: 'gnubok_uncategorize_transaction',
|
||
},
|
||
},
|
||
INVOICE_ALREADY_SENT: {
|
||
httpStatus: 409,
|
||
message_sv: 'Fakturan har redan skickats eller betalats.',
|
||
message_en: 'The invoice is already sent or paid.',
|
||
},
|
||
}
|
||
|
||
// ─────────────────────────────────────────────────────────────────
|
||
// Wave 1: invoicing & transactions
|
||
// ─────────────────────────────────────────────────────────────────
|
||
|
||
const TRANSACTIONS: Record<string, StructuredErrorEntry> = {
|
||
TX_CATEGORIZE_TX_NOT_FOUND: {
|
||
httpStatus: 404,
|
||
message_sv: 'Transaktionen kunde inte hittas.',
|
||
message_en: 'Transaction not found.',
|
||
},
|
||
TX_CATEGORIZE_INVALID_ACCOUNT: {
|
||
httpStatus: 400,
|
||
message_sv: 'Det valda kontot finns inte i kontoplanen.',
|
||
message_en: 'The supplied account does not exist in the chart of accounts.',
|
||
remediation: {
|
||
description: 'Activate the account in the chart of accounts or pick a different one.',
|
||
resource: 'gnubok://chart-of-accounts',
|
||
},
|
||
},
|
||
TX_CATEGORIZE_INVALID_TEMPLATE: {
|
||
httpStatus: 400,
|
||
message_sv: 'Bokföringsmallen är ogiltig eller passar inte din bolagsform.',
|
||
message_en: 'The supplied booking template is invalid or does not match the entity type.',
|
||
},
|
||
TX_CATEGORIZE_INVALID_MAPPING: {
|
||
httpStatus: 400,
|
||
message_sv: 'Konteringen saknar debet- eller kreditkonto.',
|
||
message_en: 'Mapping result is missing a debit or credit account.',
|
||
},
|
||
TX_CATEGORIZE_RACE: {
|
||
httpStatus: 409,
|
||
message_sv: 'Transaktionen kategoriserades av en annan förfrågan. Ladda om och försök igen.',
|
||
message_en: 'Transaction was already categorized by another request.',
|
||
},
|
||
TX_CATEGORIZE_SUGGEST_SI_MATCH: {
|
||
httpStatus: 409,
|
||
message_sv:
|
||
'Det finns en öppen leverantörsfaktura från samma leverantör med samma belopp. Matcha mot fakturan istället för att bokföra direkt på leverantörsskuldskontot — annars skapas en dubblerad verifikation som måste stornas (BFL 5 kap 5 §).',
|
||
message_en:
|
||
'An open supplier invoice from the same supplier matches this amount. Suggest matching to the invoice instead of a plain 244x categorization to avoid producing a duplicate verifikation (BFL 5 kap 5 §).',
|
||
remediation: {
|
||
description:
|
||
'Match the transaction via POST /api/transactions/{id}/match-supplier-invoice, or resend with confirm_no_match: true to keep the plain 244x categorization.',
|
||
},
|
||
},
|
||
TX_CATEGORIZE_SUGGEST_CI_MATCH: {
|
||
httpStatus: 409,
|
||
message_sv:
|
||
'Det finns en obetald kundfaktura från samma kund med samma belopp. Matcha mot fakturan istället för att bokföra direkt mot kundfordringskontot — annars skapas en dubblerad verifikation som måste stornas (BFL 5 kap 5 §).',
|
||
message_en:
|
||
'An unpaid customer invoice from the same customer matches this amount. Suggest matching to the invoice instead of a plain 151x categorization to avoid producing a duplicate verifikation (BFL 5 kap 5 §).',
|
||
remediation: {
|
||
description:
|
||
'Match the transaction via POST /api/transactions/{id}/match-invoice, or resend with confirm_no_match: true to keep the plain 151x categorization.',
|
||
},
|
||
},
|
||
TX_UNCATEGORIZE_NO_LINKED_ENTRY: {
|
||
httpStatus: 400,
|
||
message_sv: 'Transaktionen har ingen kopplad verifikation att stornera.',
|
||
message_en: 'Transaction has no linked journal entry to reverse.',
|
||
},
|
||
TX_EXCHANGE_RATE_UNAVAILABLE: {
|
||
httpStatus: 502,
|
||
message_sv:
|
||
'Kunde inte hämta växelkursen från Riksbanken. Försök igen om en stund — verifikationen måste bokföras i SEK.',
|
||
message_en:
|
||
'Could not fetch the exchange rate from Riksbanken. The verifikation must be posted in SEK.',
|
||
retryable: true,
|
||
},
|
||
}
|
||
|
||
const MATCH_INVOICE: Record<string, StructuredErrorEntry> = {
|
||
MATCH_INVOICE_NOT_FOUND: {
|
||
httpStatus: 404,
|
||
message_sv: 'Fakturan kunde inte hittas.',
|
||
message_en: 'Invoice not found.',
|
||
},
|
||
MATCH_INVOICE_NOT_INCOME: {
|
||
httpStatus: 400,
|
||
message_sv: 'Endast intäktstransaktioner kan matchas mot kundfakturor.',
|
||
message_en: 'Only income transactions can be matched to customer invoices.',
|
||
},
|
||
MATCH_INVOICE_TX_ALREADY_LINKED: {
|
||
httpStatus: 400,
|
||
message_sv: 'Transaktionen är redan kopplad till en faktura.',
|
||
message_en: 'Transaction is already linked to an invoice.',
|
||
},
|
||
MATCH_INVOICE_NOT_OPEN: {
|
||
httpStatus: 400,
|
||
message_sv: 'Fakturan är inte i ett obetalt läge och kan inte matchas.',
|
||
message_en: 'Invoice is not in an unpaid state.',
|
||
},
|
||
MATCH_INVOICE_NOT_INVOICE_TYPE: {
|
||
httpStatus: 400,
|
||
message_sv: 'Endast fakturor kan matchas mot en transaktion. Proforma och följesedel saknar momsskyldighet.',
|
||
message_en: 'Only invoices may be matched to a transaction; proforma and delivery notes have no VAT obligation.',
|
||
},
|
||
MATCH_INVOICE_ALREADY_PAID: {
|
||
httpStatus: 409,
|
||
message_sv: 'Fakturan har redan slutbetalats av en annan förfrågan.',
|
||
message_en: 'Invoice has already been fully paid or is no longer matchable.',
|
||
},
|
||
MATCH_INVOICE_DUPLICATE_PAYMENT: {
|
||
httpStatus: 409,
|
||
message_sv: 'Den här transaktionen är redan matchad mot fakturan.',
|
||
message_en: 'This transaction is already matched to this invoice.',
|
||
},
|
||
MATCH_INVOICE_RECORD_PAYMENT_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Kunde inte registrera fakturabetalningen.',
|
||
message_en: 'Failed to record invoice payment.',
|
||
retryable: true,
|
||
},
|
||
MATCH_INVOICE_LINK_TX_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Kunde inte koppla transaktionen till fakturan.',
|
||
message_en: 'Failed to link transaction to invoice.',
|
||
retryable: true,
|
||
},
|
||
MATCH_INVOICE_PARTIAL: {
|
||
httpStatus: 200,
|
||
message_sv: 'Matchningen registrerades men verifikationen kunde inte skapas.',
|
||
message_en: 'Match recorded but the journal entry could not be created.',
|
||
},
|
||
MATCH_INVOICE_ALREADY_HAS_PAYMENT_VOUCHER: {
|
||
httpStatus: 409,
|
||
message_sv:
|
||
'Fakturan har redan en betalningsverifikation. Koppla istället bankhändelsen till befintlig verifikation, eller rätta tidigare bokföring först.',
|
||
message_en:
|
||
'Invoice already has a payment journal entry. Link the bank transaction to the existing voucher instead, or correct the prior bookkeeping first.',
|
||
},
|
||
MATCH_INVOICE_POSSIBLE_DUPLICATE: {
|
||
httpStatus: 409,
|
||
message_sv:
|
||
'Det finns redan en bokförd verifikation på samma belopp och datum. Har du redan bokfört denna betalning? Koppla bankhändelsen till befintlig verifikation, eller skapa ny verifikation ändå om de inte hör ihop.',
|
||
message_en:
|
||
'A posted journal entry already books the same amount on a nearby date. The user may have already booked this payment manually — link to the existing voucher or pass force=true to create a new one anyway.',
|
||
},
|
||
MATCH_INVOICE_FORCE_CANDIDATE_MISMATCH: {
|
||
httpStatus: 409,
|
||
message_sv:
|
||
'Verifikationen som dubblettkontrollen visade matchar inte längre. Stäng dialogen och försök igen så att rätt verifikation visas.',
|
||
message_en:
|
||
'The candidate journal entry echoed in expected_journal_entry_id does not match the one detected at request time. Re-run the duplicate-payment pre-flight to obtain the current candidate, then retry.',
|
||
},
|
||
}
|
||
|
||
const LINK_TX_JE: Record<string, StructuredErrorEntry> = {
|
||
LINK_TX_JE_NOT_FOUND: {
|
||
httpStatus: 404,
|
||
message_sv: 'Verifikationen kunde inte hittas.',
|
||
message_en: 'Journal entry not found.',
|
||
},
|
||
LINK_TX_JE_NOT_POSTED: {
|
||
httpStatus: 400,
|
||
message_sv: 'Endast bokförda verifikationer kan kopplas till en banktransaktion.',
|
||
message_en: 'Only posted journal entries can be linked to a transaction.',
|
||
},
|
||
LINK_TX_TX_ALREADY_LINKED: {
|
||
httpStatus: 400,
|
||
message_sv: 'Transaktionen är redan kopplad till en verifikation.',
|
||
message_en: 'Transaction is already linked to a journal entry.',
|
||
},
|
||
LINK_TX_INVOICE_NOT_FOUND: {
|
||
httpStatus: 404,
|
||
message_sv: 'Fakturan kunde inte hittas.',
|
||
message_en: 'Invoice not found.',
|
||
},
|
||
LINK_TX_INVOICE_NOT_OPEN: {
|
||
httpStatus: 400,
|
||
message_sv: 'Fakturan är inte i ett obetalt läge och kan inte kopplas.',
|
||
message_en: 'Invoice is not in an unpaid state.',
|
||
},
|
||
LINK_TX_INVOICE_RACE: {
|
||
httpStatus: 409,
|
||
message_sv: 'Fakturan ändrades samtidigt. Försök igen.',
|
||
message_en: 'Invoice status changed concurrently. Retry the request.',
|
||
},
|
||
}
|
||
|
||
const MATCH_SI: Record<string, StructuredErrorEntry> = {
|
||
MATCH_SI_NOT_FOUND: {
|
||
httpStatus: 404,
|
||
message_sv: 'Leverantörsfakturan kunde inte hittas.',
|
||
message_en: 'Supplier invoice not found.',
|
||
},
|
||
MATCH_SI_NOT_EXPENSE: {
|
||
httpStatus: 400,
|
||
message_sv: 'Endast utgiftstransaktioner kan matchas mot leverantörsfakturor.',
|
||
message_en: 'Only expense transactions can be matched to supplier invoices.',
|
||
},
|
||
MATCH_SI_TX_ALREADY_LINKED: {
|
||
httpStatus: 400,
|
||
message_sv: 'Transaktionen är redan kopplad till en leverantörsfaktura.',
|
||
message_en: 'Transaction is already linked to a supplier invoice.',
|
||
},
|
||
MATCH_SI_ALREADY_PAID: {
|
||
httpStatus: 400,
|
||
message_sv: 'Leverantörsfakturan är redan betald eller krediterad.',
|
||
message_en: 'Supplier invoice is already paid or credited.',
|
||
},
|
||
MATCH_SI_NOT_OPEN: {
|
||
httpStatus: 409,
|
||
message_sv: 'Leverantörsfakturan har redan slutbetalats av en annan förfrågan.',
|
||
message_en: 'Supplier invoice has already been fully paid or is no longer matchable.',
|
||
},
|
||
MATCH_SI_DUPLICATE_PAYMENT: {
|
||
httpStatus: 409,
|
||
message_sv: 'Den här transaktionen är redan matchad mot leverantörsfakturan.',
|
||
message_en: 'This transaction is already matched to this supplier invoice.',
|
||
},
|
||
MATCH_SI_RECORD_PAYMENT_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Kunde inte registrera leverantörsfakturabetalningen.',
|
||
message_en: 'Failed to record supplier invoice payment.',
|
||
retryable: true,
|
||
},
|
||
MATCH_SI_LINK_TX_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Kunde inte koppla transaktionen till leverantörsfakturan.',
|
||
message_en: 'Failed to link transaction to supplier invoice.',
|
||
retryable: true,
|
||
},
|
||
MATCH_SI_CASH_FX_UNSUPPORTED: {
|
||
httpStatus: 400,
|
||
message_sv:
|
||
'Kontantmetoden stödjer inte valutakursdifferenser. Byt till löpande bokföring eller bokför valutakursdifferensen manuellt.',
|
||
message_en:
|
||
'Cash accounting does not support exchange-rate differences. Switch to accrual or book the FX difference manually.',
|
||
},
|
||
TX_UNCATEGORIZE_NOT_BOOKED: {
|
||
httpStatus: 400,
|
||
message_sv: 'Transaktionen är inte bokförd. Det finns inget att av-kategorisera.',
|
||
message_en: 'Transaction has no journal entry — nothing to uncategorize.',
|
||
},
|
||
TX_UNCATEGORIZE_JE_NOT_POSTED: {
|
||
httpStatus: 400,
|
||
message_sv: 'Verifikationen är inte bokförd. Reversal kan inte utföras.',
|
||
message_en: 'Journal entry is not in posted status; reversal is not possible.',
|
||
},
|
||
TX_INGEST_INSERT_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Transaktionerna kunde inte importeras.',
|
||
message_en: 'Transaction ingest failed.',
|
||
retryable: true,
|
||
},
|
||
TX_BATCH_CATEGORIZE_EMPTY: {
|
||
httpStatus: 400,
|
||
message_sv: 'Batchen är tom.',
|
||
message_en: 'Batch is empty — pass at least one item.',
|
||
},
|
||
}
|
||
|
||
const INVOICE: Record<string, StructuredErrorEntry> = {
|
||
INVOICE_CUSTOMER_NOT_FOUND: {
|
||
httpStatus: 404,
|
||
message_sv: 'Kunden kunde inte hittas.',
|
||
message_en: 'Customer not found.',
|
||
},
|
||
INVOICE_CREATE_VAT_RULE_VIOLATION: {
|
||
httpStatus: 400,
|
||
message_sv: 'Momssatsen är inte tillåten för denna kundtyp.',
|
||
message_en: 'The VAT rate is not allowed for this customer type.',
|
||
},
|
||
INVOICE_CREATE_ROT_RUT_VALIDATION: {
|
||
httpStatus: 400,
|
||
message_sv: 'ROT/RUT-avdraget kunde inte valideras. Kontrollera personnummer och fastighetsbeteckning.',
|
||
message_en: 'ROT/RUT deduction failed validation. Check personnummer and housing designation.',
|
||
},
|
||
INVOICE_CREATE_ROT_RUT_PERSONNUMMER_INVALID: {
|
||
httpStatus: 400,
|
||
message_sv: 'Personnumret för ROT/RUT-avdraget är ogiltigt.',
|
||
message_en: 'The personnummer provided for the ROT/RUT deduction is invalid.',
|
||
},
|
||
INVOICE_CREATE_INSERT_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Fakturan kunde inte sparas.',
|
||
message_en: 'Invoice insert failed.',
|
||
},
|
||
INVOICE_CREATE_ITEMS_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Fakturaraderna kunde inte sparas.',
|
||
message_en: 'Invoice items insert failed.',
|
||
},
|
||
INVOICE_CREATE_NUMBER_ASSIGN_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Kunde inte tilldela fakturanummer vid skapande.',
|
||
message_en: 'Failed to assign invoice number on create.',
|
||
},
|
||
INVOICE_CREDIT_ORIGINAL_NOT_FOUND: {
|
||
httpStatus: 404,
|
||
message_sv: 'Ursprungsfakturan kunde inte hittas.',
|
||
message_en: 'Original invoice not found.',
|
||
},
|
||
INVOICE_CREDIT_NOT_INVOICE: {
|
||
httpStatus: 400,
|
||
message_sv: 'Kreditfakturor kan endast skapas från riktiga fakturor.',
|
||
message_en: 'Credit notes can only be created from standard invoices.',
|
||
},
|
||
INVOICE_CREDIT_ALREADY_CREDITED: {
|
||
httpStatus: 400,
|
||
message_sv: 'Fakturan har redan krediterats.',
|
||
message_en: 'Invoice has already been credited.',
|
||
},
|
||
INVOICE_CREDIT_NOT_SENT: {
|
||
httpStatus: 400,
|
||
message_sv: 'Endast skickade, betalda eller förfallna fakturor kan krediteras.',
|
||
message_en: 'Only sent, paid, or overdue invoices can be credited.',
|
||
},
|
||
INVOICE_SEND_EMAIL_NOT_CONFIGURED: {
|
||
httpStatus: 503,
|
||
message_sv:
|
||
'E-posttjänsten är inte konfigurerad. Kontrollera att RESEND_API_KEY och RESEND_FROM_EMAIL är satta.',
|
||
message_en: 'Email service is not configured.',
|
||
remediation: {
|
||
description: 'Set RESEND_API_KEY and RESEND_FROM_EMAIL in the deployment environment.',
|
||
},
|
||
},
|
||
INVOICE_SEND_NO_CUSTOMER_EMAIL: {
|
||
httpStatus: 400,
|
||
message_sv: 'Kunden saknar e-postadress. Uppdatera kunduppgifterna först.',
|
||
message_en: 'Customer has no email address.',
|
||
remediation: { description: 'Add an email address on the customer record before sending.' },
|
||
},
|
||
INVOICE_SEND_COMPANY_SETTINGS_MISSING: {
|
||
httpStatus: 404,
|
||
message_sv: 'Företagsinställningar saknas.',
|
||
message_en: 'Company settings are missing.',
|
||
},
|
||
INVOICE_SEND_NUMBER_ASSIGN_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Kunde inte tilldela fakturanummer.',
|
||
message_en: 'Failed to assign invoice number on send.',
|
||
},
|
||
INVOICE_SEND_PROVIDER_FAILED: {
|
||
httpStatus: 502,
|
||
message_sv: 'E-postleverantören kunde inte skicka meddelandet.',
|
||
message_en: 'The email provider could not deliver the message.',
|
||
},
|
||
INVOICE_SEND_PDF_RENDER_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv:
|
||
'Fakturans PDF kunde inte skapas. Kontrollera fakturarader och kunduppgifter och försök igen.',
|
||
message_en: 'Failed to render invoice PDF before send; no invoice number was consumed.',
|
||
},
|
||
INVOICE_PDF_RENDER_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Fakturans PDF kunde inte skapas.',
|
||
message_en: 'Invoice PDF rendering failed.',
|
||
},
|
||
INVOICE_SEND_PARTIAL: {
|
||
httpStatus: 200,
|
||
message_sv:
|
||
'Fakturan skickades men en efterföljande åtgärd misslyckades (verifikation eller PDF-bilaga).',
|
||
message_en: 'Invoice was sent but a follow-up step (journal entry or PDF) failed.',
|
||
},
|
||
INVOICE_SEND_CANCELLED: {
|
||
httpStatus: 400,
|
||
message_sv: 'Makulerade fakturor kan inte skickas. Skapa en ny faktura istället.',
|
||
message_en: 'Cancelled invoices cannot be sent; create a new invoice instead.',
|
||
},
|
||
INVOICE_PAID_NOT_FOUND: {
|
||
httpStatus: 404,
|
||
message_sv: 'Fakturan kunde inte hittas.',
|
||
message_en: 'Invoice not found.',
|
||
},
|
||
INVOICE_PAID_NOT_PAYABLE: {
|
||
httpStatus: 400,
|
||
message_sv: 'Fakturan kan inte markeras som betald i nuvarande status.',
|
||
message_en: 'Invoice is not in a payable status.',
|
||
},
|
||
INVOICE_PAID_LINES_UNBALANCED: {
|
||
httpStatus: 400,
|
||
message_sv: 'Verifikationsraderna är inte balanserade (debet ≠ kredit).',
|
||
message_en: 'Custom journal lines do not balance.',
|
||
},
|
||
INVOICE_PAID_NO_FISCAL_PERIOD: {
|
||
httpStatus: 400,
|
||
message_sv: 'Ingen öppen räkenskapsperiod för betalningsdatumet.',
|
||
message_en: 'No open fiscal period covers the payment date.',
|
||
},
|
||
INVOICE_PAID_RACE: {
|
||
httpStatus: 409,
|
||
message_sv: 'Fakturan har redan betalats av en annan förfrågan.',
|
||
message_en: 'Invoice was already paid by another request.',
|
||
},
|
||
INVOICE_PAID_BOOK_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Kunde inte bokföra betalningen.',
|
||
message_en: 'Failed to create payment journal entry.',
|
||
},
|
||
INVOICE_PAID_LIKELY_DUPLICATE: {
|
||
httpStatus: 409,
|
||
message_sv:
|
||
'Det finns redan en obokförd inkommande banktransaktion som kan vara denna betalning. Länka den istället, eller markera som betald ändå om du är säker.',
|
||
message_en:
|
||
'A likely-matching unlinked inbound bank transaction was found for this customer. Suggest linking it instead of creating a new payment entry.',
|
||
remediation: {
|
||
description:
|
||
'Match the candidate transaction via POST /api/transactions/{id}/match-invoice, or resend mark-paid with force: true to create the payment entry anyway. When using the v1 endpoint, the force retry requires a fresh Idempotency-Key (the original key is bound to the body hash).',
|
||
},
|
||
},
|
||
INVOICE_DELETE_NOT_DRAFT: {
|
||
httpStatus: 400,
|
||
message_sv: 'Endast utkast kan tas bort. Bokförda fakturor måste krediteras istället.',
|
||
message_en: 'Only draft invoices can be deleted; non-drafts must be credited.',
|
||
remediation: {
|
||
description: 'Issue a credit note instead of deleting a posted invoice.',
|
||
},
|
||
},
|
||
INVOICE_UPDATE_NOT_DRAFT: {
|
||
httpStatus: 409,
|
||
message_sv: 'Endast utkast kan ändras. Bokförda fakturor är oföränderliga — utfärda en kreditfaktura istället.',
|
||
message_en: 'Only draft invoices can be updated. Issued invoices are immutable — issue a credit note instead.',
|
||
remediation: {
|
||
description: 'Issue a credit note via POST /invoices/{id}:credit and create a fresh invoice with the corrected details.',
|
||
},
|
||
},
|
||
INVOICE_CANCEL_RACE: {
|
||
httpStatus: 409,
|
||
message_sv: 'Fakturan ändrades samtidigt och kunde inte makuleras. Ladda om och försök igen.',
|
||
message_en: 'Invoice was modified concurrently and could not be cancelled. Reload and retry.',
|
||
},
|
||
// Quotes / Offerter
|
||
QUOTE_NOT_FOUND: {
|
||
httpStatus: 404,
|
||
message_sv: 'Offerten kunde inte hittas.',
|
||
message_en: 'Quote not found.',
|
||
},
|
||
QUOTE_INVALID_STATE: {
|
||
httpStatus: 400,
|
||
message_sv: 'Offerten är inte i en status som tillåter denna åtgärd.',
|
||
message_en: 'Quote is not in a state that allows this action.',
|
||
},
|
||
QUOTE_TOKEN_INVALID: {
|
||
httpStatus: 404,
|
||
message_sv: 'Länken är ogiltig eller har gått ut.',
|
||
message_en: 'The link is invalid or has expired.',
|
||
},
|
||
QUOTE_NUMBER_ASSIGN_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Kunde inte tilldela offertnummer.',
|
||
message_en: 'Failed to assign quote number.',
|
||
},
|
||
QUOTE_CONVERSION_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Offerten kunde inte konverteras till faktura.',
|
||
message_en: 'Failed to convert quote to invoice.',
|
||
},
|
||
QUOTE_NOT_QUOTE: {
|
||
httpStatus: 400,
|
||
message_sv: 'Detta dokument är inte en offert.',
|
||
message_en: 'This document is not a quote.',
|
||
},
|
||
}
|
||
|
||
const SUPPLIER_INVOICE: Record<string, StructuredErrorEntry> = {
|
||
SI_NOT_FOUND: {
|
||
httpStatus: 404,
|
||
message_sv: 'Leverantörsfakturan kunde inte hittas.',
|
||
message_en: 'Supplier invoice not found.',
|
||
},
|
||
SI_APPROVE_NOT_REGISTERED: {
|
||
httpStatus: 400,
|
||
message_sv: 'Endast registrerade fakturor kan godkännas.',
|
||
message_en: 'Only invoices in registered status can be approved.',
|
||
},
|
||
SI_APPROVE_UPDATE_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Kunde inte godkänna leverantörsfakturan.',
|
||
message_en: 'Failed to update supplier invoice status to approved.',
|
||
},
|
||
PO_THREE_WAY_MATCH_FAILED: {
|
||
httpStatus: 422,
|
||
message_sv:
|
||
'Trevägs-matchning misslyckades: leverantörsfakturan stämmer inte med inköpsordern eller godsmottagningen.',
|
||
message_en:
|
||
'Three-way match failed: the supplier invoice does not reconcile with the purchase order / goods receipt.',
|
||
},
|
||
PO_LINK_REQUIRED: {
|
||
httpStatus: 422,
|
||
message_sv:
|
||
'Inställningarna kräver att varje leverantörsfaktura kopplas till en inköpsorder.',
|
||
message_en:
|
||
'Company settings require every supplier invoice to be linked to a purchase order.',
|
||
},
|
||
PO_NOT_FOUND: {
|
||
httpStatus: 404,
|
||
message_sv: 'Inköpsordern kunde inte hittas.',
|
||
message_en: 'Purchase order not found.',
|
||
},
|
||
}
|
||
|
||
// ─────────────────────────────────────────────────────────────────
|
||
// Wave 2: periods, year-end, reports
|
||
// ─────────────────────────────────────────────────────────────────
|
||
|
||
const PERIOD: Record<string, StructuredErrorEntry> = {
|
||
PERIOD_NOT_FOUND: {
|
||
httpStatus: 404,
|
||
message_sv: 'Räkenskapsperioden kunde inte hittas.',
|
||
message_en: 'Fiscal period not found.',
|
||
},
|
||
PERIOD_LOCK_FAILED: {
|
||
httpStatus: 400,
|
||
message_sv: 'Perioden kunde inte låsas.',
|
||
message_en: 'Failed to lock period.',
|
||
},
|
||
PERIOD_LOCK_HAS_DRAFTS: {
|
||
httpStatus: 400,
|
||
message_sv: 'Perioden innehåller verifikationsutkast som måste bokföras eller raderas innan låsning.',
|
||
message_en: 'Period contains draft journal entries.',
|
||
},
|
||
PERIOD_LOCK_ALREADY_LOCKED: {
|
||
httpStatus: 409,
|
||
message_sv: 'Perioden är redan låst.',
|
||
message_en: 'Period is already locked.',
|
||
},
|
||
}
|
||
|
||
const YEAR_END: Record<string, StructuredErrorEntry> = {
|
||
YEAR_END_PREVIEW_FAILED: {
|
||
httpStatus: 400,
|
||
message_sv: 'Bokslutsförhandsgranskningen misslyckades.',
|
||
message_en: 'Failed to preview year-end closing.',
|
||
},
|
||
YEAR_END_FAILED: {
|
||
httpStatus: 400,
|
||
message_sv: 'Bokslutet kunde inte verkställas.',
|
||
message_en: 'Failed to execute year-end closing.',
|
||
},
|
||
YEAR_END_PRIOR_PERIOD_OPEN: {
|
||
httpStatus: 400,
|
||
message_sv: 'En tidigare period är fortfarande öppen. Stäng den först.',
|
||
message_en: 'A prior fiscal period is still open.',
|
||
},
|
||
YEAR_END_UNBALANCED_TRIAL: {
|
||
httpStatus: 400,
|
||
message_sv: 'Resultaträkningens debet och kredit balanserar inte. Granska verifikationerna innan bokslut.',
|
||
message_en: 'Trial balance does not balance.',
|
||
},
|
||
YEAR_END_NEXT_PERIOD_HAS_IB: {
|
||
httpStatus: 400,
|
||
message_sv: 'Nästa räkenskapsperiod har redan ingående balanser bokförda. Storno dem innan du kör om bokslutet.',
|
||
message_en: 'Next fiscal period already has opening balances posted; reverse them before re-running year-end.',
|
||
},
|
||
}
|
||
|
||
const OPENING_BAL: Record<string, StructuredErrorEntry> = {
|
||
OPENING_BAL_PERIOD_NOT_FOUND: {
|
||
httpStatus: 404,
|
||
message_sv: 'Räkenskapsperioden kunde inte hittas.',
|
||
message_en: 'Fiscal period not found.',
|
||
},
|
||
}
|
||
|
||
const FX: Record<string, StructuredErrorEntry> = {
|
||
FX_PERIOD_NOT_FOUND: {
|
||
httpStatus: 404,
|
||
message_sv: 'Räkenskapsperioden kunde inte hittas.',
|
||
message_en: 'Fiscal period not found.',
|
||
},
|
||
FX_PERIOD_CLOSED: {
|
||
httpStatus: 400,
|
||
message_sv: 'Perioden är redan stängd. Valutaomvärdering kan inte köras.',
|
||
message_en: 'Period is already closed; currency revaluation cannot be run.',
|
||
},
|
||
FX_FAILED: {
|
||
httpStatus: 400,
|
||
message_sv: 'Valutaomvärderingen misslyckades.',
|
||
message_en: 'Currency revaluation failed.',
|
||
},
|
||
}
|
||
|
||
const REPORT: Record<string, StructuredErrorEntry> = {
|
||
REPORT_PERIOD_REQUIRED: {
|
||
httpStatus: 400,
|
||
message_sv: 'period_id krävs.',
|
||
message_en: 'period_id query parameter is required.',
|
||
},
|
||
REPORT_GENERATION_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Rapporten kunde inte genereras.',
|
||
message_en: 'Failed to generate the report.',
|
||
},
|
||
}
|
||
|
||
const VAT_REPORT: Record<string, StructuredErrorEntry> = {
|
||
VAT_REPORT_MISSING_PARAMS: {
|
||
httpStatus: 400,
|
||
message_sv: 'periodType, year och period krävs.',
|
||
message_en: 'periodType, year and period query parameters are required.',
|
||
},
|
||
VAT_REPORT_INVALID_PERIOD_TYPE: {
|
||
httpStatus: 400,
|
||
message_sv: 'periodType måste vara monthly, quarterly eller yearly.',
|
||
message_en: 'periodType must be one of monthly, quarterly, yearly.',
|
||
},
|
||
VAT_REPORT_INVALID_YEAR: {
|
||
httpStatus: 400,
|
||
message_sv: 'year måste vara ett giltigt årtal mellan 2000 och 2100.',
|
||
message_en: 'year must be a number between 2000 and 2100.',
|
||
},
|
||
VAT_REPORT_INVALID_PERIOD: {
|
||
httpStatus: 400,
|
||
message_sv: 'period är ogiltig för vald periodtyp.',
|
||
message_en: 'period is invalid for the chosen period type.',
|
||
},
|
||
VAT_REPORT_GENERATION_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Momsdeklarationen kunde inte beräknas.',
|
||
message_en: 'Failed to calculate VAT declaration.',
|
||
},
|
||
}
|
||
|
||
const PS_REPORT: Record<string, StructuredErrorEntry> = {
|
||
PS_REPORT_MISSING_PARAMS: {
|
||
httpStatus: 400,
|
||
message_sv: 'periodType, year och period krävs.',
|
||
message_en: 'periodType, year and period query parameters are required.',
|
||
},
|
||
PS_REPORT_INVALID_PERIOD_TYPE: {
|
||
httpStatus: 400,
|
||
message_sv: 'periodType måste vara monthly eller quarterly.',
|
||
message_en: 'periodType must be monthly or quarterly.',
|
||
},
|
||
PS_REPORT_INVALID_YEAR: {
|
||
httpStatus: 400,
|
||
message_sv: 'year måste vara ett giltigt årtal mellan 2000 och 2100.',
|
||
message_en: 'year must be a number between 2000 and 2100.',
|
||
},
|
||
PS_REPORT_INVALID_PERIOD: {
|
||
httpStatus: 400,
|
||
message_sv: 'period är ogiltig för vald periodtyp.',
|
||
message_en: 'period is invalid for the chosen period type.',
|
||
},
|
||
PS_REPORT_GENERATION_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Periodisk sammanställning kunde inte beräknas.',
|
||
message_en: 'Failed to generate periodisk sammanställning.',
|
||
},
|
||
PS_REPORT_CSV_BLOCKED_BY_ERRORS: {
|
||
httpStatus: 400,
|
||
message_sv: 'CSV kan inte laddas ner. Åtgärda blockerande fel först.',
|
||
message_en: 'CSV download blocked by validation errors. Fix them first.',
|
||
},
|
||
PS_REPORT_MISSING_FILER_INFO: {
|
||
httpStatus: 400,
|
||
message_sv: 'Kontaktuppgifter saknas. Fyll i namn, telefon och e-post under Inställningar.',
|
||
message_en: 'Tax contact information is missing on company_settings.',
|
||
},
|
||
}
|
||
|
||
const SIE_EXPORT: Record<string, StructuredErrorEntry> = {
|
||
SIE_EXPORT_COMPANY_NOT_FOUND: {
|
||
httpStatus: 404,
|
||
message_sv: 'Företagsinställningar saknas — SIE-exporten kan inte skapas.',
|
||
message_en: 'Company settings missing; SIE export cannot be generated.',
|
||
},
|
||
SIE_EXPORT_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'SIE-exporten misslyckades.',
|
||
message_en: 'Failed to generate SIE export.',
|
||
},
|
||
}
|
||
|
||
const TAX_DECL: Record<string, StructuredErrorEntry> = {
|
||
TAX_DECL_GENERATION_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Skattedeklarationen kunde inte genereras.',
|
||
message_en: 'Failed to generate tax declaration.',
|
||
},
|
||
}
|
||
|
||
// ─────────────────────────────────────────────────────────────────
|
||
// Wave 3: imports (SIE, bank-file, opening-balance)
|
||
// ─────────────────────────────────────────────────────────────────
|
||
|
||
const SIE_IMPORT: Record<string, StructuredErrorEntry> = {
|
||
SIE_PARSE_NO_FILE: {
|
||
httpStatus: 400,
|
||
message_sv: 'Ingen fil bifogad i förfrågan.',
|
||
message_en: 'No file attached to the request.',
|
||
},
|
||
SIE_PARSE_INVALID_TYPE: {
|
||
httpStatus: 400,
|
||
message_sv: 'Filtypen stöds inte. Ladda upp en fil med ändelsen .sie eller .se.',
|
||
message_en: 'Unsupported file type; upload a .sie or .se file.',
|
||
},
|
||
SIE_PARSE_FILE_TOO_LARGE: {
|
||
httpStatus: 400,
|
||
message_sv: 'Filen är för stor. Maxstorlek är 50 MB.',
|
||
message_en: 'File exceeds the 50 MB size limit.',
|
||
},
|
||
SIE_PARSE_EMPTY: {
|
||
httpStatus: 400,
|
||
message_sv: 'Filen är tom (0 bytes). Kontrollera exporten från bokföringsprogrammet.',
|
||
message_en: 'File is empty.',
|
||
},
|
||
SIE_PARSE_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Kunde inte tolka SIE-filen. Filen kan vara skadad eller i ett format som inte stöds.',
|
||
message_en: 'Failed to parse the SIE file.',
|
||
},
|
||
SIE_PARSE_VALIDATION_FAILED: {
|
||
httpStatus: 400,
|
||
message_sv: 'SIE-filen innehåller valideringsfel som måste åtgärdas innan import.',
|
||
message_en: 'SIE file failed validation.',
|
||
},
|
||
SIE_DUPLICATE_FILE: {
|
||
httpStatus: 409,
|
||
message_sv: 'Den här filen har redan importerats.',
|
||
message_en: 'File has already been imported.',
|
||
},
|
||
SIE_DUPLICATE_PERIOD: {
|
||
httpStatus: 409,
|
||
message_sv: 'En SIE-import för ett överlappande räkenskapsår finns redan.',
|
||
message_en: 'An SIE import for an overlapping fiscal period already exists.',
|
||
},
|
||
SIE_IMPORT_UNMAPPED_ACCOUNTS: {
|
||
httpStatus: 400,
|
||
message_sv: 'Vissa konton saknar mappning. Gå tillbaka till kontomappningssteget och koppla alla konton.',
|
||
message_en: 'One or more accounts have no mapping target.',
|
||
remediation: { description: 'Map every source account to a BAS account before importing.' },
|
||
},
|
||
SIE_IMPORT_ACCOUNT_ACTIVATION_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Kunde inte aktivera konton i kontoplanen. Kontrollera att kontona inte redan finns med andra inställningar.',
|
||
message_en: 'Failed to activate mapped accounts in the chart of accounts.',
|
||
},
|
||
SIE_IMPORT_FAILED: {
|
||
httpStatus: 400,
|
||
message_sv: 'Importen slutfördes med fel. Se detaljerna nedan.',
|
||
message_en: 'SIE import completed with errors.',
|
||
},
|
||
SIE_IMPORT_UNEXPECTED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Importen avbröts oväntat. Ingen data har sparats.',
|
||
message_en: 'Unexpected error during SIE import; no data was committed.',
|
||
},
|
||
SIE_REPLACE_FAILED: {
|
||
httpStatus: 400,
|
||
message_sv: 'SIE-importen kunde inte ersättas.',
|
||
message_en: 'Failed to replace SIE import.',
|
||
},
|
||
}
|
||
|
||
const BANK_FILE: Record<string, StructuredErrorEntry> = {
|
||
BANK_FILE_NO_FILE: {
|
||
httpStatus: 400,
|
||
message_sv: 'Ingen fil bifogad i förfrågan.',
|
||
message_en: 'No file attached to the request.',
|
||
},
|
||
BANK_FILE_TOO_LARGE: {
|
||
httpStatus: 400,
|
||
message_sv: 'Filen är för stor. Maxstorlek är 10 MB.',
|
||
message_en: 'File exceeds the 10 MB size limit.',
|
||
},
|
||
BANK_FILE_DUPLICATE: {
|
||
httpStatus: 409,
|
||
message_sv: 'Den här filen har redan importerats.',
|
||
message_en: 'Bank file has already been imported.',
|
||
},
|
||
BANK_FILE_PARSE_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Kunde inte tolka bankfilen.',
|
||
message_en: 'Failed to parse the bank file.',
|
||
},
|
||
BANK_FILE_NO_TRANSACTIONS: {
|
||
httpStatus: 400,
|
||
message_sv: 'Bankfilen innehåller inga transaktioner att importera.',
|
||
message_en: 'No transactions to import.',
|
||
},
|
||
BANK_FILE_IMPORT_RECORD_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Kunde inte skapa importpost.',
|
||
message_en: 'Failed to create the bank file import record.',
|
||
},
|
||
BANK_FILE_EXECUTE_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Bankfilsimporten misslyckades.',
|
||
message_en: 'Bank file import failed.',
|
||
},
|
||
}
|
||
|
||
const OPENING_BALANCE_IMPORT: Record<string, StructuredErrorEntry> = {
|
||
OB_NO_FILE: {
|
||
httpStatus: 400,
|
||
message_sv: 'Ingen fil bifogad.',
|
||
message_en: 'No file attached.',
|
||
},
|
||
OB_FILE_TOO_LARGE: {
|
||
httpStatus: 400,
|
||
message_sv: 'Filen är för stor. Maxstorlek är 10 MB.',
|
||
message_en: 'File exceeds the 10 MB size limit.',
|
||
},
|
||
OB_INVALID_FORMAT: {
|
||
httpStatus: 400,
|
||
message_sv: 'Filformatet stöds inte. Tillåtna format: .xlsx, .xls, .csv, .ods.',
|
||
message_en: 'Unsupported file format.',
|
||
},
|
||
OB_INVALID_COLUMN_OVERRIDES: {
|
||
httpStatus: 400,
|
||
message_sv: 'Ogiltig kolumnmappning.',
|
||
message_en: 'Invalid column overrides JSON.',
|
||
},
|
||
OB_PARSE_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Kunde inte tolka filen.',
|
||
message_en: 'Failed to parse the opening balance file.',
|
||
},
|
||
OB_PERIOD_NOT_FOUND: {
|
||
httpStatus: 404,
|
||
message_sv: 'Räkenskapsperioden hittades inte.',
|
||
message_en: 'Fiscal period not found.',
|
||
},
|
||
OB_PERIOD_CLOSED: {
|
||
httpStatus: 400,
|
||
message_sv: 'Räkenskapsperioden är stängd.',
|
||
message_en: 'Fiscal period is closed.',
|
||
},
|
||
OB_PERIOD_LOCKED: {
|
||
httpStatus: 400,
|
||
message_sv: 'Räkenskapsperioden är låst.',
|
||
message_en: 'Fiscal period is locked.',
|
||
},
|
||
OB_PERIOD_ALREADY_HAS_BALANCES: {
|
||
httpStatus: 409,
|
||
message_sv: 'Räkenskapsperioden har redan ingående balanser.',
|
||
message_en: 'Fiscal period already has opening balances set.',
|
||
},
|
||
OB_TOO_FEW_LINES: {
|
||
httpStatus: 400,
|
||
message_sv: 'Minst två rader med belopp krävs.',
|
||
message_en: 'At least two lines with amounts are required.',
|
||
},
|
||
OB_PNL_ACCOUNT: {
|
||
httpStatus: 400,
|
||
message_sv: 'Resultatkonton (klass 3-8) kan inte användas i ingående balanser.',
|
||
message_en: 'Profit & loss accounts (class 3-8) are not allowed in opening balances.',
|
||
},
|
||
OB_UNBALANCED: {
|
||
httpStatus: 400,
|
||
message_sv: 'Debet och kredit balanserar inte.',
|
||
message_en: 'Opening balance debits and credits do not match.',
|
||
},
|
||
OB_ACCOUNT_ACTIVATION_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Kunde inte aktivera konton i kontoplanen.',
|
||
message_en: 'Failed to activate accounts in the chart of accounts.',
|
||
},
|
||
OB_EXECUTE_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Importen misslyckades.',
|
||
message_en: 'Opening balance import failed.',
|
||
},
|
||
}
|
||
|
||
const REGISTER_IMPORT: Record<string, StructuredErrorEntry> = {
|
||
REG_IMPORT_NO_FILE: {
|
||
httpStatus: 400,
|
||
message_sv: 'Ingen fil bifogad.',
|
||
message_en: 'No file attached.',
|
||
},
|
||
REG_IMPORT_FILE_TOO_LARGE: {
|
||
httpStatus: 400,
|
||
message_sv: 'Filen är för stor. Maxstorlek är 10 MB.',
|
||
message_en: 'File exceeds the 10 MB size limit.',
|
||
},
|
||
REG_IMPORT_INVALID_FORMAT: {
|
||
httpStatus: 400,
|
||
message_sv: 'Filformatet stöds inte. Tillåtna format: .xlsx, .xls, .csv, .ods.',
|
||
message_en: 'Unsupported file format.',
|
||
},
|
||
REG_IMPORT_INVALID_COLUMN_OVERRIDES: {
|
||
httpStatus: 400,
|
||
message_sv: 'Ogiltig kolumnmappning.',
|
||
message_en: 'Invalid column overrides JSON.',
|
||
},
|
||
REG_IMPORT_PARSE_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Kunde inte tolka filen.',
|
||
message_en: 'Failed to parse the register file.',
|
||
},
|
||
REG_IMPORT_NO_ROWS: {
|
||
httpStatus: 400,
|
||
message_sv: 'Inga giltiga rader hittades i filen.',
|
||
message_en: 'No valid rows found in the file.',
|
||
},
|
||
REG_IMPORT_EXECUTE_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Importen misslyckades.',
|
||
message_en: 'Register import failed.',
|
||
},
|
||
}
|
||
|
||
// ─────────────────────────────────────────────────────────────────
|
||
// Wave 3 tail: provider migration extension codes
|
||
// ─────────────────────────────────────────────────────────────────
|
||
|
||
const PROVIDER_MIGRATION: Record<string, StructuredErrorEntry> = {
|
||
PROVIDER_INVALID: {
|
||
httpStatus: 400,
|
||
message_sv: 'Okänd leverantör.',
|
||
message_en: 'Unknown provider.',
|
||
},
|
||
PROVIDER_CONSENT_NOT_READY: {
|
||
httpStatus: 400,
|
||
message_sv: 'Anslutningen är inte klar. Slutför inloggningen först.',
|
||
message_en: 'Provider consent is not ready; finish authentication first.',
|
||
},
|
||
PROVIDER_CONSENT_NOT_FOUND: {
|
||
httpStatus: 404,
|
||
message_sv: 'Anslutningen kunde inte hittas.',
|
||
message_en: 'Provider consent not found.',
|
||
},
|
||
PROVIDER_CONNECT_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Kunde inte starta anslutningen till leverantören.',
|
||
message_en: 'Failed to start provider connection flow.',
|
||
},
|
||
PROVIDER_TOKEN_REQUIRED: {
|
||
httpStatus: 400,
|
||
message_sv: 'API-token krävs för den här leverantören.',
|
||
message_en: 'apiToken is required for this provider.',
|
||
},
|
||
PROVIDER_COMPANY_ID_REQUIRED: {
|
||
httpStatus: 400,
|
||
message_sv: 'companyId krävs för den här leverantören.',
|
||
message_en: 'companyId is required for this provider.',
|
||
},
|
||
PROVIDER_TOKEN_SUBMIT_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Tokensubmissionen misslyckades.',
|
||
message_en: 'Failed to submit provider token.',
|
||
},
|
||
PROVIDER_PREVIEW_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Förhandsgranskningen från leverantören misslyckades.',
|
||
message_en: 'Provider preview failed.',
|
||
},
|
||
PROVIDER_SIE_FETCH_FAILED: {
|
||
httpStatus: 502,
|
||
message_sv: 'Kunde inte hämta SIE-data från leverantören.',
|
||
message_en: 'Failed to fetch SIE data from the provider.',
|
||
},
|
||
PROVIDER_SIE_NO_YEARS: {
|
||
httpStatus: 404,
|
||
message_sv: 'Inga räkenskapsår 2024–2026 hittades hos leverantören.',
|
||
message_en: 'No fiscal years available for 2024–2026.',
|
||
},
|
||
PROVIDER_SIE_ONLY_FORTNOX: {
|
||
httpStatus: 400,
|
||
message_sv: 'SIE-export stöds för närvarande endast för Fortnox.',
|
||
message_en: 'SIE export is currently only supported for Fortnox.',
|
||
},
|
||
PROVIDER_MIGRATE_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Migrationen från leverantören misslyckades.',
|
||
message_en: 'Provider migration failed.',
|
||
},
|
||
PROVIDER_DISCONNECT_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Frånkoppling från leverantören misslyckades.',
|
||
message_en: 'Provider disconnect failed.',
|
||
},
|
||
PROVIDER_ACCEPT_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Kunde inte slutföra anslutningen.',
|
||
message_en: 'Failed to accept consent.',
|
||
},
|
||
PROVIDER_STATUS_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Kunde inte hämta status från leverantören.',
|
||
message_en: 'Failed to fetch provider status.',
|
||
},
|
||
}
|
||
|
||
// ─────────────────────────────────────────────────────────────────
|
||
// Wave 4: documents, masters, salary, company, API keys
|
||
// ─────────────────────────────────────────────────────────────────
|
||
|
||
const DOCUMENT: Record<string, StructuredErrorEntry> = {
|
||
DOC_UPLOAD_NO_FILE: {
|
||
httpStatus: 400,
|
||
message_sv: 'Ingen fil bifogad.',
|
||
message_en: 'No file attached.',
|
||
},
|
||
DOC_UPLOAD_TOO_LARGE: {
|
||
httpStatus: 400,
|
||
message_sv: 'Filen är för stor.',
|
||
message_en: 'Uploaded file exceeds the size limit.',
|
||
},
|
||
DOC_UPLOAD_UNSUPPORTED_TYPE: {
|
||
httpStatus: 400,
|
||
message_sv: 'Filtypen stöds inte.',
|
||
message_en: 'Unsupported file type.',
|
||
},
|
||
DOC_UPLOAD_STORAGE_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Filen kunde inte sparas.',
|
||
message_en: 'Document storage failed.',
|
||
},
|
||
DOC_UPLOAD_PERIOD_LOCKED: {
|
||
httpStatus: 400,
|
||
message_sv: 'Det går inte att bifoga underlag till verifikationer i en låst eller stängd period.',
|
||
message_en: 'Cannot attach documents to entries in a locked or closed fiscal period.',
|
||
},
|
||
DOC_DOWNLOAD_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Det gick inte att skapa nedladdningslänken.',
|
||
message_en: 'Failed to create signed download URL.',
|
||
},
|
||
DOC_NOT_FOUND: {
|
||
httpStatus: 404,
|
||
message_sv: 'Dokumentet kunde inte hittas.',
|
||
message_en: 'Document not found.',
|
||
},
|
||
DOC_LINK_ENTRY_NOT_FOUND: {
|
||
httpStatus: 404,
|
||
message_sv: 'Verifikationen kunde inte hittas.',
|
||
message_en: 'Journal entry not found.',
|
||
},
|
||
DOC_LINK_ALREADY_LINKED: {
|
||
httpStatus: 409,
|
||
message_sv: 'Dokumentet är redan kopplat till en verifikation.',
|
||
message_en: 'Document is already linked to a journal entry.',
|
||
},
|
||
DOC_LINK_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Kopplingen misslyckades.',
|
||
message_en: 'Failed to link document to journal entry.',
|
||
},
|
||
}
|
||
|
||
const CUSTOMER: Record<string, StructuredErrorEntry> = {
|
||
CUSTOMER_NOT_FOUND: {
|
||
httpStatus: 404,
|
||
message_sv: 'Kunden kunde inte hittas.',
|
||
message_en: 'Customer not found.',
|
||
},
|
||
CUSTOMER_DUPLICATE_ORG_NUMBER: {
|
||
httpStatus: 409,
|
||
message_sv: 'En kund med samma organisationsnummer finns redan.',
|
||
message_en: 'A customer with that organisation number already exists.',
|
||
},
|
||
CUSTOMER_CREATE_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Kunden kunde inte skapas.',
|
||
message_en: 'Failed to create customer.',
|
||
},
|
||
CUSTOMER_UPDATE_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Kunden kunde inte uppdateras.',
|
||
message_en: 'Failed to update customer.',
|
||
},
|
||
CUSTOMER_DELETE_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Kunden kunde inte tas bort.',
|
||
message_en: 'Failed to delete customer.',
|
||
},
|
||
CUSTOMER_HAS_INVOICES: {
|
||
httpStatus: 409,
|
||
message_sv: 'Kunden har fakturor och kan inte tas bort.',
|
||
message_en: 'Customer cannot be deleted while invoices reference it.',
|
||
},
|
||
}
|
||
|
||
const SUPPLIER: Record<string, StructuredErrorEntry> = {
|
||
SUPPLIER_NOT_FOUND: {
|
||
httpStatus: 404,
|
||
message_sv: 'Leverantören kunde inte hittas.',
|
||
message_en: 'Supplier not found.',
|
||
},
|
||
SUPPLIER_DUPLICATE_ORG_NUMBER: {
|
||
httpStatus: 409,
|
||
message_sv: 'En leverantör med samma organisationsnummer finns redan.',
|
||
message_en: 'A supplier with that organisation number already exists.',
|
||
},
|
||
SUPPLIER_CREATE_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Leverantören kunde inte skapas.',
|
||
message_en: 'Failed to create supplier.',
|
||
},
|
||
SUPPLIER_UPDATE_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Leverantören kunde inte uppdateras.',
|
||
message_en: 'Failed to update supplier.',
|
||
},
|
||
SUPPLIER_DELETE_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Leverantören kunde inte tas bort.',
|
||
message_en: 'Failed to delete supplier.',
|
||
},
|
||
// v1 archive refusal — leverantörsfakturor pointing at this supplier still
|
||
// need its name/address for BFL 7 kap audit. Issue credit notes first.
|
||
SUPPLIER_HAS_INVOICES: {
|
||
httpStatus: 409,
|
||
message_sv:
|
||
'Leverantören kan inte arkiveras eftersom det finns öppna leverantörsfakturor som refererar till den.',
|
||
message_en:
|
||
'Supplier cannot be archived while open supplier invoices reference it.',
|
||
remediation: {
|
||
description:
|
||
'Close (credit / mark paid) every open supplier invoice before archiving the supplier. The dashboard exposes the same blocker.',
|
||
},
|
||
},
|
||
// v1 strict-mode: update / delete only allowed on `registered` SIs (the
|
||
// SI analogue of `draft`). Mirrors the dashboard internal route.
|
||
SI_NOT_DRAFT: {
|
||
httpStatus: 400,
|
||
message_sv:
|
||
'Leverantörsfakturan är inte längre i status "registrerad" och kan därför inte uppdateras eller tas bort.',
|
||
message_en:
|
||
'Supplier invoice is not in `registered` status and cannot be updated or deleted.',
|
||
},
|
||
}
|
||
|
||
const SUPPLIER_INVOICE_WAVE4: Record<string, StructuredErrorEntry> = {
|
||
SI_CREATE_DUPLICATE_INVOICE_NUMBER: {
|
||
httpStatus: 409,
|
||
message_sv: 'En leverantörsfaktura med samma nummer finns redan.',
|
||
message_en: 'A supplier invoice with that number already exists.',
|
||
},
|
||
SI_CREATE_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Leverantörsfakturan kunde inte skapas.',
|
||
message_en: 'Failed to create supplier invoice.',
|
||
},
|
||
SI_CREATE_INVALID_INPUT: {
|
||
httpStatus: 400,
|
||
message_sv: 'Ogiltig kombination av fakturafält. Kontrollera formuläret och försök igen.',
|
||
message_en: 'Invalid combination of supplier invoice fields.',
|
||
},
|
||
SI_PAID_ALREADY: {
|
||
httpStatus: 409,
|
||
message_sv: 'Leverantörsfakturan är redan betald eller krediterad.',
|
||
message_en: 'Supplier invoice is already paid or credited.',
|
||
},
|
||
SI_PAID_NOT_PAYABLE: {
|
||
httpStatus: 400,
|
||
message_sv: 'Leverantörsfakturan kan inte markeras som betald i nuvarande status.',
|
||
message_en: 'Supplier invoice is not in a payable state.',
|
||
},
|
||
SI_PAID_PERIOD_LOCKED: {
|
||
httpStatus: 400,
|
||
message_sv: 'Bokföringen är låst. Betalningen kan inte registreras.',
|
||
message_en: 'Bookkeeping is locked; payment cannot be recorded.',
|
||
},
|
||
SI_PAID_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Kunde inte registrera betalningen.',
|
||
message_en: 'Failed to record supplier invoice payment.',
|
||
},
|
||
SI_PAID_LIKELY_DUPLICATE: {
|
||
httpStatus: 409,
|
||
message_sv:
|
||
'Det finns redan en obokförd banktransaktion som kan vara denna betalning. Länka den istället, eller markera som betald ändå om du är säker.',
|
||
message_en:
|
||
'A likely-matching unlinked bank transaction was found for this supplier. Suggest linking it instead of creating a new payment entry.',
|
||
remediation: {
|
||
description:
|
||
'Match the candidate transaction via POST /api/transactions/{id}/match-supplier-invoice, or resend mark-paid with force: true to create the payment entry anyway.',
|
||
},
|
||
},
|
||
SI_CREDIT_ALREADY_CREDITED: {
|
||
httpStatus: 409,
|
||
message_sv: 'Leverantörsfakturan har redan krediterats.',
|
||
message_en: 'Supplier invoice has already been credited.',
|
||
},
|
||
SI_CREDIT_PERIOD_LOCKED: {
|
||
httpStatus: 400,
|
||
message_sv: 'Bokföringen är låst. Krediteringen kan inte skapas.',
|
||
message_en: 'Bookkeeping is locked; credit note cannot be created.',
|
||
},
|
||
SI_CREDIT_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Kunde inte kreditera leverantörsfakturan.',
|
||
message_en: 'Failed to credit supplier invoice.',
|
||
},
|
||
}
|
||
|
||
const SALARY: Record<string, StructuredErrorEntry> = {
|
||
SALARY_RUN_NOT_FOUND: {
|
||
httpStatus: 404,
|
||
message_sv: 'Lönekörningen kunde inte hittas.',
|
||
message_en: 'Salary run not found.',
|
||
},
|
||
SALARY_RUN_NO_EMPLOYEES: {
|
||
httpStatus: 400,
|
||
message_sv: 'Inga aktiva anställda finns i företaget.',
|
||
message_en: 'No active employees in the company.',
|
||
},
|
||
SALARY_RUN_TAX_TABLE_MISSING: {
|
||
httpStatus: 400,
|
||
message_sv: 'Skattetabellen saknas för perioden. Importera skattetabellen först.',
|
||
message_en: 'Tax table is missing for the period.',
|
||
},
|
||
SALARY_RUN_PERIOD_LOCKED: {
|
||
httpStatus: 400,
|
||
message_sv: 'Lönekörningen kan inte göras i en låst period.',
|
||
message_en: 'Salary run cannot be processed in a locked period.',
|
||
},
|
||
SALARY_RUN_NOT_CALCULATED: {
|
||
httpStatus: 400,
|
||
message_sv: 'Lönekörningen måste beräknas innan bokföring.',
|
||
message_en: 'Salary run must be calculated before booking.',
|
||
},
|
||
SALARY_RUN_CREATE_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Lönekörningen kunde inte skapas.',
|
||
message_en: 'Failed to create salary run.',
|
||
},
|
||
SALARY_RUN_CALCULATE_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Lönekörningen kunde inte beräknas.',
|
||
message_en: 'Failed to calculate salary run.',
|
||
},
|
||
SALARY_RUN_BOOK_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Lönekörningen kunde inte bokföras.',
|
||
message_en: 'Failed to book salary run.',
|
||
},
|
||
AGI_NO_SALARY_RUN: {
|
||
httpStatus: 400,
|
||
message_sv: 'Det finns ingen lönekörning för perioden.',
|
||
message_en: 'No salary run exists for the period.',
|
||
},
|
||
AGI_FSKATT_VERIFICATION_FAILED: {
|
||
httpStatus: 400,
|
||
message_sv: 'F-skattekontrollen misslyckades. Kontrollera leverantörens F-skatt.',
|
||
message_en: 'F-skatt verification failed.',
|
||
},
|
||
AGI_GENERATION_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'AGI-deklarationen kunde inte genereras.',
|
||
message_en: 'Failed to generate AGI declaration.',
|
||
},
|
||
// Phase 5 PR-1 — v1 REST surface error codes.
|
||
EMPLOYEE_NOT_FOUND: {
|
||
httpStatus: 404,
|
||
message_sv: 'Den anställda kunde inte hittas.',
|
||
message_en: 'Employee not found.',
|
||
},
|
||
EMPLOYEE_DUPLICATE_PERSONNUMMER: {
|
||
httpStatus: 409,
|
||
message_sv: 'En anställd med samma personnummer finns redan.',
|
||
message_en: 'An employee with that personnummer already exists.',
|
||
},
|
||
SALARY_RUN_DUPLICATE_PERIOD: {
|
||
httpStatus: 409,
|
||
message_sv: 'En lönekörning för perioden finns redan.',
|
||
message_en: 'A salary run for that period already exists.',
|
||
},
|
||
SALARY_RUN_PATCH_NOT_DRAFT: {
|
||
httpStatus: 400,
|
||
message_sv: 'Endast utkast (draft) kan uppdateras.',
|
||
message_en: 'Only draft salary runs can be patched.',
|
||
},
|
||
SALARY_RUN_DELETE_NOT_DRAFT: {
|
||
httpStatus: 400,
|
||
message_sv: 'Endast utkast (draft) kan raderas.',
|
||
message_en: 'Only draft salary runs can be deleted.',
|
||
},
|
||
SALARY_RUN_CALCULATE_NOT_DRAFT: {
|
||
httpStatus: 400,
|
||
message_sv: 'Lönekörningen måste vara i status draft för beräkning.',
|
||
message_en: 'Salary run must be in draft status to calculate.',
|
||
},
|
||
SALARY_RUN_APPROVE_NOT_REVIEW: {
|
||
httpStatus: 400,
|
||
message_sv: 'Lönekörningen måste vara i status review för godkännande.',
|
||
message_en: 'Salary run must be in review status to approve.',
|
||
},
|
||
SALARY_RUN_APPROVE_VALIDATION_FAILED: {
|
||
httpStatus: 400,
|
||
message_sv: 'Valideringsfel — korrigera innan godkännande.',
|
||
message_en: 'Validation failed — fix issues before approving.',
|
||
},
|
||
SALARY_RUN_MARK_PAID_NOT_APPROVED: {
|
||
httpStatus: 400,
|
||
message_sv: 'Lönekörningen måste vara godkänd för att markeras som betald.',
|
||
message_en: 'Salary run must be approved before it can be marked paid.',
|
||
},
|
||
SALARY_RUN_BOOK_NOT_PAID: {
|
||
httpStatus: 400,
|
||
message_sv: 'Lönekörningen måste vara markerad som betald för bokföring.',
|
||
message_en: 'Salary run must be marked paid before booking.',
|
||
},
|
||
AGI_GENERATE_NOT_BOOKABLE: {
|
||
httpStatus: 400,
|
||
message_sv: 'AGI kan endast genereras för lönekörningar i status review, approved, paid, booked eller corrected.',
|
||
message_en: 'AGI can only be generated for salary runs in review, approved, paid, booked, or corrected status.',
|
||
},
|
||
AGI_INCOMPLETE_DATA: {
|
||
httpStatus: 400,
|
||
message_sv: 'AGI-data ofullständig — kontrollera att företaget har organisationsnummer, kontaktnamn, telefon och e-post.',
|
||
message_en: 'AGI data is incomplete — verify the company has org number, contact name, phone, and email.',
|
||
},
|
||
COMPANY_NOT_FOUND: {
|
||
httpStatus: 404,
|
||
message_sv: 'Företaget kunde inte hittas.',
|
||
message_en: 'Company not found.',
|
||
},
|
||
// Phase 5 PR-1 carry-over: distinct error code for the salary-run DELETE
|
||
// FK-null guard so an operator seeing this in logs knows a journal entry
|
||
// is at risk, not just a status race.
|
||
SALARY_RUN_DELETE_HAS_JOURNAL_ENTRY: {
|
||
httpStatus: 400,
|
||
message_sv: 'Lönekörningen är kopplad till en verifikation och kan inte raderas (BFL 5 kap räkenskapsinformation).',
|
||
message_en: 'Salary run is linked to a journal entry and cannot be deleted (BFL 5 kap räkenskapsinformation).',
|
||
},
|
||
// Phase 5 PR-3 — additional import error codes.
|
||
SIE_IMPORT_DUPLICATE: {
|
||
httpStatus: 409,
|
||
message_sv: 'Den här SIE-filen har redan importerats.',
|
||
message_en: 'This SIE file has already been imported.',
|
||
},
|
||
BANK_IMPORT_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Bankfilsimporten misslyckades.',
|
||
message_en: 'Bank file import failed.',
|
||
},
|
||
BANK_FILE_FORMAT_UNKNOWN: {
|
||
httpStatus: 400,
|
||
message_sv: 'Bankfilens format kunde inte identifieras.',
|
||
message_en: 'Bank file format could not be identified.',
|
||
},
|
||
BANK_IMPORT_DUPLICATE_OTHER_COMPANY: {
|
||
httpStatus: 409,
|
||
message_sv: 'Den här filen har redan importerats för ett annat företag av samma användare.',
|
||
message_en: 'This file has already been imported into another company by this user.',
|
||
},
|
||
}
|
||
|
||
const COMPANY: Record<string, StructuredErrorEntry> = {
|
||
COMPANY_CREATE_DUPLICATE_ORG_NUMBER: {
|
||
httpStatus: 409,
|
||
message_sv: 'Ett företag med samma organisationsnummer finns redan.',
|
||
message_en: 'A company with that organisation number already exists.',
|
||
},
|
||
COMPANY_CREATE_BAS_SEED_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Kontoplanen kunde inte skapas. Försök igen.',
|
||
message_en: 'Failed to seed the chart of accounts.',
|
||
},
|
||
COMPANY_CREATE_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'Företaget kunde inte skapas.',
|
||
message_en: 'Failed to create company.',
|
||
},
|
||
}
|
||
|
||
const API_KEY: Record<string, StructuredErrorEntry> = {
|
||
API_KEY_SCOPE_INVALID: {
|
||
httpStatus: 400,
|
||
message_sv: 'En eller flera scopes är ogiltiga.',
|
||
message_en: 'One or more requested scopes are invalid.',
|
||
},
|
||
API_KEY_QUOTA_EXCEEDED: {
|
||
httpStatus: 429,
|
||
message_sv: 'Du har nått maxgränsen för antal API-nycklar.',
|
||
message_en: 'API key quota exceeded.',
|
||
},
|
||
API_KEY_CREATE_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'API-nyckeln kunde inte skapas.',
|
||
message_en: 'Failed to create API key.',
|
||
},
|
||
API_KEY_REVOKE_FAILED: {
|
||
httpStatus: 500,
|
||
message_sv: 'API-nyckeln kunde inte återkallas.',
|
||
message_en: 'Failed to revoke API key.',
|
||
},
|
||
API_KEY_NOT_FOUND: {
|
||
httpStatus: 404,
|
||
message_sv: 'API-nyckeln kunde inte hittas.',
|
||
message_en: 'API key not found.',
|
||
},
|
||
}
|
||
|
||
// ─────────────────────────────────────────────────────────────────
|
||
// Provider connection / external HTTP codes
|
||
// ─────────────────────────────────────────────────────────────────
|
||
|
||
const PROVIDER: Record<string, StructuredErrorEntry> = {
|
||
PROVIDER_AUTH_EXPIRED: {
|
||
httpStatus: 401,
|
||
message_sv: 'Anslutningen till leverantören har gått ut. Återanslut för att fortsätta.',
|
||
message_en: 'Provider authentication expired or refresh failed.',
|
||
},
|
||
PROVIDER_RATE_LIMITED: {
|
||
httpStatus: 429,
|
||
message_sv:
|
||
'Leverantören begränsar antalet anrop just nu. Vänta en stund och försök igen.',
|
||
message_en: 'Provider rate limit exceeded.',
|
||
},
|
||
PROVIDER_UNREACHABLE: {
|
||
httpStatus: 502,
|
||
message_sv: 'Leverantörens tjänst är inte tillgänglig just nu. Försök igen om en stund.',
|
||
message_en: 'Provider service is unreachable (network/DNS error).',
|
||
},
|
||
PROVIDER_UPSTREAM_ERROR: {
|
||
httpStatus: 502,
|
||
message_sv: 'Leverantören svarade med ett fel. Försök igen om en stund.',
|
||
message_en: 'Provider returned an upstream 5xx error.',
|
||
},
|
||
}
|
||
|
||
// ─────────────────────────────────────────────────────────────────
|
||
// Combined registry
|
||
// ─────────────────────────────────────────────────────────────────
|
||
|
||
const REGISTRY: Record<string, StructuredErrorEntry> = {
|
||
...GENERIC,
|
||
...BOOKKEEPING,
|
||
...TRANSACTIONS,
|
||
...MATCH_INVOICE,
|
||
...LINK_TX_JE,
|
||
...MATCH_SI,
|
||
...INVOICE,
|
||
...SUPPLIER_INVOICE,
|
||
...PERIOD,
|
||
...YEAR_END,
|
||
...OPENING_BAL,
|
||
...FX,
|
||
...REPORT,
|
||
...VAT_REPORT,
|
||
...PS_REPORT,
|
||
...SIE_EXPORT,
|
||
...TAX_DECL,
|
||
...SIE_IMPORT,
|
||
...BANK_FILE,
|
||
...OPENING_BALANCE_IMPORT,
|
||
...REGISTER_IMPORT,
|
||
...PROVIDER_MIGRATION,
|
||
...DOCUMENT,
|
||
...CUSTOMER,
|
||
...SUPPLIER,
|
||
...SUPPLIER_INVOICE_WAVE4,
|
||
...SALARY,
|
||
...COMPANY,
|
||
...API_KEY,
|
||
...PROVIDER,
|
||
}
|
||
|
||
export function getErrorEntry(code: string): StructuredErrorEntry | undefined {
|
||
return REGISTRY[code]
|
||
}
|
||
|
||
export function hasErrorEntry(code: string): boolean {
|
||
return code in REGISTRY
|
||
}
|
||
|
||
/**
|
||
* Test-only: returns all registered codes. Used by the unit test that asserts
|
||
* the matrix in the plan file stays in sync with this registry.
|
||
*/
|
||
export function listErrorCodes(): string[] {
|
||
return Object.keys(REGISTRY)
|
||
}
|