@financial-times/content-curation-client 5.4.0 → 6.1.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.js CHANGED
@@ -523,51 +523,132 @@ function trimTrailingSlashes(value) {
523
523
  return end === value.length ? value : value.slice(0, end);
524
524
  }
525
525
 
526
+ // src/schemas/ftpink/legacyHubPage/index.ts
527
+ import { z as z2 } from "zod";
528
+ var LegacyFlourishChildSchema = z2.object({
529
+ source: z2.literal("flourish"),
530
+ properties: z2.object({
531
+ id: z2.string().min(1)
532
+ // e.g. "visualisation/21901162"
533
+ })
534
+ });
535
+ var LegacyListChildSchema = z2.object({
536
+ source: z2.literal("list"),
537
+ properties: z2.object({
538
+ id: z2.string().uuid(),
539
+ maxItems: z2.number().optional()
540
+ })
541
+ });
542
+ var LegacyContentChildSchema = z2.object({
543
+ source: z2.literal("content"),
544
+ properties: z2.object({
545
+ ids: z2.array(z2.string()).nonempty()
546
+ })
547
+ });
548
+ var LegacyContainerChildSchema = z2.discriminatedUnion("source", [
549
+ LegacyFlourishChildSchema,
550
+ LegacyListChildSchema,
551
+ LegacyContentChildSchema
552
+ ]);
553
+ var LegacyTopperSchema = z2.object({
554
+ type: z2.literal("topper-basic"),
555
+ properties: z2.object({
556
+ title: z2.string(),
557
+ sponsorText: z2.string().optional(),
558
+ sponsorImage: z2.string().url().optional()
559
+ })
560
+ });
561
+ var LegacyInfoBoxSchema = z2.object({
562
+ type: z2.literal("info-box"),
563
+ properties: z2.object({
564
+ bodyHTML: z2.string(),
565
+ title: z2.string().optional()
566
+ })
567
+ });
568
+ var LegacyContainerSchema = z2.object({
569
+ type: z2.literal("container"),
570
+ children: z2.array(LegacyContainerChildSchema).min(1),
571
+ properties: z2.object({
572
+ title: z2.string().optional(),
573
+ design: z2.enum(["chart", "four-story", "freeform", "hero-lead"]).default("freeform"),
574
+ backgroundColor: z2.string().optional()
575
+ })
576
+ });
577
+ var LegacyExperimentSchema = z2.object({
578
+ type: z2.literal("experiment"),
579
+ children: z2.tuple([]),
580
+ properties: z2.object({
581
+ experimentName: z2.string(),
582
+ id: z2.string(),
583
+ title: z2.string().optional(),
584
+ config: z2.object({
585
+ value: z2.unknown().optional(),
586
+ // Hub pages support experiments with HTML and Text.
587
+ // For now we just support JSON. As we migrate pages, this may change.
588
+ format: z2.enum(["json"]).default("json")
589
+ }).partial().optional()
590
+ })
591
+ });
592
+ var LegacyBlockSchema = z2.discriminatedUnion("type", [
593
+ LegacyTopperSchema,
594
+ LegacyInfoBoxSchema,
595
+ LegacyContainerSchema,
596
+ LegacyExperimentSchema
597
+ ]);
598
+ var LegacyPageStructureOutputSchema = z2.object({
599
+ uuid: z2.string().uuid(),
600
+ title: z2.string(),
601
+ conceptId: z2.string().uuid().optional(),
602
+ themeName: z2.string().optional(),
603
+ metaDescription: z2.string().optional(),
604
+ blocks: z2.array(LegacyBlockSchema)
605
+ });
606
+
526
607
  // src/schemas/ftpink/page/index.ts
527
- import { z as z3 } from "zod";
608
+ import { z as z4 } from "zod";
528
609
 
529
610
  // src/schemas/prosemirror.ts
