@scorehub/mcp-server 0.3.0 → 0.3.1
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 +7 -0
- package/dist/auth.js +31 -6
- package/dist/index.js +6 -3
- package/package.json +1 -1
package/dist/auth.d.ts
CHANGED
|
@@ -15,6 +15,12 @@ export interface OAuthShop {
|
|
|
15
15
|
name: string;
|
|
16
16
|
code: string;
|
|
17
17
|
region: string;
|
|
18
|
+
country?: string;
|
|
19
|
+
brands?: OAuthShopBrand[];
|
|
20
|
+
}
|
|
21
|
+
export interface OAuthShopBrand {
|
|
22
|
+
id: string;
|
|
23
|
+
name: string;
|
|
18
24
|
}
|
|
19
25
|
export interface TokenStore {
|
|
20
26
|
access_token: string;
|
|
@@ -57,6 +63,7 @@ export interface AuthorizeResult {
|
|
|
57
63
|
export declare function loadTokens(host: string): TokenStore | null;
|
|
58
64
|
export declare function saveTokens(host: string, tokens: TokenStore): void;
|
|
59
65
|
export declare function clearTokens(host: string): void;
|
|
66
|
+
export declare function formatShopAuthorizationDetails(shop?: OAuthShop): string;
|
|
60
67
|
export declare function exchangeCodeForTokens(tokenEndpoint: string, code: string, codeVerifier: string, clientId: string, redirectUri: string): Promise<OAuthTokens>;
|
|
61
68
|
export declare function refreshAccessToken(tokenEndpoint: string, refreshToken: string, clientId: string): Promise<OAuthTokens>;
|
|
62
69
|
export declare function getValidAccessToken(host: string, tokenEndpoint: string, clientId: string): Promise<{
|
package/dist/auth.js
CHANGED
|
@@ -6,6 +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
10
|
exports.exchangeCodeForTokens = exchangeCodeForTokens;
|
|
10
11
|
exports.refreshAccessToken = refreshAccessToken;
|
|
11
12
|
exports.getValidAccessToken = getValidAccessToken;
|
|
@@ -119,15 +120,39 @@ function parseOAuthAccount(value) {
|
|
|
119
120
|
return undefined;
|
|
120
121
|
}
|
|
121
122
|
function parseOAuthShop(value) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
&& typeof
|
|
125
|
-
&& typeof
|
|
126
|
-
&& typeof
|
|
127
|
-
|
|
123
|
+
const shop = value;
|
|
124
|
+
if (shop && typeof shop === "object"
|
|
125
|
+
&& typeof shop.id === "string"
|
|
126
|
+
&& typeof shop.name === "string"
|
|
127
|
+
&& typeof shop.code === "string"
|
|
128
|
+
&& typeof shop.region === "string") {
|
|
129
|
+
const brands = Array.isArray(shop.brands)
|
|
130
|
+
? shop.brands.filter((brand) => (Boolean(brand)
|
|
131
|
+
&& typeof brand.id === "string"
|
|
132
|
+
&& typeof brand.name === "string"))
|
|
133
|
+
: undefined;
|
|
134
|
+
return {
|
|
135
|
+
id: shop.id,
|
|
136
|
+
name: shop.name,
|
|
137
|
+
code: shop.code,
|
|
138
|
+
region: shop.region,
|
|
139
|
+
...(typeof shop.country === "string" ? { country: shop.country } : {}),
|
|
140
|
+
...(brands !== undefined ? { brands } : {}),
|
|
141
|
+
};
|
|
128
142
|
}
|
|
129
143
|
return undefined;
|
|
130
144
|
}
|
|
145
|
+
function formatShopAuthorizationDetails(shop) {
|
|
146
|
+
if (!shop)
|
|
147
|
+
return "";
|
|
148
|
+
const country = shop.country?.trim() || "未获取";
|
|
149
|
+
const brands = shop.brands === undefined
|
|
150
|
+
? "未获取"
|
|
151
|
+
: shop.brands.length === 0
|
|
152
|
+
? "未绑定"
|
|
153
|
+
: shop.brands.map((brand) => brand.name).join("、");
|
|
154
|
+
return `店铺名称:${shop.name}\n国家:${country}\n绑定品牌:${brands}`;
|
|
155
|
+
}
|
|
131
156
|
function tokenStoreFromOAuthTokens(tokens, previous) {
|
|
132
157
|
return {
|
|
133
158
|
access_token: tokens.access_token,
|
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: `✅
|
|
250
|
+
text: `✅ 已切换店铺。\n${(0, auth_js_1.formatShopAuthorizationDetails)(result.selectedShop)}\n可以继续使用 ScoreHub 工具。`,
|
|
251
251
|
}],
|
|
252
252
|
};
|
|
253
253
|
}
|
|
@@ -269,7 +269,7 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
|
269
269
|
(0, auth_js_1.clearTokens)(TOKEN_STORE_KEY);
|
|
270
270
|
}
|
|
271
271
|
try {
|
|
272
|
-
await (0, auth_js_1.authorize)({
|
|
272
|
+
const result = await (0, auth_js_1.authorize)({
|
|
273
273
|
authEndpoint: AUTHORIZE_URL,
|
|
274
274
|
tokenEndpoint: TOKEN_ENDPOINT,
|
|
275
275
|
clientId: CLIENT_ID,
|
|
@@ -277,7 +277,10 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
|
277
277
|
port: 0,
|
|
278
278
|
});
|
|
279
279
|
return {
|
|
280
|
-
content: [{
|
|
280
|
+
content: [{
|
|
281
|
+
type: "text",
|
|
282
|
+
text: `✅ 授权成功!\n${(0, auth_js_1.formatShopAuthorizationDetails)(result.selectedShop)}\n可以直接继续使用 ScoreHub 工具。`,
|
|
283
|
+
}],
|
|
281
284
|
};
|
|
282
285
|
}
|
|
283
286
|
catch (error) {
|