@nuskin/cs-product-lib 1.0.1 → 1.0.2-cx12-6001.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/cs-product-lib",
3
- "version": "1.0.1",
3
+ "version": "1.0.2-cx12-6001.1",
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/csProduct.js CHANGED
@@ -46,6 +46,7 @@ const csProduct = (props) => {
46
46
  const VARIANT_RESOURCES = 'variants.resources'
47
47
  const PRODUCT_CATEGORY = 'categories'
48
48
  const PRODUCT_SUBCATEGORIES = 'categories.subcategories'
49
+ const PRODUCT_BRAND_STYLE = 'features.brand_style';
49
50
  const DEFAULT_LOCALE = 'en'
50
51
  const PRODUCT_TYPE = 'product'
51
52
  const INCLUDE_FALLBACK = '&include_fallback=true'
@@ -54,7 +55,7 @@ const csProduct = (props) => {
54
55
  const BUNDLE_TYPE = 'bundle'
55
56
 
56
57
  // eslint-disable-next-line max-len
57
- const productIncludes = `&include[]=${VARIANTS}&include[]=${PRODUCT_FAQS}&include[]=${KEY_INGREDIENTS}&include[]=${PRODUCT_HIGHLIGHTS}&include[]=${PRODUCT_RESOURCES}&include[]=${VARIANT_KEY_INGREDIENTS}&include[]=${VARIANT_HIGHLIGHTS}&include[]=${VARIANT_FAQS}&include[]=${VARIANT_RESOURCES}&include[]=${PRODUCT_CATEGORY}&include[]=${PRODUCT_SUBCATEGORIES}`
58
+ const productIncludes = `&include[]=${VARIANTS}&include[]=${PRODUCT_FAQS}&include[]=${KEY_INGREDIENTS}&include[]=${PRODUCT_HIGHLIGHTS}&include[]=${PRODUCT_RESOURCES}&include[]=${VARIANT_KEY_INGREDIENTS}&include[]=${VARIANT_HIGHLIGHTS}&include[]=${VARIANT_FAQS}&include[]=${VARIANT_RESOURCES}&include[]=${PRODUCT_CATEGORY}&include[]=${PRODUCT_SUBCATEGORIES}&include[]=${PRODUCT_BRAND_STYLE}`
58
59
  const requiredIncludes = `&include[]=${REQUIRED}${VARIANTS}&include[]=${REQUIRED}${PRODUCT_FAQS}&include[]=${REQUIRED}${KEY_INGREDIENTS}&include[]=${REQUIRED}${PRODUCT_HIGHLIGHTS}&include[]=${REQUIRED}${PRODUCT_RESOURCES}&include[]=${REQUIRED}${VARIANT_KEY_INGREDIENTS}&include[]=${REQUIRED}${VARIANT_HIGHLIGHTS}&include[]=${REQUIRED}${VARIANT_FAQS}&include[]=${REQUIRED}${VARIANT_RESOURCES}&include[]=${REQUIRED}${PRODUCT_CATEGORY}&include[]=${REQUIRED}${PRODUCT_SUBCATEGORIES}`
59
60
  const optionalIncludes = `&include[]=${OPTIONAL}${VARIANTS}&include[]=${OPTIONAL}${PRODUCT_FAQS}&include[]=${OPTIONAL}${KEY_INGREDIENTS}&include[]=${OPTIONAL}${PRODUCT_HIGHLIGHTS}&include[]=${OPTIONAL}${PRODUCT_RESOURCES}&include[]=${OPTIONAL}${VARIANT_KEY_INGREDIENTS}&include[]=${OPTIONAL}${VARIANT_HIGHLIGHTS}&include[]=${OPTIONAL}${VARIANT_FAQS}&include[]=${OPTIONAL}${VARIANT_RESOURCES}&include[]=${OPTIONAL}${PRODUCT_CATEGORY}&include[]=${OPTIONAL}${PRODUCT_SUBCATEGORIES}`
60
61
 
@@ -145,6 +146,7 @@ const csProduct = (props) => {
145
146
  result[type] = strings
146
147
  return result
147
148
  }, {})
149
+ translation.subscriptions = helpers.mapSubscriptions(translation?.subscriptions)
148
150
  }
