create-ailk 0.46.0 → 0.46.2

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.
@@ -42,6 +42,9 @@ const PERIOD = lookupKeyPeriodSchema.enum;
42
42
 
43
43
  type PricingSectionData = Extract<PageSection, { type: "pricing" }>["data"];
44
44
  type PricingPlanCard = PricingSectionData["plans"][number];
45
+ type PricingPlanLevel = NonNullable<PricingPlanCard["levels"]>[number];
46
+ /** A bound section's level card, as the page writes it (#12174 D6). */
47
+ export type OfferingsLevelGroup = NonNullable<PricingSectionData["offeringGroups"]>[number];
45
48
  /** `AddonCard` ignores `key`; it is carried so a tile names its `{plan}` too. */
46
49
  type PricingAddonTile = NonNullable<PricingSectionData["addons"]>[number] & {
47
50
  key: string;
@@ -60,6 +63,8 @@ export interface OfferingsPricingLabels {
60
63
  withRequired(plan: string, required: string): string;
61
64
  /** A deposit plan's footnote, from the formatted deposit (#10030 D10). */
62
65
  depositNote(deposit: string): string;
66
+ /** The yearly total under a per-month annual price (#12139 D1). */
67
+ billedYearly(amount: string): string;
63
68
  }
64
69
 
65
70
  export interface OfferingsPricing {
@@ -67,6 +72,12 @@ export interface OfferingsPricing {
67
72
  addons: PricingSectionData | null;
68
73
  }
69
74
 
75
+ /** The layouts a plans fragment takes (#12140 D3): every variant but `addons`. */
76
+ export type OfferingsLayout = Exclude<
77
+ NonNullable<PricingSectionData["variant"]>,
78
+ "addons"
79
+ >;
80
+
70
81
  /** The route every Offerings CTA links to, followed by a grammar key. */
71
82
  export const OFFERINGS_CHECKOUT_PATH = "/api/offerings/checkout";
72
83
 
@@ -270,8 +281,11 @@ function bundleCard(
270
281
  // NO_HAND_IMPLEMENT_OK: builder-assessors run for #10030 — the builder is the implementer.
271
282
  if (product.deposit !== undefined)
272
283
  card.priceFootnote = labels.depositNote(formatMinorUnits(product.deposit, once.currency, locale));
273
- else if (product.termsNote)
284
+ else if (product.termsNote) {
274
285
  card.priceFootnote = stripFormatCharacters(product.termsNote);
286
+ // Beside both prices, the terms note describes the annual one (#12139 D2).
287
+ if (monthly && yearly) card.priceFootnoteAnnualOnly = true;
288
+ }
275
289
  const annualHref =
276
290
  monthly && yearly && offeringsBundleHref(once.lookupKey, yearly.lookupKey);
277
291
  if (annualHref) card.annualCtaHref = annualHref;
@@ -298,7 +312,18 @@ function planCard(
298
312
  const once = priceFor(product, PERIOD.once);
299
313
  const price: PricingPlanCard["price"] = {};
300
314
  if (monthly) price.monthly = phrase(monthly, locale, labels);
301
- if (yearly) price.annual = phrase(yearly, locale, labels);
315
+ // 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)
318
+ price.annual = monthly
319
+ ? labels.monthly(
320
+ formatMinorUnits(
321
+ Math.round(yearly.amount / 12),
322
+ yearly.currency,
323
+ locale,
324
+ ),
325
+ )
326
+ : phrase(yearly, locale, labels);
302
327
  if (once && !monthly && !yearly) price.custom = phrase(once, locale, labels);
303
328
 
304
329
  const card: PricingPlanCard = {
@@ -314,12 +339,19 @@ function planCard(
314
339
  if (product.unitLabel)
315
340
  card.priceUnit = stripFormatCharacters(product.unitLabel);
316
341
  if (product.note) card.priceSubhead = stripFormatCharacters(product.note);
317
- if (product.termsNote)
318
- card.priceFootnote = stripFormatCharacters(product.termsNote);
342
+ if (monthly && yearly)
343
+ card.annualPriceNote = labels.billedYearly(
344
+ formatMinorUnits(yearly.amount, yearly.currency, locale),
345
+ );
319
346
  // A deposit plan's footnote (#10030 D10), in its one-time Price's currency;
320
347
  // it takes the footnote over a terms note (the rarer field).
321
348
  if (product.deposit !== undefined && once)
322
349
  card.priceFootnote = labels.depositNote(formatMinorUnits(product.deposit, once.currency, locale));
350
+ else if (product.termsNote) {
351
+ card.priceFootnote = stripFormatCharacters(product.termsNote);
352
+ // Beside both prices, the terms note describes the annual one (#12139 D2).
353
+ if (monthly && yearly) card.priceFootnoteAnnualOnly = true;
354
+ }
323
355
  // Annual mode shows the yearly Price only when a monthly one is beside it,
324
356
  // so only then does the card need a second link (D5, D6).
325
357
  const annualHref =
@@ -333,6 +365,170 @@ function planCard(
333
365
  return card;
334
366
  }
335
367
 
368
+ /**
369
+ * `features-and-plans` for one product with a monthly and a yearly Price
370
+ * (#12140 D4): two blocks, each selling its own Price, built from the
371
+ * product's card as `planCard` made it. The yearly block is keyed by its
372
+ * lookup key, which the plan-slug grammar refuses, so it never collides with a
373
+ * card's key or matches `?plan=`; the terms note sits on it alone (#12139 D2).
374
+ * `null` when the product is not that shape or either key is outside the
375
+ * grammar — the caller then keeps the card as built.
376
+ */
377
+ function splitBlocks(
378
+ product: OfferingsProduct,
379
+ card: PricingPlanCard,
380
+ locale: string,
381
+ labels: OfferingsPricingLabels,
382
+ ): PricingPlanCard[] | null {
383
+ const monthly = priceFor(product, PERIOD.monthly);
384
+ const yearly = priceFor(product, PERIOD.yearly);
385
+ if (product.requires !== undefined || !monthly || !yearly) return null;
386
+ const monthlyHref = offeringsCheckoutHref(monthly.lookupKey);
387
+ const yearlyHref = offeringsCheckoutHref(yearly.lookupKey);
388
+ if (!monthlyHref || !yearlyHref) return null;
389
+ const {
390
+ price: _price,
391
+ annualCtaHref: _annualCtaHref,
392
+ annualPriceNote: _annualPriceNote,
393
+ priceFootnote: _priceFootnote,
394
+ priceFootnoteAnnualOnly: _priceFootnoteAnnualOnly,
395
+ ...shared
396
+ } = card;
397
+ const yearlyBlock: PricingPlanCard = {
398
+ key: yearly.lookupKey,
399
+ name: card.name,
400
+ price: { annual: phrase(yearly, locale, labels) },
401
+ features: card.features,
402
+ cta: { label: card.cta.label, href: yearlyHref },
403
+ };
404
+ if (card.priceUnit !== undefined) yearlyBlock.priceUnit = card.priceUnit;
405
+ if (card.priceSubhead !== undefined)
406
+ yearlyBlock.priceSubhead = card.priceSubhead;
407
+ if (product.termsNote)
408
+ yearlyBlock.priceFootnote = stripFormatCharacters(product.termsNote);
409
+ return [
410
+ {
411
+ ...shared,
412
+ price: { monthly: phrase(monthly, locale, labels) },
413
+ cta: { label: card.cta.label, href: monthlyHref },
414
+ },
415
+ yearlyBlock,
416
+ ];
417
+ }
418
+
419
+ /**
420
+ * The plans fragment in `layout` (#12140 D3): the cards as built, framed for
421
+ * the layout that renders them. Absent, today's toggle fragment. `product` is
422
+ * the one plan product behind `cards`, when there is exactly one.
423
+ */
424
+ function plansFragment(
425
+ cards: PricingPlanCard[],
426
+ layout: OfferingsLayout | undefined,
427
+ product: OfferingsProduct | undefined,
428
+ locale: string,
429
+ labels: OfferingsPricingLabels,
430
+ ): PricingSectionData {
431
+ switch (layout) {
432
+ case undefined:
433
+ case "three-tiers-with-toggle":
434
+ return {
435
+ variant: "three-tiers-with-toggle",
436
+ cardLayout: "centered",
437
+ // #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
+ ),
445
+ plans: cards,
446
+ };
447
+ // These variants show monthly prices only, so they take no toggle.
448
+ case "with-comparison-table":
449
+ case "two-tiers-with-extra-tier":
450
+ case "band-hero":
451
+ return { variant: layout, cardLayout: "centered", plans: cards };
452
+ // The variant renders one plan and has no card layout.
453
+ case "single-price-with-details":
454
+ return { variant: layout, plans: cards.slice(0, 1) };
455
+ case "features-and-plans": {
456
+ // A level card (#12174 D6) is never split: `product` is undefined then.
457
+ const split =
458
+ product && splitBlocks(product, cards[0]!, locale, labels);
459
+ const rows = product ? features(product) : [];
460
+ return {
461
+ variant: layout,
462
+ plans: split ?? cards,
463
+ ...(rows.length > 0
464
+ ? { features: rows.map((title) => ({ title })) }
465
+ : {}),
466
+ };
467
+ }
468
+ }
469
+ }
470
+
471
+ /** The card fields that change with the level (#12174 D3), as `card` has them. */
472
+ function levelOf(card: PricingPlanCard): Omit<PricingPlanLevel, "label" | "key"> {
473
+ const level: Omit<PricingPlanLevel, "label" | "key"> = {
474
+ price: card.price,
475
+ features: card.features,
476
+ cta: card.cta,
477
+ };
478
+ if (card.priceUnit !== undefined) level.priceUnit = card.priceUnit;
479
+ if (card.priceSubhead !== undefined) level.priceSubhead = card.priceSubhead;
480
+ if (card.annualPriceNote !== undefined)
481
+ level.annualPriceNote = card.annualPriceNote;
482
+ if (card.priceFootnote !== undefined) level.priceFootnote = card.priceFootnote;
483
+ if (card.priceFootnoteAnnualOnly !== undefined)
484
+ level.priceFootnoteAnnualOnly = card.priceFootnoteAnnualOnly;
485
+ if (card.annualCtaHref !== undefined) level.annualCtaHref = card.annualCtaHref;
486
+ return level;
487
+ }
488
+
489
+ /**
490
+ * The level cards of a bound section's `offeringGroups` (#12174 D6), in the
491
+ * groups' order. Each level is its plan product's card as `planCard` builds
492
+ * it, trimmed to the level fields, labelled by the page; a level whose plan
493
+ * is not a shown plain plan (not shown, not a `plan`, a required product or a
494
+ * bundle) is dropped, and a group with no level left gives no card. The card
495
+ * 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
497
+ * when one of its levels sells the first recommended plan among the groups'.
498
+ */
499
+ function levelCards(
500
+ groups: readonly OfferingsLevelGroup[],
501
+ planProducts: OfferingsProduct[],
502
+ locale: string,
503
+ labels: OfferingsPricingLabels,
504
+ ): PricingPlanCard[] {
505
+ const byPlan = new Map(
506
+ planProducts.filter((p) => p.requires === undefined).map((p) => [p.plan, p]),
507
+ );
508
+ const grouped = groups.flatMap((group) =>
509
+ group.levels.flatMap((level) => byPlan.get(level.plan) ?? []),
510
+ );
511
+ const recommendedPlan = firstRecommended(grouped);
512
+ return groups.flatMap((group) => {
513
+ const levels: PricingPlanLevel[] = group.levels.flatMap((level) => {
514
+ 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) }] : [];
517
+ });
518
+ const first = levels[0];
519
+ if (!first) return [];
520
+ const { label: _label, key: _key, ...shown } = first;
521
+ const card: PricingPlanCard = { key: group.key, name: group.name, ...shown, levels };
522
+ if (group.description !== undefined) card.description = group.description;
523
+ if (group.levels.some((level) => level.plan === recommendedPlan)) {
524
+ card.highlighted = true;
525
+ card.highlightStyle = "pill";
526
+ card.highlightLabel = labels.recommended;
527
+ }
528
+ return [card];
529
+ });
530
+ }
531
+
336
532
  function addonTile(
337
533
  product: OfferingsProduct,
338
534
  highlighted: boolean,
@@ -412,6 +608,14 @@ function narrowToPlans(
412
608
  * `exclude` (#12103 D2) drops the plan cards of the plans it lists — the ones
413
609
  * a section's own `offeringPlans` already shows — so the page's unlisted
414
610
  * plans section does not show them twice. Add-on tiles are unaffected.
611
+ *
612
+ * `layout` (#12140 D3) frames the plans fragment for the variant a bound
613
+ * section names; the cards are built the same either way. Absent, the plans
614
+ * fragment is the toggle layout, exactly as before. Add-ons are unaffected.
615
+ *
616
+ * `levelGroups` (#12174 D6) makes the plan cards a bound section's level
617
+ * cards, one per group (`levelCards`), in place of one card per plan. Absent,
618
+ * the cards are built exactly as before.
415
619
  */
416
620
  export function offeringsPricing(
417
621
  shownSet: unknown,
@@ -420,6 +624,8 @@ export function offeringsPricing(
420
624
  labels: OfferingsPricingLabels;
421
625
  plans?: readonly string[] | undefined;
422
626
  exclude?: readonly string[] | undefined;
627
+ layout?: OfferingsLayout | undefined;
628
+ levelGroups?: readonly OfferingsLevelGroup[] | undefined;
423
629
  },
424
630
  ): OfferingsPricing | null {
425
631
  const parsed = shownSetSchema.safeParse(shownSet);
@@ -447,35 +653,34 @@ export function offeringsPricing(
447
653
  const recommendedPlan = firstRecommended(planProducts);
448
654
  const recommendedAddon = firstRecommended(addonProducts);
449
655
 
450
- const plans = planProducts
451
- .map((p) => {
452
- const required =
453
- p.requires === undefined
454
- ? undefined
455
- : offerings.find((o) => o.plan === p.requires);
456
- if (p.requires !== undefined) {
457
- return required ? bundleCard(p, required, p.plan === recommendedPlan, locale, labels) : null;
458
- }
459
- return planCard(p, p.plan === recommendedPlan, locale, labels);
460
- })
461
- .filter(isPresent);
656
+ 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);
462
670
  const addons = addonProducts
463
671
  .map((p) => addonTile(p, p.plan === recommendedAddon, locale, labels))
464
672
  .filter(isPresent);
465
673
 
674
+ // 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).
676
+ const product =
677
+ plans.length === 1 && !options.levelGroups
678
+ ? planProducts.find((p) => p.plan === plans[0]!.key)
679
+ : undefined;
466
680
  return {
467
681
  plans:
468
682
  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
- }
683
+ ? plansFragment(plans, options.layout, product, locale, labels)
479
684
  : null,
480
685
  addons: addons.length > 0 ? { variant: "addons", plans: [], addons } : null,
481
686
  };