@fern-api/fdr-sdk 1.2.23-c9e3b5b30f → 1.2.23-f333a93cab

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.
@@ -707,6 +707,25 @@ function toViewers(viewers) {
707
707
  }
708
708
  return viewers.map((v) => RoleId(v));
709
709
  }
710
+ function mergeVariantViewers(seg) {
711
+ const segViewers = metaStrArr(seg.metadata, "viewers");
712
+ const variantViewers = seg.variant?.viewers;
713
+ if ((segViewers == null || segViewers.length === 0) && (variantViewers == null || variantViewers.length === 0)) {
714
+ return void 0;
715
+ }
716
+ const merged = /* @__PURE__ */ new Set();
717
+ if (segViewers != null) {
718
+ for (const v of segViewers) {
719
+ merged.add(v);
720
+ }
721
+ }
722
+ if (variantViewers != null) {
723
+ for (const v of variantViewers) {
724
+ merged.add(v);
725
+ }
726
+ }
727
+ return merged.size > 0 ? [...merged].map((v) => RoleId(v)) : void 0;
728
+ }
710
729
  function detailSlug(detail) {
711
730
  return metaStr(detail.metadata, "slug") ?? "";
712
731
  }
@@ -904,7 +923,7 @@ function sectionNode(ctx, scoped, sectionChildren) {
904
923
  slug,
905
924
  icon: metaStr(seg.metadata, "icon"),
906
925
  hidden: seg.hidden,
907
- viewers: toViewers(metaStrArr(seg.metadata, "viewers"))
926
+ viewers: mergeVariantViewers(seg)
908
927
  });
909
928
  return {
910
929
  type: "section",
@@ -919,23 +938,108 @@ function sectionNode(ctx, scoped, sectionChildren) {
919
938
  children: [...leafChildren, ...sectionChildren]
920
939
  };
921
940
  }
