@nuskin/ns-product-lib 2.18.0-brw-4218.1 → 2.18.0
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +2 -2
- package/src/graph-ql/product.js +47 -26
- package/src/product.js +1 -1
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nuskin/ns-product-lib",
|
3
|
-
"version": "2.18.0
|
3
|
+
"version": "2.18.0",
|
4
4
|
"description": "This project contains shared Product models and code between the backend and frontend.",
|
5
5
|
"main": "src/index.js",
|
6
6
|
"scripts": {
|
@@ -22,7 +22,7 @@
|
|
22
22
|
"@nuskin/configuration-sdk": "2.3.2",
|
23
23
|
"@nuskin/ns-common-lib": "1.4.7",
|
24
24
|
"@nuskin/ns-util": "4.5.4",
|
25
|
-
"@nuskin/product-lib": "2.2.0
|
25
|
+
"@nuskin/product-lib": "2.2.0",
|
26
26
|
"axios": "1.6.7",
|
27
27
|
"axios-mock-adapter": "1.21.2",
|
28
28
|
"eslint": "^8.56.0",
|
package/src/graph-ql/product.js
CHANGED
@@ -28,7 +28,6 @@ async function getProduct(id, market, locale, config) {
|
|
28
28
|
env: config.graphqlUrl.includes('test') ? 'test' : config.graphqlUrl.includes('dev') ? 'dev' : 'prod',
|
29
29
|
okta
|
30
30
|
});
|
31
|
-
|
32
31
|
if (data && data.data) {
|
33
32
|
//use to get default variant based on requested sku
|
34
33
|
config.sku = id;
|
@@ -65,6 +64,10 @@ async function getProducts(ids, market, locale, config) {
|
|
65
64
|
count: 0
|
66
65
|
};
|
67
66
|
|
67
|
+
if (!Array.isArray(ids)) {
|
68
|
+
ids = [ids]
|
69
|
+
}
|
70
|
+
|
68
71
|
const okta = typeof sessionStorage !== 'undefined' ? parseOktaObject(sessionStorage.oktaTokens) : null;
|
69
72
|
|
70
73
|
try {
|
@@ -110,7 +113,7 @@ function mapSkusToProducts(skus, products){
|
|
110
113
|
const matchedProducts = products.filter((product)=>{
|
111
114
|
let matched = false;
|
112
115
|
if(product.id) {matched = product.id === sku;}
|
113
|
-
if(product.variants.length){
|
116
|
+
if(product.variants && product.variants.length){
|
114
117
|
product.variants.forEach((variant)=>{
|
115
118
|
matched |= variant.sku === sku;
|
116
119
|
});
|
@@ -350,26 +353,44 @@ function mapVariants(product) {
|
|
350
353
|
* @returns {array} kitBundleProducts
|
351
354
|
*/
|
352
355
|
function mapChildSKU(kitBundleProducts) {
|
353
|
-
if (!kitBundleProducts || !kitBundleProducts.kitProducts) {
|
356
|
+
if (!kitBundleProducts || !kitBundleProducts.kitProducts) /* istanbul ignore next */ {
|
354
357
|
return [];
|
355
358
|
}
|
356
|
-
|
359
|
+
const personalOffer = typeof sessionStorage !== 'undefined' && sessionStorage.getItem('personalOffer') ? JSON.parse(sessionStorage.getItem('personalOffer')) : false
|
357
360
|
return kitBundleProducts.kitProducts.map((kitProduct) => {
|
358
361
|
const { product } = kitProduct;
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
362
|
+
if (product.variants.length > 1 && typeof personalOffer === 'object') /* istanbul ignore next */ {
|
363
|
+
return product.variants.map((variant) => {
|
364
|
+
return {
|
365
|
+
productId: product.id,
|
366
|
+
skuId: variant.sku,
|
367
|
+
type: kitProduct.isMandatory ? 'MANDATORY' : 'OPTIONAL',
|
368
|
+
skuQuantity: kitProduct.quantity,
|
369
|
+
// eslint-disable-next-line max-len
|
370
|
+
availableChannels: Array.isArray(kitBundleProducts.availableChannels) ? kitBundleProducts.availableChannels.join(',') : kitBundleProducts.availableChannels,
|
371
|
+
inventory: {
|
372
|
+
atpQty: variant.atpQuantity,
|
373
|
+
backOrdered: variant.status.inventory === 'backordered',
|
374
|
+
backOrderedQty: variant.backorderQuantity
|
375
|
+
}
|
376
|
+
}
|
377
|
+
})
|
378
|
+
} else {
|
379
|
+
const defaultVariant = product.variants[0];
|
380
|
+
return {
|
381
|
+
productId: product.id,
|
382
|
+
skuId: defaultVariant.sku,
|
383
|
+
type: kitProduct.isMandatory ? 'MANDATORY' : 'OPTIONAL',
|
384
|
+
skuQuantity: kitProduct.quantity,
|
385
|
+
availableChannels: Array.isArray(kitBundleProducts.availableChannels) ? kitBundleProducts.availableChannels.join(',') : kitBundleProducts.availableChannels,
|
386
|
+
inventory: {
|
387
|
+
atpQty: defaultVariant.atpQuantity,
|
388
|
+
backOrdered: defaultVariant.status.inventory === 'backordered',
|
389
|
+
backOrderedQty: defaultVariant.backorderQuantity
|
390
|
+
}
|
370
391
|
}
|
371
392
|
}
|
372
|
-
});
|
393
|
+
}).flat();
|
373
394
|
}
|
374
395
|
|
375
396
|
|
@@ -479,9 +500,16 @@ function mapOrderTypes(availableChannels, purchaseTypes) {
|
|
479
500
|
orderTypes.web = true
|
480
501
|
orderTypes.order = true
|
481
502
|
}
|
503
|
+
if (purchaseTypes && !purchaseTypes.buyOnce) {
|
504
|
+
orderTypes.web = false
|
505
|
+
orderTypes.order = false
|
506
|
+
}
|
482
507
|
if (purchaseTypes && purchaseTypes.subscription) {
|
483
508
|
orderTypes.adr = true
|
484
509
|
}
|
510
|
+
if (purchaseTypes && !purchaseTypes.subscription) {
|
511
|
+
orderTypes.adr = false
|
512
|
+
}
|
485
513
|
|
486
514
|
return orderTypes;
|
487
515
|
}
|
@@ -491,6 +519,7 @@ function mapOrderTypes(availableChannels, purchaseTypes) {
|
|
491
519
|
* @param {string} status
|
492
520
|
* @returns {string} status
|
493
521
|
*/
|
522
|
+
/* istanbul ignore next */
|
494
523
|
function mapProductStatus(status) {
|
495
524
|
const { equinoxStatus } = ProductStatus;
|
496
525
|
let newStatus = '';
|
@@ -514,10 +543,10 @@ function mapProductStatus(status) {
|
|
514
543
|
newStatus = ProductStatus.NotReleasedForSale;
|
515
544
|
break;
|
516
545
|
}
|
517
|
-
|
518
546
|
return newStatus;
|
519
547
|
}
|
520
548
|
|
549
|
+
/* istanbul ignore next */
|
521
550
|
function mapPromos(product) {
|
522
551
|
if ((product.price.retailSales !== null && product.price.retailSales >= 0) || (product.price.wholesaleSales !== null && product.price.wholesaleSales >= 0)) {
|
523
552
|
if (product.pricingJson) {
|
@@ -560,17 +589,9 @@ function mapPromos(product) {
|
|
560
589
|
return { message: product.salesLabel, offerId: null, priceMap: {}, cvMap: {}, pvMap: {} }
|
561
590
|
}
|
562
591
|
return {message: null, offerId: null}
|
563
|
-
// if (isKitBundle) {
|
564
|
-
// const { pricingJson } = product
|
565
|
-
// const parsedPricing = JSON.parse(pricingJson)
|
566
|
-
// const promotion = parsedPricing.promotion
|
567
|
-
// return (promotion && promotion.length >= 1) ? { message: promotion[0].message, offerId: promotion[0].offerId } : { message: '', offerId: '' }
|
568
|
-
// } else {
|
569
|
-
// return { message: product.salesLabel || product.salesText, offerId: product.salesLabel || product.salesText }
|
570
|
-
// }
|
571
|
-
|
572
592
|
}
|
573
593
|
|
594
|
+
/* istanbul ignore next */
|
574
595
|
function parseOktaObject(okta) {
|
575
596
|
if (!okta || typeof okta !== 'string') {
|
576
597
|
return null;
|
package/src/product.js
CHANGED
@@ -393,7 +393,7 @@ const Product = function (productData) {
|
|
393
393
|
Object.keys(this.priceMap).forEach(priceTypeKey => {
|
394
394
|
const eventPriceType = priceTypeKey.substring(0, priceTypeKey.indexOf(`-${this.priceType}`));
|
395
395
|
|
396
|
-
if (eventPriceType) {
|
396
|
+
if (eventPriceType && this.priceMap[eventPriceType]) {
|
397
397
|
eventPriceTypes.push(eventPriceType);
|
398
398
|
}
|
399
399
|
});
|