core

package
v0.0.0-...-fea5d8a Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2024 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

package core is the collection of re-usable functions that primarily provides data (DB / CRUD) operations to the app. For instance, creating and mutating objects like lists, subscribers etc. All such methods return an echo.HTTPError{} (which implements error.error) that can be directly returned as a response to HTTP handlers without further processing.

Index

Constants

View Source
const (
	CampaignAnalyticsViews   = "views"
	CampaignAnalyticsClicks  = "clicks"
	CampaignAnalyticsBounces = "bounces"
)
View Source
const (
	SortAsc  = "asc"
	SortDesc = "desc"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Constants

type Constants struct {
	SendOptinConfirmation bool
	BounceActions         map[string]struct {
		Count  int
		Action string
	}
	CacheSlowQueries bool
}

Constants represents constant config.

type Core

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

Core represents the listmonk core with all shared, global functions.

func New

func New(o *Opt, h *Hooks) *Core

New returns a new instance of the core.

func (*Core) AddSubscriptions

func (c *Core) AddSubscriptions(subIDs, listIDs []int, status string) error

AddSubscriptions adds list subscriptions to subscribers.

func (*Core) AddSubscriptionsByQuery

func (c *Core) AddSubscriptionsByQuery(query string, sourceListIDs, targetListIDs []int, status string) error

AddSubscriptionsByQuery adds list subscriptions to subscribers by a given arbitrary query expression. sourceListIDs is the list of list IDs to filter the subscriber query with.

func (*Core) BlocklistSubscribers

func (c *Core) BlocklistSubscribers(subIDs []int) error

BlocklistSubscribers blocklists the given list of subscribers.

func (*Core) BlocklistSubscribersByQuery

func (c *Core) BlocklistSubscribersByQuery(query string, listIDs []int) error

BlocklistSubscribersByQuery blocklists the given list of subscribers.

func (*Core) ConfirmOptionSubscription

func (c *Core) ConfirmOptionSubscription(subUUID string, listUUIDs []string, meta models.JSON) error

ConfirmOptionSubscription confirms a subscriber's optin subscription.

func (*Core) CreateCampaign

func (c *Core) CreateCampaign(o models.Campaign, listIDs []int, mediaIDs []int) (models.Campaign, error)

CreateCampaign creates a new campaign.

func (*Core) CreateList

func (c *Core) CreateList(l models.List) (models.List, error)

CreateList creates a new list.

func (*Core) CreateTemplate

func (c *Core) CreateTemplate(name, typ, subject string, body []byte) (models.Template, error)

CreateTemplate creates a new template.

func (*Core) DeleteBlocklistedSubscribers

func (c *Core) DeleteBlocklistedSubscribers() (int, error)

DeleteBlocklistedSubscribers deletes blocklisted subscribers.

func (*Core) DeleteBounce

func (c *Core) DeleteBounce(id int) error

DeleteBounce deletes a list.

func (*Core) DeleteBounces

func (c *Core) DeleteBounces(ids []int) error

DeleteBounces deletes multiple lists.

func (*Core) DeleteCampaign

func (c *Core) DeleteCampaign(id int) error

DeleteCampaign deletes a campaign.

func (*Core) DeleteCampaignLinkClicks

func (c *Core) DeleteCampaignLinkClicks(before time.Time) error

DeleteCampaignLinkClicks deletes campaign views older than a given date.

func (*Core) DeleteCampaignViews

func (c *Core) DeleteCampaignViews(before time.Time) error

DeleteCampaignViews deletes campaign views older than a given date.

func (*Core) DeleteList

func (c *Core) DeleteList(id int) error

DeleteList deletes a list.

func (*Core) DeleteLists

func (c *Core) DeleteLists(ids []int) error

DeleteLists deletes multiple lists.

func (*Core) DeleteMedia

func (c *Core) DeleteMedia(id int) (string, error)

DeleteMedia deletes a given media item and returns the filename of the deleted item.

func (*Core) DeleteOrphanSubscribers

func (c *Core) DeleteOrphanSubscribers() (int, error)

DeleteOrphanSubscribers deletes orphan subscriber records (subscribers without lists).

func (*Core) DeleteSubscriberBounces

func (c *Core) DeleteSubscriberBounces(id int, uuid string) error

DeleteSubscriberBounces deletes the given list of subscribers.

func (*Core) DeleteSubscribers

func (c *Core) DeleteSubscribers(subIDs []int, subUUIDs []string) error

DeleteSubscribers deletes the given list of subscribers.

func (*Core) DeleteSubscribersByQuery

func (c *Core) DeleteSubscribersByQuery(query string, listIDs []int) error

DeleteSubscribersByQuery deletes subscribers by a given arbitrary query expression.

func (*Core) DeleteSubscriptions

func (c *Core) DeleteSubscriptions(subIDs, listIDs []int) error

DeleteSubscriptions delete list subscriptions from subscribers.

func (*Core) DeleteSubscriptionsByQuery

func (c *Core) DeleteSubscriptionsByQuery(query string, sourceListIDs, targetListIDs []int) error

DeleteSubscriptionsByQuery deletes list subscriptions from subscribers by a given arbitrary query expression. sourceListIDs is the list of list IDs to filter the subscriber query with.

func (*Core) DeleteTemplate

func (c *Core) DeleteTemplate(id int) error

DeleteTemplate deletes a given template.

func (*Core) DeleteUnconfirmedSubscriptions

func (c *Core) DeleteUnconfirmedSubscriptions(beforeDate time.Time) (int, error)

DeleteUnconfirmedSubscriptions sets list subscriptions to 'unsubscribed' by a given arbitrary query expression. sourceListIDs is the list of list IDs to filter the subscriber query with.

func (*Core) ExportSubscribers

func (c *Core) ExportSubscribers(query string, subIDs, listIDs []int, batchSize int) (func() ([]models.SubscriberExport, error), error)

ExportSubscribers returns an iterator function that provides lists of subscribers based on the given criteria in an exportable form. The iterator function returned can be called repeatedly until there are nil subscribers. It's an iterator because exports can be extremely large and may have to be fetched in batches from the DB and streamed somewhere.

func (*Core) GetArchivedCampaign

func (c *Core) GetArchivedCampaign(id int, uuid, archiveSlug string) (models.Campaign, error)

GetArchivedCampaign retrieves a campaign with the archive template body.

func (*Core) GetArchivedCampaigns

func (c *Core) GetArchivedCampaigns(offset, limit int) (models.Campaigns, int, error)

GetArchivedCampaigns retrieves campaigns with a template body.

func (*Core) GetBounce

func (c *Core) GetBounce(id int) (models.Bounce, error)

GetBounce retrieves bounce entries based on the given params.

func (*Core) GetCampaign

func (c *Core) GetCampaign(id int, uuid, archiveSlug string) (models.Campaign, error)

GetCampaign retrieves a campaign.

func (*Core) GetCampaignAnalyticsCounts

func (c *Core) GetCampaignAnalyticsCounts(campIDs []int, typ, fromDate, toDate string) ([]models.CampaignAnalyticsCount, error)
func (c *Core) GetCampaignAnalyticsLinks(campIDs []int, typ, fromDate, toDate string) ([]models.CampaignAnalyticsLink, error)

GetCampaignAnalyticsLinks returns link click analytics for the given campaign IDs.

func (*Core) GetCampaignForPreview

func (c *Core) GetCampaignForPreview(id, tplID int) (models.Campaign, error)

GetCampaignForPreview retrieves a campaign with a template body.

func (*Core) GetDashboardCharts

func (c *Core) GetDashboardCharts() (types.JSONText, error)

GetDashboardCharts returns chart data points to render on the dashboard.

func (*Core) GetDashboardCounts

func (c *Core) GetDashboardCounts() (types.JSONText, error)

GetDashboardCounts returns stats counts to show on the dashboard.

func (*Core) GetList

func (c *Core) GetList(id int, uuid string) (models.List, error)

GetList gets a list by its ID or UUID.

func (*Core) GetLists

func (c *Core) GetLists(typ string) ([]models.List, error)

GetLists gets all lists optionally filtered by type.

func (*Core) GetListsByOptin

func (c *Core) GetListsByOptin(ids []int, optinType string) ([]models.List, error)

GetListsByOptin returns lists by optin type.

func (*Core) GetMedia

func (c *Core) GetMedia(id int, uuid string, s media.Store) (media.Media, error)

GetMedia returns a media item.

func (*Core) GetRunningCampaignStats

func (c *Core) GetRunningCampaignStats() ([]models.CampaignStats, error)

GetRunningCampaignStats returns the progress stats of running campaigns.

func (*Core) GetSettings

func (c *Core) GetSettings() (models.Settings, error)

GetSettings returns settings from the DB.

func (*Core) GetSubscriber

func (c *Core) GetSubscriber(id int, uuid, email string) (models.Subscriber, error)

GetSubscriber fetches a subscriber by one of the given params.

func (*Core) GetSubscriberLists

func (c *Core) GetSubscriberLists(subID int, uuid string, listIDs []int, listUUIDs []string, subStatus string, listType string) ([]models.List, error)

GetSubscriberLists returns a subscriber's lists based on the given conditions.

func (*Core) GetSubscriberProfileForExport

func (c *Core) GetSubscriberProfileForExport(id int, uuid string) (models.SubscriberExportProfile, error)

GetSubscriberProfileForExport returns the subscriber's profile data as a JSON exportable. Get the subscriber's data. A single query that gets the profile, list subscriptions, campaign views, and link clicks. Names of private lists are replaced with "Private list".

func (*Core) GetSubscribersByEmail

func (c *Core) GetSubscribersByEmail(emails []string) (models.Subscribers, error)

GetSubscribersByEmail fetches a subscriber by one of the given params.

func (*Core) GetSubscriptions

func (c *Core) GetSubscriptions(subID int, subUUID string, allLists bool) ([]models.Subscription, error)

GetSubscriptions retrieves the subscriptions for a subscriber.

func (*Core) GetTemplate

func (c *Core) GetTemplate(id int, noBody bool) (models.Template, error)

GetTemplate retrieves a given template.

func (*Core) GetTemplates

func (c *Core) GetTemplates(status string, noBody bool) ([]models.Template, error)

GetTemplates retrieves all templates.

func (*Core) InsertMedia

func (c *Core) InsertMedia(fileName, thumbName, contentType string, meta models.JSON, provider string, s media.Store) (media.Media, error)

InsertMedia inserts a new media file into the DB.

func (*Core) InsertSubscriber

func (c *Core) InsertSubscriber(sub models.Subscriber, listIDs []int, listUUIDs []string, preconfirm bool) (models.Subscriber, bool, error)

InsertSubscriber inserts a subscriber and returns the ID. The first bool indicates if it was a new subscriber, and the second bool indicates if the subscriber was sent an optin confirmation. bool = optinSent?

func (*Core) QueryBounces

func (c *Core) QueryBounces(campID, subID int, source, orderBy, order string, offset, limit int) ([]models.Bounce, int, error)

QueryBounces retrieves paginated bounce entries based on the given params. It also returns the total number of bounce records in the DB.

func (*Core) QueryCampaigns

func (c *Core) QueryCampaigns(searchStr string, statuses, tags []string, orderBy, order string, offset, limit int) (models.Campaigns, int, error)

QueryCampaigns retrieves paginated campaigns optionally filtering them by the given arbitrary query expression. It also returns the total number of records in the DB.

func (*Core) QueryLists

func (c *Core) QueryLists(searchStr, typ, optin string, tags []string, orderBy, order string, offset, limit int) ([]models.List, int, error)

QueryLists gets multiple lists based on multiple query params. Along with the paginated and sliced results, the total number of lists in the DB is returned.

func (*Core) QueryMedia

func (c *Core) QueryMedia(provider string, s media.Store, query string, offset, limit int) ([]media.Media, int, error)

QueryMedia returns media entries optionally filtered by a query string.

func (*Core) QuerySubscribers

func (c *Core) QuerySubscribers(query string, listIDs []int, subStatus string, order, orderBy string, offset, limit int) (models.Subscribers, int, error)

QuerySubscribers queries and returns paginated subscrribers based on the given params including the total count.

func (*Core) RecordBounce

func (c *Core) RecordBounce(b models.Bounce) error

RecordBounce records a new bounce.

func (*Core) RefreshMatView

func (c *Core) RefreshMatView(name string, concurrent bool) error

RefreshMatView refreshes a Postgres materialized view.

func (*Core) RefreshMatViews

func (c *Core) RefreshMatViews(concurrent bool) error

RefreshMatViews refreshes all materialized views.

func (*Core) RegisterCampaignLinkClick

func (c *Core) RegisterCampaignLinkClick(linkUUID, campUUID, subUUID string) (string, error)

RegisterCampaignLinkClick registers a subscriber's link click on a campaign.

func (*Core) RegisterCampaignView

func (c *Core) RegisterCampaignView(campUUID, subUUID string) error

RegisterCampaignView registers a subscriber's view on a campaign.

func (*Core) SetDefaultTemplate

func (c *Core) SetDefaultTemplate(id int) error

SetDefaultTemplate sets a template as default.

func (*Core) UnsubscribeByCampaign

func (c *Core) UnsubscribeByCampaign(subUUID, campUUID string, blocklist bool) error

UnsubscribeByCampaign unsubscribes a given subscriber from lists in a given campaign.

func (*Core) UnsubscribeLists

func (c *Core) UnsubscribeLists(subIDs, listIDs []int, listUUIDs []string) error

UnsubscribeLists sets list subscriptions to 'unsubscribed'.

func (*Core) UnsubscribeListsByQuery

func (c *Core) UnsubscribeListsByQuery(query string, sourceListIDs, targetListIDs []int) error

UnsubscribeListsByQuery sets list subscriptions to 'unsubscribed' by a given arbitrary query expression. sourceListIDs is the list of list IDs to filter the subscriber query with.

func (*Core) UpdateCampaign

func (c *Core) UpdateCampaign(id int, o models.Campaign, listIDs []int, mediaIDs []int, sendLater bool) (models.Campaign, error)

UpdateCampaign updates a campaign.

func (*Core) UpdateCampaignArchive

func (c *Core) UpdateCampaignArchive(id int, enabled bool, tplID int, meta models.JSON, archiveSlug string) error

UpdateCampaignArchive updates a campaign's archive properties.

func (*Core) UpdateCampaignStatus

func (c *Core) UpdateCampaignStatus(id int, status string) (models.Campaign, error)

UpdateCampaignStatus updates a campaign's status, eg: draft to running.

func (*Core) UpdateList

func (c *Core) UpdateList(id int, l models.List) (models.List, error)

UpdateList updates a given list.

func (*Core) UpdateSettings

func (c *Core) UpdateSettings(s models.Settings) error

UpdateSettings updates settings.

func (*Core) UpdateSubscriber

func (c *Core) UpdateSubscriber(id int, sub models.Subscriber) (models.Subscriber, error)

UpdateSubscriber updates a subscriber's properties.

func (*Core) UpdateSubscriberWithLists

func (c *Core) UpdateSubscriberWithLists(id int, sub models.Subscriber, listIDs []int, listUUIDs []string, preconfirm, deleteLists bool) (models.Subscriber, bool, error)

UpdateSubscriberWithLists updates a subscriber's properties. If deleteLists is set to true, all existing subscriptions are deleted and only the ones provided are added or retained.

func (*Core) UpdateTemplate

func (c *Core) UpdateTemplate(id int, name, subject string, body []byte) (models.Template, error)

UpdateTemplate updates a given template.

type Hooks

type Hooks struct {
	SendOptinConfirmation    func(models.Subscriber, []int) (int, error)
	SendNewSubscriberWebhook func(int, []int) error
}

Hooks contains external function hooks that are required by the core package.

type Opt

type Opt struct {
	Constants Constants
	I18n      *i18n.I18n
	DB        *sqlx.DB
	Queries   *models.Queries
	Log       *log.Logger
}

Opt contains the controllers required to start the core.

Jump to

Keyboard shortcuts

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