A package to interact with the Cockpit CMS API, including functionalities to handle GraphQL requests and various CMS content manipulations.
Install the package via npm:
npm install --save @unchainedshop/cockpit-api
First, set your cockpit graphql endpoint to env
COCKPIT_GRAPHQL_ENDPOINT
then import and initialize the API:
import { CockpitAPI } from '@unchainedshop/cockpit-api';
const cockpit = await CockpitAPI();
You can make GraphQL requests using the graphQL
method:
import { gql } from 'graphql-tag';
const query = gql`
query {
allPosts {
title
content
}
}
`;
const result = await cockpit.graphQL(query, {});
console.log(result);
You can perform various content operations such as fetching items, aggregating models, and manipulating pages.
Example to get a content item:
const contentItem = await cockpit.getContentItem({ model: 'posts', id: '123' });
console.log(contentItem);
Provides various methods to interact with the Cockpit CMS.
Methods:
graphQL(document, variables)
getContentItem({ model, id }, locale, queryParams)
getAggregateModel({ model, pipeline }, locale)
getContentItems(model, locale, queryParams)
getContentTree(model, locale, queryParams)
postContentItem(model, item)
deleteContentItem(model, id)
pages(locale, queryParams)
pageById({ page, id }, locale, queryParams)
pageByRoute(route, locale)
pagesMenus(locale)
pagesMenu(name, locale)
pagesRoutes(locale)
pagesSitemap()
pagesSetting(locale)
healthCheck()
lokalize(projectName,locale, nested)
assetById(assetId)
imageAssetById(assetId, queryParams)
getFullRouteForSlug(slug)
you can change the caching behavior by setting the envs below
COCKPIT_CACHE__MAX_LIMIT # number of records to store in before overwriting it
COCKPIT_CACHE_TTL # caching period in milliseconds
Contributions are welcome! Please open an issue or submit a pull request.
- Fork the repository.
- Create a new branch:
git checkout -b feature-branch-name
. - Make your changes and commit them:
git commit -m 'Add new feature'
. - Push to the branch:
git push origin feature-branch-name
. - Open a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
This `README.md` covers installation, basic usage, detailed API reference, contribution guidelines, and licensing information. Adjust the details as needed for your specific implementation.