feishu-mcp 0.1.5 → 0.1.7

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.
@@ -28,9 +28,16 @@ export class TokenCacheManager {
28
28
  writable: true,
29
29
  value: void 0
30
30
  });
31
+ Object.defineProperty(this, "scopeVersionCacheFile", {
32
+ enumerable: true,
33
+ configurable: true,
34
+ writable: true,
35
+ value: void 0
36
+ });
31
37
  this.cache = new Map();
32
38
  this.userTokenCacheFile = path.resolve(process.cwd(), 'user_token_cache.json');
33
39
  this.tenantTokenCacheFile = path.resolve(process.cwd(), 'tenant_token_cache.json');
40
+ this.scopeVersionCacheFile = path.resolve(process.cwd(), 'scope_version_cache.json');
34
41
  this.loadTokenCaches();
35
42
  this.startCacheCleanupTimer();
36
43
  }
@@ -49,6 +56,7 @@ export class TokenCacheManager {
49
56
  loadTokenCaches() {
50
57
  this.loadUserTokenCache();
51
58
  this.loadTenantTokenCache();
59
+ this.loadScopeVersionCache();
52
60
  }
53
61
  /**
54
62
  * 加载用户token缓存
@@ -417,4 +425,124 @@ export class TokenCacheManager {
417
425
  }, 5 * 60 * 1000);
418
426
  Logger.info('Token缓存清理定时器已启动,每5分钟执行一次');
419
427
  }
428
+ /**
429
+ * 获取所有用户token的key列表(不包含前缀)
430
+ * @returns 用户token的key数组
431
+ */
432
+ getAllUserTokenKeys() {
433
+ const keys = [];
434
+ for (const [key] of this.cache.entries()) {
435
+ if (key.startsWith('user_access_token:')) {
436
+ // 提取clientKey(去掉前缀)
437
+ const clientKey = key.substring('user_access_token:'.length);
438
+ keys.push(clientKey);
439
+ }
440
+ }
441
+ Logger.debug(`获取到 ${keys.length} 个用户token keys`);
442
+ return keys;
443
+ }
444
+ /**
445
+ * 获取scope版本信息
446
+ * @param clientKey 客户端缓存键
447
+ * @returns scope版本信息,如果未找到则返回null
448
+ */
449
+ getScopeVersionInfo(clientKey) {
450
+ const cacheKey = `scope_version:${clientKey}`;
451
+ const cacheItem = this.cache.get(cacheKey);
452
+ if (!cacheItem) {
453
+ Logger.debug(`Scope版本信息未找到: ${clientKey}`);
454
+ return null;
455
+ }
456
+ Logger.debug(`获取Scope版本信息成功: ${clientKey}`);
457
+ return cacheItem.data;
458
+ }
459
+ /**
460
+ * 保存scope版本信息
461
+ * @param clientKey 客户端缓存键
462
+ * @param scopeVersionInfo scope版本信息
463
+ * @returns 是否成功保存
464
+ */
465
+ saveScopeVersionInfo(clientKey, scopeVersionInfo) {
466
+ try {
467
+ const cacheKey = `scope_version:${clientKey}`;
468
+ const now = Date.now();
469
+ // scope版本信息永久有效,不设置过期时间
470
+ const cacheItem = {
471
+ data: scopeVersionInfo,
472
+ timestamp: now,
473
+ expiresAt: Number.MAX_SAFE_INTEGER // 永久有效
474
+ };
475
+ this.cache.set(cacheKey, cacheItem);
476
+ this.saveScopeVersionCache();
477
+ Logger.debug(`Scope版本信息保存成功: ${clientKey}, 版本: ${scopeVersionInfo.scopeVersion}`);
478
+ return true;
479
+ }
480
+ catch (error) {
481
+ Logger.error(`保存Scope版本信息失败: ${clientKey}`, error);
482
+ return false;
483
+ }
484
+ }
485
+ /**
486
+ * 检查scope版本是否需要校验
487
+ * @param clientKey 客户端缓存键
488
+ * @param currentScopeVersion 当前scope版本号
489
+ * @returns 是否需要校验
490
+ */
491
+ shouldValidateScope(clientKey, currentScopeVersion) {
492
+ const scopeVersionInfo = this.getScopeVersionInfo(clientKey);
493
+ if (!scopeVersionInfo) {
494
+ Logger.debug(`Scope版本信息不存在,需要校验: ${clientKey}`);
495
+ return true;
496
+ }
497
+ // 如果版本号不同,需要重新校验
498
+ if (scopeVersionInfo.validatedVersion !== currentScopeVersion) {
499
+ Logger.debug(`Scope版本号已更新,需要重新校验: ${clientKey}, 旧版本: ${scopeVersionInfo.validatedVersion}, 新版本: ${currentScopeVersion}`);
500
+ return true;
501
+ }
502
+ Logger.debug(`Scope版本已校验过,无需重复校验: ${clientKey}, 版本: ${currentScopeVersion}`);
503
+ return false;
504
+ }
505
+ /**
506
+ * 加载scope版本缓存
507
+ */
508
+ loadScopeVersionCache() {
509
+ if (fs.existsSync(this.scopeVersionCacheFile)) {
510
+ try {
511
+ const raw = fs.readFileSync(this.scopeVersionCacheFile, 'utf-8');
512
+ const cacheData = JSON.parse(raw);
513
+ let loadedCount = 0;
514
+ for (const key in cacheData) {
515
+ if (key.startsWith('scope_version:')) {
516
+ this.cache.set(key, cacheData[key]);
517
+ loadedCount++;
518
+ }
519
+ }
520
+ Logger.info(`已加载Scope版本缓存,共 ${loadedCount} 条记录`);
521
+ }
522
+ catch (error) {
523
+ Logger.warn('加载Scope版本缓存失败:', error);
524
+ }
525
+ }
526
+ else {
527
+ Logger.info('Scope版本缓存文件不存在,将创建新的缓存');
528
+ }
529
+ }
530
+ /**
531
+ * 保存scope版本缓存到文件
532
+ */
533
+ saveScopeVersionCache() {
534
+ const cacheData = {};
535
+ for (const [key, value] of this.cache.entries()) {
536
+ if (key.startsWith('scope_version:')) {
537
+ cacheData[key] = value;
538
+ }
539
+ }
540
+ try {
541
+ fs.writeFileSync(this.scopeVersionCacheFile, JSON.stringify(cacheData, null, 2), 'utf-8');
542
+ Logger.debug('Scope版本缓存已保存到文件');
543
+ }
544
+ catch (error) {
545
+ Logger.warn('保存Scope版本缓存失败:', error);
546
+ }
547
+ }
420
548
  }
