@fern-api/fdr-sdk 1.2.41-f793e24db2 → 1.2.42-080b4f1d94

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.
Files changed (90) hide show
  1. package/dist/js/client/FdrClient.js +1 -0
  2. package/dist/js/client/FdrClient.js.map +1 -1
  3. package/dist/js/client/FdrClient.mjs +1 -0
  4. package/dist/js/client/FdrClient.mjs.map +1 -1
  5. package/dist/js/converters/index.js +9 -0
  6. package/dist/js/converters/index.js.map +1 -1
  7. package/dist/js/converters/index.mjs +9 -0
  8. package/dist/js/converters/index.mjs.map +1 -1
  9. package/dist/js/index.js +10 -0
  10. package/dist/js/index.js.map +1 -1
  11. package/dist/js/index.mjs +10 -0
  12. package/dist/js/index.mjs.map +1 -1
  13. package/dist/js/navigation/index.js +9 -0
  14. package/dist/js/navigation/index.js.map +1 -1
  15. package/dist/js/navigation/index.mjs +9 -0
  16. package/dist/js/navigation/index.mjs.map +1 -1
  17. package/dist/js/navigation/ledger-root-builder.js +212 -36
  18. package/dist/js/navigation/ledger-root-builder.js.map +1 -1
  19. package/dist/js/navigation/ledger-root-builder.mjs +212 -36
  20. package/dist/js/navigation/ledger-root-builder.mjs.map +1 -1
  21. package/dist/js/orpc-client.js +1 -0
  22. package/dist/js/orpc-client.js.map +1 -1
  23. package/dist/js/orpc-client.mjs +1 -0
  24. package/dist/js/orpc-client.mjs.map +1 -1
  25. package/dist/navigation/__test__/ledger-root-builder.crossProductDedup.test.d.ts +2 -0
  26. package/dist/navigation/__test__/ledger-root-builder.crossProductDedup.test.d.ts.map +1 -0
  27. package/dist/navigation/__test__/ledger-root-builder.crossProductDedup.test.js +267 -0
  28. package/dist/navigation/__test__/ledger-root-builder.crossProductDedup.test.js.map +1 -0
  29. package/dist/navigation/__test__/ledger-root-builder.ledgerParity.test.d.ts +2 -0
  30. package/dist/navigation/__test__/ledger-root-builder.ledgerParity.test.d.ts.map +1 -0
  31. package/dist/navigation/__test__/ledger-root-builder.ledgerParity.test.js +306 -0
  32. package/dist/navigation/__test__/ledger-root-builder.ledgerParity.test.js.map +1 -0
  33. package/dist/navigation/__test__/ledger-root-builder.metadataPreservation.test.js +167 -4
  34. package/dist/navigation/__test__/ledger-root-builder.metadataPreservation.test.js.map +1 -1
  35. package/dist/navigation/__test__/ledger-root-builder.rootChildOrder.test.js +102 -0
  36. package/dist/navigation/__test__/ledger-root-builder.rootChildOrder.test.js.map +1 -1
  37. package/dist/navigation/__test__/ledger-root-builder.sidebarDepth.test.d.ts +2 -0
  38. package/dist/navigation/__test__/ledger-root-builder.sidebarDepth.test.d.ts.map +1 -0
  39. package/dist/navigation/__test__/ledger-root-builder.sidebarDepth.test.js +273 -0
  40. package/dist/navigation/__test__/ledger-root-builder.sidebarDepth.test.js.map +1 -0
  41. package/dist/navigation/__test__/ledger-root-builder.skipSlugApiReference.test.js +276 -0
  42. package/dist/navigation/__test__/ledger-root-builder.skipSlugApiReference.test.js.map +1 -1
  43. package/dist/navigation/__test__/ledger-root-builder.skipSlugGroupOrdering.test.d.ts +2 -0
  44. package/dist/navigation/__test__/ledger-root-builder.skipSlugGroupOrdering.test.d.ts.map +1 -0
  45. package/dist/navigation/__test__/ledger-root-builder.skipSlugGroupOrdering.test.js +234 -0
  46. package/dist/navigation/__test__/ledger-root-builder.skipSlugGroupOrdering.test.js.map +1 -0
  47. package/dist/navigation/__test__/ledger-root-builder.skipSlugSiblingSection.test.d.ts +2 -0
  48. package/dist/navigation/__test__/ledger-root-builder.skipSlugSiblingSection.test.d.ts.map +1 -0
  49. package/dist/navigation/__test__/ledger-root-builder.skipSlugSiblingSection.test.js +360 -0
  50. package/dist/navigation/__test__/ledger-root-builder.skipSlugSiblingSection.test.js.map +1 -0
  51. package/dist/navigation/ledger-root-builder.d.ts.map +1 -1
  52. package/dist/navigation/ledger-root-builder.js +312 -47
  53. package/dist/navigation/ledger-root-builder.js.map +1 -1
  54. package/dist/navigation/utils/__test__/syntheticSectionPath.test.d.ts +2 -0
  55. package/dist/navigation/utils/__test__/syntheticSectionPath.test.d.ts.map +1 -0
  56. package/dist/navigation/utils/__test__/syntheticSectionPath.test.js +29 -0
  57. package/dist/navigation/utils/__test__/syntheticSectionPath.test.js.map +1 -0
  58. package/dist/navigation/utils/index.d.ts +1 -0
  59. package/dist/navigation/utils/index.d.ts.map +1 -1
  60. package/dist/navigation/utils/index.js +1 -0
  61. package/dist/navigation/utils/index.js.map +1 -1
  62. package/dist/navigation/utils/syntheticSectionPath.d.ts +13 -0
  63. package/dist/navigation/utils/syntheticSectionPath.d.ts.map +1 -0
  64. package/dist/navigation/utils/syntheticSectionPath.js +20 -0
  65. package/dist/navigation/utils/syntheticSectionPath.js.map +1 -0
  66. package/dist/orpc-client/docs-ledger/contract.d.ts +9 -0
  67. package/dist/orpc-client/docs-ledger/contract.d.ts.map +1 -1
  68. package/dist/orpc-client/docs-ledger/contract.js +1 -0
  69. package/dist/orpc-client/docs-ledger/contract.js.map +1 -1
  70. package/dist/tsconfig.tsbuildinfo +1 -1
  71. package/dist/types/navigation/__test__/ledger-root-builder.crossProductDedup.test.d.ts +2 -0
  72. package/dist/types/navigation/__test__/ledger-root-builder.crossProductDedup.test.d.ts.map +1 -0
  73. package/dist/types/navigation/__test__/ledger-root-builder.ledgerParity.test.d.ts +2 -0
  74. package/dist/types/navigation/__test__/ledger-root-builder.ledgerParity.test.d.ts.map +1 -0
  75. package/dist/types/navigation/__test__/ledger-root-builder.sidebarDepth.test.d.ts +2 -0
  76. package/dist/types/navigation/__test__/ledger-root-builder.sidebarDepth.test.d.ts.map +1 -0
  77. package/dist/types/navigation/__test__/ledger-root-builder.skipSlugGroupOrdering.test.d.ts +2 -0
  78. package/dist/types/navigation/__test__/ledger-root-builder.skipSlugGroupOrdering.test.d.ts.map +1 -0
  79. package/dist/types/navigation/__test__/ledger-root-builder.skipSlugSiblingSection.test.d.ts +2 -0
  80. package/dist/types/navigation/__test__/ledger-root-builder.skipSlugSiblingSection.test.d.ts.map +1 -0
  81. package/dist/types/navigation/ledger-root-builder.d.ts.map +1 -1
  82. package/dist/types/navigation/utils/__test__/syntheticSectionPath.test.d.ts +2 -0
  83. package/dist/types/navigation/utils/__test__/syntheticSectionPath.test.d.ts.map +1 -0
  84. package/dist/types/navigation/utils/index.d.ts +1 -0
  85. package/dist/types/navigation/utils/index.d.ts.map +1 -1
  86. package/dist/types/navigation/utils/syntheticSectionPath.d.ts +13 -0
  87. package/dist/types/navigation/utils/syntheticSectionPath.d.ts.map +1 -0
  88. package/dist/types/orpc-client/docs-ledger/contract.d.ts +9 -0
  89. package/dist/types/orpc-client/docs-ledger/contract.d.ts.map +1 -1
  90. package/package.json +1 -1
