Contentful Personalization & Analytics
    Preparing search index...

    Module @contentful/optimization-api-schemas - v0.0.0

    Contentful Optimization API Schema Library.

    A collection of Zod Mini schemas and their inferred TypeScript types that provide run-time validation for Optimization SDK API requests and responses.

    Contentful Logo

    Contentful Personalization & Analytics

    API Schema Library

    Guides · Reference · Contributing

    Warning

    The Optimization SDK Suite is pre-release (alpha). Breaking changes may be published at any time.

    The Contentful Optimization API Schema Library is a collection of Zod Mini schemas and their inferred TypeScript types. These schemas help provide run-time validation when working with requests and responses for the APIs referenced within Optimization SDKs.

    Table of Contents

    Install using an NPM-compatible package manager, pnpm for example:

    pnpm install @contentful/optimization-api-schemas
    

    Consult Zod's documentation for more information on working with Zod Mini schemas.

    These schemas assist in determining whether Contentful content entries provided by the CDA and its SDK are valid for optimization. These schemas do not encapsulate all features and functionality specified in the CDA SDK's exported TypeScript type system, but strive to remain compatible enough for the purposes of optimization.

    • CtflEntry: Zod schema describing a generic Contentful entry; the fields member is loosely typed as any valid JSON
    • OptimizedEntry: Zod schema describing a CtflEntry that has associated optimization entries
    • OptimizationEntry: Zod schema describing an optimization entry, which is associated with an OptimizedEntry via its fields.nt_experiences property
    • OptimizationConfig: Zod schema describing the configuration of an OptimizationEntry via its fields.nt_config property
    • isEntry<S extends SkeletonType, M extends ChainModifiers, L extends string>: Type guard that checks whether the given value is a Contentful Entry, passing through the specified skeleton, chain modifiers, and locale
    • isOptimizedEntry: Type guard for OptimizedEntry
    • isOptimizationEntry: Type guard for OptimizationEntry
    • normalizeOptimizationConfig: Runtime helper that fills omitted OptimizationConfig fields with SDK-safe defaults

    These schemas help validate at run-time that both the request and response data for Experience API requests conform to current API specifications.

    • ExperienceRequestData: Zod schema describing the data payload for an Experience API request
    • BatchExperienceRequestData: Zod schema describing the data payload for a batch Experience API request; requires at least one batch event
    • ExperienceEvent: Zod schema union of supported Experience API events
    • BatchExperienceEvent: Zod schema describing each valid Experience API event within a batch; Similar to ExperienceEvent, but with an additional anonymousId member on each event schema

    Experience API event schemas:

    • AliasEvent: Zod schema describing an alias event
    • ViewEvent: Zod schema describing a component view event used for entry and Custom Flag exposure tracking
    • GroupEvent: Zod schema describing a group event
    • IdentifyEvent: Zod schema describing an identify event
    • PageViewEvent: Zod schema describing a page view event
    • ScreenViewEvent: Zod schema describing a screen view event
    • TrackEvent: Zod schema describing a custom track event
    • ExperienceResponse: Zod schema describing a full Experience API response; includes a data object with changes, experiences, and profile properties
    • BatchExperienceResponse: Zod schema describing a batch Experience API response; includes a data payload described by BatchExperienceResponseData
    • BatchExperienceResponseData: Zod schema describing the data payload for BatchExperienceResponse
    • Change: Union of supported change types, which currently only includes VariableChange; this change type is used for Custom Flags
    • SelectedOptimization: Zod schema describing a selected optimization outcome for a user
    • Profile: Zod schema describing a full user profile as received from the Experience API

    Insights API endpoints currently do not return response data.

    • InsightsEvent: Zod schema union of supported Insights API events
    • BatchInsightsEvent: Zod schema describing a batched Insights API event payload; expects a profile property alongside a collection of events

    Insights API event schemas:

    • ClickEvent: Zod schema describing a component_click event used for entry click tracking
    • HoverEvent: Zod schema describing a component_hover event used for entry hover tracking
    • ViewEvent: Zod schema describing a component view event used for entry and Custom Flag exposure tracking

    Interfaces

    NormalizedOptimizationConfig

    Type Aliases

    AliasEvent
    App
    AudienceEntry
    AudienceEntryFields
    AudienceEntrySkeleton
    BatchExperienceEvent
    BatchExperienceEventArray
    BatchExperienceRequestData
    BatchExperienceResponse
    BatchExperienceResponseData
    BatchInsightsEvent
    BatchInsightsEventArray
    Campaign
    Change
    ChangeArray
    Channel
    ClickEvent
    CtflEntry
    Dictionary
    EntryFields
    EntryReplacementComponent
    EntryReplacementVariant
    EntrySys
    ExperienceData
    ExperienceEvent
    ExperienceEventArray
    ExperienceEventType
    ExperienceRequestData
    ExperienceRequestOptions
    ExperienceResponse
    Flags
    GeoLocation
    GroupEvent
    HoverEvent
    IdentifyEvent
    InlineVariableComponent
    InsightsEvent
    InsightsEventArray
    InsightsEventType
    InteractionEventProperties
    Json
    Library
    MergeTagEntry
    OptimizationComponent
    OptimizationComponentArray
    OptimizationConfig
    OptimizationData
    OptimizationEntry
    OptimizationEntryArray
    OptimizationEntryFields
    OptimizationEntrySkeleton
    OptimizationType
    OptimizedEntry
    Page
    PageEventContext
    PageViewEvent
    PartialProfile
    Profile
    Properties
    ResponseEnvelope
    Screen
    ScreenEventContext
    ScreenViewEvent
    SelectedOptimization
    SelectedOptimizationArray
    SessionStatistics
    TrackEvent
    Traits
    UniversalEventContext
    UniversalEventProperties
    UnknownChange
    VariableChange
    ViewEvent

    Variables

    AliasEvent
    App
    AudienceEntry
    AudienceEntryFields
    AudienceEntrySkeleton
    BatchExperienceEvent
    BatchExperienceEventArray
    BatchExperienceRequestData
    BatchExperienceResponse
    BatchExperienceResponseData
    BatchInsightsEvent
    BatchInsightsEventArray
    Campaign
    Change
    ChangeArray
    ChangeBase
    ChangeType
    Channel
    ClickEvent
    CtflEntry
    Dictionary
    EntryFields
    EntryReplacementComponent
    EntryReplacementVariant
    EntrySys
    ExperienceData
    ExperienceEvent
    ExperienceEventArray
    ExperienceRequestData
    ExperienceRequestOptions
    ExperienceResponse
    GeoLocation
    GroupEvent
    HoverEvent
    IdentifyEvent
    InlineVariableComponent
    InlineVariableComponentValueType
    InlineVariableVariant
    InsightsEvent
    InsightsEventArray
    InteractionEventProperties
    Library
    MergeTagEntry
    OptimizationComponent
    OptimizationComponentArray
    OptimizationConfig
    OptimizationEntry
    OptimizationEntryArray
    OptimizationEntryFields
    OptimizationEntrySkeleton
    OptimizationType
    OptimizedEntry
    Page
    PageEventContext
    PageViewEvent
    PartialProfile
    Profile
    Properties
    ResponseEnvelope
    Screen
    ScreenEventContext
    ScreenViewEvent
    SelectedOptimization
    SelectedOptimizationArray
    SessionStatistics
    TrackEvent
    Traits
    UniversalEventContext
    UniversalEventProperties
    UnknownChange
    VariableChange
    VariableChangeValue
    ViewEvent

    Functions

    isEntry
    isEntryReplacementComponent
    isEntryReplacementVariant
    isInlineVariableComponent
    isMergeTagEntry
    isOptimizationEntry
    isOptimizedEntry
    normalizeOptimizationConfig
    parseWithFriendlyError