@bettercms-ai/sdk 1.14.0 → 1.15.0

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.
package/README.md CHANGED
@@ -85,6 +85,40 @@ try {
85
85
  }
86
86
  ```
87
87
 
88
+ ## Draft previews and visual editing
89
+
90
+ A client created with `perspective: "drafts"` reads unpublished content — through a
91
+ `content:read:draft` API key, or through a `previewToken` minted for one document.
92
+
93
+ Draft reads also carry **stega provenance**: invisible zero-width characters appended to every
94
+ prose value, naming the entry and field it came from. That is what lets the dashboard's canvas
95
+ (and the `<VisualEditing>` overlay) map a rendered string back to its editor without guessing at
96
+ its text. It is **on by default for `perspective: "drafts"` from 1.15.0** — before that it had to
97
+ be asked for, and a preview build that did not know to ask rendered anonymous strings.
98
+
99
+ ```ts
100
+ const draft = createClient({
101
+ apiUrl,
102
+ workspace: "my-workspace",
103
+ apiKey: process.env.BETTERCMS_DRAFT_KEY,
104
+ perspective: "drafts", // stega is on
105
+ });
106
+
107
+ // Opt out — e.g. when diffing or checksumming draft content, where the invisible
108
+ // characters would show up as differences.
109
+ const plain = createClient({
110
+ apiUrl,
111
+ workspace: "my-workspace",
112
+ apiKey: process.env.BETTERCMS_DRAFT_KEY,
113
+ perspective: "drafts",
114
+ stega: false,
115
+ });
116
+ ```
117
+
118
+ Published reads never carry provenance, whatever `stega` is set to: the payload must not reach a
119
+ production build. Strip it yourself with `stripStega(value)` if you need the clean string, and
120
+ decode it with `decodeStega(value)`.
121
+
88
122
  ## API
89
123
 
90
124
  ### `BetterCMS.site(options)`
package/dist/index.cjs CHANGED
@@ -1307,6 +1307,7 @@ function createClient(options) {
1307
1307
  throw lastError ?? new BetterCMSError("Unreachable", 0, "NETWORK_ERROR");
1308
1308
  }
1309
1309
  const draft = perspective === "drafts";
1310
+ const stega = options.stega ?? draft;
1310
1311
  return {
1311
1312
  perspective,
1312
1313
  async getEntry(slug, opts) {
@@ -1314,12 +1315,12 @@ function createClient(options) {
1314
1315
  token: previewToken,
1315
1316
  depth: opts?.depth,
1316
1317
  select: opts?.select?.join(","),
1317
- stega: options.stega ? "1" : void 0
1318
+ stega: stega ? "1" : void 0
1318
1319
  })}` : `${base}/content-entries/${encodeURIComponent(slug)}${qs({
1319
1320
  depth: opts?.depth,
1320
1321
  select: opts?.select?.join(","),
1321
1322
  perspective: draft ? "draft" : void 0,
1322
- stega: draft && options.stega ? "1" : void 0
1323
+ stega: draft && stega ? "1" : void 0
1323
1324
  })}`;
1324
1325
  return unwrap(await fetchJSON(url));
1325
1326
  },
@@ -1331,7 +1332,7 @@ function createClient(options) {
1331
1332
  depth: opts?.depth,
1332
1333
  select: opts?.select?.join(","),
1333
1334
  perspective: draft ? "draft" : void 0,
1334
- stega: draft && options.stega ? "1" : void 0
1335
+ stega: draft && stega ? "1" : void 0
1335
1336
  })}`;
1336
1337
  return unwrap(await fetchJSON(url));
1337
1338
  },