|
| 1 | +--- |
| 2 | +name: contentstack-cli-content-type |
| 3 | +description: >- |
| 4 | + Develops and maintains the contentstack-cli-content-type csdx plugin (content-type list, |
| 5 | + details, audit, compare, compare-remote, diagram). Use when editing this repository, |
| 6 | + ContentTypeCommand setup and flags, CMA/Management SDK usage, axios audit/references calls, |
| 7 | + diff/compare HTML output, Graphviz diagrams, or oclif readme/manifest workflows. |
| 8 | +--- |
| 9 | + |
| 10 | +# contentstack-cli-content-type |
| 11 | + |
| 12 | +## Repository role |
| 13 | + |
| 14 | +npm package `contentstack-cli-content-type`: a **Contentstack CLI** (`csdx`) plugin that reads Content Type metadata from a stack—list, field details, audit log lines, version or cross-stack comparison, and stack content-model diagrams. |
| 15 | + |
| 16 | +## Code layout |
| 17 | + |
| 18 | +| Area | Path | |
| 19 | +|------|------| |
| 20 | +| Command classes (oclif) | `src/commands/content-type/*.ts` | |
| 21 | +| Shared base | `src/core/command.ts` — `ContentTypeCommand` extends `@contentstack/cli-command` `Command` | |
| 22 | +| Core output / logic | `src/core/content-type/*.ts` | |
| 23 | +| HTTP client (axios CMA) | `src/core/contentstack/client.ts`, `src/core/contentstack/error.ts` | |
| 24 | +| Stack / CT fetch helpers | `src/utils/index.ts` (uses Management SDK from `@contentstack/cli-utilities`) | |
| 25 | +| Types | `src/types/index.ts` | |
| 26 | +| Config (pagination limits) | `src/config/index.ts` | |
| 27 | + |
| 28 | +Commands **parse flags**, call **`setup(flags)`** (see below), build **`managementSDKClient`**, then call utils + core builders. See [references/architecture.md](references/architecture.md) and [references/commands.md](references/commands.md). |
| 29 | + |
| 30 | +## Authentication and stack identity |
| 31 | + |
| 32 | +1. `authenticationHandler.getAuthDetails()`; must have **access token** or command exits with `auth:login` message (`exit: 2`). |
| 33 | +2. User must pass **either** a **management token alias** (`-a` / `--alias` or `--token-alias`) **or** **stack API key** (`-k` / `--stack-api-key`) or deprecated `--stack` (maps to stack key). If neither: error and `process.exit(1)` (message references “token alias or stack UID”). |
| 34 | +3. Token alias: `getToken(alias)` → `apiKey` from token; warns if token type is not `management`. |
| 35 | +4. `ContentTypeCommand` constructs **`ContentstackClient(this.cmaHost, authToken)`** for REST calls that use `api_key` in headers. |
| 36 | + |
| 37 | +**Do not log** tokens, `authorization` / `authtoken` headers, or full CLI credentials. |
| 38 | + |
| 39 | +## Two ways to call APIs |
| 40 | + |
| 41 | +- **Axios `ContentstackClient`**: `GET https://{cmaHost}/v3/...` with default headers `authorization` (if Bearer) or `authtoken`, plus per-request `headers: { api_key }`. Used for audit logs and references. Errors → `ContentstackError` via `buildError`. |
| 42 | +- **Management SDK** (`managementSDKClient({ host, 'X-CS-CLI': ... })`): stack fetch, content types, global fields, content type by version—see `src/utils/index.ts`. |
| 43 | + |
| 44 | +## Build and CLI metadata |
| 45 | + |
| 46 | +From `package.json`: |
| 47 | + |
| 48 | +- **`prepack`**: `rm -rf lib && tsc -b && oclif manifest && oclif readme` — publishable `lib/`, manifest, and README command docs. |
| 49 | +- **`version`**: `oclif readme && git add README.md`. |
| 50 | + |
| 51 | +After changing commands, flags, or descriptions, run the appropriate script so **README** and **oclif.manifest.json** stay in sync. |
| 52 | + |
| 53 | +## Short command names (csdx) |
| 54 | + |
| 55 | +`package.json` → `csdxConfig.shortCommandName`: |
| 56 | + |
| 57 | +| Command id | Short name | |
| 58 | +|------------|------------| |
| 59 | +| `content-type:audit` | CTAUDIT | |
| 60 | +| `content-type:compare` | CTCMP | |
| 61 | +| `content-type:compare-remote` | CTCMP-R | |
| 62 | +| `content-type:details` | CTDET | |
| 63 | +| `content-type:diagram` | CTDIAG | |
| 64 | +| `content-type:list` | CTLS | |
| 65 | + |
| 66 | +## Further reading |
| 67 | + |
| 68 | +- [references/architecture.md](references/architecture.md) — command → core mapping, auth flow, CMA shape. |
| 69 | +- [references/commands.md](references/commands.md) — flags, UX notes, files to edit per command. |
0 commit comments