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
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cursor-Switch 数据模型与类型定义
|
|
3
|
-
* 100% 兼容 AoZai account_cache.json 数据结构
|
|
4
|
-
*/
|
|
5
1
|
export interface MachineIds {
|
|
6
2
|
'telemetry.devDeviceId': string;
|
|
7
3
|
'telemetry.macMachineId': string;
|
|
@@ -46,6 +42,12 @@ export interface AccountInfo {
|
|
|
46
42
|
period_usage_fetched_at?: string;
|
|
47
43
|
email_password?: string;
|
|
48
44
|
cursor_password?: string;
|
|
45
|
+
checkout_links?: {
|
|
46
|
+
pro?: string;
|
|
47
|
+
pro_plus?: string;
|
|
48
|
+
ultra?: string;
|
|
49
|
+
updated_at?: string;
|
|
50
|
+
};
|
|
49
51
|
}
|
|
50
52
|
export interface SwitchResult {
|
|
51
53
|
success: boolean;
|
|
@@ -57,4 +59,10 @@ export interface ResolvedCursorPaths {
|
|
|
57
59
|
storageJson: string;
|
|
58
60
|
sqliteDb: string;
|
|
59
61
|
executablePath?: string;
|
|
62
|
+
globalStorageDir?: string;
|
|
63
|
+
userDataDir?: string;
|
|
64
|
+
machineIdFile?: string;
|
|
65
|
+
authJson?: string;
|
|
66
|
+
cliConfigJson?: string;
|
|
67
|
+
localStateFile?: string;
|
|
60
68
|
}
|
package/dist/types.js
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AccountStore } from '../core/account-store.js';
|
|
2
|
+
export interface ParsedPublicLine {
|
|
3
|
+
email?: string;
|
|
4
|
+
emailPassword?: string;
|
|
5
|
+
cursorPassword?: string;
|
|
6
|
+
token?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function parsePublicAccountLine(rawLine: string): ParsedPublicLine | null;
|
|
9
|
+
export declare function importAccountsFromText(content: string, store: AccountStore): number;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { TokenParser } from '../core/token-parser.js';
|
|
2
|
+
import { generateMachineIds } from '../core/fingerprint.js';
|
|
3
|
+
const EMAIL_RE = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/;
|
|
4
|
+
function isLikelyCursorToken(raw) {
|
|
5
|
+
const s = (raw || '').trim();
|
|
6
|
+
if (!s)
|
|
7
|
+
return false;
|
|
8
|
+
if (s.includes('::') || /%3A%3A/i.test(s)) {
|
|
9
|
+
const jwtPart = TokenParser.extractTokenPart(s);
|
|
10
|
+
return TokenParser.isJwtShaped(jwtPart);
|
|
11
|
+
}
|
|
12
|
+
return TokenParser.isJwtShaped(s);
|
|
13
|
+
}
|
|
14
|
+
export function parsePublicAccountLine(rawLine) {
|
|
15
|
+
const line = (rawLine || '').trim();
|
|
16
|
+
if (!line || line.startsWith('#') || line.startsWith('//')) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
const normalized = line.replace(/\s*----\s*/g, '----');
|
|
20
|
+
if (normalized.includes('----')) {
|
|
21
|
+
const parts = normalized
|
|
22
|
+
.split('----')
|
|
23
|
+
.map((s) => s.trim())
|
|
24
|
+
.filter(Boolean);
|
|
25
|
+
if (parts.length === 0)
|
|
26
|
+
return null;
|
|
27
|
+
let email;
|
|
28
|
+
let token;
|
|
29
|
+
const rest = [];
|
|
30
|
+
for (const part of parts) {
|
|
31
|
+
if (!token && isLikelyCursorToken(part)) {
|
|
32
|
+
token = part;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (!email && EMAIL_RE.test(part)) {
|
|
36
|
+
email = part.toLowerCase();
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
rest.push(part);
|
|
40
|
+
}
|
|
41
|
+
if (!email && !token)
|
|
42
|
+
return null;
|
|
43
|
+
return {
|
|
44
|
+
email,
|
|
45
|
+
emailPassword: rest[0] || undefined,
|
|
46
|
+
cursorPassword: rest[1] || undefined,
|
|
47
|
+
token,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
if (isLikelyCursorToken(line)) {
|
|
51
|
+
const parsed = TokenParser.parse(line);
|
|
52
|
+
return {
|
|
53
|
+
email: parsed.email || undefined,
|
|
54
|
+
token: line,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
export function importAccountsFromText(content, store) {
|
|
60
|
+
const lines = String(content || '').split(/\r?\n/);
|
|
61
|
+
let count = 0;
|
|
62
|
+
for (const rawLine of lines) {
|
|
63
|
+
const seg = parsePublicAccountLine(rawLine);
|
|
64
|
+
if (!seg)
|
|
65
|
+
continue;
|
|
66
|
+
let email = seg.email;
|
|
67
|
+
let tokenStr = '';
|
|
68
|
+
let workosToken;
|
|
69
|
+
if (seg.token) {
|
|
70
|
+
const parsed = TokenParser.parse(seg.token);
|
|
71
|
+
tokenStr = parsed.token || TokenParser.extractTokenPart(seg.token);
|
|
72
|
+
if (seg.token.includes('::') || /%3A%3A/i.test(seg.token)) {
|
|
73
|
+
workosToken = seg.token.replace(/%3A%3A/gi, '::');
|
|
74
|
+
}
|
|
75
|
+
if (!email && parsed.email) {
|
|
76
|
+
email = parsed.email.toLowerCase();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (!email)
|
|
80
|
+
continue;
|
|
81
|
+
const existing = store.getByEmail(email);
|
|
82
|
+
const info = {
|
|
83
|
+
...(existing || {}),
|
|
84
|
+
email,
|
|
85
|
+
token: tokenStr || existing?.token || '',
|
|
86
|
+
workos_cursor_session_token: workosToken || existing?.workos_cursor_session_token,
|
|
87
|
+
email_password: seg.emailPassword || existing?.email_password,
|
|
88
|
+
cursor_password: seg.cursorPassword || existing?.cursor_password,
|
|
89
|
+
machine_ids: existing?.machine_ids || generateMachineIds(),
|
|
90
|
+
created_at: existing?.created_at || new Date().toISOString(),
|
|
91
|
+
};
|
|
92
|
+
store.addOrUpdate(info);
|
|
93
|
+
count++;
|
|
94
|
+
}
|
|
95
|
+
return count;
|
|
96
|
+
}
|
|
@@ -1,31 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 全平台多浏览器适配与 URL 安全调起引擎
|
|
3
|
-
* 支持 Windows (Chrome/Edge/Brave/Firefox/Arc) / macOS (Safari/Chrome/Arc) / Linux (Firefox/Chromium)
|
|
4
|
-
* 支持 WSL 环境自动穿透、无头服务器 (SSH) 优雅降级与跨浏览器 Cookie 免密注入
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* 跨操作系统与环境安全打开浏览器 URL
|
|
8
|
-
* 具备 WSL 穿透与无头/SSH 降级容错机制
|
|
9
|
-
*/
|
|
10
1
|
export declare function openBrowserUrl(url: string): Promise<boolean>;
|
|
11
|
-
/**
|
|
12
|
-
* 跨操作系统与环境以无痕/隐私窗口模式调起浏览器
|
|
13
|
-
* 确保打开一个全新的未登录实例,不携带历史 Cookie
|
|
14
|
-
*/
|
|
15
2
|
export declare function openIncognitoBrowserUrl(url: string): Promise<boolean>;
|
|
16
|
-
/**
|
|
17
|
-
* 动态探测本地常见浏览器安装路径 (多盘符扫描)
|
|
18
|
-
*/
|
|
19
3
|
export declare function findInstalledBrowsers(): {
|
|
20
4
|
name: string;
|
|
21
5
|
path: string;
|
|
22
6
|
}[];
|
|
23
|
-
/**
|
|
24
|
-
* 动态探测本地环境变量或当前目录中的免密脚本
|
|
25
|
-
*/
|
|
26
|
-
export declare function findPythonDashboardScript(): string | null;
|
|
27
|
-
/**
|
|
28
|
-
* 生成全浏览器通用的 1 行 Console 免密注入 JavaScript 代码
|
|
29
|
-
* 适用于任何浏览器 (Chrome / Edge / Safari / Firefox / Arc / Brave 等)
|
|
30
|
-
*/
|
|
31
7
|
export declare function getCookieInjectionSnippet(sessionToken: string): string;
|
|
@@ -1,25 +1,14 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 全平台多浏览器适配与 URL 安全调起引擎
|
|
3
|
-
* 支持 Windows (Chrome/Edge/Brave/Firefox/Arc) / macOS (Safari/Chrome/Arc) / Linux (Firefox/Chromium)
|
|
4
|
-
* 支持 WSL 环境自动穿透、无头服务器 (SSH) 优雅降级与跨浏览器 Cookie 免密注入
|
|
5
|
-
*/
|
|
6
1
|
import os from 'node:os';
|
|
7
2
|
import path from 'node:path';
|
|
8
3
|
import fs from 'node:fs';
|
|
9
4
|
import { spawn } from 'node:child_process';
|
|
10
5
|
import open from 'open';
|
|
11
|
-
/**
|
|
12
|
-
* 跨操作系统与环境安全打开浏览器 URL
|
|
13
|
-
* 具备 WSL 穿透与无头/SSH 降级容错机制
|
|
14
|
-
*/
|
|
15
6
|
export async function openBrowserUrl(url) {
|
|
16
|
-
// 1. WSL (Windows Subsystem for Linux) 自动穿透调用宿主 Windows 浏览器
|
|
17
7
|
const isWsl = Boolean(process.env.WSL_DISTRO_NAME ||
|
|
18
8
|
process.env.WSL_INTEROP ||
|
|
19
9
|
(fs.existsSync('/proc/version') && fs.readFileSync('/proc/version', 'utf8').toLowerCase().includes('microsoft')));
|
|
20
10
|
if (isWsl) {
|
|
21
11
|
try {
|
|
22
|
-
// 优先尝试 wslview,若无则调用 cmd.exe 穿透
|
|
23
12
|
const child = spawn('wslview', [url], { stdio: 'ignore' });
|
|
24
13
|
child.on('error', () => {
|
|
25
14
|
try {
|
|
@@ -32,7 +21,6 @@ export async function openBrowserUrl(url) {
|
|
|
32
21
|
}
|
|
33
22
|
catch { }
|
|
34
23
|
}
|
|
35
|
-
// 2. 调起系统默认浏览器 (使用 open 模块)
|
|
36
24
|
try {
|
|
37
25
|
const cp = await open(url);
|
|
38
26
|
if (cp && typeof cp.unref === 'function') {
|
|
@@ -41,7 +29,6 @@ export async function openBrowserUrl(url) {
|
|
|
41
29
|
return true;
|
|
42
30
|
}
|
|
43
31
|
catch { }
|
|
44
|
-
// 3. 降级原生 Shell 命令调起
|
|
45
32
|
try {
|
|
46
33
|
const platform = process.platform;
|
|
47
34
|
if (platform === 'win32') {
|
|
@@ -60,16 +47,11 @@ export async function openBrowserUrl(url) {
|
|
|
60
47
|
catch { }
|
|
61
48
|
return false;
|
|
62
49
|
}
|
|
63
|
-
/**
|
|
64
|
-
* 跨操作系统与环境以无痕/隐私窗口模式调起浏览器
|
|
65
|
-
* 确保打开一个全新的未登录实例,不携带历史 Cookie
|
|
66
|
-
*/
|
|
67
50
|
export async function openIncognitoBrowserUrl(url) {
|
|
68
51
|
const platform = process.platform;
|
|
69
52
|
const isWsl = Boolean(process.env.WSL_DISTRO_NAME ||
|
|
70
53
|
process.env.WSL_INTEROP ||
|
|
71
54
|
(fs.existsSync('/proc/version') && fs.readFileSync('/proc/version', 'utf8').toLowerCase().includes('microsoft')));
|
|
72
|
-
// 1. WSL 环境穿透宿主 Windows 浏览器无痕窗口
|
|
73
55
|
if (isWsl) {
|
|
74
56
|
try {
|
|
75
57
|
spawn('/mnt/c/Windows/System32/cmd.exe', ['/c', 'start', '""', 'chrome', '--incognito', `"${url}"`], { stdio: 'ignore' }).unref();
|
|
@@ -82,10 +64,8 @@ export async function openIncognitoBrowserUrl(url) {
|
|
|
82
64
|
}
|
|
83
65
|
catch { }
|
|
84
66
|
}
|
|
85
|
-
// 2. Windows 平台
|
|
86
67
|
if (platform === 'win32') {
|
|
87
68
|
const installed = findInstalledBrowsers();
|
|
88
|
-
// 优先尝试 Google Chrome
|
|
89
69
|
const chrome = installed.find((b) => b.name.includes('Chrome'));
|
|
90
70
|
if (chrome && fs.existsSync(chrome.path)) {
|
|
91
71
|
try {
|
|
@@ -95,7 +75,6 @@ export async function openIncognitoBrowserUrl(url) {
|
|
|
95
75
|
}
|
|
96
76
|
catch { }
|
|
97
77
|
}
|
|
98
|
-
// 次选 Microsoft Edge
|
|
99
78
|
const edge = installed.find((b) => b.name.includes('Edge'));
|
|
100
79
|
if (edge && fs.existsSync(edge.path)) {
|
|
101
80
|
try {
|
|
@@ -105,7 +84,6 @@ export async function openIncognitoBrowserUrl(url) {
|
|
|
105
84
|
}
|
|
106
85
|
catch { }
|
|
107
86
|
}
|
|
108
|
-
// Brave
|
|
109
87
|
const brave = installed.find((b) => b.name.includes('Brave'));
|
|
110
88
|
if (brave && fs.existsSync(brave.path)) {
|
|
111
89
|
try {
|
|
@@ -115,7 +93,6 @@ export async function openIncognitoBrowserUrl(url) {
|
|
|
115
93
|
}
|
|
116
94
|
catch { }
|
|
117
95
|
}
|
|
118
|
-
// Firefox
|
|
119
96
|
const firefox = installed.find((b) => b.name.includes('Firefox'));
|
|
120
97
|
if (firefox && fs.existsSync(firefox.path)) {
|
|
121
98
|
try {
|
|
@@ -125,7 +102,6 @@ export async function openIncognitoBrowserUrl(url) {
|
|
|
125
102
|
}
|
|
126
103
|
catch { }
|
|
127
104
|
}
|
|
128
|
-
// 降级尝试系统命令唤起
|
|
129
105
|
try {
|
|
130
106
|
spawn('cmd.exe', ['/c', 'start', '""', 'chrome', '--incognito', `"${url}"`], { detached: true, stdio: 'ignore', windowsVerbatimArguments: true }).unref();
|
|
131
107
|
return true;
|
|
@@ -138,7 +114,6 @@ export async function openIncognitoBrowserUrl(url) {
|
|
|
138
114
|
catch { }
|
|
139
115
|
}
|
|
140
116
|
else if (platform === 'darwin') {
|
|
141
|
-
// macOS
|
|
142
117
|
try {
|
|
143
118
|
spawn('open', ['-na', 'Google Chrome', '--args', '--incognito', url], { detached: true, stdio: 'ignore' }).unref();
|
|
144
119
|
return true;
|
|
@@ -156,7 +131,6 @@ export async function openIncognitoBrowserUrl(url) {
|
|
|
156
131
|
catch { }
|
|
157
132
|
}
|
|
158
133
|
else {
|
|
159
|
-
// Linux
|
|
160
134
|
const linuxAttempts = [
|
|
161
135
|
{ cmd: 'google-chrome', args: ['--incognito', url] },
|
|
162
136
|
{ cmd: 'microsoft-edge', args: ['--inprivate', url] },
|
|
@@ -173,12 +147,8 @@ export async function openIncognitoBrowserUrl(url) {
|
|
|
173
147
|
catch { }
|
|
174
148
|
}
|
|
175
149
|
}
|
|
176
|
-
// 终极降级: 使用标准浏览器打开
|
|
177
150
|
return openBrowserUrl(url);
|
|
178
151
|
}
|
|
179
|
-
/**
|
|
180
|
-
* 动态探测本地常见浏览器安装路径 (多盘符扫描)
|
|
181
|
-
*/
|
|
182
152
|
export function findInstalledBrowsers() {
|
|
183
153
|
const platform = process.platform;
|
|
184
154
|
const browsers = [];
|
|
@@ -205,7 +175,6 @@ export function findInstalledBrowsers() {
|
|
|
205
175
|
}
|
|
206
176
|
}
|
|
207
177
|
}
|
|
208
|
-
// LocalAppData 目录 (针对用户态免提权安装的 Chrome / Arc)
|
|
209
178
|
const localAppData = process.env.LOCALAPPDATA || path.join(os.homedir(), 'AppData', 'Local');
|
|
210
179
|
const localCandidates = [
|
|
211
180
|
{ name: 'Google Chrome (User)', full: path.join(localAppData, 'Google', 'Chrome', 'Application', 'chrome.exe') },
|
|
@@ -236,7 +205,6 @@ export function findInstalledBrowsers() {
|
|
|
236
205
|
}
|
|
237
206
|
}
|
|
238
207
|
else {
|
|
239
|
-
// Linux
|
|
240
208
|
const linuxBinaries = [
|
|
241
209
|
{ name: 'Google Chrome', bin: '/usr/bin/google-chrome' },
|
|
242
210
|
{ name: 'Chromium', bin: '/usr/bin/chromium-browser' },
|
|
@@ -252,31 +220,6 @@ export function findInstalledBrowsers() {
|
|
|
252
220
|
}
|
|
253
221
|
return browsers;
|
|
254
222
|
}
|
|
255
|
-
/**
|
|
256
|
-
* 动态探测本地环境变量或当前目录中的免密脚本
|
|
257
|
-
*/
|
|
258
|
-
export function findPythonDashboardScript() {
|
|
259
|
-
const envScript = process.env.CURSOR_DASHBOARD_SCRIPT;
|
|
260
|
-
if (envScript && fs.existsSync(envScript)) {
|
|
261
|
-
return envScript;
|
|
262
|
-
}
|
|
263
|
-
const cwd = process.cwd();
|
|
264
|
-
const candidates = [
|
|
265
|
-
path.join(cwd, 'scripts', 'open_cursor_dashboard.cmd'),
|
|
266
|
-
path.join(cwd, 'scripts', 'open_cursor_dashboard.py'),
|
|
267
|
-
path.join(os.homedir(), '.cursor-switch', 'scripts', 'open_cursor_dashboard.py'),
|
|
268
|
-
];
|
|
269
|
-
for (const cand of candidates) {
|
|
270
|
-
if (fs.existsSync(cand)) {
|
|
271
|
-
return cand;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
return null;
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* 生成全浏览器通用的 1 行 Console 免密注入 JavaScript 代码
|
|
278
|
-
* 适用于任何浏览器 (Chrome / Edge / Safari / Firefox / Arc / Brave 等)
|
|
279
|
-
*/
|
|
280
223
|
export function getCookieInjectionSnippet(sessionToken) {
|
|
281
224
|
const token = sessionToken.trim().replace(/["\r\n]/g, '');
|
|
282
225
|
return `document.cookie="WorkosCursorSessionToken=${token};domain=.cursor.com;path=/;max-age=31536000;secure";location.reload();`;
|
package/dist/utils/clipboard.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 跨操作系统零依赖系统剪贴板拷贝工具
|
|
3
|
-
* 原生支持 Windows (clip.exe), macOS (pbcopy), Linux (wl-copy / xclip)
|
|
4
|
-
*/
|
|
5
1
|
import { spawn } from 'node:child_process';
|
|
6
2
|
export function copyToClipboard(text) {
|
|
7
3
|
return new Promise((resolve) => {
|
|
@@ -16,7 +12,6 @@ export function copyToClipboard(text) {
|
|
|
16
12
|
args = [];
|
|
17
13
|
}
|
|
18
14
|
else {
|
|
19
|
-
// Linux: 优先测试 Wayland wl-copy,否则回退到 xclip / xsel
|
|
20
15
|
if (process.env.WAYLAND_DISPLAY) {
|
|
21
16
|
cmd = 'wl-copy';
|
|
22
17
|
args = [];
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { AccountInfo, MachineIds } from '../types.js';
|
|
2
|
+
import { ConfigStore } from '../core/config-store.js';
|
|
3
|
+
import { type CredentialBundles } from '../core/token-parser.js';
|
|
4
|
+
export type RequestedCopyFormat = 'single' | 'triple' | 'web' | 'json';
|
|
5
|
+
export declare function normalizeCopyFormatInput(raw?: string): RequestedCopyFormat | undefined;
|
|
6
|
+
export declare function resolveAccountCopyPayload(account: AccountInfo, opts?: {
|
|
7
|
+
format?: RequestedCopyFormat;
|
|
8
|
+
separator?: string;
|
|
9
|
+
configStore?: ConfigStore;
|
|
10
|
+
}): {
|
|
11
|
+
resolvedFormat: RequestedCopyFormat;
|
|
12
|
+
text: string;
|
|
13
|
+
bundles: CredentialBundles;
|
|
14
|
+
fallbackReason?: string;
|
|
15
|
+
};
|
|
16
|
+
export declare function copyPreferredAccountCredential(account: AccountInfo, opts?: {
|
|
17
|
+
format?: RequestedCopyFormat;
|
|
18
|
+
separator?: string;
|
|
19
|
+
configStore?: ConfigStore;
|
|
20
|
+
}): Promise<{
|
|
21
|
+
copied: boolean;
|
|
22
|
+
resolvedFormat: RequestedCopyFormat;
|
|
23
|
+
text: string;
|
|
24
|
+
bundles: CredentialBundles;
|
|
25
|
+
fallbackReason?: string;
|
|
26
|
+
}>;
|
|
27
|
+
export declare function renderCredentialSummaryLines(bundles: CredentialBundles, copiedFormat?: RequestedCopyFormat): string[];
|
|
28
|
+
export declare function printExtractedCredentialsResult(params: {
|
|
29
|
+
header: string;
|
|
30
|
+
account: AccountInfo;
|
|
31
|
+
machineIds: MachineIds;
|
|
32
|
+
copyFormat?: RequestedCopyFormat;
|
|
33
|
+
configStore?: ConfigStore;
|
|
34
|
+
showPlaintext?: boolean;
|
|
35
|
+
}): Promise<Awaited<ReturnType<typeof copyPreferredAccountCredential>>>;
|
|
36
|
+
export declare function runInteractiveCopyAccountMenu(account: AccountInfo, configStore?: ConfigStore): Promise<void>;
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import boxen from 'boxen';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { ConfigStore } from '../core/config-store.js';
|
|
4
|
+
import { formatMachineIdSummary } from '../core/fingerprint.js';
|
|
5
|
+
import { TokenParser, } from '../core/token-parser.js';
|
|
6
|
+
import { copyToClipboard } from './clipboard.js';
|
|
7
|
+
import { quickSelect, Separator } from './live-menu.js';
|
|
8
|
+
import { formatPlanBadge } from './plan-formatter.js';
|
|
9
|
+
import { safePressAnyKey } from './prompt-utils.js';
|
|
10
|
+
export function normalizeCopyFormatInput(raw) {
|
|
11
|
+
const val = (raw || '').trim().toLowerCase();
|
|
12
|
+
if (!val)
|
|
13
|
+
return undefined;
|
|
14
|
+
if (val === '1' || val === 'single' || val === 'jwt' || val === 'access')
|
|
15
|
+
return 'single';
|
|
16
|
+
if (val === '3' || val === 'triple' || val === 'bundle' || val === 'pack')
|
|
17
|
+
return 'triple';
|
|
18
|
+
if (val === 'web' || val === 'session' || val === 'workos')
|
|
19
|
+
return 'web';
|
|
20
|
+
if (val === 'json' || val === 'full')
|
|
21
|
+
return 'json';
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
export function resolveAccountCopyPayload(account, opts = {}) {
|
|
25
|
+
const bundles = TokenParser.formatCredentialBundles(account, { separator: opts.separator });
|
|
26
|
+
const cfgStore = opts.configStore || new ConfigStore();
|
|
27
|
+
const desired = opts.format || cfgStore.getPreferredCopyFormat();
|
|
28
|
+
if (desired === 'json') {
|
|
29
|
+
const jsonPayload = JSON.stringify({
|
|
30
|
+
email: account.email,
|
|
31
|
+
token: bundles.accessToken || account.token,
|
|
32
|
+
refresh_token: bundles.refreshToken || undefined,
|
|
33
|
+
workos_cursor_session_token: bundles.workosToken || account.workos_cursor_session_token || undefined,
|
|
34
|
+
machine_ids: account.machine_ids,
|
|
35
|
+
}, null, 2);
|
|
36
|
+
return { resolvedFormat: 'json', text: jsonPayload, bundles };
|
|
37
|
+
}
|
|
38
|
+
if (desired === 'triple') {
|
|
39
|
+
if (bundles.tripleBundle) {
|
|
40
|
+
return { resolvedFormat: 'triple', text: bundles.tripleBundle, bundles };
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
resolvedFormat: 'single',
|
|
44
|
+
text: bundles.singleToken,
|
|
45
|
+
bundles,
|
|
46
|
+
fallbackReason: '该账号暂缺可用 refresh_token,暂不能组成完整三段包,已自动改为提供一段凭据',
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
if (desired === 'web') {
|
|
50
|
+
if (bundles.workosToken) {
|
|
51
|
+
return { resolvedFormat: 'web', text: bundles.workosToken, bundles };
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
resolvedFormat: 'single',
|
|
55
|
+
text: bundles.singleToken,
|
|
56
|
+
bundles,
|
|
57
|
+
fallbackReason: '该账号未存独立 WorkOS Web Cookie,已改为提供主凭据',
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
resolvedFormat: 'single',
|
|
62
|
+
text: bundles.singleToken,
|
|
63
|
+
bundles,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export async function copyPreferredAccountCredential(account, opts = {}) {
|
|
67
|
+
const resolved = resolveAccountCopyPayload(account, opts);
|
|
68
|
+
const copied = await copyToClipboard(resolved.text);
|
|
69
|
+
return { copied, ...resolved };
|
|
70
|
+
}
|
|
71
|
+
function previewToken(text) {
|
|
72
|
+
if (text.length <= 28)
|
|
73
|
+
return text;
|
|
74
|
+
return `${text.slice(0, 14)}...${text.slice(-10)}`;
|
|
75
|
+
}
|
|
76
|
+
const FORMAT_LABELS = {
|
|
77
|
+
single: '一段单凭据',
|
|
78
|
+
triple: '三段完整凭据 (Access----Refresh----Web)',
|
|
79
|
+
web: '一段 WorkOS Web 凭据',
|
|
80
|
+
json: '完整 JSON 配置',
|
|
81
|
+
};
|
|
82
|
+
export function renderCredentialSummaryLines(bundles, copiedFormat) {
|
|
83
|
+
const badge = TokenParser.formatCredentialBadge(bundles.classification);
|
|
84
|
+
const stateDesc = bundles.classification.credentialState === 'client_with_rt'
|
|
85
|
+
? chalk.green(`${badge} · 客户端双票 + 网页凭据完整`)
|
|
86
|
+
: bundles.classification.credentialState === 'web_only'
|
|
87
|
+
? chalk.yellow(`${badge} · 仅网页 Cookie(暂缺 60 天 refresh_token)`)
|
|
88
|
+
: chalk.cyan(badge);
|
|
89
|
+
const lines = [
|
|
90
|
+
` 凭据形态 : ${stateDesc}`,
|
|
91
|
+
` 一段凭据 : ${chalk.grey(previewToken(bundles.singleToken))} ${chalk.dim(`(${bundles.singleToken.length} 字符)`)}`,
|
|
92
|
+
];
|
|
93
|
+
if (bundles.tripleBundle) {
|
|
94
|
+
lines.push(` 三段全票 : ${chalk.cyan(previewToken(bundles.tripleBundle))} ${chalk.dim(`(Access----Refresh----Web,共 ${bundles.tripleBundle.length} 字符)`)}`);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
lines.push(` 三段全票 : ${chalk.dim('暂不可用(缺少 refresh_token,仅可提供一段)')}`);
|
|
98
|
+
}
|
|
99
|
+
if (copiedFormat) {
|
|
100
|
+
lines.push(` 当前已复制: ${chalk.white(FORMAT_LABELS[copiedFormat])}`);
|
|
101
|
+
}
|
|
102
|
+
return lines;
|
|
103
|
+
}
|
|
104
|
+
export async function printExtractedCredentialsResult(params) {
|
|
105
|
+
const { header, account, machineIds, copyFormat, configStore, showPlaintext } = params;
|
|
106
|
+
const res = await copyPreferredAccountCredential(account, { format: copyFormat, configStore });
|
|
107
|
+
console.log(boxen([
|
|
108
|
+
chalk.bold.green(header),
|
|
109
|
+
chalk.dim('────────────────────────────────────────────────'),
|
|
110
|
+
` 登录邮箱 : ${chalk.bold.white(account.email)}`,
|
|
111
|
+
` 会员级别 : ${formatPlanBadge(account.subscription_type)}`,
|
|
112
|
+
` 专属指纹 : ${chalk.cyan(formatMachineIdSummary(machineIds))}`,
|
|
113
|
+
...renderCredentialSummaryLines(res.bundles, res.resolvedFormat),
|
|
114
|
+
` 系统剪贴板: ${res.copied ? chalk.green('✔ 已自动写入系统剪贴板 (随时 Ctrl+V 粘贴)') : chalk.yellow('○ 剪贴板未生效,可在下方或 copy 菜单获取')}`,
|
|
115
|
+
].join('\n'), { padding: { top: 0, bottom: 0, left: 1, right: 1 }, borderColor: 'green', borderStyle: 'round' }));
|
|
116
|
+
if (res.fallbackReason) {
|
|
117
|
+
console.log(chalk.yellow(`! 提示: ${res.fallbackReason}`));
|
|
118
|
+
}
|
|
119
|
+
if (showPlaintext) {
|
|
120
|
+
console.log(chalk.bold.white('\n📋 一段凭据 (单 Token):'));
|
|
121
|
+
console.log(chalk.cyan(res.bundles.singleToken));
|
|
122
|
+
if (res.bundles.tripleBundle) {
|
|
123
|
+
console.log(chalk.bold.white('\n📦 三段完整凭据 (AccessToken----RefreshToken----WorkosSessionToken):'));
|
|
124
|
+
console.log(chalk.green(res.bundles.tripleBundle));
|
|
125
|
+
console.log(chalk.dim('\n提示: 使用 cswitch copy -f 3 可随时一键复制三段打包串(或设默认偏好为三段)。\n'));
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
console.log('');
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else if (!res.copied) {
|
|
132
|
+
console.log(chalk.yellow('\n提示: 自动写入剪贴板未生效,已回退输出本次凭据:'));
|
|
133
|
+
console.log(chalk.cyan(res.text) + '\n');
|
|
134
|
+
}
|
|
135
|
+
return res;
|
|
136
|
+
}
|
|
137
|
+
export async function runInteractiveCopyAccountMenu(account, configStore = new ConfigStore()) {
|
|
138
|
+
while (true) {
|
|
139
|
+
const bundles = TokenParser.formatCredentialBundles(account);
|
|
140
|
+
const hasDistinctWeb = Boolean(bundles.workosToken && bundles.workosToken !== bundles.singleToken);
|
|
141
|
+
const currentPref = configStore.getPreferredCopyFormat();
|
|
142
|
+
const choices = [];
|
|
143
|
+
choices.push({
|
|
144
|
+
name: `1. 复制一段 · ${bundles.classification.tokenType === 'web' ? 'WorkOS Web Cookie (user_xxx::...)' : 'Access Token (原生 Bearer JWT eyJ...)'}`,
|
|
145
|
+
value: 'single',
|
|
146
|
+
key: '1',
|
|
147
|
+
description: '单段主凭据,适合第三方工具、Bearer API 或即取即用场景',
|
|
148
|
+
});
|
|
149
|
+
if (hasDistinctWeb) {
|
|
150
|
+
choices.push({
|
|
151
|
+
name: '2. 复制一段 · WorkOS Session Token (官网 Cookie user_xxx::...)',
|
|
152
|
+
value: 'web',
|
|
153
|
+
key: '2',
|
|
154
|
+
description: '网页 Cookie 凭据,适合官网 dash、购买续费或退款服务',
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
const tripleKey = hasDistinctWeb ? '3' : '2';
|
|
158
|
+
if (bundles.tripleBundle) {
|
|
159
|
+
choices.push({
|
|
160
|
+
name: `${tripleKey}. 复制三段 · 完整防过期包 (Access----Refresh----Web) [防过期推荐]`,
|
|
161
|
+
value: 'triple',
|
|
162
|
+
key: tripleKey,
|
|
163
|
+
description: '包含 60 天客户端 Access + Refresh + 网页 Session 三件套,粘贴回 cswitch 即可完整恢复',
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
choices.push({
|
|
168
|
+
name: `${tripleKey}. 复制三段 · (当前缺 refresh_token,仅可提供一段)`,
|
|
169
|
+
value: 'triple_unavailable',
|
|
170
|
+
disabled: '需先通过浏览器 OAuth 或纯净代登取得 refresh_token',
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
const jsonKey = hasDistinctWeb ? '4' : '3';
|
|
174
|
+
choices.push({
|
|
175
|
+
name: `${jsonKey}. 一键复制完整账号配置 (JSON 格式,含 refresh_token 与指纹)`,
|
|
176
|
+
value: 'json',
|
|
177
|
+
key: jsonKey,
|
|
178
|
+
description: '导出包含邮箱、三类凭据及机器指纹的完整 JSON 备份',
|
|
179
|
+
});
|
|
180
|
+
const viewKey = hasDistinctWeb ? '5' : '4';
|
|
181
|
+
choices.push({
|
|
182
|
+
name: `${viewKey}. 查看凭据完整明文 (终端打印一段 / 三段 / Refresh Token)`,
|
|
183
|
+
value: 'view',
|
|
184
|
+
key: viewKey,
|
|
185
|
+
description: '在终端屏幕上完整输出当前账号可用凭据明文',
|
|
186
|
+
});
|
|
187
|
+
choices.push({
|
|
188
|
+
name: `d. 切换默认复制格式 (当前默认: ${currentPref === 'triple' ? chalk.cyan('三段完整包') : chalk.green('一段单凭据')})`,
|
|
189
|
+
value: 'toggle_default',
|
|
190
|
+
key: 'd',
|
|
191
|
+
description: '影响 cswitch copy、代登及 OAuth 完成后的默认剪贴板写入格式',
|
|
192
|
+
});
|
|
193
|
+
choices.push(new Separator());
|
|
194
|
+
choices.push({ name: '0. 返回上一级', value: '__back__', key: '0' });
|
|
195
|
+
const pick = await quickSelect({
|
|
196
|
+
message: `请选择要提供的凭据形态 [${account.email}] (${TokenParser.formatCredentialBadge(bundles.classification)}):`,
|
|
197
|
+
choices,
|
|
198
|
+
});
|
|
199
|
+
if (pick === '__back__' || !pick)
|
|
200
|
+
return;
|
|
201
|
+
if (pick === 'toggle_default') {
|
|
202
|
+
const next = currentPref === 'triple' ? 'single' : 'triple';
|
|
203
|
+
configStore.setPreferredCopyFormat(next);
|
|
204
|
+
console.log(chalk.green(`\n✔ 已将默认自动复制格式切换为:【${next === 'triple' ? '三段完整包 (Access----Refresh----Web)' : '一段单凭据'}】\n`));
|
|
205
|
+
await safePressAnyKey();
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
if (pick === 'view') {
|
|
209
|
+
console.log(chalk.bold.cyan(`\n● 账号 ${account.email} 凭据明文详情 (${TokenParser.formatCredentialBadge(bundles.classification)}):\n`));
|
|
210
|
+
console.log(chalk.white('【一段 · 主凭据 (Access / Single)】:'));
|
|
211
|
+
console.log(chalk.green(bundles.singleToken) + '\n');
|
|
212
|
+
if (bundles.refreshToken) {
|
|
213
|
+
console.log(chalk.white('【60 天 Refresh Token】:'));
|
|
214
|
+
console.log(chalk.cyan(bundles.refreshToken) + '\n');
|
|
215
|
+
}
|
|
216
|
+
if (bundles.workosToken && bundles.workosToken !== bundles.singleToken) {
|
|
217
|
+
console.log(chalk.white('【一段 · WorkOS Web Cookie】:'));
|
|
218
|
+
console.log(chalk.cyan(bundles.workosToken) + '\n');
|
|
219
|
+
}
|
|
220
|
+
if (bundles.tripleBundle) {
|
|
221
|
+
console.log(chalk.white('【三段 · 完整打包串 (Access----Refresh----Web)】:'));
|
|
222
|
+
console.log(chalk.yellow(bundles.tripleBundle) + '\n');
|
|
223
|
+
}
|
|
224
|
+
await safePressAnyKey();
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
const fmt = pick;
|
|
228
|
+
const copyRes = await copyPreferredAccountCredential(account, {
|
|
229
|
+
format: fmt,
|
|
230
|
+
configStore,
|
|
231
|
+
});
|
|
232
|
+
console.log(boxen([
|
|
233
|
+
chalk.bold.green(`✔ 已复制【${FORMAT_LABELS[copyRes.resolvedFormat]}】到系统剪贴板!`),
|
|
234
|
+
chalk.dim('────────────────────────────────────────────────'),
|
|
235
|
+
` 账号邮箱 : ${chalk.bold.white(account.email)}`,
|
|
236
|
+
` 凭据预览 : ${chalk.dim(previewToken(copyRes.text))} ${chalk.grey(`(共 ${copyRes.text.length} 字符)`)}`,
|
|
237
|
+
` 操作提示 : ${chalk.yellow('随时使用 Ctrl+V (或 Cmd+V) 粘贴即可')}`,
|
|
238
|
+
].join('\n'), { padding: { top: 0, bottom: 0, left: 1, right: 1 }, borderColor: 'green', borderStyle: 'round' }));
|
|
239
|
+
if (!copyRes.copied) {
|
|
240
|
+
console.log(chalk.yellow('提示: 自动写入剪贴板未生效,以下为明文内容:'));
|
|
241
|
+
console.log(chalk.grey(copyRes.text) + '\n');
|
|
242
|
+
}
|
|
243
|
+
await safePressAnyKey();
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
}
|