dashboard

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const PlanTypeFree = "free"

PlanTypeFree is the attributes.type value that identifies the free-tier plan template. The free plan's configuration.plan id is not fixed (it can be "build"), so the CLI keys off this type rather than a hard-coded id when it needs to map the user-facing "free" choice to a concrete plan.

Variables

View Source
var (
	DefaultDashboardURL = "https://dashboard.algolia.com"
	DefaultAPIURL       = "https://api.dashboard.algolia.com"
	DefaultOAuthScope   = "public applications:manage keys:manage"
)

Production defaults; overridable via ldflags or ALGOLIA_DASHBOARD_URL / ALGOLIA_API_URL / ALGOLIA_OAUTH_SCOPE env vars.

View Source
var ErrSessionExpired = errors.New("session expired")

ErrSessionExpired is returned when an API call gets a 401 Unauthorized.

View Source
var WriteACL = []string{
	"search", "browse", "seeUnretrievableAttributes", "listIndexes",
	"analytics", "logs", "addObject", "deleteObject", "deleteIndex",
	"settings", "editSettings", "recommendation",
}

WriteACL is the set of permissions for API keys created by the CLI.

Functions

This section is empty.

Types

type APIKeyAttributes

type APIKeyAttributes struct {
	Value string `json:"value"`
}

APIKeyAttributes contains the actual API key fields.

type APIKeyResource

type APIKeyResource struct {
	ID         string           `json:"id"`
	Type       string           `json:"type"`
	Attributes APIKeyAttributes `json:"attributes"`
}

APIKeyResource is a JSON:API resource wrapper for an API key.

type Application

type Application struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	APIKey    string `json:"api_key,omitempty"`
	PlanLabel string `json:"plan_label,omitempty"` // current plan label, e.g. "Grow Plus"
}

Application is a flattened view of an Algolia application for CLI consumption.

type ApplicationAttributes

type ApplicationAttributes struct {
	Name          string          `json:"name"`
	ApplicationID string          `json:"application_id"`
	APIKey        string          `json:"api_key"`
	Plan          ApplicationPlan `json:"plan"`
}

ApplicationAttributes contains the actual application fields.

type ApplicationPlan added in v1.11.0

type ApplicationPlan struct {
	Name       string `json:"name"`
	Label      string `json:"label"`
	Version    int    `json:"version"`
	PayAsYouGo bool   `json:"pay_as_you_go"`
}

ApplicationPlan is the plan applied to an application (attributes.plan). Label (e.g. "Grow Plus") matches a self-serve plan template's Name.

type ApplicationResource

type ApplicationResource struct {
	ID         string                `json:"id"`
	Type       string                `json:"type"`
	Attributes ApplicationAttributes `json:"attributes"`
}

ApplicationResource is a JSON:API resource wrapper for an application.

type ApplicationsResponse

type ApplicationsResponse struct {
	Data  []ApplicationResource `json:"data"`
	Meta  PaginationMeta        `json:"meta"`
	Links PaginationLinks       `json:"links"`
}

ApplicationsResponse is the JSON:API response from GET /1/applications.

type ChangePlanRequest added in v1.11.0

type ChangePlanRequest struct {
	Plan string `json:"plan"`
}

ChangePlanRequest is the payload for PATCH /1/applications/{id}/plan/self-serve.

Every request body in this client is a plain JSON object (see CreateApplicationRequest and UpdateApplicationRequest) rather than a JSON:API data.attributes envelope, so we mirror that existing convention here.

type Client

type Client struct {
	DashboardURL string
	APIURL       string
	OAuthScope   string
	ClientID     string
	// contains filtered or unexported fields
}

Client interacts with the Algolia Dashboard OAuth endpoint and the Public API.

func NewClient

func NewClient(clientID string) *Client

NewClient creates a new dashboard client with the given OAuth client ID. Respects ALGOLIA_DASHBOARD_URL, ALGOLIA_API_URL, and ALGOLIA_OAUTH_SCOPE environment variables, falling back to the compiled-in defaults (set via ldflags).

func NewClientWithHTTPClient

func NewClientWithHTTPClient(clientID string, httpClient *http.Client) *Client

NewClientWithHTTPClient creates a new dashboard client with a custom HTTP client. Used primarily in tests; callers must set DashboardURL and APIURL explicitly.

func (*Client) AuthorizationCodeGrant

func (c *Client) AuthorizationCodeGrant(
	code, codeVerifier, redirectURI string,
) (*OAuthTokenResponse, error)

AuthorizationCodeGrant exchanges an authorization code + PKCE code_verifier for an access token. The redirectURI must match the one used in the authorize URL.

func (*Client) AuthorizeURL

func (c *Client) AuthorizeURL(codeChallenge, redirectURI string) string

AuthorizeURL builds the OAuth 2.0 authorization URL for the browser-based sign-in flow.

func (*Client) ChangeApplicationPlan added in v1.11.0

func (c *Client) ChangeApplicationPlan(accessToken, appID, plan string) (*Application, error)

ChangeApplicationPlan changes the plan of an application

func (*Client) CreateAPIKey

func (c *Client) CreateAPIKey(
	accessToken, appID string,
	acl []string,
	description string,
) (string, error)

CreateAPIKey creates a new API key with the given ACL for the specified application.

func (*Client) CreateApplication

func (c *Client) CreateApplication(accessToken, region, name string) (*Application, error)

CreateApplication creates a new application for the authenticated user.

func (*Client) GetApplication

func (c *Client) GetApplication(accessToken, appID string) (*Application, error)

GetApplication returns a single application by its ID.

func (*Client) GetCrawlerUser added in v1.8.3

func (c *Client) GetCrawlerUser(accessToken string) (*DashboardCrawlerUserData, error)

GetCrawlerUser gets the crawler API user data for the current authenticated user

func (*Client) GetSelfServePlans added in v1.11.0

func (c *Client) GetSelfServePlans(accessToken string) ([]Plan, error)

GetSelfServePlans returns the available plans

func (*Client) GetUser added in v1.11.0

func (c *Client) GetUser(accessToken string) (*DashboardUser, error)

GetUser returns account-level information for the authenticated user

func (*Client) ListApplications

func (c *Client) ListApplications(accessToken string) ([]Application, error)

ListApplications returns all applications for the authenticated user, following pagination to fetch every page.

func (*Client) ListRegions

func (c *Client) ListRegions(accessToken string) ([]Region, error)

ListRegions returns the allowed hosting regions for application creation.

func (*Client) RefreshToken

func (c *Client) RefreshToken(refreshToken string) (*OAuthTokenResponse, error)

RefreshToken uses a refresh token to obtain a new access token.

func (*Client) RevokeToken

func (c *Client) RevokeToken(token string) error

RevokeToken revokes an OAuth access or refresh token via POST /2/oauth/revoke.

func (*Client) SignupAuthorizeURL

func (c *Client) SignupAuthorizeURL(codeChallenge, redirectURI string) string

SignupAuthorizeURL builds an OAuth 2.0 authorization URL that opens the sign-up page instead of the default sign-in page.

func (*Client) UpdateApplication added in v1.11.0

func (c *Client) UpdateApplication(accessToken, appID, name string) (*Application, error)

UpdateApplication renames an existing application.

type CreateAPIKeyRequest

type CreateAPIKeyRequest struct {
	ACL         []string `json:"acl"`
	Description string   `json:"description"`
}

CreateAPIKeyRequest is the payload for POST /1/applications/{application_id}/api-keys.

type CreateAPIKeyResponse

type CreateAPIKeyResponse struct {
	Data APIKeyResource `json:"data"`
}

CreateAPIKeyResponse is the JSON:API response from POST /1/applications/{application_id}/api-keys.

type CreateApplicationRequest

type CreateApplicationRequest struct {
	RegionCode string `json:"region_code"`
	Name       string `json:"name"`
}

CreateApplicationRequest is the payload for POST /1/applications.

type DashboardCrawlerError added in v1.8.3

type DashboardCrawlerError struct {
	Status string  `json:"status"`
	Title  string  `json:"title"`
	Detail *string `json:"detail"`
}

type DashboardCrawlerErrorResponse added in v1.8.3

type DashboardCrawlerErrorResponse struct {
	Errors []DashboardCrawlerError `json:"errors"`
}

type DashboardCrawlerUserData added in v1.8.3

type DashboardCrawlerUserData struct {
	ID     string `json:"id"`
	Email  string `json:"email"`
	Name   string `json:"name"`
	APIKey string `json:"apiKey"`
}

DashboardCrawlerUserData contains the user information from the crawler API

type DashboardCrawlerUserResponse added in v1.8.3

type DashboardCrawlerUserResponse struct {
	Data DashboardCrawlerUserData `json:"data"`
}

DashboardCrawlerUserResponse is the JSON:API response from GET /1/crawler/user

type DashboardUser added in v1.11.0

type DashboardUser struct {
	HasPaymentMethod bool `json:"has_payment_method"`
}

