@nuskin/cs-product-lib 1.1.4 → 1.2.0-brw-4716.2
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 +1 -1
- package/src/csProduct.js +6 -0
- package/src/formatProduct.js +1 -1
- package/src/helpers.js +25 -18
- package/src/transformBundle.js +1 -1
package/package.json
CHANGED
package/src/csProduct.js
CHANGED
|
@@ -453,6 +453,12 @@ const csProduct = (props) => {
|
|
|
453
453
|
if (!Array.isArray(skus)) {
|
|
454
454
|
skus = [skus]
|
|
455
455
|
}
|
|
456
|
+
|
|
457
|
+
const skuBundle = await getBundles(skus, locale)
|
|
458
|
+
if (skuBundle.length > 0 && !skuBundle[0].error || skuBundle[0].error.message !== undefined) {
|
|
459
|
+
return skuBundle
|
|
460
|
+
}
|
|
461
|
+
|
|
456
462
|
const query = `{"variants": {"$in_query":{"sap_data.skus": {"$in": ${helpers?.arrayString(
|
|
457
463
|
skus
|
|
458
464
|
)}}}}}`
|
package/src/formatProduct.js
CHANGED
|
@@ -21,7 +21,7 @@ const formatProduct = (parent, homeUrl) => {
|
|
|
21
21
|
features: helpers?.mapFeatures(parent),
|
|
22
22
|
productDetails: helpers?.mapProductDetails(parent),
|
|
23
23
|
benefitsMedia: {
|
|
24
|
-
image: helpers?.mapImage(parent?.benefits_media?.image),
|
|
24
|
+
image: helpers?.mapImage(parent?.benefits_media?.image, true, null, 460, 95),
|
|
25
25
|
youTubeVideoId: parent?.benefits_media?.youtube_video_id
|
|
26
26
|
},
|
|
27
27
|
benefits: helpers?.mapBenefits(parent),
|
package/src/helpers.js
CHANGED
|
@@ -131,7 +131,7 @@ function mapSubscriptions(subscriptions) {
|
|
|
131
131
|
/* istanbul ignore next */
|
|
132
132
|
function mapProductImages(parent) {
|
|
133
133
|
if ((parent?.product_images_bynder || []).length) {
|
|
134
|
-
return parent?.product_images_bynder.map((img) => mapImage(img))
|
|
134
|
+
return parent?.product_images_bynder.map((img) => mapImage(img, true, 600, 600, 95))
|
|
135
135
|
}
|
|
136
136
|
if ((parent?.product_images || []).length) {
|
|
137
137
|
return parent?.product_images.map((img) => mapImage(img))
|
|
@@ -254,7 +254,7 @@ function mapCsStatus(variant) {
|
|
|
254
254
|
const getProductImages = (parent = {}) => {
|
|
255
255
|
const { product_images_bynder = [], product_images = [] } = parent
|
|
256
256
|
if (product_images_bynder?.length)
|
|
257
|
-
return product_images_bynder?.map((img) => mapImage(img))
|
|
257
|
+
return product_images_bynder?.map((img) => mapImage(img, true, 600, 600, 95))
|
|
258
258
|
|
|
259
259
|
return product_images?.map((img) => mapImage(img))
|
|
260
260
|
}
|
|
@@ -498,7 +498,7 @@ function mapPoints(parent) {
|
|
|
498
498
|
}
|
|
499
499
|
|
|
500
500
|
/* istanbul ignore next */
|
|
501
|
-
function mapImage(image, useWebp = false) {
|
|
501
|
+
function mapImage(image, useWebp = false, width, height, quality = 100, transform = 'fit') {
|
|
502
502
|
if (Array.isArray(image)) {
|
|
503
503
|
image = image[0]
|
|
504
504
|
}
|
|
@@ -524,10 +524,17 @@ function mapImage(image, useWebp = false) {
|
|
|
524
524
|
// isSvg will only work if a public link to the original derivative is authored on the bynder asset.
|
|
525
525
|
const isSvg = derivatives.original && derivatives.original.includes('.svg');
|
|
526
526
|
let imgURL = derivatives.webImage
|
|
527
|
+
let thumbnail = derivatives.thumbnail
|
|
527
528
|
if (isSvg) {
|
|
528
529
|
imgURL = derivatives.original
|
|
529
|
-
} else if (
|
|
530
|
-
imgURL = `${derivatives.transformBaseUrl}.webp`
|
|
530
|
+
} else if (derivatives.transformBaseUrl) {
|
|
531
|
+
imgURL = thumbnail = `${derivatives.transformBaseUrl}${useWebp ? '.webp' : ''}`
|
|
532
|
+
if (width || height) {
|
|
533
|
+
imgURL += `?quality=${quality}&io=transform:${transform}${width ? `,width:${width}` : ''}${height ? `,height:${height}` : ''}`
|
|
534
|
+
} else if (quality && quality !== 100) {
|
|
535
|
+
imgURL += `?quality=${quality}`
|
|
536
|
+
}
|
|
537
|
+
thumbnail += '?quality=85&io=transform:fill,width:50,height:50'
|
|
531
538
|
}
|
|
532
539
|
return {
|
|
533
540
|
url: imgURL,
|
|
@@ -536,7 +543,7 @@ function mapImage(image, useWebp = false) {
|
|
|
536
543
|
image.description ||
|
|
537
544
|
image.name ||
|
|
538
545
|
'',
|
|
539
|
-
thumbnail:
|
|
546
|
+
thumbnail: thumbnail
|
|
540
547
|
}
|
|
541
548
|
} else if ((image || {}).files) {
|
|
542
549
|
const isSvg = (image.files.original || {}).url && (image.files.original || {}).url.includes('.svg');
|
|
@@ -593,7 +600,7 @@ function mapProductDetails(productOrVariant) {
|
|
|
593
600
|
const includedItems = productDetails.included_items
|
|
594
601
|
const highlights = (productDetails.highlights || []).map((highlight) => ({
|
|
595
602
|
iconUrl: !isNullOrEmpty(highlight.icon_bynder)
|
|
596
|
-
? (mapImage(highlight.icon_bynder) || {}).url
|
|
603
|
+
? (mapImage(highlight.icon_bynder, true, 60, 60, 95) || {}).url
|
|
597
604
|
: (highlight.icon || {}).url,
|
|
598
605
|
label: highlight.text
|
|
599
606
|
}))
|
|
@@ -624,7 +631,7 @@ function featureImage(feature) {
|
|
|
624
631
|
function mapFeatures(productOrVariant) {
|
|
625
632
|
return ((productOrVariant || {}).features || []).map((feature = {}) => ({
|
|
626
633
|
// eslint-disable-next-line no-nested-ternary
|
|
627
|
-
image: mapImage(featureImage(feature)),
|
|
634
|
+
image: mapImage(featureImage(feature), true, null, 455, 95),
|
|
628
635
|
subtitle: feature.header,
|
|
629
636
|
features: feature.features,
|
|
630
637
|
backgroundColor: mapBrandStyle(feature, BACKGROUND_COLOR),
|
|
@@ -716,7 +723,7 @@ function mapBenefitsAndFeatures(productOrVariant) {
|
|
|
716
723
|
: jsonBenefits
|
|
717
724
|
|
|
718
725
|
return {
|
|
719
|
-
image: mapImage(benefitsMedia.image),
|
|
726
|
+
image: mapImage(benefitsMedia.image, true, null, 460, 95),
|
|
720
727
|
youTubeVideoId: benefitsMedia.youTubeVideoId,
|
|
721
728
|
benefits: benefitsToMarkdown(legacyBenefits, jsonBenefits),
|
|
722
729
|
backgroundColor: productOrVariant?.background_color,
|
|
@@ -740,7 +747,7 @@ function mapResults(productOrVariant) {
|
|
|
740
747
|
image: mapImage(
|
|
741
748
|
(Array.isArray(results.image_or_video) &&
|
|
742
749
|
results.image_or_video.length > 0) ||
|
|
743
|
-
results.image
|
|
750
|
+
results.image, true, null, 460, 95
|
|
744
751
|
),
|
|
745
752
|
youTubeVideoId: results.youtube_video_id
|
|
746
753
|
}
|
|
@@ -752,7 +759,7 @@ function mapSustainability(product) {
|
|
|
752
759
|
const image = mapImage(
|
|
753
760
|
Array.isArray(sustainability.image)
|
|
754
761
|
? sustainability.image[0]
|
|
755
|
-
: sustainability.image
|
|
762
|
+
: sustainability.image, true, null, 460, 95
|
|
756
763
|
)
|
|
757
764
|
const richText = sustainability.description
|
|
758
765
|
const description = hasRichTextContent(richText)
|
|
@@ -762,7 +769,7 @@ function mapSustainability(product) {
|
|
|
762
769
|
image: mapImage(
|
|
763
770
|
Array.isArray(highlight.image)
|
|
764
771
|
? highlight.image[0]
|
|
765
|
-
: highlight.image
|
|
772
|
+
: highlight.image, true, 60, 60, 95
|
|
766
773
|
),
|
|
767
774
|
description: hasRichTextContent(highlight.description)
|
|
768
775
|
? createMarkdown(highlight.description)
|
|
@@ -787,7 +794,7 @@ function mapUsage(productOrVariant, legacyUsage) {
|
|
|
787
794
|
recommendations: decodeHTML(usage.recommendations),
|
|
788
795
|
warnings: decodeHTML(usage.warnings),
|
|
789
796
|
additionalText: usage.additional_text,
|
|
790
|
-
image: mapImage(usage.image_or_video || usage.image),
|
|
797
|
+
image: mapImage(usage.image_or_video || usage.image, true, null, 460, 95),
|
|
791
798
|
youTubeVideoId: usage.youtube_video_id,
|
|
792
799
|
markdown: legacyUsage ? htmlToMarkdown(legacyUsage) : null
|
|
793
800
|
}
|
|
@@ -856,7 +863,7 @@ function mapIngredients(ings, legacyIngredients) {
|
|
|
856
863
|
keyIngredients: ((ingredients || {}).key_ingredients || []).map(
|
|
857
864
|
(keyIngredient) => ({
|
|
858
865
|
image: !isNullOrEmpty(keyIngredient.icon_bynder)
|
|
859
|
-
? mapImage(keyIngredient.icon_bynder, true)
|
|
866
|
+
? mapImage(keyIngredient.icon_bynder, true, 100, 100, 95)
|
|
860
867
|
: {
|
|
861
868
|
url: (keyIngredient.icon || {}).url,
|
|
862
869
|
alt: (keyIngredient.icon || {}).title
|
|
@@ -868,7 +875,7 @@ function mapIngredients(ings, legacyIngredients) {
|
|
|
868
875
|
nutritionInformationImage: !isNullOrEmpty(
|
|
869
876
|
(ingredients || {}).nutrition_information_image_bynder
|
|
870
877
|
)
|
|
871
|
-
? mapImage(ingredients.nutrition_information_image_bynder)
|
|
878
|
+
? mapImage(ingredients.nutrition_information_image_bynder, true, null, 1200, 95)
|
|
872
879
|
: (ingredients || {}).nutrition_information_image
|
|
873
880
|
? {
|
|
874
881
|
url: ingredients.nutrition_information_image.url,
|
|
@@ -894,7 +901,7 @@ function mapIngredients(ings, legacyIngredients) {
|
|
|
894
901
|
{
|
|
895
902
|
keyIngredients: keyIngredients.map((keyIngredient) => ({
|
|
896
903
|
image: !isNullOrEmpty(keyIngredient.icon_bynder)
|
|
897
|
-
? mapImage(keyIngredient.icon_bynder, true)
|
|
904
|
+
? mapImage(keyIngredient.icon_bynder, true, 100, 100, 95)
|
|
898
905
|
: {
|
|
899
906
|
url: (keyIngredient.icon || {}).url,
|
|
900
907
|
alt: (keyIngredient.icon || {}).title
|
|
@@ -905,7 +912,7 @@ function mapIngredients(ings, legacyIngredients) {
|
|
|
905
912
|
nutritionInformationImage: !isNullOrEmpty(
|
|
906
913
|
(ings || {}).nutrition_information_image_bynder
|
|
907
914
|
)
|
|
908
|
-
? mapImage(ings.nutrition_information_image_bynder)
|
|
915
|
+
? mapImage(ings.nutrition_information_image_bynder, true, null, 1200, 95)
|
|
909
916
|
: (ings || {}).nutrition_information_image
|
|
910
917
|
? {
|
|
911
918
|
url: ings.nutrition_information_image.url,
|
|
@@ -953,7 +960,7 @@ function mapDisclaimerWarnings(disclaimerWarnings) {
|
|
|
953
960
|
if (!text && !hasRichTextContent(richText)) {
|
|
954
961
|
return null
|
|
955
962
|
}
|
|
956
|
-
const icon = mapImage(disclaimerWarning.icon)
|
|
963
|
+
const icon = mapImage(disclaimerWarning.icon, true, 25, 25, 85)
|
|
957
964
|
const boldText = disclaimerWarning.bold_text || ''
|
|
958
965
|
const link = mapLink(disclaimerWarning.link)
|
|
959
966
|
const markdownText = createMarkdown(richText, text, boldText, link)
|
package/src/transformBundle.js
CHANGED
|
@@ -22,7 +22,7 @@ const transformBundle = (parent, homeUrl) => ({
|
|
|
22
22
|
salesLabel: parent?.sales_label,
|
|
23
23
|
salesText: parent?.sales_text,
|
|
24
24
|
features: {
|
|
25
|
-
image: helpers?.mapImage(parent?.features?.image),
|
|
25
|
+
image: helpers?.mapImage(parent?.features?.image, true, null, 455, 95),
|
|
26
26
|
subtitle: parent?.features?.header,
|
|
27
27
|
features: parent?.features?.features,
|
|
28
28
|
backgroundColor: parent?.features?.background_color
|