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.
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 JSONPersonalizedEntry: Zod schema describing a CtflEntry that has associated personalization
entriesPersonalizationEntry: Zod schema describing a personalization entry, which is associated with a
PersonalizedEntry via its fields.nt_experiences propertyPersonalizationConfig: Zod schema describing the configuration of a PersonalizationEntry via
its fields.nt_config propertyisEntry<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 localeisPersonalizedEntry: Type guard for PersonalizedEntryisPersonalizationEntry: Type guard for PersonalizationEntryThese 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 requestExperienceEvent: Zod schema union of supported experience/personalization eventsBatchExperienceEvent: Zod schema describing each valid experience/personalization event within a
batch; Similar to ExperienceEvent, but with an additional anonymousId member on each event
schemaExperience/personalization event schemas:
AliasEvent: Zod schema describing an alias eventComponentViewEvent: Zod schema describing a component view event (may be a Contentful entry or
a Custom Flag)IdentifyEvent: Zod schema describing an identify eventPageViewEvent: Zod schema describing a page view eventScreenViewEvent: Zod schema describing a screen view eventTrackEvent: Zod schema describing a custom track eventExperienceResponse: Zod schema describing a full Experience API response; includes a data
object with changes, experiences, and profile propertiesBatchExperienceResponse: Zod schema describing a batch experience response from the Experience
API; includes a profiles collectionChange: Union of supported change types, which currently only includes VariableChange; this
change type is used for Custom FlagsSelectedPersonalization: Zod schema describing a selected personalization outcome for a userProfile: Zod schema describing a full user profile as received from the Experience APIInsights API endpoints currently do not return response data.
InsightsEvent: Zod schema union of supported insights/analytics eventsBatchInsightsEvent: Zod schema describing a batched Insights event payload; expects a profile
property alongside a collection of eventsInsights/analytics event schemas:
ComponentViewEvent: Zod schema describing a component view event (may be a Contentful entry or
a Custom Flag)