Skip to main content

Portable contexts

Vox resolves the values of entities in a selection of contexts, eg the Swedish name in the Swedish market. A system outside the installation that owns the content, eg a delivery system that receives projections from Vox, must select and resolve exactly as Vox does, or it shows other values than Vox's own preview. This page specifies the logic and its data, so it can be implemented in any runtime.

  • The .NET implementation is CommerceMind.Vox.Contexts, which depends on nothing else in Vox. Vox itself uses it, so a .NET system that references it can't drift from Vox.
  • Vox Serve is Vox's own delivery system built on this specification. It selects contexts from requests with the published manifest and resolves the published documents and their references with CommerceMind.Vox.Contexts, so it serves the same values as Vox core.

Nothing in the logic depends on culture or platform. Strings are compared ordinally and case-sensitively.

Keys​

A key is a set of contexts, at most one member per context type, eg Language=sv|Market=se. It's written as its context types and members joined by |, ordered ordinally by the names of the context types, each as Type=member. The empty key "" is the baseline, the content without contexts. Names starting with $ are reserved, and a key with one is rejected.

Keys name application contexts only. Drafts and content releases aren't contexts but authoring scopes, see Authoring scopes.

The manifest​

The manifest is the context space of a model as JSON. GET api/contexts/manifest serves it.

{
"formatVersion": 3,
"revision": "5f0c…",
"contextTypes": [
{
"name": "Language",
"queryName": "language",
"isRestricted": false,
"isConcurrent": false,
"selection": "explicit",
"isPortable": true,
"members": [{ "id": "sv", "fallbacks": ["en"] }, { "id": "en", "fallbacks": [] }]
},
{
"name": "Experiment",
"queryName": "experiment",
"isRestricted": false,
"isConcurrent": true,
"selection": "criteria",
"isPortable": true,
"members": [
{ "id": "hero-a", "fallbacks": [], "group": "hero", "criteria": { "between": { "input": "bucket", "from": 1, "to": 51 } } },
{ "id": "hero-b", "fallbacks": [], "group": "hero", "criteria": { "between": { "input": "bucket", "from": 51, "to": 101 } } }
]
}
]
}
  • formatVersion is 3. An implementation rejects a manifest of a version it doesn't support.
  • revision is the lowercase hex SHA-256 of the UTF-8 JSON of { "formatVersion", "contextTypes" }, written as Vox writes them. It changes whenever anything in the manifest does, and documents built with a manifest carry it, so a system can tell when documents and manifest disagree, eg during a rebuild.
  • contextTypes are in stacking order, from the highest to the lowest.
  • isRestricted is true for context types that need a permission to select. They're only exported when the exporter is allowed to read them.
  • selection is explicit, when members are only selected by the caller, criteria, when the criteria expressions of the members select them (see Criteria), or programmatic, when Vox selects them with application code (see Selection).
  • isPortable is false for a context type whose members Vox selects with application code. A system outside Vox can't select those, and its caller passes their members explicitly.
  • isConcurrent is true for a context type that can have several selected members at once, one of each group, eg the variants of experiments that run at the same time. Any other context type has one selected member at most.
  • members are the members with their fallback chains, from the closest fallback. A system needs no fallback logic of its own.
  • group is the group of a member of a concurrent context type, eg the experiment of a variant, or missing for a group of its own. One member of a group is selected at most, and the bucket of a visitor is of the group (see Criteria).
  • criteria is the criteria expression of a member of a criteria context type, or missing if it has none.

Selection​

Selection turns an input into the selected members of some context types. The input is:

{
"host": "shop.example.se",
"path": "/sv/regnjackor",
"query": { "page": ["2"] },
"headers": { "accept-language": "sv-SE" },
"cookies": { "vox-visitor": "4f1c…" },
"attributes": { "customerGroup": "b2b" },
"nowUtc": "2026-10-24T12:00:00Z",
"visitorId": "4f1c…",
"explicit": { "Language": ["sv"], "warehouse": ["north"] }
}
  • headers are by their names in lowercase. attributes are the caller's, eg the claims of its token, which the host fills so they mean the same everywhere.
  • explicit are the members the caller selects, by the names or query names of their context types.

Selection runs in this order:

  1. Explicit members. A context type named in explicit is selected with those members, whatever else would select it. An unknown context type and a context type named twice are rejected, also when one of the names has an empty list. An empty list selects nothing: criteria don't select that context type either.
  2. Programmatic context types are selected by Vox with application code before it selects the rest, and passed on as explicit members. A system outside Vox can't, so its caller passes their members explicitly, and a context type without one isn't selected.
  3. Criteria context types that aren't selected explicitly select the members whose criteria hold, see Criteria. A context type whose criteria read the members of another (context.<type>) is selected after it, and otherwise they're selected in stacking order. Criteria that read each other's members are rejected.
  4. Fallbacks. Each selected member gets its fallback chain from the manifest.

