- Added a new endpoint for simulating rules based on sample messages, allowing users to test rule conditions and actions. - Enhanced webhook management with versioning, preview capabilities, and improved validation for webhook requests. - Updated service interfaces to support new functionalities, including max retries for webhooks and signing secrets. - Implemented observability metrics for webhook retries and dead-letter tracking, improving error handling and monitoring. - Enhanced unit tests to cover new simulation and webhook features, ensuring robust functionality and validation.
68 lines
5.3 KiB
Go
68 lines
5.3 KiB
Go
package mail
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"time"
|
|
|
|
"github.com/ultisuite/ulti-backend/internal/api/query"
|
|
"github.com/ultisuite/ulti-backend/internal/mail/rules"
|
|
)
|
|
|
|
// ServiceAPI is the mail handler service boundary. *Service implements it in production.
|
|
type ServiceAPI interface {
|
|
ResolveUserID(ctx context.Context, externalID string) (string, error)
|
|
ListAccounts(ctx context.Context, externalID string, params query.ListParams) (AccountsList, error)
|
|
CreateAccount(ctx context.Context, externalID string, req *createAccountRequest) (string, error)
|
|
GetAccount(ctx context.Context, externalID, accountID string) (map[string]any, error)
|
|
DeleteAccount(ctx context.Context, externalID, accountID string) error
|
|
ListMessages(ctx context.Context, externalID string, filter MessageListFilter, params query.ListParams) (MessagesList, error)
|
|
GetMessage(ctx context.Context, externalID, messageID string) (map[string]any, error)
|
|
UpdateLabels(ctx context.Context, externalID, messageID string, labels []string) error
|
|
UpdateFlags(ctx context.Context, externalID, messageID string, flags []string) error
|
|
DeleteMessage(ctx context.Context, externalID, messageID string) error
|
|
GetThread(ctx context.Context, externalID, threadID string) (map[string]any, error)
|
|
SendMessage(ctx context.Context, userID string, req *sendMessageRequest) (id, status string, err error)
|
|
SendOutboxNow(ctx context.Context, userID, outboxID string) (status string, err error)
|
|
RescheduleOutbox(ctx context.Context, userID, outboxID string, scheduledAt time.Time) (status string, err error)
|
|
CancelScheduledOutbox(ctx context.Context, userID, outboxID string) (status string, err error)
|
|
ListDrafts(ctx context.Context, externalID string, params query.ListParams) (DraftsList, error)
|
|
GetDraft(ctx context.Context, externalID, draftID string) (map[string]any, error)
|
|
CreateDraft(ctx context.Context, userID string, req *draftRequest) (string, error)
|
|
UpdateDraft(ctx context.Context, externalID, draftID string, req *draftRequest) error
|
|
DeleteDraft(ctx context.Context, externalID, draftID string) error
|
|
ListRules(ctx context.Context, externalID string, params query.ListParams) (RulesList, error)
|
|
CreateRule(ctx context.Context, userID string, req *createRuleRequest) (string, error)
|
|
UpdateRule(ctx context.Context, externalID, ruleID string, req *updateRuleRequest) error
|
|
DeleteRule(ctx context.Context, externalID, ruleID string) error
|
|
SimulateRule(ctx context.Context, externalID string, req *simulateRuleRequest) (rules.SimulationResult, error)
|
|
ListWebhooks(ctx context.Context, externalID string, params query.ListParams) (WebhooksList, error)
|
|
CreateWebhook(ctx context.Context, externalID string, req *createWebhookRequest, method string, maxRetries int) (string, error)
|
|
UpdateWebhook(ctx context.Context, externalID, webhookID string, req *updateWebhookRequest, method string, maxRetries int) error
|
|
PreviewWebhookTemplate(ctx context.Context, externalID string, req *previewWebhookRequest) (map[string]any, error)
|
|
DeleteWebhook(ctx context.Context, externalID, webhookID string) error
|
|
ListIdentities(ctx context.Context, externalID, accountID string, params query.ListParams) (IdentitiesList, error)
|
|
GetIdentity(ctx context.Context, externalID, identityID string) (map[string]any, error)
|
|
CreateIdentity(ctx context.Context, externalID, accountID string, req *createIdentityRequest) (string, error)
|
|
UpdateIdentity(ctx context.Context, externalID, identityID string, req *updateIdentityRequest) error
|
|
DeleteIdentity(ctx context.Context, externalID, identityID string) error
|
|
ListFolders(ctx context.Context, externalID, accountID string, params query.ListParams) (FoldersList, error)
|
|
GetFolder(ctx context.Context, externalID, folderID string) (map[string]any, error)
|
|
CreateFolder(ctx context.Context, userID string, req *createFolderRequest) (string, error)
|
|
UpdateFolder(ctx context.Context, externalID, folderID string, req *updateFolderRequest) error
|
|
DeleteFolder(ctx context.Context, externalID, folderID string) error
|
|
ListUserLabels(ctx context.Context, externalID string, params query.ListParams) (UserLabelsList, error)
|
|
CreateUserLabel(ctx context.Context, externalID string, req *createUserLabelRequest) (string, error)
|
|
UpdateUserLabel(ctx context.Context, externalID, labelID string, req *updateUserLabelRequest) error
|
|
DeleteUserLabel(ctx context.Context, externalID, labelID string) error
|
|
SearchMessages(ctx context.Context, externalID string, filter MessageSearchFilter, params query.ListParams) (MessageSearchResult, error)
|
|
ListMessageAttachments(ctx context.Context, externalID, messageID string) ([]map[string]any, error)
|
|
MessageAttachmentCIDMap(ctx context.Context, externalID, messageID string) (map[string]string, error)
|
|
UploadMessageAttachment(ctx context.Context, externalID, messageID, filename, contentType, contentID string, isInline bool, reader io.Reader, size int64) (string, error)
|
|
OpenAttachment(ctx context.Context, externalID, attachmentID string) (filename, contentType string, size int64, isInline bool, body io.ReadCloser, err error)
|
|
UploadDraftAttachment(ctx context.Context, externalID, draftID, filename, contentType, contentID string, isInline bool, reader io.Reader, size int64) (string, error)
|
|
OpenDraftAttachment(ctx context.Context, externalID, draftID, attachmentID string) (filename, contentType string, body io.ReadCloser, err error)
|
|
}
|
|
|
|
var _ ServiceAPI = (*Service)(nil)
|