buster/apps/web/src/api/buster_rest/users/requests.ts

132 lines
3.4 KiB
TypeScript
Raw Normal View History

2025-07-04 07:14:52 +08:00
import type { ShareAssetType } from '@buster/server-shared/share';
import type { OrganizationUser } from '@buster/server-shared/organization';
2025-07-04 13:56:31 +08:00
import { BASE_URL } from '../config';
import { serverFetch } from '../../createServerInstance';
Biome linter test (#336) * update files for use with biom * fix prettier formats * minor biome fixes * fix additional files * update linting rules * fix additional linting errors * fix linting errors * update lib * run check in the lib direcotyr * update some linting errors * fix problems * move addtional files to stricter linting * fix imports and linting errors * update some biome settings * fix query parser * quick wins * update files * fix addtional things * fix context files * update additional biome files * fix additional files * biome fixes * fixin files * fix broken * fix additional files and problems * fix biome buster stuff * fix helpers and * stricter linting * fixed * fix missing types * fix linting * remove missing imports * update more biome test stuff * update fixes * update imports * more updates * fix some linting errors * fix broken children as prop errors * lint ci * update lint check * Update package.json * Update next.config.mjs * fix some broken tests * update some tests * chore(versions): bump api to v0.1.16; bump web to v0.1.16; bump cli to v0.1.16 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * Update web-unit-tests.yml * fix some tests * chore(versions): bump api to v0.1.17; bump web to v0.1.17; bump cli to v0.1.17 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * update ignore files * chore(versions): bump api to v0.1.18; bump web to v0.1.18; bump cli to v0.1.18 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * Update web-lint.yml * chore(versions): bump api to v0.1.19; bump web to v0.1.19; bump cli to v0.1.19 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * update boime package settings * chore(versions): bump api to v0.1.20; bump web to v0.1.20; bump cli to v0.1.20 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * save to dropdown bug fixes * update console logs * update chart animation * chore(versions): bump api to v0.1.21; bump web to v0.1.21; bump cli to v0.1.21 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * update build * chore(versions): bump api to v0.1.22; bump web to v0.1.22; bump cli to v0.1.22 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * additinal updates for biome 2 * update imports * chore(versions): bump api to v0.1.23; bump web to v0.1.23; bump cli to v0.1.23 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * final updates * chore(versions): bump api to v0.1.24; bump web to v0.1.24; bump cli to v0.1.24 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * Update dashboard-updates.test.ts * chore(versions): bump api to v0.1.25; bump web to v0.1.25; bump cli to v0.1.25 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * crazy fix * chore(versions): bump api to v0.1.26; bump web to v0.1.26; bump cli to v0.1.26 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * more attempts for stable tests * chore(versions): bump api to v0.1.27; bump web to v0.1.27; bump cli to v0.1.27 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * update tests * split the test off * chore(versions): bump api to v0.1.28; bump web to v0.1.28; bump cli to v0.1.28 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * Update pie-styling-updates.spec.ts * Create web-e2e-tests-optimized.yml * chore(versions): bump api to v0.1.29; bump web to v0.1.29; bump cli to v0.1.29 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * update tests * chore(versions): bump api to v0.1.30; bump web to v0.1.30; bump cli to v0.1.30 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * Update web-e2e-tests-optimized.yml * chore(versions): bump api to v0.1.31; bump web to v0.1.31; bump cli to v0.1.31 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * Update web-e2e-tests-optimized.yml * chore(versions): bump api to v0.1.32; bump web to v0.1.32; bump cli to v0.1.32 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * Update web-e2e-tests-optimized.yml * chore(versions): bump api to v0.1.33; bump web to v0.1.33; bump cli to v0.1.33 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * Update web-e2e-tests-optimized.yml * chore(versions): bump api to v0.1.34; bump web to v0.1.34; bump cli to v0.1.34 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * Update web-e2e-tests-optimized.yml * Update web-e2e-tests-optimized.yml * Revert "Update web-e2e-tests-optimized.yml" This reverts commit dfc9263a2621f1c00dee30e28dbb01a9f8f914ef. * Update web-e2e-tests-optimized.yml * chore(versions): bump api to v0.1.35; bump web to v0.1.35; bump cli to v0.1.35 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * Update web-e2e-tests-optimized.yml * chore(versions): bump api to v0.1.36; bump web to v0.1.36; bump cli to v0.1.36 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2025-05-31 01:16:48 +08:00
import { mainApi } from '../instances';
2025-07-08 05:33:44 +08:00
import type {
UserResponse,
UserFavoriteResponse,
UserListResponse
} from '@buster/server-shared/user';
2025-07-08 05:33:44 +08:00
export const getMyUserInfo = async () => {
return mainApi.get<UserResponse>('/users').then((response) => response.data);
2025-02-15 12:02:25 +08:00
};
export const getMyUserInfo_server = async ({
jwtToken
}: {
jwtToken: string | undefined;
2025-07-08 05:33:44 +08:00
}): Promise<UserResponse | null> => {
if (!jwtToken) {
2025-05-13 23:46:21 +08:00
//If Anonymous user, it will fail, so we catch the error and return undefined
2025-07-08 05:33:44 +08:00
return await serverFetch<UserResponse>('/users', {
2025-05-13 23:46:21 +08:00
method: 'GET'
});
}
//use fetch instead of serverFetch because...
return fetch(`${BASE_URL}/users`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${jwtToken}`
}
2025-05-13 23:46:21 +08:00
}).then(async (response) => {
if (!response.ok) {
const errorData = await response.json().catch(() => null);
throw {
status: response.status,
statusText: response.statusText,
...errorData
};
}
2025-07-08 05:33:44 +08:00
return (await response.json()) as UserResponse;
2025-05-13 23:46:21 +08:00
});
};
export const getUser = async ({ userId }: { userId: string }) => {
return mainApi.get<OrganizationUser>(`/users/${userId}`).then((response) => response.data);
};
export const getUser_server = async ({ userId }: { userId: string }) => {
2025-02-15 12:20:22 +08:00
return serverFetch<OrganizationUser>(`/users/${userId}`);
};
export const updateOrganizationUser = async ({
userId,
...params
}: {
userId: string;
name?: string;
2025-02-18 05:42:24 +08:00
role?: OrganizationUser['role'];
}) => {
return mainApi
.put<OrganizationUser>(`/users/${userId}`, params)
.then((response) => response.data);
};
2025-02-18 06:03:41 +08:00
export const inviteUser = async ({
emails,
team_ids
}: {
emails: string[];
team_ids?: string[];
}) => {
Biome linter test (#336) * update files for use with biom * fix prettier formats * minor biome fixes * fix additional files * update linting rules * fix additional linting errors * fix linting errors * update lib * run check in the lib direcotyr * update some linting errors * fix problems * move addtional files to stricter linting * fix imports and linting errors * update some biome settings * fix query parser * quick wins * update files * fix addtional things * fix context files * update additional biome files * fix additional files * biome fixes * fixin files * fix broken * fix additional files and problems * fix biome buster stuff * fix helpers and * stricter linting * fixed * fix missing types * fix linting * remove missing imports * update more biome test stuff * update fixes * update imports * more updates * fix some linting errors * fix broken children as prop errors * lint ci * update lint check * Update package.json * Update next.config.mjs * fix some broken tests * update some tests * chore(versions): bump api to v0.1.16; bump web to v0.1.16; bump cli to v0.1.16 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * Update web-unit-tests.yml * fix some tests * chore(versions): bump api to v0.1.17; bump web to v0.1.17; bump cli to v0.1.17 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * update ignore files * chore(versions): bump api to v0.1.18; bump web to v0.1.18; bump cli to v0.1.18 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * Update web-lint.yml * chore(versions): bump api to v0.1.19; bump web to v0.1.19; bump cli to v0.1.19 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * update boime package settings * chore(versions): bump api to v0.1.20; bump web to v0.1.20; bump cli to v0.1.20 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * save to dropdown bug fixes * update console logs * update chart animation * chore(versions): bump api to v0.1.21; bump web to v0.1.21; bump cli to v0.1.21 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * update build * chore(versions): bump api to v0.1.22; bump web to v0.1.22; bump cli to v0.1.22 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * additinal updates for biome 2 * update imports * chore(versions): bump api to v0.1.23; bump web to v0.1.23; bump cli to v0.1.23 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * final updates * chore(versions): bump api to v0.1.24; bump web to v0.1.24; bump cli to v0.1.24 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * Update dashboard-updates.test.ts * chore(versions): bump api to v0.1.25; bump web to v0.1.25; bump cli to v0.1.25 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * crazy fix * chore(versions): bump api to v0.1.26; bump web to v0.1.26; bump cli to v0.1.26 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * more attempts for stable tests * chore(versions): bump api to v0.1.27; bump web to v0.1.27; bump cli to v0.1.27 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * update tests * split the test off * chore(versions): bump api to v0.1.28; bump web to v0.1.28; bump cli to v0.1.28 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * Update pie-styling-updates.spec.ts * Create web-e2e-tests-optimized.yml * chore(versions): bump api to v0.1.29; bump web to v0.1.29; bump cli to v0.1.29 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * update tests * chore(versions): bump api to v0.1.30; bump web to v0.1.30; bump cli to v0.1.30 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * Update web-e2e-tests-optimized.yml * chore(versions): bump api to v0.1.31; bump web to v0.1.31; bump cli to v0.1.31 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * Update web-e2e-tests-optimized.yml * chore(versions): bump api to v0.1.32; bump web to v0.1.32; bump cli to v0.1.32 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * Update web-e2e-tests-optimized.yml * chore(versions): bump api to v0.1.33; bump web to v0.1.33; bump cli to v0.1.33 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * Update web-e2e-tests-optimized.yml * chore(versions): bump api to v0.1.34; bump web to v0.1.34; bump cli to v0.1.34 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * Update web-e2e-tests-optimized.yml * Update web-e2e-tests-optimized.yml * Revert "Update web-e2e-tests-optimized.yml" This reverts commit dfc9263a2621f1c00dee30e28dbb01a9f8f914ef. * Update web-e2e-tests-optimized.yml * chore(versions): bump api to v0.1.35; bump web to v0.1.35; bump cli to v0.1.35 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] * Update web-e2e-tests-optimized.yml * chore(versions): bump api to v0.1.36; bump web to v0.1.36; bump cli to v0.1.36 [skip ci] * chore: update tag_info.json with potential release versions [skip ci] --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2025-05-31 01:16:48 +08:00
return mainApi.post<null>('/users/invite', {
2025-02-18 06:03:41 +08:00
emails,
team_ids
});
};
2025-03-11 12:36:25 +08:00
2025-03-14 04:31:54 +08:00
//USER FAVORITES
2025-03-11 12:36:25 +08:00
export const getUserFavorites = async () => {
2025-07-08 05:33:44 +08:00
return mainApi.get<UserFavoriteResponse>('/users/favorites').then((response) => response.data);
2025-03-11 12:36:25 +08:00
};
export const getUserFavorites_server = async () => {
2025-07-08 05:33:44 +08:00
return serverFetch<UserFavoriteResponse>('/users/favorites');
2025-03-11 12:36:25 +08:00
};
2025-04-09 23:54:40 +08:00
export const createUserFavorite = async (
payload: {
id: string;
asset_type: ShareAssetType;
index?: number;
name: string; //just used for the UI for optimistic update
}[]
) => {
2025-03-11 12:36:25 +08:00
return mainApi
2025-07-08 05:33:44 +08:00
.post<UserFavoriteResponse>('/users/favorites', payload)
2025-03-11 12:36:25 +08:00
.then((response) => response.data);
};
2025-04-09 23:54:40 +08:00
export const deleteUserFavorite = async (data: string[]) => {
2025-03-11 12:36:25 +08:00
return mainApi
2025-07-08 05:33:44 +08:00
.delete<UserFavoriteResponse>('/users/favorites', { data })
2025-03-11 12:36:25 +08:00
.then((response) => response.data);
};
2025-03-14 04:31:54 +08:00
export const updateUserFavorites = async (payload: string[]) => {
2025-03-11 12:36:25 +08:00
return mainApi
2025-07-08 05:33:44 +08:00
.put<UserFavoriteResponse>('/users/favorites', payload)
2025-03-11 12:36:25 +08:00
.then((response) => response.data);
};
2025-03-14 04:31:54 +08:00
//USER LIST
2025-03-20 01:41:41 +08:00
export const getUserList = async (payload: {
team_id: string;
page?: number;
page_size?: number;
}) => {
2025-03-11 12:36:25 +08:00
return mainApi
2025-07-08 05:33:44 +08:00
.get<UserListResponse>('/users', { params: payload })
2025-03-11 12:36:25 +08:00
.then((response) => response.data);
};
2025-03-20 01:41:41 +08:00
export const getUserList_server = async (payload: Parameters<typeof getUserList>[0]) => {
2025-07-08 05:33:44 +08:00
return serverFetch<UserListResponse>('/users', { params: payload });
2025-03-11 12:36:25 +08:00
};