Skip to content

refactor(audience): make identityType mandatory on Identify and Alias (SDK-222)#696

Merged
ImmutableJeffrey merged 3 commits into
mainfrom
feat/sdk-222-identitytype-mandatory
Apr 22, 2026
Merged

refactor(audience): make identityType mandatory on Identify and Alias (SDK-222)#696
ImmutableJeffrey merged 3 commits into
mainfrom
feat/sdk-222-identitytype-mandatory

Conversation

@ImmutableJeffrey
Copy link
Copy Markdown
Collaborator

@ImmutableJeffrey ImmutableJeffrey commented Apr 22, 2026

Summary

  • Flips identityType / fromType / toType to non-nullable on the Identify and Alias string overloads, removes the runtime null/empty warn-and-drop blocks so the type signature stops lying about optionality.
  • Makes MessageBuilder.Identify's identityType parameter non-nullable and always emits the field — the conditional that omitted an empty field is gone so the wire shape cannot drift.
  • Flips IdentityType.ToLowercaseString() to throw ArgumentOutOfRangeException on out-of-range enum casts rather than returning null. A silent null used to leak through to a dropped event; now the programmer error fails loud at the call site.
  • Reverts the Identify(Dictionary<string, object> traits) overload added in feat(audience): ImmutableAudience singleton + GDPR (SDK-147) #694 — it emits identify events with no identityType and cannot carry one meaningfully. Required precondition: the revert and the mandate are a single compile unit.
  • Tests repointed — invalid-enum-cast cases assert the throw; MessageBuilder tests that passed null for identityType now pass a valid value. Test count 161 → 155 (the six IdentifyTraits_* tests are gone with the overload).

Rationale

CDP requires identityType on every identify / alias event to match records to the correct identity namespace when processing data-deletion requests. The signatures merged in #694 accepted string? identityType / string? fromType / string? toType and silently dropped null-or-empty inputs, leaving the contract implicit and letting events ship without an identity namespace CDP can use.

Raised in PR #694 review thread

Linear: SDK-222
Parent: SDK-99 Unity SDK v1

ImmutableJeffrey and others added 2 commits April 22, 2026 17:17
…erload

Reverts 9b00cce, which added a traits-only Identify overload that
mirrored the @imtbl/audience Web SDK's identify(traits) shape.

The overload emits identify events with no identityType and cannot
carry one meaningfully (no userId to attach one to). CDP requires
identityType on every identify event to match records during data
deletion, so records produced by this path would be unreachable for
erasure.

Mechanical prerequisite for SDK-222: making identityType mandatory
on MessageBuilder.Identify is a compile error while this overload
exists. Web SDK parity will be reopened under a separate ticket once
the Web SDK drops its equivalent for the same CDP reason.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
CDP requires identityType on every identify / alias event so it can
match records to the correct identity namespace during data deletion.
Enforce the invariant through the type system end to end:

- `Identify(userId, identityType, traits?)` — identityType is
  non-nullable. The null/empty warn-and-drop block is gone; the type
  signature no longer lies about optionality.
- `Alias(fromId, fromType, toId, toType)` — fromType and toType are
  non-nullable. Same block removed.
- `MessageBuilder.Identify` — identityType parameter is non-nullable
  and always emitted; the conditional that omitted an empty field is
  gone so the wire shape cannot drift.
- `IdentityType.ToLowercaseString()` — casting to an out-of-range
  enum value now throws `ArgumentOutOfRangeException` rather than
  returning null. A silent null used to leak through to a dropped
  event; now the programmer error fails loud at the call site.

Tests repointed: invalid-enum-cast cases assert the throw, and
MessageBuilder tests that passed `null` for identityType now pass a
valid value since the parameter is no longer nullable.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ImmutableJeffrey ImmutableJeffrey requested review from a team as code owners April 22, 2026 07:20
Comment thread src/Packages/Audience/Runtime/ImmutableAudience.cs Outdated
Comment thread src/Packages/Audience/Runtime/ImmutableAudience.cs
ImmutableJeffrey added a commit that referenced this pull request Apr 22, 2026
Rewrites the comments on IdentityType.ToLowercaseString, the
Identify(string) and Alias(string) overloads in ImmutableAudience,
and the matching test comments and assertion messages so they
explain why identityType is mandatory — downstream data-deletion
needs it to match a user's events — without naming the specific
internal pipeline. Same invariant, just no internal name in the
source.

The test comment on ToLowercaseString_UnknownValue_Throws is
also rewritten to read cold: leads with the rule and a concrete
bad-cast example, names what ToLowercaseString emits and how the
backend uses it, then explains why a default return would hide
the bug.

Addresses PR #696 review: #696 (comment)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Rewrites the comments on IdentityType.ToLowercaseString, the
Identify(string) and Alias(string) overloads in ImmutableAudience,
and the matching test comments and assertion messages so they
explain why identityType is mandatory — downstream data-deletion
needs it to match a user's events — without naming the specific
internal pipeline. Same invariant, just no internal name in the
source.

The test comment on ToLowercaseString_UnknownValue_Throws is
also rewritten to read cold: leads with the rule and a concrete
bad-cast example, names what ToLowercaseString emits and how the
backend uses it, then explains why a default return would hide
the bug.

Addresses PR #696 review thread (discussion_r3122316478).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ImmutableJeffrey ImmutableJeffrey force-pushed the feat/sdk-222-identitytype-mandatory branch from 6606636 to d8c7f48 Compare April 22, 2026 08:42
@ImmutableJeffrey ImmutableJeffrey merged commit d08fe12 into main Apr 22, 2026
19 checks passed
@ImmutableJeffrey ImmutableJeffrey deleted the feat/sdk-222-identitytype-mandatory branch April 22, 2026 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

2 participants