@financial-times/n-flags-client v15.0.1
n-flags-client
Provides a mechanism for us to toggle features and services, inspired by Martin Fowler’s feature toggles. Flags can be overridden using an x-flags
header or next-flags
cookie. Also sends reports to Sentry of any expired flags still in use.
Usage
Client side
Flags are exposed via flags.html, which are consumed by n-ui.
Server side
Any apps using n-express with the withFlags
option turned on will get flags added to res.locals.flags
, via the middleware it consumes in this repo. By default it will request from FT.com’s set of platinum flag services, but can be overridden using the setUrls([arr])
method.
The default behaviour when NODE_ENV=production
is set is to get overrides from the HTTP header that Fastly sets. For apps that are not routed via Fastly, you can set OVERRIDE_FLAGS_FROM_COOKIE=true
to get overrides from a cookie.
API
init(options)
Initialises the flag client. Options:
timeout
: A length of time (ms) to wait for response from the flag server default 3000interval
: An interval (ms) between attempts to fetch fresh flag data default 30000retry
: The number of times to retry if a fetch fails default 1filter
: a function, returning true or false, that is passed the raw data object fora flag and is used to decide whether or not it should be discarded from the flag set for the current app
Returns a promise that is resolved when flags have been successfully fetched at least once (or that resolves immediately if none of the above options are passed).
getArray()
Returns a simplified array of flags similar to that retrieved from the flags API, but lacking expiry date information.
get(name)
Returns the current state of a flag (or false if the flag doesn’t exist). If no name is provided, it returns a hash of all current flag objects, including information on expiry dates.
getModel(name)
Returns a flag model for the named flag.
11 days ago
3 months ago
4 months ago
10 months ago
9 months ago
8 months ago
11 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago