Skip to content

Commit 9241d4c

Browse files
authored
New Components - heroku (#14601)
* init * new component * pnpm-lock.yaml
1 parent f4c7812 commit 9241d4c

File tree

6 files changed

+277
-4
lines changed

6 files changed

+277
-4
lines changed
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const ENTITIES = [
2+
{
3+
value: "api:addon-attachment",
4+
label: "addon-attachment - An add-on has been attached or removed from the app",
5+
},
6+
{
7+
value: "api:addon",
8+
label: "addon - An add-on for the app has been newly provisioned or deleted, or its details have been modified",
9+
},
10+
{
11+
value: "api:app",
12+
label: "app - The app itself has been provisioned or deleted, or its details have been modified",
13+
},
14+
{
15+
value: "api:build",
16+
label: "build - A new build for the app has been initiated or the build’s status has changed since the last notification",
17+
},
18+
{
19+
value: "api:collaborator",
20+
label: "collaborator - A collaborator has been added or removed from the app, or an existing collaborator’s details have been modified",
21+
},
22+
{
23+
value: "api:domain",
24+
label: "domain - Custom domain details have been added or removed from the app",
25+
},
26+
{
27+
value: "api:dyno",
28+
label: "dyno - A new dyno has begun running for the app",
29+
},
30+
{
31+
value: "api:formation",
32+
label: "formation - The dyno formation for a particular process type has been modified",
33+
},
34+
{
35+
value: "api:release",
36+
label: "release - A new release for the app has been initiated or the release’s status has changed since the last notification",
37+
},
38+
{
39+
value: "api:sni-endpoint",
40+
label: "sni-endpoint - An SNI endpoint has been specified or removed for the app, or the existing SNI endpoint’s details have been modified",
41+
},
42+
];
43+
44+
export default {
45+
ENTITIES,
46+
};

components/heroku/heroku.app.mjs

+64-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,71 @@
1+
import { axios } from "@pipedream/platform";
2+
import constants from "./common/constants.mjs";
3+
14
export default {
25
type: "app",
36
app: "heroku",
4-
propDefinitions: {},
7+
propDefinitions: {
8+
appId: {
9+
type: "string",
10+
label: "App ID",
11+
description: "The ID of the app",
12+
async options() {
13+
const apps = await this.listApps();
14+
return apps?.map((app) => ({
15+
label: app.name,
16+
value: app.id,
17+
})) || [];
18+
},
19+
},
20+
entities: {
21+
type: "string[]",
22+
label: "Entities",
23+
description: "The entity or entities to subscribe to",
24+
options: constants.ENTITIES,
25+
},
26+
},
527
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
28+
_baseUrl() {
29+
return "https://api.heroku.com";
30+
},
31+
_makeRequest(opts = {}) {
32+
const {
33+
$ = this,
34+
path,
35+
...otherOpts
36+
} = opts;
37+
return axios($, {
38+
...otherOpts,
39+
url: `${this._baseUrl()}${path}`,
40+
headers: {
41+
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
42+
Accept: "application/vnd.heroku+json; version=3",
43+
},
44+
});
45+
},
46+
listApps(opts = {}) {
47+
return this._makeRequest({
48+
path: "/apps",
49+
...opts,
50+
});
51+
},
52+
createWebhookSubscription({
53+
appId, ...opts
54+
}) {
55+
return this._makeRequest({
56+
method: "POST",
57+
path: `/apps/${appId}/webhooks`,
58+
...opts,
59+
});
60+
},
61+
deleteWebhookSubscription({
62+
appId, hookId, ...opts
63+
}) {
64+
return this._makeRequest({
65+
method: "DELETE",
66+
path: `/apps/${appId}/webhooks/${hookId}`,
67+
...opts,
68+
});
969
},
1070
},
1171
};

