import { useMutation, useQuery, } from '@tanstack/react-query' import { fetchDataSourceAuth, fetchDataSourceListAuth, fetchDataSourceOAuthUrl, fetchDefaultDataSourceListAuth, } from './datasource' import { useInvalid } from './use-base' const NAME_SPACE = 'data-source-auth' export const useGetDataSourceListAuth = () => { return useQuery({ queryKey: [NAME_SPACE, 'list'], queryFn: () => fetchDataSourceListAuth(), retry: 0, }) } export const useInvalidDataSourceListAuth = ( ) => { return useInvalid([NAME_SPACE, 'list']) } // !This hook is used for fetching the default data source list, which will be legacy and deprecated in the near future. export const useGetDefaultDataSourceListAuth = () => { return useQuery({ queryKey: [NAME_SPACE, 'default-list'], queryFn: () => fetchDefaultDataSourceListAuth(), retry: 0, }) } export const useInvalidDefaultDataSourceListAuth = ( ) => { return useInvalid([NAME_SPACE, 'default-list']) } export const useGetDataSourceOAuthUrl = ( provider: string, ) => { return useMutation({ mutationKey: [NAME_SPACE, 'oauth-url', provider], mutationFn: (credentialId?: string) => { return fetchDataSourceOAuthUrl(provider, credentialId) }, }) } export const useGetDataSourceAuth = ({ pluginId, provider, }: { pluginId: string provider: string }) => { return useQuery({ queryKey: [NAME_SPACE, 'specific-data-source', pluginId, provider], queryFn: () => fetchDataSourceAuth(pluginId, provider), retry: 0, }) } export const useInvalidDataSourceAuth = ({ pluginId, provider, }: { pluginId: string provider: string }) => { return useInvalid([NAME_SPACE, 'specific-data-source', pluginId, provider]) }