@nuskin/mobile-cart
Advanced tools
Comparing version 2.1.8 to 2.1.9
@@ -44,2 +44,3 @@ "use strict"; | ||
} = (0, _nsLoginReactNative.useAuthStore)(); | ||
const configurations = (0, _utilsModule.useConfigurationStore)(state => state.configurations); | ||
const localeState = (0, _valtio.useSnapshot)(_utilsModule.localizationState); | ||
@@ -66,7 +67,9 @@ const [itemCount, setItemCount] = (0, _react.useState)(0); | ||
const [baseURL, setBaseURL] = (0, _react.useState)(); | ||
const [locale, setLocale] = (0, _react.useState)(); | ||
let locale = localeState.locale.language + '_' + localeState.locale.country; | ||
//const [locale, setLocale] = useState(loc); | ||
const [sessionID, setSessionId] = (0, _react.useState)(''); | ||
const [storeId, setStoreId] = (0, _react.useState)(); | ||
const [countryFlag, setCountryFlag] = (0, _react.useState)(0); | ||
const [equinoxActive, setEquinoxActive] = (0, _react.useState)(false); | ||
//const [equinoxActive, setEquinoxActive] = useState(false); | ||
const [krCartApiUrl, setKrCartApiUrl] = (0, _react.useState)(''); | ||
@@ -77,2 +80,3 @@ const [krCartUrl, setKrCartUrl] = (0, _react.useState)(''); | ||
const featureFlags = (0, _featureFlags.useFeatureFlagStore)(); | ||
/** | ||
@@ -169,3 +173,3 @@ * Sets the itemCount state variable. This is the total item count on the cart | ||
console.log('Product Id is.............................', productId, sku); | ||
if (equinoxActive && featureFlags.isEnabled('cx114-176')) { | ||
if (configurations.EQUINOX_ACTIVE && featureFlags.isEnabled('cx114-176')) { | ||
try { | ||
@@ -190,3 +194,3 @@ let header; | ||
console.log('.............. Items added as......... SKU ID ...........', header, JSON.stringify(await _asyncStorage.default.getItem('sessionID'))); | ||
console.log('locale & store ID:', locale, storeId); | ||
console.log('locale & store ID:', locale, configurations.EQUINOX_STORE_ID); | ||
const response = await (0, _axiosUtil.axios)({ | ||
@@ -198,3 +202,3 @@ method: 'POST', | ||
locale: locale, | ||
storeId: storeId | ||
storeId: configurations.EQUINOX_STORE_ID | ||
}, | ||
@@ -207,13 +211,5 @@ data: [{ | ||
type: 'DEFAULT' | ||
} | ||
// skus: [ | ||
// { | ||
// skuId: skus?.sku, | ||
// productId: skus?.product, | ||
// type: 'DEFAULT', | ||
// }, | ||
] | ||
}] | ||
}] | ||
}); | ||
console.log('Item Added To Cart', response.data); | ||
@@ -270,4 +266,2 @@ await getCartItems(); | ||
await getCart(); | ||
// await addSkuToCart('18004215', 1, true); | ||
// await addSkuToCart('18004230', 1, true); | ||
} | ||
@@ -279,4 +273,2 @@ } else { | ||
setQuantity(0); | ||
// await addSkuToCart('18004215', 1, true); | ||
// await addSkuToCart('18004230', 1, true); | ||
} | ||
@@ -288,27 +280,89 @@ } | ||
}; | ||
(0, _react.useEffect)(() => { | ||
(async () => { | ||
if (!equinoxActive || !featureFlags.isEnabled('cx114-176')) { | ||
const contextOk = shoppingContext === ShoppingContextValue.Stela && isAuthenticated && !!userId || shoppingContext === ShoppingContextValue.Vera && (!isAuthenticated && !!!userId || isAuthenticated && !!userId); | ||
const krOk = country === 'KR' && !!krCartApiUrl && !!krCartUrl && !!krApiClient && !!krApiKey && contextOk; | ||
const nsOk = country !== 'KR' && !!clientId && !!clientSecret && !!cartUrl && !!country && contextOk; | ||
if (nsOk || krOk) { | ||
api.setData({ | ||
userId, | ||
anonymousCartId, | ||
country, | ||
cartUrl, | ||
clientId, | ||
clientSecret, | ||
krCartApiUrl, | ||
krCartUrl, | ||
krApiClient, | ||
krApiKey | ||
}); | ||
updateCartInfo(); | ||
const updateEquinoxCart = async () => { | ||
try { | ||
if (userId) { | ||
const storedSession = await _asyncStorage.default.getItem('sessionID'); | ||
if (storedSession) { | ||
await mergeCartEquinox(); | ||
// trigger webview reload | ||
setCartVersion(cartVersion + 1); | ||
} else { | ||
await getCartItems(); | ||
// trigger webview reload | ||
setCartVersion(cartVersion + 1); | ||
} | ||
} else { | ||
if (sessionID) { | ||
await getCartItems(); | ||
} else { | ||
setQuantity(0); | ||
} | ||
} | ||
})(); | ||
}, [cartUrl, country, isAuthenticated, clientId, clientSecret, userId, krApiClient, krApiKey, krCartApiUrl, shoppingContext]); | ||
} catch (err) { | ||
console.log('Cart: error updating equinox cart information', err); | ||
} | ||
}; | ||
(0, _react.useEffect)(() => { | ||
const loadConfigs = async () => { | ||
// const configurations = configuration.getConfigState(); | ||
// const promises = [ | ||
// localization.loadLocalization(), | ||
// AsyncStorage.getItem(CartIdKey), | ||
// ]; | ||
// const results = await Promise.all(promises); | ||
// now using the results array again! | ||
//@ts-ignore | ||
// let savedCartInfo = JSON.parse(results[1]); | ||
const storedCart = await _asyncStorage.default.getItem(CartIdKey); | ||
let savedCartInfo = JSON.parse(storedCart); | ||
if (!savedCartInfo || !savedCartInfo.anonymousCartMap) { | ||
savedCartInfo = { | ||
anonymousCartMap: {}, | ||
userId: '' | ||
}; | ||
} | ||
console.log('Cart: saved cartInfo', savedCartInfo); | ||
setAnonymousCartMap(savedCartInfo.anonymousCartMap); | ||
console.log('Cart: configurations', configurations); | ||
setShoppingContext(configurations.VERA_SHOPPING_CONTEXT || configurations.STELA_SHOPPING_CONTEXT); | ||
setCloudUrl(`${configurations.NUSKIN_CLOUD_URL}`); | ||
setCartUrl(`${configurations.NUSKIN_CLOUD_URL}/cart/v2`); | ||
setNuskinUrl(`${configurations.NUSKIN_URL}`); | ||
setClientId(configurations.CUSTOMER_API_CLIENT_ID); | ||
setClientSecret(configurations.CUSTOMER_API_CLIENT_SECRET); | ||
setKrCartApiUrl(configurations.KR_CART_API_URL); | ||
setKrCartUrl(configurations.KR_CART_URL); | ||
setKrApiClient(configurations.KR_API_CLIENT); | ||
setKrApiKey(configurations.KR_API_KEY); | ||
setBaseURL(configurations.EQUINOX_API_BASE_URL); | ||
setStoreId(configurations.EQUINOX_STORE_ID); | ||
setCountryFlag(1); | ||
}; | ||
loadConfigs(); | ||
}, [configurations]); | ||
(0, _react.useEffect)(() => { | ||
if (configurations.EQUINOX_ACTIVE && featureFlags.isEnabled('cx114-176')) { | ||
updateEquinoxCart(); | ||
} else { | ||
const contextOk = shoppingContext === ShoppingContextValue.Stela && isAuthenticated && !!userId || shoppingContext === ShoppingContextValue.Vera && (!isAuthenticated && !!!userId || isAuthenticated && !!userId); | ||
const krOk = country === 'KR' && !!krCartApiUrl && !!krCartUrl && !!krApiClient && !!krApiKey && contextOk; | ||
const nsOk = country !== 'KR' && !!clientId && !!clientSecret && !!cartUrl && !!country && contextOk; | ||
if (nsOk || krOk) { | ||
api.setData({ | ||
userId, | ||
anonymousCartId, | ||
country, | ||
cartUrl, | ||
clientId, | ||
clientSecret, | ||
krCartApiUrl, | ||
krCartUrl, | ||
krApiClient, | ||
krApiKey | ||
}); | ||
updateCartInfo(); | ||
} | ||
} | ||
}, [cartUrl, configurations, country, isAuthenticated, clientId, clientSecret, userId, krApiClient, krApiKey, krCartApiUrl, shoppingContext]); | ||
(0, _react.useEffect)(() => { | ||
const getUserId = async () => { | ||
@@ -331,15 +385,4 @@ const user = await getUser(); | ||
}; | ||
const setIsCartMergedAsynFalse = async () => { | ||
await _asyncStorage.default.setItem('isCartMerged', 'false'); | ||
}; | ||
const callMergeCartEquinoxAsync = async () => { | ||
if ((await _asyncStorage.default.getItem('isCartMerged')) === 'false') { | ||
mergeCartEquinox(); | ||
// trigger webview reload | ||
setCartVersion(cartVersion + 1); | ||
} | ||
}; | ||
if (isAuthenticated) { | ||
getUserId(); | ||
callMergeCartEquinoxAsync(); | ||
} else { | ||
@@ -349,13 +392,2 @@ setUserId(''); | ||
setAuthToken(''); | ||
setIsCartMergedAsynFalse(); | ||
(async () => { | ||
if (equinoxActive && featureFlags.isEnabled('cx114-176')) { | ||
const storedSession = await _asyncStorage.default.getItem('sessionID'); | ||
if (storedSession) { | ||
getCartItems(); | ||
} else { | ||
setQuantity(0); | ||
} | ||
} | ||
})(); | ||
} | ||
@@ -365,3 +397,3 @@ }, [isAuthenticated]); | ||
(async () => { | ||
if (!equinoxActive || !featureFlags.isEnabled('cx114-176')) { | ||
if (!configurations.EQUINOX_ACTIVE || !featureFlags.isEnabled('cx114-176')) { | ||
const storeAsync = async () => { | ||
@@ -386,5 +418,2 @@ if (!anonymousCartId) { | ||
(0, _react.useEffect)(() => { | ||
// console.log('ShoppingContext', shoppingContext); | ||
// console.log('locale', localeState); | ||
let country = InitialValue; | ||
@@ -407,44 +436,9 @@ let language = InitialValue; | ||
}, [localeState.locale, shoppingContext]); | ||
async function getConfgs() { | ||
const promises = [_utilsModule.localization.loadLocalization(), _utilsModule.configuration.getConfigState(), _asyncStorage.default.getItem(CartIdKey)]; | ||
const results = await Promise.all(promises); | ||
// now using the results array again! | ||
const configs = results[1]; | ||
let savedCartInfo = JSON.parse(results[2]); | ||
if (!savedCartInfo || !savedCartInfo.anonymousCartMap) { | ||
savedCartInfo = { | ||
anonymousCartMap: {}, | ||
userId: '' | ||
}; | ||
} | ||
console.log('Cart: saved cartInfo', savedCartInfo); | ||
setAnonymousCartMap(savedCartInfo.anonymousCartMap); | ||
console.log('Cart: configs', configs); | ||
setShoppingContext(configs.VERA_SHOPPING_CONTEXT || configs.STELA_SHOPPING_CONTEXT); | ||
setCloudUrl(`${configs.NUSKIN_CLOUD_URL}`); | ||
setCartUrl(`${configs.NUSKIN_CLOUD_URL}/cart/v2`); | ||
setNuskinUrl(`${configs.NUSKIN_URL}`); | ||
setClientId(configs.CUSTOMER_API_CLIENT_ID); | ||
setClientSecret(configs.CUSTOMER_API_CLIENT_SECRET); | ||
setKrCartApiUrl(configs.KR_CART_API_URL); | ||
setKrCartUrl(configs.KR_CART_URL); | ||
setKrApiClient(configs.KR_API_CLIENT); | ||
setKrApiKey(configs.KR_API_KEY); | ||
setEquinoxActive(configs.EQUINOX_ACTIVE); | ||
setBaseURL(configs.EQUINOX_API_BASE_URL); | ||
setStoreId(configs.EQUINOX_STORE_ID); | ||
let loc = localeState.locale.language + '_' + localeState.locale.country; | ||
setLocale(loc); | ||
setCountryFlag(1); | ||
} | ||
(0, _react.useEffect)(() => { | ||
getConfgs(); | ||
}, [country]); | ||
(0, _react.useEffect)(() => { | ||
(async () => { | ||
if (baseURL !== undefined && locale !== undefined && storeId !== undefined && equinoxActive && featureFlags.isEnabled('cx114-176')) { | ||
if (baseURL !== undefined && locale !== undefined && configurations.EQUINOX_STORE_ID !== undefined && configurations.EQUINOX_ACTIVE && featureFlags.isEnabled('cx114-176')) { | ||
getAnnonymousSessionId(); | ||
} | ||
})(); | ||
}, [baseURL, locale, storeId]); | ||
}, [storeId]); | ||
async function getAnnonymousSessionId() { | ||
@@ -460,3 +454,3 @@ const sessionToken = await _asyncStorage.default.getItem('sessionID'); | ||
console.log('Get Customer Api Called...'); | ||
console.log('Base API is ...', baseURL, locale, storeId); | ||
console.log('Base API is ...', baseURL, locale, configurations.EQUINOX_STORE_ID); | ||
await (0, _nsLoginReactNative.getEquinoxUser)(GetCustomerAPICallValue.Anonymous); | ||
@@ -468,3 +462,3 @@ const storedSession = await _asyncStorage.default.getItem('sessionID'); | ||
(async () => { | ||
if (equinoxActive && featureFlags.isEnabled('cx114-176') && sessionID !== undefined) { | ||
if (configurations.EQUINOX_ACTIVE && featureFlags.isEnabled('cx114-176') && sessionID !== undefined) { | ||
getCartItems(); | ||
@@ -476,3 +470,3 @@ } | ||
(async () => { | ||
if (equinoxActive && featureFlags.isEnabled('cx114-176')) { | ||
if (configurations.EQUINOX_ACTIVE && featureFlags.isEnabled('cx114-176')) { | ||
if (countryFlag == 1) { | ||
@@ -495,4 +489,4 @@ getCartItems(); | ||
let header; | ||
console.log('Inside getCartItems'); | ||
if (isAuthenticated === true) { | ||
console.log('Authenticated header'); | ||
let token = await getAccessToken(); | ||
@@ -508,2 +502,3 @@ console.log('Token', token); | ||
} | ||
console.log('API details-->' + baseURL, ',', localeState.locale.language + '_' + localeState.locale.country, ',', configurations.EQUINOX_STORE_ID, ',', JSON.stringify(header)); | ||
try { | ||
@@ -515,4 +510,4 @@ var _response$data, _response$data2, _response$data2$value; | ||
params: { | ||
locale: locale, | ||
storeId: storeId | ||
locale: localeState.locale.language + '_' + localeState.locale.country, | ||
storeId: configurations.EQUINOX_STORE_ID | ||
}, | ||
@@ -526,2 +521,3 @@ headers: header | ||
setQuantity(response.data.value.count); | ||
console.log('count-->', response.data.value.count); | ||
} | ||
@@ -543,3 +539,3 @@ } catch (err) { | ||
console.log('NextGenApi.tsx -> getXSkSessionId - Equinox API Response', response.data.email, response.headers); | ||
await _asyncStorage.default.setItem('isCartMerged', 'true'); | ||
//await AsyncStorage.setItem('isCartMerged', 'true'); | ||
await getCartItems(); | ||
@@ -546,0 +542,0 @@ } else { |
@@ -5,3 +5,3 @@ /* eslint-disable */ | ||
import React, { useContext, useEffect, useState } from 'react'; | ||
import { configuration, localizationState, localization } from '@nuskin/utils-module'; | ||
import { localizationState, useConfigurationStore } from '@nuskin/utils-module'; | ||
import { useSnapshot } from 'valtio'; | ||
@@ -36,2 +36,3 @@ import nsCartUtil from './NsCartApi'; | ||
} = useAuthStore(); | ||
const configurations = useConfigurationStore(state => state.configurations); | ||
const localeState = useSnapshot(localizationState); | ||
@@ -58,7 +59,9 @@ const [itemCount, setItemCount] = useState(0); | ||
const [baseURL, setBaseURL] = useState(); | ||
const [locale, setLocale] = useState(); | ||
let locale = localeState.locale.language + '_' + localeState.locale.country; | ||
//const [locale, setLocale] = useState(loc); | ||
const [sessionID, setSessionId] = useState(''); | ||
const [storeId, setStoreId] = useState(); | ||
const [countryFlag, setCountryFlag] = useState(0); | ||
const [equinoxActive, setEquinoxActive] = useState(false); | ||
//const [equinoxActive, setEquinoxActive] = useState(false); | ||
const [krCartApiUrl, setKrCartApiUrl] = useState(''); | ||
@@ -69,2 +72,3 @@ const [krCartUrl, setKrCartUrl] = useState(''); | ||
const featureFlags = useFeatureFlagStore(); | ||
/** | ||
@@ -161,3 +165,3 @@ * Sets the itemCount state variable. This is the total item count on the cart | ||
console.log('Product Id is.............................', productId, sku); | ||
if (equinoxActive && featureFlags.isEnabled('cx114-176')) { | ||
if (configurations.EQUINOX_ACTIVE && featureFlags.isEnabled('cx114-176')) { | ||
try { | ||
@@ -182,3 +186,3 @@ let header; | ||
console.log('.............. Items added as......... SKU ID ...........', header, JSON.stringify(await AsyncStorage.getItem('sessionID'))); | ||
console.log('locale & store ID:', locale, storeId); | ||
console.log('locale & store ID:', locale, configurations.EQUINOX_STORE_ID); | ||
const response = await axios({ | ||
@@ -190,3 +194,3 @@ method: 'POST', | ||
locale: locale, | ||
storeId: storeId | ||
storeId: configurations.EQUINOX_STORE_ID | ||
}, | ||
@@ -199,13 +203,5 @@ data: [{ | ||
type: 'DEFAULT' | ||
} | ||
// skus: [ | ||
// { | ||
// skuId: skus?.sku, | ||
// productId: skus?.product, | ||
// type: 'DEFAULT', | ||
// }, | ||
] | ||
}] | ||
}] | ||
}); | ||
console.log('Item Added To Cart', response.data); | ||
@@ -262,4 +258,2 @@ await getCartItems(); | ||
await getCart(); | ||
// await addSkuToCart('18004215', 1, true); | ||
// await addSkuToCart('18004230', 1, true); | ||
} | ||
@@ -271,4 +265,2 @@ } else { | ||
setQuantity(0); | ||
// await addSkuToCart('18004215', 1, true); | ||
// await addSkuToCart('18004230', 1, true); | ||
} | ||
@@ -280,27 +272,89 @@ } | ||
}; | ||
useEffect(() => { | ||
(async () => { | ||
if (!equinoxActive || !featureFlags.isEnabled('cx114-176')) { | ||
const contextOk = shoppingContext === ShoppingContextValue.Stela && isAuthenticated && !!userId || shoppingContext === ShoppingContextValue.Vera && (!isAuthenticated && !!!userId || isAuthenticated && !!userId); | ||
const krOk = country === 'KR' && !!krCartApiUrl && !!krCartUrl && !!krApiClient && !!krApiKey && contextOk; | ||
const nsOk = country !== 'KR' && !!clientId && !!clientSecret && !!cartUrl && !!country && contextOk; | ||
if (nsOk || krOk) { | ||
api.setData({ | ||
userId, | ||
anonymousCartId, | ||
country, | ||
cartUrl, | ||
clientId, | ||
clientSecret, | ||
krCartApiUrl, | ||
krCartUrl, | ||
krApiClient, | ||
krApiKey | ||
}); | ||
updateCartInfo(); | ||
const updateEquinoxCart = async () => { | ||
try { | ||
if (userId) { | ||
const storedSession = await AsyncStorage.getItem('sessionID'); | ||
if (storedSession) { | ||
await mergeCartEquinox(); | ||
// trigger webview reload | ||
setCartVersion(cartVersion + 1); | ||
} else { | ||
await getCartItems(); | ||
// trigger webview reload | ||
setCartVersion(cartVersion + 1); | ||
} | ||
} else { | ||
if (sessionID) { | ||
await getCartItems(); | ||
} else { | ||
setQuantity(0); | ||
} | ||
} | ||
})(); | ||
}, [cartUrl, country, isAuthenticated, clientId, clientSecret, userId, krApiClient, krApiKey, krCartApiUrl, shoppingContext]); | ||
} catch (err) { | ||
console.log('Cart: error updating equinox cart information', err); | ||
} | ||
}; | ||
useEffect(() => { | ||
const loadConfigs = async () => { | ||
// const configurations = configuration.getConfigState(); | ||
// const promises = [ | ||
// localization.loadLocalization(), | ||
// AsyncStorage.getItem(CartIdKey), | ||
// ]; | ||
// const results = await Promise.all(promises); | ||
// now using the results array again! | ||
//@ts-ignore | ||
// let savedCartInfo = JSON.parse(results[1]); | ||
const storedCart = await AsyncStorage.getItem(CartIdKey); | ||
let savedCartInfo = JSON.parse(storedCart); | ||
if (!savedCartInfo || !savedCartInfo.anonymousCartMap) { | ||
savedCartInfo = { | ||
anonymousCartMap: {}, | ||
userId: '' | ||
}; | ||
} | ||
console.log('Cart: saved cartInfo', savedCartInfo); | ||
setAnonymousCartMap(savedCartInfo.anonymousCartMap); | ||
console.log('Cart: configurations', configurations); | ||
setShoppingContext(configurations.VERA_SHOPPING_CONTEXT || configurations.STELA_SHOPPING_CONTEXT); | ||
setCloudUrl(`${configurations.NUSKIN_CLOUD_URL}`); | ||
setCartUrl(`${configurations.NUSKIN_CLOUD_URL}/cart/v2`); | ||
setNuskinUrl(`${configurations.NUSKIN_URL}`); | ||
setClientId(configurations.CUSTOMER_API_CLIENT_ID); | ||
setClientSecret(configurations.CUSTOMER_API_CLIENT_SECRET); | ||
setKrCartApiUrl(configurations.KR_CART_API_URL); | ||
setKrCartUrl(configurations.KR_CART_URL); | ||
setKrApiClient(configurations.KR_API_CLIENT); | ||
setKrApiKey(configurations.KR_API_KEY); | ||
setBaseURL(configurations.EQUINOX_API_BASE_URL); | ||
setStoreId(configurations.EQUINOX_STORE_ID); | ||
setCountryFlag(1); | ||
}; | ||
loadConfigs(); | ||
}, [configurations]); | ||
useEffect(() => { | ||
if (configurations.EQUINOX_ACTIVE && featureFlags.isEnabled('cx114-176')) { | ||
updateEquinoxCart(); | ||
} else { | ||
const contextOk = shoppingContext === ShoppingContextValue.Stela && isAuthenticated && !!userId || shoppingContext === ShoppingContextValue.Vera && (!isAuthenticated && !!!userId || isAuthenticated && !!userId); | ||
const krOk = country === 'KR' && !!krCartApiUrl && !!krCartUrl && !!krApiClient && !!krApiKey && contextOk; | ||
const nsOk = country !== 'KR' && !!clientId && !!clientSecret && !!cartUrl && !!country && contextOk; | ||
if (nsOk || krOk) { | ||
api.setData({ | ||
userId, | ||
anonymousCartId, | ||
country, | ||
cartUrl, | ||
clientId, | ||
clientSecret, | ||
krCartApiUrl, | ||
krCartUrl, | ||
krApiClient, | ||
krApiKey | ||
}); | ||
updateCartInfo(); | ||
} | ||
} | ||
}, [cartUrl, configurations, country, isAuthenticated, clientId, clientSecret, userId, krApiClient, krApiKey, krCartApiUrl, shoppingContext]); | ||
useEffect(() => { | ||
const getUserId = async () => { | ||
@@ -323,15 +377,4 @@ const user = await getUser(); | ||
}; | ||
const setIsCartMergedAsynFalse = async () => { | ||
await AsyncStorage.setItem('isCartMerged', 'false'); | ||
}; | ||
const callMergeCartEquinoxAsync = async () => { | ||
if ((await AsyncStorage.getItem('isCartMerged')) === 'false') { | ||
mergeCartEquinox(); | ||
// trigger webview reload | ||
setCartVersion(cartVersion + 1); | ||
} | ||
}; | ||
if (isAuthenticated) { | ||
getUserId(); | ||
callMergeCartEquinoxAsync(); | ||
} else { | ||
@@ -341,13 +384,2 @@ setUserId(''); | ||
setAuthToken(''); | ||
setIsCartMergedAsynFalse(); | ||
(async () => { | ||
if (equinoxActive && featureFlags.isEnabled('cx114-176')) { | ||
const storedSession = await AsyncStorage.getItem('sessionID'); | ||
if (storedSession) { | ||
getCartItems(); | ||
} else { | ||
setQuantity(0); | ||
} | ||
} | ||
})(); | ||
} | ||
@@ -357,3 +389,3 @@ }, [isAuthenticated]); | ||
(async () => { | ||
if (!equinoxActive || !featureFlags.isEnabled('cx114-176')) { | ||
if (!configurations.EQUINOX_ACTIVE || !featureFlags.isEnabled('cx114-176')) { | ||
const storeAsync = async () => { | ||
@@ -378,5 +410,2 @@ if (!anonymousCartId) { | ||
useEffect(() => { | ||
// console.log('ShoppingContext', shoppingContext); | ||
// console.log('locale', localeState); | ||
let country = InitialValue; | ||
@@ -399,44 +428,9 @@ let language = InitialValue; | ||
}, [localeState.locale, shoppingContext]); | ||
async function getConfgs() { | ||
const promises = [localization.loadLocalization(), configuration.getConfigState(), AsyncStorage.getItem(CartIdKey)]; | ||
const results = await Promise.all(promises); | ||
// now using the results array again! | ||
const configs = results[1]; | ||
let savedCartInfo = JSON.parse(results[2]); | ||
if (!savedCartInfo || !savedCartInfo.anonymousCartMap) { | ||
savedCartInfo = { | ||
anonymousCartMap: {}, | ||
userId: '' | ||
}; | ||
} | ||
console.log('Cart: saved cartInfo', savedCartInfo); | ||
setAnonymousCartMap(savedCartInfo.anonymousCartMap); | ||
console.log('Cart: configs', configs); | ||
setShoppingContext(configs.VERA_SHOPPING_CONTEXT || configs.STELA_SHOPPING_CONTEXT); | ||
setCloudUrl(`${configs.NUSKIN_CLOUD_URL}`); | ||
setCartUrl(`${configs.NUSKIN_CLOUD_URL}/cart/v2`); | ||
setNuskinUrl(`${configs.NUSKIN_URL}`); | ||
setClientId(configs.CUSTOMER_API_CLIENT_ID); | ||
setClientSecret(configs.CUSTOMER_API_CLIENT_SECRET); | ||
setKrCartApiUrl(configs.KR_CART_API_URL); | ||
setKrCartUrl(configs.KR_CART_URL); | ||
setKrApiClient(configs.KR_API_CLIENT); | ||
setKrApiKey(configs.KR_API_KEY); | ||
setEquinoxActive(configs.EQUINOX_ACTIVE); | ||
setBaseURL(configs.EQUINOX_API_BASE_URL); | ||
setStoreId(configs.EQUINOX_STORE_ID); | ||
let loc = localeState.locale.language + '_' + localeState.locale.country; | ||
setLocale(loc); | ||
setCountryFlag(1); | ||
} | ||
useEffect(() => { | ||
getConfgs(); | ||
}, [country]); | ||
useEffect(() => { | ||
(async () => { | ||
if (baseURL !== undefined && locale !== undefined && storeId !== undefined && equinoxActive && featureFlags.isEnabled('cx114-176')) { | ||
if (baseURL !== undefined && locale !== undefined && configurations.EQUINOX_STORE_ID !== undefined && configurations.EQUINOX_ACTIVE && featureFlags.isEnabled('cx114-176')) { | ||
getAnnonymousSessionId(); | ||
} | ||
})(); | ||
}, [baseURL, locale, storeId]); | ||
}, [storeId]); | ||
async function getAnnonymousSessionId() { | ||
@@ -452,3 +446,3 @@ const sessionToken = await AsyncStorage.getItem('sessionID'); | ||
console.log('Get Customer Api Called...'); | ||
console.log('Base API is ...', baseURL, locale, storeId); | ||
console.log('Base API is ...', baseURL, locale, configurations.EQUINOX_STORE_ID); | ||
await getEquinoxUser(GetCustomerAPICallValue.Anonymous); | ||
@@ -460,3 +454,3 @@ const storedSession = await AsyncStorage.getItem('sessionID'); | ||
(async () => { | ||
if (equinoxActive && featureFlags.isEnabled('cx114-176') && sessionID !== undefined) { | ||
if (configurations.EQUINOX_ACTIVE && featureFlags.isEnabled('cx114-176') && sessionID !== undefined) { | ||
getCartItems(); | ||
@@ -468,3 +462,3 @@ } | ||
(async () => { | ||
if (equinoxActive && featureFlags.isEnabled('cx114-176')) { | ||
if (configurations.EQUINOX_ACTIVE && featureFlags.isEnabled('cx114-176')) { | ||
if (countryFlag == 1) { | ||
@@ -487,4 +481,4 @@ getCartItems(); | ||
let header; | ||
console.log('Inside getCartItems'); | ||
if (isAuthenticated === true) { | ||
console.log('Authenticated header'); | ||
let token = await getAccessToken(); | ||
@@ -500,2 +494,3 @@ console.log('Token', token); | ||
} | ||
console.log('API details-->' + baseURL, ',', localeState.locale.language + '_' + localeState.locale.country, ',', configurations.EQUINOX_STORE_ID, ',', JSON.stringify(header)); | ||
try { | ||
@@ -507,4 +502,4 @@ var _response$data, _response$data2, _response$data2$value; | ||
params: { | ||
locale: locale, | ||
storeId: storeId | ||
locale: localeState.locale.language + '_' + localeState.locale.country, | ||
storeId: configurations.EQUINOX_STORE_ID | ||
}, | ||
@@ -518,2 +513,3 @@ headers: header | ||
setQuantity(response.data.value.count); | ||
console.log('count-->', response.data.value.count); | ||
} | ||
@@ -535,3 +531,3 @@ } catch (err) { | ||
console.log('NextGenApi.tsx -> getXSkSessionId - Equinox API Response', response.data.email, response.headers); | ||
await AsyncStorage.setItem('isCartMerged', 'true'); | ||
//await AsyncStorage.setItem('isCartMerged', 'true'); | ||
await getCartItems(); | ||
@@ -538,0 +534,0 @@ } else { |
{ | ||
"name": "@nuskin/mobile-cart", | ||
"private": false, | ||
"version": "2.1.8", | ||
"version": "2.1.9", | ||
"repository": { | ||
@@ -142,3 +142,3 @@ "type": "git", | ||
}, | ||
"commithash": "26f324d58637add55655e6b41acc7ac8489a4049", | ||
"commithash": "981e0952930bc93e0822fb10c19f628d0c80f2da", | ||
"author": { | ||
@@ -145,0 +145,0 @@ "name": "Ranjani Mohan", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
258838
181
3460