Add SendGrid webhook event models and signature verification#29
Add SendGrid webhook event models and signature verification#29thoven87 wants to merge 16 commits into
Conversation
Introduces comprehensive models for SendGrid webhook event types, including delivery, engagement, and account status change events. Adds ECDSA signature verification for webhook security, updates Package.swift to include swift-crypto, and provides extensive documentation and tests for event parsing and verification.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #29 +/- ##
===========================================
- Coverage 86.86% 57.63% -29.23%
===========================================
Files 12 16 +4
Lines 274 786 +512
===========================================
+ Hits 238 453 +215
- Misses 36 333 +297
🚀 New features to boost your workflow:
|
|
So this basically only adds structs that a Vapor/Hummingbird server should decode and methods to verify their signature, right? |
I just noticed that I am missing the received case. I will fix this shortly along with the CRUD operations https://www.twilio.com/docs/sendgrid/api-reference/webhooks/create-an-event-webhook |
Introduces methods for managing SendGrid Event Webhooks (create, test, retrieve, update, delete, signature verification, public key retrieval) and Parse Webhook settings/statistics in SendGridClient. Also updates SendGridError to include url and id fields for improved error context, and fixes the base API URL to support new endpoints.
Introduces SendGridReceivedEvent to handle inbound email 'received' events, updates SendGridWebhookEvent and related enums for the new event type, and adds models for event webhook input, settings, signature verification, and parse webhook statistics. Also adds sgContentType to engagement events and improves documentation for uniqueArgs.
Added unit tests to verify decoding of SendGrid 'received' webhook events, including support for both Unix and ISO 8601 timestamps, additional fields, and v3_payload_details. Also updated existing test data to use generic test values for consistency.
Updated several public method signatures in SendGridClient to use multiline formatting for parameters, improving readability and consistency. Also adjusted body encoding and decoding calls to multiline style.
Changed the expected sgEventId value in the delivered event decoding test to 'test_delivered_event_id' for consistency or improved test clarity.
@fpseverino all the failing tests are related to the email validation API |
fpseverino
left a comment
There was a problem hiding this comment.
A very well designed API, great work!
You tested it with real SendGrid API keys, right?
There was a problem hiding this comment.
We need to split this file into smaller ones, you should create a subfolder (inside the "Models" one) called "Webhooks" or something like that
There was a problem hiding this comment.
We need to split this file into smaller ones, you should create a subfolder (inside the "Models" one) called "Webhooks" or something like that
I don't know how much smaller you want. I split the file into two categories, Input and Response
Yes! |
Co-authored-by: Francesco Paolo Severino <96546612+fpseverino@users.noreply.github.com>
Co-authored-by: Francesco Paolo Severino <96546612+fpseverino@users.noreply.github.com>
Co-authored-by: Francesco Paolo Severino <96546612+fpseverino@users.noreply.github.com>
Co-authored-by: Francesco Paolo Severino <96546612+fpseverino@users.noreply.github.com>
Co-authored-by: Francesco Paolo Severino <96546612+fpseverino@users.noreply.github.com>
Moved all Event Webhook-related API methods from SendGridClient to a new SendGridWebhookClient for better separation of concerns. Added public initializers to model structs for easier instantiation. Updated tests to use the new SendGridWebhookClient.
Standardizes property names in SendGrid event models by renaming fields such as asmGroupId to asmGroupID, sgEventId to sgEventID, and similar fields to consistently use 'ID' suffix capitalization. Updates all related CodingKeys, initializers, encoders/decoders, and test cases to match the new naming convention for improved clarity and Swift API guidelines compliance.
Extracted EventWebhookInput and SendGridTestWebhookInput structs from WebhookEvent.swift into a new file WebhookEvent+Input.swift for better code organization and separation of concerns.
Introduces detailed .docc documentation for SendGridKit webhook types, including EventWebhookInput, SendGridTestWebhookInput, SendGridWebhookClient, SendGridWebhookEvent, and signature verification. Updates the main documentation index to reference new webhook types and corrects a minor typo in SendGridWebhookClient's initializer comment. Also updates the README to use Vapor for webhook examples and clarifies body handling.
Introduces comprehensive models for SendGrid webhook event types, including delivery, engagement, and account status change events. Adds ECDSA signature verification for webhook security, updates Package.swift to include swift-crypto, and provides extensive documentation and tests for event parsing and verification.
Closes #28