@nuskin/ns-product-lib 2.6.0-cx24-3464.1 → 2.6.0-cx24-3464.3
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +31 -5
- package/package.json +1 -1
- package/src/productData.js +106 -61
package/CHANGELOG.md
CHANGED
@@ -1,16 +1,42 @@
|
|
1
|
-
# [2.6.0-cx24-3464.
|
1
|
+
# [2.6.0-cx24-3464.3](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.6.0-cx24-3464.2...v2.6.0-cx24-3464.3) (2023-03-10)
|
2
2
|
|
3
3
|
|
4
4
|
### Update
|
5
5
|
|
6
|
-
* get child skus to be used for add-to-cart #CX24-3464 ([
|
6
|
+
* get child skus to be used for add-to-cart #CX24-3464 ([b3c334f](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/b3c334f01b851737aff78d8345e4eea8aa702bb3)), closes [#CX24-3464](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-3464)
|
7
7
|
|
8
|
-
|
8
|
+
# [2.6.0-cx24-3464.2](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.6.0-cx24-3464.1...v2.6.0-cx24-3464.2) (2023-03-10)
|
9
9
|
|
10
10
|
|
11
|
-
###
|
11
|
+
### New
|
12
|
+
|
13
|
+
* Update equinox query for KIT and its mapping ([7df6f96](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/7df6f9671c58eddb57c9acfd9d4b79b8dec6a78e))
|
14
|
+
|
15
|
+
### Release
|
16
|
+
|
17
|
+
* Automated changes by GitLab pipeline [skip ci] ([f8233b3](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/f8233b37ecf0c805404395c68e0237930e274904))
|
18
|
+
* Automated changes by GitLab pipeline [skip ci] ([8aa3e84](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/8aa3e84df61f6855ad1544f592f4a2825a92e6fb))
|
19
|
+
|
20
|
+
### Update
|
21
|
+
|
22
|
+
* get child skus to be used for add-to-cart #CX24-3464 ([9bf1a82](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/9bf1a828a3073dd4118abba088a22b854db78172)), closes [#CX24-3464](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-3464)
|
23
|
+
* get child skus to be used for add-to-cart #CX24-3464 ([b1b7dc9](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/b1b7dc9f9ed85aca18fd2ec98d5938131e79aaed)), closes [#CX24-3464](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-3464)
|
24
|
+
* get child skus to be used for add-to-cart #CX24-3464 ([9cc5a85](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/9cc5a85768a9080fd232acb8096eb7cd50e37028)), closes [#CX24-3464](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-3464)
|
25
|
+
* removed with credentials default ([48f7bdb](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/48f7bdbe9154a82ed48195d0f93f9e4772bf92dc))
|
26
|
+
|
27
|
+
# [2.6.0-cx24-33721.2](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.6.0-cx24-33721.1...v2.6.0-cx24-33721.2) (2023-03-09)
|
28
|
+
|
29
|
+
|
30
|
+
### Update
|
31
|
+
|
32
|
+
* removed with credentials default ([48f7bdb](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/48f7bdbe9154a82ed48195d0f93f9e4772bf92dc))
|
33
|
+
|
34
|
+
# [2.6.0-cx24-33721.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.5.1...v2.6.0-cx24-33721.1) (2023-03-08)
|
35
|
+
|
36
|
+
|
37
|
+
### New
|
12
38
|
|
13
|
-
*
|
39
|
+
* Update equinox query for KIT and its mapping ([7df6f96](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/7df6f9671c58eddb57c9acfd9d4b79b8dec6a78e))
|
14
40
|
|
15
41
|
## [2.5.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.5.0...v2.5.1) (2023-03-07)
|
16
42
|
|
package/package.json
CHANGED
package/src/productData.js
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
"use strict";
|
2
|
-
const { getConfiguration } = require('@nuskin/configuration-sdk');
|
2
|
+
const { getConfiguration, getCachedConfigurations } = require('@nuskin/configuration-sdk');
|
3
3
|
const axios = require("axios");
|
4
4
|
const contentstack = require('./contentstack/contentstack');
|
5
5
|
const Product = require("./product");
|
6
6
|
const CustomerTypes = require('./models/customerTypes');
|
7
7
|
const ProductStatus = require("./models/productStatus");
|
8
|
+
|
9
|
+
const productTypes = {
|
10
|
+
kit: 'kit'
|
11
|
+
};
|
12
|
+
|
8
13
|
/** @type {*} */
|
9
14
|
const ProductData = {
|
10
15
|
/**
|
@@ -27,10 +32,23 @@ const ProductData = {
|
|
27
32
|
},
|
28
33
|
|
29
34
|
getProductFromEquinox: async function (skus, locale, config) {
|
30
|
-
|
35
|
+
|
36
|
+
let skuFilter = [];
|
37
|
+
|
38
|
+
if(Array.isArray(skus)) {
|
39
|
+
skus.forEach((sku) => {
|
40
|
+
skuFilter.push(`index_key_productId="${sku}" OR index_key_skuId="${sku}"`)
|
41
|
+
})
|
42
|
+
} else {
|
43
|
+
//all featured products
|
44
|
+
skuFilter.push(`index_key_productId="${skus}" OR index_key_skuId="${skus}"`)
|
45
|
+
}
|
46
|
+
|
47
|
+
const filter = skuFilter.join(" OR ")
|
48
|
+
//axios.defaults.withCredentials = true;
|
31
49
|
|
32
50
|
const url = `${config.API_Base_URLs}/orchestrationservices/storefront/catalogs/search/`;
|
33
|
-
const href = `${url}?filter
|
51
|
+
const href = `${url}?filter='\\\\''${encodeURI(filter)}'\\''`;
|
34
52
|
const response = await axios.request({
|
35
53
|
method: 'get',
|
36
54
|
url: href,
|
@@ -44,7 +62,7 @@ const ProductData = {
|
|
44
62
|
});
|
45
63
|
|
46
64
|
if (response.data.product) {
|
47
|
-
return this.eqProductMapper(response.data.product, skus);
|
65
|
+
return await this.eqProductMapper(response.data.product, skus);
|
48
66
|
}
|
49
67
|
|
50
68
|
return {
|
@@ -99,7 +117,7 @@ const ProductData = {
|
|
99
117
|
eqProductVariantMapper: function (eqVariant) {
|
100
118
|
|
101
119
|
let imageURL = eqVariant.properties.imageURL;
|
102
|
-
const regex = /\d
|
120
|
+
const regex = /\d+\.\d+/
|
103
121
|
let thumbnailImage = ''
|
104
122
|
|
105
123
|
if (imageURL.includes('contentstack')) {
|
@@ -312,15 +330,17 @@ const ProductData = {
|
|
312
330
|
}
|
313
331
|
},
|
314
332
|
|
315
|
-
eqProductMapper: function (productDataResponse, skus) {
|
316
|
-
console.log(productDataResponse, skus);
|
317
|
-
let prod = [];
|
333
|
+
eqProductMapper: async function (productDataResponse, skus) {
|
334
|
+
// console.log(productDataResponse, skus);
|
318
335
|
let count = 0;
|
319
336
|
let variants = {};
|
337
|
+
const products = [];
|
320
338
|
|
321
|
-
|
322
|
-
let
|
323
|
-
const
|
339
|
+
for (const productData of productDataResponse) {
|
340
|
+
let product = (productData.type && productData.type === "kit") ? productData : productData.sku[count];
|
341
|
+
const childSkus = await this.fetchChildSkus(product);
|
342
|
+
let imageURL = product.properties.imageURL;
|
343
|
+
const regex = /\d+\.\d+/
|
324
344
|
let thumbnailImage = ''
|
325
345
|
|
326
346
|
if (imageURL.includes('contentstack')) {
|
@@ -329,9 +349,9 @@ const ProductData = {
|
|
329
349
|
thumbnailImage = imageURL.replace(regex, '40.40')
|
330
350
|
}
|
331
351
|
|
332
|
-
if (
|
333
|
-
//exclude base product from variants
|
334
|
-
|
352
|
+
if (productData.sku && productData.sku.length > 1) {
|
353
|
+
// exclude base product from variants
|
354
|
+
productData.sku.filter(v => v.identifier.substring(2, 4) !== "55").map(variant => {
|
335
355
|
variants[variant.identifier] = this.eqProductVariantMapper(variant);
|
336
356
|
return variant;
|
337
357
|
});
|
@@ -342,20 +362,20 @@ const ProductData = {
|
|
342
362
|
eventLabels,
|
343
363
|
computedPrice,
|
344
364
|
defaultProductPrice
|
345
|
-
} = this.getEqProductPromotions(
|
346
|
-
const productPrice = eventName ? defaultProductPrice :
|
347
|
-
const discountedPrice = eventName ? computedPrice :
|
348
|
-
|
349
|
-
|
350
|
-
"sku":
|
351
|
-
"globalProductID":
|
352
|
-
"title":
|
353
|
-
"country":
|
365
|
+
} = this.getEqProductPromotions(product);
|
366
|
+
const productPrice = eventName ? defaultProductPrice : product.priceFacets["Regular Price"];
|
367
|
+
const discountedPrice = eventName ? computedPrice : product.priceFacets["Regular Price"];
|
368
|
+
|
369
|
+
product = {
|
370
|
+
"sku": product.identifier,
|
371
|
+
"globalProductID": productData.identifier,
|
372
|
+
"title": productData.properties.name,
|
373
|
+
"country": product.properties.market,
|
354
374
|
"language": "en",
|
355
|
-
"shortDescr":
|
356
|
-
"longDescr":
|
375
|
+
"shortDescr": productData.properties.description,
|
376
|
+
"longDescr": productData.properties.productDetailsDescription,
|
357
377
|
"fullImage": imageURL,
|
358
|
-
"imageAltText":
|
378
|
+
"imageAltText": productData.properties.name,
|
359
379
|
"productCarouselImages": [
|
360
380
|
{
|
361
381
|
"contentType": "img",
|
@@ -364,10 +384,10 @@ const ProductData = {
|
|
364
384
|
}
|
365
385
|
],
|
366
386
|
"thumbnail": thumbnailImage,
|
367
|
-
"ingredients":
|
368
|
-
"benefits":
|
369
|
-
"usage":
|
370
|
-
"resources":
|
387
|
+
"ingredients": productData.properties.ingredients,
|
388
|
+
"benefits": productData.properties.benefits,
|
389
|
+
"usage": productData.properties.usage,
|
390
|
+
"resources": product.properties.resources,
|
371
391
|
"videos": "",
|
372
392
|
"movie": "",
|
373
393
|
"youtube": "",
|
@@ -377,49 +397,49 @@ const ProductData = {
|
|
377
397
|
"sectionContent": "<div class=\"contentSections\"></div>\n"
|
378
398
|
}
|
379
399
|
],
|
380
|
-
"scanQualified":
|
381
|
-
"availableQuantity":
|
400
|
+
"scanQualified": productData.properties.scanQualifiedCount,
|
401
|
+
"availableQuantity": (product.inventoryProperties) ? product.inventoryProperties.atpQty : 0,
|
382
402
|
"maxQuantity": 999,
|
383
403
|
"points": "",
|
384
|
-
"cv": (
|
385
|
-
"pv":
|
404
|
+
"cv": (product.priceFacets.CV) ? product.priceFacets.CV : '',
|
405
|
+
"pv": product.priceFacets.PV,
|
386
406
|
"priceType": "WRTL",
|
387
407
|
"price": discountedPrice,
|
388
408
|
"priceMap": {
|
389
409
|
"WRTL": productPrice,
|
390
|
-
"WADW-WRTL":
|
391
|
-
"WADR":
|
392
|
-
"RTL":
|
393
|
-
"WADW":
|
394
|
-
"WHL":
|
395
|
-
"WWHL":
|
410
|
+
"WADW-WRTL": product.priceFacets["Regular Price"],
|
411
|
+
"WADR": product.priceFacets["Regular Price"],
|
412
|
+
"RTL": product.priceFacets["Regular Price"],
|
413
|
+
"WADW": product.priceFacets["Wholesale Price"],
|
414
|
+
"WHL": product.priceFacets["Wholesale Price"],
|
415
|
+
"WWHL": product.priceFacets["Wholesale Price"]
|
396
416
|
},
|
397
417
|
"cvMap": {
|
398
|
-
"WWHL": (
|
399
|
-
"WADW": (
|
400
|
-
"WHL": (
|
418
|
+
"WWHL": (product.priceFacets.CV) ? product.priceFacets.CV : '',
|
419
|
+
"WADW": (product.priceFacets.CV) ? product.priceFacets.CV : '',
|
420
|
+
"WHL": (product.priceFacets.CV) ? product.priceFacets.CV : ''
|
401
421
|
},
|
402
422
|
"pvMap": {
|
403
|
-
"WWHL":
|
404
|
-
"WADW":
|
405
|
-
"WHL":
|
423
|
+
"WWHL": product.priceFacets.PV,
|
424
|
+
"WADW": product.priceFacets.PV,
|
425
|
+
"WHL": product.priceFacets.PV
|
406
426
|
},
|
407
|
-
"orderTypes": this._setOrderType(
|
408
|
-
|
409
|
-
"custTypes": this.switchCustType(
|
410
|
-
"division":
|
427
|
+
"orderTypes": this._setOrderType(product.properties),
|
428
|
+
childSkus,
|
429
|
+
"custTypes": this.switchCustType(product.properties.customerTypes),
|
430
|
+
"division": productData.properties.division,
|
411
431
|
"backOrderDate": null,
|
412
432
|
"locallyProduced": false,
|
413
433
|
"agelocme": null,
|
414
434
|
"count": "",
|
415
435
|
"flavor": "",
|
416
|
-
"size":
|
436
|
+
"size": product.properties.size,
|
417
437
|
"shade": "",
|
418
|
-
"status": this.switchStatusFromEquinox(
|
438
|
+
"status": this.switchStatusFromEquinox(product.properties.productStatus),
|
419
439
|
"variantType": "Other",
|
420
|
-
"variantDropdownLabel":
|
440
|
+
"variantDropdownLabel": product.properties.variantLabel || "",
|
421
441
|
"variantDropdownPlaceholder": "Select Type",
|
422
|
-
"variantsLabel":
|
442
|
+
"variantsLabel": product.properties.variantLabel || "",
|
423
443
|
"groupOffer": false,
|
424
444
|
"personalOffer": false,
|
425
445
|
"savedEventName": eventName,
|
@@ -429,7 +449,7 @@ const ProductData = {
|
|
429
449
|
"nettoWeight": "",
|
430
450
|
"variants": variants,
|
431
451
|
"searchScore": 0,
|
432
|
-
"isExclusive":
|
452
|
+
"isExclusive": product.properties.isExclusive || false,
|
433
453
|
"marketAttributes": {
|
434
454
|
"discount": true,
|
435
455
|
"redeem": true,
|
@@ -437,15 +457,15 @@ const ProductData = {
|
|
437
457
|
},
|
438
458
|
"restrictedMarkets": [],
|
439
459
|
"addOns": [],
|
440
|
-
"inventory":
|
441
|
-
"equinoxProductId":
|
460
|
+
"inventory": product.inventory || "", //inventory label
|
461
|
+
"equinoxProductId": productData.identifier
|
442
462
|
};
|
443
|
-
|
444
|
-
|
445
|
-
}
|
463
|
+
|
464
|
+
products.push(new Product(product));
|
465
|
+
}
|
446
466
|
|
447
467
|
let data = {
|
448
|
-
products: this._sortProductsBySku(skus,
|
468
|
+
products: this._sortProductsBySku(skus, products),
|
449
469
|
count: productDataResponse.length
|
450
470
|
};
|
451
471
|
return {
|
@@ -457,6 +477,31 @@ const ProductData = {
|
|
457
477
|
};
|
458
478
|
},
|
459
479
|
|
480
|
+
/**
|
481
|
+
*
|
482
|
+
* @param {*} product
|
483
|
+
*/
|
484
|
+
fetchChildSkus: async function(product) {
|
485
|
+
if (product.type === productTypes.kit) {
|
486
|
+
const config = getCachedConfigurations(['Equinox_Markets']);
|
487
|
+
const { skukits } = product.properties;
|
488
|
+
|
489
|
+
if (!skukits) {
|
490
|
+
return [];
|
491
|
+
}
|
492
|
+
|
493
|
+
const kits = skukits.split(',').map(kit => {
|
494
|
+
const [sku, qty] = kit.split('~');
|
495
|
+
return { sku, qty };
|
496
|
+
});
|
497
|
+
const skus = kits.map(k => k.sku);
|
498
|
+
const products = await this.getProductFromEquinox(skus, 'en_US', config);
|
499
|
+
console.log(products);
|
500
|
+
}
|
501
|
+
|
502
|
+
return [];
|
503
|
+
},
|
504
|
+
|
460
505
|
/**
|
461
506
|
*
|
462
507
|
* Map status from equinox to legacy
|