@mparticle/web-sdk 2.42.0 → 2.43.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 +38 -35
- package/dist/mparticle.esm.js +38 -35
- package/dist/mparticle.js +205 -169
- package/package.json +4 -2
- package/src/identity-user-interfaces.ts +1 -1
- package/src/identity-utils.ts +20 -1
- package/src/identity.js +15 -8
- package/src/mp-instance.ts +1 -0
- package/src/roktManager.ts +6 -0
- package/src/sessionManager.ts +23 -15
- package/src/validators.ts +31 -1
package/dist/mparticle.js
CHANGED
|
@@ -203,7 +203,7 @@ var mParticle = (function () {
|
|
|
203
203
|
Base64: Base64$1
|
|
204
204
|
};
|
|
205
205
|
|
|
206
|
-
var version = "2.
|
|
206
|
+
var version = "2.43.1";
|
|
207
207
|
|
|
208
208
|
var Constants = {
|
|
209
209
|
sdkVersion: version,
|
|
@@ -2844,6 +2844,25 @@ var mParticle = (function () {
|
|
|
2844
2844
|
isValidKeyValue: function isValidKeyValue(key) {
|
|
2845
2845
|
return Boolean(key && !isObject(key) && !Array.isArray(key) && !this.isFunction(key));
|
|
2846
2846
|
},
|
|
2847
|
+
removeFalsyIdentityValues: function removeFalsyIdentityValues(identityApiData, logger) {
|
|
2848
|
+
if (!identityApiData || !identityApiData.userIdentities) {
|
|
2849
|
+
return identityApiData;
|
|
2850
|
+
}
|
|
2851
|
+
var cleanedData = {};
|
|
2852
|
+
var cleanedUserIdentities = __assign({}, identityApiData.userIdentities);
|
|
2853
|
+
for (var identityType in identityApiData.userIdentities) {
|
|
2854
|
+
if (identityApiData.userIdentities.hasOwnProperty(identityType)) {
|
|
2855
|
+
var value = identityApiData.userIdentities[identityType];
|
|
2856
|
+
// Check if value is falsy (undefined, false, 0, '', etc.) but not null
|
|
2857
|
+
if (value !== null && !value) {
|
|
2858
|
+
logger.warning("Identity value for '".concat(identityType, "' is falsy (").concat(value, "). This value will be removed from the request."));
|
|
2859
|
+
delete cleanedUserIdentities[identityType];
|
|
2860
|
+
}
|
|
2861
|
+
}
|
|
2862
|
+
}
|
|
2863
|
+
cleanedData.userIdentities = cleanedUserIdentities;
|
|
2864
|
+
return cleanedData;
|
|
2865
|
+
},
|
|
2847
2866
|
validateIdentities: function validateIdentities(identityApiData, method) {
|
|
2848
2867
|
var validIdentityRequestKeys = {
|
|
2849
2868
|
userIdentities: 1,
|
|
@@ -3473,6 +3492,164 @@ var mParticle = (function () {
|
|
|
3473
3492
|
return new Date().getTime() > new Date(lastSyncDate).getTime() + frequencyCap * DAYS_IN_MILLISECONDS;
|
|
3474
3493
|
};
|
|
3475
3494
|
|
|
3495
|
+
var _a = Constants.IdentityMethods,
|
|
3496
|
+
Identify$2 = _a.Identify,
|
|
3497
|
+
Modify$3 = _a.Modify,
|
|
3498
|
+
Login$2 = _a.Login,
|
|
3499
|
+
Logout$2 = _a.Logout;
|
|
3500
|
+
var CACHE_HEADER = 'x-mp-max-age';
|
|
3501
|
+
var cacheOrClearIdCache = function cacheOrClearIdCache(method, knownIdentities, idCache, identityResponse, parsingCachedResponse) {
|
|
3502
|
+
// when parsing a response that has already been cached, simply return instead of attempting another cache
|
|
3503
|
+
if (parsingCachedResponse) {
|
|
3504
|
+
return;
|
|
3505
|
+
}
|
|
3506
|
+
// default the expire timestamp to one day in milliseconds unless a header comes back
|
|
3507
|
+
var expireTimestamp = getExpireTimestamp(identityResponse === null || identityResponse === void 0 ? void 0 : identityResponse.cacheMaxAge);
|
|
3508
|
+
switch (method) {
|
|
3509
|
+
case Login$2:
|
|
3510
|
+
case Identify$2:
|
|
3511
|
+
cacheIdentityRequest(method, knownIdentities, expireTimestamp, idCache, identityResponse);
|
|
3512
|
+
break;
|
|
3513
|
+
case Modify$3:
|
|
3514
|
+
case Logout$2:
|
|
3515
|
+
idCache.purge();
|
|
3516
|
+
break;
|
|
3517
|
+
}
|
|
3518
|
+
};
|
|
3519
|
+
var cacheIdentityRequest = function cacheIdentityRequest(method, identities, expireTimestamp, idCache, identityResponse) {
|
|
3520
|
+
var responseText = identityResponse.responseText,
|
|
3521
|
+
status = identityResponse.status;
|
|
3522
|
+
var cache = idCache.retrieve() || {};
|
|
3523
|
+
var cacheKey = concatenateIdentities(method, identities);
|
|
3524
|
+
var hashedKey = generateHash(cacheKey);
|
|
3525
|
+
var mpid = responseText.mpid,
|
|
3526
|
+
is_logged_in = responseText.is_logged_in;
|
|
3527
|
+
var cachedResponseBody = {
|
|
3528
|
+
mpid: mpid,
|
|
3529
|
+
is_logged_in: is_logged_in
|
|
3530
|
+
};
|
|
3531
|
+
cache[hashedKey] = {
|
|
3532
|
+
responseText: JSON.stringify(cachedResponseBody),
|
|
3533
|
+
status: status,
|
|
3534
|
+
expireTimestamp: expireTimestamp
|
|
3535
|
+
};
|
|
3536
|
+
idCache.store(cache);
|
|
3537
|
+
};
|
|
3538
|
+
// We need to ensure that identities are concatenated in a deterministic way, so
|
|
3539
|
+
// we sort the identities based on their enum.
|
|
3540
|
+
// we create an array, set the user identity at the index of the user identity type
|
|
3541
|
+
var concatenateIdentities = function concatenateIdentities(method, userIdentities) {
|
|
3542
|
+
var DEVICE_APPLICATION_STAMP = 'device_application_stamp';
|
|
3543
|
+
// set DAS first since it is not an official identity type
|
|
3544
|
+
var cacheKey = "".concat(method, ":").concat(DEVICE_APPLICATION_STAMP, "=").concat(userIdentities.device_application_stamp, ";");
|
|
3545
|
+
var idLength = Object.keys(userIdentities).length;
|
|
3546
|
+
var concatenatedIdentities = '';
|
|
3547
|
+
if (idLength) {
|
|
3548
|
+
var userIDArray = new Array();
|
|
3549
|
+
// create an array where each index is equal to the user identity type
|
|
3550
|
+
for (var key in userIdentities) {
|
|
3551
|
+
if (key === DEVICE_APPLICATION_STAMP) {
|
|
3552
|
+
continue;
|
|
3553
|
+
} else {
|
|
3554
|
+
userIDArray[Types.IdentityType.getIdentityType(key)] = userIdentities[key];
|
|
3555
|
+
}
|
|
3556
|
+
}
|
|
3557
|
+
concatenatedIdentities = userIDArray.reduce(function (prevValue, currentValue, index) {
|
|
3558
|
+
var idName = Types.IdentityType.getIdentityName(index);
|
|
3559
|
+
return "".concat(prevValue).concat(idName, "=").concat(currentValue, ";");
|
|
3560
|
+
}, cacheKey);
|
|
3561
|
+
}
|
|
3562
|
+
return concatenatedIdentities;
|
|
3563
|
+
};
|
|
3564
|
+
var hasValidCachedIdentity = function hasValidCachedIdentity(method, proposedUserIdentities, idCache) {
|
|
3565
|
+
// There is an edge case where multiple identity calls are taking place
|
|
3566
|
+
// before identify fires, so there may not be a cache. See what happens when
|
|
3567
|
+
// the ? in idCache is removed to the following test
|
|
3568
|
+
// "queued events contain login mpid instead of identify mpid when calling
|
|
3569
|
+
// login immediately after mParticle initializes"
|
|
3570
|
+
var cache = idCache === null || idCache === void 0 ? void 0 : idCache.retrieve();
|
|
3571
|
+
// if there is no cache, then there is no valid cached identity
|
|
3572
|
+
if (!cache) {
|
|
3573
|
+
return false;
|
|
3574
|
+
}
|
|
3575
|
+
var cacheKey = concatenateIdentities(method, proposedUserIdentities);
|
|
3576
|
+
var hashedKey = generateHash(cacheKey);
|
|
3577
|
+
// if cache doesn't have the cacheKey, there is no valid cached identity
|
|
3578
|
+
if (!cache.hasOwnProperty(hashedKey)) {
|
|
3579
|
+
return false;
|
|
3580
|
+
}
|
|
3581
|
+
// If there is a valid cache key, compare the expireTimestamp to the current time.
|
|
3582
|
+
// If the current time is greater than the expireTimestamp, it is not a valid
|
|
3583
|
+
// cached identity.
|
|
3584
|
+
var expireTimestamp = cache[hashedKey].expireTimestamp;
|
|
3585
|
+
if (expireTimestamp < new Date().getTime()) {
|
|
3586
|
+
return false;
|
|
3587
|
+
} else {
|
|
3588
|
+
return true;
|
|
3589
|
+
}
|
|
3590
|
+
};
|
|
3591
|
+
var getCachedIdentity = function getCachedIdentity(method, proposedUserIdentities, idCache) {
|
|
3592
|
+
var cacheKey = concatenateIdentities(method, proposedUserIdentities);
|
|
3593
|
+
var hashedKey = generateHash(cacheKey);
|
|
3594
|
+
var cache = idCache.retrieve();
|
|
3595
|
+
var cachedIdentity = cache ? cache[hashedKey] : null;
|
|
3596
|
+
return {
|
|
3597
|
+
responseText: parseIdentityResponse(cachedIdentity.responseText),
|
|
3598
|
+
expireTimestamp: cachedIdentity.expireTimestamp,
|
|
3599
|
+
status: cachedIdentity.status
|
|
3600
|
+
};
|
|
3601
|
+
};
|
|
3602
|
+
// https://go.mparticle.com/work/SQDSDKS-6079
|
|
3603
|
+
var createKnownIdentities = function createKnownIdentities(identityApiData, deviceId) {
|
|
3604
|
+
var identitiesResult = {};
|
|
3605
|
+
if (isObject(identityApiData === null || identityApiData === void 0 ? void 0 : identityApiData.userIdentities)) {
|
|
3606
|
+
for (var identity in identityApiData.userIdentities) {
|
|
3607
|
+
identitiesResult[identity] = identityApiData.userIdentities[identity];
|
|
3608
|
+
}
|
|
3609
|
+
}
|
|
3610
|
+
identitiesResult.device_application_stamp = deviceId;
|
|
3611
|
+
return identitiesResult;
|
|
3612
|
+
};
|
|
3613
|
+
var removeExpiredIdentityCacheDates = function removeExpiredIdentityCacheDates(idCache) {
|
|
3614
|
+
var cache = idCache.retrieve() || {};
|
|
3615
|
+
var currentTime = new Date().getTime();
|
|
3616
|
+
// Iterate over the cache and remove any key/value pairs that are expired
|
|
3617
|
+
for (var key in cache) {
|
|
3618
|
+
if (cache[key].expireTimestamp < currentTime) {
|
|
3619
|
+
delete cache[key];
|
|
3620
|
+
}
|
|
3621
|
+
}
|
|
3622
|
+
idCache.store(cache);
|
|
3623
|
+
};
|
|
3624
|
+
var tryCacheIdentity = function tryCacheIdentity(knownIdentities, idCache, parseIdentityResponse, mpid, callback, identityApiData, identityMethod) {
|
|
3625
|
+
// https://go.mparticle.com/work/SQDSDKS-6095
|
|
3626
|
+
var shouldReturnCachedIdentity = hasValidCachedIdentity(identityMethod, knownIdentities, idCache);
|
|
3627
|
+
// If Identity is cached, then immediately parse the identity response
|
|
3628
|
+
if (shouldReturnCachedIdentity) {
|
|
3629
|
+
var cachedIdentity = getCachedIdentity(identityMethod, knownIdentities, idCache);
|
|
3630
|
+
parseIdentityResponse(cachedIdentity, mpid, callback, identityApiData, identityMethod, knownIdentities, true);
|
|
3631
|
+
return true;
|
|
3632
|
+
}
|
|
3633
|
+
return false;
|
|
3634
|
+
};
|
|
3635
|
+
var getExpireTimestamp = function getExpireTimestamp(maxAge) {
|
|
3636
|
+
if (maxAge === void 0) {
|
|
3637
|
+
maxAge = ONE_DAY_IN_SECONDS;
|
|
3638
|
+
}
|
|
3639
|
+
return new Date().getTime() + maxAge * MILLIS_IN_ONE_SEC;
|
|
3640
|
+
};
|
|
3641
|
+
var parseIdentityResponse = function parseIdentityResponse(responseText) {
|
|
3642
|
+
return responseText ? JSON.parse(responseText) : {};
|
|
3643
|
+
};
|
|
3644
|
+
var hasIdentityRequestChanged = function hasIdentityRequestChanged(currentUser, newIdentityRequest) {
|
|
3645
|
+
if (!currentUser || !(newIdentityRequest === null || newIdentityRequest === void 0 ? void 0 : newIdentityRequest.userIdentities)) {
|
|
3646
|
+
return false;
|
|
3647
|
+
}
|
|
3648
|
+
var currentUserIdentities = currentUser.getUserIdentities().userIdentities;
|
|
3649
|
+
var newIdentities = newIdentityRequest.userIdentities;
|
|
3650
|
+
return JSON.stringify(currentUserIdentities) !== JSON.stringify(newIdentities);
|
|
3651
|
+
};
|
|
3652
|
+
|
|
3476
3653
|
var Messages$6 = Constants.Messages;
|
|
3477
3654
|
function SessionManager(mpInstance) {
|
|
3478
3655
|
var self = this;
|
|
@@ -3484,9 +3661,10 @@ var mParticle = (function () {
|
|
|
3484
3661
|
self.startNewSession();
|
|
3485
3662
|
} else {
|
|
3486
3663
|
// https://go.mparticle.com/work/SQDSDKS-6045
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3664
|
+
// https://go.mparticle.com/work/SQDSDKS-6323
|
|
3665
|
+
var currentUser = mpInstance.Identity.getCurrentUser();
|
|
3666
|
+
var sdkIdentityRequest = mpInstance._Store.SDKConfig.identifyRequest;
|
|
3667
|
+
if (hasIdentityRequestChanged(currentUser, sdkIdentityRequest)) {
|
|
3490
3668
|
mpInstance.Identity.identify(mpInstance._Store.SDKConfig.identifyRequest, mpInstance._Store.SDKConfig.identityCallback);
|
|
3491
3669
|
mpInstance._Store.identifyCalled = true;
|
|
3492
3670
|
mpInstance._Store.SDKConfig.identityCallback = null;
|
|
@@ -6158,10 +6336,10 @@ var mParticle = (function () {
|
|
|
6158
6336
|
}
|
|
6159
6337
|
|
|
6160
6338
|
var _Constants$IdentityMe = Constants.IdentityMethods,
|
|
6161
|
-
Modify$
|
|
6162
|
-
Identify$
|
|
6163
|
-
Login$
|
|
6164
|
-
Logout$
|
|
6339
|
+
Modify$2 = _Constants$IdentityMe.Modify,
|
|
6340
|
+
Identify$1 = _Constants$IdentityMe.Identify,
|
|
6341
|
+
Login$1 = _Constants$IdentityMe.Login,
|
|
6342
|
+
Logout$1 = _Constants$IdentityMe.Logout;
|
|
6165
6343
|
function Forwarders(mpInstance, kitBlocker) {
|
|
6166
6344
|
var _this = this;
|
|
6167
6345
|
var self = this;
|
|
@@ -6425,28 +6603,28 @@ var mParticle = (function () {
|
|
|
6425
6603
|
mpInstance._Store.activeForwarders.forEach(function (forwarder) {
|
|
6426
6604
|
var filteredUser = filteredMparticleUser(user.getMPID(), forwarder, mpInstance, kitBlocker);
|
|
6427
6605
|
var filteredUserIdentities = filteredUser.getUserIdentities();
|
|
6428
|
-
if (identityMethod === Identify$
|
|
6606
|
+
if (identityMethod === Identify$1) {
|
|
6429
6607
|
if (forwarder.onIdentifyComplete) {
|
|
6430
6608
|
result = forwarder.onIdentifyComplete(filteredUser, filteredUserIdentities);
|
|
6431
6609
|
if (result) {
|
|
6432
6610
|
mpInstance.Logger.verbose(result);
|
|
6433
6611
|
}
|
|
6434
6612
|
}
|
|
6435
|
-
} else if (identityMethod === Login$
|
|
6613
|
+
} else if (identityMethod === Login$1) {
|
|
6436
6614
|
if (forwarder.onLoginComplete) {
|
|
6437
6615
|
result = forwarder.onLoginComplete(filteredUser, filteredUserIdentities);
|
|
6438
6616
|
if (result) {
|
|
6439
6617
|
mpInstance.Logger.verbose(result);
|
|
6440
6618
|
}
|
|
6441
6619
|
}
|
|
6442
|
-
} else if (identityMethod === Logout$
|
|
6620
|
+
} else if (identityMethod === Logout$1) {
|
|
6443
6621
|
if (forwarder.onLogoutComplete) {
|
|
6444
6622
|
result = forwarder.onLogoutComplete(filteredUser, filteredUserIdentities);
|
|
6445
6623
|
if (result) {
|
|
6446
6624
|
mpInstance.Logger.verbose(result);
|
|
6447
6625
|
}
|
|
6448
6626
|
}
|
|
6449
|
-
} else if (identityMethod === Modify$
|
|
6627
|
+
} else if (identityMethod === Modify$2) {
|
|
6450
6628
|
if (forwarder.onModifyComplete) {
|
|
6451
6629
|
result = forwarder.onModifyComplete(filteredUser, filteredUserIdentities);
|
|
6452
6630
|
if (result) {
|
|
@@ -6999,156 +7177,6 @@ var mParticle = (function () {
|
|
|
6999
7177
|
}
|
|
7000
7178
|
}
|
|
7001
7179
|
|
|
7002
|
-
var _a = Constants.IdentityMethods,
|
|
7003
|
-
Identify$1 = _a.Identify,
|
|
7004
|
-
Modify$2 = _a.Modify,
|
|
7005
|
-
Login$1 = _a.Login,
|
|
7006
|
-
Logout$1 = _a.Logout;
|
|
7007
|
-
var CACHE_HEADER = 'x-mp-max-age';
|
|
7008
|
-
var cacheOrClearIdCache = function cacheOrClearIdCache(method, knownIdentities, idCache, identityResponse, parsingCachedResponse) {
|
|
7009
|
-
// when parsing a response that has already been cached, simply return instead of attempting another cache
|
|
7010
|
-
if (parsingCachedResponse) {
|
|
7011
|
-
return;
|
|
7012
|
-
}
|
|
7013
|
-
// default the expire timestamp to one day in milliseconds unless a header comes back
|
|
7014
|
-
var expireTimestamp = getExpireTimestamp(identityResponse === null || identityResponse === void 0 ? void 0 : identityResponse.cacheMaxAge);
|
|
7015
|
-
switch (method) {
|
|
7016
|
-
case Login$1:
|
|
7017
|
-
case Identify$1:
|
|
7018
|
-
cacheIdentityRequest(method, knownIdentities, expireTimestamp, idCache, identityResponse);
|
|
7019
|
-
break;
|
|
7020
|
-
case Modify$2:
|
|
7021
|
-
case Logout$1:
|
|
7022
|
-
idCache.purge();
|
|
7023
|
-
break;
|
|
7024
|
-
}
|
|
7025
|
-
};
|
|
7026
|
-
var cacheIdentityRequest = function cacheIdentityRequest(method, identities, expireTimestamp, idCache, identityResponse) {
|
|
7027
|
-
var responseText = identityResponse.responseText,
|
|
7028
|
-
status = identityResponse.status;
|
|
7029
|
-
var cache = idCache.retrieve() || {};
|
|
7030
|
-
var cacheKey = concatenateIdentities(method, identities);
|
|
7031
|
-
var hashedKey = generateHash(cacheKey);
|
|
7032
|
-
var mpid = responseText.mpid,
|
|
7033
|
-
is_logged_in = responseText.is_logged_in;
|
|
7034
|
-
var cachedResponseBody = {
|
|
7035
|
-
mpid: mpid,
|
|
7036
|
-
is_logged_in: is_logged_in
|
|
7037
|
-
};
|
|
7038
|
-
cache[hashedKey] = {
|
|
7039
|
-
responseText: JSON.stringify(cachedResponseBody),
|
|
7040
|
-
status: status,
|
|
7041
|
-
expireTimestamp: expireTimestamp
|
|
7042
|
-
};
|
|
7043
|
-
idCache.store(cache);
|
|
7044
|
-
};
|
|
7045
|
-
// We need to ensure that identities are concatenated in a deterministic way, so
|
|
7046
|
-
// we sort the identities based on their enum.
|
|
7047
|
-
// we create an array, set the user identity at the index of the user identity type
|
|
7048
|
-
var concatenateIdentities = function concatenateIdentities(method, userIdentities) {
|
|
7049
|
-
var DEVICE_APPLICATION_STAMP = 'device_application_stamp';
|
|
7050
|
-
// set DAS first since it is not an official identity type
|
|
7051
|
-
var cacheKey = "".concat(method, ":").concat(DEVICE_APPLICATION_STAMP, "=").concat(userIdentities.device_application_stamp, ";");
|
|
7052
|
-
var idLength = Object.keys(userIdentities).length;
|
|
7053
|
-
var concatenatedIdentities = '';
|
|
7054
|
-
if (idLength) {
|
|
7055
|
-
var userIDArray = new Array();
|
|
7056
|
-
// create an array where each index is equal to the user identity type
|
|
7057
|
-
for (var key in userIdentities) {
|
|
7058
|
-
if (key === DEVICE_APPLICATION_STAMP) {
|
|
7059
|
-
continue;
|
|
7060
|
-
} else {
|
|
7061
|
-
userIDArray[Types.IdentityType.getIdentityType(key)] = userIdentities[key];
|
|
7062
|
-
}
|
|
7063
|
-
}
|
|
7064
|
-
concatenatedIdentities = userIDArray.reduce(function (prevValue, currentValue, index) {
|
|
7065
|
-
var idName = Types.IdentityType.getIdentityName(index);
|
|
7066
|
-
return "".concat(prevValue).concat(idName, "=").concat(currentValue, ";");
|
|
7067
|
-
}, cacheKey);
|
|
7068
|
-
}
|
|
7069
|
-
return concatenatedIdentities;
|
|
7070
|
-
};
|
|
7071
|
-
var hasValidCachedIdentity = function hasValidCachedIdentity(method, proposedUserIdentities, idCache) {
|
|
7072
|
-
// There is an edge case where multiple identity calls are taking place
|
|
7073
|
-
// before identify fires, so there may not be a cache. See what happens when
|
|
7074
|
-
// the ? in idCache is removed to the following test
|
|
7075
|
-
// "queued events contain login mpid instead of identify mpid when calling
|
|
7076
|
-
// login immediately after mParticle initializes"
|
|
7077
|
-
var cache = idCache === null || idCache === void 0 ? void 0 : idCache.retrieve();
|
|
7078
|
-
// if there is no cache, then there is no valid cached identity
|
|
7079
|
-
if (!cache) {
|
|
7080
|
-
return false;
|
|
7081
|
-
}
|
|
7082
|
-
var cacheKey = concatenateIdentities(method, proposedUserIdentities);
|
|
7083
|
-
var hashedKey = generateHash(cacheKey);
|
|
7084
|
-
// if cache doesn't have the cacheKey, there is no valid cached identity
|
|
7085
|
-
if (!cache.hasOwnProperty(hashedKey)) {
|
|
7086
|
-
return false;
|
|
7087
|
-
}
|
|
7088
|
-
// If there is a valid cache key, compare the expireTimestamp to the current time.
|
|
7089
|
-
// If the current time is greater than the expireTimestamp, it is not a valid
|
|
7090
|
-
// cached identity.
|
|
7091
|
-
var expireTimestamp = cache[hashedKey].expireTimestamp;
|
|
7092
|
-
if (expireTimestamp < new Date().getTime()) {
|
|
7093
|
-
return false;
|
|
7094
|
-
} else {
|
|
7095
|
-
return true;
|
|
7096
|
-
}
|
|
7097
|
-
};
|
|
7098
|
-
var getCachedIdentity = function getCachedIdentity(method, proposedUserIdentities, idCache) {
|
|
7099
|
-
var cacheKey = concatenateIdentities(method, proposedUserIdentities);
|
|
7100
|
-
var hashedKey = generateHash(cacheKey);
|
|
7101
|
-
var cache = idCache.retrieve();
|
|
7102
|
-
var cachedIdentity = cache ? cache[hashedKey] : null;
|
|
7103
|
-
return {
|
|
7104
|
-
responseText: parseIdentityResponse(cachedIdentity.responseText),
|
|
7105
|
-
expireTimestamp: cachedIdentity.expireTimestamp,
|
|
7106
|
-
status: cachedIdentity.status
|
|
7107
|
-
};
|
|
7108
|
-
};
|
|
7109
|
-
// https://go.mparticle.com/work/SQDSDKS-6079
|
|
7110
|
-
var createKnownIdentities = function createKnownIdentities(identityApiData, deviceId) {
|
|
7111
|
-
var identitiesResult = {};
|
|
7112
|
-
if (isObject(identityApiData === null || identityApiData === void 0 ? void 0 : identityApiData.userIdentities)) {
|
|
7113
|
-
for (var identity in identityApiData.userIdentities) {
|
|
7114
|
-
identitiesResult[identity] = identityApiData.userIdentities[identity];
|
|
7115
|
-
}
|
|
7116
|
-
}
|
|
7117
|
-
identitiesResult.device_application_stamp = deviceId;
|
|
7118
|
-
return identitiesResult;
|
|
7119
|
-
};
|
|
7120
|
-
var removeExpiredIdentityCacheDates = function removeExpiredIdentityCacheDates(idCache) {
|
|
7121
|
-
var cache = idCache.retrieve() || {};
|
|
7122
|
-
var currentTime = new Date().getTime();
|
|
7123
|
-
// Iterate over the cache and remove any key/value pairs that are expired
|
|
7124
|
-
for (var key in cache) {
|
|
7125
|
-
if (cache[key].expireTimestamp < currentTime) {
|
|
7126
|
-
delete cache[key];
|
|
7127
|
-
}
|
|
7128
|
-
}
|
|
7129
|
-
idCache.store(cache);
|
|
7130
|
-
};
|
|
7131
|
-
var tryCacheIdentity = function tryCacheIdentity(knownIdentities, idCache, parseIdentityResponse, mpid, callback, identityApiData, identityMethod) {
|
|
7132
|
-
// https://go.mparticle.com/work/SQDSDKS-6095
|
|
7133
|
-
var shouldReturnCachedIdentity = hasValidCachedIdentity(identityMethod, knownIdentities, idCache);
|
|
7134
|
-
// If Identity is cached, then immediately parse the identity response
|
|
7135
|
-
if (shouldReturnCachedIdentity) {
|
|
7136
|
-
var cachedIdentity = getCachedIdentity(identityMethod, knownIdentities, idCache);
|
|
7137
|
-
parseIdentityResponse(cachedIdentity, mpid, callback, identityApiData, identityMethod, knownIdentities, true);
|
|
7138
|
-
return true;
|
|
7139
|
-
}
|
|
7140
|
-
return false;
|
|
7141
|
-
};
|
|
7142
|
-
var getExpireTimestamp = function getExpireTimestamp(maxAge) {
|
|
7143
|
-
if (maxAge === void 0) {
|
|
7144
|
-
maxAge = ONE_DAY_IN_SECONDS;
|
|
7145
|
-
}
|
|
7146
|
-
return new Date().getTime() + maxAge * MILLIS_IN_ONE_SEC;
|
|
7147
|
-
};
|
|
7148
|
-
var parseIdentityResponse = function parseIdentityResponse(responseText) {
|
|
7149
|
-
return responseText ? JSON.parse(responseText) : {};
|
|
7150
|
-
};
|
|
7151
|
-
|
|
7152
7180
|
var AudienceManager = /** @class */function () {
|
|
7153
7181
|
function AudienceManager(userAudienceUrl, apiKey, logger) {
|
|
7154
7182
|
this.url = '';
|
|
@@ -7275,7 +7303,10 @@ var mParticle = (function () {
|
|
|
7275
7303
|
this.IdentityRequest = {
|
|
7276
7304
|
preProcessIdentityRequest: function preProcessIdentityRequest(identityApiData, callback, method) {
|
|
7277
7305
|
mpInstance.Logger.verbose(Messages$2.InformationMessages.StartingLogEvent + ': ' + method);
|
|
7278
|
-
|
|
7306
|
+
|
|
7307
|
+
// First, remove any falsy identity values and warn about them
|
|
7308
|
+
var cleanedIdentityApiData = mpInstance._Helpers.Validators.removeFalsyIdentityValues(identityApiData, mpInstance.Logger);
|
|
7309
|
+
var identityValidationResult = mpInstance._Helpers.Validators.validateIdentities(cleanedIdentityApiData, method);
|
|
7279
7310
|
if (!identityValidationResult.valid) {
|
|
7280
7311
|
mpInstance.Logger.error('ERROR: ' + identityValidationResult.error);
|
|
7281
7312
|
return {
|
|
@@ -7292,7 +7323,8 @@ var mParticle = (function () {
|
|
|
7292
7323
|
};
|
|
7293
7324
|
}
|
|
7294
7325
|
return {
|
|
7295
|
-
valid: true
|
|
7326
|
+
valid: true,
|
|
7327
|
+
cleanedIdentities: cleanedIdentityApiData
|
|
7296
7328
|
};
|
|
7297
7329
|
},
|
|
7298
7330
|
createIdentityRequest: function createIdentityRequest(identityApiData, platform, sdkVendor, sdkVersion, deviceId, context, mpid) {
|
|
@@ -7415,7 +7447,7 @@ var mParticle = (function () {
|
|
|
7415
7447
|
mpid = currentUser.getMPID();
|
|
7416
7448
|
}
|
|
7417
7449
|
if (preProcessResult.valid) {
|
|
7418
|
-
var identityApiRequest = mpInstance._Identity.IdentityRequest.createIdentityRequest(
|
|
7450
|
+
var identityApiRequest = mpInstance._Identity.IdentityRequest.createIdentityRequest(preProcessResult.cleanedIdentities, Constants.platform, Constants.sdkVendor, Constants.sdkVersion, mpInstance._Store.deviceId, mpInstance._Store.context, mpid);
|
|
7419
7451
|
if (mpInstance._Helpers.getFeatureFlag(Constants.FeatureFlags.CacheIdentity)) {
|
|
7420
7452
|
var successfullyCachedIdentity = tryCacheIdentity(identityApiRequest.known_identities, self.idCache, self.parseIdentityResponse, mpid, callback, identityApiData, Identify);
|
|
7421
7453
|
if (successfullyCachedIdentity) {
|
|
@@ -7454,7 +7486,7 @@ var mParticle = (function () {
|
|
|
7454
7486
|
}
|
|
7455
7487
|
if (preProcessResult.valid) {
|
|
7456
7488
|
var evt,
|
|
7457
|
-
identityApiRequest = mpInstance._Identity.IdentityRequest.createIdentityRequest(
|
|
7489
|
+
identityApiRequest = mpInstance._Identity.IdentityRequest.createIdentityRequest(preProcessResult.cleanedIdentities, Constants.platform, Constants.sdkVendor, Constants.sdkVersion, mpInstance._Store.deviceId, mpInstance._Store.context, mpid);
|
|
7458
7490
|
if (mpInstance._Helpers.canLog()) {
|
|
7459
7491
|
if (mpInstance._Store.webviewBridgeEnabled) {
|
|
7460
7492
|
mpInstance._NativeSdkHelpers.sendToNative(Constants.NativeSdkPaths.Logout, JSON.stringify(mpInstance._Identity.IdentityRequest.convertToNative(identityApiData)));
|
|
@@ -7497,7 +7529,7 @@ var mParticle = (function () {
|
|
|
7497
7529
|
mpid = currentUser.getMPID();
|
|
7498
7530
|
}
|
|
7499
7531
|
if (preProcessResult.valid) {
|
|
7500
|
-
var identityApiRequest = mpInstance._Identity.IdentityRequest.createIdentityRequest(
|
|
7532
|
+
var identityApiRequest = mpInstance._Identity.IdentityRequest.createIdentityRequest(preProcessResult.cleanedIdentities, Constants.platform, Constants.sdkVendor, Constants.sdkVersion, mpInstance._Store.deviceId, mpInstance._Store.context, mpid);
|
|
7501
7533
|
if (mpInstance._Helpers.getFeatureFlag(Constants.FeatureFlags.CacheIdentity)) {
|
|
7502
7534
|
var successfullyCachedIdentity = tryCacheIdentity(identityApiRequest.known_identities, self.idCache, self.parseIdentityResponse, mpid, callback, identityApiData, Login);
|
|
7503
7535
|
if (successfullyCachedIdentity) {
|
|
@@ -7534,8 +7566,8 @@ var mParticle = (function () {
|
|
|
7534
7566
|
if (currentUser) {
|
|
7535
7567
|
mpid = currentUser.getMPID();
|
|
7536
7568
|
}
|
|
7537
|
-
var newUserIdentities = identityApiData && identityApiData.userIdentities ? identityApiData.userIdentities : {};
|
|
7538
7569
|
if (preProcessResult.valid) {
|
|
7570
|
+
var newUserIdentities = identityApiData && identityApiData.userIdentities ? preProcessResult.cleanedIdentities.userIdentities : {};
|
|
7539
7571
|
var identityApiRequest = mpInstance._Identity.IdentityRequest.createModifyIdentityRequest(currentUser ? currentUser.getUserIdentities().userIdentities : {}, newUserIdentities, Constants.platform, Constants.sdkVendor, Constants.sdkVersion, mpInstance._Store.context);
|
|
7540
7572
|
if (mpInstance._Helpers.canLog()) {
|
|
7541
7573
|
if (mpInstance._Store.webviewBridgeEnabled) {
|
|
@@ -9731,6 +9763,9 @@ var mParticle = (function () {
|
|
|
9731
9763
|
this.launcherOptions = __assign({
|
|
9732
9764
|
sandbox: sandbox
|
|
9733
9765
|
}, options === null || options === void 0 ? void 0 : options.launcherOptions);
|
|
9766
|
+
if (options === null || options === void 0 ? void 0 : options.domain) {
|
|
9767
|
+
this.domain = options.domain;
|
|
9768
|
+
}
|
|
9734
9769
|
};
|
|
9735
9770
|
RoktManager.prototype.attachKit = function (kit) {
|
|
9736
9771
|
this.kit = kit;
|
|
@@ -10889,7 +10924,8 @@ var mParticle = (function () {
|
|
|
10889
10924
|
}, mpInstance);
|
|
10890
10925
|
var roktOptions = {
|
|
10891
10926
|
sandbox: config === null || config === void 0 ? void 0 : config.isDevelopmentMode,
|
|
10892
|
-
launcherOptions: config === null || config === void 0 ? void 0 : config.launcherOptions
|
|
10927
|
+
launcherOptions: config === null || config === void 0 ? void 0 : config.launcherOptions,
|
|
10928
|
+
domain: config === null || config === void 0 ? void 0 : config.domain
|
|
10893
10929
|
};
|
|
10894
10930
|
// https://go.mparticle.com/work/SQDSDKS-7339
|
|
10895
10931
|
mpInstance._RoktManager.init(roktConfig, roktFilteredUser, mpInstance.Identity, mpInstance.Logger, roktOptions);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mparticle/web-sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.43.1",
|
|
4
4
|
"description": "mParticle core SDK for web applications",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"keywords": [
|
|
@@ -28,7 +28,9 @@
|
|
|
28
28
|
"build:npm": "cross-env ENVIRONMENT=prod BUILD=cjs rollup --config rollup.config.js",
|
|
29
29
|
"build:esm": "cross-env ENVIRONMENT=prod BUILD=esm rollup --config rollup.config.js",
|
|
30
30
|
"build:stub": "cross-env ENVIRONMENT=prod BUILD=stub rollup --config rollup.config.js",
|
|
31
|
-
"build:snippet": "
|
|
31
|
+
"build:snippet": "npm run build:snippet:mp && npm run build:snippet:rokt",
|
|
32
|
+
"build:snippet:mp": "uglifyjs snippet.js -m -o snippet.min.js",
|
|
33
|
+
"build:snippet:rokt": "uglifyjs snippet.rokt.js -m -o snippet.rokt.min.js",
|
|
32
34
|
"build:tests": "cross-env ENVIRONMENT=prod TESTTYPE=main rollup --config rollup.test.config.js",
|
|
33
35
|
"build:test-bundle": "cross-env TESTTYPE=main ENVIRONMENT=prod rollup --config rollup.test.config.js",
|
|
34
36
|
"build:browserify:cjs": "browserify test/integrations/cjs/browserify/index.js -o test/integrations/cjs/dist/browserify-output.js",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AllUserAttributes, MPID,
|
|
1
|
+
import { AllUserAttributes, MPID, User } from '@mparticle/web-sdk';
|
|
2
2
|
import { SDKIdentityTypeEnum } from './identity.interfaces';
|
|
3
3
|
import { MessageType } from './types';
|
|
4
4
|
import { BaseEvent, SDKProduct } from './sdkRuntimeModels';
|
package/src/identity-utils.ts
CHANGED
|
@@ -7,10 +7,11 @@ import {
|
|
|
7
7
|
UserIdentities,
|
|
8
8
|
IdentityCallback,
|
|
9
9
|
} from '@mparticle/web-sdk';
|
|
10
|
-
import { IdentityAPIMethod } from './identity.interfaces';
|
|
10
|
+
import { IdentityAPIMethod, IIdentityRequest } from './identity.interfaces';
|
|
11
11
|
import {
|
|
12
12
|
IdentityResultBody,
|
|
13
13
|
IIdentityResponse,
|
|
14
|
+
IMParticleUser,
|
|
14
15
|
} from './identity-user-interfaces';
|
|
15
16
|
|
|
16
17
|
const { Identify, Modify, Login, Logout } = Constants.IdentityMethods;
|
|
@@ -279,3 +280,21 @@ const getExpireTimestamp = (maxAge: number = ONE_DAY_IN_SECONDS): number =>
|
|
|
279
280
|
|
|
280
281
|
const parseIdentityResponse = (responseText: string): IdentityResultBody =>
|
|
281
282
|
responseText ? JSON.parse(responseText) : ({} as IdentityResultBody);
|
|
283
|
+
|
|
284
|
+
export const hasIdentityRequestChanged = (
|
|
285
|
+
currentUser: IMParticleUser,
|
|
286
|
+
newIdentityRequest: IdentityApiData
|
|
287
|
+
): boolean => {
|
|
288
|
+
if (!currentUser || !newIdentityRequest?.userIdentities) {
|
|
289
|
+
return false;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const currentUserIdentities =
|
|
293
|
+
currentUser.getUserIdentities().userIdentities;
|
|
294
|
+
|
|
295
|
+
const newIdentities = newIdentityRequest.userIdentities;
|
|
296
|
+
|
|
297
|
+
return (
|
|
298
|
+
JSON.stringify(currentUserIdentities) !== JSON.stringify(newIdentities)
|
|
299
|
+
);
|
|
300
|
+
};
|
package/src/identity.js
CHANGED
|
@@ -33,8 +33,14 @@ export default function Identity(mpInstance) {
|
|
|
33
33
|
Messages.InformationMessages.StartingLogEvent + ': ' + method
|
|
34
34
|
);
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
// First, remove any falsy identity values and warn about them
|
|
37
|
+
const cleanedIdentityApiData = mpInstance._Helpers.Validators.removeFalsyIdentityValues(
|
|
37
38
|
identityApiData,
|
|
39
|
+
mpInstance.Logger
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
var identityValidationResult = mpInstance._Helpers.Validators.validateIdentities(
|
|
43
|
+
cleanedIdentityApiData,
|
|
38
44
|
method
|
|
39
45
|
);
|
|
40
46
|
|
|
@@ -64,6 +70,7 @@ export default function Identity(mpInstance) {
|
|
|
64
70
|
|
|
65
71
|
return {
|
|
66
72
|
valid: true,
|
|
73
|
+
cleanedIdentities: cleanedIdentityApiData,
|
|
67
74
|
};
|
|
68
75
|
},
|
|
69
76
|
|
|
@@ -237,7 +244,7 @@ export default function Identity(mpInstance) {
|
|
|
237
244
|
|
|
238
245
|
if (preProcessResult.valid) {
|
|
239
246
|
var identityApiRequest = mpInstance._Identity.IdentityRequest.createIdentityRequest(
|
|
240
|
-
|
|
247
|
+
preProcessResult.cleanedIdentities,
|
|
241
248
|
Constants.platform,
|
|
242
249
|
Constants.sdkVendor,
|
|
243
250
|
Constants.sdkVersion,
|
|
@@ -332,7 +339,7 @@ export default function Identity(mpInstance) {
|
|
|
332
339
|
if (preProcessResult.valid) {
|
|
333
340
|
var evt,
|
|
334
341
|
identityApiRequest = mpInstance._Identity.IdentityRequest.createIdentityRequest(
|
|
335
|
-
|
|
342
|
+
preProcessResult.cleanedIdentities,
|
|
336
343
|
Constants.platform,
|
|
337
344
|
Constants.sdkVendor,
|
|
338
345
|
Constants.sdkVersion,
|
|
@@ -422,7 +429,7 @@ export default function Identity(mpInstance) {
|
|
|
422
429
|
|
|
423
430
|
if (preProcessResult.valid) {
|
|
424
431
|
var identityApiRequest = mpInstance._Identity.IdentityRequest.createIdentityRequest(
|
|
425
|
-
|
|
432
|
+
preProcessResult.cleanedIdentities,
|
|
426
433
|
Constants.platform,
|
|
427
434
|
Constants.sdkVendor,
|
|
428
435
|
Constants.sdkVersion,
|
|
@@ -514,11 +521,11 @@ export default function Identity(mpInstance) {
|
|
|
514
521
|
if (currentUser) {
|
|
515
522
|
mpid = currentUser.getMPID();
|
|
516
523
|
}
|
|
517
|
-
var newUserIdentities =
|
|
518
|
-
identityApiData && identityApiData.userIdentities
|
|
519
|
-
? identityApiData.userIdentities
|
|
520
|
-
: {};
|
|
521
524
|
if (preProcessResult.valid) {
|
|
525
|
+
var newUserIdentities =
|
|
526
|
+
identityApiData && identityApiData.userIdentities
|
|
527
|
+
? preProcessResult.cleanedIdentities.userIdentities
|
|
528
|
+
: {};
|
|
522
529
|
var identityApiRequest = mpInstance._Identity.IdentityRequest.createModifyIdentityRequest(
|
|
523
530
|
currentUser
|
|
524
531
|
? currentUser.getUserIdentities().userIdentities
|
package/src/mp-instance.ts
CHANGED
|
@@ -1406,6 +1406,7 @@ function completeSDKInitialization(apiKey, config, mpInstance) {
|
|
|
1406
1406
|
const roktOptions: IRoktOptions = {
|
|
1407
1407
|
sandbox: config?.isDevelopmentMode,
|
|
1408
1408
|
launcherOptions: config?.launcherOptions,
|
|
1409
|
+
domain: config?.domain,
|
|
1409
1410
|
};
|
|
1410
1411
|
// https://go.mparticle.com/work/SQDSDKS-7339
|
|
1411
1412
|
mpInstance._RoktManager.init(
|
package/src/roktManager.ts
CHANGED
|
@@ -58,6 +58,7 @@ export interface IRoktKit {
|
|
|
58
58
|
export interface IRoktOptions {
|
|
59
59
|
sandbox?: boolean;
|
|
60
60
|
launcherOptions?: IRoktLauncherOptions;
|
|
61
|
+
domain?: string;
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
export type IRoktLauncherOptions = Dictionary<any>;
|
|
@@ -81,6 +82,7 @@ export default class RoktManager {
|
|
|
81
82
|
private identityService: SDKIdentityApi;
|
|
82
83
|
private launcherOptions?: IRoktLauncherOptions;
|
|
83
84
|
private logger: SDKLoggerApi;
|
|
85
|
+
private domain?: string;
|
|
84
86
|
/**
|
|
85
87
|
* Initializes the RoktManager with configuration settings and user data.
|
|
86
88
|
*
|
|
@@ -126,6 +128,10 @@ export default class RoktManager {
|
|
|
126
128
|
// Launcher options are set here for the kit to pick up and pass through
|
|
127
129
|
// to the Rokt Launcher.
|
|
128
130
|
this.launcherOptions = { sandbox, ...options?.launcherOptions };
|
|
131
|
+
|
|
132
|
+
if (options?.domain) {
|
|
133
|
+
this.domain = options.domain;
|
|
134
|
+
}
|
|
129
135
|
}
|
|
130
136
|
|
|
131
137
|
public attachKit(kit: IRoktKit): void {
|