Skip to content

New Components - oto #16621

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

Merged
merged 5 commits into from
May 13, 2025
Merged

New Components - oto #16621

merged 5 commits into from
May 13, 2025

Conversation

michelle0927
Copy link
Collaborator

@michelle0927 michelle0927 commented May 9, 2025

Resolves #16557

Summary by CodeRabbit

  • New Features

    • Added the ability to create new products, including support for custom attributes and product details.
    • Introduced actions to fetch order details and list orders with filtering options.
    • Added an instant event source that emits notifications when an order status changes.
    • Enhanced brand and order selection with dynamic options.
  • Improvements

    • Implemented comprehensive API client methods for product, order, and brand management.
    • Added support for paginated order retrieval and webhook lifecycle management.
  • Chores

    • Updated package dependencies and version information.

Copy link

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

Copy link
Contributor

coderabbitai bot commented May 9, 2025

"""

Walkthrough

This update introduces a new integration for the Oto API, including foundational app logic, utility and constants modules, multiple action modules for product and order management, and a webhook source for order status updates. The implementation includes dynamic property definitions, API methods, webhook lifecycle management, and a test fixture for event simulation.

Changes

Files / Paths Change Summary
components/oto/oto.app.mjs Implements the Oto app with prop definitions, API methods (CRUD for products, orders, brands, webhooks), and pagination support.
components/oto/common/constants.mjs, components/oto/common/utils.mjs Adds shared constants for statuses and default limits; introduces a utility for parsing objects from JSON.
components/oto/actions/create-product/create-product.mjs,
components/oto/actions/get-order-details/get-order-details.mjs,
components/oto/actions/list-orders/list-orders.mjs
Adds actions for creating products, fetching order details, and listing orders, each with input validation and API calls.
components/oto/sources/common/base.mjs Introduces a base class for webhook sources, handling webhook registration, event processing, and metadata generation.
components/oto/sources/order-status-updated-instant/order-status-updated-instant.mjs,
components/oto/sources/order-status-updated-instant/test-event.mjs
Adds a source module for order status update webhooks and a static test event for simulation.
components/oto/package.json Bumps version to 0.1.0 and adds dependency on @pipedream/platform.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ActionModule
    participant OtoApp
    participant OtoAPI

    User->>ActionModule: Provide input (e.g., orderId, product details)
    ActionModule->>OtoApp: Call API method (e.g., getOrderDetails, createProduct)
    OtoApp->>OtoAPI: Make HTTP request with auth
    OtoAPI-->>OtoApp: Return response
    OtoApp-->>ActionModule: Return data
    ActionModule-->>User: Output result/summary
Loading
sequenceDiagram
    participant OtoAPI
    participant WebhookSourceBase
    participant Database
    participant HTTP

    OtoAPI-->>WebhookSourceBase: Send webhook event (order status update)
    WebhookSourceBase->>Database: Retrieve webhook ID
    WebhookSourceBase->>WebhookSourceBase: generateMeta(event)
    WebhookSourceBase-->>HTTP: Emit event with metadata
Loading

Assessment against linked issues

Objective Addressed Explanation
Implement Oto component integration (core app, API methods, and foundational logic) (#16557)
Add webhook source for order status updates (#16557)
Add actions for create product, get order details, list orders (#16557)
Implement actions/sources for calls, leads, and campaigns (#16557) Only order/product actions and order status webhook present.

Suggested labels

ai-assisted, action, trigger / source

Suggested reviewers

  • GTFalcao

Poem

A rabbit hopped through Oto’s code,
With actions, triggers, all bestowed.
Orders and products now in play,
Webhooks leap in, right away!
Constants, utils, tests—what fun,
This integration’s just begun.
🐇✨
"""

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/oto/common/constants.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 packageResolve (node:internal/modules/esm/resolve:839:9)
at moduleResolve (node:internal/modules/esm/resolve:908:18)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)

components/oto/oto.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 packageResolve (node:internal/modules/esm/resolve:839:9)
at moduleResolve (node:internal/modules/esm/resolve:908:18)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)

✨ 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.
    • 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.

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

🧹 Nitpick comments (6)
components/oto/actions/create-product/create-product.mjs (3)

