email

package
v0.20251216.0 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: MPL-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrQueueFull = errors.New("email-exporter queue is full")

Functions

This section is empty.

Types

type Case added in v0.20251103.0

type Case struct {
	// Origin is required in all requests, a safe default is "Web".
	Origin string `json:"Origin"`

	// Subject is an optional standard field. Max length: 255 characters.
	Subject string `json:"Subject,omitempty"`

	// Description is an optional standard field. Max length: 32,768 characters.
	Description string `json:"Description,omitempty"`

	// ContactEmail is an optional standard field indicating the email address
	// of the requester. Max length: 80 characters.
	ContactEmail string `json:"ContactEmail,omitempty"`

	// Organization indicates the name of the requesting organization. Max
	// length: 255 characters.
	Organization string `json:"Organization__c,omitempty"`

	// AccountId indicates the requester's ACME Account ID. Max length: 255
	// characters.
	AccountId string `json:"Account_ID__c,omitempty"`

	// RateLimitName indicates which rate limit the override request is for. Max
	// length: 255 characters.
	RateLimitName string `json:"Rate_Limit_Name__c,omitempty"`

	// Tier indicates the requested tier of the rate limit override. Max length:
	// 255 characters.
	RateLimitTier string `json:"Rate_Limit_Tier__c,omitempty"`

	// UseCase indicates the intended to use case supplied by the requester. Max
	// length: 131,072 characters.
	UseCase string `json:"Use_Case__c,omitempty"`
}

Case represents the payload for populating a new Case object in Salesforce. For more information, see: https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_case.htm https://help.salesforce.com/s/articleView?id=platform.custom_field_types.htm&type=5

type EmailCache

type EmailCache struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewHashedEmailCache

func NewHashedEmailCache(maxEntries int, stats prometheus.Registerer) *EmailCache

func (*EmailCache) Remove

func (c *EmailCache) Remove(email string)

func (*EmailCache) Seen

func (c *EmailCache) Seen(email string) bool

func (*EmailCache) StoreIfAbsent

func (c *EmailCache) StoreIfAbsent(email string) bool

StoreIfAbsent stores the email in the cache if it is not already present, as a single atomic operation. It returns true if the email was stored and false if it was already in the cache. If the cache is nil, true is always returned.

type ExporterImpl

type ExporterImpl struct {
	emailpb.UnsafeExporterServer

	sync.Mutex
	// contains filtered or unexported fields
}

ExporterImpl implements the gRPC server and processes email exports.

func NewExporterImpl

func NewExporterImpl(client SalesforceClient, cache *EmailCache, perDayLimit float64, maxConcurrentRequests int, stats prometheus.Registerer, logger blog.Logger) *ExporterImpl

NewExporterImpl initializes an ExporterImpl with the given client and configuration. Both perDayLimit and maxConcurrentRequests should be distributed proportionally among instances based on their share of the daily request cap. For example, if the total daily limit is 50,000 and one instance is assigned 40% (20,000 requests), it should also receive 40% of the max concurrent requests (e.g., 2 out of 5). For more details, see: https://developer.salesforce.com/docs/marketing/pardot/guide/overview.html?q=rate%20limits

func (*ExporterImpl) Drain

func (impl *ExporterImpl) Drain()

Drain blocks until all workers have finished processing the email queue.

func (*ExporterImpl) SendCase added in v0.20251103.0

func (impl *ExporterImpl) SendCase(ctx context.Context, req *emailpb.SendCaseRequest) (*emptypb.Empty, error)

SendCase immediately submits a new Case to the Salesforce REST API using the provided details. Any retries are handled internally by the SalesforceClient. The following fields are required: Origin, Subject, ContactEmail.

func (*ExporterImpl) SendContacts

func (impl *ExporterImpl) SendContacts(ctx context.Context, req *emailpb.SendContactsRequest) (*emptypb.Empty, error)

SendContacts enqueues the provided email addresses. If the queue cannot accommodate the new emails, an ErrQueueFull is returned.

func (*ExporterImpl) Start

func (impl *ExporterImpl) Start(daemonCtx context.Context)

Start begins asynchronous processing of the email queue. When the parent daemonCtx is cancelled the queue will be drained and the workers will exit.

type SalesforceClient added in v0.20251103.0

type SalesforceClient interface {
	SendContact(email string) error
	SendCase(payload Case) error
}

SalesforceClient is an interface for interacting with a limited set of Salesforce APIs. It exists to facilitate testing mocks.

type SalesforceClientImpl added in v0.20251103.0

type SalesforceClientImpl struct {
	// contains filtered or unexported fields
}

SalesforceClientImpl handles authentication and sending contacts to Pardot and creating Cases in Salesforce.

func NewSalesforceClientImpl added in v0.20251103.0

func NewSalesforceClientImpl(clk clock.Clock, businessUnit, clientId, clientSecret, salesforceBaseURL, pardotBaseURL string) (*SalesforceClientImpl, error)

NewSalesforceClientImpl creates a new SalesforceClientImpl.

func (*SalesforceClientImpl) SendCase added in v0.20251103.0

func (pc *SalesforceClientImpl) SendCase(payload Case) error

SendCase submits a new Case object to Salesforce. For more information, see: https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_sobject_create.htm

func (*SalesforceClientImpl) SendContact added in v0.20251103.0

func (pc *SalesforceClientImpl) SendContact(email string) error

SendContact submits an email to the Pardot Contacts endpoint, retrying up to 3 times with exponential backoff.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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