From 6f71f173c6aa536c6967711814970c371a8c179d Mon Sep 17 00:00:00 2001 From: Charlie Cruzan Date: Thu, 19 Sep 2024 15:17:13 -1000 Subject: [PATCH] Small connect fixes for billing meters --- pkg/cmd/listen.go | 12 +++++++++++- .../v1.billing.meter.error_report_triggered.json | 16 ++++++++++------ .../v1.billing.meter.no_meter_found.json | 12 ++++++++---- pkg/proxy/v2_stripe_event.go | 5 +++++ 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/pkg/cmd/listen.go b/pkg/cmd/listen.go index a30a130e..eff12a26 100644 --- a/pkg/cmd/listen.go +++ b/pkg/cmd/listen.go @@ -269,12 +269,22 @@ func (lc *listenCmd) createVisitor(logger *log.Logger, format string, printJSON VisitData: func(de websocket.DataElement) error { switch data := de.Data.(type) { case proxy.V2EventPayload: + if strings.ToUpper(format) == outputFormatJSON || printJSON { + fmt.Println(de.Marshaled) + return nil + } + + maybeConnect := "" + if data.IsConnect() { + maybeConnect = "connect " + } localTime := time.Now().Format(timeLayout) color := ansi.Color(os.Stdout) - outputStr := fmt.Sprintf("%s --> %s [%s]", + outputStr := fmt.Sprintf("%s --> %s%s [%s]", color.Faint(localTime), + maybeConnect, ansi.Bold(data.Type), ansi.Linkify(data.ID, data.URLForEventID(lc.deviceToken), logger.Out), ) diff --git a/pkg/fixtures/triggers/v1.billing.meter.error_report_triggered.json b/pkg/fixtures/triggers/v1.billing.meter.error_report_triggered.json index 565f6426..cf977d33 100644 --- a/pkg/fixtures/triggers/v1.billing.meter.error_report_triggered.json +++ b/pkg/fixtures/triggers/v1.billing.meter.error_report_triggered.json @@ -55,13 +55,17 @@ "Authorization": "Bearer ${billing_meter_event_session:authentication_token}" }, "params": { - "event_name": "${list_billing_meters_after_creation:data.0.event_name}", - "timestamp":"${time-now-RFC3339}", - "identifier": "${generate-uuid}", - "payload": { - "value":"1" + "events": [ + { + "event_name": "${list_billing_meters_after_creation:data.0.event_name}", + "timestamp":"${time-now-RFC3339}", + "identifier": "${generate-uuid}", + "payload": { + "value":"1" + } } - } + ] + } } ] } diff --git a/pkg/fixtures/triggers/v1.billing.meter.no_meter_found.json b/pkg/fixtures/triggers/v1.billing.meter.no_meter_found.json index a03ce15c..68ae2d58 100644 --- a/pkg/fixtures/triggers/v1.billing.meter.no_meter_found.json +++ b/pkg/fixtures/triggers/v1.billing.meter.no_meter_found.json @@ -24,11 +24,15 @@ "Authorization": "Bearer ${billing_meter_event_session:authentication_token}" }, "params": { - "event_name": "${generate-uuid}", - "timestamp":"${time-now-RFC3339}", - "payload": { - "value":"10" + "events": [ + { + "event_name": "${generate-uuid}", + "timestamp":"${time-now-RFC3339}", + "payload": { + "value":"10" + } } + ] } } ] diff --git a/pkg/proxy/v2_stripe_event.go b/pkg/proxy/v2_stripe_event.go index 786a6c8a..c6ef0efe 100644 --- a/pkg/proxy/v2_stripe_event.go +++ b/pkg/proxy/v2_stripe_event.go @@ -26,3 +26,8 @@ type primaryRelatedObject struct { func (e *V2EventPayload) URLForEventID(cliEndpointID string) string { return fmt.Sprintf("https://dashboard.stripe.com/workbench/webhooks/%s?event=%s", cliEndpointID, e.ID) } + +// IsConnect returns true if this event is associated with a connected account +func (e *V2EventPayload) IsConnect() bool { + return e.Context != "" +}