Skip to content

API reference

featureFlags(options) creates a Layeron Feature Flags module for code-defined flags, rollout rules, publishing, rollback, and evaluation.

Terminal window
import { featureFlags } from "@layeron/modules"

Create a Layeron Feature Flags module from code-defined flags.

Terminal window
featureFlags(options: FeatureFlagsModuleOptions): FeatureFlagsModule

Reference to a Layeron product instance used by Feature Flags.

FieldTypeDescription
productNamestringLayeron product name for the referenced instance.
namespacestringPlatform namespace for the instance. Defaults to default.
namestringStable name of the referenced product instance.

Options accepted by featureFlags(options).

FieldTypeDescription
namestringStable Feature Flags instance name.
namespacestring | undefinedPlatform namespace for the instance. Defaults to default.
flagsRecord<Layeron.Modules.FeatureFlags.FeatureFlag>Code-defined flags keyed by flag key.
policyLayeron.Modules.Policy.PolicyModule | undefinedPolicy module used to authorize Feature Flags operations.
auditboolean | undefinedWhether Feature Flags records audit history for publish and rollback operations. Defaults to true.
observabilityLayeron.Observability.ObservabilityConfig | undefinedObservability settings for evaluations, publishes, history reads, and rollbacks.

Code-defined flag definition.

FieldTypeDescription
keystringStable flag key used for evaluation.
type”boolean” | “string” | “number” | “json” | “variant”Value type returned by the flag.
defaultunknownFallback value returned when no rule or environment override matches.
environmentsRecord<unknown> | undefinedEnvironment-specific override values keyed by environment name.
rulesFeatureFlagRule[] | undefinedOrdered targeting rules evaluated before the default value.

Targeting rule for one feature flag.

FieldTypeDescription
idstring | undefinedOptional stable rule id returned when this rule matches.
kind”tenant” | “user” | “attribute” | “percentage”Targeting strategy used by the rule.
valueunknownFlag value returned when the rule matches.
tenantsstring[] | undefinedTenant ids matched by a tenant rule.
usersstring[] | undefinedUser ids matched by a user rule.
attributestring | undefinedAttribute name read from evaluation attributes.
operator”equals” | undefinedAttribute comparison operator. The current operator is equals.
expectedunknown | undefinedExpected attribute value for an attribute rule.
percentageint32 | undefinedPercentage rollout from 0 to 100 for a percentage rule.
stickinessstring | undefinedEvaluation context field used to keep percentage rollout assignment stable.

Backing product references used by the Feature Flags runtime.

FieldTypeDescription
policyFeatureFlagsProductRef | undefinedPolicy product reference used for Feature Flags authorization.

Normalized Feature Flags module configuration.

FieldTypeDescription
kind”feature_flags”Module configuration discriminator for Feature Flags.
namestringStable Feature Flags instance name.
namespacestringPlatform namespace for the instance. Defaults to default.
flagsFeatureFlag[]Normalized flag definitions compiled from code.
backingFeatureFlagsBackingConfigBacking product references used by the Feature Flags runtime.
auditbooleanWhether Feature Flags records audit history for publish and rollback operations.
snapshotFeatureFlagsSnapshotCurrent code-defined Feature Flags snapshot.
observabilityLayeron.Observability.ObservabilityConfig | undefinedObservability settings recorded with the Feature Flags product configuration.

Immutable Feature Flags snapshot that can be published, read, or rolled back.

FieldTypeDescription
version”0.1”Snapshot schema version.
namespacestringPlatform namespace for the instance. Defaults to default.
namestringStable Feature Flags instance name.
flagsFeatureFlag[]Flag definitions contained in the snapshot.
checksumstringStable checksum of the snapshot content.

Input accepted by Feature Flags evaluation.

FieldTypeDescription
keystringFlag key to evaluate.
environmentstring | undefinedEnvironment name used for environment overrides and published snapshots.
tenantIdstring | undefinedTenant id used by tenant rules, percentage stickiness, and Policy context.
userIdstring | undefinedUser id used by user rules, percentage stickiness, and Policy subject derivation.
sessionIdstring | undefinedSession id used by percentage stickiness when selected.
attributesRecord<unknown> | undefinedStructured attributes used by attribute rules and Policy context.
subjectLayeron.Modules.Policy.PolicySubject | undefinedExplicit Policy subject for authorized Feature Flags operations.
defaultunknown | undefinedFallback value returned when the flag key is missing.

Result returned after evaluating a feature flag.

