@shopgate/pwa-common-commerce 7.9.0 → 7.9.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.
@@ -4,8 +4,9 @@ import{ADD_PRODUCT_TO_FAVORITES,REMOVE_PRODUCT_FROM_FAVORITES,CANCEL_REQUEST_SYN
4
4
  * @param {string} listId List identifier.
5
5
  * @param {number} quantity New favorites quantity to set
6
6
  * @param {string} notes New favorites notes to set
7
+ * @param {boolean} showToast Whether to show a confirmation toast after product was added
7
8
  * @returns {Object}
8
- */export var addProductToFavorites=function addProductToFavorites(productId,listId,quantity,notes){return{type:ADD_PRODUCT_TO_FAVORITES,productId:productId,listId:listId,quantity:quantity,notes:notes};};/**
9
+ */export var addProductToFavorites=function addProductToFavorites(productId,listId,quantity,notes){var showToast=arguments.length>4&&arguments[4]!==undefined?arguments[4]:true;return{type:ADD_PRODUCT_TO_FAVORITES,productId:productId,listId:listId,quantity:quantity,notes:notes,showToast:showToast};};/**
9
10
  * First action to update a product in favorites.
10
11
  * @param {number} productId Id of the product to add.
11
12
  * @param {string} listId List identifier.
@@ -34,13 +35,15 @@ import{ADD_PRODUCT_TO_FAVORITES,REMOVE_PRODUCT_FROM_FAVORITES,CANCEL_REQUEST_SYN
34
35
  * @param {string} listId List identifier.
35
36
  * @param {number} quantity New favorites quantity to set
36
37
  * @param {string} notes New favorites notes to set
38
+ * @param {boolean} showToast Whether to show a confirmation toast after product was added
37
39
  * @returns {Object}
38
- */export var requestAddFavorites=function requestAddFavorites(productId,listId,quantity,notes){return{type:REQUEST_ADD_FAVORITES,productId:productId,listId:listId,quantity:quantity,notes:notes};};/**
40
+ */export var requestAddFavorites=function requestAddFavorites(productId,listId,quantity,notes){var showToast=arguments.length>4&&arguments[4]!==undefined?arguments[4]:true;return{type:REQUEST_ADD_FAVORITES,productId:productId,listId:listId,quantity:quantity,notes:notes,showToast:showToast};};/**
39
41
  * Action to be triggered upon successful addFavorites pipeline call.
40
42
  * @param {string} productId Product identifier.
41
43
  * @param {string} listId List identifier.
44
+ * @param {boolean} showToast Whether to show a confirmation toast after product was added
42
45
  * @returns {Object}
43
- */export var successAddFavorites=function successAddFavorites(productId,listId){return{type:SUCCESS_ADD_FAVORITES,productId:productId,listId:listId};};/**
46
+ */export var successAddFavorites=function successAddFavorites(productId,listId){var showToast=arguments.length>2&&arguments[2]!==undefined?arguments[2]:true;return{type:SUCCESS_ADD_FAVORITES,productId:productId,listId:listId,showToast:showToast};};/**
44
47
  * Action to be triggered upon a failed addFavorites pipeline call.
45
48
  * @param {string} productId Product identifier.
46
49
  * @param {Error} error The error that occurred.
@@ -4,6 +4,7 @@ import _regeneratorRuntime from"@babel/runtime/regenerator";function asyncGenera
4
4
  * @param {string} listId Id of the list to be added.
5
5
  * @param {number} quantity New favorites quantity to set
6
6
  * @param {string} notes New favorites notes to set
7
+ * @param {boolean} showToast Whether to show a confirmation toast after product was added
7
8
  * @returns {Function} A redux thunk.
8
- */function addFavorites(productId){var listId=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var quantity=arguments.length>2?arguments[2]:undefined;var notes=arguments.length>3?arguments[3]:undefined;return(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch,getState){var lists,defaultList,takenListId,request;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:// Fallback for deprecated calls without list id.
9
- lists=getState().favorites.lists.lists;defaultList=(lists===null||lists===void 0?void 0:lists[0])||{id:'DEFAULT'};takenListId=listId||defaultList.id;request=new PipelineRequest(SHOPGATE_USER_ADD_FAVORITES).setInput({productId:productId,favoritesListId:takenListId,quantity:quantity,notes:notes}).setRetries(0).dispatch();_context.prev=4;_context.next=7;return request;case 7:dispatch(successAddFavorites(productId,takenListId));_context.next=13;break;case 10:_context.prev=10;_context.t0=_context["catch"](4);dispatch(errorAddFavorites(productId,_context.t0,takenListId));case 13:return _context.abrupt("return",request);case 14:case"end":return _context.stop();}}},_callee,null,[[4,10]]);}));return function(_x,_x2){return _ref.apply(this,arguments);};}());}export default addFavorites;
9
+ */function addFavorites(productId){var listId=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var quantity=arguments.length>2?arguments[2]:undefined;var notes=arguments.length>3?arguments[3]:undefined;var showToast=arguments.length>4&&arguments[4]!==undefined?arguments[4]:true;return(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch,getState){var lists,defaultList,takenListId,request;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:// Fallback for deprecated calls without list id.
10
+ lists=getState().favorites.lists.lists;defaultList=(lists===null||lists===void 0?void 0:lists[0])||{id:'DEFAULT'};takenListId=listId||defaultList.id;request=new PipelineRequest(SHOPGATE_USER_ADD_FAVORITES).setInput({productId:productId,favoritesListId:takenListId,quantity:quantity,notes:notes}).setRetries(0).dispatch();_context.prev=4;_context.next=7;return request;case 7:dispatch(successAddFavorites(productId,takenListId,showToast));_context.next=13;break;case 10:_context.prev=10;_context.t0=_context["catch"](4);dispatch(errorAddFavorites(productId,_context.t0,takenListId));case 13:return _context.abrupt("return",request);case 14:case"end":return _context.stop();}}},_callee,null,[[4,10]]);}));return function(_x,_x2){return _ref.apply(this,arguments);};}());}export default addFavorites;
@@ -5,8 +5,9 @@ import _regeneratorRuntime from"@babel/runtime/regenerator";function asyncGenera
5
5
  * @param {string} listId List identifier.
