api

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const BaseURLOverrideRequired = "override"
View Source
const BaseURLPlaceholder = "${baseURL}"
View Source
const DefaultBaseURL = "https://sovorem.am"

DefaultBaseURL is the production origin the CLI talks to. It is compiled into the binary on purpose: the endpoint is environment configuration, not user data, so it lives in code (shipped via releases) and is never persisted to a user's config file where a stale value could shadow it after an upgrade.

Variables

This section is empty.

Functions

func APIBaseURL

func APIBaseURL() string

APIBaseURL returns the origin used for /v1/* API requests, without a trailing slash. Precedence: --api-url flag > SOVOREM_API_URL env > built-in default.

func FrontendBaseURL

func FrontendBaseURL() string

FrontendBaseURL returns the origin used for the browser /cli/login page, without a trailing slash. Precedence: --api-url flag > SOVOREM_FRONTEND_URL env > built-in default.

func NormalizeBaseURL

func NormalizeBaseURL(raw string) (string, error)

NormalizeBaseURL validates that raw is an absolute http(s) origin and returns it without a trailing slash. http is intentionally allowed so local dev servers (e.g. http://localhost:3000) work.

func SetBaseOverride

func SetBaseOverride(raw string) error

SetBaseOverride validates raw and, when non-empty, makes it the base origin for both API requests and the browser login URL. An empty string is a no-op, so callers can pass an unset flag value safely.

func SubmitCLILesson

func SubmitCLILesson(uuid string, results []CLIStepResult, captureDebug bool) (LessonSubmissionEvent, SubmissionDebugData, error)

Types

type CLICommandJqOutput

type CLICommandJqOutput struct {
	Query   string
	Results []string
	Error   string
}

type CLICommandResult

type CLICommandResult struct {
	ExitCode     int
	FinalCommand string            `json:"-"`
	Command      CLIStepCLICommand `json:"-"`
	Stdout       string
	Variables    map[string]string
	JqOutputs    []CLICommandJqOutput `json:"-"`
}

type CLICommandTest

type CLICommandTest struct {
	ExitCode           *int          `yaml:"exitCode"`
	StdoutContainsAll  []string      `yaml:"stdoutContainsAll"`
	StdoutContainsNone []string      `yaml:"stdoutContainsNone"`
	StdoutLinesGt      *int          `yaml:"stdoutLinesGt"`
	StdoutJq           *StdoutJqTest `yaml:"stdoutJq"`
}

type CLIData

type CLIData struct {
	// ContainsCompleteDir     bool
	BaseURLDefault          string    `yaml:"baseURLDefault"`
	Steps                   []CLIStep `yaml:"steps"`
	AllowedOperatingSystems []string  `yaml:"allowedOperatingSystems"`
}

type CLIStep

type CLIStep struct {
	CLICommand      *CLIStepCLICommand  `yaml:"cliCommand"`
	HTTPRequest     *CLIStepHTTPRequest `yaml:"httpRequest"`
	NoPenaltyOnFail bool                `yaml:"noPenaltyOnFail"`
}

type CLIStepCLICommand

type CLIStepCLICommand struct {
	Command          string           `yaml:"command"`
	Tests            []CLICommandTest `yaml:"tests"`
	SleepAfterMs     *int             `yaml:"sleepAfterMs"`
	StdoutFilterTmdl *string          `yaml:"stdoutFilterTmdl"`
}

func (*CLIStepCLICommand) GetSleepAfterMs

func (c *CLIStepCLICommand) GetSleepAfterMs() *int

type CLIStepHTTPRequest

type CLIStepHTTPRequest struct {
	ResponseVariables       []HTTPRequestResponseVariable       `yaml:"responseVariables"`
	ResponseHeaderVariables []HTTPRequestResponseHeaderVariable `yaml:"responseHeaderVariables"`
	Tests                   []HTTPRequestTest                   `yaml:"tests"`
	Request                 HTTPRequest                         `yaml:"request"`
	SleepAfterMs            *int                                `yaml:"sleepAfterMs"`
}

func (*CLIStepHTTPRequest) GetSleepAfterMs

func (h *CLIStepHTTPRequest) GetSleepAfterMs() *int

type CLIStepResult

type CLIStepResult struct {
	CLICommandResult  *CLICommandResult
	HTTPRequestResult *HTTPRequestResult
}

type CurrentUserResponse

type CurrentUserResponse struct {
	Handle string `json:"handle"`
}

func FetchCurrentUser

func FetchCurrentUser() (*CurrentUserResponse, error)

type HTTPBasicAuth

type HTTPBasicAuth struct {
	Username string `yaml:"username"`
	Password string `yaml:"password"`
}

type HTTPRequest

type HTTPRequest struct {
	Method          string            `yaml:"method"`
	FullURL         string            `yaml:"fullURL"`
	Headers         map[string]string `yaml:"headers"`
	BodyJSON        map[string]any    `yaml:"bodyJSON"`
	BodyForm        map[string]string `yaml:"bodyForm"`
	FollowRedirects *bool             `yaml:"followRedirects"`

	BasicAuth *HTTPBasicAuth `yaml:"basicAuth"`
}

type HTTPRequestResponseHeaderVariable

type HTTPRequestResponseHeaderVariable struct {
	Name   string `yaml:"name"`
	Header string `yaml:"header"`
	Regex  string `yaml:"regex"`
}

type HTTPRequestResponseVariable

type HTTPRequestResponseVariable struct {
	Name      string `yaml:"name"`
	Path      string `yaml:"path"`
	BodyRegex string `yaml:"bodyRegex"`
}

type HTTPRequestResult

type HTTPRequestResult struct {
	Err              string `json:"-"`
	StatusCode       int
	ResponseHeaders  map[string]string
	ResponseTrailers map[string]string
	BodyString       string
	Variables        map[string]string
	Request          CLIStepHTTPRequest
}

type HTTPRequestTest

type HTTPRequestTest struct {
	StatusCode       *int                      `yaml:"statusCode"`
	BodyContains     *string                   `yaml:"bodyContains"`
	BodyContainsNone *string                   `yaml:"bodyContainsNone"`
	HeadersContain   *HTTPRequestTestHeader    `yaml:"headersContain"`
	TrailersContain  *HTTPRequestTestHeader    `yaml:"trailersContain"`
	JSONValue        *HTTPRequestTestJSONValue `yaml:"jsonValue"`
}

HTTPRequestTest should have only one field set

type HTTPRequestTestHeader

type HTTPRequestTestHeader struct {
	Key   string `yaml:"key"`
	Value string `yaml:"value"`
}

type HTTPRequestTestJSONValue

type HTTPRequestTestJSONValue struct {
	Path        string       `yaml:"path"`
	Operator    OperatorType `yaml:"operator"`
	IntValue    *int         `yaml:"intValue"`
	StringValue *string      `yaml:"stringValue"`
	BoolValue   *bool        `yaml:"boolValue"`
}

type JqExpectedResult

type JqExpectedResult struct {
	Type     JqValueType `yaml:"type"`
	Operator JqOperator  `yaml:"operator"`
	Value    any         `yaml:"value"`
}

type JqOperator

type JqOperator string // defined fully on backend

type JqValueType

type JqValueType string
const (
	JqTypeString JqValueType = "string"
	JqTypeInt    JqValueType = "int"
	JqTypeBool   JqValueType = "bool"
)

type Lesson

type Lesson struct {
	Lesson struct {
		Type          string
		LessonDataCLI *LessonDataCLI
	}
}

func FetchLesson

func FetchLesson(uuid string) (*Lesson, error)

type LessonDataCLI

type LessonDataCLI struct {
	// Readme  string
	CLIData CLIData
}

type LessonSubmissionEvent

type LessonSubmissionEvent struct {
	ResultSlug       VerificationResultSlug
	StructuredErrCLI *StructuredErrCLI
	XPReward         int
	XPBreakdown      []XPBreakdownItem
}

type LoginRequest

type LoginRequest struct {
	Otp string `json:"otp"`
}

type LoginResponse

type LoginResponse struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
}

func FetchAccessToken

func FetchAccessToken() (*LoginResponse, error)

func LoginWithCode

func LoginWithCode(code string) (*LoginResponse, error)

type OperatorType

type OperatorType string
const (
	OpEquals      OperatorType = "eq"
	OpGreaterThan OperatorType = "gt"
	OpContains    OperatorType = "contains"
	OpNotContains OperatorType = "not_contains"
)

type Sleepable

type Sleepable interface {
	GetSleepAfterMs() *int
}

type StdoutJqTest

type StdoutJqTest struct {
	InputMode       string             `yaml:"inputMode"` // "json" or "jsonl"
	Query           string             `yaml:"query"`
	ExpectedResults []JqExpectedResult `yaml:"expectedResults"`
}

type StructuredErrCLI

type StructuredErrCLI struct {
	ErrorMessage    string `json:"Error"`
	FailedStepIndex int    `json:"FailedStepIndex"`
	FailedTestIndex int    `json:"FailedTestIndex"`
}

type SubmissionDebugData

type SubmissionDebugData struct {
	Endpoint           string
	RequestBody        string
	ResponseStatusCode int
	ResponseBody       string
}

type VerificationResultSlug

type VerificationResultSlug string
const (
	// "noop" is for "noPenaltyOnFail" on the CLI type
	VerificationResultSlugNoop        VerificationResultSlug = "noop"
	VerificationResultSlugSystemError VerificationResultSlug = "system-error"
	VerificationResultSlugSuccess     VerificationResultSlug = "success"
	VerificationResultSlugFailure     VerificationResultSlug = "failure"
)

type XPBreakdownItem

type XPBreakdownItem struct {
	Name    string
	Percent float64
	XP      int
}

Jump to

Keyboard shortcuts

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