create-ailk 0.46.1 → 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.
- package/component-catalog.json +389 -4
- package/component-catalog.md +9 -7
- package/dist/surfaces.js +1 -1
- package/package.json +3 -3
- package/templates/apps/web/CLAUDE.md +156 -2
- package/templates/apps/web/app/globals.css +12 -0
- package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +4 -0
- package/templates/apps/web/app/llms.txt/route.ts +22 -0
- package/templates/apps/web/app/sitemap.xml/__tests__/site-listing.test.ts +4 -0
- package/templates/apps/web/app/sitemap.xml/route.ts +43 -0
- package/templates/apps/web/lib/__tests__/in-page-magnet.test.ts +170 -1
- package/templates/apps/web/lib/__tests__/magnet-addresses.test.ts +406 -0
- package/templates/apps/web/lib/__tests__/offerings-pricing.test.ts +822 -4
- package/templates/apps/web/lib/__tests__/pricing-page.test.ts +383 -0
- package/templates/apps/web/lib/__tests__/served-pages.test.ts +44 -0
- package/templates/apps/web/lib/in-page-magnet.ts +86 -9
- package/templates/apps/web/lib/magnet-addresses.ts +317 -0
- package/templates/apps/web/lib/offerings-pricing.ts +477 -40
- package/templates/apps/web/lib/paid-section-contracts.ts +41 -1
- package/templates/apps/web/lib/pricing-page.ts +248 -13
- package/templates/apps/web/lib/served-pages.ts +38 -1
- package/templates/apps/web/messages/en.json +2 -1
- package/templates/apps/web/site-pages.config.tsx +9 -0
- package/versions.json +50 -50
|
@@ -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,7 +62,20 @@ import {
|
|
|
41
62
|
const PERIOD = lookupKeyPeriodSchema.enum;
|
|
42
63
|
|
|
43
64
|
type PricingSectionData = Extract<PageSection, { type: "pricing" }>["data"];
|
|
44
|
-
|
|
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
|
+
};
|
|
77
|
+
/** A bound section's level card, as the page writes it (#12174 D6). */
|
|
78
|
+
export type OfferingsLevelGroup = NonNullable<PricingSectionData["offeringGroups"]>[number];
|
|
45
79
|
/** `AddonCard` ignores `key`; it is carried so a tile names its `{plan}` too. */
|
|
46
80
|
type PricingAddonTile = NonNullable<PricingSectionData["addons"]>[number] & {
|
|
47
81
|
key: string;
|
|
@@ -62,6 +96,8 @@ export interface OfferingsPricingLabels {
|
|
|
62
96
|
depositNote(deposit: string): string;
|
|
63
97
|
/** The yearly total under a per-month annual price (#12139 D1). */
|
|
64
98
|
billedYearly(amount: string): string;
|
|
99
|
+
/** A contact card's price when it has no display price (#12193 D5 rule 7). */
|
|
100
|
+
custom: string;
|
|
65
101
|
}
|
|
66
102
|
|
|
67
103
|
export interface OfferingsPricing {
|
|
@@ -187,12 +223,20 @@ function stripFormatCharacters(text: string, keepNewlines = false): string {
|
|
|
187
223
|
}
|
|
188
224
|
|
|
189
225
|
/** The product's own button label (#12103 D1), else the translated default. */
|
|
190
|
-
function ctaLabel(
|
|
226
|
+
function ctaLabel(
|
|
227
|
+
product: Pick<OfferingsProduct, "ctaLabel">,
|
|
228
|
+
labels: OfferingsPricingLabels,
|
|
229
|
+
): string {
|
|
191
230
|
const own = product.ctaLabel && stripFormatCharacters(product.ctaLabel);
|
|
192
231
|
return own || labels.cta;
|
|
193
232
|
}
|
|
194
233
|
|
|
195
|
-
|
|
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[] {
|
|
196
240
|
return product.marketingFeatures
|
|
197
241
|
.map((feature) => stripFormatCharacters(feature))
|
|
198
242
|
.filter((feature) => feature.length > 0);
|
|
@@ -205,6 +249,11 @@ function priceFor(
|
|
|
205
249
|
return product.prices.find((p) => p.period === period);
|
|
206
250
|
}
|
|
207
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
|
+
|
|
208
257
|
/** The Price a card shows in monthly mode: `monthly`, else `yearly`, else `once`. */
|
|
209
258
|
function shownPrice(product: OfferingsProduct): OfferingsPrice | undefined {
|
|
210
259
|
return (
|
|
@@ -225,6 +274,23 @@ function phrase(
|
|
|
225
274
|
return labels.oneTime(amount);
|
|
226
275
|
}
|
|
227
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
|
+
|
|
228
294
|
/**
|
|
229
295
|
* Only the first `recommended` Product of a group is highlighted (D4). Each
|
|
230
296
|
* offering's own flag is read; the shown set's top-level `recommended` ids
|
|
@@ -269,10 +335,11 @@ function bundleCard(
|
|
|
269
335
|
}
|
|
270
336
|
const card: PricingPlanCard = {
|
|
271
337
|
key: product.plan,
|
|
272
|
-
name:
|
|
338
|
+
name: titleOf(product),
|
|
273
339
|
price,
|
|
274
340
|
features: features(product),
|
|
275
341
|
cta: { label: ctaLabel(product, labels), href },
|
|
342
|
+
offerPrices: offerPricesOf([once]),
|
|
276
343
|
};
|
|
277
344
|
// The deposit note wins the footnote; the terms note shows only without one.
|
|
278
345
|
// NO_HAND_IMPLEMENT_OK: builder-assessors run for #10030 — the builder is the implementer.
|
|
@@ -310,25 +377,29 @@ function planCard(
|
|
|
310
377
|
const price: PricingPlanCard["price"] = {};
|
|
311
378
|
if (monthly) price.monthly = phrase(monthly, locale, labels);
|
|
312
379
|
// Beside a monthly Price, annual mode shows the yearly Price per month, so
|
|
313
|
-
// the two modes compare in one unit (#12139 D1)
|
|
314
|
-
|
|
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);
|
|
315
384
|
price.annual = monthly
|
|
316
385
|
? labels.monthly(
|
|
317
386
|
formatMinorUnits(
|
|
318
|
-
Math.round(yearly.amount / 12),
|
|
387
|
+
Math.round(yearly.amount / 12 / unit) * unit,
|
|
319
388
|
yearly.currency,
|
|
320
389
|
locale,
|
|
321
390
|
),
|
|
322
391
|
)
|
|
323
392
|
: phrase(yearly, locale, labels);
|
|
393
|
+
}
|
|
324
394
|
if (once && !monthly && !yearly) price.custom = phrase(once, locale, labels);
|
|
325
395
|
|
|
326
396
|
const card: PricingPlanCard = {
|
|
327
397
|
key: product.plan,
|
|
328
|
-
name:
|
|
398
|
+
name: titleOf(product),
|
|
329
399
|
price,
|
|
330
400
|
features: features(product),
|
|
331
401
|
cta: { label: ctaLabel(product, labels), href },
|
|
402
|
+
offerPrices: offerPricesOf([monthly, yearly, once]),
|
|
332
403
|
};
|
|
333
404
|
const description =
|
|
334
405
|
product.description && stripFormatCharacters(product.description, true);
|
|
@@ -389,14 +460,17 @@ function splitBlocks(
|
|
|
389
460
|
annualPriceNote: _annualPriceNote,
|
|
390
461
|
priceFootnote: _priceFootnote,
|
|
391
462
|
priceFootnoteAnnualOnly: _priceFootnoteAnnualOnly,
|
|
463
|
+
offerPrices: _offerPrices,
|
|
392
464
|
...shared
|
|
393
465
|
} = card;
|
|
466
|
+
// Each block publishes only the Price it sells (#12193 D9).
|
|
394
467
|
const yearlyBlock: PricingPlanCard = {
|
|
395
468
|
key: yearly.lookupKey,
|
|
396
469
|
name: card.name,
|
|
397
470
|
price: { annual: phrase(yearly, locale, labels) },
|
|
398
471
|
features: card.features,
|
|
399
472
|
cta: { label: card.cta.label, href: yearlyHref },
|
|
473
|
+
offerPrices: offerPricesOf([yearly]),
|
|
400
474
|
};
|
|
401
475
|
if (card.priceUnit !== undefined) yearlyBlock.priceUnit = card.priceUnit;
|
|
402
476
|
if (card.priceSubhead !== undefined)
|
|
@@ -408,6 +482,7 @@ function splitBlocks(
|
|
|
408
482
|
...shared,
|
|
409
483
|
price: { monthly: phrase(monthly, locale, labels) },
|
|
410
484
|
cta: { label: card.cta.label, href: monthlyHref },
|
|
485
|
+
offerPrices: offerPricesOf([monthly]),
|
|
411
486
|
},
|
|
412
487
|
yearlyBlock,
|
|
413
488
|
];
|
|
@@ -431,10 +506,13 @@ function plansFragment(
|
|
|
431
506
|
return {
|
|
432
507
|
variant: "three-tiers-with-toggle",
|
|
433
508
|
cardLayout: "centered",
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
509
|
+
// #12174 D6 — a level priced both ways turns it on too.
|
|
510
|
+
billingToggle: cards.some((card) =>
|
|
511
|
+
[card, ...(card.levels ?? [])].some(
|
|
512
|
+
(shown) =>
|
|
513
|
+
shown.price.monthly !== undefined &&
|
|
514
|
+
shown.price.annual !== undefined,
|
|
515
|
+
),
|
|
438
516
|
),
|
|
439
517
|
plans: cards,
|
|
440
518
|
};
|
|
@@ -447,6 +525,7 @@ function plansFragment(
|
|
|
447
525
|
case "single-price-with-details":
|
|
448
526
|
return { variant: layout, plans: cards.slice(0, 1) };
|
|
449
527
|
case "features-and-plans": {
|
|
528
|
+
// A level card (#12174 D6) is never split: `product` is undefined then.
|
|
450
529
|
const split =
|
|
451
530
|
product && splitBlocks(product, cards[0]!, locale, labels);
|
|
452
531
|
const rows = product ? features(product) : [];
|
|
@@ -461,6 +540,90 @@ function plansFragment(
|
|
|
461
540
|
}
|
|
462
541
|
}
|
|
463
542
|
|
|
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
|
+
*/
|
|
547
|
+
function levelOf(card: PricingPlanCard): Omit<PricingPlanLevel, "label" | "key"> {
|
|
548
|
+
const level: Omit<PricingPlanLevel, "label" | "key"> = {
|
|
549
|
+
price: card.price,
|
|
550
|
+
features: card.features,
|
|
551
|
+
cta: card.cta,
|
|
552
|
+
};
|
|
553
|
+
if (card.description !== undefined) level.description = card.description;
|
|
554
|
+
if (card.offerPrices !== undefined) level.offerPrices = card.offerPrices;
|
|
555
|
+
if (card.priceUnit !== undefined) level.priceUnit = card.priceUnit;
|
|
556
|
+
if (card.priceSubhead !== undefined) level.priceSubhead = card.priceSubhead;
|
|
557
|
+
if (card.annualPriceNote !== undefined)
|
|
558
|
+
level.annualPriceNote = card.annualPriceNote;
|
|
559
|
+
if (card.priceFootnote !== undefined) level.priceFootnote = card.priceFootnote;
|
|
560
|
+
if (card.priceFootnoteAnnualOnly !== undefined)
|
|
561
|
+
level.priceFootnoteAnnualOnly = card.priceFootnoteAnnualOnly;
|
|
562
|
+
if (card.annualCtaHref !== undefined) level.annualCtaHref = card.annualCtaHref;
|
|
563
|
+
return level;
|
|
564
|
+
}
|
|
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
|
+
|
|
573
|
+
/**
|
|
574
|
+
* The level cards of a bound section's `offeringGroups` (#12174 D6), in the
|
|
575
|
+
* groups' order. Each level is its plan product's card as `planCard` builds
|
|
576
|
+
* it, trimmed to the level fields, labelled by the page; a level whose plan
|
|
577
|
+
* is not a shown plain plan (not shown, not a `plan`, a required product or a
|
|
578
|
+
* bundle) is dropped, and a group with no level left gives no card. The card
|
|
579
|
+
* takes the group's key, title and description — never a product's name or
|
|
580
|
+
* description, so no level carries one — and the first level's fields as its own. It is highlighted
|
|
581
|
+
* when one of its levels sells the first recommended plan among the groups'.
|
|
582
|
+
*/
|
|
583
|
+
function levelCards(
|
|
584
|
+
groups: readonly OfferingsLevelGroup[],
|
|
585
|
+
planProducts: OfferingsProduct[],
|
|
586
|
+
locale: string,
|
|
587
|
+
labels: OfferingsPricingLabels,
|
|
588
|
+
): PricingPlanCard[] {
|
|
589
|
+
// #12210 D6 rule 5 — a level names one slug, so one price point.
|
|
590
|
+
const byPlan = new Map(
|
|
591
|
+
planProducts
|
|
592
|
+
.filter((p) => p.requires === undefined)
|
|
593
|
+
.flatMap(offeringPointProducts)
|
|
594
|
+
.map((p) => [p.plan, p]),
|
|
595
|
+
);
|
|
596
|
+
const grouped = groups.flatMap((group) =>
|
|
597
|
+
group.levels.flatMap((level) => byPlan.get(level.plan) ?? []),
|
|
598
|
+
);
|
|
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;
|
|
602
|
+
return groups.flatMap((group) => {
|
|
603
|
+
const levels: PricingPlanLevel[] = group.levels.flatMap((level) => {
|
|
604
|
+
const product = byPlan.get(level.plan);
|
|
605
|
+
const card = product && planCard(product, false, locale, labels);
|
|
606
|
+
if (!card) return [];
|
|
607
|
+
const { description: _description, ...fields } = levelOf(card);
|
|
608
|
+
return [{ label: level.label, key: product.plan, ...fields, ...helperOf(product) }];
|
|
609
|
+
});
|
|
610
|
+
const first = levels[0];
|
|
611
|
+
if (!first) return [];
|
|
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;
|
|
614
|
+
const card: PricingPlanCard = { key: group.key, name: group.name, ...shown, levels };
|
|
615
|
+
if (group.description !== undefined) card.description = group.description;
|
|
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)) {
|
|
619
|
+
card.highlighted = true;
|
|
620
|
+
card.highlightStyle = "pill";
|
|
621
|
+
card.highlightLabel = labels.recommended;
|
|
622
|
+
}
|
|
623
|
+
return [card];
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
|
|
464
627
|
function addonTile(
|
|
465
628
|
product: OfferingsProduct,
|
|
466
629
|
highlighted: boolean,
|
|
@@ -473,7 +636,7 @@ function addonTile(
|
|
|
473
636
|
|
|
474
637
|
const tile: PricingAddonTile = {
|
|
475
638
|
key: product.plan,
|
|
476
|
-
name:
|
|
639
|
+
name: titleOf(product),
|
|
477
640
|
price: phrase(shown, locale, labels),
|
|
478
641
|
features: features(product),
|
|
479
642
|
cta: { label: ctaLabel(product, labels), href },
|
|
@@ -493,6 +656,184 @@ function addonTile(
|
|
|
493
656
|
return tile;
|
|
494
657
|
}
|
|
495
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
|
+
|
|
496
837
|
// #8927 D3 — `GET /v1/content/shown-offerings` sends the shown set without
|
|
497
838
|
// `workspaceId` and `organizationId` (spec 8924 D3), which the strict schema
|
|
498
839
|
// requires. Both ids become optional; an id that is present is still
|
|
@@ -507,11 +848,30 @@ function isPresent<T>(value: T | null): value is T {
|
|
|
507
848
|
return value !== null;
|
|
508
849
|
}
|
|
509
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
|
+
|
|
510
869
|
/**
|
|
511
870
|
* The products whose `{plan}` is in `plans`, plus every product a kept one
|
|
512
871
|
* `requires`, in the snapshot's order (#10044 D4); `plans` absent → all.
|
|
513
872
|
* One level of `requires` is followed: a required product is sold only
|
|
514
|
-
* 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).
|
|
515
875
|
*/
|
|
516
876
|
function narrowToPlans(
|
|
517
877
|
offerings: OfferingsProduct[],
|
|
@@ -520,12 +880,12 @@ function narrowToPlans(
|
|
|
520
880
|
if (plans === undefined) return offerings;
|
|
521
881
|
const listed = new Set(plans);
|
|
522
882
|
const kept = new Set(
|
|
523
|
-
offerings.filter((o) =>
|
|
883
|
+
offerings.filter((o) => namedIn(o, listed)).flatMap(offeringPlanSlugs),
|
|
524
884
|
);
|
|
525
885
|
for (const o of offerings) {
|
|
526
|
-
if (
|
|
886
|
+
if (namedIn(o, kept) && o.requires !== undefined) kept.add(o.requires);
|
|
527
887
|
}
|
|
528
|
-
return offerings.filter((o) =>
|
|
888
|
+
return offerings.filter((o) => namedIn(o, kept));
|
|
529
889
|
}
|
|
530
890
|
|
|
531
891
|
/**
|
|
@@ -544,6 +904,21 @@ function narrowToPlans(
|
|
|
544
904
|
* `layout` (#12140 D3) frames the plans fragment for the variant a bound
|
|
545
905
|
* section names; the cards are built the same either way. Absent, the plans
|
|
546
906
|
* fragment is the toggle layout, exactly as before. Add-ons are unaffected.
|
|
907
|
+
*
|
|
908
|
+
* `levelGroups` (#12174 D6) makes the plan cards a bound section's level
|
|
909
|
+
* cards, one per group (`levelCards`), in place of one card per plan. Absent,
|
|
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.
|
|
547
922
|
*/
|
|
548
923
|
export function offeringsPricing(
|
|
549
924
|
shownSet: unknown,
|
|
@@ -553,13 +928,23 @@ export function offeringsPricing(
|
|
|
553
928
|
plans?: readonly string[] | undefined;
|
|
554
929
|
exclude?: readonly string[] | undefined;
|
|
555
930
|
layout?: OfferingsLayout | undefined;
|
|
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;
|
|
556
937
|
},
|
|
557
938
|
): OfferingsPricing | null {
|
|
558
939
|
const parsed = shownSetSchema.safeParse(shownSet);
|
|
559
940
|
if (!parsed.success) return null;
|
|
560
941
|
const { state, offerings: shown } = parsed.data;
|
|
561
|
-
|
|
562
|
-
const
|
|
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;
|
|
563
948
|
|
|
564
949
|
// #10028 D9 — a product some shown plan requires is sold only inside that
|
|
565
950
|
// bundle (decision 6), so it gets no card of its own. Read over the whole
|
|
@@ -567,38 +952,90 @@ export function offeringsPricing(
|
|
|
567
952
|
const requiredPlans = new Set(
|
|
568
953
|
shown.map((o) => o.requires).filter((plan) => plan !== undefined),
|
|
569
954
|
);
|
|
570
|
-
const offerings = narrowToPlans(
|
|
955
|
+
const offerings = narrowToPlans(
|
|
956
|
+
shown,
|
|
957
|
+
collection === undefined ? options.plans : collectionPlans(parsed.data, collection),
|
|
958
|
+
);
|
|
571
959
|
const excluded = new Set(options.exclude);
|
|
572
960
|
// #11166 — the two group reads are exact, so an `offer` falls into neither.
|
|
573
961
|
const planProducts = offerings.filter(
|
|
574
962
|
(o) =>
|
|
575
963
|
o.ailkGroup === "plan" &&
|
|
576
|
-
!
|
|
577
|
-
!
|
|
964
|
+
!namedIn(o, requiredPlans) &&
|
|
965
|
+
!namedIn(o, excluded),
|
|
578
966
|
);
|
|
579
967
|
const addonProducts = offerings.filter((o) => o.ailkGroup === "addon");
|
|
580
968
|
const recommendedPlan = firstRecommended(planProducts);
|
|
581
969
|
const recommendedAddon = firstRecommended(addonProducts);
|
|
582
970
|
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
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);
|
|
1020
|
+
const plans = options.levelGroups
|
|
1021
|
+
? levelCards(options.levelGroups, planProducts, locale, labels)
|
|
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);
|
|
598
1033
|
|
|
599
1034
|
// Each card is keyed by its product's `{plan}`, so a lone card names its product.
|
|
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).
|
|
600
1037
|
const product =
|
|
601
|
-
plans.length === 1
|
|
1038
|
+
plans.length === 1 && !options.levelGroups && plans[0]!.levels === undefined
|
|
602
1039
|
? planProducts.find((p) => p.plan === plans[0]!.key)
|
|
603
1040
|
: undefined;
|
|
604
1041
|
return {
|