@shopgate/pwa-common-commerce 7.12.0-beta.2 → 7.12.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopgate/pwa-common-commerce",
3
- "version": "7.12.0-beta.2",
3
+ "version": "7.12.0-beta.4",
4
4
  "description": "Commerce library for the Shopgate Connect PWA.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Shopgate <support@shopgate.com>",
@@ -19,8 +19,8 @@
19
19
  "reselect": "^3.0.1"
20
20
  },
21
21
  "devDependencies": {
22
- "@shopgate/pwa-common": "7.12.0-beta.2",
23
- "@shopgate/pwa-core": "7.12.0-beta.2",
22
+ "@shopgate/pwa-common": "7.12.0-beta.4",
23
+ "@shopgate/pwa-core": "7.12.0-beta.4",
24
24
  "lodash": "^4.17.4",
25
25
  "react": "~16.12.0",
26
26
  "react-dom": "~16.12.0"
@@ -1,4 +1,4 @@
1
- function _objectWithoutProperties(source,excluded){if(source==null)return{};var target=_objectWithoutPropertiesLoose(source,excluded);var key,i;if(Object.getOwnPropertySymbols){var sourceSymbolKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceSymbolKeys.length;i++){key=sourceSymbolKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key];}}return target;}function _objectWithoutPropertiesLoose(source,excluded){if(source==null)return{};var target={};var sourceKeys=Object.keys(source);var key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;target[key]=source[key];}return target;}function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}import difference from'lodash/difference';import PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';import{generateResultHash,shouldFetchData}from'@shopgate/pwa-common/helpers/redux';import{isNumber}from'@shopgate/pwa-common/helpers/validation';import configuration from'@shopgate/pwa-common/collections/Configuration';import{DEFAULT_PRODUCTS_FETCH_PARAMS}from'@shopgate/pwa-common/constants/Configuration';import{SORT_SCOPE_CATEGORY}from'@shopgate/engage/filter/constants';import{makeGetDefaultSortOrder}from'@shopgate/engage/filter/selectors';import{getFulfillmentParams}from'@shopgate/pwa-common-commerce/product/selectors/product';import{SHOPGATE_CATALOG_GET_PRODUCTS,SHOPGATE_CATALOG_GET_HIGHLIGHT_PRODUCTS,SHOPGATE_CATALOG_GET_LIVESHOPPING_PRODUCTS}from"../constants/Pipelines";import buildRequestFilters from"../../filter/actions/helpers/buildRequestFilters";import requestProducts from"../action-creators/requestProducts";import receiveProducts from"../action-creators/receiveProducts";import errorProducts from"../action-creators/errorProducts";import deleteProductsByIds from"../action-creators/deleteProductsByIds";import receiveProductsCached from"../action-creators/receiveProductsCached";/**
1
+ function _objectWithoutProperties(source,excluded){if(source==null)return{};var target=_objectWithoutPropertiesLoose(source,excluded);var key,i;if(Object.getOwnPropertySymbols){var sourceSymbolKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceSymbolKeys.length;i++){key=sourceSymbolKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key];}}return target;}function _objectWithoutPropertiesLoose(source,excluded){if(source==null)return{};var target={};var sourceKeys=Object.keys(source);var key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;target[key]=source[key];}return target;}function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}import difference from'lodash/difference';import PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';import{generateResultHash,shouldFetchData}from'@shopgate/pwa-common/helpers/redux';import{isNumber}from'@shopgate/pwa-common/helpers/validation';import configuration from'@shopgate/pwa-common/collections/Configuration';import{DEFAULT_PRODUCTS_FETCH_PARAMS}from'@shopgate/pwa-common/constants/Configuration';import{SORT_SCOPE_CATEGORY}from'@shopgate/engage/filter/constants';import{makeGetDefaultSortOrder}from'@shopgate/engage/filter/selectors';import{getFulfillmentParams}from'@shopgate/pwa-common-commerce/product/selectors/product';import{SHOPGATE_CATALOG_GET_PRODUCTS,SHOPGATE_CATALOG_GET_HIGHLIGHT_PRODUCTS,SHOPGATE_CATALOG_GET_LIVESHOPPING_PRODUCTS}from"../constants/Pipelines";import buildRequestFilters from"../../filter/actions/helpers/buildRequestFilters";import requestProducts from"../action-creators/requestProducts";import receiveProducts from"../action-creators/receiveProducts";import errorProducts from"../action-creators/errorProducts";import deleteProductsByIds from"../action-creators/deleteProductsByIds";import receiveProductsCached from"../action-creators/receiveProductsCached";import{makeGetProductResultByCustomHash}from"../selectors/product";/**
2
2
  * Process the pipeline params to be compatible.
