Visitor Identity
Export reference for Flags SDK and middleware visitor identity
import {
createCookieIdentity,
createRequestIdentity,
createVisitorCookieIdentity,
createVisitorRequestIdentity,
setSaltBucketingConfig,
} from "@octopus-energy/flags/identity";The Flags SDK factories and middleware factories are separate exports. A flag family selects one identity strategy; built-in strategies neither combine nor fall back to one another. For setup, see the identity guides.
Flags SDK factories
createCookieIdentity(options?)
Returns a Flags SDK identify callback. It reads visitor.id from options.cookie
then options.header; it returns optional enrichment without an ID when neither
is available. It never creates or persists an ID.
CookieIdentityOptions combines CookieOptions (cookie, header) with an
optional identify enrichment callback. Defaults: oe-visitor-id and
x-oe-visitor-id.
createCookieIdentityCookieIdentityOptionscreateRequestIdentity(options)
Returns a Flags SDK identify callback derived from the normalised client IP,
user agent, and an experiment-specific salt. RequestIdentityOptions requires
experimentName and accepts optional identify enrichment. It returns
enrichment without visitor.id when root-salt infrastructure is unavailable.
createRequestIdentityProp
Type
RequestIdentityOptionsProp
Type
Middleware factories
createVisitorCookieIdentity(options?)
Returns VisitorCookieIdentity. resolve(request) always returns a
VisitorIdentityResult: it reads or creates an anonymous ID, includes complete
requestHeaders, and its response(response?) forwards those headers and
persists the cookie. CookieOptions accepts cookie and header.
createVisitorCookieIdentityProp
Type
CookieOptionsVisitorCookieIdentityProp
Type
createVisitorRequestIdentity()
Returns VisitorIdentity. resolve(request, { experimentName }) derives a
request identity and returns VisitorIdentityResult | undefined. It returns
the original request headers and its response(response?) adds no cookie.
createVisitorRequestIdentityProp
Type
VisitorIdentityProp
Type
VisitorIdentityContextProp
Type
VisitorIdentityResult
Extends MiddlewareResult with visitorId. MiddlewareResult exposes
requestHeaders: Headers and response(response?: NextResponse): NextResponse.
Call response() only after downstream middleware has selected its response.
VisitorIdentityResultProp
Type
MiddlewareResultProp
Type
Salt configuration
setSaltBucketingConfig(config)
Sets the package-wide SaltBucketingConfig used by request-based identity.
config.getRootSalt() returns a root salt synchronously or asynchronously; it
can return a fixed environment value or a dynamic value when rotating the salt.
config.onSaltMissing(error) receives unavailable-salt reports. Configure it
once before use.
setSaltBucketingConfigProp
Type
SaltBucketingConfigProp
Type
createSaltRotationHandler(options?)
Creates a Web Request handler that rotates the root salt. Omit the options to
use CRON_SECRET, GLOBAL_CONFIG (falling back to EDGE_CONFIG), and
VERCEL_API_TOKEN, or pass resolved values explicitly.
createSaltRotationHandlerProp
Type
SaltRotationHandlerOptionsProp
Type
Supporting types
IdentityEnrichmentProp
Type