@haelp/teto
Version:
A typescript-based controllable TETR.IO client.
64 lines (63 loc) • 2.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "users", {
enumerable: true,
get: function() {
return users;
}
});
const users = (get, post, __)=>{
/** Checks whethere a user exists */ const exists = async (username)=>{
const res = await get({
token: undefined,
uri: `users/${username}/exists`
});
if (res.success === false) throw new Error(res.error.msg);
return res.exists;
};
/** Resolves a username to a user ID */ const resolve = async (username)=>{
const res = await get({
token: undefined,
uri: `users/${encodeURIComponent(username.trim())}/resolve`
});
if (res.success === false) throw new Error(res.error.msg + ": " + username);
return res._id;
};
return {
/** Checks whether a user exists */ exists,
authenticate: async (username, password)=>{
const res = await post({
token: undefined,
uri: "users/authenticate",
body: {
username,
password,
totp: ""
}
});
if (res.success === false) throw new Error(res.error.msg);
return {
token: res.token,
id: res.userid
};
},
me: async ()=>{
const res = await get({
uri: "users/me"
});
if (res.success === false) throw new Error("Failure loading profile: " + res.error.msg);
return res.user;
},
resolve,
/** Get a user's profile */ get: async (options)=>{
const res = await get({
uri: "users/" + ("username" in options ? await resolve(options.username) : options.id)
});
if (res.success === false) throw new Error("Failure loading profile: " + res.error.msg);
return res.user;
}
};
};
//# sourceMappingURL=users.js.map