149
151
  }
150
152
  }
@@ -28,6 +28,7 @@ const formatVariant = (parent) => ({
28
28
  availableQuantity: _.get(parent, 'defaults.status.availableQuantity', 0),
29
29
  maxQuantity: _.get(parent, 'defaults.status.maxQuantity', 0),
30
30
  status: {
31
+ status: _.get(parent, 'defaults.status.status.retail', null),
31
32
  retail: _.get(parent, 'defaults.status.status.retail', null),
32
33
  wholesale: _.get(parent, 'defaults.status.status.wholesale', null),
33
34
  isBackordered: _.get(parent, 'defaults.status.backordered', null),
package/src/helpers.js CHANGED
@@ -10,6 +10,37 @@ const templateSettings = require('lodash/templateSettings')
10
10
  const _ = require('lodash')
11
11
  const { isNullOrEmpty } = require('@nuskin/ns-common-lib')
12
12
 
13
+ // CONSTS for helpers
14
+ const TEXT_COLOR = 'textColor';
15
+ const BACKGROUND_COLOR = 'backgroundColor';
16
+
17
+ /* istanbul ignore next */
18
+ function mapBrandStyle(feature, type) {
19
+ // if brand style background color is authored, use it, and make text black.
20
+ // otherwise make text white, and use feature.background_color if it exists or default the background color to be #4f4d4d if not
21
+ const isBrandStyle = feature.brand_style && Array.isArray(feature.brand_style) && feature.brand_style.length > 0;
22
+ // eslint-disable-next-line no-nested-ternary
23
+ const backgroundColor = isBrandStyle ? feature.brand_style[0].background_color : feature.background_color.length > 1 ? feature.background_color : '#4f4d4d';
24
+ const textColor = isBrandStyle && feature.brand_style[0].background_color.length > 0 ? '#000000' : '#ffffff';
25
+
26
+ switch (type) {
27
+ case TEXT_COLOR:
28
+ if (!textColor.includes('#')) {
29
+ return `#${textColor}`
30
+ }
31
+ return textColor;
32
+ case BACKGROUND_COLOR:
33
+ if (!backgroundColor.includes('#')) {
34
+ return `#${backgroundColor}`
35
+ }
36
+ return backgroundColor;
37
+ default:
38
+ break;
39
+ }
40
+ return null; // error, need to specify type i.e. text or background color etc
41
+ }
42
+
43
+
13
44
  /* istanbul ignore next */
14
45
  const parseLocale = (locale) => {
15
46
  const localeSplit = locale.split('-')
@@ -522,7 +553,8 @@ function mapFeatures(productOrVariant) {
522
553
  image: mapImage(featureImage(feature)),
523
554
  subtitle: feature.header,
524
555
  features: feature.features,
525
- backgroundColor: feature.background_color
556
+ backgroundColor: mapBrandStyle(feature, BACKGROUND_COLOR),
557
+ textColor: mapBrandStyle(feature, TEXT_COLOR)
526
558
  }))
527
559
  }
528
560
 
@@ -612,7 +644,9 @@ function mapBenefitsAndFeatures(productOrVariant) {
612
644
  return {
613
645
  image: mapImage(benefitsMedia.image),
614
646
  youTubeVideoId: benefitsMedia.youTubeVideoId,
615
- benefits: benefitsToMarkdown(legacyBenefits, jsonBenefits)
647
+ benefits: benefitsToMarkdown(legacyBenefits, jsonBenefits),
648
+ backgroundColor: productOrVariant?.background_color,
649
+ textColor: productOrVariant?.text_color
616
650
  }
617
651
  }
618
652
 
@@ -1047,6 +1081,7 @@ function mapCrossProductIds(product) {
1047
1081
  }
1048
1082
 
1049
1083
  module.exports = {
1084
+ mapBrandStyle,
1050
1085
  mapWarranty,
1051
1086
  mapUpSellProductIds,
1052
1087
  mapCrossProductIds,