api

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package api is a thin, typed client over the panel's management API (/api/v1). It carries the bearer token and refreshes it transparently when it is about to expire.

Index

Constants

View Source
const (
	KindPublic = "public"
	KindSecret = "secret"
)

Write-key kinds (non-negotiable #12): public keys identify the project in the browser; secret keys are backend-only.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIKey

type APIKey struct {
	ID        int    `json:"id"`
	Kind      string `json:"kind"`
	Label     string `json:"label"`
	Key       string `json:"key"`
	CreatedAt string `json:"created_at"`
}

APIKey is a project write key. Key is masked on list, full on create.

type Catalog

type Catalog struct {
	Events []struct {
		Name  string `json:"name"`
		Count int    `json:"count"`
	} `json:"events"`
	Properties []struct {
		Key   string `json:"key"`
		Count int    `json:"count"`
	} `json:"properties"`
}

Catalog is the observed event names and property keys for a project.

type Client

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

Client talks to one panel as one signed-in user.

func New

func New(creds *config.Credentials) *Client

New builds a client around stored credentials.

func (*Client) Catalog

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

Catalog returns the observed event names and property keys for a project.

func (*Client) Context

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

Context returns the active team + project.

func (*Client) CreateKey

func (c *Client) CreateKey(ctx context.Context, projectID, kind, label string) (*APIKey, error)

CreateKey mints a write key. The full value is only ever returned here.

func (*Client) CreateProject

func (c *Client) CreateProject(ctx context.Context, teamID int, name, timezone string) (*Project, error)

CreateProject creates a project inside a team.

func (*Client) Events

func (c *Client) Events(ctx context.Context, projectID string, filters url.Values) (*EventsPage, error)

Events returns recent events for a project, newest first.

func (*Client) Keys

func (c *Client) Keys(ctx context.Context, projectID string) ([]APIKey, error)

Keys lists a project's active write keys (secret keys are masked).

func (*Client) Project

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

Project returns one project.

func (*Client) Projects

func (c *Client) Projects(ctx context.Context, teamID int) ([]Project, error)

Projects lists the projects of a team.

func (*Client) SwitchProject

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

SwitchProject sets the active project (and pulls its team along).

func (*Client) SwitchTeam

func (c *Client) SwitchTeam(ctx context.Context, teamID int) (*Context, error)

SwitchTeam sets the active team.

func (*Client) Teams

func (c *Client) Teams(ctx context.Context) ([]Team, error)

Teams lists the user's teams.

func (*Client) Whoami

func (c *Client) Whoami(ctx context.Context) (*User, error)

Whoami returns the signed-in account and its current context.

type Context

type Context struct {
	Team    *Team    `json:"team"`
	Project *Project `json:"project"`
}

Context is the active team + project pair.

type Event

type Event struct {
	UUID             string `json:"uuid"`
	Event            string `json:"event"`
	DistinctID       string `json:"distinct_id"`
	PersonID         string `json:"person_id"`
	Properties       string `json:"properties"`
	Verified         int    `json:"verified"`
	VerificationMode string `json:"verification_mode"`
	Timestamp        string `json:"timestamp"`
}

Event is one row from the events explorer.

type EventsPage

type EventsPage struct {
	Events  []Event `json:"events"`
	Page    int     `json:"page"`
	PerPage int     `json:"perPage"`
	HasMore bool    `json:"hasMore"`
}

EventsPage is the paginated events response.

type Project

type Project struct {
	ID                       string `json:"id"`
	Name                     string `json:"name"`
	TeamID                   int    `json:"team_id"`
	Timezone                 string `json:"timezone"`
	IdentityVerificationMode string `json:"identity_verification_mode"`
	PublicKey                string `json:"public_key"`
	CreatedAt                string `json:"created_at"`
}

Project carries the summary fields the API returns. current_project on the user/context payloads only fills ID and Name; the project endpoints fill the rest.

type Team

type Team struct {
	ID         int    `json:"id"`
	Name       string `json:"name"`
	Slug       string `json:"slug"`
	IsPersonal bool   `json:"isPersonal"`
	Role       string `json:"role"`
	RoleLabel  string `json:"roleLabel"`
	IsCurrent  bool   `json:"isCurrent"`
}

Team mirrors the panel's UserTeam DTO (camelCase keys, straight from response()->json).

type User

type User struct {
	ID             int      `json:"id"`
	Name           string   `json:"name"`
	Email          string   `json:"email"`
	CurrentTeam    *Team    `json:"current_team"`
	CurrentProject *Project `json:"current_project"`
}

User is the whoami payload.

Jump to

Keyboard shortcuts

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