Description
Invoices are mutable (amounts may be corrected, recipients changed) but the SDK stores only the latest version, losing the history of changes. For audit and dispute purposes, each modification to an invoice should be recorded as a new immutable version with a timestamp, author, and change summary. A version history tracker should store ordered snapshots and expose the diff between any two versions.
Technical Context
Add src/invoiceVersionTracker.ts. Stores InvoiceVersion[] in src/snapshot.ts keyed by invoiceId. Each InvoiceVersion includes version: number, snapshot: InvoiceRecord, changedBy: string, changedAt: Date, and changeSummary: string. Integrates with src/client.ts updateInvoice() which must create a new version on every update. Uses src/diff.ts and generateSplitDiff() from src/splitPreview.ts for the change summary.
Acceptance Criteria
Description
Invoices are mutable (amounts may be corrected, recipients changed) but the SDK stores only the latest version, losing the history of changes. For audit and dispute purposes, each modification to an invoice should be recorded as a new immutable version with a timestamp, author, and change summary. A version history tracker should store ordered snapshots and expose the diff between any two versions.
Technical Context
Add
src/invoiceVersionTracker.ts. StoresInvoiceVersion[]insrc/snapshot.tskeyed byinvoiceId. EachInvoiceVersionincludesversion: number,snapshot: InvoiceRecord,changedBy: string,changedAt: Date, andchangeSummary: string. Integrates withsrc/client.tsupdateInvoice()which must create a new version on every update. Usessrc/diff.tsandgenerateSplitDiff()fromsrc/splitPreview.tsfor the change summary.Acceptance Criteria
InvoiceVersionTracker.record(invoiceId, newSnapshot, changedBy)creates and persists a newInvoiceVersionentryInvoiceVersionTracker.getHistory(invoiceId): Promise<InvoiceVersion[]>returns all versions in ascending orderInvoiceVersionTracker.diff(invoiceId, fromVersion, toVersion): Promise<InvoiceDiff>returns a structured diff between two version snapshotssrc/client.tsupdateInvoice()callsrecord()before overwriting the stored invoicediff(1, 3)captures all intermediate changes