@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 +2 -2
- package/dist/auth.js +29 -14
- package/dist/index.js +2 -2
- package/package.json +1 -1
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
|
-
|
|
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
|
|
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.
|
|
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
|
-
|
|
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
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const
|
|
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
|
|
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.
|
|
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.
|
|
282
|
+
text: `✅ 授权成功!\n${(0, auth_js_1.formatAuthorizationDetails)(result.account, result.selectedShop)}\n可以直接继续使用 ScoreHub 工具。`,
|
|
283
283
|
}],
|
|
284
284
|
};
|
|
285
285
|
}
|