@dreamor/atlas-cli 0.7.4 → 0.7.6
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.
|
@@ -7,7 +7,6 @@ const _require = createRequire(import.meta.url);
|
|
|
7
7
|
const BANMA_HOST = 'banma-yuntu.alibaba-inc.com';
|
|
8
8
|
// 白名单:只保存 getBanmaIdentity 真正需要的 cookies,避免整域 cookies 落盘
|
|
9
9
|
const WANT_COOKIES = new Set(['access_token', 'buc_username', 'buc_userinfo']);
|
|
10
|
-
const EMP_ID_NAMES = new Set(['emp_id', 'empId', 'employeeId']);
|
|
11
10
|
/**
|
|
12
11
|
* 动态加载 playwright。顶层静态 import 会让单文件 bundle 在未安装 playwright 的
|
|
13
12
|
* 环境下无法启动(连 --version 都 require 失败),故改为运行时动态 import + try/catch
|
|
@@ -61,10 +60,25 @@ export async function login(_port) {
|
|
|
61
60
|
log('请在浏览器中完成 SSO 登录...');
|
|
62
61
|
log('登录成功后页面会自动跳转,CLI 会自动捕获 cookies');
|
|
63
62
|
await page.goto(`https://${BANMA_HOST}/`, { waitUntil: 'domcontentloaded', timeout: 60000 });
|
|
64
|
-
// 等待 access_token cookie 出现(最多 120s
|
|
65
|
-
|
|
63
|
+
// 等待 access_token cookie 出现(最多 120s)。
|
|
64
|
+
// 注意 access_token 是 HttpOnly cookie,不能用 document.cookie 检测,
|
|
65
|
+
// 必须走 page.context().cookies() 才能读到。
|
|
66
|
+
const MAX_WAIT = 120_000;
|
|
67
|
+
const POLL_INTERVAL = 500;
|
|
68
|
+
let foundToken = false;
|
|
69
|
+
for (let elapsed = 0; elapsed < MAX_WAIT; elapsed += POLL_INTERVAL) {
|
|
70
|
+
const allCookies = await page.context().cookies();
|
|
71
|
+
if (allCookies.some((c) => c.name === 'access_token' && c.value)) {
|
|
72
|
+
foundToken = true;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
await page.waitForTimeout(POLL_INTERVAL);
|
|
76
|
+
}
|
|
77
|
+
if (!foundToken) {
|
|
78
|
+
log('SSO 登录检测超时。如果您已完成登录,请按 Ctrl+C 重试或确认账号权限。');
|
|
79
|
+
}
|
|
66
80
|
// 额外等待确保残留 cookie 写入完毕
|
|
67
|
-
await page.waitForTimeout(
|
|
81
|
+
await page.waitForTimeout(500);
|
|
68
82
|
// Extract cookies — 精确白名单,避免整域 cookies 落盘
|
|
69
83
|
const cookies = await page.context().cookies();
|
|
70
84
|
const atlasCookies = cookies
|
|
@@ -84,10 +98,11 @@ export async function loginStatus() {
|
|
|
84
98
|
try {
|
|
85
99
|
const daemonCookies = await fetchCookiesFromDaemon();
|
|
86
100
|
if (daemonCookies && daemonCookies.length > 0) {
|
|
87
|
-
const
|
|
101
|
+
const { getBanmaIdentity } = await import('./session.js');
|
|
102
|
+
const identity = getBanmaIdentity(daemonCookies);
|
|
88
103
|
return {
|
|
89
104
|
loggedIn: true,
|
|
90
|
-
account:
|
|
105
|
+
account: identity?.staffId || identity?.user || 'via-daemon',
|
|
91
106
|
mode: 'daemon',
|
|
92
107
|
};
|
|
93
108
|
}
|
|
@@ -98,10 +113,11 @@ export async function loginStatus() {
|
|
|
98
113
|
// Check local cookies
|
|
99
114
|
const cookies = await readCookies();
|
|
100
115
|
if (cookies && cookies.length > 0) {
|
|
101
|
-
const
|
|
116
|
+
const { getBanmaIdentity } = await import('./session.js');
|
|
117
|
+
const identity = getBanmaIdentity(cookies);
|
|
102
118
|
return {
|
|
103
119
|
loggedIn: true,
|
|
104
|
-
account:
|
|
120
|
+
account: identity?.staffId || identity?.user || '已登录',
|
|
105
121
|
mode: 'local',
|
|
106
122
|
};
|
|
107
123
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const ATLAS_VERSION = '0.7.
|
|
1
|
+
export const ATLAS_VERSION = '0.7.6';
|