Shows the three live packages as cards with their price and what is included. Each card links to the contact section with ?pakket=<id>, so the contact form can preselect it. Invalid packages from the CMS are skipped and the pakket value is only accepted when it names a package. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
30 lines
963 B
TypeScript
30 lines
963 B
TypeScript
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<string>();
|
|
return packages.filter((pkg) => {
|
|
if (!isValidPackage(pkg) || seen.has(pkg.id)) return false;
|
|
seen.add(pkg.id);
|
|
return true;
|
|
});
|
|
}
|