@shopgate/engage 6.22.0-beta.6 → 6.22.0-beta.8

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,3 +1,3 @@
1
1
  import{connect}from'react-redux';import{getIsBackInStockEnabled,makeGetSubscriptionByProduct}from'@shopgate/engage/back-in-stock/selectors';import{getProduct}from'@shopgate/engage/product';/**
2
2
  * @return {Object} The extended component props.
3
- */var makeMapStateToProps=function makeMapStateToProps(){var getSubscriptionByProduct=makeGetSubscriptionByProduct();return function(state,props){return{subscription:getSubscriptionByProduct(state,props),isBackInStockEnabled:getIsBackInStockEnabled(state,props),product:getProduct(state,props)};};};export default connect(makeMapStateToProps);
3
+ */var makeMapStateToProps=function makeMapStateToProps(){var getSubscriptionByProduct=makeGetSubscriptionByProduct({status:'active'});return function(state,props){return{subscription:getSubscriptionByProduct(state,props),isBackInStockEnabled:getIsBackInStockEnabled(state,props),product:getProduct(state,props)};};};export default connect(makeMapStateToProps);
@@ -1,4 +1,4 @@
1
- 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 React,{useCallback}from'react';import{css}from'glamor';import{LoadingIndicator,Accordion,Card}from'@shopgate/engage/components';import{i18n}from'@shopgate/engage/core';import{useBackInStockSubscriptions}from'@shopgate/engage/back-in-stock/hooks';import Subscription from"../Subscription";var styles={divider:css({height:1,width:'calc(100% + 32px)',backgroundColor:'rgb(234, 234, 234)',marginLeft:-16,marginRight:-16,marginBottom:16}).toString(),emptyText:css({marginBottom:16,textAlign:'center'}).toString(),listTitle:css({fontWeight:'700'}).toString()};/**
1
+ 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 React,{useCallback}from'react';import{css}from'glamor';import{LoadingIndicator,Accordion,Card}from'@shopgate/engage/components';import{i18n}from'@shopgate/engage/core';import{useBackInStockSubscriptions}from'@shopgate/engage/back-in-stock/hooks';import Subscription from"../Subscription";var styles={root:css({margin:'8px 8px 10px'}).toString(),divider:css({height:1,width:'calc(100% + 32px)',backgroundColor:'rgb(234, 234, 234)',marginLeft:-16,marginRight:-16,marginBottom:16}).toString(),emptyText:css({marginBottom:16,textAlign:'center'}).toString(),listTitle:css({fontWeight:'700'}).toString()};/**
2
2
  * The Back In Stock Subscriptions List.
3
3
  * @returns {JSX}
4
4
  */var List=function List(){var _useBackInStockSubscr=useBackInStockSubscriptions(),isInitial=_useBackInStockSubscr.isInitial,groupedSubscriptions=_useBackInStockSubscr.groupedSubscriptions;var _renderLabel=useCallback(function(groupKey){return/*#__PURE__*/React.createElement("div",{className:styles.listTitle},i18n.text("back_in_stock.list_states.".concat(groupKey)));},[]);return/*#__PURE__*/React.createElement("div",null,Object.entries(groupedSubscriptions).map(function(_ref){var _ref2=_slicedToArray(_ref,2),groupKey=_ref2[0],filteredSubscriptions=_ref2[1];return/*#__PURE__*/React.createElement(Card,{className:styles.root,key:groupKey},/*#__PURE__*/React.createElement(Accordion,{className:"",openWithChevron:true,renderLabel:function renderLabel(){return _renderLabel(groupKey);},chevronPosition:"left",startOpened:true},/*#__PURE__*/React.createElement("div",{className:styles.divider}),isInitial?/*#__PURE__*/React.createElement(LoadingIndicator,null):null,!isInitial&&filteredSubscriptions.length===0?/*#__PURE__*/React.createElement("div",{className:styles.emptyText},i18n.text('back_in_stock.empty_list_reminder')):null,!isInitial&&filteredSubscriptions.map(function(subscription,index){return/*#__PURE__*/React.createElement("div",{key:subscription.subscriptionCode},/*#__PURE__*/React.createElement(Subscription,{subscription:subscription,productId:subscription.productCode,key:subscription.subscriptionCode,group:groupKey}),index===filteredSubscriptions.length-1?null:/*#__PURE__*/React.createElement("div",{className:styles.divider}));})));}));};export default List;
