kern0-cli 0.1.3 → 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 });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kern0-cli",
3
- "version": "0.1.3",
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",