Skip to content

Commit

Permalink
refactor: Identify refactor points in Identity related workflows (#886)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexs-mparticle authored May 22, 2024
1 parent b5e164d commit a99b6fe
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default function Identity(mpInstance) {
this.idCache = null;
this.audienceManager = null;

// https://go.mparticle.com/work/SQDSDKS-6353
this.IdentityRequest = {
preProcessIdentityRequest: function(identityApiData, callback, method) {
mpInstance.Logger.verbose(
Expand Down Expand Up @@ -217,6 +218,7 @@ export default function Identity(mpInstance) {
* @param {Function} [callback] A callback function that is called when the identify request completes
*/
identify: function(identityApiData, callback) {
// https://go.mparticle.com/work/SQDSDKS-6337
var mpid,
currentUser = mpInstance.Identity.getCurrentUser(),
preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(
Expand Down Expand Up @@ -310,6 +312,7 @@ export default function Identity(mpInstance) {
* @param {Function} [callback] A callback function that is called when the logout request completes
*/
logout: function(identityApiData, callback) {
// https://go.mparticle.com/work/SQDSDKS-6337
var mpid,
currentUser = mpInstance.Identity.getCurrentUser(),
preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(
Expand Down Expand Up @@ -399,6 +402,7 @@ export default function Identity(mpInstance) {
* @param {Function} [callback] A callback function that is called when the login request completes
*/
login: function(identityApiData, callback) {
// https://go.mparticle.com/work/SQDSDKS-6337
var mpid,
currentUser = mpInstance.Identity.getCurrentUser(),
preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(
Expand Down Expand Up @@ -494,6 +498,7 @@ export default function Identity(mpInstance) {
* @param {Function} [callback] A callback function that is called when the modify request completes
*/
modify: function(identityApiData, callback) {
// https://go.mparticle.com/work/SQDSDKS-6337
var mpid,
currentUser = mpInstance.Identity.getCurrentUser(),
preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(
Expand Down Expand Up @@ -781,6 +786,7 @@ export default function Identity(mpInstance) {
},
};

// https://go.mparticle.com/work/SQDSDKS-6354
/**
* Invoke these methods on the mParticle.Identity.getCurrentUser() object.
* Example: mParticle.Identity.getCurrentUser().getAllUserAttributes()
Expand Down Expand Up @@ -1466,6 +1472,7 @@ export default function Identity(mpInstance) {
};
};

// https://go.mparticle.com/work/SQDSDKS-6355
this.parseIdentityResponse = function(
xhr,
previousMPID,
Expand Down Expand Up @@ -1513,6 +1520,7 @@ export default function Identity(mpInstance) {
mpInstance._Store.mpid = identityApiResult.mpid;

if (prevUser) {
// https://go.mparticle.com/work/SQDSDKS-6329
mpInstance._Persistence.setLastSeenTime(previousMPID);
}

Expand Down Expand Up @@ -1569,6 +1577,7 @@ export default function Identity(mpInstance) {
'Successfully parsed Identity Response'
);

// https://go.mparticle.com/work/SQDSDKS-6356
//this covers an edge case where, users stored before "firstSeenTime" was introduced
//will not have a value for "fst" until the current MPID changes, and in some cases,
//the current MPID will never change
Expand All @@ -1577,6 +1586,7 @@ export default function Identity(mpInstance) {
prevUser &&
identityApiResult.mpid === prevUser.getMPID()
) {
// https://go.mparticle.com/work/SQDSDKS-6329
mpInstance._Persistence.setFirstSeenTime(
identityApiResult.mpid
);
Expand Down Expand Up @@ -1645,12 +1655,14 @@ export default function Identity(mpInstance) {
identityApiData
);

// https://go.mparticle.com/work/SQDSDKS-6357
mpInstance._Store.context =
identityApiResult.context || mpInstance._Store.context;
}

newUser = mpInstance.Identity.getCurrentUser();

// https://go.mparticle.com/work/SQDSDKS-6359
if (
identityApiData &&
identityApiData.onUserAlias &&
Expand Down Expand Up @@ -1784,6 +1796,7 @@ export default function Identity(mpInstance) {
}
}

// https://go.mparticle.com/work/SQDSDKS-6354
currentUserInMemory = this.IdentityAPI.getUser(mpid);

for (var identityType in newUserIdentities) {
Expand Down
2 changes: 2 additions & 0 deletions src/identityApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default function IdentityAPIClient(mpInstance) {
var xhr,
xhrCallback = function() {
if (xhr.readyState === 4) {
// https://go.mparticle.com/work/SQDSDKS-6368
mpInstance.Logger.verbose(
'Received ' + xhr.statusText + ' from server'
);
Expand Down Expand Up @@ -73,6 +74,7 @@ export default function IdentityAPIClient(mpInstance) {
previousMPID,
xhrCallback = function() {
if (xhr.readyState === 4) {
// https://go.mparticle.com/work/SQDSDKS-6368
mpInstance.Logger.verbose(
'Received ' + xhr.statusText + ' from server'
);
Expand Down
2 changes: 2 additions & 0 deletions src/persistence.js
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,7 @@ export default function _Persistence(mpInstance) {
if (!mpid) {
return;
}
// https://go.mparticle.com/work/SQDSDKS-6329
if (!time) {
time = new Date().getTime();
}
Expand Down Expand Up @@ -1152,6 +1153,7 @@ export default function _Persistence(mpInstance) {
if (!mpid) {
return;
}
// https://go.mparticle.com/work/SQDSDKS-6329
if (!time) {
time = new Date().getTime();
}
Expand Down
3 changes: 3 additions & 0 deletions src/sdkRuntimeModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ export interface SDKEvent {
IsFirstRun: boolean;
EventName: string;
EventCategory: number;

// https://go.mparticle.com/work/SQDSDKS-5196
UserAttributes?: { [key: string]: string | string[] | null };

UserIdentities?: ISDKUserIdentity[];
SourceMessageId: string;
MPID: string;
Expand Down
3 changes: 3 additions & 0 deletions src/serverModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ export interface IServerV2DTO {
dp_v?: number;
n?: string;
et?: number;

// https://go.mparticle.com/work/SQDSDKS-5196
ua?: Dictionary<string | string[]>;

ui?: ISDKUserIdentity[];
ia?: Dictionary<Dictionary<string>>;
str?: ServerSettings;
Expand Down

0 comments on commit a99b6fe

Please sign in to comment.