23-31: Consider using number type for numerical values

The price and taxAmount props are defined as strings, but they represent numerical values. It would be more appropriate to use the "integer" or "number" type for these props to ensure proper validation and handling.

 price: {
-  type: "string",
+  type: "number",
   label: "Price",
   description: "Price of the product",
 },
 taxAmount: {
-  type: "string",
+  type: "number",
   label: "Tax Amount",
   description: "Tax Amount of the product",
 },

80-85: Consider adding JSON schema validation for customAttributes

The customAttributes property allows for JSON input but currently relies on the parseObject utility for processing. Consider adding a JSON schema to validate the structure of the customAttributes to ensure it conforms to the expected format before attempting to parse it.

You could enhance the property definition to include validation:

customAttributes: {
  type: "object",
  label: "Custom Attributes",
  description: "Custom attributes of the product specified as a JSON Array of objects with keys `attributeName` and `attributeValue`. Example: `[{ \"attributeName\": \"112\", \"attributeValue\": \"test product\"}]`",
  optional: true,
  default: "[]",
  validate: {
    type: "array",
    items: {
      type: "object",
      properties: {
        attributeName: { type: "string" },
        attributeValue: { type: "string" }
      },
      required: ["attributeName", "attributeValue"]
    }
  }
}

106-108: Add a check for empty response

The code checks if response.productId exists, but it would be good to add handling for cases where the API response is unexpected or empty.

 if (response.productId) {
   $.export("$summary", `Successfully created product with ID: ${response.productId}`);
+} else {
+  $.export("$summary", "Product created but no ID was returned");
 }
components/oto/sources/order-status-updated-instant/test-event.mjs (1)

12-12: Consider using a current timestamp for the test event

The timestamp value (1746721659000) corresponds to May 8, 2025, which is a future date. While this might be intentional for testing purposes, it's generally better to use a non-future timestamp to avoid confusion.

-  "timestamp": 1746721659000,
+  "timestamp": 1683561659000, // May 8, 2023 instead of 2025
components/oto/sources/common/base.mjs (1)

45-52: Parse raw strings and emit only valid JSON payloads

event.body can arrive as a string for non-application/json deliveries.
Iterating on a string later in workflows leads to hard-to-debug runtime errors.

-    const { body } = event;
-    if (!body) {
+    let { body } = event;
+    if (!body) {
       return;
     }
+    // If the body is a raw string, attempt to JSON-parse it.
+    if (typeof body === "string") {
+      try {
+        body = JSON.parse(body);
+      } catch {
+        // Un-parsable payload – emit the raw string
+      }
+    }
components/oto/oto.app.mjs (1)

13-17: Return { label, value } objects for a better UX in dropdowns

Returning raw strings works, but Pipedream will show identical text for both the option label and the value.
Using an object clarifies what the user is selecting.

-        return clientStores?.map(({ storeName }) => storeName) || [];
+        return clientStores?.map(({ storeName }) => ({
+          label: storeName,
+          value: storeName,
+        })) || [];
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between db6a41c and cae8bf7.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (10)
  • components/oto/actions/create-product/create-product.mjs (1 hunks)
  • components/oto/actions/get-order-details/get-order-details.mjs (1 hunks)
  • components/oto/actions/list-orders/list-orders.mjs (1 hunks)
  • components/oto/common/constants.mjs (1 hunks)
  • components/oto/common/utils.mjs (1 hunks)
  • components/oto/oto.app.mjs (1 hunks)
  • components/oto/package.json (2 hunks)
  • components/oto/sources/common/base.mjs (1 hunks)
  • components/oto/sources/order-status-updated-instant/order-status-updated-instant.mjs (1 hunks)
  • components/oto/sources/order-status-updated-instant/test-event.mjs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: pnpm publish
  • GitHub Check: Publish TypeScript components
  • GitHub Check: Verify TypeScript components
  • GitHub Check: Lint Code Base
🔇 Additional comments (6)
components/oto/package.json (1)

3-3: Package configuration looks good

The version bump to 0.1.0 is appropriate for introducing new features, and the addition of the @pipedream/platform dependency is necessary for Pipedream component functionality.

Also applies to: 14-16

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

1-24: Well-implemented utility function for JSON parsing

The parseObject utility function is well-written with proper error handling for different input types. It safely handles parsing of JSON strings, arrays of strings, and returns the original input when parsing isn't possible or necessary.

I appreciate the defensive programming approach - checking for falsy values first, handling arrays separately, and providing graceful fallbacks when JSON parsing fails.

components/oto/common/constants.mjs (1)

1-70: Good practice using constants module

Creating a constants module with exported values like DEFAULT_LIMIT and STATUSES is a good practice for maintaining consistent values across the integration. This promotes code maintainability and prevents hardcoded values scattered throughout the codebase.

components/oto/actions/create-product/create-product.mjs (1)

1-111: Well-structured action component

Overall, this is a well-structured action component with clear property definitions, good documentation links, and proper implementation of the API call with the Oto client. The use of the parseObject utility for handling the customAttributes is appropriate.

components/oto/actions/get-order-details/get-order-details.mjs (1)

1-28: Implementation looks good

The Get Order Details action is well-implemented with appropriate prop definitions, clear documentation links, and concise execution logic.

components/oto/sources/order-status-updated-instant/order-status-updated-instant.mjs (1)

1-26: Implementation looks good

The Order Status Updated source component is well-structured. It properly extends the common base, implements the required methods, and uses appropriate deduplication strategy for order events.

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

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

58-68: Avoid using this in default parameters & add JSON header for POST/PUT

Default-initialising $ = this inside the parameter list is unusual and can be brittle because this is not bound until after parameter initialisation (Edge / older runtimes will treat it as undefined).
Move the fallback assignment into the body and add an explicit "Content-Type": "application/json" header for write requests.

-    _makeRequest({
-      $ = this, path, ...otherOpts
-    }) {
-      return axios($, {
+    _makeRequest(opts = {}) {
+      const {
+        path,
+        $: pd = this,         // fallback once `this` is bound
+        headers = {},
+        ...otherOpts
+      } = opts;
+      return axios(pd, {
        ...otherOpts,
        url: `${this._baseUrl()}${path}`,
        headers: {
          Authorization: `Bearer ${this.$auth.oauth_access_token}`,
+          "Content-Type": "application/json",
+          ...headers,
        },
      });
    },
🧹 Nitpick comments (1)
components/oto/oto.app.mjs (1)

54-133: Consider implementing rate limiting or retry mechanisms

For improved reliability, consider implementing rate limiting awareness or retry mechanisms for API calls, especially for production environments where API rate limits may be encountered.

    _makeRequest(opts = {}) {
      const {
        path,
        $: pd = this,
        headers = {},
+       retries = 3,
+       retryDelay = 1000,
        ...otherOpts
      } = opts;
      
+     const makeRequestWithRetry = async (attempt = 0) => {
+       try {
+         return await axios(pd, {
+           ...otherOpts,
+           url: `${this._baseUrl()}${path}`,
+           headers: {
+             Authorization: `Bearer ${this.$auth.oauth_access_token}`,
+             "Content-Type": "application/json",
+             ...headers,
+           },
+         });
+       } catch (error) {
+         // Retry on 429 (rate limit) or 5xx errors
+         if ((error.response?.status === 429 || 
+              (error.response?.status >= 500 && error.response?.status < 600)) && 
+             attempt < retries) {
+           // Exponential backoff
+           const delay = retryDelay * Math.pow(2, attempt);
+           await new Promise(resolve => setTimeout(resolve, delay));
+           return makeRequestWithRetry(attempt + 1);
+         }
+         throw error;
+       }
+     };
+     
+     return makeRequestWithRetry();
    },
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cae8bf7 and 2ab4e4b.

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

108-132: Robust pagination implementation

The pagination implementation properly handles undefined arrays with the nullish coalescing operator (response[resourceKey] ?? []) and includes appropriate logic for page counting and maximum item limits.

@michelle0927 michelle0927 merged commit d926afb into master May 13, 2025
11 checks passed
@michelle0927 michelle0927 deleted the issue-16557 branch May 13, 2025 15:10
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] oto
2 participants