A context type has one selected member at most. A concurrent one can have several, one of each group, eg a variant of each running experiment. A selection with more, explicitly or by criteria, is rejected: criteria of members that can apply at once must exclude each other. Several members are ordered by their ids, compared ordinally. Members of different groups are meant to set different values; where two of them both have a value, this order decides, so it's the same everywhere, although it isn't meant to be relied on. A member selected twice is selected once.

A context type without a selected member isn't selected, so its cells resolve to the baseline. The result is the selected members by the names of their context types:

{ "Language": [{ "id": "sv", "fallbacks": ["en"] }] }

Criteria​

A criteria expression is a JSON tree. Each node is an object with a single operator:

{
"and": [
{ "equals": { "input": "host", "value": "shop.example.se", "ignoreCase": true } },
{ "not": { "startsWith": { "input": "path", "value": "/en/" } } },
{ "between": { "input": "now", "from": "2026-11-01T00:00:00Z", "to": "2026-12-01T00:00:00Z" } }
]
}
  • and and or take an array of at least one node, and not takes a node.
  • equals, in and startsWith compare strings: value, or values for in. They compare ordinally, or ordinally ignoring case with "ignoreCase": true.
  • exists is true if the input has a value.
  • lessThan and greaterThan compare with value, exclusively, and between from from, inclusive, to to, exclusive. A number is compared as a decimal with the input read as a decimal, and a time, an ISO 8601 string with Z or an offset, as an instant with the input read as one. An input that can't be read as the bound's kind doesn't match.

The inputs are:

InputValues
host, pathThe host and path of the request.
query.<name>The values of a query string parameter.
header.<name>A header, by its name ignoring case.
cookie.<name>, attribute.<name>A cookie, or an attribute of the caller.
nowThe current UTC time.
bucketThe visitor's bucket for the member's group, see below.
context.<type>The members selected of another context type, by its name or query name.

An input with several values matches if one of them does, and an input without a value matches no comparison. So not of a comparison holds for a missing input.

The bucket of a visitor for a member is a number from 1 to 100: the first four bytes of the SHA-256 of the UTF-8 bytes of {visitorId}:{contextType}:{group} as a big-endian unsigned integer, modulo 100, plus 1, where group is the member's group, or its id without one. Without a visitor id, there's no bucket. The members of a group share a bucket, so their ranges split the visitors between them, eg the variants of an experiment, and each group buckets a visitor independently.

An expression with an unknown operator or input, or a node with other than one operator, is rejected when it's written. A member whose criteria aren't valid is never selected.

Candidates​

A selection selects members of some context types. The candidates of a context type are its selected members in their order, see Selection, followed by their fallbacks from the manifest in the same order, without repeating a member. A member that the manifest doesn't list, eg one of a context type selected programmatically, has no fallbacks.

Resolution​

A key matches a selection if every context of the key is among the candidates of its context type. Of the matching keys, the most specific one wins. Keys are compared by their context types in stacking order, from the highest:

  • a key's rank for a context type is the position of its member among the candidates, and a key without the context type ranks after every candidate,
  • the first context type where two keys rank differently decides.

So a closer fallback beats a farther one, a key with a context beats a key without it, and the stacking order decides, not the number of contexts: with Market ranked above Channel and Language, Market=se beats Channel=web|Language=sv. The baseline matches every selection and ranks last.

Documents​

A keyed document is an entity's values per key:

{
"memberOf": ["Market"],
"cells": [
{ "key": "", "values": { "name": "Rain jacket", "color": "Red" } },
{ "key": "Language=sv", "values": { "name": "Regnjacka" } },
{ "key": "Market=se", "exists": true, "values": {} }
]
}
  • values are the values of a cell by the paths of their fields. A document uses the same paths in all of its cells.
  • Each path resolves to its value in the most specific matching cell that has the path, so a Swedish cell with only a name still has the color of the baseline.

Existence​

exists is optional on a cell. A document exists in a selection if both of these hold:

  • Its own existence. Its baseline cell doesn't say "exists": false.
  • Its memberships. For each context type in memberOf with selected members, the entity is a member of one of them. It's a member of a selected member by the most specific matching cell with exists whose key has the member or one of its fallbacks, ranked with the member and its fallbacks as the candidates of the context type. Without one, it isn't a member. So a product in Swedish is in Finland Swedish, which falls back to Swedish, and a product hidden in Swedish is hidden in Finland Swedish too. The key can have other application context types too, eg Channel=web|Language=sv for a membership of the web channel that only applies in Swedish, and it then matches like any other key, so Channel=web|Language=sv wins over Channel=web when Swedish or a language that falls back to it is selected.

