@contentful/optimization-api-schemas
v0.1.0-alpha8
Published
<p align="center"> <a href="https://www.contentful.com/developers/docs/personalization/"> <img alt="Contentful Logo" title="Contentful" src="../../contentful-icon.png" width="150"> </a> </p>
Keywords
Readme
Readme · Reference · Contributing
[!WARNING]
The Optimization SDK Suite is currently 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 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.
Essential Schemas
CtflEntry: Zod schema describing a generic Contentful entry; thefieldsmember is loosely typed as any valid JSONPersonalizedEntry: Zod schema describing aCtflEntrythat has associated personalization entriesPersonalizationEntry: Zod schema describing a personalization entry, which is associated with aPersonalizedEntryvia itsfields.nt_experiencespropertyPersonalizationConfig: Zod schema describing the configuration of aPersonalizationEntryvia 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 localeisPersonalizedEntry: Type guard forPersonalizedEntryisPersonalizationEntry: Type guard forPersonalizationEntry
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 requestExperienceEvent: Zod schema union of supported experience/personalization eventsBatchExperienceEvent: Zod schema describing each valid experience/personalization event within a batch; Similar toExperienceEvent, but with an additionalanonymousIdmember on each event schema
Experience/personalization event schemas:
AliasEvent: Zod schema describing analiaseventComponentViewEvent: Zod schema describing acomponentview event (may be a Contentful entry or a Custom Flag)IdentifyEvent: 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 response from the Experience API; includes aprofilescollectionChange: Union of supported change types, which currently only includesVariableChange; 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 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/analytics eventsBatchInsightsEvent: Zod schema describing a batched Insights event payload; expects aprofileproperty alongside a collection ofevents
Insights/analytics event schemas:
ComponentViewEvent: Zod schema describing acomponentview event (may be a Contentful entry or a Custom Flag)
