Class: Logi::Commands::Developer

Inherits:
Thor
  • Object
show all
Defined in:
lib/logi/commands/developer.rb

Overview

Developer self-serve: promote your account to a developer, check its identity-verification state, and verify your email with a code.

Why: registering an RP (logi apps create) requires (1) a developer/admin role and (2) an identity-verified email. These commands let an AI agent or a human complete the whole onboarding from the terminal, no web console.

All endpoints authenticate with the PAK (Bearer) — no special scope is required (same trust level as promote_to_developer).

Instance Method Summary collapse

Instance Method Details

#registerObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/logi/commands/developer.rb', line 23

def register
  body = {
    email_address: options[:email],
    organization_name: options[:org]
  }.compact

  data = authed_client.post("/api/v1/me/promote_to_developer", body: body)
  user = data["user"] || {}
  org  = data["organization"] || {}

  Output.success(data, options) do
    puts pastel.green("✓ You're a developer now")
    puts "  role:         #{user['role']}"
    puts "  email:        #{user['email_address'] || '-'}"
    puts "  organization: #{org['name'] || '-'}#{org['slug'] ? " (#{org['slug']})" : ''}"
    puts ""
    unless identity_verified?(user)
      puts pastel.yellow("  Your email isn't verified yet — RP registration needs it.")
      puts pastel.dim("    → logi developer verify-email")
    end
  end
rescue HttpClient::Error => e
  handle_register_error(e)
end

#statusObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/logi/commands/developer.rb', line 49

def status
  data = authed_client.get("/api/v1/me")
  user = data["user"] || {}

  Output.success({ user: user }, options) do
    puts pastel.bold("logi developer status")
    puts ""
    puts "  role:                    #{user['role'] || '-'}"
    puts "  identity_verified_level: #{user['identity_verified_level'] || '-'}"
    puts "  email:                   #{user['email_address'] || '-'}"
    puts ""
    if identity_verified?(user)
      ok "Identity verified — you can register RPs."
    else
      warn "Identity not verified — required before `logi apps create`."
      puts pastel.dim("    → logi developer verify-email")
    end
  end
rescue HttpClient::Error => e
  Output.failure(code: "status_failed", message: "Couldn't fetch status: #{e.status} #{e.body}",
                 status: e.status, options: options) do
    abort pastel.red("Couldn't fetch status: #{e.status} #{e.body}")
  end
  exit 1
end

#verify_emailObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/logi/commands/developer.rb', line 76

def verify_email
  client = authed_client

  # Short-circuit: already verified → no email is sent.
  me = client.get("/api/v1/me")["user"] || {}
  if identity_verified?(me)
    Output.success({ identity_verified_level: me["identity_verified_level"] }, options) do
      puts pastel.green("✓ Your email is already verified.")
    end
    return
  end

  # In JSON / non-interactive mode the code comes from LOGI_VERIFY_CODE.
  # Validate it BEFORE sending an email so an automation mistake doesn't
  # trigger a wasted email + an out-of-contract abort.
  preflight_code = noninteractive_code
  if Output.json?(options) && (preflight_code.nil? || preflight_code.empty?)
    Output.failure(
      code: "code_required",
      message: "Set LOGI_VERIFY_CODE with the 6-digit code in JSON mode.",
      options: options
    ) { abort pastel.red("Set LOGI_VERIFY_CODE with the 6-digit code in JSON mode.") }
    exit 1
  end

  client.post("/api/v1/me/email_verifications")
  Output.chatter(pastel.dim("A 6-digit code was sent to your email (valid 10 minutes)."), options)

  code = preflight_code && !preflight_code.empty? ? preflight_code : read_code
  data = client.post("/api/v1/me/email_verifications/verify_code", body: { code: code })

  Output.success(data, options) do
    puts pastel.green("✓ Email verified")
    puts "  identity_verified_level: #{data['identity_verified_level']}"
  end
rescue HttpClient::Error => e
  handle_verify_error(e)
end