Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

New Components - invoice_ninja #15354

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

New Components - invoice_ninja #15354

wants to merge 3 commits into from

Conversation

luancazarine
Copy link
Collaborator

@luancazarine luancazarine commented Jan 21, 2025

Resolves #15154.

Summary by CodeRabbit

  • New Features

    • Added support for creating clients, invoices, and payments in Invoice Ninja
    • Introduced webhook sources for new clients, invoices, and payments
    • Implemented dynamic property selection and API interaction methods
  • Improvements

    • Enhanced API integration with comprehensive method support
    • Added utility functions for parsing and handling data
    • Included classification options and constants
  • Documentation

    • Added detailed property descriptions and method documentation
    • Included sample event emitters for testing

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

vercel bot commented Jan 21, 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 24, 2025 3:19pm
pipedream-docs ⬜️ Ignored (Inspect) Jan 24, 2025 3:19pm
pipedream-docs-redirect-do-not-edit ⬜️ Ignored (Inspect) Jan 24, 2025 3:19pm

Copy link
Contributor

coderabbitai bot commented Jan 21, 2025

Walkthrough

This pull request introduces a comprehensive set of components for the Invoice Ninja integration, including actions for creating clients, invoices, and payments, along with webhook sources for tracking new clients, invoices, and payments. The implementation provides a robust set of methods in the application module to interact with the Invoice Ninja API, including creating, retrieving, and managing various entities. The changes establish a complete workflow for managing invoicing-related operations with detailed property definitions and error handling.

Changes

File Change Summary
components/invoice_ninja/actions/... Added new action modules for creating clients, invoices, and payments with comprehensive property definitions and API interaction methods
components/invoice_ninja/common/... Introduced CLASSIFICATION_OPTIONS constant and parseObject utility function
components/invoice_ninja/invoice_ninja.app.mjs Expanded propDefinitions and added multiple API interaction methods
components/invoice_ninja/package.json Created package configuration for the Invoice Ninja component
components/invoice_ninja/sources/... Added webhook source modules for new clients, invoices, and payments with base functionality and test events

Assessment against linked issues

Objective Addressed Explanation
Create new client
Create new invoice
Record new payment
Webhook sources for new events
Async options for group settings

Possibly related PRs

Poem

🐰 Invoices dance, clients take flight,
Payments sing in the moonlight bright!
CodeRabbit weaves API's sweet song,
Where numbers and data belong!
Ninja's ledger, now complete and clear! 🧾


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 Payment (Instant)

Actions
 - Create Client
 - Create Invoice
 - Create Payment
@michelle0927 michelle0927 marked this pull request as ready for review January 24, 2025 16:03
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: 5

🧹 Nitpick comments (16)
components/invoice_ninja/invoice_ninja.app.mjs (4)

76-107: Optional property consideration.
The newly introduced country and group settings properties look fine. Consider marking both as optional if the API allows. This helps avoid confusion when no value is provided.


127-154: Gateway config labeling.
When returning (id: value, config: label), consider clarifying user-facing labels, because config might not always be user-friendly.


157-165: Hard-coded base URL.
The _baseUrl() method is returning a fixed URL. If your integration needs to support multiple regions or custom domains, consider making this a parameter or prop.


196-237: Broad coverage of retrieval and CRUD operations.
The range of helper methods (getClients, getUsers, etc.) is comprehensive. Adding unit tests for these endpoints would strengthen confidence in integration correctness.

Would you like me to draft basic test examples for these methods?

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

1-22: Convenient event source definition.
This source correctly extends common/base.mjs and uses sampleEmit. The getSummary method is straightforward, though consider using a safe default if client.name is missing or null.

components/invoice_ninja/sources/new-invoice-instant/new-invoice-instant.mjs (1)

14-16: Avoid magic numbers for event IDs.
Returning a hard-coded event ID (2) may cause confusion or maintenance issues later. Consider referencing a constant or an enum to document the meaning of this ID.

 getEvent() {
-  return 2;
+  return EVENT_IDS.INVOICE_CREATED; // Example constant
}
components/invoice_ninja/sources/new-payment-instant/new-payment-instant.mjs (2)

14-16: Centralize event ID definitions.
Similar to the invoice source, returning just 4 may be unclear to future maintainers. Replace the magic number with a clearly named reference.

getEvent() {
-  return 4;
+  return EVENT_IDS.PAYMENT_CREATED; // Example constant
}

