Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
24 changes: 24 additions & 0 deletions components/blocknative/actions/get-chains/get-chains.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import app from "../../blocknative.app.mjs";

export default {
key: "blocknative-get-chains",
name: "Get Chains",
description: "Get a list of supported chains. [See the documentation](https://docs.blocknative.com/gas-prediction/gas-platform-1)",
version: "0.0.1",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
type: "action",
props: {
app,
},
async run({ $ }) {
const response = await this.app.getChains({
$,
});
$.export("$summary", "Successfully retrieved " + response.length + " chains");
return response;
},
Comment on lines +17 to +23
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 | 🟠 Major

Add validation for response structure.

The code accesses response.length without validating that the response is an array, which could cause a runtime error if the API returns an unexpected structure.

Apply this diff to add validation:

 async run({ $ }) {
   const response = await this.app.getChains({
     $,
   });
-  $.export("$summary", "Successfully retrieved " + response.length + " chains");
+  if (!Array.isArray(response)) {
+    throw new Error("Unexpected response format: expected an array");
+  }
+  $.export("$summary", `Successfully retrieved ${response.length} chains`);
   return response;
 },

Additionally, prefer template literals over string concatenation.

🤖 Prompt for AI Agents
In components/blocknative/actions/get-chains/get-chains.mjs around lines 17 to
23, the code assumes response is an array and uses response.length and string
concatenation; update it to validate that response is an array before using
length (e.g., if not an array, log/export a clear error or return an empty
array/throw), ensure downstream returns a predictable value, and change the
summary message to use a template literal for readability (e.g., include the
validated length variable in a backtick string).

};
40 changes: 40 additions & 0 deletions components/blocknative/actions/get-gas-prices/get-gas-prices.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import app from "../../blocknative.app.mjs";

export default {
key: "blocknative-get-gas-prices",
name: "Get Gas Prices",
description: "Get gas price estimations with confidence levels. [See the documentation](https://docs.blocknative.com/gas-prediction/gas-platform)",
version: "0.0.1",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
type: "action",
props: {
app,
confidenceLevels: {
propDefinition: [
app,
"confidenceLevels",
],
},
chainid: {
propDefinition: [
app,
"chainid",
],
},
},
async run({ $ }) {
const response = await this.app.getBlockprices({
$,
params: {
confidenceLevels: this.confidenceLevels.join(","),
chainid: this.chainid,
},
});
$.export("$summary", "Successfully retrieved " + response.blockPrices[0].estimatedPrices.length + " estimated prices");
return response;
},
Comment on lines +29 to +39
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 | 🔴 Critical

Add validation for nested response structure.

Line 37 accesses deeply nested properties (response.blockPrices[0].estimatedPrices.length) without validation. This will throw a runtime error if:

  • response.blockPrices is undefined or not an array
  • response.blockPrices is empty
  • response.blockPrices[0] doesn't have estimatedPrices

Apply this diff to add proper validation:

 async run({ $ }) {
   const response = await this.app.getBlockprices({
     $,
     params: {
       confidenceLevels: this.confidenceLevels.join(","),
       chainid: this.chainid,
     },
   });
-  $.export("$summary", "Successfully retrieved " + response.blockPrices[0].estimatedPrices.length + " estimated prices");
+  if (!response.blockPrices?.length || !response.blockPrices[0]?.estimatedPrices) {
+    throw new Error("Unexpected response format: missing blockPrices or estimatedPrices");
+  }
+  $.export("$summary", `Successfully retrieved ${response.blockPrices[0].estimatedPrices.length} estimated prices`);
   return response;
 },

Additionally, prefer template literals over string concatenation.

🤖 Prompt for AI Agents
In components/blocknative/actions/get-gas-prices/get-gas-prices.mjs around lines
29 to 39, the code assumes response.blockPrices[0].estimatedPrices exists and
reads its length directly; add defensive checks to ensure response is an object,
response.blockPrices is an array with at least one element, and
response.blockPrices[0].estimatedPrices is an array before accessing .length,
falling back to 0 (or a safe default) if any check fails; then use a template
literal for the summary export (e.g. `Successfully retrieved ${count} estimated
prices`) and keep returning the original response.

};
24 changes: 24 additions & 0 deletions components/blocknative/actions/get-oracles/get-oracles.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import app from "../../blocknative.app.mjs";

