Repository navigation
feat(customerio): add record event support in v2 router transform - #5311
Conversation
Implements Customer.io v2 batch API transformer using the native batching framework. Routes v2-enabled workspaces through CustomerIOIntegration (BatchDestination) targeting /api/v2/batch, while keeping the v1 path unchanged for all other workspaces. Fixes in v2 util: - Guard last_used against undefined timestamp (NaN sent to API) - Replace all dots in trait keys, not just the first (regex /\./g) - Use null-check for previousId to allow numeric 0 (Zod allows z.number()) - Zod refine now validates alias events require userId + previousId Co-Authored-By: Claude Sonnet 4.6 <[email protected]> 🔒 Scanned for secrets using gitleaks 8.30.1
- Route record-type messages through buildRecordEvent (insert/update→identify, delete→delete person)
- Add networkHandler for CustomerIO v1 with 207 partial-failure per-job mapping
- Add CustomerIOConnectionConfig schema and connection-aware router request types
- Guard identifiers against explicit null with ?? {} before validation
- Fix module.exports → ES export in networkHandler.ts for consistency
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
🔒 Scanned for secrets using gitleaks 8.30.1
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
Note
|
| Layer / File(s) | Summary |
|---|---|
Types, schema, and config src/v0/destinations/customerio/types.ts, src/v0/destinations/customerio/v2/types.ts, src/v0/destinations/customerio/v2/config.ts |
Imports RudderRecordV2, adds CustomerIOConnectionConfigSchema and CustomerIOConnection, expands CustomerIORouterRequest to accept record messages with connection typing, adds RECORD_ACTION_MAP and REQUIRED_IDENTIFIER_KEYS, and extends the v2 input schema to accept record messages. |
Record payload builder src/v0/destinations/customerio/v2/recordTransform.ts |
Validates connection config, maps record actions, validates id or email, and builds person payloads with optional attributes for non-delete actions. |
Router record branching src/v0/destinations/customerio/routerTransform.ts, src/v0/destinations/customerio/transform.ts |
Adds record-message detection, size validation, record-message routing through buildRecordEvent, keeps the existing envelope path for non-record messages, and updates transformEvent to use the new request type and body builder. |
Record routing tests src/v0/destinations/customerio/v2/recordTransform.test.ts, src/v0/destinations/customerio/routerTransform.test.ts |
Tests record-event routing, batching, and error paths for missing identifiers and missing connection config, and verifies buildRecordEvent action mapping, identifier selection, and unsupported-action errors. |
CustomerIO v1 Network Handler
| Layer / File(s) | Summary |
|---|---|
Response mapping and wiring src/v1/destinations/customerio/networkHandler.ts |
Defines the 207 response shapes, maps multi-status batch errors to per-job delivery states, throws proxy errors for non-success statuses with auth categorization, and wires networkHandler into the proxy framework. |
Network handler tests src/v1/destinations/customerio/networkHandler.test.ts |
Tests success mapping, 207 partial-failure mapping, empty-error handling, thrown 400 responses, and auth error categories for 401 and 403. |
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
- rudderlabs/rudder-transformer#5187: Updates
BatchDestinationtyping and batching plumbing that this PR uses in the CustomerIO router integration. - rudderlabs/rudder-transformer#5299: Touches the same CustomerIO v0 type surface around
CustomerIORouterRequestand connection typing. - rudderlabs/rudder-transformer#5303: Modifies the same CustomerIO router transform path that this PR extends for
recordmessages.
Suggested reviewers
- ItsSudip
- shekhar-rudder
- saikumarrs
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
✅ Passed checks (4 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | ✅ Passed | The title clearly summarizes the main change by describing record event support in the Customer.io v2 router transform. |
| Description check | ✅ Passed | The description follows the required template and includes the change summary, Linear task, objectives, and checklist sections. |
| Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create PR with unit tests
- Commit unit tests in branch
feat/customerio-record-v2
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 @coderabbitai help to get the list of available commands.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #5311 +/- ##
===========================================
+ Coverage 92.68% 92.69% +0.01%
===========================================
Files 697 700 +3
Lines 37867 37937 +70
Branches 8887 8895 +8
===========================================
+ Hits 35097 35167 +70
Misses 2542 2542
Partials 228 228 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
c6e9761 to
e8ac67f
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (3)
src/v1/destinations/customerio/networkHandler.test.ts (1)
46-81: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a 207 test for malformed
errorspayload shape.Please add a case like
destinationResponse: { response: { errors: {} }, status: 207 }to lock in graceful fallback behavior and prevent parser regressions on unexpected API payloads.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/v1/destinations/customerio/networkHandler.test.ts` around lines 46 - 81, Add a new test case within the '207 — partial failure' describe block to handle malformed errors payload shapes. Create a test that passes a destinationResponse with errors as an empty object (errors: {}) instead of an array, while keeping the same structure as the existing tests using metadata and batch data. This test should verify that the responseHandler gracefully falls back to marking all batch items as 200 statusCode when the errors payload is malformed, ensuring the parser handles unexpected API response shapes without breaking.src/v0/destinations/customerio/routerTransform.test.ts (1)
75-78: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a record-path test for invalid destination config.
Please add a case where
siteID/apiKeyis missing ondestination.Configfor a record message and assert the same config-validation error path as non-record events.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/v0/destinations/customerio/routerTransform.test.ts` around lines 75 - 78, The current test only validates ConfigurationError when connection is absent for non-record events. Add a new test case that verifies the same ConfigurationError is thrown when siteID or apiKey is missing from destination.Config for a record message. Create an Integration with a destination configuration that lacks these required fields, call transformEvent with a record message input, and assert that ConfigurationError is thrown to ensure consistent validation across both record and non-record event types.src/v0/destinations/customerio/v2/recordTransform.test.ts (1)
118-128: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a regression test for prototype-key actions.
Please add an unsupported-action case like
action: 'toString'(or'__proto__') to lock in the guard behavior against prototype-chain bypasses.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/v0/destinations/customerio/v2/recordTransform.test.ts` around lines 118 - 128, Add a regression test case to verify that the buildRecordEvent function properly guards against prototype-chain bypass attempts. Create a new test case (similar to the existing unsupported action test) that uses prototype-key actions such as 'toString' or '__proto__' as the action value, and verify that these also throw InstrumentationError with an appropriate error message. This will ensure the validation logic is protected against prototype pollution attacks.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/v0/destinations/customerio/routerTransform.ts`:
- Around line 38-53: The `transformEvent` method skips calling
`validateConfigFields(this.destination)` for record events because the method
returns early within the `isRecordMessage` block. Move the
`validateConfigFields(this.destination)` call to the beginning of the
`transformEvent` method, before any conditional checks, so that destination
configuration validation is performed consistently for all event types including
record events.
In `@src/v0/destinations/customerio/v2/recordTransform.ts`:
- Around line 20-23: The validation check using the `in` operator in the
condition `if (!(action in RECORD_ACTION_MAP))` checks the entire prototype
chain instead of only own properties, allowing prototype keys like "toString" to
bypass the guard. Replace the `in` operator with an own-property check using
either `Object.hasOwn()` or `Object.prototype.hasOwnProperty.call()` to ensure
only actual properties of RECORD_ACTION_MAP are considered valid actions,
preventing prototype methods from being assigned to the cioAction variable.
In `@src/v1/destinations/customerio/networkHandler.ts`:
- Around line 27-31: The code assumes response.errors is iterable when it
exists, but if Customer.io returns a malformed response shape where errors is a
non-array value (string, object, etc.), the forEach call will throw and break
the handler. Add validation to ensure errors is actually an array before calling
forEach on it. Check if errors is an array using Array.isArray() on the errors
variable, and only populate the failedByIndex Map if it is a valid array;
otherwise, treat it as an empty array to safely handle the malformed response.
---
Nitpick comments:
In `@src/v0/destinations/customerio/routerTransform.test.ts`:
- Around line 75-78: The current test only validates ConfigurationError when
connection is absent for non-record events. Add a new test case that verifies
the same ConfigurationError is thrown when siteID or apiKey is missing from
destination.Config for a record message. Create an Integration with a
destination configuration that lacks these required fields, call transformEvent
with a record message input, and assert that ConfigurationError is thrown to
ensure consistent validation across both record and non-record event types.
In `@src/v0/destinations/customerio/v2/recordTransform.test.ts`:
- Around line 118-128: Add a regression test case to verify that the
buildRecordEvent function properly guards against prototype-chain bypass
attempts. Create a new test case (similar to the existing unsupported action
test) that uses prototype-key actions such as 'toString' or '__proto__' as the
action value, and verify that these also throw InstrumentationError with an
appropriate error message. This will ensure the validation logic is protected
against prototype pollution attacks.
In `@src/v1/destinations/customerio/networkHandler.test.ts`:
- Around line 46-81: Add a new test case within the '207 — partial failure'
describe block to handle malformed errors payload shapes. Create a test that
passes a destinationResponse with errors as an empty object (errors: {}) instead
of an array, while keeping the same structure as the existing tests using
metadata and batch data. This test should verify that the responseHandler
gracefully falls back to marking all batch items as 200 statusCode when the
errors payload is malformed, ensuring the parser handles unexpected API response
shapes without breaking.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: c002c99b-92de-45c4-bddb-458ce76636d8
⛔ Files ignored due to path filters (6)
src/v0/destinations/customerio/docs/businesslogic.mdis excluded by!**/*.mdtest/integrations/destinations/customerio/dataDelivery/data.tsis excluded by!**/test/**test/integrations/destinations/customerio/network.tsis excluded by!**/test/**test/integrations/destinations/customerio/processor/data.tsis excluded by!**/test/**test/integrations/destinations/customerio/router/data.tsis excluded by!**/test/**test/integrations/destinations/customerio/router/dataV2.tsis excluded by!**/test/**
📒 Files selected for processing (10)
src/v0/destinations/customerio/routerTransform.test.tssrc/v0/destinations/customerio/routerTransform.tssrc/v0/destinations/customerio/transform.tssrc/v0/destinations/customerio/types.tssrc/v0/destinations/customerio/v2/config.tssrc/v0/destinations/customerio/v2/recordTransform.test.tssrc/v0/destinations/customerio/v2/recordTransform.tssrc/v0/destinations/customerio/v2/types.tssrc/v1/destinations/customerio/networkHandler.test.tssrc/v1/destinations/customerio/networkHandler.ts
💤 Files with no reviewable changes (1)
- src/v0/destinations/customerio/transform.ts
🔒 Scanned for secrets using gitleaks 8.30.1
There was a problem hiding this comment.
Pull request overview
Adds CustomerIO “record” message support to the v2 router transform (mapping record insert/update → person identify, delete → person delete), and introduces a v1 CustomerIO network handler with explicit 207 partial-failure handling for data delivery tests.
Changes:
- Add
recordas a supported v2 router input type and implement record→v2 payload transformation + batching. - Introduce CustomerIO v1
networkHandlerwith 207 multi-status per-job mapping and accompanying unit/dataDelivery tests. - Update CustomerIO test fixtures (router v2 datasets, network mocks, dataDelivery scenarios) and connection-aware request typing.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/integrations/destinations/customerio/router/dataV2.ts | Renames exported dataset and adds v2 router test cases for record events (mirror/upsert). |
| test/integrations/destinations/customerio/router/data.ts | Updates router test aggregation to use dataV1/dataV2 naming. |
| test/integrations/destinations/customerio/processor/data.ts | Refactors processor test export to v1data + re-export aggregation. |
| test/integrations/destinations/customerio/network.ts | Adds mocked HTTP responses for CustomerIO /v2/batch including 207 partial failures. |
| test/integrations/destinations/customerio/dataDelivery/data.ts | Adds proxy v1 dataDelivery scenarios for 200/207/400/401 response handling. |
| src/v1/destinations/customerio/networkHandler.ts | Adds v1 network handler with 207 partial-failure mapping and error propagation via TransformerProxyError. |
| src/v1/destinations/customerio/networkHandler.test.ts | Unit tests for v1 network handler success, 207 mapping, and auth/error cases. |
| src/v0/destinations/customerio/v2/types.ts | Extends supported input types to include record; adds record payload/message types and re-exports connection schema. |
| src/v0/destinations/customerio/v2/recordTransform.ts | Implements buildRecordEvent to map record actions into CustomerIO v2 person payloads. |
| src/v0/destinations/customerio/v2/recordTransform.test.ts | Adds unit tests validating record action mapping, identifier requirements, and error cases. |
| src/v0/destinations/customerio/v2/config.ts | Introduces record action mapping and required identifier keys. |
| src/v0/destinations/customerio/types.ts | Adds CustomerIOConnectionConfig schema/types and updates router request typing to be connection-aware + support record messages. |
| src/v0/destinations/customerio/transform.ts | Minor cleanup (removes a stale comment). |
| src/v0/destinations/customerio/routerTransform.ts | Routes record messages through buildRecordEvent and enforces per-object size constraints. |
| src/v0/destinations/customerio/routerTransform.test.ts | Adds router unit tests for record routing, errors, and batching behavior. |
| src/v0/destinations/customerio/docs/businesslogic.md | Updates doc snippet to align with current datacenter === 'EU' behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
shekhar-rudder
left a comment
There was a problem hiding this comment.
A few cleanup points around the record-event support — mostly removing duplication and unused/unnecessary exports.
… field for record events
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/v0/destinations/customerio/v2/recordTransform.test.ts (1)
96-103: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd an explicit
identifiers: nullregression test.Line 96+ covers empty/invalid identifier shapes, but not the explicit null path that this PR introduces. Add a case with
identifiers: nulland assert the sameInstrumentationErrormessage to lock the null-coalescing contract.Proposed test addition
it('throws InstrumentationError when identifiers is empty object', () => { @@ expect(() => buildRecordEvent(message, baseConnectionConfig)).toThrow(InstrumentationError); }); + + it('throws InstrumentationError when identifiers is null', () => { + const message = { + type: 'record' as const, + action: 'insert' as const, + identifiers: null as any, + }; + expect(() => buildRecordEvent(message, baseConnectionConfig)).toThrow(InstrumentationError); + expect(() => buildRecordEvent(message, baseConnectionConfig)).toThrow( + 'A non-empty `id` or `email` identifier is required', + ); + });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/v0/destinations/customerio/v2/recordTransform.test.ts` around lines 96 - 103, Add a regression test in recordTransform.test.ts for the buildRecordEvent path where identifiers is null, since the current InstrumentationError coverage only checks an empty object. Extend the existing buildRecordEvent test group to include a message with identifiers: null and assert it throws the same InstrumentationError message as the empty identifiers case, using the buildRecordEvent symbol to keep the null-coalescing behavior locked in.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/v0/destinations/customerio/v2/recordTransform.test.ts`:
- Around line 96-103: Add a regression test in recordTransform.test.ts for the
buildRecordEvent path where identifiers is null, since the current
InstrumentationError coverage only checks an empty object. Extend the existing
buildRecordEvent test group to include a message with identifiers: null and
assert it throws the same InstrumentationError message as the empty identifiers
case, using the buildRecordEvent symbol to keep the null-coalescing behavior
locked in.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: d1b6c57d-b275-4a58-96c2-908436b56c92
⛔ Files ignored due to path filters (1)
test/integrations/destinations/customerio/router/dataV2.tsis excluded by!**/test/**
📒 Files selected for processing (2)
src/v0/destinations/customerio/v2/recordTransform.test.tssrc/v0/destinations/customerio/v2/recordTransform.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/v0/destinations/customerio/v2/recordTransform.ts
shekhar-rudder
left a comment
There was a problem hiding this comment.
Review of the latest commit (record identifiers/attributes extraction). One issue: when both id and email are present, email is dropped entirely rather than being preserved as an attribute, which contradicts the new test's stated success criteria.
🔒 Scanned for secrets using gitleaks 8.30.1
|



🔒 Scanned for secrets using gitleaks 8.30.1
What are the changes introduced in this PR?
Co-Authored-By: Claude Sonnet 4.6 [email protected]
What is the related Linear task?
Resolves INT-6570
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.