@@ -1,4 +1,5 @@
1
1
  import * as FernNavigation from "./index.js";
2
+ import { stripSyntheticSegments } from "./utils/syntheticSectionPath.js";
2
3
  const STRUCTURAL_SEGMENT_TYPES = new Set([
3
4
  "section",
4
5
  "apiReference",
@@ -59,6 +60,41 @@ function metaStr(metadata, key) {
59
60
  }
60
61
  return undefined;
61
62
  }
63
+ /**
64
+ * V1 availability values stored in ledger metadata are lowercase (e.g. "deprecated"),
65
+ * but the latest Availability type uses PascalCase (e.g. "Deprecated"). This map
66
+ * normalises both formats so the badge component can look up display names correctly.
67
+ */
68
+ const AVAILABILITY_LOOKUP = {
69
+ // V1 lowercase values (stored by docsPublishTransform from V1 navigation tree)
70
+ alpha: FernNavigation.Availability.Alpha,
71
+ stable: FernNavigation.Availability.Stable,
72
+ "generally-available": FernNavigation.Availability.GenerallyAvailable,
73
+ "in-development": FernNavigation.Availability.InDevelopment,
74
+ "pre-release": FernNavigation.Availability.PreRelease,
75
+ deprecated: FernNavigation.Availability.Deprecated,
76
+ beta: FernNavigation.Availability.Beta,
77
+ preview: FernNavigation.Availability.Preview,
78
+ legacy: FernNavigation.Availability.Legacy,
79
+ // Latest PascalCase values (pass-through)
80
+ Alpha: FernNavigation.Availability.Alpha,
81
+ Stable: FernNavigation.Availability.Stable,
82
+ GenerallyAvailable: FernNavigation.Availability.GenerallyAvailable,
83
+ InDevelopment: FernNavigation.Availability.InDevelopment,
84
+ PreRelease: FernNavigation.Availability.PreRelease,
85
+ Deprecated: FernNavigation.Availability.Deprecated,
86
+ Beta: FernNavigation.Availability.Beta,
87
+ Preview: FernNavigation.Availability.Preview,
88
+ Legacy: FernNavigation.Availability.Legacy
89
+ };
90
+ /** Read an availability field from metadata, converting V1 lowercase to latest PascalCase. */
91
+ function metaAvailability(metadata) {
92
+ const raw = metaStr(metadata, "availability");
93
+ if (raw == null) {
94
+ return undefined;
95
+ }
96
+ return AVAILABILITY_LOOKUP[raw];
97
+ }
62
98
  function metaBool(metadata, key) {
63
99
  if (metadata != null && typeof metadata === "object" && key in metadata) {
64
100
  const v = metadata[key];
@@ -197,7 +233,7 @@ function artifactToNode(ctx, route) {
197
233
  }),
198
234
  pageId: FernNavigation.PageId(pageId),
199
235
  noindex: metaBool(md, "noindex"),
200
- availability: undefined
236
+ availability: metaAvailability(md)
201
237
  };
202
238
  return node;
203
239
  }
