@mparticle/web-sdk 2.23.7 → 2.23.8

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/src/identity.js CHANGED
@@ -4,6 +4,8 @@ import Types from './types';
4
4
  var Messages = Constants.Messages,
5
5
  HTTPCodes = Constants.HTTPCodes;
6
6
 
7
+ const { Identify, Modify } = Constants.IdentityMethods;
8
+
7
9
  export default function Identity(mpInstance) {
8
10
  var self = this;
9
11
  this.checkIdentitySwap = function(
@@ -1476,7 +1478,7 @@ export default function Identity(mpInstance) {
1476
1478
  }
1477
1479
 
1478
1480
  if (xhr.status === 200) {
1479
- if (method === 'modify') {
1481
+ if (method === Modify) {
1480
1482
  newIdentitiesByType = mpInstance._Identity.IdentityRequest.combineUserIdentities(
1481
1483
  previousUIByName,
1482
1484
  identityApiData.userIdentities
@@ -1507,7 +1509,7 @@ export default function Identity(mpInstance) {
1507
1509
  //will not have a value for "fst" until the current MPID changes, and in some cases,
1508
1510
  //the current MPID will never change
1509
1511
  if (
1510
- method === 'identify' &&
1512
+ method === Identify &&
1511
1513
  prevUser &&
1512
1514
  identityApiResult.mpid === prevUser.getMPID()
1513
1515
  ) {
@@ -1568,6 +1570,7 @@ export default function Identity(mpInstance) {
1568
1570
  );
1569
1571
  }
1570
1572
 
1573
+ // https://go.mparticle.com/work/SQDSDKS-6041
1571
1574
  mpInstance._Persistence.saveUserIdentitiesToPersistence(
1572
1575
  identityApiResult.mpid,
1573
1576
  newIdentitiesByType
@@ -1620,6 +1623,8 @@ export default function Identity(mpInstance) {
1620
1623
  mpInstance._APIClient.prepareForwardingStats
1621
1624
  );
1622
1625
  }
1626
+
1627
+ // TODO: https://go.mparticle.com/work/SQDSDKS-6036
1623
1628
  mpInstance._Forwarders.setForwarderUserIdentities(
1624
1629
  newUser.getUserIdentities().userIdentities
1625
1630
  );
@@ -1628,8 +1633,7 @@ export default function Identity(mpInstance) {
1628
1633
  method
1629
1634
  );
1630
1635
  mpInstance._Forwarders.setForwarderOnUserIdentified(
1631
- newUser,
1632
- method
1636
+ newUser
1633
1637
  );
1634
1638
  }
1635
1639
  var newIdentitiesByName = {};
@@ -1646,7 +1650,7 @@ export default function Identity(mpInstance) {
1646
1650
  newIdentitiesByName,
1647
1651
  method,
1648
1652
  identityApiResult.mpid,
1649
- method === 'modify'
1653
+ method === Modify
1650
1654
  ? previousUIByNameCopy
1651
1655
  : incomingMpidUIByNameCopy
1652
1656
  );
@@ -3,6 +3,8 @@ import Constants from './constants';
3
3
  var HTTPCodes = Constants.HTTPCodes,
4
4
  Messages = Constants.Messages;
5
5
 
6
+ const { Modify } = Constants.IdentityMethods;
7
+
6
8
  export default function IdentityAPIClient(mpInstance) {
7
9
  this.sendAliasRequest = function(aliasRequest, callback) {
8
10
  var xhr,
@@ -107,7 +109,7 @@ export default function IdentityAPIClient(mpInstance) {
107
109
  );
108
110
  } else {
109
111
  previousMPID = mpid || null;
110
- if (method === 'modify') {
112
+ if (method === Modify) {
111
113
  xhr.open(
112
114
  'post',
113
115
  mpInstance._Helpers.createServiceUrl(
@@ -1330,6 +1330,7 @@ function completeSDKInitialization(apiKey, config, mpInstance) {
1330
1330
 
1331
1331
  mpInstance._Store.configurationLoaded = true;
1332
1332
 
1333
+ // https://go.mparticle.com/work/SQDSDKS-6044
1333
1334
  if (!mpInstance._Store.webviewBridgeEnabled) {
1334
1335
  // Load any settings/identities/attributes from cookie or localStorage
1335
1336
  mpInstance._Persistence.initializeStorage();
@@ -1401,6 +1402,7 @@ function completeSDKInitialization(apiKey, config, mpInstance) {
1401
1402
  mpInstance._Events.logAST();
1402
1403
 
1403
1404
  // Call mParticle._Store.SDKConfig.identityCallback when identify was not called due to a reload or a sessionId already existing
1405
+ // Any identity callback should always be ran regardless if an identity call is made
1404
1406
  if (
1405
1407
  !mpInstance._Store.identifyCalled &&
1406
1408
  mpInstance._Store.SDKConfig.identityCallback &&
@@ -1455,6 +1457,7 @@ function completeSDKInitialization(apiKey, config, mpInstance) {
1455
1457
  mpInstance._preInit.readyQueue = [];
1456
1458
  }
1457
1459
 
1460
+ // https://go.mparticle.com/work/SQDSDKS-6040
1458
1461
  if (mpInstance._Store.isFirstRun) {
1459
1462
  mpInstance._Store.isFirstRun = false;
1460
1463
  }
@@ -10,6 +10,8 @@ var Base64 = Polyfill.Base64,
10
10
 
11
11
  export default function _Persistence(mpInstance) {
12
12
  var self = this;
13
+
14
+ // https://go.mparticle.com/work/SQDSDKS-5022
13
15
  this.useLocalStorage = function() {
14
16
  return (
15
17
  !mpInstance._Store.SDKConfig.useCookieStorage &&
@@ -24,6 +26,7 @@ export default function _Persistence(mpInstance) {
24
26
  cookies = self.getCookie(),
25
27
  allData;
26
28
 
29
+ // https://go.mparticle.com/work/SQDSDKS-6045
27
30
  // Determine if there is any data in cookies or localStorage to figure out if it is the first time the browser is loading mParticle
28
31
  if (!localStorageData && !cookies) {
29
32
  mpInstance._Store.isFirstRun = true;
@@ -32,10 +35,12 @@ export default function _Persistence(mpInstance) {
32
35
  mpInstance._Store.isFirstRun = false;
33
36
  }
34
37
 
38
+ // https://go.mparticle.com/work/SQDSDKS-6045
35
39
  if (!mpInstance._Store.isLocalStorageAvailable) {
36
40
  mpInstance._Store.SDKConfig.useCookieStorage = true;
37
41
  }
38
42
 
43
+ // https://go.mparticle.com/work/SQDSDKS-6046
39
44
  if (mpInstance._Store.isLocalStorageAvailable) {
40
45
  storage = window.localStorage;
41
46
  if (mpInstance._Store.SDKConfig.useCookieStorage) {
@@ -43,6 +48,7 @@ export default function _Persistence(mpInstance) {
43
48
  // no mParticle cookie exists yet and there is localStorage. Get the localStorage, set them to cookies, then delete the localStorage item.
44
49
  if (localStorageData) {
45
50
  if (cookies) {
51
+ // https://go.mparticle.com/work/SQDSDKS-6047
46
52
  allData = mpInstance._Helpers.extend(
47
53
  false,
48
54
  localStorageData,
@@ -61,6 +67,7 @@ export default function _Persistence(mpInstance) {
61
67
  // no mParticle localStorage exists yet and there are cookies. Get the cookies, set them to localStorage, then delete the cookies.
62
68
  if (cookies) {
63
69
  if (localStorageData) {
70
+ // https://go.mparticle.com/work/SQDSDKS-6047
64
71
  allData = mpInstance._Helpers.extend(
65
72
  false,
66
73
  localStorageData,
@@ -79,6 +86,7 @@ export default function _Persistence(mpInstance) {
79
86
  self.storeDataInMemory(cookies);
80
87
  }
81
88
 
89
+ // https://go.mparticle.com/work/SQDSDKS-6048
82
90
  try {
83
91
  if (mpInstance._Store.isLocalStorageAvailable) {
84
92
  var encodedProducts = localStorage.getItem(
@@ -107,6 +115,8 @@ export default function _Persistence(mpInstance) {
107
115
  );
108
116
  }
109
117
 
118
+ // https://go.mparticle.com/work/SQDSDKS-6046
119
+ // Stores all non-current user MPID information into the store
110
120
  for (var key in allData) {
111
121
  if (allData.hasOwnProperty(key)) {
112
122
  if (!SDKv2NonMPIDCookieKeys[key]) {
@@ -117,6 +127,8 @@ export default function _Persistence(mpInstance) {
117
127
  }
118
128
  self.update();
119
129
  } catch (e) {
130
+ // If cookies or local storage is corrupt, we want to remove it
131
+ // so that in the future, initializeStorage will work
120
132
  if (
121
133
  self.useLocalStorage() &&
122
134
  mpInstance._Store.isLocalStorageAvailable
@@ -154,6 +166,7 @@ export default function _Persistence(mpInstance) {
154
166
  }
155
167
  };
156
168
 
169
+ // https://go.mparticle.com/work/SQDSDKS-6045
157
170
  this.storeDataInMemory = function(obj, currentMPID) {
158
171
  try {
159
172
  if (!obj) {
@@ -235,6 +248,7 @@ export default function _Persistence(mpInstance) {
235
248
  }
236
249
  };
237
250
 
251
+ // https://go.mparticle.com/work/SQDSDKS-5022
238
252
  this.determineLocalStorageAvailability = function(storage) {
239
253
  var result;
240
254
 
@@ -310,6 +324,7 @@ export default function _Persistence(mpInstance) {
310
324
  return parsedDecodedProducts;
311
325
  };
312
326
 
327
+ // https://go.mparticle.com/work/SQDSDKS-6021
313
328
  this.setLocalStorage = function() {
314
329
  if (!mpInstance._Store.isLocalStorageAvailable) {
315
330
  return;
@@ -492,7 +507,8 @@ export default function _Persistence(mpInstance) {
492
507
  }
493
508
  };
494
509
 
495
- // only used in persistence
510
+ // https://go.mparticle.com/work/SQDSDKS-5022
511
+ // https://go.mparticle.com/work/SQDSDKS-6021
496
512
  this.setCookie = function() {
497
513
  var mpid,
498
514
  currentUser = mpInstance.Identity.getCurrentUser();
@@ -996,6 +1012,7 @@ export default function _Persistence(mpInstance) {
996
1012
  }
997
1013
  };
998
1014
 
1015
+ // https://go.mparticle.com/work/SQDSDKS-6021
999
1016
  this.savePersistence = function(persistence) {
1000
1017
  var encodedPersistence = self.encodePersistence(
1001
1018
  JSON.stringify(persistence)
@@ -1168,6 +1185,7 @@ export default function _Persistence(mpInstance) {
1168
1185
  }
1169
1186
  };
1170
1187
 
1188
+ // https://go.mparticle.com/work/SQDSDKS-6045
1171
1189
  // Forwarder Batching Code
1172
1190
  this.forwardingStatsBatches = {
1173
1191
  uploadsTable: {},
@@ -10,6 +10,7 @@ import { SDKConsentApi, SDKConsentState } from './consent';
10
10
  import { IPersistence } from './persistence.interfaces';
11
11
  import { IMPSideloadedKit } from './sideloadedKit';
12
12
  import { ISessionManager } from './sessionManager';
13
+ import { Kit, MPForwarder } from './forwarders.interfaces';
13
14
 
14
15
  // TODO: Resolve this with version in @mparticle/web-sdk
15
16
  export type SDKEventCustomFlags = Dictionary<any>;
@@ -184,10 +185,6 @@ export type BooleanStringTitleCase = 'False' | 'True';
184
185
 
185
186
  export type LogLevelType = 'none' | 'verbose' | 'warning' | 'error';
186
187
 
187
- // TODO: Create true types for Kits and Kit Configs
188
- export type Kit = Dictionary;
189
- export type MPForwarder = Dictionary;
190
-
191
188
  // TODO: This should eventually be moved into wherever init logic lives
192
189
  // TODO: Replace/Merge this with MPConfiguration in @types/mparticle__web-sdk
193
190
  // SDK Init Config represents the config that is passed into mParticle.init when
@@ -13,7 +13,12 @@ import {
13
13
  SDKProduct,
14
14
  SDKUserIdentity,
15
15
  } from './sdkRuntimeModels';
16
- import { parseNumber, parseStringOrNumber, Dictionary } from './utils';
16
+ import {
17
+ parseNumber,
18
+ parseStringOrNumber,
19
+ Dictionary,
20
+ isValidCustomFlagProperty,
21
+ } from './utils';
17
22
  import { ServerSettings } from './store';
18
23
  import { MPID } from '@mparticle/web-sdk';
19
24
  import {
@@ -145,22 +150,12 @@ function convertCustomFlags(event: SDKEvent, dto: IServerV2DTO) {
145
150
 
146
151
  if (event.CustomFlags.hasOwnProperty(prop)) {
147
152
  if (Array.isArray(event.CustomFlags[prop])) {
148
- event.CustomFlags[prop].forEach(function(customFlagProperty) {
149
- // TODO: Can we use our utility functions here?
150
- if (
151
- typeof customFlagProperty === 'number' ||
152
- typeof customFlagProperty === 'string' ||
153
- typeof customFlagProperty === 'boolean'
154
- ) {
153
+ event.CustomFlags[prop].forEach(customFlagProperty => {
154
+ if (isValidCustomFlagProperty(customFlagProperty)) {
155
155
  valueArray.push(customFlagProperty.toString());
156
156
  }
157
157
  });
158
- } else if (
159
- // TODO: Can we use our utility functions here?
160
- typeof event.CustomFlags[prop] === 'number' ||
161
- typeof event.CustomFlags[prop] === 'string' ||
162
- typeof event.CustomFlags[prop] === 'boolean'
163
- ) {
158
+ } else if (isValidCustomFlagProperty(event.CustomFlags[prop])) {
164
159
  valueArray.push(event.CustomFlags[prop].toString());
165
160
  }
166
161
 
@@ -44,6 +44,7 @@ export default function SessionManager(
44
44
  self.endSession();
45
45
  self.startNewSession();
46
46
  } else {
47
+ // https://go.mparticle.com/work/SQDSDKS-6045
47
48
  const persistence: IPersistenceMinified = mpInstance._Persistence.getPersistence();
48
49
  if (persistence && !persistence.cu) {
49
50
  mpInstance.Identity.identify(
package/src/store.ts CHANGED
@@ -11,11 +11,9 @@ import { IKitConfigs } from './configAPIClient';
11
11
  import Constants from './constants';
12
12
  import {
13
13
  DataPlanResult,
14
- Kit,
15
14
  KitBlockerOptions,
16
15
  LogLevelType,
17
16
  MParticleWebSDK,
18
- MPForwarder,
19
17
  SDKDataPlan,
20
18
  SDKEvent,
21
19
  SDKGeoLocation,
@@ -24,6 +22,7 @@ import {
24
22
  } from './sdkRuntimeModels';
25
23
  import { isNumber, isDataPlanSlug, Dictionary } from './utils';
26
24
  import { SDKConsentState } from './consent';
25
+ import { Kit, MPForwarder } from './forwarders.interfaces';
27
26
 
28
27
  // This represents the runtime configuration of the SDK AFTER
29
28
  // initialization has been complete and all settings and
package/src/utils.ts CHANGED
@@ -201,7 +201,10 @@ const converted = (s: string): string => {
201
201
 
202
202
  const isString = (value: any): boolean => typeof value === 'string';
203
203
  const isNumber = (value: any): boolean => typeof value === 'number';
204
+ const isBoolean = (value: any): boolean => typeof value === 'boolean';
204
205
  const isFunction = (fn: any): boolean => typeof fn === 'function';
206
+ const isValidCustomFlagProperty = (value: any): boolean =>
207
+ isNumber(value) || isString(value) || isBoolean(value);
205
208
 
206
209
  const toDataPlanSlug = (value: any): string =>
207
210
  // Make sure we are only acting on strings or numbers
@@ -247,4 +250,5 @@ export {
247
250
  isFunction,
248
251
  isDataPlanSlug,
249
252
  isEmpty,
253
+ isValidCustomFlagProperty,
250
254
  };
package/src/validators.ts CHANGED
@@ -1,5 +1,11 @@
1
1
  import Types from './types';
2
- import { isFunction, isNumber, isObject, isStringOrNumber, valueof } from './utils';
2
+ import {
3
+ isFunction,
4
+ isNumber,
5
+ isObject,
6
+ isStringOrNumber,
7
+ valueof,
8
+ } from './utils';
3
9
  import Constants from './constants';
4
10
  import { IdentityApiData } from '@mparticle/web-sdk';
5
11
 
@@ -10,6 +16,8 @@ type ValidationIdentitiesReturn = {
10
16
  error?: valueof<typeof Constants.Messages.ValidationMessages>;
11
17
  };
12
18
 
19
+ const { Modify } = Constants.IdentityMethods;
20
+
13
21
  const Validators = {
14
22
  // From ./utils
15
23
  // Utility Functions for backwards compatability
@@ -43,7 +51,7 @@ const Validators = {
43
51
  copyUserAttributes: 1,
44
52
  };
45
53
  if (identityApiData) {
46
- if (method === 'modify') {
54
+ if (method === Modify) {
47
55
  if (
48
56
  (isObject(identityApiData.userIdentities) &&
49
57
  !Object.keys(identityApiData.userIdentities).length) ||