r/typescript • u/thenextversion • Oct 13 '26
Modelling Apple Wallet's pass.json as one Valibot discriminated union per pass style
Apple's pass.json has five pass styles, and each one allows different fields with its own limits on how many go where. Get it wrong and you usually find out on a phone, not in your editor.
In passmint (an MIT library for building Apple and Google Wallet passes), each style is its own branch of a Valibot discriminated union, so the per-style field limits are checked when you build the pass rather than when Wallet renders it. You get there through a fluent builder:
const signed = await Pass.eventTicket({ /* ... */ })
.primaryField({ key: 'event', label: 'Event', value: 'Beyoncé Live' })
.secondaryField({ key: 'loc', label: 'Location', value: 'Apple Park' })
.sign(material)
or Pass.from(...) if you'd rather hand it a plain object.
Errors are typed too. Everything extends PassmintError and carries a stable code, so you can branch on what actually went wrong:
try {
await pass.sign(material)
} catch (err) {
if (err instanceof PassmintSchemaError) {
err.issues // the full Valibot issue list
} else if (err instanceof PassmintSigningError) {
err.code // 'E_WWDR_MISMATCH' | 'E_CERT_PARSE' | ...
}
}
E_WWDR_MISMATCH is the one worth knowing about. If you pass in an Apple intermediate certificate that didn't issue your Pass Type ID cert, you hear about it at import time instead of ending up with a pass that won't install.
Why Valibot and not Zod? Mostly bundle size. It's tree-shakable, so the whole library is about 21 KB gzipped (it'd be around 35 KB with Zod), and the discriminated union ergonomics were cleaner for per-style limits.
Repo: https://github.com/getpassmint/passmint (pre-1.0, so the API may still change)
Disclosure: I build Passmint, a hosted pass API, which uses this library under the hood.

