@shopgate/pwa-common-commerce 6.22.0 → 6.22.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.
package/cart/streams/index.js
CHANGED
|
@@ -1,48 +1,56 @@
|
|
|
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 _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen);}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++){arr2[i]=arr[i];}return arr2;}function _iterableToArrayLimit(arr,i){var _i=arr==null?null:typeof Symbol!=="undefined"&&arr[Symbol.iterator]||arr["@@iterator"];if(_i==null)return;var _arr=[];var _n=true;var _d=false;var _s,_e;try{for(_i=_i.call(arr);!(_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;}import{ACTION_PUSH,ACTION_REPLACE}from'@virtuous/conductor';import{main$}from'@shopgate/pwa-common/streams/main';import{routeWillEnter$,routeDidEnter$,routeWillLeave$,routeDidLeave$,navigate$}from'@shopgate/pwa-common/streams/router';import{getCurrentPathname}from'@shopgate/pwa-common/selectors/router';import{CART_PATH,REQUEST_CART,RECEIVE_CART,ERROR_CART,ADD_PRODUCTS_TO_CART,SUCCESS_ADD_PRODUCTS_TO_CART,ERROR_ADD_PRODUCTS_TO_CART,UPDATE_PRODUCTS_IN_CART,SUCCESS_UPDATE_PRODUCTS_IN_CART,ERROR_UPDATE_PRODUCTS_IN_CART,DELETE_PRODUCTS_FROM_CART,SUCCESS_DELETE_PRODUCTS_FROM_CART,ERROR_DELETE_PRODUCTS_FROM_CART,ADD_COUPONS_TO_CART,SUCCESS_ADD_COUPONS_TO_CART,ERROR_ADD_COUPONS_TO_CART,DELETE_COUPONS_FROM_CART,ERROR_DELETE_COUPONS_FROM_CART,SUCCESS_DELETE_COUPONS_FROM_CART,DEEPLINK_CART_ADD_PRODUCT_PATTERN}from"../constants";/**
|
|
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 _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen);}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++){arr2[i]=arr[i];}return arr2;}function _iterableToArrayLimit(arr,i){var _i=arr==null?null:typeof Symbol!=="undefined"&&arr[Symbol.iterator]||arr["@@iterator"];if(_i==null)return;var _arr=[];var _n=true;var _d=false;var _s,_e;try{for(_i=_i.call(arr);!(_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;}import queryString from'query-string';import{ACTION_PUSH,ACTION_REPLACE}from'@virtuous/conductor';import{main$}from'@shopgate/pwa-common/streams/main';import{routeWillEnter$,routeDidEnter$,routeWillLeave$,routeDidLeave$,navigate$}from'@shopgate/pwa-common/streams/router';import{getCurrentPathname}from'@shopgate/pwa-common/selectors/router';import{pushNotificationOpened$}from'@shopgate/pwa-common/streams/app';import{INDEX_PATH_DEEPLINK,INDEX_PATH}from'@shopgate/pwa-common/constants/RoutePaths';import{CART_PATH,REQUEST_CART,RECEIVE_CART,ERROR_CART,ADD_PRODUCTS_TO_CART,SUCCESS_ADD_PRODUCTS_TO_CART,ERROR_ADD_PRODUCTS_TO_CART,UPDATE_PRODUCTS_IN_CART,SUCCESS_UPDATE_PRODUCTS_IN_CART,ERROR_UPDATE_PRODUCTS_IN_CART,DELETE_PRODUCTS_FROM_CART,SUCCESS_DELETE_PRODUCTS_FROM_CART,ERROR_DELETE_PRODUCTS_FROM_CART,ADD_COUPONS_TO_CART,SUCCESS_ADD_COUPONS_TO_CART,ERROR_ADD_COUPONS_TO_CART,DELETE_COUPONS_FROM_CART,ERROR_DELETE_COUPONS_FROM_CART,SUCCESS_DELETE_COUPONS_FROM_CART,DEEPLINK_CART_ADD_PRODUCT_PATTERN}from"../constants";/**
|
|
2
|
+
* Specialized stream to handle push notifications that redirect to index screen with a coupon code.
|
|
3
|
+
* Default logic would dispatch a historyReset in that case without link in the action payload,
|
|
4
|
+
* so we need to hook onto the pushNotificationOpen stream to inspect the link.
|
|
2
5
|
* @type {Observable}
|
|
3
|
-
*/
|
|
6
|
+
*/var pushNotificationWithIndexCouponOpened$=pushNotificationOpened$.filter(function(_ref){var action=_ref.action;if(!action.link){// stop execution when push contains no link
|
|
7
|
+
return false;}var _action$link$split=action.link.split('?'),_action$link$split2=_slicedToArray(_action$link$split,1),pathname=_action$link$split2[0];if(pathname!==INDEX_PATH&&pathname!==INDEX_PATH_DEEPLINK){// stop execution when link doesn't reference index path
|
|
8
|
+
return false;}var parsed=queryString.parseUrl(action.link);if(!parsed||!parsed.query||!parsed.query.coupon){// stop execution when link doesn't contain a coupon
|
|
9
|
+
return false;}return true;}).map(function(input){return _extends({},input,{action:{historyAction:ACTION_PUSH,route:{query:{coupon:queryString.parseUrl(input.action.link).query.coupon}}}});});/**
|
|
4
10
|
* @type {Observable}
|
|
5
|
-
*/export var
|
|
11
|
+
*/export var routeWithCouponWillEnter$=routeWillEnter$.merge(pushNotificationWithIndexCouponOpened$).filter(function(_ref2){var action=_ref2.action;return[ACTION_PUSH,ACTION_REPLACE].includes(action.historyAction)&&action.route.query.coupon;});/**
|
|
12
|
+
* @type {Observable}
|
|
13
|
+
*/export var cartWillEnter$=routeWillEnter$.filter(function(_ref3){var action=_ref3.action;return action.route.pattern===CART_PATH;});/**
|
|
6
14
|
* @type {Observable}
|
|
7
|
-
*/export var cartDidEnter$=routeDidEnter$.filter(function(
|
|
15
|
+
*/export var cartDidEnter$=routeDidEnter$.filter(function(_ref4){var action=_ref4.action;return action.route.pattern===CART_PATH;});/**
|
|
8
16
|
* @type {Observable}
|
|
9
|
-
*/export var cartWillLeave$=routeWillLeave$.filter(function(
|
|
17
|
+
*/export var cartWillLeave$=routeWillLeave$.filter(function(_ref5){var action=_ref5.action;return action.route.pattern===CART_PATH;});/**
|
|
10
18
|
* @type {Observable}
|
|
11
|
-
*/export var cartDidLeave$=routeDidLeave$.filter(function(
|
|
19
|
+
*/export var cartDidLeave$=routeDidLeave$.filter(function(_ref6){var action=_ref6.action;return action.route.pattern===CART_PATH;});/**
|
|
12
20
|
* @type {Observable}
|
|
13
|
-
*/export var cartRequesting$=main$.filter(function(
|
|
21
|
+
*/export var cartRequesting$=main$.filter(function(_ref7){var action=_ref7.action;return action.type===REQUEST_CART;});/**
|
|
14
22
|
* @type {Observable}
|
|
15
|
-
*/export var cartReceived$=main$.filter(function(
|
|
23
|
+
*/export var cartReceived$=main$.filter(function(_ref8){var action=_ref8.action;return action.type===RECEIVE_CART||action.type===ERROR_CART;});/**
|
|
16
24
|
* Gets triggered when the user tried to add a coupon to the cart.
|
|
17
25
|
* @type {Observable}
|
|
18
|
-
*/export var couponsAdded$=main$.filter(function(
|
|
26
|
+
*/export var couponsAdded$=main$.filter(function(_ref9){var action=_ref9.action;return action.type===ADD_COUPONS_TO_CART;});/**
|
|
19
27
|
* Gets triggered when the user tried to add a coupon to the cart.
|
|
20
28
|
* @type {Observable}
|
|
21
|
-
*/export var couponsDeleted$=main$.filter(function(
|
|
29
|
+
*/export var couponsDeleted$=main$.filter(function(_ref10){var action=_ref10.action;return action.type===DELETE_COUPONS_FROM_CART;});/**
|
|
22
30
|
* Gets triggered when the user tried to add a coupon to the cart.
|
|
23
31
|
* @type {Observable}
|
|
24
|
-
*/export var couponsUpdated$=main$.filter(function(
|
|
32
|
+
*/export var couponsUpdated$=main$.filter(function(_ref11){var action=_ref11.action;return action.type===SUCCESS_ADD_COUPONS_TO_CART||action.type===ERROR_ADD_COUPONS_TO_CART||action.type===SUCCESS_DELETE_COUPONS_FROM_CART||action.type===ERROR_DELETE_COUPONS_FROM_CART;});/**
|
|
25
33
|
* Gets triggered when the user tried to add a product to the cart.
|
|
26
34
|
* @type {Observable}
|
|
27
|
-
*/export var productsAdded$=main$.filter(function(
|
|
35
|
+
*/export var productsAdded$=main$.filter(function(_ref12){var action=_ref12.action;return action.type===ADD_PRODUCTS_TO_CART;});/**
|
|
28
36
|
* Gets triggered when the user tried to add a product to the cart.
|
|
29
37
|
* @type {Observable}
|
|
30
|
-
*/export var productsModified$=main$.filter(function(
|
|
38
|
+
*/export var productsModified$=main$.filter(function(_ref13){var action=_ref13.action;return action.type===UPDATE_PRODUCTS_IN_CART;});/**
|
|
31
39
|
* Gets triggered when the user tried to add a product to the cart.
|
|
32
40
|
* @type {Observable}
|
|
33
|
-
*/export var productsDeleted$=main$.filter(function(
|
|
41
|
+
*/export var productsDeleted$=main$.filter(function(_ref14){var action=_ref14.action;return action.type===DELETE_PRODUCTS_FROM_CART;});/**
|
|
34
42
|
* Gets triggered when the cart has been updated while the cart route was visible.
|
|
35
43
|
* @type {Observable}
|
|
36
|
-
*/export var cartUpdatedWhileVisible$=cartReceived$.filter(function(
|
|
44
|
+
*/export var cartUpdatedWhileVisible$=cartReceived$.filter(function(_ref15){var getState=_ref15.getState;return getCurrentPathname(getState())===CART_PATH;});/**
|
|
37
45
|
* Gets triggered when the user tried to add a coupon to the cart.
|
|
38
46
|
* @type {Observable}
|
|
39
|
-
*/export var productsUpdated$=main$.filter(function(
|
|
47
|
+
*/export var productsUpdated$=main$.filter(function(_ref16){var action=_ref16.action;return action.type===SUCCESS_ADD_PRODUCTS_TO_CART||action.type===ERROR_ADD_PRODUCTS_TO_CART||action.type===SUCCESS_UPDATE_PRODUCTS_IN_CART||action.type===ERROR_UPDATE_PRODUCTS_IN_CART||action.type===SUCCESS_DELETE_PRODUCTS_FROM_CART||action.type===ERROR_DELETE_PRODUCTS_FROM_CART;});/**
|
|
40
48
|
* Gets triggered when the remote cart was updated.
|
|
41
49
|
* @type {Observable}
|
|
42
|
-
*/export var remoteCartDidUpdate$=main$.filter(function(
|
|
50
|
+
*/export var remoteCartDidUpdate$=main$.filter(function(_ref17){var action=_ref17.action;return action.type===SUCCESS_ADD_PRODUCTS_TO_CART||action.type===ERROR_ADD_PRODUCTS_TO_CART||action.type===SUCCESS_UPDATE_PRODUCTS_IN_CART||action.type===ERROR_UPDATE_PRODUCTS_IN_CART||action.type===SUCCESS_DELETE_PRODUCTS_FROM_CART||action.type===ERROR_DELETE_PRODUCTS_FROM_CART||action.type===SUCCESS_ADD_COUPONS_TO_CART||action.type===ERROR_ADD_COUPONS_TO_CART||action.type===SUCCESS_DELETE_COUPONS_FROM_CART||action.type===ERROR_DELETE_COUPONS_FROM_CART;});/**
|
|
43
51
|
* Gets triggered whenever any cart update request fails.
|
|
44
52
|
* @type {Observable}
|
|
45
|
-
*/export var cartUpdateFailed$=main$.filter(function(
|
|
53
|
+
*/export var cartUpdateFailed$=main$.filter(function(_ref18){var action=_ref18.action;return action.type===ERROR_ADD_PRODUCTS_TO_CART||action.type===ERROR_UPDATE_PRODUCTS_IN_CART||action.type===ERROR_DELETE_PRODUCTS_FROM_CART||action.type===ERROR_ADD_COUPONS_TO_CART||action.type===ERROR_DELETE_COUPONS_FROM_CART;});/**
|
|
46
54
|
* Gets triggered when /cart_add_product/123/COUPON route is navigated
|
|
47
55
|
* @type {Observable}
|
|
48
|
-
*/export var routeAddProductNavigate$=navigate$.filter(function(
|
|
56
|
+
*/export var routeAddProductNavigate$=navigate$.filter(function(_ref19){var _ref19$action$params=_ref19.action.params;_ref19$action$params=_ref19$action$params===void 0?{}:_ref19$action$params;var _ref19$action$params$=_ref19$action$params.pathname,pathname=_ref19$action$params$===void 0?'':_ref19$action$params$;return pathname.includes(DEEPLINK_CART_ADD_PRODUCT_PATTERN.split('/')[1]);}).map(function(params){var _params$action$params=params.action.params.pathname.split('/'),_params$action$params2=_slicedToArray(_params$action$params,4),productId=_params$action$params2[2],couponCode=_params$action$params2[3];return _extends({},params,{action:_extends({},params.action,{productId:decodeURIComponent(productId),couponCode:couponCode?decodeURIComponent(couponCode):undefined})});});
|
|
@@ -20,10 +20,10 @@ pipelineDependencies.set(pipelines.SHOPGATE_CART_ADD_COUPONS,[pipelines.SHOPGATE
|
|
|
20
20
|
*/event.addCallback('viewWillAppear',function(){dispatch(fetchCart());});// Reset the productPendingCount on app start to avoid a wrong value in the cart badge.
|
|
21
21
|
dispatch(setCartProductPendingCount(0));});subscribe(cartNeedsSync$,function(_ref3){var dispatch=_ref3.dispatch;dispatch(fetchCart());});subscribe(cartBusy$,function(){LoadingProvider.setLoading(CART_PATH);});subscribe(cartIdle$,function(){LoadingProvider.resetLoading(CART_PATH);});subscribe(cartDidEnterOrAppDidStart$,function(_ref4){var dispatch=_ref4.dispatch;dispatch(fetchRegisterUrl())["catch"](function(e){return e;});});subscribe(cartUpdateFailed$,function(_ref5){var dispatch=_ref5.dispatch,action=_ref5.action;/**
|
|
22
22
|
* @type {PipelineErrorElement[]} errors
|
|
23
|
-
*/var _action$errors=action.errors,errors=_action$errors===void 0?[]:_action$errors;if(Array.isArray(errors)&&errors.length){// Supports only one error, because none of the pipelines is ever called with multiple items.
|
|
23
|
+
*/var _action$errors=action.errors,errors=_action$errors===void 0?[]:_action$errors,_action$couponsIds=action.couponsIds,couponsIds=_action$couponsIds===void 0?[]:_action$couponsIds;if(Array.isArray(errors)&&errors.length){// Supports only one error, because none of the pipelines is ever called with multiple items.
|
|
24
24
|
// Multiple errors would cause the this to overlay multiple modals on top of each other.
|
|
25
25
|
var _errors$=errors[0],message=_errors$.message,handled=_errors$.handled;// Some errors are already handled automatically before
|
|
26
|
-
if(handled){return;}dispatch(showModal({confirm:'modal.ok',dismiss:null,title:'modal.title_error',message:message,type:MODAL_PIPELINE_ERROR,params:_extends({},errors[0])}));}});/**
|
|
26
|
+
if(handled){return;}dispatch(showModal({confirm:'modal.ok',dismiss:null,title:'modal.title_error',message:message,type:MODAL_PIPELINE_ERROR,params:_extends({},errors[0],Array.isArray(couponsIds)&&couponsIds.length>0?{request:{couponsIds:couponsIds}}:null)}));}});/**
|
|
27
27
|
* Gets triggered when a route with a coupon within its GET parameters will enter.
|
|
28
28
|
*/subscribe(routeWithCouponWillEnter$,function(_ref6){var dispatch=_ref6.dispatch,action=_ref6.action;var coupon=action.route.query.coupon;if(coupon){dispatch(addCouponsToCart([coupon]));}});/**
|
|
29
29
|
* Deeplink to add product to cart, eg /cart_add_product/123
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{mutable}from'@shopgate/pwa-common/helpers/redux';import fetchRootCategories from"./fetchRootCategories";import fetchCategory from"./fetchCategory";/**
|
|
2
|
+
* Retrieves a category from the server when a categoryId is given. Otherwise it will fetch the
|
|
3
|
+
* root categories.
|
|
4
|
+
* @param {string} categoryId The category ID.
|
|
5
|
+
* @return {Function} The dispatched action.
|
|
6
|
+
*/function fetchCategoryOrRootCategories(categoryId){return function(dispatch){if(!categoryId){dispatch(fetchRootCategories());return;}dispatch(fetchCategory(categoryId));};}export default mutable(fetchCategoryOrRootCategories);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
*
|
|
1
|
+
import{logDeprecationMessage}from'@shopgate/pwa-core/helpers';import fetchCategoryOrRootCategories from"./fetchCategoryOrRootCategories";/**
|
|
2
|
+
* Deprecation fallback for the fetchCategoryOrRootCategories action
|
|
3
|
+
* @deprecated
|
|
3
4
|
* @param {string} categoryId The category ID.
|
|
4
5
|
* @return {Function} The dispatched action.
|
|
5
|
-
*/var getCategory=function getCategory(categoryId){
|
|
6
|
+
*/var getCategory=function getCategory(categoryId){logDeprecationMessage('The fetch action getCategory will be removed in future versions due naming conflict with getCategory selector. Please use fetchCategoryOrRootCategories as a replacement');return fetchCategoryOrRootCategories(categoryId);};export default getCategory;
|
package/category/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// ACTIONS
|
|
2
|
-
export{default as fetchCategory}from"./actions/fetchCategory";export{default as
|
|
2
|
+
export{default as fetchCategory}from"./actions/fetchCategory";export{default as fetchCategoryOrRootCategories}from"./actions/fetchCategoryOrRootCategories";export{default as fetchCategoryChildren}from"./actions/fetchCategoryChildren";export{default as fetchCategoryProducts}from"./actions/fetchCategoryProducts";export{default as fetchRootCategories}from"./actions/fetchRootCategories";// CONSTANTS
|
|
3
3
|
export*from"./constants/index";export*from"./constants/Pipelines";export*from"./constants/Portals";// SELECTORS
|
|
4
4
|
export*from"./selectors";// STREAMS
|
|
5
5
|
export*from"./streams";// HELPERS
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopgate/pwa-common-commerce",
|
|
3
|
-
"version": "6.22.
|
|
3
|
+
"version": "6.22.1",
|
|
4
4
|
"description": "Commerce library for the Shopgate Connect PWA.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Shopgate <support@shopgate.com>",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"reselect": "^3.0.1"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@shopgate/pwa-common": "6.22.
|
|
22
|
-
"@shopgate/pwa-core": "6.22.
|
|
21
|
+
"@shopgate/pwa-common": "6.22.1",
|
|
22
|
+
"@shopgate/pwa-core": "6.22.1",
|
|
23
23
|
"lodash": "^4.17.4",
|
|
24
24
|
"react": "~16.12.0",
|
|
25
25
|
"react-dom": "~16.12.0"
|