import { callWorker } from './workerClient'; import type { AccountDeviceBody, InvitationBody } from './generated/api'; import type { PersonalProfile } from './protocol/account'; const API_BASE = import.meta.env.VITE_WEBDROP_API_URL ?? '/api/v1'; export interface AccountStatus { username: string | null; revision: number; remembered?: boolean; personal?: PersonalProfile; error?: string; unlockUsername?: string } export type AccountDevice = AccountDeviceBody; export type AccountInvitation = InvitationBody; export const accountApi = { register: (username: string, password: string, remember = true) => callWorker('registerAccount', { username, password, remember, apiBase: API_BASE }), login: (username: string, password: string, remember = true) => callWorker('loginAccount', { username, password, remember, apiBase: API_BASE }), savedLogin: () => callWorker<{ username: string; password: string; saved: boolean }>('savedLogin', { apiBase: API_BASE }), clearSavedLogin: () => callWorker('clearSavedLogin', { apiBase: API_BASE }), status: () => callWorker('accountStatus', { apiBase: API_BASE }), logout: () => callWorker('logoutAccount', { apiBase: API_BASE }), sync: () => callWorker('syncAccount', { apiBase: API_BASE }), invitations: () => callWorker('accountInvitations', { apiBase: API_BASE }), acceptInvitation: (id: string) => callWorker('acceptInvitation', { id, apiBase: API_BASE }), updatePersonal: (displayName: string, avatar?: string) => callWorker('updatePersonal', { displayName, avatar, apiBase: API_BASE }), devices: () => callWorker('accountDevices', { apiBase: API_BASE }), renameDevice: (id: string, name: string) => callWorker('renameAccountDevice', { id, name, apiBase: API_BASE }), revokeDevice: (id: string) => callWorker('revokeAccountDevice', { id, apiBase: API_BASE }), };