metheus-governance-mcp-cli 0.2.161 → 0.2.162
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/cli.mjs +49 -4
- package/package.json +1 -1
package/cli.mjs
CHANGED
|
@@ -3047,6 +3047,17 @@ async function postJSONWithAuthHeaders(urlText, timeoutSeconds, token, payload,
|
|
|
3047
3047
|
});
|
|
3048
3048
|
}
|
|
3049
3049
|
|
|
3050
|
+
function isRetryableNetworkError(error) {
|
|
3051
|
+
const text = String(error?.message || error || "").trim();
|
|
3052
|
+
return /ECONNABORTED|ECONNRESET|ETIMEDOUT|socket hang up|http timeout|aborted/i.test(text);
|
|
3053
|
+
}
|
|
3054
|
+
|
|
3055
|
+
function sleepMs(delayMs) {
|
|
3056
|
+
return new Promise((resolve) => {
|
|
3057
|
+
setTimeout(resolve, Math.max(0, Number(delayMs) || 0));
|
|
3058
|
+
});
|
|
3059
|
+
}
|
|
3060
|
+
|
|
3050
3061
|
async function putJSONWithAuthHeaders(urlText, timeoutSeconds, token, payload, extraHeaders = {}) {
|
|
3051
3062
|
return new Promise((resolve, reject) => {
|
|
3052
3063
|
const url = new URL(urlText);
|
|
@@ -3094,6 +3105,34 @@ async function putJSONWithAuthHeaders(urlText, timeoutSeconds, token, payload, e
|
|
|
3094
3105
|
});
|
|
3095
3106
|
}
|
|
3096
3107
|
|
|
3108
|
+
async function putJSONWithAuthHeadersWithRetry(
|
|
3109
|
+
urlText,
|
|
3110
|
+
timeoutSeconds,
|
|
3111
|
+
token,
|
|
3112
|
+
payload,
|
|
3113
|
+
extraHeaders = {},
|
|
3114
|
+
options = {},
|
|
3115
|
+
) {
|
|
3116
|
+
const attempts = Math.max(1, Number(options.attempts) || 1);
|
|
3117
|
+
const initialBackoffMs = Math.max(0, Number(options.initialBackoffMs) || 0);
|
|
3118
|
+
let lastError = null;
|
|
3119
|
+
for (let attempt = 1; attempt <= attempts; attempt += 1) {
|
|
3120
|
+
try {
|
|
3121
|
+
return await putJSONWithAuthHeaders(urlText, timeoutSeconds, token, payload, extraHeaders);
|
|
3122
|
+
} catch (error) {
|
|
3123
|
+
lastError = error;
|
|
3124
|
+
if (attempt >= attempts || !isRetryableNetworkError(error)) {
|
|
3125
|
+
break;
|
|
3126
|
+
}
|
|
3127
|
+
const backoffMs = initialBackoffMs > 0 ? initialBackoffMs * attempt : 0;
|
|
3128
|
+
if (backoffMs > 0) {
|
|
3129
|
+
await sleepMs(backoffMs);
|
|
3130
|
+
}
|
|
3131
|
+
}
|
|
3132
|
+
}
|
|
3133
|
+
throw lastError;
|
|
3134
|
+
}
|
|
3135
|
+
|
|
3097
3136
|
function inferCtxpackDocTypeFromPath(relativePath, artifactKind = "", existingDocType = "") {
|
|
3098
3137
|
const explicit = String(existingDocType || "").trim().toLowerCase();
|
|
3099
3138
|
if (explicit) {
|
|
@@ -3188,9 +3227,10 @@ async function replaceProjectCtxpackFiles({
|
|
|
3188
3227
|
throw new Error("invalid project_id for ctxpack update");
|
|
3189
3228
|
}
|
|
3190
3229
|
const ctxpackURL = `${siteBaseURL}/api/v1/projects/${encodeURIComponent(projectID)}/ctxpack`;
|
|
3230
|
+
const ctxpackUpdateURL = `${ctxpackURL}?response=minimal`;
|
|
3191
3231
|
const currentCtxpack = safeObject(await getJSONWithAuthHeaders(
|
|
3192
3232
|
ctxpackURL,
|
|
3193
|
-
timeoutSeconds,
|
|
3233
|
+
Math.max(timeoutSeconds, 60),
|
|
3194
3234
|
token,
|
|
3195
3235
|
{ "X-Actor-User-Id": actorUserID },
|
|
3196
3236
|
));
|
|
@@ -3249,9 +3289,9 @@ async function replaceProjectCtxpackFiles({
|
|
|
3249
3289
|
if (!files.length) {
|
|
3250
3290
|
throw new Error("ctxpack update produced no pushable ctxpack files");
|
|
3251
3291
|
}
|
|
3252
|
-
const responseText = await
|
|
3253
|
-
|
|
3254
|
-
timeoutSeconds,
|
|
3292
|
+
const responseText = await putJSONWithAuthHeadersWithRetry(
|
|
3293
|
+
ctxpackUpdateURL,
|
|
3294
|
+
Math.max(timeoutSeconds, 60),
|
|
3255
3295
|
token,
|
|
3256
3296
|
{
|
|
3257
3297
|
version_id: versionID,
|
|
@@ -3259,6 +3299,11 @@ async function replaceProjectCtxpackFiles({
|
|
|
3259
3299
|
},
|
|
3260
3300
|
{
|
|
3261
3301
|
"X-Actor-User-Id": actorUserID,
|
|
3302
|
+
Prefer: "return=minimal",
|
|
3303
|
+
},
|
|
3304
|
+
{
|
|
3305
|
+
attempts: 3,
|
|
3306
|
+
initialBackoffMs: 500,
|
|
3262
3307
|
},
|
|
3263
3308
|
);
|
|
3264
3309
|
const parsed = safeObject(parseJSONText(responseText));
|