Skip to content

fix: Allow all user identity types in Identity.search#1256

Merged
rmi22186 merged 5 commits intodevelopmentfrom
fix/send-all-identities
May 5, 2026
Merged

fix: Allow all user identity types in Identity.search#1256
rmi22186 merged 5 commits intodevelopmentfrom
fix/send-all-identities

Conversation

@rmi22186
Copy link
Copy Markdown
Member

@rmi22186 rmi22186 commented May 5, 2026

Summary

Expands Identity.search so it forwards every identifier the partner has, not just email. Builds on #1255 (the initial IDSync Search client API), which restricted known_identities to { email }.

In production, partners sometimes pass hashed email through other, other2-10, or customerid rather than the plain email field. The previous shape silently dropped those, so search returned 404 even when a match existed under a non-email key.

What changed

src/identity/search.ts

  • sendSearchRequest now accepts UserIdentities (the SDK's full identity surface) instead of the bespoke { email: string } type.
  • The "no usable identifier" guard now checks that any property has a non-empty string value (was: required email specifically).
  • Forwards { ...knownIdentities } to the wire instead of { email: knownIdentities.email }.
  • Removes the now-unused IIdentitySearchKnownIdentities interface in favor of UserIdentities.

Public types (src/public-types.ts, src/identity.interfaces.ts)

  • Drops IIdentitySearchKnownIdentities from the public surface (it was never load-bearing for kits — only one prior consumer, this PR removes it).
  • Adds IUserIdentities for consumption by Kit
  • SDKIdentityApi.search and executeSearchRequest updated to use UserIdentities.

Tests (test/src/tests-search.ts)

  • Renames the existing guard test to reflect the new "any non-empty string identifier" contract; expands its inputs to include { email: 12345, other: null } (mixed wrong-typed + null).
  • New: forwards non-email identifiers (e.g. hashed email in 'other') to the wire — asserts that { other: 'sha256:abc123', customerid: 'cust-1' } produces a 200 round-trip with the full identifier set in the request body.

Breaking changes

IIdentitySearchKnownIdentities is removed from the public exports. It was added in #1255 and (per `git grep`) had no external consumers, so the practical blast radius is zero — but worth flagging for changelog purposes.

Test plan

  • `npm run test` — Mocha suite, including the renamed/extended guard test and the new `forwards non-email identifiers` test
  • `npm run build` — `tsc -p tsconfig.types.json` should emit `IUserIdentities` into `dist/types/src/public-types.d.ts`
  • Verify a kit consumer (Rokt) can `import type { IUserIdentities } from '@mparticle/web-sdk'` and call `mParticle.Identity.search(apiKey, { other: '' }, cb)` against a real workspace with a non-email identifier

🤖 Generated with Claude Code

pair with mparticle-integrations/mparticle-javascript-integration-rokt#93

@rmi22186 rmi22186 marked this pull request as ready for review May 5, 2026 13:21
@rmi22186 rmi22186 requested a review from a team as a code owner May 5, 2026 13:21
@rmi22186 rmi22186 requested a review from alexs-mparticle May 5, 2026 13:21
@cursor
Copy link
Copy Markdown

cursor Bot commented May 5, 2026

PR Summary

Medium Risk
Expands the identity search request payload and validation logic; behavior changes could affect who gets matched and what identifiers are sent over the wire, and it removes a previously exported type.

Overview
Identity.search now accepts and forwards the full UserIdentities map (not just email) to the /v1/search endpoint, after stripping falsy identity values.

The guard rails were updated to skip the network call unless any identifier contains a non-empty string, and types/exports were adjusted by removing IIdentitySearchKnownIdentities and adding IUserIdentities to the public surface. Tests were updated and expanded to cover non-email identifiers and falsy/null handling.

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

Comment thread src/identity/search.ts Outdated
Comment thread src/identity/search.ts Outdated
Comment on lines +121 to +127
const hasIdentifier =
knownIdentities &&
typeof knownIdentities === 'object' &&
Object.values(knownIdentities).some(
(v) => typeof v === 'string' && v.length > 0,
);
if (!hasIdentifier) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making this a convenience method right before invocation doesn't really help with readability, IMO.

We probably have some utility methods that could help clean this up a bit instead, or we can roll this into a new utility method.

Suggested change
const hasIdentifier =
knownIdentities &&
typeof knownIdentities === 'object' &&
Object.values(knownIdentities).some(
(v) => typeof v === 'string' && v.length > 0,
);
if (!hasIdentifier) {
if (!isEmpty(knownIdentities) && knownIdentities.some(v => !isEmpty(v)) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed. I had the same idea and the robot was telling me isEmpty would let things like {email: 1234} through. However, we do validation prior to this so it ended up being a non issue.

Comment thread src/identity/search.ts Outdated
Comment thread src/identity.interfaces.ts Outdated
rmi22186 added a commit that referenced this pull request May 5, 2026
- IUserIdentities: drop redundant `| undefined` from each property — the
  `?` modifier already implies undefined (per @alexs-mparticle review).
- search.ts: route knownIdentities through `Validators.removeFalsyIdentityValues`
  before the guard and the wire spread. Strips undefined/0/false/'' (with a
  caller-side warning), preserves null (server accepts it as a "no value"
  sentinel). Resolves the Cursor bot concern about unvalidated values
  reaching the wire while matching `Identity.identify/login/modify`
  behavior.
- search.ts: simplify the no-usable-identifier guard with `isEmpty` plus a
  string-value check (per @alexs-mparticle review).
- tests-search.ts: add coverage for the falsy-stripping + null-preservation
  behavior — `{ email: 'valid@example.com', customerid: null, other: '' }`
  hits the wire as `{ email: 'valid@example.com', customerid: null }`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- IUserIdentities: drop redundant `| undefined` from each property — the
  `?` modifier already implies undefined (per @alexs-mparticle review).
- search.ts: route knownIdentities through `Validators.removeFalsyIdentityValues`
  before the guard and the wire spread. Strips undefined/0/false/'' (with a
  caller-side warning), preserves null (server accepts it as a "no value"
  sentinel). Resolves the Cursor bot concern about unvalidated values
  reaching the wire while matching `Identity.identify/login/modify`
  behavior.
- search.ts: simplify the no-usable-identifier guard with `isEmpty` plus a
  string-value check (per @alexs-mparticle review).
- identity.js: trim the `Identity.search` JSDoc to a one-liner — the long
  identifier-list inventory drifts from the type and adds noise without
  helping readers.
- tests-search.ts: add coverage for the falsy-stripping + null-preservation
  behavior — `{ email: 'valid@example.com', customerid: null, other: '' }`
  hits the wire as `{ email: 'valid@example.com', customerid: null }`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@rmi22186 rmi22186 force-pushed the fix/send-all-identities branch from 24274c0 to 4dcf5a7 Compare May 5, 2026 14:54
Comment thread src/identity/search.ts
Comment thread src/identity/search.ts Outdated
rmi22186 and others added 2 commits May 5, 2026 11:25
Co-authored-by: Alex S <49695018+alexs-mparticle@users.noreply.github.com>
Co-authored-by: Alex S <49695018+alexs-mparticle@users.noreply.github.com>
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a6672c9. Configure here.

Comment thread src/identity/search.ts Outdated
Comment thread src/identity/search.ts Outdated
Comment thread src/identity/search.ts
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 5, 2026

@rmi22186 rmi22186 requested a review from samdozor May 5, 2026 16:22
@rmi22186 rmi22186 merged commit 40e2972 into development May 5, 2026
30 of 33 checks passed
github-actions Bot pushed a commit that referenced this pull request May 5, 2026
# [2.67.0](v2.66.0...v2.67.0) (2026-05-05)

### Bug Fixes

* Allow all user identity types in Identity.search ([#1256](#1256)) ([40e2972](40e2972))

### Features

* Add Identity.search for IDSync Search ([#1255](#1255)) ([2b249b9](2b249b9))
@mparticle-automation
Copy link
Copy Markdown
Collaborator

🎉 This PR is included in version 2.67.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants