@shopgate/engage 7.22.0-beta.1 → 7.22.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{PipelineRequest}from'@shopgate/engage/core/classes';import{FETCH_CUSTOMER,FETCH_CUSTOMER_ERROR,FETCH_CUSTOMER_SUCCESS}from"../constants/actions";/**
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{PipelineRequest}from'@shopgate/engage/core/classes';import{EINVALIDCALL}from'@shopgate/engage/core/constants';import{FETCH_CUSTOMER,FETCH_CUSTOMER_ERROR,FETCH_CUSTOMER_SUCCESS}from"../constants";/**
2
2
  * Starts entering the checkout process for the customer.
3
3
  * @returns {Function}
4
- */export var fetchCustomerData=function fetchCustomerData(){return(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch){var _ref3,customer;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:dispatch({type:FETCH_CUSTOMER});_context.prev=1;_context.next=4;return new PipelineRequest('shopgate.customer.getCustomer').setTrusted().dispatch();case 4:_ref3=_context.sent;customer=_ref3.customer;dispatch({type:FETCH_CUSTOMER_SUCCESS,customer:customer});return _context.abrupt("return",customer);case 10:_context.prev=10;_context.t0=_context["catch"](1);dispatch({type:FETCH_CUSTOMER_ERROR,error:_context.t0});throw _context.t0;case 14:case"end":return _context.stop();}},_callee,null,[[1,10]]);}));return function(_x){return _ref.apply(this,arguments);};}());};
4
+ */export var fetchCustomerData=function fetchCustomerData(){return(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch){var _ref3,customer;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:dispatch({type:FETCH_CUSTOMER});_context.prev=1;_context.next=4;return new PipelineRequest('shopgate.customer.getCustomer').setTrusted().setErrorBlacklist([EINVALIDCALL]).dispatch();case 4:_ref3=_context.sent;customer=_ref3.customer;dispatch({type:FETCH_CUSTOMER_SUCCESS,customer:customer});return _context.abrupt("return",customer);case 10:_context.prev=10;_context.t0=_context["catch"](1);dispatch({type:FETCH_CUSTOMER_ERROR,error:_context.t0});throw _context.t0;case 14:case"end":return _context.stop();}},_callee,null,[[1,10]]);}));return function(_x){return _ref.apply(this,arguments);};}());};
@@ -0,0 +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{PipelineRequest}from"../../core";import selectLocation from"../action-creators/selectLocation";/**
2
+ * Fetches the default location of the user
3
+ * @returns {Function} redux thunk
4
+ */var fetchDefaultLocation=function fetchDefaultLocation(){return(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch){var request,_ref2,location;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:request=new PipelineRequest('shopgate.user.getDefaultLocation').dispatch();_context.next=3;return request;case 3:_ref2=_context.sent;location=_ref2.location;if(location){dispatch(selectLocation(location));}return _context.abrupt("return",request);case 7:case"end":return _context.stop();}},_callee);}));return function(_x){return _ref.apply(this,arguments);};}());};export default fetchDefaultLocation;
@@ -1,4 +1,4 @@
1
- import{SET_LOCATIONS_PENDING}from"../constants/ActionTypes";export{default as fetchFulfillmentSlots}from"./fetchFulfillmentSlots";export{default as fetchInventories}from"./fetchInventories";export{default as fetchLocations}from"./fetchLocations";export{default as fetchProductInventories}from"./fetchProductInventories";export{default as fetchProductLocations}from"./fetchProductLocations";export{default as submitReservation}from"./submitReservation";export{default as setUserSearchGeolocation}from"./setUserSearchGeolocation";export{default as setUserGeolocation}from"./setUserGeolocation";/**
1
+ import{SET_LOCATIONS_PENDING}from"../constants/ActionTypes";export{default as fetchFulfillmentSlots}from"./fetchFulfillmentSlots";export{default as fetchInventories}from"./fetchInventories";export{default as fetchLocations}from"./fetchLocations";export{default as fetchProductInventories}from"./fetchProductInventories";export{default as fetchProductLocations}from"./fetchProductLocations";export{default as submitReservation}from"./submitReservation";export{default as setUserSearchGeolocation}from"./setUserSearchGeolocation";export{default as setUserGeolocation}from"./setUserGeolocation";export{default as sendDefaultLocationCode}from"./sendDefaultLocationCode";export{default as fetchDefaultLocation}from"./fetchDefaultLocation";/**
2
2
  * Sets pending state of locations
3
3
  * @param {boolean} value Value
4
4
  * @returns {Object}
@@ -0,0 +1,6 @@
1
+ import{PipelineRequest}from"../../core";/**
2
+ * pipeline call to shopgate.user.sendDefaultLocationCodeCode.v1
3
+ * to set user default location in data base
4
+ * @param {string} locationCode The location code to send to backend
5
+ * @returns {Function} redux thunk
6
+ */var sendDefaultLocationCode=function sendDefaultLocationCode(locationCode){return function(){return new PipelineRequest('shopgate.user.setDefaultLocationCode').setInput({locationCode:locationCode}).dispatch();};};export default sendDefaultLocationCode;
@@ -1,7 +1,6 @@
1
1
  import React,{useCallback,useMemo}from'react';import PropTypes from'prop-types';import{connect}from'react-redux';import{getCurrentRoute}from'@shopgate/pwa-common/selectors/router';import{selectGlobalLocation}from'@shopgate/engage/locations/action-creators';import{getPreferredLocation,getIsPending}from"../../selectors";import{getIsLocationBasedShopping}from"../../../core/selectors";import{FulfillmentSheet}from"../FulfillmentSheet";import{STAGE_SELECT_STORE,MULTI_LINE_RESERVE}from"../../constants";/**
2
2
  * Maps state to props.
3
3
  * @param {Object} state State
4
- * @param {Object} props Props
5
4
  * @return {Object}
6
5
  */var mapStateToProps=function mapStateToProps(state){return{currentRoute:getCurrentRoute(state),isLocationBasedShopping:getIsLocationBasedShopping(state),isPending:getIsPending(state),preferredLocation:getPreferredLocation(state)};};/**
7
6
  * Maps the contents of the state to the component props.
@@ -1,5 +1,5 @@
1
1
  import React,{useCallback,useContext}from'react';import{RippleButton}from'@shopgate/engage/components';import{StoreContext}from"./Store.context";import{i18n}from"../../../core";import{StoreFinderContext}from"../../locations.context";import{selectLocationButton,selectLocationButtonWrapper}from"../StoreList/Store.style";/**
2
2
  * The StoreFinderSelectLocationButton component.
3
3
  * Renders if route query.selectLocation param is passed
4
- * @returns {JSX}
4
+ * @returns {JSX.Element}
5
5
  */export var StoreFinderSelectLocationButton=function StoreFinderSelectLocationButton(){var store=useContext(StoreContext);var _useContext=useContext(StoreFinderContext),selectLocation=_useContext.selectLocation,isLoading=_useContext.isLoading;var handleClick=useCallback(function(e){e.stopPropagation();selectLocation(store);},[selectLocation,store]);return React.createElement("div",{className:selectLocationButtonWrapper},React.createElement(RippleButton,{onClick:handleClick,className:selectLocationButton.toString(),disabled:isLoading||(store===null||store===void 0?void 0:store.isComingSoon)},i18n.text('locations.select_location')));};
