@bettercms-ai/sdk 1.19.0 → 1.21.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 CHANGED
@@ -58,6 +58,7 @@ __export(index_exports, {
58
58
  deleteSubmission: () => deleteSubmission,
59
59
  deleteWorkspace: () => deleteWorkspace,
60
60
  encodeStega: () => encodeStega,
61
+ entrySeoInput: () => entrySeoInput,
61
62
  formInitialValues: () => formInitialValues,
62
63
  getApiKeyUsage: () => getApiKeyUsage,
63
64
  getBlockType: () => import_types.getBlockType,
@@ -638,12 +639,13 @@ async function updateModel(client, id, input) {
638
639
  );
639
640
  return res.data;
640
641
  }
642
+ var withWarnings = (res) => res.warnings?.length ? { ...res.data, warnings: res.warnings } : res.data;
641
643
  async function createEntry(client, input) {
642
644
  const res = await client.fetchJSON(
643
645
  client.url("/management/content/entries"),
644
646
  { method: "POST", body: JSON.stringify(input) }
645
647
  );
646
- return res.data;
648
+ return withWarnings(res);
647
649
  }
648
650
  async function updateEntry(client, id, input, opts) {
649
651
  const headers = {};
@@ -652,7 +654,7 @@ async function updateEntry(client, id, input, opts) {
652
654
  client.url(`/management/content/entries/${id}`),
653
655
  { method: "PATCH", body: JSON.stringify(input), headers }
654
656
  );
655
- return res.data;
657
+ return withWarnings(res);
656
658
  }
657
659
  async function deleteManagedPage(client, id) {
658
660
  const res = await client.fetchJSON(
@@ -677,6 +679,13 @@ async function deleteModel(client, id) {
677
679
  }
678
680
 
679
681
  // src/methods/management/media.ts
682
+ async function updateAsset(client, id, input) {
683
+ const { data } = await client.fetchJSON(
684
+ client.url(`/management/media/${encodeURIComponent(id)}`),
685
+ { method: "PATCH", body: JSON.stringify(input) }
686
+ );
687
+ return data;
688
+ }
680
689
  var MIME_BY_EXT = {
681
690
  png: "image/png",
682
691
  jpg: "image/jpeg",
@@ -804,6 +813,10 @@ async function uploadAsset(client, input) {
804
813
  body: bytes
805
814
  }
806
815
  );
816
+ if (input.transcript && input.transcript.trim()) {
817
+ await updateAsset(client, data.id, { transcript: input.transcript });
818
+ return { ...data, transcript: input.transcript };
819
+ }
807
820
  return data;
808
821
  }
809
822
 
@@ -1065,6 +1078,10 @@ var BetterCMSManagementClient = class extends BetterCMSDeliveryClient {
1065
1078
  uploadAsset(input) {
1066
1079
  return uploadAsset(this, input);
1067
1080
  }
1081
+ /** Set an asset's alt text, caption or transcript (video/audio only). `null` clears. */
1082
+ updateAsset(id, input) {
1083
+ return updateAsset(this, id, input);
1084
+ }
1068
1085
  // ── Forms (read-only): discover dashboard-built forms to embed into site code ──
1069
1086
  /** List forms in the key's project (or workspace-level). */
1070
1087
  listForms() {
@@ -1533,6 +1550,68 @@ function jsonLdNodes(schema) {
1533
1550
  }
1534
1551
  return out;
1535
1552
  }
1553
+ var SCHEMA_TYPE_CHOICES = [
1554
+ "WebPage",
1555
+ "AboutPage",
1556
+ "ContactPage",
1557
+ "CollectionPage",
1558
+ "Blog",
1559
+ "BlogPosting",
1560
+ "Article",
1561
+ "Product",
1562
+ "FAQPage",
1563
+ "Event",
1564
+ "Organization",
1565
+ "LocalBusiness"
1566
+ ];
1567
+ function compact(node) {
1568
+ return Object.fromEntries(Object.entries(node).filter(([, value]) => value != null && value !== ""));
1569
+ }
1570
+ function schemaNode(type, { name, description, image, url }) {
1571
+ switch (type) {
1572
+ case "BlogPosting":
1573
+ case "Article":
1574
+ return compact({ "@type": type, headline: name, description, image, url, mainEntityOfPage: url });
1575
+ case "Product":
1576
+ case "Event":
1577
+ return compact({ "@type": type, name, description, image, url });
1578
+ case "FAQPage":
1579
+ case "WebSite":
1580
+ return compact({ "@type": type, name, description, url });
1581
+ case "Organization":
1582
+ return compact({ "@type": type, name, description, url, logo: image });
1583
+ default:
1584
+ return compact({ "@type": type, name, description, url, image });
1585
+ }
1586
+ }
1587
+ function pageJsonLd(page, meta, canonical, siteSchema) {
1588
+ const custom = jsonLdNodes(meta.schema);
1589
+ if (custom.length > 0) return custom;
1590
+ const props = {
1591
+ name: (page.metaTitle || page.title || "").trim(),
1592
+ description: (page.metaDescription || "").trim(),
1593
+ image: (meta.og?.image || "").trim(),
1594
+ url: canonical.trim()
1595
+ };
1596
+ const schemaType = meta.schemaType;
1597
+ if (typeof schemaType === "string" && SCHEMA_TYPE_CHOICES.includes(schemaType)) {
1598
+ return [schemaNode(schemaType, props)];
1599
+ }
1600
+ if (page.slug === "home") {
1601
+ return jsonLdNodes(siteSchema).length > 0 ? [] : [schemaNode("WebSite", props)];
1602
+ }
1603
+ return [schemaNode("WebPage", props)];
1604
+ }
1605
+ function entrySeoInput(entry) {
1606
+ const { metaTitle, metaDescription, noindex, ...metaJson } = entry.seo ?? {};
1607
+ return {
1608
+ title: metaTitle || entry.slug,
1609
+ metaTitle: metaTitle ?? null,
1610
+ metaDescription: metaDescription ?? null,
1611
+ metaJson,
1612
+ noindex: noindex === true
1613
+ };
1614
+ }
1536
1615
  function resolveSeo(page, defaults = {}, location = {}) {
1537
1616
  const meta = page.metaJson ?? {};
1538
1617
  const title = page.metaTitle || page.title || "";
@@ -1560,7 +1639,9 @@ function resolveSeo(page, defaults = {}, location = {}) {
1560
1639
  image: twImage,
1561
1640
  site: defaults.twitterHandle || ""
1562
1641
  },
1563
- jsonLd: [...jsonLdNodes(defaults.siteSchema), ...jsonLdNodes(meta.schema)]
1642
+ jsonLd: [...jsonLdNodes(defaults.siteSchema), ...pageJsonLd(page, meta, canonical, defaults.siteSchema)],
1643
+ noindex: page.noindex === true,
1644
+ robots: { index: page.noindex !== true, follow: true }
1564
1645
  };
1565
1646
  }
1566
1647
 
@@ -1904,6 +1985,7 @@ var import_types = require("@bettercms-ai/types");
1904
1985
  deleteSubmission,
1905
1986
  deleteWorkspace,
1906
1987
  encodeStega,
1988
+ entrySeoInput,
1907
1989
  formInitialValues,
1908
1990
  getApiKeyUsage,
1909
1991
  getBlockType,