@bettercms-ai/sdk 1.17.0 → 1.18.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
@@ -1249,6 +1249,16 @@ function unwrap(json) {
1249
1249
  }
1250
1250
  return json;
1251
1251
  }
1252
+ function tokenSlug(token) {
1253
+ try {
1254
+ const part = token.split(".")[1];
1255
+ if (!part) return null;
1256
+ const json = atob(part.replace(/-/g, "+").replace(/_/g, "/"));
1257
+ return JSON.parse(json).entrySlug ?? null;
1258
+ } catch {
1259
+ return null;
1260
+ }
1261
+ }
1252
1262
  function createRequestCache() {
1253
1263
  const inflight = /* @__PURE__ */ new Map();
1254
1264
  const settled = /* @__PURE__ */ new Map();
@@ -1349,6 +1359,23 @@ function createClient(options) {
1349
1359
  return unwrap(await fetchJSON(url));
1350
1360
  },
1351
1361
  async getPage(slug) {
1362
+ if (draft && previewToken && tokenSlug(previewToken) === slug) {
1363
+ const url = `${apiUrl}/api/v1/preview/${encodeURIComponent(slug)}${qs({
1364
+ token: previewToken,
1365
+ stega: stega ? "1" : void 0
1366
+ })}`;
1367
+ const d = unwrap(await fetchJSON(url));
1368
+ return {
1369
+ slug: d.slug,
1370
+ title: d.title,
1371
+ metaTitle: d.metaTitle ?? null,
1372
+ metaDescription: d.metaDescription ?? null,
1373
+ metaJson: d.metaJson ?? null,
1374
+ blocks: d.blockJson ?? [],
1375
+ updatedAt: d.updatedAt ?? null,
1376
+ publishedAt: d.publishedAt ?? null
1377
+ };
1378
+ }
1352
1379
  let page = 1;
1353
1380
  for (; ; ) {
1354
1381
  const list = await this.listPages({ page, perPage: 100 });
@@ -1365,6 +1392,13 @@ function createClient(options) {
1365
1392
  })}`;
1366
1393
  return unwrap(await fetchJSON(url));
1367
1394
  },
1395
+ async listComponents() {
1396
+ const url = `${base}/components${qs({
1397
+ perspective: draft ? "draft" : void 0,
1398
+ token: draft ? previewToken : void 0
1399
+ })}`;
1400
+ return unwrap(await fetchJSON(url));
1401
+ },
1368
1402
  async getLayout() {
1369
1403
  const url = `${base}/layout${draft ? "?perspective=draft" : ""}`;
1370
1404
  try {