zinkee 0.1.17 → 0.1.19
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 +47 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/client.test.ts +61 -0
- package/src/client.ts +27 -1
- package/src/commands/profiles.test.ts +109 -0
- package/src/commands/profiles.ts +24 -2
- package/src/config.test.ts +22 -0
- package/src/config.ts +4 -8
- package/src/runtime-context.ts +7 -1
- package/src/utils/errors.test.ts +38 -1
- package/src/utils/errors.ts +10 -2
package/dist/index.js
CHANGED
|
@@ -987,6 +987,21 @@ function parseErrorBody(text, contentType) {
|
|
|
987
987
|
return text;
|
|
988
988
|
}
|
|
989
989
|
}
|
|
990
|
+
function summarizeNetworkCause(cause) {
|
|
991
|
+
const seen = /* @__PURE__ */ new Set();
|
|
992
|
+
let current = cause;
|
|
993
|
+
while (current && typeof current === "object" && !seen.has(current)) {
|
|
994
|
+
seen.add(current);
|
|
995
|
+
const candidate = current;
|
|
996
|
+
const message = typeof candidate.message === "string" ? candidate.message.trim() : "";
|
|
997
|
+
const code = typeof candidate.code === "string" ? candidate.code : void 0;
|
|
998
|
+
if (message && message !== "fetch failed") {
|
|
999
|
+
return code && !message.includes(code) ? `${message} (${code})` : message;
|
|
1000
|
+
}
|
|
1001
|
+
current = candidate.cause;
|
|
1002
|
+
}
|
|
1003
|
+
return void 0;
|
|
1004
|
+
}
|
|
990
1005
|
var ApiClient = class {
|
|
991
1006
|
constructor(options) {
|
|
992
1007
|
this.options = options;
|
|
@@ -1061,7 +1076,9 @@ var ApiClient = class {
|
|
|
1061
1076
|
cause
|
|
1062
1077
|
});
|
|
1063
1078
|
}
|
|
1064
|
-
|
|
1079
|
+
const causeSummary = summarizeNetworkCause(cause);
|
|
1080
|
+
const message = causeSummary ? `Request failed for ${method} ${url}: ${causeSummary}.` : `Request failed for ${method} ${url}.`;
|
|
1081
|
+
throw new ApiClientError("network_error", message, {
|
|
1065
1082
|
url,
|
|
1066
1083
|
method,
|
|
1067
1084
|
cause
|
|
@@ -1139,7 +1156,11 @@ var cliExitCodeByErrorCode = {
|
|
|
1139
1156
|
unknown_error: 1,
|
|
1140
1157
|
invalid_cli_usage: 2,
|
|
1141
1158
|
configuration_error: 2,
|
|
1142
|
-
command_not_allowed_in_read_only_mode: 7
|
|
1159
|
+
command_not_allowed_in_read_only_mode: 7,
|
|
1160
|
+
network_error: 1,
|
|
1161
|
+
http_error: 1,
|
|
1162
|
+
timeout: 1,
|
|
1163
|
+
invalid_json: 1
|
|
1143
1164
|
};
|
|
1144
1165
|
var errorCodeByName = {
|
|
1145
1166
|
ProfileResolutionError: "configuration_error"
|
|
@@ -1216,7 +1237,7 @@ function toCliError(error) {
|
|
|
1216
1237
|
}
|
|
1217
1238
|
if (error instanceof ApiClientError) {
|
|
1218
1239
|
const apiError = extractApiErrorDetails(error);
|
|
1219
|
-
return new CliError(
|
|
1240
|
+
return new CliError(error.code, apiError.message, apiError.details);
|
|
1220
1241
|
}
|
|
1221
1242
|
if (error instanceof Error) {
|
|
1222
1243
|
return new CliError(errorCodeByName[error.name] ?? "unknown_error", error.message);
|
|
@@ -5854,19 +5875,15 @@ function resolveProfile(config, overrides = {}) {
|
|
|
5854
5875
|
}
|
|
5855
5876
|
throw new ProfileResolutionError("No profile could be resolved from config.");
|
|
5856
5877
|
}
|
|
5857
|
-
function validateBaseUrl(value) {
|
|
5878
|
+
function validateBaseUrl(value, source = "Base URL") {
|
|
5858
5879
|
let parsed;
|
|
5859
5880
|
try {
|
|
5860
5881
|
parsed = new URL(value);
|
|
5861
5882
|
} catch {
|
|
5862
|
-
throw new ProfileResolutionError(
|
|
5863
|
-
`Environment variable ${ENV_BASE_URL} must be an absolute http(s) URL.`
|
|
5864
|
-
);
|
|
5883
|
+
throw new ProfileResolutionError(`${source} must be an absolute http(s) URL.`);
|
|
5865
5884
|
}
|
|
5866
5885
|
if (!["http:", "https:"].includes(parsed.protocol) || !parsed.host) {
|
|
5867
|
-
throw new ProfileResolutionError(
|
|
5868
|
-
`Environment variable ${ENV_BASE_URL} must be an absolute http(s) URL.`
|
|
5869
|
-
);
|
|
5886
|
+
throw new ProfileResolutionError(`${source} must be an absolute http(s) URL.`);
|
|
5870
5887
|
}
|
|
5871
5888
|
return value.replace(/\/+$/, "");
|
|
5872
5889
|
}
|
|
@@ -5878,7 +5895,7 @@ function readEnvBaseUrl(env = process.env) {
|
|
|
5878
5895
|
if (!baseUrl) {
|
|
5879
5896
|
return void 0;
|
|
5880
5897
|
}
|
|
5881
|
-
return validateBaseUrl(baseUrl);
|
|
5898
|
+
return validateBaseUrl(baseUrl, `Environment variable ${ENV_BASE_URL}`);
|
|
5882
5899
|
}
|
|
5883
5900
|
function readEnvProfile(env = process.env) {
|
|
5884
5901
|
return toNonEmptyString(env[ENV_PROFILE]);
|
|
@@ -6233,9 +6250,10 @@ function resolveRuntimeContext(config, overrides = {}) {
|
|
|
6233
6250
|
const envProfile = readEnvProfile();
|
|
6234
6251
|
const envApiKey = readEnvApiKey();
|
|
6235
6252
|
const envBaseUrl = readEnvBaseUrl();
|
|
6253
|
+
const flagBaseUrl = overrides.baseUrl !== void 0 ? validateBaseUrl(overrides.baseUrl, '"--base-url"') : void 0;
|
|
6236
6254
|
const profileOverride = overrides.profile ?? envProfile;
|
|
6237
6255
|
const apiKeyOverride = overrides.apiKey ?? envApiKey;
|
|
6238
|
-
const baseUrlOverride =
|
|
6256
|
+
const baseUrlOverride = flagBaseUrl ?? envBaseUrl;
|
|
6239
6257
|
if (apiKeyOverride && !baseUrlOverride) {
|
|
6240
6258
|
throw new ProfileResolutionError(
|
|
6241
6259
|
`Runtime API key was provided, but ${ENV_BASE_URL} or --base-url is missing.`
|
|
@@ -9049,6 +9067,19 @@ function toDisplayProfile(profileName, profile, defaultProfile) {
|
|
|
9049
9067
|
function loadConfigForAdd(filePath) {
|
|
9050
9068
|
return readConfigIfExists(filePath) ?? { profiles: {} };
|
|
9051
9069
|
}
|
|
9070
|
+
function normalizeProfileBaseUrl(baseUrl) {
|
|
9071
|
+
if (baseUrl === void 0) {
|
|
9072
|
+
return void 0;
|
|
9073
|
+
}
|
|
9074
|
+
try {
|
|
9075
|
+
return validateBaseUrl(baseUrl, '"--base-url"');
|
|
9076
|
+
} catch (error) {
|
|
9077
|
+
if (error instanceof ProfileResolutionError) {
|
|
9078
|
+
throw new CliError("configuration_error", error.message);
|
|
9079
|
+
}
|
|
9080
|
+
throw error;
|
|
9081
|
+
}
|
|
9082
|
+
}
|
|
9052
9083
|
function emitProfilesTable(stdout, data) {
|
|
9053
9084
|
printTable(
|
|
9054
9085
|
data.map((profile) => ({
|
|
@@ -9109,9 +9140,10 @@ function registerProfilesCommands(program, options = {}) {
|
|
|
9109
9140
|
`Profile "${profileName}" already exists in config.`
|
|
9110
9141
|
);
|
|
9111
9142
|
}
|
|
9143
|
+
const baseUrl = normalizeProfileBaseUrl(commandOptions.baseUrl);
|
|
9112
9144
|
let nextConfig = setProfileConfig(config, profileName, {
|
|
9113
9145
|
apiKey: commandOptions.apiKey,
|
|
9114
|
-
baseUrl
|
|
9146
|
+
baseUrl
|
|
9115
9147
|
});
|
|
9116
9148
|
if (!nextConfig.defaultProfile) {
|
|
9117
9149
|
nextConfig = setDefaultProfile(nextConfig, profileName);
|
|
@@ -9137,9 +9169,10 @@ function registerProfilesCommands(program, options = {}) {
|
|
|
9137
9169
|
}
|
|
9138
9170
|
const config = readRequiredConfig(filePath);
|
|
9139
9171
|
getRequiredProfile(config, profileName);
|
|
9172
|
+
const baseUrl = normalizeProfileBaseUrl(commandOptions.baseUrl);
|
|
9140
9173
|
const nextConfig = setProfileConfig(config, profileName, {
|
|
9141
9174
|
apiKey: commandOptions.apiKey,
|
|
9142
|
-
baseUrl
|
|
9175
|
+
baseUrl
|
|
9143
9176
|
});
|
|
9144
9177
|
writeConfig(nextConfig, filePath);
|
|
9145
9178
|
const data = toDisplayProfile(
|