diff --git a/bullet-train-core.js b/bullet-train-core.js index 12545bf..76674ab 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()); }; } @@ -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 @@ -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..77d5782 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bullet-train-nodejs", - "version": "0.1.3", + "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": { @@ -31,6 +31,10 @@ { "name": "Luke Fanning", "email": "luke@solidstategroup.com" + }, + { + "name": "Matt Elwell", + "email": "matthew.elwell@solidstategroup.com" } ], "license": "MIT",