Skip to content

feat(hs_audience): hubspot audience list membership destination - #5638

Merged
ASaiAnudeep merged 19 commits into
developfrom
feature/act2-1015-hs-audience
Oct 16, 2026
Merged

ASaiAnudeep merged 19 commits into
developfrom
feature/act2-1015-hs-audience

Conversation

@ASaiAnudeep

Copy link
Copy Markdown
Contributor

🔒 Scanned for secrets using gitleaks 8.28.0

What are the changes introduced in this PR?

Adds the HubSpot Audience destination so warehouse / audience rows can add and remove contacts on an existing HubSpot list. Membership sync only — not contact create/update like classic HubSpot. Covers transform, batching, delivery response handling, and tests (unit, component, live scaffolding).

What is the related Linear task?

Resolves ACT2-1015

Please explain the objectives of your changes below

Transformer piece of HubSpot Audience v1 (Splashtop first). Customers sync a warehouse table, SQL model, or audience into a MANUAL/SNAPSHOT HubSpot contact list. Lookout is a second way to configure the same destination later — not a separate HubSpot path.

Depends on / ships with:

Any changes to existing capabilities/behaviour, mention the reason & what are the changes ?

N/A for product behavior. Small network-adapter tweak so proxy delivery can attach the bearer token without putting it on persisted router output (live events stay token-free).

Any new dependencies introduced with this change?

N/A

Any new generic utility introduced or modified. Please explain the changes.

N/A — destination-local helpers only. Built on the existing DestinationIntegration batching / delivery framework.

Any technical or performance related pointers to consider with the change?

  • Email rows need a HubSpot contact batch-read before membership; failures are isolated per credential / chunk so one bad lookup doesn’t sink the whole batch.
  • Add and remove are separate requests (≤1000 ids each). Proxy delivery is required for auth.
  • Live membership scenario is in-repo but not yet run against a sandbox portal in this change.

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.

🔒 Scanned for secrets using gitleaks 8.28.0
@ASaiAnudeep
ASaiAnudeep requested review from a team as code owners October 7, 2026 15:27
@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a482e7b8-7351-4ae4-a6df-5c84472409cc

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@codecov

codecov Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.91281% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.15%. Comparing base (b6034ac) to head (dca3b50).

Files with missing lines Patch % Lines
src/v0/destinations/hs_audience/routerTransform.ts 90.75% 11 Missing ⚠️
src/v0/destinations/hs_audience/lookup.ts 97.95% 2 Missing ⚠️
src/v0/destinations/hs_audience/utils.ts 97.61% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #5638      +/-   ##
===========================================
+ Coverage    92.12%   92.15%   +0.03%     
===========================================
  Files          713      719       +6     
  Lines        39600    39967     +367     
  Branches      9205     9281      +76     
===========================================
+ Hits         36481    36833     +352     
- Misses        2934     2949      +15     
  Partials       185      185              

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

@am6010 am6010 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.

