@senticor/hive 1.163.0 → 1.164.0
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/hive.cjs +467 -396
- package/package.json +1 -1
package/hive.cjs
CHANGED
|
@@ -9419,9 +9419,328 @@ async function freshToken(minValidityMs = REFRESH_SKEW_MS) {
|
|
|
9419
9419
|
}
|
|
9420
9420
|
return refreshToken(creds);
|
|
9421
9421
|
}
|
|
9422
|
-
|
|
9423
|
-
|
|
9424
|
-
|
|
9422
|
+
function tokenFailureExit(failure2, minTtlSeconds) {
|
|
9423
|
+
switch (failure2.reason) {
|
|
9424
|
+
case "not_logged_in":
|
|
9425
|
+
return { code: EXIT_NOT_AUTHORIZED, symbolic: "NOT_AUTHENTICATED", issuerFailure: false, message: "not logged in. Run 'hive login' first." };
|
|
9426
|
+
case "no_refresh_token": {
|
|
9427
|
+
const left = Math.round((failure2.expiresAt - Date.now()) / 1e3);
|
|
9428
|
+
const state = left > 0 ? `has ${left} s left, less than --min-ttl ${minTtlSeconds ?? 60},` : "has expired";
|
|
9429
|
+
return { code: EXIT_NOT_AUTHORIZED, symbolic: "NOT_AUTHENTICATED", issuerFailure: false, message: `the stored token ${state} and the login holds no refresh token. Run 'hive login' again.` };
|
|
9430
|
+
}
|
|
9431
|
+
case "refresh_refused":
|
|
9432
|
+
return { code: EXIT_NOT_AUTHORIZED, symbolic: "NOT_AUTHENTICATED", issuerFailure: false, message: `the issuer refused to refresh the login (${failure2.detail}). Run 'hive login' again.` };
|
|
9433
|
+
case "issuer_unreachable":
|
|
9434
|
+
return { code: EXIT_TRANSPORT_FAILED, symbolic: "ISSUER_UNREACHABLE", issuerFailure: true, message: `could not reach ${failure2.issuer} to refresh the login. The login is kept; try again.` };
|
|
9435
|
+
case "issuer_error":
|
|
9436
|
+
return { code: EXIT_REMOTE_FAILED, symbolic: "ISSUER_ERROR", issuerFailure: true, message: `${failure2.issuer} did not refresh the login: ${failure2.detail}. The login is kept; try again.` };
|
|
9437
|
+
}
|
|
9438
|
+
}
|
|
9439
|
+
function refreshThrowExit(err) {
|
|
9440
|
+
const issuer = getStoredCredentials()?.issuer ?? "the issuer";
|
|
9441
|
+
return {
|
|
9442
|
+
code: EXIT_TRANSPORT_FAILED,
|
|
9443
|
+
symbolic: "ISSUER_UNREACHABLE",
|
|
9444
|
+
issuerFailure: true,
|
|
9445
|
+
message: `could not reach ${issuer} to refresh the login: ${err.message}. The login is kept; try again.`
|
|
9446
|
+
};
|
|
9447
|
+
}
|
|
9448
|
+
|
|
9449
|
+
// src/lib/errors.ts
|
|
9450
|
+
init_cjs_shims();
|
|
9451
|
+
|
|
9452
|
+
// src/lib/tenant-selection.ts
|
|
9453
|
+
init_cjs_shims();
|
|
9454
|
+
var applied = null;
|
|
9455
|
+
function recordTenantSelection(selection) {
|
|
9456
|
+
applied = selection;
|
|
9457
|
+
}
|
|
9458
|
+
function appliedTenantSelection() {
|
|
9459
|
+
return applied;
|
|
9460
|
+
}
|
|
9461
|
+
function describeAppliedTenant(selection) {
|
|
9462
|
+
if (!selection.applied || selection.value === null) {
|
|
9463
|
+
return "No X-Hive-Tenant was sent, so the server resolved your self-tenant";
|
|
9464
|
+
}
|
|
9465
|
+
return `Sent X-Hive-Tenant: ${selection.value} (${selection.source}, from ${selection.origin})`;
|
|
9466
|
+
}
|
|
9467
|
+
|
|
9468
|
+
// src/lib/break-glass.ts
|
|
9469
|
+
init_cjs_shims();
|
|
9470
|
+
var sent = false;
|
|
9471
|
+
function recordBreakGlass(reason) {
|
|
9472
|
+
sent = reason !== null;
|
|
9473
|
+
}
|
|
9474
|
+
function breakGlassSent() {
|
|
9475
|
+
return sent;
|
|
9476
|
+
}
|
|
9477
|
+
|
|
9478
|
+
// src/lib/errors.ts
|
|
9479
|
+
var CliCommandError = class extends Error {
|
|
9480
|
+
exitCode;
|
|
9481
|
+
symbolicCode;
|
|
9482
|
+
remediation;
|
|
9483
|
+
tenant;
|
|
9484
|
+
problemType;
|
|
9485
|
+
details;
|
|
9486
|
+
constructor(symbolicCode, exitCode, message, options) {
|
|
9487
|
+
super(message, options);
|
|
9488
|
+
this.name = "CliCommandError";
|
|
9489
|
+
this.exitCode = exitCode;
|
|
9490
|
+
this.symbolicCode = symbolicCode;
|
|
9491
|
+
this.remediation = options?.remediation;
|
|
9492
|
+
this.tenant = options?.tenant;
|
|
9493
|
+
this.problemType = options?.problemType;
|
|
9494
|
+
this.details = options?.details;
|
|
9495
|
+
}
|
|
9496
|
+
};
|
|
9497
|
+
function commandError(symbolicCode, exitCode, message, options) {
|
|
9498
|
+
return new CliCommandError(symbolicCode, exitCode, message, options);
|
|
9499
|
+
}
|
|
9500
|
+
function remoteErrorFields(data) {
|
|
9501
|
+
const body = data ?? {};
|
|
9502
|
+
if (typeof body.type === "string" && typeof body.title === "string" && typeof body.status === "number") {
|
|
9503
|
+
return {
|
|
9504
|
+
code: typeof body.code === "string" ? body.code.trim() : "",
|
|
9505
|
+
message: typeof body.detail === "string" ? body.detail.trim() : body.title.trim()
|
|
9506
|
+
};
|
|
9507
|
+
}
|
|
9508
|
+
const raw = body.error;
|
|
9509
|
+
if (raw && typeof raw === "object") {
|
|
9510
|
+
const nested = raw;
|
|
9511
|
+
return {
|
|
9512
|
+
code: String(nested.code ?? "").trim(),
|
|
9513
|
+
message: String(nested.message ?? "").trim()
|
|
9514
|
+
};
|
|
9515
|
+
}
|
|
9516
|
+
return {
|
|
9517
|
+
code: String(raw || body.code || "").trim(),
|
|
9518
|
+
message: String(body.message || "").trim()
|
|
9519
|
+
};
|
|
9520
|
+
}
|
|
9521
|
+
function remoteProblemType(data) {
|
|
9522
|
+
if (!data || typeof data !== "object" || Array.isArray(data)) return void 0;
|
|
9523
|
+
const body = data;
|
|
9524
|
+
return typeof body.type === "string" && typeof body.title === "string" && typeof body.status === "number" ? body.type : void 0;
|
|
9525
|
+
}
|
|
9526
|
+
function remoteProblemDetails(data) {
|
|
9527
|
+
if (!remoteProblemType(data)) return void 0;
|
|
9528
|
+
const raw = data.details;
|
|
9529
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return void 0;
|
|
9530
|
+
const out = {};
|
|
9531
|
+
for (const [name, value] of Object.entries(raw)) {
|
|
9532
|
+
if (value === null || ["string", "number", "boolean"].includes(typeof value)) out[name] = value;
|
|
9533
|
+
}
|
|
9534
|
+
return Object.keys(out).length ? out : void 0;
|
|
9535
|
+
}
|
|
9536
|
+
function fieldText(value) {
|
|
9537
|
+
if (value === null || value === void 0) return "";
|
|
9538
|
+
if (typeof value === "object") {
|
|
9539
|
+
try {
|
|
9540
|
+
const json2 = JSON.stringify(value);
|
|
9541
|
+
return json2 && json2 !== "{}" && json2 !== "[]" ? json2 : "";
|
|
9542
|
+
} catch {
|
|
9543
|
+
return "";
|
|
9544
|
+
}
|
|
9545
|
+
}
|
|
9546
|
+
return String(value).trim();
|
|
9547
|
+
}
|
|
9548
|
+
function schemaErrorFields(data) {
|
|
9549
|
+
const errors = data?.schemaErrors;
|
|
9550
|
+
if (!Array.isArray(errors)) return [];
|
|
9551
|
+
const paths = errors.map((entry) => String(entry?.instancePath ?? "").trim()).filter(Boolean).map((path10) => path10.replace(/^\//, ""));
|
|
9552
|
+
return [...new Set(paths)];
|
|
9553
|
+
}
|
|
9554
|
+
function remoteFailureRemediation(data, request) {
|
|
9555
|
+
const code = remoteErrorFields(data).code.toUpperCase();
|
|
9556
|
+
if (code === "PRECONDITION_REQUIRED" || code === "VERSION_CONFLICT") return versionTokenRemediation(data, request);
|
|
9557
|
+
const scope = tenantFailureScope();
|
|
9558
|
+
if (code === "TENANT_NOT_ALLOWED") {
|
|
9559
|
+
const selection = appliedTenantSelection();
|
|
9560
|
+
const pinned = selection?.applied === true && selection.source === "pinned";
|
|
9561
|
+
return scope + "The requested tenant is not in your active memberships. " + (pinned ? "It is a saved pin, not something this command asked for \u2014 run 'hive config clear --tenant' to drop it. " : "If the tenant is saved in CLI config, run 'hive config clear --tenant'. ") + "Platform-scoped commands (hive org *, hive admin list|grant|revoke) ignore a pin already; for other platform-admin operations (mission create) omit --tenant / HIVE_TENANT. Run 'hive diag authz' to list memberships and optionally pin one with 'hive config use --tenant=<displayKey>'.";
|
|
9562
|
+
}
|
|
9563
|
+
if (code === "MISSION_NOT_FOUND") {
|
|
9564
|
+
return scope + "The mission id was not found in the CURRENT tenant scope. A mission is only visible under the tenant it was created in \u2014 check you are using the same --tenant / HIVE_TENANT (or self-tenant) as at create time. Run 'hive mission list --tenant <tenant>' to find the scope that owns it." + // #503: since #501 a platform admin who is not a member gets this 404 too.
|
|
9565
|
+
(breakGlassSent() ? "" : ' A platform admin who is not a member of the mission reaches it with --break-glass "<ticket reference>", audited.');
|
|
9566
|
+
}
|
|
9567
|
+
return void 0;
|
|
9568
|
+
}
|
|
9569
|
+
function versionTokenRemediation(data, request) {
|
|
9570
|
+
const fromPath = request?.path?.match(/^\/api\/records\/([^/?#]+)(\/[^?#]*)?/);
|
|
9571
|
+
const pathId = fromPath && fromPath[1] !== "bulk" ? fromPath[1] : void 0;
|
|
9572
|
+
const fromBody = data?.recordId;
|
|
9573
|
+
let id = pathId ?? (typeof fromBody === "string" && fromBody ? fromBody : void 0);
|
|
9574
|
+
if (pathId) {
|
|
9575
|
+
try {
|
|
9576
|
+
id = decodeURIComponent(pathId);
|
|
9577
|
+
} catch {
|
|
9578
|
+
id = pathId;
|
|
9579
|
+
}
|
|
9580
|
+
}
|
|
9581
|
+
const read = id ? `Read the record again with 'hive record get --id ${id}'` : "Read the record again with 'hive record get'";
|
|
9582
|
+
const lifecycle = request?.method === "POST" && pathId && /^\/(archive|unarchive|transitions\/[^/]+)\/?$/.test(fromPath?.[2] ?? "");
|
|
9583
|
+
if (lifecycle) {
|
|
9584
|
+
return `Nothing was written. ${read} and run the command again with its data.recordVersion as --expectedRecordVersion <n>.`;
|
|
9585
|
+
}
|
|
9586
|
+
if (request?.method) {
|
|
9587
|
+
return `Nothing was written. ${read}, put its data.recordVersion into the JSON file as expectedRecordVersion, and run the command again.`;
|
|
9588
|
+
}
|
|
9589
|
+
return `Nothing was written. ${read} and send its data.recordVersion again: as --expectedRecordVersion for transition, archive and unarchive, as expectedRecordVersion in the JSON file for patch and create.`;
|
|
9590
|
+
}
|
|
9591
|
+
function tenantFailureScope() {
|
|
9592
|
+
const selection = appliedTenantSelection();
|
|
9593
|
+
return selection ? `${describeAppliedTenant(selection)}. ` : "";
|
|
9594
|
+
}
|
|
9595
|
+
function remoteFailureTenant(data) {
|
|
9596
|
+
const code = remoteErrorFields(data).code.toUpperCase();
|
|
9597
|
+
if (code !== "TENANT_NOT_ALLOWED" && code !== "MISSION_NOT_FOUND") return void 0;
|
|
9598
|
+
return appliedTenantSelection() ?? void 0;
|
|
9599
|
+
}
|
|
9600
|
+
function remoteFailureError(status2, data, action, exitCode = exitCodeForStatus(status2)) {
|
|
9601
|
+
const remediation = remoteFailureRemediation(data);
|
|
9602
|
+
const tenant = remoteFailureTenant(data);
|
|
9603
|
+
const problemType = remoteProblemType(data);
|
|
9604
|
+
const details = remoteProblemDetails(data);
|
|
9605
|
+
return commandError(
|
|
9606
|
+
"REMOTE_FAILED",
|
|
9607
|
+
exitCode,
|
|
9608
|
+
`${action} failed${status2 ? ` (HTTP ${status2})` : ""}: ${remoteFailureText(data)}${remediation ? ` \u2014 ${remediation}` : ""}`,
|
|
9609
|
+
remediation || tenant || problemType || details ? {
|
|
9610
|
+
...remediation ? { remediation } : {},
|
|
9611
|
+
...tenant ? { tenant } : {},
|
|
9612
|
+
...problemType ? { problemType } : {},
|
|
9613
|
+
...details ? { details } : {}
|
|
9614
|
+
} : void 0
|
|
9615
|
+
);
|
|
9616
|
+
}
|
|
9617
|
+
function remoteFailureText(data) {
|
|
9618
|
+
const body = data;
|
|
9619
|
+
const { code, message } = remoteErrorFields(data);
|
|
9620
|
+
const isProblem = typeof body?.type === "string" && typeof body?.title === "string" && typeof body?.status === "number";
|
|
9621
|
+
const parts = [code, message, ...isProblem ? [] : [fieldText(body?.detail)]].filter(Boolean);
|
|
9622
|
+
const fields = isProblem ? [] : schemaErrorFields(data);
|
|
9623
|
+
if (fields.length) parts.push(`(offending field${fields.length > 1 ? "s" : ""}: ${fields.join(", ")})`);
|
|
9624
|
+
const text = [...new Set(parts)].join(": ") || "unexpected response";
|
|
9625
|
+
const details = remoteProblemDetails(data);
|
|
9626
|
+
if (!details) return text;
|
|
9627
|
+
return `${text} (${Object.entries(details).map(([name, value]) => `${name}: ${JSON.stringify(value)}`).join(", ")})`;
|
|
9628
|
+
}
|
|
9629
|
+
function toStructuredError(err) {
|
|
9630
|
+
const e = err;
|
|
9631
|
+
const code = e?.symbolicCode || e?.code || "ERROR";
|
|
9632
|
+
const message = e?.symbolicCode ? e.message : formatCliError(err);
|
|
9633
|
+
return {
|
|
9634
|
+
ok: false,
|
|
9635
|
+
error: {
|
|
9636
|
+
code,
|
|
9637
|
+
message,
|
|
9638
|
+
...e?.remediation ? { remediation: e.remediation } : {},
|
|
9639
|
+
...e?.problemType ? { type: e.problemType } : {},
|
|
9640
|
+
...e?.tenant ? { tenant: e.tenant } : {},
|
|
9641
|
+
...e?.details ? { details: e.details } : {}
|
|
9642
|
+
}
|
|
9643
|
+
};
|
|
9644
|
+
}
|
|
9645
|
+
function isJsonMode(ctx2) {
|
|
9646
|
+
const args = ctx2?.args;
|
|
9647
|
+
if (args) {
|
|
9648
|
+
if (args.json === true) return true;
|
|
9649
|
+
return String(args.format ?? "").toLowerCase() === "json";
|
|
9650
|
+
}
|
|
9651
|
+
const argv = process.argv;
|
|
9652
|
+
if (argv.includes("--json")) return true;
|
|
9653
|
+
if (argv.some((a) => a.toLowerCase() === "--format=json")) return true;
|
|
9654
|
+
const i = argv.indexOf("--format");
|
|
9655
|
+
return i !== -1 && String(argv[i + 1] || "").toLowerCase() === "json";
|
|
9656
|
+
}
|
|
9657
|
+
function formatCliError(err) {
|
|
9658
|
+
const e = err;
|
|
9659
|
+
if (e?.symbolicCode) return `${e.symbolicCode}: ${e.message}`;
|
|
9660
|
+
switch (e?.code) {
|
|
9661
|
+
case "ENOENT":
|
|
9662
|
+
return `file not found: ${e.path ?? "(unknown path)"}`;
|
|
9663
|
+
case "EACCES":
|
|
9664
|
+
return `permission denied: ${e.path ?? "(unknown path)"}`;
|
|
9665
|
+
case "EISDIR":
|
|
9666
|
+
return `expected a file but found a directory: ${e.path ?? ""}`;
|
|
9667
|
+
case "ECONNREFUSED":
|
|
9668
|
+
return `cannot reach the API${e.address ? ` at ${e.address}:${e.port}` : ""} (connection refused). Is the stack up? Check --api-url / HIVE_API_URL, or run 'hive login'.`;
|
|
9669
|
+
case "ENOTFOUND":
|
|
9670
|
+
return `cannot resolve host '${e.hostname ?? ""}'. Check the API URL (--api-url / HIVE_API_URL).`;
|
|
9671
|
+
case "ETIMEDOUT":
|
|
9672
|
+
case "ECONNRESET":
|
|
9673
|
+
return `network error reaching the API (${e.code}). Check connectivity or --api-url.`;
|
|
9674
|
+
}
|
|
9675
|
+
if (e instanceof SyntaxError) return `invalid JSON: ${e.message}`;
|
|
9676
|
+
return e && e.message || String(err);
|
|
9677
|
+
}
|
|
9678
|
+
function exitCodeForError(err) {
|
|
9679
|
+
const e = err;
|
|
9680
|
+
if (typeof e?.exitCode === "number") return e.exitCode;
|
|
9681
|
+
return exitCodeForTransportError(e?.code) ?? EXIT_FAILURE;
|
|
9682
|
+
}
|
|
9683
|
+
function installRemoteFailureExit() {
|
|
9684
|
+
process.on("exit", (code) => {
|
|
9685
|
+
if (code !== EXIT_OK) return;
|
|
9686
|
+
const failure2 = pendingRemoteFailure();
|
|
9687
|
+
if (!failure2) return;
|
|
9688
|
+
const symbolic = remoteErrorFields(failure2.body).code || remoteFailureCode(failure2.status);
|
|
9689
|
+
const remediation = remoteFailureRemediation(failure2.body, { method: failure2.method, path: failure2.path }) ?? (failure2.status === 401 ? "Run 'hive login' to authenticate, or set HIVE_TOKEN." : void 0);
|
|
9690
|
+
const tenant = remoteFailureTenant(failure2.body);
|
|
9691
|
+
const problemType = remoteProblemType(failure2.body);
|
|
9692
|
+
const details = remoteProblemDetails(failure2.body);
|
|
9693
|
+
const message = `${failure2.method} ${failure2.path} failed${failure2.status ? ` (HTTP ${failure2.status})` : ""}: ${remoteFailureText(failure2.body)}`;
|
|
9694
|
+
if (isJsonMode()) {
|
|
9695
|
+
console.error(JSON.stringify({
|
|
9696
|
+
ok: false,
|
|
9697
|
+
error: {
|
|
9698
|
+
code: symbolic,
|
|
9699
|
+
message,
|
|
9700
|
+
...problemType ? { type: problemType } : {},
|
|
9701
|
+
...remediation ? { remediation } : {},
|
|
9702
|
+
...tenant ? { tenant } : {},
|
|
9703
|
+
...details ? { details } : {}
|
|
9704
|
+
}
|
|
9705
|
+
}));
|
|
9706
|
+
} else {
|
|
9707
|
+
console.error(`\x1B[31mError:\x1B[0m ${symbolic}: ${message}`);
|
|
9708
|
+
if (remediation) console.error(remediation);
|
|
9709
|
+
}
|
|
9710
|
+
process.exitCode = exitCodeForStatus(failure2.status);
|
|
9711
|
+
});
|
|
9712
|
+
}
|
|
9713
|
+
function installErrorHandling(cmd) {
|
|
9714
|
+
const verbose = process.argv.includes("-v") || process.argv.includes("--verbose");
|
|
9715
|
+
const seen = /* @__PURE__ */ new Set();
|
|
9716
|
+
const walk = (c) => {
|
|
9717
|
+
if (!c || typeof c !== "object" || seen.has(c)) return;
|
|
9718
|
+
seen.add(c);
|
|
9719
|
+
const node2 = c;
|
|
9720
|
+
if (typeof node2.run === "function") {
|
|
9721
|
+
const orig = node2.run;
|
|
9722
|
+
node2.run = async (ctx2) => {
|
|
9723
|
+
try {
|
|
9724
|
+
return await orig(ctx2);
|
|
9725
|
+
} catch (err) {
|
|
9726
|
+
if (isJsonMode(ctx2)) {
|
|
9727
|
+
console.error(JSON.stringify(toStructuredError(err)));
|
|
9728
|
+
} else {
|
|
9729
|
+
console.error(`\x1B[31mError:\x1B[0m ${formatCliError(err)}`);
|
|
9730
|
+
}
|
|
9731
|
+
if (verbose && err instanceof Error && err.stack) console.error(err.stack);
|
|
9732
|
+
process.exit(exitCodeForError(err));
|
|
9733
|
+
}
|
|
9734
|
+
};
|
|
9735
|
+
}
|
|
9736
|
+
const subs = node2.subCommands;
|
|
9737
|
+
if (subs && typeof subs === "object") {
|
|
9738
|
+
for (const key of Object.keys(subs)) {
|
|
9739
|
+
walk(subs[key]);
|
|
9740
|
+
}
|
|
9741
|
+
}
|
|
9742
|
+
};
|
|
9743
|
+
walk(cmd);
|
|
9425
9744
|
}
|
|
9426
9745
|
|
|
9427
9746
|
// src/lib/client.ts
|
|
@@ -9441,14 +9760,33 @@ var HiveClient = class {
|
|
|
9441
9760
|
const headers = { accept };
|
|
9442
9761
|
if (this.tenant) headers["x-hive-tenant"] = this.tenant;
|
|
9443
9762
|
if (this.breakGlass) headers["x-hive-break-glass"] = this.breakGlass;
|
|
9763
|
+
const envToken2 = envToken()?.token;
|
|
9764
|
+
if (envToken2) {
|
|
9765
|
+
headers["authorization"] = `Bearer ${envToken2}`;
|
|
9766
|
+
return headers;
|
|
9767
|
+
}
|
|
9768
|
+
let fresh;
|
|
9444
9769
|
try {
|
|
9445
|
-
|
|
9446
|
-
if (token) headers["authorization"] = `Bearer ${token}`;
|
|
9770
|
+
fresh = await freshToken();
|
|
9447
9771
|
} catch (e) {
|
|
9448
|
-
|
|
9772
|
+
throw this._refreshStop(refreshThrowExit(e), e);
|
|
9773
|
+
}
|
|
9774
|
+
if (fresh.ok) {
|
|
9775
|
+
headers["authorization"] = `Bearer ${fresh.token}`;
|
|
9776
|
+
} else {
|
|
9777
|
+
const t = tokenFailureExit(fresh.failure);
|
|
9778
|
+
if (t.issuerFailure) throw this._refreshStop(t);
|
|
9449
9779
|
}
|
|
9450
9780
|
return headers;
|
|
9451
9781
|
}
|
|
9782
|
+
/**
|
|
9783
|
+
* The error that stops a command whose stored login could not be refreshed because of the
|
|
9784
|
+
* issuer (#518). It names the ways out, since the stop also reaches a command that would not
|
|
9785
|
+
* have needed the token (an expired login, a local API without auth).
|
|
9786
|
+
*/
|
|
9787
|
+
_refreshStop(t, cause) {
|
|
9788
|
+
return commandError(t.symbolic, t.code, `${t.message} To go on without the stored login, run 'hive logout' or set HIVE_TOKEN.`, cause === void 0 ? void 0 : { cause });
|
|
9789
|
+
}
|
|
9452
9790
|
/** Low-level request helper (no external deps, uses Node built-ins) */
|
|
9453
9791
|
async _request(method, path10, body) {
|
|
9454
9792
|
const url2 = new import_node_url2.URL(path10, this.baseUrl);
|
|
@@ -9598,375 +9936,101 @@ function renderTable(rows, meta3) {
|
|
|
9598
9936
|
(r) => cols.map((c, i) => {
|
|
9599
9937
|
let v = r[c];
|
|
9600
9938
|
if (v === null || v === void 0) v = "";
|
|
9601
|
-
v = String(v);
|
|
9602
|
-
if (v.length > 40) v = v.slice(0, 37) + "...";
|
|
9603
|
-
return v.padEnd(widths[i]);
|
|
9604
|
-
}).join(" ")
|
|
9605
|
-
);
|
|
9606
|
-
const parts = [hdr, sep, ...body];
|
|
9607
|
-
if (meta3) {
|
|
9608
|
-
const extras = [];
|
|
9609
|
-
for (const [k, v] of Object.entries(meta3)) {
|
|
9610
|
-
if (Array.isArray(v)) continue;
|
|
9611
|
-
if (typeof v === "object") continue;
|
|
9612
|
-
extras.push(`${k}: ${v}`);
|
|
9613
|
-
}
|
|
9614
|
-
if (extras.length) parts.push("", extras.join(" \u2502 "));
|
|
9615
|
-
}
|
|
9616
|
-
return parts.join("\n");
|
|
9617
|
-
}
|
|
9618
|
-
function output(data, format) {
|
|
9619
|
-
const fmt = (format || "table").toLowerCase();
|
|
9620
|
-
let text;
|
|
9621
|
-
if (fmt === "json") text = formatJson(data);
|
|
9622
|
-
else if (fmt === "yaml") text = formatYaml(data);
|
|
9623
|
-
else text = formatTable(data);
|
|
9624
|
-
console.log(text);
|
|
9625
|
-
}
|
|
9626
|
-
|
|
9627
|
-
// src/lib/config.ts
|
|
9628
|
-
init_cjs_shims();
|
|
9629
|
-
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
9630
|
-
var import_node_os2 = __toESM(require("os"), 1);
|
|
9631
|
-
var import_node_path2 = __toESM(require("path"), 1);
|
|
9632
|
-
var hiveDir2 = () => process.env.HIVE_CLI_STATE_DIR?.trim() || import_node_path2.default.join(import_node_os2.default.homedir(), ".hive");
|
|
9633
|
-
var configFile = () => import_node_path2.default.join(hiveDir2(), "config.json");
|
|
9634
|
-
function configPath() {
|
|
9635
|
-
return configFile();
|
|
9636
|
-
}
|
|
9637
|
-
function readConfig() {
|
|
9638
|
-
try {
|
|
9639
|
-
const parsed = JSON.parse(import_node_fs2.default.readFileSync(configFile(), "utf-8"));
|
|
9640
|
-
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
9641
|
-
} catch {
|
|
9642
|
-
return {};
|
|
9643
|
-
}
|
|
9644
|
-
}
|
|
9645
|
-
function saveConfig(patch2) {
|
|
9646
|
-
const merged = { ...readConfig() };
|
|
9647
|
-
for (const [key, value] of Object.entries(patch2)) {
|
|
9648
|
-
if (typeof value === "string" && value.trim() !== "") merged[key] = value.trim();
|
|
9649
|
-
}
|
|
9650
|
-
import_node_fs2.default.mkdirSync(hiveDir2(), { recursive: true, mode: 448 });
|
|
9651
|
-
import_node_fs2.default.writeFileSync(configFile(), JSON.stringify(merged, null, 2) + "\n", { mode: 384 });
|
|
9652
|
-
return merged;
|
|
9653
|
-
}
|
|
9654
|
-
function clearConfig(keys) {
|
|
9655
|
-
const merged = { ...readConfig() };
|
|
9656
|
-
for (const key of keys) delete merged[key];
|
|
9657
|
-
import_node_fs2.default.mkdirSync(hiveDir2(), { recursive: true, mode: 448 });
|
|
9658
|
-
import_node_fs2.default.writeFileSync(configFile(), JSON.stringify(merged, null, 2) + "\n", { mode: 384 });
|
|
9659
|
-
return merged;
|
|
9660
|
-
}
|
|
9661
|
-
function isInteractive() {
|
|
9662
|
-
return Boolean(process.stdin.isTTY);
|
|
9663
|
-
}
|
|
9664
|
-
async function resolveSetting(opts) {
|
|
9665
|
-
const flag = typeof opts.flag === "string" && opts.flag.trim() ? opts.flag.trim() : void 0;
|
|
9666
|
-
if (flag) return { value: flag, source: "flag" };
|
|
9667
|
-
const envVars = opts.envVar === void 0 ? [] : Array.isArray(opts.envVar) ? opts.envVar : [opts.envVar];
|
|
9668
|
-
for (const name of envVars) {
|
|
9669
|
-
const env = process.env[name]?.trim();
|
|
9670
|
-
if (env) return { value: env, source: "env" };
|
|
9671
|
-
}
|
|
9672
|
-
const saved = opts.saved?.trim();
|
|
9673
|
-
if (saved) return { value: saved, source: "saved" };
|
|
9674
|
-
if (isInteractive()) {
|
|
9675
|
-
const answer = (await promptText(`${opts.label} [${opts.def}]: `)).trim();
|
|
9676
|
-
return answer ? { value: answer, source: "prompt" } : { value: opts.def, source: "default" };
|
|
9677
|
-
}
|
|
9678
|
-
return { value: opts.def, source: "default" };
|
|
9679
|
-
}
|
|
9680
|
-
async function fetchAuthConfig(apiUrl) {
|
|
9681
|
-
try {
|
|
9682
|
-
const base = apiUrl.replace(/\/+$/, "");
|
|
9683
|
-
const res = await fetch(`${base}/api/auth/config`, { headers: { accept: "application/json, application/problem+json" } });
|
|
9684
|
-
if (!res.ok) return null;
|
|
9685
|
-
const body = await res.json();
|
|
9686
|
-
const issuerUrl = typeof body.issuerUrl === "string" ? body.issuerUrl : void 0;
|
|
9687
|
-
if (!issuerUrl) return null;
|
|
9688
|
-
return {
|
|
9689
|
-
issuerUrl,
|
|
9690
|
-
clientId: typeof body.clientId === "string" ? body.clientId : void 0,
|
|
9691
|
-
audience: typeof body.audience === "string" ? body.audience : void 0
|
|
9692
|
-
};
|
|
9693
|
-
} catch {
|
|
9694
|
-
return null;
|
|
9695
|
-
}
|
|
9696
|
-
}
|
|
9697
|
-
|
|
9698
|
-
// src/lib/errors.ts
|
|
9699
|
-
init_cjs_shims();
|
|
9700
|
-
|
|
9701
|
-
// src/lib/tenant-selection.ts
|
|
9702
|
-
init_cjs_shims();
|
|
9703
|
-
var applied = null;
|
|
9704
|
-
function recordTenantSelection(selection) {
|
|
9705
|
-
applied = selection;
|
|
9706
|
-
}
|
|
9707
|
-
function appliedTenantSelection() {
|
|
9708
|
-
return applied;
|
|
9709
|
-
}
|
|
9710
|
-
function describeAppliedTenant(selection) {
|
|
9711
|
-
if (!selection.applied || selection.value === null) {
|
|
9712
|
-
return "No X-Hive-Tenant was sent, so the server resolved your self-tenant";
|
|
9713
|
-
}
|
|
9714
|
-
return `Sent X-Hive-Tenant: ${selection.value} (${selection.source}, from ${selection.origin})`;
|
|
9715
|
-
}
|
|
9716
|
-
|
|
9717
|
-
// src/lib/break-glass.ts
|
|
9718
|
-
init_cjs_shims();
|
|
9719
|
-
var sent = false;
|
|
9720
|
-
function recordBreakGlass(reason) {
|
|
9721
|
-
sent = reason !== null;
|
|
9722
|
-
}
|
|
9723
|
-
function breakGlassSent() {
|
|
9724
|
-
return sent;
|
|
9725
|
-
}
|
|
9726
|
-
|
|
9727
|
-
// src/lib/errors.ts
|
|
9728
|
-
var CliCommandError = class extends Error {
|
|
9729
|
-
exitCode;
|
|
9730
|
-
symbolicCode;
|
|
9731
|
-
remediation;
|
|
9732
|
-
tenant;
|
|
9733
|
-
problemType;
|
|
9734
|
-
details;
|
|
9735
|
-
constructor(symbolicCode, exitCode, message, options) {
|
|
9736
|
-
super(message, options);
|
|
9737
|
-
this.name = "CliCommandError";
|
|
9738
|
-
this.exitCode = exitCode;
|
|
9739
|
-
this.symbolicCode = symbolicCode;
|
|
9740
|
-
this.remediation = options?.remediation;
|
|
9741
|
-
this.tenant = options?.tenant;
|
|
9742
|
-
this.problemType = options?.problemType;
|
|
9743
|
-
this.details = options?.details;
|
|
9744
|
-
}
|
|
9745
|
-
};
|
|
9746
|
-
function commandError(symbolicCode, exitCode, message, options) {
|
|
9747
|
-
return new CliCommandError(symbolicCode, exitCode, message, options);
|
|
9748
|
-
}
|
|
9749
|
-
function remoteErrorFields(data) {
|
|
9750
|
-
const body = data ?? {};
|
|
9751
|
-
if (typeof body.type === "string" && typeof body.title === "string" && typeof body.status === "number") {
|
|
9752
|
-
return {
|
|
9753
|
-
code: typeof body.code === "string" ? body.code.trim() : "",
|
|
9754
|
-
message: typeof body.detail === "string" ? body.detail.trim() : body.title.trim()
|
|
9755
|
-
};
|
|
9756
|
-
}
|
|
9757
|
-
const raw = body.error;
|
|
9758
|
-
if (raw && typeof raw === "object") {
|
|
9759
|
-
const nested = raw;
|
|
9760
|
-
return {
|
|
9761
|
-
code: String(nested.code ?? "").trim(),
|
|
9762
|
-
message: String(nested.message ?? "").trim()
|
|
9763
|
-
};
|
|
9764
|
-
}
|
|
9765
|
-
return {
|
|
9766
|
-
code: String(raw || body.code || "").trim(),
|
|
9767
|
-
message: String(body.message || "").trim()
|
|
9768
|
-
};
|
|
9769
|
-
}
|
|
9770
|
-
function remoteProblemType(data) {
|
|
9771
|
-
if (!data || typeof data !== "object" || Array.isArray(data)) return void 0;
|
|
9772
|
-
const body = data;
|
|
9773
|
-
return typeof body.type === "string" && typeof body.title === "string" && typeof body.status === "number" ? body.type : void 0;
|
|
9774
|
-
}
|
|
9775
|
-
function remoteProblemDetails(data) {
|
|
9776
|
-
if (!remoteProblemType(data)) return void 0;
|
|
9777
|
-
const raw = data.details;
|
|
9778
|
-
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return void 0;
|
|
9779
|
-
const out = {};
|
|
9780
|
-
for (const [name, value] of Object.entries(raw)) {
|
|
9781
|
-
if (value === null || ["string", "number", "boolean"].includes(typeof value)) out[name] = value;
|
|
9782
|
-
}
|
|
9783
|
-
return Object.keys(out).length ? out : void 0;
|
|
9784
|
-
}
|
|
9785
|
-
function fieldText(value) {
|
|
9786
|
-
if (value === null || value === void 0) return "";
|
|
9787
|
-
if (typeof value === "object") {
|
|
9788
|
-
try {
|
|
9789
|
-
const json2 = JSON.stringify(value);
|
|
9790
|
-
return json2 && json2 !== "{}" && json2 !== "[]" ? json2 : "";
|
|
9791
|
-
} catch {
|
|
9792
|
-
return "";
|
|
9939
|
+
v = String(v);
|
|
9940
|
+
if (v.length > 40) v = v.slice(0, 37) + "...";
|
|
9941
|
+
return v.padEnd(widths[i]);
|
|
9942
|
+
}).join(" ")
|
|
9943
|
+
);
|
|
9944
|
+
const parts = [hdr, sep, ...body];
|
|
9945
|
+
if (meta3) {
|
|
9946
|
+
const extras = [];
|
|
9947
|
+
for (const [k, v] of Object.entries(meta3)) {
|
|
9948
|
+
if (Array.isArray(v)) continue;
|
|
9949
|
+
if (typeof v === "object") continue;
|
|
9950
|
+
extras.push(`${k}: ${v}`);
|
|
9793
9951
|
}
|
|
9952
|
+
if (extras.length) parts.push("", extras.join(" \u2502 "));
|
|
9794
9953
|
}
|
|
9795
|
-
return
|
|
9796
|
-
}
|
|
9797
|
-
function schemaErrorFields(data) {
|
|
9798
|
-
const errors = data?.schemaErrors;
|
|
9799
|
-
if (!Array.isArray(errors)) return [];
|
|
9800
|
-
const paths = errors.map((entry) => String(entry?.instancePath ?? "").trim()).filter(Boolean).map((path10) => path10.replace(/^\//, ""));
|
|
9801
|
-
return [...new Set(paths)];
|
|
9954
|
+
return parts.join("\n");
|
|
9802
9955
|
}
|
|
9803
|
-
function
|
|
9804
|
-
const
|
|
9805
|
-
|
|
9806
|
-
if (
|
|
9807
|
-
|
|
9808
|
-
|
|
9809
|
-
|
|
9810
|
-
}
|
|
9811
|
-
if (code === "MISSION_NOT_FOUND") {
|
|
9812
|
-
return scope + "The mission id was not found in the CURRENT tenant scope. A mission is only visible under the tenant it was created in \u2014 check you are using the same --tenant / HIVE_TENANT (or self-tenant) as at create time. Run 'hive mission list --tenant <tenant>' to find the scope that owns it." + // #503: since #501 a platform admin who is not a member gets this 404 too.
|
|
9813
|
-
(breakGlassSent() ? "" : ' A platform admin who is not a member of the mission reaches it with --break-glass "<ticket reference>", audited.');
|
|
9814
|
-
}
|
|
9815
|
-
return void 0;
|
|
9956
|
+
function output(data, format) {
|
|
9957
|
+
const fmt = (format || "table").toLowerCase();
|
|
9958
|
+
let text;
|
|
9959
|
+
if (fmt === "json") text = formatJson(data);
|
|
9960
|
+
else if (fmt === "yaml") text = formatYaml(data);
|
|
9961
|
+
else text = formatTable(data);
|
|
9962
|
+
console.log(text);
|
|
9816
9963
|
}
|
|
9817
|
-
|
|
9818
|
-
|
|
9819
|
-
|
|
9964
|
+
|
|
9965
|
+
// src/lib/config.ts
|
|
9966
|
+
init_cjs_shims();
|
|
9967
|
+
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
9968
|
+
var import_node_os2 = __toESM(require("os"), 1);
|
|
9969
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
9970
|
+
var hiveDir2 = () => process.env.HIVE_CLI_STATE_DIR?.trim() || import_node_path2.default.join(import_node_os2.default.homedir(), ".hive");
|
|
9971
|
+
var configFile = () => import_node_path2.default.join(hiveDir2(), "config.json");
|
|
9972
|
+
function configPath() {
|
|
9973
|
+
return configFile();
|
|
9820
9974
|
}
|
|
9821
|
-
function
|
|
9822
|
-
|
|
9823
|
-
|
|
9824
|
-
|
|
9975
|
+
function readConfig() {
|
|
9976
|
+
try {
|
|
9977
|
+
const parsed = JSON.parse(import_node_fs2.default.readFileSync(configFile(), "utf-8"));
|
|
9978
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
9979
|
+
} catch {
|
|
9980
|
+
return {};
|
|
9981
|
+
}
|
|
9825
9982
|
}
|
|
9826
|
-
function
|
|
9827
|
-
const
|
|
9828
|
-
const
|
|
9829
|
-
|
|
9830
|
-
|
|
9831
|
-
|
|
9832
|
-
|
|
9833
|
-
|
|
9834
|
-
`${action} failed${status2 ? ` (HTTP ${status2})` : ""}: ${remoteFailureText(data)}${remediation ? ` \u2014 ${remediation}` : ""}`,
|
|
9835
|
-
remediation || tenant || problemType || details ? {
|
|
9836
|
-
...remediation ? { remediation } : {},
|
|
9837
|
-
...tenant ? { tenant } : {},
|
|
9838
|
-
...problemType ? { problemType } : {},
|
|
9839
|
-
...details ? { details } : {}
|
|
9840
|
-
} : void 0
|
|
9841
|
-
);
|
|
9983
|
+
function saveConfig(patch2) {
|
|
9984
|
+
const merged = { ...readConfig() };
|
|
9985
|
+
for (const [key, value] of Object.entries(patch2)) {
|
|
9986
|
+
if (typeof value === "string" && value.trim() !== "") merged[key] = value.trim();
|
|
9987
|
+
}
|
|
9988
|
+
import_node_fs2.default.mkdirSync(hiveDir2(), { recursive: true, mode: 448 });
|
|
9989
|
+
import_node_fs2.default.writeFileSync(configFile(), JSON.stringify(merged, null, 2) + "\n", { mode: 384 });
|
|
9990
|
+
return merged;
|
|
9842
9991
|
}
|
|
9843
|
-
function
|
|
9844
|
-
const
|
|
9845
|
-
const
|
|
9846
|
-
|
|
9847
|
-
|
|
9848
|
-
|
|
9849
|
-
if (fields.length) parts.push(`(offending field${fields.length > 1 ? "s" : ""}: ${fields.join(", ")})`);
|
|
9850
|
-
const text = [...new Set(parts)].join(": ") || "unexpected response";
|
|
9851
|
-
const details = remoteProblemDetails(data);
|
|
9852
|
-
if (!details) return text;
|
|
9853
|
-
return `${text} (${Object.entries(details).map(([name, value]) => `${name}: ${JSON.stringify(value)}`).join(", ")})`;
|
|
9992
|
+
function clearConfig(keys) {
|
|
9993
|
+
const merged = { ...readConfig() };
|
|
9994
|
+
for (const key of keys) delete merged[key];
|
|
9995
|
+
import_node_fs2.default.mkdirSync(hiveDir2(), { recursive: true, mode: 448 });
|
|
9996
|
+
import_node_fs2.default.writeFileSync(configFile(), JSON.stringify(merged, null, 2) + "\n", { mode: 384 });
|
|
9997
|
+
return merged;
|
|
9854
9998
|
}
|
|
9855
|
-
function
|
|
9856
|
-
|
|
9857
|
-
const code = e?.symbolicCode || e?.code || "ERROR";
|
|
9858
|
-
const message = e?.symbolicCode ? e.message : formatCliError(err);
|
|
9859
|
-
return {
|
|
9860
|
-
ok: false,
|
|
9861
|
-
error: {
|
|
9862
|
-
code,
|
|
9863
|
-
message,
|
|
9864
|
-
...e?.remediation ? { remediation: e.remediation } : {},
|
|
9865
|
-
...e?.problemType ? { type: e.problemType } : {},
|
|
9866
|
-
...e?.tenant ? { tenant: e.tenant } : {},
|
|
9867
|
-
...e?.details ? { details: e.details } : {}
|
|
9868
|
-
}
|
|
9869
|
-
};
|
|
9999
|
+
function isInteractive() {
|
|
10000
|
+
return Boolean(process.stdin.isTTY);
|
|
9870
10001
|
}
|
|
9871
|
-
function
|
|
9872
|
-
const
|
|
9873
|
-
if (
|
|
9874
|
-
|
|
9875
|
-
|
|
10002
|
+
async function resolveSetting(opts) {
|
|
10003
|
+
const flag = typeof opts.flag === "string" && opts.flag.trim() ? opts.flag.trim() : void 0;
|
|
10004
|
+
if (flag) return { value: flag, source: "flag" };
|
|
10005
|
+
const envVars = opts.envVar === void 0 ? [] : Array.isArray(opts.envVar) ? opts.envVar : [opts.envVar];
|
|
10006
|
+
for (const name of envVars) {
|
|
10007
|
+
const env = process.env[name]?.trim();
|
|
10008
|
+
if (env) return { value: env, source: "env" };
|
|
9876
10009
|
}
|
|
9877
|
-
const
|
|
9878
|
-
if (
|
|
9879
|
-
if (
|
|
9880
|
-
|
|
9881
|
-
|
|
9882
|
-
}
|
|
9883
|
-
function formatCliError(err) {
|
|
9884
|
-
const e = err;
|
|
9885
|
-
if (e?.symbolicCode) return `${e.symbolicCode}: ${e.message}`;
|
|
9886
|
-
switch (e?.code) {
|
|
9887
|
-
case "ENOENT":
|
|
9888
|
-
return `file not found: ${e.path ?? "(unknown path)"}`;
|
|
9889
|
-
case "EACCES":
|
|
9890
|
-
return `permission denied: ${e.path ?? "(unknown path)"}`;
|
|
9891
|
-
case "EISDIR":
|
|
9892
|
-
return `expected a file but found a directory: ${e.path ?? ""}`;
|
|
9893
|
-
case "ECONNREFUSED":
|
|
9894
|
-
return `cannot reach the API${e.address ? ` at ${e.address}:${e.port}` : ""} (connection refused). Is the stack up? Check --api-url / HIVE_API_URL, or run 'hive login'.`;
|
|
9895
|
-
case "ENOTFOUND":
|
|
9896
|
-
return `cannot resolve host '${e.hostname ?? ""}'. Check the API URL (--api-url / HIVE_API_URL).`;
|
|
9897
|
-
case "ETIMEDOUT":
|
|
9898
|
-
case "ECONNRESET":
|
|
9899
|
-
return `network error reaching the API (${e.code}). Check connectivity or --api-url.`;
|
|
10010
|
+
const saved = opts.saved?.trim();
|
|
10011
|
+
if (saved) return { value: saved, source: "saved" };
|
|
10012
|
+
if (isInteractive()) {
|
|
10013
|
+
const answer = (await promptText(`${opts.label} [${opts.def}]: `)).trim();
|
|
10014
|
+
return answer ? { value: answer, source: "prompt" } : { value: opts.def, source: "default" };
|
|
9900
10015
|
}
|
|
9901
|
-
|
|
9902
|
-
return e && e.message || String(err);
|
|
9903
|
-
}
|
|
9904
|
-
function exitCodeForError(err) {
|
|
9905
|
-
const e = err;
|
|
9906
|
-
if (typeof e?.exitCode === "number") return e.exitCode;
|
|
9907
|
-
return exitCodeForTransportError(e?.code) ?? EXIT_FAILURE;
|
|
9908
|
-
}
|
|
9909
|
-
function installRemoteFailureExit() {
|
|
9910
|
-
process.on("exit", (code) => {
|
|
9911
|
-
if (code !== EXIT_OK) return;
|
|
9912
|
-
const failure2 = pendingRemoteFailure();
|
|
9913
|
-
if (!failure2) return;
|
|
9914
|
-
const symbolic = remoteErrorFields(failure2.body).code || remoteFailureCode(failure2.status);
|
|
9915
|
-
const remediation = remoteFailureRemediation(failure2.body) ?? (failure2.status === 401 ? "Run 'hive login' to authenticate, or set HIVE_TOKEN." : void 0);
|
|
9916
|
-
const tenant = remoteFailureTenant(failure2.body);
|
|
9917
|
-
const problemType = remoteProblemType(failure2.body);
|
|
9918
|
-
const details = remoteProblemDetails(failure2.body);
|
|
9919
|
-
const message = `${failure2.method} ${failure2.path} failed${failure2.status ? ` (HTTP ${failure2.status})` : ""}: ${remoteFailureText(failure2.body)}`;
|
|
9920
|
-
if (isJsonMode()) {
|
|
9921
|
-
console.error(JSON.stringify({
|
|
9922
|
-
ok: false,
|
|
9923
|
-
error: {
|
|
9924
|
-
code: symbolic,
|
|
9925
|
-
message,
|
|
9926
|
-
...problemType ? { type: problemType } : {},
|
|
9927
|
-
...remediation ? { remediation } : {},
|
|
9928
|
-
...tenant ? { tenant } : {},
|
|
9929
|
-
...details ? { details } : {}
|
|
9930
|
-
}
|
|
9931
|
-
}));
|
|
9932
|
-
} else {
|
|
9933
|
-
console.error(`\x1B[31mError:\x1B[0m ${symbolic}: ${message}`);
|
|
9934
|
-
if (remediation) console.error(remediation);
|
|
9935
|
-
}
|
|
9936
|
-
process.exitCode = exitCodeForStatus(failure2.status);
|
|
9937
|
-
});
|
|
10016
|
+
return { value: opts.def, source: "default" };
|
|
9938
10017
|
}
|
|
9939
|
-
function
|
|
9940
|
-
|
|
9941
|
-
|
|
9942
|
-
|
|
9943
|
-
if (!
|
|
9944
|
-
|
|
9945
|
-
const
|
|
9946
|
-
if (
|
|
9947
|
-
|
|
9948
|
-
|
|
9949
|
-
|
|
9950
|
-
|
|
9951
|
-
|
|
9952
|
-
|
|
9953
|
-
|
|
9954
|
-
|
|
9955
|
-
console.error(`\x1B[31mError:\x1B[0m ${formatCliError(err)}`);
|
|
9956
|
-
}
|
|
9957
|
-
if (verbose && err instanceof Error && err.stack) console.error(err.stack);
|
|
9958
|
-
process.exit(exitCodeForError(err));
|
|
9959
|
-
}
|
|
9960
|
-
};
|
|
9961
|
-
}
|
|
9962
|
-
const subs = node2.subCommands;
|
|
9963
|
-
if (subs && typeof subs === "object") {
|
|
9964
|
-
for (const key of Object.keys(subs)) {
|
|
9965
|
-
walk(subs[key]);
|
|
9966
|
-
}
|
|
9967
|
-
}
|
|
9968
|
-
};
|
|
9969
|
-
walk(cmd);
|
|
10018
|
+
async function fetchAuthConfig(apiUrl) {
|
|
10019
|
+
try {
|
|
10020
|
+
const base = apiUrl.replace(/\/+$/, "");
|
|
10021
|
+
const res = await fetch(`${base}/api/auth/config`, { headers: { accept: "application/json, application/problem+json" } });
|
|
10022
|
+
if (!res.ok) return null;
|
|
10023
|
+
const body = await res.json();
|
|
10024
|
+
const issuerUrl = typeof body.issuerUrl === "string" ? body.issuerUrl : void 0;
|
|
10025
|
+
if (!issuerUrl) return null;
|
|
10026
|
+
return {
|
|
10027
|
+
issuerUrl,
|
|
10028
|
+
clientId: typeof body.clientId === "string" ? body.clientId : void 0,
|
|
10029
|
+
audience: typeof body.audience === "string" ? body.audience : void 0
|
|
10030
|
+
};
|
|
10031
|
+
} catch {
|
|
10032
|
+
return null;
|
|
10033
|
+
}
|
|
9970
10034
|
}
|
|
9971
10035
|
|
|
9972
10036
|
// src/lib/runtime.ts
|
|
@@ -10511,22 +10575,22 @@ var artifactName = injectedString(
|
|
|
10511
10575
|
true ? "hive-cli" : void 0
|
|
10512
10576
|
) || String(process.env.HIVE_CLI_ARTIFACT_NAME || "hive-cli").trim() || "hive-cli";
|
|
10513
10577
|
var packageVersion = injectedString(
|
|
10514
|
-
true ? "1.
|
|
10578
|
+
true ? "1.164.0" : void 0
|
|
10515
10579
|
) || String(process.env.HIVE_CLI_PACKAGE_VERSION || "").trim() || readPackageVersion();
|
|
10516
10580
|
var releaseVersion = injectedString(
|
|
10517
|
-
true ? "1.
|
|
10581
|
+
true ? "1.164.0" : void 0
|
|
10518
10582
|
) || String(process.env.HIVE_CLI_RELEASE_VERSION || "").trim() || packageVersion || "dev";
|
|
10519
10583
|
var releaseChannel = injectedString(
|
|
10520
10584
|
true ? "final" : void 0
|
|
10521
10585
|
) || String(process.env.HIVE_CLI_RELEASE_CHANNEL || "").trim() || (releaseVersion.includes("-rc.") ? "rc" : releaseVersion === "dev" ? "dev" : "final");
|
|
10522
10586
|
var buildCommit = injectedString(
|
|
10523
|
-
true ? "
|
|
10587
|
+
true ? "27a870bc10e581e44f64aa623083470a8a9fcf4f" : void 0
|
|
10524
10588
|
) || String(process.env.HIVE_CLI_BUILD_COMMIT || "").trim() || "unknown";
|
|
10525
10589
|
var buildTimestamp = injectedString(
|
|
10526
|
-
true ? "2026-11-
|
|
10590
|
+
true ? "2026-11-18T08:02:36Z" : void 0
|
|
10527
10591
|
) || String(process.env.HIVE_CLI_BUILD_TIMESTAMP || "").trim() || "unknown";
|
|
10528
10592
|
var ociRef = injectedString(
|
|
10529
|
-
true ? "registry.onstackit.cloud/senticor/hive-cli:1.
|
|
10593
|
+
true ? "registry.onstackit.cloud/senticor/hive-cli:1.164.0" : void 0
|
|
10530
10594
|
) || String(process.env.HIVE_CLI_OCI_REF || "").trim() || `registry.onstackit.cloud/senticor/${artifactName}:${releaseVersion}`;
|
|
10531
10595
|
var RELEASE_INFO = Object.freeze({
|
|
10532
10596
|
packageVersion,
|
|
@@ -11692,26 +11756,12 @@ async function printAuthToken(args) {
|
|
|
11692
11756
|
try {
|
|
11693
11757
|
fresh = await freshToken(minTtl * 1e3);
|
|
11694
11758
|
} catch (err) {
|
|
11695
|
-
const
|
|
11696
|
-
tokenFailure(
|
|
11759
|
+
const t = refreshThrowExit(err);
|
|
11760
|
+
tokenFailure(t.message, t.code);
|
|
11697
11761
|
}
|
|
11698
11762
|
if (!fresh.ok) {
|
|
11699
|
-
const
|
|
11700
|
-
|
|
11701
|
-
case "not_logged_in":
|
|
11702
|
-
return tokenFailure("not logged in. Run 'hive login' first.", EXIT_NOT_AUTHORIZED);
|
|
11703
|
-
case "no_refresh_token": {
|
|
11704
|
-
const left2 = Math.round((failure2.expiresAt - Date.now()) / 1e3);
|
|
11705
|
-
const state = left2 > 0 ? `has ${left2} s left, less than --min-ttl ${minTtl},` : "has expired";
|
|
11706
|
-
return tokenFailure(`the stored token ${state} and the login holds no refresh token. Run 'hive login' again.`, EXIT_NOT_AUTHORIZED);
|
|
11707
|
-
}
|
|
11708
|
-
case "refresh_refused":
|
|
11709
|
-
return tokenFailure(`the issuer refused to refresh the login (${failure2.detail}). Run 'hive login' again.`, EXIT_NOT_AUTHORIZED);
|
|
11710
|
-
case "issuer_unreachable":
|
|
11711
|
-
return tokenFailure(`could not reach ${failure2.issuer} to refresh the login. The login is kept; try again.`, EXIT_TRANSPORT_FAILED);
|
|
11712
|
-
case "issuer_error":
|
|
11713
|
-
return tokenFailure(`${failure2.issuer} did not refresh the login: ${failure2.detail}. The login is kept; try again.`, EXIT_REMOTE_FAILED);
|
|
11714
|
-
}
|
|
11763
|
+
const t = tokenFailureExit(fresh.failure, minTtl);
|
|
11764
|
+
return tokenFailure(t.message, t.code);
|
|
11715
11765
|
}
|
|
11716
11766
|
const left = Math.round((fresh.expiresAt - Date.now()) / 1e3);
|
|
11717
11767
|
if (left < minTtl) {
|
|
@@ -36787,7 +36837,8 @@ var recordArgs = withArgs({
|
|
|
36787
36837
|
name: { type: "string", description: "Alias for --transition (used by `record transition`)" },
|
|
36788
36838
|
dryRun: { type: "boolean", description: "Preview archive/unarchive without mutating state" },
|
|
36789
36839
|
recordIds: { type: "string", description: "Comma-separated record ids for bulk archive/unarchive" },
|
|
36790
|
-
|
|
36840
|
+
expectedRecordVersion: { type: "string", description: "Optimistic-concurrency token for record transition/archive/unarchive: the record's current data.recordVersion (see `hive record get`). Required on version-controlled record types" },
|
|
36841
|
+
expectedSchemaVersion: { type: "string", description: "Deprecated alias of --expectedRecordVersion (it never referred to data.schemaVersion)" },
|
|
36791
36842
|
schema: { type: "string", description: "Path to a JSON Schema file (for `record validate`)" },
|
|
36792
36843
|
dataOnly: { type: "boolean", description: "Validate the record's `.data` instead of the whole file" },
|
|
36793
36844
|
filter: { type: "string", description: "Comma-separated registry filters as key=value pairs (for `record list`)" }
|
|
@@ -36824,33 +36875,54 @@ function parseRegisteredRecordFilters(raw) {
|
|
|
36824
36875
|
}
|
|
36825
36876
|
return out;
|
|
36826
36877
|
}
|
|
36827
|
-
function
|
|
36878
|
+
function applyRecordVersionToken(args, body) {
|
|
36879
|
+
const canonical = optionalVersionInt(args, "expectedRecordVersion");
|
|
36880
|
+
const alias = optionalVersionInt(args, "expectedSchemaVersion");
|
|
36881
|
+
if (canonical !== void 0 && alias !== void 0 && canonical !== alias) {
|
|
36882
|
+
throw commandError("INVALID_FLAG", 1, "--expectedRecordVersion and its deprecated alias --expectedSchemaVersion differ; pass only --expectedRecordVersion");
|
|
36883
|
+
}
|
|
36884
|
+
const value = canonical ?? alias;
|
|
36885
|
+
if (value !== void 0) body.expectedRecordVersion = value;
|
|
36886
|
+
}
|
|
36887
|
+
function refuseVersionFlagOnBulk(args, action) {
|
|
36888
|
+
for (const key of ["expectedRecordVersion", "expectedSchemaVersion"]) {
|
|
36889
|
+
if (args[key] !== void 0) {
|
|
36890
|
+
throw commandError(
|
|
36891
|
+
"INVALID_FLAG",
|
|
36892
|
+
1,
|
|
36893
|
+
`--${key} does not apply to ${action}: one version cannot guard several records. To version-check each row, use --file with { "records": [{ "recordId": "...", "expectedRecordVersion": <n> }] }.`
|
|
36894
|
+
);
|
|
36895
|
+
}
|
|
36896
|
+
}
|
|
36897
|
+
}
|
|
36898
|
+
function optionalVersionInt(args, key) {
|
|
36828
36899
|
const raw = args[key];
|
|
36829
36900
|
if (raw === void 0 || raw === null || raw === "") return void 0;
|
|
36830
36901
|
const parsed = Number(raw);
|
|
36831
|
-
if (!Number.isInteger(parsed) || parsed <
|
|
36832
|
-
throw commandError("INVALID_FLAG", 1, `--${key} must be a
|
|
36902
|
+
if (typeof raw === "boolean" || !Number.isInteger(parsed) || parsed < 0) {
|
|
36903
|
+
throw commandError("INVALID_FLAG", 1, `--${key} must be a non-negative integer`);
|
|
36833
36904
|
}
|
|
36834
36905
|
return parsed;
|
|
36835
36906
|
}
|
|
36836
36907
|
function recordLifecycleBody(args) {
|
|
36837
36908
|
const body = {};
|
|
36838
36909
|
if (args.reason) body.reason = String(args.reason);
|
|
36839
|
-
|
|
36840
|
-
if (expectedSchemaVersion !== void 0) body.expectedSchemaVersion = expectedSchemaVersion;
|
|
36910
|
+
applyRecordVersionToken(args, body);
|
|
36841
36911
|
return body;
|
|
36842
36912
|
}
|
|
36843
36913
|
function recordBulkLifecycleBody(args, action) {
|
|
36914
|
+
refuseVersionFlagOnBulk(args, action);
|
|
36844
36915
|
const body = args.file ? { ...recordOf5(readJsonFile(args.file)) } : {};
|
|
36916
|
+
if (args.reason) body.reason = String(args.reason);
|
|
36917
|
+
if (Array.isArray(body.records) && body.records.length && args.recordIds === void 0 && body.recordIds === void 0) return body;
|
|
36845
36918
|
const recordIds = normalizeCliList(args.recordIds ?? body.recordIds);
|
|
36846
36919
|
if (!recordIds.length) {
|
|
36847
36920
|
throw commandError(
|
|
36848
36921
|
"RECORD_IDS_REQUIRED",
|
|
36849
36922
|
1,
|
|
36850
|
-
`${action} requires --record-ids <id[,id...]> or --file containing recordIds[].`
|
|
36923
|
+
`${action} requires --record-ids <id[,id...]> or --file containing recordIds[] or records[].`
|
|
36851
36924
|
);
|
|
36852
36925
|
}
|
|
36853
|
-
if (args.reason) body.reason = String(args.reason);
|
|
36854
36926
|
body.recordIds = recordIds;
|
|
36855
36927
|
return body;
|
|
36856
36928
|
}
|
|
@@ -36929,8 +37001,7 @@ var record2 = defineCommand({
|
|
|
36929
37001
|
const recordId2 = reqAny(args, "recordId", "id");
|
|
36930
37002
|
const transitionName = reqAny(args, "transition", "name");
|
|
36931
37003
|
const body = {};
|
|
36932
|
-
|
|
36933
|
-
if (expectedSchemaVersion !== void 0) body.expectedSchemaVersion = expectedSchemaVersion;
|
|
37004
|
+
applyRecordVersionToken(args, body);
|
|
36934
37005
|
return output((await client.post(`/api/records/${enc(recordId2)}/transitions/${enc(transitionName)}`, body)).data, fmt);
|
|
36935
37006
|
}
|
|
36936
37007
|
}),
|