api

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package api talks to the Bachs HTTP API.

Only the handful of calls the CLI needs. Errors carry the server's own message rather than a bare status code: a bad event name or a key missing webhooks:write is worth reading, and hiding it behind "400" wastes the user's time.

Index

Constants

This section is empty.

Variables

View Source
var Version = "dev"

Version is the CLI version, overridden at build time via -ldflags. Set by main before any request is made, so the user agent is computed per call rather than frozen at init.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func New

func New(cfg config.Config) *Client

func (*Client) CloseSession

func (c *Client) CloseSession(ctx context.Context, sessionID string) error

CloseSession releases a session so fanout stops aiming at a socket nobody holds. Best-effort at shutdown — the server's reaper covers the case where this never runs, which is why a failure here is not worth surfacing.

func (*Client) CreateEndpoint added in v0.2.0

func (c *Client) CreateEndpoint(
	ctx context.Context, req CreateEndpointRequest,
) (*CreateEndpointResponse, error)

func (*Client) CreateSession

func (c *Client) CreateSession(
	ctx context.Context, req CreateSessionRequest,
) (*CreateSessionResponse, error)

func (*Client) DeleteEndpoint added in v0.2.0

func (c *Client) DeleteEndpoint(ctx context.Context, endpointID string) error

func (*Client) ListEndpoints added in v0.2.0

func (c *Client) ListEndpoints(ctx context.Context) ([]Endpoint, error)

func (*Client) ListEvents added in v0.2.0

func (c *Client) ListEvents(
	ctx context.Context, limit, offset int,
) (*EventsResponse, error)

ListEvents returns a page of recent events, newest first.

The server takes only limit and offset, so any filtering by type or outcome happens in the caller. Pages are capped at 100 server-side.

func (*Client) ListSessions added in v0.2.2

func (c *Client) ListSessions(ctx context.Context) ([]Session, error)

ListSessions returns the forwarding sessions that have not finished.

func (*Client) Raw added in v0.2.1

func (c *Client) Raw(
	ctx context.Context, method, path string, body any, out any,
) error

Raw performs an arbitrary request against the API.

Used by the generated resource commands, where the path and method come from the OpenAPI spec rather than a hand-written method per endpoint.

func (*Client) Replay

func (c *Client) Replay(
	ctx context.Context, eventID string,
) (*ReplayResponse, error)

func (*Client) Trigger added in v0.2.0

func (c *Client) Trigger(
	ctx context.Context, eventType string,
) (*TriggerResponse, error)

Trigger emits a sample event so a handler can be exercised without making a real payment. Sandbox only; the server refuses in production.

type CreateEndpointRequest added in v0.2.0

type CreateEndpointRequest struct {
	Name       string   `json:"name"`
	URL        string   `json:"url"`
	EventTypes []string `json:"event_types"`
}

type CreateEndpointResponse added in v0.2.0

type CreateEndpointResponse struct {
	Endpoint
	Secret string `json:"secret"`
}

CreateEndpointResponse carries the signing secret, which the API returns only on creation.

type CreateSessionRequest

type CreateSessionRequest struct {
	DeviceName string   `json:"device_name,omitempty"`
	ForwardTo  string   `json:"forward_to,omitempty"`
	Events     []string `json:"events,omitempty"`
}

type CreateSessionResponse

type CreateSessionResponse struct {
	SessionID     string   `json:"session_id"`
	Token         string   `json:"token"`
	SigningSecret string   `json:"signing_secret"`
	WebSocketPath string   `json:"websocket_path"`
	Events        []string `json:"events"`
	// How often to cycle the connection. Server-dictated so deploys can
	// drain sockets without stranding them.
	ReconnectAfterSeconds int `json:"reconnect_after_seconds"`
}

type DeviceCodeRequest added in v0.2.1

type DeviceCodeRequest struct {
	DeviceName string `json:"device_name,omitempty"`
}

type DeviceCodeResponse added in v0.2.1

