UNPKG

@shopgate/engage

Version:
39 lines 5.39 kB
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{createSelector}from'reselect';import{appConfig}from'@shopgate/engage';import{appSupportsCookieConsent}from'@shopgate/engage/core/helpers';var _appConfig$cookieCons=appConfig.cookieConsent,_appConfig$cookieCons2=_appConfig$cookieCons===void 0?{}:_appConfig$cookieCons,isCookieConsentActivated=_appConfig$cookieCons2.isCookieConsentActivated,showComfortCookiesToggle=_appConfig$cookieCons2.showComfortCookiesToggle;/** * Selects the cookie consent modal state. * @param {Object} state The current state of the cookie consent modal. * @returns {Object} whether cookie consent modal is shown. */export var getCookieConsentModalState=function getCookieConsentModalState(state){var _state$tracking;return(state===null||state===void 0?void 0:(_state$tracking=state.tracking)===null||_state$tracking===void 0?void 0:_state$tracking.cookieConsentModal)||{};};/** * Selects the cookie settings state. * @param {Object} state The current state of the cookie settings. * @returns {Object} whether cookies have been accepted by the user. */export var getCookieSettingsState=function getCookieSettingsState(state){var _state$tracking2;return(state===null||state===void 0?void 0:(_state$tracking2=state.tracking)===null||_state$tracking2===void 0?void 0:_state$tracking2.cookieSettings)||{};};/** * Determines whether the cookie consent process is finished (selection happened before, feature is * inactive, app doesn't support the feature). * @returns {boolean} Whether the cookie consent process is handled either by user * or by app/feature settings */export var getIsCookieConsentHandled=createSelector(getCookieSettingsState,function(settingsState){if(!isCookieConsentActivated||!appSupportsCookieConsent()){return true;}return(settingsState===null||settingsState===void 0?void 0:settingsState.comfortCookiesAccepted)!==null||(settingsState===null||settingsState===void 0?void 0:settingsState.statisticsCookiesAccepted)!==null;});/** * Selects the property of the comfort cookie settings. * @private This selector is intended to be used internally. When a cookie consent status needs * to be checked for a feature, please use `getAreComfortCookiesAccepted` instead. * @returns {boolean|null} whether comfort cookies have been selected by the user. */export var getAreComfortCookiesAcceptedInternal=createSelector(getCookieSettingsState,function(settingsState){return settingsState.comfortCookiesAccepted;});/** * Selects the property of the statistics cookie settings. * @private This selector is intended to be used internally. When a cookie consent status needs * to be checked for a feature, please use `getAreStatisticsCookiesAccepted` instead. * @returns {boolean|null} whether statistics cookies have been selected by the user. */export var getAreStatisticsCookiesAcceptedInternal=createSelector(getCookieSettingsState,function(settingsState){return settingsState.statisticsCookiesAccepted;});/** * Determines if comfort cookies were accepted in the cookie consent process. When cookie * consent is inactive, the selector will also return true. * @returns {boolean} whether comfort cookies are set and should activate tracking. */export var getAreComfortCookiesAccepted=createSelector(getCookieSettingsState,getIsCookieConsentHandled,function(settingsState,consentHandled){if(!consentHandled)return false;if(!isCookieConsentActivated||!showComfortCookiesToggle)return true;if(settingsState.comfortCookiesAccepted===null)return true;return settingsState.comfortCookiesAccepted;});/** * Determines if statistics cookies were accepted in the cookie consent process. When cookie * consent is inactive, the selector will also return true. * @returns {boolean} whether statistics cookies are set and should activate tracking. */export var getAreStatisticsCookiesAccepted=createSelector(getCookieSettingsState,getIsCookieConsentHandled,function(settingsState,consentHandled){if(!consentHandled)return false;if(!isCookieConsentActivated)return true;if(settingsState.statisticsCookiesAccepted===null)return true;return settingsState.statisticsCookiesAccepted;});/** * Selects the visibility property of the cookie consent modal. * @returns {boolean} whether cookie consent modal is shown. */export var getIsCookieConsentModalVisible=createSelector(getCookieConsentModalState,getAreComfortCookiesAcceptedInternal,getAreStatisticsCookiesAcceptedInternal,function(modalState,comfortCookiesState,statisticsCookiesState){return modalState.isCookieConsentModalVisible&&comfortCookiesState===null&&statisticsCookiesState===null;});/** * Determines if the cookie consent feature is activated */export var getIsCookieConsentActivated=createSelector(function(){return isCookieConsentActivated&&appSupportsCookieConsent();});/** * Creates a meta data object for tracking opt in tracking events */export var getCookieConsentTrackingMeta=createSelector(getIsCookieConsentActivated,function(_){var props=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};return props;},function(isActivated,states){return _extends({permission:'tracking',usesSoftTrackingOptIn:isActivated},states);});