Skip to content

feat(audience): wire onError callback from AudienceConfig through to core#2857

Merged
ImmutableJeffrey merged 2 commits intomainfrom
feat/audience-onerror
Apr 16, 2026
Merged

feat(audience): wire onError callback from AudienceConfig through to core#2857
ImmutableJeffrey merged 2 commits intomainfrom
feat/audience-onerror

Conversation

@ImmutableJeffrey
Copy link
Copy Markdown
Contributor

@ImmutableJeffrey ImmutableJeffrey commented Apr 15, 2026

Adds onError?: (err: AudienceError) => void to AudienceConfig and forwards it to the two places in the Audience constructor that already accept it downstream.

What changes

  • packages/audience/sdk/src/types.ts gains the onError? field on AudienceConfig.
  • packages/audience/sdk/src/sdk.ts passes config.onError into the MessageQueue options object (previously had onFlush but not onError) and into the 7th positional slot of createConsentManager (previously hard-coded to undefined).
  • packages/audience/sdk/src/index.ts re-exports AudienceError (runtime) and AudienceErrorCode (type) from @imtbl/audience-core so ESM consumers can import the error type. CDN consumers already have AudienceError via window.ImmutableAudience.AudienceError from feat(audience): CDN bundle entry point and tsup build (SDK-115) #2853.
  • packages/audience/sdk/src/sdk.test.ts adds two tests verifying the full wire-through against a mocked backend.

Why this exists

AudienceError is exported from @imtbl/audience-core and attached to window.ImmutableAudience by PR #2853, but the public AudienceConfig has no onError field and the Audience constructor passes undefined where the wire-through would go. Net result: studios using @imtbl/audience today have no way to receive AudienceError. This PR closes that gap with the smallest possible change — all the error mapping logic already exists in core.

Test plan

  • pnpm --filter @imtbl/audience run lint
  • pnpm --filter @imtbl/audience run typecheck
  • pnpm --filter @imtbl/audience run test — 58/58 passing (56 baseline + 2 new)
  • pnpm --filter @imtbl/audience-core run test — 150/150, no regression
  • CI green on this branch

Refs SDK-49

@nx-cloud
Copy link
Copy Markdown

nx-cloud bot commented Apr 15, 2026

View your CI Pipeline Execution ↗ for commit 4165586

Command Status Duration Result
nx run-many -p @imtbl/sdk,@imtbl/checkout-widge... ✅ Succeeded 1s View ↗
nx affected -t build,lint,test ✅ Succeeded 3s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-16 05:59:33 UTC

@nx-cloud
Copy link
Copy Markdown

nx-cloud bot commented Apr 15, 2026

View your CI Pipeline Execution ↗ for commit 6706e2e

Command Status Duration Result
nx affected -t build,lint,test ✅ Succeeded 9s View ↗
nx run-many -p @imtbl/sdk,@imtbl/checkout-widge... ✅ Succeeded 6s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-15 04:57:30 UTC

@ImmutableJeffrey ImmutableJeffrey force-pushed the feat/audience-cdn-bundle branch 2 times, most recently from 90add33 to 42565f8 Compare April 15, 2026 07:19
nattb8
nattb8 previously approved these changes Apr 15, 2026
@ImmutableJeffrey ImmutableJeffrey marked this pull request as ready for review April 15, 2026 23:12
@ImmutableJeffrey ImmutableJeffrey requested a review from a team as a code owner April 15, 2026 23:12
Base automatically changed from feat/audience-cdn-bundle to main April 15, 2026 23:41
@ImmutableJeffrey ImmutableJeffrey dismissed nattb8’s stale review April 15, 2026 23:41

The base branch was changed.

@ImmutableJeffrey ImmutableJeffrey requested a review from a team as a code owner April 15, 2026 23:41
nattb8
nattb8 previously approved these changes Apr 15, 2026
…core

Exposes AudienceError to web SDK consumers. The core queue and consent
manager already accept an onError callback and map TransportError to a
public AudienceError via toAudienceError; this commit just forwards
AudienceConfig.onError into both positional slots in the Audience
constructor, which were previously hard-coded to undefined.

Also re-exports AudienceError (runtime) and AudienceErrorCode (type)
from the @imtbl/audience package index so ESM consumers can import
the error type they need for their onError handler. CDN consumers
already have it via window.ImmutableAudience.AudienceError from the
CDN bundle work in #2853.

Two new sdk.test.ts tests cover the wire-through end-to-end: a flush
failure against a mocked backend, and a consent sync failure against
a mocked backend. Both verify the AudienceError shape (name, code,
status, endpoint) rather than just that the callback fires.

Refs SDK-49

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ImmutableJeffrey ImmutableJeffrey added this pull request to the merge queue Apr 16, 2026
Merged via the queue into main with commit c4f8424 Apr 16, 2026
7 checks passed
@ImmutableJeffrey ImmutableJeffrey deleted the feat/audience-onerror branch April 16, 2026 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants