How to use the @shopgate/pwa-core/classes/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 / commerce / product / actions / fetchProducts.js View on Github external
}

      return null;
    }

    // Fire the onBeforeDispatch callback to inform a caller that fetchProducts will return data.
    onBeforeDispatch();

    dispatch(requestProducts({
      hash,
      cached,
      cachedTime,
      requestParams,
    }));

    return new PipelineRequest(pipeline)
      .setInput(requestParams)
      .dispatch()
      .then((response) => {
        let totalResultCount = response.totalProductCount;

        /**
         * When the next check was written, getHighlightProducts and getLiveshoppingProducts
         * didn't deliver a totalProductCount within their responses - they simply returned all
         * available products.
         * So we set the products count of the response as totalProductCount to decrease the
         * amount of logic, which is necessary to deal with product related pipelines.
         */
        if (
          typeof totalResultCount === 'undefined' &&
          (
            pipeline === pipelines.SHOPGATE_CATALOG_GET_HIGHLIGHT_PRODUCTS ||
github shopgate / pwa / libraries / common / actions / user / fetchRegisterUrl.js View on Github external
return new Promise((resolve, reject) => {
    if (shouldFetchData(getEntryByType(URL_TYPE_REGISTER, state), 'url')) {
      dispatch(requestUrl(URL_TYPE_REGISTER));

      new PipelineRequest('shopgate.user.getRegistrationUrl')
        .setTrusted()
        .dispatch()
        .then(({ url, expires }) => {
          dispatch(receiveUrl(URL_TYPE_REGISTER, url, expires));
          resolve(url);
        })
        .catch((error) => {
          logger.error(error);
          dispatch(errorUrl(URL_TYPE_REGISTER));
          reject();
        });
    } else {
      // The registrationUrl is still valid
      resolve(getRegisterUrl(state));
    }
  });
github shopgate / pwa / libraries / commerce / product / actions / getProductOptions.js View on Github external
const getProductOptions = productId => (dispatch, getState) => {
  const state = getState();
  const cachedData = state.product.optionsByProductId[productId];

  if (!shouldFetchData(cachedData)) {
    return;
  }

  dispatch(requestProductOptions(productId));

  new PipelineRequest('shopgate.catalog.getProductOptions')
    .setInput({ productId })
    .dispatch()
    .then(result => dispatch(receiveProductOptions(productId, result.options)))
    .catch((error) => {
      logger.error(error);
      dispatch(errorProductOptions(productId));
    });
};
github shopgate / pwa / libraries / common / actions / user / login.js View on Github external
export default ({ login, password }) => (dispatch) => {
  dispatch(requestLogin(login, password));

  const params = {
    strategy: 'basic',
    parameters: {
      login,
      password,
    },
  };

  new PipelineRequest('shopgate.user.loginUser')
    .setTrusted()
    .setHandledErrors([EINVALIDCALL])
    .setInput(params)
    .dispatch()
    .then(({ success, messages }) => {
      if (success) {
        dispatch(successLogin());
      } else {
        dispatch(errorLogin(messages));
      }
    })
    .catch((error) => {
      const { code } = error;

      if (code === EINVALIDCALL) {
        /**
github shopgate / pwa / libraries / commerce / reviews / actions / fetchReviews.js View on Github external
) => (dispatch) => {
  const hash = generateResultHash({
    pipeline: pipelines.SHOPGATE_CATALOG_GET_PRODUCT_REVIEWS,
    productId,
  }, false);
  dispatch(requestProductReviewsList(hash));

  /**
   * For testing purposes there's need to keep and return the promise reference, not a result of
   * chained functions.
   * Otherwise test case won't get the original resolver.
   * To get more insights, please take a look at ../spec.js.
   * @type {Promise}
   */
  const request = new PipelineRequest(pipelines.SHOPGATE_CATALOG_GET_PRODUCT_REVIEWS)
    .setInput({
      productId,
      limit,
      offset,
      sort,
    })
    .dispatch();

  request
    .then((result) => {
      dispatch(receiveProductReviewsList(hash, productId, result.reviews, result.totalReviewCount));
    })
    .catch((error) => {
      logger.error(error);
      dispatch(errorProductReviewsList(hash));
    });
github shopgate / pwa / libraries / commerce / product / actions / getProductDescription.js View on Github external
const getProductDescription = productId => (dispatch, getState) => {
  const state = getState();
  const description = state.product.descriptionsByProductId[productId];

  if (!shouldFetchData(description)) {
    return;
  }

  dispatch(requestProductDescription(productId));

  new PipelineRequest('shopgate.catalog.getProductDescription')
    .setInput({ productId })
    .dispatch()
    .then(result => dispatch(receiveProductDescription(productId, result.description)))
    .catch((error) => {
      logger.error(error);
      dispatch(errorProductDescription(productId));
    });
};
github shopgate / pwa / libraries / commerce / favorites / actions / getFavorites.js View on Github external
const getFavorites = (ignoreCache = false) => (dispatch, getState) => {
  const data = getState().favorites.products;
  if (!ignoreCache && !shouldFetchData(data)) {
    return new Promise(res => res());
  }
  const timestamp = Date.now();
  dispatch(requestFavorites());
  const promise = new PipelineRequest('shopgate.user.getFavorites')
    .setHandledErrors([EFAVORITE, EUNKNOWN, EBIGAPI])
    .dispatch();
  promise
    .then((result) => {
      dispatch(receiveFavorites(result.products, timestamp));
    })
    .catch((err) => {
      logger.error(err);
      dispatch(errorFetchFavorites(err));
    });
  return promise;
};
github shopgate / pwa / libraries / commerce / product / actions / fetchProduct.js View on Github external
if (!forceFetch && !shouldFetchData(product)) {
    if (product.productData) {
      dispatch(receiveProductCached(product.productData));
    }

    return;
  }

  const requestParams = {
    ...configuration.get(DEFAULT_PRODUCTS_FETCH_PARAMS),
    productId,
  };

  dispatch(requestProduct(productId, forceFetch));

  new PipelineRequest(pipelines.SHOPGATE_CATALOG_GET_PRODUCT)
    .setInput(requestParams)
    .dispatch()
    .then((result) => {
      dispatch(receiveProduct(productId, result));
    })
    .catch((error) => {
      logger.error(error);
      dispatch(errorProduct(productId, error.code));
    });
};
github shopgate / pwa / libraries / commerce / product / actions / fetchProductOptions.js View on Github external
const fetchProductOptions = productId => (dispatch, getState) => {
  const state = getState();
  const cachedData = state.product.optionsByProductId[productId];

  if (!shouldFetchData(cachedData)) {
    return;
  }

  dispatch(requestProductOptions(productId));

  new PipelineRequest(pipelines.SHOPGATE_CATALOG_GET_PRODUCT_OPTIONS)
    .setInput({ productId })
    .dispatch()
    .then(result => dispatch(receiveProductOptions(productId, result.options)))
    .catch((error) => {
      logger.error(error);
      dispatch(errorProductOptions(productId, error.code));
    });
};
github shopgate / pwa / libraries / commerce / category / actions / fetchCategoryChildren.js View on Github external
const fetchCategoryChildren = categoryId => (dispatch, getState) => {
  const state = getState();
  const category = state.category.childrenByCategoryId[categoryId];

  if (!shouldFetchData(category, 'children')) {
    return;
  }

  dispatch(requestCategoryChildren(categoryId));

  new PipelineRequest(pipelines.SHOPGATE_CATALOG_GET_CATEGORY_CHILDREN)
    .setInput({ categoryId })
    .dispatch()
    .then(result => dispatch(receiveCategoryChildren(categoryId, result.categories)))
    .catch((error) => {
      logger.error(error);
      dispatch(errorCategoryChildren(categoryId));
    });
};