- Remove all sector-specific extensions (construction, ecommerce, export, hotel, restaurant, tech) — only general-purpose extensions remain - Move NE-bilaga and SRU export from extensions to core reports (lib/reports/) - Move moms-box-mapping from extensions/export/shared to lib/vat/ - Replace per-extension API routes with catch-all dispatcher (app/api/extensions/ext/[...path]/route.ts) - Add manifest.json for each extension with metadata, env vars, and deps - Add api-routes.ts pattern for extension-defined API endpoints - Add code generation scripts (generate-extension-registry, create-extension) - Add extensions.config.json for opt-in extension loading - Add extensions.schema.json for config validation - Add email service interface with noop default (lib/email/service.ts) - Add CI workflow (core-build.yml) to verify core builds with zero extensions - Add migration 045: expand account_type CHECK for untaxed_reserves - Update CLAUDE.md with comprehensive extension system documentation - Update all report engines and bookkeeping services for new imports - Clean up extensions.schema.json to only list existing extensions Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
74 lines
2.0 KiB
TypeScript
74 lines
2.0 KiB
TypeScript
import { NextResponse } from 'next/server'
|
|
import { processOverdueReminders } from '@/lib/invoices/reminder-processor'
|
|
import { getEmailService } from '@/lib/email/service'
|
|
|
|
// Verify cron secret for security
|
|
function verifyCronSecret(request: Request): boolean {
|
|
const authHeader = request.headers.get('authorization')
|
|
const cronSecret = process.env.CRON_SECRET
|
|
|
|
if (!cronSecret) {
|
|
console.error('CRON_SECRET not configured')
|
|
return false
|
|
}
|
|
|
|
if (!authHeader) {
|
|
return false
|
|
}
|
|
|
|
// Support both "Bearer <token>" and just "<token>" formats
|
|
const token = authHeader.startsWith('Bearer ')
|
|
? authHeader.substring(7)
|
|
: authHeader
|
|
|
|
return token === cronSecret
|
|
}
|
|
|
|
export async function GET(request: Request) {
|
|
// Verify cron authentication
|
|
if (!verifyCronSecret(request)) {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
|
}
|
|
|
|
// Check if email service is configured
|
|
if (!getEmailService().isConfigured()) {
|
|
console.error('Email service not configured, skipping reminder cron')
|
|
return NextResponse.json({
|
|
success: false,
|
|
error: 'Email service not configured'
|
|
}, { status: 503 })
|
|
}
|
|
|
|
try {
|
|
console.log('Starting invoice reminder cron job...')
|
|
|
|
const result = await processOverdueReminders()
|
|
|
|
console.log(`Reminder cron completed: ${result.sent} sent, ${result.failed} failed out of ${result.processed} processed`)
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
processed: result.processed,
|
|
sent: result.sent,
|
|
failed: result.failed,
|
|
results: result.results.map(r => ({
|
|
invoiceNumber: r.invoiceNumber,
|
|
reminderLevel: r.reminderLevel,
|
|
success: r.success,
|
|
error: r.error
|
|
}))
|
|
})
|
|
} catch (error) {
|
|
console.error('Invoice reminder cron job error:', error)
|
|
return NextResponse.json(
|
|
{ error: error instanceof Error ? error.message : 'Cron job failed' },
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|
|
|
|
// Also support POST for manual triggering via dashboard
|
|
export async function POST(request: Request) {
|
|
return GET(request)
|
|
}
|