530
- import { z as z2 } from "zod";
531
- var HrefSchema = z2.string().refine((v) => /^(https?:\/\/|mailto:).+/.test(v), {
611
+ import { z as z3 } from "zod";
612
+ var HrefSchema = z3.string().refine((v) => /^(https?:\/\/|mailto:).+/.test(v), {
532
613
  message: "Expected http(s):// or mailto: URL"
533
614
  });
534
- var ProseMirrorLinkMark = z2.object({
535
- type: z2.literal("link"),
536
- attrs: z2.object({
615
+ var ProseMirrorLinkMark = z3.object({
616
+ type: z3.literal("link"),
617
+ attrs: z3.object({
537
618
  href: HrefSchema
538
619
  })
539
620
  });
540
- var ProseMirrorMark = z2.discriminatedUnion("type", [
621
+ var ProseMirrorMark = z3.discriminatedUnion("type", [
541
622
  ProseMirrorLinkMark,
542
- z2.object({ type: z2.literal("bold") }),
543
- z2.object({ type: z2.literal("italic") }),
544
- z2.object({ type: z2.literal("underline") }),
545
- z2.object({ type: z2.literal("strike") })
623
+ z3.object({ type: z3.literal("bold") }),
624
+ z3.object({ type: z3.literal("italic") }),
625
+ z3.object({ type: z3.literal("underline") }),
626
+ z3.object({ type: z3.literal("strike") })
546
627
  ]);
547
- var ProseMirrorTextNode = z2.object({
548
- type: z2.literal("text"),
549
- text: z2.string(),
550
- marks: z2.array(ProseMirrorMark).optional()
628
+ var ProseMirrorTextNode = z3.object({
629
+ type: z3.literal("text"),
630
+ text: z3.string(),
631
+ marks: z3.array(ProseMirrorMark).optional()
551
632
  });
552
- var ProseMirrorParagraphNode = z2.object({
553
- type: z2.literal("paragraph"),
554
- content: z2.array(ProseMirrorTextNode)
633
+ var ProseMirrorParagraphNode = z3.object({
634
+ type: z3.literal("paragraph"),
635
+ content: z3.array(ProseMirrorTextNode)
555
636
  });
556
- var ProseMirrorNode = z2.union([ProseMirrorParagraphNode, ProseMirrorTextNode]);
557
- var ProseMirrorDocSchema = z2.object({
558
- type: z2.literal("doc"),
559
- content: z2.array(ProseMirrorNode).min(1, { message: "Document must contain at least one paragraph" })
637
+ var ProseMirrorNode = z3.union([ProseMirrorParagraphNode, ProseMirrorTextNode]);
638
+ var ProseMirrorDocSchema = z3.object({
639
+ type: z3.literal("doc"),
640
+ content: z3.array(ProseMirrorNode).min(1, { message: "Document must contain at least one paragraph" })
560
641
  });
561
642
 
562
643
  // src/schemas/ftpink/page/index.ts
563
- var HeadingSchema = z3.object({
564
- text: z3.string(),
565
- href: z3.string().url().optional()
644
+ var HeadingSchema = z4.object({
645
+ text: z4.string(),
646
+ href: z4.string().url().optional()
566
647
  });
567
- var BasePageItemProps = z3.object({
648
+ var BasePageItemProps = z4.object({
568
649
  heading: HeadingSchema.optional()
569
650
  });
570
- var ValidJSONStringSchema = z3.string().refine(
651
+ var ValidJSONStringSchema = z4.string().refine(
571
652
  (val) => {
572
653
  try {
573
654
  JSON.parse(val);
@@ -580,40 +661,36 @@ var ValidJSONStringSchema = z3.string().refine(
580
661
  );
581
662
  function defineSliceSchema(options) {
582
663
  const { typeName, propsShape } = options;
583
- const BaseSchema = z3.object({
584
- type: z3.literal(typeName),
585
- hidden: z3.boolean().optional(),
664
+ const BaseSchema = z4.object({
665
+ type: z4.literal(typeName),
666
+ hidden: z4.boolean().optional(),
586
667
  properties: propsShape
587
668
  });
588
669
  const InputSchema = BaseSchema.extend({
589
- sliceId: z3.string().uuid().optional()
670
+ sliceId: z4.string().uuid().optional()
590
671
  });
591
672
  const OutputSchema = BaseSchema.extend({
592
- sliceId: z3.string().uuid()
673
+ sliceId: z4.string().uuid()
593
674
  });
594
675
  return { InputSchema, OutputSchema };
595
676
  }
596
- var HomepageSlice = defineSliceSchema({
597
- typeName: "HomepageSlice",
598
- propsShape: BasePageItemProps.optional()
599
- });
600
677
  var InteractiveSlice = defineSliceSchema({
601
678
  typeName: "Interactive",
602
679
  propsShape: BasePageItemProps.extend({
603
- flourishDescription: z3.string().optional(),
680
+ flourishDescription: z4.string().optional(),
604
681
  // Optional description for the Flourish graphic
605
- flourishId: z3.string().nonempty(),
606
- flourishAltText: z3.string().nonempty(),
607
- storyUUID: z3.string().uuid().optional(),
608
- theme: z3.string().optional()
682
+ flourishId: z4.string().nonempty(),
683
+ flourishAltText: z4.string().nonempty(),
684
+ storyUUID: z4.string().uuid().optional(),
685
+ theme: z4.string().optional()
609
686
  })
610
687
  });
611
688
  var ExperimentSlice = defineSliceSchema({
612
689
  typeName: "Experiment",
613
690
  propsShape: BasePageItemProps.extend({
614
- experimentId: z3.string().nonempty(),
691
+ experimentId: z4.string().nonempty(),
615
692
  // Unique ID for the experiment
616
- experimentName: z3.string().nonempty(),
693
+ experimentName: z4.string().nonempty(),
617
694
  // Human-readable name of the experiment
618
695
  contentJson: ValidJSONStringSchema
619
696
  // The experiment’s JSON payload as a valid JSON string
@@ -622,9 +699,9 @@ var ExperimentSlice = defineSliceSchema({
622
699
  var StripSlice = defineSliceSchema({
623
700
  typeName: "Strip",
624
701
  propsShape: BasePageItemProps.extend({
625
- listId: z3.string().uuid(),
702
+ listId: z4.string().uuid(),
626
703
  // The ID of the strip to display
627
- maxStories: z3.number().int().min(1).max(20)
704
+ maxStories: z4.number().int().min(1).max(20)
628
705
  // Maximum number of stories to display in the strip
629
706
  })
630
707
  });
@@ -632,26 +709,25 @@ var TopperSlice = defineSliceSchema({
632
709
  typeName: "Topper",
633
710
  propsShape: BasePageItemProps.extend({
634
711
  description: ProseMirrorDocSchema,
635
- strapline: z3.string().optional()
712
+ strapline: z4.string().optional()
636
713
  })
637
714
  });
638
715
  var HeroSlice = defineSliceSchema({
639
716
  typeName: "Hero",
640
717
  propsShape: BasePageItemProps.extend({
641
- listId: z3.string().uuid(),
718
+ listId: z4.string().uuid(),
642
719
  // The ID of the spark list to display
643
- maxStories: z3.number().int().min(1).max(20)
720
+ maxStories: z4.number().int().min(1).max(20)
644
721
  // Maximum number of stories to display in the hero
645
722
  })
646
723
  });
647
724
  var StoryGroupSlice = defineSliceSchema({
648
725
  typeName: "StoryGroup",
649
726
  propsShape: BasePageItemProps.extend({
650
- storySlots: z3.array(z3.string().uuid()).nonempty()
727
+ storySlots: z4.array(z4.string().uuid()).nonempty()
651
728
  })
652
729
  });
653
- var SliceApiInputSchema = z3.discriminatedUnion("type", [
654
- HomepageSlice.InputSchema,
730
+ var SliceApiInputSchema = z4.discriminatedUnion("type", [
655
731
  InteractiveSlice.InputSchema,
656
732
  ExperimentSlice.InputSchema,
657
733
  StripSlice.InputSchema,
@@ -659,8 +735,7 @@ var SliceApiInputSchema = z3.discriminatedUnion("type", [
659
735
  HeroSlice.InputSchema,
660
736
  StoryGroupSlice.InputSchema
661
737
  ]);
662
- var SliceApiOutputSchema = z3.discriminatedUnion("type", [
663
- HomepageSlice.OutputSchema,
738
+ var SliceApiOutputSchema = z4.discriminatedUnion("type", [
664
739
  InteractiveSlice.OutputSchema,
665
740
  ExperimentSlice.OutputSchema,
666
741
  StripSlice.OutputSchema,
@@ -668,139 +743,26 @@ var SliceApiOutputSchema = z3.discriminatedUnion("type", [
668
743
  HeroSlice.OutputSchema,
669
744
  StoryGroupSlice.OutputSchema
670
745
  ]);
671
- var BasePagePropertiesSchema = z3.object({
672
- title: z3.string(),
673
- pageId: z3.string().uuid(),
674
- publicationId: z3.string(),
675
- conceptId: z3.string().uuid().optional(),
676
- metaDescription: z3.string().optional(),
677
- pageTheme: z3.string().optional(),
678
- sponsorText: z3.string().optional(),
679
- sponsorImage: z3.string().url().optional()
746
+ var BasePagePropertiesSchema = z4.object({
747
+ title: z4.string(),
748
+ pageId: z4.string().uuid(),
749
+ publicationId: z4.string(),
750
+ conceptId: z4.string().uuid().optional(),
751
+ metaDescription: z4.string().optional(),
752
+ pageTheme: z4.string().optional(),
753
+ sponsorText: z4.string().optional(),
754
+ sponsorImage: z4.string().url().optional(),
755
+ pageCategory: z4.string().optional()
680
756
  });
681
- var PageStructureInputSchema = z3.object({
757
+ var PageStructureInputSchema = z4.object({
682
758
  properties: BasePagePropertiesSchema,
683
- children: z3.array(SliceApiInputSchema)
759
+ children: z4.array(SliceApiInputSchema)
684
760
  });
685
- var HomepageStructureInputSchema = PageStructureInputSchema.extend({
686
- properties: BasePagePropertiesSchema.extend({
687
- // This is optional for the input. If clients don't send it, we generate a uuid.
688
- homepageListId: z3.string().uuid()
689
- })
690
- });
691
- var PageStructureOutputSchema = z3.object({
692
- type: z3.literal("Page"),
693
- schemaVersion: z3.number(),
761
+ var PageStructureOutputSchema = z4.object({
762
+ type: z4.literal("Page"),
763
+ schemaVersion: z4.number(),
694
764
  properties: BasePagePropertiesSchema,
695
- children: z3.array(SliceApiOutputSchema)
696
- });
697
- var HomepageStructureOutputSchema = PageStructureOutputSchema.extend({
698
- type: z3.literal("Homepage"),
699
- properties: BasePagePropertiesSchema.extend({
700
- homepageListId: z3.string().uuid()
701
- })
702
- });
703
-
704
- // src/homepage.ts
705
- var HomepageClient = class extends BaseApiClient {
706
- async getStructure(pageId) {
707
- return this.get(`/v1/homepage/${pageId}/structure`, HomepageStructureOutputSchema);
708
- }
709
- async getStructuresByHomepageListId(homepageListId) {
710
- return this.get(
711
- `/v1/homepage/list/${homepageListId}/structures`,
712
- HomepageStructureOutputSchema.array()
713
- );
714
- }
715
- async upsertStructure(pageId, data) {
716
- return this.put(
717
- `/v1/homepage/${pageId}/structure`,
718
- data,
719
- HomepageStructureInputSchema,
720
- HomepageStructureOutputSchema
721
- );
722
- }
723
- };
724
-
725
- // src/schemas/ftpink/legacyHubPage/index.ts
726
- import { z as z4 } from "zod";
727
- var LegacyFlourishChildSchema = z4.object({
728
- source: z4.literal("flourish"),
729
- properties: z4.object({
730
- id: z4.string().min(1)
731
- // e.g. "visualisation/21901162"
732
- })
733
- });
734
- var LegacyListChildSchema = z4.object({
735
- source: z4.literal("list"),
736
- properties: z4.object({
737
- id: z4.string().uuid(),
738
- maxItems: z4.number().optional()
739
- })
740
- });
741
- var LegacyContentChildSchema = z4.object({
742
- source: z4.literal("content"),
743
- properties: z4.object({
744
- ids: z4.array(z4.string()).nonempty()
745
- })
746
- });
747
- var LegacyContainerChildSchema = z4.discriminatedUnion("source", [
748
- LegacyFlourishChildSchema,
749
- LegacyListChildSchema,
750
- LegacyContentChildSchema
751
- ]);
752
- var LegacyTopperSchema = z4.object({
753
- type: z4.literal("topper-basic"),
754
- properties: z4.object({
755
- title: z4.string(),
756
- sponsorText: z4.string().optional(),
757
- sponsorImage: z4.string().url().optional()
758
- })
759
- });
760
- var LegacyInfoBoxSchema = z4.object({
761
- type: z4.literal("info-box"),
762
- properties: z4.object({
763
- bodyHTML: z4.string(),
764
- title: z4.string().optional()
765
- })
766
- });
767
- var LegacyContainerSchema = z4.object({
768
- type: z4.literal("container"),
769
- children: z4.array(LegacyContainerChildSchema).min(1),
770
- properties: z4.object({
771
- title: z4.string().optional(),
772
- design: z4.enum(["chart", "four-story", "freeform", "hero-lead"]).default("freeform"),
773
- backgroundColor: z4.string().optional()
774
- })
775
- });
776
- var LegacyExperimentSchema = z4.object({
777
- type: z4.literal("experiment"),
778
- children: z4.tuple([]),
779
- properties: z4.object({
780
- experimentName: z4.string(),
781
- id: z4.string(),
782
- title: z4.string().optional(),
783
- config: z4.object({
784
- value: z4.unknown().optional(),
785
- // Hub pages support experiments with HTML and Text.
786
- // For now we just support JSON. As we migrate pages, this may change.
787
- format: z4.enum(["json"]).default("json")
788
- }).partial().optional()
789
- })
790
- });
791
- var LegacyBlockSchema = z4.discriminatedUnion("type", [
792
- LegacyTopperSchema,
793
- LegacyInfoBoxSchema,
794
- LegacyContainerSchema,
795
- LegacyExperimentSchema
796
- ]);
797
- var LegacyPageStructureOutputSchema = z4.object({
798
- uuid: z4.string().uuid(),
799
- title: z4.string(),
800
- conceptId: z4.string().uuid().optional(),
801
- themeName: z4.string().optional(),
802
- metaDescription: z4.string().optional(),
803
- blocks: z4.array(LegacyBlockSchema)
765
+ children: z4.array(SliceApiOutputSchema)
804
766
  });
805
767
 
806
768
  // src/schemas/ftpink/draft/index.ts
@@ -861,14 +823,9 @@ var PageClient = class extends BaseApiClient {
861
823
 
862
824
  // src/client.ts
863
825
  var ApiClient = class extends BaseApiClient {
864
- /**
865
- * Homepage API endpoints
866
- */
867
- homepage;
868
826
  page;
869
827
  constructor(config) {
870
828
  super(config);
871
- this.homepage = new HomepageClient(config);
872
829
  this.page = new PageClient(config);
873
830
  }
874
831
  };
@@ -886,9 +843,6 @@ export {
886
843
  DraftContributorInputSchema,
887
844
  DraftContributorSchema,
888
845
  DraftSchema,
889
- HomepageClient,
890
- HomepageStructureInputSchema,
891
- HomepageStructureOutputSchema,
892
846
  LegacyPageStructureOutputSchema,
893
847
  PageClient,
894
848
  PageDraftSchema,