@scorehub/mcp-server 0.3.1 → 0.3.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/dist/auth.d.ts CHANGED
@@ -8,7 +8,7 @@ export interface OAuthTokens {
8
8
  }
9
9
  export interface OAuthAccount {
10
10
  id: string;
11
- email: string;
11
+ phone?: string;
12
12
  }
13
13
  export interface OAuthShop {
14
14
  id: string;
@@ -63,7 +63,7 @@ export interface AuthorizeResult {
63
63
  export declare function loadTokens(host: string): TokenStore | null;
64
64
  export declare function saveTokens(host: string, tokens: TokenStore): void;
65
65
  export declare function clearTokens(host: string): void;
66
- export declare function formatShopAuthorizationDetails(shop?: OAuthShop): string;
66
+ export declare function formatAuthorizationDetails(account?: OAuthAccount, shop?: OAuthShop): string;
67
67
  export declare function exchangeCodeForTokens(tokenEndpoint: string, code: string, codeVerifier: string, clientId: string, redirectUri: string): Promise<OAuthTokens>;
68
68
  export declare function refreshAccessToken(tokenEndpoint: string, refreshToken: string, clientId: string): Promise<OAuthTokens>;
69
69
  export declare function getValidAccessToken(host: string, tokenEndpoint: string, clientId: string): Promise<{
package/dist/auth.js CHANGED
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.loadTokens = loadTokens;
7
7
  exports.saveTokens = saveTokens;
8
8
  exports.clearTokens = clearTokens;
9
- exports.formatShopAuthorizationDetails = formatShopAuthorizationDetails;
9
+ exports.formatAuthorizationDetails = formatAuthorizationDetails;
10
10
  exports.exchangeCodeForTokens = exchangeCodeForTokens;
11
11
  exports.refreshAccessToken = refreshAccessToken;
12
12
  exports.getValidAccessToken = getValidAccessToken;
@@ -49,7 +49,13 @@ function loadTokens(host) {
49
49
  if (!(0, node_fs_1.existsSync)(file))
50
50
  return null;
51
51
  try {
52
- return JSON.parse((0, node_fs_1.readFileSync)(file, "utf-8"));
52
+ const stored = JSON.parse((0, node_fs_1.readFileSync)(file, "utf-8"));
53
+ const account = parseOAuthAccount(stored.account);
54
+ const { account: _storedAccount, ...tokenFields } = stored;
55
+ return {
56
+ ...tokenFields,
57
+ ...(account ? { account } : {}),
58
+ };
53
59
  }
54
60
  catch {
55
61
  return null;
@@ -112,12 +118,18 @@ function parseOAuthTokens(payload) {
112
118
  throw new Error(getTokenErrorMessage(payload));
113
119
  }
114
120
  function parseOAuthAccount(value) {
115
- if (value && typeof value === "object"
116
- && typeof value.id === "string"
117
- && typeof value.email === "string") {
118
- return value;
119
- }
120
- return undefined;
121
+ if (!value || typeof value !== "object" || typeof value.id !== "string")
122
+ return undefined;
123
+ const account = value;
124
+ const phone = typeof account.phone === "string" && isBasicPhoneNumber(account.phone)
125
+ ? account.phone
126
+ : typeof account.email === "string" && isBasicPhoneNumber(account.email)
127
+ ? account.email
128
+ : undefined;
129
+ return {
130
+ id: account.id,
131
+ ...(phone ? { phone } : {}),
132
+ };
121
133
  }
122
134
  function parseOAuthShop(value) {
123
135
  const shop = value;
@@ -142,16 +154,19 @@ function parseOAuthShop(value) {
142
154
  }
143
155
  return undefined;
144
156
  }
145
- function formatShopAuthorizationDetails(shop) {
146
- if (!shop)
147
- return "";
148
- const country = shop.country?.trim() || "未获取";
149
- const brands = shop.brands === undefined
157
+ function isBasicPhoneNumber(value) {
158
+ return /^\d{6,20}$/.test(value);
159
+ }
160
+ function formatAuthorizationDetails(account, shop) {
161
+ const phone = account?.phone?.trim() || "未获取";
162
+ const shopName = shop?.name?.trim() || "未获取";
163
+ const country = shop?.country?.trim() || "未获取";
164
+ const brands = shop?.brands === undefined
150
165
  ? "未获取"
151
166
  : shop.brands.length === 0
152
167
  ? "未绑定"
153
168
  : shop.brands.map((brand) => brand.name).join("、");
154
- return `店铺名称:${shop.name}\n国家:${country}\n绑定品牌:${brands}`;
169
+ return `当前登录账号:${phone}\n当前授权店铺:${shopName}\n店铺所属国家:${country}\n店铺关联品牌:${brands}`;
155
170
  }
156
171
  function tokenStoreFromOAuthTokens(tokens, previous) {
157
172
  return {
package/dist/index.js CHANGED
@@ -247,7 +247,7 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
247
247
  return {
248
248
  content: [{
249
249
  type: "text",
250
- text: `✅ 已切换店铺。\n${(0, auth_js_1.formatShopAuthorizationDetails)(result.selectedShop)}\n可以继续使用 ScoreHub 工具。`,
250
+ text: `✅ 已切换店铺。\n${(0, auth_js_1.formatAuthorizationDetails)(result.account, result.selectedShop)}\n可以继续使用 ScoreHub 工具。`,
251
251
  }],
252
252
  };
253
253
  }
@@ -279,7 +279,7 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
279
279
  return {
280
280
  content: [{
281
281
  type: "text",
282
- text: `✅ 授权成功!\n${(0, auth_js_1.formatShopAuthorizationDetails)(result.selectedShop)}\n可以直接继续使用 ScoreHub 工具。`,
282
+ text: `✅ 授权成功!\n${(0, auth_js_1.formatAuthorizationDetails)(result.account, result.selectedShop)}\n可以直接继续使用 ScoreHub 工具。`,
283
283
  }],
284
284
  };
285
285
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scorehub/mcp-server",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "ScoreHub local MCP proxy — OAuth login, token caching, and tool forwarding to remote MCP endpoint",
5
5
  "engines": {
6
6
  "node": ">=18"