feat(models): implement WebhookEvent model - #52
Conversation
Adds src/shade/models/webhook.py with a WebhookEvent ShadeObject carrying id, type, data, created_at (aliased from createdAt) and livemode, plus a WebhookEventType str enum for the platform's event type strings. data is deliberately kept as the raw decoded JSON object; coercion into a typed resource model belongs to the webhooks resource layer (#66/#69), which does not exist yet. Exports both from shade.models and the package root.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughAdds ChangesWebhook event support
Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/shade/models/webhook.py`:
- Around line 86-88: Update the webhook model’s data and livemode fields to use
dict[str, Any] and StrictBool respectively, preserving the existing created_at
alias. Ensure malformed payloads are rejected with InvalidRequestError, and
revise or remove tests that expect non-dict data or string livemode values such
as "false" to be accepted or coerced.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 244eb1c8-6ab4-4e8c-a7de-e0eb61a4cb24
📒 Files selected for processing (4)
src/shade/__init__.pysrc/shade/models/__init__.pysrc/shade/models/webhook.pytests/test_webhook_event.py
|
Hello @Depo-dev |
# Conflicts: # src/shade/__init__.py # src/shade/models/__init__.py
data now requires dict[str, Any] and livemode requires StrictBool so malformed payloads raise InvalidRequestError instead of silently coercing (e.g. a JSON-encoded "false" string, or an array/scalar data payload).
codebestia
left a comment
There was a problem hiding this comment.
LGTM!
Thank you for your contribution.
Description
Adds the
WebhookEventmodel — a parsed, verified webhook event delivered by the Shade platform — plus aWebhookEventTypeconstants enum.src/shade/models/webhook.py:WebhookEvent(ShadeObject)withid: str,type: str,data: Any,created_at: datetime(aliased fromcreatedAt),livemode: bool. Follows the convention established byTransfer: pydantic field aliases for camelCase→snake_case,extra="allow"so a server-side field addition never breaks an older SDK, andInvalidRequestError(not a rawValidationError) on a malformed payload.WebhookEventType(str, Enum)with the 11 event types listed in issue #68. Members compare equal to their wire values, soevent.type == WebhookEventType.PAYMENT_COMPLETEDworks directly in conditionals.WebhookEvent.typestays a plainstr, so an event type added server-side still parses.Both are exported from
shade.modelsand the package root.Fixes #42
Scope notes
datais left as the raw decoded JSON object at this layer, per the issue's acceptance criteria. Coercion into a typed resource model is the resource layer's job (#66 / #69).Webhook.construct_event()does not exist yet —src/shade/resources/has not been created (issue #66). There is nothing to wire up in this PR; the model docstring documents the contract the resource layer is expected to honour.Type of change
How Has This Been Tested?
tests/test_webhook_event.py— 23 tests covering:createdAtparses to an awaredatetimedatastays a raw dict (and passes non-dict payloads through unchanged)id,type,data,createdAt,livemode) raisesInvalidRequestErrorInvalidRequestErrorcreatedAtraises, with the offending field named infield_errorslivemodetrue / false / JSON-string coercionto_dict()round-trips by alias;reprshows the event idWebhookEventTypeconstants equal their wire strings and work in conditionalsResults:
The
mypyrun reports 24 pre-existing errors inhttp.py,gateway.pyand__init__.py; none are in the files this PR adds.black24+ would want a blank line after the module docstring, but the repo pinsblack ^23.7and every existing module omits it, so the new file matchestransfer.py/base.py.Checklist:
from_dictbehaviour and the raw-datatyping contract)Summary by CodeRabbit