@@ -2,29 +2,32 @@ function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimi
2
2
  * @param {Object} state The application state.
3
3
  * @returns {Object}
4
4
  */export var getBackInStockState=function getBackInStockState(state){return state.backInStock;};/**
5
- * @param {Object} state The application state.
6
- * @returns {Object}
5
+ * Selector to retrieve the back-in-stock subscriptions list
6
+ * @returns {Array}
7
7
  */export var getBackInStockSubscriptions=createSelector(getBackInStockState,function(state){return state.subscriptions;});/**
8
- * @param {Object} state The application state.
9
- * @returns {Object}
8
+ * Selector to retrieve the current fetching state of back-in-stock subscriptions
9
+ * @returns {boolean}
10
10
  */export var getBackInStockSubscriptionsFetching=createSelector(getBackInStockState,function(state){return state.isFetching;});/**
11
- * @param {Object} state The application state.
12
- * @returns {Object}
11
+ * Selector to determine if back-in-stock subscriptions have been fetched before
12
+ * @returns {boolean}
13
13
  */export var getBackInStockSubscriptionsInitial=createSelector(getBackInStockState,function(state){return state.isInitial;});/**
14
- * Creates a selector to retrieve the current status of the push app permission
15
- * @param {Object} state The application state.
16
- * @returns {Object}
14
+ * Selector to retrieve the current status of the push app permission
15
+ * @returns {string}
17
16
  */export var getBackInStockPushPermissionStatus=createSelector(getBackInStockState,function(state){return state.pushPermissionStatus;});/**
18
17
  * Creates a selector that retrieves the subscription of
19
18
  * a product / variant or null by its variantId / productId
19
+ * @param {Object} params Params
20
+ * @param {string} params.status Get subscription for a specific status
20
21
  * @returns {Function}
21
- */export var makeGetSubscriptionByProduct=function makeGetSubscriptionByProduct(){return createSelector(function(state){var props=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};return props.variantId?props.variantId:props.productId;},getBackInStockSubscriptions,function(requestedProductCode,subscriptions){if(!requestedProductCode){return false;}return subscriptions.find(function(_ref){var productCode=_ref.productCode;return productCode===requestedProductCode;})||null;});};/**
22
+ */export var makeGetSubscriptionByProduct=function makeGetSubscriptionByProduct(){var _ref=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{},status=_ref.status;return createSelector(function(state){var props=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};return props.variantId?props.variantId:props.productId;},getBackInStockSubscriptions,function(requestedProductCode,subscriptions){if(!requestedProductCode){return false;}return subscriptions.find(function(_ref2){var productCode=_ref2.productCode,subscriptionStatus=_ref2.status;var match=productCode===requestedProductCode;if(match&&status){// When the selector factory is created for a specific status, the subscription also
23
+ // needs to fulfill this condition
24
+ match=subscriptionStatus===status;}return match;})||null;});};/**
22
25
  * Creates a selector that retrieves the subscription of
23
26
  * a product / variant by its characteristics
24
27
  * @returns {Function}
25
- */export var makeGetSubscriptionByCharacteristics=function makeGetSubscriptionByCharacteristics(){var getProductByCharacteristics=makeGetProductByCharacteristics();return createSelector(getProductByCharacteristics,getBackInStockSubscriptions,function(product,subscriptions){if(!product){return null;}return subscriptions.find(function(_ref2){var productCode=_ref2.productCode;return productCode===product.id;})||null;});};/**
26
- * Creates a selector to determine if the back-in-stock feature is enabled
27
- * @returns {Function}
28
+ */export var makeGetSubscriptionByCharacteristics=function makeGetSubscriptionByCharacteristics(){var getProductByCharacteristics=makeGetProductByCharacteristics();return createSelector(getProductByCharacteristics,getBackInStockSubscriptions,function(product,subscriptions){if(!product){return null;}return subscriptions.find(function(_ref3){var productCode=_ref3.productCode;return productCode===product.id;})||null;});};/**
29
+ * Selector to determine if the back-in-stock feature is enabled
30
+ * @returns {boolean}
28
31
  */export var getIsBackInStockEnabled=createSelector(getClientInformation,getIsIos,getBackInStockPushPermissionStatus,function(clientInformation,isIos,pushPermissionStatus){var isRNEngage=navigator.userAgent.includes('RN Engage');/**
29
32
  * No support for the react-native-engage dev app on iOS since push token handling will not
30
33
  * work as expected, and back-in-stock related requests will fail.
@@ -32,9 +35,9 @@ function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimi
32
35
  * The feature can be enabled on react-native-engage based apps (>= 11.0.0) with proper
33
36
  * support for push permissions checks
34
37
  */if(parseInt(major,10)<11||pushPermissionStatus===PERMISSION_STATUS_NOT_SUPPORTED){return false;}return(appConfig===null||appConfig===void 0?void 0:appConfig.showBackInStock)||false;});/**
35
- * Creates a selector to determine if back-in-stock related requests are currently possible.
36
- * @returns {Function}
38
+ * Selector to determine if back-in-stock related requests are currently possible.
39
+ * @returns {boolean}
37
40
  */export var getAreBackInStockRequestsPossible=createSelector(getIsBackInStockEnabled,getBackInStockPushPermissionStatus,function(featureEnabled,pushPermissionStatus){return featureEnabled&&pushPermissionStatus===PERMISSION_STATUS_GRANTED;});/**
38
41
  * Returns if subscription list is in use
39
- * @returns {Function}
42
+ * @returns {boolean}
40
43
  */export var getHasBackInStockSubscriptions=createSelector(getBackInStockSubscriptions,function(subscriptions){return!!subscriptions.length;});
