@besile/scm-cli 2026.3.30 → 2026.3.32

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/README.zh.md CHANGED
@@ -44,7 +44,7 @@
44
44
  npm install -g @besile/scm-cli
45
45
 
46
46
  # 安装 CLI SKILL(必需,AI Agent 调用时需要)
47
- npx skills add @besile/scm-cli -y -g
47
+ npx skills add github:besile/scm-cli -y -g
48
48
  ```
49
49
 
50
50
  **方式二 — 从源码安装:**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@besile/scm-cli",
3
- "version": "2026.3.30",
3
+ "version": "2026.3.32",
4
4
  "description": "SCM CLI — Supply Chain Management CLI Tool",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -10,7 +10,7 @@
10
10
  },
11
11
  "repository": {
12
12
  "type": "git",
13
- "url": "git@home.cogo.club:xubinghua/scm-cli.git"
13
+ "url": "git@github.com:besile/scm-cli.git"
14
14
  },
15
15
  "keywords": [
16
16
  "scm",
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * scm-cli auth login command
7
7
  */
8
- import { scmClient, loadConfig, createLogger } from '../../internal/index.js';
8
+ import { scmClient, loadConfig, createLogger, saveToken } from '../../internal/index.js';
9
9
 
10
10
  /**
11
11
  * Execute login
@@ -75,6 +75,9 @@ export function loginCommand(program) {
75
75
  console.log('正在登录 SCM...');
76
76
  const result = await doLogin(opts.openId, opts.mobile, opts.password);
77
77
 
78
+ // Save token to cache
79
+ await saveToken(opts.openId, result);
80
+
78
81
  console.log('\n✅ 登录成功!');
79
82
  console.log('───────────────');
80
83
  console.log(`用户: ${result.username}`);
@@ -86,6 +86,43 @@ export async function checkToken(openId) {
86
86
  }
87
87
  }
88
88
 
89
+ /**
90
+ * 保存 Token 到缓存
91
+ *
92
+ * @param {string} openId - 飞书用户 openId
93
+ * @param {Object} tokenInfo - { access_token, expires_in, user_id, username }
94
+ */
95
+ export async function saveToken(openId, tokenInfo) {
96
+ const { readFileSync, writeFileSync, mkdirSync } = await import('node:fs');
97
+ const { dirname } = await import('node:path');
98
+
99
+ // Ensure directory exists
100
+ const dir = dirname(TOKEN_FILE);
101
+ mkdirSync(dir, { recursive: true });
102
+
103
+ // Load existing tokens
104
+ let tokens = {};
105
+ try {
106
+ const existing = readFileSync(TOKEN_FILE, 'utf-8');
107
+ tokens = JSON.parse(existing);
108
+ } catch {
109
+ // File doesn't exist yet, start fresh
110
+ }
111
+
112
+ const expiresIn = tokenInfo.expires_in || tokenInfo.expiresIn || 12 * 3600;
113
+ const now = Date.now() / 1000;
114
+
115
+ tokens[openId] = {
116
+ access_token: tokenInfo.access_token || tokenInfo.accessToken,
117
+ expires_at: now + expiresIn,
118
+ user_id: tokenInfo.user_id || tokenInfo.userId || '',
119
+ username: tokenInfo.username || '',
120
+ last_login: now,
121
+ };
122
+
123
+ writeFileSync(TOKEN_FILE, JSON.stringify(tokens, null, 2), 'utf-8');
124
+ }
125
+
89
126
  /**
90
127
  * Token 文件路径
91
128
  */
@@ -37,6 +37,7 @@ export {
37
37
  getCachedToken,
38
38
  checkToken,
39
39
  TOKEN_FILE_PATH,
40
+ saveToken,
40
41
  printLoginHint,
41
42
  promptLogin,
42
43
  withAuth,