@qmuse/qmuse-cli 1.0.5-dev.3 → 1.0.5
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/dist/cli.js +24 -10
- package/dist/config.js +4 -2
- package/dist/login.js +3 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -66,6 +66,17 @@ const str = (f, k) => {
|
|
|
66
66
|
const v = f[k];
|
|
67
67
|
return typeof v === 'string' ? v : undefined;
|
|
68
68
|
};
|
|
69
|
+
/** 封网期间为已知租户提供稳定的产品展示名,服务端配置恢复后仍可兼容其返回值。 */
|
|
70
|
+
const TENANT_DISPLAY_NAMES = new Map([
|
|
71
|
+
['A_BAO_PC', '智能体涌现奖大赛账号'],
|
|
72
|
+
['A_BAO', '阿宝'],
|
|
73
|
+
]);
|
|
74
|
+
function tenantDisplayName(tenantCode, tenantName) {
|
|
75
|
+
const code = tenantCode?.trim();
|
|
76
|
+
return (code ? TENANT_DISPLAY_NAMES.get(code) : undefined) ||
|
|
77
|
+
tenantName?.trim() ||
|
|
78
|
+
(code ? '企业专属版' : 'QMuse');
|
|
79
|
+
}
|
|
69
80
|
const num = (f, key, def) => {
|
|
70
81
|
const v = str(f, key);
|
|
71
82
|
const n = v === undefined ? def : Number(v);
|
|
@@ -634,7 +645,8 @@ async function cmdWhoami(flags) {
|
|
|
634
645
|
log.info(`本地空间 : ${cfg.spaceId}`);
|
|
635
646
|
return;
|
|
636
647
|
}
|
|
637
|
-
|
|
648
|
+
// 身份发现不能被上一个账号遗留的空间选择阻断。
|
|
649
|
+
const result = await api.whoami({ ...cfg, spaceId: undefined });
|
|
638
650
|
if (!result.ok || !result.data?.userId) {
|
|
639
651
|
if (result.status === 401) {
|
|
640
652
|
if (flags['--json'] === true) {
|
|
@@ -654,8 +666,7 @@ async function cmdWhoami(flags) {
|
|
|
654
666
|
fail(`查询当前用户失败: ${result.errorMessage ?? result.errorCode ?? `HTTP ${result.status}`}`);
|
|
655
667
|
}
|
|
656
668
|
const currentUser = result.data;
|
|
657
|
-
const tenantName = currentUser.tenantName
|
|
658
|
-
(currentUser.tenantCode ? '企业专属版' : 'QMuse');
|
|
669
|
+
const tenantName = tenantDisplayName(currentUser.tenantCode, currentUser.tenantName);
|
|
659
670
|
if (flags['--json'] === true) {
|
|
660
671
|
output({
|
|
661
672
|
apiBaseUrl,
|
|
@@ -703,7 +714,8 @@ async function cmdSpace(command, flags) {
|
|
|
703
714
|
const sub = command[1];
|
|
704
715
|
requireAuth(cfg);
|
|
705
716
|
if (sub === 'list') {
|
|
706
|
-
|
|
717
|
+
// 空间发现接口不携带当前空间,确保账号切换后仍能列出新账号的空间。
|
|
718
|
+
const r = await api.listSpaces(num(flags, '--page-index', 1), num(flags, '--page-size', 20), { ...cfg, spaceId: undefined });
|
|
707
719
|
if (!r.ok || !r.data)
|
|
708
720
|
fail(`查询空间失败: ${r.errorMessage ?? r.errorCode ?? `HTTP ${r.status}`}`);
|
|
709
721
|
if (flags['--json'] === true) {
|
|
@@ -763,12 +775,14 @@ async function cmdLogin(flags) {
|
|
|
763
775
|
}
|
|
764
776
|
async function cmdLogout(flags) {
|
|
765
777
|
const cfg = resolveCfg(flags);
|
|
766
|
-
|
|
767
|
-
log.warn('当前未配置登录态,无需退出');
|
|
768
|
-
return;
|
|
769
|
-
}
|
|
778
|
+
const hadSession = !!(cfg.sessionId || '').trim();
|
|
770
779
|
deleteSession(cfg);
|
|
771
|
-
|
|
780
|
+
if (hadSession) {
|
|
781
|
+
log.success('已清除当前环境的登录态和空间选择');
|
|
782
|
+
}
|
|
783
|
+
else {
|
|
784
|
+
log.info('当前未配置登录态;已清除空间选择');
|
|
785
|
+
}
|
|
772
786
|
}
|
|
773
787
|
// ---------------- 帮助 & 入口 ----------------
|
|
774
788
|
const HELP = `QMuse CLI —— 将本地 React 项目导入 QMuse
|
|
@@ -786,7 +800,7 @@ const HELP = `QMuse CLI —— 将本地 React 项目导入 QMuse
|
|
|
786
800
|
命令:
|
|
787
801
|
whoami 查看当前环境、登录和空间状态
|
|
788
802
|
login [--status] [--log] [--json] 通过 QMuse 网页登录
|
|
789
|
-
logout
|
|
803
|
+
logout 清除保存的登录态和空间选择
|
|
790
804
|
config [get|path] 查看配置
|
|
791
805
|
|
|
792
806
|
cloud init -d "<应用功能描述>" 校验当前空间的 QMuse 云服务权益
|
package/dist/config.js
CHANGED
|
@@ -160,7 +160,7 @@ export function saveSession(sessionId, cfg, options = {}) {
|
|
|
160
160
|
const user = migrateLegacy(path, credentials);
|
|
161
161
|
storeVerified(credentials, origin, sessionId);
|
|
162
162
|
writeConfig(path, {
|
|
163
|
-
spaceId: user.spaceId,
|
|
163
|
+
spaceId: options.clearSpaceId ? undefined : user.spaceId,
|
|
164
164
|
credentialOrigins: [...new Set([...credentialOrigins(user), origin])],
|
|
165
165
|
});
|
|
166
166
|
}
|
|
@@ -175,7 +175,9 @@ export function deleteSession(cfg, options = {}) {
|
|
|
175
175
|
credentials.delete(origin);
|
|
176
176
|
if (credentials.get(origin))
|
|
177
177
|
throw new Error('系统凭证库删除校验失败,请重试退出登录');
|
|
178
|
-
writeConfig(path, {
|
|
178
|
+
writeConfig(path, {
|
|
179
|
+
credentialOrigins: credentialOrigins(user).filter(value => value !== origin),
|
|
180
|
+
});
|
|
179
181
|
}
|
|
180
182
|
export function findConfigPath() {
|
|
181
183
|
for (const path of configPaths()) {
|
package/dist/login.js
CHANGED
|
@@ -54,11 +54,11 @@ export function closePrompt() {
|
|
|
54
54
|
export function openBrowser(url) {
|
|
55
55
|
return open(url, { wait: false }).then(() => true, () => false);
|
|
56
56
|
}
|
|
57
|
-
export function persistSession(sessionId, targetConfig = loadConfig()) {
|
|
57
|
+
export function persistSession(sessionId, targetConfig = loadConfig(), options = {}) {
|
|
58
58
|
const origin = apiOrigin(targetConfig.baseUrl);
|
|
59
59
|
if (!origin)
|
|
60
60
|
throw new Error('登录目标不是有效的 HTTP(S) 地址');
|
|
61
|
-
saveSession(sessionId, targetConfig);
|
|
61
|
+
saveSession(sessionId, targetConfig, options);
|
|
62
62
|
log.success('登录态已保存到系统凭证库');
|
|
63
63
|
return origin;
|
|
64
64
|
}
|
|
@@ -118,7 +118,7 @@ export async function loginBrowser(cfg, options = {}, dependencyOverrides) {
|
|
|
118
118
|
message: `登录态校验失败:${verified.errorMessage ?? verified.errorCode ?? `HTTP ${verified.status}`}`,
|
|
119
119
|
};
|
|
120
120
|
}
|
|
121
|
-
dependencies.persist(verified.data.sessionId, cfg);
|
|
121
|
+
dependencies.persist(verified.data.sessionId, cfg, { clearSpaceId: true });
|
|
122
122
|
return { success: true, sessionId: verified.data.sessionId, method: 'browser' };
|
|
123
123
|
}
|
|
124
124
|
if (!SESSION_EXCHANGE_PENDING_CODES.has(exchanged.errorCode || '')) {
|