@bettercms-ai/sdk 1.45.0 → 1.47.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.
@@ -1,4 +1,4 @@
1
- import './read-client-E9OHtQAW.js';
1
+ import './read-client-D5jzCGEc.js';
2
2
  import { RichTextResolved, RichTextEmbeds } from '@bettercms-ai/types';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import './read-client-E9OHtQAW.cjs';
1
+ import './read-client-D5jzCGEc.cjs';
2
2
  import { RichTextResolved, RichTextEmbeds } from '@bettercms-ai/types';
3
3
 
4
4
  /**
@@ -348,8 +348,15 @@ interface CreateClientOptions {
348
348
  * guessing at their text. It stays OFF on every other perspective, unconditionally, so a
349
349
  * published build cannot acquire a payload by accident — pass `stega: false` to opt a draft
350
350
  * read out (a diff or a checksum over draft content is the case that wants it).
351
+ *
352
+ * `2` asks for the field-ref frame (since 1.47.0): each value carries `<target>:<id>:<path>`
353
+ * and an open marker, so a value a library splits still resolves whole (`resolveStega`,
354
+ * `markEditable`); what is framed is decided by the model's field types (a `select`, `slug`,
355
+ * `link` or `date` never carries one); and a branch read's page blocks and the draft Layout are
356
+ * framed too. About half the bytes of `true`, still not the default: a framed draft page measured
357
+ * about twice its unframed size gzipped. Clean what you compare with `stegaClean`.
351
358
  */
352
- stega?: boolean;
359
+ stega?: boolean | 2;
353
360
  /** Per-attempt timeout in ms. Defaults to 10000. */
354
361
  timeout?: number;
355
362
  /**
@@ -368,6 +375,18 @@ interface CreateClientOptions {
368
375
  */
369
376
  cache?: boolean;
370
377
  }
