Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions components/heroku/common/constants.mjs
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,
};
68 changes: 64 additions & 4 deletions components/heroku/heroku.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,71 @@
import { axios } from "@pipedream/platform";
import constants from "./common/constants.mjs";

export default {
type: "app",
app: "heroku",
propDefinitions: {},
propDefinitions: {
appId: {
type: "string",
label: "App ID",
description: "The ID of the app",
async options() {
const apps = await this.listApps();
return apps?.map((app) => ({
label: app.name,
value: app.id,
})) || [];
},
},
entities: {
type: "string[]",
label: "Entities",
description: "The entity or entities to subscribe to",
options: constants.ENTITIES,
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.heroku.com";
},
_makeRequest(opts = {}) {
const {
$ = this,
path,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: `${this._baseUrl()}${path}`,
headers: {
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
Accept: "application/vnd.heroku+json; version=3",
},
});
},
listApps(opts = {}) {
return this._makeRequest({
path: "/apps",
...opts,
});
},
createWebhookSubscription({
appId, ...opts
}) {
return this._makeRequest({
method: "POST",
path: `/apps/${appId}/webhooks`,
...opts,
});
},
deleteWebhookSubscription({
appId, hookId, ...opts
}) {
return this._makeRequest({
method: "DELETE",
path: `/apps/${appId}/webhooks/${hookId}`,
...opts,
});
},
},
};
18 changes: 18 additions & 0 deletions components/heroku/package.json
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 <support@pipedream.com> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +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/articles/app-webhooks-schema#webhook-create)",
version: "0.0.1",
type: "source",
dedupe: "unique",
props: {
heroku,
http: "$.interface.http",
db: "$.service.db",
appId: {
propDefinition: [
heroku,
"appId",
],
},
entities: {
propDefinition: [
heroku,
"entities",
],
},
},
hooks: {
async activate() {
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 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 } = event;
if (!body) {
return;
}
const meta = this.generateMeta(body);
this.$emit(body, meta);
},
sampleEmit,
};
69 changes: 69 additions & 0 deletions components/heroku/sources/new-webhook-event-instant/test-event.mjs
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"
}
}
}
Loading
Loading