@nuskin/ns-product-lib 2.5.0-cx24-refactor.1 → 2.5.0-cx24-2556.10.1

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,9 +1,10 @@
1
- # [2.5.0-cx24-refactor.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.5.0-cx24-2179.2.17...v2.5.0-cx24-refactor.1) (2023-01-26)
1
+ # [2.5.0-cx24-2556.10.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.5.0-cx24-2179.2.17...v2.5.0-cx24-2556.10.1) (2023-01-26)
2
2
 
3
3
 
4
4
  ### Update
5
5
 
6
- * refactoring getConfiguration ([76c54aa](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/76c54aa7b3a9a81c56e701314e6515edac451fe2))
6
+ * dynamically select environment (CX24-2556) ([3ba9fea](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/3ba9fea8a3e308b25f8dea39572af59f86b4d2b8))
7
+ * dynamically select environment (CX24-2556) ([4729d82](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/4729d82e49c9a21d17f3e6a619b25fe0aa51dc88))
7
8
 
8
9
  # [2.5.0-cx24-2179.2.17](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.5.0-cx24-2179.2.16...v2.5.0-cx24-2179.2.17) (2023-01-24)
9
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/ns-product-lib",
3
- "version": "2.5.0-cx24-refactor.1",
3
+ "version": "2.5.0-cx24-2556.10.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": {
@@ -130,100 +130,6 @@ async function getAEMConfig() {
130
130
  }
131
131
  }
132
132
 
133
- /**
134
- * getEquinoxMarkets will get the list of Equinox-enabled markets from contentstack
135
- *
136
- * @typedef EquinoxEnabledMarket
137
- * @property {string} market_name
138
- * @property {string} country_code
139
- * @property {string} store_id
140
- *
141
- * @typedef EquinoxEnabledMarkets
142
- * @property {EquinoxEnabledMarket[]} [dev_markets]
143
- * @property {EquinoxEnabledMarket[]} [test_markets]
144
- * @property {EquinoxEnabledMarket[]} [staging_markets]
145
- * @property {EquinoxEnabledMarket[]} [prod_markets]
146
- *
147
- * @export
148
- * @return {Promise<EquinoxEnabledMarkets>}
149
- */
150
- async function getEquinoxMarkets() {
151
- try {
152
- if (isCacheExpired(cacheKeys.equinoxMarkets)) {
153
- const marketConfig = `${platform.env}_markets`;
154
- const variables = { uid: 'blt5633ff9e560f14ef' };
155
- const query = `query EquinoxMarketsByUid($uid: String!) {
156
- equinox_markets(uid: $uid) {
157
- ${marketConfig} {
158
- market_name
159
- country_code
160
- store_id
161
- }
162
- }
163
- }`;
164
-
165
- const { data } = await contentstackService({
166
- data: { variables, query }
167
- });
168
-
169
- setCachedData(cacheKeys.equinoxMarkets, data.equinox_markets[marketConfig]);
170
- }
171
-
172
- return getCachedData(cacheKeys.equinoxMarkets);
173
- } catch (error) {
174
- console.error(error);
175
- return [];
176
- }
177
- }
178
-
179
- /**getKongUrl gets the URL for Kong in contentstack
180
- *
181
- * @returns {string}
182
- */
183
- async function getKongUrl() {
184
- try {
185
- if (isCacheExpired(cacheKeys.kongUrl)) {
186
- const variables = { uid: 'blt5633ff9e560f14ef' };
187
- const query = `query KongUrlByUid($uid: String!) {
188
- equinox_markets(uid: $uid) {
189
- kong_urls {
190
- ${platform.env}
191
- }
192
- }
193
- }`;
194
-
195
- const { data } = await contentstackService({
196
- data: { variables, query }
197
- });
198
-
199
- setCachedData(cacheKeys.kongUrl, data.equinox_markets.kong_urls[platform.env]);
200
- }
201
-
202
- return getCachedData(cacheKeys.kongUrl);
203
- } catch (error) {
204
- console.error(error);
205
- return [];
206
- }
207
- }
208
-
209
- /**
210
- * isMarketEnabled checks is the given market is in the list
211
- * of equinox-enabled markets.
212
- *
213
- * @param {string} market
214
- * @returns {EquinoxEnabledMarket|null}
215
- */
216
- async function isMarketEnabled(market) {
217
- const markets = await getEquinoxMarkets();
218
- const currentMarket = markets.filter(m => m.country_code.toLowerCase() === market.toLowerCase());
219
-
220
- if (currentMarket.length > 0) {
221
- return currentMarket[0];
222
- }
223
-
224
- return null;
225
- }
226
-
227
133
  /**
228
134
  * Contentstack HTTP - axios wrapper for contentstack request
229
135
  *
@@ -243,8 +149,5 @@ async function contentstackService(config) {
243
149
  }
244
150
 
245
151
  module.exports = {
246
- getAEMConfig,
247
- getEquinoxMarkets,
248
- isMarketEnabled,
249
- getKongUrl
250
- }
152
+ getAEMConfig
153
+ }
@@ -1,16 +1,14 @@
1
1
  "use strict";
2
2
  const { getConfiguration } = require('@nuskin/configuration-sdk');
3
- // import { ConfigService } from '@nuskin/ns-util';
3
+ const { getEnvironmentFromUrl } = require('@nuskin/ns-common-lib');
4
4
  const axios = require("axios");
5
5
  const contentstack = require('./contentstack/contentstack');
6
6
  const Product = require("./product");
7
7
  const CustomerTypes = require('./models/customerTypes');
8
8
  const ProductStatus = require("./models/productStatus");
9
- const { getEnvironmentFromUrl } = require('@nuskin/ns-common-lib');
10
-
11
9
  /** @type {*} */
