@nuskin/cs-product-lib 1.0.4 → 1.0.6-cx12-6632.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.4",
3
+ "version": "1.0.6-cx12-6632.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
@@ -53,11 +53,14 @@ const csProduct = (props) => {
53
53
  const REQUIRED = 'required_products.product.'
54
54
  const OPTIONAL = 'optional_products.product.'
55
55
  const BUNDLE_TYPE = 'bundle'
56
+ const PRODUCT_BUNDLE = 'product_bundle'
56
57
 
57
58
  // eslint-disable-next-line max-len
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}`
59
+ 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}&include[]=${PRODUCT_BUNDLE}`
59
60
  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}`
60
61
  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}`
62
+ const bundleRequiredIncludes = `&include[]=${PRODUCT_BUNDLE}.${REQUIRED}${VARIANTS}&include[]=${PRODUCT_BUNDLE}.${REQUIRED}${PRODUCT_FAQS}&include[]=${PRODUCT_BUNDLE}.${REQUIRED}${KEY_INGREDIENTS}&include[]=${PRODUCT_BUNDLE}.${REQUIRED}${PRODUCT_HIGHLIGHTS}&include[]=${PRODUCT_BUNDLE}.${REQUIRED}${PRODUCT_RESOURCES}&include[]=${PRODUCT_BUNDLE}.${REQUIRED}${VARIANT_KEY_INGREDIENTS}&include[]=${PRODUCT_BUNDLE}.${REQUIRED}${VARIANT_HIGHLIGHTS}&include[]=${PRODUCT_BUNDLE}.${REQUIRED}${VARIANT_FAQS}&include[]=${PRODUCT_BUNDLE}.${REQUIRED}${VARIANT_RESOURCES}&include[]=${PRODUCT_BUNDLE}.${REQUIRED}${PRODUCT_CATEGORY}&include[]=${PRODUCT_BUNDLE}.${REQUIRED}${PRODUCT_SUBCATEGORIES}`
63
+ const bundlOptionalIncludes = `&include[]=${PRODUCT_BUNDLE}.${OPTIONAL}${VARIANTS}&include[]=${PRODUCT_BUNDLE}.${OPTIONAL}${PRODUCT_FAQS}&include[]=${PRODUCT_BUNDLE}.${OPTIONAL}${KEY_INGREDIENTS}&include[]=${PRODUCT_BUNDLE}.${OPTIONAL}${PRODUCT_HIGHLIGHTS}&include[]=${PRODUCT_BUNDLE}.${OPTIONAL}${PRODUCT_RESOURCES}&include[]=${PRODUCT_BUNDLE}.${OPTIONAL}${VARIANT_KEY_INGREDIENTS}&include[]=${PRODUCT_BUNDLE}.${OPTIONAL}${VARIANT_HIGHLIGHTS}&include[]=${PRODUCT_BUNDLE}.${OPTIONAL}${VARIANT_FAQS}&include[]=${PRODUCT_BUNDLE}.${OPTIONAL}${VARIANT_RESOURCES}&include[]=${PRODUCT_BUNDLE}.${OPTIONAL}${PRODUCT_CATEGORY}&include[]=${PRODUCT_BUNDLE}.${OPTIONAL}${PRODUCT_SUBCATEGORIES}`
61
64
 
62
65
  validateConfig(props)
63
66
  const { apiKey, environment, deliveryToken, homeUrl, awsBase, clientId } = props
@@ -183,6 +186,45 @@ const csProduct = (props) => {
183
186
  })
184
187
  }
185
188
 
189
+ const formatBundleKit = async (products, locale, translations) => {
190
+ for (let p = 0; p < products.length; p++) {
191
+ for (let b = 0; b < products[p]?.product_bundle?.length || 0; b++) {
192
+
193
+ for (
194
+ let i = 0;
195
+ i < (products[p].product_bundle[b].required_products || []).length;
196
+ i++
197
+ ) {
198
+ await removeInvalidVariants(
199
+ products[p].product_bundle[b].required_products[i].product,
200
+ locale,
201
+ translations
202
+ )
203
+ }
204
+ for (
205
+ let i = 0;
206
+ i < (products[p].product_bundle[b].optional_products || []).length;
207
+ i++
208
+ ) {
209
+ await removeInvalidVariants(
210
+ products[p].product_bundle[b].optional_products[i].product,
211
+ locale,
212
+ translations
213
+ )
214
+ }
215
+ products[p].product_bundle[b].type = "bundle"
216
+ }
217
+ products[p].bundle = formatBundleWithSchema(products[p].product_bundle)
218
+ if(products[p].product_bundle?.length > 0){
219
+ products[p].variants = []
220
+ }
221
+ products[p].type = (products[p].product_bundle?.length || 0) > 0 ? "bundle" : null
222
+ delete products[p].product_bundle
223
+
224
+
225
+ }
226
+ }
227
+
186
228
  // includes is an array of all the referenced types in the contentType you are requesting that should be resolved
187
229
  // and returned (Example: ['common_strings'])
