Skip to main content

Authoring setup and scopes

Vox saves entities directly by default. Authoring adds a published view and one editable draft for each opted-in Vox-owned entity.

For the team workflow, see Prepare a draft.

External entities keep the versions supplied by their source. An import handler maps a source payload onto the model.

Enabling authoring​

An application enables authoring in AddVox, and each entity type opts in with the marker interface IVoxAuthoredEntity:

builder.AddVox(options => options.UseAuthoring());

public class Product : IVoxAuthoredEntity
{
// ...
}

public class Order : IVoxEntity
{
// Saved immediately, in the same model, API and admin
}

Authoring is drafts, publishing, scheduling, restores and content releases, the authoring scopes. Only authored entity types have them; an owned entity type that isn't authored stays immediate-write, even when it relates to authored ones. An application can author without releases:

options.UseAuthoring(authoring => authoring.WithoutContentReleases());

Without UseAuthoring there's only published content: no draft or release scopes, no authoring services, scheduled publications or HTTP routes, and the admin has no draft, publish or release controls. Vox refuses to start with an authored entity type without it. IVoxEntityTypeRegistry.Authoring, a VoxAuthoringModel, tells which scopes the application has: HasDrafts, HasReleases, ReleaseEntityType, ReleaseAuthority, the source whose releases it uses, and Supports(scope). Context entity types and content releases are published immediately and can't be authored, nor can external entity types. VoxEntityType.HasAuthoringData is true for an authored entity type and for an external one whose drafts and releases are received.

Authoring scopes​

An authoring scope is the version of content that's read or written. Scopes are separate from the application's contexts, such as language, market, channel or an experiment, and applications can't add scopes:

ScopeContentReads through to
publishedThe live version. This is the default.
draftThe ordinary draft of every entity, published into published content.published
release:{id}The changes of a content release, published together.published
release-draft:{id}A draft within the release, published into the release.release:{id}

The ancestry is fixed. An entity without changes of its own in a scope reads as it is in the scope's parent, so the draft and a release read through to published content, and a draft within a release reads through to its release. An entity with changes reads the fields it didn't change from the parent too, see Conflict handling. The ordinary draft never reads a release, and releases don't read each other. After a draft is published or reverted, the entity reads as published again and no longer reports a pending draft.

An entity may also exist only as a draft. It is absent from published reads until it is published. Creating an entity with IVoxEntityUpdater publishes it; IVoxAuthoringEntityUpdater creates a draft-only entity in the draft scope.

Over HTTP, ?scope= chooses the scope of reads and writes, eg ?scope=draft or ?scope=release:autumn, and ?context= the application contexts, eg ?scope=draft&context=language:sv. A stored cell is addressed by its scope and its application contexts, written draft|Language=sv.

Resolution order​

A read composes the scope's version of the entity first, and then resolves the application contexts within it. So a contextual value keeps its precedence over a general change of the scope. With a published name "Rain jacket", a published Swedish name "Regnjacka" and a draft that changes the general name to "Light rain jacket":

ReadName
publishedRain jacket
published, SwedishRegnjacka
draftLight rain jacket
draft, SwedishRegnjacka

The draft's Swedish cell is inherited from published content, and it's more specific than the general name. Changing the Swedish cell in the draft, eg to "Lätt regnjacka", makes the draft read "Lätt regnjacka" in Swedish. Deleting the inherited Swedish cell in the draft lets "Light rain jacket" apply in Swedish too, and reverting the draft's Swedish edit reveals the published "Regnjacka" again. The context stacking order only ranks application contexts within a scope.

GET {id}/content returns the published version and the draft side by side, with draftInfo: the draft version, last editor, changed fields, schedule, and publication error or conflict details. Editors use it to show what a draft changes.

Variations are written to the same published content, drafts and releases, and are published with them, but each has a concurrency boundary of its own. An editor can therefore prepare a market-specific value without turning an unrelated edit of the entity into part of the same conflict.

Saving through .NET​

IVoxEntityUpdater writes published content, of every entity type, with plain versions. The authoring updater, IVoxAuthoringEntityUpdater, writes authored entity types in an authoring scope, eg the draft:

var product = await authoringUpdater.CreateAsync(
new ProductActions.Create { Id = "rain-jacket", Name = "Rain jacket" },
VoxContentScope.Draft,
cancellationToken: cancellationToken);

var edited = await authoringUpdater.UpdateAsync(
"rain-jacket",
VoxCellVersion.Draft(product.Version),
new ProductActions.SetName { Name = "Waterproof rain jacket" },
cancellationToken: cancellationToken);

