@nuskin/ns-product-lib 2.11.0-cx24-5092.3 → 2.11.0-cx24-5092.5

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 CHANGED
@@ -1,3 +1,18 @@
1
+ # [2.11.0-cx24-5092.5](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.11.0-cx24-5092.4...v2.11.0-cx24-5092.5) (2023-09-09)
2
+
3
+
4
+ ### New
5
+
6
+ * Moving from AEM to CS for EQ markets ([c6d52c3](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/c6d52c3e1f6f8d7d596d5c86095265c90624e53d))
7
+ * Moving from AEM to CS for EQ markets ([cc8b3fc](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/cc8b3fc5403e021589d9d42f1db71ff380f87b57))
8
+
9
+ # [2.11.0-cx24-5092.4](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.11.0-cx24-5092.3...v2.11.0-cx24-5092.4) (2023-09-08)
10
+
11
+
12
+ ### New
13
+
14
+ * Moving from AEM to CS for EQ markets ([af5acd8](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/af5acd8dca1c73004b6ee634faf90d6e47f974fd))
15
+
1
16
  # [2.11.0-cx24-5092.3](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.11.0-cx24-5092.2...v2.11.0-cx24-5092.3) (2023-09-08)
2
17
 
3
18
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/ns-product-lib",
3
- "version": "2.11.0-cx24-5092.3",
3
+ "version": "2.11.0-cx24-5092.5",
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": {
@@ -27,9 +27,12 @@ const ProductData = {
27
27
 
28
28
 
29
29
  const config = (await getConfiguration(['Equinox_Markets'])).Equinox_Markets;
30
- const graphQLResponse = ProductGraphQL.getProductFromGraphQL(skus.toString())
31
- console.log(graphQLResponse)
32
- console.log(isEquinoxEnabled)
30
+ skus.forEach((sku) => {
31
+ const graphQLResponse = ProductGraphQL.getProductFromGraphQL(sku, market, locale)
32
+ console.log(graphQLResponse)
33
+ console.log(isEquinoxEnabled)
34
+ })
35
+
33
36
 
34
37
 
35
38
 
@@ -3,38 +3,48 @@
3
3
  const axios = require("axios");
4
4
  //const Product = require("./product");
5
5
  const getProductGql = require('./graphQl/query')
6
+ const { getEnvironmentFromUrl } = require('@nuskin/ns-common-lib');
7
+
6
8
 
7
9
 
8
- const ProductGraphQL = {
9
- getProductFromGraphQL: async function (sku) {
10
10
 
11
- let data = JSON.stringify({
11
+ const ProductGraphQL = {
12
+ getProductGraphqlUrl: function () {
13
+ const env = getEnvironmentFromUrl(window.location.host);
14
+
15
+ switch (env) {
16
+ case "dev":
17
+ return "https://test.nuskin.com/product-api/graphql";
18
+ case "stage":
19
+ case "test":
20
+ return "https://test.nuskin.com/product-api/graphql";
21
+ case "unknown":
22
+ case "prod":
23
+ default:
24
+ return "https://www.nuskin.com/product-api/graphql";
25
+ }
26
+ },
27
+ getProductFromGraphQL: async function (sku, market, locale) {
28
+
29
+ const url = this.getProductGraphqlUrl();
30
+
31
+
32
+ const payload = {
12
33
  query: getProductGql,
13
- variables: { "market": "us", "language": "en", "id": sku, "useContentSource": null, "quantity": 1, "okta": null }
14
- });
34
+ variables: { sku, market, locale }
35
+ }
15
36
 
16
- let axiosGqlConfig = {
37
+
38
+ const response = await axios.request({
17
39
  method: 'post',
18
- url: 'https://product.api.test.nuskin.com/graphql',
19
- headers: {
20
- 'authority': 'product.api.test.nuskin.com',
21
- 'accept': '*/*',
22
- 'accept-language': 'en-US,en;q=0.9',
23
- 'content-type': 'application/json',
24
- 'origin': 'https://mysite.test.mynuskin.com',
25
- 'referer': 'https://mysite.test.mynuskin.com/'
26
-
27
- },
28
- data: data
29
- };
30
-
31
- axios.request(axiosGqlConfig)
32
- .then((response) => {
33
- return response.data
34
- })
35
- .catch((error) => {
36
- console.log(error);
37
- });
40
+ url: url,
41
+ data: payload,
42
+ responseType: 'json'
43
+ });
44
+
45
+ if (!response.data || !response.data.data) return [];
46
+
47
+ return response.data.data.productsById.products;
38
48
 
39
49
  }
40
50