Skip to content

fix: encoding behaviour for customerio endpoints - #4615

Merged
vinayteki95 merged 2 commits into
developfrom
fix.url-encoding-customerio
Sep 15, 2025
Merged

vinayteki95 merged 2 commits into
developfrom
fix.url-encoding-customerio

Conversation

@vinayteki95

Copy link
Copy Markdown
Contributor

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.

@coderabbitai

coderabbitai Bot commented Sep 9, 2025 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes

    • Improved reliability of Customer.io requests by consistently URL-encoding user identifiers and device tokens in endpoint paths. Handles emails and IDs with +, @, spaces, slashes, and other special characters to prevent request failures or misrouting.
  • Tests

    • Added comprehensive tests covering encoding of emails, spaces, special characters, slashes, undefined values, and non-string inputs.

Walkthrough

Introduces 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

Cohort / File(s) Summary
Customer.io util path-parameter encoding
src/v0/destinations/customerio/util.js
Added encodePathParameter(param) using encodeURIComponent for strings and exported it. Updated identifyResponseBuilder and DefaultResponseBuilder to use encoded values for :id and :device_id path segments. Removed older conditional encoding implementation.
Customer.io util tests
src/v0/destinations/customerio/util.test.js
Replaced/added tests to verify encoding for emails with '+' and '@', spaces, and special characters; added undefined passthrough test; retained tests for slash encoding and non-string passthrough.

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • sivashanmukh
  • sandeepdsvs

Pre-merge checks (2 passed, 1 warning)

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The PR description currently retains the template headings but leaves most sections as placeholders or "N/A" and does not describe the actual code changes, risks, testing performed, or the developer checklist status; although it includes "Resolves INT-4105", that single line is insufficient to meet the repository's template requirements. Key missing information includes a brief explainer of the implementation (what was changed and why), impact/breaking-change notes, testing details (including the added/modified tests), and completed developer checklist entries. As written the description is largely incomplete against the required template. Please complete the template by adding a concise summary of the implementation (e.g., addition of encodePathParameter, where it is used, and associated test changes), confirm the Linear task reference, state whether this introduces breaking changes, describe manual and automated testing performed (attach the Allure/CI report link), and mark the developer checklist items as completed; update docs if needed and then request review.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title "fix: encoding behaviour for customerio endpoints" accurately and concisely captures the primary change—correcting URL-encoding behavior for Customer.io endpoint path parameters—and aligns with the modified util and test files in the changeset. It is short, focused, and free of extraneous details. For small style consistency, consider using American spelling "behavior" and optionally adding "path-parameter" for slightly more specificity.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

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.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

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 Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix.url-encoding-customerio

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

Comment thread src/v0/destinations/customerio/util.js Resolved
@vinayteki95
vinayteki95 marked this pull request as ready for review September 12, 2025 12:43
@vinayteki95
vinayteki95 requested review from a team and sivashanmukh as code owners September 12, 2025 12:43
@vinayteki95
vinayteki95 requested review from a team, krishna2020 and manish339k September 12, 2025 12:43
@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@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 (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, id currently holds an encoded value, which can be confusing when later used in presence checks. Use rawId for checks and encodedId for 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

📥 Commits

Reviewing files that changed from the base of the PR and between 3192141 and 7ebf21c.

⛔ Files ignored due to path filters (1)
  • test/integrations/destinations/customerio/processor/data.ts is 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.js
  • src/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

codecov Bot commented Sep 12, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.78%. Comparing base (d74003b) to head (7ebf21c).
⚠️ Report is 29 commits behind head on develop.

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

@vinayteki95
vinayteki95 merged commit 5f6bad6 into develop Sep 15, 2025
@vinayteki95
vinayteki95 deleted the fix.url-encoding-customerio branch September 15, 2025 06:05
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.

3 participants