VoxCellVersion names the scope the command is saved in and the version of the entity it read there. An entity without a draft reads as its published version in the draft, so the first draft edit uses the published version too. The authoring updater rejects published content, which IVoxEntityUpdater saves immediately, and entity types that aren't authored. To publish what's in a draft, save it to the draft and publish the draft with IVoxEntityPublisher, or do both as one change, see Save and publish. The batch, cell and restore APIs are split the same way: IVoxAuthoringBatchEntityUpdater, IVoxAuthoringEntityCellUpdater and IVoxAuthoringEntityRestorer. Cells and existence take the scope and the application-context keys apart:

await cellUpdater.WriteAsync(productType, "rain-jacket", VoxContentScope.Draft,
[VoxCellKey.Baseline.With(nameof(Language), "sv")], values, version, cancellationToken: cancellationToken);
await authoringUpdater.SetExistsAsync(productType, "rain-jacket", VoxContentScope.Draft,
VoxCellKey.Baseline.With(nameof(Market), "se"), true, cancellationToken);

To save into a content release, name its scope, VoxCellVersion.Release(id, version), or for a draft within it new VoxCellVersion(VoxContentScope.ReleaseDraft(id), version):

var edited = await authoringUpdater.UpdateAsync(
"rain-jacket",
VoxCellVersion.Release(release.Id, product.Version),
new ProductActions.SetName { Name = "Autumn rain jacket" },
cancellationToken: cancellationToken);

Read a scope from the authoring entity store, IVoxAuthoringEntityStore<Product>. The ordinary IVoxEntityStore<Product> reads a VoxReadView(scope, contexts): a view without a scope inherits the scope in use, eg the draft while a calculation of a draft runs, and an explicit VoxContentScope.Published reads published content also where another scope is in use, eg a preview. IVoxContentContext.Use(scope) sets the scope in use.

var live = await products.GetAsync("rain-jacket", cancellationToken);
var preview = await products.GetAsync("rain-jacket", VoxContentScope.Draft, cancellationToken);
var releasePreview = await products.GetAsync("rain-jacket", VoxContentScope.Release(release.Id), cancellationToken);
// swedish is a VoxContextSelection, eg from IVoxContextResolver
var swedishDraft = await products.GetAsync("rain-jacket", new VoxReadView(VoxContentScope.Draft, swedish), cancellationToken);
var versions = await products.GetContentAsync("rain-jacket", cancellationToken: cancellationToken);

Save and publish as one change​

An editor who changes a draft and wants it live right away, eg with the admin's Save and publish, saves and publishes in one operation: IVoxEntityPublisher.PublishActionsAsync, or over HTTP the batch of actions with "publish": true and ?scope=draft:

POST /vox/api/products/rain-jacket/actions?scope=draft
{ "version": 7, "actions": [{ "action": "SetPurchasePrice", "values": { "purchasePrice": 120 } }], "publish": true }

The actions apply to the draft as it is, with its earlier saved changes, and the result is published with the usual permissions, validation and conflicts, all of it or nothing. If the draft already changes the description and the form changes the name, both are published. If the publication fails, eg since the name isn't unique in published content or published content changed since the draft began, nothing is saved: the draft keeps its description and the new name isn't in it.

Nothing reacts to the draft in between. Its calculations don't run for it, eg a new purchase price isn't calculated into a margin in the draft and then again in published content; no dependency work, assessment or projection is recorded for it; and subscribers that opted into drafts get the publication's event, not one of the draft. The edit is still in the draft's audit log, followed by the publication, and the action logs are kept. The publication evaluates the entity's calculations in published content and returns the published entity with their results; dependents and previews that read published content follow it. When the actions set the draft back to what's published, eg "Raincoat" back to "Rain jacket", nothing is published, the draft is discarded, and the result is the published entity. Since the actions, the draft and the publication are one transaction, the calculations of this combined operation run inside it.

Action handlers and validators may read entities of other storage providers, eg a cart in Redis for an entity in SQL, with their ordinary consistency. Every write of the operation is in the transaction of the entity's provider, so a handler that writes to another provider fails the whole operation. Only the ordinary draft is published this way: a draft within a release is saved and then published into its release in a second request, and publish: true with another scope is refused. A custom storage provider that doesn't implement it answers 405 Method Not Allowed before anything is saved.

Calculations in drafts​

