create-ailk 0.46.2 → 0.46.3

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,8 @@
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), by `contactLink`'s rule.
21
22
  * - §3.7 — `yearly` reads as annual and `once` as one-time at render, never
22
23
  * in the key (D2).
23
24
  *
@@ -25,13 +26,33 @@
25
26
  * and the period phrasings arrive in `labels` (D9, customer-facing-i18n). A
26
27
  * seller's own button label (`ctaLabel`, Stripe `ailk_cta`) and an add-on's
27
28
  * eyebrow (`ailk_eyebrow`) are seller-authored text shown as written, as the
28
- * product name is (#12103 D1, D5).
29
+ * product name is (#12103 D1, D5), and so are the card keys and a contact's
30
+ * display price (#12193 D1, D2).
31
+ *
32
+ * #12193 — a selecting bound section passes `tiers` (and `collection`): plans
33
+ * sharing a Stripe `ailk_tier` become one level card, and a collection's
34
+ * contacts (priceless products with a URL) become contact cards and tiles.
35
+ * Every card and level carries `offerPrices`, the render-time Prices the
36
+ * JSON-LD reads (D9), never a stored field.
37
+ *
38
+ * #12210 — a plan product with several price points (one `{plan}` slug per
39
+ * point) is one level card whose levels are its points: each level's amount,
40
+ * label and checkout link come from its Price, everything else from the
41
+ * product (`offeringPointProducts`). A product is named by any of its slugs.
29
42
  */
30
43
  import {
44
+ PRICING_SEGMENT_LEVELS_MAX,
45
+ PRICING_SELECT_LEVELS_MAX,
46
+ OFFER_PERIOD_OF,
47
+ offeringPlanSlugs,
48
+ offeringPointProducts,
49
+ offeringPricePoints,
31
50
  parseLookupKey,
32
51
  lookupKeyPeriodSchema,
33
52
  workspaceShownSetSchema,
34
53
  type LookupKeyPeriod,
54
+ type OfferPrice,
55
+ type OfferingsContactProduct,
35
56
  type OfferingsPrice,
36
57
  type OfferingsProduct,
37
58
  type PageSection,
@@ -41,8 +62,18 @@ import {
41
62
  const PERIOD = lookupKeyPeriodSchema.enum;
42
63
 
43
64
  type PricingSectionData = Extract<PageSection, { type: "pricing" }>["data"];
44
- type PricingPlanCard = PricingSectionData["plans"][number];
45
- type PricingPlanLevel = NonNullable<PricingPlanCard["levels"]>[number];
65
+
66
+ // #12193 D9 — `offerPrices` (`OfferPrice`, the contribution's shape) is a
67
+ // render-time field, never in the stored section schema, so no author or agent
68
+ // can declare one.
69
+ type PricingPlanLevel = NonNullable<PricingSectionData["plans"][number]["levels"]>[number] & {
70
+ offerPrices?: OfferPrice[];
71
+ };
72
+ /** The schema's plan card plus the render-time `offerPrices`, on it and its levels. */
73
+ type PricingPlanCard = Omit<PricingSectionData["plans"][number], "levels"> & {
74
+ levels?: PricingPlanLevel[];
75
+ offerPrices?: OfferPrice[];
76
+ };
46
77
  /** A bound section's level card, as the page writes it (#12174 D6). */
47
78
  export type OfferingsLevelGroup = NonNullable<PricingSectionData["offeringGroups"]>[number];
48
79
  /** `AddonCard` ignores `key`; it is carried so a tile names its `{plan}` too. */
@@ -65,6 +96,8 @@ export interface OfferingsPricingLabels {
65
96
  depositNote(deposit: string): string;
66
97
  /** The yearly total under a per-month annual price (#12139 D1). */
67
98
  billedYearly(amount: string): string;
99
+ /** A contact card's price when it has no display price (#12193 D5 rule 7). */
100
+ custom: string;
68
101
  }
69
102
 
70
103
  export interface OfferingsPricing {
@@ -190,12 +223,20 @@ function stripFormatCharacters(text: string, keepNewlines = false): string {
190
223
  }
191
224
 
192
225
  /** The product's own button label (#12103 D1), else the translated default. */
193
- function ctaLabel(product: OfferingsProduct, labels: OfferingsPricingLabels): string {
226
+ function ctaLabel(
227
+ product: Pick<OfferingsProduct, "ctaLabel">,
228
+ labels: OfferingsPricingLabels,
229
+ ): string {
194
230
  const own = product.ctaLabel && stripFormatCharacters(product.ctaLabel);
195
231
  return own || labels.cta;
196
232
  }
197
233
 
198
- function features(product: OfferingsProduct): string[] {
234
+ /** A card's or tile's title: `ailk_name` when set (#12193 D5 rule 3), else the Stripe name. */
235
+ function titleOf(product: Pick<OfferingsProduct, "shortName" | "name">): string {
236
+ return stripFormatCharacters(product.shortName ?? product.name);
237
+ }
238
+
239
+ function features(product: Pick<OfferingsProduct, "marketingFeatures">): string[] {
199
240
  return product.marketingFeatures
200
241
  .map((feature) => stripFormatCharacters(feature))
201
242
  .filter((feature) => feature.length > 0);
@@ -208,6 +249,11 @@ function priceFor(
208
249
  return product.prices.find((p) => p.period === period);
209
250
  }
210
251
 
252
+ /** Whether any of `product`'s slugs is in `slugs` (#12210 D12). */
253
+ function namedIn(product: OfferingsProduct, slugs: ReadonlySet<string>): boolean {
254
+ return offeringPlanSlugs(product).some((slug) => slugs.has(slug));
255
+ }
256
+
211
257
  /** The Price a card shows in monthly mode: `monthly`, else `yearly`, else `once`. */
212
258
  function shownPrice(product: OfferingsProduct): OfferingsPrice | undefined {
213
259
  return (
@@ -228,6 +274,23 @@ function phrase(
228
274
  return labels.oneTime(amount);
229
275
  }
230
276
 
277
+ /**
278
+ * `prices` as `offerPrices` (#12193 D9): each amount in major units at full
279
+ * precision (`255.67`, `3068`), never a rounded display amount.
280
+ */
281
+ function offerPricesOf(prices: readonly (OfferingsPrice | undefined)[]): OfferPrice[] {
282
+ return prices
283
+ .filter((price): price is OfferingsPrice => price !== undefined)
284
+ .map((price) => {
285
+ const exponent = currencyExponent(price.currency);
286
+ return {
287
+ amount: String(Number((price.amount / 10 ** exponent).toFixed(exponent))),
288
+ currency: price.currency.toUpperCase(),
289
+ period: OFFER_PERIOD_OF[price.period],
290
+ };
291
+ });
292
+ }
293
+
231
294
  /**
232
295
  * Only the first `recommended` Product of a group is highlighted (D4). Each
233
296
  * offering's own flag is read; the shown set's top-level `recommended` ids
@@ -272,10 +335,11 @@ function bundleCard(
272
335
  }
273
336
  const card: PricingPlanCard = {
274
337
  key: product.plan,
275
- name: stripFormatCharacters(product.name),
338
+ name: titleOf(product),
276
339
  price,
277
340
  features: features(product),
278
341
  cta: { label: ctaLabel(product, labels), href },
342
+ offerPrices: offerPricesOf([once]),
279
343
  };
280
344
  // The deposit note wins the footnote; the terms note shows only without one.
281
345
  // NO_HAND_IMPLEMENT_OK: builder-assessors run for #10030 — the builder is the implementer.
@@ -313,25 +377,29 @@ function planCard(
313
377
  const price: PricingPlanCard["price"] = {};
314
378
  if (monthly) price.monthly = phrase(monthly, locale, labels);
315
379
  // 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)
380
+ // the two modes compare in one unit (#12139 D1), in whole currency units
381
+ // (#12193 D8); its exact total goes in a note.
382
+ if (yearly) {
383
+ const unit = 10 ** currencyExponent(yearly.currency);
318
384
  price.annual = monthly
319
385
  ? labels.monthly(
320
386
  formatMinorUnits(
321
- Math.round(yearly.amount / 12),
387
+ Math.round(yearly.amount / 12 / unit) * unit,
322
388
  yearly.currency,
323
389
  locale,
324
390
  ),
325
391
  )
326
392
  : phrase(yearly, locale, labels);
393
+ }
327
394
  if (once && !monthly && !yearly) price.custom = phrase(once, locale, labels);
328
395
 
329
396
  const card: PricingPlanCard = {
330
397
  key: product.plan,
331
- name: stripFormatCharacters(product.name),
398
+ name: titleOf(product),
332
399
  price,
333
400
  features: features(product),
334
401
  cta: { label: ctaLabel(product, labels), href },
402
+ offerPrices: offerPricesOf([monthly, yearly, once]),
335
403
  };
336
404
  const description =
337
405
  product.description && stripFormatCharacters(product.description, true);
@@ -392,14 +460,17 @@ function splitBlocks(
392
460
  annualPriceNote: _annualPriceNote,
393
461
  priceFootnote: _priceFootnote,
394
462
  priceFootnoteAnnualOnly: _priceFootnoteAnnualOnly,
463
+ offerPrices: _offerPrices,
395
464
  ...shared
396
465
  } = card;
466
+ // Each block publishes only the Price it sells (#12193 D9).
397
467
  const yearlyBlock: PricingPlanCard = {
398
468
  key: yearly.lookupKey,
399
469
  name: card.name,
400
470
  price: { annual: phrase(yearly, locale, labels) },
401
471
  features: card.features,
402
472
  cta: { label: card.cta.label, href: yearlyHref },
473
+ offerPrices: offerPricesOf([yearly]),
403
474
  };
404
475
  if (card.priceUnit !== undefined) yearlyBlock.priceUnit = card.priceUnit;
405
476
  if (card.priceSubhead !== undefined)
@@ -411,6 +482,7 @@ function splitBlocks(
411
482
  ...shared,
412
483
  price: { monthly: phrase(monthly, locale, labels) },
413
484
  cta: { label: card.cta.label, href: monthlyHref },
485
+ offerPrices: offerPricesOf([monthly]),
414
486
  },
415
487
  yearlyBlock,
416
488
  ];
@@ -468,13 +540,18 @@ function plansFragment(
468
540
  }
469
541
  }
470
542
 
471
- /** The card fields that change with the level (#12174 D3), as `card` has them. */
543
+ /**
544
+ * The card fields that change with the level (#12174 D3), as `card` has them —
545
+ * its description and `offerPrices` too (#12193 D5 rule 5, D9).
546
+ */
472
547
  function levelOf(card: PricingPlanCard): Omit<PricingPlanLevel, "label" | "key"> {
473
548
  const level: Omit<PricingPlanLevel, "label" | "key"> = {
474
549
  price: card.price,
475
550
  features: card.features,
476
551
  cta: card.cta,
477
552
  };
553
+ if (card.description !== undefined) level.description = card.description;
554
+ if (card.offerPrices !== undefined) level.offerPrices = card.offerPrices;
478
555
  if (card.priceUnit !== undefined) level.priceUnit = card.priceUnit;
479
556
  if (card.priceSubhead !== undefined) level.priceSubhead = card.priceSubhead;
480
557
  if (card.annualPriceNote !== undefined)
@@ -486,6 +563,13 @@ function levelOf(card: PricingPlanCard): Omit<PricingPlanLevel, "label" | "key">
486
563
  return level;
487
564
  }
488
565
 
566
+ /** A level's helper text: its product's `switchHelper` (#12209 D5), else none. */
567
+ function helperOf(product: OfferingsProduct): { helper?: string } {
568
+ return product.switchHelper === undefined
569
+ ? {}
570
+ : { helper: stripFormatCharacters(product.switchHelper) };
571
+ }
572
+
489
573
  /**
490
574
  * The level cards of a bound section's `offeringGroups` (#12174 D6), in the
491
575
  * groups' order. Each level is its plan product's card as `planCard` builds
@@ -493,7 +577,7 @@ function levelOf(card: PricingPlanCard): Omit<PricingPlanLevel, "label" | "key">
493
577
  * is not a shown plain plan (not shown, not a `plan`, a required product or a
494
578
  * bundle) is dropped, and a group with no level left gives no card. The card
495
579
  * 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
580
+ * description, so no level carries one — and the first level's fields as its own. It is highlighted
497
581
  * when one of its levels sells the first recommended plan among the groups'.
498
582
  */
499
583
  function levelCards(
@@ -502,25 +586,36 @@ function levelCards(
502
586
  locale: string,
503
587
  labels: OfferingsPricingLabels,
504
588
  ): PricingPlanCard[] {
589
+ // #12210 D6 rule 5 — a level names one slug, so one price point.
505
590
  const byPlan = new Map(
506
- planProducts.filter((p) => p.requires === undefined).map((p) => [p.plan, p]),
591
+ planProducts
592
+ .filter((p) => p.requires === undefined)
593
+ .flatMap(offeringPointProducts)
594
+ .map((p) => [p.plan, p]),
507
595
  );
508
596
  const grouped = groups.flatMap((group) =>
509
597
  group.levels.flatMap((level) => byPlan.get(level.plan) ?? []),
510
598
  );
511
- const recommendedPlan = firstRecommended(grouped);
599
+ // The Recommended product by id, so a group naming any of its price points
600
+ // is highlighted (#12210 D12).
601
+ const recommendedId = grouped.find((p) => p.recommended)?.productId;
512
602
  return groups.flatMap((group) => {
513
603
  const levels: PricingPlanLevel[] = group.levels.flatMap((level) => {
514
604
  const product = byPlan.get(level.plan);
515
605
  const card = product && planCard(product, false, locale, labels);
516
- return card ? [{ label: level.label, key: product.plan, ...levelOf(card) }] : [];
606
+ if (!card) return [];
607
+ const { description: _description, ...fields } = levelOf(card);
608
+ return [{ label: level.label, key: product.plan, ...fields, ...helperOf(product) }];
517
609
  });
518
610
  const first = levels[0];
519
611
  if (!first) return [];
520
- const { label: _label, key: _key, ...shown } = first;
612
+ // #12209 D5 — `helper` is level-only, so the card's own fields leave it out.
613
+ const { label: _label, key: _key, helper: _helper, ...shown } = first;
521
614
  const card: PricingPlanCard = { key: group.key, name: group.name, ...shown, levels };
522
615
  if (group.description !== undefined) card.description = group.description;
523
- if (group.levels.some((level) => level.plan === recommendedPlan)) {
616
+ // #12209 D2 — the group's control rides its card to the section.
617
+ if (group.levelSwitchControl !== undefined) card.levelSwitchControl = group.levelSwitchControl;
618
+ if (recommendedId !== undefined && group.levels.some((level) => byPlan.get(level.plan)?.productId === recommendedId)) {
524
619
  card.highlighted = true;
525
620
  card.highlightStyle = "pill";
526
621
  card.highlightLabel = labels.recommended;
@@ -541,7 +636,7 @@ function addonTile(
541
636
 
542
637
  const tile: PricingAddonTile = {
543
638
  key: product.plan,
544
- name: stripFormatCharacters(product.name),
639
+ name: titleOf(product),
545
640
  price: phrase(shown, locale, labels),
546
641
  features: features(product),
547
642
  cta: { label: ctaLabel(product, labels), href },
@@ -561,6 +656,184 @@ function addonTile(
561
656
  return tile;
562
657
  }
563
658
 
659
+ /**
660
+ * A contact's link (#12193 D5 rule 7; contract 8879 §3.6, T3's one exception).
661
+ * The stored URL is `https:` with no credentials (the normalizer's parse).
662
+ * Internal — `pathname + search + hash` — only when its origin is
663
+ * `siteOrigin` and its path starts with exactly one `/`; external (a new tab,
664
+ * `noopener noreferrer`) otherwise. `null` — no card or tile — for a path that
665
+ * does not percent-decode, or a same-origin one under `/api/`, so a contact is
666
+ * never a button onto one of our own routes such as the checkout. Never throws.
667
+ */
668
+ function contactLink(
669
+ raw: string,
670
+ siteOrigin: string | undefined,
671
+ ): { href: string; external?: true } | null {
672
+ let url: URL;
673
+ let decoded: string;
674
+ try {
675
+ url = new URL(raw);
676
+ decoded = decodeURIComponent(url.pathname).toLowerCase();
677
+ } catch {
678
+ return null;
679
+ }
680
+ if (url.origin === siteOrigin) {
681
+ if (/^\/api(?:\/|$)/.test(decoded.replace(/^[/\\]+/, "/"))) return null;
682
+ if (/^\/(?![/\\])/.test(url.pathname)) return { href: url.pathname + url.search + url.hash };
683
+ }
684
+ return { href: url.href, external: true };
685
+ }
686
+
687
+ /** A plan contact's card (#12193 D5 rule 7): no Price, so no `Offer` and never highlighted. */
688
+ function contactCard(
689
+ contact: OfferingsContactProduct,
690
+ siteOrigin: string | undefined,
691
+ labels: OfferingsPricingLabels,
692
+ ): PricingPlanCard | null {
693
+ const link = contactLink(contact.url, siteOrigin);
694
+ if (!link) return null;
695
+ const card: PricingPlanCard = {
696
+ key: contact.plan,
697
+ name: stripFormatCharacters(contact.tier ?? contact.shortName ?? contact.name),
698
+ price: { custom: contact.priceText ? stripFormatCharacters(contact.priceText) : labels.custom },
699
+ features: features(contact),
700
+ cta: { label: ctaLabel(contact, labels), ...link },
701
+ offerPrices: [],
702
+ };
703
+ const description = contact.description && stripFormatCharacters(contact.description, true);
704
+ if (description) card.description = description;
705
+ return card;
706
+ }
707
+
708
+ /** An add-on contact's tile (#12193 AC-7): its display price, label and link. */
709
+ function contactTile(
710
+ contact: OfferingsContactProduct,
711
+ siteOrigin: string | undefined,
712
+ labels: OfferingsPricingLabels,
713
+ ): PricingAddonTile | null {
714
+ const link = contactLink(contact.url, siteOrigin);
715
+ if (!link) return null;
716
+ return {
717
+ key: contact.plan,
718
+ name: titleOf(contact),
719
+ price: contact.priceText ? stripFormatCharacters(contact.priceText) : labels.custom,
720
+ features: features(contact),
721
+ cta: { label: ctaLabel(contact, labels), ...link },
722
+ };
723
+ }
724
+
725
+ /** `ailkOrder`, null last. */
726
+ function compareOrder(a: number | null, b: number | null): number {
727
+ if (a === b) return 0;
728
+ if (a === null) return 1;
729
+ if (b === null) return -1;
730
+ return a - b;
731
+ }
732
+
733
+ /** Snapshot order (#12193 D5 rule 4): `ailkOrder` null last, then name, then id. */
734
+ function compareProducts(a: OfferingsProduct, b: OfferingsProduct): number {
735
+ return (
736
+ compareOrder(a.ailkOrder, b.ailkOrder) ||
737
+ (a.name < b.name ? -1 : a.name > b.name ? 1 : 0) ||
738
+ (a.productId < b.productId ? -1 : a.productId > b.productId ? 1 : 0)
739
+ );
740
+ }
741
+
742
+ /** The longest select item secondary label (#12209 D3, the level `detail`). */
743
+ const LEVEL_DETAIL_MAX = 24;
744
+
745
+ /**
746
+ * One tier's card (#12193 D5 rules 2–5): its plans in snapshot order, at most
747
+ * `levelLimit` (four, or twenty for a select, #12209 D8), each its own card as `planCard` builds it, labelled `level ?? shortName
748
+ * ?? name` — a repeated label falls back to `shortName ?? name`, and one still
749
+ * repeated is dropped. Two or more levels make a level card titled `name`,
750
+ * keyed and described by its first level; one makes a plain card titled
751
+ * `name`. Nothing comes from the page.
752
+ *
753
+ * #12210 D6 rules 2–4, 6 — a multi-point member is one level per price point,
754
+ * in product then point order, labelled by the point's label else its price
755
+ * phrase (a repeat falls back to the phrase, one still repeated is dropped),
756
+ * with the phrase as the select item's `detail`. A card holds at most 20
757
+ * levels; one with points and more than four levels takes the select. A
758
+ * multi-point product's own card is this card with itself as the one member.
759
+ */
760
+ function tierCard(
761
+ name: string,
762
+ members: OfferingsProduct[],
763
+ highlighted: boolean,
764
+ locale: string,
765
+ labels: OfferingsPricingLabels,
766
+ levelLimit: number,
767
+ ): PricingPlanCard | null {
768
+ const title = stripFormatCharacters(name);
769
+ const levels: PricingPlanLevel[] = [];
770
+ // A member with price points sends the card to the select, so the tier keeps
771
+ // up to the select's 20 levels rather than cutting its members at four.
772
+ const memberLimit = members.some((m) => offeringPointProducts(m).length > 1) ? PRICING_SELECT_LEVELS_MAX : levelLimit;
773
+ const entries = [...members]
774
+ .sort(compareProducts)
775
+ .slice(0, memberLimit)
776
+ .flatMap((product) => offeringPointProducts(product).map((point) => ({ product, point })))
777
+ .slice(0, PRICING_SELECT_LEVELS_MAX);
778
+ const hasPoints = entries.some(({ product, point }) => point !== product);
779
+ for (const { product, point } of entries) {
780
+ const card = planCard(point, false, locale, labels);
781
+ const shown = shownPrice(point);
782
+ if (!card || !shown) continue;
783
+ const taken = new Set(levels.map((level) => level.label));
784
+ const isPoint = point !== product;
785
+ const pricePhrase = phrase(shown, locale, labels);
786
+ const pointLabel = offeringPricePoints(point.prices)[0]?.label;
787
+ const own = isPoint
788
+ ? pointLabel && stripFormatCharacters(pointLabel)
789
+ : product.level === undefined
790
+ ? undefined
791
+ : stripFormatCharacters(product.level);
792
+ const label = [own, isPoint ? pricePhrase : titleOf(product)].find(
793
+ (text): text is string => text !== undefined && text.length > 0 && !taken.has(text),
794
+ );
795
+ if (label === undefined) continue;
796
+ const detail =
797
+ isPoint && label !== pricePhrase && [...pricePhrase].length <= LEVEL_DETAIL_MAX
798
+ ? { detail: pricePhrase }
799
+ : {};
800
+ levels.push({ label, key: point.plan, ...levelOf(card), ...helperOf(product), ...detail });
801
+ }
802
+ const first = levels[0];
803
+ if (!first) return null;
804
+ // #12209 D3, D5 — `helper` and `detail` are level-only, so the card's own fields leave them out.
805
+ const { label: _label, helper: _helper, detail: _detail, ...shown } = first;
806
+ const card: PricingPlanCard = { ...shown, name: title, ...(levels.length > 1 ? { levels } : {}) };
807
+ // #12210 D6 rule 6 — segments keep four levels (#12209 AC 8).
808
+ if (hasPoints && levels.length > PRICING_SEGMENT_LEVELS_MAX) card.levelSwitchControl = "select";
809
+ if (highlighted) {
810
+ card.highlighted = true;
811
+ card.highlightStyle = "pill";
812
+ card.highlightLabel = labels.recommended;
813
+ }
814
+ return card;
815
+ }
816
+
817
+ /** A card or tile with what orders it among its section's (#12193 D5 rule 6). */
818
+ interface Placed<T> {
819
+ item: T;
820
+ order: number | null;
821
+ contact: boolean;
822
+ }
823
+
824
+ /** Cards by `ailkOrder` (null last), a plan card before a contact on a tie, else as built. */
825
+ function inOrder<T>(placed: Placed<T>[]): T[] {
826
+ return placed
827
+ .map((entry, index) => ({ entry, index }))
828
+ .sort(
829
+ (a, b) =>
830
+ compareOrder(a.entry.order, b.entry.order) ||
831
+ Number(a.entry.contact) - Number(b.entry.contact) ||
832
+ a.index - b.index,
833
+ )
834
+ .map(({ entry }) => entry.item);
835
+ }
836
+
564
837
  // #8927 D3 — `GET /v1/content/shown-offerings` sends the shown set without
565
838
  // `workspaceId` and `organizationId` (spec 8924 D3), which the strict schema
566
839
  // requires. Both ids become optional; an id that is present is still
@@ -575,11 +848,30 @@ function isPresent<T>(value: T | null): value is T {
575
848
  return value !== null;
576
849
  }
577
850
 
851
+ /** Whether `collection` names `value`'s collection, compared lowercased (#12193 D5 rule 1). */
852
+ function inCollection(value: string | undefined, collection: string): boolean {
853
+ return value !== undefined && value.toLowerCase() === collection.toLowerCase();
854
+ }
855
+
856
+ /**
857
+ * The plan slugs of every shown product and contact of `collection` (#12193
858
+ * D5): the cards a collection section shows, so the page's unbound plans slot
859
+ * leaves them out. `[]` for a shown set that does not parse.
860
+ */
861
+ export function collectionPlans(shownSet: unknown, collection: string): string[] {
862
+ const parsed = shownSetSchema.safeParse(shownSet);
863
+ if (!parsed.success) return [];
864
+ return [...parsed.data.offerings, ...(parsed.data.contacts ?? [])]
865
+ .filter((o) => o.ailkGroup !== "offer" && inCollection(o.collection, collection))
866
+ .map((o) => o.plan);
867
+ }
868
+
578
869
  /**
579
870
  * The products whose `{plan}` is in `plans`, plus every product a kept one
580
871
  * `requires`, in the snapshot's order (#10044 D4); `plans` absent → all.
581
872
  * One level of `requires` is followed: a required product is sold only
582
- * inside its bundle and requires nothing itself (#10028 decision 6).
873
+ * inside its bundle and requires nothing itself (#10028 decision 6). A
874
+ * product is matched by any of its price points' slugs (#12210 D6 rule 7).
583
875
  */
584
876
  function narrowToPlans(
585
877
  offerings: OfferingsProduct[],
@@ -588,12 +880,12 @@ function narrowToPlans(
588
880
  if (plans === undefined) return offerings;
589
881
  const listed = new Set(plans);
590
882
  const kept = new Set(
591
- offerings.filter((o) => listed.has(o.plan)).map((o) => o.plan),
883
+ offerings.filter((o) => namedIn(o, listed)).flatMap(offeringPlanSlugs),
592
884
  );
593
885
  for (const o of offerings) {
594
- if (kept.has(o.plan) && o.requires !== undefined) kept.add(o.requires);
886
+ if (namedIn(o, kept) && o.requires !== undefined) kept.add(o.requires);
595
887
  }
596
- return offerings.filter((o) => kept.has(o.plan));
888
+ return offerings.filter((o) => namedIn(o, kept));
597
889
  }
598
890
 
599
891
  /**
@@ -616,6 +908,17 @@ function narrowToPlans(
616
908
  * `levelGroups` (#12174 D6) makes the plan cards a bound section's level
617
909
  * cards, one per group (`levelCards`), in place of one card per plan. Absent,
618
910
  * the cards are built exactly as before.
911
+ *
912
+ * `tiers` (#12193 D5, a selecting bound section) groups plain plans sharing a
913
+ * Stripe `tier` into one card each (`tierCard`). `collection` maps every shown
914
+ * product of that collection in place of `plans`, with its contacts as
915
+ * contact cards and tiles, linked by `contactLink` against `siteOrigin`.
916
+ * Cards and tiles are ordered by `ailkOrder`. Absent, the cards are built
917
+ * exactly as before, and no contact is shown.
918
+ *
919
+ * With `tiers`, `levelLimit` (#12209 D8) caps a tier card's levels — four
920
+ * (the default, segments) or twenty (a select) — and `groupTiers: false`
921
+ * (#12209 D11) makes every plan its own card, whatever its tier.
619
922
  */
620
923
  export function offeringsPricing(
621
924
  shownSet: unknown,
@@ -626,13 +929,22 @@ export function offeringsPricing(
626
929
  exclude?: readonly string[] | undefined;
627
930
  layout?: OfferingsLayout | undefined;
628
931
  levelGroups?: readonly OfferingsLevelGroup[] | undefined;
932
+ collection?: string | undefined;
933
+ tiers?: boolean | undefined;
934
+ levelLimit?: number | undefined;
935
+ groupTiers?: boolean | undefined;
936
+ siteOrigin?: string | undefined;
629
937
  },
630
938
  ): OfferingsPricing | null {
631
939
  const parsed = shownSetSchema.safeParse(shownSet);
632
940
  if (!parsed.success) return null;
633
941
  const { state, offerings: shown } = parsed.data;
634
- if (state !== "current" || shown.length === 0) return null;
635
- const { locale, labels } = options;
942
+ const { collection, siteOrigin, locale, labels } = options;
943
+ const contacts =
944
+ collection === undefined
945
+ ? []
946
+ : (parsed.data.contacts ?? []).filter((c) => inCollection(c.collection, collection));
947
+ if (state !== "current" || (shown.length === 0 && contacts.length === 0)) return null;
636
948
 
637
949
  // #10028 D9 — a product some shown plan requires is sold only inside that
638
950
  // bundle (decision 6), so it gets no card of its own. Read over the whole
@@ -640,41 +952,90 @@ export function offeringsPricing(
640
952
  const requiredPlans = new Set(
641
953
  shown.map((o) => o.requires).filter((plan) => plan !== undefined),
642
954
  );
643
- const offerings = narrowToPlans(shown, options.plans);
955
+ const offerings = narrowToPlans(
956
+ shown,
957
+ collection === undefined ? options.plans : collectionPlans(parsed.data, collection),
958
+ );
644
959
  const excluded = new Set(options.exclude);
645
960
  // #11166 — the two group reads are exact, so an `offer` falls into neither.
646
961
  const planProducts = offerings.filter(
647
962
  (o) =>
648
963
  o.ailkGroup === "plan" &&
649
- !requiredPlans.has(o.plan) &&
650
- !excluded.has(o.plan),
964
+ !namedIn(o, requiredPlans) &&
965
+ !namedIn(o, excluded),
651
966
  );
652
967
  const addonProducts = offerings.filter((o) => o.ailkGroup === "addon");
653
968
  const recommendedPlan = firstRecommended(planProducts);
654
969
  const recommendedAddon = firstRecommended(addonProducts);
655
970
 
971
+ // #12193 D5 rule 2 — with `tiers`, plain plans sharing a tier are one card,
972
+ // placed where its first member is.
973
+ // #12209 D11 — `groupTiers: false` leaves every plan its own card.
974
+ const tierOf = (p: OfferingsProduct) =>
975
+ options.tiers && options.groupTiers !== false && p.requires === undefined ? p.tier : undefined;
976
+ const placedPlans: Placed<PricingPlanCard | null>[] = [];
977
+ const seenTiers = new Set<string>();
978
+ const inSnapshotOrder = options.tiers ? [...planProducts].sort(compareProducts) : planProducts;
979
+ for (const p of inSnapshotOrder) {
980
+ const tier = tierOf(p);
981
+ if (tier !== undefined) {
982
+ if (seenTiers.has(tier)) continue;
983
+ seenTiers.add(tier);
984
+ const members = planProducts.filter((m) => tierOf(m) === tier);
985
+ placedPlans.push({
986
+ item: tierCard(
987
+ tier,
988
+ members,
989
+ members.some((m) => m.plan === recommendedPlan),
990
+ locale,
991
+ labels,
992
+ options.levelLimit ?? PRICING_SEGMENT_LEVELS_MAX,
993
+ ),
994
+ order: p.ailkOrder,
995
+ contact: false,
996
+ });
997
+ continue;
998
+ }
999
+ const named = p.requires === undefined ? undefined : new Set([p.requires]);
1000
+ const required = named && offerings.find((o) => namedIn(o, named));
1001
+ // #12210 D6 rules 3, 8 — a multi-point product is one level card of its
1002
+ // points; a bundle whose required product has points gives no card, its
1003
+ // recurring Price being ambiguous.
1004
+ const item =
1005
+ p.requires !== undefined
1006
+ ? required && offeringPointProducts(required).length === 1
1007
+ ? bundleCard(p, required, p.plan === recommendedPlan, locale, labels)
1008
+ : null
1009
+ : offeringPointProducts(p).length > 1
1010
+ ? tierCard(titleOf(p), [p], p.plan === recommendedPlan, locale, labels, 1)
1011
+ : planCard(p, p.plan === recommendedPlan, locale, labels);
1012
+ placedPlans.push({ item, order: p.ailkOrder, contact: false });
1013
+ }
1014
+ for (const c of contacts.filter((c) => c.ailkGroup === "plan")) {
1015
+ placedPlans.push({ item: contactCard(c, siteOrigin, labels), order: c.ailkOrder, contact: true });
1016
+ }
1017
+ // Outside tier mode the cards keep the snapshot's order exactly, as before.
1018
+ const ordered = <T>(placed: Placed<T>[]) =>
1019
+ options.tiers ? inOrder(placed) : placed.map((entry) => entry.item);
656
1020
  const plans = options.levelGroups
657
1021
  ? 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);
1022
+ : ordered(placedPlans).filter(isPresent);
1023
+ const addons = ordered<PricingAddonTile | null>([
1024
+ ...addonProducts.map((p) => ({
1025
+ item: addonTile(p, p.plan === recommendedAddon, locale, labels),
1026
+ order: p.ailkOrder,
1027
+ contact: false,
1028
+ })),
1029
+ ...contacts
1030
+ .filter((c) => c.ailkGroup === "addon")
1031
+ .map((c) => ({ item: contactTile(c, siteOrigin, labels), order: c.ailkOrder, contact: true })),
1032
+ ]).filter(isPresent);
673
1033
 
674
1034
  // 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).
1035
+ // A level card's key is the group's, so it names no product (#12174 D6); a
1036
+ // lone level card is never split either (#12210 D6 rule 8).
676
1037
  const product =
677
- plans.length === 1 && !options.levelGroups
1038
+ plans.length === 1 && !options.levelGroups && plans[0]!.levels === undefined
678
1039
  ? planProducts.find((p) => p.plan === plans[0]!.key)
679
1040
  : undefined;
680
1041
  return {