Repository navigation
feat(customerio): add endpoint paths to responses - #4671
Conversation
Summary by CodeRabbit
WalkthroughReplaces individual Customer.io endpoint constants with a consolidated Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Client as Upstream Event
participant Transform as transform
participant Builders as util.*ResponseBuilder
participant Util as util.getEndpointDetails
participant CIO as Customer.io API
Client->>Transform: event message
Transform->>Builders: invoke builder by event type
Builders->>Util: getEndpointDetails({ eventType, id, deviceId })
Util-->>Builders: { endpoint, path }
Builders-->>Transform: { rawPayload, endpointDetails, requestConfig }
alt endpointDetails.path == "v2/batch"
Transform->>Transform: group by endpointDetails.path
Transform->>CIO: POST endpointDetails.endpoint (batch)
CIO-->>Transform: response
else
Transform->>CIO: request to endpointDetails.endpoint
CIO-->>Transform: response
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Suggestions:
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ 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. Comment |
- Enhanced config.js with better validation and error handling - Updated transform.js with improved data processing logic - Refactored util.js for better performance and maintainability - Added comprehensive test cases for util functions - Updated integration test data for processor and router
74c38de to
b9837cf
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/v0/destinations/customerio/util.test.js (1)
140-147: Remove duplicate test case.This test case appears to be a duplicate of the earlier test on lines 132-139, both testing the same scenario with identical expected output.
- it('Should throw error for null userId before encoding', async () => { - let expectedOutput = 'userId or email is not present'; - try { - identifyResponseBuilder(null, getIdentifyTestMessage()); - } catch (error) { - expect(error.message).toEqual(expectedOutput); - } - });
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
test/integrations/destinations/customerio/processor/data.tsis excluded by!**/test/**test/integrations/destinations/customerio/router/data.tsis excluded by!**/test/**
📒 Files selected for processing (4)
src/v0/destinations/customerio/config.js(2 hunks)src/v0/destinations/customerio/transform.js(5 hunks)src/v0/destinations/customerio/util.js(10 hunks)src/v0/destinations/customerio/util.test.js(5 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.js
⚙️ CodeRabbit configuration file
Focus on ESLint errors (max 3) and warnings (max 5).
Files:
src/v0/destinations/customerio/config.jssrc/v0/destinations/customerio/transform.jssrc/v0/destinations/customerio/util.jssrc/v0/destinations/customerio/util.test.js
🧠 Learnings (1)
📚 Learning: 2025-08-13T04:47:19.615Z
Learnt from: ItsSudip
PR: rudderlabs/rudder-transformer#4497
File: src/v0/destinations/tiktok_ads/transformV2.js:422-435
Timestamp: 2025-08-13T04:47:19.615Z
Learning: The getSuccessRespEvents function in src/v0/util/index.js is designed to be flexible and can accept both single request objects and arrays as the first parameter (message). It simply assigns the input directly to the batchedRequest property without processing, allowing downstream consumers to handle the appropriate format.
Applied to files:
src/v0/destinations/customerio/transform.js
🧬 Code graph analysis (4)
src/v0/destinations/customerio/config.js (1)
src/v0/destinations/customerio/util.js (1)
ENDPOINTS(35-35)
src/v0/destinations/customerio/transform.js (2)
src/v0/destinations/mp/transform.js (1)
endpointDetails(52-55)src/v0/destinations/customerio/util.js (5)
endpointDetails(167-167)endpointDetails(178-178)endpointDetails(215-215)endpointDetails(222-222)getEndpointDetails(34-37)
src/v0/destinations/customerio/util.js (3)
src/v0/destinations/customerio/config.js (1)
ENDPOINTS(7-36)src/v0/destinations/customerio/transform.js (1)
endpointDetails(142-142)src/v0/util/index.js (2)
defaultPutRequestConfig(448-451)defaultDeleteRequestConfig(442-445)
src/v0/destinations/customerio/util.test.js (1)
src/v0/destinations/customerio/util.js (2)
identifyResponseBuilder(105-171)aliasResponseBuilder(173-192)
⏰ 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: 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: Build Transformer Docker Image - PR / Build Transformer Docker Image ARM64
- GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
- GitHub Check: Code Coverage
- GitHub Check: UT Tests
- GitHub Check: test_and_publish
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: Analyze (go)
🔇 Additional comments (22)
src/v0/destinations/customerio/transform.js (6)
20-20: LGTM! Clean import addition.The
getEndpointDetailsimport aligns with the refactored architecture for centralized endpoint management.
79-80: LGTM! Improved endpoint handling.The refactor from direct endpoint assignment to using
endpointDetailsstructure improves consistency and maintainability across the codebase.
142-142: LGTM! Consistent endpoint resolution.Using
getEndpointDetailsfor batch endpoint resolution maintains consistency with the refactored approach.
158-158: LGTM! Cleaner metadata extraction.Removing the direct endpoint usage from message metadata simplifies the batching logic and aligns with the centralized endpoint management approach.
168-169: LGTM! Consistent endpoint assignment in batching.The batched request construction now uses the centralized
endpointDetailsapproach, maintaining consistency across the transform logic.
146-146: Batch filtering verified — endpointDetails.path is used correctlysrc/v0/destinations/customerio/config.js defines path 'v2/batch', transform.js checks resp.message.endpoint?.includes(endpointDetails.path), and tests reference the same path — no changes required.
src/v0/destinations/customerio/config.js (3)
3-6: LGTM! Well-structured base endpoint constants.The hierarchical approach with
BASE_ENDPOINT,BASE_ENDPOINT_V1, andBASE_ENDPOINT_V2provides clear versioning structure and reduces duplication.
7-36: LGTM! Excellent endpoint consolidation.The
ENDPOINTSconfiguration object provides several benefits:
- Centralizes all endpoint definitions in one place
- Separates endpoint URLs from path identifiers
- Maintains consistency with template parameters (
:id,:device_id)- Improves maintainability for future endpoint changes
This refactor significantly improves the codebase architecture.
58-58: LGTM! Clean API surface.Exporting the unified
ENDPOINTSobject instead of individual constants provides a cleaner and more maintainable public API.src/v0/destinations/customerio/util.js (8)
23-23: LGTM! Proper configuration import.Importing
ENDPOINTSfrom the centralized config aligns with the architectural improvements.
34-37: LGTM! Well-designed endpoint resolution function.The
getEndpointDetailsfunction provides a clean abstraction for endpoint resolution with proper parameter substitution. The template replacement logic correctly handles both:idand:device_idplaceholders.
112-112: LGTM! Proper parameter encoding.Using
encodePathParameterensures URL safety for user identifiers that might contain special characters.
167-167: LGTM! Consistent endpoint resolution pattern.The
identifyResponseBuildercorrectly usesgetEndpointDetailsand maintains the new response structure withendpointDetails.Also applies to: 170-170
178-178: LGTM! Clean alias endpoint handling.The
aliasResponseBuilderproperly usesgetEndpointDetailsfor merge operations without requiring parameter substitution.Also applies to: 191-191
215-215: LGTM! Consistent group endpoint handling.The
groupResponseBuildermaintains consistency with the new endpoint resolution approach.Also applies to: 217-217
222-222: LGTM! Comprehensive endpoint handling in default builder.The
defaultResponseBuildercorrectly handles all endpoint scenarios:
- Device deletion with both
idanddeviceIdparameters- Device registration with encoded
id- User events with encoded
id- Anonymous events without parameters
The conditional logic properly selects the appropriate endpoint type based on the event context.
Also applies to: 236-242, 279-285, 304-304
317-317: LGTM! Proper public API export.Adding
getEndpointDetailsto the module exports makes it available for use in transform logic and maintains a clean separation of concerns.src/v0/destinations/customerio/util.test.js (5)
107-110: LGTM! Test updated for new endpoint structure.The test expectations correctly reflect the new
endpointDetailsstructure with separateendpointandpathproperties.
153-156: LGTM! Alias builder tests updated correctly.All test expectations properly reflect the new
endpointDetailsstructure for merge operations.Also applies to: 164-167, 175-178, 186-189
202-205: LGTM! Group builder test updated correctly.The test expectation correctly reflects the batch endpoint structure.
239-247: LGTM! Enhanced encoding test coverage.The additional test cases for spaces and special characters provide good coverage of the encoding behavior.
335-335: LGTM! URL encoding test updated correctly.The test expectation properly reflects the new
endpointDetails.endpointstructure while verifying proper URL encoding of user IDs with forward slashes.
|
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 #4671 +/- ##
========================================
Coverage 91.78% 91.78%
========================================
Files 642 642
Lines 33974 33979 +5
Branches 8043 8044 +1
========================================
+ Hits 31184 31189 +5
Misses 2538 2538
Partials 252 252 ☔ 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 (3)
src/v0/destinations/customerio/util.js (2)
34-37: Harden getEndpointDetails: validate eventType and required params.Guard against invalid eventType and missing placeholders to fail fast and avoid malformed URLs.
Apply this diff:
-const getEndpointDetails = ({ eventType, id, deviceId }) => { - const { endpoint, path } = ENDPOINTS[eventType]; - return { endpoint: endpoint.replace(':id', id).replace(':device_id', deviceId), path }; -}; +const getEndpointDetails = ({ eventType, id, deviceId }) => { + const cfg = ENDPOINTS[eventType]; + if (!cfg) { + throw new InstrumentationError(`Unsupported eventType: ${eventType}`); + } + const needsId = cfg.endpoint.includes(':id'); + const needsDevice = cfg.endpoint.includes(':device_id'); + if (needsId && (id === undefined || id === null || id === '')) { + throw new InstrumentationError(`Missing required path param "id" for eventType: ${eventType}`); + } + if (needsDevice && (deviceId === undefined || deviceId === null || deviceId === '')) { + throw new InstrumentationError( + `Missing required path param "deviceId" for eventType: ${eventType}`, + ); + } + const built = cfg.endpoint.replace(':id', id).replace(':device_id', deviceId); + return { endpoint: built, path: cfg.path }; +};
222-222: Default builder: endpoint resolution logic looks solid; minor nit.All branches pick the right endpoint via getEndpointDetails. Minor nit: encode token only when used (deviceDelete) to avoid unnecessary work on non-device flows.
Also applies to: 236-243, 279-285, 304-305
src/v0/destinations/customerio/util.test.js (1)
140-147: Deduplicate and use toThrow for error assertion.This test duplicates the prior “No Identifier…” case. Prefer a single test using toThrow.
Apply this diff:
-it('Should throw error for null userId before encoding', async () => { - let expectedOutput = 'userId or email is not present'; - try { - identifyResponseBuilder(null, getIdentifyTestMessage()); - } catch (error) { - expect(error.message).toEqual(expectedOutput); - } -}); +it('Should throw when userId/email is missing', () => { + expect(() => identifyResponseBuilder(null, getIdentifyTestMessage())).toThrow( + 'userId or email is not present', + ); +});
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
test/integrations/destinations/customerio/processor/data.tsis excluded by!**/test/**test/integrations/destinations/customerio/router/data.tsis excluded by!**/test/**
📒 Files selected for processing (4)
src/v0/destinations/customerio/config.js(2 hunks)src/v0/destinations/customerio/transform.js(5 hunks)src/v0/destinations/customerio/util.js(10 hunks)src/v0/destinations/customerio/util.test.js(5 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- src/v0/destinations/customerio/transform.js
- src/v0/destinations/customerio/config.js
🧰 Additional context used
📓 Path-based instructions (1)
**/*.js
⚙️ CodeRabbit configuration file
Focus on ESLint errors (max 3) and warnings (max 5).
Files:
src/v0/destinations/customerio/util.jssrc/v0/destinations/customerio/util.test.js
🧬 Code graph analysis (2)
src/v0/destinations/customerio/util.js (3)
src/v0/destinations/customerio/config.js (1)
ENDPOINTS(7-36)src/v0/destinations/customerio/transform.js (1)
endpointDetails(142-142)src/v0/util/index.js (2)
defaultPutRequestConfig(448-451)defaultDeleteRequestConfig(442-445)
src/v0/destinations/customerio/util.test.js (1)
src/v0/destinations/customerio/util.js (2)
identifyResponseBuilder(105-171)aliasResponseBuilder(173-192)
⏰ 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). (4)
- GitHub Check: Build User 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 Transformer Docker Image - PR / Build Transformer Docker Image AMD64
- GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image ARM64
🔇 Additional comments (11)
src/v0/destinations/customerio/util.js (6)
23-24: Consolidated ENDPOINTS import aligns with new endpointDetails API.Importing ENDPOINTS is consistent with the move to a single resolver. Looks good.
39-43: Always-encode path parameters: verify downstream compatibility.Switching to unconditional encodeURIComponent is correct for path safety. Please confirm no downstream relies on unencoded path segments (notably email ids) to prevent regressions.
112-112: Identify: encoding id and returning endpointDetails is correct.Pre-encoding the id and returning { endpoint, path } matches the new contract.
Also applies to: 167-171
178-191: Alias: endpointDetails usage for merge endpoint looks correct.No path params involved; payload shape and requestConfig are consistent.
215-218: Group: endpointDetails for v2/batch is correct.Matches ENDPOINTS.objectEvent and requestConfig.
317-318: Exporting getEndpointDetails is appropriate.Makes the resolver consumable by callers (e.g., transform).
src/v0/destinations/customerio/util.test.js (5)
107-111: LGTM: assertions updated for endpointDetails (endpoint + path).Matches the new return shape from util.js.
153-156: LGTM: alias tests validate endpointDetails for merge correctly.Endpoint and path assertions align with ENDPOINTS.mergeUser.
Also applies to: 164-167, 175-178, 186-189
202-205: LGTM: group tests assert v2/batch endpointDetails.Consistent with objectEvent routing.
239-247: LGTM: encodePathParameter coverage strengthened.Good additions for spaces and special characters.
335-336: LGTM: defaultResponseBuilder encodes userId in endpoint as expected.Asserting endpointDetails.endpoint is sufficient; payload checks are sane.
feat(customerio): improve config, transform and util functions - Enhanced config.js with better validation and error handling - Updated transform.js with improved data processing logic - Refactored util.js for better performance and maintainability - Added comprehensive test cases for util functions - Updated integration test data for processor and router

What are the changes introduced in this PR?
This PR improves the Customer.io destination integration with enhanced configuration validation, better data transformation logic, and improved utility functions for better performance and maintainability.
What is the related Linear task?
Resolves https://linear.app/rudderstack/issue/INT-4102/add-endpoint-path-details-in-rudder-transformer-for-top-15
Please explain the objectives of your changes below
This PR focuses on improving the Customer.io destination integration by:
Any changes to existing capabilities/behaviour, mention the reason & what are the changes ?
The changes maintain backward compatibility while improving:
Any new dependencies introduced with this change?
N/A
Any new generic utility introduced or modified. Please explain the changes.
Enhanced existing utility functions in Customer.io destination:
Any technical or performance related pointers to consider with the change?
@coderabbitai review
Developer checklist
Reviewer checklist