@bettercms-ai/sdk 1.9.0 → 1.11.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 +47 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +93 -6
- package/dist/index.d.ts +93 -6
- package/dist/index.js +44 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -40,6 +40,7 @@ __export(index_exports, {
|
|
|
40
40
|
ErrorCodes: () => ErrorCodes,
|
|
41
41
|
addModelFields: () => addModelFields,
|
|
42
42
|
addPageFields: () => addPageFields,
|
|
43
|
+
asStringArray: () => asStringArray,
|
|
43
44
|
createApiKey: () => createApiKey,
|
|
44
45
|
createClient: () => createClient,
|
|
45
46
|
createEntry: () => createEntry,
|
|
@@ -71,6 +72,7 @@ __export(index_exports, {
|
|
|
71
72
|
imageUrlBuilder: () => import_image_url.default,
|
|
72
73
|
inviteMember: () => inviteMember,
|
|
73
74
|
isBlock: () => import_types.isBlock,
|
|
75
|
+
isMultiValueField: () => isMultiValueField,
|
|
74
76
|
isRichText: () => isRichText,
|
|
75
77
|
listApiKeys: () => listApiKeys,
|
|
76
78
|
listEntries: () => listEntries,
|
|
@@ -98,6 +100,7 @@ __export(index_exports, {
|
|
|
98
100
|
signUp: () => signUp,
|
|
99
101
|
stripStega: () => stripStega,
|
|
100
102
|
submitForm: () => submitForm,
|
|
103
|
+
toggleOption: () => toggleOption,
|
|
101
104
|
updateApiKey: () => updateApiKey,
|
|
102
105
|
updateEntry: () => updateEntry,
|
|
103
106
|
updateForm: () => updateForm2,
|
|
@@ -775,6 +778,21 @@ async function createComponent(client, input) {
|
|
|
775
778
|
});
|
|
776
779
|
return res.data;
|
|
777
780
|
}
|
|
781
|
+
async function listExtractionCandidates(client, projectId) {
|
|
782
|
+
const qs3 = projectId ? `?projectId=${encodeURIComponent(projectId)}` : "";
|
|
783
|
+
const res = await client.fetchJSON(
|
|
784
|
+
client.url(`/management/components/extraction-candidates${qs3}`),
|
|
785
|
+
{ method: "GET" }
|
|
786
|
+
);
|
|
787
|
+
return res.data;
|
|
788
|
+
}
|
|
789
|
+
async function extractComponent(client, input) {
|
|
790
|
+
const res = await client.fetchJSON(
|
|
791
|
+
client.url("/management/components/extract"),
|
|
792
|
+
{ method: "POST", body: JSON.stringify(input) }
|
|
793
|
+
);
|
|
794
|
+
return { component: res.data, replaced: res.replaced };
|
|
795
|
+
}
|
|
778
796
|
async function updateComponent(client, id, input) {
|
|
779
797
|
const res = await client.fetchJSON(
|
|
780
798
|
client.url(`/management/components/${id}`),
|
|
@@ -963,6 +981,14 @@ var BetterCMSManagementClient = class extends BetterCMSDeliveryClient {
|
|
|
963
981
|
updateComponent(id, input) {
|
|
964
982
|
return updateComponent(this, id, input);
|
|
965
983
|
}
|
|
984
|
+
/** Sections repeating across the project's pages, proposed as components. */
|
|
985
|
+
listExtractionCandidates(projectId) {
|
|
986
|
+
return listExtractionCandidates(this, projectId);
|
|
987
|
+
}
|
|
988
|
+
/** Fold one candidate into a component and repoint every occurrence at it. */
|
|
989
|
+
extractComponent(input) {
|
|
990
|
+
return extractComponent(this, input);
|
|
991
|
+
}
|
|
966
992
|
// ── AI (Option B): write/rewrite/translate copy + generate SEO meta (BYOK-metered) ──
|
|
967
993
|
/** Write, rewrite, or translate a piece of copy. Returns the suggested text. */
|
|
968
994
|
writeContent(input) {
|
|
@@ -1568,16 +1594,33 @@ async function removeMember(client, workspaceId, memberId) {
|
|
|
1568
1594
|
}
|
|
1569
1595
|
|
|
1570
1596
|
// src/forms.ts
|
|
1597
|
+
function isMultiValueField(type) {
|
|
1598
|
+
return type === "checkboxes";
|
|
1599
|
+
}
|
|
1600
|
+
function asStringArray(value) {
|
|
1601
|
+
if (Array.isArray(value)) return value;
|
|
1602
|
+
return value ? [String(value)] : [];
|
|
1603
|
+
}
|
|
1604
|
+
function toggleOption(value, option, on) {
|
|
1605
|
+
const current = asStringArray(value);
|
|
1606
|
+
if (on) return current.includes(option) ? current : [...current, option];
|
|
1607
|
+
return current.filter((v) => v !== option);
|
|
1608
|
+
}
|
|
1571
1609
|
var DEFAULT_BASE_URL5 = "https://api.bettercms.ai";
|
|
1572
1610
|
function shouldShowField(field, values) {
|
|
1573
1611
|
if (!field.showIf) return true;
|
|
1574
|
-
|
|
1612
|
+
const trigger = values[field.showIf.field];
|
|
1613
|
+
if (Array.isArray(trigger)) return trigger.includes(field.showIf.equals);
|
|
1614
|
+
return String(trigger ?? "") === field.showIf.equals;
|
|
1575
1615
|
}
|
|
1576
1616
|
function formInitialValues(form, prefill = {}) {
|
|
1577
1617
|
const values = {};
|
|
1578
1618
|
for (const field of form.fields) {
|
|
1579
1619
|
if (field.type === "checkbox" || field.type === "consent") {
|
|
1580
1620
|
values[field.key] = false;
|
|
1621
|
+
} else if (field.type === "checkboxes") {
|
|
1622
|
+
const seed = prefill[field.key] ?? field.defaultValue ?? "";
|
|
1623
|
+
values[field.key] = seed ? seed.split(",").map((v) => v.trim()).filter(Boolean) : [];
|
|
1581
1624
|
} else {
|
|
1582
1625
|
values[field.key] = prefill[field.key] ?? field.defaultValue ?? "";
|
|
1583
1626
|
}
|
|
@@ -1627,6 +1670,7 @@ var import_types = require("@bettercms-ai/types");
|
|
|
1627
1670
|
ErrorCodes,
|
|
1628
1671
|
addModelFields,
|
|
1629
1672
|
addPageFields,
|
|
1673
|
+
asStringArray,
|
|
1630
1674
|
createApiKey,
|
|
1631
1675
|
createClient,
|
|
1632
1676
|
createEntry,
|
|
@@ -1658,6 +1702,7 @@ var import_types = require("@bettercms-ai/types");
|
|
|
1658
1702
|
imageUrlBuilder,
|
|
1659
1703
|
inviteMember,
|
|
1660
1704
|
isBlock,
|
|
1705
|
+
isMultiValueField,
|
|
1661
1706
|
isRichText,
|
|
1662
1707
|
listApiKeys,
|
|
1663
1708
|
listEntries,
|
|
@@ -1685,6 +1730,7 @@ var import_types = require("@bettercms-ai/types");
|
|
|
1685
1730
|
signUp,
|
|
1686
1731
|
stripStega,
|
|
1687
1732
|
submitForm,
|
|
1733
|
+
toggleOption,
|
|
1688
1734
|
updateApiKey,
|
|
1689
1735
|
updateEntry,
|
|
1690
1736
|
updateForm,
|