create-ailk 0.46.0 → 0.46.1

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.
@@ -3,7 +3,9 @@
3
3
  * lists, the card it lists each with, and `plans: []` reading no Stripe data.
4
4
  * #12103: plan groups (AC-2), the default Recommended's pill (AC-3) and the
5
5
  * authored card layout (AC-5), through the pure `offeringsFragments` and
6
- * `withOfferings`.
6
+ * `withOfferings`. #12140: bound (`source: offerings`) and written sections,
7
+ * the layout the page picks, the kept comparison grid, and the 0.74.0 page
8
+ * for a section with no `source`.
7
9
  */
8
10
  import {
9
11
  PageSectionsSchema,
@@ -15,6 +17,7 @@ import {
15
17
  } from "@working-theory/validation";
16
18
 
17
19
  import {
20
+ OFFERINGS_CHECKOUT_PATH,
18
21
  offeringsPricing,
19
22
  type OfferingsPricingLabels,
20
23
  } from "../offerings-pricing";
@@ -25,6 +28,7 @@ import {
25
28
  PRICING_HUB_SLUG,
26
29
  pricingPageCard,
27
30
  pricingSections,
31
+ withContactFallback,
28
32
  withOfferings,
29
33
  } from "../pricing-page";
30
34
  import type { DetailPage } from "@working-theory/site-pages/lib/route-family";
@@ -164,6 +168,7 @@ const LABELS: OfferingsPricingLabels = {
164
168
  oneTime: (amount) => "O⟪" + amount,
165
169
  withRequired: (plan, required) => "W⟪" + plan + "⟫" + required,
166
170
  depositNote: (deposit) => "D⟪" + deposit,
171
+ billedYearly: (amount) => "B⟪" + amount,
167
172
  };
168
173
  const RECOMMENDED_LABEL = "FOR-YOU⟪";
169
174
  const ADDONS_HEADLINE = "ADDONS⟪";
@@ -420,3 +425,393 @@ describe("the authored card layout survives (#12103 D6, AC-5)", () => {
420
425
  expect(dataOf(placed, "retainers").billingToggle).toBe(false);
421
426
  });
422
427
  });
