Skip to content

fix(cordial): optional check for cid - #4553

Merged
maheshkutty merged 5 commits into
developfrom
fix.cordial_source_cid
Aug 11, 2025
Merged

maheshkutty merged 5 commits into
developfrom
fix.cordial_source_cid

Conversation

@maheshkutty

Copy link
Copy Markdown
Contributor

What are the changes introduced in this PR?

We got a bugsnag alert when the payload does not contain contact.cid object which leads to the transformation failing for the payload

What is the related Linear task?

Resolves INT-4005

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.

@maheshkutty
maheshkutty requested a review from a team August 10, 2025 14:57
@coderabbitai

coderabbitai Bot commented Aug 10, 2025 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features
    • No user-facing features added.
  • Bug Fixes
    • Improved stability when event or contact fields are missing, preventing potential errors during processing.
    • More reliable external ID extraction and trait/property merging from incoming payloads.
  • Refactor
    • Internal cleanup and naming consistency for better maintainability.
  • Notes
    • No changes to public APIs or integrations.

Walkthrough

Refactors internal variable name and nested property access in src/sources/cordial/transform.js: fixes a misspelled parameter, switches several property accesses to optional chaining, updates event name extraction and merges for traits/properties, and passes the corrected payload to message.setPropertiesV2. No public API changes.

Changes

Cohort / File(s) Change Summary
Parameter & internal references
src/sources/cordial/transform.js
Renamed internal parameter from inputPaylaod to inputPayload and updated all internal references.
Event extraction & properties merge
src/sources/cordial/transform.js
Event name now sourced via inputPayload.event?.a or inputPayload.event?.action; properties merges use ...(inputPayload?.event?.properties ?? {}) and ...(inputPayload?.event ?? {}).
Contact / external ID and traits
src/sources/cordial/transform.js
External ID construction guards nested access with inputPayload?.contact?.cID and uses inputPayload.contact.cID; trait merging uses ...(inputPayload?.contact ?? {}).
Message API call
src/sources/cordial/transform.js
message.setPropertiesV2 is now invoked with inputPayload (corrected variable) instead of the misspelled variant.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggestions:

  • Run a global search for inputPaylaod to ensure no remaining misspellings.
  • Add unit tests covering cases where contact, event, or event.properties are missing/null to validate optional chaining behavior.
  • Consider adding a small comment noting why both event?.a and event?.action are checked to clarify intent.
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix.cordial_source_cid

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

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate unit tests to generate unit tests for 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.

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.

@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

🔭 Outside diff range comments (2)
src/sources/cordial/transform.js (2)

32-32: Bug: spreading a possibly undefined contact will throw at runtime

If inputPaylaod.contact is missing, { ...inputPaylaod.contact } will throw (“Cannot convert undefined or null to object”). Guard it with a nullish fallback.

Apply this change:

-  message.context.traits = { ...message.context.traits, ...inputPaylaod.contact };
+  message.context.traits = {
+    ...message.context.traits,
+    ...(inputPaylaod?.contact ?? {})
+  };

33-37: Harden event merges to avoid potential runtime errors

Similarly, if inputPaylaod.event or inputPaylaod.event.properties is absent, spreading will throw. Use guarded spreads to keep the transform robust.

-  message.properties = {
-    ...message.properties,
-    ...inputPaylaod.event.properties,
-    ...inputPaylaod.event,
-  };
+  message.properties = {
+    ...message.properties,
+    ...(inputPaylaod?.event?.properties ?? {}),
+    ...(inputPaylaod?.event ?? {}),
+  };
🧹 Nitpick comments (2)
src/sources/cordial/transform.js (2)

8-8: Nit: fix parameter typo for readability (inputPaylaod → inputPayload)

This typo appears multiple times and can be confusing. Renaming improves clarity and consistency.

Minimal example:

