Skip to content

CDP-5981: add v2 batch endpoint to TrackClient#194

Open
jcpsimmons wants to merge 2 commits into
mainfrom
cdp-5981-v2-batch
Open

CDP-5981: add v2 batch endpoint to TrackClient#194
jcpsimmons wants to merge 2 commits into
mainfrom
cdp-5981-v2-batch

Conversation

@jcpsimmons
Copy link
Copy Markdown

@jcpsimmons jcpsimmons commented May 26, 2026

Summary

Adds TrackClient.batch(operations) which POSTs an array of operations to the v2 batch endpoint. The v2 URL is derived from the existing track root (or a custom defaults.url) by swapping /api/v1/api/v2, so region selection and custom URL overrides continue to work without additional configuration.

API

cio.batch([
  { type: "person", action: "identify", identifiers: { id: "1" }, attributes: { plan: "pro" } },
  { type: "person", action: "event", identifiers: { id: "1" }, name: "signup" },
]);

The operations parameter is required and must be a non-empty array; otherwise a MissingParamError is thrown. Operation items are passed through as the batch field of the request body, so callers are free to shape items per the public API docs without the SDK pinning a schema snapshot.

Test plan

  • npm run build — clean
  • npm test — 156 tests pass, nyc 100% coverage gate holds (branches/lines/functions/statements)
  • Constructor tests extended to assert the new trackV2Root field for default region, both regions, and custom URL
  • #batch tests cover the happy path (US), region variant (EU), empty-array rejection, and non-array rejection

Opening as draft pending review of the URL derivation strategy and the permissive BatchOperation type.


Note

Low Risk
New optional API surface with input validation only; no changes to existing identify/track flows beyond URL metadata on the client.

Overview
Adds TrackClient.batch(operations) to POST a non-empty array of operations to the Track API /api/v2/batch endpoint, wrapping them as { batch: operations } with permissive BatchOperation typing.

Introduces trackV2Root (and Region.trackV2Url) by deriving v2 from the existing v1 track URL—/api/v1/api/v2 for built-in US/EU regions and custom defaults.url when that segment is present; a custom URL without /api/v1 is used unchanged for both roots.

README documents usage; tests cover US/EU batch URLs, v2 root construction, and validation when operations is missing, empty, or not an array.

Reviewed by Cursor Bugbot for commit 6077cd1. Bugbot is set up for automated code reviews on this repo. Configure here.

Dr.J added 2 commits May 26, 2026 15:41
Adds TrackClient.batch(operations) which POSTs an array of operations
to the v2 /api/v2/batch endpoint. The v2 root is derived from the
existing track root (or custom URL) so region selection continues to
work without configuration changes.
Replaces the in-constructor .replace() ceremony with a trackV2Url field
on Region, so the canonical v2 URL is the source of truth and a future
change to the Region URL shape doesn't silently no-op. Custom URLs keep
the .replace() fallback (best-effort for proxies that already include
/api/v1). Tests now assert literal expected URLs instead of mirroring
the same .replace() expression, and the batch tests assert calledOnce
on the post stub.
@jcpsimmons jcpsimmons marked this pull request as ready for review May 26, 2026 22:53
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.

2 participants