UNPKG

@haelp/teto

Version:

A typescript-based controllable TETR.IO client.

54 lines (53 loc) 1.9 kB
export 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