428
+
429
+ // ─── #12140 — bound and written sections (spec 12140 D2, D6, D7) ────────────
430
+
431
+ const PLAN_VARIANTS = [
432
+ "three-tiers-with-toggle",
433
+ "with-comparison-table",
434
+ "two-tiers-with-extra-tier",
435
+ "single-price-with-details",
436
+ "features-and-plans",
437
+ "band-hero",
438
+ ] as const;
439
+
440
+ const ALL_KEYS = ["essentials", "growth", "writing"];
441
+
442
+ describe("a bound section renders the variant the page sets (#12140 AC-1)", () => {
443
+ it.each(PLAN_VARIANTS)("%s", (variant) => {
444
+ const { placed } = render([
445
+ HERO,
446
+ pricingSection("p", { source: "offerings", variant }),
447
+ ]);
448
+ expect(placed.map((s) => s.id)).toEqual(["hero", "p"]);
449
+ expect(dataOf(placed, "p").variant).toBe(variant);
450
+ expect(dataOf(placed, "p").source).toBe("offerings");
451
+ if (variant === "with-comparison-table")
452
+ expect(keysOf(placed, "p")).toEqual(ALL_KEYS);
453
+ if (variant === "single-price-with-details")
454
+ expect(keysOf(placed, "p")).toEqual(["essentials"]);
455
+ });
456
+
457
+ it("a bound section with no variant gets the toggle layout", () => {
458
+ const { placed } = render([pricingSection("p", { source: "offerings" })]);
459
+ expect(dataOf(placed, "p").variant).toBe("three-tiers-with-toggle");
460
+ expect(dataOf(placed, "p").billingToggle).toBe(true);
461
+ });
462
+
463
+ it("drops an authored extra tier and plan card, and keeps a band's key points", () => {
464
+ const keyPointsPanel = { items: [{ title: "Fast" }] };
465
+ const { placed } = render([
466
+ pricingSection("two", {
467
+ source: "offerings",
468
+ variant: "two-tiers-with-extra-tier",
469
+ extraTier: { name: "Big", price: { custom: "Ask" }, features: [], cta: { label: "Talk", href: "/elsewhere" } },
470
+ plans: [{ key: "own", name: "Own", price: { custom: "$1" }, features: [], cta: { label: "Go", href: "/elsewhere" } }],
471
+ }),
472
+ pricingSection("band", { source: "offerings", variant: "band-hero", keyPointsPanel }),
473
+ ]);
474
+ expect(dataOf(placed, "two")).not.toHaveProperty("extraTier");
475
+ expect(keysOf(placed, "two")).toEqual(ALL_KEYS);
476
+ expect(dataOf(placed, "band").keyPointsPanel).toEqual(keyPointsPanel);
477
+ });
478
+
479
+ it("an unbound section ignores its variant and renders as in 0.74.0", () => {
480
+ const { placed } = render([HERO, pricingSection("p", { variant: "features-and-plans" })]);
481
+ expect(dataOf(placed, "p").variant).toBe("three-tiers-with-toggle");
482
+ expect(dataOf(placed, "p").cardLayout).toBe("centered");
483
+ expect(keysOf(placed, "p")).toEqual(ALL_KEYS);
484
+ });
485
+
486
+ it("a bound add-ons section takes the tiles; a bound plans section beside it takes none", () => {
487
+ const { placed } = render([
488
+ pricingSection("a", { source: "offerings", variant: "addons" }),
489
+ pricingSection("c", { source: "offerings", variant: "with-comparison-table" }),
490
+ ]);
491
+ expect(placed.map((s) => s.id)).toEqual(["a", "c"]);
492
+ expect(dataOf(placed, "a").addons?.map((t) => t.name)).toEqual(["seo"]);
493
+ expect(dataOf(placed, "a").source).toBe("offerings");
494
+ expect(dataOf(placed, "c")).not.toHaveProperty("addons");
495
+ });
496
+ });
497
+
498
+ describe("a section with no source renders exactly as in 0.74.0 (#12140 AC-2)", () => {
499
+ const AUTHORED = {
500
+ headline: "Plans",
501
+ variant: "with-comparison-table",
502
+ comparisonGroups: [{ groupName: "Core", rows: [{ featureName: "Reports", values: { growth: true } }] }],
503
+ features: [{ title: "Row", description: "One" }],
504
+ extraTier: { name: "Big", price: { custom: "Ask" }, features: [], cta: { label: "Talk", href: "/contact" } },
505
+ };
506
+ const TODAY_KEYS = ["billingToggle", "cardLayout", "headline", "plans", "recommendedLabel", "variant"];
507
+
508
+ it("an unbound plans slot keeps only today's fields", () => {
509
+ const { placed } = render([pricingSection("p", AUTHORED)]);
510
+ expect(Object.keys(dataOf(placed, "p")).sort()).toEqual(TODAY_KEYS);
511
+ expect(dataOf(placed, "p").variant).toBe("three-tiers-with-toggle");
512
+ });
513
+
514
+ it("an unbound plan group keeps only today's fields", () => {
515
+ const { placed } = render([pricingSection("g", { ...AUTHORED, offeringPlans: ["writing"] })]);
516
+ expect(Object.keys(dataOf(placed, "g")).sort()).toEqual(TODAY_KEYS);
517
+ });
518
+
519
+ it("still inserts the plans and add-ons after a leading hero on a page with no pricing section", () => {
520
+ const { placed } = render([HERO]);
521
+ expect(placed.map((s) => s.id)).toEqual(["hero", "offerings-plans", "offerings-addons"]);
522
+ });
523
+ });
524
+
525
+ describe("features-and-plans on one product with two Prices (#12140 AC-3)", () => {
526
+ const WRITING = stripeProduct(
527
+ "writing",
528
+ "plan",
529
+ [stripePrice("writing", "monthly", 3000), stripePrice("writing", "yearly", 30000)],
530
+ { marketingFeatures: ["Edits", "Briefs"] },
531
+ );
532
+ const set = workspaceShownSetSchema.parse({
533
+ ...stripeSet(),
534
+ offerings: [WRITING],
535
+ productIds: ["prod_writing"],
536
+ recommended: { plan: null, addon: null },
537
+ });
538
+
539
+ it("renders a monthly and a yearly block, each with its own checkout, beside the product's features", () => {
540
+ const { placed } = render(
541
+ [HERO, pricingSection("w", { source: "offerings", variant: "features-and-plans", offeringPlans: ["writing"] })],
542
+ { set },
543
+ );
544
+ expect(keysOf(placed, "w")).toEqual(["writing", "writing_yearly"]);
545
+ const hrefs = dataOf(placed, "w").plans.map((c) => c.cta.href);
546
+ expect(hrefs[0]!.endsWith("writing_monthly")).toBe(true);
547
+ expect(hrefs[1]!.endsWith("writing_yearly")).toBe(true);
548
+ expect(dataOf(placed, "w").features).toEqual([{ title: "Edits" }, { title: "Briefs" }]);
549
+ });
550
+
551
+ it("keeps an authored features list over the product's", () => {
552
+ const own = [{ title: "Own", description: "Mine" }];
553
+ const { placed } = render(
554
+ [pricingSection("w", { source: "offerings", variant: "features-and-plans", offeringPlans: ["writing"], features: own })],
555
+ { set },
556
+ );
557
+ expect(dataOf(placed, "w").features).toEqual(own);
558
+ });
559
+ });
560
+
561
+ describe("comparisonGroups survive the swap, matched by plan slug (#12140 AC-4)", () => {
562
+ const NAMED = workspaceShownSetSchema.parse({
563
+ ...stripeSet(),
564
+ offerings: stripeSet().offerings.map((o) => ({
565
+ ...o,
566
+ name: o.plan.charAt(0).toUpperCase() + o.plan.slice(1),
567
+ })),
568
+ });
569
+ const G = [
570
+ { groupName: "Core", rows: [{ featureName: "Reports", values: { essentials: true, growth: "Weekly", absent: true } }] },
571
+ ];
572
+ const section = (groups: unknown) =>
573
+ pricingSection("c", {
574
+ source: "offerings",
575
+ variant: "with-comparison-table",
576
+ offeringPlans: ["essentials", "growth"],
577
+ comparisonGroups: groups,
578
+ });
579
+
580
+ it("keeps the grid and keys the cards by slug, not by name", () => {
581
+ const { placed } = render([HERO, section(G)], { set: NAMED });
582
+ expect(dataOf(placed, "c").comparisonGroups).toEqual(G);
583
+ expect(keysOf(placed, "c")).toEqual(["essentials", "growth"]);
584
+ expect(dataOf(placed, "c").plans.map((c) => c.name)).toEqual(["Essentials", "Growth"]);
585
+ });
586
+
587
+ it("drops a cell's authored link and keeps every other value", () => {
588
+ const linked = [
589
+ {
590
+ groupName: "Core",
591
+ rows: [
592
+ {
593
+ featureName: "Reports",
594
+ values: {
595
+ essentials: true,
596
+ growth: { text: "Weekly", verdict: "yes", link: { label: "See", href: "https://example.com" } },
597
+ absent: true,
598
+ },
599
+ },
600
+ ],
601
+ },
602
+ ];
603
+ const { placed } = render([section(linked)], { set: NAMED });
604
+ expect(dataOf(placed, "c").comparisonGroups).toEqual([
605
+ { groupName: "Core", rows: [{ featureName: "Reports", values: { essentials: true, growth: { text: "Weekly", verdict: "yes" }, absent: true } }] },
606
+ ]);
607
+ });
608
+ });
609
+
610
+ describe("no vendor, and every price link on a non-written section is a checkout key (#12140 AC-5, NFR-2)", () => {
611
+ it("holds over a page of every bound variant, a bound add-ons section and an unbound section", () => {
612
+ const linkedGrid = [
613
+ { groupName: "Core", rows: [{ featureName: "R", values: { growth: { text: "W", link: { label: "See", href: "/elsewhere" } } } }] },
614
+ ];
615
+ const authored = {
616
+ plans: [{ key: "own", name: "Own", price: { custom: "$1" }, features: [], cta: { label: "Go", href: "/elsewhere" } }],
617
+ extraTier: { name: "Big", price: { custom: "Ask" }, features: [], cta: { label: "Talk", href: "/elsewhere" } },
618
+ comparisonGroups: linkedGrid,
619
+ };
620
+ const { placed } = render([
621
+ HERO,
622
+ ...PLAN_VARIANTS.map((variant) => pricingSection(`b-${variant}`, { source: "offerings", variant, ...authored })),
623
+ pricingSection("a", { source: "offerings", variant: "addons" }),
624
+ pricingSection("u", authored),
625
+ ]);
626
+ const priced = placed.filter((s): s is Pricing => s.type === "pricing");
627
+ expect(priced.map((s) => s.id)).toEqual([...PLAN_VARIANTS.map((v) => `b-${v}`), "a", "u"]);
628
+ const ours = (href: string | undefined) =>
629
+ href === undefined || href.startsWith(OFFERINGS_CHECKOUT_PATH);
630
+ for (const { data } of priced) {
631
+ expect(JSON.stringify(data)).not.toMatch(/stripe/i);
632
+ expect(data).not.toHaveProperty("extraTier");
633
+ for (const card of data.plans) {
634
+ expect(ours(card.cta.href)).toBe(true);
635
+ expect(ours(card.annualCtaHref)).toBe(true);
636
+ }
637
+ for (const tile of data.addons ?? []) expect(ours(tile.cta?.href)).toBe(true);
638
+ for (const group of data.comparisonGroups ?? [])
639
+ for (const row of group.rows)
640
+ for (const value of Object.values(row.values))
641
+ if (typeof value === "object") expect(value).not.toHaveProperty("link");
642
+ }
643
+ });
644
+ });
645
+
646
+ describe("a written section (#12140 AC-6)", () => {
647
+ const W = pricingSection("w", {
648
+ source: "written",
649
+ plans: [{ key: "custom", name: "Custom", price: { custom: "Ask" }, features: [], cta: { label: "Talk", href: "/contact" } }],
650
+ });
651
+ const RECOMMENDED = RECOMMENDED_LABEL;
652
+
653
+ it("stays as written beside the Offerings cards, and never becomes the plans slot", () => {
654
+ const { placed } = render([HERO, W, pricingSection("p"), EXTRAS]);
655
+ expect(placed.map((s) => s.id)).toEqual(["hero", "w", "p", "extras"]);
656
+ expect(dataOf(placed, "w")).toEqual(W.data);
657
+ expect(keysOf(placed, "p")).toEqual(ALL_KEYS);
658
+ });
659
+
660
+ it("takes a {plan}-grammar ?plan= only", () => {
661
+ expect(dataOf(render([W, pricingSection("p")], { plan: "custom" }).placed, "w")).toEqual({
662
+ ...W.data,
663
+ recommended: "custom",
664
+ recommendedLabel: RECOMMENDED,
665
+ });
666
+ expect(dataOf(render([W, pricingSection("p")], { plan: "Custom" }).placed, "w")).toEqual(W.data);
667
+ });
668
+
669
+ const W2 = pricingSection("w", {
670
+ source: "written",
671
+ plans: [
672
+ ...W.data.plans,
673
+ { key: "sneak", name: "Sneak", price: { custom: "$1" }, features: [], cta: { label: "Buy", href: "/api/offerings/checkout/writing_monthly" } },
674
+ { key: "annual", name: "Annual", price: { custom: "$2" }, features: [], cta: { label: "Buy", href: "/x" }, annualCtaHref: "/api/offerings/checkout/writing_yearly" },
675
+ { key: "absolute", name: "Absolute", price: { custom: "$3" }, features: [], cta: { label: "Buy", href: "https://example.com/api/offerings/checkout/growth_monthly" } },
676
+ ],
677
+ extraTier: { name: "Big", price: { custom: "$9" }, features: [], cta: { label: "Buy", href: "/api/offerings/checkout/growth_monthly" } },
678
+ });
679
+
680
+ it("drops every card and extra tier that links the Offerings checkout", () => {
681
+ const { placed } = render([W2, pricingSection("p")]);
682
+ expect(keysOf(placed, "w")).toEqual(["custom"]);
683
+ expect(dataOf(placed, "w")).not.toHaveProperty("extraTier");
684
+ });
685
+
686
+ it("drops a percent-encoded link to the Offerings checkout too", () => {
687
+ const encoded = (key: string, href: string) => ({
688
+ key,
689
+ name: key,
690
+ price: { custom: "$1" },
691
+ features: [],
692
+ cta: { label: "Buy", href },
693
+ });
694
+ const W3 = pricingSection("w", {
695
+ source: "written",
696
+ plans: [
697
+ ...W.data.plans,
698
+ encoded("letter", "/api/%6Ffferings/checkout/writing_monthly"),
699
+ encoded("slash", "/api%2Fofferings%2Fcheckout/writing_monthly"),
700
+ encoded("upper", "/API/%4FFFERINGS/Checkout/writing_monthly"),
701
+ encoded("malformed", "/api/offerings/%E0%A4%A"),
702
+ ],
703
+ });
704
+ expect(keysOf(render([W3, pricingSection("p")]).placed, "w")).toEqual(["custom", "malformed"]);
705
+ });
706
+
707
+ it("drops a written add-on tile and a cell link that reach the Offerings checkout", () => {
708
+ const tile = (name: string, href: string) => ({ name, price: "$1", cta: { label: "Add", href } });
709
+ const W4 = pricingSection("w", {
710
+ source: "written",
711
+ addons: [tile("Kept", "/contact"), tile("Sold", "/api/offerings/checkout/rush_once")],
712
+ comparisonGroups: [
713
+ {
714
+ groupName: "G",
715
+ rows: [
716
+ {
717
+ featureName: "Row",
718
+ values: {
719
+ custom: { text: "Yes", link: { label: "Buy", href: "/api/offerings/checkout/writing_monthly" } },
720
+ other: { text: "Ask", link: { label: "Ask", href: "/contact" } },
721
+ },
722
+ },
723
+ ],
724
+ },
725
+ ],
726
+ });
727
+ const data = dataOf(render([W4, pricingSection("p")]).placed, "w");
728
+ expect(data.addons?.map((a) => a.name)).toEqual(["Kept"]);
729
+ const values = data.comparisonGroups?.[0]?.rows[0]?.values ?? {};
730
+ expect(values["custom"]).toEqual({ text: "Yes" });
731
+ expect(values["other"]).toEqual({ text: "Ask", link: { label: "Ask", href: "/contact" } });
732
+ });
733
+
734
+ it("drops them through pricingSections for page plans: [] too", async () => {
735
+ const sections = await pricingSections([W2], { plans: [], plan: undefined, locale: "en" });
736
+ expect(fetchMock).not.toHaveBeenCalled();
737
+ expect(keysOf(sections, "w")).toEqual(["custom"]);
738
+ expect(dataOf(sections, "w")).not.toHaveProperty("extraTier");
739
+ });
740
+
741
+ it("gives way to the contact email with every other pricing section", () => {
742
+ expect(withContactFallback([HERO, W, pricingSection("p"), EXTRAS]).map((s) => s.id)).toEqual([
743
+ "hero",
744
+ "offerings-contact",
745
+ ]);
746
+ });
747
+
748
+ describe("through pricingSections", () => {
749
+ let now = Date.now();
750
+ beforeEach(() => {
751
+ now += 16_000;
752
+ jest.spyOn(Date, "now").mockReturnValue(now);
753
+ });
754
+ afterEach(() => jest.restoreAllMocks());
755
+
756
+ const answer = (data: unknown) =>
757
+ fetchMock.mockImplementation(async () => ({
758
+ ok: true,
759
+ status: 200,
760
+ json: async () => ({ ok: true, data }),
761
+ }));
762
+
763
+ it("takes the contact path when the only pricing left would be written", async () => {
764
+ answer({ status: "shown", shownSet: stripeSet() });
765
+ const sections = await pricingSections([HERO, W, pricingSection("p")], {
766
+ plans: ["absent"],
767
+ plan: undefined,
768
+ locale: "en",
769
+ });
770
+ expect(sections.map((s) => s.id)).toEqual(["hero", "offerings-contact"]);
771
+ });
772
+
773
+ it("takes the contact path on an empty shown set", async () => {
774
+ answer({ status: "empty" });
775
+ const sections = await pricingSections([HERO, W, pricingSection("p")], {
776
+ plans: undefined,
777
+ plan: undefined,
778
+ locale: "en",
779
+ });
780
+ expect(sections.map((s) => s.id)).toEqual(["hero", "offerings-contact"]);
781
+ });
782
+
783
+ it("reads no Offerings for a page whose every pricing section is written", async () => {
784
+ answer({ status: "shown", shownSet: stripeSet() });
785
+ const sections = await pricingSections([HERO, W], { plans: undefined, plan: undefined, locale: "en" });
786
+ expect(sections.map((s) => s.id)).toEqual(["hero", "w"]);
787
+ expect(sections[1]).toEqual(W);
788
+ expect(fetchMock).not.toHaveBeenCalled();
789
+ });
790
+
791
+ it("reads once when an unbound section sits beside it", async () => {
792
+ answer({ status: "shown", shownSet: stripeSet() });
793
+ const sections = await pricingSections([HERO, W, pricingSection("p")], {
794
+ plans: undefined,
795
+ plan: undefined,
796
+ locale: "en",
797
+ });
798
+ expect(fetchMock).toHaveBeenCalledTimes(1);
799
+ expect(sections.map((s) => s.id)).toEqual(["hero", "w", "p"]);
800
+ });
801
+ });
802
+ });
803
+
804
+ describe("the plan bar options survive the Stripe path (#12141 D9, AC-1)", () => {
805
+ const REC_GRID = { pickerLabel: "Plan", pinnedGroups: true, groupsOpen: "first" };
806
+
807
+ it.each([
808
+ ["an unbound plans slot", {}],
809
+ ["a bound section", { source: "offerings", variant: "with-comparison-table" }],
810
+ ])("%s keeps planBar and comparisonPlanBar over the Offerings cards, deep-equal", (_label, extra) => {
811
+ const { placed } = render([
812
+ pricingSection("p", { ...extra, planBar: {}, comparisonPlanBar: REC_GRID }),
813
+ ]);
814
+ expect(dataOf(placed, "p").planBar).toEqual({});
815
+ expect(dataOf(placed, "p").comparisonPlanBar).toEqual(REC_GRID);
816
+ });
817
+ });
@@ -60,6 +60,8 @@ export interface OfferingsPricingLabels {
60
60
  withRequired(plan: string, required: string): string;
61
61
  /** A deposit plan's footnote, from the formatted deposit (#10030 D10). */
62
62
  depositNote(deposit: string): string;
63
+ /** The yearly total under a per-month annual price (#12139 D1). */
64
+ billedYearly(amount: string): string;
63
65
  }
