@utcp/http 1.0.12 → 1.0.13
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.cjs +26 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +26 -15
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -4241,6 +4241,7 @@ var import_sdk8 = require("@utcp/sdk");
|
|
|
4241
4241
|
var OpenApiConverter = class {
|
|
4242
4242
|
spec;
|
|
4243
4243
|
spec_url;
|
|
4244
|
+
base_url;
|
|
4244
4245
|
auth_tools;
|
|
4245
4246
|
placeholder_counter = 0;
|
|
4246
4247
|
call_template_name;
|
|
@@ -4248,14 +4249,16 @@ var OpenApiConverter = class {
|
|
|
4248
4249
|
* Initializes the OpenAPI converter.
|
|
4249
4250
|
*
|
|
4250
4251
|
* @param openapi_spec Parsed OpenAPI specification as a dictionary.
|
|
4251
|
-
* @param options Optional settings including spec_url, call_template_name, and
|
|
4252
|
+
* @param options Optional settings including spec_url, call_template_name, auth_tools, and baseUrl.
|
|
4252
4253
|
* - specUrl: URL where the specification was retrieved from.
|
|
4253
4254
|
* - callTemplateName: Custom name for the call_template if spec title not provided.
|
|
4254
4255
|
* - authTools: Optional auth configuration for generated tools.
|
|
4256
|
+
* - baseUrl: Optional base URL override for all API endpoints.
|
|
4255
4257
|
*/
|
|
4256
4258
|
constructor(openapi_spec, options) {
|
|
4257
4259
|
this.spec = openapi_spec;
|
|
4258
4260
|
this.spec_url = options?.specUrl;
|
|
4261
|
+
this.base_url = options?.baseUrl;
|
|
4259
4262
|
this.auth_tools = options?.authTools;
|
|
4260
4263
|
this.placeholder_counter = 0;
|
|
4261
4264
|
let callTemplateName = options?.callTemplateName;
|
|
@@ -4290,10 +4293,15 @@ var OpenApiConverter = class {
|
|
|
4290
4293
|
this.placeholder_counter = 0;
|
|
4291
4294
|
const tools = [];
|
|
4292
4295
|
let baseUrl = "/";
|
|
4293
|
-
|
|
4294
|
-
|
|
4295
|
-
|
|
4296
|
-
|
|
4296
|
+
if (this.base_url) {
|
|
4297
|
+
baseUrl = this.base_url;
|
|
4298
|
+
} else if (this.spec.servers && Array.isArray(this.spec.servers) && this.spec.servers.length > 0 && this.spec.servers[0].url) {
|
|
4299
|
+
baseUrl = this.spec.servers[0].url;
|
|
4300
|
+
} else if (this.spec.host) {
|
|
4301
|
+
const scheme = this.spec.schemes?.[0] || "https";
|
|
4302
|
+
const basePath = this.spec.basePath || "";
|
|
4303
|
+
baseUrl = `${scheme}://${this.spec.host}${basePath}`;
|
|
4304
|
+
} else if (this.spec_url && (this.spec_url.startsWith("http://") || this.spec_url.startsWith("https://"))) {
|
|
4297
4305
|
try {
|
|
4298
4306
|
const parsedUrl = new URL(this.spec_url);
|
|
4299
4307
|
baseUrl = `${parsedUrl.protocol}//${parsedUrl.host}`;
|
|
@@ -4301,7 +4309,7 @@ var OpenApiConverter = class {
|
|
|
4301
4309
|
console.error(`[OpenApiConverter] Invalid spec_url provided: ${this.spec_url}`);
|
|
4302
4310
|
}
|
|
4303
4311
|
} else {
|
|
4304
|
-
console.warn("[OpenApiConverter] No server info
|
|
4312
|
+
console.warn("[OpenApiConverter] No server info found in OpenAPI spec. Using fallback base URL: '/'. Tools may not work correctly without a valid base URL.");
|
|
4305
4313
|
}
|
|
4306
4314
|
const paths = this.spec.paths || {};
|
|
4307
4315
|
for (const [path, pathItem] of Object.entries(paths)) {
|
|
@@ -4871,11 +4879,12 @@ var HttpCommunicationProtocol = class {
|
|
|
4871
4879
|
if (!apiKeyAuth.api_key) {
|
|
4872
4880
|
throw new Error("API key for ApiKeyAuth is empty.");
|
|
4873
4881
|
}
|
|
4874
|
-
|
|
4882
|
+
const location = apiKeyAuth.location || "header";
|
|
4883
|
+
if (location === "header") {
|
|
4875
4884
|
requestConfig.headers = { ...requestConfig.headers, [apiKeyAuth.var_name]: apiKeyAuth.api_key };
|
|
4876
|
-
} else if (
|
|
4885
|
+
} else if (location === "query") {
|
|
4877
4886
|
requestConfig.params = { ...requestConfig.params, [apiKeyAuth.var_name]: apiKeyAuth.api_key };
|
|
4878
|
-
} else if (
|
|
4887
|
+
} else if (location === "cookie") {
|
|
4879
4888
|
cookies[apiKeyAuth.var_name] = apiKeyAuth.api_key;
|
|
4880
4889
|
}
|
|
4881
4890
|
} else if (httpCallTemplate.auth.auth_type === "basic") {
|
|
@@ -5016,11 +5025,12 @@ var StreamableHttpCommunicationProtocol = class {
|
|
|
5016
5025
|
if ("api_key" in provider.auth) {
|
|
5017
5026
|
const apiKeyAuth = provider.auth;
|
|
5018
5027
|
if (apiKeyAuth.api_key) {
|
|
5019
|
-
|
|
5028
|
+
const location = apiKeyAuth.location || "header";
|
|
5029
|
+
if (location === "header") {
|
|
5020
5030
|
headers[apiKeyAuth.var_name] = apiKeyAuth.api_key;
|
|
5021
|
-
} else if (
|
|
5031
|
+
} else if (location === "query") {
|
|
5022
5032
|
queryParams[apiKeyAuth.var_name] = apiKeyAuth.api_key;
|
|
5023
|
-
} else if (
|
|
5033
|
+
} else if (location === "cookie") {
|
|
5024
5034
|
cookies[apiKeyAuth.var_name] = apiKeyAuth.api_key;
|
|
5025
5035
|
}
|
|
5026
5036
|
} else {
|
|
@@ -5147,11 +5157,12 @@ var SseCommunicationProtocol = class {
|
|
|
5147
5157
|
if ("api_key" in provider.auth) {
|
|
5148
5158
|
const apiKeyAuth = provider.auth;
|
|
5149
5159
|
if (apiKeyAuth.api_key) {
|
|
5150
|
-
|
|
5160
|
+
const location = apiKeyAuth.location || "header";
|
|
5161
|
+
if (location === "header") {
|
|
5151
5162
|
headers[apiKeyAuth.var_name] = apiKeyAuth.api_key;
|
|
5152
|
-
} else if (
|
|
5163
|
+
} else if (location === "query") {
|
|
5153
5164
|
queryParams[apiKeyAuth.var_name] = apiKeyAuth.api_key;
|
|
5154
|
-
} else if (
|
|
5165
|
+
} else if (location === "cookie") {
|
|
5155
5166
|
cookies[apiKeyAuth.var_name] = apiKeyAuth.api_key;
|
|
5156
5167
|
}
|
|
5157
5168
|
} else {
|