@nuskin/ns-product-lib 2.7.0-cx24-3682.2 → 2.7.0-cx24-3682.3
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/equinox-helpers/index.js +5 -0
- package/src/equinox-helpers/interceptors/index.js +5 -0
- package/src/equinox-helpers/interceptors/productNotFound.js +50 -0
- package/src/productData.js +2 -7
- package/src/equinox-helpers/interceptors/product.js +0 -19
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# [2.7.0-cx24-3682.3](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.7.0-cx24-3682.2...v2.7.0-cx24-3682.3) (2023-03-24)
|
2
|
+
|
3
|
+
|
4
|
+
### New
|
5
|
+
|
6
|
+
* MySite product cards show blank data when users have setup AEM Base SKU's(55) in Admin #CX24-3682 ([3ce010e](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/3ce010e162034d2cc49619f553baf7b8b7fcd4e0)), closes [#CX24-3682](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-3682)
|
7
|
+
|
1
8
|
# [2.7.0-cx24-3682.2](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.7.0-cx24-3682.1...v2.7.0-cx24-3682.2) (2023-03-24)
|
2
9
|
|
3
10
|
|
package/package.json
CHANGED
@@ -15,6 +15,11 @@
|
|
15
15
|
* @property {Inventory} [inventory]
|
16
16
|
*
|
17
17
|
* ---
|
18
|
+
*
|
19
|
+
* @description This model represents the response.
|
20
|
+
* @typedef EquinoxResponse
|
21
|
+
* @type {object}
|
22
|
+
* @property {EquinoxProduct} product
|
18
23
|
*
|
19
24
|
* @description This model represents a product within an Equinox response.
|
20
25
|
* @typedef EquinoxProduct
|
@@ -0,0 +1,50 @@
|
|
1
|
+
// httpStatus codes
|
2
|
+
const httpStatus = { notFound: 404 };
|
3
|
+
|
4
|
+
/**
|
5
|
+
* productNotFoundInterceptor is called when an equinox product is not found
|
6
|
+
* Note: Do not polute this file. Create a new file for new interceptor.
|
7
|
+
*
|
8
|
+
* @param {import('axios').AxiosError} error
|
9
|
+
* @returns {import('../').EquinoxResponse}
|
10
|
+
*/
|
11
|
+
function productNotFoundInterceptor(error) {
|
12
|
+
const segments = 'catalogs/search';
|
13
|
+
const { config, status } = error;
|
14
|
+
|
15
|
+
if (status === httpStatus.notFound && config.url.includes(segments)) {
|
16
|
+
const params = new URLSearchParams(config.url);
|
17
|
+
const filterParam = Array.from(params.values())[0];
|
18
|
+
const sku = getSKU(filterParam);
|
19
|
+
|
20
|
+
if (sku === null) {
|
21
|
+
console.error('Unable to find SKU', error);
|
22
|
+
return Promise.reject(error);
|
23
|
+
}
|
24
|
+
|
25
|
+
return {
|
26
|
+
product: {
|
27
|
+
sku
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
return Promise.reject(error);
|
33
|
+
}
|
34
|
+
|
35
|
+
/**
|
36
|
+
* getSKU returns the SKU from the given parameter.
|
37
|
+
* @param {string} param '\\''index_key_productId="02010489" OR index_key_skuId="02010489"'''
|
38
|
+
* @returns {string|null} SKU
|
39
|
+
*/
|
40
|
+
function getSKU(param) {
|
41
|
+
const result = param.match(/\d{8}/);
|
42
|
+
|
43
|
+
if (result === null) {
|
44
|
+
return null;
|
45
|
+
}
|
46
|
+
|
47
|
+
return result[0];
|
48
|
+
}
|
49
|
+
|
50
|
+
module.exports = productNotFoundInterceptor;
|
package/src/productData.js
CHANGED
@@ -6,10 +6,7 @@ const Product = require("./product");
|
|
6
6
|
const CustomerTypes = require('./models/customerTypes');
|
7
7
|
const ProductStatus = require("./models/productStatus");
|
8
8
|
const { mapAvailableQuantity, mapChildSKU } = require('./equinox-helpers');
|
9
|
-
const
|
10
|
-
productFoundInterceptor,
|
11
|
-
productNotFoundInterceptor
|
12
|
-
} = require('./equinox-helpers/interceptors/product');
|
9
|
+
const productNotFoundInterceptor = require('./equinox-helpers/interceptors');
|
13
10
|
|
14
11
|
const productTypes = {
|
15
12
|
kit: 'kit'
|
@@ -38,7 +35,6 @@ const ProductData = {
|
|
38
35
|
|
39
36
|
getProductFromEquinox: async function (skus, locale, config) {
|
40
37
|
const response = await this.searchEquinoxProduct(skus, locale, config);
|
41
|
-
console.log(response);
|
42
38
|
|
43
39
|
if (response.data.product) {
|
44
40
|
return await this.eqProductMapper(response.data.product, skus);
|
@@ -75,7 +71,7 @@ const ProductData = {
|
|
75
71
|
|
76
72
|
const url = `${config.API_Base_URLs}/orchestrationservices/storefront/catalogs/search/`;
|
77
73
|
const href = `${url}?filter='\\\\''${encodeURI(filter)}'\\''`;
|
78
|
-
axios.interceptors.response.use(
|
74
|
+
axios.interceptors.response.use((res) => res, productNotFoundInterceptor);
|
79
75
|
const response = await axios.request({
|
80
76
|
method: 'get',
|
81
77
|
url: href,
|
@@ -88,7 +84,6 @@ const ProductData = {
|
|
88
84
|
withCredentials: true
|
89
85
|
});
|
90
86
|
|
91
|
-
axios.interceptors.response.eject(productFoundInterceptor);
|
92
87
|
axios.interceptors.response.eject(productNotFoundInterceptor);
|
93
88
|
return response;
|
94
89
|
},
|
@@ -1,19 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* productFoundInterceptor is executed when an equinox product is found
|
3
|
-
* @param {import('axios').AxiosResponse} response
|
4
|
-
*/
|
5
|
-
function productFoundInterceptor(response) {
|
6
|
-
console.log('productFoundInterceptor', response);
|
7
|
-
return response;
|
8
|
-
}
|
9
|
-
|
10
|
-
/**
|
11
|
-
* productNotFoundInterceptor is called when an equinox product is not found
|
12
|
-
* @param {import('axios').AxiosError} error
|
13
|
-
*/
|
14
|
-
function productNotFoundInterceptor(error) {
|
15
|
-
console.log('productNotFoundInterceptor', error);
|
16
|
-
return Promise.reject(error);
|
17
|
-
}
|
18
|
-
|
19
|
-
module.exports = { productFoundInterceptor, productNotFoundInterceptor };
|