Documentation
¶
Index ¶
- Constants
- Variables
- func IsMonthlyLimitMessage(message string) bool
- type APIError
- type AuthenticationError
- type AuthorizationError
- type Client
- type ClientConfig
- type ConnectionAPIKey
- type ConnectionResult
- type ConnectionWorkspace
- type DeliveryUrgency
- type Event
- type HTTPDoer
- type NetworkError
- type NotFoundError
- type NotificationLevel
- type RateLimitError
- type SendEventRequest
- type SendEventResult
- type TimeoutError
- type ValidationError
- type ValidationErrors
Constants ¶
const ( // Version is the SDK release version. Version = "1.0.0" // DefaultBaseURL is the production API base URL. DefaultBaseURL = "https://api.trigv.com/api" // DefaultTimeout is the default HTTP client timeout. DefaultTimeout = 30 // DefaultMaxRetries is the default number of retries for retryable errors. DefaultMaxRetries = 2 )
Variables ¶
var ( ErrValidation = errors.New("trigv: validation error") ErrAuthentication = errors.New("trigv: authentication error") ErrAuthorization = errors.New("trigv: authorization error") ErrNotFound = errors.New("trigv: not found") ErrRateLimit = errors.New("trigv: rate limit") ErrAPI = errors.New("trigv: api error") ErrNetwork = errors.New("trigv: network error") ErrTimeout = errors.New("trigv: timeout") )
Sentinel errors for errors.Is matching.
var DeliveryUrgencies = []string{"standard", "time_sensitive"}
DeliveryUrgency values accepted by the ingest API.
var FieldMaxLengths = map[string]int{
"channel": 120,
"title": 255,
"description": 1000,
"image_url": 2048,
"url": 2048,
"event_type": 120,
"idempotency_key": 190,
}
FieldMaxLengths mirrors API contract limits.
var Levels = []string{"info", "success", "warning", "error"}
Notification levels accepted by the ingest API.
var ProhibitedFields = []string{"api_key", "icon"}
ProhibitedFields must not appear in ingest request bodies.
Functions ¶
func IsMonthlyLimitMessage ¶
IsMonthlyLimitMessage reports whether a 429 message is the workspace monthly cap.
Types ¶
type AuthenticationError ¶
AuthenticationError is returned for HTTP 401 responses.
func (*AuthenticationError) Error ¶
func (e *AuthenticationError) Error() string
func (*AuthenticationError) Is ¶
func (e *AuthenticationError) Is(target error) bool
type AuthorizationError ¶
AuthorizationError is returned for HTTP 403 responses.
func (*AuthorizationError) Error ¶
func (e *AuthorizationError) Error() string
func (*AuthorizationError) Is ¶
func (e *AuthorizationError) Is(target error) bool
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the Trigv ingest API client.
func NewClient ¶
func NewClient(cfg ClientConfig) (*Client, error)
NewClient creates a Client from configuration. APIKey may be omitted when TRIGV_API_KEY is set in the environment.
func (*Client) SendEvent ¶
func (c *Client) SendEvent(ctx context.Context, req SendEventRequest) (*SendEventResult, error)
SendEvent posts an event to POST /v1/events.
func (*Client) VerifyConnection ¶
func (c *Client) VerifyConnection(ctx context.Context) (*ConnectionResult, error)
VerifyConnection checks the API key via GET /v1/connection.
type ClientConfig ¶
type ClientConfig struct {
// APIKey is the workspace ingest API key (trgv_…).
// When empty, TRIGV_API_KEY from the environment is used.
APIKey string
// BaseURL is the API base URL. Default: DefaultBaseURL.
BaseURL string
// Timeout is the HTTP client timeout in seconds. Default: DefaultTimeout.
Timeout int
// MaxRetries is the number of retries for retryable errors.
// When nil, DefaultMaxRetries is used. Set to a pointer to 0 to disable retries.
MaxRetries *int
// HTTPClient is an optional custom HTTP client (primarily for testing).
HTTPClient HTTPDoer
}
ClientConfig configures a Trigv API client.
type ConnectionAPIKey ¶
type ConnectionAPIKey struct {
PublicID string `json:"public_id"`
Name string `json:"name"`
Prefix string `json:"prefix"`
}
ConnectionAPIKey is API key metadata from GET /v1/connection.
type ConnectionResult ¶
type ConnectionResult struct {
Workspace ConnectionWorkspace `json:"workspace"`
APIKey ConnectionAPIKey `json:"api_key"`
}
ConnectionResult is the parsed success response from GET /v1/connection.
type ConnectionWorkspace ¶
ConnectionWorkspace is workspace metadata from GET /v1/connection.
type DeliveryUrgency ¶
type DeliveryUrgency string
DeliveryUrgency controls iOS delivery urgency.
const ( UrgencyStandard DeliveryUrgency = "standard" UrgencyTimeSensitive DeliveryUrgency = "time_sensitive" )
type Event ¶
type Event struct {
PublicID string `json:"public_id"`
EventUUID string `json:"event_uuid"`
Status string `json:"status"`
Level string `json:"level"`
EventType *string `json:"event_type"`
TargetDeviceCount int `json:"target_device_count"`
ReceivedAt string `json:"received_at"`
}
Event is the event metadata returned by the ingest API.
type NetworkError ¶
NetworkError is returned for connection-level failures.
func (*NetworkError) Error ¶
func (e *NetworkError) Error() string
func (*NetworkError) Is ¶
func (e *NetworkError) Is(target error) bool
func (*NetworkError) Unwrap ¶
func (e *NetworkError) Unwrap() error
type NotFoundError ¶
NotFoundError is returned for HTTP 404 responses.
func (*NotFoundError) Error ¶
func (e *NotFoundError) Error() string
func (*NotFoundError) Is ¶
func (e *NotFoundError) Is(target error) bool
type NotificationLevel ¶
type NotificationLevel string
NotificationLevel is an ingest event severity level.
const ( LevelInfo NotificationLevel = "info" LevelSuccess NotificationLevel = "success" LevelWarning NotificationLevel = "warning" LevelError NotificationLevel = "error" )
type RateLimitError ¶
type RateLimitError struct {
Message string
StatusCode int
Retryable bool
// contains filtered or unexported fields
}
RateLimitError is returned for HTTP 429 responses.
func (*RateLimitError) Error ¶
func (e *RateLimitError) Error() string
func (*RateLimitError) Is ¶
func (e *RateLimitError) Is(target error) bool
type SendEventRequest ¶
type SendEventRequest struct {
Channel string `json:"channel"`
Title string `json:"title"`
Description string `json:"description,omitempty"`
ImageURL string `json:"image_url,omitempty"`
URL string `json:"url,omitempty"`
Level NotificationLevel `json:"level,omitempty"`
DeliveryUrgency DeliveryUrgency `json:"delivery_urgency,omitempty"`
EventType string `json:"event_type,omitempty"`
IdempotencyKey string `json:"idempotency_key,omitempty"`
}
SendEventRequest is the payload for POST /v1/events.
type SendEventResult ¶
type SendEventResult struct {
Event Event
Duplicate bool // true when HTTP 200 (duplicate idempotency key)
}
SendEventResult is the parsed success response from POST /v1/events.
type TimeoutError ¶
type TimeoutError struct {
Message string
}
TimeoutError is returned when a request times out.
func (*TimeoutError) Error ¶
func (e *TimeoutError) Error() string
func (*TimeoutError) Is ¶
func (e *TimeoutError) Is(target error) bool
type ValidationError ¶
type ValidationError struct {
Message string
Errors ValidationErrors
}
ValidationError is returned for client-side or HTTP 422 validation failures.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
func (*ValidationError) Is ¶
func (e *ValidationError) Is(target error) bool
type ValidationErrors ¶
ValidationErrors maps field names to validation messages.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
ai_agent
command
Example: AI agent task completed notification.
|
Example: AI agent task completed notification. |
|
basic
command
Example: send a basic event to the general channel.
|
Example: send a basic event to the general channel. |
|
cron_failed
command
Example: notify when a cron job fails.
|
Example: notify when a cron job fails. |
|
deploy_completed
command
Example: canonical deploy-completed notification.
|
Example: canonical deploy-completed notification. |
|
idempotency
command
Example: idempotent event delivery with a deduplication key.
|
Example: idempotent event delivery with a deduplication key. |
|
warning_event
command
Example: warning-level event.
|
Example: warning-level event. |
|
woocommerce_order
command
Example: WooCommerce new order notification.
|
Example: WooCommerce new order notification. |