3
3
  * Currently the categoryId field cannot be used in combination with the filter field. In order to
4
4
  * use them together the categoryId field has to be extracted into the filter field.
@@ -16,6 +16,7 @@ function _objectWithoutProperties(source,excluded){if(source==null)return{};var
16
16
  * @param {Object} options The options for the getProducts request.
17
17
  * @param {Object} options.params The params for the getProduct pipeline.
18
18
  * @param {string} [options.pipeline='getProducts'] The pipeline to call.
19
+ * @param {Object} [options.filters = null] Filters object for the request
19
20
  * @param {boolean} [options.cached=true] If the result will be cached.
20
21
  * @param {?number} [options.cachedTime=null] Cache TTL in ms.
21
22
  * @param {?string} [options.id=null] A unique id for the component that is using this action.
@@ -25,15 +26,17 @@ function _objectWithoutProperties(source,excluded){if(source==null)return{};var
25
26
  * into the product hash and the request.
26
27
  * @param {Function} [options.onBeforeDispatch=() => {}] A callback which is fired, before new data
27
28
  * will be returned.
29
+ * @param {boolean} [options.resolveCachedProducts=false] Whether to resolve with products even
30
+ * when no actual request was done due to cached data.
28
31
  * @return {Function} A Redux Thunk
29
- */function fetchProducts(options){var _options$params=options.params,params=_options$params===void 0?{}:_options$params,_options$filters=options.filters,filters=_options$filters===void 0?null:_options$filters,_options$pipeline=options.pipeline,pipeline=_options$pipeline===void 0?SHOPGATE_CATALOG_GET_PRODUCTS:_options$pipeline,_options$cached=options.cached,cached=_options$cached===void 0?true:_options$cached,_options$cachedTime=options.cachedTime,cachedTime=_options$cachedTime===void 0?null:_options$cachedTime,_options$id=options.id,id=_options$id===void 0?null:_options$id,_options$includeSort=options.includeSort,includeSort=_options$includeSort===void 0?true:_options$includeSort,_options$includeFilte=options.includeFilters,includeFilters=_options$includeFilte===void 0?true:_options$includeFilte,_options$includeFulfi=options.includeFulfillment,includeFulfillment=_options$includeFulfi===void 0?true:_options$includeFulfi,_options$onBeforeDisp=options.onBeforeDispatch,onBeforeDispatch=_options$onBeforeDisp===void 0?function(){}:_options$onBeforeDisp;return function(dispatch,getState){var state=getState();var offset=params.offset,limit=params.limit,hashParams=_objectWithoutProperties(params,["offset","limit"]);var defaultSort=getDefaultSortOrder(state,{scope:SORT_SCOPE_CATEGORY});var _hashParams$sort=hashParams.sort,sort=_hashParams$sort===void 0?defaultSort:_hashParams$sort;var getProductsRequestParams;if(pipeline===SHOPGATE_CATALOG_GET_PRODUCTS){getProductsRequestParams=configuration.get(DEFAULT_PRODUCTS_FETCH_PARAMS);}// Append additional global fulfillment parameters.
32
+ */function fetchProducts(options){var _options$params=options.params,params=_options$params===void 0?{}:_options$params,_options$filters=options.filters,filters=_options$filters===void 0?null:_options$filters,_options$pipeline=options.pipeline,pipeline=_options$pipeline===void 0?SHOPGATE_CATALOG_GET_PRODUCTS:_options$pipeline,_options$cached=options.cached,cached=_options$cached===void 0?true:_options$cached,_options$cachedTime=options.cachedTime,cachedTime=_options$cachedTime===void 0?null:_options$cachedTime,_options$id=options.id,id=_options$id===void 0?null:_options$id,_options$includeSort=options.includeSort,includeSort=_options$includeSort===void 0?true:_options$includeSort,_options$includeFilte=options.includeFilters,includeFilters=_options$includeFilte===void 0?true:_options$includeFilte,_options$includeFulfi=options.includeFulfillment,includeFulfillment=_options$includeFulfi===void 0?true:_options$includeFulfi,_options$onBeforeDisp=options.onBeforeDispatch,onBeforeDispatch=_options$onBeforeDisp===void 0?function(){}:_options$onBeforeDisp,_options$resolveCache=options.resolveCachedProducts,resolveCachedProducts=_options$resolveCache===void 0?false:_options$resolveCache;return function(dispatch,getState){var state=getState();var offset=params.offset,limit=params.limit,hashParams=_objectWithoutProperties(params,["offset","limit"]);var defaultSort=getDefaultSortOrder(state,{scope:SORT_SCOPE_CATEGORY});var _hashParams$sort=hashParams.sort,sort=_hashParams$sort===void 0?defaultSort:_hashParams$sort;var getProductsRequestParams;if(pipeline===SHOPGATE_CATALOG_GET_PRODUCTS){getProductsRequestParams=configuration.get(DEFAULT_PRODUCTS_FETCH_PARAMS);}// Append additional global fulfillment parameters.
30
33
  var fulfillmentParams={};if(includeFulfillment&&pipeline===SHOPGATE_CATALOG_GET_PRODUCTS){fulfillmentParams=getFulfillmentParams(state);}// We need to process the params to handle edge cases in the pipeline params.
31
34
  var requestParams=_extends({},fulfillmentParams,{},getProductsRequestParams,{},processParams(params,filters,includeSort,includeFilters));var hash=generateResultHash(_extends({pipeline:pipeline,sort:sort},fulfillmentParams,{},hashParams,{},filters&&Object.keys(filters).length&&{filters:filters},{},id&&{id:id}),includeSort,includeFilters);var result=state.product.resultsByHash[hash];var requiredProductCount=null;// Only set a required number of products if both offset and limit are valid.
32
35
  if(isNumber(offset)&&isNumber(limit)){requiredProductCount=offset+limit;}// Stop if we don't need to get any data.
33
36
  if(!shouldFetchData(result,'products',requiredProductCount)){var products=result.products;if(Array.isArray(products)){/**
34
37
  * Fire the onBeforeDispatch callback to inform
35
38
  * a caller that fetchProducts will return data.
36
- */onBeforeDispatch();dispatch(receiveProductsCached({hash:hash,requestParams:requestParams,products:products}));return Promise.resolve(result);}return null;}// Fire the onBeforeDispatch callback to inform a caller that fetchProducts will return data.
39
+ */onBeforeDispatch();dispatch(receiveProductsCached({hash:hash,requestParams:requestParams,products:products}));return Promise.resolve(resolveCachedProducts?makeGetProductResultByCustomHash(hash)(state):result);}return null;}// Fire the onBeforeDispatch callback to inform a caller that fetchProducts will return data.
37
40
  onBeforeDispatch();dispatch(requestProducts({hash:hash,cached:cached,cachedTime:cachedTime,requestParams:requestParams}));var request=new PipelineRequest(pipeline).setInput(requestParams).dispatch();request.then(function(response){var totalResultCount=response.totalProductCount;/**
38
41
  * When the next check was written, getHighlightProducts and getLiveshoppingProducts
39
42
  * didn't deliver a totalProductCount within their responses - they simply returned all
@@ -254,6 +254,11 @@ var _ref5=images[baseProductId]||{},baseProductImages=_ref5.images;if(!Array.isA
254
254
  * @param {Object} props The component props.
255
255
  * @returns {Object} The product result.
256
256
  */export var getProductsResult=createSelector(function(state){return state;},function(state,props){return props;},getResultHash,getResultByHash,getPopulatedProductsResult);/**
257
+ * Selector factory which creates a selector to retrieve a product results object based on a custom
258
+ * hash string.
259
+ * @param {string} hash A resultsByHash hash string
260
+ * @returns {Function}
261
+ */export var makeGetProductResultByCustomHash=function makeGetProductResultByCustomHash(hash){var parsedHash=JSON.parse(hash);return createSelector(function(state){return state;},function(state,props){return props;},getProductState,function(state,props,productState){var searchPhrase=props.searchPhrase;var products=[];var totalProductCount=!hash?0:null;var sort=(parsedHash===null||parsedHash===void 0?void 0:parsedHash.sort)||getSortOrder(state,_extends({},props,{scope:typeof searchPhrase==='undefined'?SORT_SCOPE_CATEGORY:SORT_SCOPE_SEARCH}));var result=productState.resultsByHash[hash];if(result&&result.products){totalProductCount=result.totalResultCount;products=result.products.map(function(productId){return getProductById(state,{productId:productId}).productData;});}return{products:products,totalProductCount:totalProductCount,sort:sort,hash:hash};});};/**
257
262
  * Selector mappings for PWA < 6.0
258
263
  * @deprecated
259
264
  */export var getCurrentProduct=getProduct;export var getCurrentProductId=getProductId;export var getCurrentBaseProductId=getBaseProductId;export var getCurrentBaseProduct=getBaseProduct;export var getCurrentProductStock=getProductStock;export var getProductStockInfo=getProductStock;export var getProductBasePrice=getProductUnitPrice;export var isOrderable=isProductOrderable;
@@ -1,8 +1,17 @@
1
1
  function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}import{ITEMS_PER_LOAD}from'@shopgate/pwa-common/constants/DisplayOptions';import{mutable}from'@shopgate/pwa-common/helpers/redux';import{makeGetDefaultSortOrder}from'@shopgate/engage/filter/selectors';import fetchProducts from"../../product/actions/fetchProducts";import requestSearchResults from"../action-creators/requestSearchResults";import receiveSearchResults from"../action-creators/receiveSearchResults";import errorSearchResults from"../action-creators/errorSearchResults";var getDefaultSortOrder=makeGetDefaultSortOrder();/**
2
2
  * Retrieves products for a certain search query.
3
- * @param {number} params The params for the products to request.
3
+ * @param {Object} params The params for the search products to request.
4
+ * @param {string} params.searchPhrase Search phrase for the request
5
+ * @param {number} [params.offset=0] Offset for the request
6
+ * @param {number} [params.limit=ITEMS_PER_LOAD] Limit for the request
7
+ * @param {string} [params.sort=DEFAULT_SORT] Limit for the request
8
+ * @param {Object} [params.filters = null] Filters object for the request
9
+ * @param {Object} [params.params = null] Additional params for the fetchProducts pipeline request
10
+ * @param {number} [params.cachedTime=null] Cache TTL in ms.
11
+ * @param {boolean} [params.resolveCachedProducts=false] Whether to resolve with products even
12
+ * when no actual request was done due to cached data.
4
13
  * @return {Function} The dispatched action.
5
- */var fetchSearchResults=function fetchSearchResults(params){return function(dispatch,getState){var defaultSortOrder=getDefaultSortOrder(getState(),{searchPhrase:params.searchPhrase});var _params$offset=params.offset,offset=_params$offset===void 0?0:_params$offset,searchPhrase=params.searchPhrase,_params$limit=params.limit,limit=_params$limit===void 0?ITEMS_PER_LOAD:_params$limit,_params$sort=params.sort,sort=_params$sort===void 0?defaultSortOrder:_params$sort,_params$filters=params.filters,filters=_params$filters===void 0?null:_params$filters,_params$params=params.params,searchParams=_params$params===void 0?null:_params$params,_params$cachedTime=params.cachedTime,cachedTime=_params$cachedTime===void 0?null:_params$cachedTime;if(!searchPhrase){return;}var promise=dispatch(fetchProducts({cachedTime:cachedTime,params:_extends({searchPhrase:searchPhrase,offset:offset,limit:limit,sort:sort},searchParams),filters:filters,onBeforeDispatch:function onBeforeDispatch(){// Dispatch the request action before the related pipeline request is executed.
14
+ */var fetchSearchResults=function fetchSearchResults(params){return function(dispatch,getState){var defaultSortOrder=getDefaultSortOrder(getState(),{searchPhrase:params.searchPhrase});var _params$offset=params.offset,offset=_params$offset===void 0?0:_params$offset,searchPhrase=params.searchPhrase,_params$limit=params.limit,limit=_params$limit===void 0?ITEMS_PER_LOAD:_params$limit,_params$sort=params.sort,sort=_params$sort===void 0?defaultSortOrder:_params$sort,_params$filters=params.filters,filters=_params$filters===void 0?null:_params$filters,_params$params=params.params,searchParams=_params$params===void 0?null:_params$params,_params$cachedTime=params.cachedTime,cachedTime=_params$cachedTime===void 0?null:_params$cachedTime,_params$resolveCached=params.resolveCachedProducts,resolveCachedProducts=_params$resolveCached===void 0?false:_params$resolveCached;if(!searchPhrase){return;}var promise=dispatch(fetchProducts({cachedTime:cachedTime,params:_extends({searchPhrase:searchPhrase,offset:offset,limit:limit,sort:sort},searchParams),filters:filters,resolveCachedProducts:resolveCachedProducts,onBeforeDispatch:function onBeforeDispatch(){// Dispatch the request action before the related pipeline request is executed.
6
15
  dispatch(requestSearchResults(searchPhrase,offset));}}));/**
7
16
  * Whenever fetchProducts is able to deliver product data
8
17
  * - either via a request or from the cache -