diff --git a/README.md b/README.md index e9810ea8..92dfef87 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,8 @@ The `initialize()` function returns a promise that resolves when the Launch Dark The user `key` is the only required attribute, see the [Launch Darkly documentation](https://docs.launchdarkly.com/docs/js-sdk-reference#section-users) for the other attributes you can provide. +The `initialize()` function accepts a second parameter, an object, which is **optional**. It allows to you configure the Launch Darkly client, see the [Launch Darkly documentation](https://docs.launchdarkly.com/sdk/client-side/javascript#customizing-your-client) to learn more about available options and default values. + ```js // /app/application/route.js @@ -123,7 +125,12 @@ export default Route.extend({ anonymous: true }; - return this.launchDarkly.initialize(user); + let options = { + sendEvents: false, // default is true, see https://docs.launchdarkly.com/sdk/client-side/javascript#analytics-events + hash: "SERVER_GENERATED_HASH", // see https://docs.launchdarkly.com/sdk/client-side/javascript#secure-mode + }; + + return this.launchDarkly.initialize(user, options); } }); ``` diff --git a/addon/services/launch-darkly-client-remote.js b/addon/services/launch-darkly-client-remote.js index 19c9e9bd..9d3e4e51 100644 --- a/addon/services/launch-darkly-client-remote.js +++ b/addon/services/launch-darkly-client-remote.js @@ -16,13 +16,16 @@ export default Service.extend(Evented, { this._super(...arguments); }, - initialize(user = {}) { + initialize(user = {}, options = {}) { let { clientSideId, streaming = false } = this._config(); - assert('ENV.launchDarkly.clientSideId must be specified in config/environment.js', clientSideId); + if (!clientSideId) { + clientSideId = options.clientSideId; // let this be deferred, maybe an API provided it + delete options.clientSideId; + } if (!clientSideId) { - warn('ENV.launchDarkly.clientSideId not specified. Defaulting all feature flags to "false"', false, { id: 'ember-launch-darkly.client-id-not-specified' }); + warn('ENV.launchDarkly.clientSideId not specified or provided via user hash. Defaulting all feature flags to "false"', false, { id: 'ember-launch-darkly.client-id-not-specified' }); this.set('_client', NullClient); @@ -39,7 +42,7 @@ export default Service.extend(Evented, { return RSVP.resolve(); } - return this._initialize(clientSideId, user, streaming); + return this._initialize(clientSideId, user, streaming, options); }, identify(user) { @@ -60,9 +63,10 @@ export default Service.extend(Evented, { return appConfig.launchDarkly || {}; }, - _initialize(id, user, streamingOptions) { + _initialize(id, user, streamingOptions, options = {}) { return new RSVP.Promise((resolve, reject) => { - let client = initialize(id, user); + + let client = initialize(id, user, options); client.on('ready', () => { this.set('_client', client);