@@ -1,4 +1,4 @@
1
1
  import React,{useContext,useCallback}from'react';import{RippleButton}from'@shopgate/engage/components';import PropTypes from'prop-types';import{isProductAvailable}from"../../helpers";import{StoreContext}from"./Store.context";import{i18n,useWidgetSettings}from"../../../core";import{FulfillmentContext}from"../../locations.context";import{selectLocationButton,selectLocationButtonWrapper}from"./Store.style";import connect from"./StoreListSearch.connector";/**
2
2
  * The StoreSelectLocationButton component.
3
- * @returns {JSX}
3
+ * @returns {JSX.Element}
4
4
  */var StoreSelectLocationButton=function StoreSelectLocationButton(_ref){var setPostalCode=_ref.setPostalCode;var store=useContext(StoreContext);var _ref2=useWidgetSettings('@shopgate/engage/locations')||{},_ref2$setUserSearchZi=_ref2.setUserSearchZipLocationFromSelection,setUserSearchZipLocationFromSelection=_ref2$setUserSearchZi===void 0?true:_ref2$setUserSearchZi;var _useContext=useContext(FulfillmentContext),selectLocation=_useContext.selectLocation,noInventory=_useContext.noInventory,isLoading=_useContext.isLoading,product=_useContext.product;var isAvailable=isProductAvailable(store,store===null||store===void 0?void 0:store.inventory);var handleClick=useCallback(function(e){e.stopPropagation();if(noInventory||isAvailable){if(setUserSearchZipLocationFromSelection){setPostalCode(store.address.postalCode,product===null||product===void 0?void 0:product.id);}selectLocation(store);}},[isAvailable,noInventory,product,selectLocation,setPostalCode,setUserSearchZipLocationFromSelection,store]);return React.createElement("div",{className:selectLocationButtonWrapper},React.createElement(RippleButton,{onClick:handleClick,className:selectLocationButton.toString(),disabled:isLoading||(store===null||store===void 0?void 0:store.isComingSoon)||!noInventory&&!isAvailable},i18n.text('locations.select_location')));};var connectedStoreSelectLocationButton=connect(StoreSelectLocationButton);export{connectedStoreSelectLocationButton as StoreSelectLocationButton};
