Repository navigation
Type webhook action/resource as enums + encode the relationship - #9
Merged
Merged
Conversation
Makes the webhook action and resource strict enums that fail fast on an unexpected value, and adds the resource -> actions relationship. - WebhookResourceName::actions(): list<WebhookAction> and supports(WebhookAction): bool encode which actions Shipmondo allows for each resource. - WebhooksEndpoint::create() rejects an unsupported resource/action pair (when both are set) before sending, instead of a server 422. - The response Webhook and the inbound WebhookEvent now type action / resourceName (resourceType) as WebhookAction / WebhookResourceName. An unknown value fails fast: a MappingException on the read path and a MalformedWebhookException in the parser (the raw strings remain reachable via Resource::$raw on the response). This reverses the earlier lenient-strings choice.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 2.x #9 +/- ##
============================================
+ Coverage 97.89% 98.07% +0.17%
- Complexity 179 186 +7
============================================
Files 32 33 +1
Lines 476 520 +44
============================================
+ Hits 466 510 +44
Misses 10 10 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two related changes around the webhook enums, both in the fail-fast direction.
1. Encode the resource ↔ action relationship
Shipmondo only allows certain actions per resource. That mapping is now on the enum:
And
WebhooksEndpoint::create()rejects an invalid pair before sending (only when bothresourceNameandactionare set — null fields stay server-authoritative):2. Strict enums on the read paths (fail-fast)
action/resourceTypewere lenient strings. They're now theWebhookAction/WebhookResourceNameenums on both webhook DTOs, and an unexpected value blows up rather than slipping through:WebhookEvent::$action/$resourceTypeare enums;WebhookParserresolves theSMD-Action/SMD-Resource-Typeheaders viatryFrom()and throwsMalformedWebhookException(aShipmondoException) if a header is missing or unknown.Webhook::$action/$resourceNameare enums; an unknown value now fails mapping with aMappingException. The original strings remain reachable viaResource::$raw.This reverses the earlier deliberate "lenient reads" choice — at the maintainer's request (preference for things to blow up when something is unexpected). Since 2.x is still in alpha, there's no stable BC to worry about.
webhooks()->getPage()/paginate()will now throw if any single webhook subscription carries an action/resource the SDK doesn't model yet (the agreed trade-off for consistency with the inbound path).Tests
WebhookResourceNameTest:actions()per resource,supports()truth table, and an invariant that everyWebhookActionis mapped to at least one resource (guards against forgetting to map a new action).WebhooksEndpointTest: invalid resource/action combo throws before sending.WebhookParserTest: unknown action, missing action, and unknown resource each throwMalformedWebhookException; happy-path assertions updated to enums.Verification