wasper-cli 0.3.2 → 0.3.3
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/cli.js +19 -4
- package/dist/index.js +19 -4
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -21,7 +21,7 @@ var package_default;
|
|
|
21
21
|
var init_package = __esm(() => {
|
|
22
22
|
package_default = {
|
|
23
23
|
name: "wasper-cli",
|
|
24
|
-
version: "0.3.
|
|
24
|
+
version: "0.3.3",
|
|
25
25
|
description: "Host an MCP server + API proxy from any OpenAPI spec. Like Drizzle Studio, but for APIs.",
|
|
26
26
|
type: "module",
|
|
27
27
|
homepage: "https://wasper.site",
|
|
@@ -4786,6 +4786,11 @@ function parseSpecText(text, url, name) {
|
|
|
4786
4786
|
const info = doc.info ?? {};
|
|
4787
4787
|
const servers = doc.servers ?? [];
|
|
4788
4788
|
let baseUrl = servers[0]?.url ?? "";
|
|
4789
|
+
if (!baseUrl && doc.swagger && doc.host) {
|
|
4790
|
+
const scheme = doc.schemes?.[0] ?? "https";
|
|
4791
|
+
const basePath = typeof doc.basePath === "string" ? doc.basePath.replace(/\/$/, "") : "";
|
|
4792
|
+
baseUrl = `${scheme}://${doc.host}${basePath}`;
|
|
4793
|
+
}
|
|
4789
4794
|
if (!baseUrl && url) {
|
|
4790
4795
|
try {
|
|
4791
4796
|
baseUrl = new URL(url).origin;
|
|
@@ -6869,6 +6874,7 @@ async function handleSpecUpload(req) {
|
|
|
6869
6874
|
try {
|
|
6870
6875
|
const state = loadSpecFromText(content, filename);
|
|
6871
6876
|
const suggestedVars = extractSuggestedVars(content, state.spec.baseUrl);
|
|
6877
|
+
logBus.broadcastServerEvent({ kind: "spec_changed" });
|
|
6872
6878
|
return json({
|
|
6873
6879
|
ok: true,
|
|
6874
6880
|
spec: { title: state.spec.title, version: state.spec.version, baseUrl: state.spec.baseUrl },
|
|
@@ -6891,6 +6897,7 @@ async function handleSpecReloadUrl(req) {
|
|
|
6891
6897
|
try {
|
|
6892
6898
|
const state = await loadSpec(body.url);
|
|
6893
6899
|
const suggestedVars = extractSuggestedVars(state.spec.raw, state.spec.baseUrl);
|
|
6900
|
+
logBus.broadcastServerEvent({ kind: "spec_changed" });
|
|
6894
6901
|
return json({
|
|
6895
6902
|
ok: true,
|
|
6896
6903
|
spec: { title: state.spec.title, version: state.spec.version, baseUrl: state.spec.baseUrl },
|
|
@@ -6902,7 +6909,8 @@ async function handleSpecReloadUrl(req) {
|
|
|
6902
6909
|
}
|
|
6903
6910
|
}
|
|
6904
6911
|
function handleGetLogs(searchParams) {
|
|
6905
|
-
const
|
|
6912
|
+
const raw = parseInt(searchParams.get("limit") ?? "500", 10);
|
|
6913
|
+
const limit = Math.min(Number.isFinite(raw) ? raw : 500, 2000);
|
|
6906
6914
|
return json(dbQueries.getRecentLogs(limit));
|
|
6907
6915
|
}
|
|
6908
6916
|
function handleClearLogs() {
|
|
@@ -6924,6 +6932,8 @@ async function handleSetAuth(req) {
|
|
|
6924
6932
|
return json({ type: body.type, config: body.config });
|
|
6925
6933
|
}
|
|
6926
6934
|
async function handleTestAuth() {
|
|
6935
|
+
if (!hasState())
|
|
6936
|
+
return badRequest("No spec loaded");
|
|
6927
6937
|
const { spec } = getState();
|
|
6928
6938
|
const authRow = dbQueries.getAuthConfig();
|
|
6929
6939
|
const authConfig = authRow ? JSON.parse(authRow.config) : { type: "none" };
|
|
@@ -6937,6 +6947,8 @@ async function handleTestAuth() {
|
|
|
6937
6947
|
}
|
|
6938
6948
|
}
|
|
6939
6949
|
function handleGetEndpoints() {
|
|
6950
|
+
if (!hasState())
|
|
6951
|
+
return json([]);
|
|
6940
6952
|
return json(getState().operations);
|
|
6941
6953
|
}
|
|
6942
6954
|
function handleGetSettings() {
|
|
@@ -6958,6 +6970,8 @@ async function handleSetSettings(req) {
|
|
|
6958
6970
|
return json(body);
|
|
6959
6971
|
}
|
|
6960
6972
|
async function executeTool(name, args, cache = new Map) {
|
|
6973
|
+
if (!hasState())
|
|
6974
|
+
return { text: "No spec loaded.", isError: true };
|
|
6961
6975
|
const { operations, spec } = getState();
|
|
6962
6976
|
if (name === "search_endpoints") {
|
|
6963
6977
|
const cacheKey2 = `search:${String(args.query ?? "").toLowerCase()}`;
|
|
@@ -7617,10 +7631,11 @@ async function handleExplorerRequest(req) {
|
|
|
7617
7631
|
};
|
|
7618
7632
|
if (timeoutMs > 0)
|
|
7619
7633
|
fetchOpts.signal = AbortSignal.timeout(timeoutMs);
|
|
7634
|
+
const parsedUrl = new URL(authedUrl);
|
|
7620
7635
|
let dnsMs = 0;
|
|
7621
7636
|
let resolvedAddr = "";
|
|
7622
7637
|
try {
|
|
7623
|
-
const u =
|
|
7638
|
+
const u = parsedUrl;
|
|
7624
7639
|
const h = u.hostname;
|
|
7625
7640
|
const defaultPort = u.protocol === "https:" ? 443 : 80;
|
|
7626
7641
|
const port = u.port ? Number(u.port) : defaultPort;
|
|
@@ -7639,7 +7654,7 @@ async function handleExplorerRequest(req) {
|
|
|
7639
7654
|
const waitMs = Math.round(performance.now() - fetchStart);
|
|
7640
7655
|
const resHeaders = Object.fromEntries(res.headers.entries());
|
|
7641
7656
|
const ct = res.headers.get("content-type") ?? "";
|
|
7642
|
-
const u =
|
|
7657
|
+
const u = parsedUrl;
|
|
7643
7658
|
const networkInfo = {
|
|
7644
7659
|
scheme: u.protocol.replace(":", ""),
|
|
7645
7660
|
host: u.host,
|
package/dist/index.js
CHANGED
|
@@ -2786,6 +2786,11 @@ function parseSpecText(text, url, name) {
|
|
|
2786
2786
|
const info = doc.info ?? {};
|
|
2787
2787
|
const servers = doc.servers ?? [];
|
|
2788
2788
|
let baseUrl = servers[0]?.url ?? "";
|
|
2789
|
+
if (!baseUrl && doc.swagger && doc.host) {
|
|
2790
|
+
const scheme = doc.schemes?.[0] ?? "https";
|
|
2791
|
+
const basePath = typeof doc.basePath === "string" ? doc.basePath.replace(/\/$/, "") : "";
|
|
2792
|
+
baseUrl = `${scheme}://${doc.host}${basePath}`;
|
|
2793
|
+
}
|
|
2789
2794
|
if (!baseUrl && url) {
|
|
2790
2795
|
try {
|
|
2791
2796
|
baseUrl = new URL(url).origin;
|
|
@@ -3607,7 +3612,7 @@ var package_default;
|
|
|
3607
3612
|
var init_package = __esm(() => {
|
|
3608
3613
|
package_default = {
|
|
3609
3614
|
name: "wasper-cli",
|
|
3610
|
-
version: "0.3.
|
|
3615
|
+
version: "0.3.3",
|
|
3611
3616
|
description: "Host an MCP server + API proxy from any OpenAPI spec. Like Drizzle Studio, but for APIs.",
|
|
3612
3617
|
type: "module",
|
|
3613
3618
|
homepage: "https://wasper.site",
|
|
@@ -5316,6 +5321,7 @@ async function handleSpecUpload(req) {
|
|
|
5316
5321
|
try {
|
|
5317
5322
|
const state = loadSpecFromText(content, filename);
|
|
5318
5323
|
const suggestedVars = extractSuggestedVars(content, state.spec.baseUrl);
|
|
5324
|
+
logBus.broadcastServerEvent({ kind: "spec_changed" });
|
|
5319
5325
|
return json({
|
|
5320
5326
|
ok: true,
|
|
5321
5327
|
spec: { title: state.spec.title, version: state.spec.version, baseUrl: state.spec.baseUrl },
|
|
@@ -5338,6 +5344,7 @@ async function handleSpecReloadUrl(req) {
|
|
|
5338
5344
|
try {
|
|
5339
5345
|
const state = await loadSpec(body.url);
|
|
5340
5346
|
const suggestedVars = extractSuggestedVars(state.spec.raw, state.spec.baseUrl);
|
|
5347
|
+
logBus.broadcastServerEvent({ kind: "spec_changed" });
|
|
5341
5348
|
return json({
|
|
5342
5349
|
ok: true,
|
|
5343
5350
|
spec: { title: state.spec.title, version: state.spec.version, baseUrl: state.spec.baseUrl },
|
|
@@ -5349,7 +5356,8 @@ async function handleSpecReloadUrl(req) {
|
|
|
5349
5356
|
}
|
|
5350
5357
|
}
|
|
5351
5358
|
function handleGetLogs(searchParams) {
|
|
5352
|
-
const
|
|
5359
|
+
const raw = parseInt(searchParams.get("limit") ?? "500", 10);
|
|
5360
|
+
const limit = Math.min(Number.isFinite(raw) ? raw : 500, 2000);
|
|
5353
5361
|
return json(dbQueries.getRecentLogs(limit));
|
|
5354
5362
|
}
|
|
5355
5363
|
function handleClearLogs() {
|
|
@@ -5371,6 +5379,8 @@ async function handleSetAuth(req) {
|
|
|
5371
5379
|
return json({ type: body.type, config: body.config });
|
|
5372
5380
|
}
|
|
5373
5381
|
async function handleTestAuth() {
|
|
5382
|
+
if (!hasState())
|
|
5383
|
+
return badRequest("No spec loaded");
|
|
5374
5384
|
const { spec } = getState();
|
|
5375
5385
|
const authRow = dbQueries.getAuthConfig();
|
|
5376
5386
|
const authConfig = authRow ? JSON.parse(authRow.config) : { type: "none" };
|
|
@@ -5384,6 +5394,8 @@ async function handleTestAuth() {
|
|
|
5384
5394
|
}
|
|
5385
5395
|
}
|
|
5386
5396
|
function handleGetEndpoints() {
|
|
5397
|
+
if (!hasState())
|
|
5398
|
+
return json([]);
|
|
5387
5399
|
return json(getState().operations);
|
|
5388
5400
|
}
|
|
5389
5401
|
function handleGetSettings() {
|
|
@@ -5405,6 +5417,8 @@ async function handleSetSettings(req) {
|
|
|
5405
5417
|
return json(body);
|
|
5406
5418
|
}
|
|
5407
5419
|
async function executeTool(name, args, cache = new Map) {
|
|
5420
|
+
if (!hasState())
|
|
5421
|
+
return { text: "No spec loaded.", isError: true };
|
|
5408
5422
|
const { operations, spec } = getState();
|
|
5409
5423
|
if (name === "search_endpoints") {
|
|
5410
5424
|
const cacheKey2 = `search:${String(args.query ?? "").toLowerCase()}`;
|
|
@@ -6064,10 +6078,11 @@ async function handleExplorerRequest(req) {
|
|
|
6064
6078
|
};
|
|
6065
6079
|
if (timeoutMs > 0)
|
|
6066
6080
|
fetchOpts.signal = AbortSignal.timeout(timeoutMs);
|
|
6081
|
+
const parsedUrl = new URL(authedUrl);
|
|
6067
6082
|
let dnsMs = 0;
|
|
6068
6083
|
let resolvedAddr = "";
|
|
6069
6084
|
try {
|
|
6070
|
-
const u =
|
|
6085
|
+
const u = parsedUrl;
|
|
6071
6086
|
const h = u.hostname;
|
|
6072
6087
|
const defaultPort = u.protocol === "https:" ? 443 : 80;
|
|
6073
6088
|
const port = u.port ? Number(u.port) : defaultPort;
|
|
@@ -6086,7 +6101,7 @@ async function handleExplorerRequest(req) {
|
|
|
6086
6101
|
const waitMs = Math.round(performance.now() - fetchStart);
|
|
6087
6102
|
const resHeaders = Object.fromEntries(res.headers.entries());
|
|
6088
6103
|
const ct = res.headers.get("content-type") ?? "";
|
|
6089
|
-
const u =
|
|
6104
|
+
const u = parsedUrl;
|
|
6090
6105
|
const networkInfo = {
|
|
6091
6106
|
scheme: u.protocol.replace(":", ""),
|
|
6092
6107
|
host: u.host,
|