type DeviceCodeResponse struct {
	DeviceCode      string `json:"device_code"`
	UserCode        string `json:"user_code"`
	VerificationURI string `json:"verification_uri"`
	ExpiresIn       int    `json:"expires_in"`
	Interval        int    `json:"interval"`
}

func RequestDeviceCode added in v0.2.1

func RequestDeviceCode(
	ctx context.Context, baseURL, deviceName string,
) (*DeviceCodeResponse, error)

RequestDeviceCode starts a login. Unauthenticated: there is no credential yet.

type DeviceTokenResponse added in v0.2.1

type DeviceTokenResponse struct {
	Status         string `json:"status"`
	APIKey         string `json:"api_key"`
	OrganizationID string `json:"organization_id"`
}

func PollDeviceToken added in v0.2.1

func PollDeviceToken(
	ctx context.Context, baseURL, deviceCode string,
) (*DeviceTokenResponse, error)

PollDeviceToken checks whether the login has been approved yet.

type Endpoint added in v0.2.0

type Endpoint struct {
	EndpointID  string   `json:"endpoint_id"`
	Name        string   `json:"name"`
	URL         *string  `json:"url"`
	Enabled     bool     `json:"enabled"`
	EventTypes  []string `json:"event_types"`
	EventSource string   `json:"event_source"`
	CreatedAt   string   `json:"created_at"`
}

type Error

type Error struct {
	StatusCode int
	Detail     string
	Code       string
}

Error is an API error with the server's own detail preserved.

func (*Error) Error

func (e *Error) Error() string

type Event added in v0.2.0

type Event struct {
	EventID    string `json:"event_id"`
	EventType  string `json:"event_type"`
	EntityType string `json:"entity_type"`
	EntityID   string `json:"entity_id"`
	CreatedAt  string `json:"created_at"`
	Account    string `json:"account"`

	// Attempts is 0 when nothing was configured to receive the event. That
	// distinction matters: it separates "nobody was listening" from "delivery
	// was tried and failed", which otherwise look identical from outside.
	Attempts int `json:"attempts"`
	Success  int `json:"success"`
	Failed   int `json:"failed"`

	LastAttemptStatus     *string `json:"last_attempt_status"`
	LastAttemptHTTPStatus *int    `json:"last_attempt_http_status"`
	LastAttemptError      *string `json:"last_attempt_error"`
	LastAttemptAt         *string `json:"last_attempt_at"`
}

Event is one webhook event and a summary of how its delivery went.

type EventsResponse added in v0.2.0

type EventsResponse struct {
	Items  []Event `json:"items"`
	Total  int     `json:"total"`
	Limit  int     `json:"limit"`
	Offset int     `json:"offset"`
}

type ReplayRequest

type ReplayRequest struct {
	EventID string `json:"event_id,omitempty"`
}

type ReplayResponse

type ReplayResponse struct {
	EventID   string `json:"event_id"`
	AttemptID string `json:"attempt_id"`
	AttemptNo int    `json:"attempt_no"`
	EventType string `json:"event_type"`
}

type Session added in v0.2.2

type Session struct {
	SessionID  string `json:"session_id"`
	DeviceName string `json:"device_name"`
	ForwardTo  string `json:"forward_to"`
	Status     string `json:"status"`
	// Live is the truth about whether anything is holding the socket right
	// now. Status alone can lie, because a killed process never gets to
	// update it.
	Live       bool   `json:"live"`
	LastSeenAt string `json:"last_seen_at"`
	CreatedAt  string `json:"created_at"`
}

type TriggerRequest added in v0.2.0

type TriggerRequest struct {
	EventType string `json:"event_type"`
}

type TriggerResponse added in v0.2.0

type TriggerResponse struct {
	EventID   string `json:"event_id"`
	EventType string `json:"event_type"`
	// Destinations is 0 when nothing is configured to receive the event, which
	// is worth surfacing: the trigger succeeded but nobody heard it.
	Destinations int `json:"destinations"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL