@nuskin/ns-product-lib 2.4.1-cx12-5910.1 → 2.4.1

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,11 +1,35 @@
1
- ## [2.4.1-cx12-5910.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.4.0...v2.4.1-cx12-5910.1) (2022-10-26)
1
+ ## [2.4.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.4.0...v2.4.1) (2022-11-06)
2
2
 
3
3
 
4
4
  ### Fix
5
5
 
6
- * try catch block for generating env (#CX12-5910) ([86930c3](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/86930c31a70bfe35a5136bc338ec618e04d860eb)), closes [#CX12-5910](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX12-5910)
6
+ * platform agnostic updates to ns-product-lib ([d53659f](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/d53659f20ab708b1212dd5820be9321e6d1855a5))
7
+
8
+ # [2.5.0-fix.2](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.5.0-fix.1...v2.5.0-fix.2) (2022-11-04)
9
+
10
+
11
+ ### Fix
12
+
13
+ * update inventory label to match with master ([005b52c](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/005b52cd10063d9af6975315f37d8995d630eb66))
14
+
15
+ # [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)
16
+
17
+
18
+ ### Fix
19
+
20
+ * use platform-specific values when initialized ([04d9c5e](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/04d9c5eb555b6a8304329ac63f1304dd61e5ecd2))
21
+
22
+ ### New
23
+
24
+ * 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)
25
+
26
+ ### Release
27
+
28
+ * Automated changes by GitLab pipeline [skip ci] ([78b03b1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/78b03b1c22a09c29c39b926696f2e2141a1ecd1e))
7
29
 
8
30
  # [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)
31
+ ## [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)
32
+ # [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)
9
33
 
10
34
 
11
35
  ### Fix
@@ -23,6 +47,22 @@
23
47
 
24
48
  ### Update
25
49
 
50
+ * 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)
51
+ * 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)
52
+ * use platform-specific values when initialized ([18de006](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/18de006211ab396f4d7fa40d0089c8e185d9cee9))
53
+ * 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)
54
+
55
+ ### New
56
+
57
+ * 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)
58
+
59
+ ### Release
60
+
61
+ * Automated changes by GitLab pipeline [skip ci] ([8f75316](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/8f75316b692ddccda5b7bea830ee6dc625b942c7))
62
+ * Automated changes by GitLab pipeline [skip ci] ([36dca5b](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/36dca5b92285ae6d8ae96345256df92102efad8e))
63
+
64
+ ### Update
65
+
26
66
  * 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)
27
67
  * 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)
28
68
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/ns-product-lib",
3
- "version": "2.4.1-cx12-5910.1",
3
+ "version": "2.4.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
- "axios-mock-adapter": "1.18.2",
28
- "jest": "25.1.0",
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
  },
@@ -3,26 +3,52 @@ const axios = require('axios');
3
3
  const { getEnvironmentFromUrl } = require('@nuskin/ns-common-lib');
4
4
  const config = require('./environment');
5
5
 
6
- let env = 'unknown';
7
-
8
- // ns-product-lib should be multi-platform compatible i.e. lambda, web, or react native etc.
9
- try {
10
- env = getEnvironmentFromUrl(window.location.host);
11
- } catch (error) {
12
- console.log("getting env from url not supported. window is likely unavailable:");
13
- console.log("Name: ", error.name);
14
- console.log("Message: ", error.message);
15
- console.log("Stack Trace: ", error.stack);
6
+ // contentstack HTTP service
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 }
16
50
  }
17
51
 
18
- // contentstack HTTP service
19
- const envConfig = config.getCredentials(env);
20
- const baseURL = `${envConfig.url}/stacks/${envConfig.apiKey}?environment=${envConfig.env}`;
21
- const headers = {
22
- 'access_token': `${envConfig.accessToken}`,
23
- 'Content-Type': 'application/json'
24
- };
25
- const http = axios.create({ baseURL, headers });
26
52
 
27
53
  // in-memory caching
28
54
  const cacheKeys = { aemConfig: 'aemConfig', equinoxMarkets: 'equinoxMarkets', kongUrl: 'kongUrl' };
@@ -30,7 +56,7 @@ const cacheTTLInSeconds = 30 * 1000;
30
56
  const cache = {
31
57
  [cacheKeys.aemConfig]: { data: null, ttl: Date.now() + cacheTTLInSeconds },
32
58
  [cacheKeys.equinoxMarkets]: { data: null, ttl: Date.now() + cacheTTLInSeconds },
33
- [cacheKeys.kongUrl]: { data: null, ttl: Date.now() + cacheTTLInSeconds}
59
+ [cacheKeys.kongUrl]: { data: null, ttl: Date.now() + cacheTTLInSeconds }
34
60
  };
35
61
 
36
62
  /**
@@ -78,7 +104,7 @@ function getCachedData(key) {
78
104
  async function getAEMConfig() {
79
105
  try {
80
106
  if (isCacheExpired(cacheKeys.aemConfig)) {
81
- const marketConfig = `market_config_${env}`;
107
+ const marketConfig = `market_config_${platform.env}`;
82
108
  const variables = { uid: 'blt52b0b83a89763791' };
83
109
  const query = `query AemConfigByUid($uid: String!) {
84
110
  aem_config(uid: $uid) {
@@ -125,7 +151,7 @@ async function getAEMConfig() {
125
151
  async function getEquinoxMarkets() {
126
152
  try {
127
153
  if (isCacheExpired(cacheKeys.equinoxMarkets)) {
128
- const marketConfig = `${env}_markets`;
154
+ const marketConfig = `${platform.env}_markets`;
129
155
  const variables = { uid: 'blt5633ff9e560f14ef' };
130
156
  const query = `query EquinoxMarketsByUid($uid: String!) {
131
157
  equinox_markets(uid: $uid) {
@@ -162,7 +188,7 @@ async function getKongUrl() {
162
188
  const query = `query KongUrlByUid($uid: String!) {
163
189
  equinox_markets(uid: $uid) {
164
190
  kong_urls {
165
- ${env}
191
+ ${platform.env}
166
192
  }
167
193
  }
168
194
  }`;
@@ -171,9 +197,9 @@ async function getKongUrl() {
171
197
  data: { variables, query }
172
198
  });
173
199
 
174
- setCachedData(cacheKeys.kongUrl, data.equinox_markets.kong_urls[env]);
200
+ setCachedData(cacheKeys.kongUrl, data.equinox_markets.kong_urls[platform.env]);
175
201
  }
176
-
202
+
177
203
  return getCachedData(cacheKeys.kongUrl);
178
204
  } catch (error) {
179
205
  console.error(error);
@@ -210,6 +236,7 @@ async function contentstackService(config) {
210
236
 
211
237
  try {
212
238
  const response = await http.post('', data);
239
+ console.log(response);
213
240
  return response.data
214
241
  } catch (error) {
215
242
  console.error(error.response.data.errors);
@@ -30,7 +30,6 @@ const ProductData = {
30
30
  axios.defaults.withCredentials = true;
31
31
 
32
32
  const url = await contentstack.getKongUrl() + `/orchestrationservices/storefront/catalogs/search/`;
33
- console.log("Dynamic URL", url)
34
33
  const href = `${url}?filter=${encodeURI(filter)}`;
35
34
  const response = await axios.request({
36
35
  method: 'get',