@shopgate/engage
Version:
Shopgate's ENGAGE library.
25 lines • 2.5 kB
JavaScript
import{APP_FEATURE_PUSH_OPT_IN,APP_FEATURE_COOKIE_CONSENT,APP_FEATURE_ANDROID_EDGE_TO_EDGE}from'@shopgate/engage/core/constants';import{hasSGJavaScriptBridge,hasWebBridge,hasNewServices,isAndroidOs}from'@shopgate/engage/core/helpers';/**
* Checks if a specific feature flag is enabled.
*
* @param {string} category The top-level category of the featureFlags object
* (e.g., 'Push', 'Analytics', 'StatusBar').
* @param {string} flag The feature flag constant to look for.
* @returns {boolean}
*/function isFeatureFlagEnabled(category,flag){var _window,_window$SGAppInfo,_window$SGAppInfo$fea,_window$SGAppInfo$fea2,_window$SGAppInfo$fea3;// Check if app provides the feature flags of the requested category
var flags=(_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[category])===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;// CHeck if the feature flag is provided
return Array.isArray(flags)&&flags.includes(flag);}/**
* Determines if the app supports the push opt-in feature
* @returns {boolean}
*/export var appSupportsPushOptIn=function appSupportsPushOptIn(){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;}return isFeatureFlagEnabled('Push',APP_FEATURE_PUSH_OPT_IN);};/**
* Determines if the app supports the cookie consent feature
* @returns {boolean}
*/export var appSupportsCookieConsent=function appSupportsCookieConsent(){if(hasWebBridge()){// Deactivated in browser mode for now
return false;}if(!hasSGJavaScriptBridge()){// Always supported in development
return true;}return isFeatureFlagEnabled('Analytics',APP_FEATURE_COOKIE_CONSENT);};/**
* Determines if the app supports Android with edge-to-edge screens
* @returns {boolean}
*/export var appSupportsAndroidEdgeToEdge=function appSupportsAndroidEdgeToEdge(){if(hasWebBridge()){// Deactivated in browser mode
return false;}if(!hasSGJavaScriptBridge()&&isAndroidOs){// Active in dev environment with Android user agent
return true;}return isFeatureFlagEnabled('StatusBar',APP_FEATURE_ANDROID_EDGE_TO_EDGE);};