From 3f4ea958c7ea35e4952459acdc31b849988612ec Mon Sep 17 00:00:00 2001 From: Alexis Georges Date: Mon, 13 Aug 2018 08:04:33 -0700 Subject: [PATCH 01/10] document promise polyfill and make all polyfill sections consistent --- README.md | 53 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 94fd592c..1cc3ec8d 100644 --- a/README.md +++ b/README.md @@ -28,17 +28,22 @@ when `client.on('change')` is called. ### EventSource polyfill If you need streaming support, and you wish to support browsers that do not -support `EventSource` natively, you can install a polyfill, such as +support `EventSource` natively, you can install a polyfill such as [EventSource](https://github.com/Yaffle/EventSource). -You can load the polyfill via a script tag in the `` before the script -where you initialize `LDClient`: +#### CDN - +You can load the polyfill via a script tag in the `` before the script where you initialize `LDClient`: -If you use [webpack](https://webpack.github.io/) or -[browserify](http://browserify.org/), make sure to require the polyfill before -`LDClient` is initialized. + + +#### NPM or Yarn + + npm install event-source-polyfill@0.0.12 + +Then import it before the module that initializes the LaunchDarkly client: + + require('event-source-polyfill'); ### Document.querySelectorAll() polyfill @@ -46,11 +51,39 @@ If you need to run A/B tests on IE7 or IE8 you will need to install a polyfill for `document.querySelector()` such as [polyfill-queryselector](https://github.com/cobbdb/polyfill-queryselector). -You can load the polyfll via a script tag in the ``: +#### CDN + +You can load the polyfill via a script tag in the `` before the script where you initialize `LDClient`: + + + +#### NPM or Yarn + + npm install polyfill-queryselector@1.0.2 + +Then import it before the module that initializes the LaunchDarkly client: + + require('polyfill-queryselector'); + +### Promise polyfill + +The newer versions of the use `Promise`. If you need to support older browsers, you will +need to install a polyfill for it, such as [es6-promise](https://github.com/stefanpenner/es6-promise). + +#### CDN + +You can load the polyfill via a script tag in the `` before the script where you initialize `LDClient`: + + + +#### NPM or Yarn + + npm install es6-promise@4.2.4 + +Then import it before the module that initializes the LaunchDarkly client: - + require('polyfill-queryselector'); -You can also install it with `npm install polyfill-queryselector` or `bower install polyfill-queryselector`. ## Installation From d407bb9bc98105500202bc52d441d70c98ae0886 Mon Sep 17 00:00:00 2001 From: Alexis Georges Date: Tue, 14 Aug 2018 15:41:11 -0700 Subject: [PATCH 02/10] fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1cc3ec8d..e2214596 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ You can load the polyfill via a script tag in the `` before the script whe Then import it before the module that initializes the LaunchDarkly client: - require('polyfill-queryselector'); + require('es6-promise/auto'); ## Installation From c9339ed5f30ec2645393c7f44da6d8641c6efb4c Mon Sep 17 00:00:00 2001 From: Eli Bishop Date: Tue, 14 Aug 2018 16:21:19 -0700 Subject: [PATCH 03/10] try to fix jdom error by setting jest url property --- jest.config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/jest.config.js b/jest.config.js index b091646b..0412e212 100644 --- a/jest.config.js +++ b/jest.config.js @@ -6,6 +6,7 @@ module.exports = { rootDir: 'src', setupFiles: ['jest-localstorage-mock', './jest.setup.js'], testMatch: ['**/__tests__/**/*-test.js'], + testURL: 'http://localhost', transform: { '^.+\\.js$': 'babel-jest', }, From 96a171e60f22cc98db4466aa4427fea48013922d Mon Sep 17 00:00:00 2001 From: Eli Bishop Date: Tue, 14 Aug 2018 16:26:14 -0700 Subject: [PATCH 04/10] bump jest version --- jest.config.js | 1 - package.json | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/jest.config.js b/jest.config.js index 0412e212..b091646b 100644 --- a/jest.config.js +++ b/jest.config.js @@ -6,7 +6,6 @@ module.exports = { rootDir: 'src', setupFiles: ['jest-localstorage-mock', './jest.setup.js'], testMatch: ['**/__tests__/**/*-test.js'], - testURL: 'http://localhost', transform: { '^.+\\.js$': 'babel-jest', }, diff --git a/package.json b/package.json index 32aa5f9c..05bf6956 100755 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "eslint-plugin-babel": "5.0.0", "eslint-plugin-prettier": "2.6.0", "eventsourcemock": "1.1.0", - "jest": "22.4.3", + "jest": "23.5.0", "jest-junit": "3.6.0", "jest-localstorage-mock": "2.2.0", "prettier": "1.11.1", From 8b23214db8f8ed31267045fe3e3f3964ae96ff62 Mon Sep 17 00:00:00 2001 From: Eli Bishop Date: Tue, 14 Aug 2018 16:31:07 -0700 Subject: [PATCH 05/10] require earlier version of jsdom to avoid problem with mocking localStorage --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 05bf6956..9559c415 100755 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "jest": "23.5.0", "jest-junit": "3.6.0", "jest-localstorage-mock": "2.2.0", + "jsdom": "11.11.0", "prettier": "1.11.1", "readline-sync": "1.4.9", "rimraf": "2.6.2", From 779bcc44b1a7f3d4f6c808facf51043bfa5b8a46 Mon Sep 17 00:00:00 2001 From: Eli Bishop Date: Tue, 14 Aug 2018 16:33:47 -0700 Subject: [PATCH 06/10] undo jest version change --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9559c415..eecb08a8 100755 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "eslint-plugin-babel": "5.0.0", "eslint-plugin-prettier": "2.6.0", "eventsourcemock": "1.1.0", - "jest": "23.5.0", + "jest": "22.4.3", "jest-junit": "3.6.0", "jest-localstorage-mock": "2.2.0", "jsdom": "11.11.0", From bf35d1b02927a14dc1d3ea0f994146653723dc14 Mon Sep 17 00:00:00 2001 From: Eli Bishop Date: Tue, 14 Aug 2018 16:55:28 -0700 Subject: [PATCH 07/10] change identify() result back to a key-value map like it used to be --- src/__tests__/LDClient-test.js | 30 +++++++++++++++++++++++++++++- src/index.js | 2 +- src/utils.js | 13 +++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/__tests__/LDClient-test.js b/src/__tests__/LDClient-test.js index 8dcfe275..94f84ed2 100644 --- a/src/__tests__/LDClient-test.js +++ b/src/__tests__/LDClient-test.js @@ -896,6 +896,34 @@ describe('LDClient', () => { }); }); + it('updates flag values when the user changes', done => { + const user2 = { key: 'user2' }; + const client = LDClient.initialize(envName, user, { bootstrap: {} }); + + client.on('ready', () => { + client.identify(user2, null, () => { + expect(client.variation('enable-foo')).toEqual(true); + done(); + }); + + getLastRequest().respond(200, { 'Content-Type': 'application/json' }, '{"enable-foo": {"value": true}}'); + }); + }); + + it('yields map of flag values as the result of identify()', done => { + const user2 = { key: 'user2' }; + const client = LDClient.initialize(envName, user, { bootstrap: {} }); + + client.on('ready', () => { + client.identify(user2, null).then(flagMap => { + expect(flagMap).toEqual({ "enable-foo": true }); + done(); + }); + + getLastRequest().respond(200, { 'Content-Type': 'application/json' }, '{"enable-foo": {"value": true}}'); + }); + }); + it('reconnects to stream if the user changes', done => { const user2 = { key: 'user2' }; const encodedUser2 = 'eyJrZXkiOiJ1c2VyMiJ9'; @@ -911,7 +939,7 @@ describe('LDClient', () => { done(); }); - getLastRequest().respond(200, { 'Content-Type': 'application/json' }, '{"enable-foo": true}'); + getLastRequest().respond(200, { 'Content-Type': 'application/json' }, '{"enable-foo": {"value": true}}'); }); }); diff --git a/src/index.js b/src/index.js index 4d1ec0c3..131365ad 100644 --- a/src/index.js +++ b/src/index.js @@ -140,7 +140,7 @@ export function initialize(env, user, options = {}) { if (settings) { updateSettings(settings); } - resolve(settings); + resolve(utils.transformVersionedValuesToValues(settings)); if (subscribedToChangeEvents) { connectStream(); } diff --git a/src/utils.js b/src/utils.js index fb0e8385..c9edeaba 100644 --- a/src/utils.js +++ b/src/utils.js @@ -76,6 +76,19 @@ export function transformValuesToVersionedValues(flags) { return ret; } +/** + * Converts the internal flag state map to a simple map of flag keys to values. + */ +export function transformVersionedValuesToValues(flagsState) { + const ret = {}; + for (const key in flagsState) { + if (flagsState.hasOwnProperty(key)) { + ret[key] = flagsState[key].value; + } + } + return ret; +} + /** * Returns an array of event groups each of which can be safely URL-encoded * without hitting the safe maximum URL length of certain browsers. From 29c3df3c5de2f64ea1e8087838c1f4b1555d096d Mon Sep 17 00:00:00 2001 From: Eli Bishop Date: Tue, 14 Aug 2018 16:58:43 -0700 Subject: [PATCH 08/10] linter --- src/__tests__/LDClient-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/__tests__/LDClient-test.js b/src/__tests__/LDClient-test.js index 94f84ed2..5ad7796b 100644 --- a/src/__tests__/LDClient-test.js +++ b/src/__tests__/LDClient-test.js @@ -916,7 +916,7 @@ describe('LDClient', () => { client.on('ready', () => { client.identify(user2, null).then(flagMap => { - expect(flagMap).toEqual({ "enable-foo": true }); + expect(flagMap).toEqual({ 'enable-foo': true }); done(); }); From f91caac202fc5647e6b202521ceff3e3a384faf9 Mon Sep 17 00:00:00 2001 From: Eli Bishop Date: Tue, 14 Aug 2018 17:12:09 -0700 Subject: [PATCH 09/10] version 2.4.1 --- CHANGELOG.md | 5 +++++ package-lock.json | 2 +- package.json | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b37043b..8694cad2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ All notable changes to the LaunchDarkly client-side JavaScript SDK will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org). +## [2.4.1] - 2018-08-14 +### Fixed: +- The result value of `identify()` (provided by either a promise or a callback, once the flag values for the new user have been retrieved) used to be a simple map of flag keys to values, until it was accidentally changed to an internal data structure in version 2.0.0. It is now a map of flag keys to values again, consistent with what is returned by `allFlags()`. +- Added TypeScript definitions for the result values of `identify()`. (Thanks, [1999](https://github.com/launchdarkly/js-client/pull/102)!) + ## [2.4.0] - 2018-07-12 ### Added: - Named exports for the `initialize` method and `version` number exports. diff --git a/package-lock.json b/package-lock.json index 7ae9e1b7..14e87b43 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "ldclient-js", - "version": "2.1.2", + "version": "2.4.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index eecb08a8..2328a91b 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ldclient-js", - "version": "2.4.0", + "version": "2.4.1", "description": "LaunchDarkly SDK for JavaScript", "author": "LaunchDarkly ", "license": "Apache-2.0", From 4a292a1a8f46a8dbf9189e07a638ef4db25282d7 Mon Sep 17 00:00:00 2001 From: Eli Bishop Date: Tue, 14 Aug 2018 17:15:46 -0700 Subject: [PATCH 10/10] add changelog item --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8694cad2..6f58add8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org). ### Fixed: - The result value of `identify()` (provided by either a promise or a callback, once the flag values for the new user have been retrieved) used to be a simple map of flag keys to values, until it was accidentally changed to an internal data structure in version 2.0.0. It is now a map of flag keys to values again, consistent with what is returned by `allFlags()`. - Added TypeScript definitions for the result values of `identify()`. (Thanks, [1999](https://github.com/launchdarkly/js-client/pull/102)!) +- Documented all optional compatibility polyfills in `README.md`. ## [2.4.0] - 2018-07-12 ### Added: