@bettercms-ai/sdk 1.10.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 +82 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +138 -3
- package/dist/index.d.ts +138 -3
- package/dist/index.js +80 -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}`;
|
|
@@ -778,6 +789,21 @@ async function createComponent(client, input) {
|
|
|
778
789
|
});
|
|
779
790
|
return res.data;
|
|
780
791
|
}
|
|
792
|
+
async function listExtractionCandidates(client, projectId) {
|
|
793
|
+
const qs3 = projectId ? `?projectId=${encodeURIComponent(projectId)}` : "";
|
|
794
|
+
const res = await client.fetchJSON(
|
|
795
|
+
client.url(`/management/components/extraction-candidates${qs3}`),
|
|
796
|
+
{ method: "GET" }
|
|
797
|
+
);
|
|
798
|
+
return res.data;
|
|
799
|
+
}
|
|
800
|
+
async function extractComponent(client, input) {
|
|
801
|
+
const res = await client.fetchJSON(
|
|
802
|
+
client.url("/management/components/extract"),
|
|
803
|
+
{ method: "POST", body: JSON.stringify(input) }
|
|
804
|
+
);
|
|
805
|
+
return { component: res.data, replaced: res.replaced };
|
|
806
|
+
}
|
|
781
807
|
async function updateComponent(client, id, input) {
|
|
782
808
|
const res = await client.fetchJSON(
|
|
783
809
|
client.url(`/management/components/${id}`),
|
|
@@ -802,6 +828,27 @@ async function generateSeoMeta(client, input) {
|
|
|
802
828
|
return res.data;
|
|
803
829
|
}
|
|
804
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
|
+
|
|
805
852
|
// src/management-client.ts
|
|
806
853
|
var DEFAULT_BASE_URL2 = "https://api.bettercms.ai/v1";
|
|
807
854
|
var DEFAULT_TIMEOUT2 = 1e4;
|
|
@@ -966,6 +1013,21 @@ var BetterCMSManagementClient = class extends BetterCMSDeliveryClient {
|
|
|
966
1013
|
updateComponent(id, input) {
|
|
967
1014
|
return updateComponent(this, id, input);
|
|
968
1015
|
}
|
|
1016
|
+
/** Sections repeating across the project's pages, proposed as components. */
|
|
1017
|
+
listExtractionCandidates(projectId) {
|
|
1018
|
+
return listExtractionCandidates(this, projectId);
|
|
1019
|
+
}
|
|
1020
|
+
/** Fold one candidate into a component and repoint every occurrence at it. */
|
|
1021
|
+
extractComponent(input) {
|
|
1022
|
+
return extractComponent(this, input);
|
|
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
|
+
}
|
|
969
1031
|
// ── AI (Option B): write/rewrite/translate copy + generate SEO meta (BYOK-metered) ──
|
|
970
1032
|
/** Write, rewrite, or translate a piece of copy. Returns the suggested text. */
|
|
971
1033
|
writeContent(input) {
|
|
@@ -1171,16 +1233,17 @@ function createClient(options) {
|
|
|
1171
1233
|
return {
|
|
1172
1234
|
perspective,
|
|
1173
1235
|
async getEntry(slug, opts) {
|
|
1174
|
-
const query = qs({
|
|
1175
|
-
depth: opts?.depth,
|
|
1176
|
-
select: opts?.select?.join(",")
|
|
1177
|
-
});
|
|
1178
1236
|
const url = draft && previewToken ? `${apiUrl}/api/v1/preview/${encodeURIComponent(slug)}${qs({
|
|
1179
1237
|
token: previewToken,
|
|
1180
1238
|
depth: opts?.depth,
|
|
1181
1239
|
select: opts?.select?.join(","),
|
|
1182
1240
|
stega: options.stega ? "1" : void 0
|
|
1183
|
-
})}` : `${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
|
+
})}`;
|
|
1184
1247
|
return unwrap(await fetchJSON(url));
|
|
1185
1248
|
},
|
|
1186
1249
|
async listEntries(opts) {
|
|
@@ -1189,7 +1252,9 @@ function createClient(options) {
|
|
|
1189
1252
|
page: opts?.page,
|
|
1190
1253
|
perPage: opts?.perPage,
|
|
1191
1254
|
depth: opts?.depth,
|
|
1192
|
-
select: opts?.select?.join(",")
|
|
1255
|
+
select: opts?.select?.join(","),
|
|
1256
|
+
perspective: draft ? "draft" : void 0,
|
|
1257
|
+
stega: draft && options.stega ? "1" : void 0
|
|
1193
1258
|
})}`;
|
|
1194
1259
|
return unwrap(await fetchJSON(url));
|
|
1195
1260
|
},
|
|
@@ -1210,6 +1275,15 @@ function createClient(options) {
|
|
|
1210
1275
|
})}`;
|
|
1211
1276
|
return unwrap(await fetchJSON(url));
|
|
1212
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
|
+
},
|
|
1213
1287
|
async listForms(opts) {
|
|
1214
1288
|
const url = `${base}/forms${qs({
|
|
1215
1289
|
projectId: opts?.projectId ?? defaultProjectId
|
|
@@ -1648,6 +1722,7 @@ var import_types = require("@bettercms-ai/types");
|
|
|
1648
1722
|
addModelFields,
|
|
1649
1723
|
addPageFields,
|
|
1650
1724
|
asStringArray,
|
|
1725
|
+
commandManagedLayout,
|
|
1651
1726
|
createApiKey,
|
|
1652
1727
|
createClient,
|
|
1653
1728
|
createEntry,
|
|
@@ -1668,6 +1743,7 @@ var import_types = require("@bettercms-ai/types");
|
|
|
1668
1743
|
getBlockType,
|
|
1669
1744
|
getEntry,
|
|
1670
1745
|
getForm,
|
|
1746
|
+
getManagedLayout,
|
|
1671
1747
|
getManagedPage,
|
|
1672
1748
|
getMedia,
|
|
1673
1749
|
getMember,
|