💡 refactor(contentful.js): Cleaning up/improving types related to contentful.js#342
Open
Charles Hudson (phobetron) wants to merge 2 commits into
Open
💡 refactor(contentful.js): Cleaning up/improving types related to contentful.js#342Charles Hudson (phobetron) wants to merge 2 commits into
contentful.js#342Charles Hudson (phobetron) wants to merge 2 commits into
Conversation
…ntentful.js` ## Summary Refactors the Optimization SDK’s Contentful entry typing to rely on the official `contentful` SDK types instead of locally modeling full Contentful entries with Zod. Runtime validation now focuses on Optimization-owned fields, with shared structural guards for resolved entries, unresolved links, Rich Text values, merge tags, audiences, optimizations, and optimized entries. ## Changes - Replaced local Contentful entry/link/schema approximations with `contentful` SDK entry, skeleton, collection, and link types. - Added shared structural guards such as `isResolvedContentfulEntry`, `isUnresolvedEntryLink`, `isRichTextDocument`, `isResolvedOptimizationEntry`, and `isResolvedOptimizedEntry`. - Updated optimized-entry resolution to reject unresolved variant links and ensure selected variants match the baseline entry content type. - Changed preview-support fetch and mapper APIs to preserve full Contentful entry collections, including collection-level `includes.Entry`, so preview variant names can resolve from included entries. - Added the Next.js `/api-schemas` subpath and updated Next.js documentation to point schema/type imports there. - Updated Web, React Web, React Native, Next.js, Node, Angular, iOS, and Android consumers to use the shared schema helpers instead of duplicated local guards. - Consolidated small shared test/build-script type guard helpers and related cleanup. ## Test coverage - Added coverage for paginated Contentful collection fetching with included entries. - Updated preview entry mapper tests for collection-based inputs. - Updated optimized-entry resolver tests for resolved entries, unresolved links, and variant resolution behavior. - Updated schema tests for the new Contentful entry and Rich Text guard behavior. - Refactored related React Native and Web tests to use shared helper guards. [[NT-3558](https://contentful.atlassian.net/browse/NT-3558)]
Wiz Scan Summary
To detect these findings earlier in the dev lifecycle, try using Wiz Code VS Code Extension. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refactors the Optimization SDK’s Contentful entry typing to rely on the official
contentfulSDK types instead of locally modeling full Contentful entries with Zod. Runtime validation now focuses on Optimization-owned fields, with shared structural guards for resolved entries, unresolved links, Rich Text values, merge tags, audiences, optimizations, and optimized entries.Changes
contentfulSDK entry, skeleton, collection, and link types.isResolvedContentfulEntry,isUnresolvedEntryLink,isRichTextDocument,isResolvedOptimizationEntry, andisResolvedOptimizedEntry.includes.Entry, so preview variant names can resolve from included entries./api-schemassubpath and updated Next.js documentation to point schema/type imports there.Test coverage
[NT-3558]