@evo/featureflags-client
v1.6.0
Published
GRPC node client for feacture flags service
Downloads
2,749
Maintainers
Keywords
Readme
Feature Flags client
NodeJS client grpc
lib, for featureflags service. Provides abilitty to gracefull set and updates
for ur features.
.proto
files were taken directly from repo above. They should be uploaded in some place from the root repo ondeploy
i guess
API
FeatureClient
is the base class. With it's constructor u will init grpc
client.
So u do this on application start:
import { FeatureClient, Variable, Types } from '@evo/featureflags-client';
// Ur default flags dict
const Flags = {
TEST: false,
NODE: false
};
const featureClient = new FeatureClient(
'thecorp', // project name
'grpc:50051', // grpc-url
Flags, // default flags
[
new Variable('username', Types.STRING) // ur controll values for Checks
],
// it`s the default value, u can skeep it, if dont want
// to controll loop start manualy
true, // isDebugg mode
// Optional argument for set interval in milliseconds for fetching flags
// from service. By default set to 5 min (5 * 60 * 1000).
1000 * 10,
);
Next thing u do, is start grpc client in async infinite loop, it will be refetching ur flags values every 5 minutes.
try {
await featureClient.start();
} catch(e) {
console.log('FF client failed to start:', e);
}
NOTE! In rare cases it can fail on start (due grpc server hangout or networks issues), then u should relaunch ur app.
In ur controllers, or somewhere when ur need ur features to work properly,
call getFlags
, and provide there context = {}
. Ctx is the object with Variable
as a key,
and a value u want checks to depend on.
import { getFlags } from '@evo/featureflags-client';
// ready to use object with proceeded checks
const flags = getFlags({ username: 'Petro' });
if (flags.TEST) doSomeThing();
Left to implement
There several features, that exists in python flags.lib , that u are free to extend:
- StatsController - Accumulates interval/flag/requests count
- Tracer - Accumulates request/flag/values