b387a77bfd
* chore: remove Sentry, consolidate migrations, add test coverage Remove @sentry/nextjs and all Sentry integration code — error tracking now handled by Recapt. Consolidate 22 incremental migrations into a single schema sync migration. Add 6 new test suites (auth, invoice matching, VAT rules, opening balances) and extend report tests with edge cases. Update Docker image name to gnubok, sync crontabs and extension presets, fix CSP missing space, simplify journal entry missing-document dialog. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: remove viewer bank import migration never applied to production 20260413150000_viewer_bank_import_permissions.sql (PR #234) was merged to main but never applied to the production database. It references current_active_company_id() which does not exist in production either. This breaks fresh installs and Supabase preview branches because the migration runs before the consolidated schema sync. Remove it so the migration chain matches production. The viewer bank import RLS policies should be re-added in a future migration alongside the helper functions they depend on. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: correct delete policies for tables without company_id column Seven tables in the generic delete-policy loop don't have a direct company_id column, causing fresh installs to fail with "column company_id does not exist". Fix by moving them out of the loop: - invoice_items, journal_entry_lines, receipt_line_items, supplier_invoice_items → join through parent table - extension_toggles, notification_settings, push_subscriptions → user-scoped (auth.uid() = user_id) All policies match their existing production definitions. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
82 lines
2.3 KiB
TypeScript
82 lines
2.3 KiB
TypeScript
import { loadExtensions } from '@/lib/extensions/loader'
|
|
import { setContextFactory } from '@/lib/extensions/registry'
|
|
import { createExtensionContext } from '@/lib/extensions/context-factory'
|
|
import { registerSupplierInvoiceHandler } from '@/lib/bookkeeping/handlers/supplier-invoice-handler'
|
|
import { registerEventLogHandler } from '@/lib/events/handlers/event-log-handler'
|
|
import { createLogger } from '@/lib/logger'
|
|
|
|
const log = createLogger('init')
|
|
|
|
let initialized = false
|
|
|
|
const REQUIRED_CORE_VARS = [
|
|
'NEXT_PUBLIC_SUPABASE_URL',
|
|
'NEXT_PUBLIC_SUPABASE_ANON_KEY',
|
|
'SUPABASE_SERVICE_ROLE_KEY',
|
|
'NEXT_PUBLIC_APP_URL',
|
|
'CRON_SECRET',
|
|
] as const
|
|
|
|
const REQUIRED_EXTENSION_VARS = [
|
|
'ENABLE_BANKING_APP_ID',
|
|
'ENABLE_BANKING_PRIVATE_KEY',
|
|
'ANTHROPIC_API_KEY',
|
|
'OPENAI_API_KEY',
|
|
] as const
|
|
|
|
const OPTIONAL_VARS = [
|
|
'LANGFUSE_SECRET_KEY',
|
|
'LANGFUSE_PUBLIC_KEY',
|
|
] as const
|
|
|
|
function validateEnvironment(): void {
|
|
// During builds (CI, Docker, Vercel), env vars may be absent or set to
|
|
// placeholder sentinels. Skip validation so Next.js page collection
|
|
// doesn't fail — real validation happens at runtime.
|
|
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL
|
|
if (!supabaseUrl || supabaseUrl.startsWith('__')) return
|
|
|
|
const missing: string[] = []
|
|
|
|
for (const v of REQUIRED_CORE_VARS) {
|
|
if (!process.env[v]) missing.push(v)
|
|
}
|
|
|
|
if (missing.length > 0) {
|
|
throw new Error(`Missing required environment variables: ${missing.join(', ')}`)
|
|
}
|
|
|
|
const missingExt: string[] = []
|
|
for (const v of REQUIRED_EXTENSION_VARS) {
|
|
if (!process.env[v]) missingExt.push(v)
|
|
}
|
|
|
|
if (missingExt.length > 0) {
|
|
log.warn(`Missing extension environment variables (extensions needing them may not work): ${missingExt.join(', ')}`)
|
|
}
|
|
|
|
for (const v of OPTIONAL_VARS) {
|
|
if (!process.env[v]) {
|
|
log.warn(`Optional environment variable ${v} is not set`)
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Ensure the system is initialized (extensions loaded, context factory wired,
|
|
* core event handlers registered).
|
|
* Called from API routes that emit events.
|
|
* Idempotent — safe to call multiple times.
|
|
*/
|
|
export function ensureInitialized(): void {
|
|
if (initialized) return
|
|
|
|
validateEnvironment()
|
|
setContextFactory(createExtensionContext)
|
|
registerSupplierInvoiceHandler()
|
|
registerEventLogHandler()
|
|
loadExtensions()
|
|
|
|
initialized = true
|
|
}
|