@nuskin/ns-product-lib 1.6.0-cx24-2382.1 → 1.6.0-cx24-2245.2
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 +9 -2
- package/package.json +2 -2
- package/src/productData.js +10 -90
package/CHANGELOG.md
CHANGED
@@ -1,9 +1,16 @@
|
|
1
|
-
# [1.6.0-cx24-
|
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)
|
2
|
+
|
3
|
+
|
4
|
+
### Update
|
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))
|
7
|
+
|
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)
|
2
9
|
|
3
10
|
|
4
11
|
### New
|
5
12
|
|
6
|
-
*
|
13
|
+
* Consume MySite Kong URL ([e8f18dc](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/e8f18dc4e42f316f1c452949ba9fc8167c4ab1f4))
|
7
14
|
|
8
15
|
# [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
16
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nuskin/ns-product-lib",
|
3
|
-
"version": "1.6.0-cx24-
|
3
|
+
"version": "1.6.0-cx24-2245.2",
|
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.
|
33
|
+
"@nuskin/ns-util": "3.105.0",
|
34
34
|
"axios": "0.27.2",
|
35
35
|
"qs": "6.11.0"
|
36
36
|
},
|
package/src/productData.js
CHANGED
@@ -1,34 +1,25 @@
|
|
1
1
|
"use strict";
|
2
|
-
const
|
3
|
-
const
|
4
|
-
const product = require("./product");
|
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
|
-
|
2
|
+
const axios = require("axios");
|
3
|
+
const product = require("./product")
|
11
4
|
/** @type {*} */
|
12
5
|
const ProductData = {
|
13
6
|
/**
|
14
7
|
* @param {*} skus
|
15
8
|
* @param {*} runConfig
|
16
9
|
* @param {*} marketConfig
|
17
|
-
* @param {boolean}
|
10
|
+
* @param {{ isEnabled: boolean, storeID: string }} equinoxOptions
|
18
11
|
*/
|
19
|
-
getProductData: async function (skus, runConfig, marketConfig,
|
12
|
+
getProductData: async function (skus, runConfig, marketConfig, equinoxOptions) {
|
20
13
|
const locale = `${runConfig.language}_${runConfig.country}`;
|
21
|
-
const enabledMarkets = await this.getEquinoxEnabledMarkets();
|
22
|
-
console.log(enabledMarkets);
|
23
14
|
|
24
|
-
if (
|
25
|
-
return await this.getProductFromEquinox(skus, locale, marketConfig,
|
15
|
+
if (equinoxOptions !== undefined && equinoxOptions.isEnabled === true) {
|
16
|
+
return await this.getProductFromEquinox(skus, locale, marketConfig, equinoxOptions.storeID);
|
26
17
|
}
|
27
18
|
|
28
19
|
return await this.getProductFromLegacy(skus, locale, marketConfig);
|
29
20
|
},
|
30
21
|
|
31
|
-
getProductFromEquinox: async function
|
22
|
+
getProductFromEquinox: async function(skus, locale, marketConfig, storeID) {
|
32
23
|
const filter = `{
|
33
24
|
"filters": [{
|
34
25
|
"field": "index_key_skuId",
|
@@ -39,7 +30,7 @@ const ProductData = {
|
|
39
30
|
axios.defaults.withCredentials = true;
|
40
31
|
const productDataResponse = await axios.request({
|
41
32
|
method: 'get',
|
42
|
-
url: `https
|
33
|
+
url: `https://${marketConfig.mySiteKongURL}/orchestrationservices/storefront/catalogs/search/`,
|
43
34
|
params: {
|
44
35
|
locale,
|
45
36
|
storeId: storeID,
|
@@ -52,7 +43,7 @@ const ProductData = {
|
|
52
43
|
return this.eqProductMapper(productDataResponse.data.product);
|
53
44
|
},
|
54
45
|
|
55
|
-
getProductFromLegacy: async function
|
46
|
+
getProductFromLegacy: async function(skus, locale, marketConfig) {
|
56
47
|
const lambdaUrl = `${marketConfig.awsUrl}/productData/v1`;
|
57
48
|
const payload = { locale, skus };
|
58
49
|
|
@@ -75,7 +66,7 @@ const ProductData = {
|
|
75
66
|
let count = 0;
|
76
67
|
productDataResponse.forEach((data, index) => {
|
77
68
|
count++
|
78
|
-
|
69
|
+
|
79
70
|
prod = {
|
80
71
|
"sku": data.sku[0].identifier,
|
81
72
|
"globalProductID": data.identifier,
|
@@ -208,77 +199,6 @@ const ProductData = {
|
|
208
199
|
client_id: marketConfig.checkout.clientId,
|
209
200
|
client_secret: marketConfig.checkout.clientSecret
|
210
201
|
};
|
211
|
-
},
|
212
|
-
|
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);
|
241
|
-
}
|
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}`;
|
270
|
-
|
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);
|
282
202
|
}
|
283
203
|
}
|
284
204
|
|