-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New Components - guru #16623
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
New Components - guru #16623
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 3 Skipped Deployments
|
WalkthroughThis update introduces a new Guru integration package, implementing several actions and instant event sources for the Guru platform. It adds support for creating cards, linking tags, exporting cards to PDF, and emitting events for announcement reads, card creations, and card updates. Supporting utility modules, constants, and a comprehensive app definition are included. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Action
participant GuruApp
participant GuruAPI
User->>Action: Trigger (e.g., create card, add tag)
Action->>GuruApp: Call method (e.g., createCard, linkTagToCard)
GuruApp->>GuruAPI: Make API request
GuruAPI-->>GuruApp: Return response
GuruApp-->>Action: Return result
Action-->>User: Summary/confirmation
sequenceDiagram
participant Guru
participant WebhookSource
participant BaseModule
participant Platform
Guru-->>WebhookSource: Send webhook event (e.g., card-created)
WebhookSource->>BaseModule: Handle event (run method)
BaseModule->>Platform: Emit event with summary and timestamp
Assessment against linked issues
Suggested reviewers
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/guru/sources/common/base.mjsOops! Something went wrong! :( ESLint: 8.57.1 Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'jsonc-eslint-parser' imported from /eslint.config.mjs Tip ⚡️ Faster reviews with caching
Enjoy the performance boost—your workflow just got faster. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (4)
✨ 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 (
|
Sources - Announcement Read (Instant) - New Card (Instant) - Card Updated (Instant) Actions - Create Card - Add Tag To Card - Export Card To PDF
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: 6
🧹 Nitpick comments (8)
components/guru/sources/new-card-instant/test-event.mjs (1)
2-9
: Consider using different UUIDs for event, card, and collection identifiers.Currently, the same UUID "64753163-9817-4500-9651-96177c32e3d1" is used for the event ID, cardId, and collectionId. While functionally valid for testing, using distinct identifiers would make the test event more realistic and prevent potential confusion when referencing these values.
"id":"64753163-9817-4500-9651-96177c32e3d1", "eventType":"card-created", "user":"[email protected]", "eventDate":"2021-04-13T13:53:00.000+0000", "properties":{ - "cardId":"64753163-9817-4500-9651-96177c32e3d1", - "collectionId":"64753163-9817-4500-9651-96177c32e3d1", + "cardId":"a5b86572-1c3d-4e8f-9a7b-3d2e6f8c9d0e", + "collectionId":"b6c97683-2d4e-5f9a-0b8c-4e3f7a9d0b1f", "source": "UI"components/guru/common/utils.mjs (2)
1-24
: Add JSDoc comments to document the parseObject utility.This utility function handles various input formats well, but would benefit from documentation explaining its purpose and behavior.
+/** + * Parses JSON strings into objects safely, without throwing errors. + * When given an array, it attempts to parse each string element. + * When given a non-array string, it attempts to parse it as JSON. + * Returns the input unchanged if it's not a string or parsing fails. + * + * @param {any} obj - The input to parse (string, array, or any other type) + * @returns {any} - Parsed object(s) or the original input if parsing fails + */ export const parseObject = (obj) => { if (!obj) return undefined; if (Array.isArray(obj)) { return obj.map((item) => { if (typeof item === "string") { try { return JSON.parse(item); } catch (e) { return item; } } return item; }); } if (typeof obj === "string") { try { return JSON.parse(obj); } catch (e) { return obj; } } return obj; };
2-2
: Consider handling empty strings consistently.Currently, empty strings will return
undefined
because they're falsy in JavaScript. Consider whether empty strings should return themselves rather thanundefined
for more consistent behavior.- if (!obj) return undefined; + if (obj === null || obj === undefined) return undefined;components/guru/actions/add-tag-to-card/add-tag-to-card.mjs (1)
17-25
: Consider using singular naming for the tag property.The property is named "tags" but the description and implementation suggest it only accepts a single tag ID. Consider renaming this property to "tagId" to better match its usage and improve clarity.
- tags: { + tagId: { propDefinition: [ guru, - "tags", + "tagId", ], type: "string", label: "Tag", description: "The ID of the tag to add to the card", },Update the run method accordingly:
const response = await this.guru.linkTagToCard({ $, cardId: this.cardId, - tagId: this.tags, + tagId: this.tagId, }); - $.export("$summary", `Successfully linked tag ${this.tags} to card ${this.cardId}`); + $.export("$summary", `Successfully linked tag ${this.tagId} to card ${this.cardId}`);components/guru/sources/common/base.mjs (2)
19-21
: Add abstract method placeholdersYou're relying on child components to implement
getEventType()
andgetSummary()
methods, but they aren't defined here as abstract methods.Consider adding placeholder methods that throw errors to make it clear they need to be implemented:
getExtraData() { return {}; }, + getEventType() { + throw new Error("getEventType() must be implemented by the child component"); + }, + getSummary(body) { + throw new Error("getSummary(body) must be implemented by the child component"); + },
40-46
: Handle potential errors in event date parsingThe
Date.parse()
method will returnNaN
if the date string is invalid, which could lead to unexpected behavior.Add a fallback for the timestamp:
async run({ body }) { + const timestamp = Date.parse(body.eventDate) || Date.now(); this.$emit(body, { id: body.id, summary: this.getSummary(body), - ts: Date.parse(body.eventDate), + ts: timestamp, }); },components/guru/actions/create-card/create-card.mjs (1)
51-65
: Add error handling for API callThe current implementation doesn't handle potential API errors explicitly.
Wrap the API call in a try/catch block:
async run({ $ }) { + try { const response = await this.guru.createCard({ $, data: { preferredPhrase: this.title, content: this.content, shareStatus: this.shareStatus, collection: { id: this.collection, }, folderIds: parseObject(this.folderIds), tags: parseObject(this.tags)?.map((item) => ({ id: item, })), }, }); + $.export("$summary", `Created card "${this.title}" successfully`); + return response; + } catch (error) { + $.export("$summary", `Failed to create card: ${error.message}`); + throw error; + } - $.export("$summary", `Created card "${this.title}" successfully`); - return response; },components/guru/guru.app.mjs (1)
149-188
: Comprehensive set of API methods for listing resources and managing webhooks.The implementation includes methods for:
- Listing various Guru resources (collections, folders, tags, cards)
- Creating and deleting webhooks for the instant sources
The
listCards()
method correctly setsreturnFullResponse: true
to access the headers needed for pagination.A small improvement would be to add error handling for API responses, particularly for cases where expected data might be missing.
Consider adding basic error handling to the API methods, particularly for the list* methods that are used in property options, to gracefully handle empty responses or API errors:
listTags({ teamId, ...opts }) { return this._makeRequest({ path: `/teams/${teamId}/tagcategories`, ...opts, + }).catch(error => { + console.error(`Error listing tags: ${error.message}`); + return []; // Return empty array to prevent options loader failures + }); }); }
📜 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 (16)
components/guru/.gitignore
(0 hunks)components/guru/actions/add-tag-to-card/add-tag-to-card.mjs
(1 hunks)components/guru/actions/create-card/create-card.mjs
(1 hunks)components/guru/actions/export-card-to-pdf/export-card-to-pdf.mjs
(1 hunks)components/guru/app/guru.app.ts
(0 hunks)components/guru/common/constants.mjs
(1 hunks)components/guru/common/utils.mjs
(1 hunks)components/guru/guru.app.mjs
(1 hunks)components/guru/package.json
(1 hunks)components/guru/sources/announcement-read-instant/announcement-read-instant.mjs
(1 hunks)components/guru/sources/announcement-read-instant/test-event.mjs
(1 hunks)components/guru/sources/card-updated-instant/card-updated-instant.mjs
(1 hunks)components/guru/sources/card-updated-instant/test-event.mjs
(1 hunks)components/guru/sources/common/base.mjs
(1 hunks)components/guru/sources/new-card-instant/new-card-instant.mjs
(1 hunks)components/guru/sources/new-card-instant/test-event.mjs
(1 hunks)
💤 Files with no reviewable changes (2)
- components/guru/.gitignore
- components/guru/app/guru.app.ts
🧰 Additional context used
🪛 GitHub Check: Lint Code Base
components/guru/sources/card-updated-instant/card-updated-instant.mjs
[warning] 7-7:
Source names should start with "New". See https://pipedream.com/docs/components/guidelines/#source-name
🔇 Additional comments (15)
components/guru/common/constants.mjs (1)
1-4
: Clean, well-defined constant for share status options.The constant clearly defines the available share status options for Guru cards, which helps maintain consistency throughout the integration.
components/guru/package.json (3)
3-3
: Version bump to 0.1.0 appropriately reflects new features.The version increase from 0.0.3 to 0.1.0 correctly follows semantic versioning for the addition of new components.
5-5
: Simplified main entry point location.Changing the main entry point from "dist/app/guru.app.mjs" to "guru.app.mjs" simplifies imports and file structure.
15-16
: Added dependency on Pipedream platform package.Adding the @pipedream/platform dependency formalizes the integration's reliance on the Pipedream framework.
components/guru/sources/announcement-read-instant/test-event.mjs (1)
1-11
: Test event structure looks good and matches expected Guru webhook payload.The test event object correctly models a Guru announcement read event with the required properties:
- Unique id field
- Proper eventType ("alert-read")
- User identification
- Timestamp in ISO 8601 format
- Properties containing relevant IDs for the card and collection
This test fixture will work well for simulating webhook payloads during development and testing.
components/guru/sources/card-updated-instant/test-event.mjs (1)
1-11
: Test event structure looks good and matches expected Guru webhook payload.The test event object correctly models a Guru card updated event with the required properties:
- Unique id field
- Proper eventType ("card-updated")
- User identification
- Timestamp in ISO 8601 format
- Properties containing relevant IDs for the card and collection
This test fixture will work well for simulating webhook payloads during development and testing.
components/guru/actions/add-tag-to-card/add-tag-to-card.mjs (2)
1-2
: Import looks good.The module correctly imports the Guru app to utilize its API methods.
3-26
: Component definition looks good with clear metadata and properties.The action component is well structured with:
- Descriptive name and key
- Helpful description with documentation link
- Appropriate version for a new component (0.0.1)
- Correctly typed as "action"
- Well-defined props using propDefinitions from the Guru app
components/guru/sources/card-updated-instant/card-updated-instant.mjs (3)
1-3
: Imports look good.The module correctly imports the common base functionality and sample event for testing.
12-20
: Methods implementation looks good.The source component correctly:
- Extends common methods from the base
- Specifies the event type as "card-updated"
- Provides a clear summary format with the card ID
The implementation follows best practices for extending the base component.
21-22
: Sample emitter assignment looks good.Correctly assigns the imported test event as the sample emitter for this source.
components/guru/sources/new-card-instant/new-card-instant.mjs (1)
1-22
: Looks good!The implementation correctly extends the base component and implements the required methods. The summary clearly identifies the new card by its ID.
components/guru/sources/announcement-read-instant/announcement-read-instant.mjs (1)
1-22
: Clean implementation of an instant Guru announcement read source component.This component extends a common base module and correctly implements the specific functionality for handling announcement read events. The component properly defines:
- A unique key identifier
- Clear name and description with documentation link
- Appropriate dedupe strategy
- Required methods for event handling:
getEventType()
that returns the correct event type "alert-read"getSummary()
to format the event outputThe implementation follows the expected pattern for Pipedream instant source components.
components/guru/guru.app.mjs (2)
1-104
: Well-structured app definition with comprehensive property definitions.The app module provides a clean implementation of property definitions with async option loaders for collections, folders, tags, and cards. The authentication setup correctly uses the username and API key from app authentication.
The property definitions follow best practices:
- Each includes descriptive labels and descriptions
- Option loaders correctly handle API responses and transform them to the expected format
- The card ID option loader properly implements pagination using the Link header
105-148
: Well-implemented API request methods with proper encapsulation.The implementation provides:
- A generic
_makeRequest()
method that encapsulates common request logic- Specific methods for user info, card creation, and tag linking
- Proper handling of HTTP methods, paths, and additional options
The
exportCardToPdf()
method correctly setsresponseType: "stream"
to handle binary data for PDF downloads.
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 @luancazarine lgtm! Just a minor change. Ready for QA!
Co-authored-by: Jorge Cortes <[email protected]>
/approve |
Resolves #13217.
Summary by CodeRabbit
New Features
Improvements
Chores