@lark-people/cli 0.0.4-beta.3 → 0.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.
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-people/cli",
3
- "version": "0.0.4-beta.3",
3
+ "version": "0.0.5",
4
4
  "description": "The official CLI for People open platform",
5
5
  "bin": {
6
6
  "people-cli": "scripts/run.js"
@@ -58,6 +58,7 @@ const messages = {
58
58
  step4: "授权",
59
59
  step4NotFound: "未找到 people-cli,跳过授权",
60
60
  step4Confirm: "是否现在执行登录授权,让 CLI 能访问你已授权的 People 数据?",
61
+ step4SkipExisting: "检测到已有用户授权,跳过登录",
61
62
  step4Skip: "跳过授权。后续运行 people-cli auth login 完成授权",
62
63
  step4Done: "授权完成",
63
64
  step4Fail: "授权失败。运行以下命令重试: people-cli auth login",
@@ -91,6 +92,7 @@ const messages = {
91
92
  step4: "Authorization",
92
93
  step4NotFound: "people-cli not found. Skipping authorization",
93
94
  step4Confirm: "Authorize now so People CLI can access your approved People data?",
95
+ step4SkipExisting: "Existing user authorization found. Skipped login",
94
96
  step4Skip: "Skipped. Run people-cli auth login to authorize later",
95
97
  step4Done: "Authorization complete",
96
98
  step4Fail: "Failed to authorize. Run people-cli auth login to retry",
@@ -451,6 +453,23 @@ function getExistingAppId(binPath) {
451
453
  }
452
454
  }
453
455
 
456
+ function isAuthenticatedStatus(status) {
457
+ return Boolean(
458
+ status &&
459
+ status.identity === "user" &&
460
+ status.userOpenId &&
461
+ status.tokenStatus !== "expired",
462
+ );
463
+ }
464
+
465
+ function shouldAutoReuseExistingConfig(existing) {
466
+ return Boolean(existing && existing.appId && existing.reusable);
467
+ }
468
+
469
+ function shouldSkipAuthLogin(existing) {
470
+ return Boolean(existing && existing.authenticated);
471
+ }
472
+
454
473
  function inspectExistingAppConfig(binPath, deps = {}) {
455
474
  const runSilentFn = deps.runSilent || runSilent;
456
475
  try {
@@ -458,16 +477,17 @@ function inspectExistingAppConfig(binPath, deps = {}) {
458
477
  const parsed = JSON.parse(out.toString());
459
478
  const appId = parsed.appId || parsed.app_id || null;
460
479
  if (!appId) {
461
- return { appId: null, reusable: false };
480
+ return { appId: null, reusable: false, authenticated: false };
462
481
  }
463
482
  try {
464
- runSilentFn(binPath, ["auth", "status"], { timeout: 10000 });
465
- return { appId, reusable: true };
483
+ const statusOut = runSilentFn(binPath, ["auth", "status"], { timeout: 10000 });
484
+ const status = JSON.parse(statusOut.toString());
485
+ return { appId, reusable: true, authenticated: isAuthenticatedStatus(status) };
466
486
  } catch (_) {
467
- return { appId, reusable: false };
487
+ return { appId, reusable: false, authenticated: false };
468
488
  }
469
489
  } catch (_) {
470
- return { appId: null, reusable: false };
490
+ return { appId: null, reusable: false, authenticated: false };
471
491
  }
472
492
  }
473
493
 
@@ -733,12 +753,16 @@ async function stepConfigInit(msg, lang) {
733
753
  }
734
754
 
735
755
  if (existing.appId && existing.reusable) {
756
+ if (shouldAutoReuseExistingConfig(existing)) {
757
+ p.log.info(msg.step3Skip);
758
+ return existing;
759
+ }
736
760
  const reuse = await p.confirm({
737
761
  message: fmt(msg.step3Found, existing.appId),
738
762
  });
739
763
  if (handleCancel(reuse, msg) && reuse) {
740
764
  p.log.info(msg.step3Skip);
741
- return;
765
+ return existing;
742
766
  }
743
767
  } else if (existing.appId) {
744
768
  p.log.warn(msg.step3Reinit);
@@ -747,19 +771,25 @@ async function stepConfigInit(msg, lang) {
747
771
  try {
748
772
  run(peopleCli, ["config", "init", "--new", "--lang", lang]);
749
773
  p.log.success(msg.step3Done);
774
+ return { appId: null, reusable: false, authenticated: false };
750
775
  } catch (_) {
751
776
  p.log.error(msg.step3Fail);
752
777
  process.exit(1);
753
778
  }
754
779
  }
755
780
 
756
- async function stepAuthLogin(msg) {
781
+ async function stepAuthLogin(msg, existing = null) {
757
782
  const peopleCli = whichPeopleCli();
758
783
  if (!peopleCli) {
759
784
  p.log.warn(msg.step4NotFound);
760
785
  return;
761
786
  }
762
787
 
788
+ if (shouldSkipAuthLogin(existing)) {
789
+ p.log.info(msg.step4SkipExisting);
790
+ return;
791
+ }
792
+
763
793
  const yes = await p.confirm({
764
794
  message: msg.step4Confirm,
765
795
  });
@@ -790,8 +820,8 @@ async function main() {
790
820
  p.intro(msg.setup);
791
821
  await stepInstallGlobally(msg);
792
822
  await stepInstallSkills(msg);
793
- await stepConfigInit(msg, lang);
794
- await stepAuthLogin(msg);
823
+ const existing = await stepConfigInit(msg, lang);
824
+ await stepAuthLogin(msg, existing);
795
825
  p.outro(msg.done);
796
826
  } else {
797
827
  console.log(msg.setup);
@@ -824,6 +854,8 @@ module.exports = {
824
854
  removeConflictingLegacyPackage,
825
855
  resolveGlobalBinOwner,
826
856
  resolveSkillsLauncher,
857
+ shouldAutoReuseExistingConfig,
858
+ shouldSkipAuthLogin,
827
859
  stepInstallSkills,
828
860
  main,
829
861
  runCLI,
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: people-cli
3
3
  version: 1.0.0
4
- description: "当用户需要通过 people-cli/People CLI 处理飞书人事或招聘数据时使用;覆盖 CoreHR 员工、部门组织、待入职、异动、离职、续约/续签、编制/HC,以及 Hire 职位、招需、投递、候选人、面试、评估、人才查询;也适用于 CLI 安装、升级、登录授权、Permission denied 和 scope 权限问题。"
4
+ description: "当用户需要处理飞书人事或飞书招聘数据时使用;覆盖 CoreHR 员工、部门组织、待入职、异动、离职、续约/续签、编制/HC,以及 Hire 职位、招需、投递、候选人、面试、评估、人才查询;也适用于 CLI 安装、升级、登录授权、Permission denied 和 scope 权限问题。"
5
5
  metadata:
6
6
  requires:
7
7
  bins: ["people-cli"]
@@ -49,7 +49,7 @@ npx @lark-people/cli install
49
49
  people-cli update --check
50
50
  ```
51
51
 
52
- 如果提示有新版本,或任意 `people-cli` JSON 输出中包含 `_notice.update` / `_notice.skills`,执行:
52
+ 如果提示有新版本,或后续任意 `people-cli` 输出中提示需要更新 CLI / Skills,执行:
53
53
 
54
54
  ```bash
55
55
  people-cli update