@qmuse/qmuse-cli 1.0.5-dev.2 → 1.0.5-dev.4
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 +16 -9
- package/dist/config.js +4 -2
- package/dist/login.js +3 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -634,7 +634,8 @@ async function cmdWhoami(flags) {
|
|
|
634
634
|
log.info(`本地空间 : ${cfg.spaceId}`);
|
|
635
635
|
return;
|
|
636
636
|
}
|
|
637
|
-
|
|
637
|
+
// 身份发现不能被上一个账号遗留的空间选择阻断。
|
|
638
|
+
const result = await api.whoami({ ...cfg, spaceId: undefined });
|
|
638
639
|
if (!result.ok || !result.data?.userId) {
|
|
639
640
|
if (result.status === 401) {
|
|
640
641
|
if (flags['--json'] === true) {
|
|
@@ -654,6 +655,8 @@ async function cmdWhoami(flags) {
|
|
|
654
655
|
fail(`查询当前用户失败: ${result.errorMessage ?? result.errorCode ?? `HTTP ${result.status}`}`);
|
|
655
656
|
}
|
|
656
657
|
const currentUser = result.data;
|
|
658
|
+
const tenantName = currentUser.tenantName?.trim() ||
|
|
659
|
+
(currentUser.tenantCode ? '企业专属版' : 'QMuse');
|
|
657
660
|
if (flags['--json'] === true) {
|
|
658
661
|
output({
|
|
659
662
|
apiBaseUrl,
|
|
@@ -664,6 +667,7 @@ async function cmdWhoami(flags) {
|
|
|
664
667
|
spaceId: currentUser.spaceId,
|
|
665
668
|
spaceName: currentUser.spaceName ?? null,
|
|
666
669
|
tenantCode: currentUser.tenantCode,
|
|
670
|
+
tenantName,
|
|
667
671
|
}, flags);
|
|
668
672
|
return;
|
|
669
673
|
}
|
|
@@ -675,7 +679,7 @@ async function cmdWhoami(flags) {
|
|
|
675
679
|
? (spaceName ? `${spaceName} [${currentUser.spaceId}]` : currentUser.spaceId)
|
|
676
680
|
: '(无)';
|
|
677
681
|
log.info(`当前空间 : ${spaceLabel}`);
|
|
678
|
-
log.info(
|
|
682
|
+
log.info(`所属产品 : ${tenantName}`);
|
|
679
683
|
}
|
|
680
684
|
async function cmdConfig(command, flags) {
|
|
681
685
|
const sub = command[1];
|
|
@@ -700,7 +704,8 @@ async function cmdSpace(command, flags) {
|
|
|
700
704
|
const sub = command[1];
|
|
701
705
|
requireAuth(cfg);
|
|
702
706
|
if (sub === 'list') {
|
|
703
|
-
|
|
707
|
+
// 空间发现接口不携带当前空间,确保账号切换后仍能列出新账号的空间。
|
|
708
|
+
const r = await api.listSpaces(num(flags, '--page-index', 1), num(flags, '--page-size', 20), { ...cfg, spaceId: undefined });
|
|
704
709
|
if (!r.ok || !r.data)
|
|
705
710
|
fail(`查询空间失败: ${r.errorMessage ?? r.errorCode ?? `HTTP ${r.status}`}`);
|
|
706
711
|
if (flags['--json'] === true) {
|
|
@@ -760,12 +765,14 @@ async function cmdLogin(flags) {
|
|
|
760
765
|
}
|
|
761
766
|
async function cmdLogout(flags) {
|
|
762
767
|
const cfg = resolveCfg(flags);
|
|
763
|
-
|
|
764
|
-
log.warn('当前未配置登录态,无需退出');
|
|
765
|
-
return;
|
|
766
|
-
}
|
|
768
|
+
const hadSession = !!(cfg.sessionId || '').trim();
|
|
767
769
|
deleteSession(cfg);
|
|
768
|
-
|
|
770
|
+
if (hadSession) {
|
|
771
|
+
log.success('已清除当前环境的登录态和空间选择');
|
|
772
|
+
}
|
|
773
|
+
else {
|
|
774
|
+
log.info('当前未配置登录态;已清除空间选择');
|
|
775
|
+
}
|
|
769
776
|
}
|
|
770
777
|
// ---------------- 帮助 & 入口 ----------------
|
|
771
778
|
const HELP = `QMuse CLI —— 将本地 React 项目导入 QMuse
|
|
@@ -783,7 +790,7 @@ const HELP = `QMuse CLI —— 将本地 React 项目导入 QMuse
|
|
|
783
790
|
命令:
|
|
784
791
|
whoami 查看当前环境、登录和空间状态
|
|
785
792
|
login [--status] [--log] [--json] 通过 QMuse 网页登录
|
|
786
|
-
logout
|
|
793
|
+
logout 清除保存的登录态和空间选择
|
|
787
794
|
config [get|path] 查看配置
|
|
788
795
|
|
|
789
796
|
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 || '')) {
|