@@ -1,4 +1,4 @@
1
- import _regeneratorRuntime from"@babel/runtime/regenerator";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 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{getProductsResult,productIsReady$,productsReceived$,productsReceivedCached$,RECEIVE_PRODUCTS_CACHED,variantDidChange$}from'@shopgate/engage/product';import{cartReceived$,fetchCart,cartDidEnter$,getCartItems}from'@shopgate/engage/cart';import{userDidLogin$}from'@shopgate/engage/user';import{appDidStart$,routeWillEnter$,UIEvents,getCurrentRoute,hex2bin,getThemeSettings,getCurrentSearchQuery}from'@shopgate/engage/core';import{receiveFavoritesWhileVisible$}from'@shopgate/pwa-common-commerce/favorites/streams';import{getFavoritesProductsIds,isFetching}from'@shopgate/pwa-common-commerce/favorites/selectors';import{categoryDidBackEnter$}from'@shopgate/pwa-common-commerce/category/streams';import{searchDidBackEntered$}from'@shopgate/pwa-common-commerce/search/streams';import{hasNewServices}from'@shopgate/engage/core/helpers';import{cookieConsentInitialized$}from'@shopgate/engage/tracking/streams';import{getUserSearch,getStoreFinderSearch,getPreferredLocation,getIsPending,getProductAlternativeLocationParams,getProductAlternativeLocations}from"./selectors";import{fetchLocations,fetchProductLocations,setPending,setUserGeolocation}from"./actions";import{setShowInventoryInLists,showInventoryInLists}from"./helpers/showInventoryInLists";import fetchInventories from"./actions/fetchInventories";import{EVENT_SET_OPEN}from"./providers/FulfillmentProvider";import fetchProductInventories from"./actions/fetchProductInventories";import{submitReservationSuccess$,userSearchChanged$,storeFinderWillEnter$,preferredLocationDidUpdateOnPDP$,provideAlternativeLocation$,preferredLocationDidUpdateGlobalOnWishlist$}from"./locations.streams";import selectLocation from"./action-creators/selectLocation";import{SET_STORE_FINDER_SEARCH_RADIUS}from"./constants";import selectGlobalLocation from"./action-creators/selectGlobalLocation";var initialLocationsResolve;var initialLocationsReject;var initialLocationsPromise=new Promise(function(resolve,reject){initialLocationsResolve=resolve;initialLocationsReject=reject;});/**
1
+ import _regeneratorRuntime from"@babel/runtime/regenerator";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 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{getProductsResult,productIsReady$,productsReceived$,productsReceivedCached$,RECEIVE_PRODUCTS_CACHED,variantDidChange$}from'@shopgate/engage/product';import{cartReceived$,fetchCart,cartDidEnter$,getCartItems}from'@shopgate/engage/cart';import{userDidLogin$}from'@shopgate/engage/user';import{appDidStart$,routeWillEnter$,UIEvents,getCurrentRoute,hex2bin,getThemeSettings,getCurrentSearchQuery,appWillInit$,appInitialization}from'@shopgate/engage/core';import{receiveFavoritesWhileVisible$}from'@shopgate/pwa-common-commerce/favorites/streams';import{getFavoritesProductsIds,isFetching}from'@shopgate/pwa-common-commerce/favorites/selectors';import{categoryDidBackEnter$}from'@shopgate/pwa-common-commerce/category/streams';import{searchDidBackEntered$}from'@shopgate/pwa-common-commerce/search/streams';import{hasNewServices}from'@shopgate/engage/core/helpers';import{cookieConsentInitialized$}from'@shopgate/engage/tracking/streams';import{getUserSearch,getStoreFinderSearch,getPreferredLocation,getIsPending,getProductAlternativeLocationParams,getProductAlternativeLocations}from"./selectors";import{fetchDefaultLocation,fetchLocations,fetchProductLocations,sendDefaultLocationCode,setPending,setUserGeolocation}from"./actions";import{setShowInventoryInLists,showInventoryInLists}from"./helpers";import fetchInventories from"./actions/fetchInventories";import{EVENT_SET_OPEN}from"./providers/FulfillmentProvider";import fetchProductInventories from"./actions/fetchProductInventories";import{submitReservationSuccess$,userSearchChanged$,storeFinderWillEnter$,preferredLocationDidUpdateOnPDP$,provideAlternativeLocation$,preferredLocationDidUpdateGlobalOnWishlist$,preferredLocationDidUpdate$}from"./locations.streams";import selectLocation from"./action-creators/selectLocation";import{SET_STORE_FINDER_SEARCH_RADIUS}from"./constants";import selectGlobalLocation from"./action-creators/selectGlobalLocation";var initialLocationsResolve;var initialLocationsReject;var initialLocationsPromise=new Promise(function(resolve,reject){initialLocationsResolve=resolve;initialLocationsReject=reject;});/**
2
2
  * Sets a location once the location has been validated.
3
3
  * @param {string} locationCode Location code
4
4
  * @param {Function} dispatch Redux dispatch function
@@ -6,22 +6,24 @@ import _regeneratorRuntime from"@babel/runtime/regenerator";function _extends(){
6
6
  */var setLocationOnceAvailable=/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(locationCode,dispatch){var _ref3,initialLocations;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:_context.prev=0;_context.next=3;return initialLocationsPromise;case 3:_ref3=_context.sent;initialLocations=_ref3.locations;if(initialLocations.some(function(l){return l.code===locationCode;})){_context.next=7;break;}return _context.abrupt("return");case 7:dispatch(selectLocation({code:locationCode}));requestAnimationFrame(function(){dispatch(setPending(false));});_context.next=13;break;case 11:_context.prev=11;_context.t0=_context["catch"](0);case 13:case"end":return _context.stop();}},_callee,null,[[0,11]]);}));return function setLocationOnceAvailable(_x,_x2){return _ref.apply(this,arguments);};}();/**
7
7
  * Locations subscriptions.
8
8
  * @param {Function} subscribe The subscribe function.
9
- */function locationsSubscriber(subscribe){subscribe(cookieConsentInitialized$,/*#__PURE__*/function(){var _ref5=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref4){var dispatch,getState,userSearch,_ref7,locations,preferredLocation,code,hasLocation,_ref9,preferredLocationDefault,locationToPreselect;return _regeneratorRuntime.wrap(function _callee2$(_context2){while(1)switch(_context2.prev=_context2.next){case 0:dispatch=_ref4.dispatch,getState=_ref4.getState;if(hasNewServices()){_context2.next=3;break;}return _context2.abrupt("return");case 3:// Fetch merchants locations.
10
- userSearch=getUserSearch(getState());_context2.prev=4;_context2.next=7;return dispatch(fetchLocations(userSearch));case 7:_ref7=_context2.sent;locations=_ref7.locations;preferredLocation=getPreferredLocation(getState());if(!preferredLocation){_context2.next=16;break;}code=preferredLocation.code;// Check if the preferred location is included within the fetched locations
11
- hasLocation=!!locations.find(function(location){return location.code===code;});if(hasLocation){_context2.next=16;break;}_context2.next=16;return dispatch(fetchLocations({codes:[code]}));case 16:// Preset preferredLocation if configured
12
- _ref9=getThemeSettings('@shopgate/engage/locations')||{},preferredLocationDefault=_ref9.preferredLocationDefault;if(preferredLocationDefault){// check if there is already a preferredLocation for the user, if not set one
13
- if(!preferredLocation){locationToPreselect=locations.find(function(l){return l.code===preferredLocationDefault;});if(locationToPreselect){dispatch(selectLocation({code:preferredLocationDefault}));}}}initialLocationsResolve(locations);_context2.next=24;break;case 21:_context2.prev=21;_context2.t0=_context2["catch"](4);initialLocationsReject(_context2.t0);case 24:UIEvents.addListener(EVENT_SET_OPEN,function(){var route=getCurrentRoute(getState());if(!route.params.productId&&!route.state.productId){return;}var productId=route.state.productId||hex2bin(route.params.productId);if(productId){dispatch(fetchProductLocations(productId,getUserSearch(getState())));}});case 25:case"end":return _context2.stop();}},_callee2,null,[[4,21]]);}));return function(_x3){return _ref5.apply(this,arguments);};}());subscribe(userSearchChanged$,/*#__PURE__*/function(){var _ref11=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref10){var dispatch,getState,action,productId,isStoreFinder,silent,state,userSearch,storeFinderSearch;return _regeneratorRuntime.wrap(function _callee3$(_context3){while(1)switch(_context3.prev=_context3.next){case 0:dispatch=_ref10.dispatch,getState=_ref10.getState,action=_ref10.action;productId=action.productId,isStoreFinder=action.isStoreFinder,silent=action.silent;if(!(silent===true)){_context3.next=4;break;}return _context3.abrupt("return");case 4:state=getState();userSearch=getUserSearch(state);if(!(isStoreFinder||action.type===SET_STORE_FINDER_SEARCH_RADIUS)){_context3.next=12;break;}storeFinderSearch=getStoreFinderSearch(state);_context3.next=10;return dispatch(fetchLocations(_extends({},userSearch,{},storeFinderSearch,{enableInLocationFinder:true})));case 10:_context3.next=19;break;case 12:if(productId){_context3.next=17;break;}_context3.next=15;return dispatch(fetchLocations(userSearch));case 15:_context3.next=19;break;case 17:_context3.next=19;return dispatch(fetchProductLocations(productId,userSearch));case 19:case"end":return _context3.stop();}},_callee3);}));return function(_x4){return _ref11.apply(this,arguments);};}());var productInventoryNeedsUpdate$=productIsReady$.merge(variantDidChange$).merge(preferredLocationDidUpdateOnPDP$).debounceTime(200);subscribe(productInventoryNeedsUpdate$,function(_ref12){var action=_ref12.action,dispatch=_ref12.dispatch,getState=_ref12.getState;var productData=action.productData;// Skip if no fulfillment methods are set.
9
+ */function locationsSubscriber(subscribe){subscribe(appWillInit$,function(){appInitialization.set('location',/*#__PURE__*/function(){var _ref5=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref4){var dispatch,getState,location;return _regeneratorRuntime.wrap(function _callee2$(_context2){while(1)switch(_context2.prev=_context2.next){case 0:dispatch=_ref4.dispatch,getState=_ref4.getState;// check if location was set by user and is stored in redux
10
+ location=getPreferredLocation(getState());// if NO location has been set: get location from backend and set in redux
11
+ if(!(!location&&hasNewServices())){_context2.next=5;break;}_context2.next=5;return dispatch(fetchDefaultLocation());case 5:case"end":return _context2.stop();}},_callee2);}));return function(_x3){return _ref5.apply(this,arguments);};}());});subscribe(preferredLocationDidUpdate$,function(_ref6){var dispatch=_ref6.dispatch,getState=_ref6.getState;var preferredLocation=getPreferredLocation(getState());if(preferredLocation){dispatch(sendDefaultLocationCode(preferredLocation.code));}});subscribe(cookieConsentInitialized$,/*#__PURE__*/function(){var _ref8=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref7){var dispatch,getState,userSearch,_ref10,locations,preferredLocation,code,hasLocation,_ref12,preferredLocationDefault,locationToPreselect;return _regeneratorRuntime.wrap(function _callee3$(_context3){while(1)switch(_context3.prev=_context3.next){case 0:dispatch=_ref7.dispatch,getState=_ref7.getState;if(hasNewServices()){_context3.next=3;break;}return _context3.abrupt("return");case 3:// Fetch merchants locations.
12
+ userSearch=getUserSearch(getState());_context3.prev=4;_context3.next=7;return dispatch(fetchLocations(userSearch));case 7:_ref10=_context3.sent;locations=_ref10.locations;preferredLocation=getPreferredLocation(getState());if(!preferredLocation){_context3.next=16;break;}code=preferredLocation.code;// Check if the preferred location is included within the fetched locations
13
+ hasLocation=!!locations.find(function(location){return location.code===code;});if(hasLocation){_context3.next=16;break;}_context3.next=16;return dispatch(fetchLocations({codes:[code]}));case 16:// Preset preferredLocation if configured
14
+ _ref12=getThemeSettings('@shopgate/engage/locations')||{},preferredLocationDefault=_ref12.preferredLocationDefault;if(preferredLocationDefault){// check if there is already a preferredLocation for the user, if not set one
15
+ if(!preferredLocation){locationToPreselect=locations.find(function(l){return l.code===preferredLocationDefault;});if(locationToPreselect){dispatch(selectLocation({code:preferredLocationDefault}));}}}initialLocationsResolve(locations);_context3.next=24;break;case 21:_context3.prev=21;_context3.t0=_context3["catch"](4);initialLocationsReject(_context3.t0);case 24:UIEvents.addListener(EVENT_SET_OPEN,function(){var route=getCurrentRoute(getState());if(!route.params.productId&&!route.state.productId){return;}var productId=route.state.productId||hex2bin(route.params.productId);if(productId){dispatch(fetchProductLocations(productId,getUserSearch(getState())));}});case 25:case"end":return _context3.stop();}},_callee3,null,[[4,21]]);}));return function(_x4){return _ref8.apply(this,arguments);};}());subscribe(userSearchChanged$,/*#__PURE__*/function(){var _ref14=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref13){var dispatch,getState,action,productId,isStoreFinder,silent,state,userSearch,storeFinderSearch;return _regeneratorRuntime.wrap(function _callee4$(_context4){while(1)switch(_context4.prev=_context4.next){case 0:dispatch=_ref13.dispatch,getState=_ref13.getState,action=_ref13.action;productId=action.productId,isStoreFinder=action.isStoreFinder,silent=action.silent;if(!(silent===true)){_context4.next=4;break;}return _context4.abrupt("return");case 4:state=getState();userSearch=getUserSearch(state);if(!(isStoreFinder||action.type===SET_STORE_FINDER_SEARCH_RADIUS)){_context4.next=12;break;}storeFinderSearch=getStoreFinderSearch(state);_context4.next=10;return dispatch(fetchLocations(_extends({},userSearch,{},storeFinderSearch,{enableInLocationFinder:true})));case 10:_context4.next=19;break;case 12:if(productId){_context4.next=17;break;}_context4.next=15;return dispatch(fetchLocations(userSearch));case 15:_context4.next=19;break;case 17:_context4.next=19;return dispatch(fetchProductLocations(productId,userSearch));case 19:case"end":return _context4.stop();}},_callee4);}));return function(_x5){return _ref14.apply(this,arguments);};}());var productInventoryNeedsUpdate$=productIsReady$.merge(variantDidChange$).merge(preferredLocationDidUpdateOnPDP$).debounceTime(200);subscribe(productInventoryNeedsUpdate$,function(_ref15){var action=_ref15.action,dispatch=_ref15.dispatch,getState=_ref15.getState;var productData=action.productData;// Skip if no fulfillment methods are set.
14
16
  if(!productData||!productData.fulfillmentMethods||productData.fulfillmentMethods.length===0){return;}var state=getState();var preferredLocation=getPreferredLocation(state);if(!preferredLocation){return;}// Fetch inventories for this specific product.
15
17
  dispatch(fetchProductInventories(action.productData.id,{locationCodes:[preferredLocation.code]}));});// Core config and cart subscriptions
