Skip to content

New Components - dolibarr #17030

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

New Components - dolibarr #17030

wants to merge 8 commits into from

Conversation

michelle0927
Copy link
Collaborator

@michelle0927 michelle0927 commented Jun 6, 2025

Resolves #16920

Summary by CodeRabbit

  • New Features
    • Introduced integration with Dolibarr, enabling users to create orders, third parties, and users directly from the platform.
    • Added event sources that emit notifications when new invoices, orders, or third parties are created in Dolibarr.
    • Enhanced user experience with dynamic property options and sample event data for easier setup and testing.
  • Chores
    • Updated package dependencies and versioning for improved compatibility.

Copy link

vercel bot commented Jun 6, 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 Jun 6, 2025 8:00pm
pipedream-docs ⬜️ Ignored (Inspect) Jun 6, 2025 8:00pm
pipedream-docs-redirect-do-not-edit ⬜️ Ignored (Inspect) Jun 6, 2025 8:00pm

Copy link
Contributor

coderabbitai bot commented Jun 6, 2025

"""

Walkthrough

This update introduces a comprehensive Dolibarr integration, adding new actions for creating users, third parties, and orders, as well as sources for emitting events on new invoices, orders, and third parties. It includes utility functions, a robust API client, and base classes for event polling, along with sample event data for testing.

Changes

File(s) Change Summary
components/dolibarr/actions/create-order/create-order.mjs New action: Create Order in Dolibarr.
components/dolibarr/actions/create-thirdparty/create-thirdparty.mjs New action: Create Third Party in Dolibarr.
components/dolibarr/actions/create-user/create-user.mjs New action: Create User in Dolibarr.
components/dolibarr/common/utils.mjs Added utility function parseObject for recursive JSON parsing.
components/dolibarr/dolibarr.app.mjs Expanded Dolibarr app: added API client, prop definitions, CRUD and pagination methods.
components/dolibarr/package.json Updated version to 0.1.0; added @pipedream/platform dependency.
components/dolibarr/sources/common/base.mjs New base component for Dolibarr polling sources with event processing and deduplication.
components/dolibarr/sources/new-invoice-created/new-invoice-created.mjs New source: emits event on new invoice creation.
components/dolibarr/sources/new-invoice-created/test-event.mjs Added sample event object for invoice creation.
components/dolibarr/sources/new-order-created/new-order-created.mjs New source: emits event on new order creation.
components/dolibarr/sources/new-order-created/test-event.mjs Added sample event object for order creation.
components/dolibarr/sources/new-thirdparty-created/new-thirdparty-created.mjs New source: emits event on new third party creation.
components/dolibarr/sources/new-thirdparty-created/test-event.mjs Added sample event object for third party creation.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Action
    participant DolibarrApp
    participant DolibarrAPI

    User->>Action: Trigger (e.g., Create Order)
    Action->>DolibarrApp: Call createOrder() with props
    DolibarrApp->>DolibarrAPI: POST /orders (with data)
    DolibarrAPI-->>DolibarrApp: API response
    DolibarrApp-->>Action: Return response
    Action-->>User: Output result
Loading
sequenceDiagram
    participant Source
    participant DolibarrApp
    participant DolibarrAPI
    participant EventStream

    loop Polling Interval
        Source->>DolibarrApp: list<Resource>() (e.g., listOrders)
        DolibarrApp->>DolibarrAPI: GET /<resource>
        DolibarrAPI-->>DolibarrApp: Resource list
        DolibarrApp-->>Source: Return items
        Source->>EventStream: Emit new events for new items
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Create User action: create a new user with required and optional fields (#16920)
Create Third Party action: create a new third party with required name and contact info (#16920)
Create Order action: create a new order with third-party ID, products/services, and order date (#16920)
New Invoice/Order/Third Party sources: emit events on creation (polling, not webhook) (#16920)
Provide sample/test event data for each source (#16920)

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
None found

Suggested labels

ai-assisted

Poem

In Dolibarr’s fields, new features bloom,
Orders, users, third parties zoom!
Events now sprout with every poll,
Utilities help to parse it all.
With sample data, tests are bright—
The rabbit hops with pure delight! 🐇✨
"""

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

components/dolibarr/dolibarr.app.mjs

