@mparticle/web-sdk 2.46.0 → 2.47.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 +71 -79
- package/dist/mparticle.esm.js +71 -79
- package/dist/mparticle.js +98 -247
- package/package.json +1 -1
- package/src/batchUploader.ts +3 -1
- package/src/constants.ts +14 -2
- package/src/helpers.js +0 -10
- package/src/identity-user-interfaces.ts +2 -2
- package/src/identity.interfaces.ts +1 -1
- package/src/identity.js +29 -138
- package/src/mp-instance.ts +25 -30
- package/src/persistence.interfaces.ts +0 -5
- package/src/persistence.js +15 -166
- package/src/roktManager.ts +6 -3
- package/src/sdkRuntimeModels.ts +0 -1
- package/src/sessionManager.ts +1 -1
- package/src/store.ts +26 -15
- package/src/utils.ts +16 -9
- package/src/vault.ts +16 -0
|
@@ -115,8 +115,8 @@ export interface IdentityModifyResultBody {
|
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
export interface mParticleUserCart {
|
|
118
|
-
add(
|
|
119
|
-
remove(
|
|
118
|
+
add(): void;
|
|
119
|
+
remove(): void;
|
|
120
120
|
clear(): void;
|
|
121
121
|
getCartProducts(): SDKProduct[];
|
|
122
122
|
}
|
package/src/identity.js
CHANGED
|
@@ -1215,7 +1215,7 @@ export default function Identity(mpInstance) {
|
|
|
1215
1215
|
mpInstance.Logger.warning(
|
|
1216
1216
|
'Deprecated function Identity.getCurrentUser().getCart() will be removed in future releases'
|
|
1217
1217
|
);
|
|
1218
|
-
return self.mParticleUserCart(
|
|
1218
|
+
return self.mParticleUserCart();
|
|
1219
1219
|
},
|
|
1220
1220
|
|
|
1221
1221
|
/**
|
|
@@ -1286,133 +1286,37 @@ export default function Identity(mpInstance) {
|
|
|
1286
1286
|
* @class mParticle.Identity.getCurrentUser().getCart()
|
|
1287
1287
|
* @deprecated
|
|
1288
1288
|
*/
|
|
1289
|
-
this.mParticleUserCart = function(
|
|
1289
|
+
this.mParticleUserCart = function() {
|
|
1290
1290
|
return {
|
|
1291
1291
|
/**
|
|
1292
1292
|
* Adds a cart product to the user cart
|
|
1293
1293
|
* @method add
|
|
1294
|
-
* @param {Object} product the product
|
|
1295
|
-
* @param {Boolean} [logEvent] a boolean to log adding of the cart object. If blank, no logging occurs.
|
|
1296
1294
|
* @deprecated
|
|
1297
1295
|
*/
|
|
1298
|
-
add: function(
|
|
1296
|
+
add: function() {
|
|
1299
1297
|
mpInstance.Logger.warning(
|
|
1300
|
-
|
|
1298
|
+
generateDeprecationMessage(
|
|
1299
|
+
'Identity.getCurrentUser().getCart().add()',
|
|
1300
|
+
true,
|
|
1301
|
+
'eCommerce.logProductAction()',
|
|
1302
|
+
'https://docs.mparticle.com/developers/sdk/web/commerce-tracking'
|
|
1303
|
+
)
|
|
1301
1304
|
);
|
|
1302
|
-
var allProducts, userProducts, arrayCopy;
|
|
1303
|
-
|
|
1304
|
-
arrayCopy = Array.isArray(product)
|
|
1305
|
-
? product.slice()
|
|
1306
|
-
: [product];
|
|
1307
|
-
arrayCopy.forEach(function(product) {
|
|
1308
|
-
product.Attributes = mpInstance._Helpers.sanitizeAttributes(
|
|
1309
|
-
product.Attributes
|
|
1310
|
-
);
|
|
1311
|
-
});
|
|
1312
|
-
|
|
1313
|
-
if (mpInstance._Store.webviewBridgeEnabled) {
|
|
1314
|
-
mpInstance._NativeSdkHelpers.sendToNative(
|
|
1315
|
-
Constants.NativeSdkPaths.AddToCart,
|
|
1316
|
-
JSON.stringify(arrayCopy)
|
|
1317
|
-
);
|
|
1318
|
-
} else {
|
|
1319
|
-
mpInstance._SessionManager.resetSessionTimer();
|
|
1320
|
-
|
|
1321
|
-
userProducts = mpInstance._Persistence.getUserProductsFromLS(
|
|
1322
|
-
mpid
|
|
1323
|
-
);
|
|
1324
|
-
|
|
1325
|
-
userProducts = userProducts.concat(arrayCopy);
|
|
1326
|
-
|
|
1327
|
-
if (logEvent === true) {
|
|
1328
|
-
mpInstance._Events.logProductActionEvent(
|
|
1329
|
-
Types.ProductActionType.AddToCart,
|
|
1330
|
-
arrayCopy
|
|
1331
|
-
);
|
|
1332
|
-
}
|
|
1333
|
-
|
|
1334
|
-
var productsForMemory = {};
|
|
1335
|
-
productsForMemory[mpid] = { cp: userProducts };
|
|
1336
|
-
|
|
1337
|
-
if (
|
|
1338
|
-
userProducts.length >
|
|
1339
|
-
mpInstance._Store.SDKConfig.maxProducts
|
|
1340
|
-
) {
|
|
1341
|
-
mpInstance.Logger.verbose(
|
|
1342
|
-
'The cart contains ' +
|
|
1343
|
-
userProducts.length +
|
|
1344
|
-
' items. Only ' +
|
|
1345
|
-
mpInstance._Store.SDKConfig.maxProducts +
|
|
1346
|
-
' can currently be saved in cookies.'
|
|
1347
|
-
);
|
|
1348
|
-
userProducts = userProducts.slice(
|
|
1349
|
-
-mpInstance._Store.SDKConfig.maxProducts
|
|
1350
|
-
);
|
|
1351
|
-
}
|
|
1352
|
-
|
|
1353
|
-
allProducts = mpInstance._Persistence.getAllUserProductsFromLS();
|
|
1354
|
-
allProducts[mpid].cp = userProducts;
|
|
1355
|
-
|
|
1356
|
-
mpInstance._Persistence.setCartProducts(allProducts);
|
|
1357
|
-
}
|
|
1358
1305
|
},
|
|
1359
1306
|
/**
|
|
1360
1307
|
* Removes a cart product from the current user cart
|
|
1361
1308
|
* @method remove
|
|
1362
|
-
* @param {Object} product the product
|
|
1363
|
-
* @param {Boolean} [logEvent] a boolean to log adding of the cart object. If blank, no logging occurs.
|
|
1364
1309
|
* @deprecated
|
|
1365
1310
|
*/
|
|
1366
|
-
remove: function(
|
|
1311
|
+
remove: function() {
|
|
1367
1312
|
mpInstance.Logger.warning(
|
|
1368
|
-
|
|
1313
|
+
generateDeprecationMessage(
|
|
1314
|
+
'Identity.getCurrentUser().getCart().remove()',
|
|
1315
|
+
true,
|
|
1316
|
+
'eCommerce.logProductAction()',
|
|
1317
|
+
'https://docs.mparticle.com/developers/sdk/web/commerce-tracking'
|
|
1318
|
+
)
|
|
1369
1319
|
);
|
|
1370
|
-
var allProducts,
|
|
1371
|
-
userProducts,
|
|
1372
|
-
cartIndex = -1,
|
|
1373
|
-
cartItem = null;
|
|
1374
|
-
|
|
1375
|
-
if (mpInstance._Store.webviewBridgeEnabled) {
|
|
1376
|
-
mpInstance._NativeSdkHelpers.sendToNative(
|
|
1377
|
-
Constants.NativeSdkPaths.RemoveFromCart,
|
|
1378
|
-
JSON.stringify(product)
|
|
1379
|
-
);
|
|
1380
|
-
} else {
|
|
1381
|
-
mpInstance._SessionManager.resetSessionTimer();
|
|
1382
|
-
|
|
1383
|
-
userProducts = mpInstance._Persistence.getUserProductsFromLS(
|
|
1384
|
-
mpid
|
|
1385
|
-
);
|
|
1386
|
-
|
|
1387
|
-
if (userProducts) {
|
|
1388
|
-
userProducts.forEach(function(cartProduct, i) {
|
|
1389
|
-
if (cartProduct.Sku === product.Sku) {
|
|
1390
|
-
cartIndex = i;
|
|
1391
|
-
cartItem = cartProduct;
|
|
1392
|
-
}
|
|
1393
|
-
});
|
|
1394
|
-
|
|
1395
|
-
if (cartIndex > -1) {
|
|
1396
|
-
userProducts.splice(cartIndex, 1);
|
|
1397
|
-
|
|
1398
|
-
if (logEvent === true) {
|
|
1399
|
-
mpInstance._Events.logProductActionEvent(
|
|
1400
|
-
Types.ProductActionType.RemoveFromCart,
|
|
1401
|
-
cartItem
|
|
1402
|
-
);
|
|
1403
|
-
}
|
|
1404
|
-
}
|
|
1405
|
-
}
|
|
1406
|
-
|
|
1407
|
-
var productsForMemory = {};
|
|
1408
|
-
productsForMemory[mpid] = { cp: userProducts };
|
|
1409
|
-
|
|
1410
|
-
allProducts = mpInstance._Persistence.getAllUserProductsFromLS();
|
|
1411
|
-
|
|
1412
|
-
allProducts[mpid].cp = userProducts;
|
|
1413
|
-
|
|
1414
|
-
mpInstance._Persistence.setCartProducts(allProducts);
|
|
1415
|
-
}
|
|
1416
1320
|
},
|
|
1417
1321
|
/**
|
|
1418
1322
|
* Clears the user's cart
|
|
@@ -1421,31 +1325,13 @@ export default function Identity(mpInstance) {
|
|
|
1421
1325
|
*/
|
|
1422
1326
|
clear: function() {
|
|
1423
1327
|
mpInstance.Logger.warning(
|
|
1424
|
-
|
|
1328
|
+
generateDeprecationMessage(
|
|
1329
|
+
'Identity.getCurrentUser().getCart().clear()',
|
|
1330
|
+
true,
|
|
1331
|
+
'',
|
|
1332
|
+
'https://docs.mparticle.com/developers/sdk/web/commerce-tracking'
|
|
1333
|
+
)
|
|
1425
1334
|
);
|
|
1426
|
-
|
|
1427
|
-
var allProducts;
|
|
1428
|
-
|
|
1429
|
-
if (mpInstance._Store.webviewBridgeEnabled) {
|
|
1430
|
-
mpInstance._NativeSdkHelpers.sendToNative(
|
|
1431
|
-
Constants.NativeSdkPaths.ClearCart
|
|
1432
|
-
);
|
|
1433
|
-
} else {
|
|
1434
|
-
mpInstance._SessionManager.resetSessionTimer();
|
|
1435
|
-
allProducts = mpInstance._Persistence.getAllUserProductsFromLS();
|
|
1436
|
-
|
|
1437
|
-
if (
|
|
1438
|
-
allProducts &&
|
|
1439
|
-
allProducts[mpid] &&
|
|
1440
|
-
allProducts[mpid].cp
|
|
1441
|
-
) {
|
|
1442
|
-
allProducts[mpid].cp = [];
|
|
1443
|
-
|
|
1444
|
-
allProducts[mpid].cp = [];
|
|
1445
|
-
|
|
1446
|
-
mpInstance._Persistence.setCartProducts(allProducts);
|
|
1447
|
-
}
|
|
1448
|
-
}
|
|
1449
1335
|
},
|
|
1450
1336
|
/**
|
|
1451
1337
|
* Returns all cart products
|
|
@@ -1455,9 +1341,14 @@ export default function Identity(mpInstance) {
|
|
|
1455
1341
|
*/
|
|
1456
1342
|
getCartProducts: function() {
|
|
1457
1343
|
mpInstance.Logger.warning(
|
|
1458
|
-
|
|
1344
|
+
generateDeprecationMessage(
|
|
1345
|
+
'Identity.getCurrentUser().getCart().getCartProducts()',
|
|
1346
|
+
true,
|
|
1347
|
+
'eCommerce.logProductAction()',
|
|
1348
|
+
'https://docs.mparticle.com/developers/sdk/web/commerce-tracking'
|
|
1349
|
+
)
|
|
1459
1350
|
);
|
|
1460
|
-
return
|
|
1351
|
+
return [];
|
|
1461
1352
|
},
|
|
1462
1353
|
};
|
|
1463
1354
|
};
|
package/src/mp-instance.ts
CHANGED
|
@@ -36,8 +36,8 @@ import Consent, { IConsent } from './consent';
|
|
|
36
36
|
import KitBlocker from './kitBlocking';
|
|
37
37
|
import ConfigAPIClient, { IKitConfigs } from './configAPIClient';
|
|
38
38
|
import IdentityAPIClient from './identityApiClient';
|
|
39
|
-
import { isFunction, parseConfig, valueof } from './utils';
|
|
40
|
-
import { LocalStorageVault } from './vault';
|
|
39
|
+
import { isFunction, parseConfig, valueof, generateDeprecationMessage } from './utils';
|
|
40
|
+
import { DisabledVault, LocalStorageVault } from './vault';
|
|
41
41
|
import { removeExpiredIdentityCacheDates } from './identity-utils';
|
|
42
42
|
import IntegrationCapture from './integrationCapture';
|
|
43
43
|
import { IPreInit, processReadyQueue } from './pre-init-utils';
|
|
@@ -706,16 +706,13 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan
|
|
|
706
706
|
*/
|
|
707
707
|
add: function(product, logEventBoolean) {
|
|
708
708
|
self.Logger.warning(
|
|
709
|
-
|
|
709
|
+
generateDeprecationMessage(
|
|
710
|
+
'eCommerce.Cart.add()',
|
|
711
|
+
true,
|
|
712
|
+
'eCommerce.logProductAction()',
|
|
713
|
+
'https://docs.mparticle.com/developers/sdk/web/commerce-tracking'
|
|
714
|
+
)
|
|
710
715
|
);
|
|
711
|
-
let mpid;
|
|
712
|
-
const currentUser = self.Identity.getCurrentUser();
|
|
713
|
-
if (currentUser) {
|
|
714
|
-
mpid = currentUser.getMPID();
|
|
715
|
-
}
|
|
716
|
-
self._Identity
|
|
717
|
-
.mParticleUserCart(mpid)
|
|
718
|
-
.add(product, logEventBoolean);
|
|
719
716
|
},
|
|
720
717
|
/**
|
|
721
718
|
* Removes a product from the cart
|
|
@@ -726,16 +723,13 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan
|
|
|
726
723
|
*/
|
|
727
724
|
remove: function(product, logEventBoolean) {
|
|
728
725
|
self.Logger.warning(
|
|
729
|
-
|
|
726
|
+
generateDeprecationMessage(
|
|
727
|
+
'eCommerce.Cart.remove()',
|
|
728
|
+
true,
|
|
729
|
+
'eCommerce.logProductAction()',
|
|
730
|
+
'https://docs.mparticle.com/developers/sdk/web/commerce-tracking'
|
|
731
|
+
)
|
|
730
732
|
);
|
|
731
|
-
let mpid;
|
|
732
|
-
const currentUser = self.Identity.getCurrentUser();
|
|
733
|
-
if (currentUser) {
|
|
734
|
-
mpid = currentUser.getMPID();
|
|
735
|
-
}
|
|
736
|
-
self._Identity
|
|
737
|
-
.mParticleUserCart(mpid)
|
|
738
|
-
.remove(product, logEventBoolean);
|
|
739
733
|
},
|
|
740
734
|
/**
|
|
741
735
|
* Clears the cart
|
|
@@ -744,14 +738,13 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan
|
|
|
744
738
|
*/
|
|
745
739
|
clear: function() {
|
|
746
740
|
self.Logger.warning(
|
|
747
|
-
|
|
741
|
+
generateDeprecationMessage(
|
|
742
|
+
'eCommerce.Cart.clear()',
|
|
743
|
+
true,
|
|
744
|
+
'',
|
|
745
|
+
'https://docs.mparticle.com/developers/sdk/web/commerce-tracking'
|
|
746
|
+
)
|
|
748
747
|
);
|
|
749
|
-
let mpid;
|
|
750
|
-
const currentUser = self.Identity.getCurrentUser();
|
|
751
|
-
if (currentUser) {
|
|
752
|
-
mpid = currentUser.getMPID();
|
|
753
|
-
}
|
|
754
|
-
self._Identity.mParticleUserCart(mpid).clear();
|
|
755
748
|
},
|
|
756
749
|
},
|
|
757
750
|
/**
|
|
@@ -1534,9 +1527,11 @@ function createKitBlocker(config, mpInstance) {
|
|
|
1534
1527
|
}
|
|
1535
1528
|
|
|
1536
1529
|
function createIdentityCache(mpInstance) {
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1530
|
+
const cacheKey = `${mpInstance._Store.storageName}-id-cache`;
|
|
1531
|
+
if (mpInstance._Store.getPrivacyFlag('IdentityCache')) {
|
|
1532
|
+
return new DisabledVault(cacheKey, { logger: mpInstance.Logger });
|
|
1533
|
+
}
|
|
1534
|
+
return new LocalStorageVault(cacheKey, { logger: mpInstance.Logger });
|
|
1540
1535
|
}
|
|
1541
1536
|
|
|
1542
1537
|
function runPreConfigFetchInitialization(mpInstance, apiKey, config) {
|
|
@@ -99,11 +99,8 @@ export interface IPersistence {
|
|
|
99
99
|
useLocalStorage(): boolean;
|
|
100
100
|
initializeStorage(): void;
|
|
101
101
|
update(): void;
|
|
102
|
-
storeProductsInMemory(products: Product[], mpid: MPID): void;
|
|
103
102
|
storeDataInMemory(obj: IPersistenceMinified, currentMPID: MPID): void;
|
|
104
103
|
determineLocalStorageAvailability(storage: Storage): boolean;
|
|
105
|
-
getUserProductsFromLS(mpid: MPID): Product[];
|
|
106
|
-
getAllUserProductsFromLS(): Product[];
|
|
107
104
|
setLocalStorage(): void;
|
|
108
105
|
getLocalStorage(): IPersistenceMinified | null;
|
|
109
106
|
expireCookies(cookieName: string): void;
|
|
@@ -120,8 +117,6 @@ export interface IPersistence {
|
|
|
120
117
|
decodePersistence(persistenceString: string): string;
|
|
121
118
|
getCookieDomain(): string;
|
|
122
119
|
getDomain(doc: string, locationHostname: string): string;
|
|
123
|
-
getCartProducts(mpid: MPID): Product[];
|
|
124
|
-
setCartProducts(allProducts: Product[]): void;
|
|
125
120
|
saveUserCookieSyncDatesToPersistence(mpid: MPID, csd: CookieSyncDates): void;
|
|
126
121
|
savePersistence(persistance: IPersistenceMinified): void;
|
|
127
122
|
getPersistence(): IPersistenceMinified;
|
package/src/persistence.js
CHANGED
|
@@ -35,6 +35,10 @@ export default function _Persistence(mpInstance) {
|
|
|
35
35
|
mpInstance._Store.isFirstRun = false;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
if (mpInstance._Store.getPrivacyFlag('SDKState')) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
38
42
|
// https://go.mparticle.com/work/SQDSDKS-6045
|
|
39
43
|
if (!mpInstance._Store.isLocalStorageAvailable) {
|
|
40
44
|
mpInstance._Store.SDKConfig.useCookieStorage = true;
|
|
@@ -86,35 +90,6 @@ export default function _Persistence(mpInstance) {
|
|
|
86
90
|
self.storeDataInMemory(cookies);
|
|
87
91
|
}
|
|
88
92
|
|
|
89
|
-
// https://go.mparticle.com/work/SQDSDKS-6048
|
|
90
|
-
try {
|
|
91
|
-
if (mpInstance._Store.isLocalStorageAvailable) {
|
|
92
|
-
var encodedProducts = localStorage.getItem(
|
|
93
|
-
mpInstance._Store.prodStorageName
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
if (encodedProducts) {
|
|
97
|
-
var decodedProducts = JSON.parse(
|
|
98
|
-
Base64.decode(encodedProducts)
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
if (mpInstance._Store.mpid) {
|
|
102
|
-
self.storeProductsInMemory(
|
|
103
|
-
decodedProducts,
|
|
104
|
-
mpInstance._Store.mpid
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
} catch (e) {
|
|
109
|
-
if (mpInstance._Store.isLocalStorageAvailable) {
|
|
110
|
-
localStorage.removeItem(mpInstance._Store.prodStorageName);
|
|
111
|
-
}
|
|
112
|
-
mpInstance._Store.cartProducts = [];
|
|
113
|
-
mpInstance.Logger.error(
|
|
114
|
-
'Error loading products in initialization: ' + e
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
93
|
// https://go.mparticle.com/work/SQDSDKS-6046
|
|
119
94
|
// Stores all non-current user MPID information into the store
|
|
120
95
|
for (var key in allData) {
|
|
@@ -142,7 +117,10 @@ export default function _Persistence(mpInstance) {
|
|
|
142
117
|
};
|
|
143
118
|
|
|
144
119
|
this.update = function() {
|
|
145
|
-
if (
|
|
120
|
+
if (
|
|
121
|
+
!mpInstance._Store.webviewBridgeEnabled &&
|
|
122
|
+
!mpInstance._Store.getPrivacyFlag('SDKState')
|
|
123
|
+
) {
|
|
146
124
|
if (mpInstance._Store.SDKConfig.useCookieStorage) {
|
|
147
125
|
self.setCookie();
|
|
148
126
|
}
|
|
@@ -151,21 +129,6 @@ export default function _Persistence(mpInstance) {
|
|
|
151
129
|
}
|
|
152
130
|
};
|
|
153
131
|
|
|
154
|
-
this.storeProductsInMemory = function(products, mpid) {
|
|
155
|
-
if (products) {
|
|
156
|
-
try {
|
|
157
|
-
mpInstance._Store.cartProducts =
|
|
158
|
-
products[mpid] && products[mpid].cp
|
|
159
|
-
? products[mpid].cp
|
|
160
|
-
: [];
|
|
161
|
-
} catch (e) {
|
|
162
|
-
mpInstance.Logger.error(
|
|
163
|
-
Messages.ErrorMessages.CookieParseError
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
|
|
169
132
|
// https://go.mparticle.com/work/SQDSDKS-6045
|
|
170
133
|
this.storeDataInMemory = function(obj, currentMPID) {
|
|
171
134
|
try {
|
|
@@ -268,64 +231,6 @@ export default function _Persistence(mpInstance) {
|
|
|
268
231
|
}
|
|
269
232
|
};
|
|
270
233
|
|
|
271
|
-
this.getUserProductsFromLS = function(mpid) {
|
|
272
|
-
if (!mpInstance._Store.isLocalStorageAvailable) {
|
|
273
|
-
return [];
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
var decodedProducts,
|
|
277
|
-
userProducts,
|
|
278
|
-
parsedProducts,
|
|
279
|
-
encodedProducts = localStorage.getItem(
|
|
280
|
-
mpInstance._Store.prodStorageName
|
|
281
|
-
);
|
|
282
|
-
if (encodedProducts) {
|
|
283
|
-
decodedProducts = Base64.decode(encodedProducts);
|
|
284
|
-
}
|
|
285
|
-
// if there is an MPID, we are retrieving the user's products, which is an array
|
|
286
|
-
if (mpid) {
|
|
287
|
-
try {
|
|
288
|
-
if (decodedProducts) {
|
|
289
|
-
parsedProducts = JSON.parse(decodedProducts);
|
|
290
|
-
}
|
|
291
|
-
if (
|
|
292
|
-
decodedProducts &&
|
|
293
|
-
parsedProducts[mpid] &&
|
|
294
|
-
parsedProducts[mpid].cp &&
|
|
295
|
-
Array.isArray(parsedProducts[mpid].cp)
|
|
296
|
-
) {
|
|
297
|
-
userProducts = parsedProducts[mpid].cp;
|
|
298
|
-
} else {
|
|
299
|
-
userProducts = [];
|
|
300
|
-
}
|
|
301
|
-
return userProducts;
|
|
302
|
-
} catch (e) {
|
|
303
|
-
return [];
|
|
304
|
-
}
|
|
305
|
-
} else {
|
|
306
|
-
return [];
|
|
307
|
-
}
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
this.getAllUserProductsFromLS = function() {
|
|
311
|
-
var decodedProducts,
|
|
312
|
-
encodedProducts = localStorage.getItem(
|
|
313
|
-
mpInstance._Store.prodStorageName
|
|
314
|
-
),
|
|
315
|
-
parsedDecodedProducts;
|
|
316
|
-
if (encodedProducts) {
|
|
317
|
-
decodedProducts = Base64.decode(encodedProducts);
|
|
318
|
-
}
|
|
319
|
-
// returns an object with keys of MPID and values of array of products
|
|
320
|
-
try {
|
|
321
|
-
parsedDecodedProducts = JSON.parse(decodedProducts);
|
|
322
|
-
} catch (e) {
|
|
323
|
-
parsedDecodedProducts = {};
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
return parsedDecodedProducts;
|
|
327
|
-
};
|
|
328
|
-
|
|
329
234
|
// https://go.mparticle.com/work/SQDSDKS-6021
|
|
330
235
|
this.setLocalStorage = function() {
|
|
331
236
|
if (!mpInstance._Store.isLocalStorageAvailable) {
|
|
@@ -333,30 +238,9 @@ export default function _Persistence(mpInstance) {
|
|
|
333
238
|
}
|
|
334
239
|
|
|
335
240
|
var key = mpInstance._Store.storageName,
|
|
336
|
-
allLocalStorageProducts = self.getAllUserProductsFromLS(),
|
|
337
241
|
localStorageData = self.getLocalStorage() || {},
|
|
338
242
|
currentUser = mpInstance.Identity.getCurrentUser(),
|
|
339
|
-
mpid = currentUser ? currentUser.getMPID() : null
|
|
340
|
-
currentUserProducts = {
|
|
341
|
-
cp: allLocalStorageProducts[mpid]
|
|
342
|
-
? allLocalStorageProducts[mpid].cp
|
|
343
|
-
: [],
|
|
344
|
-
};
|
|
345
|
-
if (mpid) {
|
|
346
|
-
allLocalStorageProducts = allLocalStorageProducts || {};
|
|
347
|
-
allLocalStorageProducts[mpid] = currentUserProducts;
|
|
348
|
-
try {
|
|
349
|
-
window.localStorage.setItem(
|
|
350
|
-
encodeURIComponent(mpInstance._Store.prodStorageName),
|
|
351
|
-
Base64.encode(JSON.stringify(allLocalStorageProducts))
|
|
352
|
-
);
|
|
353
|
-
} catch (e) {
|
|
354
|
-
mpInstance.Logger.error(
|
|
355
|
-
'Error with setting products on localStorage.'
|
|
356
|
-
);
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
|
|
243
|
+
mpid = currentUser ? currentUser.getMPID() : null;
|
|
360
244
|
if (!mpInstance._Store.SDKConfig.useCookieStorage) {
|
|
361
245
|
localStorageData.gs = localStorageData.gs || {};
|
|
362
246
|
|
|
@@ -893,42 +777,6 @@ export default function _Persistence(mpInstance) {
|
|
|
893
777
|
return '';
|
|
894
778
|
};
|
|
895
779
|
|
|
896
|
-
this.getCartProducts = function(mpid) {
|
|
897
|
-
var allCartProducts,
|
|
898
|
-
cartProductsString = localStorage.getItem(
|
|
899
|
-
mpInstance._Store.prodStorageName
|
|
900
|
-
);
|
|
901
|
-
if (cartProductsString) {
|
|
902
|
-
allCartProducts = JSON.parse(Base64.decode(cartProductsString));
|
|
903
|
-
if (
|
|
904
|
-
allCartProducts &&
|
|
905
|
-
allCartProducts[mpid] &&
|
|
906
|
-
allCartProducts[mpid].cp
|
|
907
|
-
) {
|
|
908
|
-
return allCartProducts[mpid].cp;
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
|
|
912
|
-
return [];
|
|
913
|
-
};
|
|
914
|
-
|
|
915
|
-
this.setCartProducts = function(allProducts) {
|
|
916
|
-
if (!mpInstance._Store.isLocalStorageAvailable) {
|
|
917
|
-
return;
|
|
918
|
-
}
|
|
919
|
-
|
|
920
|
-
try {
|
|
921
|
-
window.localStorage.setItem(
|
|
922
|
-
encodeURIComponent(mpInstance._Store.prodStorageName),
|
|
923
|
-
Base64.encode(JSON.stringify(allProducts))
|
|
924
|
-
);
|
|
925
|
-
} catch (e) {
|
|
926
|
-
mpInstance.Logger.error(
|
|
927
|
-
'Error with setting products on localStorage.'
|
|
928
|
-
);
|
|
929
|
-
}
|
|
930
|
-
};
|
|
931
|
-
|
|
932
780
|
this.saveUserCookieSyncDatesToPersistence = function(mpid, csd) {
|
|
933
781
|
if (csd) {
|
|
934
782
|
var persistence = self.getPersistence();
|
|
@@ -962,6 +810,9 @@ export default function _Persistence(mpInstance) {
|
|
|
962
810
|
|
|
963
811
|
// https://go.mparticle.com/work/SQDSDKS-6021
|
|
964
812
|
this.savePersistence = function(persistence) {
|
|
813
|
+
if (mpInstance._Store.getPrivacyFlag('SDKState')) {
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
965
816
|
var encodedPersistence = self.encodePersistence(
|
|
966
817
|
JSON.stringify(persistence)
|
|
967
818
|
),
|
|
@@ -1006,6 +857,9 @@ export default function _Persistence(mpInstance) {
|
|
|
1006
857
|
};
|
|
1007
858
|
|
|
1008
859
|
this.getPersistence = function() {
|
|
860
|
+
if (mpInstance._Store.getPrivacyFlag('SDKState')) {
|
|
861
|
+
return null;
|
|
862
|
+
}
|
|
1009
863
|
var persistence = this.useLocalStorage()
|
|
1010
864
|
? this.getLocalStorage()
|
|
1011
865
|
: this.getCookie();
|
|
@@ -1098,7 +952,6 @@ export default function _Persistence(mpInstance) {
|
|
|
1098
952
|
removeLocalStorage(StorageNames.localStorageName);
|
|
1099
953
|
removeLocalStorage(StorageNames.localStorageNameV3);
|
|
1100
954
|
removeLocalStorage(StorageNames.localStorageNameV4);
|
|
1101
|
-
removeLocalStorage(mpInstance._Store.prodStorageName);
|
|
1102
955
|
removeLocalStorage(mpInstance._Store.storageName);
|
|
1103
956
|
removeLocalStorage(StorageNames.localStorageProductsV4);
|
|
1104
957
|
|
|
@@ -1106,7 +959,6 @@ export default function _Persistence(mpInstance) {
|
|
|
1106
959
|
self.expireCookies(StorageNames.cookieNameV2);
|
|
1107
960
|
self.expireCookies(StorageNames.cookieNameV3);
|
|
1108
961
|
self.expireCookies(StorageNames.cookieNameV4);
|
|
1109
|
-
self.expireCookies(mpInstance._Store.prodStorageName);
|
|
1110
962
|
self.expireCookies(mpInstance._Store.storageName);
|
|
1111
963
|
|
|
1112
964
|
if (mParticle._isTestEnv) {
|
|
@@ -1117,9 +969,6 @@ export default function _Persistence(mpInstance) {
|
|
|
1117
969
|
self.expireCookies(
|
|
1118
970
|
mpInstance._Helpers.createMainStorageName(testWorkspaceToken)
|
|
1119
971
|
);
|
|
1120
|
-
removeLocalStorage(
|
|
1121
|
-
mpInstance._Helpers.createProductStorageName(testWorkspaceToken)
|
|
1122
|
-
);
|
|
1123
972
|
}
|
|
1124
973
|
};
|
|
1125
974
|
|
package/src/roktManager.ts
CHANGED
|
@@ -319,15 +319,15 @@ export default class RoktManager {
|
|
|
319
319
|
this.logger?.verbose(`RoktManager: Processing ${this.messageQueue.size} queued messages`);
|
|
320
320
|
|
|
321
321
|
this.messageQueue.forEach((message) => {
|
|
322
|
-
if(!(message.methodName in this
|
|
323
|
-
this.logger?.error(`RoktManager: Method ${message.methodName} not found
|
|
322
|
+
if(!(message.methodName in this) || !isFunction(this[message.methodName])) {
|
|
323
|
+
this.logger?.error(`RoktManager: Method ${message.methodName} not found`);
|
|
324
324
|
return;
|
|
325
325
|
}
|
|
326
326
|
|
|
327
327
|
this.logger?.verbose(`RoktManager: Processing queued message: ${message.methodName} with payload: ${JSON.stringify(message.payload)}`);
|
|
328
328
|
|
|
329
329
|
try {
|
|
330
|
-
const result = (this
|
|
330
|
+
const result = (this[message.methodName] as Function)(message.payload);
|
|
331
331
|
this.completePendingPromise(message.messageId, result);
|
|
332
332
|
} catch (error) {
|
|
333
333
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -335,6 +335,9 @@ export default class RoktManager {
|
|
|
335
335
|
this.completePendingPromise(message.messageId, Promise.reject(error));
|
|
336
336
|
}
|
|
337
337
|
});
|
|
338
|
+
|
|
339
|
+
// Clear the queue after processing all messages
|
|
340
|
+
this.messageQueue.clear();
|
|
338
341
|
}
|
|
339
342
|
|
|
340
343
|
private queueMessage(message: IRoktMessage): void {
|
package/src/sdkRuntimeModels.ts
CHANGED
|
@@ -319,7 +319,6 @@ export interface DataPlanConfig {
|
|
|
319
319
|
export interface SDKHelpersApi {
|
|
320
320
|
canLog?(): boolean;
|
|
321
321
|
createMainStorageName?(workspaceToken: string): string;
|
|
322
|
-
createProductStorageName?(workspaceToken: string): string;
|
|
323
322
|
createServiceUrl(url: string, devToken?: string): string;
|
|
324
323
|
createXHR?(cb: () => void): XMLHttpRequest;
|
|
325
324
|
extend?(...args: any[]);
|