@mparticle/web-sdk 2.23.7 → 2.23.9

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
@@ -608,7 +608,7 @@ var mParticle = (function () {
608
608
  Environment: Environment
609
609
  };
610
610
 
611
- var version = "2.23.7";
611
+ var version = "2.23.9";
612
612
 
613
613
  var Constants = {
614
614
  sdkVersion: version,
@@ -742,6 +742,7 @@ var mParticle = (function () {
742
742
  ia: 1,
743
743
  con: 1
744
744
  },
745
+ // https://go.mparticle.com/work/SQDSDKS-6039
745
746
  SDKv2NonMPIDCookieKeys: {
746
747
  gs: 1,
747
748
  cu: 1,
@@ -764,7 +765,13 @@ var mParticle = (function () {
764
765
  OfflineStorage: 'offlineStorage'
765
766
  },
766
767
  DefaultInstance: 'default_instance',
767
- CCPAPurpose: 'data_sale_opt_out'
768
+ CCPAPurpose: 'data_sale_opt_out',
769
+ IdentityMethods: {
770
+ Modify: 'modify',
771
+ Logout: 'logout',
772
+ Login: 'login',
773
+ Identify: 'identify'
774
+ }
768
775
  };
769
776
 
770
777
  /******************************************************************************
@@ -1282,9 +1289,15 @@ var mParticle = (function () {
1282
1289
  var isNumber = function isNumber(value) {
1283
1290
  return typeof value === 'number';
1284
1291
  };
1292
+ var isBoolean = function isBoolean(value) {
1293
+ return typeof value === 'boolean';
1294
+ };
1285
1295
  var isFunction = function isFunction(fn) {
1286
1296
  return typeof fn === 'function';
1287
1297
  };
1298
+ var isValidCustomFlagProperty = function isValidCustomFlagProperty(value) {
1299
+ return isNumber(value) || isString(value) || isBoolean(value);
1300
+ };
1288
1301
  var toDataPlanSlug = function toDataPlanSlug(value) {
1289
1302
  // Make sure we are only acting on strings or numbers
1290
1303
  return isStringOrNumber(value) ? value.toString().toLowerCase().replace(/[^0-9a-zA-Z]+/g, '_') : '';
@@ -2364,6 +2377,7 @@ var mParticle = (function () {
2364
2377
  this.uploader = new BatchUploader(mpInstance, millis);
2365
2378
  }
2366
2379
  this.uploader.queueEvent(event);
2380
+ // https://go.mparticle.com/work/SQDSDKS-6038
2367
2381
  mpInstance._Persistence.update();
2368
2382
  };
2369
2383
  this.processQueuedEvents = function () {
@@ -2414,6 +2428,7 @@ var mParticle = (function () {
2414
2428
  if (isEmpty(event)) {
2415
2429
  return;
2416
2430
  }
2431
+ // https://go.mparticle.com/work/SQDSDKS-6038
2417
2432
  if (options.shouldUploadEvent) {
2418
2433
  this.queueEventForBatchUpload(event);
2419
2434
  }
@@ -2494,6 +2509,7 @@ var mParticle = (function () {
2494
2509
  };
2495
2510
  }
2496
2511
 
2512
+ var Modify$3 = Constants.IdentityMethods.Modify;
2497
2513
  var Validators = {
2498
2514
  // From ./utils
2499
2515
  // Utility Functions for backwards compatability
@@ -2516,7 +2532,7 @@ var mParticle = (function () {
2516
2532
  copyUserAttributes: 1
2517
2533
  };
2518
2534
  if (identityApiData) {
2519
- if (method === 'modify') {
2535
+ if (method === Modify$3) {
2520
2536
  if (isObject(identityApiData.userIdentities) && !Object.keys(identityApiData.userIdentities).length || !isObject(identityApiData.userIdentities)) {
2521
2537
  return {
2522
2538
  valid: false,
@@ -2690,6 +2706,7 @@ var mParticle = (function () {
2690
2706
  }
2691
2707
  };
2692
2708
 
2709
+ // https://go.mparticle.com/work/SQDSDKS-6047
2693
2710
  // Standalone version of jQuery.extend, from https://github.com/dansdom/extend
2694
2711
  this.extend = function () {
2695
2712
  var options,
@@ -3191,6 +3208,7 @@ var mParticle = (function () {
3191
3208
  self.endSession();
3192
3209
  self.startNewSession();
3193
3210
  } else {
3211
+ // https://go.mparticle.com/work/SQDSDKS-6045
3194
3212
  var persistence = mpInstance._Persistence.getPersistence();
3195
3213
  if (persistence && !persistence.cu) {
3196
3214
  mpInstance.Identity.identify(mpInstance._Store.SDKConfig.identifyRequest, mpInstance._Store.SDKConfig.identityCallback);
@@ -4008,6 +4026,8 @@ var mParticle = (function () {
4008
4026
  StorageNames = Constants.StorageNames;
4009
4027
  function _Persistence(mpInstance) {
4010
4028
  var self = this;
4029
+
4030
+ // https://go.mparticle.com/work/SQDSDKS-5022
4011
4031
  this.useLocalStorage = function () {
4012
4032
  return !mpInstance._Store.SDKConfig.useCookieStorage && mpInstance._Store.isLocalStorageAvailable;
4013
4033
  };
@@ -4018,6 +4038,7 @@ var mParticle = (function () {
4018
4038
  cookies = self.getCookie(),
4019
4039
  allData;
4020
4040
 
4041
+ // https://go.mparticle.com/work/SQDSDKS-6045
4021
4042
  // Determine if there is any data in cookies or localStorage to figure out if it is the first time the browser is loading mParticle
4022
4043
  if (!localStorageData && !cookies) {
4023
4044
  mpInstance._Store.isFirstRun = true;
@@ -4025,9 +4046,13 @@ var mParticle = (function () {
4025
4046
  } else {
4026
4047
  mpInstance._Store.isFirstRun = false;
4027
4048
  }
4049
+
4050
+ // https://go.mparticle.com/work/SQDSDKS-6045
4028
4051
  if (!mpInstance._Store.isLocalStorageAvailable) {
4029
4052
  mpInstance._Store.SDKConfig.useCookieStorage = true;
4030
4053
  }
4054
+
4055
+ // https://go.mparticle.com/work/SQDSDKS-6046
4031
4056
  if (mpInstance._Store.isLocalStorageAvailable) {
4032
4057
  storage = window.localStorage;
4033
4058
  if (mpInstance._Store.SDKConfig.useCookieStorage) {
@@ -4035,6 +4060,7 @@ var mParticle = (function () {
4035
4060
  // no mParticle cookie exists yet and there is localStorage. Get the localStorage, set them to cookies, then delete the localStorage item.
4036
4061
  if (localStorageData) {
4037
4062
  if (cookies) {
4063
+ // https://go.mparticle.com/work/SQDSDKS-6047
4038
4064
  allData = mpInstance._Helpers.extend(false, localStorageData, cookies);
4039
4065
  } else {
4040
4066
  allData = localStorageData;
@@ -4049,6 +4075,7 @@ var mParticle = (function () {
4049
4075
  // no mParticle localStorage exists yet and there are cookies. Get the cookies, set them to localStorage, then delete the cookies.
4050
4076
  if (cookies) {
4051
4077
  if (localStorageData) {
4078
+ // https://go.mparticle.com/work/SQDSDKS-6047
4052
4079
  allData = mpInstance._Helpers.extend(false, localStorageData, cookies);
4053
4080
  } else {
4054
4081
  allData = cookies;
@@ -4062,6 +4089,8 @@ var mParticle = (function () {
4062
4089
  } else {
4063
4090
  self.storeDataInMemory(cookies);
4064
4091
  }
4092
+
4093
+ // https://go.mparticle.com/work/SQDSDKS-6048
4065
4094
  try {
4066
4095
  if (mpInstance._Store.isLocalStorageAvailable) {
4067
4096
  var encodedProducts = localStorage.getItem(mpInstance._Store.prodStorageName);
@@ -4079,6 +4108,9 @@ var mParticle = (function () {
4079
4108
  mpInstance._Store.cartProducts = [];
4080
4109
  mpInstance.Logger.error('Error loading products in initialization: ' + e);
4081
4110
  }
4111
+
4112
+ // https://go.mparticle.com/work/SQDSDKS-6046
4113
+ // Stores all non-current user MPID information into the store
4082
4114
  for (var key in allData) {
4083
4115
  if (allData.hasOwnProperty(key)) {
4084
4116
  if (!SDKv2NonMPIDCookieKeys[key]) {
@@ -4088,6 +4120,8 @@ var mParticle = (function () {
4088
4120
  }
4089
4121
  self.update();
4090
4122
  } catch (e) {
4123
+ // If cookies or local storage is corrupt, we want to remove it
4124
+ // so that in the future, initializeStorage will work
4091
4125
  if (self.useLocalStorage() && mpInstance._Store.isLocalStorageAvailable) {
4092
4126
  localStorage.removeItem(mpInstance._Store.storageName);
4093
4127
  } else {
@@ -4113,6 +4147,8 @@ var mParticle = (function () {
4113
4147
  }
4114
4148
  }
4115
4149
  };
4150
+
4151
+ // https://go.mparticle.com/work/SQDSDKS-6045
4116
4152
  this.storeDataInMemory = function (obj, currentMPID) {
4117
4153
  try {
4118
4154
  if (!obj) {
@@ -4164,6 +4200,8 @@ var mParticle = (function () {
4164
4200
  mpInstance.Logger.error(Messages$4.ErrorMessages.CookieParseError);
4165
4201
  }
4166
4202
  };
4203
+
4204
+ // https://go.mparticle.com/work/SQDSDKS-5022
4167
4205
  this.determineLocalStorageAvailability = function (storage) {
4168
4206
  var result;
4169
4207
  if (window.mParticle && window.mParticle._forceNoLocalStorage) {
@@ -4223,6 +4261,8 @@ var mParticle = (function () {
4223
4261
  }
4224
4262
  return parsedDecodedProducts;
4225
4263
  };
4264
+
4265
+ // https://go.mparticle.com/work/SQDSDKS-6021
4226
4266
  this.setLocalStorage = function () {
4227
4267
  if (!mpInstance._Store.isLocalStorageAvailable) {
4228
4268
  return;
@@ -4355,7 +4395,8 @@ var mParticle = (function () {
4355
4395
  }
4356
4396
  };
4357
4397
 
4358
- // only used in persistence
4398
+ // https://go.mparticle.com/work/SQDSDKS-5022
4399
+ // https://go.mparticle.com/work/SQDSDKS-6021
4359
4400
  this.setCookie = function () {
4360
4401
  var mpid,
4361
4402
  currentUser = mpInstance.Identity.getCurrentUser();
@@ -4706,6 +4747,8 @@ var mParticle = (function () {
4706
4747
  }
4707
4748
  }
4708
4749
  };
4750
+
4751
+ // https://go.mparticle.com/work/SQDSDKS-6021
4709
4752
  this.savePersistence = function (persistence) {
4710
4753
  var encodedPersistence = self.encodePersistence(JSON.stringify(persistence)),
4711
4754
  date = new Date(),
@@ -4835,6 +4878,7 @@ var mParticle = (function () {
4835
4878
  }
4836
4879
  };
4837
4880
 
4881
+ // https://go.mparticle.com/work/SQDSDKS-6045
4838
4882
  // Forwarder Batching Code
4839
4883
  this.forwardingStatsBatches = {
4840
4884
  uploadsTable: {},
@@ -5044,6 +5088,8 @@ var mParticle = (function () {
5044
5088
  commerceEvent.EventAttributes = attrs;
5045
5089
  }
5046
5090
  mpInstance._APIClient.sendEventToServer(commerceEvent, options);
5091
+
5092
+ // https://go.mparticle.com/work/SQDSDKS-6038
5047
5093
  mpInstance._Persistence.update();
5048
5094
  } else {
5049
5095
  mpInstance.Logger.verbose(Messages$3.InformationMessages.AbandonLogEvent);
@@ -5168,6 +5214,11 @@ var mParticle = (function () {
5168
5214
  };
5169
5215
  }
5170
5216
 
5217
+ var _Constants$IdentityMe$1 = Constants.IdentityMethods,
5218
+ Modify$2 = _Constants$IdentityMe$1.Modify,
5219
+ Identify$1 = _Constants$IdentityMe$1.Identify,
5220
+ Login = _Constants$IdentityMe$1.Login,
5221
+ Logout = _Constants$IdentityMe$1.Logout;
5171
5222
  function Forwarders(mpInstance, kitBlocker) {
5172
5223
  var self = this;
5173
5224
  var UserAttributeActionTypes = {
@@ -5398,6 +5449,8 @@ var mParticle = (function () {
5398
5449
  }
5399
5450
  });
5400
5451
  };
5452
+
5453
+ // TODO: https://go.mparticle.com/work/SQDSDKS-6036
5401
5454
  this.setForwarderUserIdentities = function (userIdentities) {
5402
5455
  mpInstance._Store.activeForwarders.forEach(function (forwarder) {
5403
5456
  var filteredUserIdentities = mpInstance._Helpers.filterUserIdentities(userIdentities, forwarder.userIdentityFilters);
@@ -5426,30 +5479,31 @@ var mParticle = (function () {
5426
5479
  var result;
5427
5480
  mpInstance._Store.activeForwarders.forEach(function (forwarder) {
5428
5481
  var filteredUser = filteredMparticleUser(user.getMPID(), forwarder, mpInstance, kitBlocker);
5429
- if (identityMethod === 'identify') {
5482
+ var filteredUserIdentities = filteredUser.getUserIdentities();
5483
+ if (identityMethod === Identify$1) {
5430
5484
  if (forwarder.onIdentifyComplete) {
5431
- result = forwarder.onIdentifyComplete(filteredUser);
5485
+ result = forwarder.onIdentifyComplete(filteredUser, filteredUserIdentities);
5432
5486
  if (result) {
5433
5487
  mpInstance.Logger.verbose(result);
5434
5488
  }
5435
5489
  }
5436
- } else if (identityMethod === 'login') {
5490
+ } else if (identityMethod === Login) {
5437
5491
  if (forwarder.onLoginComplete) {
5438
- result = forwarder.onLoginComplete(filteredUser);
5492
+ result = forwarder.onLoginComplete(filteredUser, filteredUserIdentities);
5439
5493
  if (result) {
5440
5494
  mpInstance.Logger.verbose(result);
5441
5495
  }
5442
5496
  }
5443
- } else if (identityMethod === 'logout') {
5497
+ } else if (identityMethod === Logout) {
5444
5498
  if (forwarder.onLogoutComplete) {
5445
- result = forwarder.onLogoutComplete(filteredUser);
5499
+ result = forwarder.onLogoutComplete(filteredUser, filteredUserIdentities);
5446
5500
  if (result) {
5447
5501
  mpInstance.Logger.verbose(result);
5448
5502
  }
5449
5503
  }
5450
- } else if (identityMethod === 'modify') {
5504
+ } else if (identityMethod === Modify$2) {
5451
5505
  if (forwarder.onModifyComplete) {
5452
- result = forwarder.onModifyComplete(filteredUser);
5506
+ result = forwarder.onModifyComplete(filteredUser, filteredUserIdentities);
5453
5507
  if (result) {
5454
5508
  mpInstance.Logger.verbose(result);
5455
5509
  }
@@ -5649,14 +5703,11 @@ var mParticle = (function () {
5649
5703
  if (event.CustomFlags.hasOwnProperty(prop)) {
5650
5704
  if (Array.isArray(event.CustomFlags[prop])) {
5651
5705
  event.CustomFlags[prop].forEach(function (customFlagProperty) {
5652
- // TODO: Can we use our utility functions here?
5653
- if (typeof customFlagProperty === 'number' || typeof customFlagProperty === 'string' || typeof customFlagProperty === 'boolean') {
5706
+ if (isValidCustomFlagProperty(customFlagProperty)) {
5654
5707
  valueArray.push(customFlagProperty.toString());
5655
5708
  }
5656
5709
  });
5657
- } else if (
5658
- // TODO: Can we use our utility functions here?
5659
- typeof event.CustomFlags[prop] === 'number' || typeof event.CustomFlags[prop] === 'string' || typeof event.CustomFlags[prop] === 'boolean') {
5710
+ } else if (isValidCustomFlagProperty(event.CustomFlags[prop])) {
5660
5711
  valueArray.push(event.CustomFlags[prop].toString());
5661
5712
  }
5662
5713
  if (valueArray.length) {
@@ -5992,6 +6043,9 @@ var mParticle = (function () {
5992
6043
 
5993
6044
  var Messages$2 = Constants.Messages,
5994
6045
  HTTPCodes$2 = Constants.HTTPCodes;
6046
+ var _Constants$IdentityMe = Constants.IdentityMethods,
6047
+ Identify = _Constants$IdentityMe.Identify,
6048
+ Modify$1 = _Constants$IdentityMe.Modify;
5995
6049
  function Identity(mpInstance) {
5996
6050
  var self = this;
5997
6051
  this.checkIdentitySwap = function (previousMPID, currentMPID, currentSessionMPIDs) {
@@ -6897,7 +6951,7 @@ var mParticle = (function () {
6897
6951
  mpInstance._Persistence.setFirstSeenTime(identityApiResult.mpid);
6898
6952
  }
6899
6953
  if (xhr.status === 200) {
6900
- if (method === 'modify') {
6954
+ if (method === Modify$1) {
6901
6955
  newIdentitiesByType = mpInstance._Identity.IdentityRequest.combineUserIdentities(previousUIByName, identityApiData.userIdentities);
6902
6956
  mpInstance._Persistence.saveUserIdentitiesToPersistence(previousMPID, newIdentitiesByType);
6903
6957
  } else {
@@ -6909,7 +6963,7 @@ var mParticle = (function () {
6909
6963
  //this covers an edge case where, users stored before "firstSeenTime" was introduced
6910
6964
  //will not have a value for "fst" until the current MPID changes, and in some cases,
6911
6965
  //the current MPID will never change
6912
- if (method === 'identify' && prevUser && identityApiResult.mpid === prevUser.getMPID()) {
6966
+ if (method === Identify && prevUser && identityApiResult.mpid === prevUser.getMPID()) {
6913
6967
  mpInstance._Persistence.setFirstSeenTime(identityApiResult.mpid);
6914
6968
  }
6915
6969
  indexOfMPID = mpInstance._Store.currentSessionMPIDs.indexOf(identityApiResult.mpid);
@@ -6925,6 +6979,8 @@ var mParticle = (function () {
6925
6979
  if (identityApiData && identityApiData.userIdentities && Object.keys(identityApiData.userIdentities).length) {
6926
6980
  newIdentitiesByType = self.IdentityRequest.combineUserIdentities(incomingMpidUIByName, identityApiData.userIdentities);
6927
6981
  }
6982
+
6983
+ // https://go.mparticle.com/work/SQDSDKS-6041
6928
6984
  mpInstance._Persistence.saveUserIdentitiesToPersistence(identityApiResult.mpid, newIdentitiesByType);
6929
6985
  mpInstance._Persistence.update();
6930
6986
  mpInstance._Persistence.findPrevCookiesBasedOnUI(identityApiData);
@@ -6945,15 +7001,17 @@ var mParticle = (function () {
6945
7001
  if (!prevUser || newUser.getMPID() !== prevUser.getMPID() || prevUser.isLoggedIn() !== newUser.isLoggedIn()) {
6946
7002
  mpInstance._Forwarders.initForwarders(newUser.getUserIdentities().userIdentities, mpInstance._APIClient.prepareForwardingStats);
6947
7003
  }
7004
+
7005
+ // TODO: https://go.mparticle.com/work/SQDSDKS-6036
6948
7006
  mpInstance._Forwarders.setForwarderUserIdentities(newUser.getUserIdentities().userIdentities);
6949
7007
  mpInstance._Forwarders.setForwarderOnIdentityComplete(newUser, method);
6950
- mpInstance._Forwarders.setForwarderOnUserIdentified(newUser, method);
7008
+ mpInstance._Forwarders.setForwarderOnUserIdentified(newUser);
6951
7009
  }
6952
7010
  var newIdentitiesByName = {};
6953
7011
  for (var key in newIdentitiesByType) {
6954
7012
  newIdentitiesByName[Types.IdentityType.getIdentityName(mpInstance._Helpers.parseNumber(key))] = newIdentitiesByType[key];
6955
7013
  }
6956
- self.sendUserIdentityChangeEvent(newIdentitiesByName, method, identityApiResult.mpid, method === 'modify' ? previousUIByNameCopy : incomingMpidUIByNameCopy);
7014
+ self.sendUserIdentityChangeEvent(newIdentitiesByName, method, identityApiResult.mpid, method === Modify$1 ? previousUIByNameCopy : incomingMpidUIByNameCopy);
6957
7015
  }
6958
7016
  if (callback) {
6959
7017
  if (xhr.status === 0) {
@@ -7840,6 +7898,7 @@ var mParticle = (function () {
7840
7898
 
7841
7899
  var HTTPCodes$1 = Constants.HTTPCodes,
7842
7900
  Messages$1 = Constants.Messages;
7901
+ var Modify = Constants.IdentityMethods.Modify;
7843
7902
  function IdentityAPIClient(mpInstance) {
7844
7903
  this.sendAliasRequest = function (aliasRequest, callback) {
7845
7904
  var xhr,
@@ -7894,7 +7953,7 @@ var mParticle = (function () {
7894
7953
  mpInstance._Helpers.invokeCallback(callback, HTTPCodes$1.activeIdentityRequest, 'There is currently an Identity request processing. Please wait for this to return before requesting again');
7895
7954
  } else {
7896
7955
  previousMPID = mpid || null;
7897
- if (method === 'modify') {
7956
+ if (method === Modify) {
7898
7957
  xhr.open('post', mpInstance._Helpers.createServiceUrl(mpInstance._Store.SDKConfig.identityUrl) + mpid + '/' + method);
7899
7958
  } else {
7900
7959
  xhr.open('post', mpInstance._Helpers.createServiceUrl(mpInstance._Store.SDKConfig.identityUrl) + method);
@@ -8873,6 +8932,8 @@ var mParticle = (function () {
8873
8932
  }
8874
8933
  mpInstance._Store.webviewBridgeEnabled = mpInstance._NativeSdkHelpers.isWebviewEnabled(mpInstance._Store.SDKConfig.requiredWebviewBridgeName, mpInstance._Store.SDKConfig.minWebviewBridgeVersion);
8875
8934
  mpInstance._Store.configurationLoaded = true;
8935
+
8936
+ // https://go.mparticle.com/work/SQDSDKS-6044
8876
8937
  if (!mpInstance._Store.webviewBridgeEnabled) {
8877
8938
  // Load any settings/identities/attributes from cookie or localStorage
8878
8939
  mpInstance._Persistence.initializeStorage();
@@ -8917,6 +8978,7 @@ var mParticle = (function () {
8917
8978
  mpInstance._Events.logAST();
8918
8979
 
8919
8980
  // Call mParticle._Store.SDKConfig.identityCallback when identify was not called due to a reload or a sessionId already existing
8981
+ // Any identity callback should always be ran regardless if an identity call is made
8920
8982
  if (!mpInstance._Store.identifyCalled && mpInstance._Store.SDKConfig.identityCallback && currentUser && currentUser.getMPID()) {
8921
8983
  mpInstance._Store.SDKConfig.identityCallback({
8922
8984
  httpCode: HTTPCodes.activeSession,
@@ -8953,6 +9015,8 @@ var mParticle = (function () {
8953
9015
  });
8954
9016
  mpInstance._preInit.readyQueue = [];
8955
9017
  }
9018
+
9019
+ // https://go.mparticle.com/work/SQDSDKS-6040
8956
9020
  if (mpInstance._Store.isFirstRun) {
8957
9021
  mpInstance._Store.isFirstRun = false;
8958
9022
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mparticle/web-sdk",
3
- "version": "2.23.7",
3
+ "version": "2.23.9",
4
4
  "description": "mParticle core SDK for web applications",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
@@ -22,20 +22,25 @@
22
22
  "repository": "https://github.com/mParticle/mparticle-web-sdk",
23
23
  "scripts": {
24
24
  "build": "cross-env ENVIRONMENT=prod BUILDALL=true rollup --config rollup.config.js",
25
+ "build:cbt": "rollup --config test/cross-browser-testing/rollup.CBT.config.js",
25
26
  "build:dev": "cross-env ENVIRONMENT=dev BUILD=iife rollup --config rollup.config.js",
26
27
  "build:iife": "cross-env ENVIRONMENT=prod BUILD=iife rollup --config rollup.config.js",
27
28
  "build:npm": "cross-env ENVIRONMENT=prod BUILD=cjs rollup --config rollup.config.js",
28
29
  "build:esm": "cross-env ENVIRONMENT=prod BUILD=esm rollup --config rollup.config.js",
29
30
  "build:stub": "cross-env ENVIRONMENT=prod BUILD=stub rollup --config rollup.config.js",
30
31
  "build:snippet": "uglifyjs snippet.js -m -o snippet.min.js",
32
+ "build:tests": "cross-env ENVIRONMENT=prod TESTTYPE=main rollup --config rollup.test.config.js",
31
33
  "build:test-bundle": "cross-env TESTTYPE=main ENVIRONMENT=prod rollup --config rollup.test.config.js",
32
34
  "build:browserify:cjs": "browserify test/integrations/cjs/browserify/index.js -o test/integrations/cjs/dist/browserify-output.js",
33
35
  "build:rollup:cjs": "rollup --config test/integrations/cjs/rollup/rollup.config.js",
34
36
  "build:webpack:cjs": "webpack --config test/integrations/cjs/webpack/webpack.config.js",
35
37
  "build:rollup:module": "rollup --config test/integrations/module/rollup/rollup.config.js",
36
38
  "build:webpack:module": "webpack --config test/integrations/module/webpack/webpack.config.js",
39
+ "build:rollup:requirejs": "rollup --config test/integrations/requirejs/rollup.requirejs.config.js",
37
40
  "build:ts": "tsc -p .",
38
41
  "test": "npm run build && npm run build:test-bundle && cross-env DEBUG=false karma start test/karma.config.js",
42
+ "test:browserstack": "karma start test/cross-browser-testing/browserstack.karma.config.js",
43
+ "test:browserstack:debug": "cross-env DEBUG=true karma start test/cross-browser-testing/browserstack.karma.config.js",
39
44
  "test:debug": "cross-env DEBUG=true karma start test/karma.config.js",
40
45
  "test:stub": "cross-env TESTTYPE=stub ENVIRONMENT=prod rollup --config rollup.test.config.js && karma start test/stub/karma.stub.config.js",
41
46
  "test:integrations": "npm run test:requirejs && npm run test:integrations:cjs && npm run test:integrations:module",
@@ -46,7 +51,7 @@
46
51
  "test:integrations:module": "npm run test:integrations:module:webpack && npm run test:integrations:module:rollup",
47
52
  "test:integrations:module:webpack": "npm run build:webpack:module && npm run test:karma:webpack:module",
48
53
  "test:integrations:module:rollup": "npm run build:rollup:module && npm run test:karma:rollup:module",
49
- "test:requirejs": "npm run build && npm run test:requirejs:before && npm run test:requirejs:after",
54
+ "test:requirejs": "npm run build:iife && npm run build:rollup:requirejs && npm run test:requirejs:before && npm run test:requirejs:after",
50
55
  "test:requirejs:before": "cross-env FILE_ORDER=before_mp karma start test/integrations/requirejs/karma.requirejs.config.js",
51
56
  "test:requirejs:after": "cross-env FILE_ORDER=after_mp karma start test/integrations/requirejs/karma.requirejs.config.js",
52
57
  "test:karma:webpack:cjs": "cross-env BUNDLER=webpack karma start test/integrations/cjs/karma.webpack.config.js",
@@ -101,15 +106,17 @@
101
106
  "browser-sync": "^2.26.3",
102
107
  "browserify": "^17.0.0",
103
108
  "chai": "^4.2.0",
109
+ "core-js": "^3.33.0",
104
110
  "cross-env": "^7.0.3",
105
111
  "eslint": "^8.36.0",
106
112
  "eslint-config-prettier": "9.0.0",
107
113
  "eslint-plugin-prettier": "3.4.1",
108
- "fetch-mock": "^7.5.1",
114
+ "fetch-mock": "^9.1.1",
109
115
  "gts": "^5.0.1",
110
116
  "jest": "^29.5.0",
111
117
  "jest-environment-jsdom": "^29.5.0",
112
118
  "karma": "^6.3.2",
119
+ "karma-browserstack-launcher": "^1.6.0",
113
120
  "karma-chai": "^0.1.0",
114
121
  "karma-chrome-launcher": "^3.1.0",
115
122
  "karma-edge-launcher": "^0.4.1",
@@ -125,7 +132,7 @@
125
132
  "rollup": "^2.75.7",
126
133
  "shelljs": "^0.8.4",
127
134
  "should": "^7.1.0",
128
- "sinon": "^11.0.0",
135
+ "sinon": "^16.1.3",
129
136
  "ts-jest": "^29.1.0",
130
137
  "tslib": "^2.1.0",
131
138
  "typescript": "^5.0.2",
@@ -134,6 +141,6 @@
134
141
  "webpack-cli": "^5.0.2"
135
142
  },
136
143
  "dependencies": {
137
- "@babel/runtime": "^7.6.0"
144
+ "@babel/runtime": "^7.23.2"
138
145
  }
139
146
  }
package/src/apiClient.ts CHANGED
@@ -1,15 +1,11 @@
1
1
  import Constants from './constants';
2
2
  import Types from './types';
3
3
  import { BatchUploader } from './batchUploader';
4
- import {
5
- MParticleUser,
6
- MParticleWebSDK,
7
- MPForwarder,
8
- SDKEvent,
9
- } from './sdkRuntimeModels';
4
+ import { MParticleUser, MParticleWebSDK, SDKEvent } from './sdkRuntimeModels';
10
5
  import KitBlocker from './kitBlocking';
11
- import { Dictionary, getRampNumber, isEmpty } from './utils';
6
+ import { Dictionary, isEmpty } from './utils';
12
7
  import { IUploadObject } from './serverModel';
8
+ import { MPForwarder } from './forwarders.interfaces';
13
9
 
14
10
  export type ForwardingStatsData = Dictionary<any>;
15
11
 
@@ -49,6 +45,7 @@ export default function APIClient(
49
45
  }
50
46
  this.uploader.queueEvent(event);
51
47
 
48
+ // https://go.mparticle.com/work/SQDSDKS-6038
52
49
  mpInstance._Persistence.update();
53
50
  };
54
51
 
@@ -120,6 +117,7 @@ export default function APIClient(
120
117
  return;
121
118
  }
122
119
 
120
+ // https://go.mparticle.com/work/SQDSDKS-6038
123
121
  if (options.shouldUploadEvent) {
124
122
  this.queueEventForBatchUpload(event);
125
123
  }
package/src/constants.ts CHANGED
@@ -146,6 +146,8 @@ const Constants = {
146
146
  ia: 1,
147
147
  con: 1,
148
148
  },
149
+
150
+ // https://go.mparticle.com/work/SQDSDKS-6039
149
151
  SDKv2NonMPIDCookieKeys: {
150
152
  gs: 1,
151
153
  cu: 1,
@@ -169,6 +171,12 @@ const Constants = {
169
171
  },
170
172
  DefaultInstance: 'default_instance',
171
173
  CCPAPurpose: 'data_sale_opt_out',
174
+ IdentityMethods: {
175
+ Modify: 'modify',
176
+ Logout: 'logout',
177
+ Login: 'login',
178
+ Identify: 'identify',
179
+ },
172
180
  } as const;
173
181
 
174
182
  export default Constants;
package/src/events.js CHANGED
@@ -349,6 +349,8 @@ export default function Events(mpInstance) {
349
349
  }
350
350
 
351
351
  mpInstance._APIClient.sendEventToServer(commerceEvent, options);
352
+
353
+ // https://go.mparticle.com/work/SQDSDKS-6038
352
354
  mpInstance._Persistence.update();
353
355
  } else {
354
356
  mpInstance.Logger.verbose(
@@ -1,9 +1,18 @@
1
- import { MParticleUser, SDKEvent, SDKEventCustomFlags, SDKUserIdentity } from './sdkRuntimeModels';
1
+ import {
2
+ MParticleUser,
3
+ SDKEvent,
4
+ SDKEventCustomFlags,
5
+ SDKUserIdentity,
6
+ } from './sdkRuntimeModels';
2
7
  import { Dictionary } from './utils';
3
8
  import { IKitConfigs } from './configAPIClient';
4
9
  import { UserAttributes } from './persistence.interfaces';
5
10
  import { IdentityApiData } from '@mparticle/web-sdk';
6
11
 
12
+ // TODO: https://go.mparticle.com/work/SQDSDKS-6035
13
+ export type Kit = Dictionary;
14
+ export type MPForwarder = Dictionary;
15
+
7
16
  // The state of the kit when accessed via window.KitName via CDN
8
17
  // or imported as an NPM package
9
18
  export interface UnregisteredKit {
@@ -32,11 +41,24 @@ export interface ConfiguredKit
32
41
  appVersion: string,
33
42
  appName: string,
34
43
  customFlags: SDKEventCustomFlags,
35
- clientId: string): string;
36
- onIdentifyComplete(user: MParticleUser, filteredIdentityRequest: IdentityApiData): string | KitMappedMethodFailure;
37
- onLoginComplete(user: MParticleUser, filteredIdentityRequest: IdentityApiData): string | KitMappedMethodFailure;
38
- onLogoutComplete(user: MParticleUser, filteredIdentityRequest: IdentityApiData): string | KitMappedMethodFailure;
39
- onModifyComplete(user: MParticleUser, filteredIdentityRequest: IdentityApiData): string | KitMappedMethodFailure;
44
+ clientId: string
45
+ ): string;
46
+ onIdentifyComplete(
47
+ user: MParticleUser,
48
+ filteredIdentityRequest: IdentityApiData
49
+ ): string | KitMappedMethodFailure;
50
+ onLoginComplete(
51
+ user: MParticleUser,
52
+ filteredIdentityRequest: IdentityApiData
53
+ ): string | KitMappedMethodFailure;
54
+ onLogoutComplete(
55
+ user: MParticleUser,
56
+ filteredIdentityRequest: IdentityApiData
57
+ ): string | KitMappedMethodFailure;
58
+ onModifyComplete(
59
+ user: MParticleUser,
60
+ filteredIdentityRequest: IdentityApiData
61
+ ): string | KitMappedMethodFailure;
40
62
  onUserIdentified(user: MParticleUser): string | KitMappedMethodFailure;
41
63
  process(event: SDKEvent): string;
42
64
  setOptOut(isOptingOut: boolean): string | KitMappedMethodFailure;
package/src/forwarders.js CHANGED
@@ -2,6 +2,9 @@ import Types from './types';
2
2
  import filteredMparticleUser from './filteredMparticleUser';
3
3
  import { isEmpty } from './utils';
4
4
  import KitFilterHelper from './kitFilterHelper';
5
+ import Constants from './constants';
6
+
7
+ const { Modify, Identify, Login, Logout } = Constants.IdentityMethods;
5
8
 
6
9
  export default function Forwarders(mpInstance, kitBlocker) {
7
10
  var self = this;
@@ -440,6 +443,7 @@ export default function Forwarders(mpInstance, kitBlocker) {
440
443
  });
441
444
  };
442
445
 
446
+ // TODO: https://go.mparticle.com/work/SQDSDKS-6036
443
447
  this.setForwarderUserIdentities = function(userIdentities) {
444
448
  mpInstance._Store.activeForwarders.forEach(function(forwarder) {
445
449
  var filteredUserIdentities = mpInstance._Helpers.filterUserIdentities(
@@ -487,30 +491,45 @@ export default function Forwarders(mpInstance, kitBlocker) {
487
491
  mpInstance,
488
492
  kitBlocker
489
493
  );
490
- if (identityMethod === 'identify') {
494
+
495
+ const filteredUserIdentities = filteredUser.getUserIdentities();
496
+
497
+ if (identityMethod === Identify) {
491
498
  if (forwarder.onIdentifyComplete) {
492
- result = forwarder.onIdentifyComplete(filteredUser);
499
+ result = forwarder.onIdentifyComplete(
500
+ filteredUser,
501
+ filteredUserIdentities
502
+ );
493
503
  if (result) {
494
504
  mpInstance.Logger.verbose(result);
495
505
  }
496
506
  }
497
- } else if (identityMethod === 'login') {
507
+ } else if (identityMethod === Login) {
498
508
  if (forwarder.onLoginComplete) {
499
- result = forwarder.onLoginComplete(filteredUser);
509
+ result = forwarder.onLoginComplete(
510
+ filteredUser,
511
+ filteredUserIdentities
512
+ );
500
513
  if (result) {
501
514
  mpInstance.Logger.verbose(result);
502
515
  }
503
516
  }
504
- } else if (identityMethod === 'logout') {
517
+ } else if (identityMethod === Logout) {
505
518
  if (forwarder.onLogoutComplete) {
506
- result = forwarder.onLogoutComplete(filteredUser);
519
+ result = forwarder.onLogoutComplete(
520
+ filteredUser,
521
+ filteredUserIdentities
522
+ );
507
523
  if (result) {
508
524
  mpInstance.Logger.verbose(result);
509
525
  }
510
526
  }
511
- } else if (identityMethod === 'modify') {
527
+ } else if (identityMethod === Modify) {
512
528
  if (forwarder.onModifyComplete) {
513
- result = forwarder.onModifyComplete(filteredUser);
529
+ result = forwarder.onModifyComplete(
530
+ filteredUser,
531
+ filteredUserIdentities
532
+ );
514
533
  if (result) {
515
534
  mpInstance.Logger.verbose(result);
516
535
  }