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) => {
var flagSetValue: ld.LDFlagValue = flagSet['key'];
});
// evaluation methods with promises
client.variation('key', user, false).then((value: ld.LDFlagValue) => { });
client.variation('key', user, 2).then((value: ld.LDFlagValue) => { });
client.variation('key', user, 'default').then((value: ld.LDFlagValue) => { });
client.variationDetail('key', user, 'default').then((detail: ld.LDEvaluationDetail) => { });
client.allFlags(user).then((flagSet: ld.LDFlagSet) => { });
// Redis integration
var redisStore0 = ld.RedisFeatureStore();
var myRedisOpts: redis.ClientOpts = {};
var redisStore1 = ld.RedisFeatureStore(myRedisOpts, 30, 'prefix', logger);
var myRedisClient: redis.RedisClient = new redis.RedisClient(myRedisOpts);
var redisStore2 = ld.RedisFeatureStore(undefined, 30, 'prefix', logger, myRedisClient);
var detailIndex: number | undefined = detail.variationIndex;
var detailReason: ld.LDEvaluationReason = detail.reason;
});
client.allFlags(user, (flagSet: ld.LDFlagSet) => {
var flagSetValue: ld.LDFlagValue = flagSet['key'];
});
// evaluation methods with promises
client.variation('key', user, false).then((value: ld.LDFlagValue) => { });
client.variation('key', user, 2).then((value: ld.LDFlagValue) => { });
client.variation('key', user, 'default').then((value: ld.LDFlagValue) => { });
client.variationDetail('key', user, 'default').then((detail: ld.LDEvaluationDetail) => { });
client.allFlags(user).then((flagSet: ld.LDFlagSet) => { });
// Redis integration
var redisStore0 = ld.RedisFeatureStore();
var myRedisOpts: redis.ClientOpts = {};
var redisStore1 = ld.RedisFeatureStore(myRedisOpts, 30, 'prefix', logger);
var myRedisClient: redis.RedisClient = new redis.RedisClient(myRedisOpts);
var redisStore2 = ld.RedisFeatureStore(undefined, 30, 'prefix', logger, myRedisClient);
});
client.allFlags(user, (flagSet: ld.LDFlagSet) => {
var flagSetValue: ld.LDFlagValue = flagSet['key'];
});
// evaluation methods with promises
client.variation('key', user, false).then((value: ld.LDFlagValue) => { });
client.variation('key', user, 2).then((value: ld.LDFlagValue) => { });
client.variation('key', user, 'default').then((value: ld.LDFlagValue) => { });
client.variationDetail('key', user, 'default').then((detail: ld.LDEvaluationDetail) => { });
client.allFlags(user).then((flagSet: ld.LDFlagSet) => { });
// Redis integration
var redisStore0 = ld.RedisFeatureStore();
var myRedisOpts: redis.ClientOpts = {};
var redisStore1 = ld.RedisFeatureStore(myRedisOpts, 30, 'prefix', logger);
var myRedisClient: redis.RedisClient = new redis.RedisClient(myRedisOpts);
var redisStore2 = ld.RedisFeatureStore(undefined, 30, 'prefix', logger, myRedisClient);
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);