Description
Invoices carry an open-ended metadata object that integrators use for custom fields like PO numbers, project codes, and tax IDs. Without schema validation, malformed metadata silently propagates through storage and rendering, causing display errors and failed webhook deliveries. The SDK should allow integrators to register a JSON Schema for invoice metadata and validate all create/update operations against it.
Technical Context
Add src/validators/invoiceMetadataValidator.ts. Uses the ajv library (JSON Schema validator) configured in package.json. Accepts a JSON Schema object at StellarSplitConfig.metadataSchema. Called from src/client.ts createInvoice() and updateInvoice(). Adds MetadataValidationError to src/errors.ts. Schema is compiled once at SDK init and reused for performance.
Acceptance Criteria
Description
Invoices carry an open-ended
metadataobject that integrators use for custom fields like PO numbers, project codes, and tax IDs. Without schema validation, malformed metadata silently propagates through storage and rendering, causing display errors and failed webhook deliveries. The SDK should allow integrators to register a JSON Schema for invoice metadata and validate all create/update operations against it.Technical Context
Add
src/validators/invoiceMetadataValidator.ts. Uses theajvlibrary (JSON Schema validator) configured inpackage.json. Accepts a JSON Schema object atStellarSplitConfig.metadataSchema. Called fromsrc/client.tscreateInvoice()andupdateInvoice(). AddsMetadataValidationErrortosrc/errors.ts. Schema is compiled once at SDK init and reused for performance.Acceptance Criteria
InvoiceMetadataValidator.validate(metadata: unknown): ValidationResultreturns{ valid: boolean, errors?: AjvError[] }using the registered schemaStellarSplitClientconstruction and reused for all subsequent callsMetadataValidationErrorwith the full AJV error list whenthrowOnInvalid: true(default true)metadataSchemais configured,validate()is a no-op and returns{ valid: true }src/client.tscreateInvoice()andupdateInvoice()callvalidate()before any persistence or network call