@aicoin/opendata-mcp 1.0.20 → 1.0.21
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/build/index.js +33 -8
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -31,8 +31,8 @@ function generateSignature(accessKeyId, accessSecret) {
|
|
|
31
31
|
// src/client/api.ts
|
|
32
32
|
var DOMAIN = process.env.AICOIN_BASE_URL || "https://open.aicoin.com";
|
|
33
33
|
var TIMEOUT_MS = 3e4;
|
|
34
|
-
var
|
|
35
|
-
var
|
|
34
|
+
var UPGRADE_GUIDE = "\n\n--- \u5982\u4F55\u89E3\u51B3 ---\n\u5F53\u524D API \u5957\u9910\u65E0\u6743\u8BBF\u95EE\u6B64\u63A5\u53E3\uFF0C\u8BF7\u5347\u7EA7\u5957\u9910\u3002\n1. \u524D\u5F80 https://www.aicoin.com/opendata \u8D2D\u4E70/\u5347\u7EA7\u5957\u9910\n2. \u5957\u9910\u7B49\u7EA7: Basic(\u514D\u8D39) | Normal(\xA599) | Premium(\xA5299) | Professional(\xA5999)\n3. \u5347\u7EA7\u540E\u5728 MCP \u914D\u7F6E\u4E2D\u8BBE\u7F6E AICOIN_ACCESS_KEY_ID \u548C AICOIN_ACCESS_SECRET\n4. \u91CD\u542F MCP \u5BA2\u6237\u7AEF";
|
|
35
|
+
var AUTH_GUIDE = "\n\n--- \u5982\u4F55\u89E3\u51B3 ---\n\u9700\u8981 API Key \u624D\u80FD\u8BBF\u95EE\u6B64\u63A5\u53E3\u3002\n1. \u524D\u5F80 https://www.aicoin.com/opendata \u6CE8\u518C\u5E76\u521B\u5EFA API Key\n2. \u5728 MCP \u914D\u7F6E\u4E2D\u8BBE\u7F6E AICOIN_ACCESS_KEY_ID \u548C AICOIN_ACCESS_SECRET\n3. \u91CD\u542F MCP \u5BA2\u6237\u7AEF";
|
|
36
36
|
function throwApiError(status, body, path) {
|
|
37
37
|
let msg = `API ${status}: ${body}`;
|
|
38
38
|
if (status === 401) {
|
|
@@ -44,6 +44,25 @@ Endpoint: ${path}`;
|
|
|
44
44
|
}
|
|
45
45
|
throw new Error(msg);
|
|
46
46
|
}
|
|
47
|
+
var BIZ_AUTH_CODES = /* @__PURE__ */ new Set([304, 403, 401]);
|
|
48
|
+
function checkBizError(data, path) {
|
|
49
|
+
if (!data || typeof data !== "object") return;
|
|
50
|
+
const obj = data;
|
|
51
|
+
if (obj.success === false) {
|
|
52
|
+
const code = Number(obj.errorCode ?? 0);
|
|
53
|
+
const errMsg = String(obj.error || obj.message || "\u672A\u77E5\u9519\u8BEF");
|
|
54
|
+
if (BIZ_AUTH_CODES.has(code)) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
`\u6743\u9650\u4E0D\u8DB3: ${errMsg}` + UPGRADE_GUIDE + `
|
|
57
|
+
Endpoint: ${path}`
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
throw new Error(
|
|
61
|
+
`API \u4E1A\u52A1\u9519\u8BEF (${code}): ${errMsg}
|
|
62
|
+
Endpoint: ${path}`
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
47
66
|
var FREE_KEY = "ronJ8uI0Yj2soAfGVs5H1YALUIINbE22";
|
|
48
67
|
var FREE_SECRET = "CWHZcH2us1CLSE7grroR1TpS0Z1JxTwU";
|
|
49
68
|
function getCredentials() {
|
|
@@ -68,9 +87,12 @@ async function apiGet(path, params = {}) {
|
|
|
68
87
|
}
|
|
69
88
|
const text = await res.text();
|
|
70
89
|
try {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return
|
|
90
|
+
const json = JSON.parse(text);
|
|
91
|
+
checkBizError(json, path);
|
|
92
|
+
return json;
|
|
93
|
+
} catch (e) {
|
|
94
|
+
if (e instanceof SyntaxError) return { raw: text };
|
|
95
|
+
throw e;
|
|
74
96
|
}
|
|
75
97
|
}
|
|
76
98
|
async function apiPost(path, body = {}) {
|
|
@@ -89,9 +111,12 @@ async function apiPost(path, body = {}) {
|
|
|
89
111
|
}
|
|
90
112
|
const txt = await res.text();
|
|
91
113
|
try {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return
|
|
114
|
+
const json = JSON.parse(txt);
|
|
115
|
+
checkBizError(json, path);
|
|
116
|
+
return json;
|
|
117
|
+
} catch (e) {
|
|
118
|
+
if (e instanceof SyntaxError) return { raw: txt };
|
|
119
|
+
throw e;
|
|
95
120
|
}
|
|
96
121
|
}
|
|
97
122
|
|