@fern-api/fdr-sdk 0.139.5-7b3614b4c → 0.139.5-974930089
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.
|
@@ -435,4 +435,308 @@ describe("pruneNavigationTree", () => {
|
|
|
435
435
|
pointsTo: "root/page",
|
|
436
436
|
});
|
|
437
437
|
});
|
|
438
|
+
it("should handle versioned root with landing pages and no pointsTo field", () => {
|
|
439
|
+
const root = {
|
|
440
|
+
type: "root",
|
|
441
|
+
id: FernNavigation.NodeId("root"),
|
|
442
|
+
slug: FernNavigation.Slug(""),
|
|
443
|
+
title: "Root",
|
|
444
|
+
version: "v2",
|
|
445
|
+
roles: undefined,
|
|
446
|
+
child: {
|
|
447
|
+
type: "versioned",
|
|
448
|
+
id: FernNavigation.NodeId("versioned"),
|
|
449
|
+
children: [
|
|
450
|
+
{
|
|
451
|
+
type: "version",
|
|
452
|
+
id: FernNavigation.NodeId("v1"),
|
|
453
|
+
slug: FernNavigation.Slug("v1"),
|
|
454
|
+
title: "Version 1",
|
|
455
|
+
default: false,
|
|
456
|
+
versionId: FernNavigation.VersionId("v1"),
|
|
457
|
+
landingPage: {
|
|
458
|
+
type: "landingPage",
|
|
459
|
+
id: FernNavigation.NodeId("v1-landing"),
|
|
460
|
+
slug: FernNavigation.Slug("v1/welcome"),
|
|
461
|
+
title: "V1 Landing",
|
|
462
|
+
pageId: FernNavigation.PageId("index.mdx"),
|
|
463
|
+
canonicalSlug: FernNavigation.Slug("welcome"),
|
|
464
|
+
icon: undefined,
|
|
465
|
+
hidden: undefined,
|
|
466
|
+
authed: undefined,
|
|
467
|
+
noindex: undefined,
|
|
468
|
+
viewers: undefined,
|
|
469
|
+
orphaned: undefined,
|
|
470
|
+
featureFlags: undefined,
|
|
471
|
+
},
|
|
472
|
+
child: {
|
|
473
|
+
type: "sidebarRoot",
|
|
474
|
+
id: FernNavigation.NodeId("v1-sidebar"),
|
|
475
|
+
children: [
|
|
476
|
+
{
|
|
477
|
+
type: "section",
|
|
478
|
+
id: FernNavigation.NodeId("v1-section"),
|
|
479
|
+
slug: FernNavigation.Slug("v1"),
|
|
480
|
+
title: "V1 Section",
|
|
481
|
+
overviewPageId: undefined,
|
|
482
|
+
children: [
|
|
483
|
+
{
|
|
484
|
+
type: "page",
|
|
485
|
+
id: FernNavigation.NodeId("v1-page"),
|
|
486
|
+
slug: FernNavigation.Slug("v1/page"),
|
|
487
|
+
title: "V1 Page",
|
|
488
|
+
pageId: FernNavigation.PageId("v1-page.mdx"),
|
|
489
|
+
canonicalSlug: undefined,
|
|
490
|
+
icon: undefined,
|
|
491
|
+
hidden: undefined,
|
|
492
|
+
authed: undefined,
|
|
493
|
+
noindex: undefined,
|
|
494
|
+
viewers: undefined,
|
|
495
|
+
orphaned: undefined,
|
|
496
|
+
featureFlags: undefined,
|
|
497
|
+
},
|
|
498
|
+
],
|
|
499
|
+
collapsed: undefined,
|
|
500
|
+
canonicalSlug: undefined,
|
|
501
|
+
icon: undefined,
|
|
502
|
+
hidden: undefined,
|
|
503
|
+
authed: undefined,
|
|
504
|
+
noindex: undefined,
|
|
505
|
+
pointsTo: undefined, // no pointsTo field
|
|
506
|
+
viewers: undefined,
|
|
507
|
+
orphaned: undefined,
|
|
508
|
+
featureFlags: undefined,
|
|
509
|
+
},
|
|
510
|
+
],
|
|
511
|
+
},
|
|
512
|
+
availability: undefined,
|
|
513
|
+
canonicalSlug: undefined,
|
|
514
|
+
icon: undefined,
|
|
515
|
+
hidden: undefined,
|
|
516
|
+
authed: undefined,
|
|
517
|
+
pointsTo: undefined, // no pointsTo field
|
|
518
|
+
viewers: undefined,
|
|
519
|
+
orphaned: undefined,
|
|
520
|
+
featureFlags: undefined,
|
|
521
|
+
},
|
|
522
|
+
{
|
|
523
|
+
type: "version",
|
|
524
|
+
id: FernNavigation.NodeId("v2"),
|
|
525
|
+
slug: FernNavigation.Slug("v2"),
|
|
526
|
+
title: "Version 2",
|
|
527
|
+
default: true,
|
|
528
|
+
versionId: FernNavigation.VersionId("v2"),
|
|
529
|
+
landingPage: {
|
|
530
|
+
type: "landingPage",
|
|
531
|
+
id: FernNavigation.NodeId("v2-landing"),
|
|
532
|
+
slug: FernNavigation.Slug("v2/welcome"),
|
|
533
|
+
title: "V2 Landing",
|
|
534
|
+
pageId: FernNavigation.PageId("index.mdx"),
|
|
535
|
+
canonicalSlug: FernNavigation.Slug("welcome"),
|
|
536
|
+
icon: undefined,
|
|
537
|
+
hidden: undefined,
|
|
538
|
+
authed: undefined,
|
|
539
|
+
noindex: undefined,
|
|
540
|
+
viewers: undefined,
|
|
541
|
+
orphaned: undefined,
|
|
542
|
+
featureFlags: undefined,
|
|
543
|
+
},
|
|
544
|
+
child: {
|
|
545
|
+
type: "sidebarRoot",
|
|
546
|
+
id: FernNavigation.NodeId("v2-sidebar"),
|
|
547
|
+
children: [
|
|
548
|
+
{
|
|
549
|
+
type: "section",
|
|
550
|
+
id: FernNavigation.NodeId("v2-section"),
|
|
551
|
+
slug: FernNavigation.Slug("welcome"),
|
|
552
|
+
title: "V2 Section",
|
|
553
|
+
overviewPageId: undefined,
|
|
554
|
+
children: [
|
|
555
|
+
{
|
|
556
|
+
type: "page",
|
|
557
|
+
id: FernNavigation.NodeId("v2-page"),
|
|
558
|
+
slug: FernNavigation.Slug("page"),
|
|
559
|
+
title: "V2 Page",
|
|
560
|
+
pageId: FernNavigation.PageId("v2-page.mdx"),
|
|
561
|
+
canonicalSlug: undefined,
|
|
562
|
+
icon: undefined,
|
|
563
|
+
hidden: undefined,
|
|
564
|
+
authed: undefined,
|
|
565
|
+
noindex: undefined,
|
|
566
|
+
viewers: undefined,
|
|
567
|
+
orphaned: undefined,
|
|
568
|
+
featureFlags: undefined,
|
|
569
|
+
},
|
|
570
|
+
],
|
|
571
|
+
collapsed: undefined,
|
|
572
|
+
canonicalSlug: undefined,
|
|
573
|
+
icon: undefined,
|
|
574
|
+
hidden: undefined,
|
|
575
|
+
authed: undefined,
|
|
576
|
+
noindex: undefined,
|
|
577
|
+
pointsTo: undefined, // no pointsTo field
|
|
578
|
+
viewers: undefined,
|
|
579
|
+
orphaned: undefined,
|
|
580
|
+
featureFlags: undefined,
|
|
581
|
+
},
|
|
582
|
+
],
|
|
583
|
+
},
|
|
584
|
+
availability: undefined,
|
|
585
|
+
canonicalSlug: undefined,
|
|
586
|
+
icon: undefined,
|
|
587
|
+
hidden: undefined,
|
|
588
|
+
authed: undefined,
|
|
589
|
+
pointsTo: undefined, // no pointsTo field
|
|
590
|
+
viewers: undefined,
|
|
591
|
+
orphaned: undefined,
|
|
592
|
+
featureFlags: undefined,
|
|
593
|
+
},
|
|
594
|
+
],
|
|
595
|
+
},
|
|
596
|
+
canonicalSlug: undefined,
|
|
597
|
+
icon: undefined,
|
|
598
|
+
hidden: undefined,
|
|
599
|
+
authed: undefined,
|
|
600
|
+
pointsTo: undefined, // no pointsTo field
|
|
601
|
+
viewers: undefined,
|
|
602
|
+
orphaned: undefined,
|
|
603
|
+
featureFlags: undefined,
|
|
604
|
+
};
|
|
605
|
+
const result = Pruner.from(root)
|
|
606
|
+
.keep((node) => node.id !== "v1-page")
|
|
607
|
+
.get();
|
|
608
|
+
// structuredClone should duplicate the object
|
|
609
|
+
expect(result === root).toBe(false);
|
|
610
|
+
expect(result).toStrictEqual({
|
|
611
|
+
type: "root",
|
|
612
|
+
id: FernNavigation.NodeId("root"),
|
|
613
|
+
slug: FernNavigation.Slug(""),
|
|
614
|
+
title: "Root",
|
|
615
|
+
version: "v2",
|
|
616
|
+
roles: undefined,
|
|
617
|
+
child: {
|
|
618
|
+
type: "versioned",
|
|
619
|
+
id: FernNavigation.NodeId("versioned"),
|
|
620
|
+
children: [
|
|
621
|
+
{
|
|
622
|
+
type: "version",
|
|
623
|
+
id: FernNavigation.NodeId("v1"),
|
|
624
|
+
slug: FernNavigation.Slug("v1"),
|
|
625
|
+
title: "Version 1",
|
|
626
|
+
default: false,
|
|
627
|
+
versionId: FernNavigation.VersionId("v1"),
|
|
628
|
+
landingPage: {
|
|
629
|
+
type: "landingPage",
|
|
630
|
+
id: FernNavigation.NodeId("v1-landing"),
|
|
631
|
+
slug: FernNavigation.Slug("v1/welcome"),
|
|
632
|
+
title: "V1 Landing",
|
|
633
|
+
pageId: FernNavigation.PageId("index.mdx"),
|
|
634
|
+
canonicalSlug: FernNavigation.Slug("welcome"),
|
|
635
|
+
icon: undefined,
|
|
636
|
+
hidden: undefined,
|
|
637
|
+
authed: undefined,
|
|
638
|
+
noindex: undefined,
|
|
639
|
+
viewers: undefined,
|
|
640
|
+
orphaned: undefined,
|
|
641
|
+
featureFlags: undefined,
|
|
642
|
+
},
|
|
643
|
+
child: {
|
|
644
|
+
type: "sidebarRoot",
|
|
645
|
+
id: FernNavigation.NodeId("v1-sidebar"),
|
|
646
|
+
children: [],
|
|
647
|
+
},
|
|
648
|
+
availability: undefined,
|
|
649
|
+
canonicalSlug: undefined,
|
|
650
|
+
icon: undefined,
|
|
651
|
+
hidden: undefined,
|
|
652
|
+
authed: undefined,
|
|
653
|
+
pointsTo: "v1/welcome",
|
|
654
|
+
viewers: undefined,
|
|
655
|
+
orphaned: undefined,
|
|
656
|
+
featureFlags: undefined,
|
|
657
|
+
},
|
|
658
|
+
{
|
|
659
|
+
type: "version",
|
|
660
|
+
id: FernNavigation.NodeId("v2"),
|
|
661
|
+
slug: FernNavigation.Slug("v2"),
|
|
662
|
+
title: "Version 2",
|
|
663
|
+
default: true,
|
|
664
|
+
versionId: FernNavigation.VersionId("v2"),
|
|
665
|
+
landingPage: {
|
|
666
|
+
type: "landingPage",
|
|
667
|
+
id: FernNavigation.NodeId("v2-landing"),
|
|
668
|
+
slug: FernNavigation.Slug("v2/welcome"),
|
|
669
|
+
title: "V2 Landing",
|
|
670
|
+
pageId: FernNavigation.PageId("index.mdx"),
|
|
671
|
+
canonicalSlug: FernNavigation.Slug("welcome"),
|
|
672
|
+
icon: undefined,
|
|
673
|
+
hidden: undefined,
|
|
674
|
+
authed: undefined,
|
|
675
|
+
noindex: undefined,
|
|
676
|
+
viewers: undefined,
|
|
677
|
+
orphaned: undefined,
|
|
678
|
+
featureFlags: undefined,
|
|
679
|
+
},
|
|
680
|
+
child: {
|
|
681
|
+
type: "sidebarRoot",
|
|
682
|
+
id: FernNavigation.NodeId("v2-sidebar"),
|
|
683
|
+
children: [
|
|
684
|
+
{
|
|
685
|
+
type: "section",
|
|
686
|
+
id: FernNavigation.NodeId("v2-section"),
|
|
687
|
+
slug: FernNavigation.Slug("welcome"),
|
|
688
|
+
title: "V2 Section",
|
|
689
|
+
overviewPageId: undefined,
|
|
690
|
+
children: [
|
|
691
|
+
{
|
|
692
|
+
type: "page",
|
|
693
|
+
id: FernNavigation.NodeId("v2-page"),
|
|
694
|
+
slug: FernNavigation.Slug("page"),
|
|
695
|
+
title: "V2 Page",
|
|
696
|
+
pageId: FernNavigation.PageId("v2-page.mdx"),
|
|
697
|
+
canonicalSlug: undefined,
|
|
698
|
+
icon: undefined,
|
|
699
|
+
hidden: undefined,
|
|
700
|
+
authed: undefined,
|
|
701
|
+
noindex: undefined,
|
|
702
|
+
viewers: undefined,
|
|
703
|
+
orphaned: undefined,
|
|
704
|
+
featureFlags: undefined,
|
|
705
|
+
},
|
|
706
|
+
],
|
|
707
|
+
collapsed: undefined,
|
|
708
|
+
canonicalSlug: undefined,
|
|
709
|
+
icon: undefined,
|
|
710
|
+
hidden: undefined,
|
|
711
|
+
authed: undefined,
|
|
712
|
+
noindex: undefined,
|
|
713
|
+
pointsTo: "page",
|
|
714
|
+
viewers: undefined,
|
|
715
|
+
orphaned: undefined,
|
|
716
|
+
featureFlags: undefined,
|
|
717
|
+
},
|
|
718
|
+
],
|
|
719
|
+
},
|
|
720
|
+
availability: undefined,
|
|
721
|
+
canonicalSlug: undefined,
|
|
722
|
+
icon: undefined,
|
|
723
|
+
hidden: undefined,
|
|
724
|
+
authed: undefined,
|
|
725
|
+
pointsTo: "v2/welcome",
|
|
726
|
+
viewers: undefined,
|
|
727
|
+
orphaned: undefined,
|
|
728
|
+
featureFlags: undefined,
|
|
729
|
+
},
|
|
730
|
+
],
|
|
731
|
+
},
|
|
732
|
+
canonicalSlug: undefined,
|
|
733
|
+
icon: undefined,
|
|
734
|
+
hidden: undefined,
|
|
735
|
+
authed: undefined,
|
|
736
|
+
pointsTo: "welcome", // unversioned pointsTo field
|
|
737
|
+
viewers: undefined,
|
|
738
|
+
orphaned: undefined,
|
|
739
|
+
featureFlags: undefined,
|
|
740
|
+
});
|
|
741
|
+
});
|
|
438
742
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updatePointsTo.d.ts","sourceRoot":"","sources":["../../../src/navigation/utils/updatePointsTo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"updatePointsTo.d.ts","sourceRoot":"","sources":["../../../src/navigation/utils/updatePointsTo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAIvC;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,cAAc,CAAC,cAAc,GACnC,IAAI,CAwBN"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FernNavigation } from "../..";
|
|
2
|
+
import { NodeCollector } from "../NodeCollector";
|
|
2
3
|
import { followRedirect } from "./followRedirect";
|
|
3
4
|
/**
|
|
4
5
|
* Uses depth-first traversal to update the pointsTo property of all nodes in the tree.
|
|
@@ -6,10 +7,28 @@ import { followRedirect } from "./followRedirect";
|
|
|
6
7
|
* @param input will be mutated
|
|
7
8
|
*/
|
|
8
9
|
export function mutableUpdatePointsTo(input) {
|
|
10
|
+
const collector = NodeCollector.collect(input);
|
|
11
|
+
const slugMap = collector.getSlugMapWithParents();
|
|
9
12
|
FernNavigation.traverseDF(input, (node) => {
|
|
10
13
|
if (FernNavigation.hasPointsTo(node)) {
|
|
11
14
|
const pointsTo = followRedirect(node);
|
|
12
|
-
|
|
15
|
+
if (pointsTo != null) {
|
|
16
|
+
if (node.type === "root") {
|
|
17
|
+
const targetNode = slugMap.get(pointsTo)?.node;
|
|
18
|
+
// if the node we should redirect to has a canonical url, default to that
|
|
19
|
+
if (targetNode != null) {
|
|
20
|
+
node.pointsTo =
|
|
21
|
+
targetNode.canonicalSlug ??
|
|
22
|
+
(node.slug === targetNode.slug ? undefined : targetNode.slug);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
node.pointsTo = node.slug === pointsTo ? undefined : pointsTo;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
node.pointsTo = undefined;
|
|
31
|
+
}
|
|
13
32
|
}
|
|
14
33
|
});
|
|
15
34
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fern-api/fdr-sdk",
|
|
3
|
-
"version": "0.139.5-
|
|
3
|
+
"version": "0.139.5-974930089",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"test:update": "vitest --run --passWithNoTests --globals -u"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@fern-api/ui-core-utils": "0.139.5-
|
|
52
|
+
"@fern-api/ui-core-utils": "0.139.5-974930089*",
|
|
53
53
|
"@ungap/structured-clone": "^1.2.0",
|
|
54
54
|
"dayjs": "^1.11.11",
|
|
55
55
|
"es-toolkit": "^1.32.0",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"@babel/core": "^7.26.9",
|
|
69
69
|
"@babel/preset-env": "^7.26.0",
|
|
70
70
|
"@babel/preset-typescript": "^7.26.0",
|
|
71
|
-
"@fern-platform/configs": "0.139.5-
|
|
71
|
+
"@fern-platform/configs": "0.139.5-974930089*",
|
|
72
72
|
"@types/node-fetch": "2.6.9",
|
|
73
73
|
"@types/qs": "6.9.14",
|
|
74
74
|
"@types/tinycolor2": "^1.4.6",
|