Skip to content

feat: [CP-432] [CP-433] Adding CP integration as a data source alternative to hCMS - #2807

Merged
lariciamota merged 21 commits into
mainfrom
feat/cp-data-plane-integration
May 12, 2025
Merged

lariciamota merged 21 commits into
mainfrom
feat/cp-data-plane-integration

Conversation

@marcopaulo7

@marcopaulo7 marcopaulo7 commented Apr 25, 2025 •

Copy link
Copy Markdown
Contributor

What's the purpose of this pull request?

This PR introduces the code necessary to enable the use of Content Platform as a data source for the store.

How it works?

The changes in this pull request introduce a new content service (contentService) that replaces the previous direct usage of the getPage function from @vtex/client-cms. The contentService decides which source should be used (hCMS or CP, based on the new contentSource.type config) and uses the related client, @vtex/client-cms for hCMS queries or the new @vtex/client-cp for CP queries.

Key Changes

  • Centralized Content Service:

    • Introduced a contentService to unify content retrieval logic across CMS platforms (hCMS and CP).
    • Backward Compatibility: Existing hCMS workflows remain unchanged; the service defaults to legacy methods for hCMS data sources.
    • Parameter Handling: Accepts ContentOptions and converts them to EntryPathParams for CP data sources (see convertOptionsToParams).
  • PreviewData Type:

    • New PreviewData type combines the existing Locator with CP-specific parameters, enabling preview enhancements without breaking changes.
  • Slug-Based Previews (CP):

    • Directly uses entry slugs for preview redirects when using CP as the data source, removing the need for extra API calls to resolve IDs (see implementation).

How to Test

  • Test Both Data Sources:
    • Verify functionality with hCMS and CP by:
      • Navigating through the store’s pages (e.g., homepage, product pages).
      • Ensuring all contentType entries (e.g., pages, blogs) render correctly.

For Local CP Testing:

  • Use a local CP instance by configuring the client:
    // Example client configuration  
    this.clientCP = new ClientCP({
      tenant: config.api.storeId,
      controlPlaneBaseUrl: "<YOUR_LOCAL_CP_URL>",  
      dataPlaneBaseUrl: "<YOUR_LOCAL_DATA_URL>"  
    })
  • For more details, refer to the client-cp PR.

Starters Deploy Preview

References

Checklist

You may erase this after checking them all 😉

PR Title and Commit Messages

  • PR title and commit messages follow the Conventional Commits specification
    • Available prefixes: feat, fix, chore, docs, style, refactor, ci and test

PR Description

  • Added a label according to the PR goal - breaking change, bug, contributing, performance, documentation..

Dependencies

  • Committed the pnpm-lock.yaml file when there were changes to the packages

Documentation

  • PR description
  • For documentation changes, ping @Mariana-Caetano to review and update (Or submit a doc request)

@marcopaulo7
marcopaulo7 requested a review from a team as a code owner April 25, 2025 14:10
@marcopaulo7
marcopaulo7 requested review from eduardoformiga and lariciamota and removed request for a team April 25, 2025 14:10
@marcopaulo7
marcopaulo7 marked this pull request as draft April 25, 2025 14:11
@codesandbox-ci

codesandbox-ci Bot commented Apr 25, 2025 •

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@marcopaulo7 marcopaulo7 added enhancement New feature or request breaking changes This pull request will introduce breaking changes labels Apr 28, 2025
@marcopaulo7 marcopaulo7 self-assigned this Apr 28, 2025
@marcopaulo7
marcopaulo7 marked this pull request as ready for review April 28, 2025 14:05
Comment thread packages/core/src/pages/login.tsx Resolved
Comment thread packages/core/src/pages/login.tsx Resolved
Comment thread packages/core/src/pages/[slug]/p.tsx Resolved
Comment thread packages/core/src/pages/404.tsx Resolved
Comment thread packages/core/src/pages/api/preview.ts Resolved
Comment thread packages/core/src/pages/login.tsx Resolved
@marcopaulo7
marcopaulo7 requested a review from lariciamota May 2, 2025 12:09
@marcopaulo7
marcopaulo7 force-pushed the feat/cp-data-plane-integration branch from a255e1c to 930482c Compare May 2, 2025 18:40
@marcopaulo7
marcopaulo7 requested a review from lariciamota May 5, 2025 21:53

@lariciamota lariciamota left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉
I've tested using the CMS config - the pages (GlobalSections, LandingPage, PLP, PDP, 404, 500 and search) are working as they should!

@marcopaulo7 marcopaulo7 removed the breaking changes This pull request will introduce breaking changes label May 6, 2025
Comment thread packages/core/src/pages/api/preview.ts Resolved
Comment thread packages/core/src/pages/api/preview.ts Resolved
Comment thread pnpm-lock.yaml Resolved
@marcopaulo7
marcopaulo7 force-pushed the feat/cp-data-plane-integration branch from 8ee8a7c to 1a68929 Compare May 8, 2025 13:01
@marcopaulo7
marcopaulo7 requested a review from lucasfp13 May 8, 2025 13:08
@lariciamota
lariciamota merged commit 122e2d9 into main May 12, 2025
@lariciamota
lariciamota deleted the feat/cp-data-plane-integration branch May 12, 2025 14:36
lariciamota pushed a commit that referenced this pull request Aug 1, 2025
…omponentKey (#2915)

## What's the purpose of this pull request?

This PR makes it so FastStore Core is capable of rendering components
based on data from the CMS, using `$componentKey`s to identity each
component. It also adds the `$componentKey`s to each component, based on
their new schemas (for Content Platform) added in [this
PR](#2742).

## How it works?

The implementation here is backwards compatible, so during the existing
rendering flow a new check was added to look for the `$componentKey`
property in a section's data. Also, for each component that renders a
section, the `$componentKey` property was added, then, when indexing all
available components, the new property will now be used if its present.
To keep backwards compatibility, the `$componentKey`s are matching the
names of the components.

## How to test it?

Since this change should be totally backwards compatible, if you're
testing this branch with any current store, fetching data from hCMS, you
should see no change in behaviour and everything should still render
normally. Running `@faststore/core` locally also should look normal.

You can also test this by using this branch alongside the new CP client
being used in #2807.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants