Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

use-datasource.ts 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import {
  2. useMutation,
  3. useQuery,
  4. } from '@tanstack/react-query'
  5. import { get } from './base'
  6. import { useInvalid } from './use-base'
  7. import type {
  8. DataSourceAuth,
  9. DataSourceCredential,
  10. } from '@/app/components/header/account-setting/data-source-page-new/types'
  11. const NAME_SPACE = 'data-source-auth'
  12. export const useGetDataSourceListAuth = () => {
  13. return useQuery({
  14. queryKey: [NAME_SPACE, 'list'],
  15. queryFn: () => get<{ result: DataSourceAuth[] }>('/auth/plugin/datasource/list'),
  16. retry: 0,
  17. })
  18. }
  19. export const useInvalidDataSourceListAuth = (
  20. ) => {
  21. return useInvalid([NAME_SPACE, 'list'])
  22. }
  23. // !This hook is used for fetching the default data source list, which will be legacy and deprecated in the near future.
  24. export const useGetDefaultDataSourceListAuth = () => {
  25. return useQuery({
  26. queryKey: [NAME_SPACE, 'default-list'],
  27. queryFn: () => get<{ result: DataSourceAuth[] }>('/auth/plugin/datasource/default-list'),
  28. retry: 0,
  29. })
  30. }
  31. export const useInvalidDefaultDataSourceListAuth = (
  32. ) => {
  33. return useInvalid([NAME_SPACE, 'default-list'])
  34. }
  35. export const useGetDataSourceOAuthUrl = (
  36. provider: string,
  37. ) => {
  38. return useMutation({
  39. mutationKey: [NAME_SPACE, 'oauth-url', provider],
  40. mutationFn: (credentialId?: string) => {
  41. return get<
  42. {
  43. authorization_url: string
  44. state: string
  45. context_id: string
  46. }>(`/oauth/plugin/${provider}/datasource/get-authorization-url?credential_id=${credentialId}`)
  47. },
  48. })
  49. }
  50. export const useGetDataSourceAuth = ({
  51. pluginId,
  52. provider,
  53. }: {
  54. pluginId: string
  55. provider: string
  56. }) => {
  57. return useQuery({
  58. queryKey: [NAME_SPACE, 'specific-data-source', pluginId, provider],
  59. queryFn: () => get<{ result: DataSourceCredential[] }>(`/auth/plugin/datasource/${pluginId}/${provider}`),
  60. retry: 0,
  61. })
  62. }
  63. export const useInvalidDataSourceAuth = ({
  64. pluginId,
  65. provider,
  66. }: {
  67. pluginId: string
  68. provider: string
  69. }) => {
  70. return useInvalid([NAME_SPACE, 'specific-data-source', pluginId, provider])
  71. }