@nuskin/cs-product-lib 1.4.3-pa-192.1 → 1.4.4

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/helpers.js +24 -19
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/cs-product-lib",
3
- "version": "1.4.3-pa-192.1",
3
+ "version": "1.4.4",
4
4
  "description": "Library for pulling and parsing product content (and applying business logic) retrieved from Contentstack",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/helpers.js CHANGED
@@ -569,6 +569,25 @@ function mapLink(link) {
569
569
  return (link || {}).href ? { url: link.href, text: link.title || '' } : null
570
570
  }
571
571
 
572
+ function convertDescription(description) {
573
+ if (description?.uid && !(description?.children && description?.type)) {
574
+ description = null
575
+ } else {
576
+ description = createMarkdown(
577
+ description && description.type ? description : null,
578
+ description
579
+ )
580
+ }
581
+ description =
582
+ description?.type ||
583
+ description === '' ||
584
+ description === 'undefined' ||
585
+ description === null
586
+ ? null
587
+ : [description]
588
+ return description
589
+ }
590
+
572
591
  function mapProductDetails(productOrVariant) {
573
592
  const productDetails = (productOrVariant || {}).product_details || {}
574
593
  if ((productOrVariant?.long_description_override || []).length > 0) {
@@ -578,24 +597,10 @@ function mapProductDetails(productOrVariant) {
578
597
  if ((productOrVariant?.included_items_override || []).length > 0) {
579
598
  productDetails.included_items = productOrVariant?.included_items_override
580
599
  }
581
- let description = productDetails.long_description
582
- if (!Array.isArray(description)) {
583
- if (description?.uid && !(description?.children && description?.type)) {
584
- description = null
585
- } else {
586
- description = createMarkdown(
587
- description && description.type ? description : null,
588
- description
589
- )
590
- }
591
- description =
592
- description?.type ||
593
- description === '' ||
594
- description === 'undefined' ||
595
- description === null
596
- ? []
597
- : [description]
598
- }
600
+ let longDescription = productDetails.long_description
601
+ if (!Array.isArray(longDescription)) { longDescription = convertDescription(longDescription) }
602
+ let description = convertDescription(productDetails.description)
603
+
599
604
  const includedItems = productDetails.included_items
600
605
  const highlights = (productDetails.highlights || []).map((highlight) => ({
601
606
  iconUrl: !isNullOrEmpty(highlight?.icon_bynder)
@@ -607,7 +612,7 @@ function mapProductDetails(productOrVariant) {
607
612
  const importer = productDetails.importer
608
613
  const warnings = productDetails.warnings
609
614
  return {
610
- description: decodeHTML(description),
615
+ description: decodeHTML(description || longDescription || []),
611
616
  includedItems: decodeHTML(includedItems),
612
617
  highlights,
613
618
  originCountry,