@nuskin/cs-product-lib 1.0.0 → 1.0.1-cx12-6830.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 +2 -1
- package/src/axiosClient.js +30 -0
- package/src/csProduct.js +272 -105
- package/src/formatProduct.js +81 -0
- package/src/formatTranslations.js +162 -0
- package/src/formatVariant.js +115 -0
- package/src/helpers.js +748 -218
- package/src/index.js +1 -0
- package/src/marketRegionMappings.js +65 -0
- package/src/productStatus.js +6 -3
- package/src/status.js +186 -0
- package/src/transformBundle.js +68 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
const formatTranslations = (parent) => ({
|
|
2
|
+
// each value is a function with 'parent' which is the ProductTranslations instance
|
|
3
|
+
product: parent?.product,
|
|
4
|
+
addToCartButton:
|
|
5
|
+
parent?.common_strings_overrides?.cart?.add_to_cart_button ||
|
|
6
|
+
parent?.common_strings.product?.addToCart,
|
|
7
|
+
allIngredients: parent.all_ingredients,
|
|
8
|
+
otherIngredients: parent.other_ingredients,
|
|
9
|
+
activeIngredients: parent.active_ingredients,
|
|
10
|
+
inactiveIngredients: parent.inactive_ingredients,
|
|
11
|
+
benefitsAndKeyFeatures: parent.benefits_and_key_features,
|
|
12
|
+
buyOnce:
|
|
13
|
+
parent?.common_strings_overrides?.cart?.buy_once ||
|
|
14
|
+
parent?.common_strings?.product?.buyOnce,
|
|
15
|
+
description:
|
|
16
|
+
parent?.common_strings_overrides?.description ||
|
|
17
|
+
parent.common_strings.product?.description,
|
|
18
|
+
nettoWeight:
|
|
19
|
+
parent?.common_strings_overrides?.netto_weight ||
|
|
20
|
+
parent?.common_strings?.product?.nettoWeight,
|
|
21
|
+
frequentlyAskedQuestions: parent.frequently_asked_questions,
|
|
22
|
+
howToUseIt: parent.how_to_use_it,
|
|
23
|
+
item:
|
|
24
|
+
parent?.common_strings_overrides?.item ||
|
|
25
|
+
parent?.common_strings?.product?.item,
|
|
26
|
+
keyIngredients: parent.key_ingredients,
|
|
27
|
+
shipping: {
|
|
28
|
+
message:
|
|
29
|
+
parent?.common_strings_overrides?.shipping?.message ||
|
|
30
|
+
parent?.common_strings?.product?.shippingMessage,
|
|
31
|
+
boldText:
|
|
32
|
+
parent?.common_strings_overrides?.shipping?.bold_text ||
|
|
33
|
+
parent?.common_strings.product?.shippingBoldText
|
|
34
|
+
},
|
|
35
|
+
refund: {
|
|
36
|
+
message:
|
|
37
|
+
parent?.common_strings_overrides?.refund?.message ||
|
|
38
|
+
parent?.common_strings.product?.refundMessage,
|
|
39
|
+
linkText:
|
|
40
|
+
parent?.common_strings_overrides?.refund?.link_text ||
|
|
41
|
+
parent?.common_strings?.product?.refundLinkText,
|
|
42
|
+
linkUrl:
|
|
43
|
+
parent?.common_strings_overrides?.refund?.link_url ||
|
|
44
|
+
parent?.common_strings?.product?.refundLinkUrl
|
|
45
|
+
},
|
|
46
|
+
loyalty: {
|
|
47
|
+
message: parent.loyalty?.message,
|
|
48
|
+
linkText: parent.loyalty?.link_text
|
|
49
|
+
},
|
|
50
|
+
exclusiveOffer: {
|
|
51
|
+
title: parent.exclusive_offer?.title,
|
|
52
|
+
message: parent.exclusive_offer?.message,
|
|
53
|
+
noQualification: parent.exclusive_offer?.no_qualification,
|
|
54
|
+
usedUpQty: parent.exclusive_offer?.used_up_qty,
|
|
55
|
+
notAvailable: parent.exclusive_offer?.not_available
|
|
56
|
+
},
|
|
57
|
+
cartToast: {
|
|
58
|
+
addedToCart:
|
|
59
|
+
parent?.common_strings_overrides?.cart?.added_to_cart ||
|
|
60
|
+
parent?.common_strings?.product?.addedToCartMessage,
|
|
61
|
+
viewCart:
|
|
62
|
+
parent?.common_strings_overrides?.cart?.view_cart ||
|
|
63
|
+
parent?.common_strings?.product?.viewCart,
|
|
64
|
+
failedAddToCart:
|
|
65
|
+
parent?.common_strings_overrides?.cart?.failed_add_to_cart ||
|
|
66
|
+
parent?.common_strings?.product?.failedToAddToCart
|
|
67
|
+
},
|
|
68
|
+
maxQuantityExceeded:
|
|
69
|
+
parent?.common_strings_overrides.status?.max_quantity_exceeded ||
|
|
70
|
+
parent?.common_strings.product?.maxQuantityExceeded,
|
|
71
|
+
nutritionFacts: parent.nutrition_facts,
|
|
72
|
+
price: {
|
|
73
|
+
retail:
|
|
74
|
+
parent?.common_strings_overrides?.price?.retail ||
|
|
75
|
+
parent?.common_strings?.pricing?.retail,
|
|
76
|
+
wholesale:
|
|
77
|
+
parent?.common_strings_overrides?.price?.wholesale ||
|
|
78
|
+
parent?.common_strings?.pricing?.wholesale,
|
|
79
|
+
subscription:
|
|
80
|
+
parent?.common_strings_overrides?.price?.subscription ||
|
|
81
|
+
parent?.common_strings?.pricing?.subscription,
|
|
82
|
+
retailSales:
|
|
83
|
+
parent?.common_strings_overrides?.price?.retail_sales ||
|
|
84
|
+
parent?.common_strings?.pricing?.retail_sales,
|
|
85
|
+
wholesaleSales:
|
|
86
|
+
parent?.common_strings_overrides?.price?.wholesale_sales ||
|
|
87
|
+
parent?.common_strings?.pricing?.wholesale_sales
|
|
88
|
+
},
|
|
89
|
+
points: {
|
|
90
|
+
sv: undefined, // TODO: deprecated, remove
|
|
91
|
+
csv: undefined, // TODO: deprecated, remove
|
|
92
|
+
pv: parent?.common_strings?.pricing?.pv,
|
|
93
|
+
cv: parent?.common_strings?.pricing?.cv
|
|
94
|
+
},
|
|
95
|
+
productDetails: parent.product_details,
|
|
96
|
+
provenResults: parent.proven_results,
|
|
97
|
+
socialImpactAndSustainability: parent.social_impact_and_sustainability,
|
|
98
|
+
recommendations: parent.recommendations,
|
|
99
|
+
resources: parent.resources,
|
|
100
|
+
resourcesSubtitle: parent.resources_subtitle,
|
|
101
|
+
selectPurchaseType: parent.select_purchase_type,
|
|
102
|
+
selectVariant: parent.select_variant,
|
|
103
|
+
similarProducts: parent.similar_products,
|
|
104
|
+
status: {
|
|
105
|
+
outOfStock:
|
|
106
|
+
parent?.common_strings_overrides?.status?.out_of_stock ||
|
|
107
|
+
parent?.common_strings?.product?.outOfStock,
|
|
108
|
+
onBackorder:
|
|
109
|
+
parent?.common_strings_overrides?.status?.on_backorder ||
|
|
110
|
+
parent?.common_strings?.product?.onBackorder,
|
|
111
|
+
reachedPurchaseLimit:
|
|
112
|
+
parent?.common_strings_overrides?.status?.reached_purchase_limit ||
|
|
113
|
+
parent?.common_strings?.product?.reachedPurchaseLimit,
|
|
114
|
+
discontinued:
|
|
115
|
+
parent?.common_strings_overrides?.status?.discontinued ||
|
|
116
|
+
parent?.common_strings?.product?.discontinued,
|
|
117
|
+
notReleasedForSale:
|
|
118
|
+
parent?.common_strings_overrides?.status?.not_released_for_sale ||
|
|
119
|
+
parent?.common_strings?.product?.notReleasedForSale,
|
|
120
|
+
stopStatus:
|
|
121
|
+
parent?.common_strings_overrides?.status?.stop_status ||
|
|
122
|
+
parent?.common_strings?.product?.stopStatus,
|
|
123
|
+
notSoldSeperately:
|
|
124
|
+
parent?.common_strings_overrides?.notSoldSeparately
|
|
125
|
+
?.notSoldSeparately ||
|
|
126
|
+
parent?.common_strings?.product?.notSoldSeparately
|
|
127
|
+
},
|
|
128
|
+
steps: parent.steps,
|
|
129
|
+
subscribe:
|
|
130
|
+
parent?.common_strings_overrides.cart?.subscribe ||
|
|
131
|
+
parent?.common_strings.product?.subscribe,
|
|
132
|
+
subscribeButton:
|
|
133
|
+
parent?.common_strings_overrides.cart?.subscribe_button ||
|
|
134
|
+
parent?.common_strings.product?.subscribeMonthly,
|
|
135
|
+
total:
|
|
136
|
+
parent?.common_strings_overrides?.cart?.total ||
|
|
137
|
+
parent?.common_strings?.product?.total,
|
|
138
|
+
viewReport: parent.view_report,
|
|
139
|
+
whatPowersIt: parent.what_powers_it,
|
|
140
|
+
whatsIncluded: parent.whats_included,
|
|
141
|
+
whyYoullLoveIt: parent.why_youll_love_it,
|
|
142
|
+
countryOfOrigin: parent.country_of_origin,
|
|
143
|
+
importer: parent.importer,
|
|
144
|
+
warnings: parent.warnings,
|
|
145
|
+
disclaimers: parent.disclaimers,
|
|
146
|
+
subscriptions: parent.subscriptions,
|
|
147
|
+
generalDisclaimer: parent.general_disclaimer_text,
|
|
148
|
+
generic: {
|
|
149
|
+
back: parent?.common_strings.generic?.back,
|
|
150
|
+
done: parent?.common_strings.generic?.done,
|
|
151
|
+
enter: parent?.common_strings.generic?.enter,
|
|
152
|
+
select: parent?.common_strings.generic?.select,
|
|
153
|
+
quantity: parent?.common_strings.generic?.quantity
|
|
154
|
+
},
|
|
155
|
+
accounts: {
|
|
156
|
+
signIn: parent?.common_strings?.accounts?.sign_in
|
|
157
|
+
}
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
module.exports = {
|
|
161
|
+
formatTranslations
|
|
162
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
const helpers = require('./helpers')
|
|
2
|
+
const _ = require('lodash')
|
|
3
|
+
const entities = require('entities')
|
|
4
|
+
|
|
5
|
+
const formatVariant = (parent) => ({
|
|
6
|
+
// Each value is a function with a parameter 'parent' that is the current instance of a Variant
|
|
7
|
+
// ContentStack references need to be queried separately
|
|
8
|
+
id: parent?.uid,
|
|
9
|
+
globalId: parent?.sap_data?.global_id,
|
|
10
|
+
sku: helpers?.getBestSkuData(parent)?.sku,
|
|
11
|
+
slug: parent?.slug,
|
|
12
|
+
size: parent?.size,
|
|
13
|
+
variantLabel: parent?.select_label,
|
|
14
|
+
variantColor: parent?.select_color,
|
|
15
|
+
title: parent?.name || parent?.defaults?.name,
|
|
16
|
+
salesLabel: parent?.sales_label,
|
|
17
|
+
salesText: parent?.sales_text,
|
|
18
|
+
description: entities.decodeHTML(
|
|
19
|
+
parent?.short_description_override || parent?.defaults.description || ''
|
|
20
|
+
),
|
|
21
|
+
salesDisclaimer: helpers?.mapSalesDisclaimer(parent?.sales_disclaimer),
|
|
22
|
+
nettoWeight: parent?.netto_weight,
|
|
23
|
+
productImages: helpers?.mapProductImages(parent),
|
|
24
|
+
isExclusive: parent?.is_exclusive,
|
|
25
|
+
pricingJson: JSON.stringify(parent?.defaults?.status?.pricing) || null,
|
|
26
|
+
price: helpers?.mapPrice(parent),
|
|
27
|
+
points: helpers?.mapPoints(parent),
|
|
28
|
+
availableQuantity: _.get(parent, 'defaults.status.availableQuantity', 0),
|
|
29
|
+
maxQuantity: _.get(parent, 'defaults.status.maxQuantity', 0),
|
|
30
|
+
status: {
|
|
31
|
+
retail: _.get(parent, 'defaults.status.status.retail', null),
|
|
32
|
+
wholesale: _.get(parent, 'defaults.status.status.wholesale', null),
|
|
33
|
+
isBackordered: _.get(parent, 'defaults.status.backordered', null),
|
|
34
|
+
backorderedAvailableDate: _.get(
|
|
35
|
+
parent,
|
|
36
|
+
'defaults.status.backorderedAvailableDate',
|
|
37
|
+
''
|
|
38
|
+
)
|
|
39
|
+
},
|
|
40
|
+
csStatus: helpers?.mapCsStatus(parent),
|
|
41
|
+
purchaseTypes: helpers?.mapPurchaseTypes(parent),
|
|
42
|
+
features: helpers?.mapFeatures(parent),
|
|
43
|
+
productDetails: helpers?.mapProductDetails(parent),
|
|
44
|
+
ingredients: helpers?.mapIngredients(
|
|
45
|
+
parent.ingredients_override,
|
|
46
|
+
parent.legacy_ingredients
|
|
47
|
+
),
|
|
48
|
+
benefitsAndFeatures: helpers?.mapBenefitsAndFeatures(parent),
|
|
49
|
+
results: helpers?.mapResults(parent),
|
|
50
|
+
usage: helpers?.mapUsage(parent, parent.legacy_usage),
|
|
51
|
+
resources: helpers?.mapResources(parent),
|
|
52
|
+
faqs: parent?.faqs?.map((faq) => ({
|
|
53
|
+
question: faq.question,
|
|
54
|
+
answers: faq.answer || []
|
|
55
|
+
})),
|
|
56
|
+
disclaimers: parent.disclaimers || [],
|
|
57
|
+
disclaimerWarnings: helpers?.mapDisclaimerWarnings(
|
|
58
|
+
parent.disclaimer_warnings
|
|
59
|
+
),
|
|
60
|
+
matchingVariant:
|
|
61
|
+
parent.sap_data?.sku_data?.findIndex((s) =>
|
|
62
|
+
parent.searchedSkus.includes(s.sku)
|
|
63
|
+
) > -1,
|
|
64
|
+
shadeable: parent.shadeable || false,
|
|
65
|
+
restrictedMarkets: parent.restricted_markets || [],
|
|
66
|
+
productType: parent?.sap_data?.product_type,
|
|
67
|
+
primaryBrand: parent.sap_data?.primary_brand,
|
|
68
|
+
brandFamily: parent?.sap_data?.brand_family,
|
|
69
|
+
marketAttributes: {
|
|
70
|
+
discount: _.get(
|
|
71
|
+
parent,
|
|
72
|
+
'defaults.status.marketAttributes.discount',
|
|
73
|
+
null
|
|
74
|
+
),
|
|
75
|
+
redeem: _.get(parent, 'defaults.status.marketAttributes.redeem', null),
|
|
76
|
+
earn: _.get(parent, 'defaults.status.marketAttributes.earn', null)
|
|
77
|
+
},
|
|
78
|
+
legacyBenefits: parent.legacy_benefits,
|
|
79
|
+
legacyLongDescription: parent.legacy_long_description,
|
|
80
|
+
legacyResources: parent.legacy_resources,
|
|
81
|
+
legacyUsage: parent.legacy_usage,
|
|
82
|
+
legacyIngredients: parent.legacy_ingredients,
|
|
83
|
+
legacyImages: parent.legacy_images || [],
|
|
84
|
+
legacyYouTube: parent.legacy_youtube_video,
|
|
85
|
+
csAtts: {
|
|
86
|
+
version: parent._version || 0,
|
|
87
|
+
updatedAt: parent.updated_at || '',
|
|
88
|
+
updatedBy: parent.updated_by || '',
|
|
89
|
+
createdAt: parent.created_at || '',
|
|
90
|
+
createdBy: parent.created_by || '',
|
|
91
|
+
locale: parent.locale || ''
|
|
92
|
+
},
|
|
93
|
+
searchKeywords: parent.search_keywords,
|
|
94
|
+
excludeFromSearch: parent.exclude_from_search,
|
|
95
|
+
customerTypes: helpers?.getBestSkuData(parent)?.status_selections
|
|
96
|
+
?.customer_types,
|
|
97
|
+
availableChannels: helpers?.getBestSkuData(parent)?.status_selections
|
|
98
|
+
?.display_channels,
|
|
99
|
+
displayChannels: helpers?.getBestSkuData(parent)?.status_selections
|
|
100
|
+
?.display_channels,
|
|
101
|
+
scanQualifiedCount: helpers?.getBestSkuData(parent)?.status_selections
|
|
102
|
+
?.scan_qualify_count,
|
|
103
|
+
scanQualifyCount: helpers?.getBestSkuData(parent)?.status_selections
|
|
104
|
+
?.scan_qualify_count,
|
|
105
|
+
chargeShipping: helpers?.getBestSkuData(parent)?.charge_shipping,
|
|
106
|
+
dangerousGoods: helpers?.getBestSkuData(parent)?.dangerous_goods,
|
|
107
|
+
channels: helpers?.getBestSkuData(parent)?.channels,
|
|
108
|
+
foreignLimit: helpers?.getBestSkuData(parent)?.foreign_limit,
|
|
109
|
+
foreignOrderLimit: helpers?.getBestSkuData(parent)?.foreign_limit,
|
|
110
|
+
orderType: parent.sap_data?.order_type
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
module.exports = {
|
|
114
|
+
formatVariant
|
|
115
|
+
}
|