12
10
  const ProductData = {
13
- /**
11
+ /**
14
12
  * @param {string[]} skus
15
13
  * @param {string} locale
16
14
  * @param {string} market
@@ -18,16 +16,12 @@ const ProductData = {
18
16
  */
19
17
  getProductData: async function (skus, locale, market, isEquinoxEnabled = false) {
20
18
  const localeMarket = `${locale}_${market}`;
21
- let env = 'test';
22
- if (typeof window !== 'undefined') {
23
- env = getEnvironmentFromUrl(window.location.host);
24
- }
25
- console.log(`ENV is ${env}`)
19
+
26
20
  if (isEquinoxEnabled) {
27
21
  let config = (await getConfiguration({
28
22
  configMapNames: ['Equinox_Markets'],
29
23
  country: market,
30
- environment: env,
24
+ environment: contentstackEnv(),
31
25
  clientId: '735b1eb810304bba966af0891ab54053'
32
26
  }));
33
27
 
@@ -152,7 +146,77 @@ const ProductData = {
152
146
  "salesEventText": "",
153
147
  "contentSection": [
154
148
  {
155
- "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"
149
+ "sectionContent": `<div class="contentSections">
150
+ <div class="contentSection section">
151
+ <div>\n<h3>BENEFITS</h3>\n
152
+ <div>\n
153
+ <div class="sectionContent parsys">
154
+ <div class="text parbase section">\n
155
+ <p>
156
+ Green tea has been used in China for thousands of years for its health-preserving and
157
+ revitalizing power. Modern science has identified powerful antioxidants in green tea
158
+ called polyphenols. One group of polyphenols called catechins is particularly potent
159
+ and is highly effective at neutralizing free radicals at the cellular level. Catechins
160
+ support healthy cell function while providing antioxidant protection to critical cell
161
+ structures such as DNA. Clinical studies show catechins interfere with the production
162
+ of certain enzymes involved in cell damage. Additionally, catechins have been demonstrated
163
+ to cause a thermogenic effect that enhances the body s metabolic rate. Tegreen 97<sup>®</sup>
164
+ from Pharmanex is a proprietary, highly concentrated extract of the catechins found
165
+ in green tea. Tegreen 97<sup>®</sup> is one of the most potent antioxidant supplements
166
+ on the market with a 97 percent polyphenol content, 65% catechins. Each Tegreen 97<sup>®</sup>
167
+ capsule contains the catechin equivalent of approximately seven cups of green tea and is
168
+ 99.5 percent caffeine free.
169
+ </p>\r\n\n
170
+ </div>\n\n
171
+ </div>\n\n
172
+ </div>\n
173
+ </div>\n
174
+ </div>\n
175
+ <div class="contentSection section">
176
+ <div>\n<h3>USAGE</h3>\n
177
+ <div>\n
178
+ <div class="sectionContent parsys">
179
+ <div class="text parbase section">\n
180
+ <p>As a dietary supplement, take one (1) to four (4) capsules daily; preferably one (1)
181
+ to two (2) each morning and evening with food. Store in a cool, dry place.</p>\r\n\n
182
+ </div>\n\n
183
+ </div>\n\n
184
+ </div>\n
185
+ </div>\n
186
+ </div>\n
187
+ <div class="contentSection section">
188
+ <div>\n<h3>INGREDIENTS</h3>\n
189
+ <div>\n
190
+ <div class="sectionContent parsys">
191
+ <div class="text parbase section">\n
192
+ <table border="1" cellspacing="1" cellpadding="0" width="360">
193
+ <tbody>\r\n
194
+ <tr>\r\n
195
+ <td><b>Nutritional Facts</b></td>\r\n
196
+ <td><b>Amount</b></td>\r\n<td><b>% Daily Value</b></td>\r\n
197
+ </tr>\r\n
198
+ <tr>\r\n
199
+ <td colspan="3"><b>Serving Size: 1 Capsule<br>\r\nServings Per Container: 120</b></td>\r\n
200
+ </tr>\r\n
201
+ <tr>\r\n
202
+ <td width="55%">Green tea leaf (20:1) Extract (<i>Camellia sinensis</i></td>\r\n
203
+ <td width="20%">250 mg</td>\r\n<td width="25%">&nbsp;</td>\r\n
204
+ </tr>\r\n
205
+ <tr>\r\n<td width="55%" colspan="3">* Daily Value not established</td>\r\n</tr>\r\n
206
+ <tr>\r\n
207
+ <td width="55%" colspan="3">
208
+ <b>Other Ingredients: Gelatin, Silicon Dioxide,
209
+ Microcrystalline Cellulose, Magnesium Stearate.</b>
210
+ </td>\r\n</tr>\r\n
211
+ </tbody>\r\n
212
+ </table>\r\n
213
+ <p>&nbsp;</p>\r\n\n
214
+ </div>\n\n
215
+ </div>\n\n
216
+ </div>\n
217
+ </div>\n
218
+ </div>\n
219
+ </div>\n`
156
220
  }
157
221
  ],
158
222
  "scanQualified": eqVariant.properties.scanQualifiedCount,
@@ -234,7 +298,9 @@ const ProductData = {
234
298
  }
235
299
 
236
300
  const defaultProductPrice = product.totalValue ? product.totalValue.originalPrice : 0;
237
- const computedPrice = product.totalValue && product.totalValue.priceAfterDiscount ? product.totalValue.priceAfterDiscount : 0;
301
+ const computedPrice = product.totalValue && product.totalValue.priceAfterDiscount
302
+ ? product.totalValue.priceAfterDiscount
303
+ : 0;
238
304
  let eventName = "";
239
305
  const eventLabels = [];
240
306
 
@@ -276,7 +342,12 @@ const ProductData = {
276
342
  });
277
343
  }
278
344
 
279
- const { eventName, eventLabels, computedPrice, defaultProductPrice} = this.getEqProductPromotions(data.sku[count]);
345
+ const {
346
+ eventName,
347
+ eventLabels,
348
+ computedPrice,
349
+ defaultProductPrice
350
+ } = this.getEqProductPromotions(data.sku[count]);
280
351
  const productPrice = eventName ? defaultProductPrice : data.sku[count].priceFacets["Regular Price"];
281
352
  const discountedPrice = eventName ? computedPrice : data.sku[count].priceFacets["Regular Price"];
282
353
 
@@ -530,4 +601,12 @@ const ProductData = {
530
601
  }
531
602
  }
532
603
 
604
+ function contentstackEnv() {
605
+ if (typeof window === 'undefined') {
606
+ return 'test';
607
+ }
608
+
609
+ return getEnvironmentFromUrl(window.location.host);
610
+ }
611
+
533
612
  module.exports = ProductData;