Skip to content

Commit ba444a3

Browse files
leggetterclaude
andcommitted
feat(listen): link guest accounts to Hookdeck Inspect
Guest accounts (project type console) were linked to Hookdeck Console with ?event_id= and ?team_id=, which mean nothing to Hookdeck Inspect. listen now links guests to Inspect directly: - Event links go to the event's Source page in Inspect, <inspect base>/<source id without src_>. The Source is looked up from the attempt's webhook_id. The link adds ?request=<request_id> when the attempt carries one, and falls back to Inspect home when the Source is unknown. - The home link is the Source page when the session listens to exactly one Source, otherwise Inspect home. Guest links no longer carry team_id. - New optional AttemptBody.RequestID (request_id, omitempty), ready for when core adds it to the attempt payload. - New Inspect base URL, default https://inspect.hookdeck.com, which can be overridden with the hidden --inspect-base flag or inspect_base. - Every link goes through pkg/listen/links. The compact and interactive renderers no longer build URLs by hand, and the unused tui.FormatEventLog is removed. Dashboard links for non-guest projects are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 6a43726 commit ba444a3

21 files changed

Lines changed: 473 additions & 139 deletions

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,6 +1481,7 @@ There are also hidden flags for development and debugging (not listed in user-fa
14811481
* `--api-base`: Sets the API base URL.
14821482
* `--dashboard-base`: Sets the web dashboard base URL.
14831483
* `--console-base`: Sets the web console base URL.
1484+
* `--inspect-base`: Sets the Hookdeck Inspect base URL that `listen` links guest accounts to.
14841485
* `--ws-base`: Sets the Websocket base URL.
14851486

14861487
## Troubleshooting

‎pkg/cmd/root.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ var flagNeedsNextArg = map[string]bool{
318318
"outpost-api-base": true,
319319
"dashboard-base": true,
320320
"console-base": true,
321+
"inspect-base": true,
321322
"ws-base": true,
322323
}
323324

@@ -403,6 +404,9 @@ func init() {
403404
rootCmd.PersistentFlags().StringVar(&Config.ConsoleBaseURL, "console-base", "", fmt.Sprintf("Sets the web console base URL (default \"%s\")", hookdeck.DefaultConsoleBaseURL))
404405
rootCmd.PersistentFlags().MarkHidden("console-base")
405406

407+
rootCmd.PersistentFlags().StringVar(&Config.InspectBaseURL, "inspect-base", "", fmt.Sprintf("Sets the Hookdeck Inspect base URL, used for guest links (default \"%s\")", hookdeck.DefaultInspectBaseURL))
408+
rootCmd.PersistentFlags().MarkHidden("inspect-base")
409+
406410
rootCmd.PersistentFlags().StringVar(&Config.WSBaseURL, "ws-base", "", fmt.Sprintf("Sets the Websocket base URL (default \"%s\")", hookdeck.DefaultWebsocektURL))
407411
rootCmd.PersistentFlags().MarkHidden("ws-base")
408412

‎pkg/config/config.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type Config struct {
3939
OutpostAPIBaseURL string
4040
DashboardBaseURL string
4141
ConsoleBaseURL string
42+
InspectBaseURL string
4243
WSBaseURL string
4344
Insecure bool
4445

@@ -404,6 +405,7 @@ func (c *Config) constructConfig() {
404405
c.OutpostAPIBaseURL = stringCoalesce(c.OutpostAPIBaseURL, c.viper.GetString(("outpost_api_base")), hookdeck.DefaultOutpostAPIBaseURL)
405406
c.DashboardBaseURL = stringCoalesce(c.DashboardBaseURL, c.viper.GetString(("dashboard_base")), hookdeck.DefaultDashboardBaseURL)
406407
c.ConsoleBaseURL = stringCoalesce(c.ConsoleBaseURL, c.viper.GetString(("console_base")), hookdeck.DefaultConsoleBaseURL)
408+
c.InspectBaseURL = stringCoalesce(c.InspectBaseURL, c.viper.GetString(("inspect_base")), hookdeck.DefaultInspectBaseURL)
407409
c.WSBaseURL = stringCoalesce(c.WSBaseURL, c.viper.GetString(("ws_base")), hookdeck.DefaultWebsocektURL)
408410
c.Profile.Name = stringCoalesce(c.Profile.Name, c.viper.GetString(("profile")), hookdeck.DefaultProfileName)
409411
// Needs to support both profile-based config

‎pkg/hookdeck/client.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,13 @@ const DefaultDashboardURL = "https://dashboard.hookdeck.com"
3434
// DefaultDashboardBaseURL is the default base URL for dashboard requests
3535
const DefaultDashboardBaseURL = "https://dashboard.hookdeck.com"
3636

37+
// DefaultConsoleBaseURL is the default base URL for Hookdeck Console.
3738
const DefaultConsoleBaseURL = "https://console.hookdeck.com"
3839

40+
// DefaultInspectBaseURL is the default base URL for Hookdeck Inspect, which
41+
// listen links to for guest accounts (project type "console").
42+
const DefaultInspectBaseURL = "https://inspect.hookdeck.com"
43+
3944
const DefaultWebsocektURL = "wss://ws.hookdeck.com"
4045

4146
const DefaultProfileName = "default"

‎pkg/listen/links/links.go‎

Lines changed: 130 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,142 @@
1-
// Package links builds dashboard/console deep-links for listen output. It is
2-
// shared by the interactive TUI and the compact/quiet printer so the two
3-
// output modes produce identical, correctly scoped URLs.
1+
// Package links builds the web links listen prints: Event Gateway dashboard
2+
// links for regular projects, and Hookdeck Inspect links for guest accounts
3+
// (project type "console"). It is shared by the interactive TUI and the
4+
// compact/quiet output so every output mode produces identical, correctly
5+
// scoped URLs.
46
package links
57

6-
// DashboardHome returns the dashboard (or console) events link for the
7-
// session, omitting the team_id parameter when the project id is unknown so
8-
// links never render with an empty value.
9-
func DashboardHome(dashboardBaseURL, consoleBaseURL, projectType, projectID string) string {
10-
if projectType == "console" {
11-
if projectID == "" {
12-
return consoleBaseURL
13-
}
14-
return consoleBaseURL + "?team_id=" + projectID
8+
import (
9+
"net/url"
10+
"strings"
11+
12+
"github.com/hookdeck/hookdeck-cli/pkg/config"
13+
"github.com/hookdeck/hookdeck-cli/pkg/hookdeck"
14+
"github.com/hookdeck/hookdeck-cli/pkg/websocket"
15+
)
16+
17+
// Target describes where a listen session's links point.
18+
type Target struct {
19+
// DashboardBaseURL is the Event Gateway dashboard, used for every project
20+
// type except console.
21+
DashboardBaseURL string
22+
// InspectBaseURL is Hookdeck Inspect, used for guest (console) projects.
23+
InspectBaseURL string
24+
// ProjectType is the profile's project type (config.ProjectType*).
25+
ProjectType string
26+
// ProjectID scopes dashboard links with team_id. Inspect links ignore it:
27+
// an Inspect page is addressed by its Source alone.
28+
ProjectID string
29+
}
30+
31+
// Event identifies one event a link points at. SourceID and RequestID only
32+
// matter for Inspect, which has no event page: an event is shown as the
33+
// request that created it, on its Source's page.
34+
type Event struct {
35+
ID string
36+
SourceID string
37+
RequestID string
38+
}
39+
40+
func (t Target) inspect() bool {
41+
return t.ProjectType == config.ProjectTypeConsole
42+
}
43+
44+
// Home returns the link to the session's events. For the dashboard that is
45+
// the CLI events view, scoped by team_id when the project id is known. For
46+
// Inspect it is the page of sourceID, or the Inspect home page when sourceID
47+
// is empty (a session listening to several Sources has no single page).
48+
func (t Target) Home(sourceID string) string {
49+
if t.inspect() {
50+
return inspectSource(t.InspectBaseURL, sourceID, "")
1551
}
16-
if projectID == "" {
17-
return dashboardBaseURL + "/events/cli"
52+
if t.ProjectID == "" {
53+
return t.DashboardBaseURL + "/events/cli"
1854
}
19-
return dashboardBaseURL + "/events/cli?team_id=" + projectID
55+
return t.DashboardBaseURL + "/events/cli?team_id=" + t.ProjectID
2056
}
2157

22-
// DashboardHomeDisplay returns the display text for the DashboardHome link:
23-
// the same destination without the team_id query parameter.
24-
func DashboardHomeDisplay(dashboardBaseURL, consoleBaseURL, projectType string) string {
25-
if projectType == "console" {
26-
return consoleBaseURL
58+
// HomeDisplay returns the display text for the Home link: the same
59+
// destination without the team_id query parameter.
60+
func (t Target) HomeDisplay(sourceID string) string {
61+
if t.inspect() {
62+
return inspectSource(t.InspectBaseURL, sourceID, "")
2763
}
28-
return dashboardBaseURL + "/events/cli"
64+
return t.DashboardBaseURL + "/events/cli"
2965
}
3066

31-
// Event returns the dashboard (or console) deep-link for a single event,
32-
// omitting the team_id parameter when the project id is unknown.
33-
func Event(dashboardBaseURL, consoleBaseURL, projectType, projectID, eventID string) string {
34-
if projectType == "console" {
35-
url := consoleBaseURL + "/?event_id=" + eventID
36-
if projectID != "" {
37-
url += "&team_id=" + projectID
38-
}
39-
return url
67+
// EventURL returns the deep-link for a single event. For the dashboard that is
68+
// the event page, scoped by team_id when the project id is known. For Inspect
69+
// it is the event's Source page, selecting its request when the request id is
70+
// known, and the Inspect home page when the Source is unknown.
71+
func (t Target) EventURL(event Event) string {
72+
if t.inspect() {
73+
return inspectSource(t.InspectBaseURL, event.SourceID, event.RequestID)
74+
}
75+
link := t.DashboardBaseURL + "/events/" + event.ID
76+
if t.ProjectID != "" {
77+
link += "?team_id=" + t.ProjectID
78+
}
79+
return link
80+
}
81+
82+
// EventDisplay returns the display text for the EventURL link, as printed at
83+
// the end of each event log line: the same destination without the team_id
84+
// query parameter.
85+
func (t Target) EventDisplay(event Event) string {
86+
if t.inspect() {
87+
return t.EventURL(event)
4088
}
41-
url := dashboardBaseURL + "/events/" + eventID
42-
if projectID != "" {
43-
url += "?team_id=" + projectID
89+
return t.DashboardBaseURL + "/events/" + event.ID
90+
}
91+
92+
// inspectSource builds an Inspect Source page link. Inspect addresses a Source
93+
// by its id without the "src_" prefix, and selects a request with ?request=.
94+
// Without a Source it falls back to the Inspect home page.
95+
func inspectSource(inspectBaseURL, sourceID, requestID string) string {
96+
bare := strings.TrimPrefix(sourceID, "src_")
97+
if bare == "" {
98+
return inspectBaseURL
99+
}
100+
link := strings.TrimSuffix(inspectBaseURL, "/") + "/" + url.PathEscape(bare)
101+
if requestID != "" {
102+
link += "?request=" + url.QueryEscape(requestID)
103+
}
104+
return link
105+
}
106+
107+
// SessionSourceID returns the id of the one Source a session listens to, or
108+
// "" when it listens to none or to several.
109+
func SessionSourceID(sources []*hookdeck.Source) string {
110+
if len(sources) != 1 || sources[0] == nil {
111+
return ""
112+
}
113+
return sources[0].ID
114+
}
115+
116+
// AttemptEvent returns the Event an attempt delivers: its event id, the
117+
// Source of its connection (resolved from the connections the session
118+
// loaded), and its request id when the server sent one.
119+
func AttemptEvent(eventID string, attempt *websocket.Attempt, connections []*hookdeck.Connection) Event {
120+
event := Event{ID: eventID}
121+
if attempt == nil {
122+
return event
123+
}
124+
event.SourceID = ConnectionSourceID(connections, attempt.Body.ConnectionId)
125+
event.RequestID = attempt.Body.RequestID
126+
return event
127+
}
128+
129+
// ConnectionSourceID returns the id of the Source that connectionID belongs
130+
// to, from the connections the session loaded, or "" when it is not among
131+
// them. An attempt names its connection (webhook_id) but not its Source.
132+
func ConnectionSourceID(connections []*hookdeck.Connection, connectionID string) string {
133+
if connectionID == "" {
134+
return ""
135+
}
136+
for _, connection := range connections {
137+
if connection != nil && connection.ID == connectionID && connection.Source != nil {
138+
return connection.Source.ID
139+
}
44140
}
45-
return url
141+
return ""
46142
}

‎pkg/listen/links/links_test.go‎

Lines changed: 89 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,55 +4,124 @@ import (
44
"testing"
55

66
"github.com/stretchr/testify/assert"
7+
8+
"github.com/hookdeck/hookdeck-cli/pkg/hookdeck"
9+
"github.com/hookdeck/hookdeck-cli/pkg/websocket"
710
)
811

912
const (
1013
dashboardBase = "https://dashboard.hookdeck.com"
11-
consoleBase = "https://console.hookdeck.com"
14+
inspectBase = "https://inspect.hookdeck.com"
1215
)
1316

14-
func TestDashboardHome(t *testing.T) {
17+
func dashboardTarget(projectID string) Target {
18+
return Target{DashboardBaseURL: dashboardBase, InspectBaseURL: inspectBase, ProjectType: "gateway", ProjectID: projectID}
19+
}
20+
21+
func inspectTarget(projectID string) Target {
22+
return Target{DashboardBaseURL: dashboardBase, InspectBaseURL: inspectBase, ProjectType: "console", ProjectID: projectID}
23+
}
24+
25+
func TestHome(t *testing.T) {
1526
t.Run("dashboard with project id", func(t *testing.T) {
16-
assert.Equal(t, "https://dashboard.hookdeck.com/events/cli?team_id=tm_123", DashboardHome(dashboardBase, consoleBase, "inbound", "tm_123"))
27+
assert.Equal(t, "https://dashboard.hookdeck.com/events/cli?team_id=tm_123", dashboardTarget("tm_123").Home("src_abc123def456"))
1728
})
1829

1930
t.Run("dashboard without project id omits team_id", func(t *testing.T) {
20-
assert.Equal(t, "https://dashboard.hookdeck.com/events/cli", DashboardHome(dashboardBase, consoleBase, "inbound", ""))
31+
assert.Equal(t, "https://dashboard.hookdeck.com/events/cli", dashboardTarget("").Home(""))
32+
})
33+
34+
t.Run("inspect with one source links to the source page without src_ or team_id", func(t *testing.T) {
35+
assert.Equal(t, "https://inspect.hookdeck.com/abc123def456", inspectTarget("tm_123").Home("src_abc123def456"))
2136
})
2237

23-
t.Run("console with project id", func(t *testing.T) {
24-
assert.Equal(t, "https://console.hookdeck.com?team_id=tm_123", DashboardHome(dashboardBase, consoleBase, "console", "tm_123"))
38+
t.Run("inspect without a single source links to inspect home", func(t *testing.T) {
39+
assert.Equal(t, "https://inspect.hookdeck.com", inspectTarget("tm_123").Home(""))
2540
})
2641

27-
t.Run("console without project id omits team_id", func(t *testing.T) {
28-
assert.Equal(t, "https://console.hookdeck.com", DashboardHome(dashboardBase, consoleBase, "console", ""))
42+
t.Run("inspect base with trailing slash", func(t *testing.T) {
43+
target := inspectTarget("")
44+
target.InspectBaseURL = "https://inspect-staging.hookdeck.com/"
45+
assert.Equal(t, "https://inspect-staging.hookdeck.com/abc123def456", target.Home("src_abc123def456"))
2946
})
3047
}
3148

32-
func TestDashboardHomeDisplay(t *testing.T) {
33-
t.Run("dashboard shows events path", func(t *testing.T) {
34-
assert.Equal(t, "https://dashboard.hookdeck.com/events/cli", DashboardHomeDisplay(dashboardBase, consoleBase, "inbound"))
49+
func TestHomeDisplay(t *testing.T) {
50+
t.Run("dashboard shows events path without team_id", func(t *testing.T) {
51+
assert.Equal(t, "https://dashboard.hookdeck.com/events/cli", dashboardTarget("tm_123").HomeDisplay("src_abc123def456"))
3552
})
3653

37-
t.Run("console shows console base", func(t *testing.T) {
38-
assert.Equal(t, "https://console.hookdeck.com", DashboardHomeDisplay(dashboardBase, consoleBase, "console"))
54+
t.Run("inspect shows the source page", func(t *testing.T) {
55+
assert.Equal(t, "https://inspect.hookdeck.com/abc123def456", inspectTarget("tm_123").HomeDisplay("src_abc123def456"))
56+
})
57+
58+
t.Run("inspect without a single source shows inspect home", func(t *testing.T) {
59+
assert.Equal(t, "https://inspect.hookdeck.com", inspectTarget("tm_123").HomeDisplay(""))
3960
})
4061
}
4162

42-
func TestEvent(t *testing.T) {
63+
func TestEventURL(t *testing.T) {
64+
event := Event{ID: "evt_1", SourceID: "src_abc123def456", RequestID: "req_1"}
65+
4366
t.Run("dashboard with project id", func(t *testing.T) {
44-
assert.Equal(t, "https://dashboard.hookdeck.com/events/evt_1?team_id=tm_123", Event(dashboardBase, consoleBase, "inbound", "tm_123", "evt_1"))
67+
assert.Equal(t, "https://dashboard.hookdeck.com/events/evt_1?team_id=tm_123", dashboardTarget("tm_123").EventURL(event))
4568
})
4669

4770
t.Run("dashboard without project id omits team_id", func(t *testing.T) {
48-
assert.Equal(t, "https://dashboard.hookdeck.com/events/evt_1", Event(dashboardBase, consoleBase, "inbound", "", "evt_1"))
71+
assert.Equal(t, "https://dashboard.hookdeck.com/events/evt_1", dashboardTarget("").EventURL(event))
72+
})
73+
74+
t.Run("inspect with source and request selects the request", func(t *testing.T) {
75+
assert.Equal(t, "https://inspect.hookdeck.com/abc123def456?request=req_1", inspectTarget("tm_123").EventURL(event))
76+
})
77+
78+
t.Run("inspect without request id links to the source page", func(t *testing.T) {
79+
assert.Equal(t, "https://inspect.hookdeck.com/abc123def456", inspectTarget("tm_123").EventURL(Event{ID: "evt_1", SourceID: "src_abc123def456"}))
80+
})
81+
82+
t.Run("inspect with unknown source falls back to inspect home", func(t *testing.T) {
83+
assert.Equal(t, "https://inspect.hookdeck.com", inspectTarget("tm_123").EventURL(Event{ID: "evt_1", RequestID: "req_1"}))
84+
})
85+
}
86+
87+
func TestEventDisplay(t *testing.T) {
88+
event := Event{ID: "evt_1", SourceID: "src_abc123def456", RequestID: "req_1"}
89+
90+
t.Run("dashboard shows the event page without team_id", func(t *testing.T) {
91+
assert.Equal(t, "https://dashboard.hookdeck.com/events/evt_1", dashboardTarget("tm_123").EventDisplay(event))
92+
})
93+
94+
t.Run("inspect shows the same link it opens", func(t *testing.T) {
95+
assert.Equal(t, "https://inspect.hookdeck.com/abc123def456?request=req_1", inspectTarget("tm_123").EventDisplay(event))
96+
})
97+
}
98+
99+
func TestSessionSourceID(t *testing.T) {
100+
one := &hookdeck.Source{ID: "src_1"}
101+
two := &hookdeck.Source{ID: "src_2"}
102+
103+
assert.Equal(t, "src_1", SessionSourceID([]*hookdeck.Source{one}))
104+
assert.Equal(t, "", SessionSourceID([]*hookdeck.Source{one, two}), "several sources have no single page")
105+
assert.Equal(t, "", SessionSourceID(nil))
106+
}
107+
108+
func TestAttemptEvent(t *testing.T) {
109+
connections := []*hookdeck.Connection{
110+
{ID: "web_a", Source: &hookdeck.Source{ID: "src_a"}},
111+
{ID: "web_b", Source: &hookdeck.Source{ID: "src_b"}},
112+
}
113+
114+
t.Run("resolves the source from webhook_id and carries request_id", func(t *testing.T) {
115+
attempt := &websocket.Attempt{Body: websocket.AttemptBody{EventID: "evt_1", ConnectionId: "web_b", RequestID: "req_1"}}
116+
assert.Equal(t, Event{ID: "evt_1", SourceID: "src_b", RequestID: "req_1"}, AttemptEvent("evt_1", attempt, connections))
49117
})
50118

51-
t.Run("console with project id", func(t *testing.T) {
52-
assert.Equal(t, "https://console.hookdeck.com/?event_id=evt_1&team_id=tm_123", Event(dashboardBase, consoleBase, "console", "tm_123", "evt_1"))
119+
t.Run("unknown connection leaves the source empty", func(t *testing.T) {
120+
attempt := &websocket.Attempt{Body: websocket.AttemptBody{EventID: "evt_1", ConnectionId: "web_zzz"}}
121+
assert.Equal(t, Event{ID: "evt_1"}, AttemptEvent("evt_1", attempt, connections))
53122
})
54123

55-
t.Run("console without project id omits team_id", func(t *testing.T) {
56-
assert.Equal(t, "https://console.hookdeck.com/?event_id=evt_1", Event(dashboardBase, consoleBase, "console", "", "evt_1"))
124+
t.Run("nil attempt", func(t *testing.T) {
125+
assert.Equal(t, Event{ID: "evt_1"}, AttemptEvent("evt_1", nil, connections))
57126
})
58127
}

‎pkg/listen/listen.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ Specify a single destination to update the path. For example, pass a connection
174174
ProjectType: config.Profile.ProjectType,
175175
APIBaseURL: config.APIBaseURL,
176176
DashboardBaseURL: config.DashboardBaseURL,
177-
ConsoleBaseURL: config.ConsoleBaseURL,
177+
InspectBaseURL: config.InspectBaseURL,
178178
WSBaseURL: config.WSBaseURL,
179179
NoWSS: flags.NoWSS,
180180
NoHealthcheck: flags.NoHealthcheck,
@@ -194,7 +194,7 @@ Specify a single destination to update the path. For example, pass a connection
194194
APIKey: config.Profile.APIKey,
195195
APIBaseURL: config.APIBaseURL,
196196
DashboardBaseURL: config.DashboardBaseURL,
197-
ConsoleBaseURL: config.ConsoleBaseURL,
197+
InspectBaseURL: config.InspectBaseURL,
198198
ProjectType: config.Profile.ProjectType,
199199
ProjectID: projectID,
200200
GuestURL: guestURL,

0 commit comments

Comments
 (0)