@shopgate/engage 6.17.0-rc.2 → 6.17.0-rc.7

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,7 +1,11 @@
1
- import{INCREASE_REJECTION_COUNT,SET_LAST_POPUP_TIMESTAMP}from"../constants";/**
1
+ import{INCREASE_REJECTION_COUNT,SET_ALREADY_RATED,SET_LAST_POPUP_TIMESTAMP}from"../constants";/**
2
2
  * Sets the last popup timestamp
3
3
  * @return {Object} The dispatched action object.
4
4
  */export var setLastPopupTimestamp=function setLastPopupTimestamp(){return{type:SET_LAST_POPUP_TIMESTAMP};};/**
5
5
  * Sets the last popup timestamp
6
6
  * @return {Object} The dispatched action object.
7
- */export var increaseRejectionCount=function increaseRejectionCount(){return{type:INCREASE_REJECTION_COUNT};};
7
+ */export var increaseRejectionCount=function increaseRejectionCount(){return{type:INCREASE_REJECTION_COUNT};};/**
8
+ * Sets the last popup timestamp
9
+ * @param {boolean} to the value to set the rated status
10
+ * @return {Object} The dispatched action object.
11
+ */export var setAlreadyRated=function setAlreadyRated(to){return{type:SET_ALREADY_RATED,to:to};};
@@ -1,11 +1,19 @@
1
- import showModalAction from'@shopgate/pwa-common/actions/modal/showModal';import{getPlatform}from'@shopgate/pwa-common/selectors/client';import{historyPush}from'@shopgate/pwa-common/actions/router';import appConfig from'@shopgate/pwa-common/helpers/config';import{increaseRejectionCount,setLastPopupTimestamp}from"../action-creators/popup";import{generateReviewLink}from"../helpers";import{TIMER_TIMESPAN}from"../constants";import{getAppRatingState}from"../selectors/appRating";var _appConfig$appRating=appConfig.appRating,bId=_appConfig$appRating.bundleId,rejectionLink=_appConfig$appRating.rejectionLink,minTimeBetweenPopups=_appConfig$appRating.minTimeBetweenPopups;/**
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);});};}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);}import showModalAction from'@shopgate/pwa-common/actions/modal/showModal';import{getPlatform}from'@shopgate/pwa-common/selectors/client';import{historyPush}from'@shopgate/pwa-common/actions/router';import appConfig from'@shopgate/pwa-common/helpers/config';import{track}from'@shopgate/pwa-tracking/helpers';import{increaseRejectionCount,setAlreadyRated,setLastPopupTimestamp}from"../action-creators/popup";import{generateReviewLink}from"../helpers";import{TIMER_TIMESPAN}from"../constants";import{getAppRatingState}from"../selectors/appRating";var _appConfig$appRating=appConfig.appRating,bundleId=_appConfig$appRating.bundleId,minDaysBetweenPopups=_appConfig$appRating.minDaysBetweenPopups,askForFeedback=_appConfig$appRating.askForFeedback,feedbackLink=_appConfig$appRating.feedbackLink;/**
2
+ * to handle the modal confirmation
3
+ * @param {string} url the url to redirect to
4
+ * @param {boolean | null} setRated the url to redirect to
5
+ * @return {(function(*, *): void)|*}
6
+ */function redirectTo(url){var setRated=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;return function(dispatch){if(!url){return;}if(setRated){dispatch(setAlreadyRated(setRated));}dispatch(historyPush(_extends({pathname:url},setRated&&{state:{target:'_blank'}})));};}/**
2
7
  * shows the actual modal
3
8
  * @param {Function} resetAction the reset action function
4
9
  * @param {Function} increaseAction the function to increase the appropriate counter
5
10
  * @param {boolean} mustShow if the modal must be shown
6
11
  * @param {boolean} hasRepeats if the counters has repeats
7
12
  * @return {(function(*, *): void)|*}
8
- */export function showModal(resetAction,increaseAction,mustShow,hasRepeats){return function(dispatch,getState){if(!mustShow&&hasRepeats&&increaseAction){dispatch(increaseAction());}if(!(mustShow&&hasRepeats)){return;}var state=getAppRatingState(getState());var isMinTimeBetweenPopupsElapsed=Date.now()-state.lastPopupAt>=minTimeBetweenPopups*TIMER_TIMESPAN;if(!isMinTimeBetweenPopupsElapsed){return;}dispatch(resetAction());dispatch(setLastPopupTimestamp());dispatch(showModalAction({confirm:'appRating.yes',dismiss:'appRating.no',title:'appRating.title',message:'appRating.message'})).then(function(confirmed){// user touched yes and we
13
+ */export function showModal(resetAction,increaseAction,mustShow,hasRepeats){return(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch,getState){var state,platform,reviewLink,appRatingState,isMinDaysBetweenPopupsElapsed,firstModalConfirmed,userGivesFeedback;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:state=getState();platform=getPlatform(state);reviewLink=generateReviewLink(bundleId[platform],platform);// no review link for current platform found -> don't show modal
14
+ if(reviewLink){_context.next=5;break;}return _context.abrupt("return");case 5:if(!mustShow&&hasRepeats&&increaseAction){dispatch(increaseAction());}if(mustShow&&hasRepeats){_context.next=8;break;}return _context.abrupt("return");case 8:appRatingState=getAppRatingState(state);isMinDaysBetweenPopupsElapsed=Date.now()-appRatingState.lastPopupAt>=minDaysBetweenPopups*TIMER_TIMESPAN;if(isMinDaysBetweenPopupsElapsed){_context.next=12;break;}return _context.abrupt("return");case 12:dispatch(resetAction());dispatch(setLastPopupTimestamp());_context.next=16;return dispatch(showModalAction({confirm:'appRating.yes',dismiss:'appRating.no',title:'appRating.title',message:'appRating.message'}));case 16:firstModalConfirmed=_context.sent;track('customEvent',{eventCategory:'appReviewPrompt',eventAction:'decision',eventLabel:firstModalConfirmed?'yes':'no'},state);// user touched yes and we
9
15
  // redirect to store
10
- if(confirmed){var platform=getPlatform(getState());var link=generateReviewLink(bId[platform],platform);if(!link){return;}dispatch(historyPush({pathname:link}));return;}// user doesn't want to rate
11
- dispatch(increaseRejectionCount());if(rejectionLink){dispatch(historyPush({pathname:rejectionLink}));}});};}
16
+ if(!firstModalConfirmed){_context.next=21;break;}dispatch(redirectTo(reviewLink,true));return _context.abrupt("return");case 21:// user doesn't want to rate
17
+ dispatch(increaseRejectionCount());// we approve for rejection
18
+ if(!askForFeedback){_context.next=29;break;}_context.next=25;return dispatch(showModalAction({confirm:'appRating.yes',dismiss:'appRating.no',title:'appRating.title',message:'appRating.rejectionApprovalMessage'}));case 25:userGivesFeedback=_context.sent;track('customEvent',{eventCategory:'appReviewPrompt',eventAction:'decision_feedback',eventLabel:userGivesFeedback?'yes':'no'},state);// user wants to give feedback
19
+ if(userGivesFeedback){dispatch(redirectTo(feedbackLink));}return _context.abrupt("return");case 29:dispatch(redirectTo(feedbackLink));case 30:case"end":return _context.stop();}}},_callee);}));return function(_x,_x2){return _ref.apply(this,arguments);};}());}
@@ -1,2 +1,2 @@
1
- export var INCREASE_APP_START_COUNT='INCREASE_APP_START_COUNT';export var RESET_APP_START_COUNT='RESET_APP_START_COUNT';export var RESET_APP_START_STATE='RESET_APP_START_STATE';export var INCREASE_ORDERS_PLACED_COUNT='INCREASE_ORDERS_PLACED_COUNT';export var RESET_ORDERS_PLACED_COUNT='RESET_ORDERS_PLACED_COUNT';export var RESET_ORDERS_PLACED_STATE='RESET_ORDERS_PLACED_STATE';export var INCREASE_TIMER_REPEATS='INCREASE_TIMER_REPEATS';export var SET_TIMER_START_TIME='SET_TIMER_START_TIME';export var SET_LAST_POPUP_TIMESTAMP='SET_LAST_POPUP_TIMESTAMP';export var INCREASE_REJECTION_COUNT='INCREASE_REJECTION_COUNT';// currently the timespan is set to a hour
2
- export var TIMER_TIMESPAN=1000*60*60;
1
+ export var INCREASE_APP_START_COUNT='INCREASE_APP_START_COUNT';export var RESET_APP_START_COUNT='RESET_APP_START_COUNT';export var RESET_APP_START_STATE='RESET_APP_START_STATE';export var INCREASE_ORDERS_PLACED_COUNT='INCREASE_ORDERS_PLACED_COUNT';export var RESET_ORDERS_PLACED_COUNT='RESET_ORDERS_PLACED_COUNT';export var RESET_ORDERS_PLACED_STATE='RESET_ORDERS_PLACED_STATE';export var INCREASE_TIMER_REPEATS='INCREASE_TIMER_REPEATS';export var SET_TIMER_START_TIME='SET_TIMER_START_TIME';export var SET_LAST_POPUP_TIMESTAMP='SET_LAST_POPUP_TIMESTAMP';export var INCREASE_REJECTION_COUNT='INCREASE_REJECTION_COUNT';export var SET_ALREADY_RATED='SET_ALREADY_RATED';// currently the timespan is set to a day
2
+ export var TIMER_TIMESPAN=1000*60*60*24;
@@ -1,6 +1,6 @@
1
1
  import{OS_ANDROID,OS_IOS}from'@shopgate/pwa-common/constants/Device';/**
2
2
  * Generates a review app deep link based on the given provider
3
3
  * @param {string} bundleId app bundle id
4
- * @param {OS_ANDROID | OS_IOS} provider the name of the provider
4
+ * @param {OS_ANDROID | OS_IOS} platform the name of the OS platform
5
5
  * @return {string | null}
6
- */export function generateReviewLink(bundleId,provider){if(!bundleId){return null;}switch(provider){case OS_IOS:{return"https://itunes.apple.com/app/id".concat(bundleId,"?action=write-review");}case OS_ANDROID:{return"https://market.android.com/details?id=".concat(bundleId);}default:{return null;}}}
6
+ */export function generateReviewLink(bundleId,platform){if(!bundleId){return null;}switch(platform){case OS_IOS:{return"https://itunes.apple.com/app/id".concat(bundleId,"?action=write-review");}case OS_ANDROID:{return"https://market.android.com/details?id=".concat(bundleId);}default:{return null;}}}
@@ -1,6 +1,6 @@
1
- function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}import{INCREASE_APP_START_COUNT,RESET_APP_START_STATE,RESET_APP_START_COUNT,INCREASE_ORDERS_PLACED_COUNT,RESET_ORDERS_PLACED_COUNT,RESET_ORDERS_PLACED_STATE,INCREASE_TIMER_REPEATS,SET_TIMER_START_TIME,SET_LAST_POPUP_TIMESTAMP,INCREASE_REJECTION_COUNT}from"../constants";var defaultState={appStartCount:0,appStartResetCount:0,ordersPlacedCount:0,ordersPlacedResetCount:0,timerRepeatsCount:0,timerStartTimestamp:null,lastPopupAt:null,rejectionCount:0};/**
1
+ function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}import{INCREASE_APP_START_COUNT,RESET_APP_START_STATE,RESET_APP_START_COUNT,INCREASE_ORDERS_PLACED_COUNT,RESET_ORDERS_PLACED_COUNT,RESET_ORDERS_PLACED_STATE,INCREASE_TIMER_REPEATS,SET_TIMER_START_TIME,SET_LAST_POPUP_TIMESTAMP,INCREASE_REJECTION_COUNT,SET_ALREADY_RATED}from"../constants";var defaultState={appStartCount:0,appStartResetCount:0,ordersPlacedCount:0,ordersPlacedResetCount:0,timerRepeatsCount:0,timerStartTimestamp:null,lastPopupAt:null,rejectionCount:0,alreadyRated:false};/**
2
2
  * Stores all the app rating states.
3
3
  * @param {Object} [state] The current state.
4
4
  * @param {Object} action The action object.
5
5
  * @return {Object} The new state.
6
- */export default(function(){var state=arguments.length>0&&arguments[0]!==undefined?arguments[0]:defaultState;var action=arguments.length>1?arguments[1]:undefined;switch(action.type){case INCREASE_APP_START_COUNT:{return _extends({},state,{appStartCount:state.appStartCount+1});}case RESET_APP_START_COUNT:{return _extends({},state,{appStartCount:0,appStartResetCount:state.appStartResetCount+1});}case RESET_APP_START_STATE:{return _extends({},state,{appStartCount:0,appStartResetCount:0});}case INCREASE_ORDERS_PLACED_COUNT:{return _extends({},state,{ordersPlacedCount:state.ordersPlacedCount+1});}case RESET_ORDERS_PLACED_COUNT:{return _extends({},state,{ordersPlacedCount:0,ordersPlacedResetCount:state.ordersPlacedResetCount+1});}case RESET_ORDERS_PLACED_STATE:{return _extends({},state,{ordersPlacedCount:0,ordersPlacedResetCount:0});}case INCREASE_TIMER_REPEATS:{return _extends({},state,{timerRepeatsCount:state.timerRepeatsCount+1});}case SET_TIMER_START_TIME:{return _extends({},state,{timerStartTimestamp:Date.now()});}case SET_LAST_POPUP_TIMESTAMP:{return _extends({},state,{lastPopupAt:Date.now()});}case INCREASE_REJECTION_COUNT:{return _extends({},state,{rejectionCount:state.rejectionCount+1});}default:return state;}});
6
+ */export default(function(){var state=arguments.length>0&&arguments[0]!==undefined?arguments[0]:defaultState;var action=arguments.length>1?arguments[1]:undefined;switch(action.type){case INCREASE_APP_START_COUNT:{return _extends({},state,{appStartCount:state.appStartCount+1});}case RESET_APP_START_COUNT:{return _extends({},state,{appStartCount:0,appStartResetCount:state.appStartResetCount+1});}case RESET_APP_START_STATE:{return _extends({},state,{appStartCount:0,appStartResetCount:0});}case INCREASE_ORDERS_PLACED_COUNT:{return _extends({},state,{ordersPlacedCount:state.ordersPlacedCount+1});}case RESET_ORDERS_PLACED_COUNT:{return _extends({},state,{ordersPlacedCount:0,ordersPlacedResetCount:state.ordersPlacedResetCount+1});}case RESET_ORDERS_PLACED_STATE:{return _extends({},state,{ordersPlacedCount:0,ordersPlacedResetCount:0});}case INCREASE_TIMER_REPEATS:{return _extends({},state,{timerRepeatsCount:state.timerRepeatsCount+1});}case SET_TIMER_START_TIME:{return _extends({},state,{timerStartTimestamp:Date.now()});}case SET_LAST_POPUP_TIMESTAMP:{return _extends({},state,{lastPopupAt:Date.now()});}case INCREASE_REJECTION_COUNT:{return _extends({},state,{rejectionCount:state.rejectionCount+1});}case SET_ALREADY_RATED:{return _extends({},state,{alreadyRated:action.to});}default:return state;}});
@@ -1,20 +1,23 @@
1
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/pwa-common/helpers/config';import{appDidStart$}from'@shopgate/pwa-common/streams/app';import event from'@shopgate/pwa-core/classes/Event';import{increaseAppStartCount,resetAppStartCount}from"../action-creators/appStart";import{increaseOrdersPlacedCount,resetOrdersPlacedCount}from"../action-creators/ordersPlaced";import{resetTimerState,setTimerStartTime}from"../action-creators/timer";import{TIMER_TIMESPAN}from"../constants";import{getAppRatingState}from"../selectors/appRating";import{showModal}from"../actions/showModal";/**
2
2
  * App rating subscriptions
