api

package
v0.27.6 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package api is Timeclock's HTTP API, defined with huma. Its OpenAPI document is served at /api/openapi.json.

Index

Constants

View Source
const Prefix = "/api/v1"

Prefix is the path prefix of every versioned operation.

Variables

This section is empty.

Functions

func Config

func Config() huma.Config

Config returns huma's configuration for the API.

func New

func New(mux *http.ServeMux, deps Deps) huma.API

New registers every operation on mux and returns the huma API.

func WithCaller

func WithCaller(ctx context.Context, id string) context.Context

WithCaller returns ctx carrying the id of the host user making a request.

func WithWorkspace added in v0.4.0

func WithWorkspace(ctx context.Context, id uuid.UUID) context.Context

WithWorkspace returns ctx carrying the workspace a request is in.

Types

type CalendarEvent added in v0.21.0

type CalendarEvent struct {
	ID        string    `json:"id"`
	Title     string    `json:"title" doc:"Empty for an event without one."`
	Link      string    `json:"link,omitempty" format:"uri" doc:"Opens the event in Google Calendar."`
	StartedAt time.Time `json:"startedAt"`
	EndedAt   time.Time `json:"endedAt"`
	// Meeting names the event wherever it comes round: its series, or a
	// one-off's title. Empty for an untitled one-off, which isn't remembered.
	Meeting string `json:"meeting,omitempty" doc:"Names the event wherever it comes round, for remembering its project."`
	// Remembered is a meeting the caller has copied before: copies go to
	// ProjectID at once.
	Remembered bool       `json:"remembered" doc:"The caller chose a project for this meeting before: copies go straight to it."`
	ProjectID  *uuid.UUID `json:"projectId,omitempty" doc:"The remembered project; absent with remembered is no project."`
}

CalendarEvent is an event on the caller's calendar, which the week offers as time to add.

type Deps

type Deps struct {
	Toggl     *clock.Toggl
	Clock     *clock.Service
	Directory host.Directory
	// Calendar reads a person's Google Calendar for them; nil reads none.
	Calendar GoogleCalendar
	// Google is the calendars people connect themselves; nil when they can't.
	Google *clock.GoogleCalendars
	// BasePath is where the web app is, for the browser to come back to.
	BasePath string
	Info     Info
	// HostTheme is the host application's look, which a workspace's own overrides.
	HostTheme host.Theme
}

Deps are what the operations need.

type GoogleCalendar added in v0.21.0

type GoogleCalendar func(ctx context.Context, p host.Person) (ts oauth2.TokenSource, ok bool, err error)

GoogleCalendar returns credentials to read a person's Google Calendar, or ok false when they have none.

type Info

type Info struct {
	// HomeURL and HomeLabel link back to the host, when there is one.
	HomeURL   string `json:"homeUrl,omitempty"`
	HomeLabel string `json:"homeLabel,omitempty"`
	// SignInURL is where a signed-out browser goes to sign in; the web app
	// appends the URL-encoded path to come back to.
	SignInURL string `json:"signInUrl,omitempty"`
	// SignOutURL is the same-origin endpoint that ends the session; the web
	// app POSTs to it. Empty offers no sign-out.
	SignOutURL string `json:"signOutUrl,omitempty"`
	// AccountsURL is where a standalone server manages its own accounts:
	// the workspaces to switch between, invitations and passwords. Empty
	// when a host application has its own users.
	AccountsURL string `json:"accountsUrl,omitempty"`
	// APIKeysURL is where a person creates an API key for the CLI, when the
	// host signs it in with one instead of through the browser.
	APIKeysURL string `json:"apiKeysUrl,omitempty" format:"uri"`
	// Calendar is whether the week can show the caller's Google Calendar
	// events beside their time.
	Calendar bool `json:"calendar,omitempty"`
	// CalendarConnect is whether people can connect their own Google
	// Calendar, where the host doesn't read it for them.
	CalendarConnect bool `json:"calendarConnect,omitempty"`
	// ThemeStorageKey is the localStorage key holding the host's light,
	// dark or system choice, so Timeclock matches it.
	ThemeStorageKey string `json:"themeStorageKey,omitempty"`
	// Theme is the look to use: the workspace's where an admin set one, the
	// host's otherwise. A missing scheme is Timeclock's own.
	Theme host.Theme `json:"theme"`
	// WorkspaceTheme is what an admin set, for the settings page to edit.
	WorkspaceTheme host.Theme `json:"workspaceTheme"`
}

Info is what the web app needs to know about where it runs.

Jump to

Keyboard shortcuts

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