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
3 changes: 0 additions & 3 deletions components/scalr/.gitignore

This file was deleted.

13 changes: 0 additions & 13 deletions components/scalr/app/scalr.app.ts

This file was deleted.

8 changes: 5 additions & 3 deletions components/scalr/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
{
"name": "@pipedream/scalr",
"version": "0.0.2",
"version": "0.1.0",
"description": "Pipedream Scalr Components",
"main": "dist/app/scalr.app.mjs",
"main": "scalr.app.mjs",
"keywords": [
"pipedream",
"scalr"
],
"files": ["dist"],
"homepage": "https://pipedream.com/apps/scalr",
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
65 changes: 65 additions & 0 deletions components/scalr/scalr.app.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "scalr",
propDefinitions: {
accountId: {
type: "string",
label: "Account ID",
description: "The ID of the account you wish to use.",
async options({ page }) {
const { data: accounts } = await this.getAccounts({
params: {
"page[number]": page + 1,
},
});
return accounts.map((account) => ({
label: account.attributes.name,
value: account.id,
}));
},
},
},
methods: {
_baseUrl() {
return `https://${this.$auth.domain}.scalr.io/api/iacp/v3`;
},
async _makeRequest(opts = {}) {
const {
$ = this,
path,
headers,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: this._baseUrl() + path,
headers: {
"Authorization": `Bearer ${this.$auth.api_token}`,
"Content-type": "application/vnd.api+json",
...headers,
},
});
},
async createWebhook({ ...args }) {
return this._makeRequest({
path: "/integrations/webhooks",
method: "post",
...args,
});
},
async removeWebhook(webhookId) {
return this._makeRequest({
path: `/integrations/webhooks/${webhookId}`,
method: "delete",
});
},
async getAccounts(args = {}) {
return this._makeRequest({
path: "/accounts",
...args,
});
},
},
};
70 changes: 70 additions & 0 deletions components/scalr/sources/common/common.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import scalr from "../../scalr.app.mjs";

export default {
props: {
scalr,
db: "$.service.db",
http: "$.interface.http",
accountId: {
propDefinition: [
scalr,
"accountId",
],
},
},
methods: {
_getWebhookId() {
return this.db.get("webhookId");
},
_setWebhookId(webhookId) {
this.db.set("webhookId", webhookId);
},
getWebhookEventType() {
throw new Error("getWebhookEventType is not implemented");
},
emitEvent(event) {
throw new Error("emitEvent is not implemented", event);
},
},
hooks: {
async activate() {
const { data } = await this.scalr.createWebhook({
data: {
"data": {
"attributes": {
"max-attempts": 3,
"timeout": 15,
"name": "Webhook Pipedream - " + new Date().toISOString(),
"url": this.http.endpoint,
},
"relationships": {
"account": {
"data": {
"type": "accounts",
"id": this.accountId,
},
},
"events": {
"data": [
{
"type": "event-definitions",
"id": this.getWebhookEventType(),
},
],
},
},
"type": "webhook-integrations",
},
},
});
this._setWebhookId(data.id);
},
async deactivate() {
const webhookId = this._getWebhookId();
await this.scalr.removeWebhook(webhookId);
},
},
async run(event) {
await this.emitEvent(event.body);
},
};
28 changes: 28 additions & 0 deletions components/scalr/sources/new-run-completed/new-run-completed.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import common from "../common/common.mjs";

export default {
...common,
name: "New Run Completed (Instant)",
version: "0.0.1",
key: "scalr-new-run-completed",
description: "Emit new event on each new completed run. [See the documentation](https://docs.scalr.io/reference/create_webhook_integration)",
type: "source",
dedupe: "unique",
hooks: {
...common.hooks,
},
methods: {
...common.methods,
getWebhookEventType() {
return "run:completed";
},
async emitEvent(data) {

this.$emit(data, {
id: data.run.id,
summary: `New run completed with ID ${data.run.id}`,
ts: Date.parse(data.run["created-at"]),
});
},
},
};
28 changes: 28 additions & 0 deletions components/scalr/sources/new-run-errored/new-run-errored.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import common from "../common/common.mjs";

export default {
...common,
name: "New Run Errored (Instant)",
version: "0.0.1",
key: "scalr-new-run-errored",
description: "Emit new event when a new run encountered an error. [See the documentation](https://docs.scalr.io/reference/create_webhook_integration)",
type: "source",
dedupe: "unique",
hooks: {
...common.hooks,
},
methods: {
...common.methods,
getWebhookEventType() {
return "run:errored";
},
async emitEvent(data) {

this.$emit(data, {
id: data.run.id,
summary: `New run completed with ID ${data.run.id}`,
ts: Date.parse(data.run["created-at"]),
});
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import common from "../common/common.mjs";

export default {
...common,
name: "New Run Needs Attention (Instant)",
version: "0.0.1",
key: "scalr-new-run-needs-attention",
description: "Emit new event when a new run needs attention. [See the documentation](https://docs.scalr.io/reference/create_webhook_integration)",
type: "source",
dedupe: "unique",
hooks: {
...common.hooks,
},
methods: {
...common.methods,
getWebhookEventType() {
return "run:needs_attention";
},
async emitEvent(data) {

this.$emit(data, {
id: data.run.id,
summary: `New run with ID ${data.run.id} needs attention`,
ts: Date.parse(data.run["created-at"]),
});
},
},
};
6 changes: 5 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading