- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.5k
Spider new components #14288
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
Spider new components #14288
Conversation
| The latest updates on your projects. Learn more about Vercel for Git ↗︎ 3 Skipped Deployments
 | 
| WalkthroughThis pull request introduces a new module  Changes
 Assessment against linked issues
 Possibly related PRs
 Suggested labels
 Suggested reviewers
 Poem
 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
 🚧 Files skipped from review as they are similar to previous changes (1)
 Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit: 
 Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
 Other keywords and placeholders
 CodeRabbit Configuration File ( | 
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.
Actionable comments posted: 3
🧹 Outside diff range and nitpick comments (4)
components/spider/spider.app.mjs (3)
11-23: Approved with a suggestion for error handling.The
_makeRequest()method is well-implemented, providing flexibility and correctly handling authentication. It uses the private_baseUrl()method and allows for additional headers and options.Consider adding basic error handling to provide more context in case of API errors:
async _makeRequest({ $ = this, path = "/", headers, ...otherOpts } = {}) { - return axios($, { - ...otherOpts, - url: this._baseUrl() + path, - headers: { - ...headers, - "Authorization": `Bearer ${this.$auth.api_key}`, - "Content-Type": "application/json", - }, - }); + try { + return await axios($, { + ...otherOpts, + url: this._baseUrl() + path, + headers: { + ...headers, + "Authorization": `Bearer ${this.$auth.api_key}`, + "Content-Type": "application/json", + }, + }); + } catch (error) { + throw new Error(`Spider API request failed: ${error.message}`); + } },This change would provide more context in case of API errors, making debugging easier.
24-29: Approved with suggestions for input validation and documentation.The
initiateCrawl()method is correctly implemented and aligns with the PR objectives. It effectively uses the_makeRequest()method to initiate a crawl.Consider adding input validation and JSDoc comments:
+ /** + * Initiates a new crawl. + * @param {Object} args - The arguments for the crawl. + * @param {string} args.url - The URL to crawl. + * @returns {Promise<Object>} The response from the Spider API. + */ async initiateCrawl(args) { + if (!args.url) { + throw new Error("URL is required to initiate a crawl"); + } return this._makeRequest({ method: "POST", path: "/crawl", ...args, }); },These changes would improve the method's robustness and documentation, making it easier for other developers to use correctly.
1-32: Consider adding action definitions and prop definitions.The Spider app component looks good overall, but it seems to be missing some key elements:
Action Definitions: The component includes methods for making API requests and initiating crawls, but there are no action definitions that would use these methods. Consider adding actions that users can trigger, such as a "Scrape New Page" action that uses the
initiateCrawl()method.
Prop Definitions: The
propDefinitionsobject is currently empty. If the app requires any configuration options or inputs from the user, these should be defined here.Here's an example of how you might add an action:
export default { // ... existing code ... propDefinitions: { url: { type: "string", label: "URL", description: "The URL of the page to scrape", }, }, actions: { scrapeNewPage: { name: "Scrape New Page", description: "Initiates a new page scrape", key: "scrapeNewPage", type: "action", props: { url: { propDefinition: [ "spider", "url", ], }, }, async run({ $ }) { const response = await this.initiateCrawl({ $, url: this.url, }); $.export("$summary", `Successfully initiated scrape for ${this.url}`); return response; }, }, }, };This addition would make the component more complete and directly usable within the Pipedream ecosystem.
components/spider/actions/scrape-new-page/scrape-new-page.mjs (1)
19-19: Fix typo in the description: change "comma split" to "comma-separated".In the
urlprop description, "comma split list" should be updated to "comma-separated list" for clarity and correctness.Apply this diff:
description: "The URI resource to crawl, e.g. `https://spider.cloud`. This can be a comma- - split list for multiple urls.", + separated list for multiple URLs.",
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
⛔ Files ignored due to path filters (1)
- pnpm-lock.yamlis excluded by- !**/pnpm-lock.yaml
📒 Files selected for processing (3)
- components/spider/actions/scrape-new-page/scrape-new-page.mjs (1 hunks)
- components/spider/package.json (2 hunks)
- components/spider/spider.app.mjs (1 hunks)
🧰 Additional context used
🔇 Additional comments (4)
components/spider/package.json (4)
3-3: Version update looks good.The version increment from 0.0.1 to 0.1.0 aligns with semantic versioning principles and reflects the addition of new features (Spider components) as described in the PR objectives.
14-14: PublishConfig update is appropriate.Setting the "access" property to "public" in publishConfig is a good practice. It ensures that the package will be publicly accessible when published, which is appropriate for components intended for user consumption.
Line range hint
1-18: Overall package.json updates look good.The changes to package.json are consistent with introducing a new Spider component:
- Version update reflects new features.
- PublishConfig ensures public accessibility.
- Dependencies section adds necessary Pipedream platform dependency.
These updates align well with the PR objectives of introducing new Spider components.
15-17: Dependencies section added correctly.The addition of @pipedream/platform as a dependency is appropriate for a Pipedream component. The version constraint "^3.0.3" allows for compatible updates, which is a good practice.
Please verify that 3.0.3 is the latest stable version of @pipedream/platform. You can check this by running:
| _baseUrl() { | ||
| return "https://api.spider.cloud"; | ||
| }, | 
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
Consider using an environment variable for the base URL.
While the implementation is correct, hardcoding the base URL might make it difficult to change in the future, especially if there are different environments (e.g., staging, production).
Consider using an environment variable:
 _baseUrl() {
-  return "https://api.spider.cloud";
+  return process.env.SPIDER_API_BASE_URL || "https://api.spider.cloud";
 },This change would allow for easier configuration across different environments while maintaining the current URL as a default.
📝 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.
| _baseUrl() { | |
| return "https://api.spider.cloud"; | |
| }, | |
| _baseUrl() { | |
| return process.env.SPIDER_API_BASE_URL || "https://api.spider.cloud"; | |
| }, | 
| storeData: { | ||
| type: "boolean", | ||
| label: "Store Data", | ||
| description: "Decide whether to store data. Default is `false`.", | ||
| optional: true, | ||
| }, | 
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.
Add a default value to the storeData prop to ensure it defaults to false.
The storeData prop is optional, but the description indicates that the default value is false. Without a default value in the prop definition, this.storeData may be undefined, which could lead to unexpected behavior when passed to the API. Adding a default property will ensure it defaults to false when not specified.
Apply this diff to set the default value for storeData:
      storeData: {
        type: "boolean",
        label: "Store Data",
        description: "Decide whether to store data. Default is `false`.",
        optional: true,
+       default: false,
      },📝 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.
| storeData: { | |
| type: "boolean", | |
| label: "Store Data", | |
| description: "Decide whether to store data. Default is `false`.", | |
| optional: true, | |
| }, | |
| storeData: { | |
| type: "boolean", | |
| label: "Store Data", | |
| description: "Decide whether to store data. Default is `false`.", | |
| optional: true, | |
| default: false, | |
| }, | 
| limit: { | ||
| type: "integer", | ||
| label: "Limit", | ||
| description: "The maximum amount of pages allowed to crawl per website. Default is 0, which crawls all pages.", | ||
| optional: true, | ||
| }, | 
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.
Add a default value to the limit prop to ensure it defaults to 0.
The limit prop is optional, but according to the description, it defaults to 0, which crawls all pages. Without specifying a default value in the prop definition, this.limit may be undefined when the action runs. Adding a default property will ensure it defaults to 0 when not specified by the user.
Apply this diff to set the default value for limit:
      limit: {
        type: "integer",
        label: "Limit",
        description: "The maximum amount of pages allowed to crawl per website. Default is 0, which crawls all pages.",
        optional: true,
+       default: 0,
      },📝 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.
| limit: { | |
| type: "integer", | |
| label: "Limit", | |
| description: "The maximum amount of pages allowed to crawl per website. Default is 0, which crawls all pages.", | |
| optional: true, | |
| }, | |
| limit: { | |
| type: "integer", | |
| label: "Limit", | |
| description: "The maximum amount of pages allowed to crawl per website. Default is 0, which crawls all pages.", | |
| optional: true, | |
| default: 0, | |
| }, | 
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.
Hi @GTFalcao, I just added a suggestion!
| key: "spider-scrape-new-page", | ||
| name: "Scrape New Page", | ||
| description: "Initiates a new page scrape (crawl). [See the documentation](https://spider.cloud/docs/api#crawl-website)", | ||
| version: "0.0.{{ts}}", | 
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.
| version: "0.0.{{ts}}", | |
| version: "0.0.1", | 
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.
Hi @GTFalcao, LGTM! Ready for QA!
Closes #14263
Summary by CodeRabbit
New Features
Version Updates
@pipedream/platform.Documentation