Skip to content

feat: validation policy, route classifier and typed validation errors - #1

Merged
very-code-com merged 1 commit into
masterfrom
feat/validation-flexibility-1.2.0
Jul 17, 2026
Merged

feat: validation policy, route classifier and typed validation errors#1
very-code-com merged 1 commit into
masterfrom
feat/validation-flexibility-1.2.0

Conversation

@very-code-com

@very-code-com very-code-com commented Jul 17, 2026

Copy link
Copy Markdown
Owner

Development branch for the validation and routing work that ships in the 1.0.0 release.

  • SuusClient::validate() for pre-flight checks with no network call.
  • Typed ValidationError / ValidationCode, reusing the SUUS codes where one exists.
  • ValidationPolicy to toggle the route-shaped rules, strict by default.
  • RouteClassifierInterface to redefine which routes count as international, driving both validation and the generated XML.
  • Domestic and international document-return services.

See the repository history and CHANGELOG.md for the released state.

…& document-return services

Makes the international business-rule handling flexible instead of hard-coded,
per integrator feedback (v1.1.0 -> v1.2.0). Default behaviour stays strict.

New public API (VeryCodeCom\Suus\Validation, \Routing):
- SuusClient::validate(ShipmentOrder): ValidationError[] - pre-flight validation
  with no network call; auto-selects the sender-country calendar (mirrors
  createShipment). Lets integrators surface validation without touching @internal.
- ValidationError (message/field/code, Stringable) + ValidationCode - typed errors
  reusing the exact SUUS codes where one exists (PRJ00351/00352/00372/00373/...).
- ValidationPolicy (strict()/relaxed() + per-rule flags enforceInternationalB2B,
  enforceServiceRouteRestrictions, enforceInternationalPackagingRestrictions),
  injectable via `new SuusClient($config, policy: ...)`.
- RouteClassifierInterface + DefaultRouteClassifier + CallableRouteClassifier,
  injectable via `routeClassifier:`. Overrides the domestic/international decision
  the library uses for BOTH validation and the generated XML.

Newly enforced locally (previously only rejected server-side by SUUS), all
policy-toggleable and confirmed against the SUUS WebApi docs (WS PK 1.0):
- international orders reject domestic-only services (StdAwizacjaSms, StdWniesienie2,
  StdDokumentyZwrotneINiezwrotneGrid2) and returnable/stackable packaging
  (PRJ00372/PRJ00373);
- domestic orders reject the international-only document-return service
  (StdDokumentyZwrotneINiezwrotneGrid3).

New typed services:
- DocumentReturnDomesticService (StdDokumentyZwrotneINiezwrotneGrid2, domestic only)
- DocumentReturnInternationalService (StdDokumentyZwrotneINiezwrotneGrid3, intl only)
  sharing AbstractDocumentReturnService with TAG_*/DOC_* constants.

Internal changes:
- ShipmentValidator::validate() now returns ValidationError[] and accepts optional
  ValidationPolicy/RouteClassifier; SoapEnvelopeBuilder takes a RouteClassifier.
- SuusValidationException::$errors is now ValidationError[] (Stringable); bare
  strings are wrapped, so getErrors(): string[] and existing usage keep working.
  Adds getValidationErrors(): ValidationError[].

Route-classifier caveat (verified live on the sandbox): the classifier is a
client-side override only. SUUS classifies each shipment on its own side from the
address country codes, so a non-PL route (e.g. DE->DE) forced to "domestic" is still
rejected (BTN0002, missing incoterms) unless the contract/product supports it. The
README/example/docblocks document this explicitly.

Docs/examples: README (Additional Services + new Pre-flight Validation, Policies &
Route Classification section), CHANGELOG (1.2.0), examples 05 (document-return
service) and new 08 (validate/policy/classifier).

Tests: 326 -> 355 unit tests (540 assertions); existing validator tests adapted to
typed errors; new ValidationPolicyAndRoutingTest covers policy/classifier/new
services in both route directions. PHPStan level 8 clean. Existing sandbox
integration tests still pass end-to-end.
@very-code-com
very-code-com merged commit 29179b6 into master Jul 17, 2026
4 checks passed
@very-code-com
very-code-com deleted the feat/validation-flexibility-1.2.0 branch July 17, 2026 08:16
@very-code-com very-code-com changed the title feat: configurable validation policy, route classifier & typed validation errors (v1.2.0) feat: validation policy, route classifier and typed validation errors Aug 14, 2026
Repository owner locked as resolved and limited conversation to collaborators Aug 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant