// After initialization, turn off graceful failure so exceptions are rethrown
getInstance().setIsGracefulFailureMode(false);
// Drop-in wrapper replacement for getting a boolean Statsig gate.
// Replace boolean calls to checkGate() with getBoolVariationWrapper() in the code.
export function getBoolVariationWrapper(
gateKey: string,
user: StatsigUser,
attributes?: Record<string, string | number | boolean | null>
) {
let assignment = false;
try {
assignment = getInstance().getBooleanAssignment(
gateKey,
user.userID,
attributes,
false
);
} catch (e) {
logger.warn(
'Error encountered evaluating boolean assignment from Eppo SDK; falling back to Statsig',
{ gateKey, user, attributes }
);
// Fallback to Statsig gate check
assignment = statsig.checkGate(user, gateKey);
}
return assignment;
}
// Drop-in wrapper replacement for getting a string Statsig config.
// Replace string calls to getConfig() with getStringVariationWrapper() in the code.
export function getStringVariationWrapper(
configKey: string,
parameterName: string,
user: StatsigUser,
attributes?: Record<string, string | number | boolean | null>
) {
let assignment = 'default';
try {
assignment = getInstance().getStringAssignment(
user.userID,
configKey,
attributes,
'default'
);
} catch (e) {
logger.warn(
'Error encountered evaluating string assignment from Eppo SDK; falling back to Statsig',
{ configKey, parameterName, user, attributes }
);
// Fallback to Statsig config parameter
const config = statsig.getConfig(user, configKey);
assignment = config.get(parameterName, 'default');
}
return assignment;
}
// Drop-in wrapper replacement for getting a numeric Statsig config parameter.
// Replace numeric calls to getConfig() with getNumericVariationWrapper() in the code.
export function getNumericVariationWrapper(
configKey: string,
parameterName: string,
user: StatsigUser,
attributes?: Record<string, string | number | boolean | null>
) {
let assignment = 0;
try {
assignment = getInstance().getNumericAssignment(
user.userID,
configKey,
attributes,
0
);
} catch (e) {
logger.warn(
'Error encountered evaluating numeric assignment from Eppo SDK; falling back to Statsig',
{ configKey, parameterName, user, attributes }
);
// Fallback to Statsig config parameter
const config = statsig.getConfig(user, configKey);
assignment = config.get(parameterName, 0);
}
return assignment;
}
// Drop-in wrapper replacement for getting experiment assignments.
// Replace calls to getExperiment() with getExperimentVariationWrapper() in the code.
export function getJSONVariationWrapper(
experimentKey: string,
parameterName: string,
user: StatsigUser,
attributes?: Record<string, string | number | boolean | null>
) {
let assignment: any = null;
try {
// For experiments with multiple parameters, use JSON assignment
const experimentResult = getInstance().getJSONAssignment(
user.userID,
experimentKey,
attributes,
{}
);
assignment = experimentResult?.[parameterName];
} catch (e) {
logger.warn(
'Error encountered evaluating experiment assignment from Eppo SDK; falling back to Statsig',
{ experimentKey, parameterName, user, attributes }
);
// Fallback to Statsig experiment
const experiment = statsig.getExperiment(user, experimentKey);
assignment = experiment.get(parameterName, null);
}
return assignment;
}