TypeScript Package

@ocuula/validators

Zod schemas and inferred TypeScript types shared across the Orchestrator stack — backend, frontend, and consumer apps. The single source of truth for every API boundary.

Installation

pnpm
pnpm add @ocuula/validators

Quick Start

Import any schema directly from the package. Each schema doubles as a runtime validator and a TypeScript type via z.infer.

TypeScript
import { TriggerSplitSchema, FeePreviewRequestSchema } from "@ocuula/validators"

const result = TriggerSplitSchema.safeParse({
  routingRuleId: "rule_abc",
  amountInPesewas: 10000,
})

if (!result.success) {
  console.error(result.error.issues)
}

Split Rule Schemas

Every split type has a dedicated Zod schema with built-in validation — percentage sums must equal 100, flat split totals cannot exceed the sentinel, and tier thresholds must be strictly ascending.

SchemaruleTypeDescription
PercentageRuleSchemaPERCENTAGE_SPLITPercentage-based splits that must sum to 100%
FlatRuleSchemaFIXED_FLAT_SPLITFixed pesewa amounts with remainder routing
WaterfallRuleSchemaMILESTONE_WATERFALLMilestone-gated percentage waterfall
DirectDebitMandateSchemaDIRECT_DEBITRecurring pull-based billing with cron schedule
TieredSplitSchemaTIERED_SPLITVolume-sensitive tiered percentage allocations

The RuleConfigurationSchema discriminated union unions all five rule types by ruleType. Use CreateRuleSchema when creating rules programmatically — it validates the full payload including merchantId and name.

Fee & Pricing Schemas

Fee calculation is driven from the validator package so frontend and backend always agree on rates.

ExportDescription
FeeModeSchemaFROM_RECEIVED or GROSS_UP_TO_NET
FeePreviewRequestSchemaValidate feee preview request payload (amount, mode, volume, split count)
FeeBreakdownSchemaMoolre collection, network, orchestration, transfer fees + remainder
lookupRateBpsByVolumePure function — returns the basis-point rate for a given 30-day volume

Provisioning & Sandbox

Merchant provisioning and sandbox top-ups are validated through shared schemas.

SchemaPurpose
ProvisionMerchantSchemaValidate merchant signup — name, provision mode, Moolre credentials, plan, environment
SandboxTopupSchemaValidate sandbox wallet top-up amounts (max GHS 100,000 per operation)

Moolre API Response Schemas

These schemas are used internally at the network boundary to parse Moolre API responses instead of trusting raw any from fetch(). They are also available for consumer apps that need to handle Moolre responses directly.

SchemaDescription
MoolreEnvelopeSchemaStandard Moolre response envelope (status, code, message, data)
MoolreTransferResponseSchemaValidate payout transfer responses (txstatus, receiver, transactionid, fees)
MoolrePaymentResponseSchemaValidate STK push / USSD collection responses
MoolreTransactionStatusSchemaValidate transfer/payment status check responses
MoolreWebhookPayloadSchemaValidate inbound Moolre payment webhook payloads including custom_metadata

Utility: treeifyError

Zod's default error format is a flat list of issues that can be hard to read for nested payloads. treeifyError re-formats errors into a nested tree structure keyed by field path — useful for showing inline validation errors in forms or API responses.

TypeScript
import { treeifyError } from "@ocuula/validators"

const result = TriggerSplitSchema.safeParse({ amountInPesewas: -100 })
if (!result.success) {
  console.log(treeifyError(result.error))
  // {
  //   amountInPesewas: ["Number must be positive"],
  //   routingRuleId: ["Required"]
  // }
}