Oops! Something went wrong! :(

ESLint: 8.57.1

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'jsonc-eslint-parser' imported from /eslint.config.mjs
at Object.getPackageJSONURL (node:internal/modules/package_json_reader:255:9)
at packageResolve (node:internal/modules/esm/resolve:767:81)
at moduleResolve (node:internal/modules/esm/resolve:853:18)
at defaultResolve (node:internal/modules/esm/resolve:983:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:799:12)
at #cachedDefaultResolve (node:internal/modules/esm/loader:723:25)
at ModuleLoader.resolve (node:internal/modules/esm/loader:706:38)
at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:307:38)
at #link (node:internal/modules/esm/module_job:170:49)


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d2d89d4 and 1e20eb1.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (1)
  • components/dolibarr/dolibarr.app.mjs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: pnpm publish
🔇 Additional comments (4)
components/dolibarr/dolibarr.app.mjs (4)

1-3: LGTM! Clean imports and constants.

The imports are appropriate for a Pipedream component and the default limit constant is well-defined.


7-67: Well-structured prop definitions with async options.

The property definitions are comprehensive and follow good patterns:

  • Consistent structure across all props
  • Proper use of async options with pagination
  • Appropriate default values and descriptions
  • Good use of optional chaining for safety

69-82: Solid foundation methods for API communication.

The _baseUrl() and _makeRequest() methods provide a clean abstraction for API calls with proper authentication header injection.


83-139: Comprehensive API method coverage.

The API methods follow a consistent pattern and cover the essential CRUD operations for the Dolibarr integration. Good separation between list and create operations.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need 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)

  • @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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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.

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: 9

🧹 Nitpick comments (8)
components/dolibarr/common/utils.mjs (1)

1-27: Consider adding safeguards against circular references and improving error handling.

The parseObject function is well-structured but could benefit from additional robustness:

  1. Circular reference protection: The recursive nature could cause infinite loops with circular object references
  2. Input validation: Consider adding type checking for edge cases
  3. More descriptive naming: parseObject could be more specific, like parseAndNormalizeInput or recursiveJsonParse

Consider this enhanced version with circular reference protection:

