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.
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 JSONOptimizedEntry: Zod schema describing a CtflEntry that has associated optimization entriesOptimizationEntry: Zod schema describing an optimization entry, which is associated with an
OptimizedEntry via its fields.nt_experiences propertyOptimizationConfig: Zod schema describing the configuration of an OptimizationEntry 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 localeisOptimizedEntry: Type guard for OptimizedEntryisOptimizationEntry: Type guard for OptimizationEntrynormalizeOptimizationConfig: Runtime helper that fills omitted OptimizationConfig fields with
SDK-safe defaultsThese 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 requestBatchExperienceRequestData: Zod schema describing the data payload for a batch Experience API
request; requires at least one batch eventExperienceEvent: Zod schema union of supported Experience API eventsBatchExperienceEvent: Zod schema describing each valid Experience API event within a batch;
Similar to ExperienceEvent, but with an additional anonymousId member on each event schemaExperience API event schemas:
AliasEvent: Zod schema describing an alias eventViewEvent: Zod schema describing a component view event used for entry and Custom Flag
exposure trackingGroupEvent: Zod schema describing a group eventIdentifyEvent: 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 API response; includes a
data payload described by BatchExperienceResponseDataBatchExperienceResponseData: Zod schema describing the data payload for
BatchExperienceResponseChange: Union of supported change types, which currently only includes VariableChange; this
change type is used for Custom FlagsSelectedOptimization: Zod schema describing a selected optimization 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 API eventsBatchInsightsEvent: Zod schema describing a batched Insights API event payload; expects a
profile property alongside a collection of eventsInsights API event schemas:
ClickEvent: Zod schema describing a component_click event used for entry click trackingHoverEvent: Zod schema describing a component_hover event used for entry hover trackingViewEvent: Zod schema describing a component view event used for entry and Custom Flag
exposure tracking
Contentful Optimization API Schema Library.
Remarks
A collection of Zod Mini schemas and their inferred TypeScript types that provide run-time validation for Optimization SDK API requests and responses.