@besile/scm-cli 2026.3.31 → 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 +1 -1
- package/package.json +1 -1
- package/src/cmd/auth/login.js +4 -1
- package/src/internal/auth/token-store.js +37 -0
- package/src/internal/index.js +1 -0
package/README.zh.md
CHANGED
package/package.json
CHANGED
package/src/cmd/auth/login.js
CHANGED
|
@@ -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
|
*/
|