FieldTypeDescription
keystringFlag key that was evaluated.
valueunknownSelected flag value.
type”boolean” | “string” | “number” | “json” | “variant”Value type of the selected flag.
reason”environment” | “tenant” | “user” | “attribute” | “percentage” | “default” | “fallback”Reason that selected the returned value.
ruleIdstring | undefinedRule id that matched, when a targeting rule selected the value.
versionstringSnapshot schema version used for the evaluation.
checksumstringSnapshot checksum used for the evaluation.

Input accepted when publishing the current code-defined snapshot.

FieldTypeDescription
environmentstring | undefinedEnvironment name that receives the published snapshot.
messagestring | undefinedHuman-readable publish message stored in history.
subjectLayeron.Modules.Policy.PolicySubject | undefinedPolicy subject used to authorize the publish operation.

Result returned after publishing a Feature Flags snapshot.

FieldTypeDescription
namespacestringPlatform namespace for the instance. Defaults to default.
namestringStable Feature Flags instance name.
versionstringPublished snapshot schema version.
checksumstringPublished snapshot checksum.
publishedAtstringISO timestamp when the snapshot was published.
environmentstring | undefinedEnvironment name that received the published snapshot.

Input accepted when reading the active Feature Flags snapshot.

FieldTypeDescription
environmentstring | undefinedEnvironment name used to read a published snapshot.
subjectLayeron.Modules.Policy.PolicySubject | undefinedPolicy subject used to authorize the read operation.

Result returned after reading the active Feature Flags snapshot.

FieldTypeDescription
namespacestringPlatform namespace for the instance. Defaults to default.
namestringStable Feature Flags instance name.
environmentstring | undefinedEnvironment name used for the read.
source”code” | “published”Source of the returned snapshot.
snapshotFeatureFlagsSnapshotReturned Feature Flags snapshot.
publishedAtstring | undefinedISO timestamp when the returned snapshot was published.
messagestring | undefinedPublish or rollback message associated with the returned snapshot.

Input accepted when reading Feature Flags publish history.

FieldTypeDescription
environmentstring | undefinedEnvironment name used to filter history entries.
limitint32 | undefinedMaximum history entries to return. The runtime caps this value at 100.
subjectLayeron.Modules.Policy.PolicySubject | undefinedPolicy subject used to authorize the history read.

One Feature Flags publish or rollback history entry.

FieldTypeDescription
action”publish” | “rollback”History action recorded for the snapshot.
environmentstring | undefinedEnvironment name associated with the history entry.
messagestring | undefinedHuman-readable message stored with the history entry.
versionstringSnapshot schema version recorded in the history entry.
checksumstringSnapshot checksum recorded in the history entry.
publishedAtstringISO timestamp when the history entry was created.

Result returned after reading Feature Flags history.

FieldTypeDescription
itemsFeatureFlagsHistoryEntry[]History entries ordered from newest to oldest.
cursorstring | undefinedPagination cursor reserved for future history pagination.

Input accepted when rolling back to a published Feature Flags snapshot.

FieldTypeDescription
checksumstringSnapshot checksum to restore.
environmentstring | undefinedEnvironment name to roll back.
messagestring | undefinedHuman-readable rollback message stored in history.
subjectLayeron.Modules.Policy.PolicySubject | undefinedPolicy subject used to authorize the rollback operation.

Result returned after rolling back a Feature Flags snapshot.

FieldTypeDescription
rolledBackToChecksumstringSnapshot checksum restored by the rollback.
rolledBackFromChecksumstring | undefinedSnapshot checksum replaced by the rollback when a previous published snapshot existed.

Layeron Feature Flags module returned by featureFlags(options).

FieldTypeDescription
name”feature_flags”Module name.
configFeatureFlagsConfigNormalized Feature Flags module configuration.
observabilityLayeron.Observability.ObservabilityConfig | undefinedEffective observability policy recorded on the module declaration.

Evaluate one feature flag and return the selected value plus selection metadata.

Terminal window
evaluate(input: FeatureFlagsEvaluateInput): FeatureFlagsEvaluateResult

Publish the current code-defined Feature Flags snapshot.

Terminal window
publish(input?: FeatureFlagsPublishInput): FeatureFlagsPublishResult

Read the active Feature Flags snapshot for an environment or the code-defined snapshot.

Terminal window
read(input?: FeatureFlagsReadInput): FeatureFlagsReadResult

Read Feature Flags publish and rollback history.

Terminal window
history(input?: FeatureFlagsHistoryInput): FeatureFlagsHistoryResult

Restore a previously published Feature Flags snapshot by checksum.

Terminal window
rollback(input: FeatureFlagsRollbackInput): FeatureFlagsRollbackResult