@@ -289,6 +289,48 @@ const getExpireTimestamp = (maxAge: number = ONE_DAY_IN_SECONDS): number =>
289289const parseIdentityResponse = ( responseText : string ) : IdentityResultBody =>
290290 responseText ? JSON . parse ( responseText ) : ( { } as IdentityResultBody ) ;
291291
292+ type Sha256IdentityAlias = 'email_sha256' | 'mobile_sha256' ;
293+
294+ const SHA256_IDENTITY_ALIASES : Readonly <
295+ Record < Sha256IdentityAlias , keyof UserIdentities >
296+ > = {
297+ email_sha256 : 'other' ,
298+ mobile_sha256 : 'other2' ,
299+ } ;
300+
301+ type UserIdentitiesWithAliases = UserIdentities &
302+ Partial < Record < Sha256IdentityAlias , string | null > > ;
303+
304+ export const normalizeUserIdentityKeys = (
305+ userIdentities : UserIdentitiesWithAliases
306+ ) : UserIdentities => {
307+ const normalized : UserIdentitiesWithAliases = { ...userIdentities } ;
308+ ( Object . keys ( SHA256_IDENTITY_ALIASES ) as Sha256IdentityAlias [ ] ) . forEach (
309+ ( alias ) => {
310+ if ( alias in normalized ) {
311+ const value = normalized [ alias ] ;
312+ delete normalized [ alias ] ;
313+ normalized [ SHA256_IDENTITY_ALIASES [ alias ] ] = value ;
314+ }
315+ }
316+ ) ;
317+ return normalized ;
318+ } ;
319+
320+ // Compare two identity objects by key and value, independent of
321+ // object key insertion order. The two sides come from different sources
322+ // (numeric IdentityType iteration vs. partner-provided / alias-normalized
323+ // order)
324+ const identitiesEqual = (
325+ a ?: UserIdentities ,
326+ b ?: UserIdentities
327+ ) : boolean => {
328+ const aKeys = Object . keys ( a ?? { } ) ;
329+ const bKeys = Object . keys ( b ?? { } ) ;
330+ if ( aKeys . length !== bKeys . length ) return false ;
331+ return aKeys . every ( ( key ) => a [ key ] === b [ key ] ) ;
332+ } ;
333+
292334export const hasIdentityRequestChanged = (
293335 currentUser : IMParticleUser ,
294336 newIdentityRequest : IdentityApiData
@@ -300,11 +342,11 @@ export const hasIdentityRequestChanged = (
300342 const currentUserIdentities =
301343 currentUser . getUserIdentities ( ) . userIdentities ;
302344
303- const newIdentities = newIdentityRequest . userIdentities ;
304-
305- return (
306- JSON . stringify ( currentUserIdentities ) !== JSON . stringify ( newIdentities )
345+ const newIdentities = normalizeUserIdentityKeys (
346+ newIdentityRequest . userIdentities
307347 ) ;
348+
349+ return ! identitiesEqual ( currentUserIdentities , newIdentities ) ;
308350} ;
309351
310352/**
0 commit comments