Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return (dispatch, getState) => {
dispatch(actions.requestUser());
return new PipelineRequest(pipelines.SHOPGATE_USER_GET_USER)
.setTrusted()
.setErrorBlacklist([EACCESS])
.dispatch()
.then((user) => {
dispatch(actions.receiveUser(user));
// If the user's login state was incorrectly set false then set to true.
if (!isUserLoggedIn(getState())) {
dispatch(actions.toggleLoggedIn(true));
}
return user;
})
.catch((error) => {
if (error.code !== EACCESS) {
logger.error(error);
return (dispatch, getState) => {
dispatch(actions.requestUser());
return new PipelineRequest(pipelines.SHOPGATE_USER_GET_USER)
.setTrusted()
.setErrorBlacklist([EACCESS])
.dispatch()
.then((user) => {
dispatch(actions.receiveUser(user));
// If the user's login state was incorrectly set false then set to true.
if (!isUserLoggedIn(getState())) {
dispatch(actions.toggleLoggedIn(true));
}
return user;
})
.catch((error) => {
switch (error.code) {
case EACCESS:
const addCouponsToCart = couponIds => dispatch => new Promise((resolve, reject) => {
dispatch(addCoupons(couponIds));
const request = new PipelineRequest(pipelines.SHOPGATE_CART_ADD_COUPONS);
request.setInput({ couponCodes: couponIds })
.setResponseProcessed(PROCESS_SEQUENTIAL)
.setRetries(0)
.setErrorBlacklist(ECART)
.dispatch()
.then(({ messages }) => {
/**
* @deprecated: The property "messages" is not supposed to be part of the pipeline response.
* Specification demands errors to be returned as response object with an "error" property.
* This code snippet needs to be removed after fixing the `@shopgate/legacy-cart` extension.
*/
if (messages && messagesHaveErrors(messages)) {
// Simulate a pipeline response error with a proper ECART error.
const errors = messages.filter(msg => msg.type === MESSAGE_TYPE_ERROR);
const error = {
...errors[0],
return (dispatch, getState) => {
const state = getState();
const pageConfig = getPageConfigById(state, { pageId });
if (!shouldFetchData(pageConfig)) {
return null;
}
dispatch(actions.requestPageConfig(pageId));
return new PipelineRequest(pipelines.SHOPGATE_CMS_GET_PAGE_CONFIG)
.setInput({ pageId })
.dispatch()
.then(result => dispatch(actions.receivePageConfig(pageId, result)))
.catch((error) => {
logger.error(error);
dispatch(actions.errorPageConfig(pageId, error.code));
});
};
}
return (dispatch, getState) => {
const state = getState();
const pageConfig = getPageConfigById(state, { pageId });
if (!force && !shouldFetchData(pageConfig)) {
return null;
}
dispatch(actions.requestPageConfig(pageId));
return new PipelineRequest(pipelines.SHOPGATE_CMS_GET_PAGE_CONFIG)
.setInput({ pageId })
.dispatch()
.then(result => dispatch(actions.receivePageConfig(pageId, result)))
.catch((error) => {
logger.error(error);
dispatch(actions.errorPageConfig(pageId));
});
};
}
return (dispatch) => {
dispatch(actions.requestLogout());
new PipelineRequest(pipelines.SHOPGATE_USER_LOGOUT_USER)
.setTrusted()
.dispatch()
.then(({ success, messages }) => {
if (success) {
dispatch(actions.successLogout());
} else {
dispatch(actions.errorLogout(messages));
}
})
.catch((error) => {
logger.error(error);
dispatch(actions.errorLogout());
});
};
}
return new Promise((resolve, reject) => {
if (!shouldFetchData(entry, 'url')) {
resolve(getRegisterUrl(state));
return;
}
dispatch(actions.requestUrl(URL_TYPE_REGISTER));
new PipelineRequest(pipelines.SHOPGATE_USER_GET_REGISTRATION_URL)
.setTrusted()
.dispatch()
.then(({ url, expires }) => {
dispatch(actions.receiveUrl(URL_TYPE_REGISTER, url, expires));
resolve(url);
})
.catch((error) => {
logger.error(error);
dispatch(actions.errorUrl(URL_TYPE_REGISTER));
reject();
});
});
};
return (dispatch) => {
dispatch(actions.requestLogin(parameters.login, parameters.password, strategy));
new PipelineRequest(SHOPGATE_USER_LOGIN_USER)
.setTrusted()
.setErrorBlacklist([
EINVALIDCALL,
ELEGACYSGCONNECT,
EINCOMPLETELOGIN,
])
.setInput({
strategy,
parameters,
})
.dispatch()
.then(({ success, messages }) => {
if (success) {
dispatch(actions.successLogin(redirect, strategy));
} else {
dispatch(actions.errorLogin(messages));
return (dispatch) => {
dispatch(actions.requestMenu(id));
new PipelineRequest(pipelines.SHOPGATE_CMS_GET_MENU)
.setInput({ id })
.dispatch()
.then((response) => {
dispatch(actions.receiveMenu(id, response.entries));
})
.catch((error) => {
logger.error(error);
dispatch(actions.errorMenu(id));
});
};
}