@bettercms-ai/sdk 1.11.0 → 1.12.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/dist/index.cjs +59 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +67 -3
- package/dist/index.d.ts +67 -3
- package/dist/index.js +57 -6
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -41,6 +41,7 @@ __export(index_exports, {
|
|
|
41
41
|
addModelFields: () => addModelFields,
|
|
42
42
|
addPageFields: () => addPageFields,
|
|
43
43
|
asStringArray: () => asStringArray,
|
|
44
|
+
commandManagedLayout: () => commandManagedLayout,
|
|
44
45
|
createApiKey: () => createApiKey,
|
|
45
46
|
createClient: () => createClient,
|
|
46
47
|
createEntry: () => createEntry,
|
|
@@ -61,6 +62,7 @@ __export(index_exports, {
|
|
|
61
62
|
getBlockType: () => import_types.getBlockType,
|
|
62
63
|
getEntry: () => getEntry,
|
|
63
64
|
getForm: () => getForm2,
|
|
65
|
+
getManagedLayout: () => getManagedLayout,
|
|
64
66
|
getManagedPage: () => getManagedPage,
|
|
65
67
|
getMedia: () => getMedia,
|
|
66
68
|
getMember: () => getMember,
|
|
@@ -285,6 +287,15 @@ var BetterCMSDeliveryClient = class {
|
|
|
285
287
|
listContentAll(opts) {
|
|
286
288
|
return listContentAll(this, opts);
|
|
287
289
|
}
|
|
290
|
+
async getLayout() {
|
|
291
|
+
try {
|
|
292
|
+
const result = await this.fetchJSON(`${this.baseUrl}/${this.workspace}/layout`);
|
|
293
|
+
return result.data;
|
|
294
|
+
} catch (error) {
|
|
295
|
+
if (error instanceof BetterCMSError && error.status === 404) return null;
|
|
296
|
+
throw error;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
288
299
|
/** Build the full URL for a content path. */
|
|
289
300
|
url(path) {
|
|
290
301
|
return `${this.baseUrl}/${this.workspace}/content/${path}`;
|
|
@@ -817,6 +828,27 @@ async function generateSeoMeta(client, input) {
|
|
|
817
828
|
return res.data;
|
|
818
829
|
}
|
|
819
830
|
|
|
831
|
+
// src/methods/management/layout.ts
|
|
832
|
+
async function getManagedLayout(client, opts) {
|
|
833
|
+
const query = new URLSearchParams();
|
|
834
|
+
if (opts?.scope) query.set("scope", opts.scope);
|
|
835
|
+
if (opts?.pageId) query.set("pageId", opts.pageId);
|
|
836
|
+
const result = await client.fetchJSON(
|
|
837
|
+
client.url(`/management/layout${query.size ? `?${query}` : ""}`),
|
|
838
|
+
opts?.projectId ? { headers: { "X-BCMS-Project": opts.projectId } } : void 0
|
|
839
|
+
);
|
|
840
|
+
return result.data;
|
|
841
|
+
}
|
|
842
|
+
async function commandManagedLayout(client, input) {
|
|
843
|
+
const { ifMatch, projectId, ...body } = input;
|
|
844
|
+
const result = await client.fetchJSON(client.url("/management/layout/commands"), {
|
|
845
|
+
method: "POST",
|
|
846
|
+
headers: { "If-Match": `W/"${ifMatch}"`, ...projectId ? { "X-BCMS-Project": projectId } : {} },
|
|
847
|
+
body: JSON.stringify(body)
|
|
848
|
+
});
|
|
849
|
+
return result.data;
|
|
850
|
+
}
|
|
851
|
+
|
|
820
852
|
// src/management-client.ts
|
|
821
853
|
var DEFAULT_BASE_URL2 = "https://api.bettercms.ai/v1";
|
|
822
854
|
var DEFAULT_TIMEOUT2 = 1e4;
|
|
@@ -989,6 +1021,13 @@ var BetterCMSManagementClient = class extends BetterCMSDeliveryClient {
|
|
|
989
1021
|
extractComponent(input) {
|
|
990
1022
|
return extractComponent(this, input);
|
|
991
1023
|
}
|
|
1024
|
+
// ── Layout: draft-only Global/page authoring; publishing remains dashboard-gated. ──
|
|
1025
|
+
getManagedLayout(opts) {
|
|
1026
|
+
return getManagedLayout(this, opts);
|
|
1027
|
+
}
|
|
1028
|
+
commandManagedLayout(input) {
|
|
1029
|
+
return commandManagedLayout(this, input);
|
|
1030
|
+
}
|
|
992
1031
|
// ── AI (Option B): write/rewrite/translate copy + generate SEO meta (BYOK-metered) ──
|
|
993
1032
|
/** Write, rewrite, or translate a piece of copy. Returns the suggested text. */
|
|
994
1033
|
writeContent(input) {
|
|
@@ -1194,16 +1233,17 @@ function createClient(options) {
|
|
|
1194
1233
|
return {
|
|
1195
1234
|
perspective,
|
|
1196
1235
|
async getEntry(slug, opts) {
|
|
1197
|
-
const query = qs({
|
|
1198
|
-
depth: opts?.depth,
|
|
1199
|
-
select: opts?.select?.join(",")
|
|
1200
|
-
});
|
|
1201
1236
|
const url = draft && previewToken ? `${apiUrl}/api/v1/preview/${encodeURIComponent(slug)}${qs({
|
|
1202
1237
|
token: previewToken,
|
|
1203
1238
|
depth: opts?.depth,
|
|
1204
1239
|
select: opts?.select?.join(","),
|
|
1205
1240
|
stega: options.stega ? "1" : void 0
|
|
1206
|
-
})}` : `${base}/content-entries/${encodeURIComponent(slug)}${
|
|
1241
|
+
})}` : `${base}/content-entries/${encodeURIComponent(slug)}${qs({
|
|
1242
|
+
depth: opts?.depth,
|
|
1243
|
+
select: opts?.select?.join(","),
|
|
1244
|
+
perspective: draft ? "draft" : void 0,
|
|
1245
|
+
stega: draft && options.stega ? "1" : void 0
|
|
1246
|
+
})}`;
|
|
1207
1247
|
return unwrap(await fetchJSON(url));
|
|
1208
1248
|
},
|
|
1209
1249
|
async listEntries(opts) {
|
|
@@ -1212,7 +1252,9 @@ function createClient(options) {
|
|
|
1212
1252
|
page: opts?.page,
|
|
1213
1253
|
perPage: opts?.perPage,
|
|
1214
1254
|
depth: opts?.depth,
|
|
1215
|
-
select: opts?.select?.join(",")
|
|
1255
|
+
select: opts?.select?.join(","),
|
|
1256
|
+
perspective: draft ? "draft" : void 0,
|
|
1257
|
+
stega: draft && options.stega ? "1" : void 0
|
|
1216
1258
|
})}`;
|
|
1217
1259
|
return unwrap(await fetchJSON(url));
|
|
1218
1260
|
},
|
|
@@ -1233,6 +1275,15 @@ function createClient(options) {
|
|
|
1233
1275
|
})}`;
|
|
1234
1276
|
return unwrap(await fetchJSON(url));
|
|
1235
1277
|
},
|
|
1278
|
+
async getLayout() {
|
|
1279
|
+
const url = `${base}/layout${draft ? "?perspective=draft" : ""}`;
|
|
1280
|
+
try {
|
|
1281
|
+
return unwrap(await fetchJSON(url));
|
|
1282
|
+
} catch (error) {
|
|
1283
|
+
if (error instanceof BetterCMSError && error.status === 404) return null;
|
|
1284
|
+
throw error;
|
|
1285
|
+
}
|
|
1286
|
+
},
|
|
1236
1287
|
async listForms(opts) {
|
|
1237
1288
|
const url = `${base}/forms${qs({
|
|
1238
1289
|
projectId: opts?.projectId ?? defaultProjectId
|
|
@@ -1671,6 +1722,7 @@ var import_types = require("@bettercms-ai/types");
|
|
|
1671
1722
|
addModelFields,
|
|
1672
1723
|
addPageFields,
|
|
1673
1724
|
asStringArray,
|
|
1725
|
+
commandManagedLayout,
|
|
1674
1726
|
createApiKey,
|
|
1675
1727
|
createClient,
|
|
1676
1728
|
createEntry,
|
|
@@ -1691,6 +1743,7 @@ var import_types = require("@bettercms-ai/types");
|
|
|
1691
1743
|
getBlockType,
|
|
1692
1744
|
getEntry,
|
|
1693
1745
|
getForm,
|
|
1746
|
+
getManagedLayout,
|
|
1694
1747
|
getManagedPage,
|
|
1695
1748
|
getMedia,
|
|
1696
1749
|
getMember,
|