@nuskin/cs-product-lib 1.0.3 → 1.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/cs-product-lib",
3
- "version": "1.0.3",
3
+ "version": "1.0.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": {
@@ -27,10 +27,7 @@ const formatProduct = (parent, homeUrl) => ({
27
27
  sustainability: helpers?.mapSustainability(parent),
28
28
  usage: helpers?.mapUsage(parent, parent.legacy_usage),
29
29
  resources: helpers?.mapResources(parent),
30
- faqs: parent.faqs?.map((faq) => ({
31
- question: faq.question,
32
- answers: faq.answer || []
33
- })),
30
+ faqs: helpers?.mapFaqs(parent),
34
31
  categories: parent.categories?.map((category) => ({
35
32
  displayName: category.display_name,
36
33
  id: category.category_id,
@@ -50,10 +50,7 @@ const formatVariant = (parent) => ({
50
50
  results: helpers?.mapResults(parent),
51
51
  usage: helpers?.mapUsage(parent, parent.legacy_usage),
52
52
  resources: helpers?.mapResources(parent),
53
- faqs: parent?.faqs?.map((faq) => ({
54
- question: faq.question,
55
- answers: faq.answer || []
56
- })),
53
+ faqs: helpers?.mapFaqs(parent),
57
54
  disclaimers: parent.disclaimers || [],
58
55
  disclaimerWarnings: helpers?.mapDisclaimerWarnings(
59
56
  parent.disclaimer_warnings
package/src/helpers.js CHANGED
@@ -1058,6 +1058,30 @@ function mapCrossProductIds(product) {
1058
1058
  return []
1059
1059
  }
1060
1060
 
1061
+ function mapFaqs(product) {
1062
+ if (product && product.faqs && product.faqs.length > 0) {
1063
+ let jsonFaqs = JSON.stringify(product.faqs);
1064
+ if (jsonFaqs.length < 10000) {
1065
+ return product?.faqs?.map((faq) => ({
1066
+ question: faq.question,
1067
+ answers: faq.answer || []
1068
+ }))
1069
+ }
1070
+ // equinox platform has a FAQ content character limit for imported products 👇
1071
+ while (jsonFaqs.length >= 10000) {
1072
+ let parsed = JSON.parse(jsonFaqs)
1073
+ // keep removing last FAQ object until desired content length is achieved
1074
+ parsed.pop()
1075
+ jsonFaqs = JSON.stringify(parsed)
1076
+ }
1077
+ return JSON.parse(jsonFaqs).map((faq) => ({
1078
+ question: faq.question,
1079
+ answers: faq.answer || []
1080
+ }))
1081
+ }
1082
+ return []
1083
+ }
1084
+
1061
1085
  module.exports = {
1062
1086
  mapBrandStyle,
1063
1087
  mapWarranty,
@@ -1098,5 +1122,6 @@ module.exports = {
1098
1122
  mapPurchaseTypes,
1099
1123
  getProductImages,
1100
1124
  parseLocale,
1101
- reorderLocale
1125
+ reorderLocale,
1126
+ mapFaqs
1102
1127
  }