Skip to article
Documentation

src/features/policy/schema.ts

Linked repository file from this build.

import { z } from "zod";
const money = z
  .number()
  .finite()
  .min(0)
  .max(1_000_000)
  .refine((n) => Math.abs(n * 100 - Math.round(n * 100)) < 1e-7, "Use at most two decimals.");
const percent = z.number().min(0).max(100);
export const policySchema = z
  .object({
    id: z.string().min(1).max(120),
    effectiveFrom: z.string().regex(/^\d{4}-(0[1-9]|1[0-2])$/),
    source: z.string().trim().min(1).max(2000),
    verification: z.string().trim().min(1).max(2000),
    grossLimits: z.array(money).length(20),
    netLimits: z.array(money).length(20),
    standardDeductions: z.array(money).length(20),
    allotments: z.array(money).length(20),
    sua: z
      .object({ heating: money, non_heating: money, limited: money, telephone: money, none: money })
      .strict(),
    shelterCap: money,
    shelterDeductionPercent: percent,
    minimumBenefit: money,
    homelessDeduction: money,
    earnedDeductionPercent: percent,
    farmExpenseAllowancePercent: percent,
    nonFarmExpenseAllowancePercent: percent,
    errorThreshold: money,
    memoResponseDays: z.number().int().min(1).max(365).nullable(),
  })
  .strict();