@mparticle/web-sdk 2.43.0 → 2.43.2

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.js CHANGED
@@ -203,7 +203,7 @@ var mParticle = (function () {
203
203
  Base64: Base64$1
204
204
  };
205
205
 
206
- var version = "2.43.0";
206
+ var version = "2.43.2";
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
- var persistence = mpInstance._Persistence.getPersistence();
3488
- if (persistence && !persistence.cu) {
3489
- // https://go.mparticle.com/work/SQDSDKS-6323
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$3 = _Constants$IdentityMe.Modify,
6162
- Identify$2 = _Constants$IdentityMe.Identify,
6163
- Login$2 = _Constants$IdentityMe.Login,
6164
- Logout$2 = _Constants$IdentityMe.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$2) {
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$2) {
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$2) {
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$3) {
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
- var identityValidationResult = mpInstance._Helpers.Validators.validateIdentities(identityApiData, method);
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(identityApiData, Constants.platform, Constants.sdkVendor, Constants.sdkVersion, mpInstance._Store.deviceId, mpInstance._Store.context, mpid);
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(identityApiData, Constants.platform, Constants.sdkVendor, Constants.sdkVersion, mpInstance._Store.deviceId, mpInstance._Store.context, mpid);
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(identityApiData, Constants.platform, Constants.sdkVendor, Constants.sdkVersion, mpInstance._Store.deviceId, mpInstance._Store.context, mpid);
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) {
@@ -9689,7 +9721,7 @@ var mParticle = (function () {
9689
9721
  this.kit = null;
9690
9722
  this.filters = {};
9691
9723
  this.currentUser = null;
9692
- this.messageQueue = [];
9724
+ this.messageQueue = new Map();
9693
9725
  this.sandbox = null;
9694
9726
  this.placementAttributesMapping = [];
9695
9727
  }
@@ -9763,11 +9795,7 @@ var mParticle = (function () {
9763
9795
  switch (_c.label) {
9764
9796
  case 0:
9765
9797
  if (!this.isReady()) {
9766
- this.queueMessage({
9767
- methodName: 'selectPlacements',
9768
- payload: options
9769
- });
9770
- return [2 /*return*/, Promise.resolve({})];
9798
+ return [2 /*return*/, this.deferredCall('selectPlacements', options)];
9771
9799
  }
9772
9800
  _c.label = 1;
9773
9801
  case 1:
@@ -9824,11 +9852,7 @@ var mParticle = (function () {
9824
9852
 
9825
9853
  RoktManager.prototype.hashAttributes = function (attributes) {
9826
9854
  if (!this.isReady()) {
9827
- this.queueMessage({
9828
- methodName: 'hashAttributes',
9829
- payload: attributes
9830
- });
9831
- return Promise.resolve({});
9855
+ return this.deferredCall('hashAttributes', attributes);
9832
9856
  }
9833
9857
  try {
9834
9858
  return this.kit.hashAttributes(attributes);
@@ -9838,10 +9862,7 @@ var mParticle = (function () {
9838
9862
  };
9839
9863
  RoktManager.prototype.setExtensionData = function (extensionData) {
9840
9864
  if (!this.isReady()) {
9841
- this.queueMessage({
9842
- methodName: 'setExtensionData',
9843
- payload: extensionData
9844
- });
9865
+ this.deferredCall('setExtensionData', extensionData);
9845
9866
  return;
9846
9867
  }
9847
9868
  try {
@@ -9886,29 +9907,57 @@ var mParticle = (function () {
9886
9907
  };
9887
9908
  RoktManager.prototype.processMessageQueue = function () {
9888
9909
  var _this = this;
9889
- if (this.messageQueue.length > 0 && this.isReady()) {
9890
- this.messageQueue.forEach(function (message) {
9891
- return __awaiter(_this, void 0, void 0, function () {
9892
- return __generator(this, function (_a) {
9893
- switch (_a.label) {
9894
- case 0:
9895
- if (!(this.kit && message.methodName in this.kit)) return [3 /*break*/, 2];
9896
- return [4 /*yield*/, this.kit[message.methodName](message.payload)];
9897
- case 1:
9898
- _a.sent();
9899
- _a.label = 2;
9900
- case 2:
9901
- return [2 /*return*/];
9902
- }
9903
- });
9904
- });
9905
- });
9906
-
9907
- this.messageQueue = [];
9910
+ var _a;
9911
+ if (!this.isReady() || this.messageQueue.size === 0) {
9912
+ return;
9908
9913
  }
9914
+ (_a = this.logger) === null || _a === void 0 ? void 0 : _a.verbose("RoktManager: Processing ".concat(this.messageQueue.size, " queued messages"));
9915
+ this.messageQueue.forEach(function (message) {
9916
+ var _a, _b, _c;
9917
+ if (!(message.methodName in _this.kit) || !isFunction(_this.kit[message.methodName])) {
9918
+ (_a = _this.logger) === null || _a === void 0 ? void 0 : _a.error("RoktManager: Method ".concat(message.methodName, " not found in kit"));
9919
+ return;
9920
+ }
9921
+ (_b = _this.logger) === null || _b === void 0 ? void 0 : _b.verbose("RoktManager: Processing queued message: ".concat(message.methodName, " with payload: ").concat(JSON.stringify(message.payload)));
9922
+ try {
9923
+ var result = _this.kit[message.methodName](message.payload);
9924
+ _this.completePendingPromise(message.messageId, result);
9925
+ } catch (error) {
9926
+ var errorMessage = error instanceof Error ? error.message : String(error);
9927
+ (_c = _this.logger) === null || _c === void 0 ? void 0 : _c.error("RoktManager: Error processing message '".concat(message.methodName, "': ").concat(errorMessage));
9928
+ _this.completePendingPromise(message.messageId, Promise.reject(error));
9929
+ }
9930
+ });
9909
9931
  };
9910
9932
  RoktManager.prototype.queueMessage = function (message) {
9911
- this.messageQueue.push(message);
9933
+ this.messageQueue.set(message.messageId, message);
9934
+ };
9935
+ RoktManager.prototype.deferredCall = function (methodName, payload) {
9936
+ var _this = this;
9937
+ return new Promise(function (resolve, reject) {
9938
+ var messageId = "".concat(methodName, "_").concat(generateUniqueId());
9939
+ _this.queueMessage({
9940
+ messageId: messageId,
9941
+ methodName: methodName,
9942
+ payload: payload,
9943
+ resolve: resolve,
9944
+ reject: reject
9945
+ });
9946
+ });
9947
+ };
9948
+ RoktManager.prototype.completePendingPromise = function (messageId, resultOrError) {
9949
+ if (!messageId || !this.messageQueue.has(messageId)) {
9950
+ return;
9951
+ }
9952
+ var message = this.messageQueue.get(messageId);
9953
+ if (message.resolve) {
9954
+ Promise.resolve(resultOrError).then(function (result) {
9955
+ return message.resolve(result);
9956
+ })["catch"](function (error) {
9957
+ return message.reject(error);
9958
+ });
9959
+ }
9960
+ this.messageQueue["delete"](messageId);
9912
9961
  };
9913
9962
  return RoktManager;
9914
9963
  }();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mparticle/web-sdk",
3
- "version": "2.43.0",
3
+ "version": "2.43.2",
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": "uglifyjs snippet.js -m -o snippet.min.js",
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, Product, User } from '@mparticle/web-sdk';
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';
@@ -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
+ };