api

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Caller

type Caller struct {
	// APIKey is the legacy "pk_xxx:sk_xxx" form, retained for tests and
	// callers that want to inspect a single string. New code should rely
	// on PublicKey/SecretKey/BearerToken instead.
	APIKey string

	PublicKey   string
	SecretKey   string
	BearerToken string

	// OrgID is the organization UUID recorded on the profile the bearer
	// token came from. Sent as X-Org-Id so org-scoped routes (api-keys,
	// marketplace) can resolve the caller's org, mirroring internal/client.
	OrgID string

	BaseURL string
	// contains filtered or unexported fields
}

Caller makes raw HTTP requests to the API for endpoints where the SDK does not decode response bodies. It carries the active profile so it can transparently refresh OAuth tokens on 401 responses.

For api-key profiles the Caller stores the public/secret key pair and emits dual headers (X-PromptVM-Public-Key + X-PromptVM-Secret-Key) on each request. For OAuth profiles only BearerToken is set, sent as Authorization: Bearer <token>.

func AnonymousFromContext added in v0.6.0

func AnonymousFromContext(cmd *cobra.Command) *Caller

AnonymousFromContext creates a Caller for public, unauthenticated endpoints (e.g. GET /api/v1/skills/s/:slug). Unlike NewFromContext it never errors when no credentials are present — the public routes accept anonymous requests.

Base-URL resolution still honors --base-url, then PROMPTVM_BASE_URL, then the active profile's baseUrl, then the default. If credentials happen to be available (flags, env, or an active profile) they are attached best-effort so authenticated callers keep working; a credential-resolution failure is ignored and the request proceeds anonymously.

func NewFromContext

func NewFromContext(cmd *cobra.Command) (*Caller, error)

NewFromContext creates a Caller from CLI flags, environment, and the active config profile.

Credential resolution mirrors internal/client.ResolveCredentials so the SDK and the raw HTTP path always agree on which key set to use.

func (*Caller) Delete

func (c *Caller) Delete(path string, result interface{}) error

Delete performs a DELETE request.

func (*Caller) Get

func (c *Caller) Get(path string, result interface{}) error

Get performs a GET request and decodes JSON into result.

func (*Caller) GetWithContext added in v0.6.0

func (c *Caller) GetWithContext(ctx context.Context, path string, result interface{}) error

GetWithContext performs a GET using the supplied context (so callers control the request timeout) and decodes JSON into result. On a >= 400 response it returns a *StatusError; on a transport failure it returns the underlying error so callers can distinguish "not found" from "could not connect".

It does not auto-refresh OAuth tokens — it is intended for public endpoints reachable anonymously; if credentials are attached they ride along but a 401 is surfaced as a StatusError rather than triggering a refresh.

func (*Caller) Patch

func (c *Caller) Patch(path string, body interface{}, result interface{}) error

Patch performs a PATCH request with a JSON body.

func (*Caller) Post

func (c *Caller) Post(path string, body interface{}, result interface{}) error

Post performs a POST request with a JSON body.

func (*Caller) PostBestEffort added in v0.6.0

func (c *Caller) PostBestEffort(ctx context.Context, path string, body interface{}) error

PostBestEffort performs a fire-and-forget POST with the supplied context. It is used for non-critical side effects (e.g. the install counter): any transport error or >= 400 response is returned for optional logging, never to fail the caller's primary operation.

type StatusError added in v0.6.0

type StatusError struct {
	StatusCode int
	Body       string
}

StatusError is returned by GetWithContext when the server responds with a status >= 400. It carries the HTTP status code so callers can map specific statuses (e.g. 404) to tailored, user-facing messages.

func (*StatusError) Error added in v0.6.0

func (e *StatusError) Error() string

Jump to

Keyboard shortcuts

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