Files
accounted/extensions/general/arcim-migration/lib/customer-metadata.ts
T
MattssonandClaude Fable 5 00ae3540db feat(customers): carry contact person and invoice copy recipients through migration (#1392)
* feat(customers): carry contact person and invoice copy recipients through migration

Extends the arcim-migration entity mapper, Fortnox provider mapper, canonical
DTOs, customer APIs (web + v1) and invoice send flows so contact person and
customer-level invoice CC/BCC addresses survive provider migrations. NULL
means unconfigured and empty means an explicit clear, so re-syncs enrich
legacy gaps without resurrecting deliberately removed values. Fortnox fixed
assets are split into a dedicated follow-up issue.

Fixes #1345

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* chore(db): bump customer metadata migration past pack-slug version

Main already contains 20260803230000; keep new versions strictly newest so
Supabase branching applies them in order.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(customers): complete Customer type consumers and make enrichment payload resolvable

The preview-pdf mock customer and the makeCustomer fixture now carry the
three new metadata fields, fixing the type-check failure in Build (zero
extensions) and Vercel.

The enrichment update in the migration orchestrator now spells its payload
as an object literal typed CustomerMetadataEnrichment (absent keys drop at
serialization), so the phantom-column guard resolves the columns instead of
counting another unresolvable dynamic payload past its ceiling. The cc/bcc
guards also verify element types instead of casting.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-04 10:00:03 +02:00

60 lines
1.9 KiB
TypeScript

export interface ExistingCustomerMetadata {
contact_person: string | null
invoice_email_cc_addresses: string[] | null
invoice_email_bcc_addresses: string[] | null
}
/**
* Keys restricted to the three metadata columns so callers can spell the
* update payload as an object literal (absent keys stay undefined and are
* dropped at serialization, leaving those columns untouched).
*/
export interface CustomerMetadataEnrichment {
contact_person?: string
invoice_email_cc_addresses?: string[]
invoice_email_bcc_addresses?: string[]
}
/**
* Build a provider-migration enrichment without overwriting user choices.
*
* NULL is the only "never configured" value. Empty strings/arrays are explicit
* clears, so a later migration rerun leaves them alone. The mapped row must
* also contain real metadata: converting NULL to an empty value is not useful.
*/
export function buildCustomerMetadataEnrichment(
existing: ExistingCustomerMetadata,
mapped: Record<string, unknown>,
): CustomerMetadataEnrichment | null {
const changes: CustomerMetadataEnrichment = {}
const contactPerson = mapped.contact_person
const cc = mapped.invoice_email_cc_addresses
const bcc = mapped.invoice_email_bcc_addresses
if (
existing.contact_person === null
&& typeof contactPerson === 'string'
&& contactPerson.trim().length > 0
) {
changes.contact_person = contactPerson
}
if (
existing.invoice_email_cc_addresses === null
&& Array.isArray(cc)
&& cc.length > 0
&& cc.every((x): x is string => typeof x === 'string')
) {
changes.invoice_email_cc_addresses = cc
}
if (
existing.invoice_email_bcc_addresses === null
&& Array.isArray(bcc)
&& bcc.length > 0
&& bcc.every((x): x is string => typeof x === 'string')
) {
changes.invoice_email_bcc_addresses = bcc
}
return Object.keys(changes).length > 0 ? changes : null
}