@nuskin/ns-product-lib 2.3.0-cx24-2186.2.3 → 2.3.1-cx12-5910.1

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,23 +1,16 @@
1
- # [2.3.0-cx24-2186.2.3](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.3.0-cx24-2186.2.2...v2.3.0-cx24-2186.2.3) (2022-10-20)
1
+ ## [2.3.1-cx12-5910.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.3.0...v2.3.1-cx12-5910.1) (2022-10-25)
2
2
 
3
3
 
4
- ### Update
4
+ ### Fix
5
5
 
6
- * added variant label (#CX24-2186) ([d4d9511](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/d4d9511502d3df8db610e8212f6f7efb95b8c16e)), closes [#CX24-2186](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2186)
6
+ * window object doesn't exist in lambda ([e092ad6](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/e092ad6ac2fda7d550c5df6c360eb52e044834a2))
7
7
 
8
- # [2.3.0-cx24-2186.2.2](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.3.0-cx24-2186.2.1...v2.3.0-cx24-2186.2.2) (2022-10-19)
8
+ # [2.3.0](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.2.0...v2.3.0) (2022-10-14)
9
9
 
10
10
 
11
11
  ### Update
12
12
 
13
- * added support for variant and price (#CX24-2186) ([bf5d224](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/bf5d224f6802c4542a3985531b72f7ee340d53bd)), closes [#CX24-2186](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2186)
14
-
15
- # [2.3.0-cx24-2186.2.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.2.0...v2.3.0-cx24-2186.2.1) (2022-10-18)
16
-
17
-
18
- ### New
19
-
20
- * added support for inventory label (#CX24-2186) ([469e309](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/469e3090e98cf2ff7fb199fbc4c2d85e42e04819)), closes [#CX24-2186](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2186)
13
+ * Get Kong URL from contentstack (CX24-2447) ([035d01d](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/035d01dcdad1b7daab11d76085be65b9e7a29210))
21
14
 
22
15
  # [2.2.0](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.1.0...v2.2.0) (2022-10-13)
23
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/ns-product-lib",
3
- "version": "2.3.0-cx24-2186.2.3",
3
+ "version": "2.3.1-cx12-5910.1",
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": {
@@ -24,6 +24,7 @@
24
24
  "eslint-config-prettier": "4.1.0",
25
25
  "eslint-plugin-json": "2.1.1",
26
26
  "eslint-plugin-prettier": "3.1.2",
27
+ "axios-mock-adapter": "1.18.2",
27
28
  "jest": "25.1.0",
28
29
  "jest-sonar-reporter": "2.0.0",
29
30
  "prettier": "1.19.1"
@@ -4,11 +4,11 @@ const { getEnvironmentFromUrl } = require('@nuskin/ns-common-lib');
4
4
  const config = require('./environment');
5
5
 
6
6
  // contentstack HTTP service
7
- const env = getEnvironmentFromUrl(window.location.host);
8
- const envConfig = config.getCredentials(env);
9
- const baseURL = `${envConfig.url}/stacks/${envConfig.apiKey}?environment=${envConfig.env}`;
7
+ const env = getEnvironmentFromUrl(window ? window.location.host : null);
8
+ const envConfig = env ? config.getCredentials(env) : null;
9
+ const baseURL = env ? `${envConfig.url}/stacks/${envConfig.apiKey}?environment=${envConfig.env}` : null;
10
10
  const headers = {
11
- 'access_token': `${envConfig.accessToken}`,
11
+ 'access_token': env ? `${envConfig.accessToken}` : '',
12
12
  'Content-Type': 'application/json'
13
13
  };
14
14
  const http = axios.create({ baseURL, headers });
package/src/product.js CHANGED
@@ -72,10 +72,6 @@ const Product = function(productData) {
72
72
  // agelocme stuff
73
73
  this.agelocme = null; // object containing agelocme information (like code, label, name)
74
74
 
75
- //equinox inventory / stock label
76
- //@example "IN STOCK"
77
- this.inventory = "";
78
-
79
75
  this.setMarketAttributes = function(productStatus) {
80
76
  if (productStatus.marketAttributes) {
81
77
  this.marketAttributes = productStatus.marketAttributes;
@@ -522,7 +518,6 @@ const Product = function(productData) {
522
518
  retData.marketAttributes = this.marketAttributes;
523
519
  retData.restrictedMarkets = this.restrictedMarkets;
524
520
  retData.addOns = this.addOns;
525
- retData.inventory = this.inventory;
526
521
 
527
522
  return retData;
528
523
  };
@@ -631,7 +626,6 @@ const Product = function(productData) {
631
626
  this.marketAttributes = productData.marketAttributes;
632
627
  this.addOns = productData.addOns || [];
633
628
  this.restrictedMarkets = productData.restrictedMarkets || [];
634
- this.inventory = productData.inventory || "";
635
629
 
636
630
  if (data.priceType) {
637
631
  this.addPricing(data.priceType, data.price);
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  const axios = require("axios");
3
3
  const contentstack = require('./contentstack/contentstack');
4
- const Product = require("./product");
4
+ const product = require("./product");
5
5
 
6
6
  /** @type {*} */
7
7
  const ProductData = {
8
8
  /**
9
- * @param {string[]} skus
10
- * @param {string} locale
11
- * @param {string} market
12
- * @param {boolean} isEquinoxEnabled
9
+ * @param {string[]} skus
10
+ * @param {string} locale
11
+ * @param {string} market
12
+ * @param {boolean} isEquinoxEnabled
13
13
  */
14
14
  getProductData: async function (skus, locale, market, isEquinoxEnabled = false) {
15
15
  const localeMarket = `${locale}_${market}`;
@@ -28,7 +28,7 @@ const ProductData = {
28
28
  getProductFromEquinox: async function (skus, locale, storeID) {
29
29
  const filter = '{"filters":[{"field":"index_key_skuId","operation":"IN","value":"' + skus.toString() + '"}]}';
30
30
  axios.defaults.withCredentials = true;
31
-
31
+
32
32
  const url = await contentstack.getKongUrl() + `/orchestrationservices/storefront/catalogs/search/`;
33
33
  console.log("Dynamic URL", url)
34
34
  const href = `${url}?filter=${encodeURI(filter)}`;
@@ -78,7 +78,7 @@ const ProductData = {
78
78
  responseType: 'json'
79
79
  });
80
80
  },
81
-
81
+
82
82
  /**
83
83
  * @param {contentstack.MarketConfig} marketConfig
84
84
  */
@@ -90,150 +90,20 @@ const ProductData = {
90
90
  };
91
91
  },
92
92
 
93
- /**
94
- * Map product variant
95
- * @todo remove unnecessary fields
96
- * @param {*} eqVariant
97
- * @returns Array<Product>
98
- */
99
- eqProductVariantMapper : function (eqVariant) {
100
-
101
- let imageURL = eqVariant.properties.imageURL;
102
- const regex = /\d+.\d+/
103
- let thumbnailImage = ''
104
-
105
- if (imageURL.includes('contentstack')) {
106
- thumbnailImage = imageURL + '?width=40'
107
- } else {
108
- thumbnailImage = imageURL.replace(regex,'40.40')
109
- }
110
-
111
- return {
112
- "sku": eqVariant.identifier,
113
- "globalProductID": eqVariant.identifier,
114
- "title": eqVariant.properties.name,
115
- "country": eqVariant.properties.market,
116
- "language": "en",
117
- "shortDescr": eqVariant.properties.description,
118
- "longDescr": eqVariant.properties.productDetailsDescription,
119
- "fullImage": imageURL,
120
- "imageAltText": eqVariant.properties.name,
121
- "productCarouselImages": [
122
- {
123
- "contentType": "img",
124
- "src": "/content/products/24/00/35/24003529/jcr:content/fullImage.imgw.1280.1280.png",
125
- "alt": ""
126
- }
127
- ],
128
- "thumbnail": thumbnailImage,
129
- "ingredients": eqVariant.properties.ingredients,
130
- "benefits": eqVariant.properties.benefits,
131
- "usage": eqVariant.properties.usage,
132
- "resources": eqVariant.properties.resources,
133
- "videos": "",
134
- "movie": "",
135
- "youtube": "",
136
- "salesEventText": "",
137
- "contentSection": [
138
- {
139
- "sectionContent": "<div class=\"contentSections\"><div class=\"contentSection section\"><div>\n<h3>BENEFITS</h3>\n<div>\n<div class=\"sectionContent parsys\"><div class=\"text parbase section\">\n<p>Green tea has been used in China for thousands of years for its health-preserving and revitalizing power. Modern science has identified powerful antioxidants in green tea called polyphenols. One group of polyphenols called catechins is particularly potent and is highly effective at neutralizing free radicals at the cellular level. Catechins support healthy cell function while providing antioxidant protection to critical cell structures such as DNA. Clinical studies show catechins interfere with the production of certain enzymes involved in cell damage. Additionally, catechins have been demonstrated to cause a thermogenic effect that enhances the body s metabolic rate. Tegreen 97<sup>®</sup> from Pharmanex is a proprietary, highly concentrated extract of the catechins found in green tea. Tegreen 97<sup>®</sup> is one of the most potent antioxidant supplements on the market with a 97 percent polyphenol content, 65% catechins. Each Tegreen 97<sup>®</sup> capsule contains the catechin equivalent of approximately seven cups of green tea and is 99.5 percent caffeine free.</p>\r\n\n</div>\n\n</div>\n\n</div>\n</div>\n</div>\n<div class=\"contentSection section\"><div>\n<h3>USAGE</h3>\n<div>\n<div class=\"sectionContent parsys\"><div class=\"text parbase section\">\n<p>As a dietary supplement, take one (1) to four (4) capsules daily; preferably one (1) to two (2) each morning and evening with food. Store in a cool, dry place.</p>\r\n\n</div>\n\n</div>\n\n</div>\n</div>\n</div>\n<div class=\"contentSection section\"><div>\n<h3>INGREDIENTS</h3>\n<div>\n<div class=\"sectionContent parsys\"><div class=\"text parbase section\">\n<table border=\"1\" cellspacing=\"1\" cellpadding=\"0\" width=\"360\"><tbody>\r\n<tr>\r\n<td><b>Nutritional Facts</b></td>\r\n<td><b>Amount</b></td>\r\n<td><b>% Daily Value</b></td>\r\n</tr>\r\n<tr>\r\n<td colspan=\"3\"><b>Serving Size: 1 Capsule<br>\r\nServings Per Container: 120</b></td>\r\n</tr>\r\n<tr>\r\n<td width=\"55%\">Green tea leaf (20:1) Extract (<i>Camellia sinensis</i></td>\r\n<td width=\"20%\">250 mg</td>\r\n<td width=\"25%\">&nbsp;</td>\r\n</tr>\r\n<tr>\r\n<td width=\"55%\" colspan=\"3\">* Daily Value not established</td>\r\n</tr>\r\n<tr>\r\n<td width=\"55%\" colspan=\"3\"><b>Other Ingredients: Gelatin, Silicon Dioxide, Microcrystalline Cellulose, Magnesium Stearate.</b></td>\r\n</tr>\r\n</tbody>\r\n</table>\r\n<p>&nbsp;</p>\r\n\n</div>\n\n</div>\n\n</div>\n</div>\n</div>\n</div>\n"
140
- }
141
- ],
142
- "scanQualified": eqVariant.properties.scanQualifiedCount,
143
- "availableQuantity": eqVariant.inventoryProperties.atpQty,
144
- "maxQuantity": 999,
145
- "points": "",
146
- "cv": (eqVariant.priceFacets.CV) ? eqVariant.priceFacets.CV : '',
147
- "pv":eqVariant.priceFacets.PV,
148
- "priceType": "WRTL",
149
- "price": eqVariant.priceFacets["Regular Price"],
150
- "priceMap": {
151
- "WRTL": eqVariant.priceFacets["Regular Price"],
152
- "WADW-WRTL": eqVariant.priceFacets["Regular Price"],
153
- "WADR": 9999.01,
154
- "RTL": eqVariant.priceFacets["Regular Price"],
155
- "WWHL": eqVariant.priceFacets["Wholesale Price"],
156
- "WADW": 9998.01,
157
- "WHL": eqVariant.priceFacets["Wholesale Price"]
158
- },
159
- "cvMap": {
160
- "WWHL": (eqVariant.priceFacets.CV) ? eqVariant.priceFacets.CV : '',
161
- "WADW": (eqVariant.priceFacets.CV) ? eqVariant.priceFacets.CV : '',
162
- "WHL": (eqVariant.priceFacets.CV) ? eqVariant.priceFacets.CV : ''
163
- },
164
- "pvMap": {
165
- "WWHL": eqVariant.priceFacets.PV,
166
- "WADW": eqVariant.priceFacets.PV,
167
- "WHL": eqVariant.priceFacets.PV
168
- },
169
- "orderTypes": {
170
- "adr": true,
171
- "order": true,
172
- "zpfc": false,
173
- "zadp": true,
174
- "ars": true,
175
- "kiosk": true,
176
- "mobile": true,
177
- "preferred customer": true,
178
- "retail": true,
179
- "web": true,
180
- "web display": true
181
- },
182
- "division": eqVariant.properties.division,
183
- "backOrderDate": null,
184
- "locallyProduced": false,
185
- "agelocme": null,
186
- "count": "",
187
- "flavor": "",
188
- "size": eqVariant.properties.size,
189
- "shade": "",
190
- "status": this.switchStatusFromEquinox(eqVariant.properties.status),
191
- "variantType": "Other",
192
- "variantDropdownLabel": eqVariant.properties.variantLabel || "",
193
- "variantDropdownPlaceholder": "Select Type",
194
- "variantsLabel": eqVariant.properties.variantLabel || "",
195
- "groupOffer": false,
196
- "personalOffer": false,
197
- "savedEventName": null,
198
- "salesLabel": "",
199
- "eventName": null,
200
- "sizeWeight": '',
201
- "nettoWeight": "",
202
- "searchScore": 0,
203
- "isExclusive": false,
204
- "marketAttributes": {
205
- "discount": true,
206
- "redeem": true,
207
- "earn": true
208
- },
209
- "restrictedMarkets": [],
210
- "addOns": []
211
- };
212
- },
213
-
214
93
  eqProductMapper: function (productDataResponse) {
215
94
  let prod = [];
216
95
  let count = 0;
217
- let variants = {};
218
96
 
219
97
  let prodArr = productDataResponse.map((data) => {
220
98
  let imageURL = data.sku[count].properties.imageURL;
221
99
  const regex = /\d+.\d+/
222
100
  let thumbnailImage = ''
223
-
101
+
224
102
  if (imageURL.includes('contentstack')) {
225
103
  thumbnailImage = imageURL + '?width=40'
226
104
  } else {
227
105
  thumbnailImage = imageURL.replace(regex,'40.40')
228
106
  }
229
-
230
- if (data.sku && data.sku.length > 1) {
231
- data.sku.map(variant => {
232
- variants[variant.identifier] = this.eqProductVariantMapper(variant);
233
- return variant;
234
- });
235
- }
236
-
237
107
  prod = {
238
108
  "sku": data.sku[count].identifier,
239
109
  "globalProductID": data.identifier,
@@ -266,7 +136,7 @@ const ProductData = {
266
136
  }
267
137
  ],
268
138
  "scanQualified": data.properties.scanQualifiedCount,
269
- "availableQuantity": data.sku[count].inventoryProperties.atpQty,
139
+ "availableQuantity": 999,
270
140
  "maxQuantity": 999,
271
141
  "points": "",
272
142
  "cv": (data.sku[count].priceFacets.CV) ? data.sku[count].priceFacets.CV : '',
@@ -278,9 +148,9 @@ const ProductData = {
278
148
  "WADW-WRTL": data.sku[count].priceFacets["Regular Price"],
279
149
  "WADR": 9999.01,
280
150
  "RTL": data.sku[count].priceFacets["Regular Price"],
151
+ "WWHL": 9998.01,
281
152
  "WADW": 9998.01,
282
- "WHL": data.sku[count].priceFacets["Wholesale Price"],
283
- "WWHL": data.sku[count].priceFacets["Wholesale Price"]
153
+ "WHL": 9998.01
284
154
  },
285
155
  "cvMap": {
286
156
  "WWHL": (data.sku[count].priceFacets.CV) ? data.sku[count].priceFacets.CV : '',
@@ -317,9 +187,9 @@ const ProductData = {
317
187
  "shade": "",
318
188
  "status": this.switchStatusFromEquinox(data.sku[count].properties.productStatus),
319
189
  "variantType": "Other",
320
- "variantDropdownLabel": data.sku[count].properties.variantLabel || "",
190
+ "variantDropdownLabel": "Select Type",
321
191
  "variantDropdownPlaceholder": "Select Type",
322
- "variantsLabel": data.sku[count].properties.variantLabel || "",
192
+ "variantsLabel": "Select Type",
323
193
  "groupOffer": false,
324
194
  "personalOffer": false,
325
195
  "savedEventName": null,
@@ -327,7 +197,8 @@ const ProductData = {
327
197
  "eventName": null,
328
198
  "sizeWeight": '',
329
199
  "nettoWeight": "",
330
- "variants": variants,
200
+ "variants": {
201
+ },
331
202
  "searchScore": 0,
332
203
  "isExclusive": data.sku[count].properties.isExclusive,
333
204
  "marketAttributes": {
@@ -336,11 +207,9 @@ const ProductData = {
336
207
  "earn": true
337
208
  },
338
209
  "restrictedMarkets": [],
339
- "addOns": [],
340
- "inventory": data.sku[count].inventory || "" //inventory label
341
-
210
+ "addOns": []
342
211
  };
343
- let newProduct = new Product(prod);
212
+ let newProduct = new product(prod);
344
213
  return newProduct
345
214
  })
346
215
 
@@ -383,13 +252,13 @@ const ProductData = {
383
252
  },
384
253
 
385
254
  /**
386
- *
387
- * @param {*} custType
388
- *
255
+ *
256
+ * @param {*} custType
257
+ *
389
258
  */
390
259
  switchCustType: function (custType) {
391
260
  let newCustType = [];
392
- if (custType.includes('Brand Affiliate - Business Entity') || custType.includes('Brand Affiliate - Individual'))
261
+ if (custType.includes('Brand Affiliate - Business Entity') || custType.includes('Brand Affiliate - Individual'))
393
262
  newCustType.push(10)
394
263
  if (custType.includes('Retail Customer'))
395
264
  newCustType.push(20)