378
+ /** A value a list filter compares against. */
379
+ type FilterValue = string | number | boolean;
380
+ type FilterOps = Partial<Record<"eq" | "ne" | "gt" | "gte" | "lt" | "lte" | "contains", FilterValue>> & {
381
+ in?: FilterValue[];
382
+ };
383
+ /**
384
+ * The delivery list's filter grammar as an object: `{ category: "news" }` is `filter[category]=news`,
385
+ * `{ startsAt: { gte: "2026-01-01" } }` is `filter[startsAt][gte]=…`, `{ tags: ["a", "b"] }` is
386
+ * `filter[tags][in]=a,b`. A content field needs `model`; `slug`, `status`, `publishedAt` and `locale`
387
+ * do not. The server allowlists the fields (src/lib/delivery/list-query.ts) and 400s anything else.
388
+ */
389
+ type EntryFilter = Record<string, FilterValue | FilterValue[] | FilterOps | undefined>;
371
390
  interface ListEntriesOptions {
372
391
  /** Filter by content-model slug. */
373
392
  model?: string;
@@ -377,6 +396,10 @@ interface ListEntriesOptions {
377
396
  depth?: 0 | 1;
378
397
  /** Projection — field names to return. */
379
398
  select?: string[];
399
+ /** Field filters, ANDed. */
400
+ filter?: EntryFilter;
401
+ /** `"-publishedAt"` or `["startsAt", "title"]`: a leading `-` sorts descending. Default: newest published first. */
402
+ sort?: string | string[];
380
403
  }
381
404
  interface GetEntryOptions {
382
405
  depth?: 0 | 1 | 2;
@@ -348,8 +348,15 @@ interface CreateClientOptions {
348
348
  * guessing at their text. It stays OFF on every other perspective, unconditionally, so a
349
349
  * published build cannot acquire a payload by accident — pass `stega: false` to opt a draft
350
350
  * read out (a diff or a checksum over draft content is the case that wants it).
351
+ *
352
+ * `2` asks for the field-ref frame (since 1.47.0): each value carries `<target>:<id>:<path>`
353
+ * and an open marker, so a value a library splits still resolves whole (`resolveStega`,
354
+ * `markEditable`); what is framed is decided by the model's field types (a `select`, `slug`,
355
+ * `link` or `date` never carries one); and a branch read's page blocks and the draft Layout are
356
+ * framed too. About half the bytes of `true`, still not the default: a framed draft page measured
357
+ * about twice its unframed size gzipped. Clean what you compare with `stegaClean`.
351
358
  */
352
- stega?: boolean;
359
+ stega?: boolean | 2;
353
360
  /** Per-attempt timeout in ms. Defaults to 10000. */
354
361
  timeout?: number;
355
362
  /**
@@ -368,6 +375,18 @@ interface CreateClientOptions {
368
375
  */
369
376
  cache?: boolean;
370
377
  }
378
+ /** A value a list filter compares against. */
379
+ type FilterValue = string | number | boolean;
380
+ type FilterOps = Partial<Record<"eq" | "ne" | "gt" | "gte" | "lt" | "lte" | "contains", FilterValue>> & {
381
+ in?: FilterValue[];
382
+ };
383
+ /**
384
+ * The delivery list's filter grammar as an object: `{ category: "news" }` is `filter[category]=news`,
385
+ * `{ startsAt: { gte: "2026-01-01" } }` is `filter[startsAt][gte]=…`, `{ tags: ["a", "b"] }` is
386
+ * `filter[tags][in]=a,b`. A content field needs `model`; `slug`, `status`, `publishedAt` and `locale`
387
+ * do not. The server allowlists the fields (src/lib/delivery/list-query.ts) and 400s anything else.
388
+ */
389
+ type EntryFilter = Record<string, FilterValue | FilterValue[] | FilterOps | undefined>;
371
390
  interface ListEntriesOptions {
372
391
  /** Filter by content-model slug. */
373
392
  model?: string;
@@ -377,6 +396,10 @@ interface ListEntriesOptions {
377
396
  depth?: 0 | 1;
378
397
  /** Projection — field names to return. */
379
398
  select?: string[];
399
+ /** Field filters, ANDed. */
400
+ filter?: EntryFilter;
401
+ /** `"-publishedAt"` or `["startsAt", "title"]`: a leading `-` sorts descending. Default: newest published first. */
402
+ sort?: string | string[];
380
403
  }
381
404
  interface GetEntryOptions {
382
405
  depth?: 0 | 1 | 2;
package/dist/read.cjs CHANGED
@@ -182,10 +182,24 @@ var BRANCH_SIGNATURE_HEADER = "X-BCMS-Branch-Signature";
182
182
 
183
183
  // src/read-client.ts
184
184
  var DEFAULT_TIMEOUT = 1e4;
185
+ function listQueryParams(filter, sort) {
186
+ const text = (v) => Array.isArray(v) ? v.join(",") : String(v);
187
+ const out = {};
188
+ for (const [field, cond] of Object.entries(filter ?? {})) {
189
+ if (cond == null) continue;
190
+ if (Array.isArray(cond)) out[`filter[${field}][in]`] = text(cond);
191
+ else if (typeof cond === "object") {
192
+ for (const [op, v] of Object.entries(cond)) if (v != null) out[`filter[${field}][${op}]`] = text(v);
193
+ } else out[`filter[${field}]`] = text(cond);
194
+ }
195
+ const order = Array.isArray(sort) ? sort.join(",") : sort;
196
+ if (order) out.sort = order;
197
+ return out;
198
+ }
185
199
  function qs(params) {
186
200
  const sp = new URLSearchParams();
187
201
  for (const [k, v] of Object.entries(params)) {
188
- if (v !== void 0 && v !== "") sp.set(k, String(v));
202
+ if (v !== void 0 && (v !== "" || k.startsWith("filter["))) sp.set(k, String(v));
189
203
  }
190
204
  const s = sp.toString();
191
205
  return s ? `?${s}` : "";
@@ -281,6 +295,7 @@ function createClient(options) {
281
295
  }
282
296
  const draft = perspective === "drafts";
283
297
  const stega = options.stega ?? draft;
298
+ const stegaParam = stega === 2 ? "2" : stega ? "1" : void 0;
284
299
  return {
285
300
  perspective,
286
301
  async getEntry(slug, opts) {
@@ -288,12 +303,12 @@ function createClient(options) {
288
303
  token: previewToken,
289
304
  depth: opts?.depth,
290
305
  select: opts?.select?.join(","),
291
- stega: stega ? "1" : void 0
306
+ stega: stegaParam
292
307
  })}` : `${base}/content-entries/${encodeURIComponent(slug)}${qs({
293
308
  depth: opts?.depth,
294
309
  select: opts?.select?.join(","),
295
310
  perspective: draft ? "draft" : void 0,
296
- stega: draft && stega ? "1" : void 0,
311
+ stega: draft ? stegaParam : void 0,
297
312
  projectId: defaultProjectId,
298
313
  branch
299
314
  })}`;
@@ -306,8 +321,9 @@ function createClient(options) {
306
321
  perPage: opts?.perPage,
307
322
  depth: opts?.depth,
308
323
  select: opts?.select?.join(","),
324
+ ...listQueryParams(opts?.filter, opts?.sort),
309
325
  perspective: draft ? "draft" : void 0,
310
- stega: draft && stega ? "1" : void 0,
326
+ stega: draft ? stegaParam : void 0,
311
327
  projectId: defaultProjectId,
312
328
  branch
313
329
  })}`;
@@ -317,7 +333,7 @@ function createClient(options) {
317
333
  if (draft && previewToken && tokenSlug(previewToken) === slug) {
318
334
  const url = `${apiUrl}/api/v1/preview/${encodeURIComponent(slug)}${qs({
319
335
  token: previewToken,
320
- stega: stega ? "1" : void 0
336
+ stega: stegaParam
321
337
  })}`;
322
338
  const d = unwrap(await fetchJSON(url));
323
339
  return {
@@ -347,6 +363,8 @@ function createClient(options) {
347
363
  page: opts?.page,
348
364
  perPage: opts?.perPage,
349
365
  slug: opts?.slug,
366
+ // Framed only on a branch, the draft lane of this list; never v1, which frames no blocks.
367
+ stega: draft && stega === 2 ? "2" : void 0,
350
368
  projectId: defaultProjectId,
351
369
  branch
352
370
  })}`;
@@ -362,7 +380,7 @@ function createClient(options) {
362
380
  return unwrap(await fetchJSON(url));
363
381
  },
364
382
  async getLayout() {
365
- const url = `${base}/layout${qs({ perspective: draft ? "draft" : void 0, projectId: defaultProjectId, branch })}`;
383
+ const url = `${base}/layout${qs({ perspective: draft ? "draft" : void 0, stega: draft && stega === 2 ? "2" : void 0, projectId: defaultProjectId, branch })}`;
366
384
  try {
367
385
  return unwrap(await fetchJSON(url));
368
386
  } catch (error) {