forked from PipedreamHQ/pipedream
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Generalise the event source for both Delivery and Engagement events * Add webhook signature verification
- Loading branch information
Showing
7 changed files
with
177 additions
and
109 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
22 changes: 0 additions & 22 deletions
22
components/sendgrid/sources/delivery-events/delivery-event-types.js
This file was deleted.
Oops, something went wrong.
51 changes: 0 additions & 51 deletions
51
components/sendgrid/sources/delivery-events/delivery-events.js
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
components/sendgrid/sources/events/delivery-event-types.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module.exports = [ | ||
{ | ||
label: "Processed (Delivery Event)", | ||
value: "processed" | ||
}, | ||
{ | ||
label: "Dropped (Delivery Event)", | ||
value: "dropped" | ||
}, | ||
{ | ||
label: "Delivered (Delivery Event)", | ||
value: "delivered" | ||
}, | ||
{ | ||
label: "Deferred (Delivery Event)", | ||
value: "deferred" | ||
}, | ||
{ | ||
label: "Bounce (Delivery Event)", | ||
value: "bounce" | ||
} | ||
]; |
26 changes: 26 additions & 0 deletions
26
components/sendgrid/sources/events/engagement-event-types.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module.exports = [ | ||
{ | ||
label: "Open (Engagement Event)", | ||
value: "open" | ||
}, | ||
{ | ||
label: "Click (Engagement Event)", | ||
value: "click" | ||
}, | ||
{ | ||
label: "Spam Report (Engagement Event)", | ||
value: "spam_report" | ||
}, | ||
{ | ||
label: "Unsubscribe (Engagement Event)", | ||
value: "unsubscribe" | ||
}, | ||
{ | ||
label: "Group Unsubscribe (Engagement Event)", | ||
value: "group_unsubscribe" | ||
}, | ||
{ | ||
label: "Group Resubscribe (Engagement Event)", | ||
value: "group_resubscribe" | ||
} | ||
]; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
const common = require("../common/http-based"); | ||
|
||
module.exports = { | ||
...common, | ||
key: "sendgrid-events", | ||
name: "Events (Instant)", | ||
description: "Emit an event when any of the specified SendGrid events is received", | ||
version: "0.0.1", | ||
dedupe: "unique", | ||
props: { | ||
...common.props, | ||
eventTypes: { | ||
type: "string[]", | ||
label: "Event Types", | ||
description: "The type of events to listen to", | ||
options(context) { | ||
const { page } = context; | ||
if (page !== 0) { | ||
return { | ||
options: [], | ||
}; | ||
} | ||
|
||
const options = [ | ||
...require('./delivery-event-types'), | ||
...require('./engagement-event-types'), | ||
]; | ||
return { | ||
options, | ||
}; | ||
} | ||
}, | ||
}, | ||
methods: { | ||
...common.methods, | ||
baseWebhookSettings() { | ||
// The list of events that a webhook can listen to. This method returns an | ||
// exhaustive list of all such flags disabled, and each event source can | ||
// then override the flags that are relevant to the event they handle. | ||
// | ||
// See the docs for more information: | ||
// https://sendgrid.com/docs/api-reference/ | ||
const eventTypesData = [ | ||
...require('./delivery-event-types'), | ||
...require('./engagement-event-types'), | ||
]; | ||
return eventTypesData.reduce((accum, eventTypeData) => ({ | ||
...accum, | ||
[eventTypeData.value]: false, | ||
}), {}); | ||
}, | ||
webhookEventFlags() { | ||
return this.eventTypes.reduce((accum, eventType) => ({ | ||
...accum, | ||
[eventType]: true, | ||
}), {}); | ||
}, | ||
generateMeta(data) { | ||
const { | ||
event: eventType, | ||
sg_event_id: id, | ||
timestamp: ts, | ||
} = data; | ||
const summary = `New event: ${eventType}`; | ||
return { | ||
id, | ||
summary, | ||
ts, | ||
}; | ||
}, | ||
}, | ||
}; |