Added extension functionality

This commit is contained in:
Emil
2026-02-21 11:39:45 +01:00
parent 2f83f232c6
commit 026497ed75
132 changed files with 3533 additions and 60 deletions
+40
View File
@@ -0,0 +1,40 @@
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',
'push-notifications',
'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
}