skill-market-cli 1.1.1 → 1.1.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skill-market-cli",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "CLI tool for managing skills on Skill Market",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/api/client.js CHANGED
@@ -26,9 +26,10 @@ class ApiClient {
26
26
  // 请求拦截器 - 添加 Token(优先 OAuth Token,其次 Personal Access Token)
27
27
  this.client.interceptors.request.use(
28
28
  async (config) => {
29
- if (isLoggedIn()) {
30
- const { accessToken, expiresAt } = getToken();
29
+ const { accessToken, expiresAt } = getToken();
30
+ const pat = getPersonalAccessToken();
31
31
 
32
+ if (accessToken) {
32
33
  // 检查 Token 是否即将过期
33
34
  if (expiresAt && Date.now() > expiresAt - 60000) {
34
35
  // Token 即将过期,尝试刷新
@@ -36,17 +37,18 @@ class ApiClient {
36
37
  const newToken = await refreshAccessToken();
37
38
  config.headers['Authorization'] = `Bearer ${newToken}`;
38
39
  } catch (e) {
39
- // 刷新失败,使用现有 Token
40
- config.headers['Authorization'] = `Bearer ${accessToken}`;
40
+ // 刷新失败,回退到 PAT(如果有)或现有 Token
41
+ if (pat) {
42
+ config.headers['Authorization'] = `Bearer ${pat}`;
43
+ } else {
44
+ config.headers['Authorization'] = `Bearer ${accessToken}`;
45
+ }
41
46
  }
42
47
  } else {
43
48
  config.headers['Authorization'] = `Bearer ${accessToken}`;
44
49
  }
45
- } else {
46
- const pat = getPersonalAccessToken();
47
- if (pat) {
48
- config.headers['Authorization'] = `Bearer ${pat}`;
49
- }
50
+ } else if (pat) {
51
+ config.headers['Authorization'] = `Bearer ${pat}`;
50
52
  }
51
53
  return config;
52
54
  },
@@ -1,5 +1,5 @@
1
1
  const chalk = require('chalk');
2
- const { clearToken, clearPersonalAccessToken, isLoggedIn } = require('../auth/token-store');
2
+ const { clearToken, clearPersonalAccessToken, isLoggedIn, getConfig, saveConfig } = require('../auth/token-store');
3
3
  const apiClient = require('../api/client');
4
4
 
5
5
  async function logout() {
@@ -18,6 +18,14 @@ async function logout() {
18
18
  clearToken();
19
19
  clearPersonalAccessToken();
20
20
 
21
+ // 清除由 login 写入的 server / mode,避免后续命令错误指向 localhost
22
+ const config = getConfig();
23
+ if (config.server || config.mode) {
24
+ delete config.server;
25
+ delete config.mode;
26
+ saveConfig(config);
27
+ }
28
+
21
29
  console.log(chalk.green('已登出本地凭证'));
22
30
  console.log('');
23
31
  }
@@ -9,7 +9,7 @@ function parseSkillMarkdown(content) {
9
9
  let frontmatter = null;
10
10
  let examples = [];
11
11
 
12
- const frontmatterMatch = content.match(/^---\s*\n([\s\S]*?)\n---\s*(?:\n|$)/);
12
+ const frontmatterMatch = content.match(/^---\s*\r?\n([\s\S]*?)\r?\n---\s*(?:\r?\n|$)/);
13
13
  if (frontmatterMatch) {
14
14
  try {
15
15
  frontmatter = YAML.parse(frontmatterMatch[1]);
@@ -18,12 +18,12 @@ function parseSkillMarkdown(content) {
18
18
  }
19
19
  }
20
20
 
21
- const examplesMatch = content.match(/## Usage Examples?\s*\n([\s\S]*?)(?=##|$)/i);
21
+ const examplesMatch = content.match(/## Usage Examples?\s*\r?\n([\s\S]*?)(?=##|$)/i);
22
22
  if (examplesMatch) {
23
23
  const exampleText = examplesMatch[1];
24
- const exampleBlocks = exampleText.split(/\n\n+/).filter((b) => b.trim());
24
+ const exampleBlocks = exampleText.split(/\r?\n\r?\n+/).filter((b) => b.trim());
25
25
  examples = exampleBlocks.map((block) => {
26
- const lines = block.split('\n').filter((l) => l.trim());
26
+ const lines = block.split(/\r?\n/).filter((l) => l.trim());
27
27
  return { prompt: lines.join('\n') };
28
28
  });
29
29
  }