import { BASE_URL } from '@/api/buster_rest/config'; import type { OrganizationUser, BusterUserResponse } from '@/api/asset_interfaces/users'; import { mainApi } from '../instances'; import { serverFetch } from '../../createServerInstance'; export const getMyUserInfo = async (): Promise => { return mainApi.get(`/users`).then((response) => response.data); }; export const getMyUserInfo_server = async ({ jwtToken }: { jwtToken: string | undefined; }): Promise => { if (!jwtToken) { try { //If Anonymous user, it will fail, so we catch the error and return undefined const res = await serverFetch(`/users`, { method: 'GET' }); return res; } catch (error) { return undefined; } } //use fetch instead of serverFetch because... return fetch(`${BASE_URL}/users`, { method: 'GET', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${jwtToken}` } }) .then((response) => { if (!response.ok) { return undefined; } return response.json(); }) .catch((error) => { return undefined; }); }; export const getUser = async ({ userId }: { userId: string }) => { return mainApi.get(`/users/${userId}`).then((response) => response.data); }; export const getUser_server = async ({ userId }: { userId: string }) => { return serverFetch(`/users/${userId}`); }; export const updateOrganizationUser = async ({ userId, ...params }: { userId: string; name?: string; role?: OrganizationUser['role']; }) => { return mainApi .put(`/users/${userId}`, params) .then((response) => response.data); }; export const inviteUser = async ({ emails, team_ids }: { emails: string[]; team_ids?: string[]; }) => { return mainApi.post(`/users/invite`, { emails, team_ids }); };