api

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRefreshTokenRejected = errors.New("refresh token rejected; please run 'taufinity auth login'")

ErrRefreshTokenRejected is returned by refreshToken when the server definitively rejects the refresh token (HTTP 401) — it is invalid, expired, or revoked. This is the ONLY condition under which getToken deletes the stored credentials and forces a re-login. Transient failures (network errors, 5xx) return a different (wrapped) error so credentials survive and the next invocation can retry.

Functions

This section is empty.

Types

type Client

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

Client is the Taufinity API client with retry/backoff and auth support.

func New

func New(baseURL string) *Client

New creates a new API client for the given base URL.

func (*Client) DeleteWithAuth

func (c *Client) DeleteWithAuth(ctx context.Context, path string) (*Response, error)

DeleteWithAuth performs an authenticated DELETE request.

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string) (*Response, error)

Get performs a GET request (always executed, even in dry-run).

func (*Client) GetWithAuth

func (c *Client) GetWithAuth(ctx context.Context, path string) (*Response, error)

GetWithAuth performs an authenticated GET request.

func (*Client) PostJSON

func (c *Client) PostJSON(ctx context.Context, path string, body any) (*Response, error)

PostJSON performs a POST request with JSON body.

func (*Client) PostJSONWithAuth

func (c *Client) PostJSONWithAuth(ctx context.Context, path string, body any) (*Response, error)

PostJSONWithAuth performs an authenticated POST request with JSON body.

func (*Client) PostMultipart

func (c *Client) PostMultipart(ctx context.Context, path string, body io.Reader, contentType string) (*Response, error)

PostMultipart performs an authenticated POST request with multipart form data.

func (*Client) RevokeAllRefreshTokens added in v0.4.0

func (c *Client) RevokeAllRefreshTokens() error

RevokeAllRefreshTokens revokes ALL of the authenticated user's CLI sessions ("log out everywhere"). Uses normal auth — getToken() auto-refreshes the access token first if it has expired, so this works after a long gap too.

func (*Client) RevokeRefreshToken added in v0.4.0

func (c *Client) RevokeRefreshToken(refreshToken string) error

RevokeRefreshToken revokes a single CLI refresh token server-side (logout). Unauthenticated: possession of the refresh token is the authorization. The refresh token travels in the body, so this works even when the access token has already expired. Best-effort — callers may ignore network errors.

func (*Client) SetAuth

func (c *Client) SetAuth(token string)

SetAuth sets an explicit auth token (overrides saved credentials).

func (*Client) SetDebug

func (c *Client) SetDebug(enabled bool)

SetDebug enables or disables debug request logging via a structured slog logger. When enabled, all HTTP requests and non-2xx responses are logged to stderr at Debug level.

func (*Client) SetDryRun

func (c *Client) SetDryRun(enabled bool)

SetDryRun enables or disables dry-run mode. In dry-run mode, non-GET requests are logged but not executed.

func (*Client) SetDryRunOutput

func (c *Client) SetDryRunOutput(w io.Writer)

SetDryRunOutput sets the writer for dry-run output.

func (*Client) SetOrg

func (c *Client) SetOrg(orgID string)

SetOrg sets the organization ID to include in requests.

func (*Client) Token added in v0.4.0

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

Token returns a usable access token, renewing it from the refresh token when it is expired or near expiry. This is the single public entry point for any "give me a usable access token" need (auth token, MCP config writers, the stdio bridge): it routes through the same renewing path as the authenticated request helpers, so every caller gets fresh, rotated tokens.

The ctx bounds the renewal HTTP call (including retry backoff), so a caller can cancel a slow refresh.

func (*Client) UploadFile

func (c *Client) UploadFile(ctx context.Context, path, filePath string) (*Response, error)

UploadFile performs a multipart file upload.

func (*Client) ValidateAuth

func (c *Client) ValidateAuth(ctx context.Context) error

ValidateAuth checks that a usable access token can be produced, renewing it from the refresh token if it is expired or near expiry. Call this before starting work to fail fast on auth issues.

It is a thin wrapper over the single renewing token path (getToken/Token): renewal — and the delete-on-definitive-401 behavior — lives in exactly one place. A still-valid (not near-expiry) token passes without a server round trip; a genuinely revoked token surfaces as a 401 on the first real request.

type Response

type Response struct {
	StatusCode int
	Headers    http.Header
	Body       []byte
}

Response wraps the HTTP response.

func (*Response) DecodeJSON

func (r *Response) DecodeJSON(v any) error

DecodeJSON decodes the response body as JSON.

func (*Response) Error

func (r *Response) Error() error

Error returns an error if the response is not successful.

func (*Response) IsSuccess

func (r *Response) IsSuccess() bool

IsSuccess returns true if the status code is 2xx.

Jump to

Keyboard shortcuts

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