Gathering detailed insights and metrics for @content-sync/content-cloud-cli
Gathering detailed insights and metrics for @content-sync/content-cloud-cli
Gathering detailed insights and metrics for @content-sync/content-cloud-cli
Gathering detailed insights and metrics for @content-sync/content-cloud-cli
npm install @content-sync/content-cloud-cli
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
900%
10
Compared to previous day
Last Week
-66.7%
20
Compared to previous week
Last Month
-53.8%
192
Compared to previous month
Last Year
0%
608
Compared to previous year
2
4
Use the Content Cloud CLI to auto-generate client code for your Content Cloud space in Content Sync.
1npm install -g @content-sync/content-cloud-cli
The URL of the publisher to connect to. This will depend on the region of your space and can be viewed in the space settings of the Content Sync app.
You can use the CC_BASE_URL
environment variable to set this or pass a -b
/ --base-url
parameter to your command.
The access token to use for all requests. This token must have access to the service:publisher API. Permissions depend on the command you want to run.
You can use the CC_ACCESS_TOKEN
environment variable to set this or pass a -a
/ --access-token
parameter to your command.
The token can include an environment ID that may alter the result of the command. Double check that you are using the correct environment ID e.g. when generating code to receive the correct information.
Print information about how to use the CLI or a specific command:
1# General information 2content-cloud help 3 4# Help with the command `generate` 5content-cloud help generate
Print basic information about the connected space and token:
1# General information about the space and token 2content-cloud info
Below examples save the files at ./app/content-cloud but you can change this to match your project folder structure.
1content-cloud generate rest typescript -o app/content-cloud
E.g. in your Next.js app, you can use the generated client like this:
1import { ContentCloudRestClient } from "@/app/content-cloud/content-cloud-rest-client"; 2 3export default async function ContentList() { 4 // For public APIs or when providing the access token statically as an environment variable: 5 const contentCloud = new ContentCloudRestClient(); 6 7 const contentList = await contentCloud.contentCollection({ 8 // E.g. to filter by content type (good for auto completion and type safety): 9 //content_type: "BasicPageContent", 10 }); 11 12 return ( 13 <div> 14 <h1>Content List</h1> 15 {contentList.items.map((content) => ( 16 <div key={content.sys.id}> 17 <h2>{content.sys.name}</h2> 18 {content.sys.slug && <p>Maybe add a route for: {content.sys.slug}</p>} 19 </div> 20 ))} 21 </div> 22 ); 23}
Never share client secrets with your users or serve it to browsers; only expose the JWTs you are creating to your end users using the client secret.
To generate a JWT and use it to request content, adjust your code like this:
1import { ContentCloudPermission, ContentCloudService, generateAccessToken } from "@/app/content-cloud/content-cloud-authentication"; 2// ... 3 4export default async function ContentList() { 5 // For private APIs without a static access token: 6 const contentCloud = new ContentCloudRestClient({ 7 accessToken: generateAccessToken({ 8 permissions: [ 9 // The base permission to query content. 10 ContentCloudPermission.CONTENT_READ, 11 // To download assets and display images. 12 ContentCloudPermission.ASSET_READ_FILE, 13 // To read and write user data. 14 ContentCloudPermission.USER_DATA_READ, 15 ContentCloudPermission.USER_DATA_WRITE, 16 ], 17 // The APIs the user is allowed to access. 18 services: [ContentCloudService.LIVE, ContentCloudService.ASSETS], 19 // From your auth system, e.g. Auth0. 20 userId: 'test-user-id', 21 userDataContentTypes: ['*'], 22 }), 23 }); 24 25 //... 26}
1content-cloud generate graphql typescript -o app/content-cloud
1content-cloud graphql graphql typescript -o app/content-cloud
No vulnerabilities found.