fix: downgrade missing extension env vars to warning, add error boundaries and cron auth fixes

- Change missing extension env vars from throw to log.warn (graceful degradation)
- Move initialized flag after all init steps complete
- Add error.tsx and loading.tsx for dashboard error boundaries
- Fix cron route auth header checks
- Add ensureInitialized() to journal entry reverse and invoice mark-paid/sent routes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jakob Wennberg
2026-03-02 15:09:23 +01:00
co-authored by Claude Opus 4.6
parent 13725ffc16
commit 4031ab680d
16 changed files with 76 additions and 12 deletions
+11 -2
View File
@@ -394,14 +394,23 @@ export async function reverseEntry(
throw new Error(`Failed to post reversal entry: ${postError.message}`)
}
// Mark original as reversed with reversed_by_id link
await supabase
// Mark original as reversed with reversed_by_id link (CAS guard: only if still 'posted')
const { data: updatedOriginal, error: casError } = await supabase
.from('journal_entries')
.update({
status: 'reversed',
reversed_by_id: reversalEntry.id,
})
.eq('id', entryId)
.eq('status', 'posted')
.select('id')
if (casError || !updatedOriginal || updatedOriginal.length === 0) {
// Another concurrent reversal already changed the status — roll back our reversal
await supabase.from('journal_entry_lines').delete().eq('journal_entry_id', reversalEntry.id)
await supabase.from('journal_entries').delete().eq('id', reversalEntry.id)
throw new Error('Entry was already reversed by a concurrent operation')
}
// Fetch complete reversal entry with lines
const { data: completeEntry } = await supabase
+3 -2
View File
@@ -46,7 +46,7 @@ function validateEnvironment(): void {
}
if (missingExt.length > 0) {
throw new Error(`Missing required extension environment variables: ${missingExt.join(', ')}`)
log.warn(`Missing extension environment variables (extensions needing them may not work): ${missingExt.join(', ')}`)
}
for (const v of OPTIONAL_VARS) {
@@ -64,10 +64,11 @@ function validateEnvironment(): void {
*/
export function ensureInitialized(): void {
if (initialized) return
initialized = true
validateEnvironment()
setContextFactory(createExtensionContext)
registerSupplierInvoiceHandler()
loadExtensions()
initialized = true
}