@vtex/client-cp
v0.4.0
Published
A client to fetch data from the VTEX Content Platform.
Maintainers
Keywords
Readme
@vtex/client-cp
A client to fetch data from the VTEX Content Platform.
Installation
npm install @vtex/client-cpUsage
import ClientCP from '@vtex/client-cp'
// Initialize the client
const client = new ClientCP({
tenant: 'mystore',
// Optional custom endpoints
controlPlaneBaseUrl: 'https://custom-control-api.com',
dataPlaneBaseUrl: 'https://custom-data-api.com'
// Disables the entryDataToPageContentType parse, to be used when testing FastStore support to the data returned by the Content Platform
disableParse: false
})
// List entries (from Data Plane API)
const entries = await client.listEntries({
accountName: 'accountName',
storeId: 'storeId',
contentType: 'contentType'
})
// Get a single entry by entryId (from Data Plane API)
const entry = await client.getEntry({
accountName: 'accountName',
storeId: 'storeId',
contentType: 'contentType',
entryId: 'entryId'
})
// Get a single entry by slug (from Data Plane API)
const entry = await client.getEntry({
accountName: 'accountName',
storeId: 'storeId',
contentType: 'contentType',
slug: 'slug'
})
// Preview entry by ID (from Control Plane API)
const previewEntry = await client.previewEntryById({
accountName: 'accountName',
storeId: 'storeId',
contentType: 'contentType',
entryId: 'entryId'
})
// Preview entry by slug (from Control Plane API)
const previewBySlug = await client.previewEntryBySlug({
accountName: 'accountName',
storeId: 'storeId',
contentType: 'contentType',
slug: 'slug'
})
// List preview entries (from Control Plane API)
const previewEntries = await client.listPreviewEntries({
accountName: 'accountName',
storeId: 'storeId',
contentType: 'contentType',
branchId: 'optional-branch-id' // optional
})API
Methods
listEntries
Fetches a list of content entries from the Data Plane API.
async listEntries(params: EntryPathParams): Promise<EntriesList>getEntry
Fetches a single content entry by ID from the Data Plane API.
async getEntry(params: EntryPathParams): Promise<EntryData>getEntryBySlug
Fetches a single content entry by slug from the Data Plane API.
async getEntryBySlug(params: EntryPathParams): Promise<EntryData>previewEntryById
Fetches a preview of a content entry by ID from the Control Plane API.
async previewEntryById(params: EntryPathParams): Promise<EntryData>previewEntryBySlug
Fetches a preview of a content entry by slug from the Control Plane API.
async previewEntryBySlug(params: EntryPathParams): Promise<EntryData>listPreviewEntries
Fetches a list of preview content entries from the Control Plane API.
async listPreviewEntries(params: EntryPathParams): Promise<EntriesList>Types
interface ContentEntry {
id: string
name: string
account: string
storeId: string
createdAt: string
updatedAt: string
createdBy: string
updatedBy: string
slug: string
}
interface EntryData {
componentKey: string
[key: string]: unknown
}
interface EntriesList {
entries: ContentEntry[]
hasNextPage: boolean
totalItems: number
}
interface EntryPathParams {
accountName: string
storeId: string
contentType: string
entryId?: string
slug?: string
branchId?: string
}
interface ClientOptions {
tenant: string
controlPlaneBaseUrl?: string
dataPlaneBaseUrl?: string
disableParse?: boolean
}Development
# Install dependencies
yarn install
# Run tests
yarn test
# Build
yarn run build