@nuskin/ns-product-lib 1.6.0-cx24-2382.1 → 2.0.0-CX24.1

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/CHANGELOG.md CHANGED
@@ -1,3 +1,98 @@
1
+ # [2.0.0-CX24.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v1.5.0...v2.0.0-CX24.1) (2022-09-16)
2
+
3
+
4
+ ### Breaking
5
+
6
+ * replace runConfig and marketConfig parameters of getProductData with locale and market (CX24-2382) ([b7b8ac7](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/b7b8ac7fa946df0b3690f700d00f5acfb0073bcf))
7
+
8
+ ### Update
9
+
10
+ * Map new equinox fields to response (CX24-2103) ([6e1800b](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/6e1800bbf9b1c6fe8f844e011b5326d772a88f5b))
11
+ * removing old contentstack.js file ([3f2df2e](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/3f2df2e298e6c50aa321720fa0cefa14b4ed025a))
12
+ * removing old contentstack.js file ([87ae17d](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/87ae17ded4471199b104daa5dee91a6285973db1))
13
+ * removing old contentstack.js file ([13d4aa2](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/13d4aa21d7bdeda38e39d6880f6bc06f4c52fee9))
14
+
15
+ # [2.0.0-cx24-2382.11](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.0.0-cx24-2382.10...v2.0.0-cx24-2382.11) (2022-09-13)
16
+
17
+
18
+ ### Update
19
+
20
+ * updating the product data map (#CX24-2103) ([097dee5](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/097dee5567d777e8f8474c3d567cc47c52c2ca30)), closes [#CX24-2103](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2103)
21
+
22
+ # [2.0.0-cx24-2382.10](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.0.0-cx24-2382.9...v2.0.0-cx24-2382.10) (2022-09-12)
23
+
24
+
25
+ ### Update
26
+
27
+ * updating the product data map (#CX24-2103) ([a13045e](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/a13045ef18a3ff2c7cfc48ae328e7935528699ae)), closes [#CX24-2103](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2103)
28
+
29
+ # [2.0.0-cx24-2382.9](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.0.0-cx24-2382.8...v2.0.0-cx24-2382.9) (2022-09-12)
30
+
31
+
32
+ ### Update
33
+
34
+ * updating the product data map (#CX24-2103) ([7226709](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/7226709e2efa7352069d439e6e93fbc13c8155aa)), closes [#CX24-2103](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2103)
35
+
36
+ # [2.0.0-cx24-2382.8](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.0.0-cx24-2382.7...v2.0.0-cx24-2382.8) (2022-09-11)
37
+
38
+
39
+ ### Update
40
+
41
+ * change the parameters passed to getProductData (CX24-2382) ([be85b9d](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/be85b9dbacdb59091d72b4905b6c2b7236eb6fff))
42
+
43
+ # [2.0.0-cx24-2382.7](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.0.0-cx24-2382.6...v2.0.0-cx24-2382.7) (2022-09-11)
44
+
45
+
46
+ ### Update
47
+
48
+ * change the parameters passed to getProductData (CX24-2382) ([cb4683d](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/cb4683d82673736c800c19cbe88878001b6e7e56))
49
+
50
+ # [2.0.0-cx24-2382.6](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.0.0-cx24-2382.5...v2.0.0-cx24-2382.6) (2022-09-11)
51
+
52
+
53
+ ### Update
54
+
55
+ * change the parameters passed to getProductData (CX24-2382) ([5e4e721](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/5e4e7210c168ff6fbc35503dba2c8ea77e9480c4))
56
+
57
+ # [2.0.0-cx24-2382.5](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.0.0-cx24-2382.4...v2.0.0-cx24-2382.5) (2022-09-09)
58
+
59
+
60
+ ### Update
61
+
62
+ * change the parameters passed to getProductData (CX24-2382) ([996aee7](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/996aee7b44b59dc19569087f34b6f127933af7e5))
63
+
64
+ # [2.0.0-cx24-2382.4](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.0.0-cx24-2382.3...v2.0.0-cx24-2382.4) (2022-09-08)
65
+
66
+
67
+ ### Update
68
+
69
+ * change the parameters passed to getProductData (CX24-2382) ([7e29c09](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/7e29c09396b44ee9f959e2a461940b5fcc382743))
70
+
71
+ # [2.0.0-cx24-2382.3](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.0.0-cx24-2382.2...v2.0.0-cx24-2382.3) (2022-09-08)
72
+
73
+
74
+ ### Update
75
+
76
+ * change the parameters passed to getProductData (CX24-2382) ([38deea7](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/38deea72a80b2bac07de35f5fa7e45f091f9f0c6))
77
+
78
+ # [2.0.0-cx24-2382.2](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.0.0-cx24-2382.1...v2.0.0-cx24-2382.2) (2022-09-07)
79
+
80
+
81
+ ### Update
82
+
83
+ * change the parameters passed to getProductData (CX24-2382) ([ba22522](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/ba225229615599f6884a56fc4fd4c172a2e3d83e))
84
+
85
+ # [2.0.0-cx24-2382.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v1.6.0-cx24-2382.1...v2.0.0-cx24-2382.1) (2022-09-06)
86
+
87
+
88
+ ### Breaking
89
+
90
+ * replace runConfig and marketConfig parameters of getProductData with locale and market (CX24-2382) ([713bbb6](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/713bbb6b52e20727ce846d4df5c84d837fb931d5))
91
+
92
+ ### New
93
+
94
+ * add equinox-enabled market validation (CX24-2382) ([6633eb5](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/6633eb5824ec621a7316aff401d29876761ffc38))
95
+
1
96
  # [1.6.0-cx24-2382.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v1.5.0...v1.6.0-cx24-2382.1) (2022-09-01)
2
97
 
3
98
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/ns-product-lib",
3
- "version": "1.6.0-cx24-2382.1",
3
+ "version": "2.0.0-CX24.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": {
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@nuskin/ns-common-lib": "1.3.0",
33
- "@nuskin/ns-util": "3.104.0",
33
+ "@nuskin/ns-util": "3.105",
34
34
  "axios": "0.27.2",
35
35
  "qs": "6.11.0"
36
36
  },
@@ -0,0 +1,181 @@
1
+ // This module can be bundled into a package for better reusability.
2
+ const axios = require('axios');
3
+ const { getEnvironmentFromUrl } = require('@nuskin/ns-common-lib');
4
+ const config = require('./environment');
5
+
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}`;
10
+ const headers = {
11
+ 'access_token': `${envConfig.accessToken}`,
12
+ 'Content-Type': 'application/json'
13
+ };
14
+ const http = axios.create({ baseURL, headers });
15
+
16
+ // in-memory caching
17
+ const cacheKeys = { aemConfig: 'aemConfig', equinoxMarkets: 'equinoxMarkets' };
18
+ const cacheTTLInSeconds = 30 * 1000;
19
+ const cache = {
20
+ [cacheKeys.aemConfig]: { data: null, ttl: Date.now() + cacheTTLInSeconds },
21
+ [cacheKeys.equinoxMarkets]: { data: null, ttl: Date.now() + cacheTTLInSeconds }
22
+ };
23
+
24
+ /**
25
+ * isCacheExpired checks if the cached data is expired.
26
+ *
27
+ * @param {string} key
28
+ * @returns {boolean}
29
+ */
30
+ function isCacheExpired(key) {
31
+ return cache[key].data === null || Date.now() > cache[key].ttl;
32
+ }
33
+
34
+ /**
35
+ * setCachedData will replace the cached data and update the TTL.
36
+ *
37
+ * @param {string} key
38
+ * @param {MarketConfig|EquinoxEnabledMarkets} data
39
+ * @returns {void}
40
+ */
41
+ function setCachedData(key, data) {
42
+ cache[key].data = data;
43
+ cache[key].ttl = Date.now() + cacheTTLInSeconds;
44
+ }
45
+
46
+ /**
47
+ * getCachedData returns the cached data.
48
+ *
49
+ * @param {string} key
50
+ */
51
+ function getCachedData(key) {
52
+ return cache[key].data;
53
+ }
54
+
55
+ /**
56
+ * getAEMConfig fetches the market config from contentstack.
57
+ *
58
+ * @typedef MarketConfig
59
+ * @property {string} aws_url
60
+ * @property {string} checkout_client_id
61
+ * @property {string} checkout_client_secret
62
+ *
63
+ * @export
64
+ * @return {Promise<null|MarketConfig>}
65
+ */
66
+ async function getAEMConfig() {
67
+ try {
68
+ if (isCacheExpired(cacheKeys.aemConfig)) {
69
+ const marketConfig = `market_config_${env}`;
70
+ const variables = { uid: 'blt52b0b83a89763791' };
71
+ const query = `query AemConfigByUid($uid: String!) {
72
+ aem_config(uid: $uid) {
73
+ title
74
+ ${marketConfig} {
75
+ checkout_client_secret
76
+ checkout_client_id
77
+ aws_url
78
+ }
79
+ }
80
+ }`;
81
+
82
+ const { data } = await contentstackService({
83
+ data: { variables, query }
84
+ });
85
+
86
+ setCachedData(cacheKeys.aemConfig, data.aem_config[marketConfig]);
87
+ }
88
+
89
+ return getCachedData(cacheKeys.aemConfig);
90
+ } catch (error) {
91
+ console.error(error);
92
+ return null;
93
+ }
94
+ }
95
+
96
+ /**
97
+ * getEquinoxMarkets will get the list of Equinox-enabled markets from contentstack
98
+ *
99
+ * @typedef EquinoxEnabledMarket
100
+ * @property {string} market_name
101
+ * @property {string} country_code
102
+ * @property {string} store_id
103
+ *
104
+ * @typedef EquinoxEnabledMarkets
105
+ * @property {EquinoxEnabledMarket[]} [dev_markets]
106
+ * @property {EquinoxEnabledMarket[]} [test_markets]
107
+ * @property {EquinoxEnabledMarket[]} [staging_markets]
108
+ * @property {EquinoxEnabledMarket[]} [prod_markets]
109
+ *
110
+ * @export
111
+ * @return {Promise<EquinoxEnabledMarkets>}
112
+ */
113
+ async function getEquinoxMarkets() {
114
+ try {
115
+ if (isCacheExpired(cacheKeys.equinoxMarkets)) {
116
+ const marketConfig = `${env}_markets`;
117
+ const variables = { uid: 'blt5633ff9e560f14ef' };
118
+ const query = `query EquinoxMarketsByUid($uid: String!) {
119
+ equinox_markets(uid: $uid) {
120
+ ${marketConfig} {
121
+ market_name
122
+ country_code
123
+ store_id
124
+ }
125
+ }
126
+ }`;
127
+
128
+ const { data } = await contentstackService({
129
+ data: { variables, query }
130
+ });
131
+
132
+ setCachedData(cacheKeys.equinoxMarkets, data.equinox_markets[marketConfig]);
133
+ }
134
+
135
+ return getCachedData(cacheKeys.equinoxMarkets);
136
+ } catch (error) {
137
+ console.error(error);
138
+ return [];
139
+ }
140
+ }
141
+
142
+ /**
143
+ * isMarketEnabled checks is the given market is in the list
144
+ * of equinox-enabled markets.
145
+ *
146
+ * @param {string} market
147
+ * @returns {EquinoxEnabledMarket|null}
148
+ */
149
+ async function isMarketEnabled(market) {
150
+ const markets = await getEquinoxMarkets();
151
+ const currentMarket = markets.filter(m => m.country_code.toLowerCase() === market.toLowerCase());
152
+
153
+ if (currentMarket.length > 0) {
154
+ return currentMarket[0];
155
+ }
156
+
157
+ return null;
158
+ }
159
+
160
+ /**
161
+ * Contentstack HTTP - axios wrapper for contentstack request
162
+ *
163
+ * @param {Object} config - required param
164
+ * @return {Promise<import('axios').AxiosResponse>} Promise that resolves to market_list_eq object
165
+ */
166
+ async function contentstackService(config) {
167
+ const data = JSON.parse(JSON.stringify(config.data));
168
+
169
+ try {
170
+ const response = await http.post('', data);
171
+ return response.data
172
+ } catch (error) {
173
+ console.error(error.response.data.errors);
174
+ }
175
+ }
176
+
177
+ module.exports = {
178
+ getAEMConfig,
179
+ getEquinoxMarkets,
180
+ isMarketEnabled
181
+ }
@@ -0,0 +1,41 @@
1
+ // use .env, but how?
2
+ const baseConfig = {
3
+ apiKey: 'blt7d4c4f4a1bf5a819',
4
+ url: 'https://graphql.contentstack.com'
5
+ };
6
+
7
+ const config = {
8
+ dev: {
9
+ ...baseConfig,
10
+ accessToken: 'cs74599c107573ea7f6c7a1413',
11
+ env: 'public-dev'
12
+ },
13
+ prod: {
14
+ ...baseConfig,
15
+ accessToken: 'cs7029c5e32f0e99978efc683d',
16
+ env: 'public-prod'
17
+ },
18
+ test: {
19
+ ...baseConfig,
20
+ accessToken: 'cs67e9fdd60eb15c301add40ea',
21
+ env: 'public-test'
22
+ }
23
+ };
24
+
25
+ /**
26
+ * getCredentials returns contentstack config.
27
+ *
28
+ * @param {string} env
29
+ * @return {{accessToken: string; apiKey: string; env: string; url: string;}}
30
+ */
31
+ function getCredentials(env) {
32
+ if (config[env] === undefined) {
33
+ return {};
34
+ }
35
+
36
+ return config[env];
37
+ }
38
+
39
+ module.exports = {
40
+ getCredentials
41
+ }
package/src/index.js CHANGED
@@ -6,6 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  const Agelocme = require("./agelocme.js");
9
+ const Contentstack = require('./contentstack/contentstack');
9
10
  const PriceType = require("./priceType.js");
10
11
  const Product = require("./product.js");
11
12
  const ProductContentMapper = require("./productContentMapper.js");
@@ -16,6 +17,7 @@ const ProductData = require("./productData.js");
16
17
 
17
18
  module.exports = {
18
19
  Agelocme,
20
+ Contentstack,
19
21
  PriceType,
20
22
  Product,
21
23
  ProductContentMapper,
@@ -1,90 +1,119 @@
1
1
  "use strict";
2
- const { getEnvironmentFromUrl } = require('@nuskin/ns-common-lib');
3
2
  const axios = require("axios");
3
+ const contentstack = require('./contentstack/contentstack');
4
4
  const product = require("./product");
5
5
 
6
- const CS_BASE_URL = 'https://graphql.contentstack.com';
7
- const CS_DELIVERY_TOKEN = 'cs74599c107573ea7f6c7a1413';
8
- const CS_API_KEY = 'blt7d4c4f4a1bf5a819';
9
- const CS_DEFAULT_ENV = 'public-dev';
10
-
11
6
  /** @type {*} */
12
7
  const ProductData = {
13
8
  /**
14
- * @param {*} skus
15
- * @param {*} runConfig
16
- * @param {*} marketConfig
9
+ * @param {string[]} skus
10
+ * @param {string} locale
11
+ * @param {string} market
17
12
  * @param {boolean} isEquinoxEnabled
18
13
  */
19
- getProductData: async function (skus, runConfig, marketConfig, isEquinoxEnabled = false) {
20
- const locale = `${runConfig.language}_${runConfig.country}`;
21
- const enabledMarkets = await this.getEquinoxEnabledMarkets();
22
- console.log(enabledMarkets);
14
+ getProductData: async function (skus, locale, market, isEquinoxEnabled = false) {
15
+ const localeMarket = `${locale}_${market}`;
16
+
17
+ if (isEquinoxEnabled) {
18
+ const marketConfig = await contentstack.isMarketEnabled(market);
23
19
 
24
- if (isEquinoxEnabled === true) {
25
- return await this.getProductFromEquinox(skus, locale, marketConfig, 406);
20
+ if (marketConfig !== null) {
21
+ return await this.getProductFromEquinox(skus, localeMarket, marketConfig.store_id);
22
+ }
26
23
  }
27
24
 
28
- return await this.getProductFromLegacy(skus, locale, marketConfig);
25
+ return await this.getProductFromLegacy(skus, localeMarket);
29
26
  },
30
27
 
31
- getProductFromEquinox: async function (skus, locale, marketConfig, storeID) {
32
- const filter = `{
33
- "filters": [{
34
- "field": "index_key_skuId",
35
- "operation": "IN",
36
- "value": "${skus.toString()}"
37
- }]
38
- }`;
28
+ getProductFromEquinox: async function (skus, locale, storeID) {
29
+ const filter = '{"filters":[{"field":"index_key_skuId","operation":"IN","value":"' + skus.toString() + '"}]}';
39
30
  axios.defaults.withCredentials = true;
40
- const productDataResponse = await axios.request({
31
+ const url = `https://storefront.api.wde.nuskin.io/orchestrationservices/storefront/catalogs/search/`;
32
+ const href = `${url}?filter=${encodeURI(filter)}`;
33
+ const response = await axios.request({
41
34
  method: 'get',
42
- url: `https://storefront.api.wts.nuskin.io/orchestrationservices/storefront/catalogs/search/`,
35
+ url: href,
43
36
  params: {
44
37
  locale,
45
- storeId: storeID,
46
- filter
38
+ storeId: storeID
47
39
  },
48
- headers: this.getProductDataRequestHeaders(marketConfig),
49
- responseType: "json"
40
+ headers: this.getEquinoxRequestHeaders(),
41
+ responseType: 'json'
50
42
  });
51
43
 
52
- return this.eqProductMapper(productDataResponse.data.product);
44
+ if (response.data.product) {
45
+ return this.eqProductMapper(response.data.product);
46
+ }
47
+
48
+ return {
49
+ status: 400,
50
+ messages: [response.data.message],
51
+ data: { count: 0, products: [] }
52
+ }
53
+ },
54
+
55
+ getEquinoxRequestHeaders() {
56
+ return {
57
+ 'Content-Type': 'application/json'
58
+ };
53
59
  },
54
60
 
55
- getProductFromLegacy: async function (skus, locale, marketConfig) {
56
- const lambdaUrl = `${marketConfig.awsUrl}/productData/v1`;
61
+ getProductFromLegacy: async function (skus, locale) {
62
+ const marketConfig = await contentstack.getAEMConfig();
63
+
64
+ if (marketConfig === null) {
65
+ return null;
66
+ }
67
+
68
+ const lambdaUrl = `${marketConfig.aws_url}/productData/v1`;
57
69
  const payload = { locale, skus };
58
70
 
59
71
  return await axios.request({
60
- method: "post",
72
+ method: 'post',
61
73
  url: lambdaUrl,
62
74
  data: payload,
63
- headers: this.getProductDataRequestHeaders(marketConfig),
64
- responseType: "json"
75
+ headers: this.getLegacyRequestHeaders(marketConfig),
76
+ responseType: 'json'
65
77
  });
66
78
  },
67
-
68
- /* eqProductMapper: function(productDataResponse) {
69
- return productDataResponse;
70
- }, */
79
+
80
+ /**
81
+ * @param {contentstack.MarketConfig} marketConfig
82
+ */
83
+ getLegacyRequestHeaders: function(marketConfig) {
84
+ return {
85
+ 'Content-Type': 'application/json',
86
+ client_id: marketConfig.checkout_client_id,
87
+ client_secret: marketConfig.checkout_client_secret
88
+ };
89
+ },
71
90
 
72
91
  eqProductMapper: function (productDataResponse) {
73
92
  let prodArr = [];
74
93
  let prod = [];
75
94
  let count = 0;
76
- productDataResponse.forEach((data, index) => {
77
- count++
78
95
 
96
+ // we can use Array.map for this one
97
+ productDataResponse.forEach((data, index) => {
98
+
99
+ let imageURL = data.sku[count].properties.imageURL;
100
+ const regex = /\d+.\d+/
101
+ let thumbnailImage = ''
102
+
103
+ if (imageURL.includes('contentstack')) {
104
+ thumbnailImage = imageURL + '?width=40'
105
+ } else {
106
+ thumbnailImage = imageURL.replace(regex,'40.40')
107
+ }
79
108
  prod = {
80
- "sku": data.sku[0].identifier,
109
+ "sku": data.sku[count].identifier,
81
110
  "globalProductID": data.identifier,
82
111
  "title": data.properties.name,
83
- "country": data.sku[0].properties.market,
112
+ "country": data.sku[count].properties.market,
84
113
  "language": "en",
85
114
  "shortDescr": data.properties.description,
86
115
  "longDescr": data.properties.productDetailsDescription,
87
- "fullImage": data.properties.imageURL,
116
+ "fullImage": imageURL,
88
117
  "imageAltText": data.properties.name,
89
118
  "productCarouselImages": [
90
119
  {
@@ -93,11 +122,11 @@ const ProductData = {
93
122
  "alt": ""
94
123
  }
95
124
  ],
96
- "thumbnail": "/content/products/24/11/08/24110845/jcr:content/fullImage.img.160.160.png/1490766406581-cache.png",
97
- "ingredients": "",
98
- "benefits": "",
99
- "usage": "",
100
- "resources": "",
125
+ "thumbnail": thumbnailImage,
126
+ "ingredients": data.properties.ingredients,
127
+ "benefits": data.properties.benefits,
128
+ "usage": data.properties.usage,
129
+ "resources": data.sku[count].properties.resources,
101
130
  "videos": "",
102
131
  "movie": "",
103
132
  "youtube": "",
@@ -111,28 +140,28 @@ const ProductData = {
111
140
  "availableQuantity": 999,
112
141
  "maxQuantity": 999,
113
142
  "points": "",
114
- "cv": 99.1,
115
- "pv": 99.01,
143
+ "cv": (data.sku[count].priceFacets.CV) ? data.sku[count].priceFacets.CV : '',
144
+ "pv": data.sku[count].priceFacets.PV,
116
145
  "priceType": "WRTL",
117
- "price": 9999.11,
146
+ "price": data.sku[count].priceFacets["Regular Price"],
118
147
  "priceMap": {
119
- "WRTL": 9999.11,
120
- "WADW-WRTL": 9999.11,
148
+ "WRTL": data.sku[count].priceFacets["Regular Price"],
149
+ "WADW-WRTL": data.sku[count].priceFacets["Regular Price"],
121
150
  "WADR": 9999.01,
122
- "RTL": 9999.11,
151
+ "RTL": data.sku[count].priceFacets["Regular Price"],
123
152
  "WWHL": 9998.01,
124
153
  "WADW": 9998.01,
125
154
  "WHL": 9998.01
126
155
  },
127
156
  "cvMap": {
128
- "WWHL": 8888,
129
- "WADW": 8888,
130
- "WHL": 8888
157
+ "WWHL": (data.sku[count].priceFacets.CV) ? data.sku[count].priceFacets.CV : '',
158
+ "WADW": (data.sku[count].priceFacets.CV) ? data.sku[count].priceFacets.CV : '',
159
+ "WHL": (data.sku[count].priceFacets.CV) ? data.sku[count].priceFacets.CV : ''
131
160
  },
132
161
  "pvMap": {
133
- "WWHL": 99,
134
- "WADW": 98,
135
- "WHL": 90
162
+ "WWHL": data.sku[count].priceFacets.PV,
163
+ "WADW": data.sku[count].priceFacets.PV,
164
+ "WHL": data.sku[count].priceFacets.PV
136
165
  },
137
166
  "orderTypes": {
138
167
  "adr": true,
@@ -148,28 +177,26 @@ const ProductData = {
148
177
  "web display": true
149
178
  },
150
179
  "childSkus": [],
151
- "custTypes": [
152
- "10"
153
- ],
154
- "division": "",
180
+ "custTypes": this.switchCustType(data.properties.customerTypes),
181
+ "division": data.properties.division,
155
182
  "backOrderDate": null,
156
183
  "locallyProduced": false,
157
184
  "agelocme": null,
158
185
  "count": "",
159
186
  "flavor": "",
160
- "size": "",
187
+ "size": data.sku[count].properties.size,
161
188
  "shade": "",
162
- "status": "RELEASED_FOR_SALE",
163
- "variantType": "",
164
- "variantDropdownLabel": "",
165
- "variantDropdownPlaceholder": "",
166
- "variantsLabel": "",
189
+ "status": this.switchStatusFromEquinox(data.sku[count].properties.productStatus),
190
+ "variantType": "Other",
191
+ "variantDropdownLabel": "Select Type",
192
+ "variantDropdownPlaceholder": "Select Type",
193
+ "variantsLabel": "Select Type",
167
194
  "groupOffer": false,
168
195
  "personalOffer": false,
169
196
  "savedEventName": null,
170
197
  "salesLabel": "",
171
198
  "eventName": null,
172
- "sizeWeight": "120 capsules",
199
+ "sizeWeight": '',
173
200
  "nettoWeight": "",
174
201
  "variants": {
175
202
  },
@@ -183,6 +210,7 @@ const ProductData = {
183
210
  "restrictedMarkets": [],
184
211
  "addOns": []
185
212
  };
213
+ count++
186
214
  let newProduct = new product(prod);
187
215
  prodArr[index] = newProduct;
188
216
 
@@ -190,7 +218,7 @@ const ProductData = {
190
218
 
191
219
  let data = {
192
220
  products: prodArr,
193
- count: count
221
+ count: count + 1
194
222
  };
195
223
  return {
196
224
  data: {
@@ -198,87 +226,48 @@ const ProductData = {
198
226
  "messages": [],
199
227
  "data": data
200
228
  }
201
- }
202
-
203
- },
204
-
205
- getProductDataRequestHeaders: function (marketConfig) {
206
- return {
207
- "Content-Type": "application/json",
208
- client_id: marketConfig.checkout.clientId,
209
- client_secret: marketConfig.checkout.clientSecret
210
229
  };
211
230
  },
212
231
 
213
- /**
214
- * Get equinox enabled market list from contentstack
215
- *
216
- * @return {Promise<null|import('@nuskin/ns-util/src/local-storage/equinox').MarketList>}
217
- * @public
218
- */
219
- getEquinoxEnabledMarkets: async function () {
220
- try {
221
- const env = getEnvironmentFromUrl(window.location.origin);
222
- const variables = { uid: 'blt5633ff9e560f14ef' }
223
- const query = `query EquinoxMarketsByUid($uid: String!) {
224
- equinox_markets(uid: $uid) {
225
- ${env}_markets {
226
- market_name
227
- country_code
228
- store_id
229
- }
230
- }
231
- }`;
232
-
233
- const { data } = await contentStackHttp({
234
- method: 'post',
235
- data: { variables, query }
236
- });
237
-
238
- return data.equinox_markets[`${env}_markets`];
239
- } catch (error) {
240
- console.error(error);
232
+ switchStatusFromEquinox: function (status) {
233
+ let newStatus = '';
234
+ switch (status) {
235
+ case 'Sellable':
236
+ newStatus = 'RELEASED_FOR_SALE';
237
+ break;
238
+ case 'Preview product':
239
+ newStatus = 'NOT_RELEASED_FOR_SALE';
240
+ break;
241
+ case 'Discontinued':
242
+ newStatus = 'DISCONTINUED';
243
+ break;
244
+ case 'Stopped':
245
+ newStatus = 'DISCONTINUED';
246
+ break;
247
+ case 'Replacement':
248
+ newStatus = 'NOT_RELEASED_FOR_SALE';
249
+ break;
250
+ default:
251
+ newStatus = 'RELEASED_FOR_SALE'
252
+ break;
241
253
  }
242
- }
243
- }
244
-
245
- /**
246
- * Contentstack HTTP - axios wrapper for contentstack request
247
- *
248
- * @typedef EquinoxEnabledMarket
249
- * @property {string} market_name
250
- * @property {string} country_code
251
- * @property {string} store_id
252
- *
253
- * @typedef EquinoxEnabledMarkets
254
- * @property {EquinoxEnabledMarket[]} [dev_markets]
255
- * @property {EquinoxEnabledMarket[]} [test_markets]
256
- * @property {EquinoxEnabledMarket[]} [staging_markets]
257
- * @property {EquinoxEnabledMarket[]} [prod_markets]
258
- *
259
- * @typedef EquinoxEnvironmentEnabledMarkets
260
- * @property {EquinoxEnabledMarkets} equinox_markets
261
- *
262
- * @typedef EquinoxEnabledMarketsResponse
263
- * @property {EquinoxEnvironmentEnabledMarkets} data
264
- *
265
- * @param {Object} config - required param
266
- * @return {Promise<EquinoxEnabledMarketsResponse>} Promise that resolves to market_list_eq object
267
- */
268
- async function contentStackHttp(config) {
269
- const defaultUrl = `${CS_BASE_URL}/stacks/${CS_API_KEY}?environment=${CS_DEFAULT_ENV}`;
254
+ return newStatus;
255
+ },
270
256
 
271
- config.method = config.method || 'get'
272
- config.url = config.url || defaultUrl
273
- config.headers = {
274
- 'access_token': `${CS_DELIVERY_TOKEN}`,
275
- 'Content-Type': 'application/json'
276
- }
277
- try {
278
- const response = await axios(config);
279
- return response.data
280
- } catch (error) {
281
- console.error(error.response.data.errors);
257
+ /**
258
+ *
259
+ * @param {*} custType
260
+ *
261
+ */
262
+ switchCustType: function (custType) {
263
+ let newCustType = [];
264
+ if (custType.includes('Brand Affiliate - Business Entity') || custType.includes('Brand Affiliate - Individual'))
265
+ newCustType.push(10)
266
+ if (custType.includes('Retail Customer'))
267
+ newCustType.push(20)
268
+ if (custType.includes('Preferred Customer/Member'))
269
+ newCustType.push(30)
270
+ return newCustType.toString()
282
271
  }
283
272
  }
284
273