This addon includes a service which wraps a ConfigCat client and aims at easing any feature flagging in your applications.
- Ember.js v3.24 or above
- Ember CLI v3.24 or above
- Node.js v12 or above
ember install ember-config-cat
# environment.js
module.exports = function (environment) {
let ENV = {
emberConfigCat: {
// your options goes here
}
};
};
Option | Default | Description | Links |
---|---|---|---|
mode |
'auto' |
Polling mode: 'auto' /'lazy' /'manual' |
π |
local |
false |
Enabling local mode: will only use default flag values | - |
flags |
- | Default values for feature-flags | - |
sdkKey |
β | Your SDK Key | π |
requestTimeoutMs |
30000 |
Amount of time the SDK waits before returning cached values | π |
maxInitWaitTimeSeconds |
5 |
Maximum waiting time between client init and config fetch | π |
pollIntervalSeconds |
60 |
Polling interval | π |
cacheTimeToLiveSeconds |
60 |
Cache TTL | π |
dataGovernance |
0 (Global) |
Determine the CDN location of the data: 0 for Global / 1 for EuOnly |
π |
logLevel |
- | Set a custom log level | π |
requestTimeoutMs
anddataGovernance
are common polling options to the three available modes- All default values except
mode
,local
andautoStart
are defined in the ConfigCat SDK - You may define either
local
orsdkKey
but the addon will fallback tolocal
mode if nosdkKey
is provided.
If your app is using ember-cli-content-security-policy, you may need to add this into environment.js
to allow ConfigCat requests.
module.exports = function (environment) {
let ENV = {
contentSecurityPolicy: {
'connect-src': ['https://cdn-global.configcat.com'],
},
};
};
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
export default class WhateverRoute extends Route {
@service configCat;
beforeModel() {
return this.configCat.initClient();
}
}
A ConfigCat user object is made of four properties (identifier, email, country and custom): structure
Calling .identifyUser()
will initialize the client if needed.
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
export default class WhateverRoute extends Route {
@service configCat;
async model() {
const user = this.authenticate();
await this.configCat.identifyUser({
identifier: user.id,
email: user.email,
});
}
}
import Component from '@glimmer/component';
import { inject as service } from '@ember/service';
export default class WhateverComponent extends Component {
@service configCat;
get isEnabled() {
return this.configCat.flags.isAwesomeFeatureEnabled;
}
}
Name | Parameters | Description |
---|---|---|
is-flag-enabled |
key | Checks if the flag is enabled |
get-flag-value |
key | Gets the current flag value |
has-flag-value |
key, value | Compares the current flag value against a provided parameters |
import Component from '@glimmer/component';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
export default class WhateverComponent extends Component {
@service configCat;
@action onClear() {
this.configCat.dispose();
}
}
Name | Type | Description |
---|---|---|
flags |
tracked property | Returns available feature-flags and values |
identifyUser |
method | Identifies user and update feature-flags values |
update |
method | Updates feature-flags values |
dispose |
method | Releases everything related to the ConfigCat client |
ember-config-cat
comes with a couple of test-helpers:
// ...
import { setupConfigCat, type TestContext } from 'ember-config-cat/test-support';
module('...', function (hooks) {
// ...
setupConfigCat(hooks);
test('...', async function (this: TestContext, assert) {
// configuring one flag
this.withFlag('featureA', true);
// configuring several flags
this.withFlags({ featureB: true, pricing: 10 });
// ...
});
});
See the Contributing guide for details.
We draw our inspiration from the ember-launch-darkly
addon
- ConfigCat API
- Using ConfigCat in JavaScript Documentation - SDK
- Browser compatibility
This project is licensed under the MIT License.