A draft is consistent like published content, see Settled saves. A draft edit that a calculation reads is written into the draft together with the values the save calculates there: a draft change of the purchase price is saved with its new margin and selling price in the draft, and a read of the draft straight after shows them.

Publishing a draft, or a draft's scheduled publication, is a save of published content: the published entity with the draft's owned values on top is evaluated in published content before the publication's transaction opens, and published with the results, so the publication returns the published entity with them. A calculation that fails fails the publication, and a scheduled one gets a publication error. Publishing a content release evaluates every item the same way, each against the other entities as they're published, and writes each item once with its calculated values.

Effects of drafts and releases​

Singletons have the same effects inspection as other entities. A website policy's draft shows its readers, their calculated differences and incoming changes, and its draft bar shows how far its changed fields reach.

A saved draft or release change starts the normal processing in its scope: the calculations, cached references and memberships that read what changed are calculated again there, and what reads their results after them. Vox can show those effects, without a separate preview calculation. Opening them only reads what the processing stored; nothing is calculated, saved or queued.

A calculation that creates an entity previews it in the draft or release too: the proposed entity can be read there, but not in published content, and it's removed again when the draft no longer leads to it. The Effects tab lists what a draft's calculations create or calculate of other entities, each with whether it's still pending, and a proposed entity is a read-only calculated preview that names the calculation that creates it. Entity types that editors author aren't previewed: they're created when the change that leads to them is published. See Create entities and calculate related entities.

For example, a category's draft raises its minimum age from 16 to 18. Every product in the category reads that age, so its calculated age is 18 in the draft, and every bundle that includes one of those products reads the product's age. The category's Effects tab in the admin lists the products whose calculated values differ in the draft, eg "Minimum age: None → 18 · Everywhere", and each product's Read by · 1 bundle lists the bundles that read it. A level is read at a time: a category that a million products read lists them a page at a time, and a count of readers stops at 1,000 ("1,000+ products"). The tab shows what the draft changes elsewhere, not the draft's own edits, which are on the Details tab.

  • Stored differences, not completion. A reader's values are compared in the draft and in published content, or in the release for a draft within a release, at the addresses its reads were recorded at, eg the general value and Sweden, whatever contexts are selected. A difference is evidence that the stored results differ there. Equal values don't prove that the latest save has been calculated: stored results can still be catching up, and the view says so. What's known about the processing is shown separately: saved changes that haven't been dispatched to their readers yet, outputs that are still to be applied, and confirmed failures.
  • Several drafts contribute. All ordinary drafts share the draft scope, so a bundle's age in the draft can come from a category draft and another editor's product draft together. A row shows what differs, not which draft caused how much of it.
  • Previous readers. A product moved from Knives to Camping in the draft no longer reads Knives there, but its age still differs. It stays a reader of Knives, labelled "Read it in published content".
  • Queries read published content. Which entities a tracked query selects, how they're ordered and counted, depends on published values. What a calculation reads of the entities it selected is tracked like any other read, so it can have effects in a draft.
  • Incoming changes. A product without a draft of its own still has effects to show when its category has one: its Effects tab lists the drafts and releases where its calculated values already differ because something it reads changed there, eg "Because it reads Knives & multitools, edited by Maria L.", with the values that differ. A draft or release where the product is edited itself isn't one of them; its effects there are the tab's own.

On Details, a calculated value that differs from published content has a small opposing-arrows icon beside it. The icon links to Effects, also when the entity has no draft of its own. It compares the value in the displayed contexts, resolving each version's general fallback independently. Unchanged values have no icon. This uses one shared published-by-id read for the open entity, without scanning readers or starting calculations; it does not use the abbreviated differences shown on the Effects tab.

A content release has an overview of its effects in this application: the entities it edits, creates or deletes, and those whose calculated values differ because they read content in it, each once, with filters by entity type, kind of change, field and calculation. A calculated effect doesn't make an entity an item of the release, and isn't counted towards its limits. The drafts within a release are listed apart, compared with the release.

After a save, the draft bar tells when saved fields have readers and how far they reach, eg "Finding effects in the draft · Age restriction is read by 1,000+ products", then "Effects found in the draft · See what this draft changes →", and settles into a quiet line once the tab was opened. A changed field that's read also says so next to its Changed marker, eg "Read by 4 products →", which opens the Effects tab with that field's readers, so the effects are found where the field was saved, also far down the page. The Effects tab has a blue dot while it has something to show: the draft's changed fields are read, or another draft or release changes the entity's calculated values. When readers are known, Publish… opens the publish dialog first, with the changed fields that are read; without known readers, publishing stays one click. The inspection is in the API at GET /api/{entityType}/{id}/effects, …/effects/readers, …/effects/outputs, …/effects/incoming and GET /api/content-releases/{id}/effects, see the API overview. Its responses are private to the principal, and they show only the entities, fields, scopes and contexts the principal may read.

