kern0-cli 0.1.2 → 0.1.4

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.
@@ -13,6 +13,7 @@ import {
13
13
  pollForToken,
14
14
  completeLogin,
15
15
  } from "../auth-flow";
16
+ import { listOrganizations } from "../api";
16
17
  import open from "open";
17
18
 
18
19
  export async function login(): Promise<void> {
@@ -52,8 +53,8 @@ export async function login(): Promise<void> {
52
53
  console.log("✅ Approved!\n");
53
54
  console.log("⏳ Completing login...\n");
54
55
 
55
- // Step 3: Complete login (fetch user, orgs, save config)
56
- const { user, organizations } = await completeLogin(
56
+ // Step 3: Complete login (save user and token)
57
+ const { user } = await completeLogin(
57
58
  tokenResponse.access_token,
58
59
  tokenResponse.expires_in,
59
60
  tokenResponse.user,
@@ -62,12 +63,19 @@ export async function login(): Promise<void> {
62
63
  console.log("✅ Login successful!\n");
63
64
  console.log(`👤 User: ${user.email}\n`);
64
65
 
65
- // Step 4: Select organization
66
+ // Step 4: Fetch organizations from API
67
+ console.log("⏳ Loading organizations...\n");
68
+ const organizations = await listOrganizations();
69
+
66
70
  if (organizations.length === 0) {
67
- console.log("⚠️ No organizations found. Create one with 'kern0 org create'.\n");
71
+ console.log("ℹ️ No organizations found. Create one with 'kern0 org create'.\n");
68
72
  return;
69
73
  }
70
74
 
75
+ // Save organizations to config
76
+ const orgData = organizations.map(o => ({ id: o.id, name: o.name }));
77
+ setOrganizations(orgData);
78
+
71
79
  if (organizations.length === 1) {
72
80
  // Auto-select if only one org
73
81
  setCurrentOrg(organizations[0].id);
@@ -34,12 +34,12 @@ export async function listOrgs(): Promise<void> {
34
34
 
35
35
  orgs.forEach(org => {
36
36
  if (!org.id || !org.name) return; // Skip orgs without proper data
37
- const marker = org.id === currentOrgId ? "* " : " ";
37
+ const marker = org.id === currentOrgId ? "✓ " : " ";
38
38
  const type = org.type === "msp" ? " (MSP)" : "";
39
- console.log(` ${marker}${org.id.substring(0, 8)}... ${org.name}${type}`);
39
+ console.log(` ${marker}${org.id} ${org.name}${type}`);
40
40
  });
41
41
 
42
- console.log("");
42
+ console.log("\n📌 Usage: kern0 org select <orgId> or kern0 org select <name>\n");
43
43
  } catch (error) {
44
44
  if (error instanceof Error) {
45
45
  console.error("Error:", error.message);
@@ -48,15 +48,21 @@ export async function listOrgs(): Promise<void> {
48
48
  }
49
49
  }
50
50
 
51
- export async function selectOrg(orgId: string): Promise<void> {
51
+ export async function selectOrg(orgIdentifier: string): Promise<void> {
52
52
  try {
53
53
  requireAuthentication();
54
54
 
55
+ // Check if orgIdentifier is a name by fetching all orgs
56
+ const allOrgs = await listOrganizations();
57
+ const orgByName = allOrgs.find(o => o.name.toLowerCase() === orgIdentifier.toLowerCase());
58
+
59
+ const finalOrgId = orgByName ? orgByName.id : orgIdentifier;
60
+
55
61
  // Verify org exists by fetching it
56
- const org = await getOrganization(orgId);
62
+ const org = await getOrganization(finalOrgId);
57
63
 
58
64
  // Update current org
59
- setCurrentOrg(orgId);
65
+ setCurrentOrg(finalOrgId);
60
66
 
61
67
  // Add to organizations list if not already there
62
68
  addOrganization({ id: org.id, name: org.name });
@@ -0,0 +1,69 @@
1
+ import { loadConfig, saveConfig } from "../config";
2
+
3
+ export async function setupCommand(): Promise<void> {
4
+ console.log("\n🔧 KernZero CLI Setup\n");
5
+
6
+ const config = loadConfig();
7
+
8
+ console.log("Current configuration:");
9
+ console.log(` API URL: ${config.api_url}\n`);
10
+
11
+ console.log("Available endpoints:");
12
+ console.log(" 1. Staging: https://staging.kernzero.com");
13
+ console.log(" 2. Production: https://kernzero.com");
14
+ console.log(" 3. Local: http://localhost:3000");
15
+ console.log(" 4. Custom (enter URL)\n");
16
+
17
+ const readline = await import("readline");
18
+ const rl = readline.createInterface({
19
+ input: process.stdin,
20
+ output: process.stdout,
21
+ });
22
+
23
+ const question = (prompt: string): Promise<string> => {
24
+ return new Promise((resolve) => {
25
+ rl.question(prompt, resolve);
26
+ });
27
+ };
28
+
29
+ try {
30
+ const choice = await question("Select option (1-4): ");
31
+
32
+ let apiUrl = config.api_url;
33
+
34
+ switch (choice.trim()) {
35
+ case "1":
36
+ apiUrl = "https://staging.kernzero.com";
37
+ console.log("\n✅ Set to Staging");
38
+ break;
39
+ case "2":
40
+ apiUrl = "https://kernzero.com";
41
+ console.log("\n✅ Set to Production");
42
+ break;
43
+ case "3":
44
+ apiUrl = "http://localhost:3000";
45
+ console.log("\n✅ Set to Local");
46
+ break;
47
+ case "4":
48
+ const custom = await question("Enter API URL: ");
49
+ apiUrl = custom.trim();
50
+ console.log(`\n✅ Set to ${apiUrl}`);
51
+ break;
52
+ default:
53
+ console.log("\n❌ Invalid option");
54
+ rl.close();
55
+ return;
56
+ }
57
+
58
+ config.api_url = apiUrl;
59
+ saveConfig(config);
60
+
61
+ console.log("\n✅ Configuration saved to ~/.kern0/config.json");
62
+ console.log("\nNext steps:");
63
+ console.log(" 1. Run: kern0 login");
64
+ console.log(" 2. Authenticate with your passkey");
65
+ console.log(" 3. Check: kern0 whoami\n");
66
+ } finally {
67
+ rl.close();
68
+ }
69
+ }
package/lib/cli/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { login, logout } from "./commands/auth";
4
+ import { setupCommand } from "./commands/setup";
4
5
  import {
5
6
  listOrgs,
6
7
  selectOrg,
@@ -40,6 +41,10 @@ async function main() {
40
41
  await logout();
41
42
  break;
42
43
 
44
+ case "setup":
45
+ await setupCommand();
46
+ break;
47
+
43
48
  // Organization commands
44
49
  case "org":
45
50
  switch (subcommand) {
@@ -174,6 +179,9 @@ Kern0 CLI - Recovery Readiness Assessment Tool
174
179
  USAGE:
175
180
  kern0 <command> [options]
176
181
 
182
+ FIRST TIME SETUP:
183
+ setup Configure API endpoint (required before login)
184
+
177
185
  AUTHENTICATION:
178
186
  login Authenticate with OAuth device flow
179
187
  logout Clear credentials and log out
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kern0-cli",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "KernZero CLI - Recovery control plane management from the terminal",
5
5
  "private": false,
6
6
  "license": "MIT",