-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - cogmento #16321
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 - cogmento #16321
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 3 Skipped Deployments
|
|
""" WalkthroughThis update introduces a new integration for Cogmento CRM, adding both polling sources and actions. The sources emit events for new contacts, deals, and tasks by polling the Cogmento API, with a shared base module handling incremental event processing. The actions enable creating contacts, deals, and tasks via API calls, supporting various required and optional fields. The Cogmento app module is expanded to handle authentication, API requests, pagination, and dynamic property options. The package metadata is updated to include necessary dependencies. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Action
participant CogmentoApp
participant CogmentoAPI
User->>Action: Trigger create-contact/deal/task
Action->>CogmentoApp: Call createContact/Deal/Task
CogmentoApp->>CogmentoAPI: POST /contacts|deals|tasks
CogmentoAPI-->>CogmentoApp: Response
CogmentoApp-->>Action: Return result
Action-->>User: Export summary/result
sequenceDiagram
participant Source
participant CogmentoApp
participant CogmentoAPI
participant EventStream
Source->>CogmentoApp: listContacts/Deals/Tasks (with timestamp)
CogmentoApp->>CogmentoAPI: GET /contacts|deals|tasks
CogmentoAPI-->>CogmentoApp: Return items
CogmentoApp-->>Source: Items list
Source->>EventStream: Emit new events for items with new timestamps
Assessment against linked issues
Suggested labels
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/cogmento/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 📜 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 (3)
🪧 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: 1
🧹 Nitpick comments (10)
components/cogmento/actions/create-contact/create-contact.mjs (1)
64-94: Consider adding input validation and error handling.While the implementation correctly builds the channels array and calls the API, it lacks validation for email format and phone numbers. Consider adding validation for these fields and specific error handling for common failure scenarios.
Also, there's no feedback if neither email nor phone is provided - consider adding a warning if both are missing, as contacts typically need at least one communication channel.
async run({ $ }) { const channels = []; + + // Validate email format if provided + if (this.email && !/^\S+@\S+\.\S+$/.test(this.email)) { + throw new Error("Invalid email format"); + } + if (this.email) { channels.push({ channel_type: "Email", value: this.email, }); } if (this.phone) { channels.push({ channel_type: "Phone", value: this.phone, }); } + + // Warn if no communication channels provided + if (channels.length === 0) { + $.export("warning", "Creating contact without any communication channels (email or phone)"); + } const response = await this.cogmento.createContact({ $, data: { first_name: this.firstName, last_name: this.lastName, channels, description: this.description, tags: this.tags, do_not_call: this.doNotCall, do_not_text: this.doNotText, do_not_email: this.doNotEmail, }, + // Add specific error handling + }).catch((error) => { + if (error.response?.status === 409) { + throw new Error(`Contact creation failed: A contact with this information may already exist.`); + } + throw error; }); $.export("$summary", `Successfully created contact: ${this.firstName} ${this.lastName}`); return response; },components/cogmento/sources/new-deal-created/new-deal-created.mjs (1)
13-15: Consider handling advanced filtering or pagination.
Usingthis.cogmento.listDealsdirectly works for smaller data sets, but if the remote API returns many deals, you may need to incorporate pagination or filtering at the source level for efficiency.components/cogmento/actions/create-deal/create-deal.mjs (1)
9-54: Enhance property validations for date and numeric fields.
Although it's common to keep them as plain strings in Pipedream, consider robust validation forcloseDate(to ensure correct YYYY-MM-DD format) andamount(to prevent invalid or negative values). This can reduce user errors.components/cogmento/actions/create-task/create-task.mjs (1)
9-49: Consider adding date format validations fordueDate.
The props are well-defined, but if users supply an incorrect date format, the API might reject the request or produce silent errors. Implementing a stricter validation or user guidance for the YYYY-MM-DD format may help.components/cogmento/cogmento.app.mjs (3)
7-79: Allow listing all users foruserIdsif required.
Currently,userIdsonly returns the single current user. If multi-user assignment is desired, you might need to fetch the entire user list from Cogmento.
80-97: Consider adding timeouts or dedicated error handling in_makeRequest.
Relying on default Axios behavior is fine for many scenarios, but specifying request timeouts or refining error handling (for example, to parse known error codes) can improve API reliability.
149-177: Validate pagination edge cases inpaginatemethod.
The loop relies onresultsandtotalfrom the API. If either is missing or zero, ensure there's no unexpected infinite loop. Also confirm that partial results are handled gracefully.components/cogmento/sources/common/base.mjs (3)
41-66: Robust event processing implementation.The event processing logic effectively handles pagination and timestamp tracking for incremental processing. The code properly emits new events and updates the last processed timestamp.
However, there's one improvement to consider: add a safeguard against empty responses or API errors.
async processEvent(max) { const lastTs = this._getLastTs(); let maxTs = lastTs; const resourceFn = this.getResourceFn(); const args = this.getArgs(); const tsField = this.getTsField(); + try { const items = this.cogmento.paginate({ fn: resourceFn, args, max, }); for await (const item of items) { const ts = Date.parse(item[tsField]); if (ts >= lastTs) { const meta = this.generateMeta(item); this.$emit(item, meta); maxTs = Math.max(ts, maxTs); } else { break; } } this._setLastTs(maxTs); + } catch (error) { + console.error("Error processing Cogmento events:", error); + // Optionally emit an error event if needed + } },
79-81: Consider adding pagination limit to run method.The
run()method callsprocessEvent()without specifying a maximum number of events to process, unlike thedeploy()hook which processes up to 25 events. For consistent behavior and to prevent excessive API calls, consider adding a reasonable limit.async run() { - await this.processEvent(); + await this.processEvent(100); // Process up to 100 events per run },
25-30: Consider more flexible sorting configuration.The
getArgs()method hardcodes sorting by the timestamp field in descending order. For more flexibility, consider allowing subclasses to override or extend this behavior.getArgs() { + const baseArgs = { params: { sort: `-${this.getTsField()}`, }, + }; + return this.extendArgs ? this.extendArgs(baseArgs) : baseArgs; }, + extendArgs(args) { + // Subclasses can override this method to extend the arguments + return args; + },
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (9)
components/cogmento/actions/create-contact/create-contact.mjs(1 hunks)components/cogmento/actions/create-deal/create-deal.mjs(1 hunks)components/cogmento/actions/create-task/create-task.mjs(1 hunks)components/cogmento/cogmento.app.mjs(1 hunks)components/cogmento/package.json(2 hunks)components/cogmento/sources/common/base.mjs(1 hunks)components/cogmento/sources/new-contact-created/new-contact-created.mjs(1 hunks)components/cogmento/sources/new-deal-created/new-deal-created.mjs(1 hunks)components/cogmento/sources/new-task-created/new-task-created.mjs(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: pnpm publish
- GitHub Check: Verify TypeScript components
- GitHub Check: Publish TypeScript components
🔇 Additional comments (15)
components/cogmento/package.json (2)
3-3: Version bump looks appropriate.The version increment from 0.0.1 to 0.1.0 follows semantic versioning, indicating new features without breaking changes. This aligns with the introduction of new Cogmento components.
14-17: Dependencies addition is appropriate.Adding the @pipedream/platform dependency is necessary for Pipedream components to leverage common utilities and interfaces. The caret version constraint (^3.0.3) allows for compatible updates.
components/cogmento/sources/new-task-created/new-task-created.mjs (2)
3-10: Component configuration looks good.The component metadata is well-defined with a descriptive name, appropriate key, documentation link, and version set to 0.0.1 for a new component. The "dedupe: unique" setting will ensure no duplicate task events are emitted.
11-19: Method implementations are clear and focused.The component effectively extends the common base by overriding only the necessary methods:
getResourceFn()returns the appropriate API method for tasksgetSummary()provides a clear, user-friendly summary formatThis approach promotes code reuse and consistency across Cogmento source components.
components/cogmento/sources/new-contact-created/new-contact-created.mjs (2)
3-10: Component configuration is well-structured.The component metadata follows the same pattern as other Cogmento sources, with appropriate key, name, description with documentation link, version, and deduplication strategy.
11-19: Method implementations maintain consistency with other source components.The component correctly extends the common base by implementing:
getResourceFn()to return the contact-specific API methodgetSummary()to format contact creation events consistentlyThis implementation maintains the pattern established across Cogmento source components.
components/cogmento/actions/create-contact/create-contact.mjs (2)
3-9: Action metadata is well-defined.The component has appropriate key, name, description with documentation link, version, and type settings. The version 0.0.1 is correct for a new component.
9-63: Props are comprehensive and well-documented.The component defines a good set of props for contact creation with:
- Required fields (first name, last name)
- Optional fields (email, phone, description, tags)
- Boolean preferences (do not call, text, email)
Each prop has clear labels and descriptions to guide users.
components/cogmento/sources/new-deal-created/new-deal-created.mjs (3)
1-2: Reusing common base source logic is consistent.
Extending the sharedcommonmodule is a good approach for deduplicating code and ensuring consistent polling/event logic.
3-10: Source metadata appears sufficiently descriptive.
The structure (key, name, description, version, type, dedupe) is aligned with conventional Pipedream source definitions, aiding maintainability and clarity.
16-18: Verify the presence oftitlefrom the API.
Ifitem.titleis missing or undefined, the summary string might look awkward. You may want to add fallback logic or confirm thattitleis always present in the Cogmento API response.components/cogmento/actions/create-deal/create-deal.mjs (1)
55-74: Confirm proper error handling for invalidamountinputs.
Castingthis.amountto a number (+this.amount) could yieldNaNwhen the input is invalid, causing unexpected behavior increateDeal. Ensure that the API or the code gracefully handles such invalid values.components/cogmento/actions/create-task/create-task.mjs (1)
51-71: Handle partial associations for tasks.
Assigning users, linking deals, or linking contacts is optional. When these fields are absent or invalid, ensure the API response is handled—either letting errors bubble up or providing user feedback.components/cogmento/cogmento.app.mjs (1)
98-148: Double-check the CRUD methods for error cases.
If the Cogmento API returns 4xx or 5xx errors, ensure that the calling code knows how to handle them. Consider logging or re-throwing useful error messages for debugging.components/cogmento/sources/common/base.mjs (1)
1-82: Well-structured base component with reusability in mind.The base component is well-designed with:
- Proper state management for tracking processed events
- Abstract methods that enforce implementation in subclasses
- Pagination handling for efficient API consumption
- Timestamp-based sorting and filtering
- Clear separation of concerns between base and child components
This structure will promote consistency across the Cogmento integration sources and reduce code duplication.
luancazarine
left a comment
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 @michelle0927, LGTM! Ready for QA!
Resolves #16292
Summary by CodeRabbit
New Features
Chores