Publishing, schedules and date ranges​

IVoxEntityPublisher owns the lifecycle operations:

await publisher.PublishAsync<Product>("rain-jacket", draftVersion, cancellationToken);
await publisher.ScheduleAsync(productType, "rain-jacket", draftVersion, publishAtUtc, cancellationToken: cancellationToken);
await publisher.UnscheduleAsync(productType, "rain-jacket", draftVersion, cancellationToken);
await publisher.RevertAsync(productType, "rain-jacket", draftVersion, cancellationToken);
await publisher.UnpublishAsync(productType, "rain-jacket", publishedVersion, cancellationToken);

PublishAsync(entityType, id, version, scope) publishes the changes of a scope into its parent: the draft into published content, and a draft within a release, VoxContentScope.ReleaseDraft(id), into the release. A release itself is published with IVoxContentReleaseManager. Over HTTP, publish, revert and resolve-conflict take ?scope=, draft by default.

There is one mutable draft and at most one active schedule. Editing a scheduled draft keeps the schedule, so the latest saved draft is what goes live. Publishing manually or unscheduling replaces the schedule, so it does nothing at its time.

Scheduled publishing​

A schedule is stored with the draft, and its time is indexed. Vox finds the schedules that are due by that time, in background work that runs on one processing host at a time (vox_scheduled_publications, see background work), and publishes them in batches. Between batches it sleeps until the earliest future schedule, and setting a schedule wakes it. Nothing is lost with a host: say a spring campaign schedules 20,000 product drafts to publish at 06:00 on 1 March, and no processing host runs at 06:00 because of a deployment. The drafts are published when a processing host starts.

A temporary error at the scheduled time, eg the database being down at 06:00, is retried with a growing delay and doesn't fail the schedule. A draft that can't be published at its time, since it fails validation or one of its owned fields conflicts with a published change, is never published partially or over newer content. Instead its schedule is marked failed, and Vox stops trying:

  • The admin shows Scheduled publish failed: … with the reason where it shows the schedule, and the draft's status is Error. Editing the draft keeps the schedule failed; the editor fixes the draft and schedules it again, or removes the schedule.
  • The entity gets a scheduled-publication-failed finding on Vox's vox-processing assessment, which every authored entity type has, so editors find every failed schedule with the admin's assessment filters, eg ?assessment.vox-processing[finding]=scheduled-publication-failed. The finding is cleared when the draft is scheduled again, unscheduled, published or discarded.

A scheduled unpublication at the end of a draft's date range has no such permanent errors: one that can't be carried out yet, eg after a transient failure, is retried until it succeeds.

A draft can have a date range: it's shown from its scheduled publication until its scheduled restore, eg a banner that's shown for a day.

await publisher.ScheduleAsync(productType, "rain-jacket", draftVersion, publishAtUtc, unpublishAtUtc: null,
restoreAtUtc: showUntilUtc, cancellationToken);
var publications = await publisher.ListPublicationsAsync(productType, "rain-jacket", cancellationToken);
await publisher.ScheduleRestoreAsync(publications[0].Id, restoreAtUtc, cancellationToken);
await publisher.RestoreAsync(publications[0].Id, cancellationToken);

Publishing records a publication: the merged cells with the values they replaced, and the existence and link changes. A restore undoes exactly the changes of that publication. It's an update of its own fields only, so it conflicts only on a field the publication changed that has changed again since, and otherwise retries until it saves. A scheduled restore is found by its time and carried out by the same background work as scheduled publishing. A restore that conflicts at its time is marked failed on the publication: the admin shows Scheduled restore failed: … on it, and its entities get the scheduled-publication-failed finding, until the restore is scheduled again or removed. Publication records are kept until their restore runs or is unscheduled.

Unpublishing at a time is different: it removes the whole live version and keeps it as a draft.

Reverting discards pending changes and returns preview reads to the published version. Reverting a draft-only entity removes it. Unpublishing is the explicit inverse: it removes the live version and retains it as an editable draft. Deleting in the draft writes a delete there, which deletes the entity when the draft is published. Deleting a published entity deletes it with its draft, its versions in content releases and every cell it has.