64
66
 
65
67
  export interface OfferingsPricing {
@@ -67,6 +69,12 @@ export interface OfferingsPricing {
67
69
  addons: PricingSectionData | null;
68
70
  }
69
71
 
72
+ /** The layouts a plans fragment takes (#12140 D3): every variant but `addons`. */
73
+ export type OfferingsLayout = Exclude<
74
+ NonNullable<PricingSectionData["variant"]>,
75
+ "addons"
76
+ >;
77
+
70
78
  /** The route every Offerings CTA links to, followed by a grammar key. */
71
79
  export const OFFERINGS_CHECKOUT_PATH = "/api/offerings/checkout";
72
80
 
@@ -270,8 +278,11 @@ function bundleCard(
270
278
  // NO_HAND_IMPLEMENT_OK: builder-assessors run for #10030 — the builder is the implementer.
271
279
  if (product.deposit !== undefined)
272
280
  card.priceFootnote = labels.depositNote(formatMinorUnits(product.deposit, once.currency, locale));
273
- else if (product.termsNote)
281
+ else if (product.termsNote) {
274
282
  card.priceFootnote = stripFormatCharacters(product.termsNote);
283
+ // Beside both prices, the terms note describes the annual one (#12139 D2).
284
+ if (monthly && yearly) card.priceFootnoteAnnualOnly = true;
285
+ }
275
286
  const annualHref =
276
287
  monthly && yearly && offeringsBundleHref(once.lookupKey, yearly.lookupKey);
277
288
  if (annualHref) card.annualCtaHref = annualHref;
@@ -298,7 +309,18 @@ function planCard(
298
309
  const once = priceFor(product, PERIOD.once);
299
310
  const price: PricingPlanCard["price"] = {};
300
311
  if (monthly) price.monthly = phrase(monthly, locale, labels);
301
- if (yearly) price.annual = phrase(yearly, locale, labels);
312
+ // Beside a monthly Price, annual mode shows the yearly Price per month, so
313
+ // the two modes compare in one unit (#12139 D1); its total goes in a note.
314
+ if (yearly)
315
+ price.annual = monthly
316
+ ? labels.monthly(
317
+ formatMinorUnits(
318
+ Math.round(yearly.amount / 12),
319
+ yearly.currency,
320
+ locale,
321
+ ),
322
+ )
323
+ : phrase(yearly, locale, labels);
302
324
  if (once && !monthly && !yearly) price.custom = phrase(once, locale, labels);
303
325
 
304
326
  const card: PricingPlanCard = {
@@ -314,12 +336,19 @@ function planCard(
314
336
  if (product.unitLabel)
315
337
  card.priceUnit = stripFormatCharacters(product.unitLabel);
316
338
  if (product.note) card.priceSubhead = stripFormatCharacters(product.note);
317
- if (product.termsNote)
318
- card.priceFootnote = stripFormatCharacters(product.termsNote);
339
+ if (monthly && yearly)
340
+ card.annualPriceNote = labels.billedYearly(
341
+ formatMinorUnits(yearly.amount, yearly.currency, locale),
342
+ );
319
343
  // A deposit plan's footnote (#10030 D10), in its one-time Price's currency;
320
344
  // it takes the footnote over a terms note (the rarer field).
321
345
  if (product.deposit !== undefined && once)
322
346
  card.priceFootnote = labels.depositNote(formatMinorUnits(product.deposit, once.currency, locale));
347
+ else if (product.termsNote) {
348
+ card.priceFootnote = stripFormatCharacters(product.termsNote);
349
+ // Beside both prices, the terms note describes the annual one (#12139 D2).
350
+ if (monthly && yearly) card.priceFootnoteAnnualOnly = true;
351
+ }
323
352
  // Annual mode shows the yearly Price only when a monthly one is beside it,
324
353
  // so only then does the card need a second link (D5, D6).
325
354
  const annualHref =
@@ -333,6 +362,105 @@ function planCard(
333
362
  return card;
334
363
  }
335
364
 
365
+ /**
366
+ * `features-and-plans` for one product with a monthly and a yearly Price
367
+ * (#12140 D4): two blocks, each selling its own Price, built from the
368
+ * product's card as `planCard` made it. The yearly block is keyed by its
369
+ * lookup key, which the plan-slug grammar refuses, so it never collides with a
370
+ * card's key or matches `?plan=`; the terms note sits on it alone (#12139 D2).
371
+ * `null` when the product is not that shape or either key is outside the
372
+ * grammar — the caller then keeps the card as built.
373
+ */
374
+ function splitBlocks(
375
+ product: OfferingsProduct,
376
+ card: PricingPlanCard,
377
+ locale: string,
378
+ labels: OfferingsPricingLabels,
379
+ ): PricingPlanCard[] | null {
380
+ const monthly = priceFor(product, PERIOD.monthly);
381
+ const yearly = priceFor(product, PERIOD.yearly);
382
+ if (product.requires !== undefined || !monthly || !yearly) return null;
383
+ const monthlyHref = offeringsCheckoutHref(monthly.lookupKey);
384
+ const yearlyHref = offeringsCheckoutHref(yearly.lookupKey);
385
+ if (!monthlyHref || !yearlyHref) return null;
386
+ const {
387
+ price: _price,
388
+ annualCtaHref: _annualCtaHref,
389
+ annualPriceNote: _annualPriceNote,
390
+ priceFootnote: _priceFootnote,
391
+ priceFootnoteAnnualOnly: _priceFootnoteAnnualOnly,
392
+ ...shared
393
+ } = card;
394
+ const yearlyBlock: PricingPlanCard = {
395
+ key: yearly.lookupKey,
396
+ name: card.name,
397
+ price: { annual: phrase(yearly, locale, labels) },
398
+ features: card.features,
399
+ cta: { label: card.cta.label, href: yearlyHref },
400
+ };
401
+ if (card.priceUnit !== undefined) yearlyBlock.priceUnit = card.priceUnit;
402
+ if (card.priceSubhead !== undefined)
403
+ yearlyBlock.priceSubhead = card.priceSubhead;
404
+ if (product.termsNote)
405
+ yearlyBlock.priceFootnote = stripFormatCharacters(product.termsNote);
406
+ return [
407
+ {
408
+ ...shared,
409
+ price: { monthly: phrase(monthly, locale, labels) },
410
+ cta: { label: card.cta.label, href: monthlyHref },
411
+ },
412
+ yearlyBlock,
413
+ ];
414
+ }
415
+
416
+ /**
417
+ * The plans fragment in `layout` (#12140 D3): the cards as built, framed for
418
+ * the layout that renders them. Absent, today's toggle fragment. `product` is
419
+ * the one plan product behind `cards`, when there is exactly one.
420
+ */
421
+ function plansFragment(
422
+ cards: PricingPlanCard[],
423
+ layout: OfferingsLayout | undefined,
424
+ product: OfferingsProduct | undefined,
425
+ locale: string,
426
+ labels: OfferingsPricingLabels,
427
+ ): PricingSectionData {
428
+ switch (layout) {
429
+ case undefined:
430
+ case "three-tiers-with-toggle":
431
+ return {
432
+ variant: "three-tiers-with-toggle",
433
+ cardLayout: "centered",
434
+ billingToggle: cards.some(
435
+ (card) =>
436
+ card.price.monthly !== undefined &&
437
+ card.price.annual !== undefined,
438
+ ),
439
+ plans: cards,
440
+ };
441
+ // These variants show monthly prices only, so they take no toggle.
442
+ case "with-comparison-table":
443
+ case "two-tiers-with-extra-tier":
444
+ case "band-hero":
445
+ return { variant: layout, cardLayout: "centered", plans: cards };
446
+ // The variant renders one plan and has no card layout.
447
+ case "single-price-with-details":
448
+ return { variant: layout, plans: cards.slice(0, 1) };
449
+ case "features-and-plans": {
450
+ const split =
451
+ product && splitBlocks(product, cards[0]!, locale, labels);
452
+ const rows = product ? features(product) : [];
453
+ return {
454
+ variant: layout,
455
+ plans: split ?? cards,
456
+ ...(rows.length > 0
457
+ ? { features: rows.map((title) => ({ title })) }
458
+ : {}),
459
+ };
460
+ }
461
+ }
462
+ }
463
+
336
464
  function addonTile(
337
465
  product: OfferingsProduct,
338
466
  highlighted: boolean,
@@ -412,6 +540,10 @@ function narrowToPlans(
412
540
  * `exclude` (#12103 D2) drops the plan cards of the plans it lists — the ones
413
541
  * a section's own `offeringPlans` already shows — so the page's unlisted
414
542
  * plans section does not show them twice. Add-on tiles are unaffected.
543
+ *
544
+ * `layout` (#12140 D3) frames the plans fragment for the variant a bound
545
+ * section names; the cards are built the same either way. Absent, the plans
546
+ * fragment is the toggle layout, exactly as before. Add-ons are unaffected.
415
547
  */
416
548
  export function offeringsPricing(
417
549
  shownSet: unknown,
@@ -420,6 +552,7 @@ export function offeringsPricing(
420
552
  labels: OfferingsPricingLabels;
421
553
  plans?: readonly string[] | undefined;
422
554
  exclude?: readonly string[] | undefined;
555
+ layout?: OfferingsLayout | undefined;
423
556
  },
424
557
  ): OfferingsPricing | null {
425
558
  const parsed = shownSetSchema.safeParse(shownSet);
@@ -463,19 +596,15 @@ export function offeringsPricing(
463
596
  .map((p) => addonTile(p, p.plan === recommendedAddon, locale, labels))
464
597
  .filter(isPresent);
465
598
 
599
+ // Each card is keyed by its product's `{plan}`, so a lone card names its product.
600
+ const product =
601
+ plans.length === 1
602
+ ? planProducts.find((p) => p.plan === plans[0]!.key)
603
+ : undefined;
466
604
  return {
467
605
  plans:
468
606
  plans.length > 0
469
- ? {
470
- variant: "three-tiers-with-toggle",
471
- cardLayout: "centered",
472
- billingToggle: plans.some(
473
- (card) =>
474
- card.price.monthly !== undefined &&
475
- card.price.annual !== undefined,
476
- ),
477
- plans,
478
- }
607
+ ? plansFragment(plans, options.layout, product, locale, labels)
479
608
  : null,
480
609
  addons: addons.length > 0 ? { variant: "addons", plans: [], addons } : null,
481
610
  };