Skip to content

feat(customerio): add v2 API support with native batching framework - #5303

Merged
maheshkutty merged 9 commits into
developfrom
feat/customerio-track-v2
Jun 23, 2026
Merged

maheshkutty merged 9 commits into
developfrom
feat/customerio-track-v2

Conversation

@maheshkutty

@maheshkutty maheshkutty commented Jun 19, 2026 •

Copy link
Copy Markdown
Contributor

🔒 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:

  • 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

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.

@maheshkutty
maheshkutty requested a review from a team as a code owner June 19, 2026 09:34
@coderabbitai

coderabbitai Bot commented Jun 19, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

⚠️ Parsing warnings (1)
Validation error: Unrecognized key: "auto_resolve_threads"
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Walkthrough

This PR introduces a complete CustomerIO v2 batch API transformation pathway gated by a batching framework feature flag. New v2 modules define TypeScript types and Zod input schema with per-event validation, datacenter-aware config constants for endpoint selection and size limits, event-specific payload builders for identify, track, page, screen, alias, group, and device operations, and a processV2 entry point that orchestrates envelope building and metadata assembly. The existing transform.ts is updated to route v2-enabled workspaces through the new pipeline. A new routerTransform.ts wires everything into a BatchDestination integration with per-object size enforcement at 32KB.

Changes

CustomerIO v2 Batching Pathway

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
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • rudderlabs/rudder-transformer#5187: Builds new destination routerTransform integrations on top of the native BatchDestination batching framework that this PR's CustomerIO integration extends.
  • rudderlabs/rudder-transformer#5299: Modifies the same src/v0/destinations/customerio/transform.ts file, 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 ⚠️ Warning 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.

❤️ Share

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

@maheshkutty
maheshkutty requested a review from Copilot June 19, 2026 09:38

@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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between f64488c and 6e25a3d.

⛔ Files ignored due to path filters (6)
  • src/v0/destinations/customerio/v2/data/CustomerIODeviceV2.json is excluded by !**/*.json
  • src/v0/destinations/customerio/v2/data/customerIoGroup.json is excluded by !**/*.json
  • test/integrations/destinations/customerio/processor/data.ts is excluded by !**/test/**
  • test/integrations/destinations/customerio/processor/v2data.ts is excluded by !**/test/**
  • test/integrations/destinations/customerio/router/data.ts is excluded by !**/test/**
  • test/integrations/destinations/customerio/router/v2data.ts is excluded by !**/test/**
📒 Files selected for processing (6)
  • src/v0/destinations/customerio/routerTransform.ts
  • src/v0/destinations/customerio/transform.ts
  • src/v0/destinations/customerio/v2/config.ts
  • src/v0/destinations/customerio/v2/transform.ts
  • src/v0/destinations/customerio/v2/types.ts
  • src/v0/destinations/customerio/v2/util.ts

@codecov

codecov Bot commented Jun 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.08602% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.68%. Comparing base (cdc967f) to head (e8ac67f).

Files with missing lines Patch % Lines
src/v0/destinations/customerio/v2/util.ts 91.86% 10 Missing ⚠️
src/v0/destinations/customerio/routerTransform.ts 96.15% 1 Missing ⚠️
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.
📢 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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 12 changed files in this pull request and generated 2 comments.

@maheshkutty
maheshkutty force-pushed the feat/customerio-track-v2 branch from 7890c4e to 3f1e988 Compare June 19, 2026 10:33

@shekhar-rudder shekhar-rudder left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 shekhar-rudder left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more from a v1-vs-v2 parity pass: the RETL / mappedToDestination preprocessing isn't carried over to the v2 path.

@shekhar-rudder shekhar-rudder left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 shekhar-rudder left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small follow-up on the RETL-aware refine: the casts can be avoided by declaring the inspected fields in the schema.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

@shekhar-rudder shekhar-rudder left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@maheshkutty
maheshkutty force-pushed the feat/customerio-track-v2 branch from c6e9761 to e8ac67f Compare June 23, 2026 05:44
@sonarqubecloud

Copy link
Copy Markdown

@maheshkutty
maheshkutty merged commit 7b004f4 into develop Jun 23, 2026
34 checks passed
@maheshkutty
maheshkutty deleted the feat/customerio-track-v2 branch June 23, 2026 06:03
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.

4 participants