Repository navigation
fix: encoding behaviour for customerio endpoints - #4615
Conversation
Summary by CodeRabbit
WalkthroughIntroduces a centralized encodePathParameter helper that URL-encodes string path parameters and applies it across Customer.io response builders to encode user identifiers and device tokens in endpoint paths. Updates tests to validate encoding for emails, spaces, special characters, undefined, and existing cases. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Src as Source
participant RB as DefaultResponseBuilder
participant ENC as encodePathParameter
participant API as Customer.io API
Src->>RB: message(userId/email, device token)
RB->>ENC: encodePathParameter(userId || email)
ENC-->>RB: encodedId
RB->>ENC: encodePathParameter(deviceToken)
ENC-->>RB: encodedToken
RB->>API: Request with :id and :device_id replaced by encoded values
API-->>RB: HTTP response
RB-->>Src: Built response
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Pre-merge checks (2 passed, 1 warning)❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. ✨ 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:
|
|
Allure Test reports for this run are available at:
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/v0/destinations/customerio/util.js (2)
40-44: Consolidated encoder is correct; drop stale commented logic.encodeURIComponent for path segments is the right choice. Remove the commented-out conditional to avoid confusion.
const encodePathParameter = (param) => { if (typeof param !== 'string') return param; - // return param.includes('/') ? encodeURIComponent(param) : param; return encodeURIComponent(param); };
228-230: Clarify raw vs encoded variables to avoid misuse.In defaultResponseBuilder,
idcurrently holds an encoded value, which can be confusing when later used in presence checks. UserawIdfor checks andencodedIdfor path replacements.const token = get(message, 'context.device.token'); const encodedToken = encodePathParameter(token); - const id = encodePathParameter(userId || getFieldValueFromMessage(message, 'email')); + const rawId = userId || getFieldValueFromMessage(message, 'email'); + const encodedId = encodePathParameter(rawId); // DEVICE DELETE from CustomerIO const isDeviceDeleteEvent = deviceDeleteRelatedEventName === evName; if (isDeviceDeleteEvent) { - if (!id || !token) { + if (!rawId || !token) { throw new InstrumentationError('userId/email or device_token not present'); } - endpoint = DEVICE_DELETE_ENDPOINT.replace(':id', id).replace(':device_id', encodedToken); + endpoint = DEVICE_DELETE_ENDPOINT.replace(':id', encodedId).replace(':device_id', encodedToken); requestConfig = defaultDeleteRequestConfig; return { rawPayload, endpoint, requestConfig }; } @@ - if (id) { - endpoint = - isDeviceRelatedEvent && token - ? DEVICE_REGISTER_ENDPOINT.replace(':id', id) - : USER_EVENT_ENDPOINT.replace(':id', id); + if (rawId) { + endpoint = + isDeviceRelatedEvent && token + ? DEVICE_REGISTER_ENDPOINT.replace(':id', encodedId) + : USER_EVENT_ENDPOINT.replace(':id', encodedId); } else { endpoint = ANON_EVENT_ENDPOINT;Also applies to: 237-237, 275-280
src/v0/destinations/customerio/util.test.js (1)
233-236: Good: preserves undefined.Maintains type semantics for non-string inputs.
Consider adding:
- identifyResponseBuilder with an email containing '+' to assert endpoint path encodes it.
- device delete flow asserting device token with '/' is encoded in ':device_id'.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
test/integrations/destinations/customerio/processor/data.tsis excluded by!**/test/**
📒 Files selected for processing (2)
src/v0/destinations/customerio/util.js(4 hunks)src/v0/destinations/customerio/util.test.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/v0/destinations/customerio/util.test.jssrc/v0/destinations/customerio/util.js
🧬 Code graph analysis (1)
src/v0/destinations/customerio/util.js (3)
src/v0/destinations/customerio/transform.js (2)
userId(44-44)message(154-154)src/v0/util/index.js (3)
getFieldValueFromMessage(687-693)message(1162-1162)message(1196-1196)src/v0/destinations/customerio/util.test.js (3)
message(11-28)message(32-43)message(48-63)
⏰ 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). (8)
- 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: Code Coverage
- GitHub Check: test_and_publish
- GitHub Check: UT Tests
- GitHub Check: Analyze (go)
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (6)
src/v0/destinations/customerio/util.js (3)
110-110: Good: encode ID once and keep raw for validation.Using a pre-encodedId reduces repetition and prevents accidental partial encodes later.
168-168: Correct endpoint substitution with encoded ID.This ensures emails/userIds with reserved characters are safe in the path.
237-237: Nice: device token encoded only in path, raw in payload.Endpoint uses
encodedToken, while payload keeps the original token—matches API expectations.src/v0/destinations/customerio/util.test.js (3)
208-211: Good coverage for email encoding.Covers '+' and '@' and validates strict path-segment encoding.
212-216: Good: whitespace encoding case.Confirms spaces are percent-encoded in path segments.
218-221: Good: special characters case.Catches '#' and '?' which must be encoded in path segments.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #4615 +/- ##
===========================================
- Coverage 91.78% 91.78% -0.01%
===========================================
Files 642 642
Lines 33931 33951 +20
Branches 8032 8044 +12
===========================================
+ Hits 31145 31163 +18
- Misses 2556 2558 +2
Partials 230 230 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|



What are the changes introduced in this PR?
Write a brief explainer on your code changes.
What is the related Linear task?
Resolves INT-4105
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.