@evo/featureflags-client
TypeScript icon, indicating that this package has built-in type declarations

1.6.0 • Public • Published

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 on deploy 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

Readme

Keywords

none

Package Sidebar

Install

npm i @evo/featureflags-client

Weekly Downloads

448

Version

1.6.0

License

ISC

Unpacked Size

578 kB

Total Files

34

Last publish

Collaborators

  • stoyanovk
  • lequan
  • zemlanin
  • alexander
  • seedofjoy
  • 041616
  • docccdev
  • orhideous
  • tailhook
  • hunson.abadeer
  • mark_tven
  • amostovenko
  • sadkovoy
  • himiranov
  • evo-kazymyrov