pages

package
v0.235.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 26 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pages is shareable pages (migration 0116; docs/pages.md, design docs/design/pages.md): a page an agent writes for its owner, its immutable versions, the share links that let someone without a muster account open it, and what those viewers send back.

🔴 THIS PACKAGE IMPORTS NOTHING OF internal/api OR internal/ui. It is the model (spec, validation, limits), the store and the renderer (the content document, the shell, the SDK). The routes, tools and the owner's approval live in internal/api as a thin layer over Store, so serving could move to a separate host later without touching this package (the design's "core, not a plugin").

🔴 PAGE CONTENT IS UNTRUSTED, WHOEVER RENDERS IT. Blocks are an agent's words and script; responses are a stranger's. The content document is served with ContentHeaders (an opaque origin by HTTP header, no network), and what muster itself draws from either is HTML-escaped.

Index

Constants

View Source
const (
	// MaxVersionBytes bounds one version's blocks as JSON (0116's CHECK).
	MaxVersionBytes = 512 << 10
	// MaxBlocks bounds a version's block count.
	MaxBlocks = 100
	// MaxHTMLBytes bounds one html block.
	MaxHTMLBytes = 256 << 10
	// MaxMarkdownBytes bounds one markdown block.
	MaxMarkdownBytes = 64 << 10
	// MaxSubmitBytes bounds a submit's data as JSON.
	MaxSubmitBytes = 32 << 10
	// MaxTitleRunes bounds a page's title (0116's CHECK).
	MaxTitleRunes = 200
)

