File size: 3,233 Bytes
bbb1195
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { api } from './api';
import { Account, QuotaData } from '../types/account';

/**
 * List all accounts
 */
export async function listAccounts(): Promise<Account[]> {
    return await api.get<Account[]>('/api/accounts');
}

/**
 * Get current account
 */
export async function getCurrentAccount(): Promise<Account | null> {
    return await api.get<Account | null>('/api/accounts/current');
}

/**
 * Add account using refresh token
 */
export async function addAccount(email: string, refreshToken: string): Promise<Account> {
    return await api.post<Account>('/api/accounts', { email, refresh_token: refreshToken });
}

/**
 * Delete account
 */
export async function deleteAccount(accountId: string): Promise<void> {
    return await api.delete<void>(`/api/accounts/${accountId}`);
}

/**
 * Delete multiple accounts
 */
export async function deleteAccounts(accountIds: string[]): Promise<void> {
    // Delete sequentially
    for (const id of accountIds) {
        await deleteAccount(id);
    }
}

/**
 * Set current account (cloud version - no IDE sync)
 */
export async function switchAccount(accountId: string): Promise<void> {
    return await api.post<void>(`/api/accounts/${accountId}/set-current`);
}

/**
 * Fetch account quota
 */
export async function fetchAccountQuota(accountId: string): Promise<QuotaData> {
    return await api.post<QuotaData>(`/api/accounts/${accountId}/quota`);
}

export interface RefreshStats {
    total: number;
    success: number;
    failed: number;
    details: string[];
}

/**
 * Refresh all account quotas
 */
export async function refreshAllQuotas(): Promise<RefreshStats> {
    return await api.post<RefreshStats>('/api/accounts/refresh-all');
}

// ========================================
// Cloud-incompatible functions (stubs)
// ========================================

/**
 * OAuth login - Not supported in cloud version
 * Users should add accounts via Refresh Token
 */
export async function startOAuthLogin(): Promise<Account> {
    throw new Error('OAuth login is not supported in cloud version. Please add accounts using Refresh Token.');
}

/**
 * Complete OAuth login - Not supported
 */
export async function completeOAuthLogin(): Promise<Account> {
    throw new Error('OAuth login is not supported in cloud version.');
}

/**
 * Cancel OAuth login - Not supported
 */
export async function cancelOAuthLogin(): Promise<void> {
    // No-op
}

/**
 * Import V1 accounts - Not supported in cloud version
 */
export async function importV1Accounts(): Promise<Account[]> {
    throw new Error('V1 import is not supported in cloud version.');
}

/**
 * Import from DB - Not supported in cloud version
 */
export async function importFromDb(): Promise<Account> {
    throw new Error('DB import is not supported in cloud version.');
}

/**
 * Import from custom DB - Not supported in cloud version
 */
export async function importFromCustomDb(_path: string): Promise<Account> {
    throw new Error('Custom DB import is not supported in cloud version.');
}

/**
 * Sync account from DB - Not supported in cloud version
 */
export async function syncAccountFromDb(): Promise<Account | null> {
    // Return null silently (used in background tasks)
    return null;
}