import { getBackendSrv } from '@grafana/runtime'; import { Team, UserDTO, UserOrg, UserSession } from '../../types'; import { ChangePasswordFields, ProfileUpdateFields } from './types'; async function changePassword(payload: ChangePasswordFields): Promise { try { await getBackendSrv().put('/api/user/password', payload); } catch (err) { console.error(err); } } function loadUser(): Promise { return getBackendSrv().get('/api/user'); } function loadTeams(): Promise { return getBackendSrv().get('/api/user/teams'); } function loadOrgs(): Promise { return getBackendSrv().get('/api/user/orgs'); } function loadSessions(): Promise { return getBackendSrv().get('/api/user/auth-tokens'); } async function revokeUserSession(tokenId: number): Promise { await getBackendSrv().post('/api/user/revoke-auth-token', { authTokenId: tokenId, }); } async function setUserOrg(org: UserOrg): Promise { await getBackendSrv().post('/api/user/using/' + org.orgId, {}); } async function updateUserProfile(payload: ProfileUpdateFields): Promise { try { await getBackendSrv().put('/api/user', payload); } catch (err) { console.error(err); } } export const api = { changePassword, revokeUserSession, loadUser, loadSessions, loadOrgs, loadTeams, setUserOrg, updateUserProfile, };