@shopgate/pwa-common-commerce 7.27.4 → 7.27.5-alpha.1

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.
@@ -2,9 +2,10 @@ import PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';import{s
2
2
  * Fetches the data for a given category ID (including child categories).
3
3
  * @param {string} categoryId The category ID.
4
4
  * @return {Function} The dispatched action.
5
- */function fetchCategory(categoryId){return function(dispatch,getState){var category=getCategory(getState(),{categoryId:categoryId});if(!shouldFetchData(category)){/**
5
+ */function fetchCategory(categoryId){return function(dispatch,getState){var category=getCategory(getState(),{categoryId:categoryId});// Check if we need to fetch data
6
+ if(!shouldFetchData(category)){/**
6
7
  * Child categories are maybe missing.
7
8
  * So we need to check it (check happens inside fetchCategoryChildren).
8
9
  * This is the case if we got categories from getRootCategory
9
- */if(category.childrenCount){dispatch(fetchCategoryChildren(categoryId));}return Promise.resolve(category);}// No data at all. So we have the fetch the category with children included
10
+ */if(category.childrenCount){dispatch(fetchCategoryChildren(categoryId));}return Promise.resolve(category);}// No data at all. So we have to fetch the category with children included
10
11
  dispatch(requestCategory(categoryId));var request=new PipelineRequest(SHOPGATE_CATALOG_GET_CATEGORY).setInput({categoryId:categoryId,includeChildren:true}).setResponseBehavior({error:errorBehavior.modal()}).dispatch();request.then(function(result){dispatch(receiveCategory(categoryId,result,result.children||[]));})["catch"](function(error){dispatch(errorCategory(categoryId,error.code));});return request;};}/** @mixes {MutableFunction} */export default mutable(fetchCategory);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopgate/pwa-common-commerce",
3
- "version": "7.27.4",
3
+ "version": "7.27.5-alpha.1",
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": "^4.1.8"
20
20
  },
21
21
  "devDependencies": {
22
- "@shopgate/pwa-common": "7.27.4",
23
- "@shopgate/pwa-core": "7.27.4",
22
+ "@shopgate/pwa-common": "7.27.5-alpha.1",
23
+ "@shopgate/pwa-core": "7.27.5-alpha.1",
24
24
  "lodash": "^4.17.4",
25
25
  "react": "~16.14.0",
26
26
  "react-dom": "~16.14.0"
@@ -1,4 +1,8 @@
1
1
  var _excluded=["offset","limit"];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
+ * Checks if a product ID type is a product identifiers type.
3
+ * @param {string} productIdType The product ID type to check.
4
+ * @returns {boolean}
5
+ */export var isProductIdentifiersProductIdType=function isProductIdentifiersProductIdType(productIdType){return['sku','ean','upc'].includes(productIdType);};/**
2
6
  * Process the pipeline params to be compatible.
3
7
  * Currently the categoryId field cannot be used in combination with the filter field. In order to
4
8
  * use them together the categoryId field has to be extracted into the filter field.
@@ -11,7 +15,7 @@ var _excluded=["offset","limit"];function _objectWithoutProperties(source,exclud
11
15
  */var processParams=function processParams(params,activeFilters){var includeSort=arguments.length>2&&arguments[2]!==undefined?arguments[2]:true;var includeFilters=arguments.length>3&&arguments[3]!==undefined?arguments[3]:true;var filters=buildRequestFilters(activeFilters);var newParams=_extends({},params,{},includeFilters&&filters&&Object.keys(filters).length&&{filters:filters});/**
12
16
  * Check if the sort parameter should be included in the request parameters,
13
17
  * and remove it if necessary.
14
- */if(includeSort===false&&params&&params.sort){delete newParams.sort;}return newParams;};var getDefaultSortOrder=makeGetDefaultSortOrder();/**
18
+ */if(includeSort===false&&params&&params.sort){delete newParams.sort;}if(newParams.productIdType){if(isProductIdentifiersProductIdType(newParams.productIdType)){if(newParams.productIdType==='sku'){newParams.productSkus=newParams.productIds;}else if(newParams.productIdType==='ean'){newParams.productEans=newParams.productIds;}else if(newParams.productIdType==='upc'){newParams.productUpcs=newParams.productIds;}delete newParams.productIds;}}delete newParams.productIdType;return newParams;};var getDefaultSortOrder=makeGetDefaultSortOrder();/**
15
19
  * Retrieves a product from the Redux store.
16
20
  * @param {Object} options The options for the getProducts request.
17
21
  * @param {Object} options.params The params for the getProduct pipeline.
@@ -43,4 +47,4 @@ onBeforeDispatch();dispatch(requestProducts({hash:hash,cached:cached,cachedTime:
43
47
  * available products.
44
48
  * So we set the products count of the response as totalProductCount to decrease the
45
49
  * amount of logic, which is necessary to deal with product related pipeline.
46
- */if(typeof totalResultCount==='undefined'&&(pipeline===SHOPGATE_CATALOG_GET_HIGHLIGHT_PRODUCTS||pipeline===SHOPGATE_CATALOG_GET_LIVESHOPPING_PRODUCTS)){totalResultCount=response.products.length;}dispatch(receiveProducts({hash:hash,requestParams:requestParams,products:response.products,totalResultCount:totalResultCount,cached:cached,cachedTime:cachedTime}));if(Array.isArray(params===null||params===void 0?void 0:params.productIds)){var requestIds=params===null||params===void 0?void 0:params.productIds;var responseIds=response.products.map(function(product){return product.id;});var missingResponseIds=difference(requestIds,responseIds);if(missingResponseIds.length>0){dispatch(deleteProductsByIds(missingResponseIds));}}})["catch"](function(error){dispatch(errorProducts({errorCode:error.code,hash:hash,requestParams:requestParams}));});return request;};}export default fetchProducts;
50
+ */if(typeof totalResultCount==='undefined'&&(pipeline===SHOPGATE_CATALOG_GET_HIGHLIGHT_PRODUCTS||pipeline===SHOPGATE_CATALOG_GET_LIVESHOPPING_PRODUCTS)){totalResultCount=response.products.length;}dispatch(receiveProducts({hash:hash,requestParams:requestParams,products:response.products,totalResultCount:totalResultCount,cached:cached,cachedTime:cachedTime}));if(!isProductIdentifiersProductIdType(params===null||params===void 0?void 0:params.productIdType)&&Array.isArray(params===null||params===void 0?void 0:params.productIds)){var requestIds=params===null||params===void 0?void 0:params.productIds;var responseIds=response.products.map(function(product){return product.id;});var missingResponseIds=difference(requestIds,responseIds);if(missingResponseIds.length>0){dispatch(deleteProductsByIds(missingResponseIds));}}})["catch"](function(error){dispatch(errorProducts({errorCode:error.code,hash:hash,requestParams:requestParams}));});return request;};}export default fetchProducts;
@@ -0,0 +1,65 @@
1
+ // fetchProductsById.d.ts
2
+
3
+ import { ThunkAction } from 'redux-thunk';
4
+ import { AnyAction } from 'redux';
5
+
6
+ export interface FetchProductsResult {
7
+ products: any[];
8
+ totalProductCount: number;
9
+ }
10
+
11
+ export interface FetchProductsConfig {
12
+ /**
13
+ * Array of product IDs to fetch.
14
+ */
15
+ productIds: string[];
16
+ /**
17
+ * Optional unique identifier for the component making the request.
18
+ */
19
+ componentId?: string | null;
20
+ /**
21
+ * Whether to cache the result by hash.
22
+ */
23
+ cached?: boolean;
24
+ /**
25
+ * Whether to include fulfillment information in the response.
26
+ */
27
+ includeFulfillment?: boolean;
28
+ /**
29
+ * Optional type of the product IDs. Needs only to be set if the product IDs are not regular
30
+ * product IDs.
31
+ */
32
+ productIdType?: 'id' | 'sku' | 'ean' | 'upc';
33
+ }
34
+
35
+ /**
36
+ * Dispatches a fetch products action to retrieve products by their IDs.
37
+ */
38
+ declare function fetchProductsById(
39
+ options: FetchProductsConfig
40
+ ): ThunkAction<Promise<FetchProductsResult | void>, any, unknown, AnyAction>;
41
+
42
+ /**
43
+ * Dispatches a fetch products action to retrieve products by their IDs.
44
+ * @deprecated Use the object-based API instead.
45
+ */
46
+ declare function fetchProductsById(
47
+ /**
48
+ * Array of product IDs to fetch.
49
+ */
50
+ productIds: string[],
51
+ /**
52
+ * Optional unique identifier for the component making the request.
53
+ */
54
+ componentId?: string | null,
55
+ /**
56
+ * Whether to cache the result by hash.
57
+ */
58
+ cached?: boolean,
59
+ /**
60
+ * Whether to include fulfillment information in the response.
61
+ */
62
+ includeFulfillment?: boolean
63
+ ): ThunkAction<Promise<FetchProductsResult | void>, any, unknown, AnyAction>;
64
+
65
+ export default fetchProductsById;
@@ -1,10 +1,23 @@
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{getProductDataById}from'@shopgate/engage/product/selectors/product';import{shouldFetchData}from'@shopgate/pwa-common/helpers/redux';import fetchProducts from"./fetchProducts";/**
2
- * Retrieves products by id from the store.
3
- * @param {Array} productIds The product id's to request.
4
- * @param {string} [componentId=null] A unique id for the component that is using this action.
5
- * @param {boolean} [cached=true] cache result by hash
6
- * @param {boolean} [includeFulfillment=true] includes fulfillment
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);}function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}import{getProductDataById}from'@shopgate/engage/product/selectors/product';import{shouldFetchData}from'@shopgate/pwa-common/helpers/redux';import fetchProducts,{isProductIdentifiersProductIdType}from"./fetchProducts";/**
2
+ * Dispatches a fetch products action to retrieve products by their IDs.
3
+ * @param {Object|string[]} optionsOrProductIds Action options or an array of product IDs
4
+ * (deprecated)
5
+ * @param {string[]} params.productIds The product id's to request
6
+ * @param {string} [params.componentId=null] A unique id for the component that is using this action
7
+ * @param {boolean} [params.cached=true] Whether to cache the result by hash
8
+ * @param {boolean} [params.includeFulfillment=true] Whether to include fulfillment data to the
9
+ * request
10
+ *
11
+ * @param {string} [componentId=null] (deprecated) A unique id for the component that is using this
12
+ * action
13
+ * @param {boolean} [cached=true] (deprecated) Whether to cache the result by hash
14
+ * @param {boolean} [includeFulfillment=true] (deprecated) Whether to include fulfillment data to
15
+ * the request
7
16
  * @return {Function} A Redux Thunk
8
- */var fetchProductsById=function fetchProductsById(productIds){var componentId=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var cached=arguments.length>2&&arguments[2]!==undefined?arguments[2]:true;var includeFulfillment=arguments.length>3&&arguments[3]!==undefined?arguments[3]:true;return function(dispatch,getState){var state=getState();var products=state.product.productsById;// Filter out only the products that are not yet available in the store.
9
- var missingIds=productIds.filter(function(id){return shouldFetchData(products[id]);});// Then only perform a pipeline request if there are products missing.
10
- if(!missingIds.length){var productsById=productIds.map(function(id){return getProductDataById(state,{productId:id});});var totalProductCount=productsById.length;return{products:productsById,totalProductCount:totalProductCount};}return dispatch(fetchProducts(_extends({},componentId&&{id:componentId},{cached:cached,params:{productIds:missingIds},includeFulfillment:includeFulfillment,includeFilters:false,includeSort:false})));};};export default fetchProductsById;
17
+ */var fetchProductsById=function fetchProductsById(optionsOrProductIds){var componentId=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var cached=arguments.length>2&&arguments[2]!==undefined?arguments[2]:true;var includeFulfillment=arguments.length>3&&arguments[3]!==undefined?arguments[3]:true;return function(dispatch,getState){var localProductIds;var localComponentId;var localCached;var localIncludeFulfillment;var productIdType;if(Array.isArray(optionsOrProductIds)){// Backwards compatibility for previous implementation where the function had a parameter list
18
+ localProductIds=optionsOrProductIds;localComponentId=componentId||null;localCached=cached!==undefined?cached:true;localIncludeFulfillment=includeFulfillment!==undefined?includeFulfillment:true;}else if(_typeof(optionsOrProductIds)==='object'&&optionsOrProductIds!==null){// New object parameter mode
19
+ localProductIds=optionsOrProductIds.productIds;var _optionsOrProductIds$=optionsOrProductIds.componentId;localComponentId=_optionsOrProductIds$===void 0?null:_optionsOrProductIds$;var _optionsOrProductIds$2=optionsOrProductIds.cached;localCached=_optionsOrProductIds$2===void 0?true:_optionsOrProductIds$2;var _optionsOrProductIds$3=optionsOrProductIds.includeFulfillment;localIncludeFulfillment=_optionsOrProductIds$3===void 0?true:_optionsOrProductIds$3;productIdType=optionsOrProductIds.productIdType;}var requestProductIds=localProductIds;// When the productIds are regular product IDs, we can check the Redux store for existing
20
+ // and only request the missing ones. That certainly doesn't work for SKUs, EANs or UPCs,
21
+ if(!isProductIdentifiersProductIdType(productIdType)){var state=getState();var products=state.product.productsById;// Filter out only the products that are not yet available in the store.
22
+ requestProductIds=localProductIds.filter(function(id){return shouldFetchData(products[id]);});// Then only perform a pipeline request if there are products missing.
23
+ if(!requestProductIds.length){var productsById=localProductIds.map(function(id){return getProductDataById(state,{productId:id});});var totalProductCount=productsById.length;return{products:productsById,totalProductCount:totalProductCount};}}return dispatch(fetchProducts(_extends({},localComponentId&&{id:localComponentId},{cached:localCached,params:_extends({productIds:requestProductIds},productIdType&&{productIdType:productIdType}),includeFulfillment:localIncludeFulfillment,includeFilters:false,includeSort:false})));};};export default fetchProductsById;
@@ -1,4 +1,4 @@
1
- var _excluded=["useDefaultRequestForProductIds"];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);}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;}import fetchHighlightProducts from"./fetchHighlightProducts";import fetchProducts from"./fetchProducts";import fetchProductsById from"./fetchProductsById";/**
1
+ var _excluded=["useDefaultRequestForProductIds","productIdType"];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);}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;}import fetchHighlightProducts from"./fetchHighlightProducts";import fetchProducts from"./fetchProducts";import fetchProductsById from"./fetchProductsById";/**
2
2
  * Dispatches other actions based on the query type.
3
3
  * @param {number|string} type The query type.
4
4
  * @param {string} value The value to use with the query.
@@ -8,8 +8,8 @@ var _excluded=["useDefaultRequestForProductIds"];function _extends(){_extends=Ob
8
8
  */var fetchProductsByQuery=function fetchProductsByQuery(type,value){var options=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};var id=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;return function(dispatch){/**
9
9
  * Remove all properties from the options which are just intended to be used inside this function
10
10
  * and not supposed to be used for the actual products request.
11
- */var _options$useDefaultRe=options.useDefaultRequestForProductIds,useDefaultRequestForProductIds=_options$useDefaultRe===void 0?false:_options$useDefaultRe,sanitizedOptions=_objectWithoutProperties(options,_excluded);switch(type){// Product highlights
12
- case 1:{var params=_extends({},sanitizedOptions);dispatch(fetchHighlightProducts(_extends({params:params},id&&{id:id})));break;}// Search phrase
11
+ */var _options$useDefaultRe=options.useDefaultRequestForProductIds,useDefaultRequestForProductIds=_options$useDefaultRe===void 0?false:_options$useDefaultRe,_options$productIdTyp=options.productIdType,productIdType=_options$productIdTyp===void 0?undefined:_options$productIdTyp,sanitizedOptions=_objectWithoutProperties(options,_excluded);switch(type){// Product highlights
12
+ case 1:{var params=_extends({},sanitizedOptions);return dispatch(fetchHighlightProducts(_extends({params:params},id&&{id:id})));}// Search phrase
13
13
  case 2:case 3:{var _params=_extends({searchPhrase:value},sanitizedOptions);return dispatch(fetchProducts(_extends({params:_params},id&&{id:id},{includeFilters:false})));}// Product ID's
14
14
  case 4:{/**
15
15
  * By default the productIds query type bypasses the regular product request logic. It will
@@ -21,6 +21,6 @@ case 4:{/**
21
21
  *
22
22
  * ATTENTION: To make the system work completely, also the "getProductsResult" selector helper
23
23
  * needs to be called with this parameter.
24
- */if(useDefaultRequestForProductIds){var _params2=_extends({productIds:value},sanitizedOptions);// Limit and offset are not fully supported for product requests with productId list
25
- delete _params2.limit;delete _params2.offset;dispatch(fetchProducts(_extends({params:_params2},id&&{id:id},{includeFilters:false})));}else{dispatch(fetchProductsById(value,id));}break;}// Category
24
+ */if(useDefaultRequestForProductIds){var _params2=_extends({productIds:value,productIdType:productIdType},sanitizedOptions);// Limit and offset are not fully supported for product requests with productId list
25
+ delete _params2.limit;delete _params2.offset;return dispatch(fetchProducts(_extends({params:_params2},id&&{id:id},{includeFilters:false,includeSort:false})));}return dispatch(fetchProductsById(value,id));}// Category
26
26
  case 5:{var _params3=_extends({categoryId:value},sanitizedOptions);return dispatch(fetchProducts(_extends({params:_params3},id&&{id:id},{includeFilters:false})));}default:}return null;};};export default fetchProductsByQuery;