17-19: Ensure robust summary generation.
If a payment object is missing or if number is not defined, the string interpolation could be incomplete. Safeguard with a fallback.

getSummary(payment) {
-  return `New payment created: ${payment.number}`;
+  const paymentNumber = payment?.number || "N/A";
+  return `New payment created: ${paymentNumber}`;
}
components/invoice_ninja/sources/common/base.mjs (1)

35-38: Handle missing webhook ID on deactivation.
If a hook ID was never set or was lost due to DB resets, webhookId may be undefined. Consider a safeguard to avoid failing unexpectedly.

async deactivate() {
  const webhookId = this._getHookId();
+ if (!webhookId) {
+   console.warn("No webhook ID found to deactivate");
+   return;
+ }
  await this.app.deleteWebhook(webhookId);
}
components/invoice_ninja/sources/new-invoice-instant/test-event.mjs (2)

2-5: Clarify repeated ID fields.
IDs (id, user_id, assigned_user_id, etc.) share the same placeholder values. While suitable for a test fixture, consider varying them to simulate a more realistic scenario and better test coverage.


58-58: Potential discount conflict.
discount: "10.00" and partial: "10.00" may conflict with paid_to_date: "10.00". Confirm the logic behind these fields to avoid confusion in test scenarios.

Do you want me to help refactor these values or open an issue tracking the correct test data scenarios?

components/invoice_ninja/actions/create-payment/create-payment.mjs (2)

4-137: Consider using numeric types for amount and refunded.
Since you're ultimately parsing them as floats at lines 153 and 154, consider changing the prop definitions from string to number for clarity and type-consistency.

