cursor-switch 1.0.7 → 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 -241
- 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 +0 -20
- package/dist/core/dashboard-launcher.js +3 -53
- 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 -31
- package/dist/core/outlook-launcher.js +194 -248
- 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 +54 -38
- package/dist/core/pure-login-service.js +483 -395
- 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 -548
- 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/core/welcome-offer-service.d.ts +0 -52
- package/dist/core/welcome-offer-service.js +0 -369
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { ensureGlobalProxy } from '../utils/proxy-bootstrap.js';
|
|
2
|
+
import { TokenParser } from './token-parser.js';
|
|
3
|
+
export const CURSOR_OAUTH_CLIENT_ID = 'KbZUR41cY7W6zRSdpSUJ7I7mLYBKOCmB';
|
|
4
|
+
const TOKEN_REFRESH_URL = 'https://api2.cursor.sh/oauth/token';
|
|
5
|
+
const WEB_USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36';
|
|
6
|
+
export function resolveSessionPair(params) {
|
|
7
|
+
const rawSession = (params.workosSessionToken || '').trim().replace(/%3A/gi, ':');
|
|
8
|
+
const rawToken = (params.token || '').trim().replace(/%3A/gi, ':');
|
|
9
|
+
let jwt = '';
|
|
10
|
+
let userId = (params.userId || '').trim();
|
|
11
|
+
if (rawToken) {
|
|
12
|
+
jwt = TokenParser.extractTokenPart(rawToken);
|
|
13
|
+
userId = userId || TokenParser.extractUserId(rawToken) || '';
|
|
14
|
+
}
|
|
15
|
+
if (!jwt && rawSession) {
|
|
16
|
+
jwt = TokenParser.extractTokenPart(rawSession);
|
|
17
|
+
}
|
|
18
|
+
if (!userId && rawSession) {
|
|
19
|
+
userId = TokenParser.extractUserId(rawSession) || '';
|
|
20
|
+
}
|
|
21
|
+
const cookieJwt = rawSession && rawSession.includes('::') && TokenParser.isJwtShaped(TokenParser.extractTokenPart(rawSession))
|
|
22
|
+
? TokenParser.extractTokenPart(rawSession)
|
|
23
|
+
: jwt;
|
|
24
|
+
const sessionCookieValue = userId && cookieJwt ? `${userId}::${cookieJwt}` : undefined;
|
|
25
|
+
return { userId: userId || undefined, jwt: cookieJwt || jwt, sessionCookieValue };
|
|
26
|
+
}
|
|
27
|
+
export async function refreshClientAccessToken(refreshToken, fetchImpl = fetch) {
|
|
28
|
+
ensureGlobalProxy();
|
|
29
|
+
const rt = refreshToken.trim();
|
|
30
|
+
if (!rt || rt.includes('::')) {
|
|
31
|
+
return { ok: false, error: '无效的客户端 refresh_token(不能包含 user_xxx:: Cookie 前缀)' };
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
const res = await fetchImpl(TOKEN_REFRESH_URL, {
|
|
35
|
+
method: 'POST',
|
|
36
|
+
headers: {
|
|
37
|
+
'Content-Type': 'application/json',
|
|
38
|
+
Accept: 'application/json',
|
|
39
|
+
'User-Agent': WEB_USER_AGENT,
|
|
40
|
+
},
|
|
41
|
+
body: JSON.stringify({
|
|
42
|
+
grant_type: 'refresh_token',
|
|
43
|
+
client_id: CURSOR_OAUTH_CLIENT_ID,
|
|
44
|
+
refresh_token: rt,
|
|
45
|
+
}),
|
|
46
|
+
signal: AbortSignal.timeout(10000),
|
|
47
|
+
});
|
|
48
|
+
const data = (await res.json().catch(() => null));
|
|
49
|
+
const errCode = typeof data?.error === 'string' ? data.error.toLowerCase() : '';
|
|
50
|
+
if (res.status === 401 ||
|
|
51
|
+
res.status === 403 ||
|
|
52
|
+
data?.shouldLogout === true ||
|
|
53
|
+
(res.status === 400 && (errCode === 'invalid_grant' || errCode === 'expired_token'))) {
|
|
54
|
+
return {
|
|
55
|
+
ok: false,
|
|
56
|
+
status: res.status,
|
|
57
|
+
shouldLogout: true,
|
|
58
|
+
error: data?.error || `服务端拒绝续期并要求登出 (HTTP ${res.status})`,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (!res.ok) {
|
|
62
|
+
return {
|
|
63
|
+
ok: false,
|
|
64
|
+
status: res.status,
|
|
65
|
+
error: `oauth/token 返回 HTTP ${res.status}`,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const newAccessToken = typeof data?.access_token === 'string' ? data.access_token.trim() : '';
|
|
69
|
+
if (!newAccessToken) {
|
|
70
|
+
return { ok: false, status: res.status, error: 'oauth/token 响应缺少 access_token' };
|
|
71
|
+
}
|
|
72
|
+
const rotatedRefresh = typeof data?.refresh_token === 'string' && data.refresh_token.trim()
|
|
73
|
+
? data.refresh_token.trim()
|
|
74
|
+
: rt;
|
|
75
|
+
return {
|
|
76
|
+
ok: true,
|
|
77
|
+
accessToken: newAccessToken,
|
|
78
|
+
refreshToken: rotatedRefresh,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
return { ok: false, error: err?.message || String(err) };
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
export async function resolveSwitchCredentials(account, opts = {}) {
|
|
86
|
+
const warnings = [];
|
|
87
|
+
const effectiveRefreshInput = TokenParser.extractEffectiveRefreshToken(account.token, account.refresh_token, account.workos_cursor_session_token);
|
|
88
|
+
const classified = TokenParser.classify(account.token, effectiveRefreshInput);
|
|
89
|
+
let accessToken = classified.cleanToken;
|
|
90
|
+
let refreshToken = classified.cleanRefreshToken || accessToken;
|
|
91
|
+
let authId = classified.authId;
|
|
92
|
+
let userId = classified.userId;
|
|
93
|
+
let tokenType = classified.tokenType;
|
|
94
|
+
let upgradedFromWeb = false;
|
|
95
|
+
let refreshed = false;
|
|
96
|
+
let shouldLogout = false;
|
|
97
|
+
let preflightIssue;
|
|
98
|
+
const pair = resolveSessionPair({
|
|
99
|
+
token: account.token,
|
|
100
|
+
workosSessionToken: account.workos_cursor_session_token,
|
|
101
|
+
userId,
|
|
102
|
+
});
|
|
103
|
+
let workosSessionToken = pair.sessionCookieValue;
|
|
104
|
+
const rawPrimaryJwtType = String(TokenParser.parseJwtPayload(classified.cleanToken)?.type || '').toLowerCase();
|
|
105
|
+
const needsSessionConversionFromWeb = rawPrimaryJwtType === 'web' && classified.hasUsableRefreshToken;
|
|
106
|
+
if (opts.autoRefreshExpiring !== false &&
|
|
107
|
+
classified.hasUsableRefreshToken &&
|
|
108
|
+
classified.cleanRefreshToken &&
|
|
109
|
+
(classified.isExpired || classified.isExpiringSoon || needsSessionConversionFromWeb)) {
|
|
110
|
+
const refreshRes = await refreshClientAccessToken(classified.cleanRefreshToken, opts.fetchImpl);
|
|
111
|
+
if (refreshRes.ok && refreshRes.accessToken) {
|
|
112
|
+
accessToken = refreshRes.accessToken;
|
|
113
|
+
refreshToken = refreshRes.refreshToken || classified.cleanRefreshToken;
|
|
114
|
+
authId = TokenParser.extractAuthId(accessToken) || authId;
|
|
115
|
+
userId = TokenParser.extractUserId(accessToken) || userId;
|
|
116
|
+
tokenType = 'client';
|
|
117
|
+
refreshed = true;
|
|
118
|
+
}
|
|
119
|
+
else if (refreshRes.shouldLogout) {
|
|
120
|
+
shouldLogout = true;
|
|
121
|
+
warnings.push(`原有 refresh_token 已被官方失效 (${refreshRes.error || 'shouldLogout'}),切入后可能需要重新授权`);
|
|
122
|
+
preflightIssue = {
|
|
123
|
+
kind: 'refresh_revoked',
|
|
124
|
+
severity: 'blocking',
|
|
125
|
+
title: '该账号原授权已被官方失效,无法用老凭据换取新 Token',
|
|
126
|
+
reason: `官方刷新接口返回失效信号 (${refreshRes.error || 'shouldLogout'}),切入 Cursor 客户端后极可能立即要求重新登录。`,
|
|
127
|
+
recommendation: '建议先通过「纯净云端代登 (cswitch pure)」或「浏览器 OAuth (cswitch oauth)」重新登录获取最新凭据。',
|
|
128
|
+
ageHours: classified.ageHours,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
else if (refreshRes.error) {
|
|
132
|
+
warnings.push(`临期自动续期跳过 (${refreshRes.error}),将继续写入现有凭据`);
|
|
133
|
+
if (classified.isExpired) {
|
|
134
|
+
preflightIssue = {
|
|
135
|
+
kind: 'token_expired',
|
|
136
|
+
severity: 'blocking',
|
|
137
|
+
title: '该账号 Access Token 已过期且本次自动续期失败',
|
|
138
|
+
reason: `原有令牌已过期且刷新失败 (${refreshRes.error}),直接写入客户端后很可能无法正常使用。`,
|
|
139
|
+
recommendation: '请检查网络代理后重试,或重新通过 cswitch pure / cswitch oauth 获取新 Token。',
|
|
140
|
+
ageHours: classified.ageHours,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
else if (classified.isExpired && !classified.hasUsableRefreshToken && classified.tokenType !== 'web') {
|
|
146
|
+
preflightIssue = {
|
|
147
|
+
kind: 'token_expired',
|
|
148
|
+
severity: 'blocking',
|
|
149
|
+
title: '该账号 Access Token 已过期且缺少客户端 Refresh Token',
|
|
150
|
+
reason: '当前凭据已超过有效期,且无法通过 /oauth/token 自动续期。',
|
|
151
|
+
recommendation: '请先重新获取该账号的新 Token(cswitch pure 或 cswitch oauth)后再切换。',
|
|
152
|
+
ageHours: classified.ageHours,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
if (tokenType === 'web') {
|
|
156
|
+
const ageLabel = classified.ageHours !== undefined
|
|
157
|
+
? `(签发于 ${TokenParser.formatAgeText(classified.ageHours)})`
|
|
158
|
+
: '';
|
|
159
|
+
if (classified.isExpired) {
|
|
160
|
+
preflightIssue = {
|
|
161
|
+
kind: 'token_expired',
|
|
162
|
+
severity: 'blocking',
|
|
163
|
+
title: `该网页端 Token 已超过 JWT 有效期${ageLabel},切入客户端极可能失效重登`,
|
|
164
|
+
reason: '该 web 令牌已过期且无法直接作为桌面端 refresh_token 自动续期。',
|
|
165
|
+
recommendation: '可在当前界面通过「浏览器 OAuth (cswitch oauth)」或「纯净代登 (cswitch pure)」重新获取 60 天客户端凭据。',
|
|
166
|
+
ageHours: classified.ageHours,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
else if (opts.autoUpgradeWebToken !== false) {
|
|
170
|
+
warnings.push('当前账号仅存有网页端 web 会话 Cookie,未包含桌面端客户端双票,切入 IDE 后刷新可能要求重新登录');
|
|
171
|
+
preflightIssue = {
|
|
172
|
+
kind: 'web_upgrade_failed',
|
|
173
|
+
severity: 'blocking',
|
|
174
|
+
title: `该账号当前仅为网页端 Cookie${ageLabel},尚未包含桌面端 60 天双票`,
|
|
175
|
+
reason: '纯网页 Cookie 可用于官网控制台 (cswitch dash) 与额度查询,但直接写入桌面端 state.vscdb 后续刷新时容易触发重新登录。',
|
|
176
|
+
recommendation: '建议在当前界面直接通过「浏览器 OAuth (cswitch oauth)」或「纯净代登 (cswitch pure)」获取桌面端 60 天客户端双票后再切入。',
|
|
177
|
+
ageHours: classified.ageHours,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
warnings.push('将直接写入网页端 web 令牌;Cursor 客户端后续刷新时可能要求重新登录');
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (!refreshToken || refreshToken.includes('::')) {
|
|
185
|
+
refreshToken = accessToken;
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
accessToken,
|
|
189
|
+
refreshToken,
|
|
190
|
+
authId,
|
|
191
|
+
userId,
|
|
192
|
+
workosSessionToken,
|
|
193
|
+
tokenType,
|
|
194
|
+
upgradedFromWeb,
|
|
195
|
+
refreshed,
|
|
196
|
+
shouldLogout,
|
|
197
|
+
preflightIssue,
|
|
198
|
+
warnings,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
export function buildOAuthAccountInfo(params) {
|
|
202
|
+
const { email, accessToken, refreshToken, authId, usageRes, existing, machineIds } = params;
|
|
203
|
+
const userId = TokenParser.extractUserId(accessToken) || TokenParser.extractUserId(authId || undefined);
|
|
204
|
+
const derivedSession = existing?.workos_cursor_session_token?.includes('::')
|
|
205
|
+
? existing.workos_cursor_session_token
|
|
206
|
+
: userId && TokenParser.isJwtShaped(accessToken)
|
|
207
|
+
? `${userId}::${accessToken}`
|
|
208
|
+
: existing?.workos_cursor_session_token;
|
|
209
|
+
const subType = usageRes?.success && usageRes.subscriptionType
|
|
210
|
+
? usageRes.subscriptionType
|
|
211
|
+
: existing?.subscription_type || 'free';
|
|
212
|
+
return {
|
|
213
|
+
email,
|
|
214
|
+
token: accessToken,
|
|
215
|
+
refresh_token: refreshToken || accessToken,
|
|
216
|
+
workos_cursor_session_token: derivedSession,
|
|
217
|
+
subscription_type: subType,
|
|
218
|
+
current_period_usage: usageRes?.currentPeriodUsage || existing?.current_period_usage,
|
|
219
|
+
machine_ids: machineIds,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
export async function upgradeAccountWebTokenOnIngest(account, _opts = {}) {
|
|
223
|
+
const classification = TokenParser.classifyAccount(account);
|
|
224
|
+
const pair = resolveSessionPair({
|
|
225
|
+
token: account.token,
|
|
226
|
+
workosSessionToken: account.workos_cursor_session_token,
|
|
227
|
+
userId: classification.userId,
|
|
228
|
+
});
|
|
229
|
+
const preservedAccount = {
|
|
230
|
+
...account,
|
|
231
|
+
workos_cursor_session_token: account.workos_cursor_session_token || pair.sessionCookieValue,
|
|
232
|
+
};
|
|
233
|
+
if (classification.credentialState === 'expired') {
|
|
234
|
+
return {
|
|
235
|
+
status: 'expired',
|
|
236
|
+
account: preservedAccount,
|
|
237
|
+
classification,
|
|
238
|
+
error: 'JWT 已超过有效期 (exp)',
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
if (classification.credentialState !== 'web_only') {
|
|
242
|
+
return {
|
|
243
|
+
status: 'already_client',
|
|
244
|
+
account: preservedAccount,
|
|
245
|
+
classification,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
return {
|
|
249
|
+
status: 'web_only_skipped',
|
|
250
|
+
account: preservedAccount,
|
|
251
|
+
classification,
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
export function applyParsedCredentialToAccount(params) {
|
|
255
|
+
const { parsed, email, existing, usageRes, machineIds, fallbackWorkosToToken } = params;
|
|
256
|
+
const samePrimaryToken = Boolean(existing && parsed.token && parsed.token === TokenParser.extractTokenPart(existing.token));
|
|
257
|
+
const refreshToken = parsed.refreshToken || (samePrimaryToken ? existing?.refresh_token : undefined);
|
|
258
|
+
let workosSession = parsed.workosSessionToken ||
|
|
259
|
+
(samePrimaryToken ? existing?.workos_cursor_session_token : undefined);
|
|
260
|
+
if (!workosSession && fallbackWorkosToToken) {
|
|
261
|
+
workosSession = parsed.userId ? `${parsed.userId}::${parsed.token}` : parsed.token;
|
|
262
|
+
}
|
|
263
|
+
const subType = usageRes?.success && usageRes.subscriptionType
|
|
264
|
+
? usageRes.subscriptionType
|
|
265
|
+
: existing?.subscription_type || 'free';
|
|
266
|
+
return {
|
|
267
|
+
email,
|
|
268
|
+
token: parsed.token,
|
|
269
|
+
refresh_token: refreshToken,
|
|
270
|
+
workos_cursor_session_token: workosSession,
|
|
271
|
+
subscription_type: subType,
|
|
272
|
+
current_period_usage: usageRes?.currentPeriodUsage || existing?.current_period_usage,
|
|
273
|
+
machine_ids: machineIds,
|
|
274
|
+
};
|
|
275
|
+
}
|
|
@@ -1,35 +1,71 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 智能凭据解析引擎
|
|
3
|
-
* 仅支持 WorkOS Session Token (user_xxx::eyJ...) 与 纯 JWT Token (eyJ...)
|
|
4
|
-
*/
|
|
5
1
|
export interface ParsedTokenResult {
|
|
6
2
|
email?: string;
|
|
7
3
|
token: string;
|
|
4
|
+
refreshToken?: string;
|
|
8
5
|
workosSessionToken?: string;
|
|
9
6
|
expiresAtMs?: number;
|
|
10
7
|
sub?: string;
|
|
8
|
+
userId?: string;
|
|
9
|
+
tokenType?: 'web' | 'client';
|
|
10
|
+
segmentCount?: number;
|
|
11
11
|
isValid: boolean;
|
|
12
|
-
format: 'session' | 'jwt' | 'unknown';
|
|
12
|
+
format: 'session' | 'jwt' | 'bundle' | 'unknown';
|
|
13
|
+
}
|
|
14
|
+
export interface CredentialBundles {
|
|
15
|
+
classification: TokenClassification;
|
|
16
|
+
accessToken?: string;
|
|
17
|
+
refreshToken?: string;
|
|
18
|
+
workosToken?: string;
|
|
19
|
+
singleToken: string;
|
|
20
|
+
tripleBundle?: string;
|
|
21
|
+
separator: string;
|
|
22
|
+
}
|
|
23
|
+
export type CredentialState = 'client_with_rt' | 'client_no_rt' | 'web_only' | 'expired';
|
|
24
|
+
export interface TokenClassification {
|
|
25
|
+
tokenType: 'web' | 'client';
|
|
26
|
+
credentialState: CredentialState;
|
|
27
|
+
cleanToken: string;
|
|
28
|
+
cleanRefreshToken?: string;
|
|
29
|
+
hasUsableRefreshToken: boolean;
|
|
30
|
+
isExpired: boolean;
|
|
31
|
+
isExpiringSoon: boolean;
|
|
32
|
+
expiresAtMs?: number;
|
|
33
|
+
issuedAtMs?: number;
|
|
34
|
+
ageHours?: number;
|
|
35
|
+
authId?: string;
|
|
36
|
+
userId?: string;
|
|
37
|
+
email?: string;
|
|
13
38
|
}
|
|
14
39
|
export declare class TokenParser {
|
|
15
|
-
/**
|
|
16
|
-
* 极简 base64url 解码
|
|
17
|
-
*/
|
|
18
40
|
static decodeBase64Url(str: string): string;
|
|
19
|
-
/**
|
|
20
|
-
* 提取纯 Token 部分(去除前缀 user_xxx::)
|
|
21
|
-
*/
|
|
22
41
|
static extractTokenPart(rawToken: string): string;
|
|
23
|
-
/**
|
|
24
|
-
* 判断是否具有 JWT 的基本形态
|
|
25
|
-
*/
|
|
26
42
|
static isJwtShaped(str: string): boolean;
|
|
27
|
-
/**
|
|
28
|
-
* 解析 JWT Payload
|
|
29
|
-
*/
|
|
30
43
|
static parseJwtPayload(jwt: string): Record<string, any> | null;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
44
|
+
private static readonly EMAIL_RE;
|
|
45
|
+
private static readonly PLACEHOLDER_PARTS;
|
|
46
|
+
private static cleanSegmentText;
|
|
47
|
+
private static isCompleteSingleCredential;
|
|
48
|
+
private static splitCredentialSegments;
|
|
49
|
+
private static extractEmailFromPayload;
|
|
50
|
+
private static parseSingleCredential;
|
|
34
51
|
static parse(input: string): ParsedTokenResult;
|
|
52
|
+
static extractAuthId(rawToken?: string | null): string | undefined;
|
|
53
|
+
static extractUserId(rawTokenOrSub?: string | null): string | undefined;
|
|
54
|
+
static classify(token: string, explicitRefreshToken?: string | null, nowMs?: number): TokenClassification;
|
|
55
|
+
static extractWebSessionToken(rawOrBundle?: string | null): string;
|
|
56
|
+
static extractEffectiveRefreshToken(token: string, explicitRefreshToken?: string | null, workosSessionToken?: string | null): string | undefined;
|
|
57
|
+
static classifyAccount(account: {
|
|
58
|
+
token: string;
|
|
59
|
+
refresh_token?: string | null;
|
|
60
|
+
workos_cursor_session_token?: string | null;
|
|
61
|
+
}, nowMs?: number): TokenClassification;
|
|
62
|
+
static formatCredentialBadge(cls: TokenClassification): string;
|
|
63
|
+
static formatCredentialBundles(account: {
|
|
64
|
+
token: string;
|
|
65
|
+
refresh_token?: string | null;
|
|
66
|
+
workos_cursor_session_token?: string | null;
|
|
67
|
+
}, opts?: {
|
|
68
|
+
separator?: string;
|
|
69
|
+
}): CredentialBundles;
|
|
70
|
+
static formatAgeText(ageHours?: number): string;
|
|
35
71
|
}
|