@bettercms-ai/sdk 1.25.0 → 1.26.1

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
@@ -94,8 +94,12 @@ __export(index_exports, {
94
94
  portableText: () => portableText,
95
95
  publishManagedLayout: () => publishManagedLayout,
96
96
  publishPage: () => publishPage,
97
+ publishedContentFile: () => publishedContentFile,
98
+ publishedEntry: () => publishedEntry,
99
+ readPublishedContent: () => readPublishedContent,
97
100
  regenerateApiKey: () => regenerateApiKey,
98
101
  removeMember: () => removeMember,
102
+ resetPublishedContentCache: () => resetPublishedContentCache,
99
103
  resolveSeo: () => resolveSeo,
100
104
  revokeApiKey: () => revokeApiKey,
101
105
  rich: () => rich,
@@ -1393,7 +1397,8 @@ function createClient(options) {
1393
1397
  depth: opts?.depth,
1394
1398
  select: opts?.select?.join(","),
1395
1399
  perspective: draft ? "draft" : void 0,
1396
- stega: draft && stega ? "1" : void 0
1400
+ stega: draft && stega ? "1" : void 0,
1401
+ projectId: defaultProjectId
1397
1402
  })}`;
1398
1403
  return unwrap(await fetchJSON(url));
1399
1404
  },
@@ -1405,7 +1410,8 @@ function createClient(options) {
1405
1410
  depth: opts?.depth,
1406
1411
  select: opts?.select?.join(","),
1407
1412
  perspective: draft ? "draft" : void 0,
1408
- stega: draft && stega ? "1" : void 0
1413
+ stega: draft && stega ? "1" : void 0,
1414
+ projectId: defaultProjectId
1409
1415
  })}`;
1410
1416
  return unwrap(await fetchJSON(url));
1411
1417
  },
@@ -1439,19 +1445,21 @@ function createClient(options) {
1439
1445
  async listPages(opts) {
1440
1446
  const url = `${base}/pages${qs({
1441
1447
  page: opts?.page,
1442
- perPage: opts?.perPage
1448
+ perPage: opts?.perPage,
1449
+ projectId: defaultProjectId
1443
1450
  })}`;
1444
1451
  return unwrap(await fetchJSON(url));
1445
1452
  },
1446
1453
  async listComponents() {
1447
1454
  const url = `${base}/components${qs({
1448
1455
  perspective: draft ? "draft" : void 0,
1449
- token: draft ? previewToken : void 0
1456
+ token: draft ? previewToken : void 0,
1457
+ projectId: defaultProjectId
1450
1458
  })}`;
1451
1459
  return unwrap(await fetchJSON(url));
1452
1460
  },
1453
1461
  async getLayout() {
1454
- const url = `${base}/layout${draft ? "?perspective=draft" : ""}`;
1462
+ const url = `${base}/layout${qs({ perspective: draft ? "draft" : void 0, projectId: defaultProjectId })}`;
1455
1463
  try {
1456
1464
  return unwrap(await fetchJSON(url));
1457
1465
  } catch (error) {
@@ -1685,6 +1693,45 @@ async function search(opts) {
1685
1693
  }
1686
1694
  }
1687
1695
 
1696
+ // src/published-content.ts
1697
+ var cache = null;
1698
+ var checkedAt = 0;
1699
+ function publishedContentFile() {
1700
+ const proc = globalThis.process;
1701
+ if (typeof proc?.getBuiltinModule !== "function") return null;
1702
+ return proc.env?.BCMS_CONTENT_FILE || `${proc.cwd?.() ?? "."}/bcms-content.json`;
1703
+ }
1704
+ function readPublishedContent() {
1705
+ const file = publishedContentFile();
1706
+ if (!file) return null;
1707
+ const now = Date.now();
1708
+ if (cache && cache.file === file && now - checkedAt < 1e3) return cache.content;
1709
+ checkedAt = now;
1710
+ const proc = globalThis.process;
1711
+ const fs = proc.getBuiltinModule("node:fs");
1712
+ try {
1713
+ const stamp = fs.statSync(file).mtimeMs;
1714
+ if (cache && cache.file === file && cache.stamp === stamp) return cache.content;
1715
+ cache = { file, stamp, content: JSON.parse(fs.readFileSync(file, "utf8")) };
1716
+ } catch {
1717
+ if (!cache || cache.file !== file) cache = { file, stamp: -1, content: null };
1718
+ }
1719
+ return cache.content;
1720
+ }
1721
+ function publishedEntry(slug) {
1722
+ const collections = readPublishedContent()?.collections ?? {};
1723
+ for (const rows of Object.values(collections)) {
1724
+ if (!Array.isArray(rows)) continue;
1725
+ const hit = rows.find((row) => row?.slug === slug);
1726
+ if (hit) return hit;
1727
+ }
1728
+ return null;
1729
+ }
1730
+ function resetPublishedContentCache() {
1731
+ cache = null;
1732
+ checkedAt = 0;
1733
+ }
1734
+
1688
1735
  // src/index.ts
1689
1736
  var import_image_url = __toESM(require("@bettercms-ai/image-url"), 1);
1690
1737
 
@@ -2042,8 +2089,12 @@ var import_types = require("@bettercms-ai/types");
2042
2089
  portableText,
2043
2090
  publishManagedLayout,
2044
2091
  publishPage,
2092
+ publishedContentFile,
2093
+ publishedEntry,
2094
+ readPublishedContent,
2045
2095
  regenerateApiKey,
2046
2096
  removeMember,
2097
+ resetPublishedContentCache,
2047
2098
  resolveSeo,
2048
2099
  revokeApiKey,
2049
2100
  rich,