DashboardUser is a flattened view of the authenticated user's account info from GET /1/user, exposing only what plan changes need.

type ErrClusterUnavailable

type ErrClusterUnavailable struct {
	Region  string
	Message string
}

ErrClusterUnavailable is returned when a region has no available cluster.

func (*ErrClusterUnavailable) Error

func (e *ErrClusterUnavailable) Error() string

type OAuthErrorResponse

type OAuthErrorResponse struct {
	Error            string `json:"error"`
	ErrorDescription string `json:"error_description"`
}

OAuthErrorResponse is the error format from the OAuth endpoints.

type OAuthTokenResponse

type OAuthTokenResponse struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	TokenType    string `json:"token_type"`
	ExpiresIn    int    `json:"expires_in"`
	Scope        string `json:"scope"`
	CreatedAt    int64  `json:"created_at"`
	User         *User  `json:"user,omitempty"`
}

OAuthTokenResponse is the response from POST /2/oauth/token.

type PaginationLinks struct {
	First string `json:"first"`
	Last  string `json:"last"`
	Prev  string `json:"prev"`
	Next  string `json:"next"`
}

PaginationLinks contains pagination URLs.

type PaginationMeta added in v1.8.1

type PaginationMeta struct {
	TotalCount  int `json:"total_count"`
	PerPage     int `json:"per_page"`
	CurrentPage int `json:"current_page"`
	TotalPages  int `json:"total_pages"`
}

PaginationMeta contains page-based pagination metadata.

type Plan added in v1.11.0

type Plan struct {
	ID          string `json:"id"`           // configuration.plan (e.g. "build", "grow", "grow-plus")
	Name        string `json:"name"`         // human-readable name (e.g. "Grow Plus")
	Description string `json:"description"`  // short description
	Type        string `json:"type"`         // "free" or "freeform"
	Price       string `json:"price"`        // "Free" for the free plan, otherwise the freeform pricing string
	AcceptTerms string `json:"accept_terms"` // ToS text shown before changing the plan
}

Plan is a flattened, CLI-friendly view of a self-serve plan template.

func (Plan) IsFree added in v1.11.0

func (p Plan) IsFree() bool

IsFree reports whether the plan is the free-tier plan (no payment method required).

type PlanTemplateAttributes added in v1.11.0

type PlanTemplateAttributes struct {
	Name          string                    `json:"name"`
	Description   string                    `json:"description"`
	Type          string                    `json:"type"`               // e.g. "free" or "freeform"
	Freeform      string                    `json:"freeform,omitempty"` // pricing string for paygo plans
	Configuration PlanTemplateConfiguration `json:"configuration"`
}

PlanTemplateAttributes contains the actual plan template fields.

type PlanTemplateConfiguration added in v1.11.0

type PlanTemplateConfiguration struct {
	Plan        string `json:"plan"`
	AcceptTerms string `json:"accept_terms"`
}

PlanTemplateConfiguration holds the plan identifier and the terms text.

type PlanTemplateResource added in v1.11.0

type PlanTemplateResource struct {
	ID         string                 `json:"id"`
	Type       string                 `json:"type"`
	Attributes PlanTemplateAttributes `json:"attributes"`
}

PlanTemplateResource is a JSON:API resource wrapper for a self-serve plan template.

type PlanTemplatesResponse added in v1.11.0

type PlanTemplatesResponse struct {
	Data []PlanTemplateResource `json:"data"`
}

PlanTemplatesResponse is the JSON:API response from GET /1/plan-templates/self-serve.

type Region

type Region struct {
	Code string `json:"code"`
	Name string `json:"name"`
}

Region represents a hosting region from GET /1/hosting/regions.

type RegionsResponse

type RegionsResponse struct {
	RegionCodes []Region `json:"region_codes"`
}

RegionsResponse is the response from GET /1/hosting/regions.

type SingleApplicationResponse

type SingleApplicationResponse struct {
	Data ApplicationResource `json:"data"`
}

SingleApplicationResponse is the JSON:API response from GET /1/application/:id.

type UpdateApplicationRequest added in v1.11.0

type UpdateApplicationRequest struct {
	Name string `json:"name"`
}

UpdateApplicationRequest is the payload for PATCH /1/applications/{id}.

type User

type User struct {
	ID        int    `json:"id"`
	Email     string `json:"email"`
	Name      string `json:"name"`
	AvatarURL string `json:"avatar_url"`
}

User represents the authenticated user from the OAuth token response.

Jump to

Keyboard shortcuts

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