@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.common.js +27 -36
- package/dist/mparticle.esm.js +27 -36
- package/dist/mparticle.js +62 -281
- package/package.json +21 -10
- package/src/identity.js +8 -22
- package/src/mockBatchCreator.ts +6 -8
- package/src/mp-instance.js +3 -15
- package/src/persistence.interfaces.ts +3 -9
- package/src/persistence.js +5 -30
- package/src/sdkRuntimeModels.ts +5 -1
- package/src/store.ts +5 -10
- package/src/utils.ts +22 -0
- package/src/migrations.js +0 -279
package/src/identity.js
CHANGED
|
@@ -1563,29 +1563,15 @@ export default function Identity(mpInstance) {
|
|
|
1563
1563
|
mpInstance._Store.currentSessionMPIDs
|
|
1564
1564
|
);
|
|
1565
1565
|
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
mpInstance._Persistence.saveUserAttributesToPersistence(
|
|
1575
|
-
identityApiResult.mpid,
|
|
1576
|
-
userAttributes
|
|
1566
|
+
if (
|
|
1567
|
+
identityApiData &&
|
|
1568
|
+
identityApiData.userIdentities &&
|
|
1569
|
+
Object.keys(identityApiData.userIdentities).length
|
|
1570
|
+
) {
|
|
1571
|
+
newIdentitiesByType = self.IdentityRequest.combineUserIdentities(
|
|
1572
|
+
incomingMpidUIByName,
|
|
1573
|
+
identityApiData.userIdentities
|
|
1577
1574
|
);
|
|
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
1575
|
}
|
|
1590
1576
|
|
|
1591
1577
|
mpInstance._Persistence.saveUserIdentitiesToPersistence(
|
package/src/mockBatchCreator.ts
CHANGED
|
@@ -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
|
-
|
|
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(
|
|
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);
|
package/src/mp-instance.js
CHANGED
|
@@ -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);
|
|
@@ -1345,9 +1343,6 @@ function completeSDKInitialization(apiKey, config, mpInstance) {
|
|
|
1345
1343
|
mpInstance._Store.configurationLoaded = true;
|
|
1346
1344
|
|
|
1347
1345
|
if (!mpInstance._Store.webviewBridgeEnabled) {
|
|
1348
|
-
// Migrate any cookies from previous versions to current cookie version
|
|
1349
|
-
mpInstance._Migrations.migrate();
|
|
1350
|
-
|
|
1351
1346
|
// Load any settings/identities/attributes from cookie or localStorage
|
|
1352
1347
|
mpInstance._Persistence.initializeStorage();
|
|
1353
1348
|
}
|
|
@@ -1398,15 +1393,6 @@ function completeSDKInitialization(apiKey, config, mpInstance) {
|
|
|
1398
1393
|
};
|
|
1399
1394
|
}
|
|
1400
1395
|
|
|
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
1396
|
currentUser = mpInstance.Identity.getCurrentUser();
|
|
1411
1397
|
|
|
1412
1398
|
if (
|
|
@@ -1556,7 +1542,9 @@ function runPreConfigFetchInitialization(mpInstance, apiKey, config) {
|
|
|
1556
1542
|
Messages.InformationMessages.StartingInitialization
|
|
1557
1543
|
);
|
|
1558
1544
|
|
|
1559
|
-
//
|
|
1545
|
+
// Check to see if localStorage is available before main configuration runs
|
|
1546
|
+
// since we will need this for the current implementation of user persistence
|
|
1547
|
+
// TODO: Refactor this when we refactor User Identity Persistence
|
|
1560
1548
|
try {
|
|
1561
1549
|
mpInstance._Store.isLocalStorageAvailable = mpInstance._Persistence.determineLocalStorageAvailability(
|
|
1562
1550
|
window.localStorage
|
|
@@ -98,16 +98,10 @@ export interface IPersistence {
|
|
|
98
98
|
expires: string,
|
|
99
99
|
domain: string,
|
|
100
100
|
maxCookieSize: number
|
|
101
|
-
):
|
|
101
|
+
): string;
|
|
102
102
|
findPrevCookiesBasedOnUI(identityApiData: IdentityApiData): void;
|
|
103
|
-
encodePersistence(
|
|
104
|
-
decodePersistence(
|
|
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;
|
package/src/persistence.js
CHANGED
|
@@ -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
|
|
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(
|
|
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;
|
package/src/sdkRuntimeModels.ts
CHANGED
|
@@ -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(
|
|
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
|
|
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
|
-
|
|
228
|
-
|
|
229
|
-
);
|
|
222
|
+
this.SDKConfig.isDevelopmentMode = mpInstance._Helpers.returnConvertedBoolean(
|
|
223
|
+
config.isDevelopmentMode
|
|
224
|
+
);
|
|
230
225
|
} else {
|
|
231
226
|
this.SDKConfig.isDevelopmentMode = false;
|
|
232
227
|
}
|
package/src/utils.ts
CHANGED
|
@@ -5,6 +5,12 @@ type valueof<T> = T[keyof T];
|
|
|
5
5
|
// Placeholder for Dictionary-like Types
|
|
6
6
|
export type Dictionary<V = any> = Record<string, V>;
|
|
7
7
|
|
|
8
|
+
const createCookieString = (value: string): string =>
|
|
9
|
+
replaceCommasWithPipes(replaceQuotesWithApostrophes(value));
|
|
10
|
+
|
|
11
|
+
const revertCookieString = (value: string): string =>
|
|
12
|
+
replacePipesWithCommas(replaceApostrophesWithQuotes(value));
|
|
13
|
+
|
|
8
14
|
const inArray = (items: any[], name: string): boolean => {
|
|
9
15
|
let i = 0;
|
|
10
16
|
|
|
@@ -134,6 +140,16 @@ const parseStringOrNumber = (
|
|
|
134
140
|
}
|
|
135
141
|
};
|
|
136
142
|
|
|
143
|
+
const replaceCommasWithPipes = (value: string): string => value.replace(/,/g, '|');
|
|
144
|
+
|
|
145
|
+
const replacePipesWithCommas = (value: string): string => value.replace(/\|/g, ',');
|
|
146
|
+
|
|
147
|
+
const replaceApostrophesWithQuotes = (value: string): string =>
|
|
148
|
+
value.replace(/\'/g, '"');
|
|
149
|
+
|
|
150
|
+
const replaceQuotesWithApostrophes = (value: string): string =>
|
|
151
|
+
value.replace(/\"/g, "'");
|
|
152
|
+
|
|
137
153
|
// FIXME: REFACTOR for V3
|
|
138
154
|
// only used in store.js to sanitize server-side formatting of
|
|
139
155
|
// booleans when checking for `isDevelopmentMode`
|
|
@@ -172,6 +188,8 @@ const isEmpty = (value: Dictionary<any> | null | undefined): boolean =>
|
|
|
172
188
|
value == null || !(Object.keys(value) || value).length;
|
|
173
189
|
|
|
174
190
|
export {
|
|
191
|
+
createCookieString,
|
|
192
|
+
revertCookieString,
|
|
175
193
|
valueof,
|
|
176
194
|
converted,
|
|
177
195
|
decoded,
|
|
@@ -184,6 +202,10 @@ export {
|
|
|
184
202
|
isStringOrNumber,
|
|
185
203
|
parseNumber,
|
|
186
204
|
parseStringOrNumber,
|
|
205
|
+
replaceCommasWithPipes,
|
|
206
|
+
replacePipesWithCommas,
|
|
207
|
+
replaceApostrophesWithQuotes,
|
|
208
|
+
replaceQuotesWithApostrophes,
|
|
187
209
|
returnConvertedBoolean,
|
|
188
210
|
isString,
|
|
189
211
|
isNumber,
|
package/src/migrations.js
DELETED
|
@@ -1,279 +0,0 @@
|
|
|
1
|
-
import Constants from './constants';
|
|
2
|
-
import Polyfill from './polyfill';
|
|
3
|
-
|
|
4
|
-
var StorageNames = Constants.StorageNames,
|
|
5
|
-
Base64 = Polyfill.Base64,
|
|
6
|
-
CookiesGlobalSettingsKeys = {
|
|
7
|
-
das: 1,
|
|
8
|
-
},
|
|
9
|
-
MPIDKeys = {
|
|
10
|
-
ui: 1,
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export default function Migrations(mpInstance) {
|
|
14
|
-
var self = this;
|
|
15
|
-
// if there is a cookie or localStorage:
|
|
16
|
-
// 1. determine which version it is ('mprtcl-api', 'mprtcl-v2', 'mprtcl-v3', 'mprtcl-v4')
|
|
17
|
-
// 2. return if 'mprtcl-v4', otherwise migrate to mprtclv4 schema
|
|
18
|
-
// 3. if 'mprtcl-api', could be JSSDKv2 or JSSDKv1. JSSDKv2 cookie has a 'globalSettings' key on it
|
|
19
|
-
this.migrate = function() {
|
|
20
|
-
try {
|
|
21
|
-
migrateCookies();
|
|
22
|
-
} catch (e) {
|
|
23
|
-
mpInstance._Persistence.expireCookies(StorageNames.cookieNameV3);
|
|
24
|
-
mpInstance._Persistence.expireCookies(StorageNames.cookieNameV4);
|
|
25
|
-
mpInstance.Logger.error('Error migrating cookie: ' + e);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (mpInstance._Store.isLocalStorageAvailable) {
|
|
29
|
-
try {
|
|
30
|
-
migrateLocalStorage();
|
|
31
|
-
} catch (e) {
|
|
32
|
-
localStorage.removeItem(StorageNames.localStorageNameV3);
|
|
33
|
-
localStorage.removeItem(StorageNames.localStorageNameV4);
|
|
34
|
-
mpInstance.Logger.error('Error migrating localStorage: ' + e);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
function migrateCookies() {
|
|
40
|
-
var cookies = window.document.cookie.split('; '),
|
|
41
|
-
foundCookie,
|
|
42
|
-
i,
|
|
43
|
-
l,
|
|
44
|
-
parts,
|
|
45
|
-
name,
|
|
46
|
-
cookie;
|
|
47
|
-
|
|
48
|
-
mpInstance.Logger.verbose(
|
|
49
|
-
Constants.Messages.InformationMessages.CookieSearch
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
for (i = 0, l = cookies.length; i < l; i++) {
|
|
53
|
-
try {
|
|
54
|
-
parts = cookies[i].split('=');
|
|
55
|
-
name = mpInstance._Helpers.decoded(parts.shift());
|
|
56
|
-
cookie = mpInstance._Helpers.decoded(parts.join('='));
|
|
57
|
-
} catch (e) {
|
|
58
|
-
mpInstance.Logger.verbose(
|
|
59
|
-
'Unable to parse cookie: ' + name + '. Skipping.'
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
//most recent version needs no migration
|
|
64
|
-
if (name === mpInstance._Store.storageName) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
if (name === StorageNames.cookieNameV4) {
|
|
68
|
-
// adds cookies to new namespace, removes previous cookie
|
|
69
|
-
finishCookieMigration(cookie, StorageNames.cookieNameV4);
|
|
70
|
-
if (mpInstance._Store.isLocalStorageAvailable) {
|
|
71
|
-
migrateProductsToNameSpace();
|
|
72
|
-
}
|
|
73
|
-
return;
|
|
74
|
-
// migration path for SDKv1CookiesV3, doesn't need to be encoded
|
|
75
|
-
}
|
|
76
|
-
if (name === StorageNames.cookieNameV3) {
|
|
77
|
-
foundCookie = self.convertSDKv1CookiesV3ToSDKv2CookiesV4(
|
|
78
|
-
cookie
|
|
79
|
-
);
|
|
80
|
-
finishCookieMigration(foundCookie, StorageNames.cookieNameV3);
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function finishCookieMigration(cookie, cookieName) {
|
|
87
|
-
var date = new Date(),
|
|
88
|
-
cookieDomain = mpInstance._Persistence.getCookieDomain(),
|
|
89
|
-
expires,
|
|
90
|
-
domain;
|
|
91
|
-
|
|
92
|
-
expires = new Date(
|
|
93
|
-
date.getTime() + StorageNames.CookieExpiration * 24 * 60 * 60 * 1000
|
|
94
|
-
).toGMTString();
|
|
95
|
-
|
|
96
|
-
if (cookieDomain === '') {
|
|
97
|
-
domain = '';
|
|
98
|
-
} else {
|
|
99
|
-
domain = ';domain=' + cookieDomain;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
mpInstance.Logger.verbose(
|
|
103
|
-
Constants.Messages.InformationMessages.CookieSet
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
window.document.cookie =
|
|
107
|
-
encodeURIComponent(mpInstance._Store.storageName) +
|
|
108
|
-
'=' +
|
|
109
|
-
cookie +
|
|
110
|
-
';expires=' +
|
|
111
|
-
expires +
|
|
112
|
-
';path=/' +
|
|
113
|
-
domain;
|
|
114
|
-
|
|
115
|
-
mpInstance._Persistence.expireCookies(cookieName);
|
|
116
|
-
mpInstance._Store.migratingToIDSyncCookies = true;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
this.convertSDKv1CookiesV3ToSDKv2CookiesV4 = function(SDKv1CookiesV3) {
|
|
120
|
-
SDKv1CookiesV3 = mpInstance._Persistence.replacePipesWithCommas(
|
|
121
|
-
mpInstance._Persistence.replaceApostrophesWithQuotes(SDKv1CookiesV3)
|
|
122
|
-
);
|
|
123
|
-
var parsedSDKv1CookiesV3 = JSON.parse(SDKv1CookiesV3);
|
|
124
|
-
var parsedCookiesV4 = JSON.parse(restructureToV4Cookie(SDKv1CookiesV3));
|
|
125
|
-
|
|
126
|
-
if (parsedSDKv1CookiesV3.mpid) {
|
|
127
|
-
parsedCookiesV4.gs.csm.push(parsedSDKv1CookiesV3.mpid);
|
|
128
|
-
// all other values are already encoded, so we have to encode any new values
|
|
129
|
-
parsedCookiesV4.gs.csm = Base64.encode(
|
|
130
|
-
JSON.stringify(parsedCookiesV4.gs.csm)
|
|
131
|
-
);
|
|
132
|
-
migrateProductsFromSDKv1ToSDKv2CookiesV4(
|
|
133
|
-
parsedSDKv1CookiesV3,
|
|
134
|
-
parsedSDKv1CookiesV3.mpid
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return JSON.stringify(parsedCookiesV4);
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
function restructureToV4Cookie(cookies) {
|
|
142
|
-
try {
|
|
143
|
-
var cookiesV4Schema = { gs: { csm: [] } };
|
|
144
|
-
cookies = JSON.parse(cookies);
|
|
145
|
-
|
|
146
|
-
for (var key in cookies) {
|
|
147
|
-
if (cookies.hasOwnProperty(key)) {
|
|
148
|
-
if (CookiesGlobalSettingsKeys[key]) {
|
|
149
|
-
cookiesV4Schema.gs[key] = cookies[key];
|
|
150
|
-
} else if (key === 'mpid') {
|
|
151
|
-
cookiesV4Schema.cu = cookies[key];
|
|
152
|
-
} else if (cookies.mpid) {
|
|
153
|
-
cookiesV4Schema[cookies.mpid] =
|
|
154
|
-
cookiesV4Schema[cookies.mpid] || {};
|
|
155
|
-
if (MPIDKeys[key]) {
|
|
156
|
-
cookiesV4Schema[cookies.mpid][key] = cookies[key];
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
return JSON.stringify(cookiesV4Schema);
|
|
162
|
-
} catch (e) {
|
|
163
|
-
mpInstance.Logger.error(
|
|
164
|
-
'Failed to restructure previous cookie into most current cookie schema'
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function migrateProductsToNameSpace() {
|
|
170
|
-
var lsProdV4Name = StorageNames.localStorageProductsV4;
|
|
171
|
-
var products = localStorage.getItem(
|
|
172
|
-
StorageNames.localStorageProductsV4
|
|
173
|
-
);
|
|
174
|
-
localStorage.setItem(mpInstance._Store.prodStorageName, products);
|
|
175
|
-
localStorage.removeItem(lsProdV4Name);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function migrateProductsFromSDKv1ToSDKv2CookiesV4(cookies, mpid) {
|
|
179
|
-
if (!mpInstance._Store.isLocalStorageAvailable) {
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
var localStorageProducts = {};
|
|
184
|
-
localStorageProducts[mpid] = {};
|
|
185
|
-
if (cookies.cp) {
|
|
186
|
-
try {
|
|
187
|
-
localStorageProducts[mpid].cp = JSON.parse(
|
|
188
|
-
Base64.decode(cookies.cp)
|
|
189
|
-
);
|
|
190
|
-
} catch (e) {
|
|
191
|
-
localStorageProducts[mpid].cp = cookies.cp;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
if (!Array.isArray(localStorageProducts[mpid].cp)) {
|
|
195
|
-
localStorageProducts[mpid].cp = [];
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
localStorage.setItem(
|
|
200
|
-
mpInstance._Store.prodStorageName,
|
|
201
|
-
Base64.encode(JSON.stringify(localStorageProducts))
|
|
202
|
-
);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
function migrateLocalStorage() {
|
|
206
|
-
var cookies,
|
|
207
|
-
v3LSName = StorageNames.localStorageNameV3,
|
|
208
|
-
v4LSName = StorageNames.localStorageNameV4,
|
|
209
|
-
currentVersionLSData = window.localStorage.getItem(
|
|
210
|
-
mpInstance._Store.storageName
|
|
211
|
-
),
|
|
212
|
-
v4LSData,
|
|
213
|
-
v3LSData,
|
|
214
|
-
v3LSDataStringCopy;
|
|
215
|
-
|
|
216
|
-
if (currentVersionLSData) {
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
v4LSData = window.localStorage.getItem(v4LSName);
|
|
221
|
-
if (v4LSData) {
|
|
222
|
-
finishLSMigration(v4LSData, v4LSName);
|
|
223
|
-
migrateProductsToNameSpace();
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
v3LSData = window.localStorage.getItem(v3LSName);
|
|
228
|
-
if (v3LSData) {
|
|
229
|
-
mpInstance._Store.migratingToIDSyncCookies = true;
|
|
230
|
-
v3LSDataStringCopy = v3LSData.slice();
|
|
231
|
-
v3LSData = JSON.parse(
|
|
232
|
-
mpInstance._Persistence.replacePipesWithCommas(
|
|
233
|
-
mpInstance._Persistence.replaceApostrophesWithQuotes(
|
|
234
|
-
v3LSData
|
|
235
|
-
)
|
|
236
|
-
)
|
|
237
|
-
);
|
|
238
|
-
// localStorage may contain only products, or the full persistence
|
|
239
|
-
// when there is an MPID on the cookie, it is the full persistence
|
|
240
|
-
if (v3LSData.mpid) {
|
|
241
|
-
v3LSData = JSON.parse(
|
|
242
|
-
self.convertSDKv1CookiesV3ToSDKv2CookiesV4(
|
|
243
|
-
v3LSDataStringCopy
|
|
244
|
-
)
|
|
245
|
-
);
|
|
246
|
-
finishLSMigration(JSON.stringify(v3LSData), v3LSName);
|
|
247
|
-
return;
|
|
248
|
-
// if no MPID, it is only the products
|
|
249
|
-
} else if ((v3LSData.cp || v3LSData.pb) && !v3LSData.mpid) {
|
|
250
|
-
cookies = mpInstance._Persistence.getCookie();
|
|
251
|
-
if (cookies) {
|
|
252
|
-
migrateProductsFromSDKv1ToSDKv2CookiesV4(
|
|
253
|
-
v3LSData,
|
|
254
|
-
cookies.cu
|
|
255
|
-
);
|
|
256
|
-
localStorage.removeItem(StorageNames.localStorageNameV3);
|
|
257
|
-
return;
|
|
258
|
-
} else {
|
|
259
|
-
localStorage.removeItem(StorageNames.localStorageNameV3);
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
function finishLSMigration(data, lsName) {
|
|
266
|
-
try {
|
|
267
|
-
window.localStorage.setItem(
|
|
268
|
-
encodeURIComponent(mpInstance._Store.storageName),
|
|
269
|
-
data
|
|
270
|
-
);
|
|
271
|
-
} catch (e) {
|
|
272
|
-
mpInstance.Logger.error(
|
|
273
|
-
'Error with setting localStorage item.'
|
|
274
|
-
);
|
|
275
|
-
}
|
|
276
|
-
window.localStorage.removeItem(encodeURIComponent(lsName));
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|