Repository navigation
fix(cordial): optional check for cid - #4553
Conversation
Summary by CodeRabbit
WalkthroughRefactors internal variable name and nested property access in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggestions:
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Actionable comments posted: 0
🔭 Outside diff range comments (2)
src/sources/cordial/transform.js (2)
32-32: Bug: spreading a possibly undefinedcontactwill throw at runtimeIf
inputPaylaod.contactis 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 errorsSimilarly, if
inputPaylaod.eventorinputPaylaod.event.propertiesis 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 fallbackIf
acould be an empty string,||would incorrectly fall back toaction.??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
⛔ Files ignored due to path filters (2)
go/webhook/testcases/testdata/testcases/cordial/when_contact_object_is_not_present_in_the_event_payload_0.jsonis excluded by!**/*.jsontest/integrations/sources/cordial/data.tsis 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 whencontactis absentUsing
inputPaylaod?.contact?.cIDis correct and aligns with the PR goal to avoid transformation failures.
20-24: Confirm property casing incordialtransform and consider fallbackOur repository search only finds
inputPaylaod.contact.cID(no instances ofcontact.cid), so the code will work as-is against existing references. However, if the upstream payload ever usescid(all lowercase), we’d silently drop that value.• Please confirm the API contract/spec for
cIDvs.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, + }); + }
|
Allure Test reports for this run are available at:
|
|
Allure Test reports for this run are available at:
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
|
There was a problem hiding this comment.
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
📒 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 usescID, notcid.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 lowercasecontact.cidin 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.



What are the changes introduced in this PR?
We got a bugsnag alert when the payload does not contain
contact.cidobject which leads to the transformation failing for the payloadWhat 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.