@b10cks/client 1.8.0 → 1.10.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.d.ts CHANGED
@@ -240,6 +240,21 @@ export declare class B10cksDataApi {
240
240
  getCollection<T>(endpoint: Endpoint, params?: ApiQueryParams, options?: CollectionFetchOptions): Promise<T[]>;
241
241
  getContent<T = Record<string, unknown>>(fullSlug: string, params?: Omit<IBContentQueryParams, 'token' | 'full_slug'>): Promise<IBContent<T>>;
242
242
  getContents<T = Record<string, unknown>>(params?: IBGetContentsParams, options?: CollectionFetchOptions): Promise<IBContent<T>[]>;
243
+ /**
244
+ * The ancestor trail of an entry, ordered from the tree root down to the
245
+ * entry itself. Addressed by full slug or by content id.
246
+ *
247
+ * Unpublished ancestors are omitted rather than blanked, so the position in
248
+ * the trail is not the position in the tree — read `depth` for that, and pass
249
+ * `ancestors: 'all'` when structural levels are never published by design.
250
+ */
251
+ getBreadcrumb<T = Record<string, unknown>>(slug: string, params?: IBBreadcrumbParams): Promise<IBBreadcrumbLevel<T>[]>;
252
+ /**
253
+ * Like {@link getBreadcrumb}, but keeps the response's `meta` block — the
254
+ * resolved language, its fallback, the space's i18n mode, and the root and
255
+ * current ids.
256
+ */
257
+ getBreadcrumbResponse<T = Record<string, unknown>>(slug: string, params?: IBBreadcrumbParams): Promise<IBBreadcrumbResponse<T>>;
243
258
  getBlock(blockId: string, params?: ApiQueryParams): Promise<IBBlock>;
244
259
  getBlocks(params?: IBGetBlocksParams, options?: CollectionFetchOptions): Promise<IBBlock[]>;
245
260
  search<T = Record<string, unknown>>(params: IBSearchParams): Promise<IBSearchResponse<T>>;
@@ -250,7 +265,7 @@ export declare class B10cksDataApi {
250
265
  * separate one for news. Unknown names respond with 404.
251
266
  */
252
267
  getNamedSitemap(name: string, params?: Omit<IBContentQueryParams, 'token'>, options?: CollectionFetchOptions): Promise<IBSitemapEntry[]>;
253
- getDataEntries(source: string, params?: ApiQueryParams, options?: CollectionFetchOptions): Promise<IBDataEntry[]>;
268
+ getDataEntries(source: string, params?: IBDataEntryParams, options?: CollectionFetchOptions): Promise<IBDataEntry[]>;
254
269
  getDataSources(params?: ApiQueryParams, options?: CollectionFetchOptions): Promise<IBDataSource[]>;
255
270
  getSpace(params?: ApiQueryParams): Promise<IBSpace>;
256
271
  lookupRedirect(source: string): Promise<IBRedirectLookupResult | false>;
@@ -302,6 +317,35 @@ export declare interface B10cksLinkResolved {
302
317
  */
303
318
  export declare function bindPreviewStore<T>(store: PreviewStore<T>): () => void;
304
319
 
320
+ /**
321
+ * Renders a trail as a schema.org `BreadcrumbList`, ready to be serialized into
322
+ * an `application/ld+json` script tag.
323
+ *
324
+ * `position` numbers the emitted items consecutively — unlike a level's `depth`,
325
+ * which is its position in the content tree and may skip a dropped ancestor.
326
+ */
327
+ export declare function breadcrumbJsonLd<T>(levels: IBBreadcrumbLevel<T>[], options?: BreadcrumbJsonLdOptions): BreadcrumbListJsonLd;
328
+
329
+ export declare interface BreadcrumbJsonLdOptions {
330
+ /** Absolute base URL. Without it, `item` carries the relative path. */
331
+ siteUrl?: string;
332
+ /** Drop the current entry from the list. Defaults to `false` — Google expects it. */
333
+ excludeCurrent?: boolean;
334
+ }
335
+
336
+ export declare interface BreadcrumbListItem {
337
+ '@type': 'ListItem';
338
+ position: number;
339
+ name: string;
340
+ item: string;
341
+ }
342
+
343
+ export declare interface BreadcrumbListJsonLd {
344
+ '@context': 'https://schema.org';
345
+ '@type': 'BreadcrumbList';
346
+ itemListElement: BreadcrumbListItem[];
347
+ }
348
+
305
349
  export declare type BridgeEvent = {
306
350
  type: EventType;
307
351
  payload: EventPayloadMap[EventType];
@@ -369,7 +413,7 @@ export declare type DateFilter = string | {
369
413
 
370
414
  export declare type EditableFieldMode = 'inline' | 'select';
371
415
 
372
- export declare type Endpoint = 'blocks' | `blocks/${string}` | 'contents' | `contents/${string}` | `datasources/${string}/entries` | 'datasources' | 'redirects' | 'search' | 'sitemap' | `sitemaps/${string}` | 'spaces/me';
416
+ export declare type Endpoint = 'blocks' | `blocks/${string}` | `breadcrumbs/${string}` | 'contents' | `contents/${string}` | `datasources/${string}/entries` | 'datasources' | 'redirects' | 'search' | 'sitemap' | `sitemaps/${string}` | 'spaces/me';
373
417
 
374
418
  /**
375
419
  * Inject the preview outline styles once. Selected/hovered blocks get an
@@ -422,11 +466,18 @@ export declare type FieldUpdateEvent = {
422
466
  */
423
467
  export declare function filterSitemapEntries(entries: IBSitemapEntry[], options?: SitemapFilterOptions): IBSitemapEntry[];
424
468
 
469
+ /**
470
+ * Depth-first search for the path to the node carrying `id`. The root node
471
+ * itself is not considered a match — callers handle the root explicitly.
472
+ */
473
+ export declare function findPathById(root: unknown, id: string): FieldPath | null;
474
+
425
475
  /** Read the value at `path` within `target`, or undefined if absent. */
426
476
  export declare function getAtPath(target: unknown, path: FieldPath): unknown;
427
477
 
428
478
  export declare interface GetConfigOptions extends Omit<IBContentQueryParams, 'token' | 'full_slug'> {
429
479
  slug?: string;
480
+ /** @deprecated Use `language_iso`, matching every other content param. */
430
481
  language?: string;
431
482
  bypassCache?: boolean;
432
483
  }
@@ -434,6 +485,12 @@ export declare interface GetConfigOptions extends Omit<IBContentQueryParams, 'to
434
485
  export declare interface IBBaseQueryParams extends IBPaginationParams, IBSortParams {
435
486
  vid?: string;
436
487
  version?: string;
488
+ /**
489
+ * Content revision to read at. Defaults to the client's current revision;
490
+ * pass it explicitly to pin a request (or `Date.now()` to bypass the
491
+ * delivery cache from a server route).
492
+ */
493
+ rv?: string | number;
437
494
  token: string;
438
495
  }
439
496
 
@@ -458,6 +515,98 @@ export declare interface IBBlockFilter {
458
515
  updated_at?: DateFilter;
459
516
  }
460
517
 
518
+ /**
519
+ * One level of a breadcrumb trail.
520
+ *
521
+ * A level is resolved through its own i18n family, so an untranslated ancestor
522
+ * is served from the fallback language and flagged (`is_fallback`) rather than
523
+ * dropped.
524
+ */
525
+ export declare interface IBBreadcrumbLevel<Content = IBContentBlock<string> & {
526
+ [index: string]: unknown;
527
+ }> {
528
+ id: string;
529
+ external_id: string | null;
530
+ name: string;
531
+ slug: string;
532
+ /** Stored path of this level, without a locale segment. */
533
+ full_slug: string;
534
+ /** Delivery path, with the *requested* language's locale segment applied. */
535
+ path: string;
536
+ /** Slug of the assigned block definition. */
537
+ block: string | null;
538
+ parent_id: string | null;
539
+ position: number;
540
+ /**
541
+ * Depth in the content tree, 0 for the root — not the index in the trail. A
542
+ * gap in the sequence is where an unpublished ancestor was dropped.
543
+ */
544
+ depth: number;
545
+ is_root: boolean;
546
+ /** True for the entry the trail was requested for. */
547
+ is_current: boolean;
548
+ /** The requested language. */
549
+ language_iso: string;
550
+ /** The language this level was actually served from. */
551
+ resolved_language_iso: string;
552
+ is_fallback: boolean;
553
+ is_published: boolean;
554
+ published_at: string | null;
555
+ updated_at: string | null;
556
+ /** Only present when requested with `include_content`. */
557
+ content?: Content;
558
+ /** Only present when requested with `translations`. */
559
+ translations?: IBBreadcrumbTranslation[];
560
+ }
561
+
562
+ export declare interface IBBreadcrumbMeta {
563
+ language_iso: string;
564
+ fallback_language_iso: string | null;
565
+ i18n_mode: 'overlay' | 'independent';
566
+ levels: number;
567
+ root_id: string | null;
568
+ current_id: string | null;
569
+ }
570
+
571
+ export declare interface IBBreadcrumbParams {
572
+ /** Language every level is resolved for. Unknown values fall back to the space default. */
573
+ language?: string;
574
+ language_iso?: string;
575
+ /** A version id is not accepted here — every level is a different entry. */
576
+ vid?: 'published' | 'draft';
577
+ /** Include the requested entry as the last level. Defaults to `true`. */
578
+ include_self?: boolean;
579
+ /** `all` keeps unpublished ancestors, which are dropped by default. */
580
+ ancestors?: 'published' | 'all';
581
+ /** Add published sibling translations to every level. */
582
+ translations?: boolean;
583
+ /** Add the resolved `content` payload to every level; honors `take`/`except`. */
584
+ include_content?: boolean;
585
+ /** Comma-separated field whitelist for `include_content`. */
586
+ take?: string;
587
+ /** Comma-separated field blacklist for `include_content`. */
588
+ except?: string;
589
+ }
590
+
591
+ export declare interface IBBreadcrumbResponse<Content = IBContentBlock<string> & {
592
+ [index: string]: unknown;
593
+ }> {
594
+ /** The trail, ordered from the tree root down to the requested entry. */
595
+ breadcrumb: IBBreadcrumbLevel<Content>[];
596
+ meta: IBBreadcrumbMeta;
597
+ rv?: string | number;
598
+ }
599
+
600
+ /** A published sibling translation of a breadcrumb level. */
601
+ export declare interface IBBreadcrumbTranslation {
602
+ language_iso: string;
603
+ name: string | null;
604
+ /** Stored path of the translation, without a locale segment. */
605
+ full_slug: string;
606
+ /** Delivery path of the translation, with its own locale segment applied. */
607
+ path: string;
608
+ }
609
+
461
610
  export declare interface IBCollectionResponse<T> {
462
611
  data: T[];
463
612
  rv?: string | number;
@@ -532,6 +681,14 @@ export declare interface IBDataEntry {
532
681
  updated_at: string;
533
682
  }
534
683
 
684
+ export declare type IBDataEntryParams = Omit<IBBaseQueryParams, 'token'> & {
685
+ /**
686
+ * Serves the entries mutated for this dimension (usually a locale), falling
687
+ * back to the stored base value for keys the dimension does not override.
688
+ */
689
+ dimension?: string;
690
+ };
691
+
535
692
  export declare interface IBDataSource {
536
693
  id: string;
537
694
  name: string;
@@ -665,6 +822,26 @@ export declare type IdFilter = string | {
665
822
 
666
823
  declare type Listener = () => void;
667
824
 
825
+ /**
826
+ * Merge a `CONTENT_UPDATE` payload into an existing content tree.
827
+ *
828
+ * The editor sends updates scoped to the edited item — the payload is the block
829
+ * that changed, carrying its own `id` — and only sends the whole tree when the
830
+ * root block itself is edited (as `{ id: entryId, ...entryContent }`). Blindly
831
+ * assigning the payload as the new root therefore collapses the page to the
832
+ * edited block, so the payload is instead matched by `id`:
833
+ *
834
+ * - payload without an `id` → treated as the whole tree (legacy/whole-tree push)
835
+ * - payload id equal to the root's id → replaces the root
836
+ * - payload id found in the tree → replaces that node in place, immutably
837
+ * - payload id found nowhere → ignored (an update for a block not rendered here)
838
+ *
839
+ * When the root is rendered without its entry id (`entry.content` alone, so the
840
+ * root has no `id` to match) an update that matches nothing nested but has the
841
+ * same `block` type as the root is taken as the root.
842
+ */
843
+ export declare function mergeContentUpdate<T>(root: T, update: Record<string, unknown>): T;
844
+
668
845
  export declare function normalizePathSegment(value: string | null | undefined): string;
669
846
 
670
847
  export declare class PreviewBridge {
@@ -706,7 +883,7 @@ export declare interface PreviewBridgeInitOptions {
706
883
 
707
884
  /**
708
885
  * A framework-agnostic, reactive holder for the content tree shown in the
709
- * preview. The editor pushes whole-tree (`CONTENT_UPDATE`) or granular
886
+ * preview. The editor pushes block-scoped (`CONTENT_UPDATE`) or granular
710
887
  * (`CONTENT_PATCH`) changes; subscribers re-render from the new snapshot.
711
888
  */
712
889
  export declare class PreviewStore<T = Record<string, unknown>> {
@@ -716,6 +893,12 @@ export declare class PreviewStore<T = Record<string, unknown>> {
716
893
  subscribe: (listener: Listener) => (() => void);
717
894
  getSnapshot: () => T;
718
895
  setContent(next: T): void;
896
+ /**
897
+ * Apply an editor `CONTENT_UPDATE` payload. See {@link mergeContentUpdate}:
898
+ * scoped payloads are merged by `id` instead of replacing the whole tree.
899
+ * Unknown ids are ignored and do not notify subscribers.
900
+ */
901
+ applyContentUpdate(update: Record<string, unknown>): void;
719
902
  patch(path: FieldPath, value: unknown): void;
720
903
  private emit;
721
904
  }
@@ -737,8 +920,11 @@ export declare function renderSitemapIndex(paths: string[], siteUrl?: string): s
737
920
  /**
738
921
  * Renders `IBSitemapEntry[]` as a `<urlset>` XML string.
739
922
  * Pass `siteUrl` to emit absolute `<loc>` values; without it, relative paths are used.
923
+ *
924
+ * Locale prefixing follows {@link SitemapPathOptions.localePrefix}, which
925
+ * defaults to `auto` — a mono-lingual entry set is emitted unprefixed.
740
926
  */
741
- export declare function renderSitemapXml(entries: IBSitemapEntry[], siteUrl?: string): string;
927
+ export declare function renderSitemapXml(entries: IBSitemapEntry[], siteUrl?: string, options?: SitemapPathOptions): string;
742
928
 
743
929
  /**
744
930
  * Resolves a B10cksLink value to a plain { href, target } object.
@@ -751,6 +937,11 @@ export declare function renderSitemapXml(entries: IBSitemapEntry[], siteUrl?: st
751
937
  */
752
938
  export declare function resolveB10cksLink(link: B10cksLink | undefined | null): B10cksLinkResolved | undefined;
753
939
 
940
+ export declare type RootBlock<T> = T & {
941
+ id: string;
942
+ block: string;
943
+ };
944
+
754
945
  export declare type SelectUpdateEvent = {
755
946
  selectedItem: string;
756
947
  };
@@ -767,13 +958,34 @@ export declare function setAtPath<T>(target: T, path: FieldPath, value: unknown)
767
958
  */
768
959
  export declare function setPreviewScrollOffset(offset: number | string): void;
769
960
 
770
- export declare interface SitemapFilterOptions {
961
+ export declare interface SitemapFilterOptions extends SitemapPathOptions {
771
962
  /** Absolute base URL used for deduplication. Without it, paths are compared as strings. */
772
963
  siteUrl?: string;
773
964
  /** Only include entries for this locale (ISO code). */
774
965
  locale?: string;
775
966
  }
776
967
 
968
+ /**
969
+ * How a locale segment is applied to an entry's stored `full_slug`. The SDK
970
+ * cannot infer the consuming app's routing, so this mirrors the usual i18n
971
+ * strategies.
972
+ *
973
+ * - `auto` (default) prefixes only when the entries span more than one
974
+ * `language_iso`. A mono-lingual space is served at `/about`, not `/en/about`,
975
+ * even though its entries still carry a language.
976
+ * - `always` prefixes every entry.
977
+ * - `never` uses paths as stored, for an app that routes the locale some other
978
+ * way (a route param, a domain).
979
+ * - `except-default` prefixes every locale but {@link SitemapPathOptions.defaultLocale}.
980
+ */
981
+ export declare type SitemapLocalePrefix = 'auto' | 'always' | 'never' | 'except-default';
982
+
983
+ export declare interface SitemapPathOptions {
984
+ localePrefix?: SitemapLocalePrefix;
985
+ /** The unprefixed locale under `localePrefix: 'except-default'`. */
986
+ defaultLocale?: string;
987
+ }
988
+
777
989
  export declare type StringFilter = string | {
778
990
  eq: string;
779
991
  } | {
@@ -789,13 +1001,30 @@ export declare type StringFilter = string | {
789
1001
  } | {
790
1002
  '^like': string;
791
1003
  } | {
792
- 'like$': string;
1004
+ like$: string;
793
1005
  } | {
794
1006
  null: true;
795
1007
  } | {
796
1008
  '!null': true;
797
1009
  };
798
1010
 
1011
+ /**
1012
+ * Flatten a content entry into a renderable root block.
1013
+ *
1014
+ * An entry's `content` object carries `block` but not `id` — the id lives on the
1015
+ * entry. Rendering `entry.content` directly therefore yields a root block the
1016
+ * visual editor cannot address: `v-editable` no-ops on it, and the editor's
1017
+ * root-level `CONTENT_UPDATE` (sent as `{ id: entryId, … }`) matches nothing.
1018
+ * Use this helper to carry the entry id into the tree:
1019
+ *
1020
+ * ```ts
1021
+ * const block = toRootBlock(entry) // { ...entry.content, id, block }
1022
+ * ```
1023
+ */
1024
+ export declare function toRootBlock<T extends Record<string, unknown>>(entry: IBContent<T>): RootBlock<T>;
1025
+
1026
+ export declare function toRootBlock<T extends Record<string, unknown>>(entry: IBContent<T> | null | undefined): RootBlock<T> | null;
1027
+
799
1028
  export declare namespace types {
800
1029
  export {
801
1030
  FetchClient,
@@ -809,7 +1038,13 @@ export declare namespace types {
809
1038
  IBContentRelation,
810
1039
  IBContent,
811
1040
  IBContentBlock,
1041
+ IBBreadcrumbTranslation,
1042
+ IBBreadcrumbLevel,
1043
+ IBBreadcrumbMeta,
1044
+ IBBreadcrumbResponse,
1045
+ IBBreadcrumbParams,
812
1046
  IBDataEntry,
1047
+ IBDataEntryParams,
813
1048
  IBPaginationParams,
814
1049
  IBSortParams,
815
1050
  IBBaseQueryParams,