export default {
key: "blocknative-get-oracles",
name: "Get Oracles",
description: "Get a list of supported oracles. [See the documentation](https://docs.blocknative.com/gas-prediction/gas-platform-2)",
version: "0.0.1",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
type: "action",
props: {
app,
},
async run({ $ }) {
const response = await this.app.getOracles({
$,
});
$.export("$summary", "Successfully retrieved " + response.length + " results");
return response;
},
Comment on lines +17 to +23
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 | 🟠 Major

Add validation for response structure.

The code accesses response.length without validating that the response is an array. If the API returns an unexpected structure, this will cause a runtime error.

Consider adding validation:

 async run({ $ }) {
   const response = await this.app.getOracles({
     $,
   });
-  $.export("$summary", "Successfully retrieved " + response.length + " results");
+  if (!Array.isArray(response)) {
+    throw new Error("Unexpected response format: expected an array");
+  }
+  $.export("$summary", `Successfully retrieved ${response.length} results`);
   return response;
 },

Additionally, prefer template literals over string concatenation for improved readability.

📝 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 run({ $ }) {
const response = await this.app.getOracles({
$,
});
$.export("$summary", "Successfully retrieved " + response.length + " results");
return response;
},
async run({ $ }) {
const response = await this.app.getOracles({
$,
});
if (!Array.isArray(response)) {
throw new Error("Unexpected response format: expected an array");
}
$.export("$summary", `Successfully retrieved ${response.length} results`);
return response;
},
🤖 Prompt for AI Agents
In components/blocknative/actions/get-oracles/get-oracles.mjs around lines 17 to
23, the code assumes response is an array and uses response.length and string
concatenation; validate the response shape first (e.g. if
(!Array.isArray(response)) handle it by either throwing a descriptive error or
normalizing to an empty array), then use the array's length safely and export
the summary using a template literal (e.g. `\`Successfully retrieved
${results.length} results\``); ensure the function still returns the normalized
value so callers never receive an unexpected structure.

};
66 changes: 61 additions & 5 deletions components/blocknative/blocknative.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,67 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "blocknative",
propDefinitions: {},
propDefinitions: {
confidenceLevels: {
type: "integer[]",
label: "confidenceLevels",
description: "Confidence levels to include in the gas price estimation",
},
chainid: {
type: "string",
label: "chainid",
description: "Blockchain network identifier to query gas prices for",
async options() {
const response = await this.getChains();
return response.map(({
label, chainId,
}) => ({
value: chainId,
label: label,
}));
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.blocknative.com";
},
async _makeRequest(opts = {}) {
const {
$ = this,
path,
headers,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: this._baseUrl() + path,
headers: {
"Authorization": `${this.$auth.api_key}`,
...headers,
},
});
},

async getBlockprices(args = {}) {
return this._makeRequest({
path: "/gasprices/blockprices",
...args,
});
},
async getChains(args = {}) {
return this._makeRequest({
path: "/chains",
...args,
});
},
async getOracles(args = {}) {
return this._makeRequest({
path: "/oracles",
...args,
});
},
},
};
};
5 changes: 4 additions & 1 deletion components/blocknative/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/blocknative",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Blocknative Components",
"main": "blocknative.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.1.1"
}
}
2 changes: 1 addition & 1 deletion components/browseract/browseract.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/camino_ai/camino_ai.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/clappia/clappia.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/elastic_security/elastic_security.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/postnitro/postnitro.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/redash/redash.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/spike/spike.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/straico/straico.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/straker_verify/straker_verify.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/trackvia/trackvia.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
31 changes: 14 additions & 17 deletions pnpm-lock.yaml

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

Loading