@shopgate/pwa-common-commerce 7.9.0-beta.1 → 7.9.0-beta.3

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.
@@ -1,4 +1,4 @@
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{mutable}from'@shopgate/pwa-common/helpers/redux';import{getWishlistItemQuantityEnabled,getLoadWishlistOnAppStartEnabled}from'@shopgate/engage/core/selectors/merchantSettings';import{getFavoritesDefaultList,getFavoritesLists,makeIsProductOnSpecificFavoriteList}from"../selectors";import{addProductToFavorites,removeProductFromFavorites,requestFlushFavoritesBuffer,openFavoritesListChooser,updateProductInFavorites}from"../action-creators";import fetchFavoritesListsWithItems from"./fetchFavoritesListsWithItems";/**
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{mutable}from'@shopgate/pwa-common/helpers/redux';import{getWishlistItemQuantityEnabled,getLoadWishlistOnAppStartEnabled}from'@shopgate/engage/core/selectors/shopSettings';import{getFavoritesDefaultList,getFavoritesLists,makeIsProductOnSpecificFavoriteList}from"../selectors";import{addProductToFavorites,removeProductFromFavorites,requestFlushFavoritesBuffer,openFavoritesListChooser,updateProductInFavorites}from"../action-creators";import fetchFavoritesListsWithItems from"./fetchFavoritesListsWithItems";/**
2
2
  * Adds a product to the favorite list (debounced and buffered).
3
3
  * @mixes {MutableFunction}
4
4
  * @param {string} productId Product identifier.
@@ -1,4 +1,4 @@
1
- import _regeneratorRuntime from"@babel/runtime/regenerator";function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance");}function _iterableToArrayLimit(arr,i){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}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 pipelineDependencies from'@shopgate/pwa-core/classes/PipelineDependencies';import appConfig from'@shopgate/pwa-common/helpers/config';import showModal from'@shopgate/pwa-common/actions/modal/showModal';import{appDidStart$}from'@shopgate/pwa-common/streams';import groupBy from'lodash/groupBy';import ToastProvider from'@shopgate/pwa-common/providers/toast';import{getLoadWishlistOnAppStartEnabled,getWishlistItemQuantityEnabled}from'@shopgate/engage/core/selectors/merchantSettings';import{LoadingProvider}from'@shopgate/pwa-common/providers';import{favoritesWillEnter$,shouldFetchFreshFavorites$,addProductToFavoritesDebounced$,removeProductFromFavoritesDebounced$,errorFavoritesLimit$,refreshFavorites$,didReceiveFlushFavoritesBuffer$,updateProductInFavoritesDebounced$,favoritesDidAddItem$}from"../streams";import{SHOPGATE_USER_ADD_FAVORITES,SHOPGATE_USER_DELETE_FAVORITES}from"../constants/Pipelines";import addFavorites from"../actions/addFavorites";import updateFavorites from"../actions/updateFavorites";import removeFavorites from"../actions/removeFavorites";import fetchFavoritesListsWithItems from"../actions/fetchFavoritesListsWithItems";import fetchFavorites from"../actions/fetchFavorites";import{requestAddFavorites,requestRemoveFavorites,cancelRequestSyncFavorites,errorFavorites,idleSyncFavorites,requestUpdateFavorites}from"../action-creators";import{REQUEST_ADD_FAVORITES,REQUEST_REMOVE_FAVORITES,FAVORITES_LIMIT_ERROR,REQUEST_UPDATE_FAVORITES,FAVORITES_PATH}from"../constants";import{getFavoritesCount,makeGetProductRelativesOnFavorites,getFavoritesProducts}from"../selectors";/**
1
+ import _regeneratorRuntime from"@babel/runtime/regenerator";function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance");}function _iterableToArrayLimit(arr,i){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}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 pipelineDependencies from'@shopgate/pwa-core/classes/PipelineDependencies';import appConfig from'@shopgate/pwa-common/helpers/config';import showModal from'@shopgate/pwa-common/actions/modal/showModal';import{appDidStart$}from'@shopgate/pwa-common/streams';import groupBy from'lodash/groupBy';import ToastProvider from'@shopgate/pwa-common/providers/toast';import{getLoadWishlistOnAppStartEnabled,getWishlistItemQuantityEnabled}from'@shopgate/engage/core/selectors/shopSettings';import{LoadingProvider}from'@shopgate/pwa-common/providers';import{favoritesWillEnter$,shouldFetchFreshFavorites$,addProductToFavoritesDebounced$,removeProductFromFavoritesDebounced$,errorFavoritesLimit$,refreshFavorites$,didReceiveFlushFavoritesBuffer$,updateProductInFavoritesDebounced$,favoritesDidAddItem$,favoritesSyncIdle$}from"../streams";import{SHOPGATE_USER_ADD_FAVORITES,SHOPGATE_USER_DELETE_FAVORITES}from"../constants/Pipelines";import addFavorites from"../actions/addFavorites";import updateFavorites from"../actions/updateFavorites";import removeFavorites from"../actions/removeFavorites";import fetchFavoritesListsWithItems from"../actions/fetchFavoritesListsWithItems";import fetchFavorites from"../actions/fetchFavorites";import{requestAddFavorites,requestRemoveFavorites,cancelRequestSyncFavorites,errorFavorites,idleSyncFavorites,requestUpdateFavorites}from"../action-creators";import{REQUEST_ADD_FAVORITES,REQUEST_REMOVE_FAVORITES,FAVORITES_LIMIT_ERROR,REQUEST_UPDATE_FAVORITES,FAVORITES_PATH}from"../constants";import{getFavoritesCount,makeGetProductRelativesOnFavorites,getFavoritesProducts}from"../selectors";/**
2
2
  * @param {Function} subscribe Subscribes to an observable.
3
3
  */export default function favorites(subscribe){if(!appConfig.hasFavorites){return;}/** App start */subscribe(appDidStart$,/*#__PURE__*/function(){var _ref2=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref){var dispatch,getState,loadWishlistOnAppStartEnabled;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:dispatch=_ref.dispatch,getState=_ref.getState;// Setup sync pipeline dependencies (concurrency to each other and themselves)
4
4
  pipelineDependencies.set(SHOPGATE_USER_ADD_FAVORITES,[SHOPGATE_USER_ADD_FAVORITES,SHOPGATE_USER_DELETE_FAVORITES]);pipelineDependencies.set(SHOPGATE_USER_DELETE_FAVORITES,[SHOPGATE_USER_ADD_FAVORITES,SHOPGATE_USER_DELETE_FAVORITES]);loadWishlistOnAppStartEnabled=getLoadWishlistOnAppStartEnabled(getState());if(!loadWishlistOnAppStartEnabled){_context.next=7;break;}_context.next=7;return dispatch(fetchFavoritesListsWithItems(false));case 7:case"end":return _context.stop();}}},_callee);}));return function(_x){return _ref2.apply(this,arguments);};}());/** Favorites route enter */subscribe(favoritesWillEnter$,/*#__PURE__*/function(){var _ref4=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref3){var dispatch;return _regeneratorRuntime.wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:dispatch=_ref3.dispatch;_context2.next=3;return dispatch(fetchFavoritesListsWithItems(true));case 3:case"end":return _context2.stop();}}},_callee2);}));return function(_x2){return _ref4.apply(this,arguments);};}());/** User login / logout */subscribe(shouldFetchFreshFavorites$,/*#__PURE__*/function(){var _ref6=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref5){var dispatch;return _regeneratorRuntime.wrap(function _callee3$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:dispatch=_ref5.dispatch;_context3.next=3;return dispatch(fetchFavoritesListsWithItems(true));case 3:case"end":return _context3.stop();}}},_callee3);}));return function(_x3){return _ref6.apply(this,arguments);};}());subscribe(addProductToFavoritesDebounced$,function(_ref7){var _getFavoritesProducts;var action=_ref7.action,dispatch=_ref7.dispatch,getState=_ref7.getState;var state=getState();var wishlistItemQuantityEnabled=getWishlistItemQuantityEnabled(state);// Nothing to do, when the store already contains the item
@@ -20,4 +20,4 @@ subscribe(errorFavoritesLimit$,function(_ref12){var dispatch=_ref12.dispatch;dis
20
20
  */subscribe(didReceiveFlushFavoritesBuffer$,/*#__PURE__*/function(){var _ref15=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(actionBuffer){var dispatch,actions,actionsByListAndProduct,idleLists;return _regeneratorRuntime.wrap(function _callee6$(_context6){while(1){switch(_context6.prev=_context6.next){case 0:if(!(!Array.isArray(actionBuffer)||!actionBuffer.length)){_context6.next=2;break;}return _context6.abrupt("return");case 2:LoadingProvider.setLoading(FAVORITES_PATH);// All actions provide the same functionality, just take the first entry
21
21
  dispatch=actionBuffer[0].dispatch;// Group all buffered actions by listId and productID
22
22
  actions=actionBuffer.map(function(_ref16){var action=_ref16.action;return action;});actionsByListAndProduct=groupBy(actions,function(_ref17){var listId=_ref17.listId,productId=_ref17.productId;return"".concat(listId,"-").concat(productId,"}");});idleLists=[];_context6.next=9;return Object.values(actionsByListAndProduct).forEach(/*#__PURE__*/function(){var _ref18=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(groupedActions){var _groupedActions,_groupedActions$,productId,listId,quantity,notes,updateActions,addActions,removeActions,_updateActions$slice,_updateActions$slice2,lastUpdateAction,addRemoveBalance;return _regeneratorRuntime.wrap(function _callee5$(_context5){while(1){switch(_context5.prev=_context5.next){case 0:_groupedActions=_slicedToArray(groupedActions,1),_groupedActions$=_groupedActions[0];_groupedActions$=_groupedActions$===void 0?{}:_groupedActions$;productId=_groupedActions$.productId,listId=_groupedActions$.listId,quantity=_groupedActions$.quantity,notes=_groupedActions$.notes;updateActions=groupedActions.filter(function(action){return action.type===REQUEST_UPDATE_FAVORITES;});addActions=groupedActions.filter(function(action){return action.type===REQUEST_ADD_FAVORITES;});removeActions=groupedActions.filter(function(action){return action.type===REQUEST_REMOVE_FAVORITES;});_context5.prev=6;if(!(updateActions.length>0)){_context5.next=11;break;}_updateActions$slice=updateActions.slice(-1),_updateActions$slice2=_slicedToArray(_updateActions$slice,1),lastUpdateAction=_updateActions$slice2[0];_context5.next=11;return dispatch(updateFavorites(lastUpdateAction.productId,lastUpdateAction.listId,lastUpdateAction.quantity,lastUpdateAction.notes));case 11:// Sum up all adds and removes, based on sum dispatch add / remove
23
- addRemoveBalance=addActions.length-removeActions.length;if(!(addRemoveBalance>0)){_context5.next=15;break;}_context5.next=15;return dispatch(addFavorites(productId,listId,quantity,notes));case 15:if(!(addRemoveBalance<0)){_context5.next=18;break;}_context5.next=18;return dispatch(removeFavorites(productId,listId,quantity,notes));case 18:if(!(updateActions.length===0&&addRemoveBalance===0)){_context5.next=22;break;}dispatch(cancelRequestSyncFavorites(groupedActions.length,listId));_context5.next=26;break;case 22:if(idleLists.includes(listId)){_context5.next=26;break;}idleLists.push(listId);_context5.next=26;return dispatch(idleSyncFavorites(listId));case 26:_context5.next=34;break;case 28:_context5.prev=28;_context5.t0=_context5["catch"](6);if(idleLists.includes(listId)){_context5.next=34;break;}idleLists.push(listId);_context5.next=34;return dispatch(idleSyncFavorites(listId));case 34:case"end":return _context5.stop();}}},_callee5,null,[[6,28]]);}));return function(_x6){return _ref18.apply(this,arguments);};}());case 9:LoadingProvider.unsetLoading(FAVORITES_PATH);case 10:case"end":return _context6.stop();}}},_callee6);}));return function(_x5){return _ref15.apply(this,arguments);};}());subscribe(favoritesDidAddItem$,function(_ref19){var events=_ref19.events;var shouldShowToast=true;if(shouldShowToast){events.emit(ToastProvider.ADD,{id:'favorites.added',message:'favorites.added'});}});}
23
+ addRemoveBalance=addActions.length-removeActions.length;if(!(addRemoveBalance>0)){_context5.next=15;break;}_context5.next=15;return dispatch(addFavorites(productId,listId,quantity,notes));case 15:if(!(addRemoveBalance<0)){_context5.next=18;break;}_context5.next=18;return dispatch(removeFavorites(productId,listId,quantity,notes));case 18:if(!(updateActions.length===0&&addRemoveBalance===0)){_context5.next=22;break;}dispatch(cancelRequestSyncFavorites(groupedActions.length,listId));_context5.next=26;break;case 22:if(idleLists.includes(listId)){_context5.next=26;break;}idleLists.push(listId);_context5.next=26;return dispatch(idleSyncFavorites(listId));case 26:_context5.next=34;break;case 28:_context5.prev=28;_context5.t0=_context5["catch"](6);if(idleLists.includes(listId)){_context5.next=34;break;}idleLists.push(listId);_context5.next=34;return dispatch(idleSyncFavorites(listId));case 34:case"end":return _context5.stop();}}},_callee5,null,[[6,28]]);}));return function(_x6){return _ref18.apply(this,arguments);};}());case 9:case"end":return _context6.stop();}}},_callee6);}));return function(_x5){return _ref15.apply(this,arguments);};}());subscribe(favoritesSyncIdle$,function(){LoadingProvider.resetLoading(FAVORITES_PATH);});subscribe(favoritesDidAddItem$,function(_ref19){var events=_ref19.events;var shouldShowToast=true;if(shouldShowToast){events.emit(ToastProvider.ADD,{id:'favorites.added',message:'favorites.added'});}});}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopgate/pwa-common-commerce",
3
- "version": "7.9.0-beta.1",
3
+ "version": "7.9.0-beta.3",
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.9.0-beta.1",
23
- "@shopgate/pwa-core": "7.9.0-beta.1",
22
+ "@shopgate/pwa-common": "7.9.0-beta.3",
23
+ "@shopgate/pwa-core": "7.9.0-beta.3",
24
24
  "lodash": "^4.17.4",
25
25
  "react": "~16.12.0",
26
26
  "react-dom": "~16.12.0"