vies 2.1.0
vies: ^2.1.0 copied to clipboard
VIES (VAT Information Exchange System) client for Dart. Validates European VAT numbers and retrieves the business information published by the EU service.
2.1.0 #
Added #
validateVattakes the country prefix insidevatNumber.BE1003546213,BE1003.546.213,1003546213and1003.546.213are all accepted, andcountryCodeis now optional. A prefix read fromvatNumberwins overcountryCode; with no country on either side the call throwsViesClientErrorcarryingViesErrorCode.invalidInput.VatShape.splitreturns the country prefix and the number that follows it, or null when the value carries no prefix VIES knows.
Deprecated #
countryCode, removed in 3.0.0. Put the prefix invatNumberinstead. A French key of two letters can read as a country code, socountryCode: 'FR'withvatNumber: 'BE123456789'reaches Belgium wherevatNumber: 'FRBE123456789'reaches France. Keeping the prefix and the number together removes the ambiguity.
Changed #
countryCodeis no longer required. Existing calls still compile, with a deprecation warning.
2.0.1 #
- Lowers the Dart floor to 3.0, from 3.8. The code uses no language feature above 3.0.
- No change to the API or to the behaviour.
2.0.0 #
Major rewrite. Breaking changes - see migration notes below.
Added #
VatShapeis now public:VatShape.isValidandVatShape.normalizegive an offline shape check without a network call, andVatShape.supportedCountryCodeslists the prefixesRegexType.euknows.ValidationSourceonViesValidationResponse:regexmarks a result that only passed the offline shape check,viesone a member state confirmed. A regex-only answer is no longer indistinguishable from a real validation.serviceUrl:parameter onvalidateVat, soviesTestServiceUrlcan actually be reached. It was exported but unusable.maxRetryBackoffconstant, capping the exponential backoff.ViesErrorCodeenum replacing the previous string codes; each value carries awireName(stable identifier) and a human-readablemessage.- Sealed
ViesErrorbase class, implemented byViesClientErrorandViesServerError- both nowimplements Exceptioninstead of extendingAssertionError. http.Clientinjection via the newclient:parameter - enables connection reuse and clean mocking in tests.- Optional
retries:parameter with exponential backoff for transient VIES faults (MS_UNAVAILABLE,MS_MAX_CONCURRENT_REQ,SERVICE_UNAVAILABLE,SERVER_BUSY,TIMEOUT). - Strongly-typed
Countryclass;europeanCountriesis nowList<Country>. ViesValidationResponse: value-based==/hashCode,copyWith,fromJson, and arequestDateTimehelper that parses the VIESdate+offsetformat.ViesProvider.debugParseSoapResponsefor parsing tests without HTTP.- Recognises Greek prefix
ELand Northern Ireland prefixXIin the EU regex. - XML escaping of inputs before they are placed in the SOAP body.
Fixed #
- An unreadable response body was reported as
INVALID_VAT_NUMBERinstead ofPARSING_ERROR. An HTML error page served with a 200, or an empty body, told the caller their VAT number was invalid when it was not. The completeness check now runs before thevalidflag is read. - A VAT number typed in lower case was rejected offline:
normalizestripped separators without upper-casing, while the defaultRegexType.worldpattern requires upper case. Numbers ending in a letter, such as the DutchB01, were the visible victims. RegexType.euapplied one shared{8,12}length to all 29 prefixes, which rejected registered numbers. Each member state now has its own format, so Romanian numbers (2 to 10 digits) validate.- A malformed numeric character reference in a business name raised a raw
RangeErrorthrough the documentedViesErrorcontract. Such a reference is now left in place. - The retry backoff had no ceiling, so a large
retriesproduced unbounded waits. It is capped atmaxRetryBackoff, and a negativeretriescounts as zero. - Removed the
dart:ioimport (used only forSocketException) which broke Flutter web compilation. Transport failures are now classified fromhttp.ClientExceptionand work on every platform, web included. - Catch-all that previously swallowed
ViesClientErrorfrom the parsing path and reported every failure asSERVER_DISCONNECTED. - Typo in error code
SERVER_DICONNECTED->SERVER_DISCONNECTED(now exposed only viaViesErrorCode.serverDisconnected.wireName). - Iceland country code corrected from
ICtoIS. - Regex shape errors now raise
ViesClientError(wasViesServerError).
Changed #
soapBodyTemplateandviesHeadersare no longer exported: they describe how the request is built, not what the package offers.timeoutis documented as bounding one attempt, not a whole call with retries.ViesProvideris now anabstract final classwith a private constructor- no longer instantiable.
- Internal modules split out of the provider for clarity and testability:
xml_codec.dart- XML escape/unescape and tag extraction.vat_shape.dart- offline VAT regex validation.soap_parser.dart- SOAP body ->ViesValidationResponsedecoding. The provider itself now only owns the public API, the HTTP call, and the retry loop.
- Pre-compiled all regular expressions (one-time cost per process).
- Cleaner SOAP body template using
{countryCode}/{vatNumber}markers. - HTTP headers no longer include
Host/Connection(handled by the transport) and use a sensibleContent-Type. - Robust namespace handling - parser tolerates any prefix on SOAP and VIES elements and arbitrary attributes on tags.
requestDatein regex-only mode is now a proper ISO 8601 UTC timestamp.- Empty
name/addressvalues are normalised tonull.
Removed #
html_unescapedependency - replaced by an in-package XML entity decoder.ViesProvider.classIdfield (was test-only scaffolding).- The standalone
viesErrorsmap - error messages now live onViesErrorCode.
Migration from 1.x #
- import 'package:vies/vies.dart';
- try {
- final res = await ViesProvider.validateVat(
- countryCode: 'BE',
- vatNumber: '1000341796',
- );
- } on ViesServerError catch (e) {
- if (e.errorCode == 'SERVER_DICONNECTED') { ... }
- }
+ import 'package:vies/vies.dart';
+ try {
+ final res = await ViesProvider.validateVat(
+ countryCode: 'BE',
+ vatNumber: '1000341796',
+ );
+ } on ViesServerError catch (e) {
+ if (e.code == ViesErrorCode.serverDisconnected) { ... }
+ } on ViesClientError catch (e) {
+ // Invalid VAT, parsing errors, INVALID_INPUT faults ...
+ }
1.1.0 #
- Update package to dart ">=3.0.0 <4.0.0"
- Update all dependencies to latest versions
- Improvement of the response parser
- Add regex validation
- Add more tests
1.0.2 #
- Adapt to new vies SOAP response format
1.0.1 #
- Add github public repository and issue tracker
1.0.0+1 #
- Increase exceptions management
- Add more managed exceptions (SocketTimeout, TimeoutException)
1.0.0 #
- Add accessible constant country codes list
- Add accessible constant errors list
- Code refactoring
0.0.2 #
- Fix https envelope error ("Envelope" element, is not a valid SOAP version)
0.0.1+1 #
- Update lint
0.0.1 #
- Initial prerelease.