@nuskin/ns-shop 5.13.0 → 5.13.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/package.json
CHANGED
package/src/cart/cartService.js
CHANGED
|
@@ -106,7 +106,6 @@ function _getCart() {
|
|
|
106
106
|
|
|
107
107
|
// If the cartJson userId is empty OR null, then we are going from nothing to something, and we want to keep our items
|
|
108
108
|
if (cartJson &&
|
|
109
|
-
!(!userId && cartJson.id) && // clear cart if cart is persisted but not logged in
|
|
110
109
|
(!UrlService.isLocalePage() || (cartJson.cntryCd === runConfig.country)) &&
|
|
111
110
|
(!cartJson.userId || cartJson.userId === userId) &&
|
|
112
111
|
(!(isPitchApp ^ cartJson.isPitchCart))) {
|
|
@@ -224,7 +224,7 @@ const getUrl = (path, pathParam, queryParams = {}) => {
|
|
|
224
224
|
const queryStr = UrlService.toQueryString(queryParams);
|
|
225
225
|
const queryString = queryStr.length > 0 ? `?${queryStr}` : '';
|
|
226
226
|
|
|
227
|
-
return `${ConfigService.getMarketConfig().awsUrl}/cart/
|
|
227
|
+
return `${ConfigService.getMarketConfig().awsUrl}/cart/v1/${path}/${pathParam}${queryString}`;
|
|
228
228
|
};
|
|
229
229
|
|
|
230
230
|
/**
|
|
@@ -236,9 +236,8 @@ const getUrl = (path, pathParam, queryParams = {}) => {
|
|
|
236
236
|
const getPersistedCart = async (user) => {
|
|
237
237
|
const runConfig = RunConfigService.getRunConfig();
|
|
238
238
|
const response = await axios({
|
|
239
|
-
method: '
|
|
240
|
-
|
|
241
|
-
url: getUrl('getCartByAccountId', user.id, {country: runConfig.country, type: 'market'}),
|
|
239
|
+
method: 'POST',
|
|
240
|
+
url: getUrl('getCartByAccountId', user.id, {country: runConfig.country}),
|
|
242
241
|
headers: getHeaders(user.eid)
|
|
243
242
|
});
|
|
244
243
|
return get(response, 'data.cart', null);
|
|
@@ -266,19 +265,6 @@ const updatePersistedCart = async (user, cartId, payload) => {
|
|
|
266
265
|
return {pCart, cartOutdated};
|
|
267
266
|
};
|
|
268
267
|
|
|
269
|
-
const removePersistedCart = async (user, cartId) => {
|
|
270
|
-
try {
|
|
271
|
-
await axios({
|
|
272
|
-
method: 'DELETE',
|
|
273
|
-
url: getUrl('deleteCart', cartId, {accountId: user.id}),
|
|
274
|
-
headers: getHeaders(user.eid)
|
|
275
|
-
});
|
|
276
|
-
CartService.setCartProperties({id: '', version: -1});
|
|
277
|
-
} catch (err) {
|
|
278
|
-
console.error('Unable to delete persistent cart', err);
|
|
279
|
-
}
|
|
280
|
-
};
|
|
281
|
-
|
|
282
268
|
/**
|
|
283
269
|
* This adds an item from the persisted cart into the local cart.
|
|
284
270
|
*
|
|
@@ -295,9 +281,9 @@ const addPersistedItemToLocal = (pItem, userId, country, language) => {
|
|
|
295
281
|
return;
|
|
296
282
|
}
|
|
297
283
|
return CartService.addSkuToCart({
|
|
298
|
-
id: pItem.
|
|
284
|
+
id: pItem.id,
|
|
299
285
|
agelocme: pItem.agelocme,
|
|
300
|
-
sku: pItem.sku,
|
|
286
|
+
sku: get(pItem, 'price.custom.fields.sku', ''),
|
|
301
287
|
userId: userId,
|
|
302
288
|
cntryCd: country,
|
|
303
289
|
language: language,
|
|
@@ -405,9 +391,9 @@ const mergeIntoLocalCart = async (userId, pCart) => {
|
|
|
405
391
|
CartService.setCartProperties({id: pCart.id, version: pCart.version});
|
|
406
392
|
|
|
407
393
|
const {country, language} = RunConfigService.getRunConfig();
|
|
408
|
-
const lineItems = pCart.
|
|
394
|
+
const lineItems = pCart.lineItems || [];
|
|
409
395
|
const pItemsBySku = lineItems.reduce((skuArrs, pItem) => {
|
|
410
|
-
let skuArray = skuArrs.find((arr) => arr[0].sku === pItem.sku);
|
|
396
|
+
let skuArray = skuArrs.find((arr) => get(arr[0], 'price.custom.fields.sku') === get(pItem, 'price.custom.fields.sku'));
|
|
411
397
|
|
|
412
398
|
if (!skuArray) {
|
|
413
399
|
skuArray = [pItem];
|
|
@@ -425,7 +411,7 @@ const mergeIntoLocalCart = async (userId, pCart) => {
|
|
|
425
411
|
if (pSkuArray.length === 1) {
|
|
426
412
|
const pLineItem = pSkuArray[0];
|
|
427
413
|
// For agelocme the sku will be pLineItem.sku pLineItem.price.custom.fields.sku will be the content sku for agelocme
|
|
428
|
-
const matchedCartItems = cartItems.filter((cItem) => cItem.sku === pLineItem.sku || cItem.sku === pLineItem.sku);
|
|
414
|
+
const matchedCartItems = cartItems.filter((cItem) => cItem.sku === pLineItem.sku || cItem.sku === get(pLineItem, 'price.custom.fields.sku'));
|
|
429
415
|
|
|
430
416
|
if (matchedCartItems.length > 0) {
|
|
431
417
|
promises.push(mergeOneToOnePlus(pLineItem, matchedCartItems));
|
|
@@ -433,7 +419,7 @@ const mergeIntoLocalCart = async (userId, pCart) => {
|
|
|
433
419
|
promises.push(addPersistedItemToLocal(pLineItem, userId, country, language));
|
|
434
420
|
}
|
|
435
421
|
} else {
|
|
436
|
-
const pSku = pSkuArray[0].sku;
|
|
422
|
+
const pSku = get(pSkuArray[0], 'price.custom.fields.sku');
|
|
437
423
|
const cartSkuItems = cartItems.filter((cItem) => cItem.sku === pSkuArray[0].sku || cItem.sku === pSku);
|
|
438
424
|
|
|
439
425
|
if (cartSkuItems.length === 0) {
|
|
@@ -449,7 +435,7 @@ const mergeIntoLocalCart = async (userId, pCart) => {
|
|
|
449
435
|
// Remove local items that do not exist in persisted cart
|
|
450
436
|
cartItems.forEach((cItem) => {
|
|
451
437
|
if (cItem.id) {
|
|
452
|
-
if (!lineItems.some((pItem) => (pItem.sku === cItem.sku || pItem.sku === cItem.sku) && !!pItem.oneTime === !cItem.isAdr)) {
|
|
438
|
+
if (!lineItems.some((pItem) => (pItem.sku === cItem.sku || get(pItem, 'price.custom.fields.sku') === cItem.sku) && !!pItem.oneTime === !cItem.isAdr)) {
|
|
453
439
|
CartService.removeItemByKey(cItem.key);
|
|
454
440
|
}
|
|
455
441
|
}
|
|
@@ -511,8 +497,6 @@ const persistLocalItems = async (cartItems, user) => {
|
|
|
511
497
|
const payload = {
|
|
512
498
|
accountId: user.id,
|
|
513
499
|
country: runConfig.country,
|
|
514
|
-
// TODO: fix hard coding of type
|
|
515
|
-
type: 'market',
|
|
516
500
|
version: cartInfo.version,
|
|
517
501
|
actions: []
|
|
518
502
|
};
|
|
@@ -534,27 +518,18 @@ const persistLocalItems = async (cartItems, user) => {
|
|
|
534
518
|
* @return {Promise<void>}
|
|
535
519
|
*/
|
|
536
520
|
const syncCart = async () => {
|
|
537
|
-
|
|
538
|
-
let pCart = null;
|
|
521
|
+
const user = UserService.getUser();
|
|
539
522
|
|
|
540
523
|
if (user) {
|
|
541
524
|
try {
|
|
542
|
-
pCart = await getPersistedCart(user);
|
|
525
|
+
const pCart = await getPersistedCart(user);
|
|
526
|
+
const unPersistedItems = CartService.getItemData().filter(i => !i.id && !i.isBusinessPortfolio);
|
|
543
527
|
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
if (user) {
|
|
547
|
-
await mergeIntoLocalCart(user.id, pCart);
|
|
548
|
-
}
|
|
528
|
+
await mergeIntoLocalCart(user.id, pCart);
|
|
529
|
+
await persistLocalItems(unPersistedItems, user);
|
|
549
530
|
} catch (err) {
|
|
550
531
|
console.error('Failed to load the persisted cart!', err && err.response && err.response.data ? err.response.data : err);
|
|
551
532
|
}
|
|
552
|
-
if (user) {
|
|
553
|
-
const unPersistedItems = CartService.getItemData().filter(i => !i.id && !i.isBusinessPortfolio);
|
|
554
|
-
await persistLocalItems(unPersistedItems, user);
|
|
555
|
-
} else {
|
|
556
|
-
CartService.clearCart();
|
|
557
|
-
}
|
|
558
533
|
}
|
|
559
534
|
events.setValue(events.shop.CART_SYNCED_ON_LOAD, [true]);
|
|
560
535
|
};
|
|
@@ -568,7 +543,7 @@ const syncCartItems = (pCart) => {
|
|
|
568
543
|
const syncItems = [];
|
|
569
544
|
const cartItems = CartService.getItemData();
|
|
570
545
|
|
|
571
|
-
pCart
|
|
546
|
+
get(pCart, 'lineItems', []).forEach((pItem) => {
|
|
572
547
|
const pGpid = pItem.gpid;
|
|
573
548
|
const pSku = pItem.sku;
|
|
574
549
|
const pIsAdr = !pItem.oneTime;
|
|
@@ -577,7 +552,7 @@ const syncCartItems = (pCart) => {
|
|
|
577
552
|
|
|
578
553
|
if (matchedItem) {
|
|
579
554
|
syncItems.push({
|
|
580
|
-
id: pItem.
|
|
555
|
+
id: pItem.id,
|
|
581
556
|
key: matchedItem.key
|
|
582
557
|
});
|
|
583
558
|
} else {
|
|
@@ -595,8 +570,6 @@ const doPersistentUpdates = async (actions, pcId, pcVersion) => {
|
|
|
595
570
|
const payload = {
|
|
596
571
|
accountId: user.id,
|
|
597
572
|
country: RunConfigService.getRunConfig().country,
|
|
598
|
-
// TODO: fix hardcoding of type
|
|
599
|
-
type: 'market',
|
|
600
573
|
actions: actions,
|
|
601
574
|
version: pcVersion
|
|
602
575
|
};
|
|
@@ -639,10 +612,16 @@ const persistCartUpdates = async () => {
|
|
|
639
612
|
const {type, item, qtyDiff} = info.modify;
|
|
640
613
|
|
|
641
614
|
if (type === 'quantity-changed') {
|
|
642
|
-
|
|
615
|
+
if (qtyDiff > 0) {
|
|
616
|
+
actions.push(getAction(ADD, Object.assign({}, item, {quantity: qtyDiff})));
|
|
617
|
+
} else {
|
|
618
|
+
if (item.id) {
|
|
619
|
+
actions.push(getAction(REMOVE, {id: item.id, quantity: -qtyDiff}));
|
|
620
|
+
}
|
|
621
|
+
}
|
|
643
622
|
} else if (type === 'adr-status-changed' || type === 'product-changed') {
|
|
644
623
|
if (info.modify.removeId) {
|
|
645
|
-
actions.push(getAction(
|
|
624
|
+
actions.push(getAction(REMOVE, {id: info.modify.removeId, quantity: item.qty}));
|
|
646
625
|
}
|
|
647
626
|
actions.push(getAction(ADD, Object.assign({}, item, {quantity: qtyDiff || item.qty})));
|
|
648
627
|
}
|
|
@@ -650,23 +629,21 @@ const persistCartUpdates = async () => {
|
|
|
650
629
|
const item = info.remove.item;
|
|
651
630
|
|
|
652
631
|
if (item.id) {
|
|
653
|
-
actions.push(getAction(
|
|
632
|
+
actions.push(getAction(REMOVE, item));
|
|
654
633
|
}
|
|
655
634
|
} else if (info.removeItems) {
|
|
656
635
|
const removeItems = info.removeItemInfo || [];
|
|
657
|
-
removeItems.forEach((item) => actions.push(getAction(
|
|
636
|
+
removeItems.forEach((item) => actions.push(getAction(REMOVE, item)));
|
|
658
637
|
} else if (info.removeAll) {
|
|
659
638
|
if (actions.length > 0) {
|
|
660
|
-
pcActions.clear(actions.length)
|
|
661
|
-
peeked = 0;
|
|
639
|
+
pcActions.clear(actions.length)
|
|
662
640
|
}
|
|
663
|
-
await
|
|
641
|
+
await doPersistentUpdates([getAction(REMOVE_CART)], pcId, pcVersion);
|
|
664
642
|
pcId = pcActions.pcId;
|
|
665
643
|
pcVersion = pcActions.pcVersion;
|
|
666
644
|
actions = [];
|
|
667
645
|
}
|
|
668
646
|
info = pcActions.peekNext();
|
|
669
|
-
peeked += 1;
|
|
670
647
|
}
|
|
671
648
|
}
|
|
672
649
|
pcActions.clear(peeked);
|
package/src/salesEventService.js
CHANGED
|
@@ -152,14 +152,14 @@ async function getEventStatus(eventsToCheck = []) {
|
|
|
152
152
|
|
|
153
153
|
responses.forEach((response) => {
|
|
154
154
|
let activeStatus = false;
|
|
155
|
-
if (response.status === 'fulfilled') {
|
|
155
|
+
if (response.status === 'fulfilled' && response.value) {
|
|
156
156
|
const status = _decodeStatus(response.value.status);
|
|
157
157
|
if ((status.eventStatus === PRE_EVENT && status.preWaitTime <= 30000) ||
|
|
158
158
|
status.eventStatus === IN_EVENT) {
|
|
159
159
|
activeStatus = true;
|
|
160
160
|
}
|
|
161
|
+
eventStatus[response.value.eventName] = activeStatus;
|
|
161
162
|
}
|
|
162
|
-
eventStatus[response.value.eventName] = activeStatus;
|
|
163
163
|
});
|
|
164
164
|
|
|
165
165
|
return eventStatus;
|
|
@@ -190,6 +190,7 @@ async function _getTempTicket(eventName) {
|
|
|
190
190
|
} catch (err) {
|
|
191
191
|
if (err.response && err.response.data.status === 404) {
|
|
192
192
|
console.error(`getTempTicket - unable to get a temporary ticket for ${eventName}`);
|
|
193
|
+
throw err;
|
|
193
194
|
} else {
|
|
194
195
|
console.error(`getTempTicket error or timeout - waiting to try again for ${eventName}`);
|
|
195
196
|
// Timed out or some other error
|