Repository navigation
feat(customerio): add v2 API support with native batching framework - #5303
Conversation
|
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 |
|---|---|
V2 types and input schema src/v0/destinations/customerio/v2/types.ts |
Defines CustomerIOV2Identifiers, CustomerIOV2Device, CustomerIOV2Payload, and CustomerIOV2ProcessorOutput types with batched body and statusCode. Implements getV2InputSchema() Zod validator with per-event-type refinements: alias requires userId and previousId; group accepts any input; other types require at least one identifier (userId, anonymousId, email trait) or a mapped-to-destination marker. Re-exports base destination types. |
V2 config constants and endpoint helpers src/v0/destinations/customerio/v2/config.ts |
Establishes datacenter-aware host selection (EU vs default), batch API endpoint and path helpers, size limits (MAX_OBJECT_SIZE_BYTES for 32KB per-object enforcement, MAX_BATCH_PAYLOAD for request envelope size), device event name constants including delete/uninstall markers, object action names with defaults, mapping categories for object and device events, and computed MAPPING_CONFIG for event-to-action mapping. |
V2 event-type payload builders and request metadata src/v0/destinations/customerio/v2/util.ts |
Implements identifier derivation (personIdentifiers selecting userId, email, or anonymousId with validation), trait attribute construction with dot-path escaping for free-form keys, and timestamp conversion to Unix seconds. Provides per-event-type builders: buildIdentify, buildTrack, buildPage, buildScreen, buildMerge, buildObject, buildDevice with device add/delete detection via deviceActionFor. buildEnvelope routes messages by lowercased type; buildRequestMeta computes datacenter-aware endpoint, method, and Basic Auth headers from destination config. |
processV2 entry point src/v0/destinations/customerio/v2/transform.ts |
Exports processV2 function that validates destination configuration, conditionally augments message userId and folds externalId into traits when context.mappedToDestination is set, calls buildEnvelope and buildRequestMeta, and returns CustomerIOV2ProcessorOutput with undefined-stripped batch payload body and HTTP metadata (endpoint, endpointPath, method, headers, statusCode=200). |
V1/V2 routing seam src/v0/destinations/customerio/transform.ts |
Updates imports to include processV2 transformer and isBatchingFrameworkEnabled flag utility. Modifies process(event) to destructure metadata and check the CUSTOMERIO batching framework flag; when enabled, immediately returns processV2({ message, destination }); otherwise continues existing v1 single-message flow with EU endpoint domain replacement. Updates processRouterDest to explicitly cast v1 result to CustomerIOBatchedRequest at the router boundary. |
BatchDestination router integration src/v0/destinations/customerio/routerTransform.ts |
Defines CustomerIOIntegration extending BatchDestination: transformEvent calls processV2, unwraps the single-event batch payload, computes JSON serialized byte size, and enforces the 32KB per-object limit via InstrumentationError. Configures ChunkBatchStrategy with MAX_BATCH_PAYLOAD sizing and wrapBody: { batch: bodies } envelope. Exposes input schema via getV2InputSchema() and exports the integration instance as Integration. |
Sequence Diagram
sequenceDiagram
participant Client as Rudder Event Pipeline
participant Transform as transform.ts<br/>process()
participant ProcessV2 as processV2<br/>v2/transform.ts
participant Envelope as buildEnvelope<br/>v2/util.ts
participant Router as CustomerIOIntegration<br/>routerTransform.ts
participant CioAPI as Customer.io<br/>Batch API
Client->>Transform: process event
Transform->>Transform: isBatchingFrameworkEnabled<br/>CUSTOMERIO?
alt v2 enabled
Transform->>ProcessV2: processV2 message, destination
ProcessV2->>Envelope: buildEnvelope message, destination
Envelope-->>ProcessV2: CustomerIOV2Payload
ProcessV2-->>Transform: V2ProcessorOutput with batch
Transform-->>Client: V2ProcessorOutput
Client->>Router: transformEvent event
Router->>Router: compute JSON byte size
Router->>Router: size > 32KB?
alt exceeds limit
Router->>Router: throw InstrumentationError
else within limit
Router->>Router: ChunkBatchStrategy wrap
Router-->>CioAPI: POST /batch { batch: [...] }
CioAPI-->>Router: 200 OK
end
else v1 flow
Transform->>Transform: processSingleMessage
Transform->>Transform: EU domain replacement
Transform-->>Client: CustomerIOBatchedRequest
end
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~60 minutes
Possibly related PRs
- rudderlabs/rudder-transformer#5187: Builds new destination
routerTransformintegrations on top of the nativeBatchDestinationbatching framework that this PR's CustomerIO integration extends. - rudderlabs/rudder-transformer#5299: Modifies the same
src/v0/destinations/customerio/transform.tsfile, including EU/datacenter routing condition logic that the main PR's v2 routing seam builds upon.
Suggested reviewers
- krishna2020
- shekhar-rudder
- ItsSudip
🚥 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 'feat(customerio): add v2 API support with native batching framework' accurately and concisely summarizes the main change: implementing Customer.io v2 API with native batching framework support. |
| Description check | ✅ Passed | The PR description addresses the required template sections: it explains the changes introduced, links the related Linear task (INT-6612), and describes the objectives and fixes in v2 utilities. |
| 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-track-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.
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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/v2/types.ts`:
- Around line 61-70: Replace the truthiness checks for numeric identifier fields
with explicit presence checks that properly handle zero values. In the refine
function within the schema, change the conditions checking `!!msg.userId` and
`!!msg.anonymousId` to explicitly verify that these fields are not undefined and
not null, rather than relying on truthiness coercion which incorrectly rejects
the valid numeric value 0. This ensures that the schema validation properly
accepts valid numeric identifiers including zero while still rejecting truly
missing values.
In `@src/v0/destinations/customerio/v2/util.ts`:
- Around line 31-40: Replace all truthy checks for numeric identifiers (userId,
email, anonymousId, previousId) with explicit presence checks that allow falsy
but valid values like 0. Change conditions like if (userId) and if
(message.anonymousId) to explicitly check for null and undefined using
conditions like if (userId !== undefined && userId !== null) or similar. This
issue appears in multiple locations throughout the util.ts file as indicated by
the additional references to lines 72-74, 144-145, and 187-189, so ensure all
identifier validation checks are updated consistently to handle numeric zero as
a valid identifier.
🪄 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: 12491edd-9b76-42bb-9f6e-2058250cf674
⛔ Files ignored due to path filters (6)
src/v0/destinations/customerio/v2/data/CustomerIODeviceV2.jsonis excluded by!**/*.jsonsrc/v0/destinations/customerio/v2/data/customerIoGroup.jsonis excluded by!**/*.jsontest/integrations/destinations/customerio/processor/data.tsis excluded by!**/test/**test/integrations/destinations/customerio/processor/v2data.tsis excluded by!**/test/**test/integrations/destinations/customerio/router/data.tsis excluded by!**/test/**test/integrations/destinations/customerio/router/v2data.tsis excluded by!**/test/**
📒 Files selected for processing (6)
src/v0/destinations/customerio/routerTransform.tssrc/v0/destinations/customerio/transform.tssrc/v0/destinations/customerio/v2/config.tssrc/v0/destinations/customerio/v2/transform.tssrc/v0/destinations/customerio/v2/types.tssrc/v0/destinations/customerio/v2/util.ts
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #5303 +/- ##
=========================================
Coverage 92.67% 92.68%
=========================================
Files 693 697 +4
Lines 37681 37867 +186
Branches 8824 8848 +24
=========================================
+ Hits 34922 35097 +175
- Misses 2531 2560 +29
+ Partials 228 210 -18 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds Customer.io Track API v2 batch support by integrating the native batching framework, routing v2-enabled workspaces through a new CustomerIOIntegration (BatchDestination) targeting /api/v2/batch, while keeping the existing v1 transformer path unchanged.
Changes:
- Introduces a new v2 transformer (
src/v0/destinations/customerio/v2/*) that builds per-event v2 envelopes and shared request metadata for/api/v2/batch. - Adds a native batching framework integration for Customer.io (
routerTransform.ts) with per-object size checks and payload chunking. - Extends integration test fixtures to include v2 batched expectations alongside existing v1 cases.
Reviewed changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| test/integrations/destinations/customerio/router/v2data.ts | Adds router test fixture asserting v2 batching into a single /api/v2/batch request. |
| test/integrations/destinations/customerio/router/data.ts | Combines existing v1 router fixtures with new v2 fixtures. |
| test/integrations/destinations/customerio/processor/data.ts | Combines existing v1 processor fixtures with new v2 fixtures. |
| src/v0/destinations/customerio/v2/util.ts | Implements v2 envelope builders (identify/track/page/screen/merge/group/device) and request metadata. |
| src/v0/destinations/customerio/v2/types.ts | Defines v2 payload types and Zod input schema validation for the batching framework. |
| src/v0/destinations/customerio/v2/transform.ts | Adds processV2 to produce single-event v2 delivery requests reused by batching integration. |
| src/v0/destinations/customerio/v2/data/customerIoGroup.json | Adds mapping config for v2 group/object events. |
| src/v0/destinations/customerio/v2/data/CustomerIODeviceV2.json | Adds mapping config for v2 device attribute extraction. |
| src/v0/destinations/customerio/v2/config.ts | Adds v2 endpoint config, batching limits, and mapping config wiring. |
| src/v0/destinations/customerio/transform.ts | Routes v2-enabled workspaces to processV2 and widens types at the v1/v2 seam. |
| src/v0/destinations/customerio/routerTransform.ts | Adds BatchDestination integration using ChunkBatchStrategy to build /api/v2/batch requests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
7890c4e to
3f1e988
Compare
shekhar-rudder
left a comment
There was a problem hiding this comment.
A couple of points on the v2 migration — one router-only cleanup and one config-access consistency nit. The routing/gating, the four util fixes, and the test fixtures all check out.
shekhar-rudder
left a comment
There was a problem hiding this comment.
One more from a v1-vs-v2 parity pass: the RETL / mappedToDestination preprocessing isn't carried over to the v2 path.
shekhar-rudder
left a comment
There was a problem hiding this comment.
Follow-up on the RETL fix: the externalId preprocessing runs after schema validation in the router path, so externalId-only RETL events are still rejected upfront.
shekhar-rudder
left a comment
There was a problem hiding this comment.
Small follow-up on the RETL-aware refine: the casts can be avoided by declaring the inspected fields in the schema.
shekhar-rudder
left a comment
There was a problem hiding this comment.
Reviewed the v2 batching implementation — overall a clean, well-tested change that mirrors the established posthog BatchDestination pattern. A few cleanup suggestions around redundant request construction and now-unnecessary changes.
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
c6e9761 to
e8ac67f
Compare
|



🔒 Scanned for secrets using gitleaks 8.30.1
What are the changes introduced in this PR?
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:
What is the related Linear task?
Resolves INT-6612
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.