@shopgate/engage 6.22.0-beta.8 → 6.22.0-beta.9
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/back-in-stock/components/Subscriptions/components/Subscription/index.js +3 -3
- package/back-in-stock/selectors/index.js +7 -8
- package/core/constants/appFeatures.js +1 -0
- package/core/constants/index.js +1 -1
- package/core/helpers/appFeatures.js +7 -0
- package/core/helpers/index.js +1 -0
- package/package.json +7 -7
- package/push-opt-in/subscriptions/optInTrigger.js +3 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import React from'react';import{css}from'glamor';import{Link,Ripple,PriceInfo,CrossIcon,PriceStriked,Price,Availability}from'@shopgate/engage/components';import{getProductRoute,ProductImage}from'@shopgate/engage/product';import PropTypes from'prop-types';import classNames from'classnames';import{themeConfig}from'@shopgate/engage';import{BackInStockButton}from'@shopgate/engage/back-in-stock/components';import{getThemeSettings,i18n}from'@shopgate/engage/core';import{useBackInStockSubscriptions}from'@shopgate/engage/back-in-stock/hooks';var variables=themeConfig.variables;var styles={root:css({display:'flex',position:'relative',marginBottom:16}).toString(),imageContainer:css({flex:0.4,maxWidth:170,minWidth:70,paddingRight:'8px'}).toString(),infoContainer:css({flex:1}).toString(),infoContainerRow:css({display:'flex',justifyContent:'space-between'}).toString(),baseContainerRow:css({flexDirection:'column',display:'flex',marginTop:'8px'}).toString(),priceContainerRow:css({flexDirection:'column',display:'flex',alignItems:'end',marginTop:'8px'}).toString(),priceContainer:css({minWidth:100}).toString(),priceInfo:css({wordBreak:'break-word',fontSize:'0.875rem',lineHeight:'0.875rem',color:'var(--color-text-low-emphasis)',padding:"".concat(variables.gap.xsmall,"px 0"),textAlign:'right'}).toString(),titleContainer:css({}).toString(),title:css({fontSize:17,fontWeight:600,flexWrap:'wrap',overflowWrap:'anywhere'}).toString(),removeContainer:css({minWidth:'30px'}).toString(),availabilityText:css({fontSize:'0.875rem',marginBottom:'4px'}).toString(),ripple:css({minWidth:'17px'}).toString()};/**
|
|
1
|
+
import React from'react';import{css}from'glamor';import{Link,Ripple,PriceInfo,CrossIcon,PriceStriked,Price,Availability}from'@shopgate/engage/components';import{getProductRoute,ProductImage}from'@shopgate/engage/product';import PropTypes from'prop-types';import classNames from'classnames';import{themeConfig}from'@shopgate/engage';import{BackInStockButton}from'@shopgate/engage/back-in-stock/components';import{getThemeSettings,i18n}from'@shopgate/engage/core';import{useBackInStockSubscriptions}from'@shopgate/engage/back-in-stock/hooks';var variables=themeConfig.variables;var styles={root:css({display:'flex',position:'relative',marginBottom:16}).toString(),imageContainer:css({flex:0.4,maxWidth:170,minWidth:70,paddingRight:'8px'}).toString(),infoContainer:css({flex:1}).toString(),infoContainerRow:css({display:'flex',justifyContent:'space-between'}).toString(),baseContainerRow:css({flexDirection:'column',display:'flex',marginTop:'8px'}).toString(),priceContainerRow:css({flexDirection:'column',display:'flex',alignItems:'end',marginTop:'8px'}).toString(),priceContainer:css({minWidth:100}).toString(),priceInfo:css({wordBreak:'break-word',fontSize:'0.875rem',lineHeight:'0.875rem',color:'var(--color-text-low-emphasis)',padding:"".concat(variables.gap.xsmall,"px 0"),textAlign:'right'}).toString(),titleContainer:css({}).toString(),title:css({fontSize:17,fontWeight:600,flexWrap:'wrap',overflowWrap:'anywhere'}).toString(),removeContainer:css({minWidth:'30px'}).toString(),availabilityText:css({fontSize:'0.875rem',marginBottom:'4px'}).toString(),characteristicText:css({fontSize:'0.875rem'}).toString(),ripple:css({minWidth:'17px'}).toString()};/**
|
|
2
2
|
* Renders on single Back in Stock subscription
|
|
3
3
|
* @param {Object} props Props.
|
|
4
4
|
* @param {string} props.subscription The subscription which should be rendered
|
|
5
5
|
* @returns {JSX}
|
|
6
|
-
*/var Subscription=function Subscription(_ref){var _product$price,_product$price2,_product$price3,_product$price4,_product$availability,_product$availability2;var subscription=_ref.subscription;var subscriptionCode=subscription.subscriptionCode,product=subscription.product;var _useBackInStockSubscr=useBackInStockSubscriptions(),removeBackInStockSubscription=_useBackInStockSubscr.removeBackInStockSubscription;var _ref2=getThemeSettings('AppImages')||{},gridResolutions=_ref2.ListImage;var currency=((_product$price=product.price)===null||_product$price===void 0?void 0:_product$price.currency)||'EUR';var defaultPrice=((_product$price2=product.price)===null||_product$price2===void 0?void 0:_product$price2.unitPrice)||0;var specialPrice=(_product$price3=product.price)===null||_product$price3===void 0?void 0:_product$price3.unitPriceStriked;var hasStrikePrice=((_product$price4=product.price)===null||_product$price4===void 0?void 0:_product$price4.discount)>0;var productLink=getProductRoute(product.id);return/*#__PURE__*/React.createElement("div",{className:styles.root},/*#__PURE__*/React.createElement(Link,{className:styles.imageContainer,component:"div",href:productLink,"aria-hidden":true},/*#__PURE__*/React.createElement(ProductImage,{src:product.featuredImageBaseUrl,resolutions:gridResolutions})),/*#__PURE__*/React.createElement("div",{className:styles.infoContainer},/*#__PURE__*/React.createElement("div",{className:styles.infoContainerRow},/*#__PURE__*/React.createElement(Link,{href:productLink,tag:"span",className:styles.titleContainer},/*#__PURE__*/React.createElement("span",{className:styles.title// eslint-disable-next-line react/no-danger
|
|
7
|
-
,dangerouslySetInnerHTML:{__html:"".concat(product.name)}})),/*#__PURE__*/React.createElement("div",{className:styles.removeContainer},/*#__PURE__*/React.createElement("button",{onClick:function onClick(){return removeBackInStockSubscription({subscriptionCode:subscriptionCode});},type:"button","aria-label":i18n.text('favorites.remove')},/*#__PURE__*/React.createElement(Ripple,{className:styles.ripple},/*#__PURE__*/React.createElement(CrossIcon,null))))),/*#__PURE__*/React.createElement("div",{className:classNames(styles.baseContainerRow)},/*#__PURE__*/React.createElement(Availability,{text:product===null||product===void 0?void 0:(_product$availability=product.availability)===null||_product$availability===void 0?void 0:_product$availability.text,state:product===null||product===void 0?void 0:(_product$availability2=product.availability)===null||_product$availability2===void 0?void 0:_product$availability2.state,showWhenAvailable:false,className:styles.availabilityText}),/*#__PURE__*/React.createElement(BackInStockButton,{subscription:subscription,onClick:function onClick(){}})),/*#__PURE__*/React.createElement("div",{className:styles.priceContainerRow},hasStrikePrice?/*#__PURE__*/React.createElement(PriceStriked,{value:specialPrice,currency:currency}):null,/*#__PURE__*/React.createElement(Price,{currency:currency,discounted:hasStrikePrice,unitPrice:defaultPrice}),!!product.price.info&&/*#__PURE__*/React.createElement(PriceInfo,{text:product.price.info,className:styles.priceInfo}))));};export default Subscription;
|
|
6
|
+
*/var Subscription=function Subscription(_ref){var _product$price,_product$price2,_product$price3,_product$price4,_product$characterist,_product$availability,_product$availability2;var subscription=_ref.subscription;var subscriptionCode=subscription.subscriptionCode,product=subscription.product;var _useBackInStockSubscr=useBackInStockSubscriptions(),removeBackInStockSubscription=_useBackInStockSubscr.removeBackInStockSubscription;var _ref2=getThemeSettings('AppImages')||{},gridResolutions=_ref2.ListImage;var currency=((_product$price=product.price)===null||_product$price===void 0?void 0:_product$price.currency)||'EUR';var defaultPrice=((_product$price2=product.price)===null||_product$price2===void 0?void 0:_product$price2.unitPrice)||0;var specialPrice=(_product$price3=product.price)===null||_product$price3===void 0?void 0:_product$price3.unitPriceStriked;var hasStrikePrice=((_product$price4=product.price)===null||_product$price4===void 0?void 0:_product$price4.discount)>0;var productLink=getProductRoute(product.id);return/*#__PURE__*/React.createElement("div",{className:styles.root},/*#__PURE__*/React.createElement(Link,{className:styles.imageContainer,component:"div",href:productLink,"aria-hidden":true},/*#__PURE__*/React.createElement(ProductImage,{src:product.featuredImageBaseUrl,resolutions:gridResolutions})),/*#__PURE__*/React.createElement("div",{className:styles.infoContainer},/*#__PURE__*/React.createElement("div",{className:styles.infoContainerRow},/*#__PURE__*/React.createElement(Link,{href:productLink,tag:"span",className:styles.titleContainer},/*#__PURE__*/React.createElement("span",{className:styles.title// eslint-disable-next-line react/no-danger
|
|
7
|
+
,dangerouslySetInnerHTML:{__html:"".concat(product.name)}})),/*#__PURE__*/React.createElement("div",{className:styles.removeContainer},/*#__PURE__*/React.createElement("button",{onClick:function onClick(){return removeBackInStockSubscription({subscriptionCode:subscriptionCode});},type:"button","aria-label":i18n.text('favorites.remove')},/*#__PURE__*/React.createElement(Ripple,{className:styles.ripple},/*#__PURE__*/React.createElement(CrossIcon,null))))),/*#__PURE__*/React.createElement("div",{className:classNames(styles.baseContainerRow)},product===null||product===void 0?void 0:(_product$characterist=product.characteristics)===null||_product$characterist===void 0?void 0:_product$characterist.map(function(_ref3){var label=_ref3.label,value=_ref3.value;return/*#__PURE__*/React.createElement("div",{key:label+value,className:styles.characteristicText},label,': ',value);}),/*#__PURE__*/React.createElement(Availability,{text:product===null||product===void 0?void 0:(_product$availability=product.availability)===null||_product$availability===void 0?void 0:_product$availability.text,state:product===null||product===void 0?void 0:(_product$availability2=product.availability)===null||_product$availability2===void 0?void 0:_product$availability2.state,showWhenAvailable:false,className:styles.availabilityText}),/*#__PURE__*/React.createElement(BackInStockButton,{subscription:subscription,onClick:function onClick(){}})),/*#__PURE__*/React.createElement("div",{className:styles.priceContainerRow},hasStrikePrice?/*#__PURE__*/React.createElement(PriceStriked,{value:specialPrice,currency:currency}):null,/*#__PURE__*/React.createElement(Price,{currency:currency,discounted:hasStrikePrice,unitPrice:defaultPrice}),!!product.price.info&&/*#__PURE__*/React.createElement(PriceInfo,{text:product.price.info,className:styles.priceInfo}))));};export default Subscription;
|
|
@@ -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{createSelector}from'reselect';import{makeGetProductByCharacteristics}from'@shopgate/engage/product';import{appConfig}from'@shopgate/engage';import{getClientInformation
|
|
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{createSelector}from'reselect';import{makeGetProductByCharacteristics}from'@shopgate/engage/product';import{appSupportsPushOptIn}from'@shopgate/engage/core/helpers';import{hasSGJavaScriptBridge}from'@shopgate/pwa-core/helpers';import{appConfig}from'@shopgate/engage';import{getClientInformation}from'@shopgate/engage/core';import{PERMISSION_STATUS_GRANTED,PERMISSION_STATUS_NOT_SUPPORTED}from'@shopgate/engage/core/constants';/**
|
|
2
2
|
* @param {Object} state The application state.
|
|
3
3
|
* @returns {Object}
|
|
4
4
|
*/export var getBackInStockState=function getBackInStockState(state){return state.backInStock;};/**
|
|
@@ -28,13 +28,12 @@ match=subscriptionStatus===status;}return match;})||null;});};/**
|
|
|
28
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
29
|
* Selector to determine if the back-in-stock feature is enabled
|
|
30
30
|
* @returns {boolean}
|
|
31
|
-
*/export var getIsBackInStockEnabled=createSelector(getClientInformation,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
*/if(parseInt(major,10)<11||pushPermissionStatus===PERMISSION_STATUS_NOT_SUPPORTED){return false;}return(appConfig===null||appConfig===void 0?void 0:appConfig.showBackInStock)||false;});/**
|
|
31
|
+
*/export var getIsBackInStockEnabled=createSelector(getClientInformation,getBackInStockPushPermissionStatus,function(clientInformation,pushPermissionStatus){if(!appSupportsPushOptIn()){// Disabled when the app doesn't support the required features
|
|
32
|
+
return false;}// Perform app version checks when PWA runs outside the browser
|
|
33
|
+
if(hasSGJavaScriptBridge()){var _clientInformation$co=clientInformation.codebaseVersion,codebaseVersion=_clientInformation$co===void 0?'0.0.0':_clientInformation$co;var _codebaseVersion$spli=codebaseVersion.split('.'),_codebaseVersion$spli2=_slicedToArray(_codebaseVersion$spli,1),major=_codebaseVersion$spli2[0];/**
|
|
34
|
+
* The feature can be enabled on react-native-engage based apps (>= 11.0.0) with proper
|
|
35
|
+
* support for push permissions checks
|
|
36
|
+
*/if(parseInt(major,10)<11||pushPermissionStatus===PERMISSION_STATUS_NOT_SUPPORTED){return false;}}return(appConfig===null||appConfig===void 0?void 0:appConfig.showBackInStock)||false;});/**
|
|
38
37
|
* Selector to determine if back-in-stock related requests are currently possible.
|
|
39
38
|
* @returns {boolean}
|
|
40
39
|
*/export var getAreBackInStockRequestsPossible=createSelector(getIsBackInStockEnabled,getBackInStockPushPermissionStatus,function(featureEnabled,pushPermissionStatus){return featureEnabled&&pushPermissionStatus===PERMISSION_STATUS_GRANTED;});/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export var APP_FEATURE_PUSH_OPT_IN='optIn';
|
package/core/constants/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{INDEX_PATH,INDEX_PATH_DEEPLINK}from'@shopgate/pwa-common/constants/RoutePaths';export*from"./actionTypes";export*from"./geolocationRequest";// Core Constants
|
|
1
|
+
import{INDEX_PATH,INDEX_PATH_DEEPLINK}from'@shopgate/pwa-common/constants/RoutePaths';export*from"./actionTypes";export*from"./appFeatures";export*from"./geolocationRequest";// Core Constants
|
|
2
2
|
export*from'@shopgate/pwa-core/constants/AppEvents';export*from'@shopgate/pwa-core/constants/AppPermissions';export*from'@shopgate/pwa-core/constants/ErrorHandleTypes';export*from'@shopgate/pwa-core/constants/Pipeline';export*from'@shopgate/pwa-core/constants/ProcessTypes';export*from'@shopgate/pwa-core/constants/Scanner';export*from'@shopgate/pwa-core/constants/Trilean';// Common Constants
|
|
3
3
|
export*from'@shopgate/pwa-common/constants/ActionTypes';export*from'@shopgate/pwa-common/constants/Configuration';export*from'@shopgate/pwa-common/constants/Device';export*from'@shopgate/pwa-common/constants/DisplayOptions';export*from'@shopgate/pwa-common/constants/Pipelines';export*from'@shopgate/pwa-common/constants/Portals';// CLIENT CONSTANTS
|
|
4
4
|
export*from'@shopgate/pwa-common/constants/client';// MENU CONSTANTS
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import{APP_FEATURE_PUSH_OPT_IN}from'@shopgate/engage/core/constants';import{hasSGJavaScriptBridge}from'@shopgate/pwa-core/helpers';/**
|
|
2
|
+
* Determines if the app supports the push opt-in feature
|
|
3
|
+
* @returns {boolean}
|
|
4
|
+
*/export var appSupportsPushOptIn=function appSupportsPushOptIn(){var _window,_window$SGAppInfo,_window$SGAppInfo$fea,_window$SGAppInfo$fea2,_window$SGAppInfo$fea3;if(!hasSGJavaScriptBridge()){// Always supported in development
|
|
5
|
+
return true;}if(!Array.isArray((_window=window)===null||_window===void 0?void 0:(_window$SGAppInfo=_window.SGAppInfo)===null||_window$SGAppInfo===void 0?void 0:(_window$SGAppInfo$fea=_window$SGAppInfo.featureFlags)===null||_window$SGAppInfo$fea===void 0?void 0:(_window$SGAppInfo$fea2=_window$SGAppInfo$fea.Push)===null||_window$SGAppInfo$fea2===void 0?void 0:(_window$SGAppInfo$fea3=_window$SGAppInfo$fea2['1'])===null||_window$SGAppInfo$fea3===void 0?void 0:_window$SGAppInfo$fea3.flags)){// Not supported on app versions that don't provide the featureFlags object
|
|
6
|
+
return false;}// Supported when the feature flags contain the push opt-in flag
|
|
7
|
+
return window.SGAppInfo.featureFlags.Push['1'].flags.includes(APP_FEATURE_PUSH_OPT_IN);};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"./appFeatures";export{getFullImageSource}from"./getFullImageSource";export{getImageFormat}from"./getImageFormat";export{i18n}from"./i18n";export{updateLegacyNavigationBar}from"./updateLegacyNavigationBar";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopgate/engage",
|
|
3
|
-
"version": "6.22.0-beta.
|
|
3
|
+
"version": "6.22.0-beta.9",
|
|
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.
|
|
19
|
-
"@shopgate/pwa-common-commerce": "6.22.0-beta.
|
|
20
|
-
"@shopgate/pwa-core": "6.22.0-beta.
|
|
21
|
-
"@shopgate/pwa-ui-ios": "6.22.0-beta.
|
|
22
|
-
"@shopgate/pwa-ui-material": "6.22.0-beta.
|
|
23
|
-
"@shopgate/pwa-ui-shared": "6.22.0-beta.
|
|
18
|
+
"@shopgate/pwa-common": "6.22.0-beta.9",
|
|
19
|
+
"@shopgate/pwa-common-commerce": "6.22.0-beta.9",
|
|
20
|
+
"@shopgate/pwa-core": "6.22.0-beta.9",
|
|
21
|
+
"@shopgate/pwa-ui-ios": "6.22.0-beta.9",
|
|
22
|
+
"@shopgate/pwa-ui-material": "6.22.0-beta.9",
|
|
23
|
+
"@shopgate/pwa-ui-shared": "6.22.0-beta.9",
|
|
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",
|
|
@@ -1,4 +1,4 @@
|
|
|
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;});/**
|
|
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{appSupportsPushOptIn}from'@shopgate/engage/core/helpers';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 _typeof(obj
|
|
|
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;_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=
|
|
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;if(appSupportsPushOptIn()){_context.next=3;break;}return _context.abrupt("return");case 3:_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=9;break;}logger.error('PushOptInTrigger - Config invalid',appConfig===null||appConfig===void 0?void 0:appConfig.pushOptIn);return _context.abrupt("return");case 9:_context.next=11;return dispatch(requestAppPermissionStatus({permissionId:PERMISSION_ID_PUSH}));case 11:pushStatus=_context.sent;if(!(pushStatus!==PERMISSION_STATUS_NOT_DETERMINED)){_context.next=14;break;}return _context.abrupt("return");case 14: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=23;break;}return _context.abrupt("return");case 23: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 27: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());});}
|