@contentful/optimization-api-schemas
v0.1.0-alpha12
Published
<p align="center"> <a href="https://www.contentful.com/developers/docs/personalization/"> <img alt="Contentful Logo" title="Contentful" src="https://raw.githubusercontent.com/contentful/optimization/v0.1.0-alpha12/contentful-icon.png" width="150">
Keywords
Readme
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.
Getting Started
Install using an NPM-compatible package manager, pnpm for example:
pnpm install @contentful/optimization-api-schemasConsult Zod's documentation for more information on working with Zod Mini schemas.
Contentful CDA 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.
Essential Schemas
CtflEntry: Zod schema describing a generic Contentful entry; thefieldsmember is loosely typed as any valid JSONOptimizedEntry: Zod schema describing aCtflEntrythat has associated optimization entriesOptimizationEntry: Zod schema describing an optimization entry, which is associated with anOptimizedEntryvia itsfields.nt_experiencespropertyOptimizationConfig: Zod schema describing the configuration of anOptimizationEntryvia itsfields.nt_configproperty
Essential Functions
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 localeisOptimizedEntry: Type guard forOptimizedEntryisOptimizationEntry: Type guard forOptimizationEntrynormalizeOptimizationConfig: Runtime helper that fills omittedOptimizationConfigfields with SDK-safe defaults
Experience API Schemas
These schemas help validate at run-time that both the request and response data for Experience API requests conform to current API specifications.
Essential Experience API Request Schemas
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 toExperienceEvent, but with an additionalanonymousIdmember on each event schema
Experience API event schemas:
AliasEvent: Zod schema describing analiaseventViewEvent: Zod schema describing acomponentview event used for entry and Custom Flag exposure trackingGroupEvent: Zod schema describing agroupeventIdentifyEvent: Zod schema describing anidentifyeventPageViewEvent: Zod schema describing apageview eventScreenViewEvent: Zod schema describing ascreenview eventTrackEvent: Zod schema describing a customtrackevent
Essential Experience API Response Schemas
ExperienceResponse: Zod schema describing a full Experience API response; includes adataobject withchanges,experiences, andprofilepropertiesBatchExperienceResponse: Zod schema describing a batch Experience API response; includes adatapayload described byBatchExperienceResponseDataBatchExperienceResponseData: Zod schema describing thedatapayload forBatchExperienceResponseChange: Union of supported change types, which currently only includesVariableChange; 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 API
Insights API Schemas
Insights API endpoints currently do not return response data.
Essential Insights API Response Schemas
InsightsEvent: Zod schema union of supported Insights API eventsBatchInsightsEvent: Zod schema describing a batched Insights API event payload; expects aprofileproperty alongside a collection ofevents
Insights API event schemas:
ClickEvent: Zod schema describing acomponent_clickevent used for entry click trackingHoverEvent: Zod schema describing acomponent_hoverevent used for entry hover trackingViewEvent: Zod schema describing acomponentview event used for entry and Custom Flag exposure tracking
