Files
accounted/supabase/migrations/20260324120001_skatteverket_tokens.sql
T
Jakob WennbergandClaude Opus 4.6 d8e0a22495 feat: counterparty templates, Skatteverket extension, complete VAT form (#117)
* feat: separate AR/AP/accounting into distinct nav groups (#92)

Split the flat "Finans" sidebar group into three visually distinct
sections — Försäljning (AR), Inköp (AP), and Redovisning — so users
coming from Fortnox immediately find customer invoicing and supplier
invoices as top-level concepts.

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

* feat: journal entry detail view, correction chain, and account name display

- Add journal entry detail page at /bookkeeping/[id] with full entry view
- Add correction chain API and component showing storno relationships
- Add JournalEntryStatusBadge component for entry status display
- Show debit/credit account names in template picker and review dialogs
- Expand client-side BAS account name mapping with additional accounts
- Show account codes on transaction inbox suggestion buttons

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

* fix: address review feedback — N+1 query, duplicate name, nav dedup

- Batch reverse-lookup into single query per BFS iteration (was N+1)
- Differentiate account 2393 from 2893 in display names
- Extract shared loop for desktop/mobile nav group rendering

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

* feat: counterparty templates, Skatteverket extension, VAT form completeness, and UI cleanup

- Add counterparty-based categorization templates (learned from user approvals
  and auto-ingestion) with fuzzy matching in the mapping engine
- Add Skatteverket extension for direct VAT declaration submission via API
- Complete VAT declaration form with all 30 SKV 4700 boxes (ruta 08, 35-42, 50, 60-62)
- Fix ruta 49 formula to include import VAT (ruta 60+61+62)
- Simplify dashboard UI: remove redundant icons from stat cards, customer cards,
  invoice list, supplier invoices; use Badge variants consistently
- Add SkatteverketPanel component to reports page
- Add categorization_templates and skatteverket_tokens migrations
- Update tests and helpers for new types

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

* fix: address PR review feedback — VAT detection, migration timestamps, dedup

- Fix detectVatTreatment to derive actual rate (12%/6%) from VAT line
  description instead of hardcoding standard_25
- Rename skatteverket_tokens migration to 20260324120001 to avoid
  duplicate timestamp with categorization_templates (fixes Supabase
  deployment failure)
- Make refreshAccessToken accept previousRefreshCount param to enforce
  refresh limit contract at the type level
- Fix rate limiter TOCTOU by claiming slot before await
- Extract formatRedovisare/formatRedovisningsperiod to shared
  lib/skatteverket/format.ts — eliminates duplication between
  mappers.ts and SkatteverketPanel.tsx

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 13:41:12 +01:00

44 lines
1.5 KiB
SQL

-- Skatteverket OAuth2 token storage
--
-- Stores encrypted access/refresh tokens from the Skatteverket
-- `per` (BankID) OAuth2 flow. One row per user.
-- Tokens are AES-256-GCM encrypted at the application layer.
CREATE TABLE public.skatteverket_tokens (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
user_id UUID REFERENCES auth.users ON DELETE CASCADE NOT NULL,
access_token TEXT NOT NULL, -- AES-256-GCM encrypted
refresh_token TEXT, -- AES-256-GCM encrypted
expires_at TIMESTAMPTZ NOT NULL,
refresh_count INTEGER NOT NULL DEFAULT 0,
scope TEXT NOT NULL DEFAULT 'momsdeklaration',
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
UNIQUE(user_id)
);
-- RLS
ALTER TABLE public.skatteverket_tokens ENABLE ROW LEVEL SECURITY;
CREATE POLICY "Users can view own Skatteverket tokens"
ON public.skatteverket_tokens FOR SELECT
USING (auth.uid() = user_id);
CREATE POLICY "Users can insert own Skatteverket tokens"
ON public.skatteverket_tokens FOR INSERT
WITH CHECK (auth.uid() = user_id);
CREATE POLICY "Users can update own Skatteverket tokens"
ON public.skatteverket_tokens FOR UPDATE
USING (auth.uid() = user_id);
CREATE POLICY "Users can delete own Skatteverket tokens"
ON public.skatteverket_tokens FOR DELETE
USING (auth.uid() = user_id);
-- updated_at trigger
CREATE TRIGGER update_skatteverket_tokens_updated_at
BEFORE UPDATE ON public.skatteverket_tokens
FOR EACH ROW
EXECUTE FUNCTION public.update_updated_at_column();