@nuskin/ns-product-lib 2.13.0-cx24-5107.14 → 2.13.0-cx24-5107.16

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ # [2.13.0-cx24-5107.16](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.13.0-cx24-5107.15...v2.13.0-cx24-5107.16) (2023-10-19)
2
+
3
+
4
+ ### Fix
5
+
6
+ * async graphql ([1da1d02](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/1da1d02eac113c6d57546680c5d936d2139afa7e))
7
+
8
+ # [2.13.0-cx24-5107.15](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.13.0-cx24-5107.14...v2.13.0-cx24-5107.15) (2023-10-19)
9
+
10
+
11
+ ### Fix
12
+
13
+ * productImages null causing exception ([ad59208](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/ad59208a71d3af8104b7c84a4b32142d343f4918))
14
+
15
+ ### Updae
16
+
17
+ * added price unit testng ([3857a3f](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/3857a3f6effe0707cb328abe1cdd33d7953b6dfa))
18
+
1
19
  # [2.13.0-cx24-5107.14](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.13.0-cx24-5107.13...v2.13.0-cx24-5107.14) (2023-10-19)
2
20
 
3
21
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/ns-product-lib",
3
- "version": "2.13.0-cx24-5107.14",
3
+ "version": "2.13.0-cx24-5107.16",
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,15 +15,13 @@ const defaultPayload = {
15
15
  * @returns {Promise}
16
16
  */
17
17
  async function graphQlHttpRequest(payload, config) {
18
- //const url = getGraphQlUrl();
19
18
  const url = config.graphqlUrl
20
- return await axios.request({
19
+ return await axios.request({
21
20
  method: 'post',
22
21
  url: url,
23
22
  data: payload,
24
23
  responseType: 'json'
25
24
  });
26
-
27
25
  }
28
26
 
29
27
  /**
@@ -99,6 +97,7 @@ function mapProduct(product, market, locale, config) {
99
97
 
100
98
  //serves as parent
101
99
  const defaultVariant = variants[0];
100
+ const productImages = mapProductImages(defaultVariant);
102
101
  const productDetail = {
103
102
  "sku": defaultVariant.sku || product.id,
104
103
  "globalProductID": product.id,
@@ -107,9 +106,9 @@ function mapProduct(product, market, locale, config) {
107
106
  "language": locale,
108
107
  "shortDescr": defaultVariant.description,
109
108
  "longDescr": defaultVariant.productDetails.description,
110
- "fullImage": defaultVariant.productImages[0].url,
111
- "imageAltText": defaultVariant.productImages[0].alt,
112
- "thumbnail": defaultVariant.productImages[0].thumbnail,
109
+ "fullImage": productImages.fullImage,
110
+ "imageAltText": productImages.imageAltText,
111
+ "thumbnail": productImages.thumbnail,
113
112
  "ingredients": defaultVariant.ingredients,
114
113
  "benefits": defaultVariant.benefits,
115
114
  "usage": defaultVariant.usage,
@@ -208,15 +207,18 @@ function mapVariants(product) {
208
207
 
209
208
  product.variants.forEach(variant => {
210
209
  const sku = variant.sku || variant.id;
210
+
211
+ const productImages = mapProductImages(variant);
212
+
211
213
  variants[sku] = {
212
214
  "sku": sku,
213
215
  "globalProductID": product.id || variant.globalId,
214
216
  "title": variant.title,
215
217
  "shortDescr": variant.description,
216
218
  "longDescr": variant.productDetails.description,
217
- "fullImage": variant.productImages[0].url,
218
- "imageAltText": variant.productImages[0].alt,
219
- "thumbnail": variant.productImages[0].thumbnail,
219
+ "fullImage": productImages.fullImage,
220
+ "imageAltText": productImages.imageAltText,
221
+ "thumbnail": productImages.thumbnail,
220
222
  "ingredients": variant.ingredients,
221
223
  "benefits": variant.benefits,
222
224
  "usage": variant.usage,
@@ -335,6 +337,32 @@ function mapCustomerTypes(eqCustomerTypes) {
335
337
  return newCustType.toString()
336
338
  }
337
339
 
340
+ /**
341
+ * map product Images
342
+ * {
343
+ * url: "string",
344
+ * alt: "string",
345
+ * thumbnail: "string"
346
+ * }
347
+ * @param {*} product
348
+ * @returns {object} productImages
349
+ */
350
+ function mapProductImages(product) {
351
+
352
+ const productImages = {
353
+ fullImage: "",
354
+ imageAltText: "",
355
+ thumbnail: ""
356
+ };
357
+
358
+ if (product.productImages) {
359
+ productImages.fullImage = product.productImages.url || '';
360
+ productImages.imageAltText = product.productImages.alt || '';
361
+ productImages.thumbnail = product.productImages.thumbnail || '';
362
+ }
363
+
364
+ return productImages;
365
+ }
338
366
  /**
339
367
  * Map Order Types
340
368
  * @param {Array<string>} availableChannels