Contentful Personalization & Analytics
    Preparing search index...

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

    Contentful Logo

    Contentful Personalization & Analytics

    API Schema Library

    Readme · Reference · Contributing

    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 personalization. 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 personalization.

    • CtflEntry: Zod schema describing a generic Contentful entry; the fields member is loosely typed as any valid JSON
    • PersonalizedEntry: Zod schema describing a CtflEntry that has associated personalization entries
    • PersonalizationEntry: Zod schema describing a personalization entry, which is associated with a PersonalizedEntry via its fields.nt_experiences property
    • PersonalizationConfig: Zod schema describing the configuration of a PersonalizationEntry 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
    • isPersonalizedEntry: Type guard for PersonalizedEntry
    • isPersonalizationEntry: Type guard for PersonalizationEntry

    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 request
    • ExperienceEvent: Zod schema union of supported experience/personalization events
    • BatchExperienceEvent: Zod schema describing each valid experience/personalization event within a batch; Similar to ExperienceEvent, but with an additional anonymousId member on each event schema

    Experience/personalization event schemas:

    • AliasEvent: Zod schema describing an alias event
    • ComponentViewEvent: Zod schema describing a component view event (may be a Contentful entry or a Custom Flag)
    • 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 response from the Experience API; includes a profiles collection
    • Change: Union of supported change types, which currently only includes VariableChange; this change type is used for Custom Flags
    • SelectedPersonalization: Zod schema describing a selected personalization 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/analytics events
    • BatchInsightsEvent: Zod schema describing a batched Insights event payload; expects a profile property alongside a collection of events

    Insights/analytics event schemas:

    • ComponentViewEvent: Zod schema describing a component view event (may be a Contentful entry or a Custom Flag)

    Type Aliases

    AliasEvent
    App
    AudienceEntry
    AudienceEntryFields
    BatchExperienceData
    BatchExperienceEvent
    BatchExperienceEventArray
    BatchExperienceResponse
    BatchInsightsEvent
    BatchInsightsEventArray
    Campaign
    Change
    ChangeArray
    Channel
    ComponentViewEvent
    CtflEntry
    Dictionary
    EntryFields
    EntryReplacementComponent
    EntryReplacementVariant
    EntrySys
    ExperienceData
    ExperienceEvent
    ExperienceEventArray
    ExperienceEventType
    ExperienceRequestData
    ExperienceRequestOptions
    ExperienceResponse
    Flags
    GeoLocation
    GroupEvent
    IdentifyEvent
    InlineVariableComponent
    InsightsEvent
    InsightsEventArray
    InsightsEventType
    Json
    Library
    MergeTagEntry
    OptimizationData
    Page
    PageEventContext
    PageViewEvent
    PartialProfile
    PersonalizationComponent
    PersonalizationComponentArray
    PersonalizationConfig
    PersonalizationEntry
    PersonalizationEntryArray
    PersonalizationFields
    PersonalizationType
    PersonalizedEntry
    Profile
    Properties
    Screen
    ScreenEventContext
    ScreenViewEvent
    SelectedPersonalization
    SelectedPersonalizationArray
    SessionStatistics
    TrackEvent
    Traits
    UniversalEventContext
    UniversalEventProperties
    UnknownChange
    VariableChange

    Variables

    AliasEvent
    App
    AudienceEntry
    AudienceEntryFields
    BatchExperienceData
    BatchExperienceEvent
    BatchExperienceEventArray
    BatchExperienceResponse
    BatchInsightsEvent
    BatchInsightsEventArray
    Campaign
    Change
    ChangeArray
    ChangeType
    Channel
    ComponentViewEvent
    CtflEntry
    Dictionary
    EntryFields
    EntryReplacementComponent
    EntryReplacementVariant
    EntrySys
    ExperienceData
    ExperienceEvent
    ExperienceEventArray
    ExperienceRequestData
    ExperienceRequestOptions
    ExperienceResponse
    GeoLocation
    GroupEvent
    IdentifyEvent
    InlineVariableComponent
    InlineVariableComponentValueType
    InlineVariableVariant
    InsightsEvent
    InsightsEventArray
    Library
    MergeTagEntry
    Page
    PageEventContext
    PageViewEvent
    PartialProfile
    PersonalizationComponent
    PersonalizationComponentArray
    PersonalizationConfig
    PersonalizationEntry
    PersonalizationEntryArray
    PersonalizationFields
    PersonalizationType
    PersonalizedEntry
    Profile
    Properties
    Screen
    ScreenEventContext
    ScreenViewEvent
    SelectedPersonalization
    SelectedPersonalizationArray
    SessionStatistics
    TrackEvent
    Traits
    UniversalEventContext
    UniversalEventProperties
    UnknownChange
    VariableChange
    VariableChangeValue

    Functions

    isEntry
    isEntryReplacementComponent
    isEntryReplacementVariant
    isInlineVariableComponent
    isPersonalizationEntry
    isPersonalizedEntry