Javascript-SDK - 3.2.0
### New Features
- Added support for automatic datafile management ([#261](https://github.com/optimizely/javascript-sdk/pull/261)), ([#266](https://github.com/optimizely/javascript-sdk/pull/266)), ([#267](https://github.com/optimizely/javascript-sdk/pull/267)), ([#268](https://github.com/optimizely/javascript-sdk/pull/268)), ([#270](https://github.com/optimizely/javascript-sdk/pull/270)), ([#272](https://github.com/optimizely/javascript-sdk/pull/272))
- To use automatic datafile management, include `sdkKey` as a string property in the options object you pass to `createInstance`.
- When sdkKey is provided, the SDK instance will download the datafile associated with that sdkKey immediately upon construction. When the download completes, the SDK instance will update itself to use the downloaded datafile.
- Use the `onReady` method to wait until the download is complete and the SDK is ready to use.
- Customize datafile management behavior by passing a `datafileOptions` object within the options you pass to `createInstance`.
- Enable automatic updates by passing `autoUpdate: true`. Periodically (on the provided update interval), the SDK instance will download the datafile and update itself. Use this to ensure that the SDK instance is using a fresh datafile reflecting changes recently made to your experiment or feature configuration.
- Add a notification listener for the `OPTIMIZELY_CONFIG_UPDATE` notification type to be notified when an instance updates its Optimizely config after obtaining a new datafile.
- Stop active downloads and cancel recurring downloads by calling the `close` method
#### Create an instance with datafile management enabled
```js
const optimizely = require('@optimizely/optimizely-sdk');
const optimizelyClientInstance = optimizely.createInstance({
sdkKey: '12345', // Provide the sdkKey of your desired environment here
});
```
#### Use `onReady` to wait until optimizelyClientInstance has a datafile
```js
const optimizely = require('@optimizely/optimizely-sdk');
const optimizelyClientInstance = optimizely.createInstance({
sdkKey: '12345',
});
optimizelyClientInstance.onReady().then(() => {
// optimizelyClientInstance is ready to use, with datafile downloaded from the Optimizely CDN
});
```
#### Enable automatic updates, add notification listener for OPTIMIZELY_CONFIG_UPDATE notification type, and stop automatic updates
```js
const optimizely = require('@optimizely/optimizely-sdk');
const optimizelyClientInstance = optimizely.createInstance({
sdkKey: '12345',
datafileOptions: {
autoUpdate: true,
updateInterval: 600000 // 10 minutes in milliseconds
},
});
optimizelyClientInstance.notificationCenter.addNotificationListener(
optimizely.enums.NOTIFICATION_TYPES.OPTIMIZELY_CONFIG_UPDATE,
() => {
// optimizelyClientInstance has updated its Optimizely config
},
);
// Stop automatic updates - optimizelyClientInstance will use whatever datafile it currently has from now on
optimizelyClientInstance.close();
```
### Changed
- Forced variation logic has been moved from the project config module to the decision service. Prefixes for forced-variation-related log messages will reflect this change ([#261](https://github.com/optimizely/javascript-sdk/pull/261)).
- Update TypeScript definitions to account for new methods (`onReady`, `close`) and new properties on object accepted by createInstance (`datafileOptions`, `sdkKey`), ([#263](https://github.com/optimizely/javascript-sdk/pull/263)), ([#278](https://github.com/optimizely/javascript-sdk/pull/278))
- Allow react-sdk to be passed in as `clientEngine` ([#279](https://github.com/optimizely/javascript-sdk/pull/279))
### Bug Fixes:
- Add logging message for `optimizely.track()` ([#281](https://github.com/optimizely/javascript-sdk/pull/281))
https://github.com/optimizely/javascript-sdk/releases/tag/v3.2.0
Article is closed for comments.