@mparticle/web-sdk 2.24.0 → 2.25.1
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 +203 -38
- package/package.json +1 -1
- package/src/constants.ts +5 -0
- package/src/identity-utils.ts +253 -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.1";
|
|
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,156 @@ 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
|
+
var _a = JSON.parse(xhr.responseText),
|
|
6143
|
+
mpid = _a.mpid,
|
|
6144
|
+
is_logged_in = _a.is_logged_in;
|
|
6145
|
+
var cachedResponseText = {
|
|
6146
|
+
mpid: mpid,
|
|
6147
|
+
is_logged_in: is_logged_in
|
|
6148
|
+
};
|
|
6149
|
+
cache[hashedKey] = {
|
|
6150
|
+
responseText: JSON.stringify(cachedResponseText),
|
|
6151
|
+
status: xhr.status,
|
|
6152
|
+
expireTimestamp: expireTimestamp
|
|
6153
|
+
};
|
|
6154
|
+
idCache.store(cache);
|
|
6155
|
+
};
|
|
6156
|
+
// We need to ensure that identities are concatenated in a deterministic way, so
|
|
6157
|
+
// we sort the identities based on their enum.
|
|
6158
|
+
// we create an array, set the user identity at the index of the user identity type
|
|
6159
|
+
var concatenateIdentities = function concatenateIdentities(method, userIdentities) {
|
|
6160
|
+
var DEVICE_APPLICATION_STAMP = 'device_application_stamp';
|
|
6161
|
+
// set DAS first since it is not an official identity type
|
|
6162
|
+
var cacheKey = "".concat(method, ":").concat(DEVICE_APPLICATION_STAMP, "=").concat(userIdentities.device_application_stamp, ";");
|
|
6163
|
+
var idLength = Object.keys(userIdentities).length;
|
|
6164
|
+
var concatenatedIdentities = '';
|
|
6165
|
+
if (idLength) {
|
|
6166
|
+
var userIDArray = new Array();
|
|
6167
|
+
// create an array where each index is equal to the user identity type
|
|
6168
|
+
for (var key in userIdentities) {
|
|
6169
|
+
if (key === DEVICE_APPLICATION_STAMP) {
|
|
6170
|
+
continue;
|
|
6171
|
+
} else {
|
|
6172
|
+
userIDArray[Types.IdentityType.getIdentityType(key)] = userIdentities[key];
|
|
6173
|
+
}
|
|
6174
|
+
}
|
|
6175
|
+
concatenatedIdentities = userIDArray.reduce(function (prevValue, currentValue, index) {
|
|
6176
|
+
var idName = Types.IdentityType.getIdentityName(index);
|
|
6177
|
+
return "".concat(prevValue).concat(idName, "=").concat(currentValue, ";");
|
|
6178
|
+
}, cacheKey);
|
|
6179
|
+
}
|
|
6180
|
+
return concatenatedIdentities;
|
|
6181
|
+
};
|
|
6182
|
+
var hasValidCachedIdentity = function hasValidCachedIdentity(method, proposedUserIdentities, idCache) {
|
|
6183
|
+
// There is an edge case where multiple identity calls are taking place
|
|
6184
|
+
// before identify fires, so there may not be a cache. See what happens when
|
|
6185
|
+
// the ? in idCache is removed to the following test
|
|
6186
|
+
// "queued events contain login mpid instead of identify mpid when calling
|
|
6187
|
+
// login immediately after mParticle initializes"
|
|
6188
|
+
var cache = idCache === null || idCache === void 0 ? void 0 : idCache.retrieve();
|
|
6189
|
+
// if there is no cache, then there is no valid cached identity
|
|
6190
|
+
if (!cache) {
|
|
6191
|
+
return false;
|
|
6192
|
+
}
|
|
6193
|
+
var cacheKey = concatenateIdentities(method, proposedUserIdentities);
|
|
6194
|
+
var hashedKey = generateHash(cacheKey);
|
|
6195
|
+
// if cache doesn't have the cacheKey, there is no valid cached identity
|
|
6196
|
+
if (!cache.hasOwnProperty(hashedKey)) {
|
|
6197
|
+
return false;
|
|
6198
|
+
}
|
|
6199
|
+
// If there is a valid cache key, compare the expireTimestamp to the current time.
|
|
6200
|
+
// If the current time is greater than the expireTimestamp, it is not a valid
|
|
6201
|
+
// cached identity.
|
|
6202
|
+
var expireTimestamp = cache[hashedKey].expireTimestamp;
|
|
6203
|
+
if (expireTimestamp < new Date().getTime()) {
|
|
6204
|
+
return false;
|
|
6205
|
+
} else {
|
|
6206
|
+
return true;
|
|
6207
|
+
}
|
|
6208
|
+
};
|
|
6209
|
+
var getCachedIdentity = function getCachedIdentity(method, proposedUserIdentities, idCache) {
|
|
6210
|
+
var cacheKey = concatenateIdentities(method, proposedUserIdentities);
|
|
6211
|
+
var hashedKey = generateHash(cacheKey);
|
|
6212
|
+
var cache = idCache.retrieve();
|
|
6213
|
+
var cachedIdentity = cache ? cache[hashedKey] : null;
|
|
6214
|
+
return cachedIdentity;
|
|
6215
|
+
};
|
|
6216
|
+
// https://go.mparticle.com/work/SQDSDKS-6079
|
|
6217
|
+
var createKnownIdentities = function createKnownIdentities(identityApiData, deviceId) {
|
|
6218
|
+
var identitiesResult = {};
|
|
6219
|
+
if (isObject(identityApiData === null || identityApiData === void 0 ? void 0 : identityApiData.userIdentities)) {
|
|
6220
|
+
for (var identity in identityApiData.userIdentities) {
|
|
6221
|
+
identitiesResult[identity] = identityApiData.userIdentities[identity];
|
|
6222
|
+
}
|
|
6223
|
+
}
|
|
6224
|
+
identitiesResult.device_application_stamp = deviceId;
|
|
6225
|
+
return identitiesResult;
|
|
6226
|
+
};
|
|
6227
|
+
var removeExpiredIdentityCacheDates = function removeExpiredIdentityCacheDates(idCache) {
|
|
6228
|
+
var cache = idCache.retrieve() || {};
|
|
6229
|
+
var currentTime = new Date().getTime();
|
|
6230
|
+
// Iterate over the cache and remove any key/value pairs that are expired
|
|
6231
|
+
for (var key in cache) {
|
|
6232
|
+
if (cache[key].expireTimestamp < currentTime) {
|
|
6233
|
+
delete cache[key];
|
|
6234
|
+
}
|
|
6235
|
+
}
|
|
6236
|
+
idCache.store(cache);
|
|
6237
|
+
};
|
|
6238
|
+
var tryCacheIdentity = function tryCacheIdentity(knownIdentities, idCache, parseIdentityResponse, mpid, callback, identityApiData, identityMethod) {
|
|
6239
|
+
// https://go.mparticle.com/work/SQDSDKS-6095
|
|
6240
|
+
var shouldReturnCachedIdentity = hasValidCachedIdentity(identityMethod, knownIdentities, idCache);
|
|
6241
|
+
// If Identity is cached, then immediately parse the identity response
|
|
6242
|
+
if (shouldReturnCachedIdentity) {
|
|
6243
|
+
var cachedIdentity = getCachedIdentity(identityMethod, knownIdentities, idCache);
|
|
6244
|
+
parseIdentityResponse(cachedIdentity, mpid, callback, identityApiData, identityMethod, knownIdentities, true);
|
|
6245
|
+
return true;
|
|
6246
|
+
}
|
|
6247
|
+
return false;
|
|
6248
|
+
};
|
|
6249
|
+
|
|
6104
6250
|
var Messages$2 = Constants.Messages,
|
|
6105
6251
|
HTTPCodes$2 = Constants.HTTPCodes;
|
|
6106
6252
|
var _Constants$IdentityMe = Constants.IdentityMethods,
|
|
6107
6253
|
Identify = _Constants$IdentityMe.Identify,
|
|
6108
|
-
Modify$1 = _Constants$IdentityMe.Modify
|
|
6254
|
+
Modify$1 = _Constants$IdentityMe.Modify,
|
|
6255
|
+
Login = _Constants$IdentityMe.Login,
|
|
6256
|
+
Logout = _Constants$IdentityMe.Logout;
|
|
6109
6257
|
function Identity(mpInstance) {
|
|
6110
6258
|
var self = this;
|
|
6259
|
+
this.idCache = null;
|
|
6111
6260
|
this.checkIdentitySwap = function (previousMPID, currentMPID, currentSessionMPIDs) {
|
|
6112
6261
|
if (previousMPID && currentMPID && previousMPID !== currentMPID) {
|
|
6113
6262
|
var persistence = mpInstance._Persistence.getPersistence();
|
|
@@ -6119,16 +6268,6 @@ var mParticle = (function () {
|
|
|
6119
6268
|
}
|
|
6120
6269
|
};
|
|
6121
6270
|
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
6271
|
preProcessIdentityRequest: function preProcessIdentityRequest(identityApiData, callback, method) {
|
|
6133
6272
|
mpInstance.Logger.verbose(Messages$2.InformationMessages.StartingLogEvent + ': ' + method);
|
|
6134
6273
|
var identityValidationResult = mpInstance._Helpers.Validators.validateIdentities(identityApiData, method);
|
|
@@ -6163,7 +6302,7 @@ var mParticle = (function () {
|
|
|
6163
6302
|
request_id: mpInstance._Helpers.generateUniqueId(),
|
|
6164
6303
|
request_timestamp_ms: new Date().getTime(),
|
|
6165
6304
|
previous_mpid: mpid || null,
|
|
6166
|
-
known_identities:
|
|
6305
|
+
known_identities: createKnownIdentities(identityApiData, deviceId)
|
|
6167
6306
|
};
|
|
6168
6307
|
return APIRequest;
|
|
6169
6308
|
},
|
|
@@ -6265,18 +6404,24 @@ var mParticle = (function () {
|
|
|
6265
6404
|
identify: function identify(identityApiData, callback) {
|
|
6266
6405
|
var mpid,
|
|
6267
6406
|
currentUser = mpInstance.Identity.getCurrentUser(),
|
|
6268
|
-
preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(identityApiData, callback,
|
|
6407
|
+
preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(identityApiData, callback, Identify);
|
|
6269
6408
|
if (currentUser) {
|
|
6270
6409
|
mpid = currentUser.getMPID();
|
|
6271
6410
|
}
|
|
6272
6411
|
if (preProcessResult.valid) {
|
|
6273
6412
|
var identityApiRequest = mpInstance._Identity.IdentityRequest.createIdentityRequest(identityApiData, Constants.platform, Constants.sdkVendor, Constants.sdkVersion, mpInstance._Store.deviceId, mpInstance._Store.context, mpid);
|
|
6413
|
+
if (mpInstance._Helpers.getFeatureFlag(Constants.FeatureFlags.CacheIdentity)) {
|
|
6414
|
+
var successfullyCachedIdentity = tryCacheIdentity(identityApiRequest.known_identities, self.idCache, self.parseIdentityResponse, mpid, callback, identityApiData, Identify);
|
|
6415
|
+
if (successfullyCachedIdentity) {
|
|
6416
|
+
return;
|
|
6417
|
+
}
|
|
6418
|
+
}
|
|
6274
6419
|
if (mpInstance._Helpers.canLog()) {
|
|
6275
6420
|
if (mpInstance._Store.webviewBridgeEnabled) {
|
|
6276
6421
|
mpInstance._NativeSdkHelpers.sendToNative(Constants.NativeSdkPaths.Identify, JSON.stringify(mpInstance._Identity.IdentityRequest.convertToNative(identityApiData)));
|
|
6277
6422
|
mpInstance._Helpers.invokeCallback(callback, HTTPCodes$2.nativeIdentityRequest, 'Identify request sent to native sdk');
|
|
6278
6423
|
} else {
|
|
6279
|
-
mpInstance._IdentityAPIClient.sendIdentityRequest(identityApiRequest,
|
|
6424
|
+
mpInstance._IdentityAPIClient.sendIdentityRequest(identityApiRequest, Identify, callback, identityApiData, self.parseIdentityResponse, mpid, identityApiRequest.known_identities);
|
|
6280
6425
|
}
|
|
6281
6426
|
} else {
|
|
6282
6427
|
mpInstance._Helpers.invokeCallback(callback, HTTPCodes$2.loggingDisabledOrMissingAPIKey, Messages$2.InformationMessages.AbandonLogEvent);
|
|
@@ -6296,7 +6441,7 @@ var mParticle = (function () {
|
|
|
6296
6441
|
logout: function logout(identityApiData, callback) {
|
|
6297
6442
|
var mpid,
|
|
6298
6443
|
currentUser = mpInstance.Identity.getCurrentUser(),
|
|
6299
|
-
preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(identityApiData, callback,
|
|
6444
|
+
preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(identityApiData, callback, Logout);
|
|
6300
6445
|
if (currentUser) {
|
|
6301
6446
|
mpid = currentUser.getMPID();
|
|
6302
6447
|
}
|
|
@@ -6308,7 +6453,7 @@ var mParticle = (function () {
|
|
|
6308
6453
|
mpInstance._NativeSdkHelpers.sendToNative(Constants.NativeSdkPaths.Logout, JSON.stringify(mpInstance._Identity.IdentityRequest.convertToNative(identityApiData)));
|
|
6309
6454
|
mpInstance._Helpers.invokeCallback(callback, HTTPCodes$2.nativeIdentityRequest, 'Logout request sent to native sdk');
|
|
6310
6455
|
} else {
|
|
6311
|
-
mpInstance._IdentityAPIClient.sendIdentityRequest(identityApiRequest,
|
|
6456
|
+
mpInstance._IdentityAPIClient.sendIdentityRequest(identityApiRequest, Logout, callback, identityApiData, self.parseIdentityResponse, mpid);
|
|
6312
6457
|
evt = mpInstance._ServerModel.createEventObject({
|
|
6313
6458
|
messageType: Types.MessageType.Profile
|
|
6314
6459
|
});
|
|
@@ -6339,18 +6484,24 @@ var mParticle = (function () {
|
|
|
6339
6484
|
login: function login(identityApiData, callback) {
|
|
6340
6485
|
var mpid,
|
|
6341
6486
|
currentUser = mpInstance.Identity.getCurrentUser(),
|
|
6342
|
-
preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(identityApiData, callback,
|
|
6487
|
+
preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(identityApiData, callback, Login);
|
|
6343
6488
|
if (currentUser) {
|
|
6344
6489
|
mpid = currentUser.getMPID();
|
|
6345
6490
|
}
|
|
6346
6491
|
if (preProcessResult.valid) {
|
|
6347
6492
|
var identityApiRequest = mpInstance._Identity.IdentityRequest.createIdentityRequest(identityApiData, Constants.platform, Constants.sdkVendor, Constants.sdkVersion, mpInstance._Store.deviceId, mpInstance._Store.context, mpid);
|
|
6493
|
+
if (mpInstance._Helpers.getFeatureFlag(Constants.FeatureFlags.CacheIdentity)) {
|
|
6494
|
+
var successfullyCachedIdentity = tryCacheIdentity(identityApiRequest.known_identities, self.idCache, self.parseIdentityResponse, mpid, callback, identityApiData, Login);
|
|
6495
|
+
if (successfullyCachedIdentity) {
|
|
6496
|
+
return;
|
|
6497
|
+
}
|
|
6498
|
+
}
|
|
6348
6499
|
if (mpInstance._Helpers.canLog()) {
|
|
6349
6500
|
if (mpInstance._Store.webviewBridgeEnabled) {
|
|
6350
6501
|
mpInstance._NativeSdkHelpers.sendToNative(Constants.NativeSdkPaths.Login, JSON.stringify(mpInstance._Identity.IdentityRequest.convertToNative(identityApiData)));
|
|
6351
6502
|
mpInstance._Helpers.invokeCallback(callback, HTTPCodes$2.nativeIdentityRequest, 'Login request sent to native sdk');
|
|
6352
6503
|
} else {
|
|
6353
|
-
mpInstance._IdentityAPIClient.sendIdentityRequest(identityApiRequest,
|
|
6504
|
+
mpInstance._IdentityAPIClient.sendIdentityRequest(identityApiRequest, Login, callback, identityApiData, self.parseIdentityResponse, mpid, identityApiRequest.known_identities);
|
|
6354
6505
|
}
|
|
6355
6506
|
} else {
|
|
6356
6507
|
mpInstance._Helpers.invokeCallback(callback, HTTPCodes$2.loggingDisabledOrMissingAPIKey, Messages$2.InformationMessages.AbandonLogEvent);
|
|
@@ -6370,7 +6521,7 @@ var mParticle = (function () {
|
|
|
6370
6521
|
modify: function modify(identityApiData, callback) {
|
|
6371
6522
|
var mpid,
|
|
6372
6523
|
currentUser = mpInstance.Identity.getCurrentUser(),
|
|
6373
|
-
preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(identityApiData, callback,
|
|
6524
|
+
preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(identityApiData, callback, Modify$1);
|
|
6374
6525
|
if (currentUser) {
|
|
6375
6526
|
mpid = currentUser.getMPID();
|
|
6376
6527
|
}
|
|
@@ -6382,7 +6533,7 @@ var mParticle = (function () {
|
|
|
6382
6533
|
mpInstance._NativeSdkHelpers.sendToNative(Constants.NativeSdkPaths.Modify, JSON.stringify(mpInstance._Identity.IdentityRequest.convertToNative(identityApiData)));
|
|
6383
6534
|
mpInstance._Helpers.invokeCallback(callback, HTTPCodes$2.nativeIdentityRequest, 'Modify request sent to native sdk');
|
|
6384
6535
|
} else {
|
|
6385
|
-
mpInstance._IdentityAPIClient.sendIdentityRequest(identityApiRequest,
|
|
6536
|
+
mpInstance._IdentityAPIClient.sendIdentityRequest(identityApiRequest, Modify$1, callback, identityApiData, self.parseIdentityResponse, mpid, identityApiRequest.known_identities);
|
|
6386
6537
|
}
|
|
6387
6538
|
} else {
|
|
6388
6539
|
mpInstance._Helpers.invokeCallback(callback, HTTPCodes$2.loggingDisabledOrMissingAPIKey, Messages$2.InformationMessages.AbandonLogEvent);
|
|
@@ -6982,7 +7133,7 @@ var mParticle = (function () {
|
|
|
6982
7133
|
}
|
|
6983
7134
|
};
|
|
6984
7135
|
};
|
|
6985
|
-
this.parseIdentityResponse = function (xhr, previousMPID, callback, identityApiData, method) {
|
|
7136
|
+
this.parseIdentityResponse = function (xhr, previousMPID, callback, identityApiData, method, knownIdentities, parsingCachedResponse) {
|
|
6986
7137
|
var prevUser = mpInstance.Identity.getUser(previousMPID),
|
|
6987
7138
|
newUser,
|
|
6988
7139
|
mpidIsNotInCookies,
|
|
@@ -7011,6 +7162,9 @@ var mParticle = (function () {
|
|
|
7011
7162
|
mpInstance._Persistence.setFirstSeenTime(identityApiResult.mpid);
|
|
7012
7163
|
}
|
|
7013
7164
|
if (xhr.status === 200) {
|
|
7165
|
+
if (mpInstance._Helpers.getFeatureFlag(Constants.FeatureFlags.CacheIdentity)) {
|
|
7166
|
+
cacheOrClearIdCache(method, knownIdentities, self.idCache, xhr, parsingCachedResponse);
|
|
7167
|
+
}
|
|
7014
7168
|
if (method === Modify$1) {
|
|
7015
7169
|
newIdentitiesByType = mpInstance._Identity.IdentityRequest.combineUserIdentities(previousUIByName, identityApiData.userIdentities);
|
|
7016
7170
|
mpInstance._Persistence.saveUserIdentitiesToPersistence(previousMPID, newIdentitiesByType);
|
|
@@ -7100,7 +7254,7 @@ var mParticle = (function () {
|
|
|
7100
7254
|
this.sendUserIdentityChangeEvent = function (newUserIdentities, method, mpid, prevUserIdentities) {
|
|
7101
7255
|
var currentUserInMemory, userIdentityChangeEvent;
|
|
7102
7256
|
if (!mpid) {
|
|
7103
|
-
if (method !==
|
|
7257
|
+
if (method !== Modify$1) {
|
|
7104
7258
|
return;
|
|
7105
7259
|
}
|
|
7106
7260
|
}
|
|
@@ -7991,13 +8145,13 @@ var mParticle = (function () {
|
|
|
7991
8145
|
}
|
|
7992
8146
|
}
|
|
7993
8147
|
};
|
|
7994
|
-
this.sendIdentityRequest = function (identityApiRequest, method, callback, originalIdentityApiData, parseIdentityResponse, mpid) {
|
|
8148
|
+
this.sendIdentityRequest = function (identityApiRequest, method, callback, originalIdentityApiData, parseIdentityResponse, mpid, knownIdentities) {
|
|
7995
8149
|
var xhr,
|
|
7996
8150
|
previousMPID,
|
|
7997
8151
|
xhrCallback = function xhrCallback() {
|
|
7998
8152
|
if (xhr.readyState === 4) {
|
|
7999
8153
|
mpInstance.Logger.verbose('Received ' + xhr.statusText + ' from server');
|
|
8000
|
-
parseIdentityResponse(xhr, previousMPID, callback, originalIdentityApiData, method);
|
|
8154
|
+
parseIdentityResponse(xhr, previousMPID, callback, originalIdentityApiData, method, knownIdentities, false);
|
|
8001
8155
|
}
|
|
8002
8156
|
};
|
|
8003
8157
|
mpInstance.Logger.verbose(Messages$1.InformationMessages.SendIdentityBegin);
|
|
@@ -8978,8 +9132,19 @@ var mParticle = (function () {
|
|
|
8978
9132
|
mpInstance._Store.SDKConfig.flags[Constants.FeatureFlags.EventBatchingIntervalMillis] = config.flags[Constants.FeatureFlags.EventBatchingIntervalMillis];
|
|
8979
9133
|
}
|
|
8980
9134
|
}
|
|
9135
|
+
|
|
9136
|
+
// add a new function to apply items to the store that require config to be returned
|
|
8981
9137
|
mpInstance._Store.storageName = mpInstance._Helpers.createMainStorageName(config.workspaceToken);
|
|
8982
9138
|
mpInstance._Store.prodStorageName = mpInstance._Helpers.createProductStorageName(config.workspaceToken);
|
|
9139
|
+
|
|
9140
|
+
// idCache is instantiated here as opposed to when _Identity is instantiated
|
|
9141
|
+
// because it depends on _Store.storageName, which is not sent until above
|
|
9142
|
+
// because it is a setting on config which returns asyncronously
|
|
9143
|
+
// in self hosted mode
|
|
9144
|
+
mpInstance._Identity.idCache = new LocalStorageVault("".concat(mpInstance._Store.storageName, "-id-cache"), {
|
|
9145
|
+
logger: mpInstance.Logger
|
|
9146
|
+
});
|
|
9147
|
+
removeExpiredIdentityCacheDates(mpInstance._Identity.idCache);
|
|
8983
9148
|
if (config.hasOwnProperty('workspaceToken')) {
|
|
8984
9149
|
mpInstance._Store.SDKConfig.workspaceToken = config.workspaceToken;
|
|
8985
9150
|
} else {
|
|
@@ -9625,7 +9790,7 @@ var mParticle = (function () {
|
|
|
9625
9790
|
return self.getInstance().getIntegrationAttributes(moduleId);
|
|
9626
9791
|
};
|
|
9627
9792
|
this.Identity = {
|
|
9628
|
-
HTTPCodes:
|
|
9793
|
+
HTTPCodes: Constants.HTTPCodes,
|
|
9629
9794
|
aliasUsers: function aliasUsers(aliasRequest, callback) {
|
|
9630
9795
|
self.getInstance().Identity.aliasUsers(aliasRequest, callback);
|
|
9631
9796
|
},
|
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;
|