diff --git a/src/index.ts b/src/index.ts index fa81a3a..7742ff1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -66,16 +66,16 @@ export const Statsig = { * * @param {StatsigUser} user - the user to check this gate value for * @param {string} gateName - the name of the gate to check - * @returns {Promise} - The value of the gate for the user. Gates are off (return false) by default + * @returns {boolean} - The value of the gate for the user. Gates are off (return false) by default * @throws Error if initialize() was not called first * @throws Error if the gateName is not provided or not a non-empty string */ - checkGate(user: StatsigUser, gateName: string): Promise { - return this._enforceServer().checkGate(user, gateName); + checkGateSync(user: StatsigUser, gateName: string): boolean { + return this._enforceServer().checkGateSync(user, gateName); }, - getFeatureGate(user: StatsigUser, gateName: string): Promise { - return this._enforceServer().getFeatureGate(user, gateName); + getFeatureGateSync(user: StatsigUser, gateName: string): FeatureGate { + return this._enforceServer().getFeatureGateSync(user, gateName); }, /** @@ -84,25 +84,25 @@ export const Statsig = { * * @param {StatsigUser} user - the user to check this gate value for * @param {string} gateName - the name of the gate to check - * @returns {Promise} - The value of the gate for the user. Gates are off (return false) by default + * @returns {boolean} - The value of the gate for the user. Gates are off (return false) by default * @throws Error if initialize() was not called first * @throws Error if the gateName is not provided or not a non-empty string */ - checkGateWithExposureLoggingDisabled( + checkGateWithExposureLoggingDisabledSync( user: StatsigUser, gateName: string, - ): Promise { - return this._enforceServer().checkGateWithExposureLoggingDisabled( + ): boolean { + return this._enforceServer().checkGateWithExposureLoggingDisabledSync( user, gateName, ); }, - getFeatureGateWithExposureLoggingDisabled( + getFeatureGateWithExposureLoggingDisabledSync( user: StatsigUser, gateName: string, - ): Promise { - return this._enforceServer().getFeatureGateWithExposureLoggingDisabled( + ): FeatureGate { + return this._enforceServer().getFeatureGateWithExposureLoggingDisabledSync( user, gateName, ); @@ -124,12 +124,12 @@ export const Statsig = { * * @param {StatsigUser} user - the user to evaluate for the dyamic config * @param {string} configName - the name of the dynamic config to get - * @returns {Promise} - the config for the user + * @returns {DynamicConfig} - the config for the user * @throws Error if initialize() was not called first * @throws Error if the configName is not provided or not a non-empty string */ - getConfig(user: StatsigUser, configName: string): Promise { - return this._enforceServer().getConfig(user, configName); + getConfigSync(user: StatsigUser, configName: string): DynamicConfig { + return this._enforceServer().getConfigSync(user, configName); }, /** @@ -138,15 +138,14 @@ export const Statsig = { * * @param {StatsigUser} user - the user to evaluate for the dyamic config * @param {string} configName - the name of the dynamic config to get - * @returns {Promise} - the config for the user + * @returns {DynamicConfig} - the config for the user * @throws Error if initialize() was not called first - * @throws Error if the configName is not provided or not a non-empty string */ - getConfigWithExposureLoggingDisabled( + getConfigWithExposureLoggingDisabledSync( user: StatsigUser, configName: string, - ): Promise { - return this._enforceServer().getConfigWithExposureLoggingDisabled( + ): DynamicConfig { + return this._enforceServer().getConfigWithExposureLoggingDisabledSync( user, configName, ); @@ -168,15 +167,11 @@ export const Statsig = { * * @param {StatsigUser} user - the user to evaluate for the experiment * @param {string} experimentName - the name of the experiment to get - * @returns {Promise} - the experiment for the user, represented by a Dynamic Config object + * @returns {DynamicConfig} - the experiment for the user, represented by a Dynamic Config object * @throws Error if initialize() was not called first - * @throws Error if the experimentName is not provided or not a non-empty string */ - getExperiment( - user: StatsigUser, - experimentName: string, - ): Promise { - return this._enforceServer().getExperiment(user, experimentName); + getExperimentSync(user: StatsigUser, experimentName: string): DynamicConfig { + return this._enforceServer().getExperimentSync(user, experimentName); }, /** @@ -185,15 +180,14 @@ export const Statsig = { * * @param {StatsigUser} user - the user to evaluate for the experiment * @param {string} experimentName - the name of the experiment to get - * @returns {Promise} - the experiment for the user, represented by a Dynamic Config object + * @returns {DynamicConfig} - the experiment for the user, represented by a Dynamic Config object * @throws Error if initialize() was not called first - * @throws Error if the experimentName is not provided or not a non-empty string */ - getExperimentWithExposureLoggingDisabled( + getExperimentWithExposureLoggingDisabledSync( user: StatsigUser, experimentName: string, - ): Promise { - return this._enforceServer().getExperimentWithExposureLoggingDisabled( + ): DynamicConfig { + return this._enforceServer().getExperimentWithExposureLoggingDisabledSync( user, experimentName, ); @@ -215,12 +209,11 @@ export const Statsig = { * * @param {StatsigUser} user - the user to evaluate for the layer * @param {string} layerName - the name of the layer to get - * @returns {Promise} - the layer for the user, represented by a Layer + * @returns {Layer} - the layer for the user, represented by a Layer * @throws Error if initialize() was not called first - * @throws Error if the layerName is not provided or not a non-empty string */ - getLayer(user: StatsigUser, layerName: string): Promise { - return this._enforceServer().getLayer(user, layerName); + getLayerSync(user: StatsigUser, layerName: string): Layer { + return this._enforceServer().getLayerSync(user, layerName); }, /** @@ -229,15 +222,15 @@ export const Statsig = { * * @param {StatsigUser} user - the user to evaluate for the layer * @param {string} layerName - the name of the layer to get - * @returns {Promise} - the layer for the user, represented by a Layer + * @returns {Layer} - the layer for the user, represented by a Layer * @throws Error if initialize() was not called first * @throws Error if the layerName is not provided or not a non-empty string */ - getLayerWithExposureLoggingDisabled( + getLayerWithExposureLoggingDisabledSync( user: StatsigUser, layerName: string, - ): Promise { - return this._enforceServer().getLayerWithExposureLoggingDisabled( + ): Layer { + return this._enforceServer().getLayerWithExposureLoggingDisabledSync( user, layerName, ); @@ -381,6 +374,123 @@ export const Statsig = { return this._enforceServer().syncStoreIdLists(); }, + //#region Deprecated Async Methods + + /** + * @deprecated Please use checkGateSync instead. + * @see https://docs.statsig.com/server/deprecation-notices + */ + checkGate(user: StatsigUser, gateName: string): Promise { + return this._enforceServer().checkGate(user, gateName); + }, + + /** + * @deprecated Please use getFeatureGateSync instead. + * @see https://docs.statsig.com/server/deprecation-notices + */ + getFeatureGate(user: StatsigUser, gateName: string): Promise { + return this._enforceServer().getFeatureGate(user, gateName); + }, + + /** + * @deprecated Please use checkGateWithExposureLoggingDisabledSync instead. + * @see https://docs.statsig.com/server/deprecation-notices + */ + async checkGateWithExposureLoggingDisabled( + user: StatsigUser, + gateName: string, + ): Promise { + return this._enforceServer().checkGateWithExposureLoggingDisabled( + user, + gateName, + ); + }, + + /** + * @deprecated Please use getFeatureGateWithExposureLoggingDisabledSync instead. + * @see https://docs.statsig.com/server/deprecation-notices + */ + getFeatureGateWithExposureLoggingDisabled( + user: StatsigUser, + gateName: string, + ): Promise { + return this._enforceServer().getFeatureGateWithExposureLoggingDisabled( + user, + gateName, + ); + }, + + /** + * @deprecated Please use getConfigSync instead. + * @see https://docs.statsig.com/server/deprecation-notices + */ + getConfig(user: StatsigUser, configName: string): Promise { + return this._enforceServer().getConfig(user, configName); + }, + + /** + * @deprecated Please use getConfigWithExposureLoggingDisabledSync instead. + * @see https://docs.statsig.com/server/deprecation-notices + */ + getConfigWithExposureLoggingDisabled( + user: StatsigUser, + configName: string, + ): Promise { + return this._enforceServer().getConfigWithExposureLoggingDisabled( + user, + configName, + ); + }, + + /** + * @deprecated Please use getExperimentSync instead. + * @see https://docs.statsig.com/server/deprecation-notices + */ + getExperiment( + user: StatsigUser, + experimentName: string, + ): Promise { + return this._enforceServer().getConfig(user, experimentName); + }, + + /** + * @deprecated Please use getExperimentWithExposureLoggingDisabledSync instead. + * @see https://docs.statsig.com/server/deprecation-notices + */ + getExperimentWithExposureLoggingDisabled( + user: StatsigUser, + experimentName: string, + ): Promise { + return this._enforceServer().getConfigWithExposureLoggingDisabled( + user, + experimentName, + ); + }, + + /** + * @deprecated Please use getLayerSync instead. + * @see https://docs.statsig.com/server/deprecation-notices + */ + getLayer(user: StatsigUser, layerName: string): Promise { + return this._enforceServer().getLayer(user, layerName); + }, + + /** + * @deprecated Please use getLayerWithExposureLoggingDisabledSync instead. + * @see https://docs.statsig.com/server/deprecation-notices + */ + getLayerWithExposureLoggingDisabled( + user: StatsigUser, + layerName: string, + ): Promise { + return this._enforceServer().getLayerWithExposureLoggingDisabled( + user, + layerName, + ); + }, + + //#endregion + _enforceServer(): StatsigServer { let instance = StatsigInstanceUtils.getInstance(); if (instance == null) {