@nuskin/ns-product-lib 2.7.0-cx24-3682.1 → 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 CHANGED
@@ -1,3 +1,19 @@
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
+
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)
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 ([219fbd5](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/219fbd59b96ed9cbbc3ea94a24d886f0e8ca563f)), closes [#CX24-3682](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-3682)
14
+ * MySite product cards show blank data when users have setup AEM Base SKU's(55) in Admin #CX24-3682 ([b86a1d2](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/b86a1d2610892564c643bd851d873e507efedd49)), closes [#CX24-3682](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-3682)
15
+ * MySite product cards show blank data when users have setup AEM Base SKU's(55) in Admin #CX24-3682 ([60d61cc](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/60d61ccd38e9b971b7ac53cf4224a9897a63fef4)), closes [#CX24-3682](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-3682)
16
+
1
17
  # [2.7.0-cx24-3682.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.6.1...v2.7.0-cx24-3682.1) (2023-03-24)
2
18
 
3
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/ns-product-lib",
3
- "version": "2.7.0-cx24-3682.1",
3
+ "version": "2.7.0-cx24-3682.3",
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,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;
@@ -6,6 +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 productNotFoundInterceptor = require('./equinox-helpers/interceptors');
9
10
 
10
11
  const productTypes = {
11
12
  kit: 'kit'
@@ -34,7 +35,6 @@ const ProductData = {
34
35
 
35
36
  getProductFromEquinox: async function (skus, locale, config) {
36
37
  const response = await this.searchEquinoxProduct(skus, locale, config);
37
- console.log(response);
38
38
 
39
39
  if (response.data.product) {
40
40
  return await this.eqProductMapper(response.data.product, skus);
@@ -71,6 +71,7 @@ const ProductData = {
71
71
 
72
72
  const url = `${config.API_Base_URLs}/orchestrationservices/storefront/catalogs/search/`;
73
73
  const href = `${url}?filter='\\\\''${encodeURI(filter)}'\\''`;
74
+ axios.interceptors.response.use((res) => res, productNotFoundInterceptor);
74
75
  const response = await axios.request({
75
76
  method: 'get',
76
77
  url: href,
@@ -83,6 +84,7 @@ const ProductData = {
83
84
  withCredentials: true
84
85
  });
85
86
 
87
+ axios.interceptors.response.eject(productNotFoundInterceptor);
86
88
  return response;
87
89
  },
88
90