- amount: {
-   type: "string",
+ amount: {
+   type: "number",
    ...
- refunded: {
-   type: "string",
+ refunded: {
+   type: "number",
    ...

138-165: Add error handling around parseObject calls.
You may want to detect invalid JSON inputs for invoices and credits, to provide a clearer error if users supply malformed JSON.

+ try {
    invoices: parseObject(this.invoices),
    credits: parseObject(this.credits),
+ } catch (err) {
+   throw new Error("Invalid JSON format in invoices or credits property.");
+ }
components/invoice_ninja/actions/create-invoice/create-invoice.mjs (2)

4-142: Validate numeric fields in the props definition.
Similar to “Create Payment,” consider using numeric field types for props like totalTaxes, amount, balance, paidToDate, and discount rather than strings. This avoids confusion and possible runtime parsing errors.


143-174: Wrap parseObject calls to handle incorrect input formats.
By gracefully catching JSON parse errors, you can provide more actionable errors to users.

components/invoice_ninja/actions/create-client/create-client.mjs (1)

206-246: Consider enhanced error handling on parseObject.
Similar to the other actions, validating user-provided JSON for contacts and settings can prevent unexpected runtime failures.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7dd5427 and a33a884.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (14)
  • components/invoice_ninja/actions/create-client/create-client.mjs (1 hunks)
  • components/invoice_ninja/actions/create-invoice/create-invoice.mjs (1 hunks)
  • components/invoice_ninja/actions/create-payment/create-payment.mjs (1 hunks)
  • components/invoice_ninja/common/constants.mjs (1 hunks)
  • components/invoice_ninja/common/utils.mjs (1 hunks)
  • components/invoice_ninja/invoice_ninja.app.mjs (1 hunks)
  • components/invoice_ninja/package.json (1 hunks)
  • components/invoice_ninja/sources/common/base.mjs (1 hunks)
  • components/invoice_ninja/sources/new-client-instant/new-client-instant.mjs (1 hunks)
  • components/invoice_ninja/sources/new-client-instant/test-event.mjs (1 hunks)
  • components/invoice_ninja/sources/new-invoice-instant/new-invoice-instant.mjs (1 hunks)
  • components/invoice_ninja/sources/new-invoice-instant/test-event.mjs (1 hunks)
  • components/invoice_ninja/sources/new-payment-instant/new-payment-instant.mjs (1 hunks)
  • components/invoice_ninja/sources/new-payment-instant/test-event.mjs (1 hunks)
✅ Files skipped from review due to trivial changes (3)
  • components/invoice_ninja/common/constants.mjs
  • components/invoice_ninja/package.json
  • components/invoice_ninja/sources/new-payment-instant/test-event.mjs
🧰 Additional context used
🪛 Gitleaks (8.21.2)
components/invoice_ninja/sources/new-client-instant/test-event.mjs

20-20: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

🔇 Additional comments (12)
components/invoice_ninja/invoice_ninja.app.mjs (4)

1-2: Imports look good.
The import from @pipedream/platform is standard practice and appears correct.


6-74: Potential off-by-one in pagination logic.
Within async options({ page }) { ... page: page + 1 }, ensure downstream code expects 1-based page indexing. If the API is zero-based, this could skip or repeat pages inadvertently.


109-126: Client contact retrieval logic.
Here, you correctly retrieve client contacts using the newly introduced showClient method, ensuring you fetch the right contact data. This approach is consistent with the rest of the file.


175-195: POST creation methods look consistent.
Your createNewInvoice, createNewClient, and recordPayment methods align well with the overall request pattern. Centralizing logic in _makeRequest ensures consistency.

components/invoice_ninja/common/utils.mjs (1)

1-24: Robust object parsing.
Your parseObject function handles array and string inputs gracefully, returning the original data on JSON parse errors. This approach is clean and avoids unhandled exceptions.

components/invoice_ninja/sources/new-invoice-instant/new-invoice-instant.mjs (2)

1-3: Proactive import usage check.
Imports for common and sampleEmit look fine for this new source, ensuring consistent base methods and test event data are integrated.


17-19: Handle potential missing invoice data.
If invoice is undefined or missing number, string concatenation may fail silently. Consider adding a quick null check or fallback.

getSummary(invoice) {
-  return `New invoice created: ${invoice.number}`;
+  const invoiceNumber = invoice?.number || "N/A";
+  return `New invoice created: ${invoiceNumber}`;
}
components/invoice_ninja/sources/new-invoice-instant/test-event.mjs (1)

59-60: Questionable test data for deleted invoice.
is_deleted: true might lead to confusion for a “new invoice” sample. If the goal is to test a normal creation flow, consider setting this to false or removing it.

-  "is_deleted": true,
+  "is_deleted": false,
✅ Verification successful

Confirmed: is_deleted: true is inappropriate for new invoice test data

The test event fixture is specifically for testing new invoice creation events (new-invoice-instant), so marking the invoice as deleted contradicts its intended purpose and could lead to confusion during testing.

🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# First, let's look at the full content of the test file
cat components/invoice_ninja/sources/new-invoice-instant/test-event.mjs

# Let's also look for similar test files in the invoice_ninja component
fd test-event.mjs components/invoice_ninja

Length of output: 2544

components/invoice_ninja/actions/create-payment/create-payment.mjs (1)

1-3: Imports look good and maintain DRY coding practices.
No issues found referencing the shared parseObject utility and the app instance.

components/invoice_ninja/actions/create-invoice/create-invoice.mjs (1)

1-3: Shared utilities usage is consistent.
The imports maintain a consistent pattern for interacting with common utilities and the app module.

components/invoice_ninja/actions/create-client/create-client.mjs (2)

1-4: Constants and utility imports are well-organized.
No issues with the import structure.


5-205: Ensure all prop definitions align with server requirements.
Confirm whether all fields labeled as string (e.g., addresses, phone numbers) meet the Invoice Ninja API constraints. For example, if some numeric fields are typed as strings, parse or define them accordingly.

Copy link
Collaborator

@michelle0927 michelle0927 left a comment

Choose a reason for hiding this comment

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

Just one minor comment not affecting functionality. Moving to QA!

settings: {
type: "object",
label: "Settings",
description: "An array of settings objects in JSON format. **Example: {\"currency_id\": 1, \"timezone_id\": 5, \"date_format_id\": 1, \"language_id\": 1}** [See the documentation](https://api-docs.invoicing.co/#tag/clients/POST/api/v1/clients) for further details",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think settings takes an object instead of an array.

Suggested change
description: "An array of settings objects in JSON format. **Example: {\"currency_id\": 1, \"timezone_id\": 5, \"date_format_id\": 1, \"language_id\": 1}** [See the documentation](https://api-docs.invoicing.co/#tag/clients/POST/api/v1/clients) for further details",
description: "A settings object in JSON format. **Example: {\"currency_id\": 1, \"timezone_id\": 5, \"date_format_id\": 1, \"language_id\": 1}** [See the documentation](https://api-docs.invoicing.co/#tag/clients/POST/api/v1/clients) for further details",

# for free to join this conversation on GitHub. Already have an account? # 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] invoice_ninja
2 participants