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