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
- Variables
- func CheckSubmit(blocks []Block, component string, data json.RawMessage) (json.RawMessage, error)
- func CleanTitle(s string) (string, error)
- func Content(v Version, o RenderOptions) string
- func ContentHeaders() map[string]string
- func CutRunes(s string, n int) string
- func HasHTML(blocks []Block) bool
- func LinkPath(token string) string
- func NewNonce() string
- func NewToken() (string, error)
- func SetContentHeaders(h http.Header)
- func SetShellHeaders(h http.Header, nonce string)
- func Shell(v ShellView) string
- func ShellCSP(nonce string) string
- func ShellHeaders(nonce string) map[string]string
- func ShellScript(base string, owner bool) string
- func TokenHash(token string) string
- func TokenShapeOK(s string) bool
- func UploadHeading(blocks []Block, component string) string
- func UploadTarget(blocks []Block, component string) bool
- func ValidComponent(s string) bool
- type Answer
- type AnswerLine
- type Block
- type Creator
- type Field
- type Link
- type LinkState
- type OwnerChrome
- type PGStore
- func (s *PGStore) AddOwnerResponse(ctx context.Context, id int64, v int, component string, kind ResponseKind, ...) (Response, error)
- func (s *PGStore) AddResponse(ctx context.Context, l Link, v int, component string, kind ResponseKind, ...) (Response, error)
- func (s *PGStore) AddVersion(ctx context.Context, c Creator, id int64, title string, blocks []Block, ...) (Page, Version, error)
- func (s *PGStore) CloseLinks(ctx context.Context, id int64) ([]Link, error)
- func (s *PGStore) Create(ctx context.Context, c Creator, title string, blocks []Block, size int) (Page, Version, error)
- func (s *PGStore) CreateLink(ctx context.Context, id int64, state LinkState, requestedBy string, ...) (Link, error)
- func (s *PGStore) DecideLink(ctx context.Context, linkID int64, live bool) (Link, error)
- func (s *PGStore) Delete(ctx context.Context, id int64) ([]Link, error)
- func (s *PGStore) Files(ctx context.Context, id int64) ([]string, error)
- func (s *PGStore) Link(ctx context.Context, id, linkID int64) (Link, error)
- func (s *PGStore) LinkByAsk(ctx context.Context, askID int64) (Link, error)
- func (s *PGStore) LinkByToken(ctx context.Context, token string) (Link, error)
- func (s *PGStore) Links(ctx context.Context, id int64) ([]Link, error)
- func (s *PGStore) LinksReusable() bool
- func (s *PGStore) Page(ctx context.Context, id int64) (Page, error)
- func (s *PGStore) PageFor(ctx context.Context, c Creator, id int64) (Page, error)
- func (s *PGStore) Pages(ctx context.Context) ([]Summary, error)
- func (s *PGStore) PagesFor(ctx context.Context, c Creator) ([]Summary, error)
- func (s *PGStore) Responses(ctx context.Context, id, after int64, limit int) ([]Response, error)
- func (s *PGStore) ResponsesBefore(ctx context.Context, id, before int64, limit int) ([]Response, error)
- func (s *PGStore) RevokeLink(ctx context.Context, id, linkID int64) (Link, error)
- func (s *PGStore) RevokeShareLink(ctx context.Context, id int64) (Link, error)
- func (s *PGStore) RotateShareLink(ctx context.Context, id int64, requestedBy string) (Link, []Link, error)
- func (s *PGStore) SetCurrent(ctx context.Context, id int64, v int) (Page, error)
- func (s *PGStore) SetLinkAsk(ctx context.Context, linkID, askID int64) error
- func (s *PGStore) ShareLink(ctx context.Context, id int64, requestedBy string, byAgent bool) (Link, bool, error)
- func (s *PGStore) ShareLinks(ctx context.Context) (map[int64]Link, error)
- func (s *PGStore) UploadBytes(ctx context.Context, id int64) (int64, error)
- func (s *PGStore) Version(ctx context.Context, id int64, v int) (Version, error)
- func (s *PGStore) Versions(ctx context.Context, id int64) ([]Version, error)
- func (s *PGStore) WithLinkKey(master []byte) (*PGStore, error)
- type Page
- type RenderOptions
- type Response
- type ResponseKind
- type ShellVersion
- type ShellView
- type Store
- type Summary
- type Version
Constants ¶
const ( // MaxVersionBytes bounds one version's blocks as JSON (0116's CHECK). MaxVersionBytes = 512 << 10 // MaxBlocksInputBytes bounds the blocks as a REQUEST carries them, before // they are parsed (Parse): twice MaxVersionBytes, because the caller's // encoder is not Go's. The stored size is Go's re-encoding (Validate), // which writes non-ASCII as raw UTF-8 but escapes <, > and & as \u003c (6 // bytes each), so JavaScript's JSON.stringify, which escapes less, is no // larger than the stored form for well-formed text. An encoder that writes // non-ASCII as \uXXXX (Python's json.dumps default) can be larger: at // worst 3x, a 2-byte UTF-8 letter as a 6-byte escape (measured: "é" is 2 // bytes in Go's encoding and 6 in Python's; an emoji 4 and 12, a surrogate // pair; "<" 6 in Go's and 1 in Python's and JSON.stringify's). Base64 // data: URIs are ASCII and the same size in every encoder, so a page of // inline screenshots is ~1x. Past this the blocks are refused unread with // the page's own error ("larger than 512 KiB"). Every MCP hop's body // bound is derived from it (mirror.MaxMCPRequestBytes). MaxBlocksInputBytes = 2 * MaxVersionBytes // 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.
const ( BlockMarkdown = "markdown" BlockQuestion = "question" BlockChoice = "choice" BlockForm = "form" BlockUpload = "upload" BlockApproval = "approval" BlockHTML = "html" )
The block types (docs/pages.md#blocks).
const ( FieldText = "text" FieldTextarea = "textarea" FieldEmail = "email" FieldNumber = "number" FieldDate = "date" FieldSelect = "select" FieldCheckbox = "checkbox" )
The form field types.
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.
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).
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.
const DefaultUploadBytesPerPage int64 = 500 << 20
DefaultUploadBytesPerPage bounds the files one page may hold in all (MUSTER_PAGES_UPLOAD_BYTES overrides it): 500 MiB.
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.
SharePrefix begins every share-link path (the shell, its content and its two writes). The access log writes it as SharePrefix + "[redacted]".
Variables ¶
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 )
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") // ErrResponseTooLarge is a response its stored form is too large to keep // (the data column's CHECK), whatever its JSON text's size. ErrResponseTooLarge = errors.New("pages: response too large") )
The errors a caller turns into words. Every "not yours" reads as ErrNotFound, exactly as a missing id.
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 ¶
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. A link's viewer and the page's owner get the SAME document: whose a response is, is the shell's route's to say (ShellScript), never the content's.
🔴 ITS THEME IS THE APP'S, AND IT IS THE SAME FOR EVERY VIEWER. The <html> carries contentThemeClass, as every document of the app does, and the stylesheet is the app's palette (contentThemeCSS); nothing about the viewer (a cookie, a header, the device's colour scheme) is read, so the document stays one document and no cache can hand one viewer's theme to another.
func ContentHeaders ¶
ContentHeaders is every header a content document is served with, exactly.
func CutRunes ¶ added in v0.249.0
CutRunes is cutRunes, for a caller outside the package (a page screen's raw ⓘ).
func HasHTML ¶
HasHTML reports whether blocks hold an html block (so custom script may submit as CustomComponent).
func NewToken ¶
NewToken is a fresh link token: 32 random bytes, base64url without padding (43 characters).
func SetContentHeaders ¶
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 ¶
SetShellHeaders sets ShellHeaders on h.
func Shell ¶
Shell is the shell document: the instance branding and the title in one slim header (and, for the owner, the version chip), the sandboxed frame of the content and the relay script (ShellScript).
func ShellCSP ¶
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 ¶
ShellHeaders is every header the shell is served with, for nonce.
func ShellScript ¶
ShellScript is the relay (docs/design/pages.md#how-the-sdk-talks-to-muster-postmessage-to-the-shell), the owner's confirm, and the header's hide-on-scroll.
🔴 THE SHELL IS THE ONLY CODE ON MUSTER'S ORIGIN A VIEWER RUNS, SO IT TRUSTS NOTHING IT IS SENT. From window messages it takes ONE thing: its own frame's first "hello", answered with a MessagePort (sdkScript holds it before any script of the page's runs). Everything else comes on that port or not at all. A send is checked on receipt, in the shell's own realm, on the shell's own structured-clone copy: a fixed field set; a submit's data normalised by a JSON round-trip (undefined dropped, a Date its ISO string, NaN null — what a link's viewer's sends always became) and then measured in BYTES against the server's cap; an upload's files 1 to 20 {file: Blob, name} pairs. That one copy is what is shown and what is posted.
A link's shell posts it at once, with credentials omitted (the link in base is the credential), as it always has.
🔴 THE OWNER'S SHELL (owner) POSTS NOTHING THE OWNER HAS NOT CONFIRMED HERE, in muster's own realm, where the page's script cannot reach (another origin, a sandboxed frame): a send opens the shell's "Send as you?" bar — the component and EVERY field, one per line, name and value as JSON with control, invisible and direction-changing characters escaped (show), so a newline cannot fake a second field nor U+202E reorder one; never cut (a summary over confirmMaxChars is refused, not shown in part); or the files' names and sizes — and only the owner's tap on its Send posts exactly that copy, with their session, same-origin (the route's own session and Origin checks; the same-origin referrer policy keeps a Referer for requireSameOrigin's fallback). Cancel, Escape (while the keyboard is in the shell: inside the frame the shell cannot see keys, and Cancel is the reliable path), or confirmWaitMs of nothing records nothing. Send is not focused when the bar opens (the bar itself is). A press of the bar within confirmGuardMs does nothing and starts the window again, so a burst of taps that opened the bar never reaches Send; Send then takes a press that begins on it after the window. One send waits at a time: another while the bar is open is answered "Another send is waiting for your answer." and dropped.
Requests go one at a time, in the order received; a several-file upload's files in turn, stopping at the first one refused.
🔴 THE HEADER IS THE BRAND, THE TRUST SIGNAL OF A SHARE LINK, AND A PAGE'S SCRIPT MUST NEVER BE ABLE TO KEEP IT HIDDEN FOR GOOD. It hides on a scroll down and returns on a scroll up, by these rules, and only these:
- it is visible on load (nothing hides it until a report arrives);
- a report at or near the top (y no more than the header's height) shows it;
- any report above the last one (a scroll up) shows it;
- only a report below the last one, past the header's height AND more than the header's height below where it last came back, hides it;
- keyboard focus inside it (CSS :focus-within) and the open version popover show it whatever the reports say;
- 🔴 and, needing nothing of the page: it comes back once no report FURTHER DOWN has arrived for revealMs, and in any case hideCapMs after it hid, whatever the reports say. So it is never hidden for longer than hideCapMs at a time, and after that only a fresh scroll down past its own height hides it again: a page creeping down by script a pixel at a time, re-dispatching scroll events, or scrolling an inner element cannot hold it.
The one op that moves it is "scroll" {y: a finite number >= 0}, and only on the port: a page's script posting one to the shell is ignored, as is one from any other window, and a y that is not such a number. TestTheShellHidesItsHeaderOnlyByTheRules and e2e pages.spec.ts.
func TokenShapeOK ¶
TokenShapeOK reports whether s is shaped like a link token. A request whose token is not is refused before any lookup.
func UploadHeading ¶ added in v0.249.0
UploadHeading names the upload part of blocks a file came through: its label, else "A file"; blocks nil (its version unread) is unreadVersionHeading.
func UploadTarget ¶
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 ¶
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 Answer ¶ added in v0.249.0
type Answer struct {
// Heading names the part of the page it was sent through: the block's own
// label, else what kind of part it is.
Heading string
Lines []AnswerLine
}
Answer is one response, described.
func DescribeAnswer ¶ added in v0.249.0
DescribeAnswer describes a submit (KindSubmit) response's data as the fields of blocks' component — blocks is the version it was sent through. A component the version does not have, or data that is not its shape, is described from the data alone (DescribeData).
blocks nil is a version that could not be read (no version has no blocks): the response is then "A response to an older version", from its data.
Every label, value and the heading are bounded (maxAnswerLabelRunes, maxAnswerValueRunes): the caller draws them as they come.
type AnswerLine ¶ added in v0.249.0
AnswerLine is one labelled value of a response.
func DescribeData ¶ added in v0.249.0
func DescribeData(v any) []AnswerLine
DescribeData is data no form defines (a page's own script's) as labelled lines: an object's keys as labels (a nested one's joined with " · "), a list of plain values joined with ", ", anything else as one "Value" line; past maxAnswerDepth levels, "(nested data)". At most maxAnswerLines lines; past that, one line says how many more. Linear in the data's size: the path is a slice joined only at a leaf, and nothing is re-encoded.
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.
type Creator ¶
type Creator struct {
AgentID int64
MirrorHost string
// MirrorSession is the mirrored session the page was made from — the
// caller's Claude Code session id (or opencode key), what the mirror
// MCP request bound to — recorded at create (0152) so the owner can open
// that session from the page. "" for an agent's page, and for a page
// made before it was recorded. It identifies; it never scopes: a tool
// acts on its HOST's pages (creatorClause), as before.
MirrorSession 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.
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 ¶
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.
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 OwnerChrome ¶ added in v0.248.0
type OwnerChrome struct {
// Version is the version the frame shows.
Version int
// Versions is every version, newest first.
Versions []ShellVersion
// DetailHref is the page's own screen (links, responses, delete).
DetailHref string
// SessionHref is where the session that made the page is NOW (internal/api
// pageSessionLink: a mirrored session's current window, or an agent's
// page), and SessionLabel its short name. "" when it cannot be resolved:
// then no session button and no "Made by" link are drawn — never a guess.
SessionHref string
SessionLabel string
// ShareButton is the page's Share button (ui.PageShareButton) and
// ShareScript its behaviour (ui.PageShareScript): the ONE share flow, the
// chat's and the Pages screens' own.
//
// 🔴 TRUSTED MARKUP AND SCRIPT, written as they are: muster's own
// renderer's output (every page-derived value in it escaped there), never
// a page's words.
}
OwnerChrome is what the owner's own view draws beyond a link's: the version chip and its popover.
type PGStore ¶
type PGStore struct {
// contains filtered or unexported fields
}
PGStore is Store on Postgres.
func (*PGStore) AddOwnerResponse ¶ added in v0.248.0
func (s *PGStore) AddOwnerResponse(ctx context.Context, id int64, v int, component string, kind ResponseKind, data []byte, uploadID string) (Response, error)
AddOwnerResponse records the owner's own response under the page row's lock (lockPage: a page being deleted takes none, as its links take none from CloseLinks on).
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 (*PGStore) CloseLinks ¶
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 (*PGStore) CreateLink ¶
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 (*PGStore) DecideLink ¶
DecideLink moves a pending link, once.
func (*PGStore) LinkByToken ¶
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 (*PGStore) LinksReusable ¶ added in v0.232.0
LinksReusable reports whether the store holds a key.
func (*PGStore) ResponsesBefore ¶ added in v0.249.0
func (s *PGStore) ResponsesBefore(ctx context.Context, id, before int64, limit int) ([]Response, error)
ResponsesBefore is page id's responses with an id below before, newest first, at most limit (1 to 500).
func (*PGStore) RevokeLink ¶
RevokeLink revokes a pending or live link; a denied or revoked one is returned as it is.
func (*PGStore) RevokeShareLink ¶ added in v0.232.0
RevokeShareLink revokes the page's live reusable link.
func (*PGStore) RotateShareLink ¶ added in v0.232.0
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 ¶
SetCurrent moves the page's current version to v, which must exist.
func (*PGStore) SetLinkAsk ¶
SetLinkAsk records the deciding card.
func (*PGStore) ShareLink ¶ added in v0.232.0
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 (*PGStore) ShareLinks ¶ added in v0.232.0
ShareLinks reads every live reusable link of the caller's, opened.
func (*PGStore) UploadBytes ¶
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 ¶
Version reads one version, blocks included; v 0 is the page's current one.
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
// 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 is the link it came through; 0 for the owner's (ByOwner).
LinkID int64
// ByOwner: the page's owner sent it from their own view of the page,
// signed in (migration 0152), not a viewer through a link.
ByOwner bool
Version int
Component string
Kind ResponseKind
Data []byte // JSON; "{}" for an upload
UploadPublicID string
CreatedAt time.Time
}
Response is one thing a viewer — or the page's owner — 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 ShellVersion ¶ added in v0.248.0
type ShellVersion struct {
Version int
// Made is when it was made, in words: the day ("today"), which
// ShareScript redraws in the reader's own zone with its time ("today at
// 9:14") from AtMS, when AtMS is set.
Made string
// AtMS is when it was made, in Unix milliseconds; 0 draws Made as it is.
AtMS int64
// Current: the page's current version (what its links show).
Current bool
// Href views it (/pages/{id}/view?v=N).
Href string
}
ShellVersion is one version as the popover lists it.
type ShellView ¶
type ShellView struct {
// Title is the page's title (an agent's words, escaped here). The header
// draws it on one line, truncated, with the whole of it in its title
// attribute.
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
BrandLogo 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").
Base string
// Nonce is the script's CSP nonce (ShellCSP).
Nonce string
// Owner is the page's signed-in OWNER's own view (/pages/{id}/view): the
// relay sends their session, and the header draws the version chip. nil
// for a link's viewer, who gets the same header without it.
Owner *OwnerChrome
}
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
// 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)
// 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)
// has none live).
RevokeShareLink(ctx context.Context, id int64) (Link, error)
// 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)
// AddOwnerResponse records one response the caller — page id's OWNER, from
// their own view — sent at version v (ByOwner, no link). The same caps as
// a link's, counted over the page's owner responses; ErrNotFound for a
// page the caller cannot see, ErrClosing for one being deleted.
AddOwnerResponse(ctx context.Context, id int64, 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)
// ResponsesBefore is page id's responses with an id below before (0: no
// bound), NEWEST first, at most limit (the owner's screen's pages).
ResponsesBefore(ctx context.Context, id, before 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.