@bettercms-ai/sdk 1.8.1 → 1.10.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 +54 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +76 -6
- package/dist/index.d.ts +76 -6
- package/dist/index.js +48 -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,8 @@ __export(index_exports, {
|
|
|
71
72
|
imageUrlBuilder: () => import_image_url.default,
|
|
72
73
|
inviteMember: () => inviteMember,
|
|
73
74
|
isBlock: () => import_types.isBlock,
|
|
75
|
+
isMultiValueField: () => isMultiValueField,
|
|
76
|
+
isRichText: () => isRichText,
|
|
74
77
|
listApiKeys: () => listApiKeys,
|
|
75
78
|
listEntries: () => listEntries,
|
|
76
79
|
listForms: () => listForms2,
|
|
@@ -81,11 +84,13 @@ __export(index_exports, {
|
|
|
81
84
|
listPages: () => listPages,
|
|
82
85
|
listSubmissions: () => listSubmissions,
|
|
83
86
|
listWorkspaces: () => listWorkspaces,
|
|
87
|
+
plain: () => plain,
|
|
84
88
|
publishPage: () => publishPage,
|
|
85
89
|
regenerateApiKey: () => regenerateApiKey,
|
|
86
90
|
removeMember: () => removeMember,
|
|
87
91
|
resolveSeo: () => resolveSeo,
|
|
88
92
|
revokeApiKey: () => revokeApiKey,
|
|
93
|
+
rich: () => rich,
|
|
89
94
|
search: () => search,
|
|
90
95
|
setPageContent: () => setPageContent,
|
|
91
96
|
shouldShowField: () => shouldShowField,
|
|
@@ -95,6 +100,7 @@ __export(index_exports, {
|
|
|
95
100
|
signUp: () => signUp,
|
|
96
101
|
stripStega: () => stripStega,
|
|
97
102
|
submitForm: () => submitForm,
|
|
103
|
+
toggleOption: () => toggleOption,
|
|
98
104
|
updateApiKey: () => updateApiKey,
|
|
99
105
|
updateEntry: () => updateEntry,
|
|
100
106
|
updateForm: () => updateForm2,
|
|
@@ -1258,6 +1264,30 @@ function stripStega(value) {
|
|
|
1258
1264
|
return value.replace(FRAME, "");
|
|
1259
1265
|
}
|
|
1260
1266
|
|
|
1267
|
+
// src/richtext.ts
|
|
1268
|
+
function isRichText(value) {
|
|
1269
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && ("html" in value || "format" in value);
|
|
1270
|
+
}
|
|
1271
|
+
function plain(value) {
|
|
1272
|
+
if (typeof value === "string") return value;
|
|
1273
|
+
if (!isRichText(value) || typeof value.html !== "string") return "";
|
|
1274
|
+
return decodeEntities(value.html.replace(/<[^>]+>/g, "")).trim();
|
|
1275
|
+
}
|
|
1276
|
+
function rich(value, fallback = "") {
|
|
1277
|
+
const html = (typeof value === "string" ? escapeHtml(value) : isRichText(value) ? value.html ?? "" : "").trim();
|
|
1278
|
+
return html ? unwrapLoneBlock(html) : escapeHtml(fallback);
|
|
1279
|
+
}
|
|
1280
|
+
function unwrapLoneBlock(html) {
|
|
1281
|
+
const m = html.match(/^<(p|div|h[1-6])(?:\s[^>]*)?>([\s\S]*)<\/\1>$/i);
|
|
1282
|
+
return m && !new RegExp(`</${m[1]}>`, "i").test(m[2]) ? m[2] : html;
|
|
1283
|
+
}
|
|
1284
|
+
function escapeHtml(s) {
|
|
1285
|
+
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
1286
|
+
}
|
|
1287
|
+
function decodeEntities(s) {
|
|
1288
|
+
return s.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/�?39;/g, "'").replace(/ /g, " ").replace(/&/g, "&");
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1261
1291
|
// src/seo.ts
|
|
1262
1292
|
function jsonLdNodes(schema) {
|
|
1263
1293
|
if (!schema) return [];
|
|
@@ -1541,16 +1571,33 @@ async function removeMember(client, workspaceId, memberId) {
|
|
|
1541
1571
|
}
|
|
1542
1572
|
|
|
1543
1573
|
// src/forms.ts
|
|
1574
|
+
function isMultiValueField(type) {
|
|
1575
|
+
return type === "checkboxes";
|
|
1576
|
+
}
|
|
1577
|
+
function asStringArray(value) {
|
|
1578
|
+
if (Array.isArray(value)) return value;
|
|
1579
|
+
return value ? [String(value)] : [];
|
|
1580
|
+
}
|
|
1581
|
+
function toggleOption(value, option, on) {
|
|
1582
|
+
const current = asStringArray(value);
|
|
1583
|
+
if (on) return current.includes(option) ? current : [...current, option];
|
|
1584
|
+
return current.filter((v) => v !== option);
|
|
1585
|
+
}
|
|
1544
1586
|
var DEFAULT_BASE_URL5 = "https://api.bettercms.ai";
|
|
1545
1587
|
function shouldShowField(field, values) {
|
|
1546
1588
|
if (!field.showIf) return true;
|
|
1547
|
-
|
|
1589
|
+
const trigger = values[field.showIf.field];
|
|
1590
|
+
if (Array.isArray(trigger)) return trigger.includes(field.showIf.equals);
|
|
1591
|
+
return String(trigger ?? "") === field.showIf.equals;
|
|
1548
1592
|
}
|
|
1549
1593
|
function formInitialValues(form, prefill = {}) {
|
|
1550
1594
|
const values = {};
|
|
1551
1595
|
for (const field of form.fields) {
|
|
1552
1596
|
if (field.type === "checkbox" || field.type === "consent") {
|
|
1553
1597
|
values[field.key] = false;
|
|
1598
|
+
} else if (field.type === "checkboxes") {
|
|
1599
|
+
const seed = prefill[field.key] ?? field.defaultValue ?? "";
|
|
1600
|
+
values[field.key] = seed ? seed.split(",").map((v) => v.trim()).filter(Boolean) : [];
|
|
1554
1601
|
} else {
|
|
1555
1602
|
values[field.key] = prefill[field.key] ?? field.defaultValue ?? "";
|
|
1556
1603
|
}
|
|
@@ -1600,6 +1647,7 @@ var import_types = require("@bettercms-ai/types");
|
|
|
1600
1647
|
ErrorCodes,
|
|
1601
1648
|
addModelFields,
|
|
1602
1649
|
addPageFields,
|
|
1650
|
+
asStringArray,
|
|
1603
1651
|
createApiKey,
|
|
1604
1652
|
createClient,
|
|
1605
1653
|
createEntry,
|
|
@@ -1631,6 +1679,8 @@ var import_types = require("@bettercms-ai/types");
|
|
|
1631
1679
|
imageUrlBuilder,
|
|
1632
1680
|
inviteMember,
|
|
1633
1681
|
isBlock,
|
|
1682
|
+
isMultiValueField,
|
|
1683
|
+
isRichText,
|
|
1634
1684
|
listApiKeys,
|
|
1635
1685
|
listEntries,
|
|
1636
1686
|
listForms,
|
|
@@ -1641,11 +1691,13 @@ var import_types = require("@bettercms-ai/types");
|
|
|
1641
1691
|
listPages,
|
|
1642
1692
|
listSubmissions,
|
|
1643
1693
|
listWorkspaces,
|
|
1694
|
+
plain,
|
|
1644
1695
|
publishPage,
|
|
1645
1696
|
regenerateApiKey,
|
|
1646
1697
|
removeMember,
|
|
1647
1698
|
resolveSeo,
|
|
1648
1699
|
revokeApiKey,
|
|
1700
|
+
rich,
|
|
1649
1701
|
search,
|
|
1650
1702
|
setPageContent,
|
|
1651
1703
|
shouldShowField,
|
|
@@ -1655,6 +1707,7 @@ var import_types = require("@bettercms-ai/types");
|
|
|
1655
1707
|
signUp,
|
|
1656
1708
|
stripStega,
|
|
1657
1709
|
submitForm,
|
|
1710
|
+
toggleOption,
|
|
1658
1711
|
updateApiKey,
|
|
1659
1712
|
updateEntry,
|
|
1660
1713
|
updateForm,
|