@shopgate/pwa-common-commerce 7.5.0-beta.3 → 7.5.0-beta.7

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.5.0-beta.3",
3
+ "version": "7.5.0-beta.7",
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.5.0-beta.3",
23
- "@shopgate/pwa-core": "7.5.0-beta.3",
22
+ "@shopgate/pwa-common": "7.5.0-beta.7",
23
+ "@shopgate/pwa-core": "7.5.0-beta.7",
24
24
  "lodash": "^4.17.4",
25
25
  "react": "~16.12.0",
26
26
  "react-dom": "~16.12.0"
@@ -3,4 +3,7 @@ function _extends(){_extends=Object.assign||function(target){for(var i=1;i<argum
3
3
  * @param {string} productId The product ID.
4
4
  * @param {boolean} forceFetch Skips shouldFetchData check. Always fetches.
5
5
  * @return {Function} A redux thunk.
6
- */function fetchProduct(productId){var forceFetch=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;return function(dispatch,getState){var state=getState();var product=getProductById(state,{productId:productId});if(!forceFetch&&!shouldFetchData(product)){if(product.productData){dispatch(receiveProductCached(product.productData));}return undefined;}var path=getCurrentPathname(state);LoadingProvider.setLoading(path);var requestParams=_extends({},configuration.get(DEFAULT_PRODUCTS_FETCH_PARAMS),{productId:productId});dispatch(requestProduct(productId,forceFetch));var request=new PipelineRequest(SHOPGATE_CATALOG_GET_PRODUCT).setInput(requestParams).dispatch();request.then(function(result){LoadingProvider.unsetLoading(path);dispatch(receiveProduct(productId,result));})["catch"](function(error){LoadingProvider.unsetLoading(path);dispatch(errorProduct(productId,error.code));});return request;};}/** @mixes {MutableFunction} */export default mutable(fetchProduct);
6
+ */function fetchProduct(productId){var forceFetch=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;return function(dispatch,getState){var state=getState();var product=getProductById(state,{productId:productId});if(!forceFetch&&!shouldFetchData(product)){if(product.productData){/*
7
+ This timeout is needed here to make sure receivedVisibleProduct$ comes after
8
+ productWillEnter$. Otherwise productIsReady$ is not working correctly.
9
+ */setTimeout(function(){dispatch(receiveProductCached(product.productData));},0);}return undefined;}var path=getCurrentPathname(state);LoadingProvider.setLoading(path);var requestParams=_extends({},configuration.get(DEFAULT_PRODUCTS_FETCH_PARAMS),{productId:productId});dispatch(requestProduct(productId,forceFetch));var request=new PipelineRequest(SHOPGATE_CATALOG_GET_PRODUCT).setInput(requestParams).dispatch();request.then(function(result){LoadingProvider.unsetLoading(path);dispatch(receiveProduct(productId,result));})["catch"](function(error){LoadingProvider.unsetLoading(path);dispatch(errorProduct(productId,error.code));});return request;};}/** @mixes {MutableFunction} */export default mutable(fetchProduct);
@@ -198,7 +198,7 @@ var _product$baseProductI=product.baseProductId,baseProductId=_product$baseProdu
198
198
  * @return {Array|null}
199
199
  */export var getProductImages=createSelector(getProductImagesState,getProductId,getBaseProductId,function(images,productId,baseProductId){var _ref4=images[productId]||{},productImages=_ref4.images,isFetching=_ref4.isFetching;if(isFetching){return null;}// If the product doesn't have images after fetching
200
200
  if(baseProductId&&(!Array.isArray(productImages)||!productImages.length)){// ...check the base product.
201
- var _ref5=images[baseProductId]||{},baseProductImages=_ref5.images;if(!Array.isArray(baseProductImages)||!baseProductImages.length){return null;}return baseProductImages;}return productImages||null;});/**
201
+ var _ref5=images[baseProductId]||{},baseProductImages=_ref5.images;if(!Array.isArray(baseProductImages)||!baseProductImages.length){return null;}return baseProductImages;}return productImages||null;});export var getFeaturedImage=createSelector(getProduct,getBaseProduct,function(product,baseProduct){var productImage=null;var baseProductImage=null;if(product===null||product===void 0?void 0:product.featuredMedia){productImage=product.featuredMedia.type==='image'?product.featuredMedia.url:null;}if(baseProduct===null||baseProduct===void 0?void 0:baseProduct.featuredMedia){baseProductImage=baseProduct.featuredMedia.type==='image'?baseProduct.featuredMedia.url:null;}return productImage||baseProductImage||(product===null||product===void 0?void 0:product.featuredImageBaseUrl)||(product===null||product===void 0?void 0:product.featuredImageUrl);});/**
202
202
  * Retrieves the product variant data.
203
203
  * @param {Object} state The current application state.
204
204
  * @param {Object} props The component props.
@@ -1,8 +1,8 @@
1
- import _regeneratorRuntime from"@babel/runtime/regenerator";function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}import showModal from'@shopgate/pwa-common/actions/modal/showModal';import Scanner from'@shopgate/pwa-core/classes/Scanner';import errorHandleScanner from"../action-creators/errorHandleScanner";/**
1
+ import _regeneratorRuntime from"@babel/runtime/regenerator";function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}import showModal from'@shopgate/pwa-common/actions/modal/showModal';import{mutable}from'@shopgate/pwa-common/helpers/redux';import Scanner from'@shopgate/pwa-core/classes/Scanner';import errorHandleScanner from"../action-creators/errorHandleScanner";/**
2
2
  * Handle no results
3
3
  * @param {string} event.scope Scanner scope.
4
4
  * @param {string} event.format Format of the scanned code.
5
5
  * @param {string} event.payload Barcode payload.
6
6
  * @param {string} message The message to display.
7
7
  * @return {Function} A redux thunk.
8
- */export default(function(_ref,message){var scope=_ref.scope,format=_ref.format,payload=_ref.payload;return(/*#__PURE__*/function(){var _ref2=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch){return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:dispatch(errorHandleScanner(scope,format,payload));dispatch(showModal({dismiss:null,confirm:'modal.ok',title:'modal.title_error',message:message})).then(function(confirmed){return confirmed&&Scanner.start();});case 2:case"end":return _context.stop();}}},_callee);}));return function(_x){return _ref2.apply(this,arguments);};}());});
8
+ */var handleNoResult=function handleNoResult(_ref,message){var scope=_ref.scope,format=_ref.format,payload=_ref.payload;return(/*#__PURE__*/function(){var _ref2=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch){return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:dispatch(errorHandleScanner(scope,format,payload));dispatch(showModal({dismiss:null,confirm:'modal.ok',title:'modal.title_error',message:message})).then(function(confirmed){return confirmed&&Scanner.start();});case 2:case"end":return _context.stop();}}},_callee);}));return function(_x){return _ref2.apply(this,arguments);};}());};/** @mixes {MutableFunction} */export default mutable(handleNoResult);
@@ -1,11 +1,11 @@
1
- import _regeneratorRuntime from"@babel/runtime/regenerator";function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}import{historyPop,historyReplace}from'@shopgate/pwa-common/actions/router';import{fetchPageConfig}from'@shopgate/pwa-common/actions/page';import{getPageConfigById}from'@shopgate/pwa-common/selectors/page';import{fetchProductsById,getProductById}from'@shopgate/pwa-common-commerce/product';import{fetchCategory,getCategory}from'@shopgate/pwa-common-commerce/category';import successHandleScanner from"../action-creators/successHandleScanner";import{QR_CODE_TYPE_CATEGORY,QR_CODE_TYPE_COUPON,QR_CODE_TYPE_HOMEPAGE,QR_CODE_TYPE_PAGE,QR_CODE_TYPE_PRODUCT,QR_CODE_TYPE_PRODUCT_WITH_COUPON,QR_CODE_TYPE_SEARCH}from"../constants";import{parse2dsQrCode}from"../helpers";import handleSearch from"./handleSearch";import handleNoResults from"./handleNoResults";/**
1
+ import _regeneratorRuntime from"@babel/runtime/regenerator";function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}import{historyPop,historyReplace}from'@shopgate/pwa-common/actions/router';import{fetchPageConfig}from'@shopgate/pwa-common/actions/page';import{getPageConfigById}from'@shopgate/pwa-common/selectors/page';import{mutable}from'@shopgate/pwa-common/helpers/redux';import{fetchProductsById,getProductById}from'@shopgate/pwa-common-commerce/product';import{fetchCategory,getCategory}from'@shopgate/pwa-common-commerce/category';import successHandleScanner from"../action-creators/successHandleScanner";import{QR_CODE_TYPE_CATEGORY,QR_CODE_TYPE_COUPON,QR_CODE_TYPE_HOMEPAGE,QR_CODE_TYPE_PAGE,QR_CODE_TYPE_PRODUCT,QR_CODE_TYPE_PRODUCT_WITH_COUPON,QR_CODE_TYPE_SEARCH}from"../constants";import{parse2dsQrCode}from"../helpers";import handleSearch from"./handleSearch";import handleNoResults from"./handleNoResults";/**
2
2
  * Handle qr code
3
3
  * @param {string} event.scope Scanner scope.
4
4
  * @param {string} event.format Format of the scanned code.
5
5
  * @param {string} event.payload Barcode payload.
6
6
  * @return {Function} A redux thunk.
7
- */export default(function(_ref){var scope=_ref.scope,format=_ref.format,payload=_ref.payload;return(/*#__PURE__*/function(){var _ref2=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch,getState){var _ref3,type,link,data,notFound;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:_ref3=parse2dsQrCode(payload)||{},type=_ref3.type,link=_ref3.link,data=_ref3.data;/**
7
+ */var handleQrCode=function handleQrCode(_ref){var scope=_ref.scope,format=_ref.format,payload=_ref.payload;return(/*#__PURE__*/function(){var _ref2=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch,getState){var _ref3,type,link,data,notFound;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:_ref3=parse2dsQrCode(payload)||{},type=_ref3.type,link=_ref3.link,data=_ref3.data;/**
8
8
  * Helper function to handle no scan results
9
9
  * @return {Function}
10
10
  */notFound=function notFound(){return dispatch(handleNoResults({scope:scope,format:format,payload:payload},'scanner.noResult.qrCode'));};_context.t0=type;_context.next=_context.t0===QR_CODE_TYPE_HOMEPAGE?5:_context.t0===QR_CODE_TYPE_SEARCH?8:_context.t0===QR_CODE_TYPE_COUPON?16:_context.t0===QR_CODE_TYPE_PRODUCT?20:_context.t0===QR_CODE_TYPE_PRODUCT_WITH_COUPON?20:_context.t0===QR_CODE_TYPE_CATEGORY?24:_context.t0===QR_CODE_TYPE_PAGE?28:32;break;case 5:dispatch(successHandleScanner(scope,format,payload));dispatch(historyReplace({pathname:link}));return _context.abrupt("break",33);case 8:_context.next=10;return dispatch(handleSearch(data.searchPhrase||''));case 10:if(!_context.sent){_context.next=14;break;}dispatch(successHandleScanner(scope,format,payload));_context.next=15;break;case 14:notFound();case 15:return _context.abrupt("break",33);case 16:dispatch(successHandleScanner(scope,format,payload));dispatch(historyReplace({pathname:link}));dispatch(historyPop());return _context.abrupt("break",33);case 20:_context.next=22;return dispatch(fetchProductsById([data.productId]));case 22:// Check from a store
11
- if(!getProductById(getState(),data)){notFound();}else{dispatch(successHandleScanner(scope,format,payload));dispatch(historyReplace({pathname:link}));}return _context.abrupt("break",33);case 24:_context.next=26;return dispatch(fetchCategory(data.categoryId));case 26:if(!getCategory(getState(),data)){notFound();}else{dispatch(successHandleScanner(scope,format,payload));dispatch(historyReplace({pathname:link}));}return _context.abrupt("break",33);case 28:_context.next=30;return dispatch(fetchPageConfig(data.pageId));case 30:if(!getPageConfigById(getState(),data)){notFound();}else{dispatch(successHandleScanner(scope,format,payload));dispatch(historyReplace({pathname:link}));}return _context.abrupt("break",33);case 32:notFound();case 33:return _context.abrupt("return",null);case 34:case"end":return _context.stop();}}},_callee);}));return function(_x,_x2){return _ref2.apply(this,arguments);};}());});
11
+ if(!getProductById(getState(),data)){notFound();}else{dispatch(successHandleScanner(scope,format,payload));dispatch(historyReplace({pathname:link}));}return _context.abrupt("break",33);case 24:_context.next=26;return dispatch(fetchCategory(data.categoryId));case 26:if(!getCategory(getState(),data)){notFound();}else{dispatch(successHandleScanner(scope,format,payload));dispatch(historyReplace({pathname:link}));}return _context.abrupt("break",33);case 28:_context.next=30;return dispatch(fetchPageConfig(data.pageId));case 30:if(!getPageConfigById(getState(),data)){notFound();}else{dispatch(successHandleScanner(scope,format,payload));dispatch(historyReplace({pathname:link}));}return _context.abrupt("break",33);case 32:notFound();case 33:return _context.abrupt("return",null);case 34:case"end":return _context.stop();}}},_callee);}));return function(_x,_x2){return _ref2.apply(this,arguments);};}());};/** @mixes {MutableFunction} */export default mutable(handleQrCode);