From 150e6ab0b939713f6381fc27ed02662fdcbe4927 Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Wed, 12 Feb 2025 09:21:07 -0300 Subject: [PATCH 1/3] Added actions --- components/ecologi/.gitignore | 3 - .../actions/buy-offsets/buy-offsets.mjs | 42 +++++++++++ .../ecologi/actions/buy-trees/buy-trees.mjs | 42 +++++++++++ components/ecologi/app/ecologi.app.ts | 13 ---- components/ecologi/common/constants.mjs | 6 ++ components/ecologi/ecologi.app.mjs | 69 +++++++++++++++++++ components/ecologi/package.json | 6 +- 7 files changed, 163 insertions(+), 18 deletions(-) delete mode 100644 components/ecologi/.gitignore create mode 100644 components/ecologi/actions/buy-offsets/buy-offsets.mjs create mode 100644 components/ecologi/actions/buy-trees/buy-trees.mjs delete mode 100644 components/ecologi/app/ecologi.app.ts create mode 100644 components/ecologi/common/constants.mjs create mode 100644 components/ecologi/ecologi.app.mjs diff --git a/components/ecologi/.gitignore b/components/ecologi/.gitignore deleted file mode 100644 index ec761ccab7595..0000000000000 --- a/components/ecologi/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.js -*.mjs -dist \ No newline at end of file diff --git a/components/ecologi/actions/buy-offsets/buy-offsets.mjs b/components/ecologi/actions/buy-offsets/buy-offsets.mjs new file mode 100644 index 0000000000000..a1d1d2da72979 --- /dev/null +++ b/components/ecologi/actions/buy-offsets/buy-offsets.mjs @@ -0,0 +1,42 @@ +import app from "../../ecologi.app.mjs"; + +export default { + key: "ecologi-buy-offsets", + name: "Buy Offsets", + description: "Buy carbon avoidance credits through Ecologi. [See the documentation](https://docs.ecologi.com/docs/public-api-docs/e07bbee7fa605-purchase-carbon-avoidance)", + version: "0.0.1", + type: "action", + props: { + app, + number: { + propDefinition: [ + app, + "number", + ], + }, + units: { + propDefinition: [ + app, + "units", + ], + }, + test: { + propDefinition: [ + app, + "test", + ], + }, + }, + async run({ $ }) { + const response = await this.app.buyOffsets({ + $, + data: { + number: this.number, + units: this.units, + test: this.test, + }, + }); + $.export("$summary", "Successfully bought carbon avoidance credits"); + return response; + }, +}; diff --git a/components/ecologi/actions/buy-trees/buy-trees.mjs b/components/ecologi/actions/buy-trees/buy-trees.mjs new file mode 100644 index 0000000000000..ed75aa39e8e05 --- /dev/null +++ b/components/ecologi/actions/buy-trees/buy-trees.mjs @@ -0,0 +1,42 @@ +import app from "../../ecologi.app.mjs"; + +export default { + key: "ecologi-buy-trees", + name: "Buy Trees", + description: "Purchase trees through Ecologi. [See the documentation](https://docs.ecologi.com/docs/public-api-docs/004342d262f93-purchase-trees)", + version: "0.0.1", + type: "action", + props: { + app, + number: { + propDefinition: [ + app, + "number", + ], + }, + name: { + propDefinition: [ + app, + "name", + ], + }, + test: { + propDefinition: [ + app, + "test", + ], + }, + }, + async run({ $ }) { + const response = await this.app.buyTrees({ + $, + data: { + number: this.number, + name: this.name, + test: this.test, + }, + }); + $.export("$summary", `Successfully bought ${this.number} tree(s)`); + return response; + }, +}; diff --git a/components/ecologi/app/ecologi.app.ts b/components/ecologi/app/ecologi.app.ts deleted file mode 100644 index 47bb2e5b60478..0000000000000 --- a/components/ecologi/app/ecologi.app.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { defineApp } from "@pipedream/types"; - -export default defineApp({ - type: "app", - app: "ecologi", - 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/ecologi/common/constants.mjs b/components/ecologi/common/constants.mjs new file mode 100644 index 0000000000000..2f55b80bf384e --- /dev/null +++ b/components/ecologi/common/constants.mjs @@ -0,0 +1,6 @@ +export default { + UNIT_TYPES: [ + "KG", + "Tonnes", + ], +}; diff --git a/components/ecologi/ecologi.app.mjs b/components/ecologi/ecologi.app.mjs new file mode 100644 index 0000000000000..930746eecc444 --- /dev/null +++ b/components/ecologi/ecologi.app.mjs @@ -0,0 +1,69 @@ +import { axios } from "@pipedream/platform"; +import constants from "./common/constants.mjs"; + +export default { + type: "app", + app: "ecologi", + propDefinitions: { + number: { + type: "integer", + label: "number", + description: "Number of trees of offsets to purchase", + }, + name: { + type: "string", + label: "name", + description: "The 'funded by' name for the trees", + optional: true, + }, + units: { + type: "string", + label: "units", + description: "The unit of the amount of offsets to purchase", + options: constants.UNIT_TYPES, + }, + test: { + type: "boolean", + label: "test", + description: "Whether this is a test transaction or not", + optional: true, + }, + }, + methods: { + _baseUrl() { + return "https://public.ecologi.com"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + headers, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + headers: { + "Authorization": `Bearer ${this.$auth.api_key}`, + "Accept": "application/json", + ...headers, + }, + }); + }, + + async buyTrees(args = {}) { + return this._makeRequest({ + path: "/impact/trees", + method: "post", + ...args, + }); + }, + async buyOffsets(args = {}) { + return this._makeRequest({ + path: "/impact/carbon", + method: "post", + ...args, + }); + }, + }, +}; diff --git a/components/ecologi/package.json b/components/ecologi/package.json index f6f9cf1bb05a1..18c0bc2bc525b 100644 --- a/components/ecologi/package.json +++ b/components/ecologi/package.json @@ -1,16 +1,18 @@ { "name": "@pipedream/ecologi", - "version": "0.0.2", + "version": "0.1.0", "description": "Pipedream Ecologi Components", "main": "dist/app/ecologi.app.mjs", "keywords": [ "pipedream", "ecologi" ], - "files": ["dist"], "homepage": "https://pipedream.com/apps/ecologi", "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } } From c826cfec83e2c2588aa3f396f62bac0c8573cf01 Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Wed, 12 Feb 2025 09:24:05 -0300 Subject: [PATCH 2/3] Added actions --- components/ecologi/actions/buy-trees/buy-trees.mjs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/ecologi/actions/buy-trees/buy-trees.mjs b/components/ecologi/actions/buy-trees/buy-trees.mjs index ed75aa39e8e05..525f6a8d7a85d 100644 --- a/components/ecologi/actions/buy-trees/buy-trees.mjs +++ b/components/ecologi/actions/buy-trees/buy-trees.mjs @@ -36,7 +36,9 @@ export default { test: this.test, }, }); + $.export("$summary", `Successfully bought ${this.number} tree(s)`); + return response; }, }; From ca5606cdf7e44027420d77a8c2d19c923432c01f Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Wed, 12 Feb 2025 09:26:54 -0300 Subject: [PATCH 3/3] Done requests changes --- pnpm-lock.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7eb3daed2a689..afeda7072dd32 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3221,7 +3221,11 @@ importers: specifier: ^1.5.1 version: 1.6.6 - components/ecologi: {} + components/ecologi: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 components/ecwid: dependencies: