Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
email: 'test@example.com',
avatar: 'http://avatar.url',
ip: '1.1.1.1',
country: 'us',
anonymous: true,
custom: {
'a': 's',
'b': true,
'c': 3,
'd': [ 'x', 'y' ],
'e': [ true, false ],
'f': [ 1, 2 ]
},
privateAttributeNames: [ 'name', 'email' ]
};
var client: ld.LDClient = ld.init('sdk-key', allOptions);
client.identify(user);
client.track('key', user);
client.track('key', user, { ok: 1 });
client.track('key', user, null, 1.5);
// evaluation methods with callbacks
client.variation('key', user, false, (value: ld.LDFlagValue) => { });
client.variation('key', user, 2, (value: ld.LDFlagValue) => { });
client.variation('key', user, 'default', (value: ld.LDFlagValue) => { });
client.variationDetail('key', user, 'default', (detail: ld.LDEvaluationDetail) => {
var detailValue: ld.LDFlagValue = detail.value;
var detailIndex: number | undefined = detail.variationIndex;
var detailReason: ld.LDEvaluationReason = detail.reason;
});
client.allFlags(user, (flagSet: ld.LDFlagSet) => {
export function register(
server: HapiServer,
options: {
languageRenderers: { [string]: LanguageRenderer },
ldkey?: string,
}
): Promise {
server.route(getRoute(options.languageRenderers));
const ldClient = LaunchDarkly.init(options.ldkey || LAUNCH_DARKLY_SDK_KEY, {
offline: process.env.NODE_ENV === 'test',
});
server.expose('getFlags', (user: LaunchDarklyUser) => {
return ldClient.allFlagsState(user).then(
state => state.allValues(),
err => {
server.app.logger.error({
err,
member: user,
});
return {}; // return empty flags on error
}
);
});
// set up launchdarkly instance before continuing
server.events.on('stop', ldClient.close);