@se-studio/contentful-cms 1.0.60 → 1.0.63

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,222 @@
1
+ # cms-edit run — Batch Operations Guide
2
+
3
+ `run` executes a sequence of `cms-edit` operations from a JSON file. It is best suited for **patching fields on existing entries** — for creating complete new pages, use `create from-json` instead.
4
+
5
+ ```bash
6
+ cms-edit run --file patch.json
7
+ cms-edit run --file patch.json --dry-run # validate without saving
8
+ ```
9
+
10
+ ---
11
+
12
+ ## Batch File Format
13
+
14
+ A batch file is a JSON array of operation objects:
15
+
16
+ ```json
17
+ [
18
+ { "cmd": "open", "args": ["/solutions"] },
19
+ { "cmd": "set", "args": ["@c1", "heading", "New Heading"] },
20
+ { "cmd": "rtf", "args": ["@c2", "body", "Updated body.\n\nSecond paragraph."] },
21
+ { "cmd": "save" }
22
+ ]
23
+ ```
24
+
25
+ Each operation has:
26
+
27
+ | Field | Type | Description |
28
+ |---|---|---|
29
+ | `cmd` | string | The operation to execute (see Supported Commands) |
30
+ | `args` | string[] | Positional arguments (same as CLI args) |
31
+ | `opts` | object | Named options (same as CLI flags, without `--`) |
32
+ | `onError` | `"stop"` \| `"continue"` | What to do if this step fails. Default: `"stop"` |
33
+ | `as` | string | Variable name to bind the ref assigned by an `add` op (e.g. `"$item"`) |
34
+
35
+ ---
36
+
37
+ ## Supported Commands
38
+
39
+ ### `open`
40
+ Load a page or article by slug.
41
+ ```json
42
+ { "cmd": "open", "args": ["/solutions"] }
43
+ ```
44
+
45
+ ### `set`
46
+ Set a scalar field on an entry.
47
+ ```json
48
+ { "cmd": "set", "args": ["@c1", "heading", "New Heading"] }
49
+ { "cmd": "set", "args": ["@c2", "backgroundColour", "Navy"] }
50
+ { "cmd": "set", "args": ["@c3", "heading", null] }
51
+ ```
52
+
53
+ ### `rtf`
54
+ Set a rich text field from a markdown string.
55
+ ```json
56
+ { "cmd": "rtf", "args": ["@c2", "body", "## Heading\n\nParagraph text."] }
57
+ ```
58
+
59
+ ### `rtf-replace`
60
+ Find and replace text within an existing rich text field.
61
+ ```json
62
+ {
63
+ "cmd": "rtf-replace",
64
+ "args": ["@c2", "body"],
65
+ "opts": {
66
+ "find": "old phrase",
67
+ "replacePlain": "new phrase",
68
+ "mode": "all"
69
+ }
70
+ }
71
+ ```
72
+ Options: `find` (required), `replacePlain`, `replaceMarkdown`, `mode` (`"all"` or `"exactlyOne"`), `ignoreMarks`, `tableCol`, `tableRow`, `section`.
73
+
74
+ ### `add`
75
+ Create a new entry and link it into the tree.
76
+ ```json
77
+ { "cmd": "add", "args": ["HeroSimple", "component"] }
78
+ { "cmd": "add", "args": ["Generic", "component"], "opts": { "parent": "@c3" } }
79
+ { "cmd": "add", "args": ["Generic", "component"], "opts": { "after": "@c5" } }
80
+ { "cmd": "add", "args": ["Generic", "component"], "opts": { "target": "topContent" } }
81
+ ```
82
+ Options: `parent` (ref of a collection to add inside), `after` (ref to insert after), `target` (field name, default `"content"`), `existingId` (link an existing entry instead of creating).
83
+
84
+ ### `links-add`
85
+ Create a new CTA link and attach it to an entry's `links` field.
86
+ ```json
87
+ { "cmd": "links-add", "args": ["@c1"], "opts": { "type": "external", "label": "Learn More", "href": "https://example.com" } }
88
+ { "cmd": "links-add", "args": ["@c1"], "opts": { "type": "internal", "label": "Contact", "slug": "/contact" } }
89
+ ```
90
+ Options: `type`, `label`, `href`, `slug`, `id`, `assetId`.
91
+
92
+ ### `save`
93
+ Write all modified entries to Contentful as drafts.
94
+ ```json
95
+ { "cmd": "save" }
96
+ ```
97
+
98
+ ---
99
+
100
+ ## Variable Binding — Safe `add` + `set` Patterns
101
+
102
+ **The problem:** After an `add parent @cN` operation, all entries that come after `@cN` in the depth-first tree are renumbered. Any `set` using a hardcoded `@cM` ref may then target the wrong entry, and the batch reports `✓` — a silent false positive.
103
+
104
+ **The solution:** Use `"as": "$varname"` on the `add` op to capture the assigned ref, then use `"$varname"` in subsequent `set`/`rtf` args:
105
+
106
+ ```json
107
+ [
108
+ { "cmd": "open", "args": ["/solutions/hepatology"] },
109
+ {
110
+ "cmd": "add",
111
+ "args": ["Generic", "component"],
112
+ "opts": { "parent": "@c3" },
113
+ "as": "$item1"
114
+ },
115
+ { "cmd": "set", "args": ["$item1", "heading", "2017 — Cohort Launch"] },
116
+ { "cmd": "rtf", "args": ["$item1", "body", "The cohort was established.\n\nInitial enrolment began."] },
117
+ {
118
+ "cmd": "add",
119
+ "args": ["Generic", "component"],
120
+ "opts": { "parent": "@c3" },
121
+ "as": "$item2"
122
+ },
123
+ { "cmd": "set", "args": ["$item2", "heading", "2019 — First Publication"] },
124
+ { "cmd": "save" }
125
+ ]
126
+ ```
127
+
128
+ `$item1` and `$item2` always refer to the entries that were just created, regardless of how subsequent adds shift ref numbers.
129
+
130
+ ---
131
+
132
+ ## Ref Renumbering — What Happens Under the Hood
133
+
134
+ After any `add parent @cN`, refs are reassigned in depth-first traversal order from the root. Items that came *after* `@cN` in the tree get bumped forward.
135
+
136
+ **Example:** Page with 10 entries (`@c0`–`@c9`). Timeline collection is `@c8`, Disease Areas is `@c9`.
137
+
138
+ | After add | New item ref | Disease Areas ref |
139
+ |---|---|---|
140
+ | Initial | — | @c9 |
141
+ | Add 1 to @c8 | @c9 | @c10 |
142
+ | Add 2 to @c8 | @c10 | @c11 |
143
+ | Add 3 to @c8 | @c11 | @c12 |
144
+
145
+ If you write `set @c10 heading "..."` after Add 1, you are setting Disease Areas — not the new item. The batch reports `✓` because the field was set successfully, just on the wrong entry.
146
+
147
+ **The tool warns when this happens:**
148
+ ```
149
+ ✓ [3] add — Created component "Generic" as @c9 (ID: abc123)
150
+ ⚠ Refs renumbered after add-to-parent. Use "as": "$varname" on the add op and "$varname" in subsequent args to avoid ref drift.
151
+ ```
152
+
153
+ ---
154
+
155
+ ## Safe Patterns
156
+
157
+ ### Pattern A — Variable binding (recommended)
158
+ Use `"as": "$name"` and `"$name"` in args. Refs always point to the right entry.
159
+
160
+ ### Pattern B — All adds first, then sets
161
+ Do all `add` operations in one batch. Re-snapshot to see final refs. Write a second batch with `set`/`rtf` on the stable refs.
162
+
163
+ ```bash
164
+ # Batch 1: add all items
165
+ cms-edit run --file add-items.json
166
+
167
+ # Inspect final refs
168
+ cms-edit snapshot
169
+
170
+ # Batch 2: set fields using the stable refs from snapshot
171
+ cms-edit run --file set-fields.json
172
+ ```
173
+
174
+ ### Pattern C — Append to end only
175
+ If new items go at the end of the tree (after all existing entries), no existing refs are displaced. Use `after` to append at the tail.
176
+
177
+ ### Pattern D — Use `create from-json` for new pages
178
+ For building complete page trees from scratch, `create from-json` is safer than a `run` batch — it manages internal refs automatically and validates slugs before writing.
179
+
180
+ ---
181
+
182
+ ## Complete Example — Patching Fields on an Existing Page
183
+
184
+ ```json
185
+ [
186
+ { "cmd": "open", "args": ["/solutions"] },
187
+ { "cmd": "set", "args": ["@c1", "heading", "Evidence-Driven Solutions"] },
188
+ { "cmd": "set", "args": ["@c1", "preHeading", "What We Do"] },
189
+ {
190
+ "cmd": "rtf",
191
+ "args": [
192
+ "@c2",
193
+ "body",
194
+ "We partner with life sciences companies.\n\nOur platform integrates real-world data across disease areas."
195
+ ]
196
+ },
197
+ { "cmd": "save" }
198
+ ]
199
+ ```
200
+
201
+ Run:
202
+ ```bash
203
+ cms-edit run --file patch.json --dry-run # validate first
204
+ cms-edit run --file patch.json # apply
205
+ cms-edit open /solutions # inspect result
206
+ ```
207
+
208
+ ---
209
+
210
+ ## Error Handling
211
+
212
+ By default, execution stops on the first error. Use `"onError": "continue"` to keep running:
213
+
214
+ ```json
215
+ [
216
+ { "cmd": "open", "args": ["/solutions"] },
217
+ { "cmd": "set", "args": ["@c99", "heading", "Test"], "onError": "continue" },
218
+ { "cmd": "save" }
219
+ ]
220
+ ```
221
+
222
+ The final exit code is non-zero if any step failed, even with `"continue"`.
@@ -0,0 +1,190 @@
1
+ # cms-edit — Standard Editing Workflow
2
+
3
+ The standard workflow is: **open → snapshot → read/edit → diff → save**.
4
+
5
+ ---
6
+
7
+ ## Step 1: Discover What Exists
8
+
9
+ ```bash
10
+ # List all pages with slugs
11
+ cms-edit sitemap
12
+
13
+ # Search for entries by text
14
+ cms-edit search "hepatology"
15
+ ```
16
+
17
+ ---
18
+
19
+ ## Step 2: Open a Page or Article
20
+
21
+ ```bash
22
+ cms-edit open /solutions/hepatology
23
+ # or by entry ID:
24
+ cms-edit open 4xKpzQ2abc123
25
+ ```
26
+
27
+ `open` fetches the full entry tree and saves it to a local session file. All subsequent commands operate on this session without re-fetching from Contentful until you `save`.
28
+
29
+ **Output:**
30
+ ```
31
+ ✓ Opened /solutions/hepatology (12 entries)
32
+
33
+ @c0 page [draft] solutions/hepatology
34
+ @c1 component [draft] Image Hero
35
+ @c2 component [draft] Text Block
36
+ @c3 collection [draft] Timeline
37
+ @c4 component [draft] Timeline Item 1
38
+ @c5 component [draft] Timeline Item 2
39
+ @c6 component [draft] Disease Areas
40
+ ```
41
+
42
+ ---
43
+
44
+ ## Step 3: Inspect the Content Tree
45
+
46
+ ```bash
47
+ # Re-print the tree at any time
48
+ cms-edit snapshot
49
+
50
+ # Read all fields on an entry
51
+ cms-edit read @c2
52
+
53
+ # Read a specific field
54
+ cms-edit read @c2 heading
55
+ ```
56
+
57
+ **Example `read @c2` output:**
58
+ ```
59
+ @c2 component [draft] Text Block
60
+ heading: "Our Approach"
61
+ body: (rich text, 2 paragraphs)
62
+ backgroundColour: null
63
+ ```
64
+
65
+ ---
66
+
67
+ ## Step 4: Edit Fields
68
+
69
+ ### Scalar fields (text, boolean, number)
70
+ ```bash
71
+ cms-edit set @c2 heading "New Heading"
72
+ cms-edit set @c2 backgroundColour "Navy"
73
+ ```
74
+
75
+ ### Rich text fields
76
+ ```bash
77
+ # Inline markdown (short content)
78
+ cms-edit rtf @c2 body "## Overview\n\nFirst paragraph.\n\nSecond paragraph."
79
+
80
+ # From a file (long content)
81
+ cms-edit rtf @c2 body --file content/body.md
82
+ ```
83
+
84
+ ### Multi-value: replacing inline content
85
+ ```bash
86
+ # Replace a specific text phrase in a rich text field
87
+ cms-edit rtf replace @c2 body --find "old phrase" --replace-plain "new phrase"
88
+ ```
89
+
90
+ ### Links (CTAs)
91
+ ```bash
92
+ # Add a new external CTA link
93
+ cms-edit links add @c2 --type external --label "Learn More" --href "https://example.com"
94
+
95
+ # Add an internal link (to another page by slug)
96
+ cms-edit links add @c2 --type internal --label "Our Team" --slug /team
97
+ ```
98
+
99
+ ### Adding new entries
100
+ ```bash
101
+ # Add a new component to the page's content array
102
+ cms-edit add HeroSimple component
103
+
104
+ # Add a child item to a collection
105
+ cms-edit add Generic component --parent @c3
106
+
107
+ # Add after a specific entry
108
+ cms-edit add Generic component --after @c5
109
+ ```
110
+
111
+ **Important:** After any `add` or `remove`, re-run `cms-edit snapshot` — @ref numbers change after structural edits.
112
+
113
+ ---
114
+
115
+ ## Step 5: Review Changes
116
+
117
+ ```bash
118
+ cms-edit diff
119
+ ```
120
+
121
+ Shows a summary of which entries have been modified and which fields changed.
122
+
123
+ ---
124
+
125
+ ## Step 6: Save
126
+
127
+ ```bash
128
+ cms-edit save
129
+ ```
130
+
131
+ Writes all changes to Contentful as **drafts**. Nothing is published. A human must review and publish in the Contentful web app.
132
+
133
+ ---
134
+
135
+ ## Common Patterns
136
+
137
+ ### Edit a specific component's heading and body
138
+ ```bash
139
+ cms-edit open /about
140
+ cms-edit snapshot
141
+ cms-edit set @c3 heading "Updated heading"
142
+ cms-edit rtf @c3 body "New body text\n\nSecond paragraph."
143
+ cms-edit diff
144
+ cms-edit save
145
+ ```
146
+
147
+ ### Add a new section to an existing page
148
+ ```bash
149
+ cms-edit open /home
150
+ cms-edit snapshot
151
+ # Add a new Text Block after @c2
152
+ cms-edit add TextBlock component --after @c2
153
+ cms-edit snapshot # re-snapshot to see the new ref
154
+ cms-edit set @c3 heading "New Section"
155
+ cms-edit rtf @c3 body "Section content.\n\nMore detail."
156
+ cms-edit save
157
+ ```
158
+
159
+ ### Fix a field on multiple pages
160
+ Use `--session` to work on multiple pages without losing state:
161
+ ```bash
162
+ cms-edit --session fix-1 open /page-one
163
+ cms-edit --session fix-1 set @c1 heading "Fixed"
164
+ cms-edit --session fix-1 save
165
+
166
+ cms-edit --session fix-2 open /page-two
167
+ cms-edit --session fix-2 set @c1 heading "Fixed"
168
+ cms-edit --session fix-2 save
169
+ ```
170
+
171
+ ---
172
+
173
+ ## Creating New Pages
174
+
175
+ For creating complete new pages with components, use `create from-json` instead of the interactive `add` workflow:
176
+
177
+ ```bash
178
+ cms-edit help create-from-json
179
+ ```
180
+
181
+ ---
182
+
183
+ ## Status Badges
184
+
185
+ | Badge | Meaning |
186
+ |---|---|
187
+ | `[published]` | Entry is live in Contentful (no draft changes) |
188
+ | `[draft]` | Entry has unpublished changes or has never been published |
189
+ | `[changed]` | Entry has been modified in this session (unsaved) |
190
+ | `[pending]` | Entry is scheduled for deletion in this session |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@se-studio/contentful-cms",
3
- "version": "1.0.60",
3
+ "version": "1.0.63",
4
4
  "description": "CLI tool for AI agents to read and edit Contentful draft content without publish permissions",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,21 +25,22 @@
25
25
  },
26
26
  "files": [
27
27
  "dist",
28
+ "docs/help",
28
29
  "skills",
29
30
  "*.md"
30
31
  ],
31
32
  "dependencies": {
32
- "@clack/prompts": "^0.9.1",
33
+ "@clack/prompts": "^1.3.0",
33
34
  "@contentful/rich-text-types": "^17.2.7",
34
35
  "@modelcontextprotocol/sdk": "^1.29.0",
35
36
  "commander": "^14.0.3",
36
- "contentful-management": "^12.3.2",
37
+ "contentful-management": "^12.3.3",
37
38
  "dotenv": "^17.4.2",
38
39
  "picocolors": "^1.1.1",
39
40
  "zod": "^4.4.3"
40
41
  },
41
42
  "devDependencies": {
42
- "@biomejs/biome": "^2.4.14",
43
+ "@biomejs/biome": "^2.4.15",
43
44
  "@types/node": "^22.19.18",
44
45
  "typescript": "^6.0.3",
45
46
  "vitest": "^4.1.5"