@mparticle/web-sdk 2.21.0 → 2.21.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mparticle/web-sdk",
3
- "version": "2.21.0",
3
+ "version": "2.21.2",
4
4
  "description": "mParticle core SDK for web applications",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
@@ -29,19 +29,24 @@
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",
44
- "test:requirejs": "npm run test:requirejs:before && npm run test:requirejs:after",
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",
49
+ "test:requirejs": "npm run build && 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",
47
52
  "test:karma:webpack:cjs": "cross-env BUNDLER=webpack karma start test/integrations/cjs/karma.webpack.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,8 @@
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",
111
+ "jest-environment-jsdom": "^29.5.0",
101
112
  "karma": "^6.3.2",
102
113
  "karma-chai": "^0.1.0",
103
114
  "karma-chrome-launcher": "^3.1.0",
@@ -115,6 +126,7 @@
115
126
  "shelljs": "^0.8.4",
116
127
  "should": "^7.1.0",
117
128
  "sinon": "^11.0.0",
129
+ "ts-jest": "^29.1.0",
118
130
  "tslib": "^2.1.0",
119
131
  "typescript": "^5.0.2",
120
132
  "uglify-js": "^3.4.9",
package/src/apiClient.ts CHANGED
@@ -8,17 +8,14 @@ import {
8
8
  SDKEvent,
9
9
  } from './sdkRuntimeModels';
10
10
  import KitBlocker from './kitBlocking';
11
- import { Dictionary, getRampNumber } from './utils';
11
+ import { Dictionary, getRampNumber, isEmpty } from './utils';
12
12
  import { IUploadObject } from './serverModel';
13
13
 
14
- const Messages = Constants.Messages;
15
-
16
14
  export type ForwardingStatsData = Dictionary<any>;
17
15
 
