Skip to content

Conversation

luancazarine
Copy link
Collaborator

@luancazarine luancazarine commented Jan 2, 2025

Resolves #13261.

Summary by CodeRabbit

  • New Features

    • Added support for creating contacts in Alegra
    • Added support for creating invoices in Alegra
    • Added functionality to find contacts
    • Introduced new webhook and event sources for clients, invoices, and items
    • Added new event sources for handling new client and new invoice events
    • Implemented a new event source for handling new items
  • Improvements

    • Enhanced Alegra app configuration with new methods and properties
    • Added utility functions for parsing and handling data
    • Implemented comprehensive error handling for API interactions
    • Standardized constants for various options and limits throughout the application
  • Chores

    • Created initial package configuration for Alegra integration
    • Added constants and utility modules to support the integration

Copy link

vercel bot commented Jan 2, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs-v2 ⬜️ Ignored (Inspect) Visit Preview Jan 7, 2025 3:21am
pipedream-docs ⬜️ Ignored (Inspect) Jan 7, 2025 3:21am
pipedream-docs-redirect-do-not-edit ⬜️ Ignored (Inspect) Jan 7, 2025 3:21am

@luancazarine luancazarine added the ai-assisted Content generated by AI, with human refinement and modification label Jan 2, 2025
Copy link
Contributor

coderabbitai bot commented Jan 2, 2025

Walkthrough

This pull request introduces a comprehensive set of components for the Alegra application, including actions for creating contacts and invoices, finding contacts, and webhook sources for tracking new clients, invoices, and items. The changes establish a robust integration with the Alegra API, providing methods for creating, searching, and monitoring various business entities with flexible configuration options.

Changes

