2016-09-16 13:55:46 +00:00
|
|
|
import Base from './base';
|
2016-09-13 19:50:37 +00:00
|
|
|
import endpoints from './endpoints';
|
|
|
|
|
2016-09-16 13:55:46 +00:00
|
|
|
class Kolide extends Base {
|
2016-09-19 23:43:35 +00:00
|
|
|
forgotPassword ({ email }) {
|
|
|
|
const { FORGOT_PASSWORD } = endpoints;
|
|
|
|
const forgotPasswordEndpoint = this.baseURL + FORGOT_PASSWORD;
|
|
|
|
|
|
|
|
return this.post(forgotPasswordEndpoint, JSON.stringify({ email }));
|
|
|
|
}
|
|
|
|
|
2016-10-05 23:43:37 +00:00
|
|
|
getConfig = () => {
|
|
|
|
const { CONFIG } = endpoints;
|
|
|
|
|
|
|
|
return this.authenticatedGet(this.endpoint(CONFIG))
|
|
|
|
.then(response => { return response.org_info; });
|
|
|
|
}
|
|
|
|
|
2016-10-14 21:08:57 +00:00
|
|
|
getInvites = () => {
|
|
|
|
const { INVITES } = endpoints;
|
|
|
|
|
|
|
|
return this.authenticatedGet(this.endpoint(INVITES))
|
|
|
|
.then(response => { return response.invites; });
|
|
|
|
}
|
|
|
|
|
2016-10-03 17:54:22 +00:00
|
|
|
getUsers = () => {
|
|
|
|
const { USERS } = endpoints;
|
|
|
|
|
|
|
|
return this.authenticatedGet(this.endpoint(USERS))
|
|
|
|
.then(response => { return response.users; });
|
|
|
|
}
|
|
|
|
|
2016-10-11 15:34:52 +00:00
|
|
|
inviteUser = (formData) => {
|
|
|
|
const { INVITES } = endpoints;
|
|
|
|
|
2016-10-14 21:08:57 +00:00
|
|
|
return this.authenticatedPost(this.endpoint(INVITES), JSON.stringify(formData))
|
|
|
|
.then(response => { return response.invite; });
|
2016-10-11 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2016-09-13 19:50:37 +00:00
|
|
|
loginUser ({ username, password }) {
|
|
|
|
const { LOGIN } = endpoints;
|
2016-09-16 13:55:46 +00:00
|
|
|
const loginEndpoint = this.baseURL + LOGIN;
|
2016-09-13 19:50:37 +00:00
|
|
|
|
2016-09-16 13:55:46 +00:00
|
|
|
return this.post(loginEndpoint, JSON.stringify({ username, password }));
|
|
|
|
}
|
2016-09-13 19:50:37 +00:00
|
|
|
|
2016-09-19 23:43:35 +00:00
|
|
|
logout () {
|
|
|
|
const { LOGOUT } = endpoints;
|
|
|
|
const logoutEndpoint = this.baseURL + LOGOUT;
|
2016-09-13 19:50:37 +00:00
|
|
|
|
2016-09-19 23:43:35 +00:00
|
|
|
return this.authenticatedPost(logoutEndpoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
me () {
|
|
|
|
const { ME } = endpoints;
|
|
|
|
const meEndpoint = this.baseURL + ME;
|
|
|
|
|
|
|
|
return this.authenticatedGet(meEndpoint);
|
2016-09-13 19:50:37 +00:00
|
|
|
}
|
2016-09-19 15:35:38 +00:00
|
|
|
|
|
|
|
resetPassword (formData) {
|
|
|
|
const { RESET_PASSWORD } = endpoints;
|
|
|
|
const resetPasswordEndpoint = this.baseURL + RESET_PASSWORD;
|
|
|
|
|
|
|
|
return this.post(resetPasswordEndpoint, JSON.stringify(formData));
|
|
|
|
}
|
2016-10-03 17:54:22 +00:00
|
|
|
|
2016-10-14 21:08:57 +00:00
|
|
|
revokeInvite = ({ entityID }) => {
|
|
|
|
const { INVITES } = endpoints;
|
|
|
|
const endpoint = `${this.endpoint(INVITES)}/${entityID}`;
|
|
|
|
|
|
|
|
return this.authenticatedDelete(endpoint);
|
|
|
|
}
|
|
|
|
|
2016-10-03 17:54:22 +00:00
|
|
|
updateUser = (user, formData) => {
|
|
|
|
const { USERS } = endpoints;
|
|
|
|
const updateUserEndpoint = `${this.baseURL}${USERS}/${user.id}`;
|
|
|
|
|
2016-10-11 16:22:11 +00:00
|
|
|
return this.authenticatedPatch(updateUserEndpoint, JSON.stringify(formData))
|
|
|
|
.then(response => { return response.user; });
|
2016-10-03 17:54:22 +00:00
|
|
|
}
|
2016-09-13 19:50:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default new Kolide();
|