api

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HintForHTTPStatus added in v1.1.0

func HintForHTTPStatus(statusCode int) string

HintForHTTPStatus returns an actionable hint for a known HTTP status code.

func HintForItemError added in v1.1.0

func HintForItemError(code string) string

HintForItemError returns an actionable hint for a known ItemError error_code.

func HintForMessage added in v1.1.0

func HintForMessage(msg string) string

HintForMessage returns an actionable hint by pattern-matching against the error message. This is used as a fallback for vague API errors that lack structured error codes.

func HintForPublishStatus added in v1.1.0

func HintForPublishStatus(statusCode string) string

HintForPublishStatus returns an actionable hint for a known publish status code.

func ParseAPIError

func ParseAPIError(body []byte) string

ParseAPIError attempts to extract a human-readable error from a Google API error response. Returns an empty string if the body is not a recognized error format.

func ResolveHint added in v1.1.0

func ResolveHint(errorCode string, httpStatus int, message string) string

ResolveHint tries all hint sources in priority order and returns the first match.

Types

type APIError

type APIError struct {
	Error *APIErrorBody `json:"error,omitempty"`
}

APIError represents a Google API error response.

type APIErrorBody

type APIErrorBody struct {
	Code    int              `json:"code"`
	Message string           `json:"message"`
	Status  string           `json:"status"`
	Details []APIErrorDetail `json:"details,omitempty"`
}

APIErrorBody represents the body of a Google API error.

type APIErrorDetail

type APIErrorDetail struct {
	Type            string           `json:"@type"`
	Reason          string           `json:"reason,omitempty"`
	FieldViolations []FieldViolation `json:"fieldViolations,omitempty"`
}

APIErrorDetail represents a detail entry in a Google API error.

type CWSError added in v1.1.0

type CWSError struct {
	Operation  string        // "upload", "publish", "status", "rollout", "cancel"
	HTTPStatus int           // HTTP status code from the API response
	Message    string        // original API error message, preserved verbatim
	Code       string        // primary error code (e.g., "PKG_INVALID_VERSION_NUMBER")
	Hint       string        // actionable suggestion for the user
	Details    []ErrorDetail // all errors when multiple ItemErrors are present
}

CWSError is a structured error returned by Chrome Web Store API operations. It preserves the original API message and attaches an actionable hint when possible.

func NewCWSError added in v1.1.0

func NewCWSError(operation string, httpStatus int, itemErrors []ItemError, fallbackMsg string) *CWSError

NewCWSError creates a CWSError from an operation, HTTP status, and ItemError list.

func (*CWSError) Error added in v1.1.0

func (e *CWSError) Error() string

type CancelResponse

type CancelResponse struct {
	Status string `json:"status,omitempty"`
}

CancelResponse represents the response from cancelSubmission.

type Client

type Client struct {
	BaseURL string // override for testing; empty uses default
	// contains filtered or unexported fields
}

Client is the Chrome Web Store API V2 client.

func NewClient

func NewClient(authenticator auth.Authenticator, publisherID string) *Client

NewClient creates a new API client.

func (*Client) CancelSubmission

func (c *Client) CancelSubmission(ctx context.Context, extensionID string) (*CancelResponse, error)

CancelSubmission cancels a pending submission.

func (*Client) FetchStatus

func (c *Client) FetchStatus(ctx context.Context, extensionID string) (*StatusResponse, []byte, error)

FetchStatus retrieves the current status of an extension.

func (*Client) Publish

func (c *Client) Publish(ctx context.Context, extensionID string, staged bool) (*PublishResponse, error)

Publish publishes the most recently uploaded version.

func (*Client) SetDeployPercentage

func (c *Client) SetDeployPercentage(ctx context.Context, extensionID string, percentage int) (*DeployPercentageResponse, error)

SetDeployPercentage sets the deploy percentage for a published extension.

func (*Client) Upload

func (c *Client) Upload(ctx context.Context, extensionID string, zipData []byte) (*UploadResponse, error)

Upload uploads a zip file to the Chrome Web Store.

type DeployPercentageRequest

type DeployPercentageRequest struct {
	DeployPercentage int `json:"deployPercentage"`
}

DeployPercentageRequest represents the request body for setPublishedDeployPercentage.

type DeployPercentageResponse

type DeployPercentageResponse struct {
	DeployPercentage int    `json:"deployPercentage"`
	Status           string `json:"status,omitempty"`
}

DeployPercentageResponse represents the response from setPublishedDeployPercentage.

type DistributionChannel

type DistributionChannel struct {
	DeployPercentage int    `json:"deployPercentage"`
	CrxVersion       string `json:"crxVersion"`
}

DistributionChannel represents a distribution channel for a published extension.

type ErrorDetail added in v1.1.0

type ErrorDetail struct {
	Code   string
	Detail string
	Hint   string
}

ErrorDetail represents a single error entry from an ItemError array.

type FieldViolation

type FieldViolation struct {
	Field       string `json:"field"`
	Description string `json:"description"`
	Reason      string `json:"reason,omitempty"`
}

FieldViolation represents a field-level error.

type ItemError

type ItemError struct {
	ErrorCode   string `json:"error_code"`
	ErrorDetail string `json:"error_detail"`
}

ItemError represents an error returned by the API.

type ItemRevisionStatus

type ItemRevisionStatus struct {
	State                string                `json:"state"`
	CrxVersion           string                `json:"crxVersion,omitempty"`
	DistributionChannels []DistributionChannel `json:"distributionChannels,omitempty"`
}

ItemRevisionStatus represents the status of an item revision (published, in-review, or draft).

type ParsedAPIError added in v1.1.0

type ParsedAPIError struct {
	Message     string   // top-level error message
	StatusCode  int      // HTTP-like code from the error body
	Status      string   // status string (e.g., "INVALID_ARGUMENT")
	Reasons     []string // reason codes from field violations (e.g., "PKG_INVALID_VERSION_NUMBER")
	Description string   // most specific description found
}

ParsedAPIError holds structured information extracted from a Google API error response.

func ParseAPIErrorDetail added in v1.1.0

func ParseAPIErrorDetail(body []byte) *ParsedAPIError

ParseAPIErrorDetail extracts structured error information from a Google API error response. Returns nil if the body is not a recognized error format.

type PublishRequest

type PublishRequest struct {
	PublishType string `json:"publishType,omitempty"`
}

PublishRequest represents the request body for the publish endpoint.

type PublishResponse

type PublishResponse struct {
	Status     []string `json:"status"`
	StatusCode string   `json:"statusCode,omitempty"`
}

PublishResponse represents the response from the publish endpoint.

type StatusResponse

type StatusResponse struct {
	Name                        string              `json:"name"`
	ItemID                      string              `json:"itemId"`
	PublishedItemRevisionStatus *ItemRevisionStatus `json:"publishedItemRevisionStatus,omitempty"`
	SubmittedItemRevisionStatus *ItemRevisionStatus `json:"submittedItemRevisionStatus,omitempty"`
	LastAsyncUploadState        string              `json:"lastAsyncUploadState,omitempty"`
	ItemError                   []ItemError         `json:"itemError,omitempty"`
}

StatusResponse represents the response from the fetchStatus endpoint (V2 API).

type UploadResponse

type UploadResponse struct {
	ID          string      `json:"id"`
	UploadState string      `json:"uploadState"`
	ItemError   []ItemError `json:"itemError,omitempty"`
}

UploadResponse represents the response from the upload endpoint.

Jump to

Keyboard shortcuts

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