Skip to content

feat(audience)!: add IdentityType, rename alias params to id/identityType#2836

Merged
ImmutableJeffrey merged 2 commits into
mainfrom
feat/audience-sdk-foundation
Apr 9, 2026
Merged

feat(audience)!: add IdentityType, rename alias params to id/identityType#2836
ImmutableJeffrey merged 2 commits into
mainfrom
feat/audience-sdk-foundation

Conversation

@ImmutableJeffrey
Copy link
Copy Markdown
Contributor

@ImmutableJeffrey ImmutableJeffrey commented Apr 8, 2026

Summary

Foundation change for the audience SDK: adds the shared IdentityType union and narrows the web SDK to use it.

  1. IdentityType const + type — shared identity type in @imtbl/audience-core matching the backend's OAS enum (passport | steam | epic | google | apple | discord | email | custom). Exported as both a const object (for runtime values) and a type alias (for parameter typing).
  2. Narrowed identify() and alias() paramsidentify()'s positional string arg changes type from stringIdentityType. alias() parameter shape also changes from { uid, provider }{ id, identityType } to match backend wire field names (fromId/fromType/toId/toType).

Commits

  1. feat(audience-core): export IdentityType const + type — the union + JSDoc pointer to the backend OAS
  2. feat(audience)!: use IdentityType for identify() and alias() paramsBREAKING, see below

⚠️ Breaking change

alias() now takes { id, identityType } objects instead of { uid, provider }. identify()'s positional string arg keeps the same name but changes type from stringIdentityType.

// before
audience.identify('user-123', 'passport', traits);
audience.alias(
  { uid: 'steam-id', provider: 'steam' },
  { uid: 'passport-id', provider: 'passport' },
);

// after
audience.identify('user-123', 'passport', traits);                  // typed
audience.alias(
  { id: 'steam-id', identityType: 'steam' },
  { id: 'passport-id', identityType: 'passport' },
);

Nothing from this package has been published externally, so the rename is safe to land — but calling it out so reviewers can push back if they disagree.

Tickets

  • Partially addresses SDK-74 (Identity types should be typed and match backend enums) — web SDK half only. Pixel half tracked as SDK-77.
  • The rename is broader than SDK-74 strictly required. SDK-74 asked for the existing string params to be narrowed; this PR also renames uid/providerid/identityType for parity with backend wire field names. Flagging for review.

Scope

This branch previously also contained commits for a TransportResult refactor, error propagation, and an AudienceError surface on Audience.init(). Those have been split out based on reviewer feedback that the transport/queue/errors layer needs deeper design work — unified error sink in core rather than sdk, collapsing the Transport interface, fixing a partial-success silent-drop in MessageQueue.flush, and wiring onError through pixel. Landing identity types first unblocks the demo PR.

Test plan

  • pnpm --filter @imtbl/audience-core --filter @imtbl/audience --filter @imtbl/pixel test — 203 tests pass (90 core + 49 sdk + 64 pixel)
  • CI green

What's next

  • Follow-up PR: audience transport/errors refactor.
  • Demo PR (feat/audience-web-sdk-demo) builds the interactive demo page on top of this branch once it lands.

🤖 Generated with Claude Code

ImmutableJeffrey and others added 2 commits April 9, 2026 09:03
Add IdentityType as a const-object-plus-type export in
@imtbl/audience-core, re-exported through @imtbl/audience. Values
mirror the backend OAS IdentityType enum exactly (passport, steam,
epic, google, apple, discord, email, custom). A new types.test.ts
guards against drift.

The const form lets studios import a runtime value (for dropdowns,
enum-style access via IdentityType.Passport) while the type form
keeps compile-time narrowing available for SDK method signatures
that will use it in subsequent commits.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Rename identify/alias parameters so they match the backend wire format.
The SDK now accepts { id, identityType } objects instead of { uid, provider },
narrowing identityType to the IdentityType union exported from
@imtbl/audience-core so invalid providers (e.g. 'foo') fail at compile time
rather than at the backend.

Before:
  audience.identify('user-123', 'passport', { email: '...' });
  audience.alias({ uid: 'steam-id', provider: 'steam' },
                 { uid: 'passport-id', provider: 'passport' });

After:
  audience.identify('user-123', 'passport', { email: '...' });
  audience.alias({ id: 'steam-id', identityType: 'steam' },
                 { id: 'passport-id', identityType: 'passport' });

BREAKING CHANGE: alias() now takes { id, identityType } objects instead
of { uid, provider }. identify()'s positional string argument stays the
same but is now typed as IdentityType instead of string.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Apr 8, 2026

View your CI Pipeline Execution ↗ for commit 7da2977

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

☁️ Nx Cloud last updated this comment at 2026-04-09 00:41:50 UTC

Comment thread packages/audience/sdk/src/types.ts Outdated
Comment thread packages/audience/sdk/src/sdk.ts Outdated
Comment thread packages/audience/core/src/transport.ts Outdated
@ImmutableJeffrey ImmutableJeffrey changed the title feat(audience): errors, structured transport, and IdentityType feat(audience)!: add IdentityType, rename alias params to id/identityType Apr 9, 2026
@ImmutableJeffrey ImmutableJeffrey force-pushed the feat/audience-sdk-foundation branch from 7a073b4 to 7da2977 Compare April 9, 2026 00:28
@ImmutableJeffrey ImmutableJeffrey added this pull request to the merge queue Apr 9, 2026
Merged via the queue into main with commit f390789 Apr 9, 2026
7 checks passed
@ImmutableJeffrey ImmutableJeffrey deleted the feat/audience-sdk-foundation branch April 9, 2026 01:18
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