bulkmailv1

import bulkmailv1 "pocketone.dev/ext/contracts/bulkmail/v1"

Package bulkmailv1 is the bulkmail/v1 contract: campaigns to many recipients, sent at a safe pace. Campaigns are records in the provider's collection (created and edited with PocketBase's records API); this contract runs them: count an audience, start, pause, resume, cancel, preview and test a campaign. Unsubscribes and bounces are mail.suppression/v1 and mail.feedback/v1.

A wire contract at /api/_c/bulkmail/v1.

Source: ext/contracts/bulkmail/v1.

Variables

var Contract = extkit.NewContract[Campaigns]("bulkmail/v1", extkit.One).JS(extkit.JSHooks, nil).JSTypes(jsTypes)

Contract is bulkmail/v1.

var W = extkit.NewWire(Contract, "bulkmail", func(inner Campaigns, g *extkit.Guard[Campaigns]) Campaigns {
	return &guardCampaigns{inner, g}
},
	extkit.Op[Campaigns]{
		Name:   "count",
		Desc:   "Says how many recipients an audience reaches, how many of them are suppressed, and a few sample addresses.",
		Method: "POST",
		Path:   "count",
		Scope:  "bulkmail:read",
		In:     reflect.TypeOf(CountInput{}),
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Campaigns, a extkit.Auth, req extkit.OpRequest) (any, error) {
			var in CountInput
			if err := extkit.DecodeInput(req.JSON, &in); err != nil {
				return nil, err
			}
			return impl.Count(ctx, a, in)
		},
	},
	extkit.Op[Campaigns]{
		Name:   "start",
		Desc:   "Queues a campaign's recipients and starts sending (Limit > 0: at most that many new recipients).",
		Method: "POST",
		Path:   "start",
		In:     reflect.TypeOf(StartInput{}),
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Campaigns, a extkit.Auth, req extkit.OpRequest) (any, error) {
			var in StartInput
			if err := extkit.DecodeInput(req.JSON, &in); err != nil {
				return nil, err
			}
			return impl.Start(ctx, a, in)
		},
	},
	extkit.Op[Campaigns]{
		Name:   "pause",
		Desc:   "Stops sending a campaign; Resume carries on.",
		Method: "POST",
		Path:   "pause",
		In:     reflect.TypeOf(Ref{}),
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Campaigns, a extkit.Auth, req extkit.OpRequest) (any, error) {
			var in Ref
			if err := extkit.DecodeInput(req.JSON, &in); err != nil {
				return nil, err
			}
			return impl.Pause(ctx, a, in)
		},
	},
	extkit.Op[Campaigns]{
		Name:   "resume",
		Desc:   "Carries on sending a paused campaign.",
		Method: "POST",
		Path:   "resume",
		In:     reflect.TypeOf(Ref{}),
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Campaigns, a extkit.Auth, req extkit.OpRequest) (any, error) {
			var in Ref
			if err := extkit.DecodeInput(req.JSON, &in); err != nil {
				return nil, err
			}
			return impl.Resume(ctx, a, in)
		},
	},
	extkit.Op[Campaigns]{
		Name:   "cancel",
		Desc:   "Stops a campaign for good; recipients not yet sent to are dropped.",
		Method: "POST",
		Path:   "cancel",
		In:     reflect.TypeOf(Ref{}),
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Campaigns, a extkit.Auth, req extkit.OpRequest) (any, error) {
			var in Ref
			if err := extkit.DecodeInput(req.JSON, &in); err != nil {
				return nil, err
			}
			return impl.Cancel(ctx, a, in)
		},
	},
	extkit.Op[Campaigns]{
		Name:   "preview",
		Desc:   "Renders a campaign's message for one recipient (the first in its audience when Email is empty).",
		Method: "POST",
		Path:   "preview",
		Scope:  "bulkmail:read",
		In:     reflect.TypeOf(PreviewInput{}),
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Campaigns, a extkit.Auth, req extkit.OpRequest) (any, error) {
			var in PreviewInput
			if err := extkit.DecodeInput(req.JSON, &in); err != nil {
				return nil, err
			}
			return impl.Preview(ctx, a, in)
		},
	},
	extkit.Op[Campaigns]{
		Name:   "test",
		Desc:   "Sends a campaign's message to one address, marked as a test.",
		Method: "POST",
		Path:   "test",
		In:     reflect.TypeOf(TestInput{}),
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Campaigns, a extkit.Auth, req extkit.OpRequest) (any, error) {
			var in TestInput
			if err := extkit.DecodeInput(req.JSON, &in); err != nil {
				return nil, err
			}
			return impl.Test(ctx, a, in)
		},
	},
)

W is bulkmail/v1's wire side: routes at /api/_c/bulkmail/v1/<op>, action hooks, MCP tools and the client.

Functions

OnCancel

func OnCancel(owner any, fn func(e *extkit.CallEvent, in *Ref) error)

OnCancel binds fn to cancel calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.

OnCount

func OnCount(owner any, fn func(e *extkit.CallEvent, in *CountInput) error)

OnCount binds fn to count calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.

OnPause

func OnPause(owner any, fn func(e *extkit.CallEvent, in *Ref) error)

OnPause binds fn to pause calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.

OnPreview

func OnPreview(owner any, fn func(e *extkit.CallEvent, in *PreviewInput) error)

OnPreview binds fn to preview calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.

OnResume

func OnResume(owner any, fn func(e *extkit.CallEvent, in *Ref) error)

OnResume binds fn to resume calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.

OnStart

func OnStart(owner any, fn func(e *extkit.CallEvent, in *StartInput) error)

OnStart binds fn to start calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.

OnTest

func OnTest(owner any, fn func(e *extkit.CallEvent, in *TestInput) error)

OnTest binds fn to test calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.

Types

Campaign

type Campaign struct {
	Campaign json.RawMessage `json:"campaign"`
}

Campaign is the campaign's record after the action, as PocketBase's records API returns it.

Campaigns

type Campaigns interface {
	// Count says how many recipients an audience reaches, how many of them are suppressed, and a few sample addresses.
	//
	//op: POST count scope=bulkmail:read
	Count(ctx context.Context, a extkit.Auth, in CountInput) (CountResult, error)

	// Start queues a campaign's recipients and starts sending (Limit > 0: at most that many new recipients).
	//
	//op: POST start
	Start(ctx context.Context, a extkit.Auth, in StartInput) (Campaign, error)

	// Pause stops sending a campaign; Resume carries on.
	//
	//op: POST pause
	Pause(ctx context.Context, a extkit.Auth, in Ref) (Campaign, error)

	// Resume carries on sending a paused campaign.
	//
	//op: POST resume
	Resume(ctx context.Context, a extkit.Auth, in Ref) (Campaign, error)

	// Cancel stops a campaign for good; recipients not yet sent to are dropped.
	//
	//op: POST cancel
	Cancel(ctx context.Context, a extkit.Auth, in Ref) (Campaign, error)

	// Preview renders a campaign's message for one recipient (the first in its audience when Email is empty).
	//
	//op: POST preview scope=bulkmail:read
	Preview(ctx context.Context, a extkit.Auth, in PreviewInput) (Preview, error)

	// Test sends a campaign's message to one address, marked as a test.
	//
	//op: POST test
	Test(ctx context.Context, a extkit.Auth, in TestInput) (Sent, error)
}

Campaigns runs an app's bulk mail campaigns.

Client

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

Client is bulkmail/v1 over HTTP, for the CLI and other apps. It implements Campaigns; the token it was made with is the credential, so the extkit.Auth argument is ignored.

NewClient

func NewClient(baseURL, token string, hc *http.Client) *Client

NewClient calls bulkmail/v1 on the app at baseURL with token (a PocketBase auth token or an API token).

Client.Cancel

func (c *Client) Cancel(ctx context.Context, _ extkit.Auth, in Ref) (Campaign, error)

Client.Count

func (c *Client) Count(ctx context.Context, _ extkit.Auth, in CountInput) (CountResult, error)

Client.Pause

func (c *Client) Pause(ctx context.Context, _ extkit.Auth, in Ref) (Campaign, error)

Client.Preview

func (c *Client) Preview(ctx context.Context, _ extkit.Auth, in PreviewInput) (Preview, error)

Client.Resume

func (c *Client) Resume(ctx context.Context, _ extkit.Auth, in Ref) (Campaign, error)

Client.Start

func (c *Client) Start(ctx context.Context, _ extkit.Auth, in StartInput) (Campaign, error)

Client.Test

func (c *Client) Test(ctx context.Context, _ extkit.Auth, in TestInput) (Sent, error)

CountInput

type CountInput struct {
	Audience json.RawMessage `json:"audience"`
}

CountInput is an audience, in the provider's audience shape (see its README).

CountResult

type CountResult struct {
	Count      int      `json:"count"`
	Suppressed int      `json:"suppressed"`
	Sample     []string `json:"sample"`
}

CountResult is an audience's size.

Preview

type Preview struct {
	To      string            `json:"to"`
	From    string            `json:"from"`
	Subject string            `json:"subject"`
	HTML    string            `json:"html"`
	Text    string            `json:"text"`
	Headers map[string]string `json:"headers"`
}

Preview is a rendered message.

PreviewInput

type PreviewInput struct {
	Campaign string `json:"campaign"`
	Email    string `json:"email,omitempty"`
}

PreviewInput picks the recipient to render for.

Ref

type Ref struct {
	Campaign string `json:"campaign"`
}

Ref names a campaign (its record id).

Sent

type Sent struct {
	Sent bool `json:"sent"`
}

Sent says a message went out.

StartInput

type StartInput struct {
	Campaign string `json:"campaign"`
	Limit    int    `json:"limit,omitempty"`
}

StartInput starts a campaign.

TestInput

type TestInput struct {
	Campaign string `json:"campaign"`
	To       string `json:"to"`
}

TestInput is where a test message goes.