@sechroom/cli 2026.6.11 → 2026.6.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.js +46 -14
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -502,9 +502,10 @@ async function runApi(label, fn) {
|
|
|
502
502
|
s.fail();
|
|
503
503
|
fail(err2);
|
|
504
504
|
}
|
|
505
|
-
|
|
505
|
+
const httpFailed = res.response !== void 0 && !res.response.ok;
|
|
506
|
+
if (res.error !== void 0 && res.error !== null || httpFailed) {
|
|
506
507
|
s.fail();
|
|
507
|
-
fail(res.error);
|
|
508
|
+
fail(res.error ?? (res.response ? `HTTP ${res.response.status} ${res.response.statusText}`.trim() : "request failed"));
|
|
508
509
|
}
|
|
509
510
|
s.succeed();
|
|
510
511
|
return res.data;
|
|
@@ -2283,20 +2284,50 @@ function systemTimezone() {
|
|
|
2283
2284
|
return "UTC";
|
|
2284
2285
|
}
|
|
2285
2286
|
}
|
|
2286
|
-
|
|
2287
|
+
function resolveBaseUrl(g) {
|
|
2288
|
+
const persisted = readPersisted();
|
|
2289
|
+
const local = readLocalConfig();
|
|
2290
|
+
const baseUrl = g.baseUrl ?? process.env.SECHROOM_BASE_URL ?? local.baseUrl ?? persisted.baseUrl ?? DEFAULT_BASE_URL2;
|
|
2291
|
+
return baseUrl.replace(/\/$/, "");
|
|
2292
|
+
}
|
|
2293
|
+
async function ensureTenant(baseUrl, g, opts) {
|
|
2287
2294
|
const persisted = readPersisted();
|
|
2288
2295
|
const local = readLocalConfig();
|
|
2289
|
-
let baseUrl = g.baseUrl ?? process.env.SECHROOM_BASE_URL ?? local.baseUrl ?? persisted.baseUrl ?? DEFAULT_BASE_URL2;
|
|
2290
2296
|
let tenant = g.tenant ?? process.env.SECHROOM_TENANT ?? local.tenant ?? persisted.tenant ?? "";
|
|
2291
|
-
if (canPrompt() && !opts.yes) {
|
|
2292
|
-
baseUrl = await promptText("Sechroom API base URL?", baseUrl);
|
|
2293
|
-
tenant = await promptText("Tenant id?", tenant || void 0);
|
|
2294
|
-
}
|
|
2295
|
-
baseUrl = baseUrl.replace(/\/$/, "");
|
|
2296
2297
|
if (!tenant) {
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
)
|
|
2298
|
+
const client = await makeClient({ baseUrl, tenant: "", clientId: persisted.clientId });
|
|
2299
|
+
const { data, error } = await client.GET("/auth/me/tenants", {});
|
|
2300
|
+
if (error) {
|
|
2301
|
+
fail(`Couldn't list your tenants: ${JSON.stringify(error)}. Pass --tenant <id> to skip this.`);
|
|
2302
|
+
}
|
|
2303
|
+
const tenants = data?.tenants ?? [];
|
|
2304
|
+
if (tenants.length === 0) {
|
|
2305
|
+
fail(
|
|
2306
|
+
"You're signed in, but your account isn't a member of any tenant yet. Ask an admin to add you (or create one in the app), then re-run \u2014 or pass --tenant <id>."
|
|
2307
|
+
);
|
|
2308
|
+
} else if (tenants.length === 1) {
|
|
2309
|
+
tenant = tenants[0].key;
|
|
2310
|
+
if (!opts.json) {
|
|
2311
|
+
process.stderr.write(
|
|
2312
|
+
`${ok("\u2713")} using your tenant ${style.cyan(tenants[0].label)} ${style.dim(`(${tenant})`)}
|
|
2313
|
+
`
|
|
2314
|
+
);
|
|
2315
|
+
}
|
|
2316
|
+
} else if (canPrompt() && !opts.yes) {
|
|
2317
|
+
tenant = await promptSelect(
|
|
2318
|
+
"You belong to several tenants \u2014 pick one:",
|
|
2319
|
+
tenants.map((t) => ({ label: t.label, value: t.key, hint: t.key })),
|
|
2320
|
+
data?.defaultTenantKey ?? tenants[0].key
|
|
2321
|
+
);
|
|
2322
|
+
} else {
|
|
2323
|
+
tenant = data?.defaultTenantKey ?? tenants[0].key;
|
|
2324
|
+
if (!opts.json) {
|
|
2325
|
+
process.stderr.write(
|
|
2326
|
+
`using tenant ${tenant} (${tenants.length} available \u2014 pass --tenant to choose another)
|
|
2327
|
+
`
|
|
2328
|
+
);
|
|
2329
|
+
}
|
|
2330
|
+
}
|
|
2300
2331
|
}
|
|
2301
2332
|
let storeLocal = Boolean(opts.local);
|
|
2302
2333
|
if (!opts.local && canPrompt() && !opts.yes) {
|
|
@@ -2388,8 +2419,9 @@ Examples:
|
|
|
2388
2419
|
const json = Boolean(g.json);
|
|
2389
2420
|
const yes = Boolean(opts.yes);
|
|
2390
2421
|
const dryRun = Boolean(opts.dryRun);
|
|
2391
|
-
const
|
|
2392
|
-
await ensureAuth(
|
|
2422
|
+
const baseUrl = resolveBaseUrl(g);
|
|
2423
|
+
await ensureAuth({ baseUrl, tenant: "", clientId: readPersisted().clientId }, yes);
|
|
2424
|
+
const cfg = await ensureTenant(baseUrl, g, { yes, json, local: Boolean(opts.local) });
|
|
2393
2425
|
const tz = await ensureTimezone(cfg, { yes, dryRun });
|
|
2394
2426
|
if (!json && tz.action !== "already-set") {
|
|
2395
2427
|
const line = tz.action === "set" ? `${ok("\u2713")} timezone set to ${tz.timezone}
|
package/package.json
CHANGED