cursor-switch 1.0.6 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -75
- package/SECURITY.md +22 -19
- package/bin/cswitch.js +31 -8
- package/dist/cli.d.ts +0 -4
- package/dist/cli.js +404 -225
- package/dist/core/account-store.d.ts +0 -7
- package/dist/core/account-store.js +22 -28
- package/dist/core/cdp-engine.d.ts +11 -49
- package/dist/core/cdp-engine.js +155 -110
- package/dist/core/config-store.d.ts +7 -6
- package/dist/core/config-store.js +33 -12
- package/dist/core/cursor-paths.d.ts +8 -18
- package/dist/core/cursor-paths.js +18 -37
- package/dist/core/dashboard-launcher.d.ts +2 -22
- package/dist/core/dashboard-launcher.js +10 -60
- package/dist/core/extract-client.d.ts +57 -0
- package/dist/core/extract-client.js +219 -0
- package/dist/core/extract-menu.d.ts +3 -0
- package/dist/core/extract-menu.js +360 -0
- package/dist/core/extract-service.d.ts +64 -0
- package/dist/core/extract-service.js +435 -0
- package/dist/core/fingerprint.d.ts +0 -4
- package/dist/core/fingerprint.js +0 -6
- package/dist/core/oauth-receiver.d.ts +1 -11
- package/dist/core/oauth-receiver.js +509 -527
- package/dist/core/official-api.d.ts +0 -17
- package/dist/core/official-api.js +4 -23
- package/dist/core/outlook-launcher.d.ts +0 -27
- package/dist/core/outlook-launcher.js +235 -261
- package/dist/core/process-manager.d.ts +0 -14
- package/dist/core/process-manager.js +7 -22
- package/dist/core/pure-login-service.d.ts +64 -28
- package/dist/core/pure-login-service.js +527 -346
- package/dist/core/refund-client.d.ts +0 -22
- package/dist/core/refund-client.js +7 -27
- package/dist/core/refund-service.d.ts +0 -16
- package/dist/core/refund-service.js +8 -34
- package/dist/core/safe-storage.d.ts +27 -0
- package/dist/core/safe-storage.js +284 -0
- package/dist/core/sqlite-bridge.d.ts +10 -11
- package/dist/core/sqlite-bridge.js +112 -47
- package/dist/core/storage-bridge.d.ts +14 -5
- package/dist/core/storage-bridge.js +84 -24
- package/dist/core/switch-orchestrator.d.ts +96 -0
- package/dist/core/switch-orchestrator.js +341 -0
- package/dist/core/token-exchange.d.ts +81 -0
- package/dist/core/token-exchange.js +275 -0
- package/dist/core/token-parser.d.ts +56 -20
- package/dist/core/token-parser.js +354 -43
- package/dist/core/update-checker.d.ts +1 -29
- package/dist/core/update-checker.js +28 -43
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -3
- package/dist/menu.d.ts +0 -7
- package/dist/menu.js +445 -538
- package/dist/types.d.ts +12 -4
- package/dist/types.js +0 -4
- package/dist/utils/account-text-importer.d.ts +9 -0
- package/dist/utils/account-text-importer.js +96 -0
- package/dist/utils/browser-utils.d.ts +0 -24
- package/dist/utils/browser-utils.js +0 -57
- package/dist/utils/clipboard.d.ts +0 -4
- package/dist/utils/clipboard.js +0 -5
- package/dist/utils/credential-bundle-ui.d.ts +36 -0
- package/dist/utils/credential-bundle-ui.js +246 -0
- package/dist/utils/live-menu.d.ts +37 -9
- package/dist/utils/live-menu.js +510 -81
- package/dist/utils/plan-formatter.d.ts +0 -26
- package/dist/utils/plan-formatter.js +10 -44
- package/dist/utils/prompt-utils.d.ts +0 -18
- package/dist/utils/prompt-utils.js +0 -23
- package/dist/utils/proxy-bootstrap.d.ts +12 -0
- package/dist/utils/proxy-bootstrap.js +141 -0
- package/dist/utils/security.d.ts +2 -4
- package/dist/utils/security.js +36 -4
- package/dist/utils/table-renderer.d.ts +0 -4
- package/dist/utils/table-renderer.js +24 -8
- package/dist/utils/time-formatter.d.ts +0 -4
- package/dist/utils/time-formatter.js +0 -8
- package/dist/utils/token-preflight-ui.d.ts +28 -0
- package/dist/utils/token-preflight-ui.js +222 -0
- package/dist/utils/window-focus.d.ts +3 -0
- package/dist/utils/window-focus.js +106 -0
- package/package.json +12 -5
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { execFileSync } from 'node:child_process';
|
|
4
|
+
import { resolveCursorPaths, resolveSidecarPaths } from './cursor-paths.js';
|
|
5
|
+
import { generateMachineIds } from './fingerprint.js';
|
|
6
|
+
import { ProcessManager } from './process-manager.js';
|
|
7
|
+
import { TokenParser } from './token-parser.js';
|
|
8
|
+
import { resolveSwitchCredentials, } from './token-exchange.js';
|
|
9
|
+
import { writeSecureFileSync } from '../utils/security.js';
|
|
10
|
+
function resolveEffectiveSidecars(paths, fallbackDbOrStoragePath) {
|
|
11
|
+
const basePath = paths?.storageJson || paths?.sqliteDb || fallbackDbOrStoragePath || '';
|
|
12
|
+
const derived = basePath ? resolveSidecarPaths(basePath) : undefined;
|
|
13
|
+
return {
|
|
14
|
+
userDataDir: paths?.userDataDir || derived?.userDataDir,
|
|
15
|
+
machineIdFile: paths?.machineIdFile || derived?.machineIdFile,
|
|
16
|
+
authJson: paths?.authJson || derived?.authJson,
|
|
17
|
+
cliConfigJson: paths?.cliConfigJson || derived?.cliConfigJson,
|
|
18
|
+
localStateFile: paths?.localStateFile || derived?.localStateFile,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export function syncSidecarFiles(paths, payload) {
|
|
22
|
+
const report = {
|
|
23
|
+
machineIdFileUpdated: false,
|
|
24
|
+
authJsonUpdated: false,
|
|
25
|
+
cliConfigUpdated: false,
|
|
26
|
+
warnings: [],
|
|
27
|
+
};
|
|
28
|
+
const sidecars = resolveEffectiveSidecars(paths);
|
|
29
|
+
if (sidecars.machineIdFile) {
|
|
30
|
+
const serviceId = payload.machineIds?.['storage.serviceMachineId'] ||
|
|
31
|
+
payload.machineIds?.['telemetry.devDeviceId'];
|
|
32
|
+
const parentExists = fs.existsSync(path.dirname(sidecars.machineIdFile));
|
|
33
|
+
if (serviceId && (parentExists || fs.existsSync(sidecars.machineIdFile))) {
|
|
34
|
+
try {
|
|
35
|
+
writeSecureFileSync(sidecars.machineIdFile, serviceId);
|
|
36
|
+
report.machineIdFileUpdated = true;
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
report.warnings.push(`更新 machineid 文件失败: ${err?.message || err}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (sidecars.authJson && fs.existsSync(sidecars.authJson)) {
|
|
44
|
+
try {
|
|
45
|
+
const raw = fs.readFileSync(sidecars.authJson, 'utf8').trim();
|
|
46
|
+
const parsed = raw ? JSON.parse(raw) : {};
|
|
47
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
48
|
+
throw new Error('auth.json 根节点不是有效的 JSON 对象');
|
|
49
|
+
}
|
|
50
|
+
if (payload.clearAuth) {
|
|
51
|
+
delete parsed.accessToken;
|
|
52
|
+
delete parsed.refreshToken;
|
|
53
|
+
delete parsed.email;
|
|
54
|
+
}
|
|
55
|
+
else if (payload.accessToken) {
|
|
56
|
+
parsed.accessToken = payload.accessToken;
|
|
57
|
+
parsed.refreshToken =
|
|
58
|
+
payload.refreshToken && !payload.refreshToken.includes('::')
|
|
59
|
+
? payload.refreshToken
|
|
60
|
+
: payload.accessToken;
|
|
61
|
+
if (payload.email && 'email' in parsed) {
|
|
62
|
+
parsed.email = payload.email;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
writeSecureFileSync(sidecars.authJson, JSON.stringify(parsed, null, 2));
|
|
66
|
+
report.authJsonUpdated = true;
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
report.warnings.push(`同步 auth.json 跳过: ${err?.message || err}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (sidecars.cliConfigJson && fs.existsSync(sidecars.cliConfigJson)) {
|
|
73
|
+
try {
|
|
74
|
+
const raw = fs.readFileSync(sidecars.cliConfigJson, 'utf8').trim();
|
|
75
|
+
const cfg = raw ? JSON.parse(raw) : {};
|
|
76
|
+
if (cfg && typeof cfg === 'object' && !Array.isArray(cfg) && 'authInfo' in cfg) {
|
|
77
|
+
if (payload.clearAuth) {
|
|
78
|
+
delete cfg.authInfo;
|
|
79
|
+
writeSecureFileSync(sidecars.cliConfigJson, JSON.stringify(cfg, null, 2));
|
|
80
|
+
report.cliConfigUpdated = true;
|
|
81
|
+
}
|
|
82
|
+
else if (payload.email) {
|
|
83
|
+
const displayName = payload.email.includes('@')
|
|
84
|
+
? payload.email.split('@')[0]
|
|
85
|
+
: payload.email;
|
|
86
|
+
const nextAuthInfo = {
|
|
87
|
+
email: payload.email,
|
|
88
|
+
displayName,
|
|
89
|
+
};
|
|
90
|
+
if (payload.userId)
|
|
91
|
+
nextAuthInfo.userId = payload.userId;
|
|
92
|
+
if (payload.authId)
|
|
93
|
+
nextAuthInfo.authId = payload.authId;
|
|
94
|
+
cfg.authInfo = nextAuthInfo;
|
|
95
|
+
writeSecureFileSync(sidecars.cliConfigJson, JSON.stringify(cfg, null, 2));
|
|
96
|
+
report.cliConfigUpdated = true;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
report.warnings.push(`同步 cli-config.json 跳过: ${err?.message || err}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return report;
|
|
105
|
+
}
|
|
106
|
+
export function resetWindowsSystemMachineGuid(newGuid, backupDir) {
|
|
107
|
+
if (process.platform !== 'win32') {
|
|
108
|
+
return { ok: false, skipped: true, error: '仅 Windows 支持重置系统注册表 MachineGuid' };
|
|
109
|
+
}
|
|
110
|
+
if (!newGuid || !newGuid.trim()) {
|
|
111
|
+
return { ok: false, skipped: true, error: '未提供有效的目标 MachineGuid' };
|
|
112
|
+
}
|
|
113
|
+
const regKey = 'HKLM\\SOFTWARE\\Microsoft\\Cryptography';
|
|
114
|
+
try {
|
|
115
|
+
let backupPath;
|
|
116
|
+
if (backupDir) {
|
|
117
|
+
fs.mkdirSync(backupDir, { recursive: true });
|
|
118
|
+
const ts = new Date().toISOString().replace(/[-:T.]/g, '').slice(0, 14);
|
|
119
|
+
backupPath = path.join(backupDir, `MachineGuid_${ts}.reg`);
|
|
120
|
+
try {
|
|
121
|
+
execFileSync('reg.exe', ['export', regKey, backupPath, '/y'], {
|
|
122
|
+
stdio: 'ignore',
|
|
123
|
+
windowsHide: true,
|
|
124
|
+
timeout: 5000,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
catch { }
|
|
128
|
+
}
|
|
129
|
+
execFileSync('reg.exe', ['add', regKey, '/v', 'MachineGuid', '/t', 'REG_SZ', '/d', newGuid, '/f'], {
|
|
130
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
131
|
+
windowsHide: true,
|
|
132
|
+
timeout: 5000,
|
|
133
|
+
});
|
|
134
|
+
return { ok: true, backupPath };
|
|
135
|
+
}
|
|
136
|
+
catch (err) {
|
|
137
|
+
const msg = err?.stderr?.toString?.() || err?.message || String(err);
|
|
138
|
+
return {
|
|
139
|
+
ok: false,
|
|
140
|
+
error: msg.includes('Access is denied') || msg.includes('拒绝访问')
|
|
141
|
+
? '修改注册表 HKLM MachineGuid 需要管理员权限,已跳过系统级写入'
|
|
142
|
+
: `写入系统注册表失败: ${msg.trim()}`,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
export async function applyMachineIdsToCursor(params) {
|
|
147
|
+
params.storage.writeMachineIds(params.machineIds);
|
|
148
|
+
if (params.sqlite.exists()) {
|
|
149
|
+
await params.sqlite.upsertServiceMachineId(params.machineIds['storage.serviceMachineId']);
|
|
150
|
+
}
|
|
151
|
+
const sidecarReport = syncSidecarFiles(params.paths, { machineIds: params.machineIds });
|
|
152
|
+
let systemRegistryResult;
|
|
153
|
+
if (params.resetSystemRegistry) {
|
|
154
|
+
const backupDir = params.paths?.globalStorageDir
|
|
155
|
+
? path.join(params.paths.globalStorageDir, 'backups')
|
|
156
|
+
: undefined;
|
|
157
|
+
const targetGuid = params.machineIds['system.machineGuid'] || params.machineIds['telemetry.devDeviceId'];
|
|
158
|
+
systemRegistryResult = resetWindowsSystemMachineGuid(targetGuid, backupDir);
|
|
159
|
+
}
|
|
160
|
+
return { sidecarReport, systemRegistryResult };
|
|
161
|
+
}
|
|
162
|
+
export async function readLocalCursorAuth(storage, sqlite) {
|
|
163
|
+
const sqliteEmail = await sqlite.readEmail();
|
|
164
|
+
const storageEmail = storage.readCurrentEmail();
|
|
165
|
+
const sqliteInfo = await sqlite.readTokenInfo();
|
|
166
|
+
if (sqliteInfo.token) {
|
|
167
|
+
const refreshToken = (await sqlite.readRefreshToken()) || storage.readRefreshToken();
|
|
168
|
+
return {
|
|
169
|
+
email: sqliteEmail || storageEmail,
|
|
170
|
+
token: sqliteInfo.token,
|
|
171
|
+
refreshToken,
|
|
172
|
+
source: 'sqlite',
|
|
173
|
+
isEncrypted: sqliteInfo.isEncrypted,
|
|
174
|
+
decrypted: sqliteInfo.decrypted,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
if (sqliteInfo.isEncrypted) {
|
|
178
|
+
return {
|
|
179
|
+
email: sqliteEmail || storageEmail,
|
|
180
|
+
token: null,
|
|
181
|
+
refreshToken: null,
|
|
182
|
+
source: 'sqlite',
|
|
183
|
+
isEncrypted: true,
|
|
184
|
+
decrypted: false,
|
|
185
|
+
encryptionError: sqliteInfo.error,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
const storageInfo = storage.readTokenInfo();
|
|
189
|
+
if (storageInfo.token) {
|
|
190
|
+
const refreshToken = storage.readRefreshToken() || (await sqlite.readRefreshToken());
|
|
191
|
+
return {
|
|
192
|
+
email: storageEmail || sqliteEmail,
|
|
193
|
+
token: storageInfo.token,
|
|
194
|
+
refreshToken,
|
|
195
|
+
source: 'storage',
|
|
196
|
+
isEncrypted: storageInfo.isEncrypted,
|
|
197
|
+
decrypted: storageInfo.decrypted,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
email: sqliteEmail || storageEmail,
|
|
202
|
+
token: null,
|
|
203
|
+
refreshToken: null,
|
|
204
|
+
source: null,
|
|
205
|
+
isEncrypted: storageInfo.isEncrypted,
|
|
206
|
+
decrypted: false,
|
|
207
|
+
encryptionError: storageInfo.error,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
export async function executeAccountSwitch(opts) {
|
|
211
|
+
const { store, storage, sqlite, targetAccount } = opts;
|
|
212
|
+
const paths = opts.paths || resolveCursorPaths();
|
|
213
|
+
const warnings = [];
|
|
214
|
+
const hadBoundMachineIds = Boolean(targetAccount.machine_ids?.['telemetry.devDeviceId']);
|
|
215
|
+
const machineIds = hadBoundMachineIds && targetAccount.machine_ids ? targetAccount.machine_ids : generateMachineIds();
|
|
216
|
+
targetAccount.machine_ids = machineIds;
|
|
217
|
+
opts.onStep?.('resolve');
|
|
218
|
+
const resolved = await resolveSwitchCredentials(targetAccount, {
|
|
219
|
+
autoUpgradeWebToken: opts.autoUpgradeWebToken,
|
|
220
|
+
autoRefreshExpiring: opts.autoRefreshExpiring,
|
|
221
|
+
fetchImpl: opts.fetchImpl,
|
|
222
|
+
});
|
|
223
|
+
warnings.push(...resolved.warnings);
|
|
224
|
+
const staleHandler = opts.resolveStaleTokenAction ||
|
|
225
|
+
(opts.confirmOnStaleToken
|
|
226
|
+
? async (issue, acc) => ({ action: (await opts.confirmOnStaleToken(issue, acc)) ? 'force' : 'abort' })
|
|
227
|
+
: undefined);
|
|
228
|
+
if (resolved.preflightIssue?.severity === 'blocking' && staleHandler) {
|
|
229
|
+
const resolution = await staleHandler(resolved.preflightIssue, targetAccount);
|
|
230
|
+
if (resolution.action === 'replace_account') {
|
|
231
|
+
const mergedAccount = {
|
|
232
|
+
...resolution.account,
|
|
233
|
+
machine_ids: resolution.account.machine_ids || targetAccount.machine_ids,
|
|
234
|
+
};
|
|
235
|
+
store.addOrUpdate(mergedAccount);
|
|
236
|
+
const nextDepth = (opts._healDepth ?? 0) + 1;
|
|
237
|
+
if (nextDepth <= 2) {
|
|
238
|
+
return executeAccountSwitch({
|
|
239
|
+
...opts,
|
|
240
|
+
targetAccount: mergedAccount,
|
|
241
|
+
_healDepth: nextDepth,
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const proceed = resolution.action === 'force';
|
|
246
|
+
if (!proceed) {
|
|
247
|
+
return {
|
|
248
|
+
success: false,
|
|
249
|
+
aborted: true,
|
|
250
|
+
email: targetAccount.email,
|
|
251
|
+
account: targetAccount,
|
|
252
|
+
machineIds,
|
|
253
|
+
tokenType: resolved.tokenType,
|
|
254
|
+
upgradedFromWeb: false,
|
|
255
|
+
refreshed: false,
|
|
256
|
+
shouldLogout: resolved.shouldLogout,
|
|
257
|
+
preflightIssue: resolved.preflightIssue,
|
|
258
|
+
sidecarReport: {
|
|
259
|
+
machineIdFileUpdated: false,
|
|
260
|
+
authJsonUpdated: false,
|
|
261
|
+
cliConfigUpdated: false,
|
|
262
|
+
warnings: [],
|
|
263
|
+
},
|
|
264
|
+
warnings,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
const finalAccount = {
|
|
269
|
+
...targetAccount,
|
|
270
|
+
token: resolved.accessToken,
|
|
271
|
+
refresh_token: resolved.refreshToken,
|
|
272
|
+
workos_cursor_session_token: resolved.workosSessionToken || targetAccount.workos_cursor_session_token,
|
|
273
|
+
machine_ids: machineIds,
|
|
274
|
+
};
|
|
275
|
+
if (resolved.upgradedFromWeb || resolved.refreshed || !hadBoundMachineIds || !store.getByEmail(targetAccount.email)) {
|
|
276
|
+
store.addOrUpdate(finalAccount);
|
|
277
|
+
}
|
|
278
|
+
if (opts.skipProcessClose) {
|
|
279
|
+
opts.onStep?.('close', 'skipped');
|
|
280
|
+
}
|
|
281
|
+
else if (ProcessManager.isCursorRunning(true)) {
|
|
282
|
+
opts.onStep?.('close', 'running');
|
|
283
|
+
await ProcessManager.closeCursor();
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
opts.onStep?.('close', 'stopped');
|
|
287
|
+
}
|
|
288
|
+
opts.onStep?.('backup');
|
|
289
|
+
storage.createBackup();
|
|
290
|
+
sqlite.createBackup();
|
|
291
|
+
const machineApply = await applyMachineIdsToCursor({
|
|
292
|
+
storage,
|
|
293
|
+
sqlite,
|
|
294
|
+
paths,
|
|
295
|
+
machineIds,
|
|
296
|
+
resetSystemRegistry: opts.resetSystemRegistry,
|
|
297
|
+
});
|
|
298
|
+
warnings.push(...machineApply.sidecarReport.warnings);
|
|
299
|
+
if (machineApply.systemRegistryResult && !machineApply.systemRegistryResult.ok && machineApply.systemRegistryResult.error) {
|
|
300
|
+
warnings.push(machineApply.systemRegistryResult.error);
|
|
301
|
+
}
|
|
302
|
+
opts.onStep?.('machine');
|
|
303
|
+
const authMetadata = {
|
|
304
|
+
authId: resolved.authId || TokenParser.extractAuthId(resolved.accessToken),
|
|
305
|
+
userId: resolved.userId || TokenParser.extractUserId(resolved.accessToken),
|
|
306
|
+
membershipType: targetAccount.subscription_type,
|
|
307
|
+
subscriptionStatus: targetAccount.subscription_status,
|
|
308
|
+
};
|
|
309
|
+
storage.writeAuth(targetAccount.email, resolved.accessToken, resolved.refreshToken, authMetadata);
|
|
310
|
+
await sqlite.injectAuth(targetAccount.email, resolved.accessToken, resolved.refreshToken, authMetadata);
|
|
311
|
+
const authSidecarReport = syncSidecarFiles(paths, {
|
|
312
|
+
email: targetAccount.email,
|
|
313
|
+
accessToken: resolved.accessToken,
|
|
314
|
+
refreshToken: resolved.refreshToken,
|
|
315
|
+
authId: authMetadata.authId,
|
|
316
|
+
userId: authMetadata.userId,
|
|
317
|
+
});
|
|
318
|
+
warnings.push(...authSidecarReport.warnings);
|
|
319
|
+
store.markCurrent(targetAccount.email);
|
|
320
|
+
opts.onStep?.('auth');
|
|
321
|
+
return {
|
|
322
|
+
success: true,
|
|
323
|
+
aborted: false,
|
|
324
|
+
email: targetAccount.email,
|
|
325
|
+
account: finalAccount,
|
|
326
|
+
machineIds,
|
|
327
|
+
tokenType: resolved.tokenType,
|
|
328
|
+
upgradedFromWeb: resolved.upgradedFromWeb,
|
|
329
|
+
refreshed: resolved.refreshed,
|
|
330
|
+
shouldLogout: resolved.shouldLogout,
|
|
331
|
+
preflightIssue: resolved.preflightIssue,
|
|
332
|
+
sidecarReport: {
|
|
333
|
+
machineIdFileUpdated: machineApply.sidecarReport.machineIdFileUpdated,
|
|
334
|
+
authJsonUpdated: authSidecarReport.authJsonUpdated,
|
|
335
|
+
cliConfigUpdated: authSidecarReport.cliConfigUpdated,
|
|
336
|
+
warnings: [...machineApply.sidecarReport.warnings, ...authSidecarReport.warnings],
|
|
337
|
+
},
|
|
338
|
+
systemRegistryResult: machineApply.systemRegistryResult,
|
|
339
|
+
warnings,
|
|
340
|
+
};
|
|
341
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { AccountInfo } from '../types.js';
|
|
2
|
+
import { OfficialApiClient } from './official-api.js';
|
|
3
|
+
import { TokenParser } from './token-parser.js';
|
|
4
|
+
export declare const CURSOR_OAUTH_CLIENT_ID = "KbZUR41cY7W6zRSdpSUJ7I7mLYBKOCmB";
|
|
5
|
+
export type FetchLike = typeof fetch;
|
|
6
|
+
export interface RefreshTokenResult {
|
|
7
|
+
ok: boolean;
|
|
8
|
+
accessToken?: string;
|
|
9
|
+
refreshToken?: string;
|
|
10
|
+
shouldLogout?: boolean;
|
|
11
|
+
error?: string;
|
|
12
|
+
status?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface SwitchPreflightIssue {
|
|
15
|
+
kind: 'refresh_revoked' | 'token_expired' | 'web_upgrade_failed';
|
|
16
|
+
severity: 'blocking' | 'warning';
|
|
17
|
+
title: string;
|
|
18
|
+
reason: string;
|
|
19
|
+
recommendation: string;
|
|
20
|
+
ageHours?: number;
|
|
21
|
+
}
|
|
22
|
+
export interface ResolvedSwitchCredentials {
|
|
23
|
+
accessToken: string;
|
|
24
|
+
refreshToken: string;
|
|
25
|
+
authId?: string;
|
|
26
|
+
userId?: string;
|
|
27
|
+
workosSessionToken?: string;
|
|
28
|
+
tokenType: 'web' | 'client';
|
|
29
|
+
upgradedFromWeb: boolean;
|
|
30
|
+
refreshed: boolean;
|
|
31
|
+
shouldLogout: boolean;
|
|
32
|
+
preflightIssue?: SwitchPreflightIssue;
|
|
33
|
+
warnings: string[];
|
|
34
|
+
}
|
|
35
|
+
export declare function resolveSessionPair(params: {
|
|
36
|
+
token: string;
|
|
37
|
+
workosSessionToken?: string | null;
|
|
38
|
+
userId?: string | null;
|
|
39
|
+
}): {
|
|
40
|
+
userId?: string;
|
|
41
|
+
jwt: string;
|
|
42
|
+
sessionCookieValue?: string;
|
|
43
|
+
};
|
|
44
|
+
export declare function refreshClientAccessToken(refreshToken: string, fetchImpl?: FetchLike): Promise<RefreshTokenResult>;
|
|
45
|
+
export declare function resolveSwitchCredentials(account: AccountInfo, opts?: {
|
|
46
|
+
autoUpgradeWebToken?: boolean;
|
|
47
|
+
autoRefreshExpiring?: boolean;
|
|
48
|
+
fetchImpl?: FetchLike;
|
|
49
|
+
maxPollAttempts?: number;
|
|
50
|
+
pollIntervalMs?: number;
|
|
51
|
+
}): Promise<ResolvedSwitchCredentials>;
|
|
52
|
+
export declare function buildOAuthAccountInfo(params: {
|
|
53
|
+
email: string;
|
|
54
|
+
accessToken: string;
|
|
55
|
+
refreshToken?: string;
|
|
56
|
+
authId?: string;
|
|
57
|
+
usageRes?: Awaited<ReturnType<typeof OfficialApiClient.fetchUsage>>;
|
|
58
|
+
existing?: AccountInfo;
|
|
59
|
+
machineIds: AccountInfo['machine_ids'];
|
|
60
|
+
}): AccountInfo;
|
|
61
|
+
export type IngestUpgradeStatus = 'already_client' | 'expired' | 'web_only_skipped';
|
|
62
|
+
export interface IngestUpgradeResult {
|
|
63
|
+
status: IngestUpgradeStatus;
|
|
64
|
+
account: AccountInfo;
|
|
65
|
+
classification: ReturnType<typeof TokenParser.classifyAccount>;
|
|
66
|
+
error?: string;
|
|
67
|
+
}
|
|
68
|
+
export declare function upgradeAccountWebTokenOnIngest(account: AccountInfo, _opts?: {
|
|
69
|
+
verifyLive?: boolean;
|
|
70
|
+
fetchImpl?: FetchLike;
|
|
71
|
+
maxPollAttempts?: number;
|
|
72
|
+
pollIntervalMs?: number;
|
|
73
|
+
}): Promise<IngestUpgradeResult>;
|
|
74
|
+
export declare function applyParsedCredentialToAccount(params: {
|
|
75
|
+
parsed: ReturnType<typeof TokenParser.parse>;
|
|
76
|
+
email: string;
|
|
77
|
+
existing?: AccountInfo;
|
|
78
|
+
usageRes?: Awaited<ReturnType<typeof OfficialApiClient.fetchUsage>>;
|
|
79
|
+
machineIds: AccountInfo['machine_ids'];
|
|
80
|
+
fallbackWorkosToToken?: boolean;
|
|
81
|
+
}): AccountInfo;
|