@@ -268,7 +304,7 @@ function apiLeafNodeFromNavRouteInternal(ctx, route, segmentApiDefinitionId) {
268
304
  endpointId: FernNavigation.EndpointId(endpointId),
269
305
  apiDefinitionId,
270
306
  isResponseStream: metaBool(md, "isResponseStream"),
271
- availability: metaStr(md, "availability"),
307
+ availability: metaAvailability(md),
272
308
  playground: undefined
273
309
  };
274
310
  }
@@ -284,7 +320,7 @@ function apiLeafNodeFromNavRouteInternal(ctx, route, segmentApiDefinitionId) {
284
320
  method: method,
285
321
  webhookId: FernNavigation.WebhookId(webhookId),
286
322
  apiDefinitionId,
287
- availability: metaStr(md, "availability")
323
+ availability: metaAvailability(md)
288
324
  };
289
325
  }
290
326
  if (route.type === "asyncapi") {
@@ -297,7 +333,7 @@ function apiLeafNodeFromNavRouteInternal(ctx, route, segmentApiDefinitionId) {
297
333
  ...meta,
298
334
  webSocketId: FernNavigation.WebSocketId(webSocketId),
299
335
  apiDefinitionId,
300
- availability: metaStr(md, "availability"),
336
+ availability: metaAvailability(md),
301
337
  playground: undefined
302
338
  };
303
339
  }
@@ -313,7 +349,7 @@ function apiLeafNodeFromNavRouteInternal(ctx, route, segmentApiDefinitionId) {
313
349
  method: method,
314
350
  grpcId: FernNavigation.GrpcId(grpcId),
315
351
  apiDefinitionId,
316
- availability: metaStr(md, "availability")
352
+ availability: metaAvailability(md)
317
353
  };
318
354
  }
319
355
  if (route.type === "graphql") {
@@ -329,7 +365,7 @@ function apiLeafNodeFromNavRouteInternal(ctx, route, segmentApiDefinitionId) {
329
365
  graphqlOperationId: FernNavigation.GraphQlOperationId(graphqlOperationId),
330
366
  graphqlOperationIds: undefined,
331
367
  apiDefinitionId,
332
- availability: metaStr(md, "availability"),
368
+ availability: metaAvailability(md),
333
369
  playground: undefined
334
370
  };
335
371
  }
@@ -517,7 +553,8 @@ function structuralNodeSlug(ctx, overviewFullPath, section, scopePrefix) {
517
553
  // basepath-absolute (it is the version/product/tab node's slug), so join it
518
554
  // directly rather than going through `contentSlug` (which would re-prefix
519
555
  // the basepath).
520
- return section !== "" ? FernNavigation.slugjoin(scopePrefix, section) : scopePrefix;
556
+ const cleanSection = stripSyntheticSegments(section);
557
+ return cleanSection !== "" ? FernNavigation.slugjoin(scopePrefix, cleanSection) : scopePrefix;
521
558
  }
522
559
  function stripLeadingScopePrefix(section, scopePrefix) {
523
560
  const prefix = scopePrefix;
@@ -532,6 +569,30 @@ function stripLeadingScopePrefix(section, scopePrefix) {
532
569
  }
533
570
  return section;
534
571
  }
572
+ function computeDuplicateSiblingSortBoundaries(siblings) {
573
+ const result = new Map();
574
+ const byPath = new Map();
575
+ for (const sibling of siblings) {
576
+ if (metaStr(sibling.seg.metadata, "type") !== "section") {
577
+ continue;
578
+ }
579
+ const group = byPath.get(sibling.seg.section) ?? [];
580
+ group.push(sibling);
581
+ byPath.set(sibling.seg.section, group);
582
+ }
583
+ for (const [, group] of byPath) {
584
+ if (group.length <= 1) {
585
+ continue;
586
+ }
587
+ for (let i = 0; i < group.length; i++) {
588
+ result.set(group[i], {
589
+ lo: group[i].seg.sortOrder,
590
+ hi: i + 1 < group.length ? group[i + 1].seg.sortOrder : Number.MAX_SAFE_INTEGER
591
+ });
592
+ }
593
+ }
594
+ return result;
595
+ }
535
596
  /**
536
597
  * Merge leaf children and section children by their original V1 tree position.
537
598
  * Leaves carry position via `displaySortOrder` (stored in nav routes), sections
@@ -595,7 +656,7 @@ function sectionNode(ctx, scoped, sectionChildren, scopePrefix) {
595
656
  noindex: metaBool(overview?.metadata, "noindex") ?? metaBool(seg.metadata, "noindex"),
596
657
  collapsible: metaBool(seg.metadata, "collapsible") ?? (metaCollapsed(seg.metadata) === true ? true : undefined),
597
658
  collapsedByDefault: metaBool(seg.metadata, "collapsedByDefault") ?? (metaCollapsed(seg.metadata) === true ? true : undefined),
598
- availability: metaStr(seg.metadata, "availability"),
659
+ availability: metaAvailability(seg.metadata),
599
660
  pointsTo: metaPointsTo != null ? pointsToSlug(metaPointsTo) : undefined,
600
661
  children: mergeChildrenByPosition(ctx, nav, sectionChildren)
601
662
  };
@@ -605,13 +666,16 @@ function sectionNode(ctx, scoped, sectionChildren, scopePrefix) {
605
666
  * `parentSectionPath(seg.section) === parentSection`, or is an orphaned segment
606
667
  * whose nearest existing ancestor is `parentSection`.
607
668
  */
