@bettercms-ai/sdk 1.26.1 → 1.26.3
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 +7 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -2
- package/dist/index.d.ts +25 -2
- package/dist/index.js +7 -6
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -633,6 +633,16 @@ declare function isMultiValueField(type: DeliveryFormFieldType): boolean;
|
|
|
633
633
|
interface DeliveryForm {
|
|
634
634
|
id: string;
|
|
635
635
|
name: string;
|
|
636
|
+
/** The project the form belongs to. */
|
|
637
|
+
projectId?: string | null;
|
|
638
|
+
/**
|
|
639
|
+
* A `draft` form refuses every submission: render it as unavailable rather than as a form that
|
|
640
|
+
* silently drops what a visitor sends. Delivered for exactly that reason, and missing from this
|
|
641
|
+
* type until the contract test held the two together.
|
|
642
|
+
*/
|
|
643
|
+
status?: "draft" | "published" | (string & {});
|
|
644
|
+
/** Set on a form the site's owner told BetterCMS to leave alone (ISO time); such a form is not wired. */
|
|
645
|
+
ignoredAt?: string | null;
|
|
636
646
|
fields: DeliveryFormField[];
|
|
637
647
|
submitLabel?: string;
|
|
638
648
|
successMessage?: string;
|
|
@@ -1487,7 +1497,7 @@ declare function search(opts: SearchOptions): Promise<SearchHit[]>;
|
|
|
1487
1497
|
* `import.meta.glob`) and the bundle holds a frozen copy no publish can reach: the platform then
|
|
1488
1498
|
* has to rebuild the whole site for every edit.
|
|
1489
1499
|
*
|
|
1490
|
-
* - On a hosted server: `BCMS_CONTENT_FILE`, re-read when it changes (
|
|
1500
|
+
* - On a hosted server: `BCMS_CONTENT_FILE`, re-read when it changes (its time is asked on every call).
|
|
1491
1501
|
* - At build time and in local dev: `<cwd>/bcms-content.json`, the snapshot the build was given.
|
|
1492
1502
|
* - Anywhere without a filesystem (a browser, an edge runtime): `null`.
|
|
1493
1503
|
*
|
|
@@ -1500,9 +1510,14 @@ interface PublishedContent {
|
|
|
1500
1510
|
apiUrl?: string | null;
|
|
1501
1511
|
workspace?: string;
|
|
1502
1512
|
projectId?: string | null;
|
|
1503
|
-
/**
|
|
1513
|
+
/**
|
|
1514
|
+
* Published entries by model slug, each row AS THE DELIVERY API SERVES IT: `id`, `slug`, `status`,
|
|
1515
|
+
* `publishedAt`, `updatedAt`, `locale`, `translationOf`, `_meta`, and the field values under
|
|
1516
|
+
* `data`. Read a value through {@link publishedEntry}, which answers either spelling.
|
|
1517
|
+
*/
|
|
1504
1518
|
collections?: Record<string, Array<Record<string, unknown> & {
|
|
1505
1519
|
slug?: string;
|
|
1520
|
+
data?: Record<string, unknown>;
|
|
1506
1521
|
}>>;
|
|
1507
1522
|
pages?: unknown[];
|
|
1508
1523
|
components?: unknown[];
|
|
@@ -1520,6 +1535,14 @@ declare function readPublishedContent<T extends PublishedContent = PublishedCont
|
|
|
1520
1535
|
/**
|
|
1521
1536
|
* One published entry by its slug, searched across every collection (first match wins, in the
|
|
1522
1537
|
* snapshot's model order). Not keyed by model slug: a page's backing model is named by the CMS.
|
|
1538
|
+
*
|
|
1539
|
+
* 🔴 THE VALUES ARE ON THE ENTRY: `publishedEntry("home")?.title`. The snapshot holds each row as
|
|
1540
|
+
* the delivery API serves it, values under `data`, and this used to hand that row back as it was
|
|
1541
|
+
* while its own doc (and the skill that names it) said "the row carries its field values" — so
|
|
1542
|
+
* `entry.title` was `undefined` and every field of a server-rendered page fell back to the copy in
|
|
1543
|
+
* the code, on every publish. Both spellings are answered: the values at the top level and the
|
|
1544
|
+
* row's own keys (`id`, `slug`, `status`, `data`, `_meta`, …) beside them, the row's winning where
|
|
1545
|
+
* a field is named like one — that field is read through `.data`, as before.
|
|
1523
1546
|
*/
|
|
1524
1547
|
declare function publishedEntry<T extends Record<string, unknown> = Record<string, unknown>>(slug: string): (T & {
|
|
1525
1548
|
slug: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -633,6 +633,16 @@ declare function isMultiValueField(type: DeliveryFormFieldType): boolean;
|
|
|
633
633
|
interface DeliveryForm {
|
|
634
634
|
id: string;
|
|
635
635
|
name: string;
|
|
636
|
+
/** The project the form belongs to. */
|
|
637
|
+
projectId?: string | null;
|
|
638
|
+
/**
|
|
639
|
+
* A `draft` form refuses every submission: render it as unavailable rather than as a form that
|
|
640
|
+
* silently drops what a visitor sends. Delivered for exactly that reason, and missing from this
|
|
641
|
+
* type until the contract test held the two together.
|
|
642
|
+
*/
|
|
643
|
+
status?: "draft" | "published" | (string & {});
|
|
644
|
+
/** Set on a form the site's owner told BetterCMS to leave alone (ISO time); such a form is not wired. */
|
|
645
|
+
ignoredAt?: string | null;
|
|
636
646
|
fields: DeliveryFormField[];
|
|
637
647
|
submitLabel?: string;
|
|
638
648
|
successMessage?: string;
|
|
@@ -1487,7 +1497,7 @@ declare function search(opts: SearchOptions): Promise<SearchHit[]>;
|
|
|
1487
1497
|
* `import.meta.glob`) and the bundle holds a frozen copy no publish can reach: the platform then
|
|
1488
1498
|
* has to rebuild the whole site for every edit.
|
|
1489
1499
|
*
|
|
1490
|
-
* - On a hosted server: `BCMS_CONTENT_FILE`, re-read when it changes (
|
|
1500
|
+
* - On a hosted server: `BCMS_CONTENT_FILE`, re-read when it changes (its time is asked on every call).
|
|
1491
1501
|
* - At build time and in local dev: `<cwd>/bcms-content.json`, the snapshot the build was given.
|
|
1492
1502
|
* - Anywhere without a filesystem (a browser, an edge runtime): `null`.
|
|
1493
1503
|
*
|
|
@@ -1500,9 +1510,14 @@ interface PublishedContent {
|
|
|
1500
1510
|
apiUrl?: string | null;
|
|
1501
1511
|
workspace?: string;
|
|
1502
1512
|
projectId?: string | null;
|
|
1503
|
-
/**
|
|
1513
|
+
/**
|
|
1514
|
+
* Published entries by model slug, each row AS THE DELIVERY API SERVES IT: `id`, `slug`, `status`,
|
|
1515
|
+
* `publishedAt`, `updatedAt`, `locale`, `translationOf`, `_meta`, and the field values under
|
|
1516
|
+
* `data`. Read a value through {@link publishedEntry}, which answers either spelling.
|
|
1517
|
+
*/
|
|
1504
1518
|
collections?: Record<string, Array<Record<string, unknown> & {
|
|
1505
1519
|
slug?: string;
|
|
1520
|
+
data?: Record<string, unknown>;
|
|
1506
1521
|
}>>;
|
|
1507
1522
|
pages?: unknown[];
|
|
1508
1523
|
components?: unknown[];
|
|
@@ -1520,6 +1535,14 @@ declare function readPublishedContent<T extends PublishedContent = PublishedCont
|
|
|
1520
1535
|
/**
|
|
1521
1536
|
* One published entry by its slug, searched across every collection (first match wins, in the
|
|
1522
1537
|
* snapshot's model order). Not keyed by model slug: a page's backing model is named by the CMS.
|
|
1538
|
+
*
|
|
1539
|
+
* 🔴 THE VALUES ARE ON THE ENTRY: `publishedEntry("home")?.title`. The snapshot holds each row as
|
|
1540
|
+
* the delivery API serves it, values under `data`, and this used to hand that row back as it was
|
|
1541
|
+
* while its own doc (and the skill that names it) said "the row carries its field values" — so
|
|
1542
|
+
* `entry.title` was `undefined` and every field of a server-rendered page fell back to the copy in
|
|
1543
|
+
* the code, on every publish. Both spellings are answered: the values at the top level and the
|
|
1544
|
+
* row's own keys (`id`, `slug`, `status`, `data`, `_meta`, …) beside them, the row's winning where
|
|
1545
|
+
* a field is named like one — that field is read through `.data`, as before.
|
|
1523
1546
|
*/
|
|
1524
1547
|
declare function publishedEntry<T extends Record<string, unknown> = Record<string, unknown>>(slug: string): (T & {
|
|
1525
1548
|
slug: string;
|
package/dist/index.js
CHANGED
|
@@ -1568,7 +1568,6 @@ async function search(opts) {
|
|
|
1568
1568
|
|
|
1569
1569
|
// src/published-content.ts
|
|
1570
1570
|
var cache = null;
|
|
1571
|
-
var checkedAt = 0;
|
|
1572
1571
|
function publishedContentFile() {
|
|
1573
1572
|
const proc = globalThis.process;
|
|
1574
1573
|
if (typeof proc?.getBuiltinModule !== "function") return null;
|
|
@@ -1577,9 +1576,6 @@ function publishedContentFile() {
|
|
|
1577
1576
|
function readPublishedContent() {
|
|
1578
1577
|
const file = publishedContentFile();
|
|
1579
1578
|
if (!file) return null;
|
|
1580
|
-
const now = Date.now();
|
|
1581
|
-
if (cache && cache.file === file && now - checkedAt < 1e3) return cache.content;
|
|
1582
|
-
checkedAt = now;
|
|
1583
1579
|
const proc = globalThis.process;
|
|
1584
1580
|
const fs = proc.getBuiltinModule("node:fs");
|
|
1585
1581
|
try {
|
|
@@ -1591,18 +1587,23 @@ function readPublishedContent() {
|
|
|
1591
1587
|
}
|
|
1592
1588
|
return cache.content;
|
|
1593
1589
|
}
|
|
1590
|
+
var flat = /* @__PURE__ */ new WeakMap();
|
|
1594
1591
|
function publishedEntry(slug) {
|
|
1595
1592
|
const collections = readPublishedContent()?.collections ?? {};
|
|
1596
1593
|
for (const rows of Object.values(collections)) {
|
|
1597
1594
|
if (!Array.isArray(rows)) continue;
|
|
1598
1595
|
const hit = rows.find((row) => row?.slug === slug);
|
|
1599
|
-
if (hit)
|
|
1596
|
+
if (!hit) continue;
|
|
1597
|
+
const data = hit.data;
|
|
1598
|
+
if (!data || typeof data !== "object" || Array.isArray(data)) return hit;
|
|
1599
|
+
let entry = flat.get(hit);
|
|
1600
|
+
if (!entry) flat.set(hit, entry = { ...data, ...hit });
|
|
1601
|
+
return entry;
|
|
1600
1602
|
}
|
|
1601
1603
|
return null;
|
|
1602
1604
|
}
|
|
1603
1605
|
function resetPublishedContentCache() {
|
|
1604
1606
|
cache = null;
|
|
1605
|
-
checkedAt = 0;
|
|
1606
1607
|
}
|
|
1607
1608
|
|
|
1608
1609
|
// src/index.ts
|