Skip to content

Invoice Version History Diff Tracker #550

Description

@Kingsman-99

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

  • InvoiceVersionTracker.record(invoiceId, newSnapshot, changedBy) creates and persists a new InvoiceVersion entry
  • InvoiceVersionTracker.getHistory(invoiceId): Promise<InvoiceVersion[]> returns all versions in ascending order
  • InvoiceVersionTracker.diff(invoiceId, fromVersion, toVersion): Promise<InvoiceDiff> returns a structured diff between two version snapshots
  • src/client.ts updateInvoice() calls record() before overwriting the stored invoice
  • Unit tests assert that three sequential updates produce three history entries and that diff(1, 3) captures all intermediate changes
  • All CI checks (npm test, npm run build, ESLint/TypeScript) pass and the branch has no merge conflicts

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions