@nuskin/ns-shop 5.13.0 → 5.14.0

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": "@nuskin/ns-shop",
3
- "version": "5.13.0",
3
+ "version": "5.14.0",
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": {
@@ -241,7 +241,17 @@ const getPersistedCart = async (user) => {
241
241
  url: getUrl('getCartByAccountId', user.id, {country: runConfig.country, type: 'market'}),
242
242
  headers: getHeaders(user.eid)
243
243
  });
244
- return get(response, 'data.cart', null);
244
+ const cart = response.data.cart;
245
+
246
+ const lsCartId = CartService.getCartProperty('id');
247
+ if ((cart && lsCartId && cart.id != lsCartId) || (!cart && lsCartId)) {
248
+ CartService.clearCart();
249
+ }
250
+
251
+ if (cart) {
252
+ CartService.setCartProperties({id: cart.id, version: response.data.version});
253
+ }
254
+ return cart;
245
255
  };
246
256
 
247
257
  /**
@@ -261,8 +271,11 @@ const updatePersistedCart = async (user, cartId, payload) => {
261
271
  });
262
272
 
263
273
  const pCart = response.data.cart || null;
264
- const cartOutdated = response.data.cartWasOutdated;
265
- CartService.setCartProperties({version: pCart ? pCart.version : -1});
274
+ if (cartId && pCart.id !== cartId) {
275
+ CartService.clearCart();
276
+ }
277
+ const cartOutdated = response.data.cartOutdated;
278
+ CartService.setCartProperties({id: pCart.id, version: pCart ? response.data.version : -1});
266
279
  return {pCart, cartOutdated};
267
280
  };
268
281
 
@@ -295,7 +308,7 @@ const addPersistedItemToLocal = (pItem, userId, country, language) => {
295
308
  return;
296
309
  }
297
310
  return CartService.addSkuToCart({
298
- id: pItem.lineId,
311
+ id: pItem.id,
299
312
  agelocme: pItem.agelocme,
300
313
  sku: pItem.sku,
301
314
  userId: userId,
@@ -402,10 +415,8 @@ const mergeIntoLocalCart = async (userId, pCart) => {
402
415
  //Todo review (seems overly complicated)
403
416
  mergingIntoLocalCart = true;
404
417
  if (pCart) {
405
- CartService.setCartProperties({id: pCart.id, version: pCart.version});
406
-
407
418
  const {country, language} = RunConfigService.getRunConfig();
408
- const lineItems = pCart.order.lineItems || [];
419
+ const lineItems = pCart.lineItems || [];
409
420
  const pItemsBySku = lineItems.reduce((skuArrs, pItem) => {
410
421
  let skuArray = skuArrs.find((arr) => arr[0].sku === pItem.sku);
411
422
 
@@ -476,7 +487,6 @@ const getAction = (action, data) => {
476
487
  gpid: data.globalProductID,
477
488
  sku: data.sku,
478
489
  quantity: data.quantity || data.qty,
479
- channel: data.isAdr ? 'subscription' : 'order',
480
490
  oneTime: !data.isAdr
481
491
  };
482
492
  break;
@@ -568,7 +578,7 @@ const syncCartItems = (pCart) => {
568
578
  const syncItems = [];
569
579
  const cartItems = CartService.getItemData();
570
580
 
571
- pCart.order.lineItems.forEach((pItem) => {
581
+ pCart.lineItems.forEach((pItem) => {
572
582
  const pGpid = pItem.gpid;
573
583
  const pSku = pItem.sku;
574
584
  const pIsAdr = !pItem.oneTime;
@@ -577,7 +587,7 @@ const syncCartItems = (pCart) => {
577
587
 
578
588
  if (matchedItem) {
579
589
  syncItems.push({
580
- id: pItem.lineId,
590
+ id: pItem.id,
581
591
  key: matchedItem.key
582
592
  });
583
593
  } else {
@@ -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;
@@ -173,7 +173,7 @@ async function getEventStatus(eventsToCheck = []) {
173
173
  * @returns {Promise<*>} a new or updated ticket for the specified event
174
174
  * @private
175
175
  */
176
- async function _getTempTicket(eventName) {
176
+ async function _getTempTicket(eventName, count = 1) {
177
177
  let ticket;
178
178
 
179
179
  try {
@@ -190,12 +190,17 @@ 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
- // Timed out or some other error
196
- // Wait and then call again.
197
- await _wait(3000);
198
- ticket = await _getTempTicket(eventName);
196
+ if (count < 6) {
197
+ // Timed out or some other error
198
+ // Wait and then call again.
199
+ await _wait(3000);
200
+ ticket = await _getTempTicket(eventName, count++);
201
+ } else {
202
+ throw err;
203
+ }
199
204
  }
200
205
  }
201
206
 
@@ -553,7 +558,7 @@ function _getTicketName(eventName) {
553
558
  * @returns {Promise<*>} a new or updated ticket for the specified event
554
559
  * @private
555
560
  */
556
- async function _getRemoteTicket(eventTicketInfo) {
561
+ async function _getRemoteTicket(eventTicketInfo, count = 1) {
557
562
  let eventName = eventTicketInfo.eventName,
558
563
  ticketId = eventTicketInfo.ticket ? eventTicketInfo.ticket.ticketId : null,
559
564
  ticketName = _getTicketName(eventName);
@@ -590,11 +595,14 @@ async function _getRemoteTicket(eventTicketInfo) {
590
595
  }
591
596
  }
592
597
  } else {
593
- console.error('salesEventService.getRemoteTicket - Sales event service error or timeout! Waiting to try again', err);
594
- // Timed out or some other error
595
- // Wait and then call again.
596
- await _wait(3000);
597
- await _getRemoteTicket(eventTicketInfo);
598
+ if (count < 6) {
599
+ console.error('salesEventService.getRemoteTicket - Sales event service error or timeout! Waiting to try again', err);
600
+ // Timed out or some other error
601
+ // Wait and then call again.
602
+ await _wait(3000);
603
+ await _getRemoteTicket(eventTicketInfo);
604
+ }
605
+ console.err('salesEventService.getRemoteTicket - retry count reached! Continueing with current ticket status.');
598
606
  }
599
607
  }
600
608