Visual preview
Visual preview loads a participating site inside the admin in the selected authoring scope and contexts.
For the team workflow, see Preview the shop.
For site setup, see Preview your site in the admin.
What can be previewed
An entity type is previewed when it's authored, IVoxAuthoredEntity, and
routable, IVoxRoutable, and the host registers preview. Its route projection, the projection whose
output is a VoxRouteDocument, gives the path of its page in the selected contexts, and the preview options map each
route space to the site its paths are opened on.
vox.AddVoxRouting()
.AddEntityFrameworkRouting(options => options.ConfigureDbContext = ConfigureRoutes)
.AddVoxRoutingApi(options => options.DefaultSpace = "storefront")
.AddVoxPreview(preview => preview
.AddSite("storefront", new Uri("https://www.northpeak.example"))
.Exclude<ContentPage>());
app.MapVox() serves the routes at /content/{**path}.
AddSite(space, origin)opens the paths of a route space on a site. A space without a site isn't previewed. The origin is an absolutehttporhttpsURL without a path.Exclude<TEntity>()leaves an authored, routable entity type out of preview.RouteProjection<TEntity>(name)names the route projection of an entity type with more than one.GrantLifetimeis how long a grant is valid, 30 minutes by default. The admin renews grants before they expire.
Preview needs authoring and the routing API. Build() checks that every previewed entity type has exactly one route
projection, or one named with RouteProjection, and tells which type doesn't.
The admin learns the previewed entity types, the sites and the grant lifetime from GET api/preview, which doesn't
exist without preview. An entity type that's previewed gets a card of its page in the rail of its entities and a
Preview button, and the full-screen preview at /{routeName}/{id}/preview.
Sessions and grants
POST api/preview/sessions, with the editor's selection, its scope in scope=, eg scope=draft, and its contexts in
context=, and { entityType, entityId, space? }, opens a page:
- It needs that the editor may read the entity in the selection.
- It evaluates the entity's route projection in the selection, so a slug that's new or changed in the draft is used, and picks the canonical route of the space, or of the first space with a site the entity has a page in, whose contexts the selection has. When the selection has no member of one of the route's context types, eg no language, it picks the first canonical route, and returns its contexts, which the admin shows as selected.
- It returns the URL of the page on its site with a grant in its
vox-previewparameter, when the grant expires, the route's contexts, and the other spaces the entity has a page in. - When the entity has no page in the selection, eg no slug in the selected language, it's a 404 that says why and which selected members it has no page in, so the admin can say "No slug in Suomi".
A grant lets the site's server read the restricted part of the editor's selection, its scope, eg draft or
release:autumn, and its restricted contexts, eg an experiment's variant, on the editor's behalf. It's protected with
ASP.NET Core Data Protection, holds the editor, the scope, the restricted contexts, the previewed entity and space, and
its expiry, and can't be read or changed outside Vox.
The site's server sends it as Vox-Preview: {grant} on its requests to Vox, next to its own API key. A grant alone
authenticates nothing:
- The grant must be valid and unexpired. Otherwise the request is a 401 with
WWW-Authenticate: VoxPreview error="expired"orerror="invalid", so the site can ask the admin for a new one. - The API client needs the preview permission of the grant's scope,
vox:Preview:Drafts,vox:Preview:Releasesor both for a draft within a release, and of each restricted context type in the grant,vox:Preview:{contextType}. - The editor must still exist, be enabled and be allowed to select what the grant previews. This is checked on every request, with the answer kept for 30 seconds.
- A request without
scope=reads the grant's scope, and an explicit one, egscope=published, overrides it. The grant's contexts are combined with the request'scontext=. A request that selects a restricted context the grant doesn't have is rejected, unless its API client may select it itself. - Responses are
Cache-Control: private, no-store.
The header works on every read of the API: by id, by route and in queries.
Reading many projections at once
POST api/entity-projections/read reads up to 200 content-delivery projections by key in one call, in the request's
scope and selection: its scope= and context= parameters, or its grant. Entity types are given by name, not by route
name, and the projections they reference aren't read:
POST /vox/api/entity-projections/read?context=Market:se,Language:sv
Authorization: ApiKey ...
Vox-Preview: {grant}
{ "documents": [ { "entityType": "ContentBlock", "entityId": "home-recommended", "projection": "block" },
{ "entityType": "Product", "entityId": "p1", "projection": "card", "contexts": "Language:en" } ] }
It answers with the scope, the selection it read in, with the grant's restricted members, and a document per one
asked for, in the same order, as a projection of a graph is delivered, with rich text as JSON documents. A document is
null where it doesn't exist in the selection, the caller may not read it, or its projection isn't for content delivery.
The documents are evaluated together, in batches per projection. Vox Serve
reads the levels of a preview with it, and so can any client of the API. The editor of a grant is checked for any
entity type, as in route delivery.
Routes in a preview
The published route index has published content only. With a grant, the route endpoint first evaluates the route projection of the grant's entity in the grant's selection, and delivers that entity when the path is one of its routes in the space. So the previewed page resolves even when its slug is new or changed in the draft. Other paths resolve by the published routes, and are delivered in the grant's selection. An entity that has never been published and isn't the grant's entity can't be reached by path in a preview.
Source maps
The site marks its elements with projection coordinates only: the key of a projection and a JSON path in its value, eg
vox://entity/Product/p1?projection=page#name. The admin asks Vox what those values came from:
POST /api/entity-projections/source-maps?scope=draft&context=language:sv
{ "keys": ["vox://entity/Product/p1?projection=page"] }
Vox evaluates each projection once, in the selection, and records what the getters of the entities it reads return,
with the entity and field each came from. A value the projection takes apart after reading it, eg the Swedish value of a
varying field or an item of a list, is recorded with its subtree. Then it walks the output by the names it's serialized
with, so paths follow [JsonPropertyName], naming policies and ignored properties, and finds the source of each value:
- Identity: the value is the instance a field had, eg
Name = context.Contexts.Resolve(product.Name)orBody = page.Body, and the items of a list that was filtered, sorted or mapped item by item. - Equal: a text that equals one recorded text, ignoring case and whitespace, eg
Trim()orToUpper(), or a number, bool, enum or date that equals the only recorded value of its type with that value. A value that the projection read beats equal ones it didn't: readingproduct.Pricing.FromPricerecords the whole pricing object, but a price of 249 comes from the from-price, not from a price range of 249 to 249 in the same object. - Contains: a text that contains recorded texts of four characters or more, eg
$"{name} – {brand}", at most five, the longest first.
A source names the entity and field, eg Brand, b-12, name, which can be another entity than the projection's, eg
the name of a brand in a product card. A value of a varying field has its member, eg Language=sv; when that isn't the
selected member, the value is a fallback, and the admin edits it at the selected member. A path can have several
sources, and a source several paths. A path without a source has none: the admin still knows the projection's entity.
References to other projections aren't walked, since the referenced projection has a key and a map of its own.
Source maps are computed only when they're asked for, for the keys on a previewed page, in the same batches as
materialization. Ordinary evaluation, delivery and publication record nothing. Each key needs read access to its entity,
sources of entities the caller can't read are left out, and keys that can't be mapped are reported with the reason.
In .NET, IVoxProjectionSourceMapper computes them.
Limits. A value computed from read values, eg a formatted price or a sum, has no source unless it equals one read value. Two equal texts read from different fields are ambiguous, so neither is the source of a copy of them. Values read outside the projection context and the projection's entity, eg from configuration, have no source.
Editing in the preview
The preview saves every edit automatically to where the selection saves, eg the draft, a release or a variant of an experiment, 800 ms after the last change and at once when a field loses focus, the selected content changes or the screen is left. The saves of one entity are serial, and a change made during a save is saved after it. A version conflict stops saving that entity until the editor reloads it.
Each autosave is an entry of its own in the audit log of drafts and releases, and the versions of the entity increment as for any edit.
Once a save can be read, the admin tells the page what changed, and the page refetches. A site that evaluates
projections when it reads them, with direct delivery, sees a save as soon as it returns. A site that reads published
projections from its own store, published with IncludeDrafts or IncludeReleases, and IncludeRestricted for restricted contexts, sees it once the publication has
processed it: the admin waits on
GET /api/entity-projections/publications/status?entityType=Product&id=p1&scope=draft&key=Language=sv&version=12
which says whether every publication of the entity type that includes the scope and the key's restricted contexts has published that version there or a later one.
The admin
- The card in the rail of an entity shows the path of its page in the selection, the selection, its title and image, and when it's on screen and the site has the SDK, a live picture of the page, scaled to the card. An entity without a page in the selection says why.
- The preview screen is full screen, without the admin's top bar and sidebar: a toolbar with the selection, the contexts of the page's route, the site, the device width, Highlight content and the draft of the entity with its Publish, the page in the middle, and the selected content at the right, in the same field editors as its details. The panel shows the fields the selected content came from first, under "Selected", and the entity's other fields below in collapsed sections, which the editor opens as needed. Its left border resizes it, up to half of the window. The status line tells whether the page has the SDK. When the page navigates, the preview follows it to the page of the entity it shows; a page of something that isn't previewed stays shown, and can't be edited.