Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions bullet-train-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
};
}
Expand All @@ -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
Expand All @@ -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 }) => {
Expand Down Expand Up @@ -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 }) => {
Expand Down Expand Up @@ -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 });
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down Expand Up @@ -31,6 +31,10 @@
{
"name": "Luke Fanning",
"email": "luke@solidstategroup.com"
},
{
"name": "Matt Elwell",
"email": "matthew.elwell@solidstategroup.com"
}
],
"license": "MIT",
Expand Down