3
3
  * @param {Function} subscribe The subscribe function
4
- */export default function appRating(subscribe){var _appConfig$appRating=appConfig.appRating,appStarts=_appConfig$appRating.appStarts,ordersPlaced=_appConfig$appRating.ordersPlaced,timeInterval=_appConfig$appRating.timeInterval,rejectionMaxCount=_appConfig$appRating.rejectionMaxCount;// even subscriber to handle app start ratings
4
+ */export default function appRating(subscribe){var _appConfig$appRating=appConfig.appRating,appStarts=_appConfig$appRating.appStarts,ordersPlaced=_appConfig$appRating.ordersPlaced,timeInterval=_appConfig$appRating.timeInterval,rejectionMaxCount=_appConfig$appRating.rejectionMaxCount,bundleId=_appConfig$appRating.bundleId;// even subscriber to handle app start ratings
5
5
  // and also time interval ratings
6
- subscribe(appDidStart$,/*#__PURE__*/function(){var _ref2=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref){var dispatch,getState,state,mustShowModal,hasRepeats,resetAction,increaseAction;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:dispatch=_ref.dispatch,getState=_ref.getState;// every time the app starts
6
+ subscribe(appDidStart$,/*#__PURE__*/function(){var _ref2=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref){var dispatch,getState,state,mustShowModal,hasRepeats,resetAction,increaseAction;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:dispatch=_ref.dispatch,getState=_ref.getState;if(!(!bundleId||!bundleId.android||!bundleId.ios)){_context.next=3;break;}return _context.abrupt("return");case 3:// every time the app starts
7
7
  // we increase the start count
8
- dispatch(increaseAppStartCount());state=getAppRatingState(getState());// cancel the process if user has
9
- // already rejected rating the app
10
- // many times before
11
- if(!(state.rejectionCount>=rejectionMaxCount)){_context.next=5;break;}return _context.abrupt("return");case 5:// initiate the first start time
12
- if(state.timerStartTimestamp===null){dispatch(setTimerStartTime());}if(Number(timeInterval.value)>0&&Number(state.timerStartTimestamp)>0&&Date.now()-state.timerStartTimestamp>=timeInterval.value*TIMER_TIMESPAN){mustShowModal=true;hasRepeats=timeInterval.repeats===null||state.timerRepeatsCount<timeInterval.repeats;resetAction=resetTimerState;// since the time is elapsed
8
+ dispatch(increaseAppStartCount());state=getAppRatingState(getState());// if the user has already rated the app
9
+ // we'll cancel the operations as we
10
+ // don't have to show the modal once more
11
+ if(!state.alreadyRated){_context.next=7;break;}return _context.abrupt("return");case 7:if(!(state.rejectionCount>=rejectionMaxCount)){_context.next=9;break;}return _context.abrupt("return");case 9:// initiate the first start time
12
+ if(state.timerStartTimestamp===null){dispatch(setTimerStartTime());}mustShowModal=false;hasRepeats=false;resetAction=null;increaseAction=null;if(timeInterval&&Number(timeInterval.value)>0&&Number(state.timerStartTimestamp)>0&&Date.now()-state.timerStartTimestamp>=timeInterval.value*TIMER_TIMESPAN){mustShowModal=true;hasRepeats=timeInterval.repeats===null||state.timerRepeatsCount<=timeInterval.repeats;resetAction=resetTimerState;// since the time is elapsed
13
13
  // we reset the starting time
14
- increaseAction=setTimerStartTime;}else{mustShowModal=Number(appStarts.value)>0&&state.appStartCount>=appStarts.value;hasRepeats=appStarts.repeats===null||state.appStartResetCount<appStarts.repeats;resetAction=resetAppStartCount;increaseAction=null;}// the actual show modal logic
15
- dispatch(showModal(resetAction,increaseAction,mustShowModal,hasRepeats));case 8:case"end":return _context.stop();}}},_callee);}));return function(_x){return _ref2.apply(this,arguments);};}());// event subscriber to handle order placed ratings
16
- subscribe(appDidStart$,function(_ref3){var dispatch=_ref3.dispatch,getState=_ref3.getState;event.addCallback('checkoutSuccess',function(){var state=getAppRatingState(getState());// cancel the process if user has
14
+ increaseAction=setTimerStartTime;}else if(appStarts){mustShowModal=Number(appStarts.value)>0&&state.appStartCount>=appStarts.value;hasRepeats=appStarts.repeats===null||state.appStartResetCount<=appStarts.repeats;resetAction=resetAppStartCount;increaseAction=null;}// the actual show modal logic
15
+ dispatch(showModal(resetAction,increaseAction,mustShowModal,hasRepeats));case 16:case"end":return _context.stop();}}},_callee);}));return function(_x){return _ref2.apply(this,arguments);};}());// event subscriber to handle order placed ratings
16
+ subscribe(appDidStart$,function(_ref3){var dispatch=_ref3.dispatch,getState=_ref3.getState;event.addCallback('checkoutSuccess',function(){if(!bundleId||!bundleId.android||!bundleId.ios){return;}var state=getAppRatingState(getState());// if the user has already rated the app
17
+ // we'll cancel the operations as we
18
+ // don't have to show the modal once more
19
+ if(state.alreadyRated){return;}// cancel the process if user has
17
20
  // already rejected rating the app
18
21
  // many times before
19
- if(state.rejectionCount>=rejectionMaxCount){return;}// orders placed count starts from 0
20
- var mustShowModal=state.ordersPlacedCount===ordersPlaced.value-1;var hasRepeats=ordersPlaced.repeats===null||state.ordersPlacedResetCount<ordersPlaced.repeats;dispatch(showModal(resetOrdersPlacedCount,increaseOrdersPlacedCount,mustShowModal,hasRepeats));});});}
22
+ if(state.rejectionCount>=rejectionMaxCount){return;}if(!ordersPlaced){return;}// orders placed count starts from 0
23
+ var mustShowModal=state.ordersPlacedCount===ordersPlaced.value-1;var hasRepeats=ordersPlaced.repeats===null||state.ordersPlacedResetCount<=ordersPlaced.repeats;dispatch(showModal(resetOrdersPlacedCount,increaseOrdersPlacedCount,mustShowModal,hasRepeats));});});}
@@ -0,0 +1 @@
1
+ import{getThemeStyles}from"../getThemeStyles";import{getThemeConfig}from"../getThemeConfig";jest.mock("../getThemeConfig",function(){return{getThemeConfig:jest.fn()};});describe('engage > core > config',function(){describe('getThemeStyles()',function(){it('should return an empty object if no styles property exists',function(){getThemeConfig.mockReturnValueOnce({});var styles=getThemeStyles();expect(styles).toEqual({});});it('should return all styles if no key is given',function(){var mockStyles={'@shopgate/engage/product/ProductGrid':{color:'red'},'@shopgate/engage/product/ProductSlider':{color:'blue'}};getThemeConfig.mockReturnValueOnce({styles:mockStyles});var styles=getThemeStyles();expect(styles).toEqual(mockStyles);});it('should return specific styles if key is given',function(){var mockStyles={'@shopgate/engage/product/ProductGrid':{color:'red'},'@shopgate/engage/product/ProductSlider':{color:'blue'}};getThemeConfig.mockReturnValueOnce({styles:mockStyles});var styles=getThemeStyles('@shopgate/engage/product/ProductSlider');expect(styles).toEqual({color:'blue'});});it('should return undefined if key is no available',function(){getThemeConfig.mockReturnValueOnce({});var styles=getThemeStyles('keyNotAvailable');expect(styles).toBeUndefined();});});});
@@ -0,0 +1,6 @@
1
+ import{getThemeConfig}from"./getThemeConfig";/**
2
+ * Retrieves the global theme styles. Returns undefined when the given key doesn't exist there.
3
+ *
4
+ * @param {string|null} [key=null] settings key
5
+ * @returns {Object|undefined|*}
6
+ */export function getThemeStyles(){var key=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;var _getThemeConfig=getThemeConfig(),_getThemeConfig$style=_getThemeConfig.styles,styles=_getThemeConfig$style===void 0?{}:_getThemeConfig$style;return key?styles[key]:styles;}
@@ -1 +1 @@
1
- import{useWidgetStyles}from"../useWidgetStyles";import{useWidgetConfig}from"../useWidgetConfig";jest.mock("../useWidgetConfig",function(){return{useWidgetConfig:jest.fn()};});describe('engage > core > hooks',function(){describe('useWidgetStyles()',function(){beforeEach(function(){jest.resetAllMocks();});it('should return an empty object if no styles property exists',function(){useWidgetConfig.mockReturnValueOnce({});var styles=useWidgetStyles();expect(styles).toEqual({});});it('should return an empty object if no styles exist',function(){useWidgetConfig.mockReturnValueOnce({style:{}});var styles=useWidgetStyles();expect(styles).toEqual({});});it('should return all widget styles.',function(){useWidgetConfig.mockReturnValueOnce({styles:{color:'#ff0000',width:'100%'}});var styles=useWidgetStyles();expect(styles).toEqual({color:'#ff0000',width:'100%'});});it('should pass down its given params to the lower level helper function.',function(){useWidgetConfig.mockReturnValueOnce({});useWidgetStyles('widgetId',3);expect(useWidgetConfig).toBeCalledWith('widgetId',3);expect(useWidgetConfig).toBeCalledTimes(1);});});});
1
+ import{useWidgetStyles}from"../useWidgetStyles";import{useWidgetConfig}from"../useWidgetConfig";import{getThemeStyles}from"../../config/getThemeStyles";jest.mock("../useWidgetConfig",function(){return{useWidgetConfig:jest.fn()};});jest.mock("../../config/getThemeStyles",function(){return{getThemeStyles:jest.fn()};});describe('engage > core > hooks',function(){describe('useWidgetStyles()',function(){beforeEach(function(){jest.resetAllMocks();});it('should return an empty object if no styles property exists',function(){useWidgetConfig.mockReturnValueOnce({});getThemeStyles.mockReturnValueOnce({});var styles=useWidgetStyles();expect(styles).toEqual({});});it('should return an empty object if no styles exist',function(){useWidgetConfig.mockReturnValueOnce({style:{}});getThemeStyles.mockReturnValueOnce({});var styles=useWidgetStyles();expect(styles).toEqual({});});it('should return all widget styles.',function(){useWidgetConfig.mockReturnValueOnce({styles:{color:'#ff0000',width:'100%'}});getThemeStyles.mockReturnValueOnce({});var styles=useWidgetStyles();expect(styles).toEqual({color:'#ff0000',width:'100%'});});it('should return all theme styles.',function(){useWidgetConfig.mockReturnValueOnce({styles:{}});getThemeStyles.mockReturnValueOnce({color:'#ff0000',width:'100%'});var styles=useWidgetStyles();expect(styles).toEqual({color:'#ff0000',width:'100%'});});it('should return merged widget/theme styles.',function(){useWidgetConfig.mockReturnValueOnce({styles:{color:'#666666',height:'100%'}});getThemeStyles.mockReturnValueOnce({color:'#ff0000',width:'100%'});var styles=useWidgetStyles();expect(styles).toEqual({color:'#666666',width:'100%',height:'100%'});});it('should pass down its given params to the lower level helper function.',function(){useWidgetConfig.mockReturnValueOnce({});getThemeStyles.mockReturnValueOnce({});useWidgetStyles('widgetId',3);expect(useWidgetConfig).toBeCalledWith('widgetId',3);expect(useWidgetConfig).toBeCalledTimes(1);expect(getThemeStyles).toBeCalledWith('widgetId');expect(getThemeStyles).toBeCalledTimes(1);});});});
@@ -1,8 +1,8 @@
1
- import{useWidgetConfig}from"./useWidgetConfig";/**
1
+ import defaultsDeep from'lodash/defaultsDeep';import{useWidgetConfig}from"./useWidgetConfig";import{getThemeStyles}from"../config/getThemeStyles";/**
2
2
  * Retrieves the styles for a specific widget by its id. Returns an empty object when no styles
3
3
  * exist.
4
4
  *
5
5
  * @param {string} widgetId The ID of the widget to look for.
6
6
  * @param {number|undefined} [index=0] The optional index of the widget.
7
7
  * @returns {Object}
8
- */export function useWidgetStyles(widgetId){var index=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var _useWidgetConfig=useWidgetConfig(widgetId,index),_useWidgetConfig$styl=_useWidgetConfig.styles,styles=_useWidgetConfig$styl===void 0?{}:_useWidgetConfig$styl;return styles;}
8
+ */export function useWidgetStyles(widgetId){var index=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var _useWidgetConfig=useWidgetConfig(widgetId,index),_useWidgetConfig$styl=_useWidgetConfig.styles,styles=_useWidgetConfig$styl===void 0?{}:_useWidgetConfig$styl;var globalStyles=getThemeStyles(widgetId);return defaultsDeep(styles,globalStyles);}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopgate/engage",
3
- "version": "6.17.0-rc.2",
3
+ "version": "6.17.0-rc.7",
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.17.0-rc.2",
19
- "@shopgate/pwa-common-commerce": "6.17.0-rc.2",
20
- "@shopgate/pwa-core": "6.17.0-rc.2",
21
- "@shopgate/pwa-ui-ios": "6.17.0-rc.2",
22
- "@shopgate/pwa-ui-material": "6.17.0-rc.2",
23
- "@shopgate/pwa-ui-shared": "6.17.0-rc.2",
18
+ "@shopgate/pwa-common": "6.17.0-rc.7",
19
+ "@shopgate/pwa-common-commerce": "6.17.0-rc.7",
20
+ "@shopgate/pwa-core": "6.17.0-rc.7",
21
+ "@shopgate/pwa-ui-ios": "6.17.0-rc.7",
22
+ "@shopgate/pwa-ui-material": "6.17.0-rc.7",
23
+ "@shopgate/pwa-ui-shared": "6.17.0-rc.7",
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",