@nuskin/ns-product-lib 2.4.1-cx24-2612.1 → 2.5.0-fix.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +28 -3
- package/package.json +4 -3
- package/src/contentstack/contentstack.js +52 -14
- package/src/productData.js +4 -24
package/CHANGELOG.md
CHANGED
@@ -1,12 +1,21 @@
|
|
1
|
-
|
1
|
+
# [2.5.0-fix.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.4.0...v2.5.0-fix.1) (2022-11-04)
|
2
2
|
|
3
3
|
|
4
4
|
### Fix
|
5
5
|
|
6
|
-
*
|
7
|
-
|
6
|
+
* use platform-specific values when initialized ([04d9c5e](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/04d9c5eb555b6a8304329ac63f1304dd61e5ecd2))
|
7
|
+
|
8
|
+
### New
|
9
|
+
|
10
|
+
* added support for inventory label (#CX24-2186) ([78e9385](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/78e9385432b6c8245061a450021fe9dd9da9b840)), closes [#CX24-2186](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2186)
|
11
|
+
|
12
|
+
### Release
|
13
|
+
|
14
|
+
* Automated changes by GitLab pipeline [skip ci] ([78b03b1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/78b03b1c22a09c29c39b926696f2e2141a1ecd1e))
|
8
15
|
|
9
16
|
# [2.4.0](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.3.0...v2.4.0) (2022-10-26)
|
17
|
+
## [2.3.1-fix.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.3.0...v2.3.1-fix.1) (2022-11-04)
|
18
|
+
# [2.4.0](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.3.0...v2.4.0) (2022-10-26)
|
10
19
|
|
11
20
|
|
12
21
|
### Fix
|
@@ -24,6 +33,22 @@
|
|
24
33
|
|
25
34
|
### Update
|
26
35
|
|
36
|
+
* added support for variant and price (#CX24-2186) ([e0bf8f2](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/e0bf8f280a838dfa4cc613e5bc34d254dbdc8e1a)), closes [#CX24-2186](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2186)
|
37
|
+
* added variant label (#CX24-2186) ([4c223b3](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/4c223b34438ed73cb824716cacb93482486f8195)), closes [#CX24-2186](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2186)
|
38
|
+
* use platform-specific values when initialized ([18de006](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/18de006211ab396f4d7fa40d0089c8e185d9cee9))
|
39
|
+
* To make multiple products work (#CX24-2444) ([ce4c483](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/ce4c483b7fbb0527e60045d8174fd503a67e63fa)), closes [#CX24-2444](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2444)
|
40
|
+
|
41
|
+
### New
|
42
|
+
|
43
|
+
* added support for inventory label (#CX24-2186) ([3e27481](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/3e2748106cd6098086dbd6b738964deabacc875d)), closes [#CX24-2186](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2186)
|
44
|
+
|
45
|
+
### Release
|
46
|
+
|
47
|
+
* Automated changes by GitLab pipeline [skip ci] ([8f75316](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/8f75316b692ddccda5b7bea830ee6dc625b942c7))
|
48
|
+
* Automated changes by GitLab pipeline [skip ci] ([36dca5b](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/36dca5b92285ae6d8ae96345256df92102efad8e))
|
49
|
+
|
50
|
+
### Update
|
51
|
+
|
27
52
|
* added support for variant and price (#CX24-2186) ([e0bf8f2](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/e0bf8f280a838dfa4cc613e5bc34d254dbdc8e1a)), closes [#CX24-2186](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2186)
|
28
53
|
* added variant label (#CX24-2186) ([4c223b3](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/4c223b34438ed73cb824716cacb93482486f8195)), closes [#CX24-2186](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2186)
|
29
54
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nuskin/ns-product-lib",
|
3
|
-
"version": "2.
|
3
|
+
"version": "2.5.0-fix.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": {
|
@@ -19,13 +19,14 @@
|
|
19
19
|
"license": "ISC",
|
20
20
|
"homepage": "https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/blob/master/README.md",
|
21
21
|
"devDependencies": {
|
22
|
+
"axios-mock-adapter": "1.21.2",
|
22
23
|
"eslint": "5.16.0",
|
23
24
|
"eslint-config-google": "0.14.0",
|
24
25
|
"eslint-config-prettier": "4.1.0",
|
25
26
|
"eslint-plugin-json": "2.1.1",
|
26
27
|
"eslint-plugin-prettier": "3.1.2",
|
27
|
-
"
|
28
|
-
"jest": "
|
28
|
+
"jest": "29.2.2",
|
29
|
+
"jest-environment-jsdom": "29.2.2",
|
29
30
|
"jest-sonar-reporter": "2.0.0",
|
30
31
|
"prettier": "1.19.1"
|
31
32
|
},
|
@@ -4,14 +4,51 @@ const { getEnvironmentFromUrl } = require('@nuskin/ns-common-lib');
|
|
4
4
|
const config = require('./environment');
|
5
5
|
|
6
6
|
// contentstack HTTP service
|
7
|
-
const
|
8
|
-
const
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
'
|
13
|
-
|
14
|
-
|
7
|
+
const platform = usePlatformSpecificVariables();
|
8
|
+
const http = axios.create({ baseURL: platform.baseURL, headers: platform.headers });
|
9
|
+
|
10
|
+
// usePlatformVariables returns an object with platform-specific values; defaults to Lambda environment
|
11
|
+
function usePlatformSpecificVariables() {
|
12
|
+
if (typeof window !== 'undefined') {
|
13
|
+
return useWebEnvironment();
|
14
|
+
}
|
15
|
+
|
16
|
+
if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
|
17
|
+
return useMobileEnvironment();
|
18
|
+
}
|
19
|
+
|
20
|
+
return useLambdaEnvironment();
|
21
|
+
}
|
22
|
+
|
23
|
+
function useWebEnvironment() {
|
24
|
+
console.log('web');
|
25
|
+
const env = getEnvironmentFromUrl(window.location.host);
|
26
|
+
const envConfig = config.getCredentials(env);
|
27
|
+
const baseURL = `${envConfig.url}/stacks/${envConfig.apiKey}?environment=${envConfig.env}`;
|
28
|
+
const headers = {
|
29
|
+
'access_token': `${envConfig.accessToken}`,
|
30
|
+
'Content-Type': 'application/json'
|
31
|
+
};
|
32
|
+
|
33
|
+
return { baseURL, env, headers }
|
34
|
+
}
|
35
|
+
|
36
|
+
function useMobileEnvironment() {
|
37
|
+
// ...
|
38
|
+
}
|
39
|
+
|
40
|
+
function useLambdaEnvironment() {
|
41
|
+
console.log('lambda');
|
42
|
+
const env = {};
|
43
|
+
const baseURL = `contentstack-call-for-lambda`;
|
44
|
+
const headers = {
|
45
|
+
'access_token': `contentstack-access-token-for-lambda`,
|
46
|
+
'Content-Type': 'application/json'
|
47
|
+
};
|
48
|
+
|
49
|
+
return { baseURL, env, headers }
|
50
|
+
}
|
51
|
+
|
15
52
|
|
16
53
|
// in-memory caching
|
17
54
|
const cacheKeys = { aemConfig: 'aemConfig', equinoxMarkets: 'equinoxMarkets', kongUrl: 'kongUrl' };
|
@@ -19,7 +56,7 @@ const cacheTTLInSeconds = 30 * 1000;
|
|
19
56
|
const cache = {
|
20
57
|
[cacheKeys.aemConfig]: { data: null, ttl: Date.now() + cacheTTLInSeconds },
|
21
58
|
[cacheKeys.equinoxMarkets]: { data: null, ttl: Date.now() + cacheTTLInSeconds },
|
22
|
-
[cacheKeys.kongUrl]: { data: null, ttl: Date.now() + cacheTTLInSeconds}
|
59
|
+
[cacheKeys.kongUrl]: { data: null, ttl: Date.now() + cacheTTLInSeconds }
|
23
60
|
};
|
24
61
|
|
25
62
|
/**
|
@@ -67,7 +104,7 @@ function getCachedData(key) {
|
|
67
104
|
async function getAEMConfig() {
|
68
105
|
try {
|
69
106
|
if (isCacheExpired(cacheKeys.aemConfig)) {
|
70
|
-
const marketConfig = `market_config_${env}`;
|
107
|
+
const marketConfig = `market_config_${platform.env}`;
|
71
108
|
const variables = { uid: 'blt52b0b83a89763791' };
|
72
109
|
const query = `query AemConfigByUid($uid: String!) {
|
73
110
|
aem_config(uid: $uid) {
|
@@ -114,7 +151,7 @@ async function getAEMConfig() {
|
|
114
151
|
async function getEquinoxMarkets() {
|
115
152
|
try {
|
116
153
|
if (isCacheExpired(cacheKeys.equinoxMarkets)) {
|
117
|
-
const marketConfig = `${env}_markets`;
|
154
|
+
const marketConfig = `${platform.env}_markets`;
|
118
155
|
const variables = { uid: 'blt5633ff9e560f14ef' };
|
119
156
|
const query = `query EquinoxMarketsByUid($uid: String!) {
|
120
157
|
equinox_markets(uid: $uid) {
|
@@ -151,7 +188,7 @@ async function getKongUrl() {
|
|
151
188
|
const query = `query KongUrlByUid($uid: String!) {
|
152
189
|
equinox_markets(uid: $uid) {
|
153
190
|
kong_urls {
|
154
|
-
${env}
|
191
|
+
${platform.env}
|
155
192
|
}
|
156
193
|
}
|
157
194
|
}`;
|
@@ -160,9 +197,9 @@ async function getKongUrl() {
|
|
160
197
|
data: { variables, query }
|
161
198
|
});
|
162
199
|
|
163
|
-
setCachedData(cacheKeys.kongUrl, data.equinox_markets.kong_urls[env]);
|
200
|
+
setCachedData(cacheKeys.kongUrl, data.equinox_markets.kong_urls[platform.env]);
|
164
201
|
}
|
165
|
-
|
202
|
+
|
166
203
|
return getCachedData(cacheKeys.kongUrl);
|
167
204
|
} catch (error) {
|
168
205
|
console.error(error);
|
@@ -199,6 +236,7 @@ async function contentstackService(config) {
|
|
199
236
|
|
200
237
|
try {
|
201
238
|
const response = await http.post('', data);
|
239
|
+
console.log(response);
|
202
240
|
return response.data
|
203
241
|
} catch (error) {
|
204
242
|
console.error(error.response.data.errors);
|
package/src/productData.js
CHANGED
@@ -43,7 +43,7 @@ const ProductData = {
|
|
43
43
|
});
|
44
44
|
|
45
45
|
if (response.data.product) {
|
46
|
-
return this.eqProductMapper(response.data.product
|
46
|
+
return this.eqProductMapper(response.data.product);
|
47
47
|
}
|
48
48
|
|
49
49
|
return {
|
@@ -210,7 +210,7 @@ const ProductData = {
|
|
210
210
|
};
|
211
211
|
},
|
212
212
|
|
213
|
-
eqProductMapper: function (productDataResponse
|
213
|
+
eqProductMapper: function (productDataResponse) {
|
214
214
|
let prod = [];
|
215
215
|
let count = 0;
|
216
216
|
let variants = {};
|
@@ -336,7 +336,7 @@ const ProductData = {
|
|
336
336
|
},
|
337
337
|
"restrictedMarkets": [],
|
338
338
|
"addOns": [],
|
339
|
-
"
|
339
|
+
"inventoryLabel": data.sku[count].inventory || ""
|
340
340
|
|
341
341
|
};
|
342
342
|
let newProduct = new Product(prod);
|
@@ -344,7 +344,7 @@ const ProductData = {
|
|
344
344
|
})
|
345
345
|
|
346
346
|
let data = {
|
347
|
-
products:
|
347
|
+
products: prodArr,
|
348
348
|
count: productDataResponse.length
|
349
349
|
};
|
350
350
|
return {
|
@@ -395,26 +395,6 @@ const ProductData = {
|
|
395
395
|
if (custType.includes('Preferred Customer/Member'))
|
396
396
|
newCustType.push(30)
|
397
397
|
return newCustType.toString()
|
398
|
-
},
|
399
|
-
|
400
|
-
/**
|
401
|
-
* Sorts the product by sku
|
402
|
-
* @param {Array} skus - the skus arrangment which the sorting will base out of
|
403
|
-
* @param {Array} products - this products to be sorted
|
404
|
-
*/
|
405
|
-
|
406
|
-
_sortProductsBySku: function (skus, products) {
|
407
|
-
|
408
|
-
if(!skus || !products || products.length === 1) {
|
409
|
-
return products
|
410
|
-
}
|
411
|
-
|
412
|
-
const sortedProducts = products.sort(function (a, b) {
|
413
|
-
return skus.indexOf(a.sku) - skus.indexOf(b.sku);
|
414
|
-
});
|
415
|
-
|
416
|
-
return sortedProducts
|
417
|
-
|
418
398
|
}
|
419
399
|
}
|
420
400
|
|