-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.go
More file actions
83 lines (72 loc) · 2.59 KB
/
Copy pathdashboard.go
File metadata and controls
83 lines (72 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
74
75
76
77
78
79
80
81
82
83
package main
import (
"encoding/json"
"fmt"
)
// This file implements `splashify dashboard` — the CLI mirror of the
// app's home /dashboard page. It returns a consolidated snapshot of the
// signals the page surfaces: WABA + phone status, setup checklist, plan,
// wallet balance, AI-credit balance, and KYC verification state.
//
// splashify dashboard consolidated snapshot (default)
// splashify dashboard setup-status just the setup checklist
// splashify dashboard whatsapp-status just the WhatsApp/Meta status
// splashify dashboard kyc KYC verification status
//
// All endpoints are read-only. Writes (sync-meta, register-phone, OBA
// apply, etc.) live under `splashify waba` to keep the dashboard surface
// focused on observation.
func cmdDashboard(args []string) error {
sub := ""
if len(args) > 0 {
sub = args[0]
}
switch sub {
case "", "overview", "details":
return cmdDashboardOverview()
case "setup-status", "setup":
return runReq("GET", "/app/dashboard/setup-status", nil)
case "whatsapp-status", "whatsapp", "wa":
return runReq("GET", "/app/dashboard/whatsapp-status", nil)
case "kyc", "kyc-status":
return runReq("GET", "/app/kyc/status", nil)
case "embedded-signup-config", "es-config":
return runReq("GET", "/app/dashboard/embedded-signup/config", nil)
default:
return fmt.Errorf("unknown dashboard subcommand: %s\n"+
"run: splashify dashboard (or setup-status | whatsapp-status | kyc)", sub)
}
}
// cmdDashboardOverview merges the six endpoints the /dashboard page hits
// on first load into a single JSON blob. Missing or failing endpoints
// degrade gracefully — the caller still sees whichever sections did
// resolve. Mirrors the consolidation pattern in cmdAccount /
// cmdBilling / cmdSubscription.
func cmdDashboardOverview() error {
cfg, err := requireConfig()
if err != nil {
return err
}
api := newAPIClient(cfg.BaseURL, cfg.Token)
fetch := func(path string) json.RawMessage {
raw, err := api.callRaw("GET", path, nil)
if err != nil {
return json.RawMessage(fmt.Sprintf(`{"error":%q}`, err.Error()))
}
return raw
}
out := map[string]json.RawMessage{
"setup_status": fetch("/app/dashboard/setup-status"),
"whatsapp_status": fetch("/app/dashboard/whatsapp-status"),
"plan": fetch("/app/plans/subscription"),
"wallet": fetch("/app/wallet/info"),
"ai_credits": fetch("/app/ai-credits/info"),
"kyc": fetch("/app/kyc/status"),
}
raw, jerr := json.Marshal(out)
if jerr != nil {
return fmt.Errorf("marshal overview: %w", jerr)
}
printJSON(raw)
return nil
}