Files
accounted/lib/extensions/sectors.ts
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

78 lines
2.9 KiB
TypeScript

import type { Sector, SectorSlug, ExtensionDefinition } from './types'
import { EXTENSION_DEFINITIONS } from './_generated/sector-definitions'
import { WORKSPACES } from './_generated/workspace-map'
import { requiredCapabilityForExtension } from '@/lib/entitlements/keys'
import type { CapabilityKey } from '@/lib/entitlements/keys'
// ============================================================
// Sector & Extension Registry
// ============================================================
//
// Sector shells are structural and always present.
// Extension definitions per sector come from the generated file
// (controlled by extensions.config.json).
// ============================================================
/** Sector shells: structural metadata, always available */
const SECTOR_SHELLS: Omit<Sector, 'extensions'>[] = [
{
slug: 'general',
name: 'Generella verktyg',
icon: 'Layers',
description: 'Verktyg som passar alla verksamheter',
},
]
/** Full sectors with extensions merged from generated definitions */
export const SECTORS: Sector[] = SECTOR_SHELLS.map(shell => ({
...shell,
extensions: EXTENSION_DEFINITIONS[shell.slug] ?? [],
}))
// ============================================================
// Helper functions
// ============================================================
export function getSector(slug: SectorSlug): Sector | undefined {
return SECTORS.find(s => s.slug === slug)
}
export function getExtensionDefinition(sectorSlug: string, extensionSlug: string): ExtensionDefinition | undefined {
const sector = SECTORS.find(s => s.slug === sectorSlug)
return sector?.extensions.find(e => e.slug === extensionSlug)
}
/**
* Paid capability an extension requires, resolved by its registry id (== slug).
* The API-route dispatcher keys off this so a paid extension is gated at the
* request chokepoint, reusing the same EXTENSION_REQUIRED_CAPABILITY map that
* hides its sidebar item and blocks its page (lib/entitlements/keys).
*/
export function requiredCapabilityForExtensionId(extensionId: string): CapabilityKey | undefined {
const ext = getAllExtensions().find(e => e.slug === extensionId)
return ext ? requiredCapabilityForExtension(ext.sector, ext.slug) : undefined
}
export function getAllExtensions(): ExtensionDefinition[] {
return SECTORS.flatMap(s => s.extensions)
}
export function getExtensionsBySector(slug: SectorSlug): ExtensionDefinition[] {
return getSector(slug)?.extensions ?? []
}
/** Extensions with a workspace and a quickAction href, for sidebar nav. */
export function getExtensionNavItems(): { href: string; label: string; icon: string }[] {
return getAllExtensions()
.filter(e => {
const key = `${e.sector}/${e.slug}`
return key in WORKSPACES && !!e.quickAction?.href
})
.sort((a, b) => (a.quickAction!.order ?? 0) - (b.quickAction!.order ?? 0))
.map(e => ({
href: e.quickAction!.href!,
label: e.quickAction!.label,
icon: e.quickAction!.icon,
}))
}