@nuskin/cs-product-lib 1.0.17 → 1.0.18
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/formatKit.js +45 -39
- package/src/formatTranslations.js +65 -65
- package/src/formatVariant.js +2 -2
- package/src/helpers.js +3 -1
package/package.json
CHANGED
package/src/formatKit.js
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
|
+
const { isNullOrEmpty } = require('@nuskin/ns-common-lib');
|
|
1
2
|
const moment = require('moment')
|
|
2
3
|
|
|
3
4
|
const parseStatus = (variant) => {
|
|
4
5
|
const dateFormat = 'YYYY-MM-DD'
|
|
5
6
|
|
|
6
|
-
if (variant
|
|
7
|
+
if (variant?.type !== 'bundle' && variant?.type !== 'kit') {
|
|
7
8
|
return {
|
|
8
|
-
status: variant
|
|
9
|
-
isBackordered: variant
|
|
10
|
-
backorderedAvailableDate: variant
|
|
9
|
+
status: variant?.status?.status,
|
|
10
|
+
isBackordered: variant?.status?.isBackordered,
|
|
11
|
+
backorderedAvailableDate: variant?.status?.backorderedAvailableDate
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
let isBackordered = false
|
|
15
16
|
let backorderedAvailableDate = null
|
|
16
|
-
if (variant
|
|
17
|
+
if (variant?.type === 'kit') {
|
|
17
18
|
try {
|
|
18
|
-
const latestBODate = Math.max(...variant
|
|
19
|
+
const latestBODate = Math.max(...variant?.requiredProducts?.flatMap(a=>a?.product?.variants?.map(s=>Number(new Date(s?.status?.backorderedAvailableDate)) || 0)))
|
|
19
20
|
if (latestBODate) {
|
|
20
21
|
isBackordered = true
|
|
21
22
|
backorderedAvailableDate = moment(new Date(latestBODate)).format(dateFormat)
|
|
@@ -23,9 +24,9 @@ const parseStatus = (variant) => {
|
|
|
23
24
|
} catch {
|
|
24
25
|
backorderedAvailableDate = null
|
|
25
26
|
}
|
|
26
|
-
} else if (variant
|
|
27
|
+
} else if (variant?.type === 'bundle') {
|
|
27
28
|
try {
|
|
28
|
-
const latestBODate = Math.max(...variant
|
|
29
|
+
const latestBODate = Math.max(...variant?.requiredProducts?.flatMap(a=>Number(new Date(a?.product?.variants[0]?.status?.backorderedAvailableDate)) || 0))
|
|
29
30
|
if (latestBODate) {
|
|
30
31
|
isBackordered = true
|
|
31
32
|
backorderedAvailableDate = moment(new Date(latestBODate)).format(dateFormat)
|
|
@@ -36,14 +37,14 @@ const parseStatus = (variant) => {
|
|
|
36
37
|
}
|
|
37
38
|
return {
|
|
38
39
|
// changed
|
|
39
|
-
status: variant
|
|
40
|
+
status: variant?.status?.status,
|
|
40
41
|
isBackordered: isBackordered,
|
|
41
42
|
backorderedAvailableDate: backorderedAvailableDate
|
|
42
43
|
}
|
|
43
44
|
};
|
|
44
45
|
|
|
45
46
|
const parsePrice = (product = []) => {
|
|
46
|
-
const requiredProducts = product
|
|
47
|
+
const requiredProducts = !isNullOrEmpty(product) ? product?.map(p => p?.requiredProducts) .flat() : []
|
|
47
48
|
|
|
48
49
|
const variants = requiredProducts?.map(p => {
|
|
49
50
|
const [firstVariant] = p?.product?.variants || []
|
|
@@ -72,7 +73,7 @@ const parsePrice = (product = []) => {
|
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
// sum of price and points from 1st variant of product bundle
|
|
75
|
-
const sumOfPriceAndPoints = variants
|
|
76
|
+
const sumOfPriceAndPoints = variants?.reduce((acc, curr) => {
|
|
76
77
|
const price = {}
|
|
77
78
|
const points = {
|
|
78
79
|
subscription : {},
|
|
@@ -99,7 +100,7 @@ const parsePrice = (product = []) => {
|
|
|
99
100
|
|
|
100
101
|
const parseKitAvailableQuantity = (kit) => {
|
|
101
102
|
try {
|
|
102
|
-
return Math.min(...kit.flatMap(a=>a
|
|
103
|
+
return Math.min(...kit.flatMap(a=>a?.sku?.map(s=>s?.inventoryProperties?.atpQty))) || 0
|
|
103
104
|
} catch {
|
|
104
105
|
return 0
|
|
105
106
|
}
|
|
@@ -107,8 +108,8 @@ const parseKitAvailableQuantity = (kit) => {
|
|
|
107
108
|
|
|
108
109
|
const parseBundleAvailableQuantity = (product) => {
|
|
109
110
|
try {
|
|
110
|
-
const {requiredProducts = []} = product
|
|
111
|
-
const quantities = requiredProducts
|
|
111
|
+
const {requiredProducts = []} = !isNullOrEmpty(product) ? product : {}
|
|
112
|
+
const quantities = requiredProducts?.map(p=>p?.product?.variants?.map(a=>a?.availableQuantity))
|
|
112
113
|
return Math.min(...quantities) || 0
|
|
113
114
|
} catch {
|
|
114
115
|
console.log("some error in availableQuantity")
|
|
@@ -118,20 +119,20 @@ const parseBundleAvailableQuantity = (product) => {
|
|
|
118
119
|
|
|
119
120
|
const parseKit = (product, market) => {
|
|
120
121
|
const kits = {}
|
|
121
|
-
const [properties] = product
|
|
122
|
+
const [properties] = !isNullOrEmpty(product) ? product : []
|
|
122
123
|
kits.id = properties?.id
|
|
123
124
|
kits.uid = properties?.uid
|
|
124
125
|
kits.title = properties?.title
|
|
125
126
|
kits.description = properties?.description
|
|
126
|
-
kits.availableChannels = properties
|
|
127
|
-
kits.chargeShipping = properties
|
|
128
|
-
kits.customerTypes = properties
|
|
129
|
-
kits.dangerousGoods = properties
|
|
127
|
+
kits.availableChannels = properties?.availableChannels
|
|
128
|
+
kits.chargeShipping = properties?.chargeShipping === 'true'
|
|
129
|
+
kits.customerTypes = properties?.customerTypes
|
|
130
|
+
kits.dangerousGoods = properties?.dangerousGoods === 'true'
|
|
130
131
|
// missing
|
|
131
|
-
kits.excludeFromSearch = properties
|
|
132
|
-
kits.isExclusive = properties
|
|
132
|
+
kits.excludeFromSearch = properties?.excludeFromSearch === 'true'
|
|
133
|
+
kits.isExclusive = properties?.isExclusive === 'true'
|
|
133
134
|
kits.marketAttributes = properties?.marketAttributes
|
|
134
|
-
kits.maxQuantity = (product
|
|
135
|
+
kits.maxQuantity = (product?.inventoryProperties || {}).atpQty
|
|
135
136
|
const priceData = parsePrice(product)
|
|
136
137
|
kits.points = priceData?.points
|
|
137
138
|
kits.price = priceData?.price
|
|
@@ -148,31 +149,31 @@ const parseKit = (product, market) => {
|
|
|
148
149
|
kits.scanQualifiedCount = properties?.scanQualifiedCount
|
|
149
150
|
// newVariant.slug = undefined
|
|
150
151
|
kits.status = parseStatus(properties)
|
|
151
|
-
if ((kits
|
|
152
|
+
if ((kits?.status || {})?.status === 'active') kits.status.status = 'sellable'
|
|
152
153
|
const kitProducts = []
|
|
153
|
-
if (properties
|
|
154
|
+
if (properties?.type === 'kit' && product?.kit) {
|
|
154
155
|
kits.type = 'kit'
|
|
155
|
-
kits.availableQuantity = parseKitAvailableQuantity(product
|
|
156
|
-
for (const kit of product
|
|
156
|
+
kits.availableQuantity = parseKitAvailableQuantity(product?.kit)
|
|
157
|
+
for (const kit of product?.kit || []) {
|
|
157
158
|
const kitProduct = formatKit(kit, market)
|
|
158
|
-
kitProduct.id = kit
|
|
159
|
-
kitProducts.push({product: kitProduct, quantity: (kit
|
|
159
|
+
kitProduct.id = kit?.identifier
|
|
160
|
+
kitProducts.push({product: kitProduct, quantity: (kit?.properties || {})?.quantity || 0, isMandatory:true})
|
|
160
161
|
}
|
|
161
|
-
} else if (properties
|
|
162
|
-
kits.type = properties
|
|
162
|
+
} else if (properties?.type === 'bundle' || (properties?.type === 'kit' && properties?.requiredProducts)) {
|
|
163
|
+
kits.type = properties?.type
|
|
163
164
|
kits.availableQuantity = parseBundleAvailableQuantity(properties)
|
|
164
165
|
for (const kit of properties?.requiredProducts || []) {
|
|
165
|
-
if (kit
|
|
166
|
+
if (kit?.product) {
|
|
166
167
|
const kitProduct = formatKit(kit?.product, market)
|
|
167
|
-
kitProduct.id = kit
|
|
168
|
-
kitProducts
|
|
168
|
+
kitProduct.id = kit?.product?.id
|
|
169
|
+
kitProducts?.push({product: kitProduct, quantity: kit?.quantity || 0, isMandatory:true})
|
|
169
170
|
}
|
|
170
171
|
}
|
|
171
172
|
for (const kit of properties?.optionalProducts || []) {
|
|
172
|
-
if (kit
|
|
173
|
+
if (kit?.product) {
|
|
173
174
|
const kitProduct = formatKit(kit?.product, market)
|
|
174
|
-
kitProduct.id = kit
|
|
175
|
-
kitProducts
|
|
175
|
+
kitProduct.id = kit?.product?.id
|
|
176
|
+
kitProducts?.push({product: kitProduct, quantity: kit?.quantity || 0, isMandatory:false})
|
|
176
177
|
}
|
|
177
178
|
}
|
|
178
179
|
}
|
|
@@ -187,8 +188,8 @@ const formatKit = (product, market) => {
|
|
|
187
188
|
}
|
|
188
189
|
|
|
189
190
|
let kit = null
|
|
190
|
-
if(['kit', 'bundle'].includes(product
|
|
191
|
-
kit = parseKit(product
|
|
191
|
+
if(['kit', 'bundle'].includes(product?.type)) {
|
|
192
|
+
kit = parseKit(product?.bundle, market)
|
|
192
193
|
}
|
|
193
194
|
return {
|
|
194
195
|
...product,
|
|
@@ -199,6 +200,11 @@ const formatKit = (product, market) => {
|
|
|
199
200
|
|
|
200
201
|
|
|
201
202
|
module.exports = {
|
|
202
|
-
formatKit
|
|
203
|
+
formatKit,
|
|
204
|
+
parseKit,
|
|
205
|
+
parseBundleAvailableQuantity,
|
|
206
|
+
parseKitAvailableQuantity,
|
|
207
|
+
parsePrice,
|
|
208
|
+
parseStatus
|
|
203
209
|
}
|
|
204
210
|
|
|
@@ -3,39 +3,39 @@ const formatTranslations = (parent) => ({
|
|
|
3
3
|
product: parent?.product,
|
|
4
4
|
addToCartButton:
|
|
5
5
|
parent?.common_strings_overrides?.cart?.add_to_cart_button ||
|
|
6
|
-
parent?.common_strings
|
|
7
|
-
allIngredients: parent
|
|
8
|
-
otherIngredients: parent
|
|
9
|
-
activeIngredients: parent
|
|
10
|
-
inactiveIngredients: parent
|
|
11
|
-
benefitsAndKeyFeatures: parent
|
|
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
12
|
buyOnce:
|
|
13
13
|
parent?.common_strings_overrides?.cart?.buy_once ||
|
|
14
14
|
parent?.common_strings?.product?.buyOnce,
|
|
15
15
|
description:
|
|
16
16
|
parent?.common_strings_overrides?.description ||
|
|
17
|
-
parent
|
|
17
|
+
parent?.common_strings?.product?.description,
|
|
18
18
|
nettoWeight:
|
|
19
19
|
parent?.common_strings_overrides?.netto_weight ||
|
|
20
20
|
parent?.common_strings?.product?.nettoWeight,
|
|
21
|
-
frequentlyAskedQuestions: parent
|
|
22
|
-
howToUseIt: parent
|
|
21
|
+
frequentlyAskedQuestions: parent?.frequently_asked_questions,
|
|
22
|
+
howToUseIt: parent?.how_to_use_it,
|
|
23
23
|
item:
|
|
24
24
|
parent?.common_strings_overrides?.item ||
|
|
25
25
|
parent?.common_strings?.product?.item,
|
|
26
|
-
keyIngredients: parent
|
|
26
|
+
keyIngredients: parent?.key_ingredients,
|
|
27
27
|
shipping: {
|
|
28
28
|
message:
|
|
29
29
|
parent?.common_strings_overrides?.shipping?.message ||
|
|
30
30
|
parent?.common_strings?.product?.shippingMessage,
|
|
31
31
|
boldText:
|
|
32
32
|
parent?.common_strings_overrides?.shipping?.bold_text ||
|
|
33
|
-
parent?.common_strings
|
|
33
|
+
parent?.common_strings?.product?.shippingBoldText
|
|
34
34
|
},
|
|
35
35
|
refund: {
|
|
36
36
|
message:
|
|
37
37
|
parent?.common_strings_overrides?.refund?.message ||
|
|
38
|
-
parent?.common_strings
|
|
38
|
+
parent?.common_strings?.product?.refundMessage,
|
|
39
39
|
linkText:
|
|
40
40
|
parent?.common_strings_overrides?.refund?.link_text ||
|
|
41
41
|
parent?.common_strings?.product?.refundLinkText,
|
|
@@ -44,15 +44,15 @@ const formatTranslations = (parent) => ({
|
|
|
44
44
|
parent?.common_strings?.product?.refundLinkUrl
|
|
45
45
|
},
|
|
46
46
|
loyalty: {
|
|
47
|
-
message: parent
|
|
48
|
-
linkText: parent
|
|
47
|
+
message: parent?.loyalty?.message,
|
|
48
|
+
linkText: parent?.loyalty?.link_text
|
|
49
49
|
},
|
|
50
50
|
exclusiveOffer: {
|
|
51
|
-
title: parent
|
|
52
|
-
message: parent
|
|
53
|
-
noQualification: parent
|
|
54
|
-
usedUpQty: parent
|
|
55
|
-
notAvailable: parent
|
|
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
56
|
},
|
|
57
57
|
cartToast: {
|
|
58
58
|
addedToCart:
|
|
@@ -66,9 +66,9 @@ const formatTranslations = (parent) => ({
|
|
|
66
66
|
parent?.common_strings?.product?.failedToAddToCart
|
|
67
67
|
},
|
|
68
68
|
maxQuantityExceeded:
|
|
69
|
-
parent?.common_strings_overrides
|
|
70
|
-
parent?.common_strings
|
|
71
|
-
nutritionFacts: parent
|
|
69
|
+
parent?.common_strings_overrides?.status?.max_quantity_exceeded ||
|
|
70
|
+
parent?.common_strings?.product?.maxQuantityExceeded,
|
|
71
|
+
nutritionFacts: parent?.nutrition_facts,
|
|
72
72
|
price: {
|
|
73
73
|
retail:
|
|
74
74
|
parent?.common_strings_overrides?.price?.retail ||
|
|
@@ -95,16 +95,16 @@ const formatTranslations = (parent) => ({
|
|
|
95
95
|
pv: parent?.common_strings?.pricing?.pv,
|
|
96
96
|
cv: parent?.common_strings?.pricing?.cv
|
|
97
97
|
},
|
|
98
|
-
productDetails: parent
|
|
99
|
-
provenResults: parent
|
|
100
|
-
socialImpactAndSustainability: parent
|
|
101
|
-
recommendations: parent
|
|
102
|
-
recommendedProductsSectionHeading: parent
|
|
103
|
-
resources: parent
|
|
104
|
-
resourcesSubtitle: parent
|
|
105
|
-
selectPurchaseType: parent
|
|
106
|
-
selectVariant: parent
|
|
107
|
-
similarProducts: parent
|
|
98
|
+
productDetails: parent?.product_details,
|
|
99
|
+
provenResults: parent?.proven_results,
|
|
100
|
+
socialImpactAndSustainability: parent?.social_impact_and_sustainability,
|
|
101
|
+
recommendations: parent?.recommendations,
|
|
102
|
+
recommendedProductsSectionHeading: parent?.recommended_products_section_heading,
|
|
103
|
+
resources: parent?.resources,
|
|
104
|
+
resourcesSubtitle: parent?.resources_subtitle,
|
|
105
|
+
selectPurchaseType: parent?.select_purchase_type,
|
|
106
|
+
selectVariant: parent?.select_variant,
|
|
107
|
+
similarProducts: parent?.similar_products,
|
|
108
108
|
status: {
|
|
109
109
|
outOfStock:
|
|
110
110
|
parent?.common_strings_overrides?.status?.out_of_stock ||
|
|
@@ -129,53 +129,53 @@ const formatTranslations = (parent) => ({
|
|
|
129
129
|
?.notSoldSeparately ||
|
|
130
130
|
parent?.common_strings?.product?.notSoldSeparately
|
|
131
131
|
},
|
|
132
|
-
steps: parent
|
|
132
|
+
steps: parent?.steps,
|
|
133
133
|
subscribe:
|
|
134
|
-
parent?.common_strings_overrides
|
|
135
|
-
parent?.common_strings
|
|
134
|
+
parent?.common_strings_overrides?.cart?.subscribe ||
|
|
135
|
+
parent?.common_strings?.product?.subscribe,
|
|
136
136
|
subscribeButton:
|
|
137
|
-
parent?.common_strings_overrides
|
|
138
|
-
parent?.common_strings
|
|
137
|
+
parent?.common_strings_overrides?.cart?.subscribe_button ||
|
|
138
|
+
parent?.common_strings?.product?.subscribeMonthly,
|
|
139
139
|
total:
|
|
140
140
|
parent?.common_strings_overrides?.cart?.total ||
|
|
141
141
|
parent?.common_strings?.product?.total,
|
|
142
|
-
viewReport: parent
|
|
143
|
-
whatPowersIt: parent
|
|
144
|
-
whatsIncluded: parent
|
|
145
|
-
whyYoullLoveIt: parent
|
|
146
|
-
countryOfOrigin: parent
|
|
147
|
-
importer: parent
|
|
148
|
-
warnings: parent
|
|
149
|
-
disclaimers: parent
|
|
150
|
-
subscriptions: parent
|
|
151
|
-
generalDisclaimer: parent
|
|
142
|
+
viewReport: parent?.view_report,
|
|
143
|
+
whatPowersIt: parent?.what_powers_it,
|
|
144
|
+
whatsIncluded: parent?.whats_included,
|
|
145
|
+
whyYoullLoveIt: parent?.why_youll_love_it,
|
|
146
|
+
countryOfOrigin: parent?.country_of_origin,
|
|
147
|
+
importer: parent?.importer,
|
|
148
|
+
warnings: parent?.warnings,
|
|
149
|
+
disclaimers: parent?.disclaimers,
|
|
150
|
+
subscriptions: parent?.subscriptions,
|
|
151
|
+
generalDisclaimer: parent?.general_disclaimer_text,
|
|
152
152
|
generic: {
|
|
153
|
-
back: parent?.common_strings
|
|
154
|
-
done: parent?.common_strings
|
|
155
|
-
enter: parent?.common_strings
|
|
156
|
-
select: parent?.common_strings
|
|
157
|
-
quantity: parent?.common_strings
|
|
158
|
-
available: parent?.common_strings
|
|
159
|
-
save: parent?.common_strings
|
|
153
|
+
back: parent?.common_strings?.generic?.back,
|
|
154
|
+
done: parent?.common_strings?.generic?.done,
|
|
155
|
+
enter: parent?.common_strings?.generic?.enter,
|
|
156
|
+
select: parent?.common_strings?.generic?.select,
|
|
157
|
+
quantity: parent?.common_strings?.generic?.quantity,
|
|
158
|
+
available: parent?.common_strings?.generic?.available,
|
|
159
|
+
save: parent?.common_strings?.generic?.save
|
|
160
160
|
},
|
|
161
161
|
accounts: {
|
|
162
162
|
signIn: parent?.common_strings?.accounts?.sign_in
|
|
163
163
|
},
|
|
164
164
|
kitAndOrBundle: {
|
|
165
|
-
thisKitContainsAmountItems: parent
|
|
166
|
-
moreDetailsOnTheProductPageHere: parent
|
|
167
|
-
addMoreToYourBundle: parent
|
|
165
|
+
thisKitContainsAmountItems: parent?.kit_and_or_bundle?.this_kit_contains_amount_items,
|
|
166
|
+
moreDetailsOnTheProductPageHere: parent?.kit_and_or_bundle?.more_details_on_the_product_page_here,
|
|
167
|
+
addMoreToYourBundle: parent?.kit_and_or_bundle?.add_more_to_your_bundle
|
|
168
168
|
},
|
|
169
169
|
promoteApps: {
|
|
170
170
|
vera: {
|
|
171
|
-
title: parent
|
|
172
|
-
logo: parent
|
|
173
|
-
bodyText: parent
|
|
174
|
-
buttonText: parent
|
|
175
|
-
buttonUrl: parent
|
|
176
|
-
delay: parent
|
|
177
|
-
promoteVeraIsActive: parent
|
|
178
|
-
hidePromoteVeraStorageItem: parent
|
|
171
|
+
title: parent?.promote_apps?.vera?.title,
|
|
172
|
+
logo: parent?.promote_apps?.vera?.logo,
|
|
173
|
+
bodyText: parent?.promote_apps?.vera?.body_text,
|
|
174
|
+
buttonText: parent?.promote_apps?.vera?.button_text,
|
|
175
|
+
buttonUrl: parent?.promote_apps?.vera?.button_url,
|
|
176
|
+
delay: parent?.promote_apps?.vera?.delay,
|
|
177
|
+
promoteVeraIsActive: parent?.promote_apps?.vera?.promote_vera_is_active,
|
|
178
|
+
hidePromoteVeraStorageItem: parent?.promote_apps?.vera?.hide_promote_vera_storage_item
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
})
|
package/src/formatVariant.js
CHANGED
|
@@ -15,8 +15,8 @@ const formatVariant = (parent) => ({
|
|
|
15
15
|
title: parent?.name || parent?.defaults?.name,
|
|
16
16
|
salesLabel: parent?.sales_label,
|
|
17
17
|
salesText: parent?.sales_text,
|
|
18
|
-
description: entities
|
|
19
|
-
parent?.short_description_override || parent?.defaults
|
|
18
|
+
description: entities?.decodeHTML(
|
|
19
|
+
parent?.short_description_override || parent?.defaults?.description || ''
|
|
20
20
|
),
|
|
21
21
|
salesDisclaimer: helpers?.mapSalesDisclaimer(parent?.sales_disclaimer),
|
|
22
22
|
nettoWeight: parent?.netto_weight,
|