Conflict handling​

A draft holds only the owned values it changed. Every other field, owned, imported or calculated, is read from the published entity, so a draft started last week shows today's price, and its preview and Effects reflect the catalog as it is. Say a draft changes only a product's description, and someone then changes the published price from 100 to 120: the draft shows 120 at once. Setting a field in the draft back to its published value removes it from the draft's changes, and the field follows published content again. Publishing applies only the draft's changes onto the current published entity.

All owned fields are still one concurrency boundary. The draft records the published version of the owned fields it's based on, with their values then, and if an owned field of the published entity changed after that, publishing returns a conflict, as a review step: an editor whose draft says "Now only 100 kr!" sees that the price changed before the two are published together. The conflict lists what published content changed, each field with its value when the draft was based on it and its value now, and says whether the draft changed it too:

  • Changed only in published content, eg the price: the draft already shows the published value, so there's nothing to choose. The editor reviews the change, eg "Price: 100 → 120", and accepts it.
  • Changed in both, eg the editor and someone else both changed the price: the editor chooses to keep the draft's value or take the published one.

Resolve the conflict by naming the fields that take the published values. The others keep the draft's values:

await publisher.ResolveAsync(
productType, "rain-jacket", draftVersion, ["marketing.tagline"], cancellationToken);

The draft is then based on the current published version and can be published. A conflict is in VoxPublishConflict.FieldChanges, and in draftInfo of GET {id}/content, whose conflictBase has the values the conflicting fields had when the draft was based on them. The values a draft was based on are kept in its own cell, so this works the same for entity types without history. The same call with a scope resolves the conflict of any authoring scope with its parent, eg of a draft within a release or of a release, and POST {id}/resolve-conflict?scope=... does over HTTP. The admin resolves conflicts in the cell editor of the entity, in the scope and contexts whose changes conflict: owned fields field by field, and each conflicting variation as a whole.

Drafts may temporarily violate a unique constraint. Vox enforces uniqueness when publishing, because unpublished work must not reserve a live value. Attribute validation and custom validators still run when a draft is saved and again when it is published.

Preview is a complete content scope​

Reading in a draft or a release is not just an ID lookup. An entity there is its published content with the changes of the draft or release on top: relations, rich-text references, context memberships and calculated values are read the same way, so a preview website can navigate the same model it will see after publication. Lists and searches are filtered by published values, and the entities that only exist in the draft or release are listed by their status there. Every edit is in the audit log, see History and audit.

Direct entity projection delivery can evaluate a published, draft, or release scope, so preview applications can use the same application-facing models as production. Entity change subscriptions and durable entity projection publications consume published changes unless they opt in to drafts or releases, with includeDrafts and includeReleases or IncludeDrafts and IncludeReleases, so unfinished work never leaks into outward-facing systems by default. Imports still update the published fields they own immediately, and every draft reads them from there, since editors don't change imported fields.

With visual preview, editors open the page of an entity on the application's own site in a draft or a release and edit what they select on it. The site reads the draft with a short-lived grant of the editor, and the preview saves to the draft automatically. Every autosave is an entry of its own in the audit log, and increments the version, so conflicts are detected as for any save.

Permissions and storage​

Creating and editing a draft uses the entity's normal create/action/edit permissions. Publishing (including saving an authored entity straight to published content), scheduling, reverting, resolving conflicts, and unpublishing additionally require {EntityType}:Publish, see VoxAuthoringPermissions. The generic Admin UI exposes this as the Publish permission of each authored entity type; an entity type that isn't authored has none.

Managing releases, including saving an entity version into one, requires vox:ContentReleases. A save also requires the entity's normal create/action/edit permission. Publishing a release additionally requires {EntityType}:Publish for every entity type represented in it.

Reading in an authoring scope needs a permission that edits there, or its preview permission: vox:Preview:Drafts for the draft and vox:Preview:Releases for a release, and both for a draft within a release, see Users and permissions. Responses in an authoring scope are private and never stored in shared caches.

Storage providers declare whether they support the draft lifecycle. Vox rejects an authored type assigned to a provider without that capability at startup. The built-in Entity Framework provider supports drafts; Redis does not, and stores only transient entity types, which can't be authored in any storage.

The built-in Entity Framework provider also supports atomic content releases. A provider must explicitly advertise that capability before an entity stored by it can be added to a release; Vox never silently degrades an atomic release into a sequence of independent publications.