@nuskin/ns-shop 6.2.1 → 6.2.2
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": "6.2.
|
|
3
|
+
"version": "6.2.2",
|
|
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": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"@nuskin/ns-common-lib": "1.4.5",
|
|
27
27
|
"@nuskin/ns-feature-flags": "1.4.2",
|
|
28
28
|
"@nuskin/ns-loyalty-web": "1.5.6",
|
|
29
|
-
"@nuskin/ns-product-lib": "2.5.
|
|
29
|
+
"@nuskin/ns-product-lib": "2.5.1",
|
|
30
30
|
"@nuskin/nuskinjquery": "2.3.1",
|
|
31
31
|
"axios": "0.21.1",
|
|
32
32
|
"decimal.js": "10.2.1",
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
"request": "2.88.2"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@nuskin/ns-account": "5.7.
|
|
39
|
-
"@nuskin/configuration-sdk": "2.2.
|
|
38
|
+
"@nuskin/ns-account": "5.7.1",
|
|
39
|
+
"@nuskin/configuration-sdk": "2.2.3",
|
|
40
40
|
"@nuskin/ns-jsanalyzer": "1.0.1",
|
|
41
|
-
"@nuskin/ns-product": "3.38.
|
|
42
|
-
"@nuskin/ns-util": "4.
|
|
41
|
+
"@nuskin/ns-product": "3.38.2",
|
|
42
|
+
"@nuskin/ns-util": "4.2.4",
|
|
43
43
|
"axios-mock-adapter": "1.18.2",
|
|
44
44
|
"babel-cli": "6.26.0",
|
|
45
45
|
"babel-core": "6.26.3",
|
package/src/cart/cartService.js
CHANGED
|
@@ -13,7 +13,7 @@ import QualificationService from '../qualification/qualificationService.js';
|
|
|
13
13
|
import {ProductStatus} from '@nuskin/ns-product-lib';
|
|
14
14
|
import webLoyalty from '@nuskin/ns-loyalty-web';
|
|
15
15
|
import axios from 'axios';
|
|
16
|
-
import { getCachedConfigField } from '@nuskin/configuration-sdk';
|
|
16
|
+
import { getCachedConfigField, getConfiguration } from '@nuskin/configuration-sdk';
|
|
17
17
|
|
|
18
18
|
export default {
|
|
19
19
|
goToCartPage,
|
|
@@ -95,6 +95,10 @@ let _cart_;
|
|
|
95
95
|
let activeEvents = [];
|
|
96
96
|
let cartSynced = false;
|
|
97
97
|
|
|
98
|
+
const awaitForConfig = async () => {
|
|
99
|
+
await getConfiguration(['Cart', 'Checkout']);
|
|
100
|
+
};
|
|
101
|
+
|
|
98
102
|
/**
|
|
99
103
|
*
|
|
100
104
|
* @memberof CartService
|
|
@@ -219,6 +223,7 @@ function updateItemPrices() {
|
|
|
219
223
|
}
|
|
220
224
|
|
|
221
225
|
async function checkForMissingEventNames(order) {
|
|
226
|
+
await awaitForConfig();
|
|
222
227
|
const cart = _getCart();
|
|
223
228
|
await cart.setMissingEventNames(order);
|
|
224
229
|
setCart(cart);
|
|
@@ -320,6 +325,7 @@ function itemIsAvailable(product) {
|
|
|
320
325
|
* @private
|
|
321
326
|
*/
|
|
322
327
|
async function addProductToCart(options) {
|
|
328
|
+
await awaitForConfig();
|
|
323
329
|
let cart = _getCart();
|
|
324
330
|
|
|
325
331
|
if (!options.sapLineId && !itemIsAvailable(options.product)) {
|
|
@@ -444,6 +450,7 @@ async function addSkuToCart(options) {
|
|
|
444
450
|
}
|
|
445
451
|
|
|
446
452
|
async function getBaseSkuCartQuantity(baseSku) {
|
|
453
|
+
await awaitForConfig();
|
|
447
454
|
const cartContents = await QualificationService.convertCartDataToBaseSkus(_getCart().getItemData(), true) || {}
|
|
448
455
|
const baseSkuData = cartContents[baseSku] || {}
|
|
449
456
|
const quantity = baseSkuData.qty || 0
|
|
@@ -461,6 +468,9 @@ async function getAddToCartQty(product) {
|
|
|
461
468
|
const featureEnabled = await checkFlag('cx15-4373');
|
|
462
469
|
let retVal = 0;
|
|
463
470
|
|
|
471
|
+
// Make sure the needed config is loaded.
|
|
472
|
+
await awaitForConfig();
|
|
473
|
+
|
|
464
474
|
if (typeof product === 'string') {
|
|
465
475
|
const response = await ProductService.getProductBySku({sku: product});
|
|
466
476
|
product = response.success && response.product;
|
|
@@ -494,6 +504,7 @@ async function getAddToCartQty(product) {
|
|
|
494
504
|
}
|
|
495
505
|
|
|
496
506
|
async function changeItemQty(cartItemInfo, qty = 0, referror) {
|
|
507
|
+
await awaitForConfig();
|
|
497
508
|
if (qty === 0) {
|
|
498
509
|
// Remove the Product
|
|
499
510
|
removeItemByKey(cartItemInfo.key);
|
|
@@ -778,6 +789,7 @@ function syncCartItemToSapItem(sapItemKey, cartItemKey = null) {
|
|
|
778
789
|
* the cart is too high an adjustment is made.
|
|
779
790
|
*/
|
|
780
791
|
async function checkItemAvailability() {
|
|
792
|
+
await awaitForConfig();
|
|
781
793
|
const featureEnabled = await checkFlag('cx15-4373');
|
|
782
794
|
const cart = _getCart();
|
|
783
795
|
|
|
@@ -89,19 +89,19 @@ async function addBundleToEquinoxCart(productBundleSkus = []) {
|
|
|
89
89
|
const cartType = _getCartShoppingContext();
|
|
90
90
|
const bundleItems = [];
|
|
91
91
|
let cachedProducts = [];
|
|
92
|
-
|
|
92
|
+
|
|
93
93
|
productsLocalStorage.searchResults.map((searchResult) => {
|
|
94
|
-
if(searchResult.resultsList && searchResult.resultsList.length > 0) {
|
|
94
|
+
if (searchResult.resultsList && searchResult.resultsList.length > 0) {
|
|
95
95
|
cachedProducts = cachedProducts.concat(searchResult.resultsList)
|
|
96
96
|
}
|
|
97
97
|
})
|
|
98
|
-
|
|
98
|
+
|
|
99
99
|
productBundleSkus.forEach((sku) => {
|
|
100
100
|
const productItem = cachedProducts.find((product) => {
|
|
101
101
|
return product.sku === sku;
|
|
102
102
|
})
|
|
103
103
|
|
|
104
|
-
if(productItem) {
|
|
104
|
+
if (productItem) {
|
|
105
105
|
bundleItems.push({
|
|
106
106
|
"quantity": 1, //TODO clarify if there are bundles that has > 1 qty of item of type
|
|
107
107
|
"skus": [
|
|
@@ -117,7 +117,7 @@ async function addBundleToEquinoxCart(productBundleSkus = []) {
|
|
|
117
117
|
})
|
|
118
118
|
}
|
|
119
119
|
})
|
|
120
|
-
|
|
120
|
+
|
|
121
121
|
const options = {
|
|
122
122
|
method: 'POST',
|
|
123
123
|
endpoint: `carts/${cartType}/items`,
|
|
@@ -168,12 +168,7 @@ async function getEquinoxCart() {
|
|
|
168
168
|
async function getEquinoxRequestConfiguration() {
|
|
169
169
|
const marketLocale = UrlService.getLocale();
|
|
170
170
|
const [, market] = marketLocale.split("_");
|
|
171
|
-
const config = (await getConfiguration(
|
|
172
|
-
configMapNames: ['Equinox_Markets'],
|
|
173
|
-
country: market,
|
|
174
|
-
environment: RunConfigService.getEnvironmentCode(),
|
|
175
|
-
clientId: ConfigService.getMarketConfig().checkout.clientId
|
|
176
|
-
})).Equinox_Markets;
|
|
171
|
+
const config = (await getConfiguration(['Equinox_Markets'])).Equinox_Markets;
|
|
177
172
|
const mySiteKongURL = config.API_Base_URLs;
|
|
178
173
|
const equinoxMarket = {
|
|
179
174
|
market_name: config.market_name,
|
|
@@ -214,7 +209,7 @@ async function _equinoxRequest(options) {
|
|
|
214
209
|
url: `${mySiteKongURL}/orchestrationservices/storefront/${options.endpoint}`,
|
|
215
210
|
headers: defaultHeaders,
|
|
216
211
|
withCredentials: (options.method !== "DELETE"),
|
|
217
|
-
params: (options.params) ? options.params : defaultEquinoxParams
|
|
212
|
+
params: (options.params) ? options.params : defaultEquinoxParams
|
|
218
213
|
};
|
|
219
214
|
|
|
220
215
|
if (options.data) {
|
|
@@ -233,7 +228,7 @@ function goToCartPage() {
|
|
|
233
228
|
}
|
|
234
229
|
|
|
235
230
|
$(async function () {
|
|
236
|
-
if(equinoxLocalStorage.isEquinoxEnabled()) {
|
|
231
|
+
if (equinoxLocalStorage.isEquinoxEnabled()) {
|
|
237
232
|
_getEquinoxSession();
|
|
238
233
|
$.subscribe(events.shop.ADD_TO_CART, (options) => {
|
|
239
234
|
getEquinoxCart().then((response) => {
|
|
@@ -241,6 +236,6 @@ $(async function () {
|
|
|
241
236
|
events.publish(events.shop.CART_UPDATED, { cartInfo: { qty: cart.value.count }, ...options });
|
|
242
237
|
});
|
|
243
238
|
});
|
|
244
|
-
|
|
239
|
+
|
|
245
240
|
}
|
|
246
241
|
})
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { getConfiguration } from '@nuskin/configuration-sdk';
|
|
2
|
+
import { EquinoxService } from '@nuskin/ns-account';
|
|
1
3
|
import {RunConfigService, storage, UrlService, equinoxLocalStorage} from '@nuskin/ns-util';
|
|
2
4
|
import Favorite from './favorite';
|
|
3
5
|
import ServiceUtils from '../ServiceUtils';
|
|
4
|
-
import {Contentstack } from '@nuskin/ns-product-lib';
|
|
5
|
-
import { EquinoxService } from '@nuskin/ns-account';
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
const FAVORITE_RESPONSE_LIST = 'FavoriteResponseList';
|
|
@@ -96,8 +96,7 @@ async function getFavorites(options) {
|
|
|
96
96
|
* @public
|
|
97
97
|
*/
|
|
98
98
|
async function addToFavorites(sku) {
|
|
99
|
-
let url = `${getServiceUrl()}?cntry=${getCountry()}
|
|
100
|
-
response;
|
|
99
|
+
let url = `${getServiceUrl()}?cntry=${getCountry()}`;
|
|
101
100
|
|
|
102
101
|
if (!isAwsMode()) {
|
|
103
102
|
url += `&eid=${ServiceUtils.getUser().eid}`;
|
|
@@ -108,19 +107,22 @@ async function addToFavorites(sku) {
|
|
|
108
107
|
|
|
109
108
|
let body = {'sku': sku};
|
|
110
109
|
|
|
111
|
-
if (
|
|
112
|
-
await
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
headers: headers,
|
|
119
|
-
credentials: 'omit',
|
|
120
|
-
body: JSON.stringify(body)
|
|
121
|
-
});
|
|
110
|
+
if (equinoxLocalStorage.isEquinoxEnabled()) {
|
|
111
|
+
if (await isMarketEquinoxEnabled()) {
|
|
112
|
+
await EquinoxService.addItemToEquinoxList(sku)
|
|
113
|
+
const equinoxFavoriteResponse = await EquinoxService.getEquinoxFavorite();
|
|
114
|
+
const response = EquinoxService.equinoxFavoritesMapper(equinoxFavoriteResponse);
|
|
115
|
+
return handleFavoritesListResponse(response);
|
|
116
|
+
}
|
|
122
117
|
}
|
|
123
118
|
|
|
119
|
+
const response = await fetch(url, {
|
|
120
|
+
method: 'POST',
|
|
121
|
+
headers: headers,
|
|
122
|
+
credentials: 'omit',
|
|
123
|
+
body: JSON.stringify(body)
|
|
124
|
+
});
|
|
125
|
+
|
|
124
126
|
return handleFavoritesListResponse(response);
|
|
125
127
|
}
|
|
126
128
|
|
|
@@ -235,7 +237,7 @@ async function getFavoritesFromServer(options) {
|
|
|
235
237
|
if (!isAwsMode()) {
|
|
236
238
|
url += `&eid=${ServiceUtils.getUser().eid}`;
|
|
237
239
|
}
|
|
238
|
-
|
|
240
|
+
|
|
239
241
|
if(await isMarketEquinoxEnabled()) {
|
|
240
242
|
|
|
241
243
|
const equinoxFavoriteResponse = await EquinoxService.getEquinoxFavorite();
|
|
@@ -262,11 +264,11 @@ async function getFavoritesFromServer(options) {
|
|
|
262
264
|
*/
|
|
263
265
|
async function handleFavoritesListResponse(response) {
|
|
264
266
|
let data = response;
|
|
265
|
-
|
|
267
|
+
|
|
266
268
|
if(!await isMarketEquinoxEnabled()) {
|
|
267
269
|
data = await ServiceUtils.transformFetchResponse(response);
|
|
268
270
|
}
|
|
269
|
-
|
|
271
|
+
|
|
270
272
|
if (!(FAVORITE_RESPONSE_LIST in data) || !(data[FAVORITE_RESPONSE_LIST] instanceof Array)) {
|
|
271
273
|
throw new Error('Malformed Favorites List response from server');
|
|
272
274
|
}
|
|
@@ -323,10 +325,7 @@ function getHeaders() {
|
|
|
323
325
|
|
|
324
326
|
async function isMarketEquinoxEnabled() {
|
|
325
327
|
|
|
326
|
-
const
|
|
327
|
-
const [, market] = marketLocale.split("_");
|
|
328
|
-
const equinoxMarket = await Contentstack.isMarketEnabled(market);
|
|
329
|
-
const isEquinoxEnabled = equinoxMarket && equinoxLocalStorage.isEquinoxEnabled();
|
|
328
|
+
const equinoxMarket = (await getConfiguration(["Equinox_Markets"])).Equinox_Markets;
|
|
330
329
|
|
|
331
|
-
return
|
|
330
|
+
return equinoxMarket.active;
|
|
332
331
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {nuskin, RunConfigService, events, storage, UrlService} from '@nuskin/ns-util';
|
|
2
2
|
import $ from '@nuskin/nuskinjquery';
|
|
3
3
|
import {ProductStatusMapper} from '@nuskin/ns-product-lib';
|
|
4
|
-
import {getCachedConfigField} from '@nuskin/configuration-sdk';
|
|
4
|
+
import {getCachedConfigField, getConfiguration} from '@nuskin/configuration-sdk';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Storage metadata for caching product statuses in session storage.
|
|
@@ -220,7 +220,7 @@ export default {
|
|
|
220
220
|
* @memberof ProductStatusService
|
|
221
221
|
* @public
|
|
222
222
|
*/
|
|
223
|
-
function getProductStatus(skus, countryCode, queryParams = {}) {
|
|
223
|
+
async function getProductStatus(skus, countryCode, queryParams = {}) {
|
|
224
224
|
const options = {countryCode: countryCode|| RunConfigService.getRunConfig().country};
|
|
225
225
|
if (queryParams.version) {
|
|
226
226
|
const version = queryParams.version;
|
|
@@ -231,6 +231,7 @@ function getProductStatus(skus, countryCode, queryParams = {}) {
|
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
233
|
|
|
234
|
+
await getConfiguration(['Shopping', 'Url'])
|
|
234
235
|
queryParams.context = getCachedConfigField('productStatusContext');
|
|
235
236
|
queryParams.storageLocation = getCachedConfigField('productStatusStorageLocation');
|
|
236
237
|
options.filter = UrlService.toQueryString(queryParams);
|
|
@@ -347,9 +348,11 @@ function queueForPublish(sku) {
|
|
|
347
348
|
return;
|
|
348
349
|
}
|
|
349
350
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
.
|
|
351
|
+
getConfiguration(['Url', 'Shopping']).then(() => {
|
|
352
|
+
let batch = getCurrentSubscriberBatch();
|
|
353
|
+
batch.requests.push(getProductStatus(sku)
|
|
354
|
+
.catch(err => {console.error(err); return null;}));
|
|
355
|
+
});
|
|
353
356
|
}
|
|
354
357
|
|
|
355
358
|
/**
|
|
@@ -388,7 +391,7 @@ function publishStatuses() {
|
|
|
388
391
|
// Wait for all status requests to be satisfied
|
|
389
392
|
Promise.all(batch.requests)
|
|
390
393
|
|
|
391
|
-
|
|
394
|
+
// Filter out nulls and flatten the status lists to a single list
|
|
392
395
|
.then(lists => lists.filter(s => !!s).reduce((acc, el) => acc.concat(el), []))
|
|
393
396
|
|
|
394
397
|
// Publish the flattened list to all subscribers
|