feat(CMA): Add entry, asset, and content-type CRUD commands#3272
Open
Ivo Toby (ivo-toby) wants to merge 11 commits into
Open
feat(CMA): Add entry, asset, and content-type CRUD commands#3272Ivo Toby (ivo-toby) wants to merge 11 commits into
Ivo Toby (ivo-toby) wants to merge 11 commits into
Conversation
…d output Implement complete CLI command surface for entries (list, get, create, update, publish, unpublish, archive, unarchive, delete), assets (list, get, upload, update, publish, unpublish, delete), and content-types (get, create, update, publish, unpublish, delete). Built on a declarative command-factory that wires up standard options (--json, --quiet, --agent-mode, --dry-run), runtime context fallback for auth/space/environment, and TOON-format output for agent consumption. Includes unit and integration tests for all commands and utilities. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add spy on process.exit in beforeEach and restore it in afterEach to mock process termination calls during upload command tests
Add firstLocaleValue to jest mock for output utility across asset command tests to prevent mock-related errors. Replace inline exit spy creation with shared exitSpy variable and simplify test assertions by removing try-catch blocks around process.exit calls.
Wiz Scan Summary
To detect these findings earlier in the dev lifecycle, try using Wiz Code VS Code Extension. |
… client
Replace createManagementClient (legacy nested client) with
createPlainClient in command-factory and all command handlers.
This eliminates the deprecation warning from contentful-management v12.
API changes:
- environment.getEntry(id) → client.entry.get({entryId: id})
- environment.getAsset(id) → client.asset.get({assetId: id})
- environment.getContentType(id) → client.contentType.get({contentTypeId: id})
- entity.publish/unpublish/delete/update() → client.<type>.<method>({id}, data)
All 329 command tests and 38 command-factory tests updated and passing.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5258d3dac1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "Codex (@codex) review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".
The old list.js was still using createManagementClient (nested/legacy client), causing the deprecation warning. Replaced with a TypeScript version using createPlainClient and the standard createCommand factory. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Makes commands more discoverable by showing concrete usage examples in help text, useful for both humans and LLM-driven workflows. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Address PR review P1 feedback: 1. Remove `default: 'master'` from --environment-id yargs option. The middleware already resolves active environment from user config and falls back to master — the yargs default made omission indistinguishable from explicit use, overriding the configured active environment. 2. Fetch the space's default locale dynamically in asset upload instead of hardcoding en-US. Spaces without en-US would fail on upload when --locale was omitted. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| } | ||
| }, | ||
| handler: async (client, argv) => { | ||
| return client.contentType.unpublish({contentTypeId: argv.id}) |
Contributor
There was a problem hiding this comment.
today I learned that content types can be unpublished :)
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
Adds a complete CLI command surface for managing entries, assets, and content types via the Contentful Management API. Built on a new declarative
createCommandfactory that standardizes option handling, output formatting, and error behavior across all commands.New commands:
contentful entry— get, list, create, update, delete, publish, unpublish, archive, unarchivecontentful asset— get, list, upload, update, delete, publish, unpublishcontentful content-type— get, create, update, delete, publish, unpublish (replaces old JS-basedget)New infrastructure:
lib/utils/command-factory.ts— Declarative command builder wiring standard options (--space-id,--environment-id,--management-token,--json,--quiet,--agent-mode,--dry-run,--yes) and error handlinglib/utils/output.ts— Unified output dispatch (JSON, table, key-value, quiet/ID-only, TOON for agents)lib/utils/exit-codes.ts— Structured exit codes (1 = client error, 2 = server error)lib/utils/validators.ts— Input validation helpers (ID format, JSON field parsing)lib/utils/toon-encoder.ts+lib/utils/toon.ts— TOON format encoder for agent-mode outputKey design decisions
--dry-runto preview operations without side effects.--json(raw API response),--quiet(IDs only for piping),--agent-mode(TOON format for LLM agent consumption).--versionto prevent accidental overwrites.--yesis passed.Changes
lib/cmds/{asset,entry,content-type}_cmds/lib/utils/lib/cmds/content-type_cmds/get.jswith TypeScript versionTest plan
npm test)npm run tsc)npm run test:integration)contentful entry list --space-id <id> --jsoncontentful asset upload --file ./test.png --title "Test" --dry-run--quietpiping works:contentful entry list --content-type page -q | head -5