The Payload Contract
Introduction
Payload v1 is stable. This page defines its node contract for renderers.
Payload v1 only grows: a later release may add keys, add values to open strings such as axis, or fill a key that is null today. Ignore keys you don't recognise, and skip a node whose kind you don't recognise.
Response Envelope
get() returns a collection whose JSON is a plain array of nodes, newest first (Ordering). cursorPaginate() and members() return Laravel's cursor paginator, with three keys after Laravel's own:
{
"data": [ /* activity nodes and group nodes, newest first */ ],
"path": "https://example.com/feed",
"per_page": 30,
// opaque string, or null at the end of the feed
"next_cursor": "eyJ...",
"next_page_url": "https://example.com/feed?cursor=eyJ...",
// null on the first page; points towards newer nodes on later pages
"prev_cursor": null,
"prev_page_url": null,
"payload_version": 1,
// opaque string, or null
"sync_token": "01J3…",
// the page's media map; see Page Media Map
"media": { "m3f2a9c41d07e6b58": { "link": { /* … */ }, "media": { /* … */ } } },
// the page's entity map; see Page Entity Map
"entities": { "e9b41c07d2a6f3e58": { "type": "delivery", "id": "42", /* … */ } }
}simplePaginate() returns Laravel's simple paginator, with the nodes in data and the same three keys after Laravel's.
Its keys are current_page, current_page_url, data, first_page_url, from, next_page_url, path, per_page, prev_page_url, to, payload_version, sync_token, media and entities. There is no total.
page() reads the items get() reads in the shape of a page: a Storyfeed\FeedResult with data, payload_version, sync_token, media and entities, and no links or cursors. Use it for a widget that shows a fixed number of items and wants the maps:
return Storyfeed::feed()->limit(8)->inlineEntities(false)->page();It iterates as FeedItem readers and serializes to JSON, so a route can return it. get() is unchanged.
Empty PHP maps such as data and link.attributes serialize as []; populated string-keyed maps serialize as JSON objects.
Entities
Every role (actor, object, target, context, origin, result, instrument, location, generator) is null or:
{
// morph alias, never a class name
"type": "delivery",
// string-cast; null for an entity with no model that was recorded without an id
"id": "42",
// snapshot label, or the resolver's; null ⇒ degraded (no snapshot yet)
"label": "Delivery #1042",
// resolved at read time; null ⇒ not linkable
"link": {
"href": "https://…/deliveries/1042",
// hint: open as a modal
"modal": false,
// link attributes, e.g. {"target": "_blank"}
"attributes": []
},
// snapshot data
"data": [],
// picture slots, files and the avatar; never null
"media": { /* see Media */ },
// a list of bodies, or null when there are none
"body": null,
// null, or what a deleted entity left behind
"tombstone": null,
// key into the page's media map; null off a page
"media_ref": "m3f2a9c41d07e6b58",
// key into the page's entity map; null off a page
"entity_ref": "e9b41c07d2a6f3e58"
}The static Feedable::feedMedia(FeedContext): ?FeedMedia resolver supplies link and media when the feed is retrieved. It receives the snapshot, which supplies type, id, data, and label; the resolver may override label. The body list contains stored bodies followed by resolved bodies, each identifying its type with $body. The body field tables and body envelope are part of this contract. See also Activity Content and Feedable API.
FeedEntity also accepts content (authored text), mediaType (its encoding), and attributedTo (the author’s IRI). These snapshot keys appear only when non-null; an empty content string is preserved.
Party nodes may carry an external home in the same link field in any role. Without an external home, link is null. See Linking a Party.
Tombstones
Deleted models are replaced by tombstones in existing activities. See Deleted Models for the lifecycle.
"object": {
// always this alias
"type": "storyfeed.tombstone",
// the tombstone's key, not the deleted model's
"id": "17",
// null, unless the model kept its label
"label": null,
// always null
"link": null,
"data": [],
// the avatar on a neutral grey
"media": { "icon": null, "image": null, "preview": null, "initials": "?", "color": "#6b7280", "files": [], "slots": [] },
"body": null,
"tombstone": {
// the deleted model's morph alias
"formerType": "order",
// ISO 8601, or null when unknown
"deleted": "1985-07-04T12:00:00.000000Z",
// true when the trickle found the deletion
"approximate": false
}
}A role has one of these states:
| State | Shape |
|---|---|
| Empty | null; for the actor, this means anonymous: no actor was recorded |
| Degraded | the model's own type, label: null, link: null, tombstone: null |
| Tombstoned | type: "storyfeed.tombstone", link: null, tombstone: {…} |
| No model | an entity given as an array: its type and label as given, link from its url, and media from its media, or the derived avatar. id as given; without one, null on a recorded activity and the label on a composed entry or source item. Never hydrated or refreshed; a recorded one without an id is in no involving() index |
When approximate is true, deleted records when storyfeed:trickle found the model missing. It is not the exact deletion time. Headlines, icons, and intents use formerType, so order.place still applies to a deleted order.
Media
"media": {
// small, representational, ~32×32, 1:1: an avatar, a logo
"icon": null,
// a larger visual representation of a NON-image resource
"image": null,
// a preview of the resource: the dense-feed thumbnail
"preview": {
"src": "https://…/photos/88/thumb.jpg",
"mediaType": "image/jpeg",
// int, or null when unknown; never 0
"width": 400,
"height": 300,
// optional alt text; null is preserved
"alt": null
},
// the avatar's text and disc colour, for an entity without an icon
"initials": "PT",
"color": "#0f766e",
"files": [],
// custom slots by name, from FeedMedia::slot()
"slots": []
}| Value | Meaning |
|---|---|
icon, image, preview | an image object, or null |
initials, color | the avatar's text and its disc colour as lowercase #rrggbb; set whenever icon is null |
files | a list of resources; an empty list when none |
slots | a map of custom slots, each an image object or a resource; empty when there are none |
width, height | dimensions for reserving display space before loading; null when unknown, never 0 |
Every entity has an avatar. When feedMedia() declares no icon, Storyfeed fills in what it left undeclared: initials from the label (the first letter of the first and last words, uppercase) and a color from the entity's type and id, so the same entity gets the same tile on every page. A party's colour follows its key. A tombstone, and an entity with no label, take #6b7280; with no label the initials are ?. Declared values win.
The three image keys use Activity Streams 2.0 definitions: for a photo, preview is its thumbnail. A picture appears only where a body names its slot. Group sample entities use the same media structure.
files is a list of resources carrying type, href, mediaType, and name from FeedResource. Each resource defaults to type Document.
Page Media Map
A paginated page builds each distinct entity's link and media once, and lists them in the paginator's top-level media map:
"media": {
"m3f2a9c41d07e6b58": {
"link": { "href": "https://…/photos/7", "modal": false, "attributes": [] },
"media": { /* see Media */ }
}
}The map has one entry per distinct {link, media} pair. Each entity's media_ref names its entry: m followed by 16 hexadecimal characters, a content hash of the pair. Identical pairs share an entry, and the same output gets the same ref on every page. Treat the ref as opaque. media_ref is null off a page, for example in get() output or a lone node. An empty map serializes as [].
By default every entity also keeps its inline link and media. Setting storyfeed.payload.inline_media to false (env STORYFEED_INLINE_MEDIA) drops link and media from entities in paginated output (cursorPaginate() or simplePaginate()), so a page carries each signed URL once. It never applies to get(): those entities always keep their inline link and media, because there is no map. Turn it off only once your renderer reads the map.
Pass the renderer the whole paginator, or its full array, never ->toArray()['data']. The nodes alone lose the top-level media and entities maps, so with inline_media off their entities render without a link or media, and with inline_entities off they are bare stubs. For load-more, append pages with storyfeed/ui's appendPage(), which merges each page's map.
A renderer resolves an entity's link and media from media[media_ref], and falls back to the entity's inline copies. Treat a missing media key, an empty object or [] as no map. When you append pages, merge each page's map into your store.
Page Entity Map
Every entity on a paginated page carries an entity_ref: e followed by 16 hexadecimal characters, a content hash of everything the entity serializes, media_ref included. The same entity output gets the same ref on every page, and two snapshot versions of one entity never share one. Treat the ref as opaque. entity_ref is null off a page, for example in get() output or a lone node.
The paginator's top-level entities map lists each distinct entity once, keyed by its entity_ref, exactly as it would appear inline. By default entities stay inline and the map is empty, serialized as []. $paginator->entities() returns the map.
Setting storyfeed.payload.inline_entities to false (env STORYFEED_INLINE_ENTITIES) replaces every entity in paginated output with a stub, at every depth: activity roles, a group's pinned roles, its sample lists, sample.featured and its children:
"actor": { "type": "user", "id": "7", "entity_ref": "e9b41c07d2a6f3e58" }The map then holds the whole entities. It never applies to get(): those entities always stay inline. Turn it off only once your renderer reads the map.
Per-Read Overrides
inlineEntities(bool) and inlineMedia(bool) on a feed builder override inline_entities and inline_media for one read, or in a named feed's definition, so a web feed can stub entities while an API reader of the same feed keeps them whole:
Storyfeed::feed('activity')->inlineEntities(false)->cursorPaginate();They apply to cursorPaginate(), simplePaginate(), members() and page(), and default to the config. get() ignores them and stays inline.
With inline_entities off, map entries keep their link and media inline, and the media map is always empty, whatever inline_media says. Each entity already travels once, so a separate media map would only repeat its pictures. With inline_entities on (the default), inline_media works as described in Page Media Map.
A renderer resolves entities before media: it reads an entity from entities[entity_ref], falling back to the inline copy, and only then resolves link and media through media[media_ref]. Treat a missing entities key, an empty object or [] as no map. When you append pages, merge each page's entities map into your store, as for media.
Feed-Specific Resolution
The resolver context includes the registered feed name, allowing one snapshot to produce different URLs per feed. This name comes from the registry, not the request. For example, a shop feed may include a signed operational link that is absent from the customer feed.
Nodes do not identify their source feed, so include the feed name in payload cache keys.
The context carries the feed, never the reader. Resolving never consults auth(), so every reader of a feed gets the same payload.
Degraded Entities
Entities without snapshots remain in the payload with label: null, link: null, and a ? avatar; their resolver is not called. storyfeed:trickle creates missing snapshots. If feedMedia() throws, Storyfeed reports the exception and returns link: null and the derived avatar.
Activity Nodes
{
"kind": "activity",
// a ULID for stored activities; an opaque string for composed/source entries
"id": "01J1K2M3N4P5Q6R7S8T9V0W1X2",
"verb": "confirm",
"published_at": "1985-07-04T14:03:22.000000Z",
// the time range the activity describes, or null
"starts_at": null,
"ends_at": null,
"headline_template": ":actor confirmed :object for :target",
// pre-rendered fallback; see below
"headline": null,
// literal values for tokens in the headline, or null
"bindings": null,
"glyph": "circle-check",
// the app's own word for what the glyph means
"glyph_intent": null,
"actor": { /* entity */ },
"object": { /* entity */ },
"target": { /* entity or null */ },
"context": { /* entity or null */ },
"origin": { /* entity or null */ },
"result": { /* entity or null */ },
"instrument": { /* entity or null */ },
"location": { /* entity or null */ },
"generator": { /* entity or null */ },
// the role whose entity the row shows, or null
"featured": "object",
"data": null,
// the roles holding a tombstone, in role order
"tombstoned": [],
// one of them is a role the verb is about
"redundant": false,
// the verb's reading once redundant
"missing_headline_template": null,
// the same, pre-rendered
"missing_headline": null
}| Key | Type | Holds |
|---|---|---|
kind | string | always "activity" |
id | string | the activity's stable, opaque id |
verb | string or null | the recorded verb; null only on a verbless entry of a composed feed or source |
published_at | string or null | ISO 8601 with microseconds; null only on a dateless entry of a composed feed or source |
starts_at, ends_at | string or null | the time range set with startsAt() and endsAt(), ISO 8601 with microseconds; either end may be null |
headline_template | string or null | the headline, with its tokens; see Headlines |
headline | string or null | the pre-rendered fallback; see Headlines |
bindings | map or null | literal text for named headline tokens, {name: text}, set with bind(); null when the activity binds nothing. See Bound Values |
glyph | string or null | the icon token; see Icons |
glyph_intent | string or null | the icon's meaning; see Icons |
actor, object, target, context, origin, result, instrument, location, generator | entity or null | the entity in each role |
featured | string or null | the role whose entity the row shows: "object" unless the activity features another role; null for none |
data | map or null | what the recording call passed to data() |
tombstoned | list | the roles ("object", "target", …) whose entity is a tombstone; [] when none |
redundant | boolean | true when a tombstoned role is selected for redundancy checks: the object by default, none for a removal verb, or what the verb's missing() selects |
missing_headline_template | string or null | the verb's ->missingHeadline(), when redundant is true and the verb declares one; otherwise null. headline_template keeps its value either way |
missing_headline | string or null | the finished text when ->missingHeadline() is a closure that returns text without role tokens, as headline is for headline_template; otherwise null |
A redundant activity still records what happened, but a relevant model has been deleted. Your renderer may display the original or missing headline.
Group Nodes
{
"kind": "group",
// opaque and stable; members() reads the group back from it
"id": "grp_djIfcmVwZWF0…",
// unknown values: render as a generic group
"axis": "actors",
// true total members
"count": 5,
"verb": "place",
// the first member's time; null on a dateless composite
"published_at": "1985-07-04T14:03:22.000000Z",
"headline_template": ":actors ordered from :target",
"headline": null,
// the bindings every member shares, or null
"bindings": null,
"glyph": "shopping-bag",
"glyph_intent": null,
"actor": null,
"object": null,
"target": { /* the shared target entity */ },
"context": null,
"origin": null,
"result": null,
"instrument": null,
"location": null,
"generator": null,
// the role every member features, when the axis pins it; else null
"featured": null,
// every role is a LIST
"sample": {
"actors": [ /* up to 3 entities */ ],
"objects": [ /* up to 3 entities */ ],
"targets": [ /* the shared target entity */ ],
"contexts": [ /* one context entity */ ],
"origins": [],
"results": [],
"instruments": [],
"locations": [],
"generators": [],
// each sampled member's featured entity, newest first
"featured": [ /* up to 3 entities */ ]
},
"distinct": {
"actors": 5, "objects": 3, "targets": 1, "contexts": 1,
"origins": 0, "results": 0, "instruments": 0,
"locations": 0, "generators": 0, "featured": 5
},
"children": [ /* member activity nodes in feed order, possibly truncated */ ],
"children_truncated": false,
// roles with a tombstone among the distinct entities
"tombstoned": [],
// true when every member is redundant
"redundant": false,
// per role, how many distinct entities are tombstones
"distinct_tombstoned": {
"actors": 0, "objects": 0, "targets": 0, "contexts": 0,
"origins": 0, "results": 0, "instruments": 0,
"locations": 0, "generators": 0, "featured": 0
}
}| Key | Type | Holds |
|---|---|---|
kind | string | always "group" |
id | string | grp_ and an opaque key; stable, and accepted by members() |
axis | string | a built-in axis (actors, actors_target, targets, object, repeat, composite, batch, context) or a custom axis's name. Render an unknown value as a generic group |
count | int | the true number of members |
verb | string | the first member's verb; a custom axis without a verb pin can group different verbs |
published_at | string or null | the first member's time, normally the newest; null on a dateless composite |
headline_template, headline | string or null | the group headline; both null when no sentence is true of the whole group |
bindings | map or null | the bound values every member holds with the same text; null when none are shared |
glyph, glyph_intent | string or null | resolved from the first member, as on an activity node |
actor, object, target, context, origin, result, instrument, location, generator | entity or null | the role's one entity, when every member shares it; see below |
featured | string or null | the role every member features, when that role holds one entity across the group; otherwise null |
sample | map of lists | distinct entities per role, limited by grouping.sample_limits (default three) and the loaded members; live ones before tombstoned ones |
sample.featured | list | each sampled member's featured entity in feed order, one per member, so an entity can repeat; limited by the loaded members and grouping.sample_limits.featured (default three) |
distinct | map of ints | per role, the true count of distinct entities across all members; featured counts the members that feature an entity |
children | list | member activity nodes in feed order, at most grouping.children_limit; members() pages through all of them |
children_truncated | boolean | true when count is more than the children included |
tombstoned | list | the roles with at least one tombstone among their distinct entities |
redundant | boolean | true only when every member is redundant |
distinct_tombstoned | map of ints | per role, how many of the distinct entities are tombstones; featured counts member occurrences whose featured entity is a tombstone, including repeats |
A singular role contains an entity only when the grouping rule uses that role, every member shares it, its sample has one entry, and its distinct count is one. Otherwise it is null. Each plural role has a limited sample and a distinct count; empty roles use [] and 0.
When a feed is filtered or scoped, count, distinct, sample and children describe only the members inside it.
samples($limit) on the feed builder caps every group's sample lists, sample.featured included, at $limit entities; samples(0) sends none. Use it per read (Storyfeed::feed()->samples(0)->cursorPaginate()) or in a named feed's definition. A capped list is [], never a missing key. The cap applies after the headline, the pinned roles and featured are read, so count, distinct, distinct_tombstoned, the headline and the pinned roles are unchanged. A negative limit throws.
children($limit) does the same for a group's presented children, at most $limit members; children(0) sends none. It is a presentation cap: members are still loaded up to grouping.children_limit, so count, distinct, the headline, the pinned roles, sample and redundant are unchanged, and the dropped members are never presented. children stays a list ([] at 0), and children_truncated, always present, is true when the cap drops members. Use it per read or in a named feed's definition. A negative limit throws.
A composed composite keeps its entry's timestamp, which may be null. Its children follow the feed's order: newest first by default, authored order with inOrder(). Dateless children keep their authored order.
Which activities group together, and when, is grouping policy, not part of the payload contract; see Aggregation.
Live groups one action within a burst, using the group shape above.
Presentation Fields
Icons
glyph contains the icon token declared with icon(). Storyfeed includes no icon set and returns null when no icon is defined for the type and verb.
glyph_intent contains the token declared with intent(), such as "success" or "danger". It describes the icon's meaning. Any string is accepted; Storyfeed provides no fixed vocabulary or validation. Without a declaration, it is null. See icon meanings.
Icons and intents are resolved independently in this order: type.verb, type.*, *.verb, then *.*.
Activity Streams 2.0 documents include neither token; their icon contains the entity's icon image.
Headlines
Render headline_template by replacing its tokens. headline contains finished text and is null when headline_template is set. For activity nodes, a closure returning role tokens sets headline_template; a closure without them sets headline. For group nodes, closures always set headline. Tests for activity closures returning tokens should check headline_template.
Both fields are null when no headline describes every group member. Renderers must handle this case; see Building Your Own Components.
See Aggregation for allowed group tokens. Singular tokens require a shared grouping role. The singular fallback may also retain a role token when the group has exactly one distinct entity for that role.
Noun substitution can change the emitted template even for the same headline definition, so cache rendered headlines per node, not per definition.
Bound Values
bindings holds literal text for tokens the recording named with bind(), as {name: text}, or null. It also holds values a headline closure binds at render time, which are never stored; the payload doesn't tell them apart, and a render-time value wins over a stored one with the same name. headline_template keeps the token:
{
"headline_template": ":actor sent :object to :recipient",
"bindings": { "recipient": "Pat [x] :object <b>" }
}Replace a token whose name is a key of bindings with its value, drawn as plain text: escape it, never parse it as markup, never link it, and never look for tokens or segments inside it. The example reads "Pat [x] :object <b>" in place of :recipient. A binding name is never a role token, count, others or verb, so a bound token never competes with an entity. A renderer that predates bindings draws the token as an unknown token.
A group node carries only the bindings that every member holds with the same text, and only when the slice holds all of the group's members. A value that differs between members is left out, and a group headline that would need it is null rather than naming one member's value.
When a closure headline returns finished text that uses only bound tokens, Storyfeed fills them in once and headline holds the literal text.
bindings is an additive field of Payload v1. Read it as absent or null when it is missing.
Links in a Headline
A rendered headline is a sentence that contains entity links. Don't wrap it in a link to make the row tappable: an <a> cannot contain another <a>, so the browser closes the outer link at the first entity link and splits the sentence. Don't enlarge it with a min-height either: on a flex container that wraps, a minimum height moves the sentence off its line.
Entity links inside the headline need no minimum target size, because WCAG 2.5.8 exempts a target in a sentence. A link alone on its own line is not exempt and needs a 24 by 24 pixel target at level AA.
Pagination and Synchronization
Ordering
Nodes are ordered by:
published_at, descending; a group's is its newest member's;- groups before activities;
- id, descending; a group's is its highest member id;
- grouping axis and hash.
Live and Log read activities published at the same instant in the same order, on stored feeds and sources alike. The order rests on ids, so a cursor keeps its place across storyfeed:curate --rehash. To merge nodes with rows of your own, sort them the same way.
Cursors
- Store cursors and return them unchanged; do not parse them.
- Results are ordered by
published_at, newest first (see Ordering), with dateless entries after them in the order given, unless a composed feed or source keeps its order. next_cursor: nullmarks the end.prev_cursor: nullmarks the newest page. On later pages it points back towards newer nodes;prev_page_urlcarries it. This also works formembers()and sources.
Sync Tokens
Store the opaque sync token with the cursor and compare tokens for equality. If a later page's token differs, discard all accumulated nodes and fetch from the start. A change from null to a non-null value also requires this.
storyfeed:curate --rehash can change the token during pagination. Check it even when data is empty and next_cursor is non-null. Clients must handle changed tokens to comply with the payload contract.