@shopgate/engage
Version:
Shopgate's ENGAGE library.
15 lines • 2.52 kB
JavaScript
import{APP_FEATURE_PUSH_OPT_IN,APP_FEATURE_COOKIE_CONSENT}from'@shopgate/engage/core/constants';import{hasSGJavaScriptBridge,hasWebBridge,hasNewServices}from'@shopgate/engage/core/helpers';/**
* Determines if the app supports the push opt-in feature
* @returns {boolean}
*/export var appSupportsPushOptIn=function appSupportsPushOptIn(){var _window,_window$SGAppInfo,_window$SGAppInfo$fea,_window$SGAppInfo$fea2,_window$SGAppInfo$fea3;if(hasWebBridge()||hasNewServices()){// Not push notifications in browser mode. Deactivated for new system for now
return false;}if(!hasSGJavaScriptBridge()){// Always supported in development
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
return false;}// Supported when the feature flags contain the push opt-in flag
return window.SGAppInfo.featureFlags.Push['1'].flags.includes(APP_FEATURE_PUSH_OPT_IN);};/**
* Determines if the app supports the cookie consent feature
* @returns {boolean}
*/export var appSupportsCookieConsent=function appSupportsCookieConsent(){var _window2,_window2$SGAppInfo,_window2$SGAppInfo$fe,_window2$SGAppInfo$fe2,_window2$SGAppInfo$fe3;if(hasWebBridge()){// Deactivated in browser mode for now
return false;}if(!hasSGJavaScriptBridge()){// Always supported in development
return true;}if(!Array.isArray((_window2=window)===null||_window2===void 0?void 0:(_window2$SGAppInfo=_window2.SGAppInfo)===null||_window2$SGAppInfo===void 0?void 0:(_window2$SGAppInfo$fe=_window2$SGAppInfo.featureFlags)===null||_window2$SGAppInfo$fe===void 0?void 0:(_window2$SGAppInfo$fe2=_window2$SGAppInfo$fe.Analytics)===null||_window2$SGAppInfo$fe2===void 0?void 0:(_window2$SGAppInfo$fe3=_window2$SGAppInfo$fe2['1'])===null||_window2$SGAppInfo$fe3===void 0?void 0:_window2$SGAppInfo$fe3.flags)){// Not supported on app versions that don't provide the featureFlags object
return false;}// Supported when the feature flags contain the cookie consent flag
return window.SGAppInfo.featureFlags.Analytics['1'].flags.includes(APP_FEATURE_COOKIE_CONSENT);};