create-ailk 0.46.2 → 0.46.4

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.
@@ -17,7 +17,9 @@
17
17
  * - T3 — every link is `OFFERINGS_CHECKOUT_PATH` plus a lookup key that
18
18
  * `parseLookupKey` accepts — plus, for a bundled plan, `?with=` and the
19
19
  * required product's key (#10028 D9); no href is built from any other
20
- * field (D5).
20
+ * field (D5) — except a contact's Stripe URL (#12193 D2, the contract's
21
+ * one stated exception) and a plan's footnote link (#12243, the same
22
+ * exception extended), both by `contactLink`'s rule.
21
23
  * - §3.7 — `yearly` reads as annual and `once` as one-time at render, never
22
24
  * in the key (D2).
23
25
  *
@@ -25,33 +27,84 @@
25
27
  * and the period phrasings arrive in `labels` (D9, customer-facing-i18n). A
26
28
  * seller's own button label (`ctaLabel`, Stripe `ailk_cta`) and an add-on's
27
29
  * eyebrow (`ailk_eyebrow`) are seller-authored text shown as written, as the
28
- * product name is (#12103 D1, D5).
30
+ * product name is (#12103 D1, D5), and so are the card keys and a contact's
31
+ * display price (#12193 D1, D2).
32
+ *
33
+ * #12193 — a selecting bound section passes `tiers` (and `collection`): plans
34
+ * sharing a Stripe `ailk_tier` become one level card, and a collection's
35
+ * contacts (priceless products with a URL) become contact cards and tiles.
36
+ * Every card and level carries `offerPrices`, the render-time Prices the
37
+ * JSON-LD reads (D9), never a stored field.
38
+ *
39
+ * #12210 — a plan product with several price points (one `{plan}` slug per
40
+ * point) is one level card whose levels are its points: each level's amount,
41
+ * label and checkout link come from its Price, everything else from the
42
+ * product (`offeringPointProducts`). A product is named by any of its slugs.
43
+ *
44
+ * #12243 — a plan's `footnote` and its link ride its card, and a level card
45
+ * takes its first level's (a card field, never a level's). `siteOrigin` makes a
46
+ * same-origin link an internal path; without it every link is external.
47
+ *
48
+ * #12246 — `offeringsPlanColumns` resolves a comparison table's plan columns
49
+ * from the same shown set: each slug's name, price, checkout link and
50
+ * Recommended flag, from the card `planCard` / `bundleCard` builds for it.
29
51
  */
30
52
  import {
53
+ PRICING_SEGMENT_LEVELS_MAX,
54
+ PRICING_SELECT_LEVELS_MAX,
55
+ OFFER_PERIOD_OF,
56
+ offeringPlanSlugs,
57
+ offeringPointProducts,
58
+ offeringPricePoints,
31
59
  parseLookupKey,
60
+ planColumnSlugs,
32
61
  lookupKeyPeriodSchema,
62
+ type PlanColumnOffering,
33
63
  workspaceShownSetSchema,
34
64
  type LookupKeyPeriod,
65
+ type OfferPrice,
66
+ type OfferingsContactProduct,
35
67
  type OfferingsPrice,
36
68
  type OfferingsProduct,
37
69
  type PageSection,
70
+ type PriceParts,
38
71
  } from "@working-theory/validation";
39
72
 
40
73
  /** The period words, read by name from their one home (#8876 AC-9). */
41
74
  const PERIOD = lookupKeyPeriodSchema.enum;
42
75
 
43
76
  type PricingSectionData = Extract<PageSection, { type: "pricing" }>["data"];
44
- type PricingPlanCard = PricingSectionData["plans"][number];
45
- type PricingPlanLevel = NonNullable<PricingPlanCard["levels"]>[number];
77
+
78
+ // #12193 D9 — `offerPrices` (`OfferPrice`, the contribution's shape) is a
79
+ // render-time field, never in the stored section schema, so no author or agent
80
+ // can declare one.
81
+ // #12242 D1 — `priceParts` (`PriceParts`) is render-time too: a side's amount
82
+ // and unit as two elements, beside the unchanged `price` phrases.
83
+ type PricingPlanLevel = NonNullable<PricingSectionData["plans"][number]["levels"]>[number] & {
84
+ offerPrices?: OfferPrice[];
85
+ priceParts?: PriceParts;
86
+ };
87
+ /**
88
+ * The schema's plan card plus the render-time `offerPrices` and `priceParts`,
89
+ * on it and its levels, and the render-time `images` (#12241 D8): the
90
+ * product's Stripe images, the wide layout's side slot when the page types none.
91
+ */
92
+ type PricingPlanCard = Omit<PricingSectionData["plans"][number], "levels"> & {
93
+ levels?: PricingPlanLevel[];
94
+ offerPrices?: OfferPrice[];
95
+ priceParts?: PriceParts;
96
+ images?: Array<{ src: string; alt: string }>;
97
+ };
98
+ /** A bound section's yearly-line and strike choices (#12242 D4, D5). */
99
+ interface CardOptions {
100
+ annualLine?: "billed" | "savings" | "none" | undefined;
101
+ strikeMonthly?: boolean | undefined;
102
+ }
46
103
  /** A bound section's level card, as the page writes it (#12174 D6). */
47
104
  export type OfferingsLevelGroup = NonNullable<PricingSectionData["offeringGroups"]>[number];
48
- /** `AddonCard` ignores `key`; it is carried so a tile names its `{plan}` too. */
49
- type PricingAddonTile = NonNullable<PricingSectionData["addons"]>[number] & {
50
- key: string;
51
- };
52
105
 
53
106
  export interface OfferingsPricingLabels {
54
- /** The CTA label on every card and tile whose product sets none of its own. */
107
+ /** The CTA label on every card whose product sets none of its own. */
55
108
  cta: string;
56
109
  /** The recommended plan's pill and the recommended add-on's eyebrow. */
57
110
  recommended: string;
@@ -65,6 +118,17 @@ export interface OfferingsPricingLabels {
65
118
  depositNote(deposit: string): string;
66
119
  /** The yearly total under a per-month annual price (#12139 D1). */
67
120
  billedYearly(amount: string): string;
121
+ /** A contact card's price when it has no display price (#12193 D5 rule 7). */
122
+ custom: string;
123
+ /** The period words inside a card's unit (#12242 D2): "/mo", "/yr". */
124
+ perMonth: string;
125
+ perYear: string;
126
+ /** The one site pattern joining a period word and a unit label (#12242 AC-9). */
127
+ unitWithLabel(period: string, label: string): string;
128
+ /** The yearly line as a savings percentage (#12242 D4). */
129
+ savings(percent: string): string;
130
+ /** The screen-reader sentence beside a struck monthly price (#12242 D5). */
131
+ regularPrice(regular: string, current: string): string;
68
132
  }
69
133
 
70
134
  export interface OfferingsPricing {
@@ -190,12 +254,20 @@ function stripFormatCharacters(text: string, keepNewlines = false): string {
190
254
  }
191
255
 
192
256
  /** The product's own button label (#12103 D1), else the translated default. */
193
- function ctaLabel(product: OfferingsProduct, labels: OfferingsPricingLabels): string {
257
+ function ctaLabel(
258
+ product: Pick<OfferingsProduct, "ctaLabel">,
259
+ labels: OfferingsPricingLabels,
260
+ ): string {
194
261
  const own = product.ctaLabel && stripFormatCharacters(product.ctaLabel);
195
262
  return own || labels.cta;
196
263
  }
197
264
 
198
- function features(product: OfferingsProduct): string[] {
265
+ /** A card's or tile's title: `ailk_name` when set (#12193 D5 rule 3), else the Stripe name. */
266
+ function titleOf(product: Pick<OfferingsProduct, "shortName" | "name">): string {
267
+ return stripFormatCharacters(product.shortName ?? product.name);
268
+ }
269
+
270
+ function features(product: Pick<OfferingsProduct, "marketingFeatures">): string[] {
199
271
  return product.marketingFeatures
200
272
  .map((feature) => stripFormatCharacters(feature))
201
273
  .filter((feature) => feature.length > 0);
@@ -208,6 +280,11 @@ function priceFor(
208
280
  return product.prices.find((p) => p.period === period);
209
281
  }
210
282
 
283
+ /** Whether any of `product`'s slugs is in `slugs` (#12210 D12). */
284
+ function namedIn(product: OfferingsProduct, slugs: ReadonlySet<string>): boolean {
285
+ return offeringPlanSlugs(product).some((slug) => slugs.has(slug));
286
+ }
287
+
211
288
  /** The Price a card shows in monthly mode: `monthly`, else `yearly`, else `once`. */
212
289
  function shownPrice(product: OfferingsProduct): OfferingsPrice | undefined {
213
290
  return (
@@ -228,6 +305,23 @@ function phrase(
228
305
  return labels.oneTime(amount);
229
306
  }
230
307
 
308
+ /**
309
+ * `prices` as `offerPrices` (#12193 D9): each amount in major units at full
310
+ * precision (`255.67`, `3068`), never a rounded display amount.
311
+ */
312
+ function offerPricesOf(prices: readonly (OfferingsPrice | undefined)[]): OfferPrice[] {
313
+ return prices
314
+ .filter((price): price is OfferingsPrice => price !== undefined)
315
+ .map((price) => {
316
+ const exponent = currencyExponent(price.currency);
317
+ return {
318
+ amount: String(Number((price.amount / 10 ** exponent).toFixed(exponent))),
319
+ currency: price.currency.toUpperCase(),
320
+ period: OFFER_PERIOD_OF[price.period],
321
+ };
322
+ });
323
+ }
324
+
231
325
  /**
232
326
  * Only the first `recommended` Product of a group is highlighted (D4). Each
233
327
  * offering's own flag is read; the shown set's top-level `recommended` ids
@@ -252,6 +346,7 @@ function bundleCard(
252
346
  highlighted: boolean,
253
347
  locale: string,
254
348
  labels: OfferingsPricingLabels,
349
+ siteOrigin: string | undefined,
255
350
  ): PricingPlanCard | null {
256
351
  const once = priceFor(product, PERIOD.once);
257
352
  const monthly = priceFor(required, PERIOD.monthly);
@@ -272,10 +367,11 @@ function bundleCard(
272
367
  }
273
368
  const card: PricingPlanCard = {
274
369
  key: product.plan,
275
- name: stripFormatCharacters(product.name),
370
+ name: titleOf(product),
276
371
  price,
277
372
  features: features(product),
278
373
  cta: { label: ctaLabel(product, labels), href },
374
+ offerPrices: offerPricesOf([once]),
279
375
  };
280
376
  // The deposit note wins the footnote; the terms note shows only without one.
281
377
  // NO_HAND_IMPLEMENT_OK: builder-assessors run for #10030 — the builder is the implementer.
@@ -289,6 +385,7 @@ function bundleCard(
289
385
  const annualHref =
290
386
  monthly && yearly && offeringsBundleHref(once.lookupKey, yearly.lookupKey);
291
387
  if (annualHref) card.annualCtaHref = annualHref;
388
+ Object.assign(card, footnoteOf(product, siteOrigin));
292
389
  if (highlighted) {
293
390
  card.highlighted = true;
294
391
  card.highlightStyle = "pill";
@@ -297,11 +394,38 @@ function bundleCard(
297
394
  return card;
298
395
  }
299
396
 
397
+ /**
398
+ * One product's own card: its bundle card when it `requires` a product of
399
+ * `offerings` (none when that product is missing or has several price points,
400
+ * its recurring Price being ambiguous — #12210 D6 rule 8), else `planCard`.
401
+ * The plans fragment and a comparison table's plan columns (#12246 D3) both
402
+ * build a card here.
403
+ */
404
+ function ownCard(
405
+ product: OfferingsProduct,
406
+ offerings: readonly OfferingsProduct[],
407
+ highlighted: boolean,
408
+ locale: string,
409
+ labels: OfferingsPricingLabels,
410
+ siteOrigin: string | undefined,
411
+ cardOptions: CardOptions = {},
412
+ ): PricingPlanCard | null {
413
+ if (product.requires === undefined)
414
+ return planCard(product, highlighted, locale, labels, siteOrigin, cardOptions);
415
+ const named = new Set([product.requires]);
416
+ const required = offerings.find((o) => namedIn(o, named));
417
+ return required && offeringPointProducts(required).length === 1
418
+ ? bundleCard(product, required, highlighted, locale, labels, siteOrigin)
419
+ : null;
420
+ }
421
+
300
422
  function planCard(
301
423
  product: OfferingsProduct,
302
424
  highlighted: boolean,
303
425
  locale: string,
304
426
  labels: OfferingsPricingLabels,
427
+ siteOrigin: string | undefined,
428
+ options: CardOptions = {},
305
429
  ): PricingPlanCard | null {
306
430
  const shown = shownPrice(product);
307
431
  const href = shown ? offeringsCheckoutHref(shown.lookupKey) : null;
@@ -313,36 +437,67 @@ function planCard(
313
437
  const price: PricingPlanCard["price"] = {};
314
438
  if (monthly) price.monthly = phrase(monthly, locale, labels);
315
439
  // Beside a monthly Price, annual mode shows the yearly Price per month, so
316
- // the two modes compare in one unit (#12139 D1); its total goes in a note.
317
- if (yearly)
440
+ // the two modes compare in one unit (#12139 D1), in whole currency units
441
+ // (#12193 D8); its exact total goes in a note.
442
+ // #12242 D1 — the same amounts as two elements: the amount, and the period
443
+ // word joined to the Stripe unit label by the site's one pattern.
444
+ const noun = product.unitLabel ? stripFormatCharacters(product.unitLabel) : "";
445
+ const unitOf = (period: string) => (noun ? labels.unitWithLabel(period, noun) : period);
446
+ const priceParts: PriceParts = {};
447
+ const monthlyAmount = monthly && formatMinorUnits(monthly.amount, monthly.currency, locale);
448
+ if (monthlyAmount) priceParts.monthly = { amount: monthlyAmount, unit: unitOf(labels.perMonth) };
449
+ if (yearly) {
450
+ const unit = 10 ** currencyExponent(yearly.currency);
451
+ const perMonth = Math.round(yearly.amount / 12 / unit) * unit;
452
+ const perMonthAmount = formatMinorUnits(perMonth, yearly.currency, locale);
318
453
  price.annual = monthly
319
- ? labels.monthly(
320
- formatMinorUnits(
321
- Math.round(yearly.amount / 12),
322
- yearly.currency,
323
- locale,
324
- ),
325
- )
454
+ ? labels.monthly(perMonthAmount)
326
455
  : phrase(yearly, locale, labels);
456
+ priceParts.annual = monthly
457
+ ? { amount: perMonthAmount, unit: unitOf(labels.perMonth) }
458
+ : { amount: formatMinorUnits(yearly.amount, yearly.currency, locale), unit: unitOf(labels.perYear) };
459
+ // #12242 D5 — the standard monthly price struck beside a lower per-month one.
460
+ if (
461
+ options.strikeMonthly === true &&
462
+ monthly &&
463
+ monthlyAmount &&
464
+ monthly.currency === yearly.currency &&
465
+ perMonth < monthly.amount
466
+ ) {
467
+ priceParts.annual.was = monthlyAmount;
468
+ priceParts.annual.wasLabel = labels.regularPrice(monthlyAmount, perMonthAmount);
469
+ }
470
+ }
327
471
  if (once && !monthly && !yearly) price.custom = phrase(once, locale, labels);
328
472
 
329
473
  const card: PricingPlanCard = {
330
474
  key: product.plan,
331
- name: stripFormatCharacters(product.name),
475
+ name: titleOf(product),
332
476
  price,
333
477
  features: features(product),
334
478
  cta: { label: ctaLabel(product, labels), href },
479
+ offerPrices: offerPricesOf([monthly, yearly, once]),
335
480
  };
481
+ if (priceParts.monthly || priceParts.annual) card.priceParts = priceParts;
336
482
  const description =
337
483
  product.description && stripFormatCharacters(product.description, true);
338
484
  if (description) card.description = description;
339
485
  if (product.unitLabel)
340
486
  card.priceUnit = stripFormatCharacters(product.unitLabel);
341
487
  if (product.note) card.priceSubhead = stripFormatCharacters(product.note);
342
- if (monthly && yearly)
343
- card.annualPriceNote = labels.billedYearly(
344
- formatMinorUnits(yearly.amount, yearly.currency, locale),
345
- );
488
+ // #12242 D4 — the yearly line: billed (the default), a savings percentage
489
+ // worked out from the two Stripe prices, or none.
490
+ if (monthly && yearly) {
491
+ if (options.annualLine === "savings") {
492
+ const percent = Math.round((1 - yearly.amount / (12 * monthly.amount)) * 100);
493
+ if (monthly.currency === yearly.currency && percent >= 1)
494
+ card.annualPriceNote = labels.savings(String(percent));
495
+ } else if (options.annualLine !== "none") {
496
+ card.annualPriceNote = labels.billedYearly(
497
+ formatMinorUnits(yearly.amount, yearly.currency, locale),
498
+ );
499
+ }
500
+ }
346
501
  // A deposit plan's footnote (#10030 D10), in its one-time Price's currency;
347
502
  // it takes the footnote over a terms note (the rarer field).
348
503
  if (product.deposit !== undefined && once)
@@ -357,6 +512,10 @@ function planCard(
357
512
  const annualHref =
358
513
  monthly && yearly && offeringsCheckoutHref(yearly.lookupKey);
359
514
  if (annualHref) card.annualCtaHref = annualHref;
515
+ Object.assign(card, footnoteOf(product, siteOrigin));
516
+ // #12241 D8 — the product's Stripe images (the normalizer keeps them only
517
+ // under `ailk_images: on`), each described by the card's title.
518
+ if (product.images) card.images = product.images.map((src) => ({ src, alt: card.name }));
360
519
  if (highlighted) {
361
520
  card.highlighted = true;
362
521
  card.highlightStyle = "pill";
@@ -392,14 +551,18 @@ function splitBlocks(
392
551
  annualPriceNote: _annualPriceNote,
393
552
  priceFootnote: _priceFootnote,
394
553
  priceFootnoteAnnualOnly: _priceFootnoteAnnualOnly,
554
+ offerPrices: _offerPrices,
555
+ priceParts: _priceParts,
395
556
  ...shared
396
557
  } = card;
558
+ // Each block publishes only the Price it sells (#12193 D9).
397
559
  const yearlyBlock: PricingPlanCard = {
398
560
  key: yearly.lookupKey,
399
561
  name: card.name,
400
562
  price: { annual: phrase(yearly, locale, labels) },
401
563
  features: card.features,
402
564
  cta: { label: card.cta.label, href: yearlyHref },
565
+ offerPrices: offerPricesOf([yearly]),
403
566
  };
404
567
  if (card.priceUnit !== undefined) yearlyBlock.priceUnit = card.priceUnit;
405
568
  if (card.priceSubhead !== undefined)
@@ -411,11 +574,21 @@ function splitBlocks(
411
574
  ...shared,
412
575
  price: { monthly: phrase(monthly, locale, labels) },
413
576
  cta: { label: card.cta.label, href: monthlyHref },
577
+ offerPrices: offerPricesOf([monthly]),
414
578
  },
415
579
  yearlyBlock,
416
580
  ];
417
581
  }
418
582
 
583
+ /** Whether `cards` need the billing toggle: a card or level priced both monthly and annually (#12174 D6). */
584
+ function needsToggle(cards: PricingPlanCard[]): boolean {
585
+ return cards.some((card) =>
586
+ [card, ...(card.levels ?? [])].some(
587
+ (shown) => shown.price.monthly !== undefined && shown.price.annual !== undefined,
588
+ ),
589
+ );
590
+ }
591
+
419
592
  /**
420
593
  * The plans fragment in `layout` (#12140 D3): the cards as built, framed for
421
594
  * the layout that renders them. Absent, today's toggle fragment. `product` is
@@ -435,23 +608,17 @@ function plansFragment(
435
608
  variant: "three-tiers-with-toggle",
436
609
  cardLayout: "centered",
437
610
  // #12174 D6 — a level priced both ways turns it on too.
438
- billingToggle: cards.some((card) =>
439
- [card, ...(card.levels ?? [])].some(
440
- (shown) =>
441
- shown.price.monthly !== undefined &&
442
- shown.price.annual !== undefined,
443
- ),
444
- ),
611
+ billingToggle: needsToggle(cards),
445
612
  plans: cards,
446
613
  };
447
614
  // These variants show monthly prices only, so they take no toggle.
448
- case "with-comparison-table":
449
615
  case "two-tiers-with-extra-tier":
450
616
  case "band-hero":
451
617
  return { variant: layout, cardLayout: "centered", plans: cards };
452
- // The variant renders one plan and has no card layout.
618
+ // The variant renders one plan and has no card layout; since #12241 D5
619
+ // its card follows the toggle, as the toggle layout's do.
453
620
  case "single-price-with-details":
454
- return { variant: layout, plans: cards.slice(0, 1) };
621
+ return { variant: layout, billingToggle: needsToggle(cards.slice(0, 1)), plans: cards.slice(0, 1) };
455
622
  case "features-and-plans": {
456
623
  // A level card (#12174 D6) is never split: `product` is undefined then.
457
624
  const split =
@@ -468,13 +635,19 @@ function plansFragment(
468
635
  }
469
636
  }
470
637
 
471
- /** The card fields that change with the level (#12174 D3), as `card` has them. */
638
+ /**
639
+ * The card fields that change with the level (#12174 D3), as `card` has them —
640
+ * its description and `offerPrices` too (#12193 D5 rule 5, D9).
641
+ */
472
642
  function levelOf(card: PricingPlanCard): Omit<PricingPlanLevel, "label" | "key"> {
473
643
  const level: Omit<PricingPlanLevel, "label" | "key"> = {
474
644
  price: card.price,
475
645
  features: card.features,
476
646
  cta: card.cta,
477
647
  };
648
+ if (card.description !== undefined) level.description = card.description;
649
+ if (card.offerPrices !== undefined) level.offerPrices = card.offerPrices;
650
+ if (card.priceParts !== undefined) level.priceParts = card.priceParts;
478
651
  if (card.priceUnit !== undefined) level.priceUnit = card.priceUnit;
479
652
  if (card.priceSubhead !== undefined) level.priceSubhead = card.priceSubhead;
480
653
  if (card.annualPriceNote !== undefined)
@@ -486,6 +659,13 @@ function levelOf(card: PricingPlanCard): Omit<PricingPlanLevel, "label" | "key">
486
659
  return level;
487
660
  }
488
661
 
662
+ /** A level's helper text: its product's `switchHelper` (#12209 D5), else none. */
663
+ function helperOf(product: OfferingsProduct): { helper?: string } {
664
+ return product.switchHelper === undefined
665
+ ? {}
666
+ : { helper: stripFormatCharacters(product.switchHelper) };
667
+ }
668
+
489
669
  /**
490
670
  * The level cards of a bound section's `offeringGroups` (#12174 D6), in the
491
671
  * groups' order. Each level is its plan product's card as `planCard` builds
@@ -493,7 +673,7 @@ function levelOf(card: PricingPlanCard): Omit<PricingPlanLevel, "label" | "key">
493
673
  * is not a shown plain plan (not shown, not a `plan`, a required product or a
494
674
  * bundle) is dropped, and a group with no level left gives no card. The card
495
675
  * takes the group's key, title and description — never a product's name or
496
- * description — and the first level's fields as its own. It is highlighted
676
+ * description, so no level carries one — and the first level's fields as its own. It is highlighted
497
677
  * when one of its levels sells the first recommended plan among the groups'.
498
678
  */
499
679
  function levelCards(
@@ -501,26 +681,48 @@ function levelCards(
501
681
  planProducts: OfferingsProduct[],
502
682
  locale: string,
503
683
  labels: OfferingsPricingLabels,
684
+ siteOrigin: string | undefined,
685
+ cardOptions: CardOptions,
504
686
  ): PricingPlanCard[] {
687
+ // #12210 D6 rule 5 — a level names one slug, so one price point.
505
688
  const byPlan = new Map(
506
- planProducts.filter((p) => p.requires === undefined).map((p) => [p.plan, p]),
689
+ planProducts
690
+ .filter((p) => p.requires === undefined)
691
+ .flatMap(offeringPointProducts)
692
+ .map((p) => [p.plan, p]),
507
693
  );
508
694
  const grouped = groups.flatMap((group) =>
509
695
  group.levels.flatMap((level) => byPlan.get(level.plan) ?? []),
510
696
  );
511
- const recommendedPlan = firstRecommended(grouped);
697
+ // The Recommended product by id, so a group naming any of its price points
698
+ // is highlighted (#12210 D12).
699
+ const recommendedId = grouped.find((p) => p.recommended)?.productId;
512
700
  return groups.flatMap((group) => {
513
- const levels: PricingPlanLevel[] = group.levels.flatMap((level) => {
701
+ const built = group.levels.flatMap((level) => {
514
702
  const product = byPlan.get(level.plan);
515
- const card = product && planCard(product, false, locale, labels);
516
- return card ? [{ label: level.label, key: product.plan, ...levelOf(card) }] : [];
703
+ const card = product && planCard(product, false, locale, labels, siteOrigin, cardOptions);
704
+ if (!card) return [];
705
+ const { description: _description, ...fields } = levelOf(card);
706
+ return [{ card, level: { label: level.label, key: product.plan, ...fields, ...helperOf(product) } }];
517
707
  });
708
+ const levels: PricingPlanLevel[] = built.map((entry) => entry.level);
518
709
  const first = levels[0];
519
710
  if (!first) return [];
520
- const { label: _label, key: _key, ...shown } = first;
521
- const card: PricingPlanCard = { key: group.key, name: group.name, ...shown, levels };
711
+ // #12209 D5 — `helper` is level-only, so the card's own fields leave it out.
712
+ const { label: _label, key: _key, helper: _helper, ...shown } = first;
713
+ // #12243 — the footnote is a card field: the first level's product's.
714
+ const card: PricingPlanCard = {
715
+ key: group.key,
716
+ name: group.name,
717
+ ...shown,
718
+ ...cardFootnote(built[0]?.card),
719
+ ...cardImages(built[0]?.card, group.name),
720
+ levels,
721
+ };
522
722
  if (group.description !== undefined) card.description = group.description;
523
- if (group.levels.some((level) => level.plan === recommendedPlan)) {
723
+ // #12209 D2 — the group's control rides its card to the section.
724
+ if (group.levelSwitchControl !== undefined) card.levelSwitchControl = group.levelSwitchControl;
725
+ if (recommendedId !== undefined && group.levels.some((level) => byPlan.get(level.plan)?.productId === recommendedId)) {
524
726
  card.highlighted = true;
525
727
  card.highlightStyle = "pill";
526
728
  card.highlightLabel = labels.recommended;
@@ -529,36 +731,238 @@ function levelCards(
529
731
  });
530
732
  }
531
733
 
532
- function addonTile(
734
+ /**
735
+ * An add-on's card (#12241 D3): its plan card — description, both prices,
736
+ * unit, note and checkout links — plus its eyebrow, the seller's
737
+ * `ailk_eyebrow`, which on the recommended add-on is the Recommended label.
738
+ * Never highlighted, so the pill, the filled button and `?plan=` stay
739
+ * plans-only.
740
+ */
741
+ function addonCard(
533
742
  product: OfferingsProduct,
534
- highlighted: boolean,
743
+ recommended: boolean,
535
744
  locale: string,
536
745
  labels: OfferingsPricingLabels,
537
- ): PricingAddonTile | null {
538
- const shown = shownPrice(product);
539
- const href = shown && offeringsCheckoutHref(shown.lookupKey);
540
- if (!shown || !href) return null;
746
+ siteOrigin: string | undefined,
747
+ ): PricingPlanCard | null {
748
+ const card = planCard(product, false, locale, labels, siteOrigin);
749
+ if (!card) return null;
750
+ const eyebrow = recommended
751
+ ? labels.recommended
752
+ : product.eyebrow && stripFormatCharacters(product.eyebrow);
753
+ if (eyebrow) card.eyebrow = eyebrow;
754
+ return card;
755
+ }
541
756
 
542
- const tile: PricingAddonTile = {
543
- key: product.plan,
544
- name: stripFormatCharacters(product.name),
545
- price: phrase(shown, locale, labels),
546
- features: features(product),
547
- cta: { label: ctaLabel(product, labels), href },
757
+ /**
758
+ * A contact's link (#12193 D5 rule 7; contract 8879 §3.6, T3's one exception).
759
+ * The stored URL is `https:` with no credentials (the normalizer's parse).
760
+ * Internal — `pathname + search + hash` — only when its origin is
761
+ * `siteOrigin` and its path starts with exactly one `/`; external (a new tab,
762
+ * `noopener noreferrer`) otherwise. `null` — no card or tile — for a path that
763
+ * does not percent-decode, or a same-origin one under `/api/`, so a contact is
764
+ * never a button onto one of our own routes such as the checkout. Never throws.
765
+ */
766
+ function contactLink(
767
+ raw: string,
768
+ siteOrigin: string | undefined,
769
+ ): { href: string; external?: true } | null {
770
+ let url: URL;
771
+ let decoded: string;
772
+ try {
773
+ url = new URL(raw);
774
+ decoded = decodeURIComponent(url.pathname).toLowerCase();
775
+ } catch {
776
+ return null;
777
+ }
778
+ if (url.origin === siteOrigin) {
779
+ if (/^\/api(?:\/|$)/.test(decoded.replace(/^[/\\]+/, "/"))) return null;
780
+ if (/^\/(?![/\\])/.test(url.pathname)) return { href: url.pathname + url.search + url.hash };
781
+ }
782
+ return { href: url.href, external: true };
783
+ }
784
+
785
+ /**
786
+ * A plan's card footnote (#12243), its format characters stripped, and its
787
+ * link through `contactLink` — the contact URL's rule, so a same-origin URL is
788
+ * an internal path, another origin's the full URL; a link `contactLink` gives
789
+ * none for is dropped and the footnote kept as text alone.
790
+ */
791
+ function footnoteOf(
792
+ product: Pick<OfferingsProduct, "footnote" | "footnoteLink">,
793
+ siteOrigin: string | undefined,
794
+ ): Pick<PricingPlanCard, "footnote" | "footnoteLink"> {
795
+ if (product.footnote === undefined) return {};
796
+ const footnote = stripFormatCharacters(product.footnote);
797
+ const { footnoteLink } = product;
798
+ const link = footnoteLink && contactLink(footnoteLink.url, siteOrigin);
799
+ return footnoteLink && link
800
+ ? { footnote, footnoteLink: { label: stripFormatCharacters(footnoteLink.label), href: link.href } }
801
+ : { footnote };
802
+ }
803
+
804
+ /** `card`'s footnote and its link, for the level card it leads (#12243 — a card field, never a level's). */
805
+ function cardFootnote(card: PricingPlanCard | undefined): Pick<PricingPlanCard, "footnote" | "footnoteLink"> {
806
+ return {
807
+ ...(card?.footnote !== undefined && { footnote: card.footnote }),
808
+ ...(card?.footnoteLink !== undefined && { footnoteLink: card.footnoteLink }),
548
809
  };
549
- if (product.unitLabel)
550
- tile.qualifier = stripFormatCharacters(product.unitLabel);
551
- // #12103 D5 — the seller's eyebrow and note; the recommended add-on's
552
- // eyebrow stays the Recommended label, the one place a tile shows it.
553
- const eyebrow = product.eyebrow && stripFormatCharacters(product.eyebrow);
554
- if (eyebrow) tile.eyebrow = eyebrow;
555
- const note = product.note && stripFormatCharacters(product.note);
556
- if (note) tile.note = note;
810
+ }
811
+
812
+ /** `card`'s Stripe images for the level card it leads, described by that card's `title` (#12241 D8 — a card field, never a level's). */
813
+ function cardImages(card: PricingPlanCard | undefined, title: string): Pick<PricingPlanCard, "images"> {
814
+ return card?.images ? { images: card.images.map(({ src }) => ({ src, alt: title })) } : {};
815
+ }
816
+
817
+ /** A plan contact's card (#12193 D5 rule 7): no Price, so no `Offer` and never highlighted. */
818
+ function contactCard(
819
+ contact: OfferingsContactProduct,
820
+ siteOrigin: string | undefined,
821
+ labels: OfferingsPricingLabels,
822
+ ): PricingPlanCard | null {
823
+ const link = contactLink(contact.url, siteOrigin);
824
+ if (!link) return null;
825
+ const card: PricingPlanCard = {
826
+ key: contact.plan,
827
+ name: stripFormatCharacters(contact.tier ?? contact.shortName ?? contact.name),
828
+ price: { custom: contact.priceText ? stripFormatCharacters(contact.priceText) : labels.custom },
829
+ features: features(contact),
830
+ cta: { label: ctaLabel(contact, labels), ...link },
831
+ offerPrices: [],
832
+ };
833
+ const description = contact.description && stripFormatCharacters(contact.description, true);
834
+ if (description) card.description = description;
835
+ return Object.assign(card, footnoteOf(contact, siteOrigin));
836
+ }
837
+
838
+ /** `ailkOrder`, null last. */
839
+ function compareOrder(a: number | null, b: number | null): number {
840
+ if (a === b) return 0;
841
+ if (a === null) return 1;
842
+ if (b === null) return -1;
843
+ return a - b;
844
+ }
845
+
846
+ /** Snapshot order (#12193 D5 rule 4): `ailkOrder` null last, then name, then id. */
847
+ function compareProducts(a: OfferingsProduct, b: OfferingsProduct): number {
848
+ return (
849
+ compareOrder(a.ailkOrder, b.ailkOrder) ||
850
+ (a.name < b.name ? -1 : a.name > b.name ? 1 : 0) ||
851
+ (a.productId < b.productId ? -1 : a.productId > b.productId ? 1 : 0)
852
+ );
853
+ }
854
+
855
+ /** The longest select item secondary label (#12209 D3, the level `detail`). */
856
+ const LEVEL_DETAIL_MAX = 24;
857
+
858
+ /**
859
+ * One tier's card (#12193 D5 rules 2–5): its plans in snapshot order, at most
860
+ * `levelLimit` (four, or twenty for a select, #12209 D8), each its own card as `planCard` builds it, labelled `level ?? shortName
861
+ * ?? name` — a repeated label falls back to `shortName ?? name`, and one still
862
+ * repeated is dropped. Two or more levels make a level card titled `name`,
863
+ * keyed and described by its first level; one makes a plain card titled
864
+ * `name`. Nothing comes from the page.
865
+ *
866
+ * #12210 D6 rules 2–4, 6 — a multi-point member is one level per price point,
867
+ * in product then point order, labelled by the point's label else its price
868
+ * phrase (a repeat falls back to the phrase, one still repeated is dropped),
869
+ * with the phrase as the select item's `detail`. A card holds at most 20
870
+ * levels; one with points and more than four levels takes the select. A
871
+ * multi-point product's own card is this card with itself as the one member.
872
+ */
873
+ function tierCard(
874
+ name: string,
875
+ members: OfferingsProduct[],
876
+ highlighted: boolean,
877
+ locale: string,
878
+ labels: OfferingsPricingLabels,
879
+ levelLimit: number,
880
+ siteOrigin: string | undefined,
881
+ cardOptions: CardOptions,
882
+ ): PricingPlanCard | null {
883
+ const title = stripFormatCharacters(name);
884
+ const levels: PricingPlanLevel[] = [];
885
+ // #12243 — the footnote is a card field: the first level's product's.
886
+ let firstCard: PricingPlanCard | undefined;
887
+ // A member with price points sends the card to the select, so the tier keeps
888
+ // up to the select's 20 levels rather than cutting its members at four.
889
+ const memberLimit = members.some((m) => offeringPointProducts(m).length > 1) ? PRICING_SELECT_LEVELS_MAX : levelLimit;
890
+ const entries = [...members]
891
+ .sort(compareProducts)
892
+ .slice(0, memberLimit)
893
+ .flatMap((product) => offeringPointProducts(product).map((point) => ({ product, point })))
894
+ .slice(0, PRICING_SELECT_LEVELS_MAX);
895
+ const hasPoints = entries.some(({ product, point }) => point !== product);
896
+ for (const { product, point } of entries) {
897
+ const card = planCard(point, false, locale, labels, siteOrigin, cardOptions);
898
+ const shown = shownPrice(point);
899
+ if (!card || !shown) continue;
900
+ const taken = new Set(levels.map((level) => level.label));
901
+ const isPoint = point !== product;
902
+ const pricePhrase = phrase(shown, locale, labels);
903
+ const pointLabel = offeringPricePoints(point.prices)[0]?.label;
904
+ const own = isPoint
905
+ ? pointLabel && stripFormatCharacters(pointLabel)
906
+ : product.level === undefined
907
+ ? undefined
908
+ : stripFormatCharacters(product.level);
909
+ const label = [own, isPoint ? pricePhrase : titleOf(product)].find(
910
+ (text): text is string => text !== undefined && text.length > 0 && !taken.has(text),
911
+ );
912
+ if (label === undefined) continue;
913
+ // #12241 D6 — a level's detail is its Price's `ailk_detail`: a point's
914
+ // own Price's, a tier level's first of monthly, yearly, once to carry
915
+ // one. Without one a point keeps its price phrase, as before.
916
+ const priceDetail = isPoint
917
+ ? shown.detail
918
+ : [PERIOD.monthly, PERIOD.yearly, PERIOD.once].map((period) => priceFor(point, period)?.detail).find(Boolean);
919
+ const detail = priceDetail
920
+ ? { detail: priceDetail }
921
+ : isPoint && label !== pricePhrase && [...pricePhrase].length <= LEVEL_DETAIL_MAX
922
+ ? { detail: pricePhrase }
923
+ : {};
924
+ levels.push({ label, key: point.plan, ...levelOf(card), ...helperOf(product), ...detail });
925
+ firstCard ??= card;
926
+ }
927
+ const first = levels[0];
928
+ if (!first) return null;
929
+ // #12209 D3, D5 — `helper` and `detail` are level-only, so the card's own fields leave them out.
930
+ const { label: _label, helper: _helper, detail: _detail, ...shown } = first;
931
+ const card: PricingPlanCard = {
932
+ ...shown,
933
+ name: title,
934
+ ...cardFootnote(firstCard),
935
+ ...cardImages(firstCard, title),
936
+ ...(levels.length > 1 ? { levels } : {}),
937
+ };
938
+ // #12210 D6 rule 6 — segments keep four levels (#12209 AC 8).
939
+ if (hasPoints && levels.length > PRICING_SEGMENT_LEVELS_MAX) card.levelSwitchControl = "select";
557
940
  if (highlighted) {
558
- tile.eyebrow = labels.recommended;
559
- tile.checkTone = "primary";
941
+ card.highlighted = true;
942
+ card.highlightStyle = "pill";
943
+ card.highlightLabel = labels.recommended;
560
944
  }
561
- return tile;
945
+ return card;
946
+ }
947
+
948
+ /** A card or tile with what orders it among its section's (#12193 D5 rule 6). */
949
+ interface Placed<T> {
950
+ item: T;
951
+ order: number | null;
952
+ contact: boolean;
953
+ }
954
+
955
+ /** Cards by `ailkOrder` (null last), a plan card before a contact on a tie, else as built. */
956
+ function inOrder<T>(placed: Placed<T>[]): T[] {
957
+ return placed
958
+ .map((entry, index) => ({ entry, index }))
959
+ .sort(
960
+ (a, b) =>
961
+ compareOrder(a.entry.order, b.entry.order) ||
962
+ Number(a.entry.contact) - Number(b.entry.contact) ||
963
+ a.index - b.index,
964
+ )
965
+ .map(({ entry }) => entry.item);
562
966
  }
563
967
 
564
968
  // #8927 D3 — `GET /v1/content/shown-offerings` sends the shown set without
@@ -575,11 +979,30 @@ function isPresent<T>(value: T | null): value is T {
575
979
  return value !== null;
576
980
  }
577
981
 
982
+ /** Whether `collection` names `value`'s collection, compared lowercased (#12193 D5 rule 1). */
983
+ function inCollection(value: string | undefined, collection: string): boolean {
984
+ return value !== undefined && value.toLowerCase() === collection.toLowerCase();
985
+ }
986
+
987
+ /**
988
+ * The plan slugs of every shown product and contact of `collection` (#12193
989
+ * D5): the cards a collection section shows, so the page's unbound plans slot
990
+ * leaves them out. `[]` for a shown set that does not parse.
991
+ */
992
+ export function collectionPlans(shownSet: unknown, collection: string): string[] {
993
+ const parsed = shownSetSchema.safeParse(shownSet);
994
+ if (!parsed.success) return [];
995
+ return [...parsed.data.offerings, ...(parsed.data.contacts ?? [])]
996
+ .filter((o) => o.ailkGroup !== "offer" && inCollection(o.collection, collection))
997
+ .map((o) => o.plan);
998
+ }
999
+
578
1000
  /**
579
1001
  * The products whose `{plan}` is in `plans`, plus every product a kept one
580
1002
  * `requires`, in the snapshot's order (#10044 D4); `plans` absent → all.
581
1003
  * One level of `requires` is followed: a required product is sold only
582
- * inside its bundle and requires nothing itself (#10028 decision 6).
1004
+ * inside its bundle and requires nothing itself (#10028 decision 6). A
1005
+ * product is matched by any of its price points' slugs (#12210 D6 rule 7).
583
1006
  */
584
1007
  function narrowToPlans(
585
1008
  offerings: OfferingsProduct[],
@@ -588,12 +1011,12 @@ function narrowToPlans(
588
1011
  if (plans === undefined) return offerings;
589
1012
  const listed = new Set(plans);
590
1013
  const kept = new Set(
591
- offerings.filter((o) => listed.has(o.plan)).map((o) => o.plan),
1014
+ offerings.filter((o) => namedIn(o, listed)).flatMap(offeringPlanSlugs),
592
1015
  );
593
1016
  for (const o of offerings) {
594
- if (kept.has(o.plan) && o.requires !== undefined) kept.add(o.requires);
1017
+ if (namedIn(o, kept) && o.requires !== undefined) kept.add(o.requires);
595
1018
  }
596
- return offerings.filter((o) => kept.has(o.plan));
1019
+ return offerings.filter((o) => namedIn(o, kept));
597
1020
  }
598
1021
 
599
1022
  /**
@@ -616,6 +1039,23 @@ function narrowToPlans(
616
1039
  * `levelGroups` (#12174 D6) makes the plan cards a bound section's level
617
1040
  * cards, one per group (`levelCards`), in place of one card per plan. Absent,
618
1041
  * the cards are built exactly as before.
1042
+ *
1043
+ * `tiers` (#12193 D5, a selecting bound section) groups plain plans sharing a
1044
+ * Stripe `tier` into one card each (`tierCard`). `collection` maps every shown
1045
+ * product of that collection in place of `plans`, with its contacts as
1046
+ * contact cards and tiles, linked by `contactLink` against `siteOrigin`, as
1047
+ * every footnote link is (#12243).
1048
+ * Cards and tiles are ordered by `ailkOrder`. Absent, the cards are built
1049
+ * exactly as before, and no contact is shown.
1050
+ *
1051
+ * With `tiers`, `levelLimit` (#12209 D8) caps a tier card's levels — four
1052
+ * (the default, segments) or twenty (a select) — and `groupTiers: false`
1053
+ * (#12209 D11) makes every plan its own card, whatever its tier.
1054
+ *
1055
+ * `contactPlans` (#12238, operator 2026-11-23) is a section's own
1056
+ * `offeringPlans`: a shown contact it names by slug becomes a contact card or
1057
+ * tile, as a collection's does. Read only without `collection`; the page's
1058
+ * `plans` never shows a contact.
619
1059
  */
620
1060
  export function offeringsPricing(
621
1061
  shownSet: unknown,
@@ -626,13 +1066,26 @@ export function offeringsPricing(
626
1066
  exclude?: readonly string[] | undefined;
627
1067
  layout?: OfferingsLayout | undefined;
628
1068
  levelGroups?: readonly OfferingsLevelGroup[] | undefined;
1069
+ collection?: string | undefined;
1070
+ tiers?: boolean | undefined;
1071
+ levelLimit?: number | undefined;
1072
+ groupTiers?: boolean | undefined;
1073
+ siteOrigin?: string | undefined;
1074
+ contactPlans?: readonly string[] | undefined;
1075
+ annualLine?: CardOptions["annualLine"];
1076
+ strikeMonthly?: boolean | undefined;
629
1077
  },
630
1078
  ): OfferingsPricing | null {
631
1079
  const parsed = shownSetSchema.safeParse(shownSet);
632
1080
  if (!parsed.success) return null;
633
1081
  const { state, offerings: shown } = parsed.data;
634
- if (state !== "current" || shown.length === 0) return null;
635
- const { locale, labels } = options;
1082
+ const { collection, siteOrigin, locale, labels } = options;
1083
+ const cardOptions: CardOptions = { annualLine: options.annualLine, strikeMonthly: options.strikeMonthly };
1084
+ const named = new Set(options.contactPlans);
1085
+ const contacts = (parsed.data.contacts ?? []).filter((c) =>
1086
+ collection === undefined ? named.has(c.plan) : inCollection(c.collection, collection),
1087
+ );
1088
+ if (state !== "current" || (shown.length === 0 && contacts.length === 0)) return null;
636
1089
 
637
1090
  // #10028 D9 — a product some shown plan requires is sold only inside that
638
1091
  // bundle (decision 6), so it gets no card of its own. Read over the whole
@@ -640,41 +1093,86 @@ export function offeringsPricing(
640
1093
  const requiredPlans = new Set(
641
1094
  shown.map((o) => o.requires).filter((plan) => plan !== undefined),
642
1095
  );
643
- const offerings = narrowToPlans(shown, options.plans);
1096
+ const offerings = narrowToPlans(
1097
+ shown,
1098
+ collection === undefined ? options.plans : collectionPlans(parsed.data, collection),
1099
+ );
644
1100
  const excluded = new Set(options.exclude);
645
1101
  // #11166 — the two group reads are exact, so an `offer` falls into neither.
646
1102
  const planProducts = offerings.filter(
647
1103
  (o) =>
648
1104
  o.ailkGroup === "plan" &&
649
- !requiredPlans.has(o.plan) &&
650
- !excluded.has(o.plan),
1105
+ !namedIn(o, requiredPlans) &&
1106
+ !namedIn(o, excluded),
651
1107
  );
652
1108
  const addonProducts = offerings.filter((o) => o.ailkGroup === "addon");
653
1109
  const recommendedPlan = firstRecommended(planProducts);
654
1110
  const recommendedAddon = firstRecommended(addonProducts);
655
1111
 
1112
+ // #12193 D5 rule 2 — with `tiers`, plain plans sharing a tier are one card,
1113
+ // placed where its first member is.
1114
+ // #12209 D11 — `groupTiers: false` leaves every plan its own card.
1115
+ const tierOf = (p: OfferingsProduct) =>
1116
+ options.tiers && options.groupTiers !== false && p.requires === undefined ? p.tier : undefined;
1117
+ const placedPlans: Placed<PricingPlanCard | null>[] = [];
1118
+ const seenTiers = new Set<string>();
1119
+ const inSnapshotOrder = options.tiers ? [...planProducts].sort(compareProducts) : planProducts;
1120
+ for (const p of inSnapshotOrder) {
1121
+ const tier = tierOf(p);
1122
+ if (tier !== undefined) {
1123
+ if (seenTiers.has(tier)) continue;
1124
+ seenTiers.add(tier);
1125
+ const members = planProducts.filter((m) => tierOf(m) === tier);
1126
+ placedPlans.push({
1127
+ item: tierCard(
1128
+ tier,
1129
+ members,
1130
+ members.some((m) => m.plan === recommendedPlan),
1131
+ locale,
1132
+ labels,
1133
+ options.levelLimit ?? PRICING_SEGMENT_LEVELS_MAX,
1134
+ siteOrigin,
1135
+ cardOptions,
1136
+ ),
1137
+ order: p.ailkOrder,
1138
+ contact: false,
1139
+ });
1140
+ continue;
1141
+ }
1142
+ // #12210 D6 rules 3, 8 — a multi-point product is one level card of its
1143
+ // points; anything else is its own card (`ownCard`).
1144
+ const item =
1145
+ p.requires === undefined && offeringPointProducts(p).length > 1
1146
+ ? tierCard(titleOf(p), [p], p.plan === recommendedPlan, locale, labels, 1, siteOrigin, cardOptions)
1147
+ : ownCard(p, offerings, p.plan === recommendedPlan, locale, labels, siteOrigin, cardOptions);
1148
+ placedPlans.push({ item, order: p.ailkOrder, contact: false });
1149
+ }
1150
+ for (const c of contacts.filter((c) => c.ailkGroup === "plan")) {
1151
+ placedPlans.push({ item: contactCard(c, siteOrigin, labels), order: c.ailkOrder, contact: true });
1152
+ }
1153
+ // Outside tier mode the cards keep the snapshot's order exactly, as before.
1154
+ const ordered = <T>(placed: Placed<T>[]) =>
1155
+ options.tiers ? inOrder(placed) : placed.map((entry) => entry.item);
656
1156
  const plans = options.levelGroups
657
- ? levelCards(options.levelGroups, planProducts, locale, labels)
658
- : planProducts
659
- .map((p) => {
660
- const required =
661
- p.requires === undefined
662
- ? undefined
663
- : offerings.find((o) => o.plan === p.requires);
664
- if (p.requires !== undefined) {
665
- return required ? bundleCard(p, required, p.plan === recommendedPlan, locale, labels) : null;
666
- }
667
- return planCard(p, p.plan === recommendedPlan, locale, labels);
668
- })
669
- .filter(isPresent);
670
- const addons = addonProducts
671
- .map((p) => addonTile(p, p.plan === recommendedAddon, locale, labels))
672
- .filter(isPresent);
1157
+ ? levelCards(options.levelGroups, planProducts, locale, labels, siteOrigin, cardOptions)
1158
+ : ordered(placedPlans).filter(isPresent);
1159
+ // #12241 D3 — add-ons are cards, an add-on contact a contact card.
1160
+ const addons = ordered<PricingPlanCard | null>([
1161
+ ...addonProducts.map((p) => ({
1162
+ item: addonCard(p, p.plan === recommendedAddon, locale, labels, siteOrigin),
1163
+ order: p.ailkOrder,
1164
+ contact: false,
1165
+ })),
1166
+ ...contacts
1167
+ .filter((c) => c.ailkGroup === "addon")
1168
+ .map((c) => ({ item: contactCard(c, siteOrigin, labels), order: c.ailkOrder, contact: true })),
1169
+ ]).filter(isPresent);
673
1170
 
674
1171
  // Each card is keyed by its product's `{plan}`, so a lone card names its product.
675
- // A level card's key is the group's, so it names no product (#12174 D6).
1172
+ // A level card's key is the group's, so it names no product (#12174 D6); a
1173
+ // lone level card is never split either (#12210 D6 rule 8).
676
1174
  const product =
677
- plans.length === 1 && !options.levelGroups
1175
+ plans.length === 1 && !options.levelGroups && plans[0]!.levels === undefined
678
1176
  ? planProducts.find((p) => p.plan === plans[0]!.key)
679
1177
  : undefined;
680
1178
  return {
@@ -682,6 +1180,56 @@ export function offeringsPricing(
682
1180
  plans.length > 0
683
1181
  ? plansFragment(plans, options.layout, product, locale, labels)
684
1182
  : null,
685
- addons: addons.length > 0 ? { variant: "addons", plans: [], addons } : null,
1183
+ addons:
1184
+ addons.length > 0
1185
+ ? { variant: "addons", billingToggle: needsToggle(addons), plans: addons }
1186
+ : null,
686
1187
  };
687
1188
  }
1189
+
1190
+ /**
1191
+ * Each of `slugs` the shown set shows as a plan column (#12246 D3), by slug:
1192
+ * a slug `planColumnSlugs` holds, as the card its point product would get —
1193
+ * `bundleCard` for a product that `requires` one (no column when that bundle
1194
+ * gives no card), else `planCard` (`ownCard`). One column per slug, so a
1195
+ * price point shows its own price. Every string is a card's, so it reaches
1196
+ * markup as React text only (T2), and every link is a card's own checkout
1197
+ * link (T3). Empty for a set that does not parse or is not `current`; never
1198
+ * reads the page's `plans`.
1199
+ */
1200
+ export function offeringsPlanColumns(
1201
+ shownSet: unknown,
1202
+ slugs: Iterable<string>,
1203
+ options: { locale: string; labels: OfferingsPricingLabels },
1204
+ ): Map<string, PlanColumnOffering> {
1205
+ const columns = new Map<string, PlanColumnOffering>();
1206
+ const parsed = shownSetSchema.safeParse(shownSet);
1207
+ if (!parsed.success || parsed.data.state !== "current") return columns;
1208
+ const shown = parsed.data.offerings;
1209
+ const shownSlugs = planColumnSlugs(shown);
1210
+ const products = shown.filter((o) => o.ailkGroup === "plan" && namedIn(o, shownSlugs));
1211
+ const recommendedPlan = firstRecommended(products);
1212
+ const { locale, labels } = options;
1213
+ for (const slug of new Set(slugs)) {
1214
+ if (!shownSlugs.has(slug)) continue;
1215
+ const product = products.find((o) => offeringPlanSlugs(o).includes(slug));
1216
+ const point = product && offeringPointProducts(product).find((p) => p.plan === slug);
1217
+ // A column shows the card's name, price and checkout link only, so the
1218
+ // card's footnote link (`siteOrigin`) and display options never matter here.
1219
+ const card = point && ownCard(point, shown, false, locale, labels, undefined);
1220
+ if (!product || !card) continue;
1221
+ const { monthly, annual, custom } = card.price;
1222
+ columns.set(slug, {
1223
+ name: card.name,
1224
+ price: {
1225
+ ...(monthly !== undefined ? { monthly } : {}),
1226
+ ...(annual !== undefined ? { annual } : {}),
1227
+ ...(custom !== undefined ? { custom } : {}),
1228
+ },
1229
+ cta: { label: card.cta.label, href: card.cta.href },
1230
+ ...(card.annualCtaHref !== undefined ? { annualCtaHref: card.annualCtaHref } : {}),
1231
+ ...(product.plan === recommendedPlan ? { recommended: true as const } : {}),
1232
+ });
1233
+ }
1234
+ return columns;
1235
+ }