16
- var fetchCart$=cartDidEnter$.switchMap(function(){return submitReservationSuccess$.first();}).delay(500);subscribe(fetchCart$,function(_ref13){var dispatch=_ref13.dispatch;dispatch(fetchCart());});subscribe(storeFinderWillEnter$,/*#__PURE__*/function(){var _ref15=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref14){var dispatch,getState,state,userSearch,storeFinderSearch;return _regeneratorRuntime.wrap(function _callee4$(_context4){while(1)switch(_context4.prev=_context4.next){case 0:dispatch=_ref14.dispatch,getState=_ref14.getState;state=getState();// Fetch merchants locations.
17
- userSearch=getUserSearch(state);storeFinderSearch=getStoreFinderSearch(state);_context4.next=6;return dispatch(fetchLocations(_extends({},userSearch,{},storeFinderSearch,{enableInLocationFinder:true})));case 6:case"end":return _context4.stop();}},_callee4);}));return function(_x5){return _ref15.apply(this,arguments);};}());/**
18
+ var fetchCart$=cartDidEnter$.switchMap(function(){return submitReservationSuccess$.first();}).delay(500);subscribe(fetchCart$,function(_ref16){var dispatch=_ref16.dispatch;dispatch(fetchCart());});subscribe(storeFinderWillEnter$,/*#__PURE__*/function(){var _ref18=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(_ref17){var dispatch,getState,state,userSearch,storeFinderSearch;return _regeneratorRuntime.wrap(function _callee5$(_context5){while(1)switch(_context5.prev=_context5.next){case 0:dispatch=_ref17.dispatch,getState=_ref17.getState;state=getState();// Fetch merchants locations.
19
+ userSearch=getUserSearch(state);storeFinderSearch=getStoreFinderSearch(state);_context5.next=6;return dispatch(fetchLocations(_extends({},userSearch,{},storeFinderSearch,{enableInLocationFinder:true})));case 6:case"end":return _context5.stop();}},_callee5);}));return function(_x6){return _ref18.apply(this,arguments);};}());/**
18
20
  * Makes sure that the active location is switched after logging in
19
21
  * to a location that is also available in the cart.
20
22
  * Avoids having a selected location that differs from the cart
21
- */var afterCartMerge$=userDidLogin$.mergeMap(function(){return cartReceived$.first();});subscribe(afterCartMerge$,/*#__PURE__*/function(){var _ref17=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(_ref16){var _cartItems$,_cartItems$$fulfillme,_cartItems$$fulfillme2;var dispatch,getState,state,cartItems,preferredLocation,activeCartLocation,firstLocationCode;return _regeneratorRuntime.wrap(function _callee5$(_context5){while(1)switch(_context5.prev=_context5.next){case 0:dispatch=_ref16.dispatch,getState=_ref16.getState;state=getState();cartItems=getCartItems(state);preferredLocation=getPreferredLocation(state,{});if(cartItems===null||cartItems===void 0?void 0:cartItems.length){_context5.next=6;break;}return _context5.abrupt("return");case 6:activeCartLocation=cartItems.find(function(item){var _item$fulfillment,_item$fulfillment$loc;return((_item$fulfillment=item.fulfillment)===null||_item$fulfillment===void 0?void 0:(_item$fulfillment$loc=_item$fulfillment.location)===null||_item$fulfillment$loc===void 0?void 0:_item$fulfillment$loc.code)===(preferredLocation===null||preferredLocation===void 0?void 0:preferredLocation.code);});if(!activeCartLocation){_context5.next=9;break;}return _context5.abrupt("return");case 9:firstLocationCode=(_cartItems$=cartItems[0])===null||_cartItems$===void 0?void 0:(_cartItems$$fulfillme=_cartItems$.fulfillment)===null||_cartItems$$fulfillme===void 0?void 0:(_cartItems$$fulfillme2=_cartItems$$fulfillme.location)===null||_cartItems$$fulfillme2===void 0?void 0:_cartItems$$fulfillme2.code;if(firstLocationCode){_context5.next=12;break;}return _context5.abrupt("return");case 12:dispatch(selectLocation({code:firstLocationCode}));dispatch(selectGlobalLocation({code:firstLocationCode}));case 14:case"end":return _context5.stop();}},_callee5);}));return function(_x6){return _ref17.apply(this,arguments);};}());/**
23
+ */var afterCartMerge$=userDidLogin$.mergeMap(function(){return cartReceived$.first();});subscribe(afterCartMerge$,/*#__PURE__*/function(){var _ref20=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(_ref19){var _cartItems$,_cartItems$$fulfillme,_cartItems$$fulfillme2;var dispatch,getState,state,cartItems,preferredLocation,activeCartLocation,firstLocationCode;return _regeneratorRuntime.wrap(function _callee6$(_context6){while(1)switch(_context6.prev=_context6.next){case 0:dispatch=_ref19.dispatch,getState=_ref19.getState;state=getState();cartItems=getCartItems(state);preferredLocation=getPreferredLocation(state,{});if(cartItems===null||cartItems===void 0?void 0:cartItems.length){_context6.next=6;break;}return _context6.abrupt("return");case 6:activeCartLocation=cartItems.find(function(item){var _item$fulfillment,_item$fulfillment$loc;return((_item$fulfillment=item.fulfillment)===null||_item$fulfillment===void 0?void 0:(_item$fulfillment$loc=_item$fulfillment.location)===null||_item$fulfillment$loc===void 0?void 0:_item$fulfillment$loc.code)===(preferredLocation===null||preferredLocation===void 0?void 0:preferredLocation.code);});if(!activeCartLocation){_context6.next=9;break;}return _context6.abrupt("return");case 9:firstLocationCode=(_cartItems$=cartItems[0])===null||_cartItems$===void 0?void 0:(_cartItems$$fulfillme=_cartItems$.fulfillment)===null||_cartItems$$fulfillme===void 0?void 0:(_cartItems$$fulfillme2=_cartItems$$fulfillme.location)===null||_cartItems$$fulfillme2===void 0?void 0:_cartItems$$fulfillme2.code;if(firstLocationCode){_context6.next=12;break;}return _context6.abrupt("return");case 12:dispatch(selectLocation({code:firstLocationCode}));dispatch(selectGlobalLocation({code:firstLocationCode}));case 14:case"end":return _context6.stop();}},_callee6);}));return function(_x7){return _ref20.apply(this,arguments);};}());/**
22
24
  * Handles an added store url parameter that will set the default store location
23
- */subscribe(routeWillEnter$,function(_ref18){var action=_ref18.action,dispatch=_ref18.dispatch,getState=_ref18.getState;var locationCode=action.route.query.store;if(!locationCode){if(!getIsPending(getState())){dispatch(setPending(false));}return;}setLocationOnceAvailable(locationCode,dispatch);});var alternative$=productInventoryNeedsUpdate$.switchMap(function(){return provideAlternativeLocation$.first();});/**
25
+ */subscribe(routeWillEnter$,function(_ref21){var action=_ref21.action,dispatch=_ref21.dispatch,getState=_ref21.getState;var locationCode=action.route.query.store;if(!locationCode){if(!getIsPending(getState())){dispatch(setPending(false));}return;}setLocationOnceAvailable(locationCode,dispatch);});var alternative$=productInventoryNeedsUpdate$.switchMap(function(){return provideAlternativeLocation$.first();});/**
24
26
  * Provide alternative location on PDP when preferred location is out of stock
25
- */subscribe(alternative$,/*#__PURE__*/function(){var _ref20=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(_ref19){var action,dispatch,getState,state,alternativeLocations,productId,params,alternativeParams,fetchParams;return _regeneratorRuntime.wrap(function _callee6$(_context6){while(1)switch(_context6.prev=_context6.next){case 0:action=_ref19.action,dispatch=_ref19.dispatch,getState=_ref19.getState;_context6.next=3;return dispatch(setUserGeolocation({silent:true}));case 3:// Get new state with geolocation
26
- state=getState();alternativeLocations=getProductAlternativeLocations(state,action);if(!alternativeLocations){_context6.next=7;break;}return _context6.abrupt("return");case 7:productId=action.productId,params=action.params;alternativeParams=getProductAlternativeLocationParams(state);fetchParams=_extends({},alternativeParams,{},params);if(fetchParams.geolocation||fetchParams.postalCode){dispatch(fetchProductLocations(productId,fetchParams));}case 11:case"end":return _context6.stop();}},_callee6);}));return function(_x7){return _ref20.apply(this,arguments);};}());subscribe(categoryDidBackEnter$.merge(searchDidBackEntered$),function(_ref21){var _getProductsResult;var action=_ref21.action,dispatch=_ref21.dispatch,getState=_ref21.getState;var state=getState();if(!showInventoryInLists(state)){return;}var categoryId=action.route.params.categoryId;var query=getCurrentSearchQuery(state);var products=(_getProductsResult=getProductsResult(state,{categoryId:hex2bin(categoryId),searchPhrase:query}))===null||_getProductsResult===void 0?void 0:_getProductsResult.products;if(!products||!products.length){return;}var productCodes=products.map(function(_ref22){var id=_ref22.id;return id;});dispatch(fetchInventories(productCodes));});subscribe(productsReceived$.merge(productsReceivedCached$),function(_ref23){var action=_ref23.action,dispatch=_ref23.dispatch,getState=_ref23.getState;if(!showInventoryInLists(getState())){return;}if(!action.products||!action.products.length||(action===null||action===void 0?void 0:action.fetchInventory)===false){return;}var productCodes=action.type!==RECEIVE_PRODUCTS_CACHED?action.products.map(function(_ref24){var id=_ref24.id;return id;}):action.products;dispatch(fetchInventories(productCodes));});subscribe(receiveFavoritesWhileVisible$.merge(preferredLocationDidUpdateGlobalOnWishlist$),function(_ref25){var dispatch=_ref25.dispatch,getState=_ref25.getState;var state=getState();if(!showInventoryInLists(state)||isFetching(getState())){return;}var productIds=getFavoritesProductsIds(state);if(!productIds||!productIds.length){return;}dispatch(fetchInventories(productIds));});subscribe(appDidStart$,function(_ref26){var getState=_ref26.getState;// enable inventory in product lists for some users
27
+ */subscribe(alternative$,/*#__PURE__*/function(){var _ref23=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7(_ref22){var action,dispatch,getState,state,alternativeLocations,productId,params,alternativeParams,fetchParams;return _regeneratorRuntime.wrap(function _callee7$(_context7){while(1)switch(_context7.prev=_context7.next){case 0:action=_ref22.action,dispatch=_ref22.dispatch,getState=_ref22.getState;_context7.next=3;return dispatch(setUserGeolocation({silent:true}));case 3:// Get new state with geolocation
28
+ state=getState();alternativeLocations=getProductAlternativeLocations(state,action);if(!alternativeLocations){_context7.next=7;break;}return _context7.abrupt("return");case 7:productId=action.productId,params=action.params;alternativeParams=getProductAlternativeLocationParams(state);fetchParams=_extends({},alternativeParams,{},params);if(fetchParams.geolocation||fetchParams.postalCode){dispatch(fetchProductLocations(productId,fetchParams));}case 11:case"end":return _context7.stop();}},_callee7);}));return function(_x8){return _ref23.apply(this,arguments);};}());subscribe(categoryDidBackEnter$.merge(searchDidBackEntered$),function(_ref24){var _getProductsResult;var action=_ref24.action,dispatch=_ref24.dispatch,getState=_ref24.getState;var state=getState();if(!showInventoryInLists(state)){return;}var categoryId=action.route.params.categoryId;var query=getCurrentSearchQuery(state);var products=(_getProductsResult=getProductsResult(state,{categoryId:hex2bin(categoryId),searchPhrase:query}))===null||_getProductsResult===void 0?void 0:_getProductsResult.products;if(!products||!products.length){return;}var productCodes=products.map(function(_ref25){var id=_ref25.id;return id;});dispatch(fetchInventories(productCodes));});subscribe(productsReceived$.merge(productsReceivedCached$),function(_ref26){var action=_ref26.action,dispatch=_ref26.dispatch,getState=_ref26.getState;if(!showInventoryInLists(getState())){return;}if(!action.products||!action.products.length||(action===null||action===void 0?void 0:action.fetchInventory)===false){return;}var productCodes=action.type!==RECEIVE_PRODUCTS_CACHED?action.products.map(function(_ref27){var id=_ref27.id;return id;}):action.products;dispatch(fetchInventories(productCodes));});subscribe(receiveFavoritesWhileVisible$.merge(preferredLocationDidUpdateGlobalOnWishlist$),function(_ref28){var dispatch=_ref28.dispatch,getState=_ref28.getState;var state=getState();if(!showInventoryInLists(state)||isFetching(getState())){return;}var productIds=getFavoritesProductsIds(state);if(!productIds||!productIds.length){return;}dispatch(fetchInventories(productIds));});subscribe(appDidStart$,function(_ref29){var getState=_ref29.getState;// enable inventory in product lists for some users
27
29
  setShowInventoryInLists(getState());});}export default locationsSubscriber;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopgate/engage",
