From 9969779c9312b1a56f7c81a782adaea771263554 Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Wed, 14 May 2025 15:34:20 -0300 Subject: [PATCH 1/4] Added actions --- components/scalr/app/scalr.app.ts | 13 ------------- components/scalr/package.json | 8 +++++--- pnpm-lock.yaml | 20 +++++++++++--------- 3 files changed, 16 insertions(+), 25 deletions(-) delete mode 100644 components/scalr/app/scalr.app.ts diff --git a/components/scalr/app/scalr.app.ts b/components/scalr/app/scalr.app.ts deleted file mode 100644 index 4bc5dc154ca0a..0000000000000 --- a/components/scalr/app/scalr.app.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { defineApp } from "@pipedream/types"; - -export default defineApp({ - type: "app", - app: "scalr", - propDefinitions: {}, - methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); - }, - }, -}); \ No newline at end of file diff --git a/components/scalr/package.json b/components/scalr/package.json index da6e1849fa52c..b49b50b4e3ce4 100644 --- a/components/scalr/package.json +++ b/components/scalr/package.json @@ -1,16 +1,18 @@ { "name": "@pipedream/scalr", - "version": "0.0.2", + "version": "0.0.1", "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 (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fa0d8715fb602..b1f7a840f3334 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7755,13 +7755,11 @@ importers: components/mailninja: {} - components/mailosaur: - specifiers: {} + components/mailosaur: {} components/mailrefine: {} - components/mailrelay: - specifiers: {} + components/mailrelay: {} components/mails_so: dependencies: @@ -10170,8 +10168,7 @@ importers: specifier: ^1.5.1 version: 1.6.6 - components/prepr_graphql: - specifiers: {} + components/prepr_graphql: {} components/prerender: dependencies: @@ -11382,7 +11379,11 @@ importers: specifier: ^1.5.1 version: 1.6.6 - components/scalr: {} + components/scalr: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 components/schedule: dependencies: @@ -11541,8 +11542,7 @@ importers: components/sellsy: {} - components/selzy: - specifiers: {} + components/selzy: {} components/semaphore: {} @@ -35634,6 +35634,8 @@ snapshots: '@putout/operator-filesystem': 5.0.0(putout@36.13.1(eslint@8.57.1)(typescript@5.6.3)) '@putout/operator-json': 2.2.0 putout: 36.13.1(eslint@8.57.1)(typescript@5.6.3) + transitivePeerDependencies: + - supports-color '@putout/operator-regexp@1.0.0(putout@36.13.1(eslint@8.57.1)(typescript@5.6.3))': dependencies: From 7d59f43105f1b02514956ee50e8cf7aea42038e8 Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Thu, 15 May 2025 16:35:45 -0300 Subject: [PATCH 2/4] Added actions --- components/scalr/.gitignore | 3 - components/scalr/scalr.app.mjs | 73 +++++++++++++++++++ components/scalr/sources/common/common.mjs | 70 ++++++++++++++++++ .../new-run-completed/new-run-completed.mjs | 28 +++++++ .../new-run-errored/new-run-errored.mjs | 28 +++++++ .../new-run-needs-attention.mjs | 28 +++++++ 6 files changed, 227 insertions(+), 3 deletions(-) delete mode 100644 components/scalr/.gitignore create mode 100644 components/scalr/scalr.app.mjs create mode 100644 components/scalr/sources/common/common.mjs create mode 100644 components/scalr/sources/new-run-completed/new-run-completed.mjs create mode 100644 components/scalr/sources/new-run-errored/new-run-errored.mjs create mode 100644 components/scalr/sources/new-run-needs-attention/new-run-needs-attention.mjs diff --git a/components/scalr/.gitignore b/components/scalr/.gitignore deleted file mode 100644 index ec761ccab7595..0000000000000 --- a/components/scalr/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.js -*.mjs -dist \ No newline at end of file diff --git a/components/scalr/scalr.app.mjs b/components/scalr/scalr.app.mjs new file mode 100644 index 0000000000000..2068cf9a57d63 --- /dev/null +++ b/components/scalr/scalr.app.mjs @@ -0,0 +1,73 @@ +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() { + const { data: accounts } = await this.getAccounts(); + 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 getWebhooks(args = {}) { + return this._makeRequest({ + path: "/integrations/webhooks", + ...args, + }); + }, + async getAccounts(args = {}) { + return this._makeRequest({ + path: "/accounts", + ...args, + }); + }, + async getEvents(args = {}) { + return this._makeRequest({ + path: "/event-definitions", + ...args, + }); + }, + }, +}; diff --git a/components/scalr/sources/common/common.mjs b/components/scalr/sources/common/common.mjs new file mode 100644 index 0000000000000..b09e019e3ca88 --- /dev/null +++ b/components/scalr/sources/common/common.mjs @@ -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); + }, +}; diff --git a/components/scalr/sources/new-run-completed/new-run-completed.mjs b/components/scalr/sources/new-run-completed/new-run-completed.mjs new file mode 100644 index 0000000000000..da8dae583b3ea --- /dev/null +++ b/components/scalr/sources/new-run-completed/new-run-completed.mjs @@ -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.", + 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"]), + }); + }, + }, +}; diff --git a/components/scalr/sources/new-run-errored/new-run-errored.mjs b/components/scalr/sources/new-run-errored/new-run-errored.mjs new file mode 100644 index 0000000000000..df7d9710f8719 --- /dev/null +++ b/components/scalr/sources/new-run-errored/new-run-errored.mjs @@ -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.", + 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"]), + }); + }, + }, +}; diff --git a/components/scalr/sources/new-run-needs-attention/new-run-needs-attention.mjs b/components/scalr/sources/new-run-needs-attention/new-run-needs-attention.mjs new file mode 100644 index 0000000000000..1ff89dbbfaa26 --- /dev/null +++ b/components/scalr/sources/new-run-needs-attention/new-run-needs-attention.mjs @@ -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.", + 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"]), + }); + }, + }, +}; From 240c714ffbd2f72805457e151b3ace46a230a95f Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Thu, 22 May 2025 12:40:37 -0300 Subject: [PATCH 3/4] Added actions --- components/scalr/scalr.app.mjs | 20 ++++++------------- .../new-run-completed/new-run-completed.mjs | 2 +- .../new-run-errored/new-run-errored.mjs | 2 +- .../new-run-needs-attention.mjs | 2 +- 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/components/scalr/scalr.app.mjs b/components/scalr/scalr.app.mjs index 2068cf9a57d63..db2328a2a9487 100644 --- a/components/scalr/scalr.app.mjs +++ b/components/scalr/scalr.app.mjs @@ -8,8 +8,12 @@ export default { type: "string", label: "Account ID", description: "The ID of the account you wish to use.", - async options() { - const { data: accounts } = await this.getAccounts(); + 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, @@ -51,23 +55,11 @@ export default { method: "delete", }); }, - async getWebhooks(args = {}) { - return this._makeRequest({ - path: "/integrations/webhooks", - ...args, - }); - }, async getAccounts(args = {}) { return this._makeRequest({ path: "/accounts", ...args, }); }, - async getEvents(args = {}) { - return this._makeRequest({ - path: "/event-definitions", - ...args, - }); - }, }, }; diff --git a/components/scalr/sources/new-run-completed/new-run-completed.mjs b/components/scalr/sources/new-run-completed/new-run-completed.mjs index da8dae583b3ea..1c291c5649f69 100644 --- a/components/scalr/sources/new-run-completed/new-run-completed.mjs +++ b/components/scalr/sources/new-run-completed/new-run-completed.mjs @@ -5,7 +5,7 @@ export default { name: "New Run Completed (Instant)", version: "0.0.1", key: "scalr-new-run-completed", - description: "Emit new event on each new completed run.", + 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: { diff --git a/components/scalr/sources/new-run-errored/new-run-errored.mjs b/components/scalr/sources/new-run-errored/new-run-errored.mjs index df7d9710f8719..be2dccb41be4c 100644 --- a/components/scalr/sources/new-run-errored/new-run-errored.mjs +++ b/components/scalr/sources/new-run-errored/new-run-errored.mjs @@ -5,7 +5,7 @@ export default { 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.", + 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: { diff --git a/components/scalr/sources/new-run-needs-attention/new-run-needs-attention.mjs b/components/scalr/sources/new-run-needs-attention/new-run-needs-attention.mjs index 1ff89dbbfaa26..b72a3faa81a50 100644 --- a/components/scalr/sources/new-run-needs-attention/new-run-needs-attention.mjs +++ b/components/scalr/sources/new-run-needs-attention/new-run-needs-attention.mjs @@ -5,7 +5,7 @@ export default { 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.", + 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: { From c5361c9709412a26cab148c241e9df8e08a0261b Mon Sep 17 00:00:00 2001 From: Michelle Bergeron Date: Thu, 22 May 2025 13:25:15 -0400 Subject: [PATCH 4/4] fix package.json --- components/scalr/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/scalr/package.json b/components/scalr/package.json index b49b50b4e3ce4..6910fb4e1274d 100644 --- a/components/scalr/package.json +++ b/components/scalr/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/scalr", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Scalr Components", "main": "scalr.app.mjs", "keywords": [