{"modulePath":"github.com/bachsdev/bachs-cli","version":"v0.2.5","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package api\n\nPackage api talks to the Bachs HTTP API.\n\nOnly 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.\n\n## Variables\n\n```go\nvar Version = \"dev\"\n```\nVersion 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.\n\n## Types\n\n```go\ntype Client struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc New(cfg config.Config) *Client\n```\n\n```go\nfunc (c *Client) CloseSession(ctx context.Context, sessionID string) error\n```\nCloseSession 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.\n\n```go\nfunc (c *Client) CreateEndpoint(\n\tctx context.Context, req CreateEndpointRequest,\n) (*CreateEndpointResponse, error)\n```\n\n```go\nfunc (c *Client) CreateSession(\n\tctx context.Context, req CreateSessionRequest,\n) (*CreateSessionResponse, error)\n```\n\n```go\nfunc (c *Client) DeleteEndpoint(ctx context.Context, endpointID string) error\n```\n\n```go\nfunc (c *Client) ListEndpoints(ctx context.Context) ([]Endpoint, error)\n```\n\n```go\nfunc (c *Client) ListEvents(\n\tctx context.Context, limit, offset int,\n) (*EventsResponse, error)\n```\nListEvents returns a page of recent events, newest first.\n\nThe server takes only limit and offset, so any filtering by type or outcome happens in the caller. Pages are capped at 100 server-side.\n\n```go\nfunc (c *Client) ListSessions(ctx context.Context) ([]Session, error)\n```\nListSessions returns the forwarding sessions that have not finished.\n\n```go\nfunc (c *Client) Raw(\n\tctx context.Context, method, path string, body any, out any,\n) error\n```\nRaw performs an arbitrary request against the API.\n\nUsed by the generated resource commands, where the path and method come from the OpenAPI spec rather than a hand-written method per endpoint.\n\n```go\nfunc (c *Client) Replay(\n\tctx context.Context, eventID string,\n) (*ReplayResponse, error)\n```\n\n```go\nfunc (c *Client) Trigger(\n\tctx context.Context, eventType string,\n) (*TriggerResponse, error)\n```\nTrigger emits a sample event so a handler can be exercised without making a real payment. Sandbox only; the server refuses in production.\n\n```go\ntype CreateEndpointRequest struct {\n\tName       string   `json:\"name\"`\n\tURL        string   `json:\"url\"`\n\tEventTypes []string `json:\"event_types\"`\n}\n```\n\n```go\ntype CreateEndpointResponse struct {\n\tEndpoint\n\tSecret string `json:\"secret\"`\n}\n```\nCreateEndpointResponse carries the signing secret, which the API returns only on creation.\n\n```go\ntype CreateSessionRequest struct {\n\tDeviceName string   `json:\"device_name,omitempty\"`\n\tForwardTo  string   `json:\"forward_to,omitempty\"`\n\tEvents     []string `json:\"events,omitempty\"`\n}\n```\n\n```go\ntype CreateSessionResponse struct {\n\tSessionID     string   `json:\"session_id\"`\n\tToken         string   `json:\"token\"`\n\tSigningSecret string   `json:\"signing_secret\"`\n\tWebSocketPath string   `json:\"websocket_path\"`\n\tEvents        []string `json:\"events\"`\n\t// How often to cycle the connection. Server-dictated so deploys can\n\t// drain sockets without stranding them.\n\tReconnectAfterSeconds int `json:\"reconnect_after_seconds\"`\n}\n```\n\n```go\ntype DeviceCodeRequest struct {\n\tDeviceName string `json:\"device_name,omitempty\"`\n}\n```\n\n```go\ntype DeviceCodeResponse struct {\n\tDeviceCode      string `json:\"device_code\"`\n\tUserCode        string `json:\"user_code\"`\n\tVerificationURI string `json:\"verification_uri\"`\n\tExpiresIn       int    `json:\"expires_in\"`\n\tInterval        int    `json:\"interval\"`\n}\n```\n\n```go\nfunc RequestDeviceCode(\n\tctx context.Context, baseURL, deviceName string,\n) (*DeviceCodeResponse, error)\n```\nRequestDeviceCode starts a login. Unauthenticated: there is no credential yet.\n\n```go\ntype DeviceTokenResponse struct {\n\tStatus         string `json:\"status\"`\n\tAPIKey         string `json:\"api_key\"`\n\tOrganizationID string `json:\"organization_id\"`\n}\n```\n\n```go\nfunc PollDeviceToken(\n\tctx context.Context, baseURL, deviceCode string,\n) (*DeviceTokenResponse, error)\n```\nPollDeviceToken checks whether the login has been approved yet.\n\n```go\ntype Endpoint struct {\n\tEndpointID  string   `json:\"endpoint_id\"`\n\tName        string   `json:\"name\"`\n\tURL         *string  `json:\"url\"`\n\tEnabled     bool     `json:\"enabled\"`\n\tEventTypes  []string `json:\"event_types\"`\n\tEventSource string   `json:\"event_source\"`\n\tCreatedAt   string   `json:\"created_at\"`\n}\n```\n\n```go\ntype Error struct {\n\tStatusCode int\n\tDetail     string\n\tCode       string\n}\n```\nError is an API error with the server's own detail preserved.\n\n```go\nfunc (e *Error) Error() string\n```\n\n```go\ntype Event struct {\n\tEventID    string `json:\"event_id\"`\n\tEventType  string `json:\"event_type\"`\n\tEntityType string `json:\"entity_type\"`\n\tEntityID   string `json:\"entity_id\"`\n\tCreatedAt  string `json:\"created_at\"`\n\tAccount    string `json:\"account\"`\n\n\t// Attempts is 0 when nothing was configured to receive the event. That\n\t// distinction matters: it separates \"nobody was listening\" from \"delivery\n\t// was tried and failed\", which otherwise look identical from outside.\n\tAttempts int `json:\"attempts\"`\n\tSuccess  int `json:\"success\"`\n\tFailed   int `json:\"failed\"`\n\n\tLastAttemptStatus     *string `json:\"last_attempt_status\"`\n\tLastAttemptHTTPStatus *int    `json:\"last_attempt_http_status\"`\n\tLastAttemptError      *string `json:\"last_attempt_error\"`\n\tLastAttemptAt         *string `json:\"last_attempt_at\"`\n}\n```\nEvent is one webhook event and a summary of how its delivery went.\n\n```go\ntype EventsResponse struct {\n\tItems  []Event `json:\"items\"`\n\tTotal  int     `json:\"total\"`\n\tLimit  int     `json:\"limit\"`\n\tOffset int     `json:\"offset\"`\n}\n```\n\n```go\ntype ReplayRequest struct {\n\tEventID string `json:\"event_id,omitempty\"`\n}\n```\n\n```go\ntype ReplayResponse struct {\n\tEventID   string `json:\"event_id\"`\n\tAttemptID string `json:\"attempt_id\"`\n\tAttemptNo int    `json:\"attempt_no\"`\n\tEventType string `json:\"event_type\"`\n}\n```\n\n```go\ntype Session struct {\n\tSessionID  string `json:\"session_id\"`\n\tDeviceName string `json:\"device_name\"`\n\tForwardTo  string `json:\"forward_to\"`\n\tStatus     string `json:\"status\"`\n\t// Live is the truth about whether anything is holding the socket right\n\t// now. Status alone can lie, because a killed process never gets to\n\t// update it.\n\tLive       bool   `json:\"live\"`\n\tLastSeenAt string `json:\"last_seen_at\"`\n\tCreatedAt  string `json:\"created_at\"`\n}\n```\n\n```go\ntype TriggerRequest struct {\n\tEventType string `json:\"event_type\"`\n}\n```\n\n```go\ntype TriggerResponse struct {\n\tEventID   string `json:\"event_id\"`\n\tEventType string `json:\"event_type\"`\n\t// Destinations is 0 when nothing is configured to receive the event, which\n\t// is worth surfacing: the trigger succeeded but nobody heard it.\n\tDestinations int `json:\"destinations\"`\n}\n```\n\n","path":"github.com/bachsdev/bachs-cli/internal/api","name":"api","synopsis":"Package api talks to the Bachs HTTP API.","isRedistributable":true}
