diff --git a/src/identity-utils.ts b/src/identity-utils.ts index d09aa6db..21a2c02c 100644 --- a/src/identity-utils.ts +++ b/src/identity-utils.ts @@ -1,7 +1,8 @@ -import { Dictionary } from './utils'; +import { Dictionary, parseNumber } from './utils'; import { LocalStorageVault } from './vault'; import Types from './types'; import { IdentityApiData, UserIdentities } from '@mparticle/web-sdk'; +import { IdentityAPIMethod } from './validators'; import { isObject } from './utils'; import { MParticleWebSDK } from './sdkRuntimeModels'; @@ -16,7 +17,7 @@ export interface ICachedIdentityCall extends UserIdentities { } export const cacheIdentityRequest = ( - method: string, + method: IdentityAPIMethod, identities: IKnownIdentities, expireTimestamp: number, idCache: LocalStorageVault, @@ -33,7 +34,7 @@ export const cacheIdentityRequest = ( // we sort the identities based on their enum. // we create an array, set the user identity at the index of the user identity type export const concatenateIdentities = ( - method: string, + method: IdentityAPIMethod, userIdentities: IKnownIdentities ): string => { // set DAS first since it is not an official identity type @@ -42,7 +43,7 @@ export const concatenateIdentities = ( let concatenatedIdentities: string = ''; if (idLength) { - let userIDArray: Array = new Array(idLength); + let userIDArray: Array = new Array(); // create an array where each index is equal to the user identity type for (let key in userIdentities) { if (key === 'device_application_stamp') { @@ -66,11 +67,11 @@ export const concatenateIdentities = ( }; export const hasValidCachedIdentity = ( - method: string, + method: IdentityAPIMethod, proposedUserIdentities: IKnownIdentities, idCache?: LocalStorageVault ): Boolean => { - // There is an edhge case where multiple identity calls are taking place + // There is an edge case where multiple identity calls are taking place // before identify fires, so there may not be a cache. See what happens when // the ? in idCache is removed to the following test // "queued events contain login mpid instead of identify mpid when calling @@ -106,7 +107,7 @@ export const hasValidCachedIdentity = ( }; export const getCachedIdentity = ( - method: string, + method: IdentityAPIMethod, proposedUserIdentities: IKnownIdentities, idCache: LocalStorageVault ): Dictionary | null => { @@ -142,7 +143,7 @@ export const createKnownIdentities = ( return identitiesResult; }; -export const removeExpiredIdentityCacheDates = function(idCache: LocalStorageVault): void { +export const removeExpiredIdentityCacheDates = (idCache: LocalStorageVault): void => { const cache: Dictionary = idCache.retrieve() || {}; idCache.purge(); diff --git a/src/sdkRuntimeModels.ts b/src/sdkRuntimeModels.ts index b472b396..01cef77c 100644 --- a/src/sdkRuntimeModels.ts +++ b/src/sdkRuntimeModels.ts @@ -11,7 +11,7 @@ import { IPersistence } from './persistence.interfaces'; import { IMPSideloadedKit } from './sideloadedKit'; import { ISessionManager } from './sessionManager'; import { Kit, MPForwarder } from './forwarders.interfaces'; -import { LocalStorageVault } from './vault'; +// import { LocalStorageVault } from './vault'; // TODO: Resolve this with version in @mparticle/web-sdk export type SDKEventCustomFlags = Dictionary; @@ -239,7 +239,7 @@ export interface SDKIdentityApi { login; logout; modify; - getUser(mpid: string); + getUser(mpid: string): MParticleUser; } export interface SDKHelpersApi { diff --git a/src/validators.ts b/src/validators.ts index e0fccf7a..f1341c88 100644 --- a/src/validators.ts +++ b/src/validators.ts @@ -9,7 +9,7 @@ import { import Constants from './constants'; import { IdentityApiData } from '@mparticle/web-sdk'; -type IdentityAPIMethod = 'login' | 'logout' | 'identify' | 'modify'; +export type IdentityAPIMethod = 'login' | 'logout' | 'identify' | 'modify'; type ValidationIdentitiesReturn = { valid: boolean;