feat(statuspages): email subscriptions, RSS feed and a JSON API
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / test (pull_request) Successful in 9m5s
ci / lint (pull_request) Successful in 10m24s
ci / build (pull_request) Successful in 18m10s
ci / image (pull_request) Successful in 5m16s
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / test (pull_request) Successful in 9m5s
ci / lint (pull_request) Successful in 10m24s
ci / build (pull_request) Successful in 18m10s
ci / image (pull_request) Successful in 5m16s
Visitors can subscribe to a page's incidents by email where the organization allows it. They confirm their address first; confirmation and unsubscribe links only show a button, so mail scanners do not act on them, and mails carry RFC 8058 one-click unsubscribe headers. Subscribers get a mail when an incident opens or resolves and for every public update. Every page also has an RSS feed of incidents and planned maintenance and a read-only JSON API (status, summary, components, incidents), both served from the cached snapshot. Abuse protection: status page servers limit feed and API reads, subscription requests and link actions per visitor; the API limits subscription requests per visitor, mailbox and page, and a new limit caps the subscriptions an organization's pages gain in seven days (platform default and per-organization override, 1000 in the cloud). Unconfirmed subscriptions count towards it and are deleted after a week. The fixed cap of 200 monitors per status page is gone; the configurable limit alone decides. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
df39b765cb
commit
cca4e80e54
39 files changed
+4332
-1408
No files matched your search
@@ -0,0 +1,63 @@
|
||||
package agentapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Visitors of a status page subscribe to its incidents by email. The status
|
||||
// page server passes their requests on; the API checks its limits, mails
|
||||
// the confirmation and later the incidents.
|
||||
|
||||
// SubscribeRequest asks for an email subscription to the page at Host, or
|
||||
// Slug if Host is empty.
|
||||
type SubscribeRequest struct {
|
||||
Host string `json:"host,omitempty"`
|
||||
Slug string `json:"slug,omitempty"`
|
||||
Email string `json:"email"`
|
||||
// IP is the visitor's address, for rate limits.
|
||||
IP string `json:"ip"`
|
||||
// Locale is the language of the mails, as the visitor's browser asks.
|
||||
Locale string `json:"locale,omitempty"`
|
||||
// PageURL is where the visitor saw the page, ending in "/". The API
|
||||
// uses it for the links in mails only where it does not know the
|
||||
// page's address itself.
|
||||
PageURL string `json:"page_url,omitempty"`
|
||||
}
|
||||
|
||||
// SubscriptionInfo describes a subscription that was confirmed or ended.
|
||||
type SubscriptionInfo struct {
|
||||
PageTitle string `json:"page_title"`
|
||||
Email string `json:"email"`
|
||||
}
|
||||
|
||||
// ErrInvalidInput means the API refused the request's content, e.g. an
|
||||
// email address that is none.
|
||||
var ErrInvalidInput = errors.New("agentapi: invalid input")
|
||||
|
||||
type tokenRequest struct {
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
// Subscribe asks for a subscription and has the confirmation mailed. It
|
||||
// succeeds whether or not the address was subscribed already, so it tells
|
||||
// nobody who is. ErrRateLimited means a limit was reached, ErrNotFound
|
||||
// that the page takes no subscriptions.
|
||||
func (c *Client) Subscribe(ctx context.Context, r SubscribeRequest) error {
|
||||
return c.do(ctx, http.MethodPost, "/subscriptions", r, nil)
|
||||
}
|
||||
|
||||
// ConfirmSubscription confirms the subscription token was mailed for.
|
||||
func (c *Client) ConfirmSubscription(ctx context.Context, token string) (SubscriptionInfo, error) {
|
||||
var out SubscriptionInfo
|
||||
err := c.do(ctx, http.MethodPost, "/subscriptions/confirm", tokenRequest{token}, &out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// Unsubscribe ends the subscription of an unsubscribe token.
|
||||
func (c *Client) Unsubscribe(ctx context.Context, token string) (SubscriptionInfo, error) {
|
||||
var out SubscriptionInfo
|
||||
err := c.do(ctx, http.MethodPost, "/subscriptions/unsubscribe", tokenRequest{token}, &out)
|
||||
return out, err
|
||||
}
|
||||
Reference in new issue
Block a user