@nuskin/ns-product-lib 2.2.0-cx24-2467.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +4 -3
- package/package.json +2 -2
- package/src/contentstack/contentstack.js +35 -3
- package/src/productData.js +21 -26
package/CHANGELOG.md
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
# [2.2.0
|
1
|
+
# [2.2.0](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.1.0...v2.2.0) (2022-10-13)
|
2
2
|
|
3
3
|
|
4
|
-
###
|
4
|
+
### Update
|
5
5
|
|
6
|
-
*
|
6
|
+
* Get Kong URL from contentstack (CX24-2447) ([272b35a](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/272b35a63908267e3c004ef43cbc2ecf0452a907))
|
7
|
+
* redirect to equinox sign-in if the market is equinox-enabled (CX24-2092) ([ffff6e2](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/ffff6e21c0c6e72e0e3e42583dd443d7a0227bea))
|
7
8
|
|
8
9
|
# [2.1.0](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.0.1...v2.1.0) (2022-10-04)
|
9
10
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nuskin/ns-product-lib",
|
3
|
-
"version": "2.2.0
|
3
|
+
"version": "2.2.0",
|
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": {
|
@@ -29,7 +29,7 @@
|
|
29
29
|
"prettier": "1.19.1"
|
30
30
|
},
|
31
31
|
"dependencies": {
|
32
|
-
"@nuskin/ns-common-lib": "1.
|
32
|
+
"@nuskin/ns-common-lib": "1.4.5",
|
33
33
|
"@nuskin/ns-util": "3.107.0",
|
34
34
|
"axios": "0.27.2",
|
35
35
|
"qs": "6.11.0"
|
@@ -14,11 +14,12 @@ const headers = {
|
|
14
14
|
const http = axios.create({ baseURL, headers });
|
15
15
|
|
16
16
|
// in-memory caching
|
17
|
-
const cacheKeys = { aemConfig: 'aemConfig', equinoxMarkets: 'equinoxMarkets' };
|
17
|
+
const cacheKeys = { aemConfig: 'aemConfig', equinoxMarkets: 'equinoxMarkets', kongUrl: 'kongUrl' };
|
18
18
|
const cacheTTLInSeconds = 30 * 1000;
|
19
19
|
const cache = {
|
20
20
|
[cacheKeys.aemConfig]: { data: null, ttl: Date.now() + cacheTTLInSeconds },
|
21
|
-
[cacheKeys.equinoxMarkets]: { data: null, ttl: Date.now() + cacheTTLInSeconds }
|
21
|
+
[cacheKeys.equinoxMarkets]: { data: null, ttl: Date.now() + cacheTTLInSeconds },
|
22
|
+
[cacheKeys.kongUrl]: { data: null, ttl: Date.now() + cacheTTLInSeconds}
|
22
23
|
};
|
23
24
|
|
24
25
|
/**
|
@@ -139,6 +140,36 @@ async function getEquinoxMarkets() {
|
|
139
140
|
}
|
140
141
|
}
|
141
142
|
|
143
|
+
/**getKongUrl gets the URL for Kong in contentstack
|
144
|
+
*
|
145
|
+
* @returns {string}
|
146
|
+
*/
|
147
|
+
async function getKongUrl() {
|
148
|
+
try {
|
149
|
+
if (isCacheExpired(cacheKeys.kongUrl)) {
|
150
|
+
const variables = { uid: 'blt5633ff9e560f14ef' };
|
151
|
+
const query = `query KongUrlByUid($uid: String!) {
|
152
|
+
equinox_markets(uid: $uid) {
|
153
|
+
kong_urls {
|
154
|
+
${env}
|
155
|
+
}
|
156
|
+
}
|
157
|
+
}`;
|
158
|
+
|
159
|
+
const { data } = await contentstackService({
|
160
|
+
data: { variables, query }
|
161
|
+
});
|
162
|
+
|
163
|
+
setCachedData(cacheKeys.kongUrl, data.equinox_markets.kong_urls[env]);
|
164
|
+
}
|
165
|
+
|
166
|
+
return getCachedData(cacheKeys.kongUrl);
|
167
|
+
} catch (error) {
|
168
|
+
console.error(error);
|
169
|
+
return [];
|
170
|
+
}
|
171
|
+
}
|
172
|
+
|
142
173
|
/**
|
143
174
|
* isMarketEnabled checks is the given market is in the list
|
144
175
|
* of equinox-enabled markets.
|
@@ -177,5 +208,6 @@ async function contentstackService(config) {
|
|
177
208
|
module.exports = {
|
178
209
|
getAEMConfig,
|
179
210
|
getEquinoxMarkets,
|
180
|
-
isMarketEnabled
|
211
|
+
isMarketEnabled,
|
212
|
+
getKongUrl
|
181
213
|
}
|
package/src/productData.js
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
"use strict";
|
2
2
|
const axios = require("axios");
|
3
3
|
const contentstack = require('./contentstack/contentstack');
|
4
|
-
const
|
4
|
+
const product = require("./product");
|
5
5
|
|
6
6
|
/** @type {*} */
|
7
7
|
const ProductData = {
|
8
8
|
/**
|
9
|
-
* @param {string[]} skus
|
10
|
-
* @param {string} locale
|
11
|
-
* @param {string} market
|
12
|
-
* @param {boolean} isEquinoxEnabled
|
9
|
+
* @param {string[]} skus
|
10
|
+
* @param {string} locale
|
11
|
+
* @param {string} market
|
12
|
+
* @param {boolean} isEquinoxEnabled
|
13
13
|
*/
|
14
14
|
getProductData: async function (skus, locale, market, isEquinoxEnabled = false) {
|
15
15
|
const localeMarket = `${locale}_${market}`;
|
@@ -28,7 +28,9 @@ const ProductData = {
|
|
28
28
|
getProductFromEquinox: async function (skus, locale, storeID) {
|
29
29
|
const filter = '{"filters":[{"field":"index_key_skuId","operation":"IN","value":"' + skus.toString() + '"}]}';
|
30
30
|
axios.defaults.withCredentials = true;
|
31
|
-
|
31
|
+
|
32
|
+
const url = await contentstack.getKongUrl() + `/orchestrationservices/storefront/catalogs/search/`;
|
33
|
+
console.log("Dynamic URL", url)
|
32
34
|
const href = `${url}?filter=${encodeURI(filter)}`;
|
33
35
|
const response = await axios.request({
|
34
36
|
method: 'get',
|
@@ -76,7 +78,7 @@ const ProductData = {
|
|
76
78
|
responseType: 'json'
|
77
79
|
});
|
78
80
|
},
|
79
|
-
|
81
|
+
|
80
82
|
/**
|
81
83
|
* @param {contentstack.MarketConfig} marketConfig
|
82
84
|
*/
|
@@ -90,26 +92,18 @@ const ProductData = {
|
|
90
92
|
|
91
93
|
eqProductMapper: function (productDataResponse) {
|
92
94
|
let prod = [];
|
93
|
-
|
95
|
+
let count = 0;
|
94
96
|
|
95
|
-
let prodArr = productDataResponse.map((data
|
97
|
+
let prodArr = productDataResponse.map((data) => {
|
96
98
|
let imageURL = data.sku[count].properties.imageURL;
|
97
99
|
const regex = /\d+.\d+/
|
98
100
|
let thumbnailImage = ''
|
99
|
-
|
101
|
+
|
100
102
|
if (imageURL.includes('contentstack')) {
|
101
103
|
thumbnailImage = imageURL + '?width=40'
|
102
104
|
} else {
|
103
105
|
thumbnailImage = imageURL.replace(regex,'40.40')
|
104
106
|
}
|
105
|
-
|
106
|
-
if (data.sku && data.sku.length > 1) {
|
107
|
-
data.sku.map(variant => {
|
108
|
-
variants.push(variant);
|
109
|
-
return variant;
|
110
|
-
});
|
111
|
-
}
|
112
|
-
|
113
107
|
prod = {
|
114
108
|
"sku": data.sku[count].identifier,
|
115
109
|
"globalProductID": data.identifier,
|
@@ -203,9 +197,10 @@ const ProductData = {
|
|
203
197
|
"eventName": null,
|
204
198
|
"sizeWeight": '',
|
205
199
|
"nettoWeight": "",
|
206
|
-
"variants":
|
200
|
+
"variants": {
|
201
|
+
},
|
207
202
|
"searchScore": 0,
|
208
|
-
"isExclusive":
|
203
|
+
"isExclusive": data.sku[count].properties.isExclusive,
|
209
204
|
"marketAttributes": {
|
210
205
|
"discount": true,
|
211
206
|
"redeem": true,
|
@@ -214,7 +209,7 @@ const ProductData = {
|
|
214
209
|
"restrictedMarkets": [],
|
215
210
|
"addOns": []
|
216
211
|
};
|
217
|
-
let newProduct = new
|
212
|
+
let newProduct = new product(prod);
|
218
213
|
return newProduct
|
219
214
|
})
|
220
215
|
|
@@ -250,20 +245,20 @@ const ProductData = {
|
|
250
245
|
newStatus = 'NOT_RELEASED_FOR_SALE';
|
251
246
|
break;
|
252
247
|
default:
|
253
|
-
newStatus = '
|
248
|
+
newStatus = 'NOT_RELEASED_FOR_SALE'
|
254
249
|
break;
|
255
250
|
}
|
256
251
|
return newStatus;
|
257
252
|
},
|
258
253
|
|
259
254
|
/**
|
260
|
-
*
|
261
|
-
* @param {*} custType
|
262
|
-
*
|
255
|
+
*
|
256
|
+
* @param {*} custType
|
257
|
+
*
|
263
258
|
*/
|
264
259
|
switchCustType: function (custType) {
|
265
260
|
let newCustType = [];
|
266
|
-
if (custType.includes('Brand Affiliate - Business Entity') || custType.includes('Brand Affiliate - Individual'))
|
261
|
+
if (custType.includes('Brand Affiliate - Business Entity') || custType.includes('Brand Affiliate - Individual'))
|
267
262
|
newCustType.push(10)
|
268
263
|
if (custType.includes('Retail Customer'))
|
269
264
|
newCustType.push(20)
|