Documentation
¶
Overview ¶
Package client provides a wrapper around the AhaSend SDK with enhanced functionality.
This package implements the AhaSendClient interface and provides additional features beyond the base SDK:
- Rate limiting (50 requests/second with 100 burst capacity)
- Automatic retry logic with exponential backoff
- HTTP request/response logging for debugging
- Structured error handling and API error translation
- Context-aware request handling
- Idempotency key support for message sending
- Configuration validation and connection testing
The Client struct wraps the official AhaSend SDK while maintaining full compatibility and adding CLI-specific enhancements for better user experience.
Index ¶
- type AhaSendClient
- type Client
- func (c *Client) CancelMessage(accountID, messageID string) (*common.SuccessResponse, error)
- func (c *Client) ConnectWebSocket(wsURL, webhookID string, forceReconnect, skipVerify bool) (*WebSocketClient, error)
- func (c *Client) CreateAPIKey(req requests.CreateAPIKeyRequest) (*responses.APIKey, error)
- func (c *Client) CreateDomain(domain string) (*responses.Domain, error)
- func (c *Client) CreateRoute(req requests.CreateRouteRequest) (*responses.Route, error)
- func (c *Client) CreateSMTPCredential(req requests.CreateSMTPCredentialRequest) (*responses.SMTPCredential, error)
- func (c *Client) CreateSuppression(req requests.CreateSuppressionRequest) (*responses.CreateSuppressionResponse, error)
- func (c *Client) CreateWebhook(req requests.CreateWebhookRequest) (*responses.Webhook, error)
- func (c *Client) CreateWebhookVerifier(secret string) (*webhooks.WebhookVerifier, error)
- func (c *Client) DeleteAPIKey(keyID string) (*common.SuccessResponse, error)
- func (c *Client) DeleteDomain(domain string) (*common.SuccessResponse, error)
- func (c *Client) DeleteRoute(routeID string) error
- func (c *Client) DeleteSMTPCredential(credentialID string) error
- func (c *Client) DeleteSuppression(email string, domain *string) (*common.SuccessResponse, error)
- func (c *Client) DeleteWebhook(webhookID string) error
- func (c *Client) GetAPIKey(keyID string) (*responses.APIKey, error)
- func (c *Client) GetAccount() (*responses.Account, error)
- func (c *Client) GetAccountID() string
- func (c *Client) GetAuthContext() context.Context
- func (c *Client) GetBounceStatistics(params requests.GetBounceStatisticsParams) (*responses.BounceStatisticsResponse, error)
- func (c *Client) GetDeliverabilityStatistics(params requests.GetDeliverabilityStatisticsParams) (*responses.DeliverabilityStatisticsResponse, error)
- func (c *Client) GetDeliveryTimeStatistics(params requests.GetDeliveryTimeStatisticsParams) (*responses.DeliveryTimeStatisticsResponse, error)
- func (c *Client) GetDomain(domain string) (*responses.Domain, error)
- func (c *Client) GetMessage(messageID string) (*responses.Message, error)
- func (c *Client) GetMessages(params requests.GetMessagesParams) (*responses.PaginatedMessagesResponse, error)
- func (c *Client) GetRoute(routeID string) (*responses.Route, error)
- func (c *Client) GetSMTPCredential(credentialID string) (*responses.SMTPCredential, error)
- func (c *Client) GetWebhook(webhookID string) (*responses.Webhook, error)
- func (c *Client) InitiateRouteStream(routeID, recipient string) (*RouteStreamResponse, error)
- func (c *Client) InitiateWebhookStream(webhookID string) (*WebhookStreamResponse, error)
- func (c *Client) ListAPIKeys(limit *int32, cursor *string) (*responses.PaginatedAPIKeysResponse, error)
- func (c *Client) ListDomains(limit *int32, cursor *string) (*responses.PaginatedDomainsResponse, error)
- func (c *Client) ListRoutes(limit *int32, cursor *string) (*responses.PaginatedRoutesResponse, error)
- func (c *Client) ListSMTPCredentials(limit *int32, cursor *string) (*responses.PaginatedSMTPCredentialsResponse, error)
- func (c *Client) ListSuppressions(params requests.GetSuppressionsParams) (*responses.PaginatedSuppressionsResponse, error)
- func (c *Client) ListWebhooks(limit *int32, cursor *string) (*responses.PaginatedWebhooksResponse, error)
- func (c *Client) Ping() error
- func (c *Client) SendMessage(req requests.CreateMessageRequest) (*responses.CreateMessageResponse, error)
- func (c *Client) SendMessageWithIdempotencyKey(req requests.CreateMessageRequest, idempotencyKey string) (*responses.CreateMessageResponse, error)
- func (c *Client) TriggerRoute(routeID string) error
- func (c *Client) TriggerWebhook(webhookID string, events []string) error
- func (c *Client) UpdateAPIKey(keyID string, req requests.UpdateAPIKeyRequest) (*responses.APIKey, error)
- func (c *Client) UpdateRoute(routeID string, req requests.UpdateRouteRequest) (*responses.Route, error)
- func (c *Client) UpdateWebhook(webhookID string, req requests.UpdateWebhookRequest) (*responses.Webhook, error)
- func (c *Client) ValidateConfiguration() error
- func (c *Client) WipeSuppressions(domain *string) (*common.SuccessResponse, error)
- type Event
- type RateLimiter
- type RouteStreamResponse
- type WebSocketClient
- type WebSocketMessage
- type WebhookStreamResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AhaSendClient ¶
type AhaSendClient interface {
// Authentication and account info
GetAccountID() string
GetAuthContext() context.Context
GetAccount() (*responses.Account, error)
Ping() error
ValidateConfiguration() error
// Message operations
SendMessage(req requests.CreateMessageRequest) (*responses.CreateMessageResponse, error)
SendMessageWithIdempotencyKey(req requests.CreateMessageRequest, idempotencyKey string) (*responses.CreateMessageResponse, error)
CancelMessage(accountID, messageID string) (*common.SuccessResponse, error)
GetMessages(params requests.GetMessagesParams) (*responses.PaginatedMessagesResponse, error)
GetMessage(messageID string) (*responses.Message, error)
// Domain operations
ListDomains(limit *int32, cursor *string) (*responses.PaginatedDomainsResponse, error)
CreateDomain(domain string) (*responses.Domain, error)
GetDomain(domain string) (*responses.Domain, error)
DeleteDomain(domain string) (*common.SuccessResponse, error)
// Webhook operations
CreateWebhookVerifier(secret string) (*webhooks.WebhookVerifier, error)
ListWebhooks(limit *int32, cursor *string) (*responses.PaginatedWebhooksResponse, error)
CreateWebhook(req requests.CreateWebhookRequest) (*responses.Webhook, error)
GetWebhook(webhookID string) (*responses.Webhook, error)
UpdateWebhook(webhookID string, req requests.UpdateWebhookRequest) (*responses.Webhook, error)
DeleteWebhook(webhookID string) error
// Webhook streaming operations (development only)
InitiateWebhookStream(webhookID string) (*WebhookStreamResponse, error)
ConnectWebSocket(wsURL, webhookID string, forceReconnect, skipVerify bool) (*WebSocketClient, error)
TriggerWebhook(webhookID string, events []string) error
// Route operations
ListRoutes(limit *int32, cursor *string) (*responses.PaginatedRoutesResponse, error)
CreateRoute(req requests.CreateRouteRequest) (*responses.Route, error)
GetRoute(routeID string) (*responses.Route, error)
UpdateRoute(routeID string, req requests.UpdateRouteRequest) (*responses.Route, error)
DeleteRoute(routeID string) error
// Route streaming operations (development only)
InitiateRouteStream(routeID, recipient string) (*RouteStreamResponse, error)
TriggerRoute(routeID string) error
// Suppression operations
ListSuppressions(params requests.GetSuppressionsParams) (*responses.PaginatedSuppressionsResponse, error)
CreateSuppression(req requests.CreateSuppressionRequest) (*responses.CreateSuppressionResponse, error)
DeleteSuppression(email string, domain *string) (*common.SuccessResponse, error)
WipeSuppressions(domains *string) (*common.SuccessResponse, error)
// SMTP operations
ListSMTPCredentials(limit *int32, cursor *string) (*responses.PaginatedSMTPCredentialsResponse, error)
GetSMTPCredential(credentialID string) (*responses.SMTPCredential, error)
CreateSMTPCredential(req requests.CreateSMTPCredentialRequest) (*responses.SMTPCredential, error)
DeleteSMTPCredential(credentialID string) error
// Statistics operations
GetDeliverabilityStatistics(params requests.GetDeliverabilityStatisticsParams) (*responses.DeliverabilityStatisticsResponse, error)
GetBounceStatistics(params requests.GetBounceStatisticsParams) (*responses.BounceStatisticsResponse, error)
GetDeliveryTimeStatistics(params requests.GetDeliveryTimeStatisticsParams) (*responses.DeliveryTimeStatisticsResponse, error)
// API Key operations
ListAPIKeys(limit *int32, cursor *string) (*responses.PaginatedAPIKeysResponse, error)
GetAPIKey(keyID string) (*responses.APIKey, error)
CreateAPIKey(req requests.CreateAPIKeyRequest) (*responses.APIKey, error)
UpdateAPIKey(keyID string, req requests.UpdateAPIKeyRequest) (*responses.APIKey, error)
DeleteAPIKey(keyID string) (*common.SuccessResponse, error)
}
AhaSendClient defines the interface for AhaSend API operations This interface allows for better testability and mocking
type Client ¶
Client wraps the AhaSend SDK client with additional functionality
func (*Client) CancelMessage ¶
func (c *Client) CancelMessage(accountID, messageID string) (*common.SuccessResponse, error)
CancelMessage cancels a scheduled message
func (*Client) ConnectWebSocket ¶
func (c *Client) ConnectWebSocket(wsURL, webhookID string, forceReconnect, skipVerify bool) (*WebSocketClient, error)
func (*Client) CreateAPIKey ¶
CreateAPIKey creates a new API key
func (*Client) CreateDomain ¶
CreateDomain creates a new domain
func (*Client) CreateRoute ¶
CreateRoute creates a new route
func (*Client) CreateSMTPCredential ¶
func (c *Client) CreateSMTPCredential(req requests.CreateSMTPCredentialRequest) (*responses.SMTPCredential, error)
CreateSMTPCredential creates a new SMTP credential
func (*Client) CreateSuppression ¶
func (c *Client) CreateSuppression(req requests.CreateSuppressionRequest) (*responses.CreateSuppressionResponse, error)
CreateSuppression creates a new suppression
func (*Client) CreateWebhook ¶
CreateWebhook creates a new webhook
func (*Client) CreateWebhookVerifier ¶
func (c *Client) CreateWebhookVerifier(secret string) (*webhooks.WebhookVerifier, error)
CreateWebhookVerifier creates a webhook verifier for the given secret
func (*Client) DeleteAPIKey ¶
func (c *Client) DeleteAPIKey(keyID string) (*common.SuccessResponse, error)
DeleteAPIKey deletes an API key
func (*Client) DeleteDomain ¶
func (c *Client) DeleteDomain(domain string) (*common.SuccessResponse, error)
DeleteDomain deletes a domain
func (*Client) DeleteRoute ¶
DeleteRoute deletes a route
func (*Client) DeleteSMTPCredential ¶
DeleteSMTPCredential deletes an SMTP credential by ID
func (*Client) DeleteSuppression ¶
DeleteSuppression deletes a suppression by email and optional domain
func (*Client) DeleteWebhook ¶
DeleteWebhook deletes a webhook
func (*Client) GetAccount ¶
GetAccount retrieves account information
func (*Client) GetAccountID ¶
GetAccountID returns the configured account ID
func (*Client) GetAuthContext ¶
GetAuthContext returns the authenticated context
func (*Client) GetBounceStatistics ¶
func (c *Client) GetBounceStatistics(params requests.GetBounceStatisticsParams) (*responses.BounceStatisticsResponse, error)
GetBounceStatistics retrieves bounce statistics
func (*Client) GetDeliverabilityStatistics ¶
func (c *Client) GetDeliverabilityStatistics(params requests.GetDeliverabilityStatisticsParams) (*responses.DeliverabilityStatisticsResponse, error)
GetDeliverabilityStatistics retrieves deliverability statistics
func (*Client) GetDeliveryTimeStatistics ¶
func (c *Client) GetDeliveryTimeStatistics(params requests.GetDeliveryTimeStatisticsParams) (*responses.DeliveryTimeStatisticsResponse, error)
GetDeliveryTimeStatistics retrieves delivery time statistics
func (*Client) GetMessage ¶
GetMessage retrieves a single message by ID
func (*Client) GetMessages ¶
func (c *Client) GetMessages(params requests.GetMessagesParams) (*responses.PaginatedMessagesResponse, error)
GetMessages retrieves messages with filtering and pagination
func (*Client) GetSMTPCredential ¶
func (c *Client) GetSMTPCredential(credentialID string) (*responses.SMTPCredential, error)
GetSMTPCredential gets a specific SMTP credential by ID
func (*Client) GetWebhook ¶
GetWebhook retrieves a single webhook by ID
func (*Client) InitiateRouteStream ¶
func (c *Client) InitiateRouteStream(routeID, recipient string) (*RouteStreamResponse, error)
func (*Client) InitiateWebhookStream ¶
func (c *Client) InitiateWebhookStream(webhookID string) (*WebhookStreamResponse, error)
func (*Client) ListAPIKeys ¶
func (c *Client) ListAPIKeys(limit *int32, cursor *string) (*responses.PaginatedAPIKeysResponse, error)
ListAPIKeys retrieves a list of API keys
func (*Client) ListDomains ¶
func (c *Client) ListDomains(limit *int32, cursor *string) (*responses.PaginatedDomainsResponse, error)
ListDomains lists domains with pagination @TODO: Add DNSValid parameter
func (*Client) ListRoutes ¶
func (c *Client) ListRoutes(limit *int32, cursor *string) (*responses.PaginatedRoutesResponse, error)
ListRoutes retrieves a paginated list of routes
func (*Client) ListSMTPCredentials ¶
func (c *Client) ListSMTPCredentials(limit *int32, cursor *string) (*responses.PaginatedSMTPCredentialsResponse, error)
ListSMTPCredentials lists all SMTP credentials with pagination
func (*Client) ListSuppressions ¶
func (c *Client) ListSuppressions(params requests.GetSuppressionsParams) (*responses.PaginatedSuppressionsResponse, error)
ListSuppressions retrieves a paginated list of suppressions
func (*Client) ListWebhooks ¶
func (c *Client) ListWebhooks(limit *int32, cursor *string) (*responses.PaginatedWebhooksResponse, error)
ListWebhooks retrieves all webhooks with pagination support
func (*Client) SendMessage ¶
func (c *Client) SendMessage(req requests.CreateMessageRequest) (*responses.CreateMessageResponse, error)
SendMessage sends a message with retry and rate limiting
func (*Client) SendMessageWithIdempotencyKey ¶
func (c *Client) SendMessageWithIdempotencyKey(req requests.CreateMessageRequest, idempotencyKey string) (*responses.CreateMessageResponse, error)
SendMessageWithIdempotencyKey sends a message with idempotency key support
func (*Client) TriggerRoute ¶
TriggerRoute triggers route events for development testing
func (*Client) TriggerWebhook ¶
TriggerWebhook triggers webhook events for development testing
func (*Client) UpdateAPIKey ¶
func (c *Client) UpdateAPIKey(keyID string, req requests.UpdateAPIKeyRequest) (*responses.APIKey, error)
UpdateAPIKey updates an existing API key
func (*Client) UpdateRoute ¶
func (c *Client) UpdateRoute(routeID string, req requests.UpdateRouteRequest) (*responses.Route, error)
UpdateRoute updates an existing route
func (*Client) UpdateWebhook ¶
func (c *Client) UpdateWebhook(webhookID string, req requests.UpdateWebhookRequest) (*responses.Webhook, error)
UpdateWebhook updates an existing webhook
func (*Client) ValidateConfiguration ¶
ValidateConfiguration validates the client configuration
func (*Client) WipeSuppressions ¶
func (c *Client) WipeSuppressions(domain *string) (*common.SuccessResponse, error)
WipeSuppressions deletes all suppressions in the account
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter wraps the golang rate limiter for API requests
func NewRateLimiter ¶
func NewRateLimiter(rps int, burst int) *RateLimiter
NewRateLimiter creates a new rate limiter rps: requests per second burst: burst capacity
func (*RateLimiter) Allow ¶
func (rl *RateLimiter) Allow() bool
Allow reports whether an event may happen now
func (*RateLimiter) GetWaitTime ¶
func (rl *RateLimiter) GetWaitTime() time.Duration
GetWaitTime returns how long the caller must wait before the next action is permitted
func (*RateLimiter) Reserve ¶
func (rl *RateLimiter) Reserve() *rate.Reservation
Reserve returns a Reservation that indicates how long the caller must wait before the action is permitted
type RouteStreamResponse ¶
type WebSocketClient ¶
type WebSocketClient struct {
// contains filtered or unexported fields
}
func (*WebSocketClient) Close ¶
func (wsc *WebSocketClient) Close() error
func (*WebSocketClient) ReadMessage ¶
func (wsc *WebSocketClient) ReadMessage(ctx context.Context) (*WebSocketMessage, error)