Reviewed against the merged spec (rudder-specs#204). Solid overall:

  • The token never reaches router output, errors, logs or stats.
  • The network.js change only affects HS_AUDIENCE.
  • Add and remove are split at 1000 ids, and each row uses its own list id.
  • The add/remove conflict guard works.
  • Each job gets its own verdict, including duplicate ids.
  • The 207 lookup is matched correctly after case and whitespace normalization.

Ran on e3b23a3 with Node 22:

  • hs_audience unit tests, network.test.js and features.test.ts: 139 passed.
  • test:ts -- component --destination=hs_audience: 9 passed.
  • eslint, prettier --check and tsc --noEmit: clean.

Two inline comments, one high and one medium. Also:

  • Stale or merged record ids: I found no evidence that add-and-remove returns a surviving id after a merge. If it ever does, missingIds fails the whole batch closed, because any added or removed id that wasn't sent retries every job. The spec already lists this as a pending live check, so it's worth covering in the live run before GA.
  • Rollout: the router default noOfJobsToBatchInAWorker is 20 (10 on hosted US). Until rudderstack-operator#1775 lands, batches are about 50× smaller, which means many more lookup and membership calls. That likely explains the slowness in local testing.
  • Nits:
    • network.js hard-codes 'HS_AUDIENCE' in the shared adapter; a statTags flag would be cleaner. Also, the comment says payload logs would store the bearer token, but requestLog doesn't log headers, so it's really the emails.
    • A missing token or list id is thrown as InstrumentationError, where ConfigurationError would give the right errorType.
    • A 408 aborts as "rejected"; it is arguably retryable.

@ASaiAnudeep
ASaiAnudeep requested a review from am6010 October 12, 2026 10:53

@lvrach lvrach 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.

Commenting, no blocker. The verdict mapping is careful: every job gets exactly one verdict, the 1,000-id split never drops or doubles a job, and the token stays out of errors, logs and stats. I ran the hs_audience unit tests (99) and the component tests (11) on 5c4d09b; all pass. Two points before GA, one of them carried over from the earlier review.

[minor] Confirm the real no-op body before GA. {} now succeeds, but an empty 200 still retries every job. The proxy hands the handler '' for an empty body (networkUtils.js:163, data || ''), missingIds('') returns null, and delivery.test.ts pins that to 500. In steady state, update rows re-add current members, so if HubSpot answers those with an empty body, each batch retries and then aborts while HubSpot already holds the right state. The earlier evidence is about memberships/add, not add-and-remove, so the real shape is still open. HubSpot's spec documents only a 200 whose body carries recordIdsMissing, recordIdsRemoved and recordsIdsAdded, and no 204 or empty body. An empty 2xx therefore cannot hide a failed add. Can you run the new live no-op steps and attach the captured body? If it is empty, treat a 2xx '' the same as {}.

[minor] One unparseable secondary email now fails its whole lookup chunk. This path is new in 8f1edcc. claimResult returns false when any hs_additional_emails entry fails validator.isEmail, so all 100 emails in the chunk get LOOKUP_UNCORRELATED on every retry. Example: a contact with hs_additional_emails = "old@legacy_corp.com". validator.isEmail rejects the underscore domain (I checked), and HubSpot's own validation is looser. Skipping an address that fails validation is safe, because it can never equal a requested email, which passed the same validator. Keep the conflict check.

Optional

  • [suggestion] Transport errors outside the five mapped codes (EPIPE, ENOTFOUND) become a synthetic 400 in networkUtils.js, and delivery.ts:209 then aborts the batch as "HubSpot membership update was rejected", though HubSpot never saw the request. The lookup path already guards against this, and delivery could do the same.
  • [suggestion] After a 429, 401 or 403 on one lookup chunk, the loop still sends the remaining chunks (lookup.ts:290-301). Stopping there and giving the rest the same error saves calls when HubSpot is already throttling.
  • [suggestion] Two cases still fail a whole chunk of 100, not one email: a 207 with a per-input error other than OBJECT_NOT_FOUND, and two contacts that claim the same email. Degrading per email would contain both.
  • [suggestion] numErrors !== errors.length rejects the chunk (lookup.ts:127-132). HubSpot groups missing ids into one error entry (context.ids), and the docs define numErrors only as "the number of errors encountered". If it counts ids, any chunk with two or more unknown emails fails. The only live-shaped fixture has one miss. The live run could include two unknown emails to settle it.
  • [suggestion] config.ts:45-47 calls INVALID_OBJECT_TYPE_FOR_LIST "HubSpot's published ineligible-list signal". It is not in HubSpot's docs or OpenAPI spec. Cite the capture, or say "observed".
  • [suggestion] The HubSpot reply mocks are hand-typed. I validated them against HubSpot's pinned Lists v3 and Contacts v3 specs: every field the code reads matches, but 8 of 11 mocks miss fields the spec requires (router/network.ts:14, lookup.test.ts:20,106, dataDelivery/network.ts:94,98). live.ts already captures real bodies. Committing a recorded 200, a 207 OBJECT_NOT_FOUND and a no-op reply would tie the tests to HubSpot.
  • [suggestion] HubSpot returns 477 while a portal migrates between data-hosting locations, with Retry-After of up to 24 hours (docs). Here 477 falls into clientFailure and aborts every job as "rejected" (delivery.ts:209), and lookup.ts:202 aborts the row. Aborted rows come back as failed keys on the next run, so nothing is lost for good. Retrying 477 is still the right verdict. The older HS destination does not handle it either.

On rollout: operator#1775 leaves noOfWorkers at the default 64 for HS_AUDIENCE, and lookups are not bounded per token. I asked there whether 64 is intended.

🔒 Scanned for secrets using gitleaks 8.28.0
🔒 Scanned for secrets using gitleaks 8.28.0
am6010
am6010 previously approved these changes Oct 15, 2026

@am6010 am6010 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.

Approving. The empty-2xx fix, hs_additional_emails matching, ConfigurationError for a missing token or list id, and the network.js comment fix all hold.

Not blocking:

  • A 408 still aborts as rejected in delivery.ts and lookup.ts. intercom_v2 retries it.
  • network.js still hard-codes HS_AUDIENCE. A statTags flag would be cleaner.
  • The failing "Verify generated secret paths" check should clear once integrations-config#2798 is released and the package is bumped here.
  • Before GA, the live run should still cover merged contact ids.

Comment thread src/adapters/network.js Resolved
🔒 Scanned for secrets using gitleaks 8.28.0
@ASaiAnudeep
ASaiAnudeep requested a review from am6010 October 16, 2026 06:18
am6010 added a commit that referenced this pull request Oct 16, 2026
ACT2-1230 review (#5681), as in HubSpot #5638. processAxiosResponse maps a
Node transport failure without an HTTP status (ENOTFOUND, EPIPE, ...) onto
a synthetic 400 with a `[CODE] :: ...` body, which delivery and the email
lookup treated as a permanent rejection.

- delivery: a 400 whose body is a Node transport message retries every job
  ('Marketo request failed (network error)').
- lookup: a client response with no HTTP status throws a RetryableError
  ('Marketo lead lookup failed (network error)') before processAxiosResponse.
am6010 added a commit that referenced this pull request Oct 16, 2026
…ssion

ACT2-1230 review (#5681), as HubSpot #5638 did in c4d8bff. Request and
response payload logs are written only at LOG_LEVEL=event, a global setting
that already controls them, so a per-destination suppression in
commonHandler is not needed. src/adapters/network.js and network.test.js
match develop again.
am6010 added a commit that referenced this pull request Oct 16, 2026
…work default

ACT2-1230 review (#5681), as in HubSpot #5638. The framework already
retries a 5xx, so the explicit '5xx' status override restated the default.
The 2xx handling and the 4xx override through perItem stay; the header
comment and the 5xx test now describe and expect the framework's retryable
throw.
am6010 added a commit that referenced this pull request Oct 16, 2026
…sted

ACT2-1230 review (#5681), as HubSpot #5638 did in 8f1edcc. A returned lead
for an address the chunk did not ask for says nothing about the requested
emails, so it is now skipped instead of retrying the whole chunk; the other
emails resolve as usual. A lead with no email, or a matched email with an
invalid id, still retries the chunk as uncorrelated.
🔒 Scanned for secrets using gitleaks 8.28.0
🔒 Scanned for secrets using gitleaks 8.28.0
@sonarqubecloud

Copy link
Copy Markdown

@ASaiAnudeep
ASaiAnudeep merged commit 0ba2227 into develop Oct 16, 2026
64 of 65 checks passed
@ASaiAnudeep
ASaiAnudeep deleted the feature/act2-1015-hs-audience branch October 16, 2026 13:25
am6010 added a commit that referenced this pull request Oct 20, 2026
…nation (#5681)

## What are the changes introduced in this PR?

Adds `MARKETO_AUDIENCE`, a batching-framework destination that adds
leads to, and removes them from, an existing Marketo static list. It is
used by rETL and by Lookout activations.

- **`src/v0/destinations/marketo_audience/`** (`DestinationIntegration`,
registered `{ routerTransform: true, batching: true }` in
`src/features.ts`):
- **`transformEvents` override (pre-stage), run once per batch before
`super.transformEvents`:**
- fetches the token once per call, using the shared `getAuthToken` and a
`MARKETO_AUDIENCE_AUTH` cache. A failed token call gets a fixed reason
per class (throttled, retry, or abort with its status), so Marketo's
message text never reaches a row; a network failure with no HTTP status
retries;
    - checks each row's own list and identifiers;
- looks up emails in batches (up to 300 per `POST
/rest/v1/leads.json?_method=GET`, with a `URLSearchParams` form body). A
returned lead whose email wasn't requested is ignored, so it can't fail
the other emails in the batch; a network failure with no HTTP status
retries the rows. A 1003 (more than 1,000 leads match) halves the batch
until single emails remain, so only the email that still returns 1003
fails, with "More than 1,000 Marketo leads match this email". A
`nextPageToken` is followed even when `moreResult` is absent.
- **Rows:** if the router input both adds and removes one lead on one
list, every row for that lead fails, including a `dontBatch` row that
the framework transforms in a separate call. Each later row naming a
lead already seen goes in its own request. Every failure is a typed
error on its own row; an unexpected pre-stage error fails the remaining
rows with a retryable error and is logged with its error name and stack
frames only (no message text, which can contain emails).
- **`transformEvent`:** synchronous. Builds one `POST`/`DELETE
/rest/v1/lists/{listId}/leads.json` per row with `Authorization:
Bearer`.
- **Batching:** `ChunkBatchStrategy` of 300 lead IDs, body `{ input }`.
- **`delivery.ts`:** overrides 2xx, 4xx and 5xx, and every verdict goes
through `perItem`, so the raw body stays out of job errors. 2xx:
Marketo's HTTP-200 responses become one verdict per job, matched by lead
ID (codes 1004/1015/1008, token 601/602 eviction, throttled
502/606/608/615 and daily quota 607, 1013, 603). 4xx: abort, except the
proxy's synthetic 400 for a network failure (EPIPE, ENOTFOUND…), which
retries because Marketo never saw the request. 5xx: retry with a fixed
reason. No lead ID, email or Marketo message text appears in any reason.
- **`secretPaths.json`:** `"MARKETO_AUDIENCE":
["headers.Authorization"]`, so Live Events masks the token.
- **`test/integrations/destinations/marketo_audience/`:** router (8
cases), dataDelivery (9 cases), network mocks.

## What is the related Linear task?

Resolves ACT2-1230 (parent ACT2-1013)

## Please explain the objectives of your changes below

Spec:
[rudder-specs#214](rudderlabs/rudder-specs#214),
§6.3, decisions D5–D12. Pattern: HubSpot `hs_audience` (#5638).

**Dependencies and merge order:**
- `check:secret-paths` passes: the `marketo_audience` definition
(rudder-integrations-config #2836, ACT2-1228) is merged to config
`main`.
- Operator values (router batch, proxy, throttle) are in
rudderstack-operator ACT2-1233. Delivery needs `transformerProxy: true`.

### Any changes to existing capabilities/behaviour, mention the reason &
what are the changes ?

N/A. No shared code changes; `network.js` is untouched. Following the
review of #5638, there's no per-destination log suppression: request
bodies reach network logs only at the global `LOG_LEVEL=event`.

### Any new dependencies introduced with this change?

N/A

### Any new generic utility introduced or modified. Please explain the
changes.

N/A. `getAuthToken` is reused unchanged. This destination strips the
shared error when Marketo returns `expires_in: 0`, because that error
contains the token. MARKETO and MARKETO_STATIC_LIST still have that
leak; it's out of scope here.

### Any technical or performance related pointers to consider with the
change?

- **Token:** at most one identity call per batch. A failed fetch fails
every remaining row once. 601/602 from the lookup or delivery evicts the
cached token, per pod; a later `dontBatch` call on the same instance
then fetches a new one.
- **Daily quota (607):** throttled, as in MARKETO and
MARKETO_STATIC_LIST. Rows retry until Marketo resets the quota at 12:00
AM CST, and the rETL sync stays running until then.
- **Repeated leads:** if two rows resolve to the same lead with the same
operation (the same Lead ID twice, or a Lead ID and an email for one
lead), they go in separate requests via `internalGroupKey`. No request
holds a lead ID twice, so delivery matches each result to its job by
lead ID.
- **Accepted for v1:** with `LOG_LEVEL=event`, network logs include the
lookup body (up to 300 emails) and the identity response, the same as
other destinations today (documented in the spec's observability notes).

**Not covered (phase 2, waiting on Marketo credentials):**
- `live.ts` is left out until `LIVE_SECRET_MARKETO_AUDIENCE` exists in
Vault. The live matrix ignores `enabled: false` and would fail on every
push.
- Live checks:
- POST and DELETE accept the JSON `input` body, and result IDs echo the
sent IDs.
  - The status for re-adding a member and for removing a non-member.
  - Case-insensitive email lookup through the `_method=GET` form post.
  - Real 606/607/1008 bodies and paging.
  - What Marketo echoes for a merged lead.

<hr>

### Developer checklist

- [x] My code follows the style guidelines of this project
- [x] **No breaking changes are being introduced.**
- [x] All related docs linked with the PR?
- [ ] All changes manually tested? (mocked only; live checks in phase 2)
- [ ] Any documentation changes needed with this change?
- [ ] Is the PR limited to 10 file changes? (18 files: one new
destination plus its tests and fixtures)
- [x] Is the PR limited to one linear task?
- [x] Are relevant unit and component test-cases added in **new
readability format**?

**Checks** (Node 22, the repo's pinned major):
- The pre-commit hook (`test:ts`, `test:js`, lint-staged, commitlint)
passed on every commit; the latest run had `test:ts` 128 suites and
`test:js` 101 suites.
- Component tests (`--destination=marketo_audience`) pass, and `tsc
--noEmit` on src and test is clean.

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

🤖 Generated with [Claude Code](https://claude.com/claude-code)
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.

5 participants