Fix/supp ag fb (#1023)
* fix: prevent credit notes from entering payment flow * fix: persist and display customer personal numbers * feat: configure automatic invoice reminder days * fix: issue credit notes through send flow * chore: add repository agent guidance * feat(mcp): route tools across user companies * fix(articles): delete unused register entries * feat(invoices): improve issued invoice actions * feat(supplier-invoices): retain uploaded source documents * docs: record implementation decisions * feat: enhance customer personal number handling and validation - Updated CustomerForm to allow personal numbers in the format of "********-1234" for individual customers. - Added validation to ensure personal numbers are only accepted for individual customers in CreateCustomerSchema. - Implemented masking and encryption for personal numbers to enhance data protection. - Introduced new utility functions for masking and encrypting personal numbers. - Added database migration to enforce unique constraints on credit note relationships and prevent duplicate entries. - Enhanced error handling and logging for credit note issuance and invoice processing. - Updated tests to cover new credit note creation guards and personal number handling. * test: enhance list companies test with supabase query mocks
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Display a personal identity number without exposing birth date or full ID.
|
||||
*/
|
||||
export function maskCustomerPersonalNumber(value: string | null | undefined): string | null {
|
||||
if (!value) return null
|
||||
const last4 = value.replace(/\D/g, '').slice(-4)
|
||||
return last4.length === 4 ? `********-${last4}` : null
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { decryptPersonnummer, encryptPersonnummer } from '@/lib/salary/personnummer'
|
||||
import { maskCustomerPersonalNumber } from '@/lib/customers/mask-personal-number'
|
||||
|
||||
export function encryptCustomerPersonalNumber(value: string | null | undefined): string | null {
|
||||
return value ? encryptPersonnummer(value) : null
|
||||
}
|
||||
|
||||
export function maskStoredCustomerPersonalNumber(value: string | null | undefined): string | null {
|
||||
if (!value) return null
|
||||
if (/^(\d{6}|\d{8})[-+]?\d{4}$/.test(value)) {
|
||||
return maskCustomerPersonalNumber(value)
|
||||
}
|
||||
return maskCustomerPersonalNumber(decryptPersonnummer(value))
|
||||
}
|
||||
|
||||
export function maskCustomerRow<T extends { personal_number?: string | null }>(row: T): T {
|
||||
return {
|
||||
...row,
|
||||
personal_number: maskStoredCustomerPersonalNumber(row.personal_number),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user