-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessages.go
More file actions
78 lines (70 loc) · 2.21 KB
/
messages.go
File metadata and controls
78 lines (70 loc) · 2.21 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
package tui
import "time"
// FlowUpdateType represents the type of progress update from an OAuth flow.
type FlowUpdateType int
const (
StepStart FlowUpdateType = iota
StepProgress
StepComplete
StepError
TimerTick // For countdown/elapsed time updates
BrowserOpened // Browser successfully opened
CallbackReceived // Callback received from browser
DeviceCodeReceived // Device code received from server
PollingUpdate // Polling status update
BackoffChanged // Slow_down interval changed
)
// FlowUpdate represents a progress update message from an OAuth flow.
//
// For StepError updates, the Fallback field distinguishes between two
// classes of failure:
//
// - Fallback == true → soft error (browser unavailable, user timeout).
// The caller should silently retry with the Device Code Flow.
//
// - Fallback == false → hard error (CSRF mismatch, token exchange failure,
// OAuth server rejection, etc.).
// The caller should surface the error to the user and exit.
type FlowUpdate struct {
Type FlowUpdateType
Step int // Current step number (1-indexed)
TotalSteps int // Total number of steps
Message string // Human-readable message
Progress float64 // Progress percentage (0.0 to 1.0)
// Fallback is only meaningful when Type == StepError.
// When true, the error is recoverable and the caller should fall back
// to the Device Code Flow instead of reporting a failure.
Fallback bool
Data map[string]any // Additional data for specific update types
}
// Helper functions to extract data from FlowUpdate.Data
// GetString safely extracts a string value from Data.
func (u *FlowUpdate) GetString(key string) string {
if u.Data == nil {
return ""
}
if val, ok := u.Data[key].(string); ok {
return val
}
return ""
}
// GetInt safely extracts an int value from Data.
func (u *FlowUpdate) GetInt(key string) int {
if u.Data == nil {
return 0
}
if val, ok := u.Data[key].(int); ok {
return val
}
return 0
}
// GetDuration safely extracts a time.Duration value from Data.
func (u *FlowUpdate) GetDuration(key string) time.Duration {
if u.Data == nil {
return 0
}
if val, ok := u.Data[key].(time.Duration); ok {
return val
}
return 0
}