Skip to content

Commit

Permalink
Address some code comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rmi22186 committed Jan 10, 2024
1 parent a5719e4 commit c8da08b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
17 changes: 9 additions & 8 deletions src/identity-utils.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -16,7 +17,7 @@ export interface ICachedIdentityCall extends UserIdentities {
}

export const cacheIdentityRequest = (
method: string,
method: IdentityAPIMethod,
identities: IKnownIdentities,
expireTimestamp: number,
idCache: LocalStorageVault<Dictionary>,
Expand All @@ -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
Expand All @@ -42,7 +43,7 @@ export const concatenateIdentities = (
let concatenatedIdentities: string = '';

if (idLength) {
let userIDArray: Array<string> = new Array(idLength);
let userIDArray: Array<string> = 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') {
Expand All @@ -66,11 +67,11 @@ export const concatenateIdentities = (
};

export const hasValidCachedIdentity = (
method: string,
method: IdentityAPIMethod,
proposedUserIdentities: IKnownIdentities,
idCache?: LocalStorageVault<Dictionary>
): 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
Expand Down Expand Up @@ -106,7 +107,7 @@ export const hasValidCachedIdentity = (
};

export const getCachedIdentity = (
method: string,
method: IdentityAPIMethod,
proposedUserIdentities: IKnownIdentities,
idCache: LocalStorageVault<Dictionary>
): Dictionary<string | number | boolean> | null => {
Expand Down Expand Up @@ -142,7 +143,7 @@ export const createKnownIdentities = (
return identitiesResult;
};

export const removeExpiredIdentityCacheDates = function(idCache: LocalStorageVault<Dictionary>): void {
export const removeExpiredIdentityCacheDates = (idCache: LocalStorageVault<Dictionary>): void => {
const cache: Dictionary<ICachedIdentityCall> = idCache.retrieve() || {};

idCache.purge();
Expand Down
4 changes: 2 additions & 2 deletions src/sdkRuntimeModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>;
Expand Down Expand Up @@ -239,7 +239,7 @@ export interface SDKIdentityApi {
login;
logout;
modify;
getUser(mpid: string);
getUser(mpid: string): MParticleUser;
}

export interface SDKHelpersApi {
Expand Down
2 changes: 1 addition & 1 deletion src/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c8da08b

Please sign in to comment.