-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[Components] scalr #13481 #16663
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
base: master
Are you sure you want to change the base?
[Components] scalr #13481 #16663
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 3 Skipped Deployments
|
WalkthroughThe changes replace the previous Scalr app integration with a new implementation that includes comprehensive API methods for managing webhooks, accounts, and events. Several new source components are added to emit events on specific run statuses, all extending a common webhook management module. The package metadata is adjusted, and the old app file and Changes
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
components/scalr/sources/common/common.mjsOops! Something went wrong! :( ESLint: 8.57.1 Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'jsonc-eslint-parser' imported from /eslint.config.mjs components/scalr/sources/new-run-errored/new-run-errored.mjsOops! Something went wrong! :( ESLint: 8.57.1 Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'jsonc-eslint-parser' imported from /eslint.config.mjs components/scalr/scalr.app.mjsOops! Something went wrong! :( ESLint: 8.57.1 Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'jsonc-eslint-parser' imported from /eslint.config.mjs
Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Note ⚡️ Faster reviews with cachingCodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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: 0
🧹 Nitpick comments (1)
components/scalr/package.json (1)
15-17
: Add runtime dependency on @pipedream/platform.
This dependency is required for the component runtime. If you expect the host to provide@pipedream/platform
, you may want to declare it as apeerDependency
instead of bundling it.Here’s a diff to switch it to a peerDependency:
- "dependencies": { - "@pipedream/platform": "^3.0.3" - } + "peerDependencies": { + "@pipedream/platform": "^3.0.3" + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (2)
components/scalr/app/scalr.app.ts
(0 hunks)components/scalr/package.json
(1 hunks)
💤 Files with no reviewable changes (1)
- components/scalr/app/scalr.app.ts
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: Verify TypeScript components
- GitHub Check: pnpm publish
- GitHub Check: Publish TypeScript components
- GitHub Check: Lint Code Base
🔇 Additional comments (3)
components/scalr/package.json (3)
14-14
: PublishConfig block closure restored.
The missing closing brace for thepublishConfig
object has been added correctly.
5-5
:❓ Verification inconclusive
Ensure the new entry point exists post-build.
The"main"
field now points toscalr.app.mjs
at the package root—verify that your build step emits this file in the package, and consider adding a"files"
array to restrict published contents.You can confirm its presence with:
🏁 Script executed:
fd scalr.app.mjsLength of output: 18
Verify new entry point and locked‐down package contents
We weren’t able to locatescalr.app.mjs
in the repo—please ensure your build step emits this file at the package root (or update"main"
to the correct path if it lands elsewhere). Also consider adding a"files"
array to limit what’s published.• Run your build and confirm the file exists:
npm run build fd scalr.app.mjs• If the output lands in a subfolder (e.g.
dist/
), update the"main"
field accordingly.
• Add a"files"
entry tocomponents/scalr/package.json
, for example:"files": [ "scalr.app.mjs", "dist/" ]
3-3
:❓ Verification inconclusive
Confirm the version downgrade intent.
The version was changed from0.0.2
to0.0.1
—ensure this aligns with your release strategy and doesn’t accidentally overwrite a newer release on npm.Run the following to list published versions:
🏁 Script executed:
npm view @pipedream/scalr versionsLength of output: 57
Confirm version downgrade intent
The published versions for@pipedream/scalr
are0.0.1
and0.0.2
. The version in components/scalr/package.json has been downgraded from0.0.2
to0.0.1
. Please confirm this is intentional and won’t accidentally overwrite a newer release on npm.
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 @lcaresia, I think you forgot to include the components in this PR.
Thanks @michelle0927! |
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: 0
🧹 Nitpick comments (7)
components/scalr/sources/new-run-completed/new-run-completed.mjs (1)
3-28
: Component implementation looks good with room for data validationThe component correctly extends the common module and properly implements the required methods. The emission logic with unique ID generation and summary creation is well-structured.
Consider adding validation for the data structure before accessing properties:
async emitEvent(data) { + if (!data?.run) { + console.log("Received invalid webhook data", data); + return; + } this.$emit(data, { id: data.run.id, summary: `New run completed with ID ${data.run.id}`, ts: Date.parse(data.run["created-at"]), }); },This would prevent potential errors if the webhook payload doesn't match the expected structure.
components/scalr/sources/common/common.mjs (4)
3-70
: Well-structured common module with appropriate abstractionThe common module provides a solid foundation for Scalr webhook-based components with proper lifecycle management and abstract methods that enforce implementation.
A few observations:
- The webhook naming pattern
"Webhook Pipedream - " + new Date().toISOString()
ensures uniqueness but will create many webhooks if components are reactivated frequently- The error message in
emitEvent
method includes the event parameter but doesn't use it correctlyFix the error message in the
emitEvent
method:emitEvent(event) { - throw new Error("emitEvent is not implemented", event); + throw new Error("emitEvent is not implemented"); },The second argument to Error constructor is not used - JavaScript Error doesn't accept the data as a second parameter.
30-61
: Webhook creation looks good but could benefit from error handlingThe webhook creation logic correctly sets up the webhook with the Scalr API and stores the webhook ID.
Consider adding error handling to the webhook creation process:
async activate() { - const { data } = await this.scalr.createWebhook({ - data: { - "data": { - "attributes": { - "max-attempts": 3, - "timeout": 15, - "name": "Webhook Pipedream - " + new Date().toISOString(), - "url": this.http.endpoint, - }, - "relationships": { - "account": { - "data": { - "type": "accounts", - "id": this.accountId, - }, - }, - "events": { - "data": [ - { - "type": "event-definitions", - "id": this.getWebhookEventType(), - }, - ], - }, - }, - "type": "webhook-integrations", - }, - }, - }); - this._setWebhookId(data.id); + try { + const { data } = await this.scalr.createWebhook({ + data: { + "data": { + "attributes": { + "max-attempts": 3, + "timeout": 15, + "name": "Webhook Pipedream - " + new Date().toISOString(), + "url": this.http.endpoint, + }, + "relationships": { + "account": { + "data": { + "type": "accounts", + "id": this.accountId, + }, + }, + "events": { + "data": [ + { + "type": "event-definitions", + "id": this.getWebhookEventType(), + }, + ], + }, + }, + "type": "webhook-integrations", + }, + }, + }); + this._setWebhookId(data.id); + } catch (err) { + console.error("Failed to create webhook", err); + throw err; + } },
62-65
: Webhook deactivation should include error handlingThe deactivation logic correctly retrieves and removes the webhook, but lacks error handling.
Add error handling to gracefully handle webhook removal failures:
async deactivate() { const webhookId = this._getWebhookId(); - await this.scalr.removeWebhook(webhookId); + if (!webhookId) { + console.log("No webhook ID found to remove"); + return; + } + try { + await this.scalr.removeWebhook(webhookId); + } catch (err) { + console.error("Failed to remove webhook", err); + // Don't throw the error to allow component deactivation to complete + } },
67-69
: Run method should include error handlingThe run method passes the webhook payload to the emitEvent method but doesn't include error handling.
Add error handling to prevent component crashes:
async run(event) { - await this.emitEvent(event.body); + try { + await this.emitEvent(event.body); + } catch (err) { + console.error("Failed to emit event", err); + } },components/scalr/scalr.app.mjs (2)
21-40
: API request handling is properly structuredThe base URL construction and request handling are well-implemented with proper authentication and content type headers.
One small improvement would be to add error handling and more detailed error information:
async _makeRequest(opts = {}) { const { $ = this, path, headers, ...otherOpts } = opts; - return axios($, { - ...otherOpts, - url: this._baseUrl() + path, - headers: { - "Authorization": `Bearer ${this.$auth.api_token}`, - "Content-type": "application/vnd.api+json", - ...headers, - }, - }); + try { + return await axios($, { + ...otherOpts, + url: this._baseUrl() + path, + headers: { + "Authorization": `Bearer ${this.$auth.api_token}`, + "Content-type": "application/vnd.api+json", + ...headers, + }, + }); + } catch (error) { + const statusCode = error.response?.status; + const statusText = error.response?.statusText; + const responseData = error.response?.data; + throw new Error(`Scalr API request failed: ${statusCode} ${statusText}. Path: ${path}. ${JSON.stringify(responseData)}`); + } },
41-72
: API methods are well-organized and consistentThe API methods for webhook management, account fetching, and event retrieval are correctly implemented and follow a consistent pattern.
A minor enhancement would be to add JSDoc comments for better code documentation:
Add JSDoc comments to document method parameters and return values:
+ /** + * Create a new webhook integration + * @param {Object} args - Request arguments + * @returns {Promise<Object>} Response containing the created webhook data + */ async createWebhook({ ...args }) { return this._makeRequest({ path: "/integrations/webhooks", method: "post", ...args, }); }, + /** + * Remove a webhook integration by ID + * @param {string} webhookId - The ID of the webhook to remove + * @returns {Promise<Object>} Response from the delete operation + */ async removeWebhook(webhookId) { return this._makeRequest({ path: `/integrations/webhooks/${webhookId}`, method: "delete", }); },
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting
📒 Files selected for processing (6)
components/scalr/.gitignore
(0 hunks)components/scalr/scalr.app.mjs
(1 hunks)components/scalr/sources/common/common.mjs
(1 hunks)components/scalr/sources/new-run-completed/new-run-completed.mjs
(1 hunks)components/scalr/sources/new-run-errored/new-run-errored.mjs
(1 hunks)components/scalr/sources/new-run-needs-attention/new-run-needs-attention.mjs
(1 hunks)
💤 Files with no reviewable changes (1)
- components/scalr/.gitignore
✅ Files skipped from review due to trivial changes (2)
- components/scalr/sources/new-run-errored/new-run-errored.mjs
- components/scalr/sources/new-run-needs-attention/new-run-needs-attention.mjs
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: Verify TypeScript components
- GitHub Check: pnpm publish
- GitHub Check: Publish TypeScript components
- GitHub Check: Lint Code Base
🔇 Additional comments (1)
components/scalr/scalr.app.mjs (1)
3-19
: App definition and account option fetching are well-implementedThe Scalr app integration correctly defines its type, identifier, and properties. The accountId property with dynamic options fetching provides a good user experience.
@@ -1,16 +1,18 @@ | |||
{ | |||
"name": "@pipedream/scalr", | |||
"version": "0.0.2", | |||
"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.
Version should be increated to "0.0.3" rather than decreased to "0.0.1".
async options() { | ||
const { data: accounts } = await this.getAccounts(); | ||
return accounts.map((account) => ({ | ||
label: account.attributes.name, | ||
value: account.id, | ||
})); | ||
}, |
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.
We should use pagination in async options whenever possible. The documentation shows that the list accounts endpoint accepts page[number]
as a parameter.
async getWebhooks(args = {}) { | ||
return this._makeRequest({ | ||
path: "/integrations/webhooks", | ||
...args, | ||
}); | ||
}, |
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.
I don't see getWebhooks
being called anywhere.
async getEvents(args = {}) { | ||
return this._makeRequest({ | ||
path: "/event-definitions", | ||
...args, | ||
}); | ||
}, |
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.
I don't see getEvents
being called anywhere.
name: "New Run Completed (Instant)", | ||
version: "0.0.1", | ||
key: "scalr-new-run-completed", | ||
description: "Emit new event on each new completed run.", |
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.
I like to put in doc links if possible, especially when there aren't any other components with links to the docs.
description: "Emit new event on each new completed run.", | |
description: "Emit new event on each new completed run. [See the documentation](https://docs.scalr.io/reference/create_webhook_integration)", |
name: "New Run Errored (Instant)", | ||
version: "0.0.1", | ||
key: "scalr-new-run-errored", | ||
description: "Emit new event when a new run encountered an error.", |
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.
description: "Emit new event when a new run encountered an error.", | |
description: "Emit new event when a new run encountered an error. [See the documentation](https://docs.scalr.io/reference/create_webhook_integration)", |
name: "New Run Needs Attention (Instant)", | ||
version: "0.0.1", | ||
key: "scalr-new-run-needs-attention", | ||
description: "Emit new event when a new run needs attention.", |
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.
description: "Emit new event when a new run needs attention.", | |
description: "Emit new event when a new run needs attention. [See the documentation](https://docs.scalr.io/reference/create_webhook_integration)", |
WHY
Summary by CodeRabbit