@mparticle/web-sdk 2.24.0 → 2.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mparticle.common.js +45 -22
- package/dist/mparticle.esm.js +45 -22
- package/dist/mparticle.js +196 -38
- package/package.json +1 -1
- package/src/constants.ts +5 -0
- package/src/identity-utils.ts +247 -0
- package/src/identity.js +81 -33
- package/src/identityApiClient.js +5 -2
- package/src/mockBatchCreator.ts +2 -2
- package/src/mp-instance.js +17 -0
- package/src/mparticle-instance-manager.js +1 -1
- package/src/sdkRuntimeModels.ts +5 -1
- package/src/store.ts +3 -0
- package/src/validators.ts +1 -2
package/dist/mparticle.js
CHANGED
|
@@ -608,7 +608,7 @@ var mParticle = (function () {
|
|
|
608
608
|
Environment: Environment
|
|
609
609
|
};
|
|
610
610
|
|
|
611
|
-
var version = "2.
|
|
611
|
+
var version = "2.25.0";
|
|
612
612
|
|
|
613
613
|
var Constants = {
|
|
614
614
|
sdkVersion: version,
|
|
@@ -763,7 +763,8 @@ var mParticle = (function () {
|
|
|
763
763
|
ReportBatching: 'reportBatching',
|
|
764
764
|
EventBatchingIntervalMillis: 'eventBatchingIntervalMillis',
|
|
765
765
|
OfflineStorage: 'offlineStorage',
|
|
766
|
-
DirectUrlRouting: 'directURLRouting'
|
|
766
|
+
DirectUrlRouting: 'directURLRouting',
|
|
767
|
+
CacheIdentity: 'cacheIdentity'
|
|
767
768
|
},
|
|
768
769
|
DefaultInstance: 'default_instance',
|
|
769
770
|
CCPAPurpose: 'data_sale_opt_out',
|
|
@@ -774,6 +775,9 @@ var mParticle = (function () {
|
|
|
774
775
|
Identify: 'identify'
|
|
775
776
|
}
|
|
776
777
|
};
|
|
778
|
+
// https://go.mparticle.com/work/SQDSDKS-6080
|
|
779
|
+
var ONE_DAY_IN_SECONDS = 60 * 60 * 24;
|
|
780
|
+
var MILLIS_IN_ONE_SEC = 1000;
|
|
777
781
|
|
|
778
782
|
/******************************************************************************
|
|
779
783
|
Copyright (c) Microsoft Corporation.
|
|
@@ -2520,7 +2524,7 @@ var mParticle = (function () {
|
|
|
2520
2524
|
};
|
|
2521
2525
|
}
|
|
2522
2526
|
|
|
2523
|
-
var Modify$
|
|
2527
|
+
var Modify$4 = Constants.IdentityMethods.Modify;
|
|
2524
2528
|
var Validators = {
|
|
2525
2529
|
// From ./utils
|
|
2526
2530
|
// Utility Functions for backwards compatability
|
|
@@ -2543,7 +2547,7 @@ var mParticle = (function () {
|
|
|
2543
2547
|
copyUserAttributes: 1
|
|
2544
2548
|
};
|
|
2545
2549
|
if (identityApiData) {
|
|
2546
|
-
if (method === Modify$
|
|
2550
|
+
if (method === Modify$4) {
|
|
2547
2551
|
if (isObject(identityApiData.userIdentities) && !Object.keys(identityApiData.userIdentities).length || !isObject(identityApiData.userIdentities)) {
|
|
2548
2552
|
return {
|
|
2549
2553
|
valid: false,
|
|
@@ -3963,7 +3967,8 @@ var mParticle = (function () {
|
|
|
3963
3967
|
ReportBatching = _a.ReportBatching,
|
|
3964
3968
|
EventBatchingIntervalMillis = _a.EventBatchingIntervalMillis,
|
|
3965
3969
|
OfflineStorage = _a.OfflineStorage,
|
|
3966
|
-
DirectUrlRouting = _a.DirectUrlRouting
|
|
3970
|
+
DirectUrlRouting = _a.DirectUrlRouting,
|
|
3971
|
+
CacheIdentity = _a.CacheIdentity;
|
|
3967
3972
|
if (!config.flags) {
|
|
3968
3973
|
return {};
|
|
3969
3974
|
}
|
|
@@ -3973,6 +3978,7 @@ var mParticle = (function () {
|
|
|
3973
3978
|
flags[EventBatchingIntervalMillis] = parseNumber(config.flags[EventBatchingIntervalMillis]) || Constants.DefaultConfig.uploadInterval;
|
|
3974
3979
|
flags[OfflineStorage] = config.flags[OfflineStorage] || '0';
|
|
3975
3980
|
flags[DirectUrlRouting] = config.flags[DirectUrlRouting] === 'True';
|
|
3981
|
+
flags[CacheIdentity] = config.flags[CacheIdentity] === 'True';
|
|
3976
3982
|
return flags;
|
|
3977
3983
|
}
|
|
3978
3984
|
function processBaseUrls(config, flags, apiKey) {
|
|
@@ -5275,10 +5281,10 @@ var mParticle = (function () {
|
|
|
5275
5281
|
}
|
|
5276
5282
|
|
|
5277
5283
|
var _Constants$IdentityMe$1 = Constants.IdentityMethods,
|
|
5278
|
-
Modify$
|
|
5279
|
-
Identify$
|
|
5280
|
-
Login = _Constants$IdentityMe$1.Login,
|
|
5281
|
-
Logout = _Constants$IdentityMe$1.Logout;
|
|
5284
|
+
Modify$3 = _Constants$IdentityMe$1.Modify,
|
|
5285
|
+
Identify$2 = _Constants$IdentityMe$1.Identify,
|
|
5286
|
+
Login$2 = _Constants$IdentityMe$1.Login,
|
|
5287
|
+
Logout$2 = _Constants$IdentityMe$1.Logout;
|
|
5282
5288
|
function Forwarders(mpInstance, kitBlocker) {
|
|
5283
5289
|
var self = this;
|
|
5284
5290
|
var UserAttributeActionTypes = {
|
|
@@ -5540,28 +5546,28 @@ var mParticle = (function () {
|
|
|
5540
5546
|
mpInstance._Store.activeForwarders.forEach(function (forwarder) {
|
|
5541
5547
|
var filteredUser = filteredMparticleUser(user.getMPID(), forwarder, mpInstance, kitBlocker);
|
|
5542
5548
|
var filteredUserIdentities = filteredUser.getUserIdentities();
|
|
5543
|
-
if (identityMethod === Identify$
|
|
5549
|
+
if (identityMethod === Identify$2) {
|
|
5544
5550
|
if (forwarder.onIdentifyComplete) {
|
|
5545
5551
|
result = forwarder.onIdentifyComplete(filteredUser, filteredUserIdentities);
|
|
5546
5552
|
if (result) {
|
|
5547
5553
|
mpInstance.Logger.verbose(result);
|
|
5548
5554
|
}
|
|
5549
5555
|
}
|
|
5550
|
-
} else if (identityMethod === Login) {
|
|
5556
|
+
} else if (identityMethod === Login$2) {
|
|
5551
5557
|
if (forwarder.onLoginComplete) {
|
|
5552
5558
|
result = forwarder.onLoginComplete(filteredUser, filteredUserIdentities);
|
|
5553
5559
|
if (result) {
|
|
5554
5560
|
mpInstance.Logger.verbose(result);
|
|
5555
5561
|
}
|
|
5556
5562
|
}
|
|
5557
|
-
} else if (identityMethod === Logout) {
|
|
5563
|
+
} else if (identityMethod === Logout$2) {
|
|
5558
5564
|
if (forwarder.onLogoutComplete) {
|
|
5559
5565
|
result = forwarder.onLogoutComplete(filteredUser, filteredUserIdentities);
|
|
5560
5566
|
if (result) {
|
|
5561
5567
|
mpInstance.Logger.verbose(result);
|
|
5562
5568
|
}
|
|
5563
5569
|
}
|
|
5564
|
-
} else if (identityMethod === Modify$
|
|
5570
|
+
} else if (identityMethod === Modify$3) {
|
|
5565
5571
|
if (forwarder.onModifyComplete) {
|
|
5566
5572
|
result = forwarder.onModifyComplete(filteredUser, filteredUserIdentities);
|
|
5567
5573
|
if (result) {
|
|
@@ -6101,13 +6107,149 @@ var mParticle = (function () {
|
|
|
6101
6107
|
}
|
|
6102
6108
|
}
|
|
6103
6109
|
|
|
6110
|
+
var _a = Constants.IdentityMethods,
|
|
6111
|
+
Identify$1 = _a.Identify,
|
|
6112
|
+
Modify$2 = _a.Modify,
|
|
6113
|
+
Login$1 = _a.Login,
|
|
6114
|
+
Logout$1 = _a.Logout;
|
|
6115
|
+
var cacheOrClearIdCache = function cacheOrClearIdCache(method, knownIdentities, idCache, xhr, parsingCachedResponse) {
|
|
6116
|
+
// when parsing a response that has already been cached, simply return instead of attempting another cache
|
|
6117
|
+
if (parsingCachedResponse) {
|
|
6118
|
+
return;
|
|
6119
|
+
}
|
|
6120
|
+
var CACHE_HEADER = 'x-mp-max-age';
|
|
6121
|
+
// default the expire timestamp to one day in milliseconds unless a header comes back
|
|
6122
|
+
var now = new Date().getTime();
|
|
6123
|
+
var expireTimestamp = now + ONE_DAY_IN_SECONDS * MILLIS_IN_ONE_SEC;
|
|
6124
|
+
if (xhr.getAllResponseHeaders().includes(CACHE_HEADER)) {
|
|
6125
|
+
expireTimestamp = now + parseNumber(xhr.getResponseHeader(CACHE_HEADER)) * MILLIS_IN_ONE_SEC;
|
|
6126
|
+
}
|
|
6127
|
+
switch (method) {
|
|
6128
|
+
case Login$1:
|
|
6129
|
+
case Identify$1:
|
|
6130
|
+
cacheIdentityRequest(method, knownIdentities, expireTimestamp, idCache, xhr);
|
|
6131
|
+
break;
|
|
6132
|
+
case Modify$2:
|
|
6133
|
+
case Logout$1:
|
|
6134
|
+
idCache.purge();
|
|
6135
|
+
break;
|
|
6136
|
+
}
|
|
6137
|
+
};
|
|
6138
|
+
var cacheIdentityRequest = function cacheIdentityRequest(method, identities, expireTimestamp, idCache, xhr) {
|
|
6139
|
+
var cache = idCache.retrieve() || {};
|
|
6140
|
+
var cacheKey = concatenateIdentities(method, identities);
|
|
6141
|
+
var hashedKey = generateHash(cacheKey);
|
|
6142
|
+
cache[hashedKey] = {
|
|
6143
|
+
responseText: xhr.responseText,
|
|
6144
|
+
status: xhr.status,
|
|
6145
|
+
expireTimestamp: expireTimestamp
|
|
6146
|
+
};
|
|
6147
|
+
idCache.store(cache);
|
|
6148
|
+
};
|
|
6149
|
+
// We need to ensure that identities are concatenated in a deterministic way, so
|
|
6150
|
+
// we sort the identities based on their enum.
|
|
6151
|
+
// we create an array, set the user identity at the index of the user identity type
|
|
6152
|
+
var concatenateIdentities = function concatenateIdentities(method, userIdentities) {
|
|
6153
|
+
var DEVICE_APPLICATION_STAMP = 'device_application_stamp';
|
|
6154
|
+
// set DAS first since it is not an official identity type
|
|
6155
|
+
var cacheKey = "".concat(method, ":").concat(DEVICE_APPLICATION_STAMP, "=").concat(userIdentities.device_application_stamp, ";");
|
|
6156
|
+
var idLength = Object.keys(userIdentities).length;
|
|
6157
|
+
var concatenatedIdentities = '';
|
|
6158
|
+
if (idLength) {
|
|
6159
|
+
var userIDArray = new Array();
|
|
6160
|
+
// create an array where each index is equal to the user identity type
|
|
6161
|
+
for (var key in userIdentities) {
|
|
6162
|
+
if (key === DEVICE_APPLICATION_STAMP) {
|
|
6163
|
+
continue;
|
|
6164
|
+
} else {
|
|
6165
|
+
userIDArray[Types.IdentityType.getIdentityType(key)] = userIdentities[key];
|
|
6166
|
+
}
|
|
6167
|
+
}
|
|
6168
|
+
concatenatedIdentities = userIDArray.reduce(function (prevValue, currentValue, index) {
|
|
6169
|
+
var idName = Types.IdentityType.getIdentityName(index);
|
|
6170
|
+
return "".concat(prevValue).concat(idName, "=").concat(currentValue, ";");
|
|
6171
|
+
}, cacheKey);
|
|
6172
|
+
}
|
|
6173
|
+
return concatenatedIdentities;
|
|
6174
|
+
};
|
|
6175
|
+
var hasValidCachedIdentity = function hasValidCachedIdentity(method, proposedUserIdentities, idCache) {
|
|
6176
|
+
// There is an edge case where multiple identity calls are taking place
|
|
6177
|
+
// before identify fires, so there may not be a cache. See what happens when
|
|
6178
|
+
// the ? in idCache is removed to the following test
|
|
6179
|
+
// "queued events contain login mpid instead of identify mpid when calling
|
|
6180
|
+
// login immediately after mParticle initializes"
|
|
6181
|
+
var cache = idCache === null || idCache === void 0 ? void 0 : idCache.retrieve();
|
|
6182
|
+
// if there is no cache, then there is no valid cached identity
|
|
6183
|
+
if (!cache) {
|
|
6184
|
+
return false;
|
|
6185
|
+
}
|
|
6186
|
+
var cacheKey = concatenateIdentities(method, proposedUserIdentities);
|
|
6187
|
+
var hashedKey = generateHash(cacheKey);
|
|
6188
|
+
// if cache doesn't have the cacheKey, there is no valid cached identity
|
|
6189
|
+
if (!cache.hasOwnProperty(hashedKey)) {
|
|
6190
|
+
return false;
|
|
6191
|
+
}
|
|
6192
|
+
// If there is a valid cache key, compare the expireTimestamp to the current time.
|
|
6193
|
+
// If the current time is greater than the expireTimestamp, it is not a valid
|
|
6194
|
+
// cached identity.
|
|
6195
|
+
var expireTimestamp = cache[hashedKey].expireTimestamp;
|
|
6196
|
+
if (expireTimestamp < new Date().getTime()) {
|
|
6197
|
+
return false;
|
|
6198
|
+
} else {
|
|
6199
|
+
return true;
|
|
6200
|
+
}
|
|
6201
|
+
};
|
|
6202
|
+
var getCachedIdentity = function getCachedIdentity(method, proposedUserIdentities, idCache) {
|
|
6203
|
+
var cacheKey = concatenateIdentities(method, proposedUserIdentities);
|
|
6204
|
+
var hashedKey = generateHash(cacheKey);
|
|
6205
|
+
var cache = idCache.retrieve();
|
|
6206
|
+
var cachedIdentity = cache ? cache[hashedKey] : null;
|
|
6207
|
+
return cachedIdentity;
|
|
6208
|
+
};
|
|
6209
|
+
// https://go.mparticle.com/work/SQDSDKS-6079
|
|
6210
|
+
var createKnownIdentities = function createKnownIdentities(identityApiData, deviceId) {
|
|
6211
|
+
var identitiesResult = {};
|
|
6212
|
+
if (isObject(identityApiData === null || identityApiData === void 0 ? void 0 : identityApiData.userIdentities)) {
|
|
6213
|
+
for (var identity in identityApiData.userIdentities) {
|
|
6214
|
+
identitiesResult[identity] = identityApiData.userIdentities[identity];
|
|
6215
|
+
}
|
|
6216
|
+
}
|
|
6217
|
+
identitiesResult.device_application_stamp = deviceId;
|
|
6218
|
+
return identitiesResult;
|
|
6219
|
+
};
|
|
6220
|
+
var removeExpiredIdentityCacheDates = function removeExpiredIdentityCacheDates(idCache) {
|
|
6221
|
+
var cache = idCache.retrieve() || {};
|
|
6222
|
+
var currentTime = new Date().getTime();
|
|
6223
|
+
// Iterate over the cache and remove any key/value pairs that are expired
|
|
6224
|
+
for (var key in cache) {
|
|
6225
|
+
if (cache[key].expireTimestamp < currentTime) {
|
|
6226
|
+
delete cache[key];
|
|
6227
|
+
}
|
|
6228
|
+
}
|
|
6229
|
+
idCache.store(cache);
|
|
6230
|
+
};
|
|
6231
|
+
var tryCacheIdentity = function tryCacheIdentity(knownIdentities, idCache, parseIdentityResponse, mpid, callback, identityApiData, identityMethod) {
|
|
6232
|
+
// https://go.mparticle.com/work/SQDSDKS-6095
|
|
6233
|
+
var shouldReturnCachedIdentity = hasValidCachedIdentity(identityMethod, knownIdentities, idCache);
|
|
6234
|
+
// If Identity is cached, then immediately parse the identity response
|
|
6235
|
+
if (shouldReturnCachedIdentity) {
|
|
6236
|
+
var cachedIdentity = getCachedIdentity(identityMethod, knownIdentities, idCache);
|
|
6237
|
+
parseIdentityResponse(cachedIdentity, mpid, callback, identityApiData, identityMethod, knownIdentities, true);
|
|
6238
|
+
return true;
|
|
6239
|
+
}
|
|
6240
|
+
return false;
|
|
6241
|
+
};
|
|
6242
|
+
|
|
6104
6243
|
var Messages$2 = Constants.Messages,
|
|
6105
6244
|
HTTPCodes$2 = Constants.HTTPCodes;
|
|
6106
6245
|
var _Constants$IdentityMe = Constants.IdentityMethods,
|
|
6107
6246
|
Identify = _Constants$IdentityMe.Identify,
|
|
6108
|
-
Modify$1 = _Constants$IdentityMe.Modify
|
|
6247
|
+
Modify$1 = _Constants$IdentityMe.Modify,
|
|
6248
|
+
Login = _Constants$IdentityMe.Login,
|
|
6249
|
+
Logout = _Constants$IdentityMe.Logout;
|
|
6109
6250
|
function Identity(mpInstance) {
|
|
6110
6251
|
var self = this;
|
|
6252
|
+
this.idCache = null;
|
|
6111
6253
|
this.checkIdentitySwap = function (previousMPID, currentMPID, currentSessionMPIDs) {
|
|
6112
6254
|
if (previousMPID && currentMPID && previousMPID !== currentMPID) {
|
|
6113
6255
|
var persistence = mpInstance._Persistence.getPersistence();
|
|
@@ -6119,16 +6261,6 @@ var mParticle = (function () {
|
|
|
6119
6261
|
}
|
|
6120
6262
|
};
|
|
6121
6263
|
this.IdentityRequest = {
|
|
6122
|
-
createKnownIdentities: function createKnownIdentities(identityApiData, deviceId) {
|
|
6123
|
-
var identitiesResult = {};
|
|
6124
|
-
if (identityApiData && identityApiData.userIdentities && mpInstance._Helpers.isObject(identityApiData.userIdentities)) {
|
|
6125
|
-
for (var identity in identityApiData.userIdentities) {
|
|
6126
|
-
identitiesResult[identity] = identityApiData.userIdentities[identity];
|
|
6127
|
-
}
|
|
6128
|
-
}
|
|
6129
|
-
identitiesResult.device_application_stamp = deviceId;
|
|
6130
|
-
return identitiesResult;
|
|
6131
|
-
},
|
|
6132
6264
|
preProcessIdentityRequest: function preProcessIdentityRequest(identityApiData, callback, method) {
|
|
6133
6265
|
mpInstance.Logger.verbose(Messages$2.InformationMessages.StartingLogEvent + ': ' + method);
|
|
6134
6266
|
var identityValidationResult = mpInstance._Helpers.Validators.validateIdentities(identityApiData, method);
|
|
@@ -6163,7 +6295,7 @@ var mParticle = (function () {
|
|
|
6163
6295
|
request_id: mpInstance._Helpers.generateUniqueId(),
|
|
6164
6296
|
request_timestamp_ms: new Date().getTime(),
|
|
6165
6297
|
previous_mpid: mpid || null,
|
|
6166
|
-
known_identities:
|
|
6298
|
+
known_identities: createKnownIdentities(identityApiData, deviceId)
|
|
6167
6299
|
};
|
|
6168
6300
|
return APIRequest;
|
|
6169
6301
|
},
|
|
@@ -6265,18 +6397,24 @@ var mParticle = (function () {
|
|
|
6265
6397
|
identify: function identify(identityApiData, callback) {
|
|
6266
6398
|
var mpid,
|
|
6267
6399
|
currentUser = mpInstance.Identity.getCurrentUser(),
|
|
6268
|
-
preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(identityApiData, callback,
|
|
6400
|
+
preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(identityApiData, callback, Identify);
|
|
6269
6401
|
if (currentUser) {
|
|
6270
6402
|
mpid = currentUser.getMPID();
|
|
6271
6403
|
}
|
|
6272
6404
|
if (preProcessResult.valid) {
|
|
6273
6405
|
var identityApiRequest = mpInstance._Identity.IdentityRequest.createIdentityRequest(identityApiData, Constants.platform, Constants.sdkVendor, Constants.sdkVersion, mpInstance._Store.deviceId, mpInstance._Store.context, mpid);
|
|
6406
|
+
if (mpInstance._Helpers.getFeatureFlag(Constants.FeatureFlags.CacheIdentity)) {
|
|
6407
|
+
var successfullyCachedIdentity = tryCacheIdentity(identityApiRequest.known_identities, self.idCache, self.parseIdentityResponse, mpid, callback, identityApiData, Identify);
|
|
6408
|
+
if (successfullyCachedIdentity) {
|
|
6409
|
+
return;
|
|
6410
|
+
}
|
|
6411
|
+
}
|
|
6274
6412
|
if (mpInstance._Helpers.canLog()) {
|
|
6275
6413
|
if (mpInstance._Store.webviewBridgeEnabled) {
|
|
6276
6414
|
mpInstance._NativeSdkHelpers.sendToNative(Constants.NativeSdkPaths.Identify, JSON.stringify(mpInstance._Identity.IdentityRequest.convertToNative(identityApiData)));
|
|
6277
6415
|
mpInstance._Helpers.invokeCallback(callback, HTTPCodes$2.nativeIdentityRequest, 'Identify request sent to native sdk');
|
|
6278
6416
|
} else {
|
|
6279
|
-
mpInstance._IdentityAPIClient.sendIdentityRequest(identityApiRequest,
|
|
6417
|
+
mpInstance._IdentityAPIClient.sendIdentityRequest(identityApiRequest, Identify, callback, identityApiData, self.parseIdentityResponse, mpid, identityApiRequest.known_identities);
|
|
6280
6418
|
}
|
|
6281
6419
|
} else {
|
|
6282
6420
|
mpInstance._Helpers.invokeCallback(callback, HTTPCodes$2.loggingDisabledOrMissingAPIKey, Messages$2.InformationMessages.AbandonLogEvent);
|
|
@@ -6296,7 +6434,7 @@ var mParticle = (function () {
|
|
|
6296
6434
|
logout: function logout(identityApiData, callback) {
|
|
6297
6435
|
var mpid,
|
|
6298
6436
|
currentUser = mpInstance.Identity.getCurrentUser(),
|
|
6299
|
-
preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(identityApiData, callback,
|
|
6437
|
+
preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(identityApiData, callback, Logout);
|
|
6300
6438
|
if (currentUser) {
|
|
6301
6439
|
mpid = currentUser.getMPID();
|
|
6302
6440
|
}
|
|
@@ -6308,7 +6446,7 @@ var mParticle = (function () {
|
|
|
6308
6446
|
mpInstance._NativeSdkHelpers.sendToNative(Constants.NativeSdkPaths.Logout, JSON.stringify(mpInstance._Identity.IdentityRequest.convertToNative(identityApiData)));
|
|
6309
6447
|
mpInstance._Helpers.invokeCallback(callback, HTTPCodes$2.nativeIdentityRequest, 'Logout request sent to native sdk');
|
|
6310
6448
|
} else {
|
|
6311
|
-
mpInstance._IdentityAPIClient.sendIdentityRequest(identityApiRequest,
|
|
6449
|
+
mpInstance._IdentityAPIClient.sendIdentityRequest(identityApiRequest, Logout, callback, identityApiData, self.parseIdentityResponse, mpid);
|
|
6312
6450
|
evt = mpInstance._ServerModel.createEventObject({
|
|
6313
6451
|
messageType: Types.MessageType.Profile
|
|
6314
6452
|
});
|
|
@@ -6339,18 +6477,24 @@ var mParticle = (function () {
|
|
|
6339
6477
|
login: function login(identityApiData, callback) {
|
|
6340
6478
|
var mpid,
|
|
6341
6479
|
currentUser = mpInstance.Identity.getCurrentUser(),
|
|
6342
|
-
preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(identityApiData, callback,
|
|
6480
|
+
preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(identityApiData, callback, Login);
|
|
6343
6481
|
if (currentUser) {
|
|
6344
6482
|
mpid = currentUser.getMPID();
|
|
6345
6483
|
}
|
|
6346
6484
|
if (preProcessResult.valid) {
|
|
6347
6485
|
var identityApiRequest = mpInstance._Identity.IdentityRequest.createIdentityRequest(identityApiData, Constants.platform, Constants.sdkVendor, Constants.sdkVersion, mpInstance._Store.deviceId, mpInstance._Store.context, mpid);
|
|
6486
|
+
if (mpInstance._Helpers.getFeatureFlag(Constants.FeatureFlags.CacheIdentity)) {
|
|
6487
|
+
var successfullyCachedIdentity = tryCacheIdentity(identityApiRequest.known_identities, self.idCache, self.parseIdentityResponse, mpid, callback, identityApiData, Login);
|
|
6488
|
+
if (successfullyCachedIdentity) {
|
|
6489
|
+
return;
|
|
6490
|
+
}
|
|
6491
|
+
}
|
|
6348
6492
|
if (mpInstance._Helpers.canLog()) {
|
|
6349
6493
|
if (mpInstance._Store.webviewBridgeEnabled) {
|
|
6350
6494
|
mpInstance._NativeSdkHelpers.sendToNative(Constants.NativeSdkPaths.Login, JSON.stringify(mpInstance._Identity.IdentityRequest.convertToNative(identityApiData)));
|
|
6351
6495
|
mpInstance._Helpers.invokeCallback(callback, HTTPCodes$2.nativeIdentityRequest, 'Login request sent to native sdk');
|
|
6352
6496
|
} else {
|
|
6353
|
-
mpInstance._IdentityAPIClient.sendIdentityRequest(identityApiRequest,
|
|
6497
|
+
mpInstance._IdentityAPIClient.sendIdentityRequest(identityApiRequest, Login, callback, identityApiData, self.parseIdentityResponse, mpid, identityApiRequest.known_identities);
|
|
6354
6498
|
}
|
|
6355
6499
|
} else {
|
|
6356
6500
|
mpInstance._Helpers.invokeCallback(callback, HTTPCodes$2.loggingDisabledOrMissingAPIKey, Messages$2.InformationMessages.AbandonLogEvent);
|
|
@@ -6370,7 +6514,7 @@ var mParticle = (function () {
|
|
|
6370
6514
|
modify: function modify(identityApiData, callback) {
|
|
6371
6515
|
var mpid,
|
|
6372
6516
|
currentUser = mpInstance.Identity.getCurrentUser(),
|
|
6373
|
-
preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(identityApiData, callback,
|
|
6517
|
+
preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(identityApiData, callback, Modify$1);
|
|
6374
6518
|
if (currentUser) {
|
|
6375
6519
|
mpid = currentUser.getMPID();
|
|
6376
6520
|
}
|
|
@@ -6382,7 +6526,7 @@ var mParticle = (function () {
|
|
|
6382
6526
|
mpInstance._NativeSdkHelpers.sendToNative(Constants.NativeSdkPaths.Modify, JSON.stringify(mpInstance._Identity.IdentityRequest.convertToNative(identityApiData)));
|
|
6383
6527
|
mpInstance._Helpers.invokeCallback(callback, HTTPCodes$2.nativeIdentityRequest, 'Modify request sent to native sdk');
|
|
6384
6528
|
} else {
|
|
6385
|
-
mpInstance._IdentityAPIClient.sendIdentityRequest(identityApiRequest,
|
|
6529
|
+
mpInstance._IdentityAPIClient.sendIdentityRequest(identityApiRequest, Modify$1, callback, identityApiData, self.parseIdentityResponse, mpid, identityApiRequest.known_identities);
|
|
6386
6530
|
}
|
|
6387
6531
|
} else {
|
|
6388
6532
|
mpInstance._Helpers.invokeCallback(callback, HTTPCodes$2.loggingDisabledOrMissingAPIKey, Messages$2.InformationMessages.AbandonLogEvent);
|
|
@@ -6982,7 +7126,7 @@ var mParticle = (function () {
|
|
|
6982
7126
|
}
|
|
6983
7127
|
};
|
|
6984
7128
|
};
|
|
6985
|
-
this.parseIdentityResponse = function (xhr, previousMPID, callback, identityApiData, method) {
|
|
7129
|
+
this.parseIdentityResponse = function (xhr, previousMPID, callback, identityApiData, method, knownIdentities, parsingCachedResponse) {
|
|
6986
7130
|
var prevUser = mpInstance.Identity.getUser(previousMPID),
|
|
6987
7131
|
newUser,
|
|
6988
7132
|
mpidIsNotInCookies,
|
|
@@ -7011,6 +7155,9 @@ var mParticle = (function () {
|
|
|
7011
7155
|
mpInstance._Persistence.setFirstSeenTime(identityApiResult.mpid);
|
|
7012
7156
|
}
|
|
7013
7157
|
if (xhr.status === 200) {
|
|
7158
|
+
if (mpInstance._Helpers.getFeatureFlag(Constants.FeatureFlags.CacheIdentity)) {
|
|
7159
|
+
cacheOrClearIdCache(method, knownIdentities, self.idCache, xhr, parsingCachedResponse);
|
|
7160
|
+
}
|
|
7014
7161
|
if (method === Modify$1) {
|
|
7015
7162
|
newIdentitiesByType = mpInstance._Identity.IdentityRequest.combineUserIdentities(previousUIByName, identityApiData.userIdentities);
|
|
7016
7163
|
mpInstance._Persistence.saveUserIdentitiesToPersistence(previousMPID, newIdentitiesByType);
|
|
@@ -7100,7 +7247,7 @@ var mParticle = (function () {
|
|
|
7100
7247
|
this.sendUserIdentityChangeEvent = function (newUserIdentities, method, mpid, prevUserIdentities) {
|
|
7101
7248
|
var currentUserInMemory, userIdentityChangeEvent;
|
|
7102
7249
|
if (!mpid) {
|
|
7103
|
-
if (method !==
|
|
7250
|
+
if (method !== Modify$1) {
|
|
7104
7251
|
return;
|
|
7105
7252
|
}
|
|
7106
7253
|
}
|
|
@@ -7991,13 +8138,13 @@ var mParticle = (function () {
|
|
|
7991
8138
|
}
|
|
7992
8139
|
}
|
|
7993
8140
|
};
|
|
7994
|
-
this.sendIdentityRequest = function (identityApiRequest, method, callback, originalIdentityApiData, parseIdentityResponse, mpid) {
|
|
8141
|
+
this.sendIdentityRequest = function (identityApiRequest, method, callback, originalIdentityApiData, parseIdentityResponse, mpid, knownIdentities) {
|
|
7995
8142
|
var xhr,
|
|
7996
8143
|
previousMPID,
|
|
7997
8144
|
xhrCallback = function xhrCallback() {
|
|
7998
8145
|
if (xhr.readyState === 4) {
|
|
7999
8146
|
mpInstance.Logger.verbose('Received ' + xhr.statusText + ' from server');
|
|
8000
|
-
parseIdentityResponse(xhr, previousMPID, callback, originalIdentityApiData, method);
|
|
8147
|
+
parseIdentityResponse(xhr, previousMPID, callback, originalIdentityApiData, method, knownIdentities, false);
|
|
8001
8148
|
}
|
|
8002
8149
|
};
|
|
8003
8150
|
mpInstance.Logger.verbose(Messages$1.InformationMessages.SendIdentityBegin);
|
|
@@ -8978,8 +9125,19 @@ var mParticle = (function () {
|
|
|
8978
9125
|
mpInstance._Store.SDKConfig.flags[Constants.FeatureFlags.EventBatchingIntervalMillis] = config.flags[Constants.FeatureFlags.EventBatchingIntervalMillis];
|
|
8979
9126
|
}
|
|
8980
9127
|
}
|
|
9128
|
+
|
|
9129
|
+
// add a new function to apply items to the store that require config to be returned
|
|
8981
9130
|
mpInstance._Store.storageName = mpInstance._Helpers.createMainStorageName(config.workspaceToken);
|
|
8982
9131
|
mpInstance._Store.prodStorageName = mpInstance._Helpers.createProductStorageName(config.workspaceToken);
|
|
9132
|
+
|
|
9133
|
+
// idCache is instantiated here as opposed to when _Identity is instantiated
|
|
9134
|
+
// because it depends on _Store.storageName, which is not sent until above
|
|
9135
|
+
// because it is a setting on config which returns asyncronously
|
|
9136
|
+
// in self hosted mode
|
|
9137
|
+
mpInstance._Identity.idCache = new LocalStorageVault("".concat(mpInstance._Store.storageName, "-id-cache"), {
|
|
9138
|
+
logger: mpInstance.Logger
|
|
9139
|
+
});
|
|
9140
|
+
removeExpiredIdentityCacheDates(mpInstance._Identity.idCache);
|
|
8983
9141
|
if (config.hasOwnProperty('workspaceToken')) {
|
|
8984
9142
|
mpInstance._Store.SDKConfig.workspaceToken = config.workspaceToken;
|
|
8985
9143
|
} else {
|
|
@@ -9625,7 +9783,7 @@ var mParticle = (function () {
|
|
|
9625
9783
|
return self.getInstance().getIntegrationAttributes(moduleId);
|
|
9626
9784
|
};
|
|
9627
9785
|
this.Identity = {
|
|
9628
|
-
HTTPCodes:
|
|
9786
|
+
HTTPCodes: Constants.HTTPCodes,
|
|
9629
9787
|
aliasUsers: function aliasUsers(aliasRequest, callback) {
|
|
9630
9788
|
self.getInstance().Identity.aliasUsers(aliasRequest, callback);
|
|
9631
9789
|
},
|
package/package.json
CHANGED
package/src/constants.ts
CHANGED
|
@@ -169,6 +169,7 @@ const Constants = {
|
|
|
169
169
|
EventBatchingIntervalMillis: 'eventBatchingIntervalMillis',
|
|
170
170
|
OfflineStorage: 'offlineStorage',
|
|
171
171
|
DirectUrlRouting: 'directURLRouting',
|
|
172
|
+
CacheIdentity: 'cacheIdentity',
|
|
172
173
|
},
|
|
173
174
|
DefaultInstance: 'default_instance',
|
|
174
175
|
CCPAPurpose: 'data_sale_opt_out',
|
|
@@ -181,3 +182,7 @@ const Constants = {
|
|
|
181
182
|
} as const;
|
|
182
183
|
|
|
183
184
|
export default Constants;
|
|
185
|
+
|
|
186
|
+
// https://go.mparticle.com/work/SQDSDKS-6080
|
|
187
|
+
export const ONE_DAY_IN_SECONDS = 60 * 60 * 24;
|
|
188
|
+
export const MILLIS_IN_ONE_SEC = 1000;
|