@nuskin/cs-product-lib 1.3.0-td-624.4 → 1.3.0

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.3.0-td-624.4",
3
+ "version": "1.3.0",
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
@@ -10,7 +10,6 @@ const { transformBundle } = require('./transformBundle')
10
10
  const { formatCategoryTranslations } = require('./formatCategoryTranslations')
11
11
  const { isNullOrEmpty } = require('@nuskin/ns-common-lib')
12
12
  const { formatDiscounts } = require('./helpers/formatDiscounts');
13
- const { formatCategory } = require('./formatCategory')
14
13
 
15
14
  const validateConfig = (props) => {
16
15
  if (!props) {
@@ -56,16 +55,16 @@ const csProduct = (props) => {
56
55
  const PRODUCT_BRAND_STYLE = 'features.brand_style'
57
56
  const DEFAULT_LOCALE = 'en'
58
57
  const PRODUCT_TYPE = 'product'
59
- const CATEGORY_TYPE = 'category'
60
58
  const INCLUDE_FALLBACK = '&include_fallback=true'
61
59
  const REQUIRED = 'required_products.product.'
62
60
  const OPTIONAL = 'optional_products.product.'
63
61
  const BUNDLE_TYPE = 'bundle'
64
62
  const PRODUCT_BUNDLE = 'product_bundle'
65
63
  const PRODUCT_SKU_KIT = 'sku_kit'
64
+ const VARIANT_DISCONTINUED_SKU_REPLACEMENT = 'variants.discontinued_sku_replacement'
66
65
 
67
66
  // eslint-disable-next-line max-len
68
- 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}&include[]=${PRODUCT_SKU_KIT}`
67
+ 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}&include[]=${PRODUCT_SKU_KIT}&include[]=${VARIANT_DISCONTINUED_SKU_REPLACEMENT}`
69
68
  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}`
70
69
  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}`
71
70
  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}`
@@ -618,28 +617,6 @@ const csProduct = (props) => {
618
617
  }
619
618
  }
620
619
 
621
- const getCategoryById = async (id,locale) => {
622
- locale = badLocaleMap(locale)
623
- try{
624
- const categories = await getEntriesByQuery({
625
- contentType: CATEGORY_TYPE,
626
- query: `{ "$or": [{"category_id": { "$regex": "^${id}" }}, {"display_name": { "$regex": "^${id}" }}, {"seo_information.slug": { "$regex": "^${id}" }}] }`,
627
- locale,
628
- includes: ['subcategories']
629
- });
630
- const { country, language} = helpers.parseLocale(locale);
631
- const category = categories[0];
632
- category.localeData = {
633
- country,
634
- language
635
- }
636
- let formattedCategory = formatCategory(category, language , homeUrl);
637
- return formattedCategory;
638
- }catch(error){
639
- return new Error('Failed to fetch category');
640
- }
641
- }
642
-
643
620
  return {
644
621
  asObject,
645
622
  getEntriesByQuery,
@@ -654,8 +631,7 @@ const csProduct = (props) => {
654
631
  getBundle,
655
632
  getBundles,
656
633
  getCategoryPageTranslations,
657
- formatProductWithSchema,
658
- getCategoryById
634
+ formatProductWithSchema
659
635
  }
660
636
  }
661
637
 
@@ -7,6 +7,8 @@ const formatTranslations = (parent) => ({
7
7
  parent?.common_strings?.product?.addToCart,
8
8
  allIngredients: parent?.all_ingredients,
9
9
  otherIngredients: parent?.other_ingredients,
10
+ replacementTitle: parent?.pdp_replacementtitle,
11
+ itemDiscontinued: parent?.pdp_itemdiscontinued,
10
12
  activeIngredients: parent?.active_ingredients,
11
13
  inactiveIngredients: parent?.inactive_ingredients,
12
14
  benefitsAndKeyFeatures: parent?.benefits_and_key_features,
@@ -118,7 +118,8 @@ const formatVariant = (parent) => {
118
118
  channels: helpers?.getBestSkuData(parent)?.channels,
119
119
  foreignLimit: helpers?.getBestSkuData(parent)?.foreign_limit,
120
120
  foreignOrderLimit: helpers?.getBestSkuData(parent)?.foreign_limit,
121
- orderType: parent.sap_data?.order_type
121
+ orderType: parent.sap_data?.order_type,
122
+ discontinuedSkuReplacement: helpers?.mapDiscontinuedSkuReplacement(parent)?.sku
122
123
  }
123
124
  }
124
125
 
package/src/helpers.js CHANGED
@@ -348,15 +348,6 @@ function mapSeoInformation(parent, homeUrl, type) {
348
348
  parent?.seo_information?.slug
349
349
  }`
350
350
  break
351
- case 'nav-category':
352
- seoData.canonicalURL = `${homeUrl}/${
353
- parent?.localeData?.country
354
- }/${parent?.localeData?.language}/catalog/${
355
- parent?.category_id || parent?.seo_information?.slug
356
- }`
357
- seoData.metaTitle = seoData.metaTitle || parent?.display_name || '',
358
- seoData.metaDescription = seoData.metaDescription || ''
359
- break
360
351
  default:
361
352
  break
362
353
  }
@@ -1191,6 +1182,14 @@ function mapFaqs(product) {
1191
1182
  return []
1192
1183
  }
1193
1184
 
1185
+ function mapDiscontinuedSkuReplacement (product) {
1186
+ if (product?.discontinued_sku_replacement?.length > 0) {
1187
+ return getBestSkuData(product?.discontinued_sku_replacement[0])
1188
+ } else {
1189
+ return {}
1190
+ }
1191
+ }
1192
+
1194
1193
  module.exports = {
1195
1194
  mapBrandStyle,
1196
1195
  mapWarranty,
@@ -1235,5 +1234,6 @@ module.exports = {
1235
1234
  mapFaqs,
1236
1235
  createMarkdownFromRTE,
1237
1236
  benefitsToMarkdown,
1238
- mapActiveEventDisclaimer
1237
+ mapActiveEventDisclaimer,
1238
+ mapDiscontinuedSkuReplacement
1239
1239
  }
@@ -1,35 +0,0 @@
1
- const helpers = require('./helpers')
2
- const formatCategory = (parent, language, homeUrl) => {
3
- return {
4
- displayName: parent?.display_name || '',
5
- categoryIdentifier: parent?.category_id || '',
6
- status: parent?.status || 'Inactive',
7
- isHiddenFromNavigation: parent?.is_hidden_from_navigation || false,
8
- startTime: parent?.start_time || '1994-01-03T08:00:01.000Z',
9
- endTime: parent?.end_time || '2038-01-01T08:00:01.000Z',
10
- // IT NEEDS TO BE CALCULATED BY CALLING CS API
11
- isTopCategory: parent?.is_top_category || false,
12
- image: helpers.mapImage(parent?.image),
13
- description: parent?.description?.[0] || '',
14
- subcategories: parent?.subcategories?.map((subcategory,index) => ({
15
- displayName: subcategory?.display_name || '',
16
- categoryIdentifier: subcategory?.category_id || '',
17
- // SEQUENCE NUMBER IS CATEGORY ORDER NUMBER IN CS
18
- sequence: index + 1
19
- })) || [],
20
- seoInformation: helpers.mapSeoInformation(
21
- parent,
22
- homeUrl,
23
- 'nav-category'
24
- ),
25
- products:
26
- parent?.products?.map((product) => ({
27
- title: product?.title || '',
28
- productID: product?.product_id || ''
29
- })) || [],
30
- language: language || 'en'
31
- }
32
- }
33
- module.exports = {
34
- formatCategory
35
- }