Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/forwarders.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ export interface ConfiguredKit
removeUserAttribute(key: string): string;
setUserAttribute(key: string, value: string): string;
setUserIdentity(id: UserIdentityId, type: UserIdentityType): void;
// Legacy method present on some kit implementations; invoked on logout.
logOut?: (evt: SDKEvent) => void;

// TODO: https://go.mparticle.com/work/SQDSDKS-5156
isSandbox: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/identity-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import {
IdentityApiData,
UserIdentities,
IdentityCallback,
} from '@mparticle/web-sdk';
import { IdentityCallback } from './identity-user-interfaces';

Check warning on line 9 in src/identity-utils.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'./identity-user-interfaces' imported multiple times.

See more on https://sonarcloud.io/project/issues?id=mParticle_mparticle-web-sdk&issues=AZ5G3yjwJdmH6nGEsFnI&open=AZ5G3yjwJdmH6nGEsFnI&pullRequest=1248

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.

Clean up the imports

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

import { IdentityAPIMethod, IIdentityRequest } from './identity.interfaces';
import {
IdentityResultBody,
Expand Down
45 changes: 29 additions & 16 deletions src/identity.interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IdentityApiData, MPID, UserIdentities } from '@mparticle/web-sdk';
import { Context } from '@mparticle/event-models';
import AudienceManager from './audienceManager';
import { ICachedIdentityCall, IKnownIdentities } from './identity-utils';
import { BaseVault } from './vault';
Expand All @@ -18,6 +19,7 @@
export type IdentityPreProcessResult = {
valid: boolean;
error?: string;
cleanedIdentities?: IdentityApiData;
};

export type IdentityAPIMethod = valueof<typeof Constants.IdentityMethods>;
Expand Down Expand Up @@ -49,14 +51,14 @@

export interface IIdentityAPIRequestData {
client_sdk: {
platform: typeof platform;
sdk_vendor: typeof sdkVendor;
sdk_version: typeof sdkVersion;
platform: string;
sdk_vendor: string;
sdk_version: string;
};
context: string | null;
context: Context | null;
environment: Environment;
request_id: string;
request_timestamp_unixtime_ms: number;
request_timestamp_ms: number;

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.

Why are we renaming this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's really a typo fix on the interface. The SDK has always been sending request_timestamp_ms, the interface was just declaring the different key name

previous_mpid: MPID | null;
known_identities: IKnownIdentities;
}
Expand Down Expand Up @@ -86,7 +88,7 @@
sdkVendor: string,
sdkVersion: string,
deviceId: string,
context: string | null,
context: Context | null,
mpid: MPID
): IIdentityAPIRequestData;
createModifyIdentityRequest(
Expand All @@ -95,17 +97,20 @@
platform: string,
sdkVendor: string,
sdkVersion: string,
context: string | null
context: Context | null
): IIdentityAPIModifyRequestData;
createIdentityChanges(
previousIdentities: UserIdentities,
newIdentitie: UserIdentities
): IIdentityAPIIdentityChangeData;
newIdentities: UserIdentities

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.

How long has this typo been here? 😓

): IIdentityAPIIdentityChangeData[];
preProcessIdentityRequest(
identityApiData: IdentityApiData,
callback: IdentityCallback,
method: IdentityAPIMethod
): IdentityPreProcessResult;
createAliasNetworkRequest(aliasRequest: IAliasRequest): object;

@crisryantan crisryantan May 21, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tied to the earlier comment. These three methods all return object, which is barely better than any. The migration goal is type safety, so this is a missed opportunity.

If you do above for createAliasNetworkRequest, the same pattern applies here, declare proper interfaces for the native shapes and use them. convertToNative returning object | void is especially confusing because void is meaningless as a return type union with anything else (it means "ignore the return value"), and the actual code returns undefined explicitly. IdentityNativeRequest | undefined would be clearer.

Happy to defer to a follow-up if you want to keep this PR scoped, but please file a ticket so it does not slip.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed, object is barely better than any, and object | void is genuinely confusing semantics.
Picking up the two alias-related ones on fix/SDKE-1103-alias-network-request-type:
createAliasNetworkRequest: : object → : IAliasNetworkRequest
convertAliasToNative: : object → : INativeAliasRequest (new interface — { DestinationMpid, SourceMpid, StartUnixtimeMs, EndUnixtimeMs, Scope? })
Creating a separate ticket (https://go/j/SDKE-1204) for convertToNative since it's a different code path (identity native bridge, not alias), will switch to INativeIdentityRequest | undefined per your suggestion

convertAliasToNative(aliasRequest: IAliasRequest): object;
convertToNative(identityApiData: IdentityApiData): object | void;
}

export type AliasRequestScope = 'device' | 'mpid';
Expand Down Expand Up @@ -150,7 +155,7 @@
getUsers?(): IMParticleUser[];
aliasUsers?(
aliasRequest?: IAliasRequest,
callback?: IdentityCallback
callback?: IAliasCallback
): void;
createAliasRequest?(
sourceUser: IMParticleUser,
Expand Down Expand Up @@ -211,12 +216,12 @@
IdentityAPI: SDKIdentityApi;
IdentityRequest: IIdentityRequest;

mParticleUser(mpid: MPID, IsLoggedIn: boolean): IMParticleUser;
mParticleUser(mpid?: MPID, IsLoggedIn?: boolean): IMParticleUser;

createUserAttributeChange(
key: string,
newValue: string,
previousUserAttributeValue: string,
newValue: string | string[] | null,

Check warning on line 223 in src/identity.interfaces.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this union type with a type alias.

See more on https://sonarcloud.io/project/issues?id=mParticle_mparticle-web-sdk&issues=AZ5G3ygXJdmH6nGEsFnH&open=AZ5G3ygXJdmH6nGEsFnH&pullRequest=1248
previousUserAttributeValue: string | string[] | null,
isNewAttribute: boolean,
deleted: boolean,
user: IMParticleUser
Expand All @@ -234,13 +239,13 @@
callback: IdentityCallback,
identityApiData: IdentityApiData,
method: IdentityAPIMethod,
knownIdentities: UserIdentities,
knownIdentities: IKnownIdentities,
parsingCachedResponse: boolean
): void;
sendUserAttributeChangeEvent(
attributeKey: string,
newUserAttributeValue: string,
previousUserAttributeValue: string,
newUserAttributeValue: string | string[] | null,
previousUserAttributeValue: string | string[] | null,
isNewAttribute: boolean,
deleted: boolean,
user: IMParticleUser
Expand All @@ -251,6 +256,14 @@
mpid: MPID,
prevUserIdentities: UserIdentities
): void;
reinitForwardersOnUserChange(
prevUser: IMParticleUser,
newUser: IMParticleUser
): void;
setForwarderCallbacks(
user: IMParticleUser,
method: IdentityAPIMethod
): void;

/**
* @deprecated
Expand Down
Loading
Loading