@qmuse/qmuse-cli 1.0.5-dev.1 → 1.0.5-dev.3

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/api.js CHANGED
@@ -11,6 +11,10 @@ export function createSessionExchangeRequest(opts) {
11
11
  export function consumeSessionExchangeToken(token, opts) {
12
12
  return apiCall('POST', '/api/login/session-exchange/consume', { token }, { anonymous: true, ...opts });
13
13
  }
14
+ /** 查询服务端实际登录身份,不触发 /api/user/me 的奖励和活跃副作用。 */
15
+ export function whoami(cfg) {
16
+ return apiCall('GET', '/api/user/whoami', undefined, cfg);
17
+ }
14
18
  export function listSpaces(pageIndex = 1, pageSize = 20, cfg) {
15
19
  const path = `/api/space/list?pageIndex=${pageIndex}&pageSize=${pageSize}`;
16
20
  return apiCall('GET', path, undefined, cfg);
package/dist/cli.js CHANGED
@@ -618,18 +618,67 @@ async function cmdDev(command, flags) {
618
618
  }
619
619
  async function cmdWhoami(flags) {
620
620
  const cfg = resolveCfg(flags);
621
+ const apiBaseUrl = `${cfg.baseUrl}${cfg.apiPrefix || ''}`;
622
+ if (!hasAuth(cfg)) {
623
+ if (flags['--json'] === true) {
624
+ output({
625
+ apiBaseUrl,
626
+ loggedIn: false,
627
+ ...(cfg.spaceId ? { spaceId: cfg.spaceId } : {}),
628
+ }, flags);
629
+ return;
630
+ }
631
+ log.info(`QMuse API: ${apiBaseUrl}`);
632
+ log.info('登录状态 : 未登录');
633
+ if (cfg.spaceId)
634
+ log.info(`本地空间 : ${cfg.spaceId}`);
635
+ return;
636
+ }
637
+ const result = await api.whoami(cfg);
638
+ if (!result.ok || !result.data?.userId) {
639
+ if (result.status === 401) {
640
+ if (flags['--json'] === true) {
641
+ output({
642
+ apiBaseUrl,
643
+ loggedIn: false,
644
+ ...(cfg.spaceId ? { spaceId: cfg.spaceId } : {}),
645
+ }, flags);
646
+ return;
647
+ }
648
+ log.info(`QMuse API: ${apiBaseUrl}`);
649
+ log.info('登录状态 : 会话已失效');
650
+ if (cfg.spaceId)
651
+ log.info(`本地空间 : ${cfg.spaceId}`);
652
+ return;
653
+ }
654
+ fail(`查询当前用户失败: ${result.errorMessage ?? result.errorCode ?? `HTTP ${result.status}`}`);
655
+ }
656
+ const currentUser = result.data;
657
+ const tenantName = currentUser.tenantName?.trim() ||
658
+ (currentUser.tenantCode ? '企业专属版' : 'QMuse');
621
659
  if (flags['--json'] === true) {
622
660
  output({
623
- apiBaseUrl: `${cfg.baseUrl}${cfg.apiPrefix || ''}`,
624
- loggedIn: hasAuth(cfg),
625
- ...(cfg.spaceId ? { spaceId: cfg.spaceId } : {}),
661
+ apiBaseUrl,
662
+ loggedIn: true,
663
+ userId: currentUser.userId,
664
+ userName: currentUser.userName,
665
+ ...(currentUser.avatarUrl ? { avatarUrl: currentUser.avatarUrl } : {}),
666
+ spaceId: currentUser.spaceId,
667
+ spaceName: currentUser.spaceName ?? null,
668
+ tenantCode: currentUser.tenantCode,
669
+ tenantName,
626
670
  }, flags);
627
671
  return;
628
672
  }
629
- log.info(`QMuse API: ${cfg.baseUrl}${cfg.apiPrefix || ''}`);
630
- log.info(`登录状态 : ${hasAuth(cfg) ? '已登录' : '未登录'}`);
631
- if (cfg.spaceId)
632
- log.info(`当前空间 : ${cfg.spaceId}`);
673
+ log.info(`QMuse API: ${apiBaseUrl}`);
674
+ log.info('登录状态 : 已登录');
675
+ log.info(`当前用户 : ${currentUser.userName} [${currentUser.userId}]`);
676
+ const spaceName = currentUser.spaceName?.trim();
677
+ const spaceLabel = currentUser.spaceId
678
+ ? (spaceName ? `${spaceName} [${currentUser.spaceId}]` : currentUser.spaceId)
679
+ : '(无)';
680
+ log.info(`当前空间 : ${spaceLabel}`);
681
+ log.info(`所属产品 : ${tenantName}`);
633
682
  }
634
683
  async function cmdConfig(command, flags) {
635
684
  const sub = command[1];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qmuse/qmuse-cli",
3
- "version": "1.0.5-dev.1",
3
+ "version": "1.0.5-dev.3",
4
4
  "description": "将本地 React 项目安全导入 QMuse 的命令行客户端",
5
5
  "type": "module",
6
6
  "bin": {