How to use the @shopgate/pwa-core.PipelineRequest function in @shopgate/pwa-core

To help you get started, we’ve selected a few @shopgate/pwa-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github shopgate / pwa / libraries / common / actions / user / fetchUser.js View on Github external
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);
github shopgate / pwa / libraries / common / actions / user / getUser.js View on Github external
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:
github shopgate / pwa / libraries / commerce / cart / actions / addCouponsToCart.js View on Github external
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],
github shopgate / pwa / libraries / common / actions / page / fetchPageConfig.js View on Github external
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));
      });
  };
}
github shopgate / pwa / libraries / common / actions / page / getPageConfig.js View on Github external
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));
      });
  };
}
github shopgate / pwa / libraries / common / actions / user / logout.js View on Github external
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());
      });
  };
}
github shopgate / pwa / libraries / common / actions / user / fetchRegisterUrl.js View on Github external
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();
        });
    });
  };
github shopgate / pwa / libraries / common / actions / user / login.js View on Github external
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));
github shopgate / pwa / libraries / common / actions / menu / fetchMenu.js View on Github external
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));
      });
  };
}