fa7d4075cf
* feat(accounting): update accounting method validation and messaging for aktiebolag and enskild firma * Remove AI subsystem and related code - Deleted AI proposals and requests persistence logic from `lib/ai/proposals/persist.ts`. - Removed re-validation logic for proposals in `lib/ai/proposals/re-validate.ts`. - Cleaned up schemas related to AI flows in `lib/api/schemas.ts`. - Removed AI-related fields from bookkeeping engine in `lib/bookkeeping/engine.ts`. - Eliminated AI event types from `lib/events/types.ts`. - Updated tests to reflect the removal of AI-related functionality in `lib/extensions/__tests__/sectors.test.ts`. - Adjusted initialization logic in `lib/init.ts` to exclude AI proposal handler registration. - Cleaned up transaction ingestion logic in `lib/transactions/ingest.ts` to remove AI flow checks. - Updated helper functions in `tests/helpers.ts` to remove AI-related settings. - Removed AI-related types and interfaces from `types/index.ts`. - Added migration script to drop AI-related tables and settings from the database. * fix(migrations): ensure foreign key constraint is dropped before removing AI tables * feat(invoice-inbox): implement deterministic invoice field extraction and inbox provisioning - Added `extract-invoice-fields.ts` for extracting fields from PDF invoices using regex and pdfjs-dist, replacing the previous AI classifier. - Introduced `inbox-provisioning.ts` to manage company inbox addresses and rotation of inboxes using Supabase RPCs. - Created `resend-inbound.ts` for handling inbound email events and attachments via the Resend API. - Defined the extension manifest for the invoice inbox, specifying required environment variables and descriptions. - Migrated database schema to remove AI-related columns and tighten the status enum in `invoice_inbox_items`. * feat(invoice-inbox): remove AI-specific columns and tighten status enum * fix(skattekonto): remove manual entry creation reference from transaction input * fix(schemas): remove accounting method validation for aktiebolag in UpdateSettingsSchema
209 lines
5.4 KiB
TypeScript
209 lines
5.4 KiB
TypeScript
/**
|
|
* Notification payload constructors for all push notification types.
|
|
*
|
|
* Centralises every notification's title/body/icon/action in one place.
|
|
* Both event handlers and the cron scheduler import from here.
|
|
*/
|
|
|
|
import type { NotificationPayload } from './notification-sender'
|
|
|
|
// ============================================================
|
|
// Helpers
|
|
// ============================================================
|
|
|
|
function formatDate(dateStr: string): string {
|
|
const date = new Date(dateStr)
|
|
return date.toLocaleDateString('sv-SE', {
|
|
day: 'numeric',
|
|
month: 'short',
|
|
})
|
|
}
|
|
|
|
// ============================================================
|
|
// Event-driven payloads
|
|
// ============================================================
|
|
|
|
export function createPeriodLockedPayload(
|
|
periodName: string,
|
|
periodId: string
|
|
): NotificationPayload {
|
|
return {
|
|
title: 'Period låst',
|
|
body: `${periodName} har låsts`,
|
|
icon: '/icons/icon-192.png',
|
|
badge: '/icons/badge-72.png',
|
|
tag: `period-locked-${periodId}`,
|
|
data: {
|
|
url: '/periods',
|
|
type: 'period_locked',
|
|
id: periodId,
|
|
},
|
|
}
|
|
}
|
|
|
|
export function createYearClosedPayload(
|
|
periodName: string,
|
|
periodId: string
|
|
): NotificationPayload {
|
|
return {
|
|
title: 'Årsbokslut klart',
|
|
body: `Årsbokslut klart för ${periodName}`,
|
|
icon: '/icons/icon-192.png',
|
|
badge: '/icons/badge-72.png',
|
|
tag: `year-closed-${periodId}`,
|
|
data: {
|
|
url: '/periods',
|
|
type: 'period_year_closed',
|
|
id: periodId,
|
|
},
|
|
}
|
|
}
|
|
|
|
export function createInvoiceSentPayload(
|
|
invoiceNumber: string,
|
|
invoiceId: string
|
|
): NotificationPayload {
|
|
return {
|
|
title: 'Faktura skickad',
|
|
body: `Faktura ${invoiceNumber} skickad`,
|
|
icon: '/icons/icon-192.png',
|
|
badge: '/icons/badge-72.png',
|
|
tag: `invoice-sent-${invoiceId}`,
|
|
data: {
|
|
url: `/invoices/${invoiceId}`,
|
|
type: 'invoice_sent',
|
|
id: invoiceId,
|
|
},
|
|
}
|
|
}
|
|
|
|
export function createReceiptExtractedPayload(
|
|
merchantName: string | null,
|
|
receiptId: string
|
|
): NotificationPayload {
|
|
const merchant = merchantName || 'Okänd butik'
|
|
return {
|
|
title: 'Kvitto analyserat',
|
|
body: `Kvitto analyserat: ${merchant}`,
|
|
icon: '/icons/icon-192.png',
|
|
badge: '/icons/badge-72.png',
|
|
tag: `receipt-extracted-${receiptId}`,
|
|
data: {
|
|
url: '/transactions',
|
|
type: 'receipt_extracted',
|
|
id: receiptId,
|
|
},
|
|
}
|
|
}
|
|
|
|
export function createReceiptMatchedPayload(
|
|
receiptId: string,
|
|
transactionId: string
|
|
): NotificationPayload {
|
|
return {
|
|
title: 'Kvitto matchat',
|
|
body: 'Kvitto matchat mot transaktion',
|
|
icon: '/icons/icon-192.png',
|
|
badge: '/icons/badge-72.png',
|
|
tag: `receipt-matched-${receiptId}`,
|
|
data: {
|
|
url: '/transactions',
|
|
type: 'receipt_matched',
|
|
id: receiptId,
|
|
},
|
|
}
|
|
}
|
|
|
|
// ============================================================
|
|
// Missing underlag payload
|
|
// ============================================================
|
|
|
|
export function createMissingUnderlagPayload(count: number): NotificationPayload {
|
|
return {
|
|
title: 'Saknade underlag',
|
|
body: `${count} verifikation(er) saknar underlag. Bifoga för att uppfylla bokföringslagen.`,
|
|
icon: '/icons/icon-192.png',
|
|
badge: '/icons/badge-72.png',
|
|
tag: 'missing-underlag-weekly',
|
|
data: {
|
|
url: '/bookkeeping?missingUnderlag=true',
|
|
type: 'missing_underlag',
|
|
},
|
|
}
|
|
}
|
|
|
|
// ============================================================
|
|
// Cron-based payloads (moved from lib/push/web-push.ts)
|
|
// ============================================================
|
|
|
|
export function createTaxDeadlinePayload(
|
|
title: string,
|
|
dueDate: string,
|
|
daysUntil: number,
|
|
deadlineId: string
|
|
): NotificationPayload {
|
|
const urgencyText =
|
|
daysUntil === 0 ? 'IDAG!' : daysUntil === 1 ? 'imorgon' : `om ${daysUntil} dagar`
|
|
|
|
return {
|
|
title: `${title}`,
|
|
body: `Deadline ${urgencyText} (${formatDate(dueDate)})`,
|
|
icon: '/icons/icon-192.png',
|
|
badge: '/icons/badge-72.png',
|
|
tag: `tax-deadline-${deadlineId}`,
|
|
data: {
|
|
url: '/deadlines',
|
|
type: 'tax_deadline',
|
|
id: deadlineId,
|
|
},
|
|
actions: [
|
|
{ action: 'view', title: 'Visa' },
|
|
{ action: 'dismiss', title: 'Avfärda' },
|
|
],
|
|
}
|
|
}
|
|
|
|
export function createInvoiceOverduePayload(
|
|
invoiceNumber: string,
|
|
customerName: string,
|
|
amount: number,
|
|
dueDate: string,
|
|
invoiceId: string
|
|
): NotificationPayload {
|
|
return {
|
|
title: `Obetald faktura #${invoiceNumber}`,
|
|
body: `${customerName} - ${amount.toLocaleString('sv-SE')} kr (förföll ${formatDate(dueDate)})`,
|
|
icon: '/icons/icon-192.png',
|
|
badge: '/icons/badge-72.png',
|
|
tag: `invoice-${invoiceId}`,
|
|
data: {
|
|
url: `/invoices/${invoiceId}`,
|
|
type: 'invoice_overdue',
|
|
id: invoiceId,
|
|
},
|
|
actions: [{ action: 'view', title: 'Visa faktura' }],
|
|
}
|
|
}
|
|
|
|
export function createInvoiceDuePayload(
|
|
invoiceNumber: string,
|
|
customerName: string,
|
|
amount: number,
|
|
dueDate: string,
|
|
invoiceId: string
|
|
): NotificationPayload {
|
|
return {
|
|
title: `Faktura #${invoiceNumber} förfaller`,
|
|
body: `${customerName} - ${amount.toLocaleString('sv-SE')} kr (${formatDate(dueDate)})`,
|
|
icon: '/icons/icon-192.png',
|
|
badge: '/icons/badge-72.png',
|
|
tag: `invoice-${invoiceId}`,
|
|
data: {
|
|
url: `/invoices/${invoiceId}`,
|
|
type: 'invoice_due',
|
|
id: invoiceId,
|
|
},
|
|
actions: [{ action: 'view', title: 'Visa faktura' }],
|
|
}
|
|
}
|