Files
accounted/lib/extensions/toggle-check.ts
T
Jakob Wennberg 497ef876bb feat: add Recapt analytics, remove push-notifications extension, UI fixes
- Integrate Recapt session tracking with user identity in dashboard layout
- Remove push-notifications extension from settings, panel registry, and toggle list
- Fix journal entry preview overflow on narrow viewports
- Update transaction manual booking button label
- Clarify invoice email error message to reference env vars

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 10:12:26 +01:00

40 lines
1.0 KiB
TypeScript

import { createServiceClient } from '@/lib/supabase/server'
/**
* Check if an extension is enabled for a specific user.
* Used by event handlers to gate execution.
*
* For backward compatibility during the transition period,
* general extensions that were previously always-on default to
* enabled when no toggle row exists.
*/
const LEGACY_GENERAL_EXTENSIONS = [
'receipt-ocr',
'ai-categorization',
'ai-chat',
'enable-banking',
]
export async function isExtensionEnabled(
userId: string,
sectorSlug: string,
extensionSlug: string
): Promise<boolean> {
const supabase = await createServiceClient()
const { data } = await supabase
.from('extension_toggles')
.select('enabled')
.eq('user_id', userId)
.eq('sector_slug', sectorSlug)
.eq('extension_slug', extensionSlug)
.single()
// If no toggle row exists, check if this is a legacy extension
if (!data) {
return sectorSlug === 'general' && LEGACY_GENERAL_EXTENSIONS.includes(extensionSlug)
}
return data.enabled
}