@@ -0,0 +1,172 @@
1
+ import { Logger } from '../logger.js';
2
+ import { TokenCacheManager } from './tokenCacheManager.js';
3
+ import { AuthService } from '../../services/feishuAuthService.js';
4
+ /**
5
+ * Token自动刷新管理器
6
+ * 定期检查并自动刷新即将过期的用户token
7
+ */
8
+ export class TokenRefreshManager {
9
+ /**
10
+ * 私有构造函数,用于单例模式
11
+ */
12
+ constructor() {
13
+ Object.defineProperty(this, "intervalId", {
14
+ enumerable: true,
15
+ configurable: true,
16
+ writable: true,
17
+ value: null
18
+ });
19
+ Object.defineProperty(this, "checkInterval", {
20
+ enumerable: true,
21
+ configurable: true,
22
+ writable: true,
23
+ value: 5 * 60 * 1000
24
+ }); // 5分钟
25
+ Object.defineProperty(this, "isRunning", {
26
+ enumerable: true,
27
+ configurable: true,
28
+ writable: true,
29
+ value: false
30
+ });
31
+ Logger.info('Token刷新管理器已初始化');
32
+ }
33
+ /**
34
+ * 获取TokenRefreshManager实例
35
+ */
36
+ static getInstance() {
37
+ if (!TokenRefreshManager.instance) {
38
+ TokenRefreshManager.instance = new TokenRefreshManager();
39
+ }
40
+ return TokenRefreshManager.instance;
41
+ }
42
+ /**
43
+ * 启动自动刷新检查
44
+ */
45
+ start() {
46
+ if (this.isRunning) {
47
+ Logger.warn('Token刷新管理器已在运行中');
48
+ return;
49
+ }
50
+ Logger.info(`启动Token自动刷新管理器,检查间隔: ${this.checkInterval / 1000}秒`);
51
+ // 立即执行一次检查
52
+ this.checkAndRefreshTokens();
53
+ // 设置定时器
54
+ this.intervalId = setInterval(() => {
55
+ this.checkAndRefreshTokens();
56
+ }, this.checkInterval);
57
+ this.isRunning = true;
58
+ Logger.info('Token自动刷新管理器已启动');
59
+ }
60
+ /**
61
+ * 停止自动刷新检查
62
+ */
63
+ stop() {
64
+ if (!this.isRunning) {
65
+ Logger.warn('Token刷新管理器未在运行');
66
+ return;
67
+ }
68
+ if (this.intervalId) {
69
+ clearInterval(this.intervalId);
70
+ this.intervalId = null;
71
+ }
72
+ this.isRunning = false;
73
+ Logger.info('Token自动刷新管理器已停止');
74
+ }
75
+ /**
76
+ * 检查并刷新即将过期的token
77
+ */
78
+ async checkAndRefreshTokens() {
79
+ try {
80
+ Logger.debug('开始检查需要刷新的token');
81
+ const tokenCacheManager = TokenCacheManager.getInstance();
82
+ // 获取所有用户token
83
+ const allCacheKeys = this.getAllUserTokenKeys();
84
+ let checkedCount = 0;
85
+ let refreshedCount = 0;
86
+ let failedCount = 0;
87
+ for (const clientKey of allCacheKeys) {
88
+ checkedCount++;
89
+ try {
90
+ const tokenStatus = tokenCacheManager.checkUserTokenStatus(clientKey);
91
+ // 检查是否需要刷新:token即将过期(5分钟内)且可以刷新
92
+ if (tokenStatus.shouldRefresh || (tokenStatus.canRefresh && tokenStatus.isExpired)) {
93
+ Logger.info(`检测到需要刷新的token: ${clientKey}`);
94
+ const tokenInfo = tokenCacheManager.getUserTokenInfo(clientKey);
95
+ if (!tokenInfo) {
96
+ Logger.warn(`无法获取token信息: ${clientKey}`);
97
+ failedCount++;
98
+ continue;
99
+ }
100
+ // 验证是否有刷新所需的必要信息
101
+ if (!tokenInfo.refresh_token) {
102
+ Logger.warn(`token没有refresh_token,无法刷新: ${clientKey}`);
103
+ failedCount++;
104
+ continue;
105
+ }
106
+ if (!tokenInfo.client_id || !tokenInfo.client_secret) {
107
+ Logger.warn(`token缺少client_id或client_secret,无法刷新: ${clientKey}`);
108
+ failedCount++;
109
+ continue;
110
+ }
111
+ // 执行刷新,使用AuthService的统一刷新方法
112
+ try {
113
+ const authService = new AuthService();
114
+ await authService.refreshUserToken(clientKey);
115
+ refreshedCount++;
116
+ Logger.info(`token刷新成功: ${clientKey}`);
117
+ }
118
+ catch (error) {
119
+ failedCount++;
120
+ Logger.warn(`token刷新失败: ${clientKey}`, error);
121
+ // 如果刷新失败是因为refresh_token无效,清除缓存
122
+ if (error?.response?.data?.code === 99991669 || error?.message?.includes('refresh_token')) {
123
+ Logger.warn(`refresh_token无效,清除缓存: ${clientKey}`);
124
+ tokenCacheManager.removeUserToken(clientKey);
125
+ }
126
+ }
127
+ }
128
+ else {
129
+ Logger.debug(`token状态正常,无需刷新: ${clientKey}`, {
130
+ isValid: tokenStatus.isValid,
131
+ isExpired: tokenStatus.isExpired,
132
+ canRefresh: tokenStatus.canRefresh,
133
+ shouldRefresh: tokenStatus.shouldRefresh
134
+ });
135
+ }
136
+ }
137
+ catch (error) {
138
+ Logger.error(`检查token时发生错误: ${clientKey}`, error);
139
+ failedCount++;
140
+ }
141
+ }
142
+ if (refreshedCount > 0 || failedCount > 0) {
143
+ Logger.info(`Token刷新检查完成: 检查${checkedCount}个,刷新${refreshedCount}个,失败${failedCount}个`);
144
+ }
145
+ else {
146
+ Logger.debug(`Token刷新检查完成: 检查${checkedCount}个,无需刷新`);
147
+ }
148
+ }
149
+ catch (error) {
150
+ Logger.error('检查并刷新token时发生错误:', error);
151
+ }
152
+ }
153
+ /**
154
+ * 获取所有用户token的key列表
155
+ */
156
+ getAllUserTokenKeys() {
157
+ try {
158
+ const tokenCacheManager = TokenCacheManager.getInstance();
159
+ return tokenCacheManager.getAllUserTokenKeys();
160
+ }
161
+ catch (error) {
162
+ Logger.error('获取所有用户token key时发生错误:', error);
163
+ return [];
164
+ }
165
+ }
166
+ /**
167
+ * 获取运行状态
168
+ */
169
+ isRunningStatus() {
170
+ return this.isRunning;
171
+ }
172
+ }
@@ -136,127 +136,127 @@ export function renderFeishuAuthResultHtml(data) {
136
136
  expiresIn = expiresIn - now;
137
137
  if (refreshExpiresIn && refreshExpiresIn > 1000000000)
138
138
  refreshExpiresIn = refreshExpiresIn - now;
139
- const tokenBlock = data && !isError ? `
140
- <div class="card">
141
- <h3>Token 信息</h3>
142
- <ul class="kv-list">
143
- <li><b>token_type:</b> <span>${data.token_type || ''}</span></li>
144
- <li><b>access_token:</b> <span class="foldable" onclick="toggleFold(this)">点击展开/收起</span><pre class="fold scrollable">${data.access_token || ''}</pre></li>
145
- <li><b>expires_in:</b> <span>${formatExpire(expiresIn)}</span></li>
146
- <li><b>refresh_token:</b> <span class="foldable" onclick="toggleFold(this)">点击展开/收起</span><pre class="fold scrollable">${data.refresh_token || ''}</pre></li>
147
- <li><b>refresh_token_expires_in:</b> <span>${formatExpire(refreshExpiresIn)}</span></li>
148
- <li><b>scope:</b> <pre class="scope">${(data.scope || '').replace(/ /g, '\n')}</pre></li>
149
- </ul>
150
- <div class="success-action">
151
- <span class="success-msg">授权成功,继续完成任务</span>
152
- <button class="copy-btn" onclick="copySuccessMsg(this)">点击复制到粘贴板</button>
153
- </div>
154
- </div>
139
+ const tokenBlock = data && !isError ? `
140
+ <div class="card">
141
+ <h3>Token 信息</h3>
142
+ <ul class="kv-list">
143
+ <li><b>token_type:</b> <span>${data.token_type || ''}</span></li>
144
+ <li><b>access_token:</b> <span class="foldable" onclick="toggleFold(this)">点击展开/收起</span><pre class="fold scrollable">${data.access_token || ''}</pre></li>
145
+ <li><b>expires_in:</b> <span>${formatExpire(expiresIn)}</span></li>
146
+ <li><b>refresh_token:</b> <span class="foldable" onclick="toggleFold(this)">点击展开/收起</span><pre class="fold scrollable">${data.refresh_token || ''}</pre></li>
147
+ <li><b>refresh_token_expires_in:</b> <span>${formatExpire(refreshExpiresIn)}</span></li>
148
+ <li><b>scope:</b> <pre class="scope">${(data.scope || '').replace(/ /g, '\n')}</pre></li>
149
+ </ul>
150
+ <div class="success-action">
151
+ <span class="success-msg">授权成功,继续完成任务</span>
152
+ <button class="copy-btn" onclick="copySuccessMsg(this)">点击复制到粘贴板</button>
153
+ </div>
154
+ </div>
155
155
  ` : '';
156
156
  let userBlock = '';
157
157
  const userInfo = data && data.userInfo && data.userInfo.data;
158
158
  if (userInfo) {
159
- userBlock = `
160
- <div class="card user-card">
161
- <div class="avatar-wrap">
162
- <img src="${userInfo.avatar_big || userInfo.avatar_thumb || userInfo.avatar_url || ''}" class="avatar" />
163
- </div>
164
- <div class="user-info">
165
- <div class="user-name">${userInfo.name || ''}</div>
166
- <div class="user-en">${userInfo.en_name || ''}</div>
167
- </div>
168
- </div>
159
+ userBlock = `
160
+ <div class="card user-card">
161
+ <div class="avatar-wrap">
162
+ <img src="${userInfo.avatar_big || userInfo.avatar_thumb || userInfo.avatar_url || ''}" class="avatar" />
163
+ </div>
164
+ <div class="user-info">
165
+ <div class="user-name">${userInfo.name || ''}</div>
166
+ <div class="user-en">${userInfo.en_name || ''}</div>
167
+ </div>
168
+ </div>
169
169
  `;
170
170
  }