3
- "version": "7.22.0-beta.1",
3
+ "version": "7.22.0-beta.3",
4
4
  "description": "Shopgate's ENGAGE library.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Shopgate <support@shopgate.com>",
@@ -16,12 +16,12 @@
16
16
  ],
17
17
  "dependencies": {
18
18
  "@shopgate/native-modules": "1.0.0-beta.18",
19
- "@shopgate/pwa-common": "7.22.0-beta.1",
20
- "@shopgate/pwa-common-commerce": "7.22.0-beta.1",
21
- "@shopgate/pwa-core": "7.22.0-beta.1",
22
- "@shopgate/pwa-ui-ios": "7.22.0-beta.1",
23
- "@shopgate/pwa-ui-material": "7.22.0-beta.1",
24
- "@shopgate/pwa-ui-shared": "7.22.0-beta.1",
19
+ "@shopgate/pwa-common": "7.22.0-beta.3",
20
+ "@shopgate/pwa-common-commerce": "7.22.0-beta.3",
21
+ "@shopgate/pwa-core": "7.22.0-beta.3",
22
+ "@shopgate/pwa-ui-ios": "7.22.0-beta.3",
23
+ "@shopgate/pwa-ui-material": "7.22.0-beta.3",
24
+ "@shopgate/pwa-ui-shared": "7.22.0-beta.3",
25
25
  "@stripe/react-stripe-js": "^1.1.2",
26
26
  "@stripe/stripe-js": "^1.3.1",
27
27
  "@virtuous/conductor": "~2.5.0",