@mparticle/web-sdk 2.21.0 → 2.21.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.js CHANGED
@@ -1,7 +1,7 @@
1
1
  var mParticle = (function () {
2
2
 
3
3
  // Base64 encoder/decoder - http://www.webtoolkit.info/javascript_base64.html
4
- var Base64$2 = {
4
+ var Base64$1 = {
5
5
  _keyStr: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',
6
6
  // Input must be a string
7
7
  encode: function encode(input) {
@@ -32,7 +32,7 @@ var mParticle = (function () {
32
32
  } else if (isNaN(chr3)) {
33
33
  enc4 = 64;
34
34
  }
35
- output = output + Base64$2._keyStr.charAt(enc1) + Base64$2._keyStr.charAt(enc2) + Base64$2._keyStr.charAt(enc3) + Base64$2._keyStr.charAt(enc4);
35
+ output = output + Base64$1._keyStr.charAt(enc1) + Base64$1._keyStr.charAt(enc2) + Base64$1._keyStr.charAt(enc3) + Base64$1._keyStr.charAt(enc4);
36
36
  }
37
37
  return output;
38
38
  },
@@ -44,7 +44,7 @@ var mParticle = (function () {
44
44
  } catch (e) {
45
45
  //log(e);
46
46
  }
47
- return Base64$2._decode(input);
47
+ return Base64$1._decode(input);
48
48
  },
49
49
  _decode: function _decode(input) {
50
50
  var output = '';
@@ -53,10 +53,10 @@ var mParticle = (function () {
53
53
  var i = 0;
54
54
  input = input.replace(/[^A-Za-z0-9\+\/\=]/g, '');
55
55
  while (i < input.length) {
56
- enc1 = Base64$2._keyStr.indexOf(input.charAt(i++));
57
- enc2 = Base64$2._keyStr.indexOf(input.charAt(i++));
58
- enc3 = Base64$2._keyStr.indexOf(input.charAt(i++));
59
- enc4 = Base64$2._keyStr.indexOf(input.charAt(i++));
56
+ enc1 = Base64$1._keyStr.indexOf(input.charAt(i++));
57
+ enc2 = Base64$1._keyStr.indexOf(input.charAt(i++));
58
+ enc3 = Base64$1._keyStr.indexOf(input.charAt(i++));
59
+ enc4 = Base64$1._keyStr.indexOf(input.charAt(i++));
60
60
  chr1 = enc1 << 2 | enc2 >> 4;
61
61
  chr2 = (enc2 & 15) << 4 | enc3 >> 2;
62
62
  chr3 = (enc3 & 3) << 6 | enc4;
@@ -200,7 +200,7 @@ var mParticle = (function () {
200
200
  isArray: function isArray(arg) {
201
201
  return Object.prototype.toString.call(arg) === '[object Array]';
202
202
  },
203
- Base64: Base64$2
203
+ Base64: Base64$1
204
204
  };
205
205
 
206
206
  function _defineProperty(obj, key, value) {
@@ -582,7 +582,7 @@ var mParticle = (function () {
582
582
  Environment: Environment
583
583
  };
584
584
 
585
- var version = "2.21.0";
585
+ var version = "2.21.1";
586
586
 
587
587
  var Constants = {
588
588
  sdkVersion: version,
@@ -1167,6 +1167,12 @@ var mParticle = (function () {
1167
1167
 
1168
1168
  var slugify = slugify$1.exports;
1169
1169
 
1170
+ var createCookieString = function createCookieString(value) {
1171
+ return replaceCommasWithPipes(replaceQuotesWithApostrophes(value));
1172
+ };
1173
+ var revertCookieString = function revertCookieString(value) {
1174
+ return replacePipesWithCommas(replaceApostrophesWithQuotes(value));
1175
+ };
1170
1176
  var inArray = function inArray(items, name) {
1171
1177
  var i = 0;
1172
1178
  if (Array.prototype.indexOf) {
@@ -1274,6 +1280,18 @@ var mParticle = (function () {
1274
1280
  return null;
1275
1281
  }
1276
1282
  };
1283
+ var replaceCommasWithPipes = function replaceCommasWithPipes(value) {
1284
+ return value.replace(/,/g, '|');
1285
+ };
1286
+ var replacePipesWithCommas = function replacePipesWithCommas(value) {
1287
+ return value.replace(/\|/g, ',');
1288
+ };
1289
+ var replaceApostrophesWithQuotes = function replaceApostrophesWithQuotes(value) {
1290
+ return value.replace(/\'/g, '"');
1291
+ };
1292
+ var replaceQuotesWithApostrophes = function replaceQuotesWithApostrophes(value) {
1293
+ return value.replace(/\"/g, "'");
1294
+ };
1277
1295
  // FIXME: REFACTOR for V3
1278
1296
  // only used in store.js to sanitize server-side formatting of
1279
1297
  // booleans when checking for `isDevelopmentMode`
@@ -2640,7 +2658,7 @@ var mParticle = (function () {
2640
2658
  }
2641
2659
  };
2642
2660
 
2643
- var StorageNames$2 = Constants.StorageNames;
2661
+ var StorageNames$1 = Constants.StorageNames;
2644
2662
  function Helpers(mpInstance) {
2645
2663
  var self = this;
2646
2664
  this.canLog = function () {
@@ -2936,16 +2954,16 @@ var mParticle = (function () {
2936
2954
  };
2937
2955
  this.createMainStorageName = function (workspaceToken) {
2938
2956
  if (workspaceToken) {
2939
- return StorageNames$2.currentStorageName + '_' + workspaceToken;
2957
+ return StorageNames$1.currentStorageName + '_' + workspaceToken;
2940
2958
  } else {
2941
- return StorageNames$2.currentStorageName;
2959
+ return StorageNames$1.currentStorageName;
2942
2960
  }
2943
2961
  };
2944
2962
  this.createProductStorageName = function (workspaceToken) {
2945
2963
  if (workspaceToken) {
2946
- return StorageNames$2.currentStorageProductsName + '_' + workspaceToken;
2964
+ return StorageNames$1.currentStorageProductsName + '_' + workspaceToken;
2947
2965
  } else {
2948
- return StorageNames$2.currentStorageProductsName;
2966
+ return StorageNames$1.currentStorageProductsName;
2949
2967
  }
2950
2968
  };
2951
2969
 
@@ -3763,7 +3781,6 @@ var mParticle = (function () {
3763
3781
  clientId: null,
3764
3782
  deviceId: null,
3765
3783
  devToken: null,
3766
- migrationData: {},
3767
3784
  serverSettings: {},
3768
3785
  dateLastEventSent: null,
3769
3786
  sessionStartDate: null,
@@ -3778,7 +3795,6 @@ var mParticle = (function () {
3778
3795
  configurationLoaded: false,
3779
3796
  identityCallInFlight: false,
3780
3797
  SDKConfig: {},
3781
- migratingToIDSyncCookies: false,
3782
3798
  nonCurrentUserMPIDs: {},
3783
3799
  identifyCalled: false,
3784
3800
  isLoggedIn: false,
@@ -4013,11 +4029,11 @@ var mParticle = (function () {
4013
4029
  };
4014
4030
  }
4015
4031
 
4016
- var Base64$1 = Polyfill.Base64,
4032
+ var Base64 = Polyfill.Base64,
4017
4033
  Messages$4 = Constants.Messages,
4018
4034
  Base64CookieKeys = Constants.Base64CookieKeys,
4019
4035
  SDKv2NonMPIDCookieKeys = Constants.SDKv2NonMPIDCookieKeys,
4020
- StorageNames$1 = Constants.StorageNames;
4036
+ StorageNames = Constants.StorageNames;
4021
4037
  function _Persistence(mpInstance) {
4022
4038
  var self = this;
4023
4039
  this.useLocalStorage = function () {
@@ -4078,7 +4094,7 @@ var mParticle = (function () {
4078
4094
  if (mpInstance._Store.isLocalStorageAvailable) {
4079
4095
  var encodedProducts = localStorage.getItem(mpInstance._Store.prodStorageName);
4080
4096
  if (encodedProducts) {
4081
- var decodedProducts = JSON.parse(Base64$1.decode(encodedProducts));
4097
+ var decodedProducts = JSON.parse(Base64.decode(encodedProducts));
4082
4098
  }
4083
4099
  if (mpInstance._Store.mpid) {
4084
4100
  self.storeProductsInMemory(decodedProducts, mpInstance._Store.mpid);
@@ -4192,7 +4208,7 @@ var mParticle = (function () {
4192
4208
  parsedProducts,
4193
4209
  encodedProducts = localStorage.getItem(mpInstance._Store.prodStorageName);
4194
4210
  if (encodedProducts) {
4195
- decodedProducts = Base64$1.decode(encodedProducts);
4211
+ decodedProducts = Base64.decode(encodedProducts);
4196
4212
  }
4197
4213
  // if there is an MPID, we are retrieving the user's products, which is an array
4198
4214
  if (mpid) {
@@ -4218,7 +4234,7 @@ var mParticle = (function () {
4218
4234
  encodedProducts = localStorage.getItem(mpInstance._Store.prodStorageName),
4219
4235
  parsedDecodedProducts;
4220
4236
  if (encodedProducts) {
4221
- decodedProducts = Base64$1.decode(encodedProducts);
4237
+ decodedProducts = Base64.decode(encodedProducts);
4222
4238
  }
4223
4239
  // returns an object with keys of MPID and values of array of products
4224
4240
  try {
@@ -4244,7 +4260,7 @@ var mParticle = (function () {
4244
4260
  allLocalStorageProducts = allLocalStorageProducts || {};
4245
4261
  allLocalStorageProducts[mpid] = currentUserProducts;
4246
4262
  try {
4247
- window.localStorage.setItem(encodeURIComponent(mpInstance._Store.prodStorageName), Base64$1.encode(JSON.stringify(allLocalStorageProducts)));
4263
+ window.localStorage.setItem(encodeURIComponent(mpInstance._Store.prodStorageName), Base64.encode(JSON.stringify(allLocalStorageProducts)));
4248
4264
  } catch (e) {
4249
4265
  mpInstance.Logger.error('Error with setting products on localStorage.');
4250
4266
  }
@@ -4502,7 +4518,7 @@ var mParticle = (function () {
4502
4518
  if (persistence.gs[key]) {
4503
4519
  // base64 encode any value that is an object or Array in globalSettings
4504
4520
  if (Array.isArray(persistence.gs[key]) && persistence.gs[key].length || mpInstance._Helpers.isObject(persistence.gs[key]) && Object.keys(persistence.gs[key]).length) {
4505
- persistence.gs[key] = Base64$1.encode(JSON.stringify(persistence.gs[key]));
4521
+ persistence.gs[key] = Base64.encode(JSON.stringify(persistence.gs[key]));
4506
4522
  } else {
4507
4523
  delete persistence.gs[key];
4508
4524
  }
@@ -4523,7 +4539,7 @@ var mParticle = (function () {
4523
4539
  if (persistence[mpid].hasOwnProperty(key)) {
4524
4540
  if (Base64CookieKeys[key]) {
4525
4541
  if (mpInstance._Helpers.isObject(persistence[mpid][key]) && Object.keys(persistence[mpid][key]).length) {
4526
- persistence[mpid][key] = Base64$1.encode(JSON.stringify(persistence[mpid][key]));
4542
+ persistence[mpid][key] = Base64.encode(JSON.stringify(persistence[mpid][key]));
4527
4543
  } else {
4528
4544
  delete persistence[mpid][key];
4529
4545
  }
@@ -4533,17 +4549,20 @@ var mParticle = (function () {
4533
4549
  }
4534
4550
  }
4535
4551
  }
4536
- return self.createCookieString(JSON.stringify(persistence));
4552
+ return createCookieString(JSON.stringify(persistence));
4537
4553
  };
4554
+
4555
+ // TODO: This should actually be decodePersistenceString or
4556
+ // we should refactor this to take a string and return an object
4538
4557
  this.decodePersistence = function (persistence) {
4539
4558
  try {
4540
4559
  if (persistence) {
4541
- persistence = JSON.parse(self.revertCookieString(persistence));
4560
+ persistence = JSON.parse(revertCookieString(persistence));
4542
4561
  if (mpInstance._Helpers.isObject(persistence) && Object.keys(persistence).length) {
4543
4562
  for (var key in persistence.gs) {
4544
4563
  if (persistence.gs.hasOwnProperty(key)) {
4545
4564
  if (Base64CookieKeys[key]) {
4546
- persistence.gs[key] = JSON.parse(Base64$1.decode(persistence.gs[key]));
4565
+ persistence.gs[key] = JSON.parse(Base64.decode(persistence.gs[key]));
4547
4566
  } else if (key === 'ie') {
4548
4567
  persistence.gs[key] = Boolean(persistence.gs[key]);
4549
4568
  }
@@ -4556,7 +4575,7 @@ var mParticle = (function () {
4556
4575
  if (persistence[mpid].hasOwnProperty(key)) {
4557
4576
  if (Base64CookieKeys[key]) {
4558
4577
  if (persistence[mpid][key].length) {
4559
- persistence[mpid][key] = JSON.parse(Base64$1.decode(persistence[mpid][key]));
4578
+ persistence[mpid][key] = JSON.parse(Base64.decode(persistence[mpid][key]));
4560
4579
  }
4561
4580
  }
4562
4581
  }
@@ -4573,24 +4592,6 @@ var mParticle = (function () {
4573
4592
  mpInstance.Logger.error('Problem with decoding cookie', e);
4574
4593
  }
4575
4594
  };
4576
- this.replaceCommasWithPipes = function (string) {
4577
- return string.replace(/,/g, '|');
4578
- };
4579
- this.replacePipesWithCommas = function (string) {
4580
- return string.replace(/\|/g, ',');
4581
- };
4582
- this.replaceApostrophesWithQuotes = function (string) {
4583
- return string.replace(/\'/g, '"');
4584
- };
4585
- this.replaceQuotesWithApostrophes = function (string) {
4586
- return string.replace(/\"/g, "'");
4587
- };
4588
- this.createCookieString = function (string) {
4589
- return self.replaceCommasWithPipes(self.replaceQuotesWithApostrophes(string));
4590
- };
4591
- this.revertCookieString = function (string) {
4592
- return self.replacePipesWithCommas(self.replaceApostrophesWithQuotes(string));
4593
- };
4594
4595
  this.getCookieDomain = function () {
4595
4596
  if (mpInstance._Store.SDKConfig.cookieDomain) {
4596
4597
  return mpInstance._Store.SDKConfig.cookieDomain;
@@ -4644,7 +4645,7 @@ var mParticle = (function () {
4644
4645
  var allCartProducts,
4645
4646
  cartProductsString = localStorage.getItem(mpInstance._Store.prodStorageName);
4646
4647
  if (cartProductsString) {
4647
- allCartProducts = JSON.parse(Base64$1.decode(cartProductsString));
4648
+ allCartProducts = JSON.parse(Base64.decode(cartProductsString));
4648
4649
  if (allCartProducts && allCartProducts[mpid] && allCartProducts[mpid].cp) {
4649
4650
  return allCartProducts[mpid].cp;
4650
4651
  }
@@ -4656,7 +4657,7 @@ var mParticle = (function () {
4656
4657
  return;
4657
4658
  }
4658
4659
  try {
4659
- window.localStorage.setItem(encodeURIComponent(mpInstance._Store.prodStorageName), Base64$1.encode(JSON.stringify(allProducts)));
4660
+ window.localStorage.setItem(encodeURIComponent(mpInstance._Store.prodStorageName), Base64.encode(JSON.stringify(allProducts)));
4660
4661
  } catch (e) {
4661
4662
  mpInstance.Logger.error('Error with setting products on localStorage.');
4662
4663
  }
@@ -4835,16 +4836,16 @@ var mParticle = (function () {
4835
4836
  self.update();
4836
4837
  };
4837
4838
  this.resetPersistence = function () {
4838
- removeLocalStorage(StorageNames$1.localStorageName);
4839
- removeLocalStorage(StorageNames$1.localStorageNameV3);
4840
- removeLocalStorage(StorageNames$1.localStorageNameV4);
4839
+ removeLocalStorage(StorageNames.localStorageName);
4840
+ removeLocalStorage(StorageNames.localStorageNameV3);
4841
+ removeLocalStorage(StorageNames.localStorageNameV4);
4841
4842
  removeLocalStorage(mpInstance._Store.prodStorageName);
4842
4843
  removeLocalStorage(mpInstance._Store.storageName);
4843
- removeLocalStorage(StorageNames$1.localStorageProductsV4);
4844
- self.expireCookies(StorageNames$1.cookieName);
4845
- self.expireCookies(StorageNames$1.cookieNameV2);
4846
- self.expireCookies(StorageNames$1.cookieNameV3);
4847
- self.expireCookies(StorageNames$1.cookieNameV4);
4844
+ removeLocalStorage(StorageNames.localStorageProductsV4);
4845
+ self.expireCookies(StorageNames.cookieName);
4846
+ self.expireCookies(StorageNames.cookieNameV2);
4847
+ self.expireCookies(StorageNames.cookieNameV3);
4848
+ self.expireCookies(StorageNames.cookieNameV4);
4848
4849
  self.expireCookies(mpInstance._Store.prodStorageName);
4849
4850
  self.expireCookies(mpInstance._Store.storageName);
4850
4851
  if (mParticle._isTestEnv) {
@@ -5130,208 +5131,6 @@ var mParticle = (function () {
5130
5131
  };
5131
5132
  }
5132
5133
 
5133
- var StorageNames = Constants.StorageNames,
5134
- Base64 = Polyfill.Base64,
5135
- CookiesGlobalSettingsKeys = {
5136
- das: 1
5137
- },
5138
- MPIDKeys = {
5139
- ui: 1
5140
- };
5141
- function Migrations(mpInstance) {
5142
- var self = this;
5143
- // if there is a cookie or localStorage:
5144
- // 1. determine which version it is ('mprtcl-api', 'mprtcl-v2', 'mprtcl-v3', 'mprtcl-v4')
5145
- // 2. return if 'mprtcl-v4', otherwise migrate to mprtclv4 schema
5146
- // 3. if 'mprtcl-api', could be JSSDKv2 or JSSDKv1. JSSDKv2 cookie has a 'globalSettings' key on it
5147
- this.migrate = function () {
5148
- try {
5149
- migrateCookies();
5150
- } catch (e) {
5151
- mpInstance._Persistence.expireCookies(StorageNames.cookieNameV3);
5152
- mpInstance._Persistence.expireCookies(StorageNames.cookieNameV4);
5153
- mpInstance.Logger.error('Error migrating cookie: ' + e);
5154
- }
5155
- if (mpInstance._Store.isLocalStorageAvailable) {
5156
- try {
5157
- migrateLocalStorage();
5158
- } catch (e) {
5159
- localStorage.removeItem(StorageNames.localStorageNameV3);
5160
- localStorage.removeItem(StorageNames.localStorageNameV4);
5161
- mpInstance.Logger.error('Error migrating localStorage: ' + e);
5162
- }
5163
- }
5164
- };
5165
- function migrateCookies() {
5166
- var cookies = window.document.cookie.split('; '),
5167
- foundCookie,
5168
- i,
5169
- l,
5170
- parts,
5171
- name,
5172
- cookie;
5173
- mpInstance.Logger.verbose(Constants.Messages.InformationMessages.CookieSearch);
5174
- for (i = 0, l = cookies.length; i < l; i++) {
5175
- try {
5176
- parts = cookies[i].split('=');
5177
- name = mpInstance._Helpers.decoded(parts.shift());
5178
- cookie = mpInstance._Helpers.decoded(parts.join('='));
5179
- } catch (e) {
5180
- mpInstance.Logger.verbose('Unable to parse cookie: ' + name + '. Skipping.');
5181
- }
5182
-
5183
- //most recent version needs no migration
5184
- if (name === mpInstance._Store.storageName) {
5185
- return;
5186
- }
5187
- if (name === StorageNames.cookieNameV4) {
5188
- // adds cookies to new namespace, removes previous cookie
5189
- finishCookieMigration(cookie, StorageNames.cookieNameV4);
5190
- if (mpInstance._Store.isLocalStorageAvailable) {
5191
- migrateProductsToNameSpace();
5192
- }
5193
- return;
5194
- // migration path for SDKv1CookiesV3, doesn't need to be encoded
5195
- }
5196
-
5197
- if (name === StorageNames.cookieNameV3) {
5198
- foundCookie = self.convertSDKv1CookiesV3ToSDKv2CookiesV4(cookie);
5199
- finishCookieMigration(foundCookie, StorageNames.cookieNameV3);
5200
- break;
5201
- }
5202
- }
5203
- }
5204
- function finishCookieMigration(cookie, cookieName) {
5205
- var date = new Date(),
5206
- cookieDomain = mpInstance._Persistence.getCookieDomain(),
5207
- expires,
5208
- domain;
5209
- expires = new Date(date.getTime() + StorageNames.CookieExpiration * 24 * 60 * 60 * 1000).toGMTString();
5210
- if (cookieDomain === '') {
5211
- domain = '';
5212
- } else {
5213
- domain = ';domain=' + cookieDomain;
5214
- }
5215
- mpInstance.Logger.verbose(Constants.Messages.InformationMessages.CookieSet);
5216
- window.document.cookie = encodeURIComponent(mpInstance._Store.storageName) + '=' + cookie + ';expires=' + expires + ';path=/' + domain;
5217
- mpInstance._Persistence.expireCookies(cookieName);
5218
- mpInstance._Store.migratingToIDSyncCookies = true;
5219
- }
5220
- this.convertSDKv1CookiesV3ToSDKv2CookiesV4 = function (SDKv1CookiesV3) {
5221
- SDKv1CookiesV3 = mpInstance._Persistence.replacePipesWithCommas(mpInstance._Persistence.replaceApostrophesWithQuotes(SDKv1CookiesV3));
5222
- var parsedSDKv1CookiesV3 = JSON.parse(SDKv1CookiesV3);
5223
- var parsedCookiesV4 = JSON.parse(restructureToV4Cookie(SDKv1CookiesV3));
5224
- if (parsedSDKv1CookiesV3.mpid) {
5225
- parsedCookiesV4.gs.csm.push(parsedSDKv1CookiesV3.mpid);
5226
- // all other values are already encoded, so we have to encode any new values
5227
- parsedCookiesV4.gs.csm = Base64.encode(JSON.stringify(parsedCookiesV4.gs.csm));
5228
- migrateProductsFromSDKv1ToSDKv2CookiesV4(parsedSDKv1CookiesV3, parsedSDKv1CookiesV3.mpid);
5229
- }
5230
- return JSON.stringify(parsedCookiesV4);
5231
- };
5232
- function restructureToV4Cookie(cookies) {
5233
- try {
5234
- var cookiesV4Schema = {
5235
- gs: {
5236
- csm: []
5237
- }
5238
- };
5239
- cookies = JSON.parse(cookies);
5240
- for (var key in cookies) {
5241
- if (cookies.hasOwnProperty(key)) {
5242
- if (CookiesGlobalSettingsKeys[key]) {
5243
- cookiesV4Schema.gs[key] = cookies[key];
5244
- } else if (key === 'mpid') {
5245
- cookiesV4Schema.cu = cookies[key];
5246
- } else if (cookies.mpid) {
5247
- cookiesV4Schema[cookies.mpid] = cookiesV4Schema[cookies.mpid] || {};
5248
- if (MPIDKeys[key]) {
5249
- cookiesV4Schema[cookies.mpid][key] = cookies[key];
5250
- }
5251
- }
5252
- }
5253
- }
5254
- return JSON.stringify(cookiesV4Schema);
5255
- } catch (e) {
5256
- mpInstance.Logger.error('Failed to restructure previous cookie into most current cookie schema');
5257
- }
5258
- }
5259
- function migrateProductsToNameSpace() {
5260
- var lsProdV4Name = StorageNames.localStorageProductsV4;
5261
- var products = localStorage.getItem(StorageNames.localStorageProductsV4);
5262
- localStorage.setItem(mpInstance._Store.prodStorageName, products);
5263
- localStorage.removeItem(lsProdV4Name);
5264
- }
5265
- function migrateProductsFromSDKv1ToSDKv2CookiesV4(cookies, mpid) {
5266
- if (!mpInstance._Store.isLocalStorageAvailable) {
5267
- return;
5268
- }
5269
- var localStorageProducts = {};
5270
- localStorageProducts[mpid] = {};
5271
- if (cookies.cp) {
5272
- try {
5273
- localStorageProducts[mpid].cp = JSON.parse(Base64.decode(cookies.cp));
5274
- } catch (e) {
5275
- localStorageProducts[mpid].cp = cookies.cp;
5276
- }
5277
- if (!Array.isArray(localStorageProducts[mpid].cp)) {
5278
- localStorageProducts[mpid].cp = [];
5279
- }
5280
- }
5281
- localStorage.setItem(mpInstance._Store.prodStorageName, Base64.encode(JSON.stringify(localStorageProducts)));
5282
- }
5283
- function migrateLocalStorage() {
5284
- var cookies,
5285
- v3LSName = StorageNames.localStorageNameV3,
5286
- v4LSName = StorageNames.localStorageNameV4,
5287
- currentVersionLSData = window.localStorage.getItem(mpInstance._Store.storageName),
5288
- v4LSData,
5289
- v3LSData,
5290
- v3LSDataStringCopy;
5291
- if (currentVersionLSData) {
5292
- return;
5293
- }
5294
- v4LSData = window.localStorage.getItem(v4LSName);
5295
- if (v4LSData) {
5296
- finishLSMigration(v4LSData, v4LSName);
5297
- migrateProductsToNameSpace();
5298
- return;
5299
- }
5300
- v3LSData = window.localStorage.getItem(v3LSName);
5301
- if (v3LSData) {
5302
- mpInstance._Store.migratingToIDSyncCookies = true;
5303
- v3LSDataStringCopy = v3LSData.slice();
5304
- v3LSData = JSON.parse(mpInstance._Persistence.replacePipesWithCommas(mpInstance._Persistence.replaceApostrophesWithQuotes(v3LSData)));
5305
- // localStorage may contain only products, or the full persistence
5306
- // when there is an MPID on the cookie, it is the full persistence
5307
- if (v3LSData.mpid) {
5308
- v3LSData = JSON.parse(self.convertSDKv1CookiesV3ToSDKv2CookiesV4(v3LSDataStringCopy));
5309
- finishLSMigration(JSON.stringify(v3LSData), v3LSName);
5310
- return;
5311
- // if no MPID, it is only the products
5312
- } else if ((v3LSData.cp || v3LSData.pb) && !v3LSData.mpid) {
5313
- cookies = mpInstance._Persistence.getCookie();
5314
- if (cookies) {
5315
- migrateProductsFromSDKv1ToSDKv2CookiesV4(v3LSData, cookies.cu);
5316
- localStorage.removeItem(StorageNames.localStorageNameV3);
5317
- return;
5318
- } else {
5319
- localStorage.removeItem(StorageNames.localStorageNameV3);
5320
- return;
5321
- }
5322
- }
5323
- }
5324
- function finishLSMigration(data, lsName) {
5325
- try {
5326
- window.localStorage.setItem(encodeURIComponent(mpInstance._Store.storageName), data);
5327
- } catch (e) {
5328
- mpInstance.Logger.error('Error with setting localStorage item.');
5329
- }
5330
- window.localStorage.removeItem(encodeURIComponent(lsName));
5331
- }
5332
- }
5333
- }
5334
-
5335
5134
  function filteredMparticleUser(mpid, forwarder, mpInstance, kitBlocker) {
5336
5135
  var self = this;
5337
5136
  return {
@@ -7111,16 +6910,8 @@ var mParticle = (function () {
7111
6910
  }
7112
6911
  mpInstance._CookieSyncManager.attemptCookieSync(previousMPID, identityApiResult.mpid, mpidIsNotInCookies);
7113
6912
  self.checkIdentitySwap(previousMPID, identityApiResult.mpid, mpInstance._Store.currentSessionMPIDs);
7114
-
7115
- //if there is any previous migration data
7116
- if (Object.keys(mpInstance._Store.migrationData).length) {
7117
- newIdentitiesByType = mpInstance._Store.migrationData.userIdentities || {};
7118
- var userAttributes = mpInstance._Store.migrationData.userAttributes || {};
7119
- mpInstance._Persistence.saveUserAttributesToPersistence(identityApiResult.mpid, userAttributes);
7120
- } else {
7121
- if (identityApiData && identityApiData.userIdentities && Object.keys(identityApiData.userIdentities).length) {
7122
- newIdentitiesByType = self.IdentityRequest.combineUserIdentities(incomingMpidUIByName, identityApiData.userIdentities);
7123
- }
6913
+ if (identityApiData && identityApiData.userIdentities && Object.keys(identityApiData.userIdentities).length) {
6914
+ newIdentitiesByType = self.IdentityRequest.combineUserIdentities(incomingMpidUIByName, identityApiData.userIdentities);
7124
6915
  }
7125
6916
  mpInstance._Persistence.saveUserIdentitiesToPersistence(identityApiResult.mpid, newIdentitiesByType);
7126
6917
  mpInstance._Persistence.update();
@@ -8138,7 +7929,6 @@ var mParticle = (function () {
8138
7929
  // These classes are for internal use only. Not documented for public consumption
8139
7930
  this._instanceName = instanceName;
8140
7931
  this._NativeSdkHelpers = new NativeSdkHelpers(this);
8141
- this._Migrations = new Migrations(this);
8142
7932
  this._SessionManager = new SessionManager(this);
8143
7933
  this._Persistence = new _Persistence(this);
8144
7934
  this._Helpers = new Helpers(this);
@@ -9087,9 +8877,6 @@ var mParticle = (function () {
9087
8877
  mpInstance._Store.webviewBridgeEnabled = mpInstance._NativeSdkHelpers.isWebviewEnabled(mpInstance._Store.SDKConfig.requiredWebviewBridgeName, mpInstance._Store.SDKConfig.minWebviewBridgeVersion);
9088
8878
  mpInstance._Store.configurationLoaded = true;
9089
8879
  if (!mpInstance._Store.webviewBridgeEnabled) {
9090
- // Migrate any cookies from previous versions to current cookie version
9091
- mpInstance._Migrations.migrate();
9092
-
9093
8880
  // Load any settings/identities/attributes from cookie or localStorage
9094
8881
  mpInstance._Persistence.initializeStorage();
9095
8882
  }
@@ -9123,12 +8910,6 @@ var mParticle = (function () {
9123
8910
  userIdentities: modifiedUIforIdentityRequest
9124
8911
  };
9125
8912
  }
9126
-
9127
- // If migrating from pre-IDSync to IDSync, a sessionID will exist and an identify request will not have been fired, so we need this check
9128
- if (mpInstance._Store.migratingToIDSyncCookies) {
9129
- mpInstance.Identity.identify(mpInstance._Store.SDKConfig.identifyRequest, mpInstance._Store.SDKConfig.identityCallback);
9130
- mpInstance._Store.migratingToIDSyncCookies = false;
9131
- }
9132
8913
  currentUser = mpInstance.Identity.getCurrentUser();
9133
8914
  if (mpInstance._Helpers.getFeatureFlag(Constants.FeatureFlags.ReportBatching)) {
9134
8915
  mpInstance._ForwardingStatsUploader.startForwardingStatsTimer();
@@ -9243,7 +9024,9 @@ var mParticle = (function () {
9243
9024
  mpInstance._Store.devToken = apiKey || null;
9244
9025
  mpInstance.Logger.verbose(Messages.InformationMessages.StartingInitialization);
9245
9026
 
9246
- //check to see if localStorage is available for migrating purposes
9027
+ // Check to see if localStorage is available before main configuration runs
9028
+ // since we will need this for the current implementation of user persistence
9029
+ // TODO: Refactor this when we refactor User Identity Persistence
9247
9030
  try {
9248
9031
  mpInstance._Store.isLocalStorageAvailable = mpInstance._Persistence.determineLocalStorageAvailability(window.localStorage);
9249
9032
  } catch (e) {
@@ -9327,7 +9110,6 @@ var mParticle = (function () {
9327
9110
  consentState: null,
9328
9111
  clientId: null,
9329
9112
  deviceId: null,
9330
- migrationData: {},
9331
9113
  serverSettings: {},
9332
9114
  dateLastEventSent: null,
9333
9115
  sessionStartDate: null,
@@ -9341,7 +9123,6 @@ var mParticle = (function () {
9341
9123
  context: null,
9342
9124
  configurationLoaded: false,
9343
9125
  identityCallInFlight: false,
9344
- migratingToIDSyncCookies: false,
9345
9126
  nonCurrentUserMPIDs: {},
9346
9127
  identifyCalled: false,
9347
9128
  isLoggedIn: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mparticle/web-sdk",
3
- "version": "2.21.0",
3
+ "version": "2.21.1",
4
4
  "description": "mParticle core SDK for web applications",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
@@ -29,18 +29,23 @@
29
29
  "build:stub": "cross-env ENVIRONMENT=prod BUILD=stub rollup --config rollup.config.js",
30
30
  "build:snippet": "uglifyjs snippet.js -nm -o snippet.min.js",
31
31
  "build:test-bundle": "cross-env TESTTYPE=main ENVIRONMENT=prod rollup --config rollup.test.config.js",
32
- "build:browserify:cjs": "browserify test/integrations/cjs/browserify/index.js -o test/integrations/cjs/dist/browserify-output.js && npm run test:karma:browserify:cjs",
33
- "build:rollup:cjs": "rollup --config test/integrations/cjs/rollup/rollup.config.js && npm run test:karma:rollup:cjs",
34
- "build:webpack:cjs": "webpack --config test/integrations/cjs/webpack/webpack.config.js && npm run test:karma:webpack:cjs",
35
- "build:rollup:module": "rollup --config test/integrations/module/rollup/rollup.config.js && npm run test:karma:rollup:module",
36
- "build:webpack:module": "webpack --config test/integrations/module/webpack/webpack.config.js && npm run test:karma:webpack:module",
32
+ "build:browserify:cjs": "browserify test/integrations/cjs/browserify/index.js -o test/integrations/cjs/dist/browserify-output.js",
33
+ "build:rollup:cjs": "rollup --config test/integrations/cjs/rollup/rollup.config.js",
34
+ "build:webpack:cjs": "webpack --config test/integrations/cjs/webpack/webpack.config.js",
35
+ "build:rollup:module": "rollup --config test/integrations/module/rollup/rollup.config.js",
36
+ "build:webpack:module": "webpack --config test/integrations/module/webpack/webpack.config.js",
37
37
  "build:ts": "tsc -p .",
38
38
  "test": "npm run build && npm run build:test-bundle && cross-env DEBUG=false karma start test/karma.config.js",
39
39
  "test:debug": "cross-env DEBUG=true karma start test/karma.config.js",
40
40
  "test:stub": "cross-env TESTTYPE=stub ENVIRONMENT=prod rollup --config rollup.test.config.js && karma start test/stub/karma.stub.config.js",
41
41
  "test:integrations": "npm run test:requirejs && npm run test:integrations:cjs && npm run test:integrations:module",
42
- "test:integrations:cjs": "npm run build:browserify:cjs && npm run build:webpack:cjs && npm run build:rollup:cjs",
43
- "test:integrations:module": "npm run build:webpack:module && npm run build:rollup:module",
42
+ "test:integrations:cjs": "npm run test:integrations:cjs:browserfy && npm run test:integrations:cjs:webpack && npm run test:integrations:cjs:rollup",
43
+ "test:integrations:cjs:browserfy": "npm run build:browserify:cjs && npm run test:karma:browserify:cjs",
44
+ "test:integrations:cjs:webpack": "npm run build:webpack:cjs && npm run test:karma:webpack:cjs",
45
+ "test:integrations:cjs:rollup": "npm run build:rollup:cjs && npm run test:karma:rollup:cjs",
46
+ "test:integrations:module": "npm run test:integrations:module:webpack && npm run test:integrations:module:rollup",
47
+ "test:integrations:module:webpack": "npm run build:webpack:module && npm run test:karma:webpack:module",
48
+ "test:integrations:module:rollup": "npm run build:rollup:module && npm run test:karma:rollup:module",
44
49
  "test:requirejs": "npm run test:requirejs:before && npm run test:requirejs:after",
45
50
  "test:requirejs:before": "cross-env FILE_ORDER=before_mp karma start test/integrations/requirejs/karma.requirejs.config.js",
46
51
  "test:requirejs:after": "cross-env FILE_ORDER=after_mp karma start test/integrations/requirejs/karma.requirejs.config.js",
@@ -49,6 +54,8 @@
49
54
  "test:karma:rollup:cjs": "cross-env BUNDLER=rollup karma start test/integrations/cjs/karma.rollup.config.js",
50
55
  "test:karma:webpack:module": "cross-env BUNDLER=webpack karma start test/integrations/module/karma.webpack.config.js",
51
56
  "test:karma:rollup:module": "cross-env BUNDLER=rollup karma start test/integrations/module/karma.rollup.config.js",
57
+ "test:jest": "jest --config jest.config.js",
58
+ "test:jest:watch": "jest --config jest.config.js --watch",
52
59
  "watch": "cross-env ENVIRONMENT=dev BUILD=iife rollup --config rollup.config.js -w",
53
60
  "watch:all": "cross-env ENVIRONMENT=prod BUILDALL=true rollup --config rollup.config.js -w",
54
61
  "watch:tests": "cross-env ENVIRONMENT=dev TESTTYPE=main rollup --config rollup.test.config.js -w",
@@ -76,15 +83,17 @@
76
83
  "@babel/preset-typescript": "^7.6.0",
77
84
  "@mparticle/data-planning-models": "^0.1.0",
78
85
  "@mparticle/event-models": "^1.1.6",
79
- "@rollup/plugin-json": "^4.1.0",
80
- "@rollup/plugin-typescript": "^8.3.3",
81
86
  "@rollup/plugin-babel": "6.0.3",
82
87
  "@rollup/plugin-commonjs": "22.0.2",
88
+ "@rollup/plugin-json": "^4.1.0",
83
89
  "@rollup/plugin-node-resolve": "13.3.0",
90
+ "@rollup/plugin-typescript": "^8.3.3",
84
91
  "@semantic-release/changelog": "^5.0.1",
85
92
  "@semantic-release/exec": "^5.0.0",
86
93
  "@semantic-release/git": "^9.0.0",
87
94
  "@types/chai": "^4.2.3",
95
+ "@types/jest": "^29.5.1",
96
+ "@types/jest-expect-message": "^1.1.0",
88
97
  "@types/mocha": "^9.0.0",
89
98
  "@types/mparticle__web-sdk": "^2.16.1",
90
99
  "@types/node": "^18.7.11",
@@ -98,6 +107,7 @@
98
107
  "eslint-plugin-prettier": "3.4.1",
99
108
  "fetch-mock": "^7.5.1",
100
109
  "gts": "^3.1.0",
110
+ "jest": "^29.5.0",
101
111
  "karma": "^6.3.2",
102
112
  "karma-chai": "^0.1.0",
103
113
  "karma-chrome-launcher": "^3.1.0",
@@ -115,6 +125,7 @@
115
125
  "shelljs": "^0.8.4",
116
126
  "should": "^7.1.0",
117
127
  "sinon": "^11.0.0",
128
+ "ts-jest": "^29.1.0",
118
129
  "tslib": "^2.1.0",
119
130
  "typescript": "^5.0.2",
120
131
  "uglify-js": "^3.4.9",