-export function parseObject(obj) {
+export function parseObject(obj, seen = new WeakSet()) {
   if (!obj) {
     return {};
   }
   if (typeof obj === "string") {
     try {
       return JSON.parse(obj);
     } catch (e) {
       return obj;
     }
   }
   if (Array.isArray(obj)) {
-    return obj.map(parseObject);
+    return obj.map(item => parseObject(item, seen));
   }
   if (typeof obj === "object") {
+    if (seen.has(obj)) {
+      return obj; // Return original object to prevent infinite recursion
+    }
+    seen.add(obj);
     return Object.fromEntries(
       Object.entries(obj).map(([
         key,
         value,
       ]) => [
         key,
-        parseObject(value),
+        parseObject(value, seen),
       ]),
     );
   }
   return obj;
 }
components/dolibarr/sources/new-order-created/test-event.mjs (1)

1-231: Well-structured test data with comprehensive coverage.

The test event object provides excellent coverage of the Dolibarr order data structure. The nested line items and comprehensive field mapping will be valuable for testing and development.

Consider these minor enhancements for maintainability:

  1. Dynamic timestamps: Some hardcoded timestamps (lines 177, 179, 218-220) might benefit from being relative to Date.now() for long-term test reliability
  2. Documentation: Adding JSDoc comments to explain key sections could help developers understand the data structure
components/dolibarr/actions/create-order/create-order.mjs (2)

26-26: Fix typo in description.

There's a typo in the description: "expecteddelivery" should be "expected delivery".

-      description: "The expecteddelivery date of the order in YYYY-MM-DD format",
+      description: "The expected delivery date of the order in YYYY-MM-DD format",

76-76: Improve summary message format.

The summary message interpolates the entire response object, which may not display meaningful information. Consider using a specific field like order ID.

-    $.export("$summary", `Successfully created order ${response}`);
+    $.export("$summary", `Successfully created order with ID: ${response.id || 'N/A'}`);
components/dolibarr/actions/create-user/create-user.mjs (1)

102-102: Improve summary message format.

Similar to the create-order action, the summary message interpolates the entire response object. Consider using a specific field like user ID or login.

-    $.export("$summary", `Successfully created user ${response}`);
+    $.export("$summary", `Successfully created user: ${response.login || response.id || 'N/A'}`);
components/dolibarr/dolibarr.app.mjs (3)

25-29: Fix label inconsistency for paymentTermCode.

The label says "Payment Term ID" but the description and value field use "code". Consider updating for consistency:

-      label: "Payment Term ID",
+      label: "Payment Term Code",

72-82: Minor: Remove unnecessary space in axios function call.

There's an extra space between axios and the opening parenthesis.

-      return axios ($, {
+      return axios($, {

68-139: Consider adding JSDoc comments for better API documentation.

Adding JSDoc comments to document method parameters and return types would improve maintainability and developer experience.

Example for one method:

+    /**
+     * List all third parties
+     * @param {Object} opts - Request options
+     * @param {Object} opts.params - Query parameters
+     * @param {number} opts.params.limit - Number of results per page
+     * @param {number} opts.params.page - Page number
+     * @returns {Promise<Array>} Array of third party objects
+     */
     listThirdParties(opts = {}) {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c671c73 and 7c623ed.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (13)
  • components/dolibarr/actions/create-order/create-order.mjs (1 hunks)
  • components/dolibarr/actions/create-thirdparty/create-thirdparty.mjs (1 hunks)
  • components/dolibarr/actions/create-user/create-user.mjs (1 hunks)
  • components/dolibarr/common/utils.mjs (1 hunks)
  • components/dolibarr/dolibarr.app.mjs (1 hunks)
  • components/dolibarr/package.json (2 hunks)
  • components/dolibarr/sources/common/base.mjs (1 hunks)
  • components/dolibarr/sources/new-invoice-created/new-invoice-created.mjs (1 hunks)
  • components/dolibarr/sources/new-invoice-created/test-event.mjs (1 hunks)
  • components/dolibarr/sources/new-order-created/new-order-created.mjs (1 hunks)
  • components/dolibarr/sources/new-order-created/test-event.mjs (1 hunks)
  • components/dolibarr/sources/new-thirdparty-created/new-thirdparty-created.mjs (1 hunks)
  • components/dolibarr/sources/new-thirdparty-created/test-event.mjs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Verify TypeScript components
  • GitHub Check: Lint Code Base
  • GitHub Check: Publish TypeScript components
  • GitHub Check: pnpm publish
🔇 Additional comments (13)
components/dolibarr/package.json (1)

3-3: Appropriate version bump for new feature additions.

The minor version increment from 0.0.1 to 0.1.0 correctly reflects the addition of new functionality described in the PR.

components/dolibarr/sources/new-thirdparty-created/new-thirdparty-created.mjs (2)

1-22: Well-structured source module following Pipedream conventions.

The module correctly extends the common base and implements the required methods. The structure follows Pipedream best practices with proper metadata and deduplication strategy.

Key strengths:

  • Clear separation of concerns with base class inheritance
  • Descriptive method implementations
  • Proper use of template literals in getSummary
  • Standard Pipedream source configuration

14-16:

✅ Verification successful

Verify the base class provides the listThirdParties method.

Ensure that this.dolibarr.listThirdParties is properly implemented in the Dolibarr app client to avoid runtime errors.


🏁 Script executed:

#!/bin/bash
# Description: Verify that listThirdParties method exists in the Dolibarr app client
# Expected: Method definition should be found in the app client

ast-grep --pattern $'listThirdParties($$$) {
  $$$
}'

# Also search for method references
rg -A 3 "listThirdParties"

Length of output: 1062


Confirmed: listThirdParties Exists in Dolibarr Client

The listThirdParties method is implemented in the Dolibarr app client:

• File: components/dolibarr/dolibarr.app.mjs

listThirdParties(opts = {}) {
  return this._makeRequest({
    path: "/thirdparties",
    ...opts,
  });
}

No changes are required.

components/dolibarr/sources/new-thirdparty-created/test-event.mjs (1)

1-161: LGTM - Comprehensive test event data structure.

The test event object provides a thorough representation of a third party entity with all the necessary fields for testing the new-thirdparty-created source. The data structure is well-organized and includes appropriate default values.

components/dolibarr/sources/new-invoice-created/test-event.mjs (1)

1-134: LGTM - Well-structured invoice test event data.

The test event object comprehensively covers all invoice-related fields with appropriate default values for testing the new-invoice-created source functionality.

components/dolibarr/sources/new-order-created/new-order-created.mjs (1)

1-23: LGTM - Well-implemented source component following established patterns.

The source component properly extends the common base module and implements the required methods. The structure is clean and follows Pipedream source component best practices.

components/dolibarr/sources/new-invoice-created/new-invoice-created.mjs (1)

1-22: LGTM! Clean source implementation.

The source component correctly extends the base class and implements the required abstract methods. The implementation follows Pipedream patterns and integrates well with the common base.

components/dolibarr/actions/create-user/create-user.mjs (1)

93-95: LGTM! Proper boolean to integer conversion.

The admin boolean conversion to 1/0 is correctly implemented for the Dolibarr API requirements.

components/dolibarr/sources/common/base.mjs (4)

54-58: Verify timestamp comparison logic.

The logic breaks when item.date_creation <= lastTs, but the condition checks item.date_creation > lastTs. This assumes items are sorted in descending order by creation date, which should be correct based on the getArgs() method. The implementation looks correct.


65-66: LGTM! Proper chronological event emission.

The code correctly updates the timestamp to the most recent item's creation date and reverses the array to emit events in chronological order (oldest first), which is the expected behavior for Pipedream sources.


68-73: Good use of abstract method pattern.

The abstract methods properly throw ConfigurationError when not implemented, providing clear guidance to developers extending this base class.


47-51:

✅ Verification successful

Verify paginate method exists in dolibarr app.

The code calls this.dolibarr.paginate() which should be implemented in the dolibarr app component. Ensure this method exists and handles the pagination correctly.


🏁 Script executed:

#!/bin/bash
# Description: Verify that the dolibarr app component has a paginate method
# Expected: Find the paginate method implementation in the dolibarr app

# Search for paginate method in dolibarr app files
fd -e mjs -e js dolibarr.app | xargs rg -A 10 "paginate"

Length of output: 271


Verified paginate method implementation
The dolibarr.app component defines an async generator paginate({ fn, params = {}, max }) that initializes pagination parameters and iterates through pages until the limit is reached. This satisfies the call in components/dolibarr/sources/common/base.mjs, so no further action is needed.

components/dolibarr/dolibarr.app.mjs (1)

1-3: LGTM!

Good use of a constant for the default pagination limit.

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

♻️ Duplicate comments (1)
components/dolibarr/dolibarr.app.mjs (1)

140-164: ⚠️ Potential issue

Critical: The pagination logic still has the infinite loop issue flagged in previous review.

The pagination method still contains the same critical flaw identified in the previous review - the page number is never incremented, which will cause an infinite loop when results.length equals params.limit.

The fix from the previous review still needs to be applied:

     async *paginate({
       fn, params = {}, max,
     }) {
       params = {
         ...params,
         limit: 100,
         page: 0,
       };
-      let total, count = 0;
+      let count = 0;
       do {
         const results = await fn({
           params,
         });
         if (!results?.length) {
           return;
         }
         for (const item of results) {
           yield item;
           if (max && ++count >= max) {
             return;
           }
         }
-        total = results?.length;
-      } while (total === params.limit);
+        params.page++;
+      } while (results.length === params.limit);
🧹 Nitpick comments (1)
components/dolibarr/dolibarr.app.mjs (1)

69-82: Minor formatting issue in _makeRequest method.

The implementation is correct, but there's unusual spacing in the axios call.

-      return axios ($, {
+      return axios($, {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7c623ed and d2d89d4.

📒 Files selected for processing (3)
  • components/dolibarr/actions/create-thirdparty/create-thirdparty.mjs (1 hunks)
  • components/dolibarr/actions/create-user/create-user.mjs (1 hunks)
  • components/dolibarr/dolibarr.app.mjs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • components/dolibarr/actions/create-user/create-user.mjs
  • components/dolibarr/actions/create-thirdparty/create-thirdparty.mjs
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Publish TypeScript components
  • GitHub Check: Lint Code Base
  • GitHub Check: pnpm publish
  • GitHub Check: Verify TypeScript components
🔇 Additional comments (3)
components/dolibarr/dolibarr.app.mjs (3)

1-2: LGTM: Clean imports and constants.

The axios import and default limit constant are appropriately defined.


7-67: LGTM: Well-structured property definitions with proper async options.

The propDefinitions are well-implemented with async option loaders that properly utilize pagination. The structure follows Pipedream conventions and provides good user experience with label-value mappings.


83-139: LGTM: Consistent and well-structured API methods.

All list and create methods follow a consistent pattern and are properly implemented. The method signatures and endpoint paths appear correct for the Dolibarr API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Components] dolibarr
1 participant