-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
43ca975
commit 1a3cf02
Showing
5 changed files
with
201 additions
and
84 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const ENTITIES = [ | ||
{ | ||
value: "api:addon-attachment", | ||
label: "addon-attachment - An add-on has been attached or removed from the app", | ||
}, | ||
{ | ||
value: "api:addon", | ||
label: "addon - An add-on for the app has been newly provisioned or deleted, or its details have been modified", | ||
}, | ||
{ | ||
value: "api:app", | ||
label: "app - The app itself has been provisioned or deleted, or its details have been modified", | ||
}, | ||
{ | ||
value: "api:build", | ||
label: "build - A new build for the app has been initiated or the build’s status has changed since the last notification", | ||
}, | ||
{ | ||
value: "api:collaborator", | ||
label: "collaborator - A collaborator has been added or removed from the app, or an existing collaborator’s details have been modified", | ||
}, | ||
{ | ||
value: "api:domain", | ||
label: "domain - Custom domain details have been added or removed from the app", | ||
}, | ||
{ | ||
value: "api:dyno", | ||
label: "dyno - A new dyno has begun running for the app", | ||
}, | ||
{ | ||
value: "api:formation", | ||
label: "formation - The dyno formation for a particular process type has been modified", | ||
}, | ||
{ | ||
value: "api:release", | ||
label: "release - A new release for the app has been initiated or the release’s status has changed since the last notification", | ||
}, | ||
{ | ||
value: "api:sni-endpoint", | ||
label: "sni-endpoint - An SNI endpoint has been specified or removed for the app, or the existing SNI endpoint’s details have been modified", | ||
}, | ||
]; | ||
|
||
export default { | ||
ENTITIES, | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "@pipedream/heroku", | ||
"version": "0.0.1", | ||
"description": "Pipedream Heroku Components", | ||
"main": "heroku.app.mjs", | ||
"keywords": [ | ||
"pipedream", | ||
"heroku" | ||
], | ||
"homepage": "https://pipedream.com/apps/heroku", | ||
"author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@pipedream/platform": "^3.0.3" | ||
} | ||
} |
80 changes: 42 additions & 38 deletions
80
components/heroku/sources/new-webhook-event-instant/new-webhook-event-instant.mjs
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 |
---|---|---|
@@ -1,70 +1,74 @@ | ||
import heroku from "../../heroku.app.mjs"; | ||
import sampleEmit from "./test-event.mjs"; | ||
|
||
export default { | ||
key: "heroku-new-webhook-event-instant", | ||
name: "New Webhook Event Instant", | ||
description: "Emit new event on each webhook event. [See the documentation](https://devcenter.heroku.com/categories/platform-api)", | ||
version: "0.0.{{ts}}", | ||
name: "New Webhook Event (Instant)", | ||
description: "Emit new event on each webhook event. [See the documentation](https://devcenter.heroku.com/articles/app-webhooks-schema#webhook-create)", | ||
version: "0.0.1", | ||
type: "source", | ||
dedupe: "unique", | ||
props: { | ||
heroku, | ||
http: { | ||
type: "$.interface.http", | ||
customResponse: false, | ||
}, | ||
http: "$.interface.http", | ||
db: "$.service.db", | ||
appId: { | ||
propDefinition: [ | ||
heroku, | ||
"appId", | ||
], | ||
}, | ||
entity: { | ||
propDefinition: [ | ||
heroku, | ||
"entity", | ||
], | ||
}, | ||
eventTypes: { | ||
entities: { | ||
propDefinition: [ | ||
heroku, | ||
"eventTypes", | ||
"entities", | ||
], | ||
}, | ||
}, | ||
hooks: { | ||
async activate() { | ||
const webhookId = await this.heroku.createWebhookSubscription( | ||
this.appId, | ||
this.entity, | ||
this.eventTypes, | ||
); | ||
this.db.set("webhookId", webhookId); | ||
const { id } = await this.heroku.createWebhookSubscription({ | ||
appId: this.appId, | ||
data: { | ||
include: this.entities, | ||
level: "notify", | ||
url: this.http.endpoint, | ||
}, | ||
}); | ||
this._setHookId(id); | ||
}, | ||
async deactivate() { | ||
const webhookId = this.db.get("webhookId"); | ||
if (webhookId) { | ||
await this.heroku.deleteWebhookSubscription(webhookId); | ||
const hookId = this._getHookId(); | ||
if (hookId) { | ||
await this.heroku.deleteWebhookSubscription({ | ||
appId: this.appId, | ||
hookId, | ||
}); | ||
} | ||
}, | ||
}, | ||
methods: { | ||
_getHookId() { | ||
return this.db.get("hookId"); | ||
}, | ||
_setHookId(hookId) { | ||
this.db.set("hookId", hookId); | ||
}, | ||
generateMeta(event) { | ||
return { | ||
id: event.id, | ||
summary: `New ${event.webhook_metadata.event.include} - ${event.action} Event`, | ||
ts: Date.now(), | ||
}; | ||
}, | ||
}, | ||
async run(event) { | ||
const { | ||
body, headers, | ||
} = event; | ||
|
||
// Validate the incoming webhook payload | ||
if (headers["heroku-webhook-hmac-sha256"] !== this.heroku.$auth.webhook_secret) { | ||
console.log("Invalid signature"); | ||
const { body } = event; | ||
if (!body) { | ||
return; | ||
} | ||
|
||
// Emit the event | ||
this.$emit(body, { | ||
id: body.id, | ||
summary: `New event: ${body.event_type}`, | ||
ts: Date.parse(body.created_at), | ||
}); | ||
const meta = this.generateMeta(body); | ||
this.$emit(body, meta); | ||
}, | ||
sampleEmit, | ||
}; |
69 changes: 69 additions & 0 deletions
69
components/heroku/sources/new-webhook-event-instant/test-event.mjs
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,69 @@ | ||
export default { | ||
"id": "a5b27512-1f14-4f45-bc26-fe6bf03686fe", | ||
"data": { | ||
"id": "9a4eaeed-24cc-4b23-a8ca-7867b251eaf3", | ||
"acm": false, | ||
"name": "", | ||
"team": null, | ||
"owner": { | ||
"id": "7b25912d-b147-48d6-b03d-f0fc72be381b", | ||
"email": "" | ||
}, | ||
"space": null, | ||
"stack": { | ||
"id": "74cfe988-7527-4ca9-9667-77bb9f3029cf", | ||
"name": "heroku-24" | ||
}, | ||
"region": { | ||
"id": "59accabd-516d-4f0e-83e6-6e3757701145", | ||
"name": "us" | ||
}, | ||
"git_url": "", | ||
"web_url": "", | ||
"repo_size": null, | ||
"slug_size": null, | ||
"created_at": "2024-11-07T16:38:38Z", | ||
"updated_at": "2024-11-07T17:14:52Z", | ||
"archived_at": null, | ||
"build_stack": { | ||
"id": "74cfe988-7527-4ca9-9667-77bb9f3029cf", | ||
"name": "heroku-24" | ||
}, | ||
"maintenance": false, | ||
"released_at": "2024-11-07T16:38:39Z", | ||
"organization": null, | ||
"internal_routing": null, | ||
"buildpack_provided_description": null | ||
}, | ||
"actor": { | ||
"id": "7b25912d-b147-48d6-b03d-f0fc72be381b", | ||
"email": "" | ||
}, | ||
"action": "update", | ||
"version": "application/vnd.heroku+json; version=3", | ||
"resource": "app", | ||
"sequence": null, | ||
"created_at": "2024-11-07T17:14:52.475272Z", | ||
"updated_at": "2024-11-07T17:14:52.475276Z", | ||
"published_at": "2024-11-07T17:14:52Z", | ||
"previous_data": { | ||
"name": "", | ||
"git_url": "", | ||
"updated_at": "2024-11-07T17:13:42Z" | ||
}, | ||
"webhook_metadata": { | ||
"attempt": { | ||
"id": "16e90948-01d8-4ba0-97de-5868a4aed0bf" | ||
}, | ||
"delivery": { | ||
"id": "bbf72057-15f2-40b0-87c7-99ccf95e1666" | ||
}, | ||
"event": { | ||
"id": "a5b27512-1f14-4f45-bc26-fe6bf03686fe", | ||
"include": "api:app" | ||
}, | ||
"webhook": { | ||
"id": "c385bb39-42ab-49c6-9255-108ff4cabdbd" | ||
} | ||
} | ||
} |