trainfabric 0.1.22 → 0.1.23
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.cjs +35 -8
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -8954,7 +8954,7 @@ function buildComputeSpec(options) {
|
|
|
8954
8954
|
|
|
8955
8955
|
// src/index.ts
|
|
8956
8956
|
var DEFAULT_TRAINFABRIC_API_URL2 = "https://api.trainfabric.com";
|
|
8957
|
-
var CLI_VERSION = "0.1.
|
|
8957
|
+
var CLI_VERSION = "0.1.23";
|
|
8958
8958
|
var CONFIG_DIR = import_node_path3.default.join(import_node_os2.default.homedir(), ".trainfabric");
|
|
8959
8959
|
var CONFIG_PATH = import_node_path3.default.join(CONFIG_DIR, "config.json");
|
|
8960
8960
|
var FALLBACK_SECRET_PATH = import_node_path3.default.join(CONFIG_DIR, "session.enc");
|
|
@@ -9418,6 +9418,21 @@ function createClient(config) {
|
|
|
9418
9418
|
projectId: config.projectId
|
|
9419
9419
|
});
|
|
9420
9420
|
}
|
|
9421
|
+
function normalizeHttpBaseUrl(value) {
|
|
9422
|
+
let url;
|
|
9423
|
+
try {
|
|
9424
|
+
url = new URL(value);
|
|
9425
|
+
} catch {
|
|
9426
|
+
throw new Error(`Invalid base URL "${value}". Use an absolute http(s) URL such as https://api.trainfabric.com.`);
|
|
9427
|
+
}
|
|
9428
|
+
if (url.protocol !== "https:" && url.protocol !== "http:") {
|
|
9429
|
+
throw new Error(`Invalid base URL "${value}". Use an absolute http(s) URL such as https://api.trainfabric.com.`);
|
|
9430
|
+
}
|
|
9431
|
+
url.pathname = url.pathname.replace(/\/+$/, "");
|
|
9432
|
+
url.search = "";
|
|
9433
|
+
url.hash = "";
|
|
9434
|
+
return url.toString().replace(/\/+$/, "");
|
|
9435
|
+
}
|
|
9421
9436
|
async function login(config) {
|
|
9422
9437
|
const apiKey = await promptApiKey();
|
|
9423
9438
|
if (!apiKey) {
|
|
@@ -9463,20 +9478,32 @@ program2.command("config:show").description("Show the active CLI configuration")
|
|
|
9463
9478
|
printJson(visibleConfig(loadConfig()));
|
|
9464
9479
|
});
|
|
9465
9480
|
program2.command("config:set-base-url").argument("<baseUrl>").description("Set the backend base URL").action((baseUrl) => {
|
|
9481
|
+
const normalizedBaseUrl = normalizeHttpBaseUrl(String(baseUrl));
|
|
9466
9482
|
const config = updateConfig((current) => {
|
|
9467
|
-
current.baseUrl =
|
|
9483
|
+
current.baseUrl = normalizedBaseUrl;
|
|
9468
9484
|
});
|
|
9469
9485
|
printJson(visibleConfig(config));
|
|
9470
9486
|
});
|
|
9471
|
-
program2.command("config:set-org").argument("<orgId>").description("Set the default organization ID").action((orgId) => {
|
|
9472
|
-
const
|
|
9473
|
-
|
|
9487
|
+
program2.command("config:set-org").argument("<orgId>").description("Set the default organization ID").action(async (orgId) => {
|
|
9488
|
+
const currentConfig = loadConfig();
|
|
9489
|
+
const organization = await createClient(currentConfig).organizations.get(String(orgId));
|
|
9490
|
+
const updatedConfig = updateConfig((current) => {
|
|
9491
|
+
current.orgId = organization.id;
|
|
9492
|
+
if (current.projectId) {
|
|
9493
|
+
current.projectId = void 0;
|
|
9494
|
+
}
|
|
9474
9495
|
});
|
|
9475
|
-
printJson(visibleConfig(
|
|
9496
|
+
printJson(visibleConfig(updatedConfig));
|
|
9476
9497
|
});
|
|
9477
|
-
program2.command("config:set-project").argument("<projectId>").description("Set the default project ID").action((projectId) => {
|
|
9498
|
+
program2.command("config:set-project").argument("<projectId>").description("Set the default project ID").action(async (projectId) => {
|
|
9499
|
+
const currentConfig = loadConfig();
|
|
9500
|
+
const project = await createClient(currentConfig).projects.get(String(projectId));
|
|
9501
|
+
if (currentConfig.orgId && project.organizationId !== currentConfig.orgId) {
|
|
9502
|
+
throw new Error(`Project ${project.id} does not belong to configured organization ${currentConfig.orgId}.`);
|
|
9503
|
+
}
|
|
9478
9504
|
const config = updateConfig((current) => {
|
|
9479
|
-
current.projectId =
|
|
9505
|
+
current.projectId = project.id;
|
|
9506
|
+
current.orgId ??= project.organizationId;
|
|
9480
9507
|
});
|
|
9481
9508
|
printJson(visibleConfig(config));
|
|
9482
9509
|
});
|