@@ -1,6 +1,6 @@
1
1
  import _regeneratorRuntime from"@babel/runtime/regenerator";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;}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{requestAppPermissions}from'@shopgate/pwa-core/commands/appPermissions';import{PERMISSION_STATUS_NOT_SUPPORTED}from'@shopgate/engage/core/constants';import{appPermissionStatusReceived}from"../action-creators";/**
2
2
  * Requests an additional app permission from the operating system.
3
- * Additionally it propagates * the received status via the APP_PERMISSION_STATUS_RECEIVED action.
3
+ * Additionally it propagates the received status via the APP_PERMISSION_STATUS_RECEIVED action.
4
4
  * @param {Object} params The action params
5
5
  * @param {string} params.permissionId The desired app permission id
6
6
  * @returns {Function} A Redux thunk
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopgate/engage",
3
- "version": "6.22.0-beta.6",
3
+ "version": "6.22.0-beta.8",
4
4
  "description": "Shopgate's ENGAGE library.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Shopgate <support@shopgate.com>",
@@ -15,12 +15,12 @@
15
15
  "connect"
16
16
  ],
17
17
  "dependencies": {
18
- "@shopgate/pwa-common": "6.22.0-beta.6",
19
- "@shopgate/pwa-common-commerce": "6.22.0-beta.6",
20
- "@shopgate/pwa-core": "6.22.0-beta.6",
21
- "@shopgate/pwa-ui-ios": "6.22.0-beta.6",
22
- "@shopgate/pwa-ui-material": "6.22.0-beta.6",
23
- "@shopgate/pwa-ui-shared": "6.22.0-beta.6",
18
+ "@shopgate/pwa-common": "6.22.0-beta.8",
19
+ "@shopgate/pwa-common-commerce": "6.22.0-beta.8",
20
+ "@shopgate/pwa-core": "6.22.0-beta.8",
21
+ "@shopgate/pwa-ui-ios": "6.22.0-beta.8",
22
+ "@shopgate/pwa-ui-material": "6.22.0-beta.8",
23
+ "@shopgate/pwa-ui-shared": "6.22.0-beta.8",
24
24
  "@virtuous/conductor": "~2.4.0",
25
25
  "babel-plugin-transform-es3-member-expression-literals": "^6.8.0",
26
26
  "babel-plugin-transform-es3-property-literals": "^6.8.0",
@@ -2,7 +2,7 @@ import React,{useMemo}from'react';import PropTypes from'prop-types';import class
2
2
  * The Push opt-in modal component.
3
3
  * @param {Object} props The component props.
4
4
  * @returns {JSX.Element}
5
- */var PushOptInModal=function PushOptInModal(_ref){var isPushOptInModalVisible=_ref.isPushOptInModalVisible,allowPushOptIn=_ref.allowPushOptIn,denyPushOptIn=_ref.denyPushOptIn;var _appConfig$pushOptIn=appConfig.pushOptIn,modalMessage=_appConfig$pushOptIn.modalMessage,modalTitle=_appConfig$pushOptIn.modalTitle,modalButtonDeny=_appConfig$pushOptIn.modalButtonDeny,modalButtonAllow=_appConfig$pushOptIn.modalButtonAllow,modalImageURL=_appConfig$pushOptIn.modalImageURL,modalImageSVG=_appConfig$pushOptIn.modalImageSVG;var imageSRC=useMemo(function(){// No overwrite configured -> use default image
5
+ */var PushOptInModal=function PushOptInModal(_ref){var isPushOptInModalVisible=_ref.isPushOptInModalVisible,allowPushOptIn=_ref.allowPushOptIn,denyPushOptIn=_ref.denyPushOptIn;var _appConfig$pushOptIn=appConfig.pushOptIn;_appConfig$pushOptIn=_appConfig$pushOptIn===void 0?{}:_appConfig$pushOptIn;var modalMessage=_appConfig$pushOptIn.modalMessage,modalTitle=_appConfig$pushOptIn.modalTitle,modalButtonDeny=_appConfig$pushOptIn.modalButtonDeny,modalButtonAllow=_appConfig$pushOptIn.modalButtonAllow,modalImageURL=_appConfig$pushOptIn.modalImageURL,modalImageSVG=_appConfig$pushOptIn.modalImageSVG;var imageSRC=useMemo(function(){// No overwrite configured -> use default image
6
6
  if(!modalImageURL&&!modalImageSVG){return pushImage;}// URL overwrite configured -> use it
7
7
  if(modalImageURL){return modalImageURL;}// SVG overwrite configured -> create data url
8
8
  try{// Remove any characters outside the Latin1 range
@@ -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{appConfig}from'@shopgate/engage';import{main$,event,appDidStart$}from'@shopgate/engage/core';import{PERMISSION_ID_PUSH,PERMISSION_STATUS_NOT_DETERMINED}from'@shopgate/engage/core/constants';import{requestAppPermissionStatus}from'@shopgate/engage/core/actions';import{increaseAppStartCount,resetAppStartCount,increaseOrdersPlacedCount,resetOrdersPlacedCount,setLastPopupTimestamp,increaseRejectionCount,showPushOptInModal}from"../action-creators";import{PUSH_OPT_IN_OPT_IN_POSTPONED}from"../constants";import{getPushOptInTriggerState}from"../selectors";var DAY_IN_MS=1000*60*60*24;var increaseRejectionCount$=main$.filter(function(_ref){var action=_ref.action;return action.type===PUSH_OPT_IN_OPT_IN_POSTPONED;});/**
1
+ import _regeneratorRuntime from"@babel/runtime/regenerator";function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj;}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;},_typeof(obj);}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{appConfig}from'@shopgate/engage';import{main$,event,appDidStart$,logger}from'@shopgate/engage/core';import{PERMISSION_ID_PUSH,PERMISSION_STATUS_NOT_DETERMINED}from'@shopgate/engage/core/constants';import{requestAppPermissionStatus}from'@shopgate/engage/core/actions';import{increaseAppStartCount,resetAppStartCount,increaseOrdersPlacedCount,resetOrdersPlacedCount,setLastPopupTimestamp,increaseRejectionCount,showPushOptInModal}from"../action-creators";import{PUSH_OPT_IN_OPT_IN_POSTPONED}from"../constants";import{getPushOptInTriggerState}from"../selectors";var DAY_IN_MS=1000*60*60*24;var increaseRejectionCount$=main$.filter(function(_ref){var action=_ref.action;return action.type===PUSH_OPT_IN_OPT_IN_POSTPONED;});/**
2
2
  * Push opt in subscriptions
3
3
  * @param {Function} subscribe The subscribe function
4
4
  */export default function pushOptIn(subscribe){/**
@@ -6,7 +6,7 @@ import _regeneratorRuntime from"@babel/runtime/regenerator";function asyncGenera
6
6
  * @param {string} configKey The "pushOptIn" key to be used
7
7
  * @param {Function} increaseCountAction Action to increase the count in Redux for the configKey
8
8
  * @returns {void}
9
- */var showOptInAfterChecks=/*#__PURE__*/function(){var _ref3=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref2,configKey,increaseCountAction){var dispatch,getState,_appConfig$pushOptIn,appStarts,ordersPlaced,rejectionMaxCount,minDaysBetweenOptIns,pushStatus,state,configValue,resetAction,resetCountState,configCountState,mustShowModal,hasRepeats,minDaysElapsed;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:dispatch=_ref2.dispatch,getState=_ref2.getState;_appConfig$pushOptIn=appConfig.pushOptIn,appStarts=_appConfig$pushOptIn.appStarts,ordersPlaced=_appConfig$pushOptIn.ordersPlaced,rejectionMaxCount=_appConfig$pushOptIn.rejectionMaxCount,minDaysBetweenOptIns=_appConfig$pushOptIn.minDaysBetweenOptIns;// TODO add check to determine if the app supports push-opt-in (is done in CURB-3915)
10
- _context.next=4;return dispatch(requestAppPermissionStatus({permissionId:PERMISSION_ID_PUSH}));case 4:pushStatus=_context.sent;if(!(pushStatus!==PERMISSION_STATUS_NOT_DETERMINED)){_context.next=7;break;}return _context.abrupt("return");case 7:dispatch(increaseCountAction());state=getPushOptInTriggerState(getState());configValue=appStarts;resetAction=resetAppStartCount;resetCountState=state.appStartResetCount;configCountState=state.appStartCount;if(configKey==='ordersPlaced'){configValue=ordersPlaced;resetAction=resetOrdersPlacedCount;resetCountState=state.ordersPlacedResetCount;configCountState=state.ordersPlacedCount;}if(!(state.rejectionCount>=rejectionMaxCount)){_context.next=16;break;}return _context.abrupt("return");case 16:mustShowModal=Number(configValue.value)>0&&configCountState>=configValue.value;hasRepeats=configValue.repeats===null||resetCountState<=configValue.repeats;minDaysElapsed=Date.now()-state.lastPopupAt>=minDaysBetweenOptIns*DAY_IN_MS;if(mustShowModal&&hasRepeats&&minDaysElapsed){dispatch(setLastPopupTimestamp());dispatch(resetAction());dispatch(showPushOptInModal());}case 20:case"end":return _context.stop();}}},_callee);}));return function showOptInAfterChecks(_x,_x2,_x3){return _ref3.apply(this,arguments);};}();// event subscriber to handle app start based push opt in
9
+ */var showOptInAfterChecks=/*#__PURE__*/function(){var _ref3=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref2,configKey,increaseCountAction){var dispatch,getState,_appConfig$pushOptIn,appStarts,ordersPlaced,rejectionMaxCount,minDaysBetweenOptIns,pushStatus,state,configValue,resetAction,resetCountState,configCountState,mustShowModal,hasRepeats,minDaysElapsed;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:dispatch=_ref2.dispatch,getState=_ref2.getState;_appConfig$pushOptIn=appConfig.pushOptIn;_appConfig$pushOptIn=_appConfig$pushOptIn===void 0?{}:_appConfig$pushOptIn;appStarts=_appConfig$pushOptIn.appStarts,ordersPlaced=_appConfig$pushOptIn.ordersPlaced,rejectionMaxCount=_appConfig$pushOptIn.rejectionMaxCount,minDaysBetweenOptIns=_appConfig$pushOptIn.minDaysBetweenOptIns;// Deactivate feature when config is invalid
10
+ if(!(typeof minDaysBetweenOptIns!=='number'||typeof rejectionMaxCount!=='number'||_typeof(ordersPlaced)!=='object'||_typeof(appStarts)!=='object')){_context.next=7;break;}logger.error('PushOptInTrigger - Config invalid',appConfig===null||appConfig===void 0?void 0:appConfig.pushOptIn);return _context.abrupt("return");case 7:_context.next=9;return dispatch(requestAppPermissionStatus({permissionId:PERMISSION_ID_PUSH}));case 9:pushStatus=_context.sent;if(!(pushStatus!==PERMISSION_STATUS_NOT_DETERMINED)){_context.next=12;break;}return _context.abrupt("return");case 12:dispatch(increaseCountAction());state=getPushOptInTriggerState(getState());configValue=appStarts;resetAction=resetAppStartCount;resetCountState=state.appStartResetCount;configCountState=state.appStartCount;if(configKey==='ordersPlaced'){configValue=ordersPlaced;resetAction=resetOrdersPlacedCount;resetCountState=state.ordersPlacedResetCount;configCountState=state.ordersPlacedCount;}if(!(state.rejectionCount>=rejectionMaxCount)){_context.next=21;break;}return _context.abrupt("return");case 21:mustShowModal=Number(configValue.value)>0&&configCountState>=configValue.value;hasRepeats=configValue.repeats===null||resetCountState<=configValue.repeats;minDaysElapsed=Date.now()-state.lastPopupAt>=minDaysBetweenOptIns*DAY_IN_MS;if(mustShowModal&&hasRepeats&&minDaysElapsed){dispatch(setLastPopupTimestamp());dispatch(resetAction());dispatch(showPushOptInModal());}case 25:case"end":return _context.stop();}}},_callee);}));return function showOptInAfterChecks(_x,_x2,_x3){return _ref3.apply(this,arguments);};}();// event subscriber to handle app start based push opt in
11
11
  subscribe(appDidStart$,/*#__PURE__*/function(){var _ref5=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref4){var dispatch,getState;return _regeneratorRuntime.wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:dispatch=_ref4.dispatch,getState=_ref4.getState;_context2.next=3;return showOptInAfterChecks({dispatch:dispatch,getState:getState},'appStarts',increaseAppStartCount);case 3:case"end":return _context2.stop();}}},_callee2);}));return function(_x4){return _ref5.apply(this,arguments);};}());// event subscriber to handle order based push opt in
12
12
  subscribe(appDidStart$,function(_ref6){var dispatch=_ref6.dispatch,getState=_ref6.getState;event.addCallback('checkoutSuccess',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(){return _regeneratorRuntime.wrap(function _callee3$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:_context3.next=2;return showOptInAfterChecks({dispatch:dispatch,getState:getState},'ordersPlaced',increaseOrdersPlacedCount);case 2:case"end":return _context3.stop();}}},_callee3);})));});subscribe(increaseRejectionCount$,function(_ref8){var dispatch=_ref8.dispatch;dispatch(increaseRejectionCount());});}
@@ -1,3 +0,0 @@
1
- import{connect}from'react-redux';import{addBackInStockSubscription}from'@shopgate/engage/back-in-stock/actions';import{makeGetSubscriptionByProduct}from'@shopgate/engage/back-in-stock/selectors';/**
2
- * @return {Object} The extended component props.
3
- */var makeMapStateToProps=function makeMapStateToProps(){var getSubscriptionByProduct=makeGetSubscriptionByProduct();return function(state,props){return{subscription:getSubscriptionByProduct(state,props)};};};var mapDispatchToProps={addBackInStockSubscription:addBackInStockSubscription};export default connect(makeMapStateToProps,mapDispatchToProps);