18
16
  export interface IAPIClient {
19
17
  uploader: BatchUploader | null;
20
18
  queueEventForBatchUpload: (event: SDKEvent) => void;
21
- shouldEnableBatching: () => boolean;
22
19
  processQueuedEvents: () => void;
23
20
  appendUserInfoToEvents: (user: MParticleUser, events: SDKEvent[]) => void;
24
21
  sendEventToServer: (event: SDKEvent, _options?: Dictionary<any>) => void;
@@ -55,22 +52,6 @@ export default function APIClient(
55
52
  mpInstance._Persistence.update();
56
53
  };
57
54
 
58
- this.shouldEnableBatching = function() {
59
- // Returns a string of a number that must be parsed
60
- // Invalid strings will be parsed to NaN which is falsey
61
- const eventsV3Percentage = parseInt(
62
- mpInstance._Helpers.getFeatureFlag(Constants.FeatureFlags.EventsV3),
63
- 10
64
- );
65
-
66
- if (!eventsV3Percentage) {
67
- return false;
68
- }
69
-
70
- const rampNumber = getRampNumber(mpInstance._Store.deviceId);
71
- return eventsV3Percentage >= rampNumber;
72
- };
73
-
74
55
  this.processQueuedEvents = function() {
75
56
  let mpid,
76
57
  currentUser = mpInstance.Identity.getCurrentUser();
@@ -135,15 +116,15 @@ export default function APIClient(
135
116
 
136
117
  this.processQueuedEvents();
137
118
 
138
- if (event && options.shouldUploadEvent) {
139
- if (this.shouldEnableBatching()) {
140
- this.queueEventForBatchUpload(event);
141
- } else {
142
- this.sendSingleEventToServer(event);
143
- }
119
+ if (isEmpty(event)) {
120
+ return;
121
+ }
122
+
123
+ if (options.shouldUploadEvent) {
124
+ this.queueEventForBatchUpload(event);
144
125
  }
145
126
 
146
- if (event && event.EventName !== Types.MessageType.AppStateTransition) {
127
+ if (event.EventName !== Types.MessageType.AppStateTransition) {
147
128
  if (kitBlocker && kitBlocker.kitBlockingEnabled) {
148
129
  event = kitBlocker.createBlockedEvent(event);
149
130
  }
@@ -156,50 +137,6 @@ export default function APIClient(
156
137
  }
157
138
  };
158
139
 
159
- this.sendSingleEventToServer = function(event) {
160
- if (event.EventDataType === Types.MessageType.Media) {
161
- return;
162
- }
163
- let xhr,
164
- xhrCallback = function() {
165
- if (xhr.readyState === 4) {
166
- mpInstance.Logger.verbose(
167
- 'Received ' + xhr.statusText + ' from server'
168
- );
169
- mpInstance._Persistence.update();
170
- }
171
- };
172
-
173
- if (!event) {
174
- mpInstance.Logger.error(Messages.ErrorMessages.EventEmpty);
175
- return;
176
- }
177
- mpInstance.Logger.verbose(Messages.InformationMessages.SendHttp);
178
- xhr = mpInstance._Helpers.createXHR(xhrCallback);
179
- if (xhr) {
180
- try {
181
- xhr.open(
182
- 'post',
183
- mpInstance._Helpers.createServiceUrl(
184
- mpInstance._Store.SDKConfig.v2SecureServiceUrl,
185
- mpInstance._Store.devToken
186
- ) + '/Events'
187
- );
188
- xhr.send(
189
- JSON.stringify(
190
- mpInstance._ServerModel.convertEventToV2DTO(
191
- event as IUploadObject
192
- )
193
- )
194
- );
195
- } catch (e) {
196
- mpInstance.Logger.error(
197
- 'Error sending event to mParticle servers. ' + e
198
- );
199
- }
200
- }
201
- };
202
-
203
140
  this.sendBatchForwardingStatsToServer = function(forwardingStatsData, xhr) {
204
141
  let url;
205
142
  let data;
package/src/constants.ts CHANGED
@@ -159,7 +159,6 @@ const Constants = {
159
159
  },
160
160
  FeatureFlags: {
161
161
  ReportBatching: 'reportBatching',
162
- EventsV3: 'eventsV3',
163
162
  EventBatchingIntervalMillis: 'eventBatchingIntervalMillis',
164
163
  OfflineStorage: 'offlineStorage',
165
164
  },
package/src/identity.js CHANGED
@@ -1058,42 +1058,36 @@ export default function Identity(mpInstance) {
1058
1058
  mpInstance._Persistence.savePersistence(cookies, mpid);
1059
1059
  }
1060
1060
 
1061
- if (mpInstance._APIClient.shouldEnableBatching()) {
1062
- // If the new attributeList length is different previous, then there is a change event.
1063
- // Loop through new attributes list, see if they are all in the same index as previous user attributes list
1064
- // If there are any changes, break, and immediately send a userAttributeChangeEvent with full array as a value
1065
- if (
1066
- !previousUserAttributeValue ||
1067
- !Array.isArray(previousUserAttributeValue)
1068
- ) {
1069
- userAttributeChange = true;
1070
- } else if (
1071
- newValue.length !==
1072
- previousUserAttributeValue.length
1073
- ) {
1074
- userAttributeChange = true;
1075
- } else {
1076
- for (var i = 0; i < newValue.length; i++) {
1077
- if (
1078
- previousUserAttributeValue[i] !==
1079
- newValue[i]
1080
- ) {
1081
- userAttributeChange = true;
1082
- break;
1083
- }
1061
+ // If the new attributeList length is different previous, then there is a change event.
1062
+ // Loop through new attributes list, see if they are all in the same index as previous user attributes list
1063
+ // If there are any changes, break, and immediately send a userAttributeChangeEvent with full array as a value
1064
+ if (
1065
+ !previousUserAttributeValue ||
1066
+ !Array.isArray(previousUserAttributeValue)
1067
+ ) {
1068
+ userAttributeChange = true;
1069
+ } else if (
1070
+ newValue.length !== previousUserAttributeValue.length
1071
+ ) {
1072
+ userAttributeChange = true;
1073
+ } else {
1074
+ for (var i = 0; i < newValue.length; i++) {
1075
+ if (previousUserAttributeValue[i] !== newValue[i]) {
1076
+ userAttributeChange = true;
1077
+ break;
1084
1078
  }
1085
1079
  }
1080
+ }
1086
1081
 
1087
- if (userAttributeChange) {
1088
- self.sendUserAttributeChangeEvent(
1089
- key,
1090
- newValue,
1091
- previousUserAttributeValue,
1092
- isNewAttribute,
1093
- false,
1094
- this
1095
- );
1096
- }
1082
+ if (userAttributeChange) {
1083
+ self.sendUserAttributeChangeEvent(
1084
+ key,
1085
+ newValue,
1086
+ previousUserAttributeValue,
1087
+ isNewAttribute,
1088
+ false,
1089
+ this
1090
+ );
1097
1091
  }
1098
1092
 
1099
1093
  mpInstance._Forwarders.initForwarders(
@@ -1563,29 +1557,15 @@ export default function Identity(mpInstance) {
1563
1557
  mpInstance._Store.currentSessionMPIDs
1564
1558
  );
1565
1559
 
1566
- //if there is any previous migration data
1567
- if (Object.keys(mpInstance._Store.migrationData).length) {
1568
- newIdentitiesByType =
1569
- mpInstance._Store.migrationData.userIdentities ||
1570
- {};
1571
- var userAttributes =
1572
- mpInstance._Store.migrationData.userAttributes ||
1573
- {};
1574
- mpInstance._Persistence.saveUserAttributesToPersistence(
1575
- identityApiResult.mpid,
1576
- userAttributes
1560
+ if (
1561
+ identityApiData &&
1562
+ identityApiData.userIdentities &&
1563
+ Object.keys(identityApiData.userIdentities).length
1564
+ ) {
1565
+ newIdentitiesByType = self.IdentityRequest.combineUserIdentities(
1566
+ incomingMpidUIByName,
1567
+ identityApiData.userIdentities
1577
1568
  );
1578
- } else {
1579
- if (
1580
- identityApiData &&
1581
- identityApiData.userIdentities &&
1582
- Object.keys(identityApiData.userIdentities).length
1583
- ) {
1584
- newIdentitiesByType = self.IdentityRequest.combineUserIdentities(
1585
- incomingMpidUIByName,
1586
- identityApiData.userIdentities
1587
- );
1588
- }
1589
1569
  }
1590
1570
 
1591
1571
  mpInstance._Persistence.saveUserIdentitiesToPersistence(
@@ -1730,10 +1710,6 @@ export default function Identity(mpInstance) {
1730
1710
  ) {
1731
1711
  var currentUserInMemory, userIdentityChangeEvent;
1732
1712
 
1733
- if (!mpInstance._APIClient.shouldEnableBatching()) {
1734
- return;
1735
- }
1736
-
1737
1713
  if (!mpid) {
1738
1714
  if (method !== 'modify') {
1739
1715
  return;
@@ -1799,9 +1775,6 @@ export default function Identity(mpInstance) {
1799
1775
  deleted,
1800
1776
  user
1801
1777
  ) {
1802
- if (!mpInstance._APIClient.shouldEnableBatching()) {
1803
- return;
1804
- }
1805
1778
  var userAttributeChangeEvent = self.createUserAttributeChange(
1806
1779
  attributeKey,
1807
1780
  newUserAttributeValue,
@@ -6,7 +6,7 @@ import { convertEvents } from './sdkToEventsApiConverter';
6
6
  import * as EventsApi from '@mparticle/event-models';
7
7
  import { Batch } from '@mparticle/event-models';
8
8
 
9
- const mockFunction = function () {
9
+ const mockFunction = function() {
10
10
  return null;
11
11
  };
12
12
  export default class _BatchValidator {
@@ -14,12 +14,12 @@ export default class _BatchValidator {
14
14
  return {
15
15
  // Certain Helper, Store, and Identity properties need to be mocked to be used in the `returnBatch` method
16
16
  _Helpers: {
17
- sanitizeAttributes:
18
- window.mParticle.getInstance()._Helpers.sanitizeAttributes,
19
- generateHash: function () {
17
+ sanitizeAttributes: window.mParticle.getInstance()._Helpers
18
+ .sanitizeAttributes,
19
+ generateHash: function() {
20
20
  return 'mockHash';
21
21
  },
22
- generateUniqueId: function () {
22
+ generateUniqueId: function() {
23
23
  return 'mockId';
24
24
  },
25
25
  extend: window.mParticle.getInstance()._Helpers.extend,
@@ -50,7 +50,6 @@ export default class _BatchValidator {
50
50
  consentState: null,
51
51
  clientId: null,
52
52
  deviceId: null,
53
- migrationData: {},
54
53
  serverSettings: {},
55
54
  dateLastEventSent: null,
56
55
  sessionStartDate: null,
@@ -64,7 +63,6 @@ export default class _BatchValidator {
64
63
  context: null,
65
64
  configurationLoaded: false,
66
65
  identityCallInFlight: false,
67
- migratingToIDSyncCookies: false,
68
66
  nonCurrentUserMPIDs: {},
69
67
  identifyCalled: false,
70
68
  isLoggedIn: false,
@@ -128,7 +126,7 @@ export default class _BatchValidator {
128
126
  const mpInstance = this.getMPInstance();
129
127
 
130
128
  const sdkEvents: SDKEvent[] = Array.isArray(events)
131
- ? events.map((event) => this.createSDKEventFunction(event))
129
+ ? events.map(event => this.createSDKEventFunction(event))
132
130
  : [this.createSDKEventFunction(events)];
133
131
 
134
132
  const batch: Batch = convertEvents('0', sdkEvents, mpInstance as any);
@@ -28,7 +28,6 @@ import Store from './store';
28
28
  import Logger from './logger';
29
29
  import Persistence from './persistence';
30
30
  import Events from './events';
31
- import Migrations from './migrations';
32
31
  import Forwarders from './forwarders';
33
32
  import ServerModel from './serverModel';
34
33
  import ForwardingStatsUploader from './forwardingStatsUploader';
@@ -59,7 +58,6 @@ export default function mParticleInstance(instanceName) {
59
58
  // These classes are for internal use only. Not documented for public consumption
60
59
  this._instanceName = instanceName;
61
60
  this._NativeSdkHelpers = new NativeSdkHelpers(this);
62
- this._Migrations = new Migrations(this);
63
61
  this._SessionManager = new SessionManager(this);
64
62
  this._Persistence = new Persistence(this);
65
63
  this._Helpers = new Helpers(this);
@@ -1290,18 +1288,6 @@ function completeSDKInitialization(apiKey, config, mpInstance) {
1290
1288
  mpInstance._APIClient = new APIClient(mpInstance, kitBlocker);
1291
1289
  mpInstance._Forwarders = new Forwarders(mpInstance, kitBlocker);
1292
1290
  if (config.flags) {
1293
- if (config.flags.hasOwnProperty(Constants.FeatureFlags.EventsV3)) {
1294
- // TODO: Remove this after 8/12/2022
1295
- if (config.flags[Constants.FeatureFlags.EventsV3] !== '100') {
1296
- var message =
1297
- 'mParticle will be enabling Event Batching for all customers on July 12, 2022. ' +
1298
- 'For more details, please see our docs: https://docs.mparticle.com/developers/sdk/web/getting-started/';
1299
- mpInstance.Logger.warning(message);
1300
- }
1301
-
1302
- mpInstance._Store.SDKConfig.flags[Constants.FeatureFlags.EventsV3] =
1303
- config.flags[Constants.FeatureFlags.EventsV3];
1304
- }
1305
1291
  if (
1306
1292
  config.flags.hasOwnProperty(
1307
1293
  Constants.FeatureFlags.EventBatchingIntervalMillis
@@ -1345,9 +1331,6 @@ function completeSDKInitialization(apiKey, config, mpInstance) {
1345
1331
  mpInstance._Store.configurationLoaded = true;
1346
1332
 
1347
1333
  if (!mpInstance._Store.webviewBridgeEnabled) {
1348
- // Migrate any cookies from previous versions to current cookie version
1349
- mpInstance._Migrations.migrate();
1350
-
1351
1334
  // Load any settings/identities/attributes from cookie or localStorage
1352
1335
  mpInstance._Persistence.initializeStorage();
1353
1336
  }
@@ -1398,15 +1381,6 @@ function completeSDKInitialization(apiKey, config, mpInstance) {
1398
1381
  };
1399
1382
  }
1400
1383
 
1401
- // 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
1402
- if (mpInstance._Store.migratingToIDSyncCookies) {
1403
- mpInstance.Identity.identify(
1404
- mpInstance._Store.SDKConfig.identifyRequest,
1405
- mpInstance._Store.SDKConfig.identityCallback
1406
- );
1407
- mpInstance._Store.migratingToIDSyncCookies = false;
1408
- }
1409
-
1410
1384
  currentUser = mpInstance.Identity.getCurrentUser();
1411
1385
 
1412
1386
  if (
@@ -1556,7 +1530,9 @@ function runPreConfigFetchInitialization(mpInstance, apiKey, config) {
1556
1530
  Messages.InformationMessages.StartingInitialization
1557
1531
  );
1558
1532
 
1559
- //check to see if localStorage is available for migrating purposes
1533
+ // Check to see if localStorage is available before main configuration runs
1534
+ // since we will need this for the current implementation of user persistence
1535
+ // TODO: Refactor this when we refactor User Identity Persistence
1560
1536
  try {
1561
1537
  mpInstance._Store.isLocalStorageAvailable = mpInstance._Persistence.determineLocalStorageAvailability(
1562
1538
  window.localStorage
@@ -98,16 +98,10 @@ export interface IPersistence {
98
98
  expires: string,
99
99
  domain: string,
100
100
  maxCookieSize: number
101
- ): void;
101
+ ): string;
102
102
  findPrevCookiesBasedOnUI(identityApiData: IdentityApiData): void;
103
- encodePersistence(persistance: IPersistenceMinified): string;
104
- decodePersistence(persistance: IPersistenceMinified): string;
105
- replaceCommasWithPipes(string: string): string;
106
- replacePipesWithCommas(string: string): string;
107
- replaceApostrophesWithQuotes(string: string): string;
108
- replaceQuotesWithApostrophes(string: string): string;
109
- createCookieString(string: string): string;
110
- revertCookieString(string: string): string;
103
+ encodePersistence(persistence: IPersistenceMinified): string;
104
+ decodePersistence(persistenceString: string): string;
111
105
  getCookieDomain(): string;
112
106
  getDomain(doc: string, locationHostname: string): string;
113
107
  getUserIdentities(mpid: MPID): UserIdentities;
@@ -1,5 +1,6 @@
1
1
  import Constants from './constants';
2
2
  import Polyfill from './polyfill';
3
+ import * as Utils from './utils';
3
4
 
4
5
  var Base64 = Polyfill.Base64,
5
6
  Messages = Constants.Messages,
@@ -760,13 +761,15 @@ export default function _Persistence(mpInstance) {
760
761
  }
761
762
  }
762
763
 
763
- return self.createCookieString(JSON.stringify(persistence));
764
+ return Utils.createCookieString(JSON.stringify(persistence));
764
765
  };
765
766
 
767
+ // TODO: This should actually be decodePersistenceString or
768
+ // we should refactor this to take a string and return an object
766
769
  this.decodePersistence = function(persistence) {
767
770
  try {
768
771
  if (persistence) {
769
- persistence = JSON.parse(self.revertCookieString(persistence));
772
+ persistence = JSON.parse(Utils.revertCookieString(persistence));
770
773
  if (
771
774
  mpInstance._Helpers.isObject(persistence) &&
772
775
  Object.keys(persistence).length
@@ -817,34 +820,6 @@ export default function _Persistence(mpInstance) {
817
820
  }
818
821
  };
819
822
 
820
- this.replaceCommasWithPipes = function(string) {
821
- return string.replace(/,/g, '|');
822
- };
823
-
824
- this.replacePipesWithCommas = function(string) {
825
- return string.replace(/\|/g, ',');
826
- };
827
-
828
- this.replaceApostrophesWithQuotes = function(string) {
829
- return string.replace(/\'/g, '"');
830
- };
831
-
832
- this.replaceQuotesWithApostrophes = function(string) {
833
- return string.replace(/\"/g, "'");
834
- };
835
-
836
- this.createCookieString = function(string) {
837
- return self.replaceCommasWithPipes(
838
- self.replaceQuotesWithApostrophes(string)
839
- );
840
- };
841
-
842
- this.revertCookieString = function(string) {
843
- return self.replacePipesWithCommas(
844
- self.replaceApostrophesWithQuotes(string)
845
- );
846
- };
847
-
848
823
  this.getCookieDomain = function() {
849
824
  if (mpInstance._Store.SDKConfig.cookieDomain) {
850
825
  return mpInstance._Store.SDKConfig.cookieDomain;
@@ -142,7 +142,11 @@ export interface MParticleWebSDK {
142
142
  _NativeSdkHelpers: any; // TODO: Set up API
143
143
  _Persistence: IPersistence;
144
144
  _preInit: any; // TODO: Set up API
145
- _resetForTests(MPConfig?: SDKInitConfig): void;
145
+ _resetForTests(
146
+ MPConfig?: SDKInitConfig,
147
+ keepPersistence?: boolean,
148
+ instance?: MParticleWebSDK
149
+ ): void;
146
150
  init(apiKey: string, config: SDKInitConfig, instanceName?: string): void;
147
151
  getAppName(): string;
148
152
  getAppVersion(): string;
package/src/store.ts CHANGED
@@ -97,9 +97,9 @@ function createSDKConfig(config: SDKInitConfig): SDKConfig {
97
97
  return sdkConfig;
98
98
  }
99
99
 
100
- // TODO: Placeholder Types, MigrationData is temporary and will be removed in the future to reduce SDK size
100
+ // TODO: Placeholder Types to be filled in as we migrate more modules
101
+ // to TypeScript
101
102
  export type PixelConfiguration = Dictionary;
102
- export type MigrationData = Dictionary;
103
103
  export type ServerSettings = Dictionary;
104
104
  export type SessionAttributes = Dictionary;
105
105
  export type IntegrationAttributes = Dictionary<Dictionary<string>>;
@@ -122,7 +122,6 @@ export interface IStore {
122
122
  clientId: string;
123
123
  deviceId: string;
124
124
  devToken: string | null;
125
- migrationData: MigrationData;
126
125
  serverSettings: ServerSettings;
127
126
  dateLastEventSent: Date;
128
127
  sessionStartDate: Date;
@@ -137,7 +136,6 @@ export interface IStore {
137
136
  configurationLoaded: boolean;
138
137
  identityCallInFlight: boolean;
139
138
  SDKConfig: Partial<SDKConfig>;
140
- migratingToIDSyncCookies: boolean; // TODO: Remove when we archive Web SDK v1
141
139
  nonCurrentUserMPIDs: Record<MPID, Dictionary>;
142
140
  identifyCalled: boolean;
143
141
  isLoggedIn: boolean;
@@ -173,7 +171,6 @@ export default function Store(
173
171
  clientId: null,
174
172
  deviceId: null,
175
173
  devToken: null,
176
- migrationData: {},
177
174
  serverSettings: {},
178
175
  dateLastEventSent: null,
179
176
  sessionStartDate: null,
@@ -188,7 +185,6 @@ export default function Store(
188
185
  configurationLoaded: false,
189
186
  identityCallInFlight: false,
190
187
  SDKConfig: {},
191
- migratingToIDSyncCookies: false,
192
188
  nonCurrentUserMPIDs: {},
193
189
  identifyCalled: false,
194
190
  isLoggedIn: false,
@@ -223,10 +219,9 @@ export default function Store(
223
219
  this.deviceId = config.deviceId;
224
220
  }
225
221
  if (config.hasOwnProperty('isDevelopmentMode')) {
226
- this.SDKConfig.isDevelopmentMode =
227
- mpInstance._Helpers.returnConvertedBoolean(
228
- config.isDevelopmentMode
229
- );
222
+ this.SDKConfig.isDevelopmentMode = mpInstance._Helpers.returnConvertedBoolean(
223
+ config.isDevelopmentMode
224
+ );
230
225
  } else {
231
226
  this.SDKConfig.isDevelopmentMode = false;
232
227
  }
@@ -421,13 +416,6 @@ export default function Store(
421
416
  if (!config.hasOwnProperty('flags')) {
422
417
  this.SDKConfig.flags = {};
423
418
  }
424
- if (
425
- !this.SDKConfig.flags.hasOwnProperty(
426
- Constants.FeatureFlags.EventsV3
427
- )
428
- ) {
429
- this.SDKConfig.flags[Constants.FeatureFlags.EventsV3] = 0;
430
- }
431
419
  if (
432
420
  !this.SDKConfig.flags.hasOwnProperty(
433
421
  Constants.FeatureFlags.EventBatchingIntervalMillis