@nuskin/ns-product-lib 1.6.0-cx24-2245.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 +97 -2
- package/package.json +2 -2
- package/src/contentstack/contentstack.js +181 -0
- package/src/contentstack/environment.js +41 -0
- package/src/index.js +2 -0
- package/src/productData.js +144 -75
package/CHANGELOG.md
CHANGED
@@ -1,9 +1,104 @@
|
|
1
|
-
# [
|
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
|
+
|
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
|
|
4
99
|
### New
|
5
100
|
|
6
|
-
*
|
101
|
+
* query equinox-enabled markets (CX24-2382) ([1fcd191](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/1fcd191d654b5ad39603140e80dddd06ab7d0056))
|
7
102
|
|
8
103
|
# [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)
|
9
104
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nuskin/ns-product-lib",
|
3
|
-
"version": "
|
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.105
|
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,
|
package/src/productData.js
CHANGED
@@ -1,81 +1,119 @@
|
|
1
1
|
"use strict";
|
2
|
-
const
|
3
|
-
const
|
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
|
-
* @param {
|
8
|
-
* @param {
|
9
|
-
* @param {
|
10
|
-
* @param {
|
9
|
+
* @param {string[]} skus
|
10
|
+
* @param {string} locale
|
11
|
+
* @param {string} market
|
12
|
+
* @param {boolean} isEquinoxEnabled
|
11
13
|
*/
|
12
|
-
getProductData: async function (skus,
|
13
|
-
const
|
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);
|
14
19
|
|
15
|
-
|
16
|
-
|
20
|
+
if (marketConfig !== null) {
|
21
|
+
return await this.getProductFromEquinox(skus, localeMarket, marketConfig.store_id);
|
22
|
+
}
|
17
23
|
}
|
18
24
|
|
19
|
-
return await this.getProductFromLegacy(skus,
|
25
|
+
return await this.getProductFromLegacy(skus, localeMarket);
|
20
26
|
},
|
21
27
|
|
22
|
-
getProductFromEquinox: async function(skus, locale,
|
23
|
-
const filter =
|
24
|
-
"filters": [{
|
25
|
-
"field": "index_key_skuId",
|
26
|
-
"operation": "IN",
|
27
|
-
"value": "${skus.toString()}"
|
28
|
-
}]
|
29
|
-
}`;
|
28
|
+
getProductFromEquinox: async function (skus, locale, storeID) {
|
29
|
+
const filter = '{"filters":[{"field":"index_key_skuId","operation":"IN","value":"' + skus.toString() + '"}]}';
|
30
30
|
axios.defaults.withCredentials = true;
|
31
|
-
const
|
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({
|
32
34
|
method: 'get',
|
33
|
-
url:
|
35
|
+
url: href,
|
34
36
|
params: {
|
35
37
|
locale,
|
36
|
-
storeId: storeID
|
37
|
-
filter
|
38
|
+
storeId: storeID
|
38
39
|
},
|
39
|
-
headers: this.
|
40
|
-
responseType:
|
40
|
+
headers: this.getEquinoxRequestHeaders(),
|
41
|
+
responseType: 'json'
|
41
42
|
});
|
42
43
|
|
43
|
-
|
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
|
+
}
|
44
53
|
},
|
45
54
|
|
46
|
-
|
47
|
-
|
55
|
+
getEquinoxRequestHeaders() {
|
56
|
+
return {
|
57
|
+
'Content-Type': 'application/json'
|
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:
|
72
|
+
method: 'post',
|
52
73
|
url: lambdaUrl,
|
53
74
|
data: payload,
|
54
|
-
headers: this.
|
55
|
-
responseType:
|
75
|
+
headers: this.getLegacyRequestHeaders(marketConfig),
|
76
|
+
responseType: 'json'
|
56
77
|
});
|
57
78
|
},
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
|
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
|
+
}
|
70
108
|
prod = {
|
71
|
-
"sku": data.sku[
|
109
|
+
"sku": data.sku[count].identifier,
|
72
110
|
"globalProductID": data.identifier,
|
73
111
|
"title": data.properties.name,
|
74
|
-
"country": data.sku[
|
112
|
+
"country": data.sku[count].properties.market,
|
75
113
|
"language": "en",
|
76
114
|
"shortDescr": data.properties.description,
|
77
115
|
"longDescr": data.properties.productDetailsDescription,
|
78
|
-
"fullImage":
|
116
|
+
"fullImage": imageURL,
|
79
117
|
"imageAltText": data.properties.name,
|
80
118
|
"productCarouselImages": [
|
81
119
|
{
|
@@ -84,11 +122,11 @@ const ProductData = {
|
|
84
122
|
"alt": ""
|
85
123
|
}
|
86
124
|
],
|
87
|
-
"thumbnail":
|
88
|
-
"ingredients":
|
89
|
-
"benefits":
|
90
|
-
"usage":
|
91
|
-
"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,
|
92
130
|
"videos": "",
|
93
131
|
"movie": "",
|
94
132
|
"youtube": "",
|
@@ -102,28 +140,28 @@ const ProductData = {
|
|
102
140
|
"availableQuantity": 999,
|
103
141
|
"maxQuantity": 999,
|
104
142
|
"points": "",
|
105
|
-
"cv":
|
106
|
-
"pv":
|
143
|
+
"cv": (data.sku[count].priceFacets.CV) ? data.sku[count].priceFacets.CV : '',
|
144
|
+
"pv": data.sku[count].priceFacets.PV,
|
107
145
|
"priceType": "WRTL",
|
108
|
-
"price":
|
146
|
+
"price": data.sku[count].priceFacets["Regular Price"],
|
109
147
|
"priceMap": {
|
110
|
-
"WRTL":
|
111
|
-
"WADW-WRTL":
|
148
|
+
"WRTL": data.sku[count].priceFacets["Regular Price"],
|
149
|
+
"WADW-WRTL": data.sku[count].priceFacets["Regular Price"],
|
112
150
|
"WADR": 9999.01,
|
113
|
-
"RTL":
|
151
|
+
"RTL": data.sku[count].priceFacets["Regular Price"],
|
114
152
|
"WWHL": 9998.01,
|
115
153
|
"WADW": 9998.01,
|
116
154
|
"WHL": 9998.01
|
117
155
|
},
|
118
156
|
"cvMap": {
|
119
|
-
"WWHL":
|
120
|
-
"WADW":
|
121
|
-
"WHL":
|
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 : ''
|
122
160
|
},
|
123
161
|
"pvMap": {
|
124
|
-
"WWHL":
|
125
|
-
"WADW":
|
126
|
-
"WHL":
|
162
|
+
"WWHL": data.sku[count].priceFacets.PV,
|
163
|
+
"WADW": data.sku[count].priceFacets.PV,
|
164
|
+
"WHL": data.sku[count].priceFacets.PV
|
127
165
|
},
|
128
166
|
"orderTypes": {
|
129
167
|
"adr": true,
|
@@ -139,28 +177,26 @@ const ProductData = {
|
|
139
177
|
"web display": true
|
140
178
|
},
|
141
179
|
"childSkus": [],
|
142
|
-
"custTypes":
|
143
|
-
|
144
|
-
],
|
145
|
-
"division": "",
|
180
|
+
"custTypes": this.switchCustType(data.properties.customerTypes),
|
181
|
+
"division": data.properties.division,
|
146
182
|
"backOrderDate": null,
|
147
183
|
"locallyProduced": false,
|
148
184
|
"agelocme": null,
|
149
185
|
"count": "",
|
150
186
|
"flavor": "",
|
151
|
-
"size":
|
187
|
+
"size": data.sku[count].properties.size,
|
152
188
|
"shade": "",
|
153
|
-
"status":
|
154
|
-
"variantType": "",
|
155
|
-
"variantDropdownLabel": "",
|
156
|
-
"variantDropdownPlaceholder": "",
|
157
|
-
"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",
|
158
194
|
"groupOffer": false,
|
159
195
|
"personalOffer": false,
|
160
196
|
"savedEventName": null,
|
161
197
|
"salesLabel": "",
|
162
198
|
"eventName": null,
|
163
|
-
"sizeWeight":
|
199
|
+
"sizeWeight": '',
|
164
200
|
"nettoWeight": "",
|
165
201
|
"variants": {
|
166
202
|
},
|
@@ -174,6 +210,7 @@ const ProductData = {
|
|
174
210
|
"restrictedMarkets": [],
|
175
211
|
"addOns": []
|
176
212
|
};
|
213
|
+
count++
|
177
214
|
let newProduct = new product(prod);
|
178
215
|
prodArr[index] = newProduct;
|
179
216
|
|
@@ -181,7 +218,7 @@ const ProductData = {
|
|
181
218
|
|
182
219
|
let data = {
|
183
220
|
products: prodArr,
|
184
|
-
count: count
|
221
|
+
count: count + 1
|
185
222
|
};
|
186
223
|
return {
|
187
224
|
data: {
|
@@ -189,16 +226,48 @@ const ProductData = {
|
|
189
226
|
"messages": [],
|
190
227
|
"data": data
|
191
228
|
}
|
192
|
-
}
|
229
|
+
};
|
230
|
+
},
|
193
231
|
|
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;
|
253
|
+
}
|
254
|
+
return newStatus;
|
194
255
|
},
|
195
256
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
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()
|
202
271
|
}
|
203
272
|
}
|
204
273
|
|