Repository navigation
feat(mp): add endpointPath to transformer responses - #4649
Conversation
Summary by CodeRabbit
WalkthroughRefactors Mixpanel transform flows to split endpoint into base and path: setImportCredentials now returns endpointDetails {endpoint, path}; transform responses and batched requests include endpointPath; engage and groups routes build endpoints as base + '/' + path + '/'. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Source
participant Transform as MP Transform
participant Creds as setImportCredentials
participant Builder as responseBuilderSimple
participant Batch as generateBatchedPayloadForArray
participant Dest as Mixpanel Endpoint
Source->>Transform: send event(s)
Transform->>Creds: request credentials
Creds-->>Transform: { endpointDetails:{endpoint, path}, headers, params }
Transform->>Builder: build response
Builder-->>Transform: response { endpoint, endpointPath, headers, params }
rect #EEF8FF
note right of Transform: Engage/Groups set endpointPath ('engage'/'groups') and compute endpoint = base + '/' + path + '/'
end
alt Single event
Transform->>Dest: POST response.endpoint (with endpointPath)
else Batched
Transform->>Batch: batch events
Batch-->>Transform: batchedRequest { endpoint, endpointPath, headers, params, payload }
Transform->>Dest: POST batchedRequest.endpoint (with endpointPath)
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Suggestions
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 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 |
|
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 #4649 +/- ##
========================================
Coverage 91.78% 91.78%
========================================
Files 642 642
Lines 33974 33979 +5
Branches 8037 8037
========================================
+ Hits 31184 31189 +5
Misses 2560 2560
Partials 230 230 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (4)
src/v0/destinations/mp/transform.js (3)
51-55: Structured return from setImportCredentials — add explicit error when credentials are missingNice refactor to endpointDetails. Add a clear failure if neither token nor service account creds are provided to avoid base64 of undefined.
Apply this diff:
const setImportCredentials = (destConfig) => { const endpointPath = 'import'; const endpointDetails = { endpoint: `${getBaseEndpoint(destConfig)}/${endpointPath}/`, path: endpointPath, }; const params = { strict: destConfig.strictMode ? 1 : 0, }; const { serviceAccountUserName, serviceAccountSecret, projectId, token } = destConfig; let credentials; if (token) { credentials = `${token}:`; } else if (serviceAccountUserName && serviceAccountSecret && projectId) { credentials = `${serviceAccountUserName}:${serviceAccountSecret}`; params.projectId = projectId; } + if (!credentials) { + throw new ConfigurationError( + 'Mixpanel /import requires either a project token or service account credentials (username, secret, projectId).' + ); + } const headers = { 'Content-Type': 'application/json', Authorization: `Basic ${base64Convertor(credentials)}`, }; return { endpointDetails, headers, params }; };Also applies to: 71-71
82-89: Avoid undefined query param project_id in response.paramsIf token auth is used, params.projectId is undefined and may leak as project_id=undefined. Set only when defined.
Apply this diff:
- response.params = { - project_id: params?.projectId, - strict: params.strict, - }; + const reqParams = { strict: params.strict }; + if (params.projectId !== undefined) { + reqParams.project_id = params.projectId; + } + response.params = reqParams;
476-478: Group endpoint override — LGTM; consider DRYing URL constructionOverriding endpointPath and endpoint for groups is correct. To reduce duplication, consider a tiny helper to join base + path and ensure consistent trailing slashes.
src/v0/destinations/mp/util.js (1)
303-314: Propagate endpointPath safely when batchingbatchedRequest.endpointPath is taken from firstEvent (src/v0/destinations/mp/util.js:303). transform.js and deleteUsers.js normally set endpointPath (e.g., src/v0/destinations/mp/transform.js:84,108,476; src/v0/destinations/mp/deleteUsers.js:15), but combineBatchRequestsWithSameJobIds (src/v0/util/index.js:2287) has no endpointPath handling — merged batches may lose it. Add a small fallback when building the batched request (e.g., default 'engage' or derive from firstEvent.endpoint) or update combineBatchRequestsWithSameJobIds to preserve/carry endpointPath.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
test/integrations/destinations/mp/processor/data.tsis excluded by!**/test/**test/integrations/destinations/mp/router/data.tsis excluded by!**/test/**
📒 Files selected for processing (2)
src/v0/destinations/mp/transform.js(5 hunks)src/v0/destinations/mp/util.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/v0/destinations/mp/util.jssrc/v0/destinations/mp/transform.js
🧠 Learnings (1)
📚 Learning: 2025-05-29T13:29:39.436Z
Learnt from: maheshkutty
PR: rudderlabs/rudder-transformer#4359
File: src/v0/util/index.js:2272-2272
Timestamp: 2025-05-29T13:29:39.436Z
Learning: The `combineBatchRequestsWithSameJobIds` function in `src/v0/util/index.js` is used by both Mixpanel and Google AdWords Offline Conversions destinations in production. The function assumes metadata is always an array in multiple operations (forEach, filter, sort, map) and needs defensive programming to handle non-array metadata cases to prevent runtime errors.
Applied to files:
src/v0/destinations/mp/util.js
🧬 Code graph analysis (1)
src/v0/destinations/mp/transform.js (2)
src/v0/destinations/mp/deleteUsers.js (2)
endpointPath(15-15)endpointPath(79-79)src/v0/destinations/mp/util.js (2)
getBaseEndpoint(458-468)destination(197-197)
⏰ 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 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 ARM64
- GitHub Check: Build User 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)
3018150 to
5a3c750
Compare
|
Allure Test reports for this run are available at:
|
- Add endpointPath field to Mixpanel destination responses - Refactor setImportCredentials to return endpoint details with path - Update batched request configuration to include endpointPath - Update test data to reflect new response structure with endpointPath
5a3c750 to
c4fa00e
Compare
|
Allure Test reports for this run are available at:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
src/v0/destinations/mp/transform.js (2)
82-89: Avoid undefined query params in router responsesEnsure
project_idis omitted when absent to reduce noise and potential lint warnings.- response.params = { - project_id: params?.projectId, - strict: params.strict, - }; + response.params = removeUndefinedValues({ + project_id: params?.projectId, + strict: params.strict, + });
476-478: Groups endpoint set correctly; consider centralizing URL joinSetting
endpointPath = 'groups'and composing with base is consistent. To DRY this and prevent future slash issues, consider a small helper (e.g.,joinBaseAndPath(base, path)) used here and in the default branch.src/v0/destinations/mp/util.js (1)
303-304: Add fallback for missing endpointPath in batched requestsPrefer an explicit endpointPath but fall back to the last path segment of endpoint when endpointPath is absent to support legacy transforms.
Location: src/v0/destinations/mp/util.js (around lines 303-304)
- batchedRequest.endpointPath = firstEvent.endpointPath; + // Prefer explicit endpointPath; fallback to last path segment of endpoint (without trailing slash) + batchedRequest.endpointPath = + firstEvent.endpointPath ?? + (typeof firstEvent.endpoint === 'string' + ? firstEvent.endpoint.replace(/\/+$/, '').split('/').pop() + : undefined);
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
test/integrations/destinations/mp/processor/data.tsis excluded by!**/test/**test/integrations/destinations/mp/router/data.tsis excluded by!**/test/**
📒 Files selected for processing (2)
src/v0/destinations/mp/transform.js(5 hunks)src/v0/destinations/mp/util.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/v0/destinations/mp/util.jssrc/v0/destinations/mp/transform.js
🧠 Learnings (1)
📚 Learning: 2025-05-29T13:29:39.436Z
Learnt from: maheshkutty
PR: rudderlabs/rudder-transformer#4359
File: src/v0/util/index.js:2272-2272
Timestamp: 2025-05-29T13:29:39.436Z
Learning: The `combineBatchRequestsWithSameJobIds` function in `src/v0/util/index.js` is used by both Mixpanel and Google AdWords Offline Conversions destinations in production. The function assumes metadata is always an array in multiple operations (forEach, filter, sort, map) and needs defensive programming to handle non-array metadata cases to prevent runtime errors.
Applied to files:
src/v0/destinations/mp/util.js
🧬 Code graph analysis (1)
src/v0/destinations/mp/transform.js (1)
src/v0/destinations/mp/util.js (2)
getBaseEndpoint(458-468)destination(197-197)
🔇 Additional comments (1)
src/v0/destinations/mp/transform.js (1)
108-110: Endpoint composition for engage: normalized path segment — niceUsing
endpointPath = 'engage'(no leading slash) and composing${base}/${path}/keeps URLs clean and avoids double slashes. This aligns with prior guidance.
|
Allure Test reports for this run are available at:
|
|
- Add endpointPath field to Mixpanel destination responses - Refactor setImportCredentials to return endpoint details with path - Update batched request configuration to include endpointPath - Update test data to reflect new response structure with endpointPath



Summary
This PR adds the
endpointPathfield to Mixpanel destination transformer responses to provide additional endpoint information.Changes
setImportCredentialsto return endpoint details with path informationendpointPathendpointPathTechnical Details
endpointPathfield to transformer responses for better endpoint identificationTesting
endpointPathfield