Skip to content

Invoice Metadata JSON Schema Validator #533

Description

@Kingsman-99

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

  • InvoiceMetadataValidator.validate(metadata: unknown): ValidationResult returns { valid: boolean, errors?: AjvError[] } using the registered schema
  • The validator is compiled once during StellarSplitClient construction and reused for all subsequent calls
  • Throws MetadataValidationError with the full AJV error list when throwOnInvalid: true (default true)
  • When no metadataSchema is configured, validate() is a no-op and returns { valid: true }
  • src/client.ts createInvoice() and updateInvoice() call validate() before any persistence or network call
  • All CI checks (npm test, npm run build, ESLint/TypeScript) pass and the branch has no merge conflicts

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions