Skip to content

feat: Userpilot - Rudderstack transformer - #4164

Merged
yashasvibajpai merged 3 commits into
rudderlabs:feat.userpilot.integration.contributionfrom
Userpilot:userpilot-integration
Apr 8, 2025
Merged

yashasvibajpai merged 3 commits into
rudderlabs:feat.userpilot.integration.contributionfrom
Userpilot:userpilot-integration

Conversation

@ThabetIbrahim

@ThabetIbrahim ThabetIbrahim commented Mar 16, 2025 •

Copy link
Copy Markdown
Contributor

What are the changes introduced in this PR?

Add support for Userpilot integration

What is the related Linear task?

Resolves INT-XXX

Please explain the objectives of your changes below

Put down any required details on the broader aspect of your changes. If there are any dependent changes, mandatorily mention them here

Any changes to existing capabilities/behaviour, mention the reason & what are the changes ?

N/A

Any new dependencies introduced with this change?

N/A

Any new generic utility introduced or modified. Please explain the changes.

N/A

Any technical or performance related pointers to consider with the change?

N/A

@coderabbitai review


Developer checklist

  • My code follows the style guidelines of this project

  • No breaking changes are being introduced.

  • All related docs linked with the PR?

  • All changes manually tested?

  • Any documentation changes needed with this change?

  • Is the PR limited to 10 file changes?

  • Is the PR limited to one linear task?

  • Are relevant unit and component test-cases added in new readability format?

Reviewer checklist

  • Is the type of change in the PR title appropriate as per the changes?

  • Verified that there are no credentials or confidential data exposed with the changes.

Summary by CodeRabbit

  • New Features
    • Introduced a new configuration framework to integrate with an external endpoint.
    • Added a comprehensive event workflow to validate inputs and construct tailored payloads for various user interactions.
    • Implemented utilities for dynamic API endpoint generation and user trait transformation.
  • Tests
    • Provided sample integration data for validating end-to-end event processing and API interactions.

@ThabetIbrahim
ThabetIbrahim requested review from a team and sivashanmukh as code owners March 16, 2025 09:33
@ThabetIbrahim
ThabetIbrahim requested review from a team, koladilip and yashasvibajpai March 16, 2025 09:33
@ThabetIbrahim ThabetIbrahim changed the title Userpilot - Rudderstack transformer feat: Userpilot - Rudderstack transformer Mar 17, 2025
@yashasvibajpai
yashasvibajpai requested a review from Copilot April 4, 2025 05:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

src/cdk/v2/destinations/userpilot/procWorkflow.yaml:63

  • The extraction of traits in the groupPayload step uses .message.traits, whereas the identifyPayload step uses .message.context.traits. Confirm whether the groupPayload should also use .message.context.traits to ensure consistent behavior.
let traits = $.transformTraits(.message.traits || {});

koladilip
koladilip previously approved these changes Apr 4, 2025
@coderabbitai

coderabbitai Bot commented Apr 4, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

This update introduces new files and functionality for the Userpilot integration. A configuration file exports the base URL and key mapping for event processing. A YAML file defines a workflow that validates inputs, prepares context, and constructs payloads for identify, track, and group events. Additionally, utility functions handle endpoint construction and trait transformation. Test data has been added to verify the integration, ensuring proper request and response formatting with the external Userpilot API.

Changes

File(s) Change Summary
src/cdk/v2/destinations/userpilot/config.js
src/cdk/v2/destinations/userpilot/procWorkflow.yaml
src/cdk/v2/destinations/userpilot/utils.js
Added Userpilot integration files: a configuration module with default URLs and mappings; a YAML workflow outlining steps to validate input, prepare context, and build payloads for various event types; and utility functions for endpoint generation and trait transformation.
test/.../data.ts Introduced a test data module exporting configurations and expected inputs/outputs for identify, track, and group events in the Userpilot integration.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Workflow as Userpilot Workflow
    participant Utils as Utility Module

    Client->>Workflow: Send event request (identify/track/group)
    Workflow->>Workflow: validateInput()
    Workflow->>Workflow: prepareContext()
    alt Event is Identify
        Workflow->>Workflow: construct identifyPayload
    else Event is Track
        Workflow->>Workflow: construct trackPayload
    else Event is Group
        Workflow->>Workflow: construct groupPayload
    end
    Workflow->>Client: returnResponse()
Loading

Poem

Oh, how the code does twirl,
As constants, mappings, and workflows unfurl.
I hopped through YAML and JS with glee,
Crafting endpoints and traits merrily.
In each test and file so neat,
A rabbit celebrates changes sweet! 🐇🎉

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

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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

koladilip
koladilip previously approved these changes Apr 4, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (2)
src/cdk/v2/destinations/userpilot/procWorkflow.yaml (2)

16-17: Fix trailing whitespace.

There is a trailing space at the end of line 16 that should be removed.

-      $.assert(.message.type in {{$.EventType.([.IDENTIFY, .TRACK, .GROUP])}}, 
+      $.assert(.message.type in {{$.EventType.([.IDENTIFY, .TRACK, .GROUP])}},
🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 16-16: trailing spaces

(trailing-spaces)


39-40: Consider adding protection against undefined context.

The code assumes that message.context always exists. Add a fallback for when context is undefined to prevent potential runtime errors.

-      let traits = $.transformTraits(.message.context.traits || {});
+      let traits = $.transformTraits(.message.context?.traits || {});
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5d3b226 and 0dddb07.

📒 Files selected for processing (4)
  • src/cdk/v2/destinations/userpilot/config.js (1 hunks)
  • src/cdk/v2/destinations/userpilot/procWorkflow.yaml (1 hunks)
  • src/cdk/v2/destinations/userpilot/utils.js (1 hunks)
  • test/integrations/destinations/userpilot/processor/data.ts (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
src/cdk/v2/destinations/userpilot/utils.js (1)
src/cdk/v2/destinations/userpilot/config.js (2)
  • DEFAULT_BASE_URL (1-1)
  • MAPPINGS (3-5)
🪛 YAMLlint (1.35.1)
src/cdk/v2/destinations/userpilot/procWorkflow.yaml

[error] 16-16: trailing spaces

(trailing-spaces)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Code Coverage
  • GitHub Check: test_and_publish
  • GitHub Check: UT Tests
🔇 Additional comments (9)
src/cdk/v2/destinations/userpilot/config.js (1)

1-9: LGTM! The configuration file is well-structured.

The file correctly exports the necessary constants for the Userpilot integration. The base URL and key mapping for transforming camelCase to snake_case are appropriately defined.

src/cdk/v2/destinations/userpilot/utils.js (2)

3-12: LGTM! Well-implemented utility functions.

The getEndpoints function correctly handles the API endpoint configuration with proper URL normalization to remove trailing slashes. The function returns appropriate endpoints for all required operations.


14-18: LGTM! Efficient trait transformation.

The transformTraits function efficiently transforms object keys based on the provided mappings using a reducer pattern. This approach allows for flexibility as more mappings can be added to the config file in the future.

test/integrations/destinations/userpilot/processor/data.ts (3)

1-147: LGTM! Comprehensive test data for the identify event.

The test data properly covers the Userpilot identify flow with appropriate request and response structures, including all necessary headers and payload attributes.


148-290: LGTM! Comprehensive test data for the track event.

The test data properly covers the Userpilot track event flow, including revenue tracking and other custom properties.


291-433: LGTM! Comprehensive test data for the group event.

The test data properly covers the Userpilot company/group identification with appropriate request and response structures for organization data.

src/cdk/v2/destinations/userpilot/procWorkflow.yaml (3)

30-42: Consider validating userId for all event types in the validateInput step.

Currently, userId validation is done separately in each payload preparation step. Since userId is required for all event types, consider moving this validation to the common validateInput step for consistency.

 - name: validateInput
   template: |
     $.assert(.message.type, "message Type is not present. Aborting message.");
     $.assert(.message.type in {{$.EventType.([.IDENTIFY, .TRACK, .GROUP])}}, 
       "message type " + .message.type + " is not supported by Userpilot");
+    $.assert(.message.userId, "User ID is required for Userpilot calls");

Then you can remove the duplicated userId assertions from each payload preparation step.

Also applies to: 43-56, 57-70


62-67: LGTM! Proper handling of group payload.

The groupPayload step correctly transforms and processes the company metadata, ensuring consistent formatting for the Userpilot API.


71-78: LGTM! Clean response construction.

The returnResponse step effectively utilizes the default request configuration and properly sets all required parameters for the API request.

@codecov

codecov Bot commented Apr 4, 2025 •

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (feat.userpilot.integration.contribution@d5f005c). Learn more about missing BASE report.

Additional details and impacted files
@@                            Coverage Diff                             @@
##             feat.userpilot.integration.contribution    #4164   +/-   ##
==========================================================================
  Coverage                                           ?   91.04%           
==========================================================================
  Files                                              ?      628           
  Lines                                              ?    32937           
  Branches                                           ?     7798           
==========================================================================
  Hits                                               ?    29987           
  Misses                                             ?     2703           
  Partials                                           ?      247           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yashasvibajpai
yashasvibajpai changed the base branch from develop to feat.userpilot.integration.contribution April 5, 2025 09:38
yashasvibajpai
yashasvibajpai previously approved these changes Apr 7, 2025
@yashasvibajpai
yashasvibajpai changed the base branch from feat.userpilot.integration.contribution to develop April 8, 2025 06:54
@yashasvibajpai
yashasvibajpai dismissed stale reviews from koladilip and themself April 8, 2025 06:54

The base branch was changed.

@yashasvibajpai
yashasvibajpai changed the base branch from develop to feat.userpilot.integration.contribution April 8, 2025 07:04
@yashasvibajpai
yashasvibajpai merged this pull request into rudderlabs:feat.userpilot.integration.contribution Apr 8, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Apr 8, 2025
10 tasks
@ThabetIbrahim
ThabetIbrahim deleted the userpilot-integration branch April 8, 2025 09:57
koladilip added a commit that referenced this pull request Apr 8, 2025
* feat: Userpilot - Rudderstack transformer (#4164)

* Userpilot - Rudderstack transformer

* fix: user id is not required & include `v1` in the path rather than DEFAULT_BASE_URL

* test: remove v1 from apiEndpoint

* chore: update functionality

Co-authored-by: Dilip Kola <[email protected]>

* chore: add util tests

---------

Co-authored-by: ThabetIbrahim <[email protected]>
Co-authored-by: Dilip Kola <[email protected]>
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.

4 participants