@nuskin/ns-shop 7.0.7 → 7.0.9-cx24-7079.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/ns-shop",
3
- "version": "7.0.7",
3
+ "version": "7.0.9-cx24-7079.1",
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": {
@@ -20,7 +20,8 @@ const shoppingContextCartTypes = {
20
20
 
21
21
  const DEFAULT_CART_TYPE = 'USER';
22
22
 
23
- let cartContents = null;
23
+ let requestStatus = 'idle';
24
+ let promise = null;
24
25
 
25
26
  export default {
26
27
  addProductToEquinoxCart,
@@ -46,8 +47,15 @@ function _getEquinoxSession() {
46
47
  method: 'GET',
47
48
  endpoint: 'customers'
48
49
  }
50
+ const customerSession = sessionStorage.getItem('customerSession') ? JSON.parse(sessionStorage.getItem('customerSession')) : ''
51
+ if (customerSession === '') {
52
+ sessionStorage.setItem('customerSession', true)
53
+ return _equinoxRequest(equinoxRequestOptions)
54
+ } else {
55
+ return null
56
+ }
57
+
49
58
 
50
- return _equinoxRequest(equinoxRequestOptions);
51
59
  }
52
60
 
53
61
  /**
@@ -216,22 +224,25 @@ function _getCartShoppingContext() {
216
224
  async function getEquinoxCart() {
217
225
 
218
226
  const cartType = _getCartShoppingContext();
219
-
227
+
220
228
  const equinoxRequestOptions = {
221
229
  method: 'GET',
222
230
  endpoint: `carts/${cartType}`
223
231
  }
224
- if (!cartContents){
225
- cartContents = _equinoxRequest(equinoxRequestOptions).then(result => {
226
- cartContents = result;
227
- });
232
+ if(requestStatus === 'pending'){
233
+ return resolvePromise(promise);
228
234
  }
235
+ if (requestStatus === 'idle'){
236
+ requestStatus = 'pending';
237
+ promise = _equinoxRequest(equinoxRequestOptions);
238
+ return resolvePromise(promise);
239
+ }
240
+ }
229
241
 
230
- await cartContents
231
-
232
- // if this is a promise, this will resolve it
233
- // otherwise, it won't do anything
234
- return cartContents;
242
+ async function resolvePromise (promise) {
243
+ const response = await promise;
244
+ requestStatus = 'idle';
245
+ return response;
235
246
  }
236
247
 
237
248
  /**
@@ -460,7 +471,6 @@ const runConfigCallback = async (runConfig) => {
460
471
  const publishEquinoxCartCount = (options) => {
461
472
  getEquinoxCart().then((response) => {
462
473
  const cart = response.data;
463
- cartContents = null;
464
474
  events.publish(events.shop.CART_UPDATED, { cartInfo: { qty: cart.value.count }, ...options });
465
475
  });
466
476
  }