A membership never makes an entity exist that doesn't.

Authoring scopes​

Drafts and content releases are authoring scopes, written published, draft, release:{id} and release-draft:{id}, a draft within a release. Their ancestry is fixed: the draft and a release read through to published content, and a draft within a release to its release. Where content is, its address, is a scope and a key, eg draft|Language=sv, or the scope alone for its baseline.

The unpublished changes of an entity are an authoring envelope, layers over its published keyed document, one per scope that changes it:

{
"layers": [
{
"scope": "draft",
"cells": { "memberOf": [], "cells": [{ "key": "", "values": { "name": "Light rain jacket", "color": "Red" } }] },
"removed": ["Language=fi-sv"]
}
]
}

A read in a scope composes the scope's keyed document first, and then resolves its contexts as above:

  1. Compose. Start with the published document, or a baseline cell with "exists": false if the entity isn't published. Apply the layers of the scope's chain, from the one above published content to the scope itself. A layer's cell replaces all values at its key, and its exists replaces the existence there. A cell without values leaves the values of its key as they are, and a key in removed loses its values, so fallbacks apply there again.
  2. Resolve the composed document in the selection.

So a contextual value keeps its precedence over a general change: reading the draft above in Swedish, a published Language=sv name, Regnjacka, beats the draft's Light rain jacket, while a draft cell at Language=sv would win. A draft-only entity has "exists": true at the baseline of its draft layer, so it exists only in the draft, and a layer's existence at Market=se replaces the published one in its scope. A layer of a release has the incarnation of the release, which tells it apart from a later release with the same id.

Authoring descriptor​

The authoring descriptor tells which scopes a model has, apart from its manifest, so that the lifecycle of releases doesn't change the manifest's revision. GET api/contexts/authoring/descriptor serves it, and VoxAuthoringDescriptor reads and writes it in .NET:

{
"formatVersion": 1,
"revision": "9f2c…",
"hasDrafts": true,
"hasReleases": true,
"releases": [{ "id": "autumn", "name": "Autumn launch", "status": "draft", "incarnation": "639286436162416016" }]
}

releaseAuthority names the source whose releases the model uses, when they aren't its own. The releases are the open ones, which can be previewed in release:{id} and, with drafts, release-draft:{id}. Another format version is rejected. A descriptor lists at most 10,000 open releases. For releases received from a source, whose status may not be filterable, it reads every release, published and reverted ones too, so more than 10,000 of them fail the descriptor with VoxReadBudgetExceededException rather than leave open ones out.

Paths​

The paths of a document's values are the properties of its objects joined with dots, eg seo.title, down to values that aren't objects, such as strings, numbers and arrays, which a more specific cell replaces as a whole. An empty object is a value of its own. A resolved document is expanded from its paths back into objects. Property names with dots can't be told apart from nested objects, so documents published as keyed cells don't use them. VoxDocumentPaths flattens and expands them in .NET.

Published documents​

A projection publication publishes a source as documents, see Entity projections, in one of two shapes per context type it enumerates:

  • Per combination: a document per combination of members where the source is read, each with its key, exists and the source's memberOf, and none without a member, so a selection finds a document only when it selects a member of every context type published per combination. A delivery system resolves them as the cells of a keyed document whose cells each hold a whole document at the path "", the empty path: the document at the most specific key that the selection matches, if the source exists in the selection by the rules of existence. A document without a value, null at "", says there's no document there, so a less specific one doesn't apply either.
  • Keyed cells: the cells of a document, which a delivery system resolves as a keyed document. A cell at a more specific key only has the values that differ from the cells a selection matching it could resolve to instead, so each selection resolves to the values of the projection evaluated in it.

With both, the document of the selection is chosen first, and its cells are resolved in the same selection. Every document carries the revision of the manifest it was built with. A publication that includes drafts or releases publishes their documents where they differ as the layers of an authoring envelope, which a delivery system composes before it resolves, see Authoring scopes.

A reference in a document, { "$projection": key }, is resolved in the request's selection, with the members of its key's optional contexts on top of it. Its key is vox://entity/{entityType}/{entityId}?projection={projection}, with &context= and its contexts in the syntax of the context parameter, eg Market:no, ordered like the key, when it has them. The entity id, projection, context types and members are escaped like URI data. A delivery system that returns a graph keys the referenced projection by it in projections, so a reader looks it up without building the key.