@nuskin/ns-product-lib 2.7.0-cx24-3682.2 → 2.7.0-cx24-3682.4

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # [2.7.0-cx24-3682.4](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.7.0-cx24-3682.3...v2.7.0-cx24-3682.4) (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 ([f55854a](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/f55854ad4abb17dbd373fe5e36a38deb2bb8fc53)), closes [#CX24-3682](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-3682)
7
+
8
+ # [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)
9
+
10
+
11
+ ### New
12
+
13
+ * 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)
14
+
1
15
  # [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
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/ns-product-lib",
3
- "version": "2.7.0-cx24-3682.2",
3
+ "version": "2.7.0-cx24-3682.4",
4
4
  "description": "This project contains shared Product models and code between the backend and frontend.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -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,5 @@
1
+ const productNotFound = require('./productNotFound');
2
+
3
+ module.exports = {
4
+ productNotFoundInterceptor: productNotFound
5
+ }
@@ -0,0 +1,49 @@
1
+ // httpStatus codes
2
+ const httpStatus = { notFound: 404 };
3
+
4
+ /**
5
+ * productNotFound 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 productNotFound(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
+ return {
22
+ product: {
23
+ sku
24
+ }
25
+ }
26
+ }
27
+
28
+ console.error('Unable to detect SKU from the given parameter', filterParam);
29
+ }
30
+
31
+ return Promise.reject(error);
32
+ }
33
+
34
+ /**
35
+ * getSKU returns the SKU from the given parameter.
36
+ * @param {string} param '\\''index_key_productId="02010489" OR index_key_skuId="02010489"'''
37
+ * @returns {string|null} SKU
38
+ */
39
+ function getSKU(param) {
40
+ const result = param.match(/\d{8}/);
41
+
42
+ if (result === null) {
43
+ return null;
44
+ }
45
+
46
+ return result[0];
47
+ }
48
+
49
+ module.exports = productNotFound;
@@ -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(productFoundInterceptor, productNotFoundInterceptor);
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 };