docs(production): standardiserad produktionsberedskap och gap-analys

Lägger docs/production-readiness.md och siax/production-gaps.json enligt SIAX Master Definition of Done. Underlag: git-, kod- och live-evidens 2026-11-11. Nivån är evidensbaserad, inte ett leveransgodkännande.
This commit is contained in:
2026-11-10 09:15:21 +01:00
parent 0fda8cae48
commit 2bee8eb778
6135 changed files with 4 additions and 1718997 deletions
-99
View File
@@ -1,99 +0,0 @@
'use client'
import {
createContext,
useCallback,
useContext,
useMemo,
useSyncExternalStore,
type ReactNode,
} from 'react'
import {
DEFAULT_PALETTE,
PALETTE_STORAGE_KEY,
PALETTE_VALUES,
isPalette,
type Palette,
} from '@/lib/theme/palettes'
const PALETTE_CHANGE_EVENT = 'accounted:palette-change'
interface PaletteContextValue {
palette: Palette
setPalette: (palette: Palette) => void
}
const PaletteContext = createContext<PaletteContextValue | null>(null)
const paletteInitScript = `
(function () {
var palette = ${JSON.stringify(DEFAULT_PALETTE)};
try {
var stored = window.localStorage.getItem(${JSON.stringify(PALETTE_STORAGE_KEY)});
if (${JSON.stringify(PALETTE_VALUES)}.indexOf(stored) !== -1) palette = stored;
} catch (_) {}
document.documentElement.dataset.palette = palette;
})();
`
function applyPalette(palette: Palette) {
document.documentElement.dataset.palette = palette
}
function getPaletteSnapshot(): Palette {
const palette = document.documentElement.dataset.palette
return isPalette(palette) ? palette : DEFAULT_PALETTE
}
function subscribeToPalette(onStoreChange: () => void) {
function handlePaletteChange() {
onStoreChange()
}
function handleStorage(event: StorageEvent) {
if (event.key !== PALETTE_STORAGE_KEY && event.key !== null) return
const palette = isPalette(event.newValue) ? event.newValue : DEFAULT_PALETTE
applyPalette(palette)
onStoreChange()
}
window.addEventListener(PALETTE_CHANGE_EVENT, handlePaletteChange)
window.addEventListener('storage', handleStorage)
return () => {
window.removeEventListener(PALETTE_CHANGE_EVENT, handlePaletteChange)
window.removeEventListener('storage', handleStorage)
}
}
export function PaletteProvider({ children }: { children: ReactNode }) {
const palette = useSyncExternalStore(
subscribeToPalette,
getPaletteSnapshot,
() => DEFAULT_PALETTE,
)
const setPalette = useCallback((nextPalette: Palette) => {
applyPalette(nextPalette)
try {
window.localStorage.setItem(PALETTE_STORAGE_KEY, nextPalette)
} catch {
// The active tab still keeps the selected palette when storage is blocked.
}
window.dispatchEvent(new Event(PALETTE_CHANGE_EVENT))
}, [])
const value = useMemo(() => ({ palette, setPalette }), [palette, setPalette])
return (
<>
<script suppressHydrationWarning dangerouslySetInnerHTML={{ __html: paletteInitScript }} />
<PaletteContext.Provider value={value}>{children}</PaletteContext.Provider>
</>
)
}
export function usePalette() {
const context = useContext(PaletteContext)
if (!context) throw new Error('usePalette must be used within PaletteProvider')
return context
}
@@ -1,25 +0,0 @@
'use client'
import { useMemo, type ReactNode } from 'react'
import { SWRConfig } from 'swr'
import { buildReferenceFallback, type ReferenceSeed } from '@/lib/reference-data/seed'
/**
* Nested SWR config carrying the server-fetched reference data as
* `fallback`. Mounted by app/(dashboard)/layout.tsx inside CompanyProvider;
* SWR merges this with the root SWRProvider so the shared cache, fetcher
* and dedupe stay global while the seed is per company.
*/
export function ReferenceDataSeed({
companyId,
fiscalPeriods,
cashAccounts,
settings,
children,
}: ReferenceSeed & { companyId: string | null; children: ReactNode }) {
const fallback = useMemo(
() => buildReferenceFallback(companyId, { fiscalPeriods, cashAccounts, settings }),
[companyId, fiscalPeriods, cashAccounts, settings],
)
return <SWRConfig value={{ fallback }}>{children}</SWRConfig>
}
-29
View File
@@ -1,29 +0,0 @@
'use client'
import { SWRConfig } from 'swr'
import type { ReactNode } from 'react'
/**
* Global SWR defaults: one shared client-side cache so repeated mounts of the
* same data (company settings, nav badges, reference data) dedupe in-flight
* requests and render instantly from cache on back-navigation, revalidating
* in the background instead of re-showing skeletons on every visit.
*
* String keys are fetched as JSON from our own API routes; hooks that read
* Supabase directly pass an array key with their own fetcher.
*/
export function SWRProvider({ children }: { children: ReactNode }) {
return (
<SWRConfig
value={{
fetcher: async (key: string) => {
const res = await fetch(key)
if (!res.ok) throw new Error(`HTTP ${res.status} for ${key}`)
return res.json()
},
}}
>
{children}
</SWRConfig>
)
}