alepha@docs:~/framework/docs/reference/providers$
cat AddressRulesProvider.md | pretty1 min read
Last commit:
#AddressRulesProvider
#Import
typescript
1import { AddressRulesProvider } from "@alepha/commerce/checkout";
#Overview
Per-country address rules for the EU.
#Why this is a provider and not a constant
The day the shop sells to Switzerland or the UK, the list needs one more entry - and editing a framework package to add a country you sell to is absurd. Substituting the provider is the supported answer:
ts
1class MyRules extends AddressRulesProvider {2 override rules() {3 return {4 ...super.rules(),5 CH: { name: "Suisse", postalCode: /^\d{4}$/, example: "8001" },6 };7 }8}9alepha.with({ provide: AddressRulesProvider, use: MyRules });
The patterns are deliberately shape-only. Validating that a postcode exists requires a carrier's address database, which is a paid API and a different concern; what this catches is the typo and the wrong-country paste, which is most of what goes wrong.