@nuskin/ns-product-lib 2.11.0-cx24-5092.7 → 2.11.0-cx24-5092.9

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,17 @@
1
+ # [2.11.0-cx24-5092.9](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.11.0-cx24-5092.8...v2.11.0-cx24-5092.9) (2023-09-13)
2
+
3
+
4
+ ### New
5
+
6
+ * Moving from AEM to CS for EQ markets ([220bf20](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/220bf20a4f6564625e1e8ecc54ffcb8061aaef08))
7
+
8
+ # [2.11.0-cx24-5092.8](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.11.0-cx24-5092.7...v2.11.0-cx24-5092.8) (2023-09-13)
9
+
10
+
11
+ ### New
12
+
13
+ * Moving from AEM to CS for EQ markets ([fe4ba38](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/fe4ba38001139d8070cbb8de56ce9600e0da3c1c))
14
+
1
15
  # [2.11.0-cx24-5092.7](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.11.0-cx24-5092.6...v2.11.0-cx24-5092.7) (2023-09-09)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/ns-product-lib",
3
- "version": "2.11.0-cx24-5092.7",
3
+ "version": "2.11.0-cx24-5092.9",
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": {
@@ -22,15 +22,15 @@ const ProductData = {
22
22
  * @param {string} market
23
23
  * @param {boolean} isEquinoxEnabled
24
24
  */
25
- getProductData: async function (skus, locale, market, isEquinoxEnabled = false) {
25
+ getProductData: async function (skus, locale, market) {
26
26
  const localeMarket = `${locale}_${market}`;
27
27
 
28
28
 
29
29
  const config = (await getConfiguration(['Equinox_Markets'])).Equinox_Markets;
30
30
  skus.forEach((sku) => {
31
31
  const graphQLResponse = ProductGraphQL.getProductFromGraphQL(sku, market, locale)
32
- console.log(graphQLResponse)
33
- console.log(isEquinoxEnabled)
32
+ return graphQLResponse;
33
+
34
34
  })
35
35
 
36
36
 
@@ -3,11 +3,13 @@
3
3
  const axios = require("axios");
4
4
  //const Product = require("./product");
5
5
  const getProductGql = require('./graphQl/query')
6
+ const ProductStatus = require("./models/productStatus");
6
7
  const { getEnvironmentFromUrl } = require('@nuskin/ns-common-lib');
7
8
 
8
9
 
9
10
 
10
11
 
12
+
11
13
  const ProductGraphQL = {
12
14
  getProductGraphqlUrl: function () {
13
15
  const env = getEnvironmentFromUrl(window.location.host);
@@ -27,15 +29,12 @@ const ProductGraphQL = {
27
29
  getProductFromGraphQL: async function (id, market, locale) {
28
30
 
29
31
  const url = this.getProductGraphqlUrl();
30
-
31
-
32
32
  const payload = {
33
33
  query: getProductGql,
34
34
  variables: { id, market, locale },
35
- operationName: "getProduct"
35
+ operationName: "getProduct",
36
+ useContentSource: "CS"
36
37
  }
37
-
38
-
39
38
  const response = await axios.request({
40
39
  method: 'post',
41
40
  url: url,
@@ -45,10 +44,158 @@ const ProductGraphQL = {
45
44
 
46
45
  if (!response.data || !response.data.data) return [];
47
46
 
48
- return response.data.data.productsById.products;
47
+ return this.mapResponseToProduct(response.data.productById);
48
+
49
+ },
50
+
51
+ mapResponseToProduct: function (response, market, locale) {
52
+ let res = {
53
+ "sku": response.variants[0].sku,
54
+ "globalProductID": response.id,
55
+ "title": response.variants[0].title,
56
+ "country": market,
57
+ "language": locale,
58
+ "shortDescr": response.variants[0].description,
59
+ "longDescr": response.variants[0].productDetails.description,
60
+ "fullImage": response.productImages[0].url,
61
+ "imageAltText": response.productImages[0].alt,
62
+
63
+ "thumbnail": response.productImages[0].thumbnail,
64
+ "ingredients": response.variants[0].ingredients,
65
+ "benefits": response.variants[0].benefits,
66
+ "usage": response.variants[0].usage,
67
+ "resources": response.variants[0].resoruces,
49
68
 
69
+
70
+ "availableQuantity": response.variants[0].availableQuantity,
71
+ "maxQuantity": response.variants[0].maxQuantity,
72
+ "points": "",
73
+ "cv": 0,
74
+ "pv": 0,
75
+ "priceType": "WRTL",
76
+ "price": 0,
77
+ "priceMap": {
78
+ "WRTL": response.variants[0].totalPrice.retail,
79
+ "WADW-WRTL": response.variants[0].totalPrice.retailSubscription,
80
+ "WADR": response.variants[0].totalPrice.retailSubscription, //retail ADR (subscription) price
81
+ "RTL": response.variants[0].totalPrice.retail,
82
+ "WWHL": response.variants[0].totalPrice.wholeSale,
83
+ "WADW": response.variants[0].totalPrice.wholesaleSubscription,//wholesale ADR (subscription price)
84
+ "WHL": response.variants[0].totalPrice.wholeSale
85
+ },
86
+ "cvMap": {
87
+ "WWHL": response.variants[0].totalPoints.wholeSale.cv,
88
+ "WADW": response.variants[0].totalPoints.subscription.cv,
89
+ "WHL": response.variants[0].totalPoints.wholeSale.cv
90
+ },
91
+ "pvMap": {
92
+ "WWHL": response.variants[0].totalPoints.wholeSale.pv,
93
+ "WADW": response.variants[0].totalPoints.subscription.pv,
94
+ "WHL": response.variants[0].totalPoints.wholeSale.pv
95
+ },
96
+ "orderTypes": this._setOrderType(response.variants[0].purchaseTypes),
97
+ "custTypes": {},
98
+ "backOrderDate": response.variants[0].status.backorderedAvailableDate,
99
+
100
+ "size": response.variants[0].size,
101
+ "status": this.switchStatusFromEquinox(response.variants[0].status.status),
102
+ "variantType": "Other",
103
+ "variantDropdownLabel": response.variantSelectLabel || response.variants[0].title,
104
+ "variantDropdownPlaceholder": "Select Type",
105
+ "variantsLabel": response.variantSelectLabel || response.variants[0].title,
106
+ "groupOffer": false,
107
+ "personalOffer": false,
108
+ "savedEventName": '',
109
+ "salesLabel": '',
110
+ "eventName": '',
111
+ "sizeWeight": '',
112
+ "nettoWeight": "",
113
+ "searchScore": 0,
114
+ "isExclusive": response.variants[0].isExclusive || false,
115
+ "equinoxProductId": response.id,
116
+ "properties": {}
117
+ }
118
+ return res;
119
+ },
120
+ /**
121
+ *
122
+ * Map status from equinox to legacy
123
+ *
124
+ * @param {*} status
125
+ * @returns {string} productStatus
126
+ */
127
+ switchStatusFromEquinox: function (status) {
128
+ const { equinoxStatus } = ProductStatus;
129
+ let newStatus = '';
130
+ switch (status.toLowerCase()) {
131
+ case equinoxStatus.SELLABLE:
132
+ newStatus = ProductStatus.ReleasedForSale;
133
+ break;
134
+ case equinoxStatus.PREVIEW_PRODUCT:
135
+ newStatus = ProductStatus.NotReleasedForSale;
136
+ break;
137
+ case equinoxStatus.DISCONTINUED:
138
+ newStatus = ProductStatus.Discontinued;
139
+ break;
140
+ case equinoxStatus.STOPPED:
141
+ newStatus = ProductStatus.Discontinued;
142
+ break;
143
+ case equinoxStatus.REPLACEMENT:
144
+ newStatus = ProductStatus.NotReleasedForSale;
145
+ break;
146
+ default:
147
+ newStatus = ProductStatus.NotReleasedForSale;
148
+ break;
149
+ }
150
+
151
+ return newStatus;
152
+ },
153
+
154
+ /**
155
+ *
156
+ * @param {*} availableChannels
157
+ *
158
+ * This function is use to convert arsPhone,web,kiosk,mobile,subscription
159
+ * to orderType object
160
+ * "adr”
161
+ "order"
162
+ "zpfc"
163
+ "zadp"
164
+ "ars"
165
+ "kiosk"
166
+ "mobile"
167
+ "preferred customer"
168
+ "retail"
169
+ "web"
170
+ "web display"
171
+ */
172
+ _setOrderType: function (purchaseTypes) {
173
+ let orderType = {
174
+ "adr": false,
175
+ "order": false,
176
+ "zpfc": false,
177
+ "zadp": false,
178
+ "ars": false,
179
+ "kiosk": false,
180
+ "mobile": false,
181
+ "preferred customer": false,
182
+ "retail": false,
183
+ "web": false,
184
+ "web display": false
185
+ };
186
+ if (purchaseTypes.buyOnce) {
187
+ orderType.web = true
188
+ orderType.order = true
189
+ }
190
+ if (purchaseTypes.subscription) {
191
+ orderType.adr = true
192
+ }
193
+
194
+
195
+ return orderType;
50
196
  }
51
197
 
198
+
52
199
  }
53
200
 
54
201
  module.exports = ProductGraphQL