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.
- package/component-catalog.json +413 -205
- package/component-catalog.md +12 -12
- package/dist/surfaces.js +1 -1
- package/package.json +3 -3
- package/templates/apps/web/CLAUDE.md +248 -16
- package/templates/apps/web/app/[locale]/layout.tsx +7 -1
- 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/i18n/request.ts +35 -12
- 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 +1245 -49
- package/templates/apps/web/lib/__tests__/pricing-page.test.ts +875 -91
- 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 +645 -97
- package/templates/apps/web/lib/paid-section-contracts.ts +41 -1
- package/templates/apps/web/lib/pricing-page.ts +375 -50
- package/templates/apps/web/lib/served-pages.ts +38 -1
- package/templates/apps/web/messages/en.json +7 -1
- package/templates/apps/web/site-pages.config.tsx +9 -0
- package/versions.json +50 -50
|
@@ -23,8 +23,23 @@
|
|
|
23
23
|
* own `variant` names; `written` keeps it as authored, never linking the
|
|
24
24
|
* Offerings checkout. A page with no `source` anywhere renders as before.
|
|
25
25
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
26
|
+
* A selecting bound section (#12193 D5) — one naming no plans — builds its
|
|
27
|
+
* cards from Stripe: tier cards, and with `offeringCollection` every shown
|
|
28
|
+
* product of that collection, contacts included. `?plan=` and `?billing=`
|
|
29
|
+
* set two render-time fields every pricing section reads (D11), and no
|
|
30
|
+
* authored copy of a render-time field ever reaches the section (D9).
|
|
31
|
+
*
|
|
32
|
+
* A comparison table's plan column (#12246, spec
|
|
33
|
+
* docs/specs/12246-one-comparison-table-whose-columns-spec.md D3, D4) is
|
|
34
|
+
* resolved from the same shown-set read: its name, price and checkout link
|
|
35
|
+
* (`offeringsPlanColumns`), and the table opens on the period the page's
|
|
36
|
+
* cards open on. On every path a comparison table drops a cell link that
|
|
37
|
+
* reaches the Offerings checkout. The pricing section's retired
|
|
38
|
+
* `with-comparison-table` variant arrives already migrated (D7).
|
|
39
|
+
*
|
|
40
|
+
* Stripe text reaches markup only as React text through `offeringsPricing`
|
|
41
|
+
* and `offeringsPlanColumns`, and JSON-LD only through renderPage's
|
|
42
|
+
* serializer (T4).
|
|
28
43
|
*
|
|
29
44
|
* Base tree: no paid import, no `oss: false`.
|
|
30
45
|
*/
|
|
@@ -33,15 +48,21 @@ import type { DetailPage } from "@working-theory/site-pages/lib/route-family";
|
|
|
33
48
|
import { contactFormText } from "@working-theory/site-pages/pages/contact/contact-form-text";
|
|
34
49
|
import { ContactFallback } from "@working-theory/ui";
|
|
35
50
|
import {
|
|
51
|
+
PRICING_SELECT_LEVELS_MAX,
|
|
36
52
|
LOOKUP_KEY_PLAN_PATTERN,
|
|
53
|
+
pricingOpensOn,
|
|
37
54
|
type PageSection,
|
|
38
55
|
} from "@working-theory/validation";
|
|
39
56
|
import { getTranslations } from "next-intl/server";
|
|
40
57
|
import { createElement, type ReactNode } from "react";
|
|
41
58
|
|
|
59
|
+
import { resolveBaseUrl } from "../src/lib/routes";
|
|
60
|
+
|
|
42
61
|
import { browserApiOrigin } from "./api-origin.generated";
|
|
43
62
|
import {
|
|
44
63
|
OFFERINGS_CHECKOUT_PATH,
|
|
64
|
+
collectionPlans,
|
|
65
|
+
offeringsPlanColumns,
|
|
45
66
|
offeringsPricing,
|
|
46
67
|
type OfferingsPricing,
|
|
47
68
|
type OfferingsPricingLabels,
|
|
@@ -51,6 +72,7 @@ import { readSiteContactEmail } from "./site-contact-email";
|
|
|
51
72
|
|
|
52
73
|
type PricingSection = Extract<PageSection, { type: "pricing" }>;
|
|
53
74
|
type PricingData = PricingSection["data"];
|
|
75
|
+
type ComparisonTableSection = Extract<PageSection, { type: "comparison-table" }>;
|
|
54
76
|
type ItemsSection = Extract<PageSection, { type: "items" }>;
|
|
55
77
|
type CardItem = ItemsSection["data"]["items"][number];
|
|
56
78
|
|
|
@@ -162,6 +184,10 @@ const KEEP_AMOUNT_PLACEHOLDER = { amount: "{amount}" };
|
|
|
162
184
|
/** Keeps both placeholders for `withRequired` to fill (#10028 D9). */
|
|
163
185
|
const KEEP_BUNDLE_PLACEHOLDERS = { plan: "{plan}", required: "{required}" };
|
|
164
186
|
const KEEP_DEPOSIT_PLACEHOLDER = { deposit: "{deposit}" };
|
|
187
|
+
/** Keeps the price-unit placeholders for the mapper to fill (#12242 D2). */
|
|
188
|
+
const KEEP_UNIT_PLACEHOLDERS = { period: "{period}", label: "{label}" };
|
|
189
|
+
const KEEP_PERCENT_PLACEHOLDER = { percent: "{percent}" };
|
|
190
|
+
const KEEP_REGULAR_PLACEHOLDERS = { regular: "{regular}", current: "{current}" };
|
|
165
191
|
|
|
166
192
|
/** The mapper's labels and the plans section's recommendation label (D6). */
|
|
167
193
|
export async function offeringsCopy(locale: string): Promise<{
|
|
@@ -193,6 +219,20 @@ export async function offeringsCopy(locale: string): Promise<{
|
|
|
193
219
|
"{deposit}",
|
|
194
220
|
() => deposit,
|
|
195
221
|
),
|
|
222
|
+
custom: t("custom"),
|
|
223
|
+
// #12242 D2 — function replacers, so a `$&` in a Stripe unit label stays text.
|
|
224
|
+
perMonth: t("perMonth"),
|
|
225
|
+
perYear: t("perYear"),
|
|
226
|
+
unitWithLabel: (period, label) =>
|
|
227
|
+
t("unitWithLabel", KEEP_UNIT_PLACEHOLDERS)
|
|
228
|
+
.replace("{period}", () => period)
|
|
229
|
+
.replace("{label}", () => label),
|
|
230
|
+
savings: (percent) =>
|
|
231
|
+
t("savings", KEEP_PERCENT_PLACEHOLDER).replace("{percent}", () => percent),
|
|
232
|
+
regularPrice: (regular, current) =>
|
|
233
|
+
t("regularPrice", KEEP_REGULAR_PLACEHOLDERS)
|
|
234
|
+
.replace("{regular}", () => regular)
|
|
235
|
+
.replace("{current}", () => current),
|
|
196
236
|
},
|
|
197
237
|
recommendedLabel: t("recommendedForYou"),
|
|
198
238
|
addonsHeadline: t("addonsHeadline"),
|
|
@@ -221,9 +261,24 @@ const AUTHORED_COPY_FIELDS = [
|
|
|
221
261
|
"collapseFeaturesOnMobile",
|
|
222
262
|
// #12141 D9 — the plan bar's options, so a connected section keeps them.
|
|
223
263
|
"planBar",
|
|
224
|
-
"comparisonPlanBar",
|
|
225
264
|
// #12174 D2 — where a level card's switch sits.
|
|
226
265
|
"levelSwitchPlacement",
|
|
266
|
+
// #12193 D7 — a page turning the billing toggle off.
|
|
267
|
+
"hideBillingToggle",
|
|
268
|
+
// #12209 D12 — the level switch's control, its derived detail and the level heading.
|
|
269
|
+
"levelSwitchControl",
|
|
270
|
+
"levelSwitchDetail",
|
|
271
|
+
"showLevelHeading",
|
|
272
|
+
// #12242 D6 — the price amount's and unit's size and tone.
|
|
273
|
+
"priceAmountSize",
|
|
274
|
+
"priceAmountTone",
|
|
275
|
+
"priceUnitSize",
|
|
276
|
+
"priceUnitTone",
|
|
277
|
+
// #12241 D9 — the lone-card rule, the rows' details and the wide side slot.
|
|
278
|
+
"loneCard",
|
|
279
|
+
"featureRowStyle",
|
|
280
|
+
"featureDetails",
|
|
281
|
+
"wideSide",
|
|
227
282
|
] as const satisfies readonly (keyof PricingData)[];
|
|
228
283
|
|
|
229
284
|
function authoredCopy(
|
|
@@ -261,14 +316,16 @@ function isUnbound(section: PageSection): section is PricingSection {
|
|
|
261
316
|
* Whether `href` reaches the Offerings checkout route, read as a browser
|
|
262
317
|
* resolves it — a relative, absolute or dot-segment form alike, on any host,
|
|
263
318
|
* whatever the case (#12140 D2 rule 7). The path is read percent-decoded too,
|
|
264
|
-
* as the router decodes it, so `/api/%6Ffferings/checkout` is caught
|
|
265
|
-
*
|
|
319
|
+
* as the router decodes it, so `/api/%6Ffferings/checkout` is caught, and with
|
|
320
|
+
* every run of `/` or `\` read as one `/`, as Next redirects `/api//offerings`
|
|
321
|
+
* onto the route (#12246). An href no URL parser accepts is one a browser
|
|
322
|
+
* cannot follow either.
|
|
266
323
|
*/
|
|
267
324
|
function linksOfferingsCheckout(href: string | undefined): boolean {
|
|
268
325
|
if (href === undefined) return false;
|
|
269
326
|
const base = "https://site.invalid";
|
|
270
327
|
const reaches = (path: string) =>
|
|
271
|
-
path.toLowerCase().startsWith(OFFERINGS_CHECKOUT_PATH);
|
|
328
|
+
path.replace(/[\\/]+/g, "/").toLowerCase().startsWith(OFFERINGS_CHECKOUT_PATH);
|
|
272
329
|
let path: string;
|
|
273
330
|
try {
|
|
274
331
|
path = new URL(href, base).pathname;
|
|
@@ -294,11 +351,11 @@ function sellsOfferings(plan: PricingPlan): boolean {
|
|
|
294
351
|
);
|
|
295
352
|
}
|
|
296
353
|
|
|
297
|
-
type ComparisonGroups =
|
|
354
|
+
type ComparisonGroups = ComparisonTableSection["data"]["groups"];
|
|
298
355
|
|
|
299
356
|
/** Whether any comparison cell's `link` reaches the Offerings checkout. */
|
|
300
|
-
function cellsSellOfferings(groups: ComparisonGroups
|
|
301
|
-
return
|
|
357
|
+
function cellsSellOfferings(groups: ComparisonGroups): boolean {
|
|
358
|
+
return groups.some((group) =>
|
|
302
359
|
group.rows.some((row) =>
|
|
303
360
|
Object.values(row.values).some(
|
|
304
361
|
(value) =>
|
|
@@ -310,9 +367,8 @@ function cellsSellOfferings(groups: ComparisonGroups | undefined): boolean {
|
|
|
310
367
|
|
|
311
368
|
/**
|
|
312
369
|
* A written section with every card, extra tier and add-on tile that links the
|
|
313
|
-
* Offerings checkout dropped,
|
|
314
|
-
*
|
|
315
|
-
* the section itself when nothing is dropped.
|
|
370
|
+
* Offerings checkout dropped (#12140 D2 rule 7), so a written price can never
|
|
371
|
+
* sell an Offerings Price; the section itself when nothing is dropped.
|
|
316
372
|
*/
|
|
317
373
|
function withoutCheckoutLinks(section: PricingSection): PricingSection {
|
|
318
374
|
const { extraTier, ...data } = section.data;
|
|
@@ -321,12 +377,10 @@ function withoutCheckoutLinks(section: PricingSection): PricingSection {
|
|
|
321
377
|
(addon) => !linksOfferingsCheckout(addon.cta?.href),
|
|
322
378
|
);
|
|
323
379
|
const dropTier = extraTier !== undefined && sellsOfferings(extraTier);
|
|
324
|
-
const dropCells = cellsSellOfferings(data.comparisonGroups);
|
|
325
380
|
if (
|
|
326
381
|
plans.length === data.plans.length &&
|
|
327
382
|
addons?.length === data.addons?.length &&
|
|
328
|
-
!dropTier
|
|
329
|
-
!dropCells
|
|
383
|
+
!dropTier
|
|
330
384
|
)
|
|
331
385
|
return section;
|
|
332
386
|
return {
|
|
@@ -335,32 +389,24 @@ function withoutCheckoutLinks(section: PricingSection): PricingSection {
|
|
|
335
389
|
...data,
|
|
336
390
|
plans,
|
|
337
391
|
...(addons !== undefined ? { addons } : {}),
|
|
338
|
-
...(dropCells && data.comparisonGroups
|
|
339
|
-
? { comparisonGroups: withoutCellLinks(data.comparisonGroups, true) }
|
|
340
|
-
: {}),
|
|
341
392
|
...(extraTier !== undefined && !dropTier ? { extraTier } : {}),
|
|
342
393
|
},
|
|
343
394
|
};
|
|
344
395
|
}
|
|
345
396
|
|
|
346
397
|
/**
|
|
347
|
-
*
|
|
348
|
-
*
|
|
349
|
-
*
|
|
350
|
-
* the Offerings checkout is dropped.
|
|
398
|
+
* A comparison table's groups with each object cell's `link` that reaches
|
|
399
|
+
* the Offerings checkout dropped (#12140 D2 rule 7, extended to the table by
|
|
400
|
+
* #12246 D3), so a hand-written cell can never sell an Offerings Price.
|
|
351
401
|
*/
|
|
352
|
-
function
|
|
353
|
-
groups: ComparisonGroups,
|
|
354
|
-
checkoutOnly = false,
|
|
355
|
-
): ComparisonGroups {
|
|
402
|
+
function withoutCheckoutCellLinks(groups: ComparisonGroups): ComparisonGroups {
|
|
356
403
|
return groups.map((group) => ({
|
|
357
404
|
...group,
|
|
358
405
|
rows: group.rows.map((row) => ({
|
|
359
406
|
...row,
|
|
360
407
|
values: Object.fromEntries(
|
|
361
408
|
Object.entries(row.values).map(([key, value]) => {
|
|
362
|
-
if (typeof value !== "object"
|
|
363
|
-
if (checkoutOnly && !linksOfferingsCheckout(value.link?.href))
|
|
409
|
+
if (typeof value !== "object" || !linksOfferingsCheckout(value.link?.href))
|
|
364
410
|
return [key, value];
|
|
365
411
|
const { link: _, ...cell } = value;
|
|
366
412
|
return [key, cell];
|
|
@@ -414,6 +460,19 @@ export type OfferingsGroups = ReadonlyMap<PricingSection, PricingData | null>;
|
|
|
414
460
|
* A bound section's `offeringGroups` (#12174 D6) narrow it to its levels'
|
|
415
461
|
* plans and map them as level cards (`offeringsPricing`'s `levelGroups`);
|
|
416
462
|
* those plans are excluded from the page-level mapping too.
|
|
463
|
+
*
|
|
464
|
+
* A selecting bound section (#12193 D5) — no `offeringPlans` and no
|
|
465
|
+
* `offeringGroups` — maps with `tiers`, its `offeringCollection` as
|
|
466
|
+
* `collection` and the site's origin for its contacts' links; a collection's
|
|
467
|
+
* plans are excluded from the page-level mapping too.
|
|
468
|
+
*
|
|
469
|
+
* A bound section whose `levelSwitchControl` is `select` maps with a level
|
|
470
|
+
* limit of twenty (#12209 D8), and a selecting one with `separateTiers` maps
|
|
471
|
+
* every plan as its own card (#12209 D11).
|
|
472
|
+
*
|
|
473
|
+
* A section's `offeringPlans` may name a contact by its slug (#12238): that
|
|
474
|
+
* contact's card or tile is mapped with the named plans. The page's `plans`
|
|
475
|
+
* names none.
|
|
417
476
|
*/
|
|
418
477
|
export function offeringsFragments(
|
|
419
478
|
declared: PageSection[],
|
|
@@ -430,7 +489,21 @@ export function offeringsFragments(
|
|
|
430
489
|
isUnbound(s) && isPlansSection(s) && s.data.offeringPlans !== undefined,
|
|
431
490
|
);
|
|
432
491
|
const bound = declared.filter(isBound);
|
|
433
|
-
const exclude = [
|
|
492
|
+
const exclude = [
|
|
493
|
+
...[...listed, ...bound].flatMap((s) => namedPlans(s) ?? []),
|
|
494
|
+
...bound.flatMap(({ data }) =>
|
|
495
|
+
data.offeringCollection === undefined ? [] : collectionPlans(shownSet, data.offeringCollection),
|
|
496
|
+
),
|
|
497
|
+
];
|
|
498
|
+
// An unparseable base URL leaves every contact link external, never a throw.
|
|
499
|
+
// Every call below takes it: a card footnote's link reads it in any section
|
|
500
|
+
// (#12243 AC-6), not only a section's contact cards in tier mode.
|
|
501
|
+
let siteOrigin: string | undefined;
|
|
502
|
+
try {
|
|
503
|
+
siteOrigin = new URL(resolveBaseUrl()).origin;
|
|
504
|
+
} catch {
|
|
505
|
+
siteOrigin = undefined;
|
|
506
|
+
}
|
|
434
507
|
const groups = new Map<PricingSection, PricingData | null>(
|
|
435
508
|
listed.map((section) => [
|
|
436
509
|
section,
|
|
@@ -438,17 +511,38 @@ export function offeringsFragments(
|
|
|
438
511
|
locale,
|
|
439
512
|
labels,
|
|
440
513
|
plans: section.data.offeringPlans,
|
|
514
|
+
contactPlans: section.data.offeringPlans,
|
|
515
|
+
siteOrigin,
|
|
441
516
|
})?.plans ?? null,
|
|
442
517
|
]),
|
|
443
518
|
);
|
|
444
519
|
for (const section of bound) {
|
|
445
|
-
const {
|
|
520
|
+
const {
|
|
521
|
+
variant,
|
|
522
|
+
offeringGroups,
|
|
523
|
+
offeringCollection,
|
|
524
|
+
levelSwitchControl,
|
|
525
|
+
separateTiers,
|
|
526
|
+
annualPriceLine,
|
|
527
|
+
annualStrikePrice,
|
|
528
|
+
} = section.data;
|
|
446
529
|
const addons = variant === "addons";
|
|
530
|
+
const named = namedPlans(section);
|
|
447
531
|
const mapped = offeringsPricing(shownSet, {
|
|
448
532
|
locale,
|
|
449
533
|
labels,
|
|
450
|
-
plans:
|
|
534
|
+
plans: named ?? plans,
|
|
535
|
+
contactPlans: section.data.offeringPlans,
|
|
536
|
+
siteOrigin,
|
|
451
537
|
...(offeringGroups ? { levelGroups: offeringGroups } : {}),
|
|
538
|
+
// #12193 D5 — a section that names no plans builds its cards from Stripe.
|
|
539
|
+
...(named === undefined ? { tiers: true } : {}),
|
|
540
|
+
...(offeringCollection !== undefined ? { collection: offeringCollection } : {}),
|
|
541
|
+
...(levelSwitchControl === "select" ? { levelLimit: PRICING_SELECT_LEVELS_MAX } : {}),
|
|
542
|
+
...(separateTiers === true ? { groupTiers: false } : {}),
|
|
543
|
+
// #12242 D4, D5 — read before mapping, never placed.
|
|
544
|
+
...(annualPriceLine !== undefined ? { annualLine: annualPriceLine } : {}),
|
|
545
|
+
...(annualStrikePrice === true ? { strikeMonthly: true } : {}),
|
|
452
546
|
...(variant === "addons"
|
|
453
547
|
? {}
|
|
454
548
|
: { layout: variant ?? "three-tiers-with-toggle" }),
|
|
@@ -459,6 +553,7 @@ export function offeringsFragments(
|
|
|
459
553
|
locale,
|
|
460
554
|
labels,
|
|
461
555
|
plans,
|
|
556
|
+
siteOrigin,
|
|
462
557
|
...(exclude.length > 0 ? { exclude } : {}),
|
|
463
558
|
});
|
|
464
559
|
return { pricing, groups };
|
|
@@ -467,7 +562,6 @@ export function offeringsFragments(
|
|
|
467
562
|
/** The layouts that render every plan they are given (#12174 D7). */
|
|
468
563
|
const EVERY_PLAN_LAYOUTS: ReadonlySet<PricingData["variant"]> = new Set([
|
|
469
564
|
"three-tiers-with-toggle",
|
|
470
|
-
"with-comparison-table",
|
|
471
565
|
"band-hero",
|
|
472
566
|
] as const);
|
|
473
567
|
|
|
@@ -535,9 +629,8 @@ const BOUND_KEPT_FIELDS = [
|
|
|
535
629
|
* D6; `billingToggle` stays the mapper's computed one), and a `?plan=`
|
|
536
630
|
* recommendation (#8842) — applied by each section to its own cards.
|
|
537
631
|
*
|
|
538
|
-
* A bound slot (#12140 D6) also keeps its `source`, its band parts
|
|
539
|
-
*
|
|
540
|
-
* mapper's; never an authored plan, extra tier or comparison-cell link.
|
|
632
|
+
* A bound slot (#12140 D6) also keeps its `source`, its band parts and its
|
|
633
|
+
* own `features` over the mapper's; never an authored plan or extra tier.
|
|
541
634
|
*/
|
|
542
635
|
function stripePlansSection(
|
|
543
636
|
slot: PricingSection | undefined,
|
|
@@ -552,15 +645,11 @@ function stripePlansSection(
|
|
|
552
645
|
const features = bound
|
|
553
646
|
? (slot.data.features ?? fragment.features)
|
|
554
647
|
: undefined;
|
|
555
|
-
const comparisonGroups = bound ? slot.data.comparisonGroups : undefined;
|
|
556
648
|
return {
|
|
557
649
|
id: slot?.id ?? "offerings-plans",
|
|
558
650
|
type: "pricing",
|
|
559
651
|
data: {
|
|
560
652
|
...authoredCopy(slot, bound ? BOUND_KEPT_FIELDS : []),
|
|
561
|
-
...(comparisonGroups
|
|
562
|
-
? { comparisonGroups: withoutCellLinks(comparisonGroups) }
|
|
563
|
-
: {}),
|
|
564
653
|
...fragment,
|
|
565
654
|
...(cardLayout !== undefined ? { cardLayout } : {}),
|
|
566
655
|
...(features !== undefined ? { features } : {}),
|
|
@@ -634,7 +723,7 @@ export function withOfferings(
|
|
|
634
723
|
// plans and carries its own headline, so a lone tile is never an
|
|
635
724
|
// unlabeled band (design review B2).
|
|
636
725
|
...(addonsSlot ? {} : { headline: addonsHeadline, gapAbove: "tight" }),
|
|
637
|
-
...authoredCopy(addonsSlot
|
|
726
|
+
...authoredCopy(addonsSlot),
|
|
638
727
|
...pricing.addons,
|
|
639
728
|
} as PricingData,
|
|
640
729
|
};
|
|
@@ -668,7 +757,7 @@ export function withOfferings(
|
|
|
668
757
|
id: section.id,
|
|
669
758
|
type: "pricing",
|
|
670
759
|
data: {
|
|
671
|
-
...authoredCopy(section, ["
|
|
760
|
+
...authoredCopy(section, ["source"]),
|
|
672
761
|
...fragment,
|
|
673
762
|
} as PricingData,
|
|
674
763
|
});
|
|
@@ -759,6 +848,221 @@ export function pagePlans(frontmatter: unknown): string[] | undefined {
|
|
|
759
848
|
return plans.filter((plan): plan is string => typeof plan === "string");
|
|
760
849
|
}
|
|
761
850
|
|
|
851
|
+
/** The render-time fields an authored section must never carry (#12193 D9, D11). */
|
|
852
|
+
const RENDER_TIME_SECTION_FIELDS = ["selectedPlan", "billingPeriod"] as const;
|
|
853
|
+
|
|
854
|
+
/**
|
|
855
|
+
* `card` without an authored `offerPrices` (#12193 D9), `priceParts` (#12242
|
|
856
|
+
* D1) or `images` (#12241 D8, the mapper's Stripe images), on it and its levels.
|
|
857
|
+
*/
|
|
858
|
+
function withoutOfferPrices<T extends object>(card: T): T {
|
|
859
|
+
const { offerPrices: _o, priceParts: _p, images: _i, ...rest } = card as T & {
|
|
860
|
+
offerPrices?: unknown;
|
|
861
|
+
priceParts?: unknown;
|
|
862
|
+
images?: unknown;
|
|
863
|
+
levels?: object[];
|
|
864
|
+
};
|
|
865
|
+
const levels = (rest as { levels?: object[] }).levels;
|
|
866
|
+
return (levels ? { ...rest, levels: levels.map((level) => withoutOfferPrices(level)) } : rest) as T;
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
/** Whether `card`, or a level of it, carries an `offerPrices`, `priceParts` or `images` key. */
|
|
870
|
+
function carriesOfferPrices(card: object): boolean {
|
|
871
|
+
return (
|
|
872
|
+
"offerPrices" in card ||
|
|
873
|
+
"priceParts" in card ||
|
|
874
|
+
"images" in card ||
|
|
875
|
+
((card as { levels?: object[] }).levels ?? []).some(carriesOfferPrices)
|
|
876
|
+
);
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
function isComparisonTable(section: PageSection): section is ComparisonTableSection {
|
|
880
|
+
return section.type === "comparison-table";
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
/** Whether a comparison table carries an authored render-time field (#12246 D3): its `billingPeriod`, a column's `offering`. */
|
|
884
|
+
function tableAuthored(section: ComparisonTableSection): boolean {
|
|
885
|
+
return "billingPeriod" in section.data || section.data.columns.some((column) => "offering" in column);
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
/** `section` without its authored render-time fields (#12246 D3). */
|
|
889
|
+
function withoutTableRenderTimeFields(section: ComparisonTableSection): ComparisonTableSection {
|
|
890
|
+
const { billingPeriod: _b, ...data } = section.data as ComparisonTableSection["data"] & {
|
|
891
|
+
billingPeriod?: unknown;
|
|
892
|
+
};
|
|
893
|
+
return {
|
|
894
|
+
...section,
|
|
895
|
+
data: {
|
|
896
|
+
...data,
|
|
897
|
+
columns: data.columns.map((column) => {
|
|
898
|
+
const { offering: _o, ...rest } = column as typeof column & { offering?: unknown };
|
|
899
|
+
return rest;
|
|
900
|
+
}),
|
|
901
|
+
},
|
|
902
|
+
};
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
/**
|
|
906
|
+
* The page's sections with every authored render-time field removed (#12193
|
|
907
|
+
* D9, D11): a plan's, level's, written card's or extra tier's `offerPrices`
|
|
908
|
+
* or `priceParts` (#12242 D1),
|
|
909
|
+
* and a section's `selectedPlan` and `billingPeriod`, so a page author or a
|
|
910
|
+
* content-write agent can never declare a JSON-LD price or a selected level.
|
|
911
|
+
* A comparison table's `billingPeriod` and its columns' `offering` too
|
|
912
|
+
* (#12246 D3), so no author declares a plan column's price or link. The
|
|
913
|
+
* input array itself when there is none.
|
|
914
|
+
*/
|
|
915
|
+
function withoutRenderTimeFields(sections: PageSection[]): PageSection[] {
|
|
916
|
+
const authored = (section: PricingSection) => {
|
|
917
|
+
const { plans, writtenPlans, extraTier } = section.data;
|
|
918
|
+
return (
|
|
919
|
+
RENDER_TIME_SECTION_FIELDS.some((field) => field in section.data) ||
|
|
920
|
+
[...plans, ...(writtenPlans ?? []), ...(extraTier ? [extraTier] : [])].some(carriesOfferPrices)
|
|
921
|
+
);
|
|
922
|
+
};
|
|
923
|
+
if (
|
|
924
|
+
!sections.some(
|
|
925
|
+
(s) => (isPricing(s) && authored(s)) || (isComparisonTable(s) && tableAuthored(s)),
|
|
926
|
+
)
|
|
927
|
+
)
|
|
928
|
+
return sections;
|
|
929
|
+
return sections.map((section) => {
|
|
930
|
+
if (isComparisonTable(section))
|
|
931
|
+
return tableAuthored(section) ? withoutTableRenderTimeFields(section) : section;
|
|
932
|
+
if (!isPricing(section) || !authored(section)) return section;
|
|
933
|
+
const { selectedPlan: _p, billingPeriod: _b, ...data } = section.data as PricingData & {
|
|
934
|
+
selectedPlan?: unknown;
|
|
935
|
+
billingPeriod?: unknown;
|
|
936
|
+
};
|
|
937
|
+
return {
|
|
938
|
+
...section,
|
|
939
|
+
data: {
|
|
940
|
+
...data,
|
|
941
|
+
plans: data.plans.map(withoutOfferPrices),
|
|
942
|
+
...(data.writtenPlans ? { writtenPlans: data.writtenPlans.map(withoutOfferPrices) } : {}),
|
|
943
|
+
...(data.extraTier ? { extraTier: withoutOfferPrices(data.extraTier) } : {}),
|
|
944
|
+
},
|
|
945
|
+
};
|
|
946
|
+
});
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
/** The billing periods `?billing=` may name (#12193 D11): the toggle's two values. */
|
|
950
|
+
const BILLING_PERIODS = new Set(["monthly", "annual"]);
|
|
951
|
+
|
|
952
|
+
/**
|
|
953
|
+
* `sections` with the render-time `selectedPlan` and `billingPeriod` on every
|
|
954
|
+
* pricing section (#12193 D11) — `selectedPlan` only for a `{plan}`-grammar
|
|
955
|
+
* `plan`, `billingPeriod` only for `monthly` or `annual` — so the server render
|
|
956
|
+
* opens that level and period. `sections` itself when neither applies.
|
|
957
|
+
*/
|
|
958
|
+
function withSelection(
|
|
959
|
+
sections: PageSection[],
|
|
960
|
+
plan: string | undefined,
|
|
961
|
+
period: string | undefined,
|
|
962
|
+
): PageSection[] {
|
|
963
|
+
const selected = {
|
|
964
|
+
...(plan !== undefined && LOOKUP_KEY_PLAN_PATTERN.test(plan) ? { selectedPlan: plan } : {}),
|
|
965
|
+
...(period !== undefined && BILLING_PERIODS.has(period) ? { billingPeriod: period } : {}),
|
|
966
|
+
};
|
|
967
|
+
if (Object.keys(selected).length === 0) return sections;
|
|
968
|
+
return sections.map((section) =>
|
|
969
|
+
isPricing(section)
|
|
970
|
+
? // Render-time fields the section reads, not authored ones.
|
|
971
|
+
{ ...section, data: { ...section.data, ...selected } as PricingData }
|
|
972
|
+
: section,
|
|
973
|
+
);
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
/** The shown set a page's plan columns resolve from, with the mapper's copy (#12246 D3). */
|
|
977
|
+
interface PlanColumnSource {
|
|
978
|
+
shownSet: unknown;
|
|
979
|
+
locale: string;
|
|
980
|
+
labels: OfferingsPricingLabels;
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
/**
|
|
984
|
+
* The period a page's comparison tables open on (#12246 D4): a valid
|
|
985
|
+
* `?billing=` wins; else the period the page's first plans section opens its
|
|
986
|
+
* cards on, by `Pricing`'s own rule (`pricingOpensOn`) — only the toggle
|
|
987
|
+
* layout shows that period, every other layout shows monthly — and monthly on
|
|
988
|
+
* a page with no plans section left. So the server HTML shows the period the
|
|
989
|
+
* cards show.
|
|
990
|
+
*/
|
|
991
|
+
function startPeriod(sections: PageSection[], period: string | undefined): "monthly" | "annual" {
|
|
992
|
+
const plans = sections.find(isPlansSection);
|
|
993
|
+
const toggles = (plans?.data.variant ?? "three-tiers-with-toggle") === "three-tiers-with-toggle";
|
|
994
|
+
return pricingOpensOn(plans && toggles ? plans.data : {}, period);
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
/**
|
|
998
|
+
* The page's comparison tables on a pricing page (#12246 D3, D4): each
|
|
999
|
+
* drops a cell link that reaches the Offerings checkout; a table with a
|
|
1000
|
+
* plan column also takes the render-time `billingPeriod` its page opens on,
|
|
1001
|
+
* and each plan column the shown set shows its render-time `offering`
|
|
1002
|
+
* (`source` is `null` off the shown path, so every plan column renders as a
|
|
1003
|
+
* typed one). A section with neither, and every section of another type,
|
|
1004
|
+
* comes back as the same object.
|
|
1005
|
+
*/
|
|
1006
|
+
function withPlanColumns(
|
|
1007
|
+
sections: PageSection[],
|
|
1008
|
+
{ source, period }: { source: PlanColumnSource | null; period: string | undefined },
|
|
1009
|
+
): PageSection[] {
|
|
1010
|
+
const tables = sections.filter(isComparisonTable);
|
|
1011
|
+
if (tables.length === 0) return sections;
|
|
1012
|
+
const slugs = tables.flatMap((t) => t.data.columns.flatMap((c) => (c.plan === undefined ? [] : [c.plan])));
|
|
1013
|
+
const resolved =
|
|
1014
|
+
source && slugs.length > 0
|
|
1015
|
+
? offeringsPlanColumns(source.shownSet, slugs, { locale: source.locale, labels: source.labels })
|
|
1016
|
+
: new Map();
|
|
1017
|
+
const billingPeriod = startPeriod(sections, period);
|
|
1018
|
+
return sections.map((section) => {
|
|
1019
|
+
if (!isComparisonTable(section)) return section;
|
|
1020
|
+
const planned = section.data.columns.some((c) => c.plan !== undefined);
|
|
1021
|
+
const linked = cellsSellOfferings(section.data.groups);
|
|
1022
|
+
if (!planned && !linked) return section;
|
|
1023
|
+
return {
|
|
1024
|
+
...section,
|
|
1025
|
+
data: {
|
|
1026
|
+
...section.data,
|
|
1027
|
+
...(linked ? { groups: withoutCheckoutCellLinks(section.data.groups) } : {}),
|
|
1028
|
+
...(planned
|
|
1029
|
+
? {
|
|
1030
|
+
columns: section.data.columns.map((column) => {
|
|
1031
|
+
const offering = column.plan === undefined ? undefined : resolved.get(column.plan);
|
|
1032
|
+
return offering ? { ...column, offering } : column;
|
|
1033
|
+
}),
|
|
1034
|
+
// A render-time field the section reads, not an authored one.
|
|
1035
|
+
billingPeriod,
|
|
1036
|
+
}
|
|
1037
|
+
: {}),
|
|
1038
|
+
} as ComparisonTableSection["data"],
|
|
1039
|
+
};
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
/**
|
|
1044
|
+
* The hub's `pricingPagesHeading` override (#12213 AC-1): the heading that
|
|
1045
|
+
* replaces the `pricingPages.heading` message on the generated `pricing-pages`
|
|
1046
|
+
* items section, or `undefined` when unset.
|
|
1047
|
+
*/
|
|
1048
|
+
export function pricingPagesHeading(frontmatter: unknown): string | undefined {
|
|
1049
|
+
if (frontmatter === null || typeof frontmatter !== "object") return undefined;
|
|
1050
|
+
const { pricingPagesHeading: value } = frontmatter as {
|
|
1051
|
+
pricingPagesHeading?: unknown;
|
|
1052
|
+
};
|
|
1053
|
+
return typeof value === "string" ? value : undefined;
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
/**
|
|
1057
|
+
* Whether the hub's generated `pricing-pages` items section is shown (#12213
|
|
1058
|
+
* AC-2, AC-3): on by default, off only when `pricingPagesSection` is `false`.
|
|
1059
|
+
*/
|
|
1060
|
+
export function pricingPagesSectionEnabled(frontmatter: unknown): boolean {
|
|
1061
|
+
if (frontmatter === null || typeof frontmatter !== "object") return true;
|
|
1062
|
+
const { pricingPagesSection } = frontmatter as { pricingPagesSection?: unknown };
|
|
1063
|
+
return pricingPagesSection !== false;
|
|
1064
|
+
}
|
|
1065
|
+
|
|
762
1066
|
/**
|
|
763
1067
|
* One Pricing page's sections in its Offerings state (#10044 D5): `/pricing`'s
|
|
764
1068
|
* three-state choice with the page's own `plans` passed through.
|
|
@@ -767,26 +1071,42 @@ export function pagePlans(frontmatter: unknown): string[] | undefined {
|
|
|
767
1071
|
* no read;
|
|
768
1072
|
* - unconnected → the written sections (`?plan=` moving the recommendation);
|
|
769
1073
|
* - shown → the page's Stripe cards in place of its `pricing` sections,
|
|
770
|
-
* when any of its plans is shown
|
|
1074
|
+
* when any of its plans is shown, or a section maps a contact (#12238) —
|
|
1075
|
+
* each plan group's own plans in its
|
|
771
1076
|
* place (#12103 D2), each bound and written section in its place (#12140);
|
|
772
1077
|
* a page whose only pricing left is written takes the contact email;
|
|
773
1078
|
* - anything else → the contact email in their place.
|
|
774
1079
|
* On the written states a `source: written` section never links the
|
|
775
|
-
* Offerings checkout (#12140 D2 rule 7).
|
|
1080
|
+
* Offerings checkout (#12140 D2 rule 7). On every path the authored
|
|
1081
|
+
* render-time fields are removed first, each comparison table's plan columns
|
|
1082
|
+
* are resolved from the shown set the page read (#12246 D3; typed off the
|
|
1083
|
+
* shown path), and `?plan=` / `?billing=`'s are set last (#12193 D9, D11).
|
|
776
1084
|
*/
|
|
777
1085
|
export async function pricingSections(
|
|
778
|
-
|
|
1086
|
+
authored: PageSection[],
|
|
779
1087
|
options: {
|
|
780
1088
|
plans: readonly string[] | undefined;
|
|
781
1089
|
plan: string | undefined;
|
|
1090
|
+
period?: string | undefined;
|
|
782
1091
|
locale: string;
|
|
783
1092
|
},
|
|
784
1093
|
): Promise<PageSection[]> {
|
|
785
|
-
const {
|
|
1094
|
+
const { plan, period } = options;
|
|
1095
|
+
const { sections, source } = await sectionsFor(withoutRenderTimeFields(authored), options);
|
|
1096
|
+
return withSelection(withPlanColumns(sections, { source, period }), plan, period);
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
async function sectionsFor(
|
|
1100
|
+
declared: PageSection[],
|
|
1101
|
+
{ plans, plan, locale }: { plans: readonly string[] | undefined; plan: string | undefined; locale: string },
|
|
1102
|
+
): Promise<{ sections: PageSection[]; source: PlanColumnSource | null }> {
|
|
786
1103
|
const written = declared.some(isWritten)
|
|
787
1104
|
? declared.map((s) => (isWritten(s) ? withoutCheckoutLinks(s) : s))
|
|
788
1105
|
: declared;
|
|
789
|
-
const asWritten = () => (
|
|
1106
|
+
const asWritten = () => ({
|
|
1107
|
+
sections: plan ? withRecommendedPlan(written, plan) : written,
|
|
1108
|
+
source: null,
|
|
1109
|
+
});
|
|
790
1110
|
if (plans !== undefined && plans.length === 0) return asWritten();
|
|
791
1111
|
const priced = declared.filter(isPricing);
|
|
792
1112
|
if (priced.length > 0 && priced.every(isWritten)) return asWritten();
|
|
@@ -801,10 +1121,14 @@ export async function pricingSections(
|
|
|
801
1121
|
labels,
|
|
802
1122
|
plans,
|
|
803
1123
|
});
|
|
804
|
-
|
|
1124
|
+
// #12238 — a page-level mapping with nothing to show (a shown set whose
|
|
1125
|
+
// only members are contacts) still places the bound and listed sections'
|
|
1126
|
+
// own cards when one of them mapped any; a set that is not current maps
|
|
1127
|
+
// none, so it keeps the contact path.
|
|
1128
|
+
if (pricing !== null || [...groups.values()].some((g) => g !== null)) {
|
|
805
1129
|
const placed = withOfferings(
|
|
806
1130
|
declared,
|
|
807
|
-
pricing,
|
|
1131
|
+
pricing ?? { plans: null, addons: null },
|
|
808
1132
|
plan,
|
|
809
1133
|
recommendedLabel,
|
|
810
1134
|
addonsHeadline,
|
|
@@ -813,10 +1137,11 @@ export async function pricingSections(
|
|
|
813
1137
|
// Every pricing section left but a written one is a Stripe one; none
|
|
814
1138
|
// means nothing shown, and written prices never stand in for the
|
|
815
1139
|
// catalogue (#12140 D2 rule 5).
|
|
816
|
-
if (placed.some((s) => isPricing(s) && !isWritten(s)))
|
|
1140
|
+
if (placed.some((s) => isPricing(s) && !isWritten(s)))
|
|
1141
|
+
return { sections: placed, source: { shownSet: read.shownSet, locale, labels } };
|
|
817
1142
|
}
|
|
818
1143
|
}
|
|
819
|
-
return withContactFallback(declared);
|
|
1144
|
+
return { sections: withContactFallback(declared), source: null };
|
|
820
1145
|
}
|
|
821
1146
|
|
|
822
1147
|
/**
|