ability-cli 0.3.4 → 0.3.6
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/index.js +25 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var DEFAULT_CONFIG = {
|
|
|
14
14
|
env: "prod",
|
|
15
15
|
profiles: {
|
|
16
16
|
test: {
|
|
17
|
-
baseUrl: "https://biz-gw.
|
|
17
|
+
baseUrl: "https://biz-gw.t-stepos.com",
|
|
18
18
|
authToken: ""
|
|
19
19
|
},
|
|
20
20
|
stg: {
|
|
@@ -22,7 +22,7 @@ var DEFAULT_CONFIG = {
|
|
|
22
22
|
authToken: ""
|
|
23
23
|
},
|
|
24
24
|
prod: {
|
|
25
|
-
baseUrl: "https://biz-gw.
|
|
25
|
+
baseUrl: "https://biz-gw.stepos.com",
|
|
26
26
|
authToken: ""
|
|
27
27
|
}
|
|
28
28
|
},
|
|
@@ -135,14 +135,15 @@ function printAbilityDetail(a) {
|
|
|
135
135
|
console.log(JSON.stringify(a.inputSchema, null, 2));
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
|
-
function
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
printError(`\u63A5\u53E3\u8FD4\u56DE\u9519\u8BEF: [${res.code}] ${msg}`);
|
|
143
|
-
process.exit(4);
|
|
138
|
+
function extractApiPayload(res) {
|
|
139
|
+
if (res && typeof res === "object" && "data" in res) {
|
|
140
|
+
const data = res.data;
|
|
141
|
+
if (data !== void 0) return data;
|
|
144
142
|
}
|
|
145
|
-
|
|
143
|
+
return res;
|
|
144
|
+
}
|
|
145
|
+
function handleApiResponse(res, jsonMode, formatter) {
|
|
146
|
+
const payload = extractApiPayload(res);
|
|
146
147
|
if (jsonMode) {
|
|
147
148
|
printJson(payload);
|
|
148
149
|
} else {
|
|
@@ -219,7 +220,7 @@ function buildAgentRequestContext(merged) {
|
|
|
219
220
|
merged.baseUrl,
|
|
220
221
|
process.env.ABILITY_CLI_BASE_URL,
|
|
221
222
|
profile.baseUrl,
|
|
222
|
-
"https://biz-gw.
|
|
223
|
+
"https://biz-gw.stepos.com"
|
|
223
224
|
);
|
|
224
225
|
return {
|
|
225
226
|
baseUrl,
|
|
@@ -261,7 +262,7 @@ async function apiGet(ctx, path2, params) {
|
|
|
261
262
|
console.error(`[verbose] Headers: ${JSON.stringify(headers, null, 2)}`);
|
|
262
263
|
}
|
|
263
264
|
const res = await fetch(url, { headers });
|
|
264
|
-
const body = await res
|
|
265
|
+
const body = await readJsonResponse(res, ctx);
|
|
265
266
|
if (ctx.verbose) console.error(`[verbose] Response: ${JSON.stringify(body, null, 2)}`);
|
|
266
267
|
return body;
|
|
267
268
|
}
|
|
@@ -279,10 +280,22 @@ async function apiPost(ctx, path2, data) {
|
|
|
279
280
|
headers,
|
|
280
281
|
body: JSON.stringify(data)
|
|
281
282
|
});
|
|
282
|
-
const body = await res
|
|
283
|
+
const body = await readJsonResponse(res, ctx);
|
|
283
284
|
if (ctx.verbose) console.error(`[verbose] Response: ${JSON.stringify(body, null, 2)}`);
|
|
284
285
|
return body;
|
|
285
286
|
}
|
|
287
|
+
async function readJsonResponse(res, ctx) {
|
|
288
|
+
const text = await res.text();
|
|
289
|
+
if (!res.ok) {
|
|
290
|
+
throw new Error(`HTTP ${res.status} ${res.statusText}: ${text.slice(0, 500)}`);
|
|
291
|
+
}
|
|
292
|
+
if (!text.trim()) return {};
|
|
293
|
+
try {
|
|
294
|
+
return JSON.parse(text);
|
|
295
|
+
} catch {
|
|
296
|
+
throw new Error(`\u54CD\u5E94\u4E0D\u662F\u5408\u6CD5 JSON (HTTP ${res.status}): ${text.slice(0, 200)}`);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
286
299
|
|
|
287
300
|
// src/commands/raw.ts
|
|
288
301
|
import fs3 from "fs";
|