@nuskin/ns-product-lib 2.16.0 → 2.17.0-cx24-5822.1
Sign up to get free protection for your applications and to get access to all the features.
package/package.json
CHANGED
package/src/graph-ql/index.js
CHANGED
package/src/graph-ql/product.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
const axios = require('axios').default;
|
2
|
-
const { getProductByIdQuery } = require('./query');
|
2
|
+
const { getProductByIdQuery , getProductsByIdQuery } = require('./query');
|
3
3
|
const ProductStatus = require("../models/productStatus");
|
4
4
|
const CustomerTypes = require('./customerTypes');
|
5
5
|
const Product = require("../product");
|
@@ -84,6 +84,64 @@ async function getProduct(id, market, locale, config) {
|
|
84
84
|
};
|
85
85
|
}
|
86
86
|
|
87
|
+
/**
|
88
|
+
* Get products by IDs
|
89
|
+
* @todo map promotions coming from promotions API
|
90
|
+
* @param {string[]} ids
|
91
|
+
* @param {string} market
|
92
|
+
* @param {string} locale
|
93
|
+
* @param {obj} config
|
94
|
+
*/
|
95
|
+
async function getProducts(ids, market, locale, config) {
|
96
|
+
|
97
|
+
const productsData = {
|
98
|
+
products: [],
|
99
|
+
count: 0
|
100
|
+
};
|
101
|
+
|
102
|
+
const okta = parseOktaObject(sessionStorage.oktaTokens);
|
103
|
+
|
104
|
+
const payload = {
|
105
|
+
...defaultPayload,
|
106
|
+
query: getProductsByIdQuery,
|
107
|
+
variables: {
|
108
|
+
ids,
|
109
|
+
market,
|
110
|
+
locale,
|
111
|
+
...(okta !== null && { okta }),
|
112
|
+
quantity: 1 // set default to 1
|
113
|
+
}
|
114
|
+
}
|
115
|
+
|
116
|
+
try {
|
117
|
+
const { data } = await graphQlHttpRequest(payload, config);
|
118
|
+
|
119
|
+
if (data && data.data && data.data.productsById && data.data.productsById.products) {
|
120
|
+
|
121
|
+
//use to get default variant based on requested sku
|
122
|
+
productsData.products = data.data.productsById.products.map((product,index)=>{
|
123
|
+
config.sku = ids[index];
|
124
|
+
const newProduct = mapProduct(product, market, locale, config);
|
125
|
+
return new Product(newProduct);
|
126
|
+
})
|
127
|
+
|
128
|
+
productsData.count = productsData.products.length;
|
129
|
+
}
|
130
|
+
|
131
|
+
} catch (e) {
|
132
|
+
console.log(`Unable to fetch products details for SKUs ${ids}`);
|
133
|
+
}
|
134
|
+
|
135
|
+
return {
|
136
|
+
data: {
|
137
|
+
"status": 200,
|
138
|
+
"messages": [],
|
139
|
+
"data": productsData
|
140
|
+
}
|
141
|
+
};
|
142
|
+
}
|
143
|
+
|
144
|
+
|
87
145
|
/**
|
88
146
|
* Map product prices
|
89
147
|
* @param {*} product
|
@@ -536,4 +594,4 @@ function parseOktaObject(okta) {
|
|
536
594
|
}
|
537
595
|
|
538
596
|
|
539
|
-
module.exports = getProduct;
|
597
|
+
module.exports = {getProduct , getProducts};
|
@@ -1,9 +1,9 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
// eslint-disable-next-line max-len
|
4
|
-
const getProductsByIdQuery = `query getProducts($
|
4
|
+
const getProductsByIdQuery = `query getProducts($ids: [String!]!, $market: String, $language: String, $okta: String, quantity: Int) {
|
5
5
|
productsById(
|
6
|
-
id: $
|
6
|
+
id: $ids
|
7
7
|
market: $market
|
8
8
|
language: $language
|
9
9
|
okta: $okta
|
package/src/productData.js
CHANGED
@@ -7,7 +7,7 @@ const CustomerTypes = require('./models/customerTypes');
|
|
7
7
|
const ProductStatus = require("./models/productStatus");
|
8
8
|
const { mapBackOrderDate, mapAvailableQuantity, mapChildSKU, mapChildSKUBundle } = require('./equinox-helpers');
|
9
9
|
const { productNotFoundInterceptor } = require('./equinox-helpers/interceptors');
|
10
|
-
const {
|
10
|
+
const { getProducts } = require('./graph-ql');
|
11
11
|
const productTypes = {
|
12
12
|
kit: 'kit',
|
13
13
|
bundle: 'bundle'
|
@@ -26,11 +26,11 @@ const ProductData = {
|
|
26
26
|
const config = (await getConfiguration(['Equinox_Markets'])).Equinox_Markets;
|
27
27
|
if (config.active) {
|
28
28
|
return (config.MySite_graphql_active_list.includes(market)) ?
|
29
|
-
await
|
29
|
+
await getProducts(skus, market, locale, config) :
|
30
30
|
await this.getProductFromEquinox(skus, localeMarket, config)
|
31
31
|
} else {
|
32
32
|
return (config.MySite_graphql_active_list.includes(market)) ?
|
33
|
-
await
|
33
|
+
await getProducts(skus, market, locale, config) :
|
34
34
|
await this.getProductFromLegacy(skus, localeMarket);
|
35
35
|
}
|
36
36
|
|