// @flow import request from 'services/request'; export type UserResponse = { elyProfileLink: string, email: string, hasMojangUsernameCollision: bool, id: number, isActive: bool, isOtpEnabled: bool, lang: string, passwordChangedAt: number, // timestamp registeredAt: number, // timestamp shouldAcceptRules: bool, username: string, uuid: string, }; export function getInfo(id: number, options: { token?: ?string } = {}): Promise { return request.get(`/api/v1/accounts/${id}`, {}, { token: options.token, }); } export function changePassword({ password = '', newPassword = '', newRePassword = '', logoutAll = true, }: { password?: string, newPassword?: string, newRePassword?: string, logoutAll?: bool, }) { return request.post('/api/accounts/change-password', { password, newPassword, newRePassword, logoutAll, }); } export function acceptRules() { return request.post('/api/accounts/accept-rules'); } export function changeUsername({ username = '', password = '', }: { username?: string, password?: string, }) { return request.post('/api/accounts/change-username', { username, password, }); } export function changeLang(lang: string) { return request.post('/api/accounts/change-lang', { lang, }); } export function requestEmailChange({ password = '' }: { password?: string }) { return request.post('/api/accounts/change-email/initialize', { password, }); } export function setNewEmail({ email = '', key = '', }: { email?: string, key?: string, }) { return request.post('/api/accounts/change-email/submit-new-email', { email, key, }); } export function confirmNewEmail({ key }: { key: string }) { return request.post('/api/accounts/change-email/confirm-new-email', { key, }); } export default { /** * @param {object} options * @param {object} [options.token] - an optional token to overwrite headers * in middleware and disable token auto-refresh * * @return {Promise} */ current(options: { token?: ?string } = {}): Promise { return getInfo(0, options); }, };