188
230
  const getEntriesByQuery = async ({
@@ -198,6 +240,8 @@ const csProduct = (props) => {
198
240
  let url = `content_types/${contentType}/entries?environment=${environment}&locale=${locale}&include_count=true&limit=${limit}&query=${query}`
199
241
  if (contentType === PRODUCT_TYPE) {
200
242
  url += productIncludes
243
+ url += bundleRequiredIncludes
244
+ url += bundlOptionalIncludes
201
245
  }
202
246
  if (contentType === BUNDLE_TYPE) {
203
247
  url += requiredIncludes
@@ -312,7 +356,7 @@ const csProduct = (props) => {
312
356
 
313
357
  let products = await queryProducts(query, locale)
314
358
  const translations = await getTranslations(locale)
315
- // await parseSharedStrings(translations);
359
+ await formatBundleKit(products, locale, translations)
316
360
  await removeInvalidVariants(products, locale, translations)
317
361
  for (const product of products) {
318
362
  product.skus = skus
@@ -331,7 +375,7 @@ const csProduct = (props) => {
331
375
 
332
376
  let products = await queryProducts(query, locale)
333
377
  const translations = await getTranslations(locale)
334
- // await parseSharedStrings(translations);
378
+ await formatBundleKit(products, locale, translations)
335
379
  await removeInvalidVariants(products, locale, translations)
336
380
  return formatProductWithSchema(products)
337
381
  }
@@ -346,7 +390,7 @@ const csProduct = (props) => {
346
390
 
347
391
  const products = await queryProducts(query, locale)
348
392
  const translations = await getTranslations(locale)
349
- // await parseSharedStrings(translations);
393
+ await formatBundleKit(products, locale, translations)
350
394
  await removeInvalidVariants(products, locale, translations)
351
395
  return formatProductWithSchema(products)
352
396
  }
@@ -358,7 +402,7 @@ const csProduct = (props) => {
358
402
  const query = `{"uid": {"$in": ${helpers?.arrayString(ids)}}}`
359
403
  let products = await queryProducts(query, locale)
360
404
  const translations = await getTranslations(locale)
361
- // await parseSharedStrings(translations);
405
+ await formatBundleKit(products, locale, translations)
362
406
  await removeInvalidVariants(products, locale, translations)
363
407
  return formatProductWithSchema(products)
364
408
  }
@@ -23,6 +23,8 @@ const formatProduct = (parent, homeUrl) => ({
23
23
  },
24
24
  benefits: helpers?.mapBenefits(parent),
25
25
  benefitsAndFeatures: helpers?.mapBenefitsAndFeatures(parent),
26
+ bundle: parent?.bundle,
27
+ type: parent?.type,
26
28
  results: helpers?.mapResults(parent),
27
29
  sustainability: helpers?.mapSustainability(parent),
28
30
  usage: helpers?.mapUsage(parent, parent.legacy_usage),
package/src/helpers.js CHANGED
@@ -21,7 +21,7 @@ function mapBrandStyle(feature, type) {
21
21
  const isBrandStyle = feature.brand_style && Array.isArray(feature.brand_style) && feature.brand_style.length > 0;
22
22
  // eslint-disable-next-line no-nested-ternary
23
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';
24
+ const textColor = isBrandStyle && feature.brand_style[0].background_color?.length > 0 ? '#000000' : '#ffffff';
25
25
 
26
26
  switch (type) {
27
27
  case TEXT_COLOR:
@@ -30,7 +30,7 @@ function mapBrandStyle(feature, type) {
30
30
  }
31
31
  return textColor;
32
32
  case BACKGROUND_COLOR:
33
- if (!backgroundColor.includes('#')) {
33
+ if (!backgroundColor?.includes('#')) {
34
34
  return `#${backgroundColor}`
35
35
  }
36
36
  return backgroundColor;
@@ -313,7 +313,7 @@ function mapVariants(parent) {
313
313
  }
314
314
 
315
315
  function mapSeoInformation(parent, homeUrl) {
316
- const { ogImage } = parent.seo_information
316
+ const { ogImage } = parent?.seo_information || {}
317
317
  const seoData = {
318
318
  metaTitle: parent?.seo_information?.meta_title || parent.name,
319
319
  metaDescription:
@@ -500,7 +500,7 @@ function mapProductDetails(productOrVariant) {
500
500
  }
501
501
  let description = productDetails.long_description
502
502
  if (!Array.isArray(description)) {
503
- if (description?.uid) {
503
+ if (description?.uid && !(description?.children && description?.type)) {
504
504
  description = null
505
505
  } else {
506
506
  description = createMarkdown(
@@ -5,6 +5,7 @@ const transformBundle = (parent, homeUrl) => ({
5
5
  id: parent.bundle_id,
6
6
  uid: parent.uid,
7
7
  title: parent.name,
8
+ type: parent.type,
8
9
  requiredProducts: parent.required_products?.map((r) => ({
9
10
  product: r?.product?.[0],
10
11
  quantity: r.quantity