-const processEvent = (inputPaylaod) => {
+const processEvent = (inputPayload) => {

Please update usages within the function accordingly.


10-10: Optional: prefer nullish coalescing (??) over || for event name fallback

If a could be an empty string, || would incorrectly fall back to action. ?? handles only nullish values.

-  let eventName = inputPaylaod.event?.a || inputPaylaod.event?.action;
+  let eventName = inputPaylaod.event?.a ?? inputPaylaod.event?.action;
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 65868f6 and 98e9042.

⛔ Files ignored due to path filters (2)
  • go/webhook/testcases/testdata/testcases/cordial/when_contact_object_is_not_present_in_the_event_payload_0.json is excluded by !**/*.json
  • test/integrations/sources/cordial/data.ts is excluded by !**/test/**
📒 Files selected for processing (1)
  • src/sources/cordial/transform.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.js

⚙️ CodeRabbit Configuration File

Focus on ESLint errors (max 3) and warnings (max 5).

Files:

  • src/sources/cordial/transform.js
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: Code Coverage
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: test_and_publish
  • GitHub Check: UT Tests
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
🔇 Additional comments (2)
src/sources/cordial/transform.js (2)

20-25: Solid fix: optional chaining prevents crashes when contact is absent

Using inputPaylaod?.contact?.cID is correct and aligns with the PR goal to avoid transformation failures.


20-24: Confirm property casing in cordial transform and consider fallback

Our repository search only finds inputPaylaod.contact.cID (no instances of contact.cid), so the code will work as-is against existing references. However, if the upstream payload ever uses cid (all lowercase), we’d silently drop that value.

• Please confirm the API contract/spec for cID vs. cid.
• If both variants can appear, consider this fallback implementation:

-  if (inputPaylaod?.contact?.cID) {
-    externalId.push({
-      type: 'cordialContactId',
-      id: inputPaylaod.contact.cID,
-    });
-  }
+  const cordialId =
+    inputPaylaod?.contact?.cID ?? inputPaylaod?.contact?.cid;
+  if (cordialId) {
+    externalId.push({
+      type: 'cordialContactId',
+      id: cordialId,
+    });
+  }

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@codecov

codecov Bot commented Aug 11, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.79%. Comparing base (7ae313f) to head (fb5d880).
⚠️ Report is 28 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4553      +/-   ##
===========================================
+ Coverage    91.63%   91.79%   +0.16%     
===========================================
  Files          643      642       -1     
  Lines        34020    33885     -135     
  Branches      8048     8025      -23     
===========================================
- Hits         31174    31106      -68     
+ Misses        2588     2549      -39     
+ Partials       258      230      -28     

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

@sonarqubecloud

Copy link
Copy Markdown

@maheshkutty
maheshkutty requested a review from ItsSudip August 11, 2025 08:06

@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 (1)
src/sources/cordial/transform.js (1)

10-13: Event name may be undefined; consider a guarded fallback.

If both a and action are missing, eventName becomes undefined. If that’s not guaranteed by upstream, add a minimal fallback.

Apply this small guard if needed:

-  let eventName = inputPayload.event?.a || inputPayload.event?.action;
+  let eventName = inputPayload.event?.a || inputPayload.event?.action;
+  if (!eventName) {
+    // Optional: pick a conservative fallback
+    eventName = 'Custom Event';
+  }

Please confirm that a or action is always present in incoming payloads for Cordial.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 98e9042 and fb5d880.

📒 Files selected for processing (1)
  • src/sources/cordial/transform.js (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.js

⚙️ CodeRabbit Configuration File

Focus on ESLint errors (max 3) and warnings (max 5).

Files:

  • src/sources/cordial/transform.js
🧬 Code Graph Analysis (1)
src/sources/cordial/transform.js (2)
src/v0/util/index.js (3)
  • message (1162-1162)
  • message (1196-1196)
  • externalId (1527-1527)
src/sources/cordial/config.js (1)
  • eventsMapping (1-4)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Code Coverage
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image ARM64
🔇 Additional comments (5)
src/sources/cordial/transform.js (5)

8-8: Parameter rename looks good.

Renaming to inputPayload fixes the typo and improves readability. No side effects observed.


16-16: Correct object passed to setPropertiesV2.

Passing inputPayload instead of the misspelled variable is correct and prevents runtime errors.


32-32: Traits merge is safe and aligned with the objective.

Optional chaining and nullish fallback prevent failures when contact is absent. This directly addresses the transformation failures.


35-37: Confirm precedence: event-level keys override event.properties.

Given the spread order, keys from inputPayload.event will override keys from inputPayload.event.properties. If you intend properties to take precedence, reverse their order.

Option if properties should win:

-    ...(inputPayload?.event?.properties ?? {}),
-    ...(inputPayload?.event ?? {}),
+    ...(inputPayload?.event ?? {}),
+    ...(inputPayload?.event?.properties ?? {}),

20-24: No changes needed—Cordial uses cID, not cid.

The search shows that across both the source transform and the CDK workflow, Cordial consistently uses contact.cID (uppercase “ID”)—there’s no reference to a lowercase contact.cid in the repo. You can safely leave the code as is, since it aligns with how the upstream payload is constructed and consumed.

Likely an incorrect or invalid review comment.

@maheshkutty
maheshkutty merged commit b430edb into develop Aug 11, 2025
@maheshkutty
maheshkutty deleted the fix.cordial_source_cid branch August 11, 2025 11:30
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