dify/web/features/account-profile/client.ts
Stephen Zhou eb71e47f3b
chore: migrate linting to vp lint with ESLint fallback (#38834)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-07-13 06:41:53 +00:00

42 lines
1.3 KiB
TypeScript

import type { GetAccountProfileResponse } from '@dify/contracts/api/console/account/types.gen'
import { queryOptions } from '@tanstack/react-query'
import { IS_DEV } from '@/config'
// oxlint-disable-next-line no-restricted-imports
import { get } from '@/service/base'
import { consoleQuery } from '@/service/client'
export type UserProfileWithMeta = {
profile: GetAccountProfileResponse
meta: {
currentVersion: string | null
currentEnv: string | null
}
}
export const isLegacyBase401 = (err: unknown): boolean =>
err instanceof Response && err.status === 401
export const userProfileQueryOptions = () =>
queryOptions<UserProfileWithMeta>({
queryKey: consoleQuery.account.profile.get.queryKey(),
queryFn: async () => {
const response = await get<Response>(
'/account/profile',
{},
{
needAllResponseContent: true,
silent: true,
},
)
const profile: GetAccountProfileResponse = await response.clone().json()
return {
profile,
meta: {
currentVersion: response.headers.get('x-version'),
currentEnv: IS_DEV ? 'DEVELOPMENT' : response.headers.get('x-env'),
},
}
},
retry: (failureCount, error) => !isLegacyBase401(error) && failureCount < 3,
})