922
- function collectDescendantApiNav(root, scopeSegs) {
923
- const rootSection = root.seg.section;
924
- const prefix = rootSection === "" ? "" : `${rootSection}/`;
925
- const routes = [...root.nav];
926
- for (const s of scopeSegs) {
927
- if (s === root) {
941
+ function directChildApiPackages(parentSection, scopeSegs) {
942
+ const sectionPaths = new Set(scopeSegs.map((s) => s.seg.section));
943
+ return scopeSegs.filter((s) => {
944
+ if (metaStr(s.seg.metadata, "type") !== "apiPackage") {
945
+ return false;
946
+ }
947
+ const parent = parentSectionPath(s.seg.section);
948
+ if (parent === parentSection) {
949
+ return true;
950
+ }
951
+ if (!sectionPaths.has(parent)) {
952
+ return nearestExistingAncestor(s.seg.section, sectionPaths) === parentSection;
953
+ }
954
+ return false;
955
+ }).sort((a, b) => a.seg.sortOrder - b.seg.sortOrder);
956
+ }
957
+ function buildApiChildren(ctx, scoped, scopeSegs, apiDefinitionId) {
958
+ const { seg, nav } = scoped;
959
+ const rawLeafNodes = nav.map((route) => apiLeafNodeFromNavRouteInternal(ctx, route, apiDefinitionId)).filter((node) => node != null);
960
+ const leafNodes = mergeEndpointPairs(ctx, rawLeafNodes, nav);
961
+ const childPackages = directChildApiPackages(seg.section, scopeSegs);
962
+ const packageNodes = childPackages.map(
963
+ (child) => apiPackageChildNode(ctx, child, scopeSegs, apiDefinitionId)
964
+ );
965
+ return [...leafNodes, ...packageNodes];
966
+ }
967
+ function apiPackageChildNode(ctx, scoped, scopeSegs, parentApiDefinitionId) {
968
+ const { seg, nav } = scoped;
969
+ const overview = overviewRoute(nav);
970
+ const overviewPageId = overview != null ? metaStr(overview.metadata, "pageId") : void 0;
971
+ const apiDefinitionId = metaStr(seg.metadata, "apiDefinitionId") ?? parentApiDefinitionId;
972
+ const slug = ctx.contentSlug(overview?.fullPath ?? nav[0]?.fullPath ?? seg.section);
973
+ const children = buildApiChildren(ctx, scoped, scopeSegs, apiDefinitionId);
974
+ return {
975
+ type: "apiPackage",
976
+ ...withMetadataDefaults({
977
+ id: ctx.nodeId(`api-pkg:${slug}`),
978
+ title: metaStr(seg.metadata, "title") ?? "",
979
+ slug,
980
+ icon: metaStr(seg.metadata, "icon"),
981
+ hidden: seg.hidden,
982
+ viewers: toViewers(metaStrArr(seg.metadata, "viewers"))
983
+ }),
984
+ apiDefinitionId: ApiDefinitionId(apiDefinitionId),
985
+ availability: metaStr(seg.metadata, "availability"),
986
+ overviewPageId: overviewPageId != null ? PageId(overviewPageId) : void 0,
987
+ noindex: void 0,
988
+ pointsTo: void 0,
989
+ children,
990
+ playground: void 0
991
+ };
992
+ }
993
+ function mergeEndpointPairs(ctx, leafNodes, allNav) {
994
+ const endpointIdToPairKey = /* @__PURE__ */ new Map();
995
+ for (const route of allNav) {
996
+ if (route.type !== "rest") {
928
997
  continue;
929
998
  }
930
- const type = metaStr(s.seg.metadata, "type");
931
- if (type !== "apiPackage") {
999
+ const pairKey = metaStr(route.metadata, "endpointPairKey");
1000
+ const endpointId = metaStr(route.metadata, "endpointId");
1001
+ if (pairKey != null && endpointId != null) {
1002
+ endpointIdToPairKey.set(endpointId, pairKey);
1003
+ }
1004
+ }
1005
+ if (endpointIdToPairKey.size === 0) {
1006
+ return leafNodes;
1007
+ }
1008
+ const result = [];
1009
+ const mergedPairKeys = /* @__PURE__ */ new Map();
1010
+ for (const node of leafNodes) {
1011
+ if (node.type !== "endpoint") {
1012
+ result.push(node);
1013
+ continue;
1014
+ }
1015
+ const pairKey = endpointIdToPairKey.get(String(node.endpointId));
1016
+ if (pairKey == null) {
1017
+ result.push(node);
932
1018
  continue;
933
1019
  }
934
- if (s.seg.section === rootSection || s.seg.section.startsWith(prefix)) {
935
- routes.push(...s.nav);
1020
+ const existingIdx = mergedPairKeys.get(pairKey);
1021
+ if (existingIdx == null) {
1022
+ mergedPairKeys.set(pairKey, result.length);
1023
+ result.push(node);
1024
+ } else {
1025
+ const first = result[existingIdx];
1026
+ if (first == null || first.type !== "endpoint") {
1027
+ result.push(node);
1028
+ continue;
1029
+ }
1030
+ const stream = node.isResponseStream ? node : first;
1031
+ const nonStream = node.isResponseStream ? first : node;
1032
+ const pairNode = {
1033
+ id: ctx.nodeId(`endpoint-pair:${pairKey}`),
1034
+ type: "endpointPair",
1035
+ collapsed: void 0,
1036
+ stream,
1037
+ nonStream
1038
+ };
1039
+ result[existingIdx] = pairNode;
936
1040
  }
937
1041
  }
938
- return routes;
1042
+ return result;
939
1043
  }
940
1044
  function apiReferenceNode(ctx, scoped, scopeSegs) {
941
1045
  const { seg, nav } = scoped;
@@ -943,8 +1047,7 @@ function apiReferenceNode(ctx, scoped, scopeSegs) {
943
1047
  const overviewPageId = overview != null ? metaStr(overview.metadata, "pageId") : void 0;
944
1048
  const apiDefinitionId = metaStr(seg.metadata, "apiDefinitionId") ?? "";
945
1049
  const slug = ctx.contentSlug(overview?.fullPath ?? nav[0]?.fullPath ?? seg.section);
946
- const allNav = collectDescendantApiNav(scoped, scopeSegs);
947
- const children = allNav.map((route) => apiLeafNodeFromNavRouteInternal(ctx, route, apiDefinitionId)).filter((node) => node != null);
1050
+ const children = buildApiChildren(ctx, scoped, scopeSegs, apiDefinitionId);
948
1051
  return {
949
1052
  type: "apiReference",
950
1053
  ...withMetadataDefaults({
@@ -953,7 +1056,7 @@ function apiReferenceNode(ctx, scoped, scopeSegs) {
953
1056
  slug,
954
1057
  icon: metaStr(seg.metadata, "icon"),
955
1058
  hidden: seg.hidden,
956
- viewers: toViewers(metaStrArr(seg.metadata, "viewers"))
1059
+ viewers: mergeVariantViewers(seg)
957
1060
  }),
958
1061
  apiDefinitionId: ApiDefinitionId(apiDefinitionId),
959
1062
  availability: void 0,
@@ -1036,7 +1139,7 @@ function changelogNode(ctx, scoped) {
1036
1139
  slug: baseSlug,
1037
1140
  icon: metaStr(seg.metadata, "icon"),
1038
1141
  hidden: seg.hidden,
1039
- viewers: toViewers(metaStrArr(seg.metadata, "viewers"))
1142
+ viewers: mergeVariantViewers(seg)
1040
1143
  }),
1041
1144
  overviewPageId: overviewPageId != null ? PageId(overviewPageId) : void 0,
1042
1145
  noindex: void 0,