components/heroku/package.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "@pipedream/heroku",
3+
"version": "0.0.1",
4+
"description": "Pipedream Heroku Components",
5+
"main": "heroku.app.mjs",
6+
"keywords": [
7+
"pipedream",
8+
"heroku"
9+
],
10+
"homepage": "https://pipedream.com/apps/heroku",
11+
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
12+
"publishConfig": {
13+
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import heroku from "../../heroku.app.mjs";
2+
import sampleEmit from "./test-event.mjs";
3+
4+
export default {
5+
key: "heroku-new-webhook-event-instant",
6+
name: "New Webhook Event (Instant)",
7+
description: "Emit new event on each webhook event. [See the documentation](https://devcenter.heroku.com/articles/app-webhooks-schema#webhook-create)",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
heroku,
13+
http: "$.interface.http",
14+
db: "$.service.db",
15+
appId: {
16+
propDefinition: [
17+
heroku,
18+
"appId",
19+
],
20+
},
21+
entities: {
22+
propDefinition: [
23+
heroku,
24+
"entities",
25+
],
26+
},
27+
},
28+
hooks: {
29+
async activate() {
30+
const { id } = await this.heroku.createWebhookSubscription({
31+
appId: this.appId,
32+
data: {
33+
include: this.entities,
34+
level: "notify",
35+
url: this.http.endpoint,
36+
},
37+
});
38+
this._setHookId(id);
39+
},
40+
async deactivate() {
41+
const hookId = this._getHookId();
42+
if (hookId) {
43+
await this.heroku.deleteWebhookSubscription({
44+
appId: this.appId,
45+
hookId,
46+
});
47+
}
48+
},
49+
},
50+
methods: {
51+
_getHookId() {
52+
return this.db.get("hookId");
53+
},
54+
_setHookId(hookId) {
55+
this.db.set("hookId", hookId);
56+
},
57+
generateMeta(event) {
58+
return {
59+
id: event.id,
60+
summary: `New ${event.webhook_metadata.event.include} - ${event.action} Event`,
61+
ts: Date.now(),
62+
};
63+
},
64+
},
65+
async run(event) {
66+
const { body } = event;
67+
if (!body) {
68+
return;
69+
}
70+
const meta = this.generateMeta(body);
71+
this.$emit(body, meta);
72+
},
73+
sampleEmit,
74+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
export default {
2+
"id": "a5b27512-1f14-4f45-bc26-fe6bf03686fe",
3+
"data": {
4+
"id": "9a4eaeed-24cc-4b23-a8ca-7867b251eaf3",
5+
"acm": false,
6+
"name": "",
7+
"team": null,
8+
"owner": {
9+
"id": "7b25912d-b147-48d6-b03d-f0fc72be381b",
10+
"email": ""
11+
},
12+
"space": null,
13+
"stack": {
14+
"id": "74cfe988-7527-4ca9-9667-77bb9f3029cf",
15+
"name": "heroku-24"
16+
},
17+
"region": {
18+
"id": "59accabd-516d-4f0e-83e6-6e3757701145",
19+
"name": "us"
20+
},
21+
"git_url": "",
22+
"web_url": "",
23+
"repo_size": null,
24+
"slug_size": null,
25+
"created_at": "2024-11-07T16:38:38Z",
26+
"updated_at": "2024-11-07T17:14:52Z",
27+
"archived_at": null,
28+
"build_stack": {
29+
"id": "74cfe988-7527-4ca9-9667-77bb9f3029cf",
30+
"name": "heroku-24"
31+
},
32+
"maintenance": false,
33+
"released_at": "2024-11-07T16:38:39Z",
34+
"organization": null,
35+
"internal_routing": null,
36+
"buildpack_provided_description": null
37+
},
38+
"actor": {
39+
"id": "7b25912d-b147-48d6-b03d-f0fc72be381b",
40+
"email": ""
41+
},
42+
"action": "update",
43+
"version": "application/vnd.heroku+json; version=3",
44+
"resource": "app",
45+
"sequence": null,
46+
"created_at": "2024-11-07T17:14:52.475272Z",
47+
"updated_at": "2024-11-07T17:14:52.475276Z",
48+
"published_at": "2024-11-07T17:14:52Z",
49+
"previous_data": {
50+
"name": "",
51+
"git_url": "",
52+
"updated_at": "2024-11-07T17:13:42Z"
53+
},
54+
"webhook_metadata": {
55+
"attempt": {
56+
"id": "16e90948-01d8-4ba0-97de-5868a4aed0bf"
57+
},
58+
"delivery": {
59+
"id": "bbf72057-15f2-40b0-87c7-99ccf95e1666"
60+
},
61+
"event": {
62+
"id": "a5b27512-1f14-4f45-bc26-fe6bf03686fe",
63+
"include": "api:app"
64+
},
65+
"webhook": {
66+
"id": "c385bb39-42ab-49c6-9255-108ff4cabdbd"
67+
}
68+
}
69+
}

pnpm-lock.yaml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)