@nuskin/ns-shop 5.14.4 → 5.14.6
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 +2 -2
- package/src/cart/cartService.js +3 -3
- package/src/cart/persistentCartService.js +22 -5
- package/src/receiver.js +31 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuskin/ns-shop",
|
|
3
|
-
"version": "5.14.
|
|
3
|
+
"version": "5.14.6",
|
|
4
4
|
"description": "The description that will amaze and astound your audience when they read it",
|
|
5
5
|
"main": "src/shop.js",
|
|
6
6
|
"scripts": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"lodash": "4.17.20"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@nuskin/ns-account": "4.
|
|
37
|
+
"@nuskin/ns-account": "4.25.2",
|
|
38
38
|
"@nuskin/ns-jsanalyzer": "1.0.1",
|
|
39
39
|
"@nuskin/ns-product": "3.36.2",
|
|
40
40
|
"@nuskin/ns-util": "3.99.2",
|
package/src/cart/cartService.js
CHANGED
|
@@ -172,8 +172,8 @@ function _getCartStorageName(country) {
|
|
|
172
172
|
*
|
|
173
173
|
* @return {*}
|
|
174
174
|
*/
|
|
175
|
-
function clearCart() {
|
|
176
|
-
_getCart().removeItems({all: true}); // to trigger events
|
|
175
|
+
function clearCart(removePersistedCart = true) {
|
|
176
|
+
_getCart().removeItems({all: true, removeCart: removePersistedCart}); // to trigger events
|
|
177
177
|
setCart(null);
|
|
178
178
|
return _cart_;
|
|
179
179
|
}
|
|
@@ -1264,7 +1264,7 @@ function syncPersistedInfo(pLineInfo) {
|
|
|
1264
1264
|
$(function() {
|
|
1265
1265
|
if (nuskin && nuskin.account) {
|
|
1266
1266
|
events.subscribe(events.authentication.LOGOUT, function () {
|
|
1267
|
-
clearCart();
|
|
1267
|
+
clearCart(false);
|
|
1268
1268
|
if (typeof AdrEditService !== 'undefined') {
|
|
1269
1269
|
AdrEditService.clearAdrEdit();
|
|
1270
1270
|
}
|
|
@@ -772,6 +772,23 @@ const loadPersistedCart = (type) => {
|
|
|
772
772
|
}
|
|
773
773
|
};
|
|
774
774
|
|
|
775
|
+
const getCartType = () => {
|
|
776
|
+
const nsConfig = ConfigService.getMarketConfig();
|
|
777
|
+
let cartType = null;
|
|
778
|
+
|
|
779
|
+
if (nsConfig.usePersistentCart && !window.location.pathname.startsWith("/content/login/corporate")) {
|
|
780
|
+
const context = ShoppingContext.getShoppingContext();
|
|
781
|
+
|
|
782
|
+
if (context) {
|
|
783
|
+
cartType = nsConfig.cartType; // set from shoppingContext
|
|
784
|
+
} else {
|
|
785
|
+
cartType = CartService.getCartProperty('type') || 'market';
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
return cartType;
|
|
790
|
+
}
|
|
791
|
+
|
|
775
792
|
/**
|
|
776
793
|
* Initializes the CART_UPDATED listener and the LOGIN listener.
|
|
777
794
|
*/
|
|
@@ -783,9 +800,8 @@ const initListeners = () => {
|
|
|
783
800
|
events.subscribe(events.shop.CART_UPDATED, addAction);
|
|
784
801
|
|
|
785
802
|
events.subscribe(events.authentication.LOGIN, function() {
|
|
786
|
-
syncCart();
|
|
803
|
+
syncCart(getCartType());
|
|
787
804
|
});
|
|
788
|
-
|
|
789
805
|
events.subscribe('get-persisted-cart-type', loadPersistedCart)
|
|
790
806
|
};
|
|
791
807
|
|
|
@@ -796,8 +812,9 @@ const initListeners = () => {
|
|
|
796
812
|
* @return {Promise<void>}
|
|
797
813
|
*/
|
|
798
814
|
const initPersistentCartService = async () => {
|
|
799
|
-
|
|
800
|
-
|
|
815
|
+
const cartType = getCartType();
|
|
816
|
+
|
|
817
|
+
if (cartType) {
|
|
801
818
|
initListeners();
|
|
802
819
|
if (window.location.pathname != '/static/checkout/checkout.html') {
|
|
803
820
|
// Persist changed that may not have gotten persisted before page refress
|
|
@@ -805,7 +822,7 @@ const initPersistentCartService = async () => {
|
|
|
805
822
|
await persistCartUpdates();
|
|
806
823
|
|
|
807
824
|
// now sync persisted cart into local.
|
|
808
|
-
await syncCart(
|
|
825
|
+
await syncCart(cartType);
|
|
809
826
|
}
|
|
810
827
|
} else {
|
|
811
828
|
events.setValue(events.shop.CART_SYNCED_ON_LOAD, [true]);
|
package/src/receiver.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import $ from '@nuskin/nuskinjquery';
|
|
2
|
-
import {UserService,
|
|
2
|
+
import {UserService, AuthenticationService} from "@nuskin/ns-account";
|
|
3
3
|
import {ConfigService, RunConfigService, storage, util, ShoppingContext, Base64, events} from "@nuskin/ns-util";
|
|
4
4
|
import {Agelocme} from '@nuskin/ns-product-lib';
|
|
5
5
|
import CartService from './cart/cartService';
|
|
@@ -308,7 +308,7 @@ const eventListener = async (message) => {
|
|
|
308
308
|
} else {
|
|
309
309
|
try {
|
|
310
310
|
CartService.clearCart();
|
|
311
|
-
promises.push(
|
|
311
|
+
promises.push(AuthenticationService.authenticateWithEid(data.eid, true));
|
|
312
312
|
} catch (err) {
|
|
313
313
|
console.error('Unable to log in mobile user!');
|
|
314
314
|
}
|
|
@@ -338,13 +338,35 @@ const eventListener = async (message) => {
|
|
|
338
338
|
}
|
|
339
339
|
}
|
|
340
340
|
|
|
341
|
-
const initalizeForMobile = () => {
|
|
342
|
-
|
|
341
|
+
const initalizeForMobile = async () => {
|
|
342
|
+
paramMap = $.getQueryParameters(window.location.search);
|
|
343
|
+
const user = UserService.getUser();
|
|
344
|
+
const cartType = paramMap.cartType || 'market';
|
|
343
345
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
+
if (paramMap.shoppingContext && ShoppingContext[paramMap.shoppingContext]) {
|
|
347
|
+
ShoppingContext.setShoppingContext(ShoppingContext[paramMap.shoppingContext], {cartType: cartType});
|
|
348
|
+
}
|
|
346
349
|
|
|
347
|
-
|
|
350
|
+
// authToken in paramMap will be the new way of initializing the cart/checkout app.
|
|
351
|
+
if (paramMap.authToken) {
|
|
352
|
+
if (user && Base64.decode(paramMap.authToken).indexOf(user.id) >= 0) {
|
|
353
|
+
user.eid = paramMap.authToken;
|
|
354
|
+
UserService.setUser(user);
|
|
355
|
+
} else {
|
|
356
|
+
try {
|
|
357
|
+
CartService.clearCart();
|
|
358
|
+
await AuthenticationService.authenticateWithEid(paramMap.authToken, true);
|
|
359
|
+
} catch (err) {
|
|
360
|
+
console.error('Unable to log in mobile user!');
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
events.setValue(events.mobile.NATIVE_INITIALIZING, [false]);
|
|
364
|
+
} else {
|
|
365
|
+
// TODO: remove the old way
|
|
366
|
+
window.addEventListener("message", eventListener)
|
|
367
|
+
document.addEventListener("message", eventListener);
|
|
368
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({name: 'ready_to_receive', payload: {}}));
|
|
369
|
+
}
|
|
348
370
|
};
|
|
349
371
|
|
|
350
372
|
const receiveUrlParams = () => {
|
|
@@ -405,10 +427,10 @@ const receiveUrlParams = () => {
|
|
|
405
427
|
/**
|
|
406
428
|
* receive certain parameters from the URL.
|
|
407
429
|
*/
|
|
408
|
-
const receive = () => {
|
|
430
|
+
const receive = async () => {
|
|
409
431
|
if (window.ReactNativeWebView) {
|
|
410
432
|
events.setValue(events.mobile.NATIVE_INITIALIZING, [true]);
|
|
411
|
-
initalizeForMobile();
|
|
433
|
+
await initalizeForMobile();
|
|
412
434
|
} else {
|
|
413
435
|
receiveUrlParams();
|
|
414
436
|
}
|