0.3.0 • Published 3 years ago
airflags v0.3.0
Airflags
*This project is in early-development stage. All feedbacks and contributions are welcome!
Features
- Toggle flags via Airtable
- Config and load once, access flags everywhere
- Support both Node.js and browser
- Written in TypeScript
Why Airtable?
- Having a web UI
- API ready
- Free plan should be more than enough for feature flags
Installation
With NPM
npm i airflags
or Yarn
yarn add airflags
Setup Airtable
Create a table with following fields (columns)
- Name as a first field with text type (representing flag name)
- Environment fields as a Checkbox type (representing flag state in each environment)
Flags can be toggled on/off by clicking the checkbox.
Usage
import Airflags from 'airflags';
// Config Airflags
Airflags.config({
environment: 'Development',
baseId: 'AIRTABLE_BASE_ID',
tableName: 'AIRTABLE_TABLE_NAME',
apiKey: 'AIRTABLE_API_KEY',
});
// Load flags from Airtable (asyncronous)
await Airflags.load();
// Get loaded feature flags
const flags = Airflags.getFlags();
Config object
- environment: The corresponded environment field name in Airtable.
- baseId, tableName and apiKey are for Airtable API. More info can be found on Airtable API doc
Example of getFlags return value
{
featureA: true,
featureB: false
}
Add type casting (optional)
type Feature = 'featureA' | 'featureB';
type FeatureFlags = Record<Feature, boolean>;
const flags: FeatureFlags = Airflags.getFlags();
Airflags is a singleton
Airflags
is a class with static methods and properties.- Meaning that
config()
andload()
methods are required to run atleast once. ThengetFlags()
can be called anywhere. - However,
config()
andload()
methods can be called anytime after when you want to change the config or reload the flags.