import type { CommonResponse } from '@/models/common' import { post } from './base' type LoginSuccess = { result: 'success' data?: { access_token?: string } } type LoginFail = { result: 'fail' data: string code: string message: string } type LoginResponse = LoginSuccess | LoginFail export const webAppLogin = ({ url, body, }: { url: string body: Record }): Promise => { return post(url, { body }, { isPublicAPI: true }) } export const changeWebAppPasswordWithToken = ({ url, body, }: { url: string body: { token: string; new_password: string; password_confirm: string } }): Promise => post(url, { body }, { isPublicAPI: true }) export const uploadPublicRemoteFileInfo = (url: string, options?: { silent?: boolean }) => { return post<{ id: string; name: string; size: number; mime_type: string; url: string }>( '/remote-files/upload', { body: { url } }, { isPublicAPI: true, ...options }, ) } export const sendWebAppEMailLoginCode = ( email: string, language = 'en-US', ): Promise => post( '/email-code-login', { body: { email, language } }, { isPublicAPI: true }, ) export const webAppEmailLoginWithCode = (data: { email: string code: string token: string }): Promise => post('/email-code-login/validity', { body: data }, { isPublicAPI: true }) export const sendWebAppResetPasswordCode = ( email: string, language = 'en-US', ): Promise => post( '/forgot-password', { body: { email, language } }, { isPublicAPI: true }, ) export const verifyWebAppResetPasswordCode = (body: { email: string code: string token: string }): Promise => post( '/forgot-password/validity', { body }, { isPublicAPI: true }, ) export const getAvatar = async ({ avatar, }: { avatar: string }): Promise<{ avatar_url: string }> => { const { consoleClient } = await import('@/service/console') return consoleClient.account.avatar.get({ query: { avatar } }) }