From 011b6073924edbaf4d8b40bd8af94aa7962f34e6 Mon Sep 17 00:00:00 2001 From: Matthew Elwell Date: Thu, 6 Jun 2019 16:19:39 +0100 Subject: [PATCH 1/3] update to use new api endpoints --- bullet-train-core.js | 16 ++++++++++++---- package.json | 6 +++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/bullet-train-core.js b/bullet-train-core.js index 12545bf..c4c970f 100644 --- a/bullet-train-core.js +++ b/bullet-train-core.js @@ -27,7 +27,7 @@ const BulletTrain = class { if (method !== "GET") { options.headers['Content-Type'] = 'application/json; charset=utf-8'; } - return fetch(url + '?format=json', options) + return fetch(url, options) .then(res => res.json()); }; } @@ -52,7 +52,7 @@ const BulletTrain = class { return flags; }; - return this.getJSON(api + 'flags/' + identity) + return this.getJSON(api + 'identities/?identifier=' + identity) .then(res => { return handleResponse(res); }).catch(({ message }) => { @@ -85,7 +85,7 @@ const BulletTrain = class { return { flags, traits }; }; - return this.getJSON(api + 'identities/' + identity + '/') + return this.getJSON(api + 'identities/?identifier=' + identity) .then(res => { return handleResponse(res); }).catch(({ message }) => { @@ -214,7 +214,15 @@ const BulletTrain = class { return Promise.reject(`setTrait() called without a ${!identity ? 'user identity' : 'trait key'}`); } - return this.getJSON(`${api}identities/${identity}/traits/${encodeURIComponent(key)}`, 'POST', JSON.stringify({ trait_value: value })) + const body = { + "identity": { + "identifier": identity + }, + "trait_key": key, + "trait_value": trait_value + } + + return this.getJSON(`${api}traits/`, 'POST', JSON.stringify(body)) .then(() => this.getUserIdentity(identity)) .catch(({ message }) => { onError && onError({ message }); diff --git a/package.json b/package.json index 9bbeb5c..70dc718 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bullet-train-nodejs", - "version": "0.1.3", + "version": "0.1.4", "description": "Bullet Train lets you manage features flags and remote config across web, mobile and server side applications. Deliver true Continuous Integration. Get builds out faster. Control who has access to new features.", "main": "index.js", "repository": { @@ -31,6 +31,10 @@ { "name": "Luke Fanning", "email": "luke@solidstategroup.com" + }, + { + "name": "Matt Elwell", + "email": "matthew.elwell@solidstategroup.com" } ], "license": "MIT", From ba6b02745dd0bc91698c8e4e363556a1f4e992d7 Mon Sep 17 00:00:00 2001 From: Matthew Elwell Date: Thu, 6 Jun 2019 16:21:53 +0100 Subject: [PATCH 2/3] Update to v1.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 70dc718..77d5782 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bullet-train-nodejs", - "version": "0.1.4", + "version": "1.0.0", "description": "Bullet Train lets you manage features flags and remote config across web, mobile and server side applications. Deliver true Continuous Integration. Get builds out faster. Control who has access to new features.", "main": "index.js", "repository": { From 06f015492304639c99fd5c5ca545a98e2106d7a1 Mon Sep 17 00:00:00 2001 From: Matthew Elwell Date: Fri, 7 Jun 2019 10:30:32 +0100 Subject: [PATCH 3/3] Fix issue with getFlagsForUser method --- bullet-train-core.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bullet-train-core.js b/bullet-train-core.js index c4c970f..76674ab 100644 --- a/bullet-train-core.js +++ b/bullet-train-core.js @@ -43,7 +43,7 @@ const BulletTrain = class { const handleResponse = (res) => { // Handle server response let flags = {}; - res.forEach(feature => { + res.flags.forEach(feature => { flags[feature.feature.name.toLowerCase().replace(/ /g, '_')] = { enabled: feature.enabled, value: feature.feature_state_value