The limits (docs/design/pages.md#limits-and-quotas). Vars where a test lowers them.

View Source
const (
	BlockMarkdown = "markdown"
	BlockQuestion = "question"
	BlockChoice   = "choice"
	BlockForm     = "form"
	BlockUpload   = "upload"
	BlockApproval = "approval"
	BlockHTML     = "html"
)

The block types (docs/pages.md#blocks).

View Source
const (
	FieldText     = "text"
	FieldTextarea = "textarea"
	FieldEmail    = "email"
	FieldNumber   = "number"
	FieldDate     = "date"
	FieldSelect   = "select"
	FieldCheckbox = "checkbox"
)

The form field types.

View Source
const ContentCSP = "sandbox allow-scripts allow-forms; default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; " +
	"img-src data: blob:; media-src data: blob:; font-src data:; connect-src 'none'; form-action 'none'; base-uri 'none'; frame-ancestors 'self'"

ContentCSP is the content document's Content-Security-Policy.

View Source
const ContentPermissionsPolicy = "camera=(), microphone=(), geolocation=(), display-capture=(), usb=(), payment=()"

ContentPermissionsPolicy denies the content document every powerful feature (the app's own policy grants the microphone to muster's pages).

View Source
const CustomComponent = "custom"

CustomComponent is the component a custom script's muster.submit and muster.upload name by default. It is accepted only by a version with an html block, and no block may be called it.

View Source
const DefaultUploadBytesPerPage int64 = 500 << 20

DefaultUploadBytesPerPage bounds the files one page may hold in all (MUSTER_PAGES_UPLOAD_BYTES overrides it): 500 MiB.

View Source
const LinkKeySize = 32

LinkKeySize is the length of the master key WithLinkKey takes: the connector store's (MUSTER_CONNECTOR_ENCRYPTION_KEY), which the link sealer derives its own key from.

View Source
const SharePrefix = "/s/"

SharePrefix begins every share-link path (the shell, its content and its two writes). The access log writes it as SharePrefix + "[redacted]".

Variables

View Source
var (
	// MaxVersionsPerPage bounds a page's versions.
	MaxVersionsPerPage = 100
	// MaxPagesPerOwner bounds an owner's pages.
	MaxPagesPerOwner = 200
	// MaxOpenLinksPerPage bounds a page's pending and live links together.
	MaxOpenLinksPerPage = 10
	// MaxResponsesPerLink bounds what one link may record, uploads included.
	MaxResponsesPerLink = 1000
	// MaxUploadsPerLink bounds the files one link may record.
	MaxUploadsPerLink = 50
)
View Source
var (
	ErrNotFound = errors.New("pages: no such page")
	// ErrLinkNotFound is a link that is unknown, not live, or expired: one
	// answer for all of them.
	ErrLinkNotFound = errors.New("pages: no such link")
	ErrInvalid      = errors.New("pages: invalid")
	// ErrTooMany is a cap reached (pages, versions, links, responses).
	ErrTooMany = errors.New("pages: too many")
	// ErrNotPending is a decision on a link that is no longer pending.
	ErrNotPending = errors.New("pages: that link is no longer waiting for a decision")
	// ErrLinkUnreadable is a page's reusable link whose sealed token does not
	// open (the server's key changed): it still serves, but its address cannot
	// be shown again — make a new link (RotateShareLink).
	ErrLinkUnreadable = errors.New("pages: this page's link can no longer be shown (the server's encryption key changed); make a new link")
	// ErrClosing is a new link asked of a page whose delete has begun
	// (CloseLinks ran): it gets none — press Delete again to finish it.
	ErrClosing = errors.New("pages: this page is being deleted; it takes no new link")
)

The errors a caller turns into words. Every "not yours" reads as ErrNotFound, exactly as a missing id.

View Source
var ErrNoLinkKey = errors.New("pages: this server keeps no reusable links (MUSTER_CONNECTOR_ENCRYPTION_KEY is unset)")

ErrNoLinkKey is a reusable link asked of a store that keeps none: this server has no encryption key, so a link's address cannot be kept.

Functions

func CheckSubmit

func CheckSubmit(blocks []Block, component string, data json.RawMessage) (json.RawMessage, error)

CheckSubmit checks a viewer's submit to component of blocks and returns its data as stored (normalised JSON). The component must be one of the blocks' (or CustomComponent on a version with an html block, whose data is any JSON up to MaxSubmitBytes), and the data must be what that component sends.

func CleanTitle

func CleanTitle(s string) (string, error)

CleanTitle trims a title and checks it: 1 to MaxTitleRunes characters, no control or text-direction characters.

func Content

func Content(v Version, o RenderOptions) string

Content is the content document of version v: muster's base styles, the SDK, then every block. It is served with ContentHeaders.

func ContentHeaders

func ContentHeaders() map[string]string

ContentHeaders is every header a content document is served with, exactly.

func HasHTML

func HasHTML(blocks []Block) bool

HasHTML reports whether blocks hold an html block (so custom script may submit as CustomComponent).

func LinkPath

func LinkPath(token string) string

LinkPath is the shell's path for token.

func NewNonce

func NewNonce() string

NewNonce is a fresh CSP nonce.

func NewToken

func NewToken() (string, error)

NewToken is a fresh link token: 32 random bytes, base64url without padding (43 characters).

func SetContentHeaders

func SetContentHeaders(h http.Header)

SetContentHeaders sets ContentHeaders on h, REPLACING whatever the app's middleware set (its page CSP allows script from 'self' with the origin intact; this one does not).

func SetShellHeaders

func SetShellHeaders(h http.Header, nonce string)

SetShellHeaders sets ShellHeaders on h.

func Shell

func Shell(v ShellView) string

Shell is the shell document: the instance branding, the title, the sandboxed frame of the content and the relay script (ShellScript).

func ShellCSP

func ShellCSP(nonce string) string

ShellCSP is the shell's Content-Security-Policy for a script nonce: its one script, its own styles, the brand logo, and frames of this origin only.

func ShellHeaders

func ShellHeaders(nonce string) map[string]string

ShellHeaders is every header the shell is served with, for nonce.

func ShellScript

func ShellScript(base string) string

ShellScript is the relay (docs/design/pages.md#how-the-sdk-talks-to-muster-postmessage-to-the-shell): a message from the shell's OWN frame asking to submit or upload is sent to base+"/submit" or base+"/upload" with credentials omitted, and the answer posted back. base "" (a preview) answers every message as a preview.

🔴 THE SHELL IS THE ONLY CODE ON MUSTER'S ORIGIN A VIEWER RUNS, SO IT TRUSTS NOTHING IT IS SENT: it accepts only its own frame's window, two ops, and sends only the component name, the data as JSON, or a Blob, to two fixed routes that authenticate by the link alone.

func TokenHash

func TokenHash(token string) string

TokenHash is the lookup key of token: its sha256, lower-case hex.

func TokenShapeOK

func TokenShapeOK(s string) bool

TokenShapeOK reports whether s is shaped like a link token. A request whose token is not is refused before any lookup.

func UploadTarget

func UploadTarget(blocks []Block, component string) bool

UploadTarget reports whether a file may be uploaded as component of blocks: an upload block's id, or CustomComponent on a version with an html block.

func ValidComponent

func ValidComponent(s string) bool

ValidComponent reports whether s is shaped like a component id (0116's CHECK on page_responses.component is the same shape, CustomComponent included).

Types

type Block

type Block struct {
	Type string `json:"type"`
	// ID names a component (every type but markdown and html): what a submit
	// and a response carry. Unique within a version.
	ID    string `json:"id,omitempty"`
	Label string `json:"label,omitempty"`
	// Text is a markdown block's source.
	Text string `json:"text,omitempty"`
	// HTML is an html block's markup and script, served verbatim inside the
	// sandbox.
	HTML string `json:"html,omitempty"`
	// Required: a question's answer, a choice's pick.
	Required bool `json:"required,omitempty"`
	// Multiline: a question's box is a textarea.
	Multiline bool `json:"multiline,omitempty"`
	// Options are a choice's answers.
	Options []string `json:"options,omitempty"`
	// Multiple: a choice takes several answers; an upload several files.
	Multiple bool `json:"multiple,omitempty"`
	// Fields are a form's fields.
	Fields []Field `json:"fields,omitempty"`
	// SubmitLabel is a component's button text ("Send" when empty).
	SubmitLabel string `json:"submit_label,omitempty"`
	// Comment: an approval also takes a comment.
	Comment bool `json:"comment,omitempty"`
}

Block is one block of a version. Which fields a block reads depends on its Type; Parse refuses a field its type does not read, so an agent is told rather than silently ignored.

func Find

func Find(blocks []Block, id string) (Block, bool)

Find is the component block named id, if blocks have one.

func Parse

func Parse(raw []byte) ([]Block, int, error)

Parse reads a version's blocks from raw (a JSON array), refusing an unknown field, and validates them (Validate). It returns the blocks and their size as stored.

func Validate

func Validate(blocks []Block) ([]Block, int, error)

Validate checks blocks — each block's fields, component ids unique and not "custom", the counts and the size — and returns them with their size as stored (their JSON).

type Creator

type Creator struct {
	AgentID    int64
	MirrorHost string
	Label      string
}

Creator is who made a page, and so who a tool may act on it as: a dispatched agent (AgentID) or a mirrored session's HOST (MirrorHost — what a mirror token proves; the session id is the caller's claim). Exactly one is set. Label is the name the owner sees.

func (Creator) Valid

func (c Creator) Valid() bool

Valid reports whether c names exactly one creator.

type Field

type Field struct {
	Name     string   `json:"name"`
	Label    string   `json:"label,omitempty"`
	Type     string   `json:"type"`
	Required bool     `json:"required,omitempty"`
	Options  []string `json:"options,omitempty"`
}

Field is one form field.

type Link struct {
	ID          int64
	OwnerID     int64
	PageID      int64
	Token       string
	TokenSHA256 string
	State       LinkState
	AskID       int64
	RequestedBy string
	// Reusable: the page's one link the owner's Share hands out every time
	// (migration 0135). Its token is kept sealed while it is live, so
	// ShareLink can show the address again; a link that is not reusable is
	// hash-only, and its address was shown once.
	Reusable bool
	// ByAgent: an agent made it (its request), not the owner.
	ByAgent   bool
	CreatedAt time.Time
	DecidedAt *time.Time
}

Link is one share link.

🔴 ITS TOKEN IS NOT STORED IN THE CLEAR. Token is set only on the Link CreateLink returns — for a hash-only link the one moment the token exists outside a request — on the Link LinkByToken returns (the presented token, already matched), and on a REUSABLE link ShareLink, RotateShareLink or ShareLinks returns (opened from its sealed copy, seal.go); every other read leaves it "". TokenSHA256 is the lookup key.

func (Link) Label

func (l Link) Label() string

Label is a link's short, non-secret name for its owner: when it was made and the first 8 hex digits of its token's hash ("created 2026-11-11 14:02 UTC · 3fa9c2e1"). The hash prefix tells two links apart; it is no part of the token and opens nothing.

type LinkState

type LinkState string

LinkState is a share link's state.

const (
	// LinkPending: an agent asked; the owner has not decided. Serves nothing.
	LinkPending LinkState = "pending"
	// LinkLive: approved (or minted by the owner). Serves the current version.
	LinkLive LinkState = "live"
	// LinkDenied: the owner said no. Serves nothing, ever.
	LinkDenied LinkState = "denied"
	// LinkRevoked: was live, and was revoked. Serves nothing, ever.
	LinkRevoked LinkState = "revoked"
)

type PGStore

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

PGStore is Store on Postgres.

func NewPG

func NewPG(pool *pgxpool.Pool) *PGStore

NewPG returns a Store on pool.

func (*PGStore) AddResponse

func (s *PGStore) AddResponse(ctx context.Context, l Link, v int, component string, kind ResponseKind, data []byte, uploadID string) (Response, error)

AddResponse records one response under the link row's lock (its caps). The link must still be live: a link revoked while the request was in flight records nothing.

func (*PGStore) AddVersion

func (s *PGStore) AddVersion(ctx context.Context, c Creator, id int64, title string, blocks []Block, size int) (Page, Version, error)

AddVersion adds the next version under the page row's lock.

func (s *PGStore) CloseLinks(ctx context.Context, id int64) ([]Link, error)

CloseLinks revokes a page's open links.

func (*PGStore) Create

func (s *PGStore) Create(ctx context.Context, c Creator, title string, blocks []Block, size int) (Page, Version, error)

Create inserts the page and its version 1 in one transaction.

func (s *PGStore) CreateLink(ctx context.Context, id int64, state LinkState, requestedBy string, byAgent bool) (Link, error)

CreateLink files a link under the page row's lock (the open-link cap).

func (s *PGStore) DecideLink(ctx context.Context, linkID int64, live bool) (Link, error)

DecideLink moves a pending link, once.

func (*PGStore) Delete

func (s *PGStore) Delete(ctx context.Context, id int64) ([]Link, error)

Delete deletes a page and returns its links that were pending.

func (*PGStore) Files

func (s *PGStore) Files(ctx context.Context, id int64) ([]string, error)

Files lists a page's uploaded files.

func (s *PGStore) Link(ctx context.Context, id, linkID int64) (Link, error)

Link reads one link of a page.

func (*PGStore) LinkByAsk

func (s *PGStore) LinkByAsk(ctx context.Context, askID int64) (Link, error)

LinkByAsk reads the link a card decides.

func (*PGStore) LinkByToken

func (s *PGStore) LinkByToken(ctx context.Context, token string) (Link, error)

LinkByToken reads one live link by its token's hash, under the system principal (sys). The token's shape is checked first, so a malformed one never reaches the database.

func (s *PGStore) Links(ctx context.Context, id int64) ([]Link, error)

Links lists a page's links.

func (*PGStore) LinksReusable added in v0.232.0

func (s *PGStore) LinksReusable() bool

LinksReusable reports whether the store holds a key.

func (*PGStore) Page

func (s *PGStore) Page(ctx context.Context, id int64) (Page, error)

Page reads the caller's page.

func (*PGStore) PageFor

func (s *PGStore) PageFor(ctx context.Context, c Creator, id int64) (Page, error)

PageFor reads c's page.

func (*PGStore) Pages

func (s *PGStore) Pages(ctx context.Context) ([]Summary, error)

Pages lists the caller's pages.

func (*PGStore) PagesFor

func (s *PGStore) PagesFor(ctx context.Context, c Creator) ([]Summary, error)

PagesFor lists c's pages.

func (*PGStore) Responses

func (s *PGStore) Responses(ctx context.Context, id, after int64, limit int) ([]Response, error)

Responses reads a page's responses after an id.

func (s *PGStore) RevokeLink(ctx context.Context, id, linkID int64) (Link, error)

RevokeLink revokes a pending or live link; a denied or revoked one is returned as it is.

func (s *PGStore) RevokeShareLink(ctx context.Context, id int64) (Link, error)

RevokeShareLink revokes the page's live reusable link.

func (s *PGStore) RotateShareLink(ctx context.Context, id int64, requestedBy string) (Link, []Link, error)

RotateShareLink revokes the page's reusable link and makes a new one.

func (*PGStore) SetCurrent

func (s *PGStore) SetCurrent(ctx context.Context, id int64, v int) (Page, error)

SetCurrent moves the page's current version to v, which must exist.

func (*PGStore) SetLinkAsk

func (s *PGStore) SetLinkAsk(ctx context.Context, linkID, askID int64) error

SetLinkAsk records the deciding card.

func (s *PGStore) ShareLink(ctx context.Context, id int64, requestedBy string, byAgent bool) (Link, bool, error)

ShareLink returns the page's reusable link, making it when it has none.

func (s *PGStore) ShareLinks(ctx context.Context) (map[int64]Link, error)

ShareLinks reads every live reusable link of the caller's, opened.

func (*PGStore) UploadBytes

func (s *PGStore) UploadBytes(ctx context.Context, id int64) (int64, error)

UploadBytes sums a page's live files (uploads is the owner's table too, so row-level security scopes both sides of the join).

func (*PGStore) Version

func (s *PGStore) Version(ctx context.Context, id int64, v int) (Version, error)

Version reads one version, blocks included; v 0 is the page's current one.

func (*PGStore) Versions

func (s *PGStore) Versions(ctx context.Context, id int64) ([]Version, error)

Versions lists a page's versions without their blocks.

func (*PGStore) WithLinkKey added in v0.232.0

func (s *PGStore) WithLinkKey(master []byte) (*PGStore, error)

WithLinkKey gives the store the master key reusable links are sealed under (MUSTER_CONNECTOR_ENCRYPTION_KEY's bytes). Without it the store makes only hash-only links.

type Page

type Page struct {
	ID             int64
	OwnerID        int64
	Title          string
	CurrentVersion int
	Creator        Creator
	CreatedAt      time.Time
	UpdatedAt      time.Time
}

Page is one page.

type RenderOptions

type RenderOptions struct {
	// Markdown renders a markdown block to SAFE HTML (every author character
	// escaped; only the renderer's own tags). nil shows the source as text.
	Markdown func(string) string
	// Preview: the owner's preview. The SDK records nothing and says so.
	Preview bool
	// Uploads: the server can store files. Without it an upload block is drawn
	// disabled, saying so.
	Uploads bool
}

RenderOptions is what Content needs beyond the version.

type Response

type Response struct {
	ID             int64
	PageID         int64
	LinkID         int64
	Version        int
	Component      string
	Kind           ResponseKind
	Data           []byte // JSON; "{}" for an upload
	UploadPublicID string
	CreatedAt      time.Time
}

Response is one thing a viewer sent.

type ResponseKind

type ResponseKind string

ResponseKind is what a response is.

const (
	// KindSubmit is a component's (or custom script's) submit: Data.
	KindSubmit ResponseKind = "submit"
	// KindUpload is a file: UploadPublicID names the uploads row.
	KindUpload ResponseKind = "upload"
)

type ShellView

type ShellView struct {
	// Title is the page's title (an agent's words, escaped here).
	Title string
	// BrandName and BrandLogo are the instance's branding as every branded
	// surface draws it (ui.Brand): the name drawn beside the logo ("" when none
	// is set, or the logo already spells it — Brand.DrawsName), the logo's URL
	// ("" for none) and its alt text (Brand.LogoAlt). No muster mark is drawn
	// without them.
	BrandName    string
	BrandLogoAlt string
	// Icon is the page's favicon and touch icon (Brand.Icon192: the
	// instance's app icon or logo icon, muster's own when none is set).
	Icon string
	// FrameSrc is the content document's path.
	FrameSrc string
	// Base is the path the relay posts to (Base+"/submit", Base+"/upload");
	// "" in a preview, which relays nothing.
	Base string
	// Nonce is the script's CSP nonce (ShellCSP).
	Nonce string
	// Banner, when set, is a line above the frame (the owner's preview says
	// what it is).
	Banner string
}

ShellView is what the shell draws.

type Store

type Store interface {
	// Create makes a page with version 1. ErrTooMany past MaxPagesPerOwner.
	Create(ctx context.Context, c Creator, title string, blocks []Block, size int) (Page, Version, error)
	// AddVersion adds the next version of c's page id and makes it current.
	// ErrTooMany past MaxVersionsPerPage.
	AddVersion(ctx context.Context, c Creator, id int64, title string, blocks []Block, size int) (Page, Version, error)
	// PageFor is c's page id.
	PageFor(ctx context.Context, c Creator, id int64) (Page, error)
	// PagesFor is c's pages, newest activity first.
	PagesFor(ctx context.Context, c Creator) ([]Summary, error)
	// Page is the caller's page id (any creator's).
	Page(ctx context.Context, id int64) (Page, error)
	// Pages is the caller's pages, newest activity first.
	Pages(ctx context.Context) ([]Summary, error)
	// Versions is page id's versions, newest first, without their blocks.
	Versions(ctx context.Context, id int64) ([]Version, error)
	// Version is version v of page id; v 0 is the current one.
	Version(ctx context.Context, id int64, v int) (Version, error)
	// SetCurrent makes version v current (a rollback).
	SetCurrent(ctx context.Context, id int64, v int) (Page, error)
	// Files is the public ids of every file sent through page id's links
	// (its upload responses): what deleting the page must delete first.
	Files(ctx context.Context, id int64) ([]string, error)
	// CloseLinks revokes every pending or live link of page id, under the page
	// row's lock, and returns them (their cards are the caller's to withdraw).
	// From its commit on, no response — no upload — is recorded through any
	// of them (AddResponse re-reads the link's state under its own lock), and
	// the page takes no NEW link (every link maker answers ErrClosing).
	CloseLinks(ctx context.Context, id int64) ([]Link, error)
	// UploadBytes is the size of every file page id holds now (its upload
	// responses' files, not revoked).
	UploadBytes(ctx context.Context, id int64) (int64, error)
	// Delete deletes page id, and with it every version, link and response
	// (the composite keys cascade). It returns the links that were still
	// pending, whose owner cards the caller withdraws.
	Delete(ctx context.Context, id int64) ([]Link, error)

	// CreateLink files a hash-only link to page id in state (LinkPending or
	// LinkLive), asked for by requestedBy (an agent when byAgent). ErrTooMany
	// past MaxOpenLinksPerPage.
	CreateLink(ctx context.Context, id int64, state LinkState, requestedBy string, byAgent bool) (Link, error)
	// LinksReusable reports whether this store keeps reusable links (it holds
	// an encryption key: WithLinkKey).
	LinksReusable() bool
	// ShareLink is page id's REUSABLE live link, its Token set: the one it has,
	// or — when it has none — a new one made by requestedBy (created true).
	// ErrNoLinkKey without a key; ErrLinkUnreadable when the one it has does
	// not open; ErrTooMany past MaxOpenLinksPerPage.
	ShareLink(ctx context.Context, id int64, requestedBy string, byAgent bool) (l Link, created bool, err error)
	// RotateShareLink revokes page id's reusable link (if it has one) and makes
	// a new one, in one transaction. It returns the new link and the revoked.
	RotateShareLink(ctx context.Context, id int64, requestedBy string) (Link, []Link, error)
	// RevokeShareLink revokes page id's reusable link (ErrLinkNotFound when it
	// has none live).
	RevokeShareLink(ctx context.Context, id int64) (Link, error)
	// ShareLinks is the live reusable link of each of the caller's pages that
	// has one, Token set, by page id. A link whose token does not open is left
	// out (its page reads as unshared, and Share says why).
	ShareLinks(ctx context.Context) (map[int64]Link, error)
	// SetLinkAsk records the owner card that decides pending link id.
	SetLinkAsk(ctx context.Context, linkID, askID int64) error
	// Links is page id's links, newest first.
	Links(ctx context.Context, id int64) ([]Link, error)
	// Link is link linkID of page id.
	Link(ctx context.Context, id, linkID int64) (Link, error)
	// LinkByAsk is the link the owner card askID decides.
	LinkByAsk(ctx context.Context, askID int64) (Link, error)
	// DecideLink moves pending link linkID to live or denied (ErrNotPending
	// when it is not pending).
	DecideLink(ctx context.Context, linkID int64, live bool) (Link, error)
	// RevokeLink revokes link linkID of page id (pending or live); revoking
	// twice is not an error.
	RevokeLink(ctx context.Context, id, linkID int64) (Link, error)
	// LinkByToken is the LIVE link token names, found by the token's sha256
	// and read with NO principal (authz.System): it is how a viewer's request
	// learns the owner it acts as. ErrLinkNotFound for anything else.
	LinkByToken(ctx context.Context, token string) (Link, error)

	// AddResponse records one response through link l at version v.
	// ErrTooMany past MaxResponsesPerLink, or MaxUploadsPerLink for an upload.
	AddResponse(ctx context.Context, l Link, v int, component string, kind ResponseKind, data []byte, uploadID string) (Response, error)
	// Responses is page id's responses with an id above after, oldest first,
	// at most limit.
	Responses(ctx context.Context, id, after int64, limit int) ([]Response, error)
}

Store is the pages tables (migration 0116).

🔴 EVERY METHOD BUT LinkByToken RUNS UNDER THE CALLER'S PRINCIPAL. The tables are under FORCE row-level security, so a request reads and writes only its own user's rows, and a new row's owner is the principal's user (owner_id's default), never a parameter. Another owner's page reads exactly as a missing one (ErrNotFound).

🔴 THE "…For" METHODS ARE ALSO SCOPED TO A CREATOR: a tool acts only on the pages its caller made (Creator), and another creator's page — the same owner's included — reads as missing.

type Summary

type Summary struct {
	Page
	Versions  int
	LiveLinks int
	Pending   int
	Responses int
}

Summary is a page as a list shows it: the page and its counts.

type Version

type Version struct {
	ID        int64
	PageID    int64
	Version   int
	Title     string
	Blocks    []Block
	SizeBytes int
	CreatedBy string
	CreatedAt time.Time
}

Version is one immutable version of a page.

Jump to

Keyboard shortcuts

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