-
Notifications
You must be signed in to change notification settings - Fork 5.6k
[Components] ecologi #13287 #15577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Components] ecologi #13287 #15577
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| 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; | ||
| }, | ||
| }; |
| 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; | ||
| }, | ||
| }; |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| export default { | ||
| UNIT_TYPES: [ | ||
| "KG", | ||
| "Tonnes", | ||
| ], | ||
| }; |
| 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, | ||
| }, | ||
| }); | ||
| }, | ||
|
|
||
| async buyTrees(args = {}) { | ||
| return this._makeRequest({ | ||
| path: "/impact/trees", | ||
| method: "post", | ||
| ...args, | ||
| }); | ||
| }, | ||
| async buyOffsets(args = {}) { | ||
| return this._makeRequest({ | ||
| path: "/impact/carbon", | ||
| method: "post", | ||
| ...args, | ||
| }); | ||
| }, | ||
| }, | ||
| }; | ||
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update pnpm-lock.yaml and specify Node.js version. The pipeline is failing due to:
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"}) |
||
There was a problem hiding this comment.
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
_makeRequestmethod 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