ExtractedInvoiceSchema (invoice/schema.ts)

mastra · templates/template-accounts-payable-invoice-processing/src/mastra/invoice/schema.ts · typescript · Apache-2.0
payments

A Zod schema for validating extracted invoice data, ensuring financial precision and consistency across line items, taxes, and totals.

// Source: https://github.com/mastra-ai/mastra | License: Apache-2.0 | Copyright 2025 Kepler Software, Inc
// Provided via justclaw.it.com; keep this notice with the code.
import { z } from 'zod';
import Decimal from 'decimal.js';
import { isCanonicalCurrency, minorUnitDigits } from './currency.ts';

const RequiredTextSchema = z.string().refine(value => value.trim().length > 0, 'Must not be blank');
const InvoiceDateSchema = z
  .string()
  .refine(
    value =>
      /^\d{4}-\d{2}-\d{2}$/.test(value) &&
      !Number.isNaN(Date.parse(`${value}T00:00:00Z`)) &&
      new Date(`${value}T00:00:00Z`).toISOString().slice(0, 10) === value,
    'invoiceDate must be yyyy-mm-dd',
  );
const CurrencySchema = z
  .string()
  .refine(isCanonicalCurrency, 'currency must be a canonical uppercase ISO 421

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key