File Change Summary
components/alegra/actions/create-contact/create-contact.mjs New module for creating contacts with comprehensive properties and an async run method
components/alegra/actions/create-invoice/create-invoice.mjs New module for generating invoices with detailed configuration options
components/alegra/actions/find-contact/find-contact.mjs New action to search for contacts using query parameters
components/alegra/alegra.app.mjs Added multiple prop definitions and API interaction methods
components/alegra/common/constants.mjs Introduced new constants for types, statuses, and options
components/alegra/common/utils.mjs Added parseObject utility function
components/alegra/sources/* Created webhook sources for new clients, invoices, and items

Assessment against linked issues

Objective Addressed Explanation
Create Contact Action [#13261]
Create Invoice Action [#13261]
Find Contact Action [#13261]
Webhook Sources (new-client, new-invoice, new-item) [#13261]

Possibly related PRs

Suggested Reviewers

  • jcortes

Poem

🐰 Hop, hop, hooray! Alegra's here to play!
Contacts, invoices, all in a row
Webhooks dancing, data's gonna flow
With CodeRabbit's magic, integration's bright
Alegra's components are looking just right! 🌟


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Sources
 - New Client (Instant)
 - New Invoice (Instant)
 - New Item (Instant)

Actions
 - Create Contact
 - Create Invoice
 - Find Contact
@luancazarine luancazarine marked this pull request as ready for review January 6, 2025 14:48
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 (11)
components/alegra/sources/new-client-instant/new-client-instant.mjs (1)

1-3: Consider validating the necessity of sampleEmit import.
If sampleEmit is solely used for testing purposes, consider importing it conditionally or extracting it to a test-only module to keep production code lean.

components/alegra/actions/find-contact/find-contact.mjs (2)

1-2: Confirm app instance name matches naming conventions.
The app is imported as alegra from "../../alegra.app.mjs". In some codebases, the pattern is to use uppercase or a more descriptive name for clarity (e.g., AlegraApp).


18-29: Leverage specialized error handling.
Currently, any network or usage error either fails silently or is caught by the outer pipeline. Consider adding user-friendly error messages or fallback logic.

components/alegra/sources/new-item-instant/test-event.mjs (1)

32-55: Check inventory and subitem structures.
The variantAttributes, itemVariants, and subitems values are null. If your code expects arrays or objects, ensure it safely handles null values to avoid runtime errors.

components/alegra/sources/new-invoice-instant/test-event.mjs (1)

4-23: Use descriptive names for invoice properties.
Properties like anotation and observations can become confusing. Consider renaming or clarifying their distinction in your code/documentation.

components/alegra/sources/common/base.mjs (2)

3-9: Use descriptive component naming.
Although the default export is succinct, consider adding a clear name or key property for better readability and identification in logs or developer tools.


16-18: Placeholder getExtraData() method.
This returns an empty object for now. If your future roadmap includes optional query params or additional event data, you can expand this method.

components/alegra/actions/create-contact/create-contact.mjs (1)

8-14: Action metadata is descriptive.
Use of key, name, and description strongly conveys the purpose of this action.

components/alegra/alegra.app.mjs (3)

7-151: Prop definitions with pagination.
All properties with an options({ page }) function effectively handle pagination for listing. The repeated structure is consistent—suggest factoring out a shared function to reduce duplication.


175-237: Expanded set of methods for Alegra API coverage.
You cover multiple resources (contacts, invoices, sellers, etc.). Consider adding robust error handling for each request to catch network or authentication failures.


238-242: Webhook deletion method finalizes coverage.
Completes the webhook lifecycle. Again, consider checking for a valid webhookId prior to deletion.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 303d3c8 and ce8519a.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (14)
  • components/alegra/actions/create-contact/create-contact.mjs (1 hunks)
  • components/alegra/actions/create-invoice/create-invoice.mjs (1 hunks)
  • components/alegra/actions/find-contact/find-contact.mjs (1 hunks)
  • components/alegra/alegra.app.mjs (1 hunks)
  • components/alegra/common/constants.mjs (1 hunks)
  • components/alegra/common/utils.mjs (1 hunks)
  • components/alegra/package.json (1 hunks)
  • components/alegra/sources/common/base.mjs (1 hunks)
  • components/alegra/sources/new-client-instant/new-client-instant.mjs (1 hunks)
  • components/alegra/sources/new-client-instant/test-event.mjs (1 hunks)
  • components/alegra/sources/new-invoice-instant/new-invoice-instant.mjs (1 hunks)
  • components/alegra/sources/new-invoice-instant/test-event.mjs (1 hunks)
  • components/alegra/sources/new-item-instant/new-item-instant.mjs (1 hunks)
  • components/alegra/sources/new-item-instant/test-event.mjs (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • components/alegra/sources/new-client-instant/test-event.mjs
  • components/alegra/package.json
🔇 Additional comments (38)
components/alegra/common/constants.mjs (5)

1-2: Confirm the default pagination limit.
It's great that you've introduced a LIMIT constant for pagination. However, verify if 30 is the best default for larger datasets.


3-6: Naming consistency looks good.
The TYPE_OPTIONS array follows self-explanatory naming, helping standardize contact types. No issues spotted.


8-11: Consistent naming for status options.
The STATUS_OPTIONS array clearly distinguishes "active" from "inactive" statuses. This is straightforward and maintainable.


13-16: Expand INVOICE_STATUS_OPTIONS if needed.
Currently supports "draft" and "open" statuses. If the Alegra API also expects additional statuses (e.g., "closed"), consider adding them here.


18-25: Future-proof your periodicity options.
The array of PERIODICITY_OPTIONS covers many intervals. This is well-defined, but confirm all required intervals are captured.

components/alegra/common/utils.mjs (4)

1-2: Confirm desired fallback behavior.
Returning undefined for a falsy obj might be intentional. Ensure this aligns with usage patterns in your codebase.


4-14: Proper JSON parsing for array items.
Parses string items within arrays gracefully. This approach is good for flexible data handling.


16-22: Graceful handling of string inputs.
Catches JSON parsing errors and returns the original string, ensuring robust fallback behavior for unexpected inputs.


23-24: Clean final return logic.
Returning the original obj is straightforward and ensures minimal transformation.

components/alegra/sources/new-item-instant/new-item-instant.mjs (4)

4-12: Well-structured source definition.
Your source object composition (merging common plus the unique config) is a standard, maintainable approach.


13-16: Clear event naming.
Returning "new-item" from getEventType() is explicit and easy to reference.


17-20: Meaningful event summary.
Uses item.name to create a succinct, user-friendly summary. Ensure that item.name is always available or handle null/undefined names for resiliency.


21-21: Sample event included.
Including a sample event is helpful for testing and demonstration. No issues spotted.

components/alegra/sources/new-invoice-instant/new-invoice-instant.mjs (4)

4-12: Consistent source structure.
Follows the same pattern as other instant sources, promoting consistency across your codebase.


13-16: Appropriate event naming.
"new-invoice" is self-descriptive and consistent with other sources.


17-20: Concise invoice summary.
Concise messaging for newly created invoices. Consider confirming that invoice.id always exists or handle edge cases gracefully.


21-21: Sample event fosters clarity.
Providing a realistic sample in sampleEmit helps users understand the event's structure and data fields.

components/alegra/sources/new-client-instant/new-client-instant.mjs (1)

4-22: Handle missing client.email in getSummary.
If client.email is undefined or null, the template string could produce an undefined result. You might want to provide a fallback or validation.

components/alegra/actions/find-contact/find-contact.mjs (1)

3-17: Ensure alignment with prop definitions.
The query prop references "query" in propDefinitions, so verify that alegra.app.mjs indeed provides a matching definition and handles non-string inputs gracefully.

components/alegra/sources/new-item-instant/test-event.mjs (2)

1-3: Review event naming consistency.
The subject is "new-item". Ensure this naming is used consistently across your event source, emitter, and consumer logic.


4-31: Confirm correct usage of alphanumeric and non-ASCII characters.
The item name includes special characters: "Un Ítem / S". Verify that Alegra's API and your database properly handle UTF-8 or extended character sets.

components/alegra/sources/new-invoice-instant/test-event.mjs (2)

1-3: Enforce consistent event naming.
The subject is "new-invoice". Confirm that any consumer code is listening explicitly for "new-invoice" events.


24-49: Validate nested objects in the invoice structure.
The invoice references multiple nested IDs (estimate, costCenter, remission, etc.). Verify that each referenced entity exists or handle potential 404s or missing data.

components/alegra/sources/common/base.mjs (5)

1-2: Good initial import.
You correctly import the alegra app reference, ensuring that the source can access necessary methods from alegra.app.mjs.


10-15: Database methods follow best practices.
Storing and retrieving hookId in the DB is straightforward and maintainable, ensuring data is persisted.


21-29: Webhook creation logic is clean.
The method splits the HTTP endpoint from an HTTPS-based string to send to the API. Ensure you handle edge cases if the URL scheme doesn't match “https://”.


30-34: Webhook deletion uses the stored ID.
This approach ensures you clean up properly. Consider validating the webhookId before sending the delete request to avoid potential undefined references.


35-47: Event emission logic is clear.
You parse the body, confirm the presence of a message field, and then derive the model data. The consistent use of client, item, or invoice is well-structured and easy to extend.

components/alegra/actions/create-contact/create-contact.mjs (3)

1-7: Imports and helper usage are well-structured.
Using parseObject from ../../common/utils.mjs ensures consistent conversion and avoids JSON parsing errors.


15-138: Comprehensive prop definitions.
You’ve included a wide range of contact fields (phones, emails, addresses, etc.). This approach provides flexibility but can be prone to user misconfiguration.

Consider adding client-side validation or default values for critical fields.


139-171: Structured data construction for contact creation.
You assemble nested objects (address, accounting, etc.) clearly. Good use of optional chaining with parse helpers in case some fields are not present.

components/alegra/alegra.app.mjs (2)

1-2: Initial setup for axios and constants.
Pulling in axios from @pipedream/platform and the LIMIT constant suggests pagination is managed consistently across the codebase.


153-174: Authentication and base URL are well-defined.
The _baseUrl() and _auth() methods help maintain clarity and reduce code duplication.

components/alegra/actions/create-invoice/create-invoice.mjs (5)

1-2: ConfigurationError import is apt.
This ensures that helpful user-facing errors get raised for misconfigurations.


3-7: Constants for invoice creation.
Importing INVOICE_STATUS_OPTIONS and PERIODICITY_OPTIONS ensures consistent usage of recognized enumerations.


8-13: Clear action metadata.
Providing key, name, description, version, and type helps keep the code self-documenting.


14-153: Well-defined invoice props.
Users can specify a broad range of invoice characteristics (status, items, client, payments, etc.), offering a complete solution. Be mindful of large user input arrays to avoid performance bottlenecks.


154-192: Robust error handling in the run method.
You catch potential exceptions and throw a descriptive ConfigurationError. This is excellent for clarity. Consider adding detailed logging around partial invoice creation states if the API partially completes the request.

GTFalcao
GTFalcao previously approved these changes Jan 6, 2025
Copy link
Collaborator

@GTFalcao GTFalcao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ce8519a and d4113b7.

📒 Files selected for processing (1)
  • components/alegra/actions/create-invoice/create-invoice.mjs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: pnpm publish
  • GitHub Check: Verify TypeScript components
  • GitHub Check: Lint Code Base
  • GitHub Check: Publish TypeScript components
🔇 Additional comments (1)
components/alegra/actions/create-invoice/create-invoice.mjs (1)

11-11: Enhance the documentation link with more context

Consider adding more context about what users can expect to find in the documentation link.

-  description: "Creates a new invoice in Alegra. [See the documentation](https://developer.alegra.com/reference/post_invoices)",
+  description: "Creates a new invoice in Alegra. [See the API documentation for all available fields and options](https://developer.alegra.com/reference/post_invoices)",

@luancazarine
Copy link
Collaborator Author

/approve

@luancazarine luancazarine merged commit fed27d2 into master Jan 7, 2025
11 checks passed
@luancazarine luancazarine deleted the issue-13261 branch January 7, 2025 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ai-assisted Content generated by AI, with human refinement and modification
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Components] alegra
3 participants