@mparticle/web-sdk 2.14.2 → 2.15.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
@@ -719,7 +719,7 @@ var mParticle = (function () {
719
719
  TriggerUploadType: TriggerUploadType
720
720
  };
721
721
 
722
- var version = "2.14.2";
722
+ var version = "2.15.2";
723
723
 
724
724
  var Constants = {
725
725
  sdkVersion: version,
@@ -891,8 +891,6 @@ var mParticle = (function () {
891
891
  DefaultInstance: 'default_instance'
892
892
  };
893
893
 
894
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
895
-
896
894
  function unwrapExports (x) {
897
895
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
898
896
  }
@@ -3576,66 +3574,6 @@ var mParticle = (function () {
3576
3574
  };
3577
3575
  }
3578
3576
 
3579
- var slugify = createCommonjsModule(function (module, exports) {
3580
- (function (name, root, factory) {
3581
- {
3582
- module.exports = factory();
3583
- module.exports['default'] = factory();
3584
- }
3585
- }('slugify', commonjsGlobal, function () {
3586
- var charMap = JSON.parse('{"$":"dollar","%":"percent","&":"and","<":"less",">":"greater","|":"or","¢":"cent","£":"pound","¤":"currency","¥":"yen","©":"(c)","ª":"a","®":"(r)","º":"o","À":"A","Á":"A","Â":"A","Ã":"A","Ä":"A","Å":"A","Æ":"AE","Ç":"C","È":"E","É":"E","Ê":"E","Ë":"E","Ì":"I","Í":"I","Î":"I","Ï":"I","Ð":"D","Ñ":"N","Ò":"O","Ó":"O","Ô":"O","Õ":"O","Ö":"O","Ø":"O","Ù":"U","Ú":"U","Û":"U","Ü":"U","Ý":"Y","Þ":"TH","ß":"ss","à":"a","á":"a","â":"a","ã":"a","ä":"a","å":"a","æ":"ae","ç":"c","è":"e","é":"e","ê":"e","ë":"e","ì":"i","í":"i","î":"i","ï":"i","ð":"d","ñ":"n","ò":"o","ó":"o","ô":"o","õ":"o","ö":"o","ø":"o","ù":"u","ú":"u","û":"u","ü":"u","ý":"y","þ":"th","ÿ":"y","Ā":"A","ā":"a","Ă":"A","ă":"a","Ą":"A","ą":"a","Ć":"C","ć":"c","Č":"C","č":"c","Ď":"D","ď":"d","Đ":"DJ","đ":"dj","Ē":"E","ē":"e","Ė":"E","ė":"e","Ę":"e","ę":"e","Ě":"E","ě":"e","Ğ":"G","ğ":"g","Ģ":"G","ģ":"g","Ĩ":"I","ĩ":"i","Ī":"i","ī":"i","Į":"I","į":"i","İ":"I","ı":"i","Ķ":"k","ķ":"k","Ļ":"L","ļ":"l","Ľ":"L","ľ":"l","Ł":"L","ł":"l","Ń":"N","ń":"n","Ņ":"N","ņ":"n","Ň":"N","ň":"n","Ō":"O","ō":"o","Ő":"O","ő":"o","Œ":"OE","œ":"oe","Ŕ":"R","ŕ":"r","Ř":"R","ř":"r","Ś":"S","ś":"s","Ş":"S","ş":"s","Š":"S","š":"s","Ţ":"T","ţ":"t","Ť":"T","ť":"t","Ũ":"U","ũ":"u","Ū":"u","ū":"u","Ů":"U","ů":"u","Ű":"U","ű":"u","Ų":"U","ų":"u","Ŵ":"W","ŵ":"w","Ŷ":"Y","ŷ":"y","Ÿ":"Y","Ź":"Z","ź":"z","Ż":"Z","ż":"z","Ž":"Z","ž":"z","Ə":"E","ƒ":"f","Ơ":"O","ơ":"o","Ư":"U","ư":"u","Lj":"LJ","lj":"lj","Nj":"NJ","nj":"nj","Ș":"S","ș":"s","Ț":"T","ț":"t","ə":"e","˚":"o","Ά":"A","Έ":"E","Ή":"H","Ί":"I","Ό":"O","Ύ":"Y","Ώ":"W","ΐ":"i","Α":"A","Β":"B","Γ":"G","Δ":"D","Ε":"E","Ζ":"Z","Η":"H","Θ":"8","Ι":"I","Κ":"K","Λ":"L","Μ":"M","Ν":"N","Ξ":"3","Ο":"O","Π":"P","Ρ":"R","Σ":"S","Τ":"T","Υ":"Y","Φ":"F","Χ":"X","Ψ":"PS","Ω":"W","Ϊ":"I","Ϋ":"Y","ά":"a","έ":"e","ή":"h","ί":"i","ΰ":"y","α":"a","β":"b","γ":"g","δ":"d","ε":"e","ζ":"z","η":"h","θ":"8","ι":"i","κ":"k","λ":"l","μ":"m","ν":"n","ξ":"3","ο":"o","π":"p","ρ":"r","ς":"s","σ":"s","τ":"t","υ":"y","φ":"f","χ":"x","ψ":"ps","ω":"w","ϊ":"i","ϋ":"y","ό":"o","ύ":"y","ώ":"w","Ё":"Yo","Ђ":"DJ","Є":"Ye","І":"I","Ї":"Yi","Ј":"J","Љ":"LJ","Њ":"NJ","Ћ":"C","Џ":"DZ","А":"A","Б":"B","В":"V","Г":"G","Д":"D","Е":"E","Ж":"Zh","З":"Z","И":"I","Й":"J","К":"K","Л":"L","М":"M","Н":"N","О":"O","П":"P","Р":"R","С":"S","Т":"T","У":"U","Ф":"F","Х":"H","Ц":"C","Ч":"Ch","Ш":"Sh","Щ":"Sh","Ъ":"U","Ы":"Y","Ь":"","Э":"E","Ю":"Yu","Я":"Ya","а":"a","б":"b","в":"v","г":"g","д":"d","е":"e","ж":"zh","з":"z","и":"i","й":"j","к":"k","л":"l","м":"m","н":"n","о":"o","п":"p","р":"r","с":"s","т":"t","у":"u","ф":"f","х":"h","ц":"c","ч":"ch","ш":"sh","щ":"sh","ъ":"u","ы":"y","ь":"","э":"e","ю":"yu","я":"ya","ё":"yo","ђ":"dj","є":"ye","і":"i","ї":"yi","ј":"j","љ":"lj","њ":"nj","ћ":"c","ѝ":"u","џ":"dz","Ґ":"G","ґ":"g","Ғ":"GH","ғ":"gh","Қ":"KH","қ":"kh","Ң":"NG","ң":"ng","Ү":"UE","ү":"ue","Ұ":"U","ұ":"u","Һ":"H","һ":"h","Ә":"AE","ә":"ae","Ө":"OE","ө":"oe","Ա":"A","Բ":"B","Գ":"G","Դ":"D","Ե":"E","Զ":"Z","Է":"E\'","Ը":"Y\'","Թ":"T\'","Ժ":"JH","Ի":"I","Լ":"L","Խ":"X","Ծ":"C\'","Կ":"K","Հ":"H","Ձ":"D\'","Ղ":"GH","Ճ":"TW","Մ":"M","Յ":"Y","Ն":"N","Շ":"SH","Չ":"CH","Պ":"P","Ջ":"J","Ռ":"R\'","Ս":"S","Վ":"V","Տ":"T","Ր":"R","Ց":"C","Փ":"P\'","Ք":"Q\'","Օ":"O\'\'","Ֆ":"F","և":"EV","฿":"baht","ა":"a","ბ":"b","გ":"g","დ":"d","ე":"e","ვ":"v","ზ":"z","თ":"t","ი":"i","კ":"k","ლ":"l","მ":"m","ნ":"n","ო":"o","პ":"p","ჟ":"zh","რ":"r","ს":"s","ტ":"t","უ":"u","ფ":"f","ქ":"k","ღ":"gh","ყ":"q","შ":"sh","ჩ":"ch","ც":"ts","ძ":"dz","წ":"ts","ჭ":"ch","ხ":"kh","ჯ":"j","ჰ":"h","Ẁ":"W","ẁ":"w","Ẃ":"W","ẃ":"w","Ẅ":"W","ẅ":"w","ẞ":"SS","Ạ":"A","ạ":"a","Ả":"A","ả":"a","Ấ":"A","ấ":"a","Ầ":"A","ầ":"a","Ẩ":"A","ẩ":"a","Ẫ":"A","ẫ":"a","Ậ":"A","ậ":"a","Ắ":"A","ắ":"a","Ằ":"A","ằ":"a","Ẳ":"A","ẳ":"a","Ẵ":"A","ẵ":"a","Ặ":"A","ặ":"a","Ẹ":"E","ẹ":"e","Ẻ":"E","ẻ":"e","Ẽ":"E","ẽ":"e","Ế":"E","ế":"e","Ề":"E","ề":"e","Ể":"E","ể":"e","Ễ":"E","ễ":"e","Ệ":"E","ệ":"e","Ỉ":"I","ỉ":"i","Ị":"I","ị":"i","Ọ":"O","ọ":"o","Ỏ":"O","ỏ":"o","Ố":"O","ố":"o","Ồ":"O","ồ":"o","Ổ":"O","ổ":"o","Ỗ":"O","ỗ":"o","Ộ":"O","ộ":"o","Ớ":"O","ớ":"o","Ờ":"O","ờ":"o","Ở":"O","ở":"o","Ỡ":"O","ỡ":"o","Ợ":"O","ợ":"o","Ụ":"U","ụ":"u","Ủ":"U","ủ":"u","Ứ":"U","ứ":"u","Ừ":"U","ừ":"u","Ử":"U","ử":"u","Ữ":"U","ữ":"u","Ự":"U","ự":"u","Ỳ":"Y","ỳ":"y","Ỵ":"Y","ỵ":"y","Ỷ":"Y","ỷ":"y","Ỹ":"Y","ỹ":"y","–":"-","‘":"\'","’":"\'","“":"\\\"","”":"\\\"","„":"\\\"","†":"+","•":"*","…":"...","₠":"ecu","₢":"cruzeiro","₣":"french franc","₤":"lira","₥":"mill","₦":"naira","₧":"peseta","₨":"rupee","₩":"won","₪":"new shequel","₫":"dong","€":"euro","₭":"kip","₮":"tugrik","₯":"drachma","₰":"penny","₱":"peso","₲":"guarani","₳":"austral","₴":"hryvnia","₵":"cedi","₸":"kazakhstani tenge","₹":"indian rupee","₺":"turkish lira","₽":"russian ruble","₿":"bitcoin","℠":"sm","™":"tm","∂":"d","∆":"delta","∑":"sum","∞":"infinity","♥":"love","元":"yuan","円":"yen","﷼":"rial"}');
3587
- var locales = JSON.parse('{"de":{"Ä":"AE","ä":"ae","Ö":"OE","ö":"oe","Ü":"UE","ü":"ue","%":"prozent","&":"und","|":"oder","∑":"summe","∞":"unendlich","♥":"liebe"},"es":{"%":"por ciento","&":"y","<":"menor que",">":"mayor que","|":"o","¢":"centavos","£":"libras","¤":"moneda","₣":"francos","∑":"suma","∞":"infinito","♥":"amor"},"fr":{"%":"pourcent","&":"et","<":"plus petit",">":"plus grand","|":"ou","¢":"centime","£":"livre","¤":"devise","₣":"franc","∑":"somme","∞":"infini","♥":"amour"},"pt":{"%":"porcento","&":"e","<":"menor",">":"maior","|":"ou","¢":"centavo","∑":"soma","£":"libra","∞":"infinito","♥":"amor"},"uk":{"И":"Y","и":"y","Й":"Y","й":"y","Ц":"Ts","ц":"ts","Х":"Kh","х":"kh","Щ":"Shch","щ":"shch","Г":"H","г":"h"},"vi":{"Đ":"D","đ":"d"}}');
3588
-
3589
- function replace (string, options) {
3590
- if (typeof string !== 'string') {
3591
- throw new Error('slugify: string argument expected')
3592
- }
3593
-
3594
- options = (typeof options === 'string')
3595
- ? {replacement: options}
3596
- : options || {};
3597
-
3598
- var locale = locales[options.locale] || {};
3599
-
3600
- var replacement = options.replacement === undefined ? '-' : options.replacement;
3601
-
3602
- var trim = options.trim === undefined ? true : options.trim;
3603
-
3604
- var slug = string.normalize().split('')
3605
- // replace characters based on charMap
3606
- .reduce(function (result, ch) {
3607
- return result + (locale[ch] || charMap[ch] || (ch === replacement ? ' ' : ch))
3608
- // remove not allowed characters
3609
- .replace(options.remove || /[^\w\s$*_+~.()'"!\-:@]+/g, '')
3610
- }, '');
3611
-
3612
- if (options.strict) {
3613
- slug = slug.replace(/[^A-Za-z0-9\s]/g, '');
3614
- }
3615
-
3616
- if (trim) {
3617
- slug = slug.trim();
3618
- }
3619
-
3620
- // Replace spaces with replacement character, treating multiple consecutive
3621
- // spaces as a single space.
3622
- slug = slug.replace(/\s+/g, replacement);
3623
-
3624
- if (options.lower) {
3625
- slug = slug.toLowerCase();
3626
- }
3627
-
3628
- return slug
3629
- }
3630
-
3631
- replace.extend = function (customMap) {
3632
- Object.assign(charMap, customMap);
3633
- };
3634
-
3635
- return replace
3636
- }));
3637
- });
3638
-
3639
3577
  var StorageNames = Constants.StorageNames,
3640
3578
  pluses = /\+/g;
3641
3579
  function Helpers(mpInstance) {
@@ -4229,8 +4167,11 @@ var mParticle = (function () {
4229
4167
  }
4230
4168
  };
4231
4169
 
4232
- this.isSlug = function (str) {
4233
- return str === slugify(str);
4170
+ this.isDataPlanSlug = function (str) {
4171
+ // This verifies that `str` matches how our backend defines data plan slug names.
4172
+ // i.e. under_score_slug instead kabob-case-slug
4173
+ // We also want to reject any non-string values
4174
+ return typeof str === 'string' && str === str.trim().replaceAll(/[^0-9a-zA-Z]+/g, '_').toLowerCase();
4234
4175
  };
4235
4176
  }
4236
4177
 
@@ -5206,6 +5147,10 @@ var mParticle = (function () {
5206
5147
  this.SDKConfig = createSDKConfig(config); // Set configuration to default settings
5207
5148
 
5208
5149
  if (config) {
5150
+ if (config.deviceId) {
5151
+ this.deviceId = config.deviceId;
5152
+ }
5153
+
5209
5154
  if (config.hasOwnProperty('isDevelopmentMode')) {
5210
5155
  this.SDKConfig.isDevelopmentMode = mpInstance._Helpers.returnConvertedBoolean(config.isDevelopmentMode);
5211
5156
  } else {
@@ -5317,14 +5262,10 @@ var mParticle = (function () {
5317
5262
  };
5318
5263
 
5319
5264
  if (config.dataPlan.hasOwnProperty('planId')) {
5320
- if (typeof config.dataPlan.planId === 'string') {
5321
- if (mpInstance._Helpers.isSlug(config.dataPlan.planId)) {
5322
- this.SDKConfig.dataPlan.PlanId = config.dataPlan.planId;
5323
- } else {
5324
- mpInstance.Logger.error('Your data plan id must be in a slug format');
5325
- }
5265
+ if (mpInstance._Helpers.isDataPlanSlug(config.dataPlan.planId)) {
5266
+ this.SDKConfig.dataPlan.PlanId = config.dataPlan.planId;
5326
5267
  } else {
5327
- mpInstance.Logger.error('Your data plan id must be a string');
5268
+ mpInstance.Logger.error('Your data plan id must be a string and match the data plan slug format (i.e. under_case_slug)');
5328
5269
  }
5329
5270
  }
5330
5271
 
@@ -5830,8 +5771,8 @@ var mParticle = (function () {
5830
5771
  for (i = 0, l = cookies.length; i < l; i++) {
5831
5772
  try {
5832
5773
  parts = cookies[i].split('=');
5833
- name = mpInstance._Helpers.decoded(parts.shift());
5834
- cookie = mpInstance._Helpers.decoded(parts.join('='));
5774
+ name = parts.shift();
5775
+ cookie = parts.join('=');
5835
5776
  } catch (e) {
5836
5777
  mpInstance.Logger.verbose('Unable to parse cookie: ' + name + '. Skipping.');
5837
5778
  }
@@ -6410,6 +6351,11 @@ var mParticle = (function () {
6410
6351
  return mpInstance._Store.deviceId;
6411
6352
  };
6412
6353
 
6354
+ this.setDeviceId = function (guid) {
6355
+ mpInstance._Store.deviceId = guid;
6356
+ self.update();
6357
+ };
6358
+
6413
6359
  this.resetPersistence = function () {
6414
6360
  removeLocalStorage(StorageNames$1.localStorageName);
6415
6361
  removeLocalStorage(StorageNames$1.localStorageNameV3);
@@ -6659,7 +6605,16 @@ var mParticle = (function () {
6659
6605
  };
6660
6606
 
6661
6607
  this.logCommerceEvent = function (commerceEvent, attrs, options) {
6662
- mpInstance.Logger.verbose(Messages$6.InformationMessages.StartingLogCommerceEvent);
6608
+ mpInstance.Logger.verbose(Messages$6.InformationMessages.StartingLogCommerceEvent); // If a developer typos the ProductActionType, the event category will be
6609
+ // null, resulting in kit forwarding errors on the server.
6610
+ // The check for `ProductAction` is required to denote that these are
6611
+ // ProductAction events, and not impression or promotions
6612
+
6613
+ if (commerceEvent.ProductAction && commerceEvent.EventCategory === null) {
6614
+ mpInstance.Logger.error('Commerce event not sent. The mParticle.ProductActionType you passed was invalid. Re-check your code.');
6615
+ return;
6616
+ }
6617
+
6663
6618
  attrs = mpInstance._Helpers.sanitizeAttributes(attrs, commerceEvent.EventName);
6664
6619
 
6665
6620
  if (mpInstance._Helpers.canLog()) {
@@ -7267,9 +7222,10 @@ var mParticle = (function () {
7267
7222
  filterUserIdentities(clonedEvent, mpInstance._Store.activeForwarders[i].userIdentityFilters); // Check user attribute filtering rules
7268
7223
 
7269
7224
  clonedEvent.UserAttributes = mpInstance._Helpers.filterUserAttributes(clonedEvent.UserAttributes, mpInstance._Store.activeForwarders[i].userAttributeFilters);
7270
- mpInstance.Logger.verbose('Sending message to forwarder: ' + mpInstance._Store.activeForwarders[i].name);
7271
7225
 
7272
7226
  if (mpInstance._Store.activeForwarders[i].process) {
7227
+ mpInstance.Logger.verbose('Sending message to forwarder: ' + mpInstance._Store.activeForwarders[i].name);
7228
+
7273
7229
  var result = mpInstance._Store.activeForwarders[i].process(clonedEvent);
7274
7230
 
7275
7231
  if (result) {
@@ -10300,6 +10256,31 @@ var mParticle = (function () {
10300
10256
 
10301
10257
  self._Persistence.update();
10302
10258
  };
10259
+ /**
10260
+ * Sets the device id
10261
+ * @method setDeviceId
10262
+ * @param {String} name device ID (UUIDv4-formatted string)
10263
+ */
10264
+
10265
+
10266
+ this.setDeviceId = function (guid) {
10267
+ var queued = queueIfNotInitialized(function () {
10268
+ self.setDeviceId(guid);
10269
+ }, self);
10270
+ if (queued) return;
10271
+
10272
+ this._Persistence.setDeviceId(guid);
10273
+ };
10274
+ /**
10275
+ * Returns a boolean for whether or not the SDKhas been fully initialized
10276
+ * @method isInitialized
10277
+ * @return {Boolean} a boolean for whether or not the SDK has been fully initialized
10278
+ */
10279
+
10280
+
10281
+ this.isInitialized = function () {
10282
+ return self._Store ? self._Store.isInitialized : false;
10283
+ };
10303
10284
  /**
10304
10285
  * Gets the app name
10305
10286
  * @method getAppName
@@ -11132,10 +11113,6 @@ var mParticle = (function () {
11132
11113
  this._setIntegrationDelay = function (module, _boolean) {
11133
11114
  self._preInit.integrationDelays[module] = _boolean;
11134
11115
  };
11135
-
11136
- this.isInitialized = function () {
11137
- return self._Store ? self._Store.isInitialized : false;
11138
- };
11139
11116
  } // Some (server) config settings need to be returned before they are set on SDKConfig in a self hosted environment
11140
11117
 
11141
11118
  function completeSDKInitialization(apiKey, config, mpInstance) {
@@ -11225,7 +11202,11 @@ var mParticle = (function () {
11225
11202
  mpInstance._ForwardingStatsUploader.startForwardingStatsTimer();
11226
11203
  }
11227
11204
 
11228
- mpInstance._Forwarders.processForwarders(config, mpInstance._APIClient.prepareForwardingStats); // Call mParticle._Store.SDKConfig.identityCallback when identify was not called due to a reload or a sessionId already existing
11205
+ mpInstance._Forwarders.processForwarders(config, mpInstance._APIClient.prepareForwardingStats);
11206
+
11207
+ mpInstance._SessionManager.initialize();
11208
+
11209
+ mpInstance._Events.logAST(); // Call mParticle._Store.SDKConfig.identityCallback when identify was not called due to a reload or a sessionId already existing
11229
11210
 
11230
11211
 
11231
11212
  if (!mpInstance._Store.identifyCalled && mpInstance._Store.SDKConfig.identityCallback && currentUser && currentUser.getMPID()) {
@@ -11253,10 +11234,6 @@ var mParticle = (function () {
11253
11234
  }
11254
11235
  });
11255
11236
  }
11256
-
11257
- mpInstance._SessionManager.initialize();
11258
-
11259
- mpInstance._Events.logAST();
11260
11237
  }
11261
11238
 
11262
11239
  mpInstance._Store.isInitialized = true; // Call any functions that are waiting for the library to be initialized
@@ -11521,6 +11498,14 @@ var mParticle = (function () {
11521
11498
  return self.getInstance().getDeviceId();
11522
11499
  };
11523
11500
 
11501
+ this.setDeviceId = function (guid) {
11502
+ return self.getInstance().setDeviceId(guid);
11503
+ };
11504
+
11505
+ this.isInitialized = function () {
11506
+ return self.getInstance().isInitialized();
11507
+ };
11508
+
11524
11509
  this.startNewSession = function () {
11525
11510
  self.getInstance().startNewSession();
11526
11511
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mparticle/web-sdk",
3
- "version": "2.14.2",
3
+ "version": "2.15.2",
4
4
  "description": "mParticle core SDK for web applications",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
@@ -116,7 +116,6 @@
116
116
  "yuidocjs": "^0.10.2"
117
117
  },
118
118
  "dependencies": {
119
- "@babel/runtime": "^7.6.0",
120
- "slugify": "^1.3.6"
119
+ "@babel/runtime": "^7.6.0"
121
120
  }
122
121
  }
package/src/events.js CHANGED
@@ -319,6 +319,20 @@ export default function Events(mpInstance) {
319
319
  Messages.InformationMessages.StartingLogCommerceEvent
320
320
  );
321
321
 
322
+ // If a developer typos the ProductActionType, the event category will be
323
+ // null, resulting in kit forwarding errors on the server.
324
+ // The check for `ProductAction` is required to denote that these are
325
+ // ProductAction events, and not impression or promotions
326
+ if (
327
+ commerceEvent.ProductAction &&
328
+ commerceEvent.EventCategory === null
329
+ ) {
330
+ mpInstance.Logger.error(
331
+ 'Commerce event not sent. The mParticle.ProductActionType you passed was invalid. Re-check your code.'
332
+ );
333
+ return;
334
+ }
335
+
322
336
  attrs = mpInstance._Helpers.sanitizeAttributes(
323
337
  attrs,
324
338
  commerceEvent.EventName
package/src/forwarders.js CHANGED
@@ -369,12 +369,11 @@ export default function Forwarders(mpInstance, kitBlocker) {
369
369
  mpInstance._Store.activeForwarders[i].userAttributeFilters
370
370
  );
371
371
 
372
- mpInstance.Logger.verbose(
373
- 'Sending message to forwarder: ' +
374
- mpInstance._Store.activeForwarders[i].name
375
- );
376
-
377
372
  if (mpInstance._Store.activeForwarders[i].process) {
373
+ mpInstance.Logger.verbose(
374
+ 'Sending message to forwarder: ' +
375
+ mpInstance._Store.activeForwarders[i].name
376
+ );
378
377
  var result = mpInstance._Store.activeForwarders[i].process(
379
378
  clonedEvent
380
379
  );
package/src/helpers.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import Types from './types';
2
2
  import Constants from './constants';
3
- import Slugify from 'slugify';
4
3
 
5
4
  var StorageNames = Constants.StorageNames,
6
5
  pluses = /\+/g;
@@ -721,7 +720,18 @@ export default function Helpers(mpInstance) {
721
720
  }
722
721
  };
723
722
 
724
- this.isSlug = function(str) {
725
- return str === Slugify(str);
723
+ this.isDataPlanSlug = function(str) {
724
+ // This verifies that `str` matches how our backend defines data plan slug names.
725
+ // i.e. under_score_slug instead kabob-case-slug
726
+ // We also want to reject any non-string values
727
+
728
+ return (
729
+ typeof str === 'string' &&
730
+ str ===
731
+ str
732
+ .trim()
733
+ .replaceAll(/[^0-9a-zA-Z]+/g, '_')
734
+ .toLowerCase()
735
+ );
726
736
  };
727
737
  }
@@ -87,6 +87,7 @@ export default function mParticleInstance(instanceName) {
87
87
  this.Identity = this._Identity.IdentityAPI;
88
88
  this.generateHash = this._Helpers.generateHash;
89
89
  this.getDeviceId = this._Persistence.getDeviceId;
90
+
90
91
  if (typeof window !== 'undefined') {
91
92
  if (window.mParticle && window.mParticle.config) {
92
93
  if (window.mParticle.config.hasOwnProperty('rq')) {
@@ -210,6 +211,27 @@ export default function mParticleInstance(instanceName) {
210
211
  self._Store.SDKConfig.appVersion = version;
211
212
  self._Persistence.update();
212
213
  };
214
+ /**
215
+ * Sets the device id
216
+ * @method setDeviceId
217
+ * @param {String} name device ID (UUIDv4-formatted string)
218
+ */
219
+ this.setDeviceId = function(guid) {
220
+ var queued = queueIfNotInitialized(function() {
221
+ self.setDeviceId(guid);
222
+ }, self);
223
+ if (queued) return;
224
+ this._Persistence.setDeviceId(guid);
225
+ };
226
+ /**
227
+ * Returns a boolean for whether or not the SDKhas been fully initialized
228
+ * @method isInitialized
229
+ * @return {Boolean} a boolean for whether or not the SDK has been fully initialized
230
+ */
231
+ this.isInitialized = function() {
232
+ return self._Store ? self._Store.isInitialized : false;
233
+ };
234
+
213
235
  /**
214
236
  * Gets the app name
215
237
  * @method getAppName
@@ -1186,9 +1208,6 @@ export default function mParticleInstance(instanceName) {
1186
1208
  this._setIntegrationDelay = function(module, boolean) {
1187
1209
  self._preInit.integrationDelays[module] = boolean;
1188
1210
  };
1189
- this.isInitialized = function() {
1190
- return self._Store ? self._Store.isInitialized : false;
1191
- };
1192
1211
  }
1193
1212
 
1194
1213
  // Some (server) config settings need to be returned before they are set on SDKConfig in a self hosted environment
@@ -1321,6 +1340,9 @@ function completeSDKInitialization(apiKey, config, mpInstance) {
1321
1340
  mpInstance._APIClient.prepareForwardingStats
1322
1341
  );
1323
1342
 
1343
+ mpInstance._SessionManager.initialize();
1344
+ mpInstance._Events.logAST();
1345
+
1324
1346
  // Call mParticle._Store.SDKConfig.identityCallback when identify was not called due to a reload or a sessionId already existing
1325
1347
  if (
1326
1348
  !mpInstance._Store.identifyCalled &&
@@ -1357,9 +1379,6 @@ function completeSDKInitialization(apiKey, config, mpInstance) {
1357
1379
  },
1358
1380
  });
1359
1381
  }
1360
-
1361
- mpInstance._SessionManager.initialize();
1362
- mpInstance._Events.logAST();
1363
1382
  }
1364
1383
 
1365
1384
  mpInstance._Store.isInitialized = true;
@@ -97,6 +97,12 @@ function mParticle() {
97
97
  this.getDeviceId = function() {
98
98
  return self.getInstance().getDeviceId();
99
99
  };
100
+ this.setDeviceId = function(guid) {
101
+ return self.getInstance().setDeviceId(guid);
102
+ };
103
+ this.isInitialized = function() {
104
+ return self.getInstance().isInitialized();
105
+ };
100
106
  this.startNewSession = function() {
101
107
  self.getInstance().startNewSession();
102
108
  };
@@ -457,8 +457,8 @@ export default function _Persistence(mpInstance) {
457
457
  for (i = 0, l = cookies.length; i < l; i++) {
458
458
  try {
459
459
  parts = cookies[i].split('=');
460
- name = mpInstance._Helpers.decoded(parts.shift());
461
- cookie = mpInstance._Helpers.decoded(parts.join('='));
460
+ name = parts.shift();
461
+ cookie = parts.join('=');
462
462
  } catch (e) {
463
463
  mpInstance.Logger.verbose(
464
464
  'Unable to parse cookie: ' + name + '. Skipping.'
@@ -1148,6 +1148,11 @@ export default function _Persistence(mpInstance) {
1148
1148
  return mpInstance._Store.deviceId;
1149
1149
  };
1150
1150
 
1151
+ this.setDeviceId = function(guid) {
1152
+ mpInstance._Store.deviceId = guid;
1153
+ self.update();
1154
+ };
1155
+
1151
1156
  this.resetPersistence = function() {
1152
1157
  removeLocalStorage(StorageNames.localStorageName);
1153
1158
  removeLocalStorage(StorageNames.localStorageNameV3);
@@ -156,6 +156,7 @@ export interface SDKConfig {
156
156
  minWebviewBridgeVersion: number;
157
157
  isIOS?: boolean;
158
158
  identifyRequest: { [key: string]: {[key: string]: string} };
159
+ identityCallback: (result) => void;
159
160
  requestConfig: boolean;
160
161
  dataPlanOptions: KitBlockerOptions // when the user provides their own data plan
161
162
  dataPlanResult?: DataPlanResult // when the data plan comes from the server via /config
package/src/store.js CHANGED
@@ -74,6 +74,9 @@ export default function Store(config, mpInstance) {
74
74
  this.SDKConfig = createSDKConfig(config);
75
75
  // Set configuration to default settings
76
76
  if (config) {
77
+ if (config.deviceId) {
78
+ this.deviceId = config.deviceId;
79
+ }
77
80
  if (config.hasOwnProperty('isDevelopmentMode')) {
78
81
  this.SDKConfig.isDevelopmentMode = mpInstance._Helpers.returnConvertedBoolean(
79
82
  config.isDevelopmentMode
@@ -194,17 +197,13 @@ export default function Store(config, mpInstance) {
194
197
  PlanId: null,
195
198
  };
196
199
  if (config.dataPlan.hasOwnProperty('planId')) {
197
- if (typeof config.dataPlan.planId === 'string') {
198
- if (mpInstance._Helpers.isSlug(config.dataPlan.planId)) {
199
- this.SDKConfig.dataPlan.PlanId = config.dataPlan.planId;
200
- } else {
201
- mpInstance.Logger.error(
202
- 'Your data plan id must be in a slug format'
203
- );
204
- }
200
+ if (
201
+ mpInstance._Helpers.isDataPlanSlug(config.dataPlan.planId)
202
+ ) {
203
+ this.SDKConfig.dataPlan.PlanId = config.dataPlan.planId;
205
204
  } else {
206
205
  mpInstance.Logger.error(
207
- 'Your data plan id must be a string'
206
+ 'Your data plan id must be a string and match the data plan slug format (i.e. under_case_slug)'
208
207
  );
209
208
  }
210
209
  }