common.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import type { Fetcher } from 'swr'
  2. import { del, get, patch, post, put } from './base'
  3. import type {
  4. AccountIntegrate, CommonResponse, DataSourceNotion,
  5. IWorkspace, LangGeniusVersionResponse, Member,
  6. OauthResponse, Provider, ProviderAzureToken, TenantInfoResponse,
  7. UserProfileOriginResponse,
  8. } from '@/models/common'
  9. import type {
  10. UpdateOpenAIKeyResponse,
  11. ValidateOpenAIKeyResponse,
  12. } from '@/models/app'
  13. export const login: Fetcher<CommonResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  14. return post(url, { body }) as Promise<CommonResponse>
  15. }
  16. export const setup: Fetcher<CommonResponse, { body: Record<string, any> }> = ({ body }) => {
  17. return post('/setup', { body }) as Promise<CommonResponse>
  18. }
  19. export const fetchUserProfile: Fetcher<UserProfileOriginResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  20. return get(url, params, { needAllResponseContent: true }) as Promise<UserProfileOriginResponse>
  21. }
  22. export const updateUserProfile: Fetcher<CommonResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  23. return post(url, { body }) as Promise<CommonResponse>
  24. }
  25. export const fetchTenantInfo: Fetcher<TenantInfoResponse, { url: string }> = ({ url }) => {
  26. return get(url) as Promise<TenantInfoResponse>
  27. }
  28. export const logout: Fetcher<CommonResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  29. return get(url, params) as Promise<CommonResponse>
  30. }
  31. export const fetchLanggeniusVersion: Fetcher<LangGeniusVersionResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  32. return get(url, { params }) as Promise<LangGeniusVersionResponse>
  33. }
  34. export const oauth: Fetcher<OauthResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  35. return get(url, { params }) as Promise<OauthResponse>
  36. }
  37. export const oneMoreStep: Fetcher<CommonResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  38. return post(url, { body }) as Promise<CommonResponse>
  39. }
  40. export const fetchMembers: Fetcher<{ accounts: Member[] | null }, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  41. return get(url, { params }) as Promise<{ accounts: Member[] | null }>
  42. }
  43. export const fetchProviders: Fetcher<Provider[] | null, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  44. return get(url, { params }) as Promise<Provider[] | null>
  45. }
  46. export const validateProviderKey: Fetcher<ValidateOpenAIKeyResponse, { url: string; body: { token: string } }> = ({ url, body }) => {
  47. return post(url, { body }) as Promise<ValidateOpenAIKeyResponse>
  48. }
  49. export const updateProviderAIKey: Fetcher<UpdateOpenAIKeyResponse, { url: string; body: { token: string | ProviderAzureToken } }> = ({ url, body }) => {
  50. return post(url, { body }) as Promise<UpdateOpenAIKeyResponse>
  51. }
  52. export const fetchAccountIntegrates: Fetcher<{ data: AccountIntegrate[] | null }, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  53. return get(url, { params }) as Promise<{ data: AccountIntegrate[] | null }>
  54. }
  55. export const inviteMember: Fetcher<CommonResponse & { account: Member }, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  56. return post(url, { body }) as Promise<CommonResponse & { account: Member }>
  57. }
  58. export const updateMemberRole: Fetcher<CommonResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  59. return put(url, { body }) as Promise<CommonResponse>
  60. }
  61. export const deleteMemberOrCancelInvitation: Fetcher<CommonResponse, { url: string }> = ({ url }) => {
  62. return del(url) as Promise<CommonResponse>
  63. }
  64. export const fetchFilePreview: Fetcher<{ content: string }, { fileID: string }> = ({ fileID }) => {
  65. return get(`/files/${fileID}/preview`) as Promise<{ content: string }>
  66. }
  67. export const fetchWorkspaces: Fetcher<{ workspaces: IWorkspace[] }, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  68. return get(url, { params }) as Promise<{ workspaces: IWorkspace[] }>
  69. }
  70. export const switchWorkspace: Fetcher<CommonResponse & { new_tenant: IWorkspace }, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  71. return post(url, { body }) as Promise<CommonResponse & { new_tenant: IWorkspace }>
  72. }
  73. export const fetchDataSource: Fetcher<{ data: DataSourceNotion[] }, { url: string }> = ({ url }) => {
  74. return get(url) as Promise<{ data: DataSourceNotion[] }>
  75. }
  76. export const syncDataSourceNotion: Fetcher<CommonResponse, { url: string }> = ({ url }) => {
  77. return get(url) as Promise<CommonResponse>
  78. }
  79. export const updateDataSourceNotionAction: Fetcher<CommonResponse, { url: string }> = ({ url }) => {
  80. return patch(url) as Promise<CommonResponse>
  81. }