608
- function directChildApiPackages(parentSection, scopeSegs) {
669
+ function directChildApiPackages(parentSection, scopeSegs, apiDefinitionId) {
609
670
  const sectionPaths = new Set(scopeSegs.map((s) => s.seg.section));
610
671
  return scopeSegs
611
672
  .filter((s) => {
612
673
  if (metaStr(s.seg.metadata, "type") !== "apiPackage") {
613
674
  return false;
614
675
  }
676
+ if (metaStr(s.seg.metadata, "apiDefinitionId") !== apiDefinitionId) {
677
+ return false;
678
+ }
615
679
  const parent = parentSectionPath(s.seg.section);
616
680
  if (parent === parentSection) {
617
681
  return true;
@@ -636,11 +700,37 @@ function buildApiChildren(ctx, scoped, scopeSegs, apiDefinitionId, scopePrefix)
636
700
  // API leaf types.
637
701
  const leafNodes = positionedApiLeafChildren(ctx, nav, apiDefinitionId);
638
702
  // Build nested ApiPackageNodes from direct child apiPackage segments.
639
- const childPackages = directChildApiPackages(seg.section, scopeSegs);
703
+ let childPackages = directChildApiPackages(seg.section, scopeSegs, apiDefinitionId);
704
+ // When multiple API-type segments share the same section path (skipUrlSlug
705
+ // group packages that collapse to their parent's section), children from
706
+ // different groups get mixed together. Scope children to this segment's DFS
707
+ // subtree using sortOrder boundaries to restore correct ownership.
708
+ const samePathApiSiblings = scopeSegs.filter((s) => s.seg.section === seg.section &&
709
+ s.seg.sortOrder !== seg.sortOrder &&
710
+ API_NODE_SEGMENT_TYPES.has(metaStr(s.seg.metadata, "type") ?? ""));
711
+ const hasCollapsedGroups = samePathApiSiblings.length > 0;
712
+ if (hasCollapsedGroups && metaStr(seg.metadata, "type") !== "apiReference") {
713
+ // This is a group package sharing its section with siblings.
714
+ // Only claim children whose sortOrder falls within our DFS subtree.
715
+ const nextSibling = samePathApiSiblings
716
+ .filter((s) => s.seg.sortOrder > seg.sortOrder)
717
+ .sort((a, b) => a.seg.sortOrder - b.seg.sortOrder)[0];
718
+ const lo = seg.sortOrder;
719
+ const hi = nextSibling?.seg.sortOrder ?? Number.MAX_SAFE_INTEGER;
720
+ childPackages = childPackages.filter((c) => c.seg.sortOrder > lo && c.seg.sortOrder < hi);
721
+ }
640
722
  const packageNodes = childPackages.map((child) => ({
641
723
  node: apiPackageChildNode(ctx, child, scopeSegs, apiDefinitionId, scopePrefix),
642
724
  childIndex: metaNum(child.seg.metadata, "childIndex")
643
725
  }));
726
+ // When collapsed groups are detected at apiReference level, children's
727
+ // childIndex values are relative to different parent groups and cannot be
728
+ // used for interleaving. Fall back to sortOrder (DFS creation order).
729
+ if (hasCollapsedGroups && metaStr(seg.metadata, "type") === "apiReference") {
730
+ return [...leafNodes, ...packageNodes.map((p, i) => ({ node: p.node, pos: leafNodes.length + i }))]
731
+ .sort((a, b) => a.pos - b.pos)
732
+ .map((p) => p.node);
733
+ }
644
734
  // Interleave by position when childIndex metadata is available
645
735
  const hasChildIndex = packageNodes.some((p) => p.childIndex != null);
646
736
  if (!hasChildIndex) {
@@ -684,7 +774,7 @@ function apiPackageChildNode(ctx, scoped, scopeSegs, parentApiDefinitionId, scop
684
774
  featureFlags: metaFeatureFlags(seg.metadata)
685
775
  }),
686
776
  apiDefinitionId: FernNavigation.ApiDefinitionId(apiDefinitionId),
687
- availability: metaStr(seg.metadata, "availability"),
777
+ availability: metaAvailability(seg.metadata),
688
778
  overviewPageId: overviewPageId != null ? FernNavigation.PageId(overviewPageId) : undefined,
689
779
  noindex: metaBool(overview?.metadata, "noindex") ?? metaBool(seg.metadata, "noindex"),
690
780
  pointsTo: metaPointsTo != null ? pointsToSlug(metaPointsTo) : undefined,
@@ -794,10 +884,10 @@ function apiReferenceNode(ctx, scoped, scopeSegs, scopePrefix) {
794
884
  featureFlags: metaFeatureFlags(seg.metadata)
795
885
  }),
796
886
  apiDefinitionId: FernNavigation.ApiDefinitionId(apiDefinitionId),
797
- availability: metaStr(seg.metadata, "availability"),
887
+ availability: metaAvailability(seg.metadata),
798
888
  overviewPageId: overviewPageId != null ? FernNavigation.PageId(overviewPageId) : undefined,
799
889
  noindex: metaBool(overview?.metadata, "noindex") ?? metaBool(seg.metadata, "noindex"),
800
- paginated: true,
890
+ paginated: metaBool(seg.metadata, "paginated"),
801
891
  showErrors: metaBool(seg.metadata, "showErrors"),
802
892
  hideTitle: metaBool(seg.metadata, "hideTitle"),
803
893
  pointsTo: metaPointsTo != null ? pointsToSlug(metaPointsTo) : undefined,
@@ -815,7 +905,12 @@ function attachedApiChangelogNode(ctx, scoped, scopeSegs, apiDefinitionId, scope
815
905
  }
816
906
  return metaStr(candidate.seg.metadata, "apiDefinitionId") === apiDefinitionId;
817
907
  });
818
- const changelogSeg = candidates.find((candidate) => parentSectionPath(candidate.seg.section) === seg.section) ?? candidates[0];
908
+ const apiReferenceCount = scopeSegs.filter((candidate) => {
909
+ return (metaStr(candidate.seg.metadata, "type") === "apiReference" &&
910
+ metaStr(candidate.seg.metadata, "apiDefinitionId") === apiDefinitionId);
911
+ }).length;
912
+ const changelogSeg = candidates.find((candidate) => parentSectionPath(candidate.seg.section) === seg.section) ??
913
+ (apiReferenceCount === 1 ? candidates[0] : undefined);
819
914
  return changelogSeg != null ? changelogNode(ctx, changelogSeg, scopePrefix) : undefined;
820
915
  }
821
916
  function hasOwningApiReference(scoped, scopeSegs) {
@@ -823,12 +918,68 @@ function hasOwningApiReference(scoped, scopeSegs) {
823
918
  if (apiDefinitionId == null || metaStr(scoped.seg.metadata, "type") !== "changelog") {
824
919
  return false;
825
920
  }
826
- return scopeSegs.some((candidate) => {
921
+ const candidates = scopeSegs.filter((candidate) => {
827
922
  if (metaStr(candidate.seg.metadata, "type") !== "apiReference") {
828
923
  return false;
829
924
  }
830
925
  return metaStr(candidate.seg.metadata, "apiDefinitionId") === apiDefinitionId;
831
926
  });
927
+ return (candidates.some((candidate) => parentSectionPath(scoped.seg.section) === candidate.seg.section) ||
928
+ candidates.length === 1);
929
+ }
930
+ /**
931
+ * True when this segment is an `apiPackage` that will be nested under an in-scope
932
+ * `apiReference` for the same API by {@link buildApiChildren}, and therefore must
933
+ * NOT also be emitted as a standalone root/section node.
934
+ *
935
+ * Without this guard, a skip-slug apiReference (section "") leaves its resource
936
+ * subpackages with `parentSectionPath === ""`, so they look root-level and get
937
+ * emitted a second time as always-expanded top-level apiReference nodes —
938
+ * duplicating every resource and endpoint in the sidebar (the "67 apiReference
939
+ * nodes vs 1" API-reference regression).
940
+ *
941
+ * Reachability mirrors {@link directChildApiPackages}: walk up the section-path
942
+ * chain (hopping to nearestExistingAncestor when a parent section is absent)
943
+ * until we reach an apiReference's section. If no apiReference is an ancestor the
944
+ * package is left where it is, so it can never be dropped.
945
+ */
946
+ function isNestedApiPackage(scoped, scopeSegs) {
947
+ if (metaStr(scoped.seg.metadata, "type") !== "apiPackage") {
948
+ return false;
949
+ }
950
+ const apiDefinitionId = metaStr(scoped.seg.metadata, "apiDefinitionId");
951
+ if (apiDefinitionId == null) {
952
+ return false;
953
+ }
954
+ const apiReferenceSections = new Set(scopeSegs
955
+ .filter((s) => metaStr(s.seg.metadata, "type") === "apiReference" &&
956
+ metaStr(s.seg.metadata, "apiDefinitionId") === apiDefinitionId)
957
+ .map((s) => s.seg.section));
958
+ if (apiReferenceSections.size === 0) {
959
+ return false;
960
+ }
961
+ const sectionPaths = new Set(scopeSegs.map((s) => s.seg.section));
962
+ const resolveParent = (section) => {
963
+ const parent = parentSectionPath(section);
964
+ if (parent === "" || sectionPaths.has(parent)) {
965
+ return parent;
966
+ }
967
+ return nearestExistingAncestor(section, sectionPaths);
968
+ };
969
+ let current = scoped.seg.section;
970
+ const seen = new Set([current]);
971
+ // Walk up until we hit an owning apiReference (nested → true) or run out.
972
+ for (;;) {
973
+ const parent = resolveParent(current);
974
+ if (apiReferenceSections.has(parent)) {
975
+ return true;
976
+ }
977
+ if (parent === "" || seen.has(parent)) {
978
+ return false;
979
+ }
980
+ seen.add(parent);
981
+ current = parent;
982
+ }
832
983
  }
833
984
  function changelogNode(ctx, scoped, scopePrefix) {
834
985
  const { seg, nav } = scoped;
@@ -952,7 +1103,13 @@ function buildSectionTree(ctx, scopeSegs, parentPath, scopePrefix, changelogScop
952
1103
  if (sec === "" || type === "tabRoot") {
953
1104
  return false;
954
1105
  }
955
- if (hasOwningApiReference(s, scopeSegs)) {
1106
+ if (hasOwningApiReference(s, scopeSegs) || isNestedApiPackage(s, scopeSegs)) {
1107
+ return false;
1108
+ }
1109
+ // Segments marked as sidebar depth 0 are V1 root-level peers and
1110
+ // must never be adopted as children of another section.
1111
+ const depth = metaNum(s.seg.metadata, "sidebarDepth");
1112
+ if (depth === 0) {
956
1113
  return false;
957
1114
  }
958
1115
  const parent = parentSectionPath(sec);
@@ -967,6 +1124,7 @@ function buildSectionTree(ctx, scopeSegs, parentPath, scopePrefix, changelogScop
967
1124
  return false;
968
1125
  })
969
1126
  .sort((a, b) => a.seg.sortOrder - b.seg.sortOrder);
1127
+ const siblingBoundaries = computeDuplicateSiblingSortBoundaries(direct);
970
1128
  return direct.map((s) => {
971
1129
  const type = metaStr(s.seg.metadata, "type");
972
1130
  const childIndex = metaNum(s.seg.metadata, "childIndex");
@@ -979,7 +1137,11 @@ function buildSectionTree(ctx, scopeSegs, parentPath, scopePrefix, changelogScop
979
1137
  }
980
1138
  else {
981
1139
  // section (or unrecognised) → recurse for nested sections.
982
- node = sectionNode(ctx, s, buildSectionTree(ctx, scopeSegs, s.seg.section, scopePrefix, changelogScopePrefix), scopePrefix);
1140
+ const boundary = siblingBoundaries.get(s);
1141
+ const childScopeSegs = boundary != null
1142
+ ? scopeSegs.filter((candidate) => candidate.seg.sortOrder >= boundary.lo && candidate.seg.sortOrder < boundary.hi)
1143
+ : scopeSegs;
1144
+ node = sectionNode(ctx, s, buildSectionTree(ctx, childScopeSegs, s.seg.section, scopePrefix, changelogScopePrefix), scopePrefix);
983
1145
  }
984
1146
  return { node, childIndex };
985
1147
  });
@@ -999,16 +1161,26 @@ function buildSectionTree(ctx, scopeSegs, parentPath, scopePrefix, changelogScop
999
1161
  function computeSiblingSortBoundaries(ordered) {
1000
1162
  const result = new Map();
1001
1163
  // Collect root-level sections grouped by their section path.
1164
+ // Sections with sec==="" (skip-slug sections) are included: when multiple
1165
+ // skip-slug sections exist at the root, they share path "" and need
1166
+ // boundaries so each only adopts its own children.
1002
1167
  const sectionPaths = new Set(ordered.map((s) => s.seg.section));
1003
1168
  const rootSections = [];
1004
1169
  for (const s of ordered) {
1005
1170
  const type = metaStr(s.seg.metadata, "type");
1006
1171
  const sec = s.seg.section;
1007
- if (type !== "section" || sec === "") {
1172
+ if (type !== "section") {
1173
+ continue;
1174
+ }
1175
+ if (sec === "") {
1176
+ rootSections.push(s);
1008
1177
  continue;
1009
1178
  }
1179
+ const depth = metaNum(s.seg.metadata, "sidebarDepth");
1010
1180
  const parent = parentSectionPath(sec);
1011
- const isRootLevel = parent === "" || (!sectionPaths.has(parent) && nearestExistingAncestor(sec, sectionPaths) === "");
1181
+ const isRootLevel = depth === 0 ||
1182
+ parent === "" ||
1183
+ (!sectionPaths.has(parent) && nearestExistingAncestor(sec, sectionPaths) === "");
1012
1184
  if (isRootLevel) {
1013
1185
  rootSections.push(s);
1014
1186
  }
@@ -1053,6 +1225,17 @@ function buildSidebarRootChildren(ctx, scopeSegs, scopePrefix, changelogScopePre
1053
1225
  // segments. Both index into the SAME child list at write time, so they
1054
1226
  // interleave directly (e.g. [page 0, page 1, section 2…15, page 16, 17]).
1055
1227
  const annotated = [];
1228
+ // ── Sibling section ownership ────────────────────────────────────────
1229
+ //
1230
+ // Multiple root-level sections can share the same section path (e.g.
1231
+ // three sections all with path equal to the version slug). When this
1232
+ // happens, buildSectionTree would incorrectly give ALL child subsections
1233
+ // to each sibling. We resolve ownership via sortOrder: a section owns
1234
+ // segments whose sortOrder falls between its own and the next sibling's.
1235
+ //
1236
+ // Computed first because hasRootSection (below) uses it to decide
1237
+ // whether bounded skip-slug siblings should activate adoption.
1238
+ const siblingBoundaries = computeSiblingSortBoundaries(ordered);
1056
1239
  // ── Root-section adoption flow ──────────────────────────────────────
1057
1240
  //
1058
1241
  // A scope may contain a "root section" — a segment with type "section"
@@ -1064,28 +1247,42 @@ function buildSidebarRootChildren(ctx, scopeSegs, scopePrefix, changelogScopePre
1064
1247
  // │ → emit pages/links inline at their displaySortOrder
1065
1248
  // │
1066
1249
  // ├─ (B) the root section itself (sec=="", type=="section")
1067
- // │ → buildSectionTree adopts ALL depth-0 children as its own
1068
- // │ → emit one sectionNode wrapping the whole subtree
1250
+ // │ → buildSectionTree adopts nested children (depth > 0)
1251
+ // │ → emit one sectionNode wrapping the subtree
1069
1252
  // │
1070
- // └─ (C) depth-0 sections (parentSectionPath=="")
1071
- // → SKIP — already adopted by (B) via buildSectionTree
1253
+ // └─ (C) depth-0 sections (sidebarDepth==0 or parentSectionPath=="")
1254
+ // → emit directly as root children (not adopted by B)
1072
1255
  //
1073
1256
  // Without a root section, depth-0 sections are emitted directly.
1074
- const hasRootSection = ordered.some((s) => metaStr(s.seg.metadata, "type") === "section" && s.seg.section === "");
1075
- // ── Sibling section ownership ────────────────────────────────────────
1076
1257
  //
1077
- // Multiple root-level sections can share the same section path (e.g.
1078
- // three sections all with path equal to the version slug). When this
1079
- // happens, buildSectionTree would incorrectly give ALL child subsections
1080
- // to each sibling. We resolve ownership via sortOrder: a section owns
1081
- // segments whose sortOrder falls between its own and the next sibling's.
1082
- const siblingBoundaries = computeSiblingSortBoundaries(ordered);
1258
+ // A section with sec=="" AND `childIndex` in its metadata is a sibling
1259
+ // inside a V1 sidebarGroup that has skipUrlSlug — not a true structural
1260
+ // wrapper. `walkNavSubTrees` always passes `childIndex`; direct
1261
+ // sidebarRoot children (true wrappers) never receive one.
1262
+ //
1263
+ // Such siblings only activate adoption when they have sortOrder
1264
+ // boundaries (multiple sec="" sections sharing the same path), which
1265
+ // correctly scope each section's children. A *single* unbounded
1266
+ // skip-slug sibling (e.g. mangopay's "Introduction") must NOT adopt
1267
+ // its depth-0 peers — doing so produces spurious breadcrumb entries.
1268
+ const hasRootSection = ordered.some((s) => metaStr(s.seg.metadata, "type") === "section" &&
1269
+ s.seg.section === "" &&
1270
+ (metaNum(s.seg.metadata, "childIndex") == null || siblingBoundaries.has(s)));
1083
1271
  for (const s of ordered) {
1084
1272
  const type = metaStr(s.seg.metadata, "type");
1085
1273
  const sec = s.seg.section;
1086
- if (hasOwningApiReference(s, scopeSegs)) {
1274
+ if (hasOwningApiReference(s, scopeSegs) || isNestedApiPackage(s, scopeSegs)) {
1087
1275
  continue;
1088
1276
  }
1277
+ // Skip apiPackage segments that share their section path with an
1278
+ // apiReference sibling (skipUrlSlug structural wrappers). Their
1279
+ // children are already claimed by the apiReference via DFS ordering.
1280
+ if (type === "apiPackage") {
1281
+ const hasApiRefSibling = ordered.some((sib) => sib.seg.section === sec && metaStr(sib.seg.metadata, "type") === "apiReference");
1282
+ if (hasApiRefSibling) {
1283
+ continue;
1284
+ }
1285
+ }
1089
1286
  if (type === "tabRoot" && metaBool(s.seg.metadata, "landingPage") === true) {
1090
1287
  continue;
1091
1288
  }
@@ -1102,21 +1299,35 @@ function buildSidebarRootChildren(ctx, scopeSegs, scopePrefix, changelogScopePre
1102
1299
  continue;
1103
1300
  }
1104
1301
  // (B) Root section wrapper — adopts depth-0 children via buildSectionTree.
1105
- if (type === "section" && sec === "") {
1106
- const sectionChildren = buildSectionTree(ctx, scopeSegs, "", scopePrefix);
1302
+ // Only applies to true root wrappers (no childIndex); sibling
1303
+ // sections with skipUrlSlug (have childIndex) fall through to (C).
1304
+ // When multiple sections share sec==="" (skip-slug), scope children
1305
+ // to each section's sortOrder range so subsections aren't duplicated.
1306
+ if (type === "section" && sec === "" && hasRootSection) {
1307
+ const bounds = siblingBoundaries.get(s);
1308
+ const ownedSegs = bounds != null
1309
+ ? scopeSegs.filter((seg) => seg.seg.sortOrder >= bounds.lo && seg.seg.sortOrder < bounds.hi)
1310
+ : scopeSegs;
1311
+ const sectionChildren = buildSectionTree(ctx, ownedSegs, "", scopePrefix, changelogScopePrefix);
1107
1312
  const node = sectionNode(ctx, s, sectionChildren, scopePrefix);
1108
1313
  annotated.push({ node, pos: metaNum(s.seg.metadata, "childIndex"), isLeaf: false });
1109
1314
  continue;
1110
1315
  }
1111
1316
  // (C) Depth-0 or orphaned sections — emit at root unless already
1112
1317
  // adopted by a root section (B).
1318
+ const depth = metaNum(s.seg.metadata, "sidebarDepth");
1113
1319
  const parent = parentSectionPath(sec);
1114
- const isRootLevel = parent === "" || (!sectionPaths.has(parent) && nearestExistingAncestor(sec, sectionPaths) === "");
1115
- // Skip depth-0 sections already adopted by the root section wrapper (B),
1116
- // but NOT structural types with sec="" (skip-slug). buildSectionTree
1117
- // filters out sec="" segments (line 1249), so they wouldn't be adopted
1118
- // and must be emitted here directly.
1119
- if (isRootLevel && hasRootSection && sec !== "") {
1320
+ const isRootLevel = depth === 0 ||
1321
+ parent === "" ||
1322
+ (!sectionPaths.has(parent) && nearestExistingAncestor(sec, sectionPaths) === "");
1323
+ // Skip sections already adopted by the root section wrapper (B).
1324
+ // Sections with sidebarDepth===0 are true V1 root peers that
1325
+ // buildSectionTree now excludes — they must NOT be skipped.
1326
+ // Sections with sidebarDepth>0 are nested children that SHOULD
1327
+ // be adopted, so they must be skipped to avoid duplication.
1328
+ // Sections without sidebarDepth (old data) are also skipped —
1329
+ // they rely on path-based hierarchy in buildSectionTree.
1330
+ if (isRootLevel && hasRootSection && sec !== "" && depth !== 0) {
1120
1331
  continue;
1121
1332
  }
1122
1333
  if (isRootLevel) {
@@ -1134,7 +1345,20 @@ function buildSidebarRootChildren(ctx, scopeSegs, scopePrefix, changelogScopePre
1134
1345
  const ownedSegs = bounds != null
1135
1346
  ? scopeSegs.filter((seg) => seg.seg.sortOrder >= bounds.lo && seg.seg.sortOrder < bounds.hi)
1136
1347
  : scopeSegs;
1137
- node = sectionNode(ctx, s, buildSectionTree(ctx, ownedSegs, sec, scopePrefix, changelogScopePrefix), scopePrefix);
1348
+ // A section with sec="" that reaches here (not adopted as a
1349
+ // root wrapper in case B) is a skipUrlSlug sibling.
1350
+ // When sortOrder boundaries exist (multiple sec="" sections),
1351
+ // the scoped ownedSegs correctly limits which subsections
1352
+ // each section can adopt. When there are NO boundaries
1353
+ // (single sec="" section, e.g. mangopay's "Introduction"),
1354
+ // buildSectionTree("") would re-adopt all depth-0 peers;
1355
+ // pass an empty child list instead — its leaf artifacts are
1356
+ // already in its own segment nav.
1357
+ const isUnboundedSkipSlugSibling = sec === "" && metaNum(s.seg.metadata, "childIndex") != null && bounds == null;
1358
+ const sectionChildren = isUnboundedSkipSlugSibling
1359
+ ? []
1360
+ : buildSectionTree(ctx, ownedSegs, sec, scopePrefix, changelogScopePrefix);
1361
+ node = sectionNode(ctx, s, sectionChildren, scopePrefix);
1138
1362
  }
1139
1363
  // Shared/merged sections (paths not rooted in scopePrefix) must not
1140
1364
  // carry childIndex — their source-version positions would sort them
@@ -1204,11 +1428,6 @@ function groupSidebarRootChildren(ctx, children) {
1204
1428
  flushRun();
1205
1429
  out.push(child);
1206
1430
  }
1207
- else if (child.type === "changelog") {
1208
- flushRun();
1209
- run.push(child);
1210
- flushRun();
1211
- }
1212
1431
  else {
1213
1432
  run.push(child);
1214
1433
  }
@@ -1375,7 +1594,7 @@ function buildVariantedNode(ctx, variants, scopeSegs, scopePrefix) {
1375
1594
  ? asSlug(FernNavigation.slugjoin(scopePrefix, variantIndividualSlug))
1376
1595
  : scopePrefix;
1377
1596
  const metaPointsTo = metaStr(variant.metadata, "pointsTo");
1378
- const children = buildSidebarRootChildren(ctx, variantSegs, scopePrefix);
1597
+ const children = buildSidebarRootChildren(ctx, variantSegs, variantSlug);
1379
1598
  return {
1380
1599
  type: "variant",
1381
1600
  ...withMetadataDefaults({
@@ -1911,6 +2130,14 @@ function buildProductGroup(ctx, products, scoped, rootSlug, skipSharedSectionMer
1911
2130
  };
1912
2131
  return node;
1913
2132
  });
2133
+ // Cross-product canonical slug deduplication (V2 parity).
2134
+ // V2's migrator deduplicates pages across products via a global pageId map:
2135
+ // the first product to register a pageId wins, and subsequent products'
2136
+ // pages with the same pageId receive a canonicalSlug pointing to the
2137
+ // canonical (default-product) page. Without this, shared content that is
2138
+ // materialized under every product scope (e.g. merge-api-basics pages)
2139
+ // appears as separate sitemap entries per product.
2140
+ markCrossProductCanonicalSlugs(children);
1914
2141
  return {
1915
2142
  type: "productgroup",
1916
2143
  id: ctx.nodeId("productgroup"),
@@ -1919,5 +2146,43 @@ function buildProductGroup(ctx, products, scoped, rootSlug, skipSharedSectionMer
1919
2146
  children
1920
2147
  };
1921
2148
  }
2149
+ /**
2150
+ * Deduplicate pages across products using pageId as a content-identity key.
2151
+ * Pages with the same pageId in different products are the same content
2152
+ * materialized per-scope; the default product's slug becomes canonical and
2153
+ * non-default copies receive `canonicalSlug` so the sitemap collapses them.
2154
+ *
2155
+ * API leaf nodes (endpoints, websockets, etc.) are unaffected — `getPageId`
2156
+ * returns undefined for those types, so product-specific API surface is
2157
+ * never suppressed.
2158
+ */
2159
+ function markCrossProductCanonicalSlugs(productNodes) {
2160
+ const pageIdToCanonical = new Map();
2161
+ // Process default product first so its slugs become the canonical targets.
2162
+ const sorted = [...productNodes].sort((a, b) => {
2163
+ if (a.default !== b.default) {
2164
+ return a.default ? -1 : 1;
2165
+ }
2166
+ return 0;
2167
+ });
2168
+ for (const product of sorted) {
2169
+ FernNavigation.traverseDF(product, (child) => {
2170
+ if (FernNavigation.hasMetadata(child) && FernNavigation.isPage(child)) {
2171
+ const pid = FernNavigation.getPageId(child);
2172
+ if (pid == null) {
2173
+ return;
2174
+ }
2175
+ const key = `pid:${pid}`;
2176
+ const canonical = pageIdToCanonical.get(key);
2177
+ if (canonical != null && !product.default) {
2178
+ child.canonicalSlug = canonical;
2179
+ }
2180
+ else if (canonical == null) {
2181
+ pageIdToCanonical.set(key, child.canonicalSlug ?? child.slug);
2182
+ }
2183
+ }
2184
+ });
2185
+ }
2186
+ }
1922
2187
  // (root keeps the bare "root" id; it is the single tree root.)
1923
2188
  //# sourceMappingURL=ledger-root-builder.js.map