Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/ecologi/.gitignore

This file was deleted.

42 changes: 42 additions & 0 deletions components/ecologi/actions/buy-offsets/buy-offsets.mjs
Original file line number Diff line number Diff line change
@@ -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;
},
};
42 changes: 42 additions & 0 deletions components/ecologi/actions/buy-trees/buy-trees.mjs
Original file line number Diff line number Diff line change
@@ -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;
},
};
13 changes: 0 additions & 13 deletions components/ecologi/app/ecologi.app.ts

This file was deleted.

6 changes: 6 additions & 0 deletions components/ecologi/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
UNIT_TYPES: [
"KG",
"Tonnes",
],
};
69 changes: 69 additions & 0 deletions components/ecologi/ecologi.app.mjs
Original file line number Diff line number Diff line change
@@ -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,
},
});
},
Comment on lines +36 to +52
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling to the request helper.

The _makeRequest method should include error handling to provide meaningful error messages.

Apply this diff to add error handling:

    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,
-        },
-      });
+      try {
+        return await axios($, {
+          ...otherOpts,
+          url: this._baseUrl() + path,
+          headers: {
+            "Authorization": `Bearer ${this.$auth.api_key}`,
+            "Accept": "application/json",
+            ...headers,
+          },
+        });
+      } catch (err) {
+        throw new Error(`Ecologi API request failed: ${err.message}`);
+      }
    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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 _makeRequest(opts = {}) {
const {
$ = this,
path,
headers,
...otherOpts
} = opts;
try {
return await axios($, {
...otherOpts,
url: this._baseUrl() + path,
headers: {
"Authorization": `Bearer ${this.$auth.api_key}`,
"Accept": "application/json",
...headers,
},
});
} catch (err) {
throw new Error(`Ecologi API request failed: ${err.message}`);
}
}


async buyTrees(args = {}) {
return this._makeRequest({
path: "/impact/trees",
method: "post",
...args,
});
},
async buyOffsets(args = {}) {
return this._makeRequest({
path: "/impact/carbon",
method: "post",
...args,
});
},
},
};
6 changes: 4 additions & 2 deletions components/ecologi/package.json
Original file line number Diff line number Diff line change
@@ -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 <support@pipedream.com> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
Comment on lines 1 to 18
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Update pnpm-lock.yaml and specify Node.js version.

The pipeline is failing due to:

  1. Out-of-date lock file
  2. Node.js version mismatch (wanted: 20.9.0, current: 18.20.6)

Apply this diff to specify the Node.js version:

   "dependencies": {
     "@pipedream/platform": "^3.0.3"
-  }
+  },
+  "engines": {
+    "node": "20.9.0"
+  }
 }

Then run the following commands to update the lock file:

pnpm install
🧰 Tools
🪛 GitHub Actions: Pull Request Checks

[error] 1-1: Cannot install with 'frozen-lockfile' because pnpm-lock.yaml is not up to date with package.json.

🪛 GitHub Actions: Components Checks

[warning] 1-1: Unsupported engine: wanted: {"node":"20.9.0"} (current: {"node":"v18.20.6","pnpm":"9.14.2"})

Loading