import type { PricingPackage } from '../content/types.ts'; const SLUG = /^[a-z0-9-]+$/; // Whether a package meets the invariants in domain-entities.md export function isValidPackage(pkg: PricingPackage): boolean { return ( SLUG.test(pkg.id) && pkg.name.trim() !== '' && Number.isInteger(pkg.price) && pkg.price > 0 && pkg.features.length > 0 && pkg.features.every((feature) => feature.trim() !== '') ); } // The packages that can be shown: invalid ones from the CMS are skipped // rather than breaking the page, and of two packages with the same id the // first wins. The order stays the same (BR-PRICE-02). export function visiblePackages( packages: readonly PricingPackage[], ): PricingPackage[] { const seen = new Set(); return packages.filter((pkg) => { if (!isValidPackage(pkg) || seen.has(pkg.id)) return false; seen.add(pkg.id); return true; }); }