6
6
  * @param {number} quantity New favorites quantity to set
7
7
  * @param {string} notes New favorites notes to set
8
+ * @param {boolean} showToast Whether to show a confirmation toast after product was added
8
9
  * @return {Function}
9
- */export var addFavorite=mutable(function(productId,listId,quantity,notes){return function(dispatch,getState){var defaultList=getFavoritesDefaultList(getState());dispatch(addProductToFavorites(productId,listId||defaultList.id,quantity,notes));};});/**
10
+ */export var addFavorite=mutable(function(productId,listId,quantity,notes){var showToast=arguments.length>4&&arguments[4]!==undefined?arguments[4]:true;return function(dispatch,getState){var defaultList=getFavoritesDefaultList(getState());dispatch(addProductToFavorites(productId,listId||defaultList.id,quantity,notes,showToast));};});/**
10
11
  * Adds a product to the favorite list (debounced and buffered).
11
12
  * @param {string} productId Product identifier.
12
13
  * @return {Function}
@@ -4,7 +4,7 @@ import _regeneratorRuntime from"@babel/runtime/regenerator";function _slicedToAr
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
5
5
  var activeProductInList=(_getFavoritesProducts=getFavoritesProducts(state).byList[action.listId])===null||_getFavoritesProducts===void 0?void 0:_getFavoritesProducts.items.find(function(_ref8){var productId=_ref8.productId;return productId===action.productId;});if(activeProductInList&&!wishlistItemQuantityEnabled){// Call cancel action with "zero" count, because request was even dispatched
6
6
  dispatch(cancelRequestSyncFavorites(0,action.listId));return;}var _appConfig$favorites=appConfig.favorites;_appConfig$favorites=_appConfig$favorites===void 0?{}:_appConfig$favorites;var _appConfig$favorites$=_appConfig$favorites.limit,limit=_appConfig$favorites$===void 0?100:_appConfig$favorites$;var count=makeGetFavoritesCountByList(function(){return action===null||action===void 0?void 0:action.listId;})(state);if(limit&&count>=limit){// Dispatch a local error only, because the request to add is prevented
7
- var error=new Error('Limit exceeded');error.code=FAVORITES_LIMIT_ERROR;dispatch(errorFavorites(action.productId,error));}else{dispatch(requestAddFavorites(action.productId,action.listId,action.quantity,action.notes));}});subscribe(updateProductInFavoritesDebounced$,function(_ref9){var action=_ref9.action,dispatch=_ref9.dispatch;dispatch(requestUpdateFavorites(action.productId,action.listId,action.quantity,action.notes));});subscribe(removeProductFromFavoritesDebounced$,function(_ref10){var _getFavoritesProducts2;var action=_ref10.action,dispatch=_ref10.dispatch,getState=_ref10.getState;var count=getFavoritesCount(getState());if(count>0){if(action.withRelatives){// Will only handle ids which are present in the store, no additional check needed
7
+ var error=new Error('Limit exceeded');error.code=FAVORITES_LIMIT_ERROR;dispatch(errorFavorites(action.productId,error));}else{dispatch(requestAddFavorites(action.productId,action.listId,action.quantity,action.notes,action.showToast));}});subscribe(updateProductInFavoritesDebounced$,function(_ref9){var action=_ref9.action,dispatch=_ref9.dispatch;dispatch(requestUpdateFavorites(action.productId,action.listId,action.quantity,action.notes));});subscribe(removeProductFromFavoritesDebounced$,function(_ref10){var _getFavoritesProducts2;var action=_ref10.action,dispatch=_ref10.dispatch,getState=_ref10.getState;var count=getFavoritesCount(getState());if(count>0){if(action.withRelatives){// Will only handle ids which are present in the store, no additional check needed
8
8
  var allOnList=makeGetProductRelativesOnFavorites(function(){return action.listId;})(getState(),{productId:action.productId});allOnList.forEach(function(id){return dispatch(requestRemoveFavorites(id,action.listId));});return;}// Avoids trying to remove something that was already removed (incoming fetch response)
9
9
  var list=getFavoritesProducts(getState()).byList[action.listId];if(!(list===null||list===void 0?void 0:list.items.find(function(_ref11){var productId=_ref11.productId;return productId===action.productId;}))){// Call cancel action with "zero" count, because request was even dispatched
10
10
  dispatch(cancelRequestSyncFavorites(0,action.listId));return;}dispatch(requestRemoveFavorites(action.productId,action.listId));}else if(!((_getFavoritesProducts2=getFavoritesProducts(getState()).byList[action.listId])===null||_getFavoritesProducts2===void 0?void 0:_getFavoritesProducts2.isFetching)){// Remove should not be possible when no favorites available
@@ -19,11 +19,11 @@ subscribe(errorFavoritesLimit$,function(_ref12){var dispatch=_ref12.dispatch;dis
19
19
  * After all pipeline requests are done it resets the favorite page's state to "idle".
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
- 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:case"end":return _context6.stop();}}},_callee6);}));return function(_x5){return _ref15.apply(this,arguments);};}());subscribe(favoritesSyncIdle$,function(){LoadingProvider.resetLoading(FAVORITES_PATH);});subscribe(addProductToFavorites$,function(_ref19){var events=_ref19.events,getState=_ref19.getState;var loadWishlistOnAppStartEnabled=getLoadWishlistOnAppStartEnabled(getState());// When wish list loading on app start is disabled, toast is shown instantly after the add
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,showToast,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,showToast=_groupedActions$.showToast;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,showToast));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(addProductToFavorites$,function(_ref19){var events=_ref19.events,getState=_ref19.getState,action=_ref19.action;var loadWishlistOnAppStartEnabled=getLoadWishlistOnAppStartEnabled(getState());// When wish list loading on app start is disabled, toast is shown instantly after the add
24
24
  // action was dispatched. We don't have to wait for the "debounced" action, since
25
25
  // removal of wishlist items is not possible.
26
- if(!loadWishlistOnAppStartEnabled){events.emit(ToastProvider.ADD,{id:'favorites.added',message:'favorites.added'});}});subscribe(favoritesDidAddItem$,function(_ref20){var events=_ref20.events,getState=_ref20.getState;var loadWishlistOnAppStartEnabled=getLoadWishlistOnAppStartEnabled(getState());// When wish list loading on app start is enabled, toast is shown after the add action from
26
+ if(!loadWishlistOnAppStartEnabled&&(action===null||action===void 0?void 0:action.showToast)!==false){events.emit(ToastProvider.ADD,{id:'favorites.added',message:'favorites.added'});}});subscribe(favoritesDidAddItem$,function(_ref20){var events=_ref20.events,getState=_ref20.getState,action=_ref20.action;var loadWishlistOnAppStartEnabled=getLoadWishlistOnAppStartEnabled(getState());// When wish list loading on app start is enabled, toast is shown after the add action from
27
27
  // the buffer system is dispatched. We wait for that since the item might have been removed
28
28
  // again within the debounce time.
29
- if(loadWishlistOnAppStartEnabled){events.emit(ToastProvider.ADD,{id:'favorites.added',message:'favorites.added'});}});}
29
+ if(loadWishlistOnAppStartEnabled&&(action===null||action===void 0?void 0:action.showToast)!==false){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",
3
+ "version": "7.9.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": "^3.0.1"
20
20
  },
21
21
  "devDependencies": {
22
- "@shopgate/pwa-common": "7.9.0",
23
- "@shopgate/pwa-core": "7.9.0",
22
+ "@shopgate/pwa-common": "7.9.1",
23
+ "@shopgate/pwa-core": "7.9.1",
24
24
  "lodash": "^4.17.4",
25
25
  "react": "~16.12.0",
26
26
  "react-dom": "~16.12.0"