171
- const errorBlock = isError ? `
172
- <div class="card error-card">
173
- <h3>授权失败</h3>
174
- <div class="error-msg">${escapeHtml(data.error || '')}</div>
175
- <div class="error-code">错误码: ${data.code || ''}</div>
176
- </div>
171
+ const errorBlock = isError ? `
172
+ <div class="card error-card">
173
+ <h3>授权失败</h3>
174
+ <div class="error-msg">${escapeHtml(data.error || '')}</div>
175
+ <div class="error-code">错误码: ${data.code || ''}</div>
176
+ </div>
177
177
  ` : '';
178
- return `
179
- <html>
180
- <head>
181
- <title>飞书授权结果</title>
182
- <meta charset="utf-8"/>
183
- <meta name="viewport" content="width=device-width,initial-scale=1"/>
184
- <style>
185
- body { background: #f7f8fa; font-family: 'Segoe UI', Arial, sans-serif; margin:0; padding:0; }
186
- .container { max-width: 600px; margin: 40px auto; padding: 16px; }
187
- .card { background: #fff; border-radius: 12px; box-shadow: 0 2px 12px #0001; margin-bottom: 24px; padding: 24px 20px; }
188
- .user-card { display: flex; align-items: center; gap: 24px; }
189
- .avatar-wrap { flex-shrink: 0; }
190
- .avatar { width: 96px; height: 96px; border-radius: 50%; box-shadow: 0 2px 8px #0002; display: block; margin: 0 auto; }
191
- .user-info { flex: 1; }
192
- .user-name { font-size: 1.5em; font-weight: bold; margin-bottom: 4px; }
193
- .user-en { color: #888; margin-bottom: 10px; }
194
- .kv-list { list-style: none; padding: 0; margin: 0; }
195
- .kv-list li { margin-bottom: 6px; word-break: break-all; }
196
- .kv-list b { color: #1976d2; }
197
- .scope { background: #f0f4f8; border-radius: 4px; padding: 6px; font-size: 0.95em; white-space: pre-line; }
198
- .foldable { color: #1976d2; cursor: pointer; text-decoration: underline; margin-left: 8px; }
199
- .fold { display: none; background: #f6f6f6; border-radius: 4px; padding: 6px; margin: 4px 0; font-size: 0.92em; max-width: 100%; overflow-x: auto; word-break: break-all; }
200
- .scrollable { max-width: 100%; overflow-x: auto; font-family: 'Fira Mono', 'Consolas', 'Menlo', monospace; font-size: 0.93em; }
201
- .success-action { margin-top: 18px; display: flex; align-items: center; gap: 16px; }
202
- .success-msg { color: #388e3c; font-weight: bold; }
203
- .copy-btn { background: #1976d2; color: #fff; border: none; border-radius: 4px; padding: 6px 16px; font-size: 1em; cursor: pointer; transition: background 0.2s; }
204
- .copy-btn:hover { background: #125ea2; }
205
- .error-card { border-left: 6px solid #e53935; background: #fff0f0; color: #b71c1c; }
206
- .error-msg { font-size: 1.1em; margin-bottom: 8px; }
207
- .error-code { color: #b71c1c; font-size: 0.95em; }
208
- .raw-block { margin-top: 24px; }
209
- .raw-toggle { color: #1976d2; cursor: pointer; text-decoration: underline; margin-bottom: 8px; display: inline-block; }
210
- .raw-pre { display: none; background: #23272e; color: #fff; border-radius: 6px; padding: 12px; font-size: 0.95em; overflow-x: auto; max-width: 100%; }
211
- @media (max-width: 700px) {
212
- .container { max-width: 98vw; padding: 4vw; }
213
- .card { padding: 4vw 3vw; }
214
- .avatar { width: 64px; height: 64px; }
215
- }
216
- </style>
217
- <script>
218
- function toggleFold(el) {
219
- var pre = el.nextElementSibling;
220
- if (pre.style.display === 'block') {
221
- pre.style.display = 'none';
222
- } else {
223
- pre.style.display = 'block';
224
- }
225
- }
226
- function toggleRaw() {
227
- var pre = document.getElementById('raw-pre');
228
- if (pre.style.display === 'block') {
229
- pre.style.display = 'none';
230
- } else {
231
- pre.style.display = 'block';
232
- }
233
- }
234
- function copySuccessMsg(btn) {
235
- var text = '授权成功,继续完成任务';
236
- navigator.clipboard.writeText(text).then(function() {
237
- btn.innerText = '已复制';
238
- btn.disabled = true;
239
- setTimeout(function() {
240
- btn.innerText = '点击复制到粘贴板';
241
- btn.disabled = false;
242
- }, 2000);
243
- });
244
- }
245
- </script>
246
- </head>
247
- <body>
248
- <div class="container">
249
- <h2 style="margin-bottom:24px;">飞书授权结果</h2>
250
- ${errorBlock}
251
- ${tokenBlock}
252
- ${userBlock}
253
- <div class="card raw-block">
254
- <span class="raw-toggle" onclick="toggleRaw()">点击展开/收起原始数据</span>
255
- <pre id="raw-pre" class="raw-pre">${escapeHtml(JSON.stringify(data, null, 2))}</pre>
256
- </div>
257
- </div>
258
- </body>
259
- </html>
178
+ return `
179
+ <html>
180
+ <head>
181
+ <title>飞书授权结果</title>
182
+ <meta charset="utf-8"/>
183
+ <meta name="viewport" content="width=device-width,initial-scale=1"/>
184
+ <style>
185
+ body { background: #f7f8fa; font-family: 'Segoe UI', Arial, sans-serif; margin:0; padding:0; }
186
+ .container { max-width: 600px; margin: 40px auto; padding: 16px; }
187
+ .card { background: #fff; border-radius: 12px; box-shadow: 0 2px 12px #0001; margin-bottom: 24px; padding: 24px 20px; }
188
+ .user-card { display: flex; align-items: center; gap: 24px; }
189
+ .avatar-wrap { flex-shrink: 0; }
190
+ .avatar { width: 96px; height: 96px; border-radius: 50%; box-shadow: 0 2px 8px #0002; display: block; margin: 0 auto; }
191
+ .user-info { flex: 1; }
192
+ .user-name { font-size: 1.5em; font-weight: bold; margin-bottom: 4px; }
193
+ .user-en { color: #888; margin-bottom: 10px; }
194
+ .kv-list { list-style: none; padding: 0; margin: 0; }
195
+ .kv-list li { margin-bottom: 6px; word-break: break-all; }
196
+ .kv-list b { color: #1976d2; }
197
+ .scope { background: #f0f4f8; border-radius: 4px; padding: 6px; font-size: 0.95em; white-space: pre-line; }
198
+ .foldable { color: #1976d2; cursor: pointer; text-decoration: underline; margin-left: 8px; }
199
+ .fold { display: none; background: #f6f6f6; border-radius: 4px; padding: 6px; margin: 4px 0; font-size: 0.92em; max-width: 100%; overflow-x: auto; word-break: break-all; }
200
+ .scrollable { max-width: 100%; overflow-x: auto; font-family: 'Fira Mono', 'Consolas', 'Menlo', monospace; font-size: 0.93em; }
201
+ .success-action { margin-top: 18px; display: flex; align-items: center; gap: 16px; }
202
+ .success-msg { color: #388e3c; font-weight: bold; }
203
+ .copy-btn { background: #1976d2; color: #fff; border: none; border-radius: 4px; padding: 6px 16px; font-size: 1em; cursor: pointer; transition: background 0.2s; }
204
+ .copy-btn:hover { background: #125ea2; }
205
+ .error-card { border-left: 6px solid #e53935; background: #fff0f0; color: #b71c1c; }
206
+ .error-msg { font-size: 1.1em; margin-bottom: 8px; }
207
+ .error-code { color: #b71c1c; font-size: 0.95em; }
208
+ .raw-block { margin-top: 24px; }
209
+ .raw-toggle { color: #1976d2; cursor: pointer; text-decoration: underline; margin-bottom: 8px; display: inline-block; }
210
+ .raw-pre { display: none; background: #23272e; color: #fff; border-radius: 6px; padding: 12px; font-size: 0.95em; overflow-x: auto; max-width: 100%; }
211
+ @media (max-width: 700px) {
212
+ .container { max-width: 98vw; padding: 4vw; }
213
+ .card { padding: 4vw 3vw; }
214
+ .avatar { width: 64px; height: 64px; }
215
+ }
216
+ </style>
217
+ <script>
218
+ function toggleFold(el) {
219
+ var pre = el.nextElementSibling;
220
+ if (pre.style.display === 'block') {
221
+ pre.style.display = 'none';
222
+ } else {
223
+ pre.style.display = 'block';
224
+ }
225
+ }
226
+ function toggleRaw() {
227
+ var pre = document.getElementById('raw-pre');
228
+ if (pre.style.display === 'block') {
229
+ pre.style.display = 'none';
230
+ } else {
231
+ pre.style.display = 'block';
232
+ }
233
+ }
234
+ function copySuccessMsg(btn) {
235
+ var text = '授权成功,继续完成任务';
236
+ navigator.clipboard.writeText(text).then(function() {
237
+ btn.innerText = '已复制';
238
+ btn.disabled = true;
239
+ setTimeout(function() {
240
+ btn.innerText = '点击复制到粘贴板';
241
+ btn.disabled = false;
242
+ }, 2000);
243
+ });
244
+ }
245
+ </script>
246
+ </head>
247
+ <body>
248
+ <div class="container">
249
+ <h2 style="margin-bottom:24px;">飞书授权结果</h2>
250
+ ${errorBlock}
251
+ ${tokenBlock}
252
+ ${userBlock}
253
+ <div class="card raw-block">
254
+ <span class="raw-toggle" onclick="toggleRaw()">点击展开/收起原始数据</span>
255
+ <pre id="raw-pre" class="raw-pre">${escapeHtml(JSON.stringify(data, null, 2))}</pre>
256
+ </div>
257
+ </div>
258
+ </body>
259
+ </html>
260
260
  `;
261
261
  }
262
262
  function escapeHtml(str) {
@@ -206,3 +206,27 @@ export class AuthRequiredError extends Error {
206
206
  this.message = message;
207
207
  }
208
208
  }
209
+ /**
210
+ * 权限不足异常类
211
+ * 用于处理应用权限范围不足的情况
212
+ */
213
+ export class ScopeInsufficientError extends Error {
214
+ constructor(missingScopes, message) {
215
+ super(message);
216
+ Object.defineProperty(this, "missingScopes", {
217
+ enumerable: true,
218
+ configurable: true,
219
+ writable: true,
220
+ value: void 0
221
+ });
222
+ Object.defineProperty(this, "message", {
223
+ enumerable: true,
224
+ configurable: true,
225
+ writable: true,
226
+ value: void 0
227
+ });
228
+ this.name = 'ScopeInsufficientError';
229
+ this.missingScopes = missingScopes;
230
+ this.message = message;
231
+ }
232
+ }