@nuskin/cs-product-lib 1.0.24-cx12-8656.1 → 1.0.24

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.24-cx12-8656.1",
3
+ "version": "1.0.24",
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
@@ -132,9 +132,6 @@ const csProduct = (props) => {
132
132
  validVariants.push({
133
133
  ...variant,
134
134
  status: varStatus,
135
- backorderQuantity: varStatus?.backordered ? varStatus?.availableQuantity : 0,
136
- availableQuantity: varStatus?.backordered ? 0 : varStatus?.availableQuantity,
137
- backorderedAvailableDate: varStatus?.backorderedAvailableDate || null,
138
135
  marketData
139
136
  })
140
137
  }
@@ -471,7 +468,7 @@ const csProduct = (props) => {
471
468
  const translations = await getEntriesByQuery({
472
469
  contentType: 'strings_product_detail_page',
473
470
  locale,
474
- includes: ['common_strings']
471
+ includes: ['common_strings', 'subscriptions.modal']
475
472
  })
476
473
  await parseSharedStrings(translations)
477
474
  return translations
package/src/formatKit.js CHANGED
@@ -16,40 +16,52 @@ const parseStatus = (variant) => {
16
16
  let backorderedAvailableDate = null
17
17
  if (variant?.type === 'kit') {
18
18
  try {
19
- let dates = [];
20
- variant?.requiredProducts?.flatMap(a => a?.product?.variants?.map(s => {
21
- const backorderDate = s?.status?.backorderedAvailableDate || null;
22
- dates.push(moment(backorderDate))
23
- }))
24
- dates = dates.filter(date => date.isValid());
25
- const latestBODate = dates && dates.length > 0 ? moment.max(dates).format(dateFormat) : null;
19
+ /* eslint-disable no-unsafe-optional-chaining */
20
+ const latestBODate = Math.max(
21
+ ...variant?.requiredProducts?.flatMap((a) =>
22
+ a?.product?.variants?.map(
23
+ (s) =>
24
+ Number(
25
+ new Date(s?.status?.backorderedAvailableDate)
26
+ ) || 0
27
+ )
28
+ )
29
+ )
26
30
  if (latestBODate) {
27
31
  isBackordered = true
28
- backorderedAvailableDate = latestBODate
32
+ backorderedAvailableDate = moment(
33
+ new Date(latestBODate)
34
+ ).format(dateFormat)
29
35
  }
30
36
  } catch {
31
37
  backorderedAvailableDate = null
32
38
  }
33
39
  } else if (variant?.type === 'bundle') {
34
40
  try {
35
- let dates = [];
36
- variant?.requiredProducts?.flatMap(a => a?.product?.variants?.map(s => {
37
- const backorderDate = s?.status?.backorderedAvailableDate || null;
38
- dates.push(moment(backorderDate))
39
- }))
40
- dates = dates.filter(date => date.isValid());
41
- const latestBODate = dates && dates.length > 0 ? moment.max(dates).format(dateFormat) : null;
41
+ const latestBODate = Math.max(
42
+ ...variant?.requiredProducts?.flatMap(
43
+ (a) =>
44
+ Number(
45
+ new Date(
46
+ a?.product?.variants[0]?.status?.backorderedAvailableDate
47
+ )
48
+ ) || 0
49
+ )
50
+ )
42
51
  if (latestBODate) {
43
52
  isBackordered = true
44
- backorderedAvailableDate = latestBODate
53
+ backorderedAvailableDate = moment(
54
+ new Date(latestBODate)
55
+ ).format(dateFormat)
45
56
  }
46
57
  } catch {
47
58
  backorderedAvailableDate = null
48
59
  }
49
60
  }
50
61
  return {
51
- status: variant?.status?.status,
52
- isBackordered: isBackordered,
62
+ // changed
63
+ status: variant?.status?.status,
64
+ isBackordered: isBackordered,
53
65
  backorderedAvailableDate: backorderedAvailableDate
54
66
  }
55
67
  }
@@ -142,85 +154,36 @@ const parsePrice = (product = []) => {
142
154
  return sumOfPriceAndPoints
143
155
  }
144
156
 
145
- const parseKitAvailableQuantity = (skuKit) => {
146
- let quantities = [];
147
- let prodQty = 0;
157
+ const parseKitAvailableQuantity = (kit) => {
148
158
  try {
149
- skuKit.flatMap(a => {
150
- prodQty = Number(a.properties.quantity)
151
- a.sku.map(s => {
152
- const backorderQty = s?.inventoryProperties?.backOrderedQty/prodQty || 0;
153
- const availableQty = s?.inventoryProperties?.atpQty/prodQty || 0;
154
- quantities.push({backorderQty, availableQty, canSellUpTo: Math.max(backorderQty, availableQty)})
155
- })
156
- })
157
- const maxAvailableQty = quantities && quantities.length > 0 ? Math.min(...quantities.map(obj=>obj.canSellUpTo)) : 0;
158
- return Math.floor(maxAvailableQty);
159
- } catch (error) {
160
- return 0;
159
+ return (
160
+ Math.min(
161
+ ...kit.flatMap((a) =>
162
+ a?.sku?.map((s) => s?.inventoryProperties?.atpQty)
163
+ )
164
+ ) || 0
165
+ )
166
+ } catch {
167
+ return 0
161
168
  }
162
169
  }
163
170
 
164
171
  const parseBundleAvailableQuantity = (product) => {
165
- let quantities = [];
166
- let prodQty = 0;
167
- try {
168
- product?.requiredProducts?.flatMap(a => {
169
- prodQty = Number(a.quantity)
170
- a?.product?.variants?.map(s => {
171
- const backorderQty = s?.backorderQuantity/prodQty || 0;
172
- const availableQty = s?.availableQuantity/prodQty || 0;
173
- quantities.push({backorderQty, availableQty, canSellUpTo: Math.max(backorderQty, availableQty)})
174
- })
175
- })
176
- const maxAvailableQty = quantities && quantities.length > 0 ? Math.min(...quantities.map(obj=>obj.canSellUpTo)) : 0;
177
- return Math.floor(maxAvailableQty);
178
- } catch (error) {
179
- return 0;
180
- }
181
- }
182
-
183
-
184
- const parseKitBackorderedQuantity = (skuKit) => {
185
- let quantities = [];
186
- let prodQty = 0;
187
172
  try {
188
- skuKit?.flatMap(a => {
189
- prodQty = Number(a?.properties?.quantity)
190
- a.sku.map(s => {
191
- const backorderQty = s?.inventoryProperties?.backOrderedQty/prodQty || 0;
192
- quantities.push(backorderQty)
193
- })
194
- })
195
- const maxBackorderedQty = quantities && quantities.length > 0 ? Math.min(...quantities) : 0;
196
- return Math.floor(maxBackorderedQty);
197
- } catch (error) {
198
- return 0;
199
- }
200
- }
201
-
202
- const parseBundleBackorderedQuantity = (product) => {
203
- let quantities = [];
204
- let prodQty = 0;
205
- try {
206
- product?.requiredProducts?.flatMap(a => {
207
- prodQty = Number(a?.quantity)
208
- a?.product?.variants?.map(s => {
209
- const backorderQty = s?.backorderQuantity/prodQty || 0;
210
- quantities.push(backorderQty)
211
- })
212
- })
213
- const maxBackorderedQty = quantities && quantities.length > 0 ? Math.min(...quantities) : 0;
214
- return Math.floor(maxBackorderedQty);
215
- } catch (error) {
216
- return 0;
173
+ const { requiredProducts = [] } = !isNullOrEmpty(product) ? product : {}
174
+ const quantities = requiredProducts?.map((p) =>
175
+ p?.product?.variants?.map((a) => a?.availableQuantity)
176
+ )
177
+ return Math.min(...quantities) || 0
178
+ } catch {
179
+ console.log('some error in availableQuantity')
180
+ return 0
217
181
  }
218
182
  }
219
183
 
220
184
  const parseKit = (product, market) => {
221
185
  const kits = {}
222
186
  const [properties] = !isNullOrEmpty(product) ? product : []
223
- const status = parseStatus(properties)
224
187
  kits.id = properties?.id
225
188
  kits.uid = properties?.uid
226
189
  kits.title = properties?.title
@@ -250,14 +213,13 @@ const parseKit = (product, market) => {
250
213
  kits.scanQualifiedCount = properties?.scanQualifiedCount
251
214
  kits.taxClass = properties?.taxClass
252
215
  // newVariant.slug = undefined
253
- kits.status = status
254
- if ((kits?.status || {})?.status === 'active') kits.status.status = 'sellable'
216
+ kits.status = parseStatus(properties)
217
+ if ((kits?.status || {})?.status === 'active')
218
+ kits.status.status = 'sellable'
255
219
  const kitProducts = []
256
220
  if (properties?.type === 'kit' && product?.kit) {
257
221
  kits.type = 'kit'
258
- kits.availableQuantity = parseKitAvailableQuantity(product.kit)
259
- kits.backorderQuantity = parseKitBackorderedQuantity(product.kit)
260
- kits.backorderedAvailableDate = status?.backorderedAvailableDate
222
+ kits.availableQuantity = parseKitAvailableQuantity(product?.kit)
261
223
  for (const kit of product?.kit || []) {
262
224
  const kitProduct = formatKit(kit, market)
263
225
  kitProduct.id = kit?.identifier
@@ -273,8 +235,6 @@ const parseKit = (product, market) => {
273
235
  ) {
274
236
  kits.type = properties?.type
275
237
  kits.availableQuantity = parseBundleAvailableQuantity(properties)
276
- kits.backorderQuantity = parseBundleBackorderedQuantity(properties)
277
- kits.backorderedAvailableDate = status?.backorderedAvailableDate
278
238
  for (const kit of properties?.requiredProducts || []) {
279
239
  if (kit?.product) {
280
240
  const kitProduct = formatKit(kit?.product, market)
@@ -25,16 +25,18 @@ const formatVariant = (parent) => ({
25
25
  pricingJson: JSON.stringify(parent?.defaults?.status?.pricing) || null,
26
26
  price: helpers?.mapPrice(parent),
27
27
  points: helpers?.mapPoints(parent),
28
- backorderedAvailableDate: _.get(parent, 'defaults.status.backorderedAvailableDate', null),
29
- backorderQuantity: _.get(parent, 'defaults.status.backordered', null) ? _.get(parent, 'defaults.status.availableQuantity', 0) : 0,
30
- availableQuantity: _.get(parent, 'defaults.status.backordered', null) ? 0 : _.get(parent, 'defaults.status.availableQuantity', 0),
28
+ availableQuantity: _.get(parent, 'defaults.status.availableQuantity', 0),
31
29
  maxQuantity: _.get(parent, 'defaults.status.maxQuantity', 0),
32
30
  status: {
33
31
  status: _.get(parent, 'defaults.status.status.retail', null),
34
32
  retail: _.get(parent, 'defaults.status.status.retail', null),
35
33
  wholesale: _.get(parent, 'defaults.status.status.wholesale', null),
36
34
  isBackordered: _.get(parent, 'defaults.status.backordered', null),
37
- backorderedAvailableDate: _.get(parent, 'defaults.status.backorderedAvailableDate', null)
35
+ backorderedAvailableDate: _.get(
36
+ parent,
37
+ 'defaults.status.backorderedAvailableDate',
38
+ ''
39
+ )
38
40
  },
39
41
  csStatus: helpers?.mapCsStatus(parent),
40
42
  purchaseTypes: helpers?.mapPurchaseTypes(parent),
@@ -45,7 +45,6 @@ async function getProductStatus(skus, locale, homeUrl, awsBase, clientId) {
45
45
  const overrideMaxQuantity = marketConfig.skuMaxQty
46
46
  ? marketConfig.skuMaxQty[skus[i]]
47
47
  : undefined
48
- // @TODO - Update this code when we update our config for minimum availableQuantity in CS
49
48
  const availableQuantity =
50
49
  productStatus.availableQuantity < 999
51
50
  ? productStatus.availableQuantity