@mittwald/cli 1.13.4 → 1.13.5

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.
@@ -0,0 +1,2 @@
1
+ import { AxiosInstance } from "@mittwald/api-client-commons";
2
+ export declare function configureAxiosBaseURL(axios: AxiosInstance, baseURL: string): void;
@@ -0,0 +1,17 @@
1
+ export function configureAxiosBaseURL(axios, baseURL) {
2
+ const trimmedBaseURL = baseURL.trim();
3
+ if (!trimmedBaseURL) {
4
+ throw new Error("MITTWALD_API_BASE_URL is empty or contains only whitespace. Please provide a valid absolute URL.");
5
+ }
6
+ let parsedUrl;
7
+ try {
8
+ parsedUrl = new URL(trimmedBaseURL);
9
+ }
10
+ catch {
11
+ throw new Error(`MITTWALD_API_BASE_URL="${trimmedBaseURL}" is not a valid absolute URL. Please provide a value like "https://api.example.com".`);
12
+ }
13
+ if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:") {
14
+ throw new Error(`MITTWALD_API_BASE_URL="${trimmedBaseURL}" must use http or https scheme. Received protocol "${parsedUrl.protocol}".`);
15
+ }
16
+ axios.defaults.baseURL = parsedUrl.toString();
17
+ }
@@ -5,6 +5,7 @@ import { CoreBaseCommand } from "./CoreBaseCommand.js";
5
5
  import { configureAxiosLogging } from "../apiutil/api_logging.js";
6
6
  import { configureAxiosRetry } from "../apiutil/api_retry.js";
7
7
  import { configureConsistencyHandling } from "../apiutil/api_consistency.js";
8
+ import { configureAxiosBaseURL } from "../apiutil/api_baseurl.js";
8
9
  import NoTokenFoundError from "../error/NoTokenFoundError.js";
9
10
  /** Base command class for authenticated commands that includes the --token flag. */
10
11
  export class BaseCommand extends CoreBaseCommand {
@@ -27,6 +28,22 @@ export class BaseCommand extends CoreBaseCommand {
27
28
  this.apiClient = MittwaldAPIV2Client.newWithToken(token);
28
29
  this.apiClient.axios.defaults.headers["User-Agent"] =
29
30
  `mittwald-cli/${this.config.version}`;
31
+ // Allow overriding API base URL for local testing/mocking.
32
+ // NOTE: This is intentionally dangerous; be careful not to leak tokens
33
+ // to unintended hosts via a leftover environment variable.
34
+ const rawBaseUrlEnv = process.env.MITTWALD_API_BASE_URL;
35
+ const overriddenBaseUrl = typeof rawBaseUrlEnv === "string" ? rawBaseUrlEnv.trim() : "";
36
+ if (overriddenBaseUrl) {
37
+ try {
38
+ const parsed = new URL(overriddenBaseUrl);
39
+ // Warn the user that requests (including tokens) will be sent to a non-default host.
40
+ this.warn(`Using overridden API base URL from MITTWALD_API_BASE_URL (host: ${parsed.host}).`);
41
+ configureAxiosBaseURL(this.apiClient.axios, overriddenBaseUrl);
42
+ }
43
+ catch {
44
+ this.warn("Ignoring MITTWALD_API_BASE_URL because it is not a valid URL.");
45
+ }
46
+ }
30
47
  configureAxiosLogging(this.apiClient.axios);
31
48
  configureAxiosRetry(this.apiClient.axios);
32
49
  configureConsistencyHandling(this.apiClient.axios);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mittwald/cli",
3
- "version": "1.13.4",
3
+ "version": "1.13.5",
4
4
  "description": "Hand-crafted CLI for the mittwald API",
5
5
  "license": "MIT",
6
6
  "repository": {