create-ailk 0.45.0 → 0.46.1

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.
Files changed (42) hide show
  1. package/README.md +6 -3
  2. package/component-catalog.json +217 -4
  3. package/component-catalog.md +10 -7
  4. package/dist/lib/env-catalog.js +1 -1
  5. package/dist/lib/import-mdx.js +10 -2
  6. package/dist/seed-workspace.d.ts +1 -1
  7. package/dist/seed-workspace.js +10 -3
  8. package/dist/surfaces.js +1 -1
  9. package/package.json +3 -3
  10. package/templates/apps/api/.env.example +23 -0
  11. package/templates/apps/api/CLAUDE.md +13 -6
  12. package/templates/apps/api/src/lib/__mocks__/prisma.ts +11 -0
  13. package/templates/apps/mcp/.env.example +8 -0
  14. package/templates/apps/mcp/CLAUDE.md +22 -6
  15. package/templates/apps/web/.env.example +1 -1
  16. package/templates/apps/web/CLAUDE.md +80 -16
  17. package/templates/apps/web/app/.well-known/mcp.json/route.ts +6 -7
  18. package/templates/apps/web/app/[locale]/layout.tsx +10 -7
  19. package/templates/apps/web/app/api/site-status/__tests__/route.test.ts +120 -0
  20. package/templates/apps/web/app/api/site-status/route.ts +62 -0
  21. package/templates/apps/web/app/llms.txt/route.ts +3 -3
  22. package/templates/apps/web/app/openapi.json/__tests__/route.test.ts +21 -4
  23. package/templates/apps/web/app/openapi.json/route.ts +10 -9
  24. package/templates/apps/web/app/sitemap.xml/route.ts +3 -3
  25. package/templates/apps/web/auth.ts +25 -1
  26. package/templates/apps/web/lib/__tests__/fixtures/mcp-stub-server.ts +10 -3
  27. package/templates/apps/web/lib/__tests__/mcp-served-tools.test.ts +61 -0
  28. package/templates/apps/web/lib/__tests__/offerings-pricing.test.ts +384 -1
  29. package/templates/apps/web/lib/__tests__/pricing-page.test.ts +675 -0
  30. package/templates/apps/web/lib/__tests__/site-brand.test.ts +5 -6
  31. package/templates/apps/web/lib/__tests__/site-visibility.test.ts +64 -0
  32. package/templates/apps/web/lib/mcp-oauth.ts +64 -0
  33. package/templates/apps/web/lib/mcp-served-tools.ts +51 -9
  34. package/templates/apps/web/lib/offerings-pricing.ts +173 -20
  35. package/templates/apps/web/lib/pricing-page.ts +382 -43
  36. package/templates/apps/web/lib/site-brand.tsx +1 -7
  37. package/templates/apps/web/lib/site-visibility.ts +45 -0
  38. package/templates/apps/web/messages/en.json +9 -0
  39. package/templates/apps/web/middleware.ts +16 -1
  40. package/templates/apps/web/src/lib/routes.ts +3 -3
  41. package/versions.json +51 -51
  42. package/templates/apps/web/app/.well-known/ai-plugin.json/route.ts +0 -93
@@ -1,18 +1,35 @@
1
1
  /**
2
2
  * The shared Pricing render (#10044 D5, AC-4): which offering pages `/pricing`
3
3
  * lists, the card it lists each with, and `plans: []` reading no Stripe data.
4
+ * #12103: plan groups (AC-2), the default Recommended's pill (AC-3) and the
5
+ * authored card layout (AC-5), through the pure `offeringsFragments` and
6
+ * `withOfferings`. #12140: bound (`source: offerings`) and written sections,
7
+ * the layout the page picks, the kept comparison grid, and the 0.74.0 page
8
+ * for a section with no `source`.
4
9
  */
5
10
  import {
6
11
  PageSectionsSchema,
12
+ workspaceShownSetSchema,
13
+ type OfferingsPrice,
14
+ type OfferingsProduct,
7
15
  type PageSection,
16
+ type WorkspaceShownSet,
8
17
  } from "@working-theory/validation";
9
18
 
19
+ import {
20
+ OFFERINGS_CHECKOUT_PATH,
21
+ offeringsPricing,
22
+ type OfferingsPricingLabels,
23
+ } from "../offerings-pricing";
10
24
  import {
11
25
  offeringPricingPages,
26
+ offeringsFragments,
12
27
  pagePlans,
13
28
  PRICING_HUB_SLUG,
14
29
  pricingPageCard,
15
30
  pricingSections,
31
+ withContactFallback,
32
+ withOfferings,
16
33
  } from "../pricing-page";
17
34
  import type { DetailPage } from "@working-theory/site-pages/lib/route-family";
18
35
 
@@ -140,3 +157,661 @@ describe("pricingSections (#10044 AC-4)", () => {
140
157
  );
141
158
  });
142
159
  });
160
+
161
+ // ─── #12103 — plan groups, the default Recommended, the card layout ─────────
162
+
163
+ const LABELS: OfferingsPricingLabels = {
164
+ cta: "CTA⟪",
165
+ recommended: "REC⟪",
166
+ monthly: (amount) => "M⟪" + amount,
167
+ annual: (amount) => "Y⟪" + amount,
168
+ oneTime: (amount) => "O⟪" + amount,
169
+ withRequired: (plan, required) => "W⟪" + plan + "⟫" + required,
170
+ depositNote: (deposit) => "D⟪" + deposit,
171
+ billedYearly: (amount) => "B⟪" + amount,
172
+ };
173
+ const RECOMMENDED_LABEL = "FOR-YOU⟪";
174
+ const ADDONS_HEADLINE = "ADDONS⟪";
175
+
176
+ function stripePrice(
177
+ plan: string,
178
+ period: "monthly" | "yearly",
179
+ amount: number,
180
+ ): OfferingsPrice {
181
+ return {
182
+ priceId: `price_${plan}${period}`,
183
+ lookupKey: `${plan}_${period}`,
184
+ plan,
185
+ period,
186
+ interval: period === "monthly" ? "month" : "year",
187
+ amount,
188
+ currency: "usd",
189
+ };
190
+ }
191
+
192
+ function stripeProduct(
193
+ plan: string,
194
+ ailkGroup: "plan" | "addon",
195
+ prices: OfferingsPrice[],
196
+ extra: Partial<OfferingsProduct> = {},
197
+ ): OfferingsProduct {
198
+ return {
199
+ productId: `prod_${plan}`,
200
+ plan,
201
+ name: plan,
202
+ description: null,
203
+ marketingFeatures: [],
204
+ unitLabel: null,
205
+ note: null,
206
+ termsNote: null,
207
+ ailkGroup,
208
+ ailkOrder: null,
209
+ prices,
210
+ recommended: false,
211
+ ...extra,
212
+ };
213
+ }
214
+
215
+ /** essentials, growth (plans, monthly only), writing (monthly + yearly), seo (add-on). */
216
+ function stripeSet(
217
+ recommended: { growth?: boolean } = {},
218
+ ): WorkspaceShownSet {
219
+ const offerings = [
220
+ stripeProduct("essentials", "plan", [stripePrice("essentials", "monthly", 1000)]),
221
+ stripeProduct("growth", "plan", [stripePrice("growth", "monthly", 2000)], {
222
+ recommended: recommended.growth ?? false,
223
+ }),
224
+ stripeProduct("writing", "plan", [
225
+ stripePrice("writing", "monthly", 3000),
226
+ stripePrice("writing", "yearly", 30000),
227
+ ]),
228
+ stripeProduct("seo", "addon", [stripePrice("seo", "monthly", 900)]),
229
+ ];
230
+ return workspaceShownSetSchema.parse({
231
+ workspaceId: "wksp_01890a5d-ac96-774b-bcce-b302099a8057",
232
+ organizationId: "org_01890a5d-ac96-774b-bcce-b302099a8058",
233
+ productIds: offerings.map((o) => o.productId),
234
+ recommended: { plan: recommended.growth ? "prod_growth" : null, addon: null },
235
+ offerings,
236
+ state: "current",
237
+ snapshotAt: "2026-11-20T00:00:00.000Z",
238
+ });
239
+ }
240
+
241
+ type Pricing = Extract<PageSection, { type: "pricing" }>;
242
+
243
+ function pricingSection(id: string, data: Record<string, unknown> = {}): Pricing {
244
+ return { id, type: "pricing", data: { plans: [], ...data } } as Pricing;
245
+ }
246
+
247
+ const HERO = {
248
+ id: "hero",
249
+ type: "hero",
250
+ data: { headline: "Pricing" },
251
+ } as PageSection;
252
+ const EXTRAS = pricingSection("extras", { variant: "addons", headline: "Extras" });
253
+
254
+ /** `offeringsFragments` then `withOfferings`, as `pricingSections` runs them. */
255
+ function render(
256
+ sections: PageSection[],
257
+ options: {
258
+ plans?: readonly string[];
259
+ plan?: string;
260
+ set?: WorkspaceShownSet;
261
+ } = {},
262
+ ) {
263
+ const fragments = offeringsFragments(sections, options.set ?? stripeSet(), {
264
+ locale: "en-US",
265
+ labels: LABELS,
266
+ plans: options.plans,
267
+ });
268
+ const placed = withOfferings(
269
+ sections,
270
+ fragments.pricing!,
271
+ options.plan,
272
+ RECOMMENDED_LABEL,
273
+ ADDONS_HEADLINE,
274
+ fragments.groups,
275
+ );
276
+ return { placed, groups: fragments.groups };
277
+ }
278
+
279
+ function dataOf(placed: PageSection[], id: string) {
280
+ const found = placed.find((s) => s.id === id);
281
+ if (!found || found.type !== "pricing") throw new Error(`no pricing ${id}`);
282
+ return found.data as Pricing["data"] & { recommended?: string };
283
+ }
284
+
285
+ const keysOf = (placed: PageSection[], id: string) =>
286
+ dataOf(placed, id).plans.map((card) => card.key);
287
+
288
+ const allKeys = (placed: PageSection[]) =>
289
+ placed.flatMap((s) =>
290
+ s.type === "pricing" ? s.data.plans.map((card) => card.key) : [],
291
+ );
292
+
293
+ describe("plan groups — offeringPlans on a pricing section (#12103 D2, AC-2)", () => {
294
+ it("two listed groups each show their own plans, with their own toggle, and none is removed", () => {
295
+ const { placed } = render([
296
+ HERO,
297
+ pricingSection("retainers", { offeringPlans: ["essentials", "growth"] }),
298
+ pricingSection("writing-skills", { offeringPlans: ["writing"] }),
299
+ EXTRAS,
300
+ ]);
301
+ expect(placed.map((s) => s.id)).toEqual(["hero", "retainers", "writing-skills", "extras"]);
302
+ expect(keysOf(placed, "retainers")).toEqual(["essentials", "growth"]);
303
+ expect(dataOf(placed, "retainers").billingToggle).toBe(false);
304
+ expect(keysOf(placed, "writing-skills")).toEqual(["writing"]);
305
+ expect(dataOf(placed, "writing-skills").billingToggle).toBe(true);
306
+ expect(dataOf(placed, "extras").addons?.map((t) => t.name)).toEqual(["seo"]);
307
+ });
308
+
309
+ it("an unlisted plans section shows the page's plans less the listed ones", () => {
310
+ const { placed } = render([
311
+ HERO,
312
+ pricingSection("retainers"),
313
+ pricingSection("writing-skills", { offeringPlans: ["writing"] }),
314
+ EXTRAS,
315
+ ]);
316
+ expect(keysOf(placed, "retainers")).toEqual(["essentials", "growth"]);
317
+ expect(keysOf(placed, "writing-skills")).toEqual(["writing"]);
318
+ });
319
+
320
+ it("removes a listed group with nothing shown, and its plan appears nowhere", () => {
321
+ const { placed } = render([
322
+ HERO,
323
+ pricingSection("retainers", { offeringPlans: ["essentials", "growth"] }),
324
+ pricingSection("writing-skills", { offeringPlans: ["absent"] }),
325
+ EXTRAS,
326
+ ]);
327
+ expect(placed.map((s) => s.id)).toEqual(["hero", "retainers", "extras"]);
328
+ expect(allKeys(placed)).not.toContain("writing");
329
+ });
330
+
331
+ it("inserts no section for the leftover plans when every plans section is listed", () => {
332
+ const { placed } = render([
333
+ HERO,
334
+ pricingSection("retainers", { offeringPlans: ["essentials"] }),
335
+ pricingSection("writing-skills", { offeringPlans: ["writing"] }),
336
+ EXTRAS,
337
+ ]);
338
+ expect(placed.map((s) => s.id)).toEqual(["hero", "retainers", "writing-skills", "extras"]);
339
+ expect(allKeys(placed)).not.toContain("growth");
340
+ expect(placed.some((s) => s.id === "offerings-plans")).toBe(false);
341
+ });
342
+
343
+ it("a page with no offeringPlans renders exactly as today (FR-3)", () => {
344
+ const a = pricingSection("a", { headline: "A", eyebrow: "Plans" });
345
+ const { placed, groups } = render([HERO, a, pricingSection("b"), EXTRAS]);
346
+ expect(placed.map((s) => s.id)).toEqual(["hero", "a", "extras"]);
347
+ expect(groups.size).toBe(0);
348
+ const cards = offeringsPricing(stripeSet(), { locale: "en-US", labels: LABELS })!.plans!.plans;
349
+ expect(dataOf(placed, "a")).toEqual({
350
+ headline: "A",
351
+ eyebrow: "Plans",
352
+ variant: "three-tiers-with-toggle",
353
+ cardLayout: "centered",
354
+ billingToggle: true,
355
+ plans: cards,
356
+ recommendedLabel: RECOMMENDED_LABEL,
357
+ });
358
+ });
359
+
360
+ it("applies ?plan= in the group whose cards carry it; the other keeps its default", () => {
361
+ const { placed } = render(
362
+ [
363
+ pricingSection("retainers", { offeringPlans: ["essentials", "growth"] }),
364
+ pricingSection("writing-skills", { offeringPlans: ["writing"] }),
365
+ ],
366
+ { plan: "writing", set: stripeSet({ growth: true }) },
367
+ );
368
+ expect(dataOf(placed, "writing-skills").plans[0]).not.toHaveProperty("highlightLabel");
369
+ const growth = dataOf(placed, "retainers").plans.find((c) => c.key === "growth");
370
+ expect(growth?.highlightLabel).toBe(LABELS.recommended);
371
+ });
372
+
373
+ it("makes no shown-offerings read for page `plans: []`, whatever a section lists", async () => {
374
+ const declared = [pricingSection("writing-skills", { offeringPlans: ["writing"] })];
375
+ const sections = await pricingSections(declared, {
376
+ plans: [],
377
+ plan: undefined,
378
+ locale: "en",
379
+ });
380
+ expect(fetchMock).not.toHaveBeenCalled();
381
+ expect(sections).toBe(declared);
382
+ });
383
+ });
384
+
385
+ describe("the default Recommended's pill (#12103 D3, AC-3)", () => {
386
+ it("shows the pill on the workspace's Recommended plan with no ?plan=", () => {
387
+ const { placed } = render([pricingSection("plans")], { set: stripeSet({ growth: true }) });
388
+ const growth = dataOf(placed, "plans").plans.find((c) => c.key === "growth");
389
+ expect(growth).toMatchObject({
390
+ highlighted: true,
391
+ highlightStyle: "pill",
392
+ highlightLabel: LABELS.recommended,
393
+ });
394
+ expect(dataOf(placed, "plans").recommended).toBeUndefined();
395
+ });
396
+
397
+ it("lets ?plan= move it for that visit", () => {
398
+ const { placed } = render([pricingSection("plans")], {
399
+ set: stripeSet({ growth: true }),
400
+ plan: "essentials",
401
+ });
402
+ const data = dataOf(placed, "plans");
403
+ expect(data.plans.some((c) => c.highlightLabel !== undefined)).toBe(false);
404
+ expect(data.recommended).toBe("essentials");
405
+ });
406
+ });
407
+
408
+ describe("the authored card layout survives (#12103 D6, AC-5)", () => {
409
+ it("keeps a plans slot's cardLayout over the mapper's, and the mapper's when the slot sets none", () => {
410
+ expect(dataOf(render([pricingSection("plans", { cardLayout: "default" })]).placed, "plans").cardLayout).toBe("default");
411
+ expect(dataOf(render([pricingSection("plans")]).placed, "plans").cardLayout).toBe("centered");
412
+ });
413
+
414
+ it("keeps a listed group's cardLayout", () => {
415
+ const { placed } = render([
416
+ pricingSection("writing-skills", { offeringPlans: ["writing"], cardLayout: "default" }),
417
+ ]);
418
+ expect(dataOf(placed, "writing-skills").cardLayout).toBe("default");
419
+ });
420
+
421
+ it("keeps the mapper's billingToggle over an authored one", () => {
422
+ const { placed } = render([
423
+ pricingSection("retainers", { offeringPlans: ["essentials", "growth"], billingToggle: true }),
424
+ ]);
425
+ expect(dataOf(placed, "retainers").billingToggle).toBe(false);
426
+ });
427
+ });
428
+
429
+ // ─── #12140 — bound and written sections (spec 12140 D2, D6, D7) ────────────
430
+
431
+ const PLAN_VARIANTS = [
432
+ "three-tiers-with-toggle",
433
+ "with-comparison-table",
434
+ "two-tiers-with-extra-tier",
435
+ "single-price-with-details",
436
+ "features-and-plans",
437
+ "band-hero",
438
+ ] as const;
439
+
440
+ const ALL_KEYS = ["essentials", "growth", "writing"];
441
+
442
+ describe("a bound section renders the variant the page sets (#12140 AC-1)", () => {
443
+ it.each(PLAN_VARIANTS)("%s", (variant) => {
444
+ const { placed } = render([
445
+ HERO,
446
+ pricingSection("p", { source: "offerings", variant }),
447
+ ]);
448
+ expect(placed.map((s) => s.id)).toEqual(["hero", "p"]);
449
+ expect(dataOf(placed, "p").variant).toBe(variant);
450
+ expect(dataOf(placed, "p").source).toBe("offerings");
451
+ if (variant === "with-comparison-table")
452
+ expect(keysOf(placed, "p")).toEqual(ALL_KEYS);
453
+ if (variant === "single-price-with-details")
454
+ expect(keysOf(placed, "p")).toEqual(["essentials"]);
455
+ });
456
+
457
+ it("a bound section with no variant gets the toggle layout", () => {
458
+ const { placed } = render([pricingSection("p", { source: "offerings" })]);
459
+ expect(dataOf(placed, "p").variant).toBe("three-tiers-with-toggle");
460
+ expect(dataOf(placed, "p").billingToggle).toBe(true);
461
+ });
462
+
463
+ it("drops an authored extra tier and plan card, and keeps a band's key points", () => {
464
+ const keyPointsPanel = { items: [{ title: "Fast" }] };
465
+ const { placed } = render([
466
+ pricingSection("two", {
467
+ source: "offerings",
468
+ variant: "two-tiers-with-extra-tier",
469
+ extraTier: { name: "Big", price: { custom: "Ask" }, features: [], cta: { label: "Talk", href: "/elsewhere" } },
470
+ plans: [{ key: "own", name: "Own", price: { custom: "$1" }, features: [], cta: { label: "Go", href: "/elsewhere" } }],
471
+ }),
472
+ pricingSection("band", { source: "offerings", variant: "band-hero", keyPointsPanel }),
473
+ ]);
474
+ expect(dataOf(placed, "two")).not.toHaveProperty("extraTier");
475
+ expect(keysOf(placed, "two")).toEqual(ALL_KEYS);
476
+ expect(dataOf(placed, "band").keyPointsPanel).toEqual(keyPointsPanel);
477
+ });
478
+
479
+ it("an unbound section ignores its variant and renders as in 0.74.0", () => {
480
+ const { placed } = render([HERO, pricingSection("p", { variant: "features-and-plans" })]);
481
+ expect(dataOf(placed, "p").variant).toBe("three-tiers-with-toggle");
482
+ expect(dataOf(placed, "p").cardLayout).toBe("centered");
483
+ expect(keysOf(placed, "p")).toEqual(ALL_KEYS);
484
+ });
485
+
486
+ it("a bound add-ons section takes the tiles; a bound plans section beside it takes none", () => {
487
+ const { placed } = render([
488
+ pricingSection("a", { source: "offerings", variant: "addons" }),
489
+ pricingSection("c", { source: "offerings", variant: "with-comparison-table" }),
490
+ ]);
491
+ expect(placed.map((s) => s.id)).toEqual(["a", "c"]);
492
+ expect(dataOf(placed, "a").addons?.map((t) => t.name)).toEqual(["seo"]);
493
+ expect(dataOf(placed, "a").source).toBe("offerings");
494
+ expect(dataOf(placed, "c")).not.toHaveProperty("addons");
495
+ });
496
+ });
497
+
498
+ describe("a section with no source renders exactly as in 0.74.0 (#12140 AC-2)", () => {
499
+ const AUTHORED = {
500
+ headline: "Plans",
501
+ variant: "with-comparison-table",
502
+ comparisonGroups: [{ groupName: "Core", rows: [{ featureName: "Reports", values: { growth: true } }] }],
503
+ features: [{ title: "Row", description: "One" }],
504
+ extraTier: { name: "Big", price: { custom: "Ask" }, features: [], cta: { label: "Talk", href: "/contact" } },
505
+ };
506
+ const TODAY_KEYS = ["billingToggle", "cardLayout", "headline", "plans", "recommendedLabel", "variant"];
507
+
508
+ it("an unbound plans slot keeps only today's fields", () => {
509
+ const { placed } = render([pricingSection("p", AUTHORED)]);
510
+ expect(Object.keys(dataOf(placed, "p")).sort()).toEqual(TODAY_KEYS);
511
+ expect(dataOf(placed, "p").variant).toBe("three-tiers-with-toggle");
512
+ });
513
+
514
+ it("an unbound plan group keeps only today's fields", () => {
515
+ const { placed } = render([pricingSection("g", { ...AUTHORED, offeringPlans: ["writing"] })]);
516
+ expect(Object.keys(dataOf(placed, "g")).sort()).toEqual(TODAY_KEYS);
517
+ });
518
+
519
+ it("still inserts the plans and add-ons after a leading hero on a page with no pricing section", () => {
520
+ const { placed } = render([HERO]);
521
+ expect(placed.map((s) => s.id)).toEqual(["hero", "offerings-plans", "offerings-addons"]);
522
+ });
523
+ });
524
+
525
+ describe("features-and-plans on one product with two Prices (#12140 AC-3)", () => {
526
+ const WRITING = stripeProduct(
527
+ "writing",
528
+ "plan",
529
+ [stripePrice("writing", "monthly", 3000), stripePrice("writing", "yearly", 30000)],
530
+ { marketingFeatures: ["Edits", "Briefs"] },
531
+ );
532
+ const set = workspaceShownSetSchema.parse({
533
+ ...stripeSet(),
534
+ offerings: [WRITING],
535
+ productIds: ["prod_writing"],
536
+ recommended: { plan: null, addon: null },
537
+ });
538
+
539
+ it("renders a monthly and a yearly block, each with its own checkout, beside the product's features", () => {
540
+ const { placed } = render(
541
+ [HERO, pricingSection("w", { source: "offerings", variant: "features-and-plans", offeringPlans: ["writing"] })],
542
+ { set },
543
+ );
544
+ expect(keysOf(placed, "w")).toEqual(["writing", "writing_yearly"]);
545
+ const hrefs = dataOf(placed, "w").plans.map((c) => c.cta.href);
546
+ expect(hrefs[0]!.endsWith("writing_monthly")).toBe(true);
547
+ expect(hrefs[1]!.endsWith("writing_yearly")).toBe(true);
548
+ expect(dataOf(placed, "w").features).toEqual([{ title: "Edits" }, { title: "Briefs" }]);
549
+ });
550
+
551
+ it("keeps an authored features list over the product's", () => {
552
+ const own = [{ title: "Own", description: "Mine" }];
553
+ const { placed } = render(
554
+ [pricingSection("w", { source: "offerings", variant: "features-and-plans", offeringPlans: ["writing"], features: own })],
555
+ { set },
556
+ );
557
+ expect(dataOf(placed, "w").features).toEqual(own);
558
+ });
559
+ });
560
+
561
+ describe("comparisonGroups survive the swap, matched by plan slug (#12140 AC-4)", () => {
562
+ const NAMED = workspaceShownSetSchema.parse({
563
+ ...stripeSet(),
564
+ offerings: stripeSet().offerings.map((o) => ({
565
+ ...o,
566
+ name: o.plan.charAt(0).toUpperCase() + o.plan.slice(1),
567
+ })),
568
+ });
569
+ const G = [
570
+ { groupName: "Core", rows: [{ featureName: "Reports", values: { essentials: true, growth: "Weekly", absent: true } }] },
571
+ ];
572
+ const section = (groups: unknown) =>
573
+ pricingSection("c", {
574
+ source: "offerings",
575
+ variant: "with-comparison-table",
576
+ offeringPlans: ["essentials", "growth"],
577
+ comparisonGroups: groups,
578
+ });
579
+
580
+ it("keeps the grid and keys the cards by slug, not by name", () => {
581
+ const { placed } = render([HERO, section(G)], { set: NAMED });
582
+ expect(dataOf(placed, "c").comparisonGroups).toEqual(G);
583
+ expect(keysOf(placed, "c")).toEqual(["essentials", "growth"]);
584
+ expect(dataOf(placed, "c").plans.map((c) => c.name)).toEqual(["Essentials", "Growth"]);
585
+ });
586
+
587
+ it("drops a cell's authored link and keeps every other value", () => {
588
+ const linked = [
589
+ {
590
+ groupName: "Core",
591
+ rows: [
592
+ {
593
+ featureName: "Reports",
594
+ values: {
595
+ essentials: true,
596
+ growth: { text: "Weekly", verdict: "yes", link: { label: "See", href: "https://example.com" } },
597
+ absent: true,
598
+ },
599
+ },
600
+ ],
601
+ },
602
+ ];
603
+ const { placed } = render([section(linked)], { set: NAMED });
604
+ expect(dataOf(placed, "c").comparisonGroups).toEqual([
605
+ { groupName: "Core", rows: [{ featureName: "Reports", values: { essentials: true, growth: { text: "Weekly", verdict: "yes" }, absent: true } }] },
606
+ ]);
607
+ });
608
+ });
609
+
610
+ describe("no vendor, and every price link on a non-written section is a checkout key (#12140 AC-5, NFR-2)", () => {
611
+ it("holds over a page of every bound variant, a bound add-ons section and an unbound section", () => {
612
+ const linkedGrid = [
613
+ { groupName: "Core", rows: [{ featureName: "R", values: { growth: { text: "W", link: { label: "See", href: "/elsewhere" } } } }] },
614
+ ];
615
+ const authored = {
616
+ plans: [{ key: "own", name: "Own", price: { custom: "$1" }, features: [], cta: { label: "Go", href: "/elsewhere" } }],
617
+ extraTier: { name: "Big", price: { custom: "Ask" }, features: [], cta: { label: "Talk", href: "/elsewhere" } },
618
+ comparisonGroups: linkedGrid,
619
+ };
620
+ const { placed } = render([
621
+ HERO,
622
+ ...PLAN_VARIANTS.map((variant) => pricingSection(`b-${variant}`, { source: "offerings", variant, ...authored })),
623
+ pricingSection("a", { source: "offerings", variant: "addons" }),
624
+ pricingSection("u", authored),
625
+ ]);
626
+ const priced = placed.filter((s): s is Pricing => s.type === "pricing");
627
+ expect(priced.map((s) => s.id)).toEqual([...PLAN_VARIANTS.map((v) => `b-${v}`), "a", "u"]);
628
+ const ours = (href: string | undefined) =>
629
+ href === undefined || href.startsWith(OFFERINGS_CHECKOUT_PATH);
630
+ for (const { data } of priced) {
631
+ expect(JSON.stringify(data)).not.toMatch(/stripe/i);
632
+ expect(data).not.toHaveProperty("extraTier");
633
+ for (const card of data.plans) {
634
+ expect(ours(card.cta.href)).toBe(true);
635
+ expect(ours(card.annualCtaHref)).toBe(true);
636
+ }
637
+ for (const tile of data.addons ?? []) expect(ours(tile.cta?.href)).toBe(true);
638
+ for (const group of data.comparisonGroups ?? [])
639
+ for (const row of group.rows)
640
+ for (const value of Object.values(row.values))
641
+ if (typeof value === "object") expect(value).not.toHaveProperty("link");
642
+ }
643
+ });
644
+ });
645
+
646
+ describe("a written section (#12140 AC-6)", () => {
647
+ const W = pricingSection("w", {
648
+ source: "written",
649
+ plans: [{ key: "custom", name: "Custom", price: { custom: "Ask" }, features: [], cta: { label: "Talk", href: "/contact" } }],
650
+ });
651
+ const RECOMMENDED = RECOMMENDED_LABEL;
652
+
653
+ it("stays as written beside the Offerings cards, and never becomes the plans slot", () => {
654
+ const { placed } = render([HERO, W, pricingSection("p"), EXTRAS]);
655
+ expect(placed.map((s) => s.id)).toEqual(["hero", "w", "p", "extras"]);
656
+ expect(dataOf(placed, "w")).toEqual(W.data);
657
+ expect(keysOf(placed, "p")).toEqual(ALL_KEYS);
658
+ });
659
+
660
+ it("takes a {plan}-grammar ?plan= only", () => {
661
+ expect(dataOf(render([W, pricingSection("p")], { plan: "custom" }).placed, "w")).toEqual({
662
+ ...W.data,
663
+ recommended: "custom",
664
+ recommendedLabel: RECOMMENDED,
665
+ });
666
+ expect(dataOf(render([W, pricingSection("p")], { plan: "Custom" }).placed, "w")).toEqual(W.data);
667
+ });
668
+
669
+ const W2 = pricingSection("w", {
670
+ source: "written",
671
+ plans: [
672
+ ...W.data.plans,
673
+ { key: "sneak", name: "Sneak", price: { custom: "$1" }, features: [], cta: { label: "Buy", href: "/api/offerings/checkout/writing_monthly" } },
674
+ { key: "annual", name: "Annual", price: { custom: "$2" }, features: [], cta: { label: "Buy", href: "/x" }, annualCtaHref: "/api/offerings/checkout/writing_yearly" },
675
+ { key: "absolute", name: "Absolute", price: { custom: "$3" }, features: [], cta: { label: "Buy", href: "https://example.com/api/offerings/checkout/growth_monthly" } },
676
+ ],
677
+ extraTier: { name: "Big", price: { custom: "$9" }, features: [], cta: { label: "Buy", href: "/api/offerings/checkout/growth_monthly" } },
678
+ });
679
+
680
+ it("drops every card and extra tier that links the Offerings checkout", () => {
681
+ const { placed } = render([W2, pricingSection("p")]);
682
+ expect(keysOf(placed, "w")).toEqual(["custom"]);
683
+ expect(dataOf(placed, "w")).not.toHaveProperty("extraTier");
684
+ });
685
+
686
+ it("drops a percent-encoded link to the Offerings checkout too", () => {
687
+ const encoded = (key: string, href: string) => ({
688
+ key,
689
+ name: key,
690
+ price: { custom: "$1" },
691
+ features: [],
692
+ cta: { label: "Buy", href },
693
+ });
694
+ const W3 = pricingSection("w", {
695
+ source: "written",
696
+ plans: [
697
+ ...W.data.plans,
698
+ encoded("letter", "/api/%6Ffferings/checkout/writing_monthly"),
699
+ encoded("slash", "/api%2Fofferings%2Fcheckout/writing_monthly"),
700
+ encoded("upper", "/API/%4FFFERINGS/Checkout/writing_monthly"),
701
+ encoded("malformed", "/api/offerings/%E0%A4%A"),
702
+ ],
703
+ });
704
+ expect(keysOf(render([W3, pricingSection("p")]).placed, "w")).toEqual(["custom", "malformed"]);
705
+ });
706
+
707
+ it("drops a written add-on tile and a cell link that reach the Offerings checkout", () => {
708
+ const tile = (name: string, href: string) => ({ name, price: "$1", cta: { label: "Add", href } });
709
+ const W4 = pricingSection("w", {
710
+ source: "written",
711
+ addons: [tile("Kept", "/contact"), tile("Sold", "/api/offerings/checkout/rush_once")],
712
+ comparisonGroups: [
713
+ {
714
+ groupName: "G",
715
+ rows: [
716
+ {
717
+ featureName: "Row",
718
+ values: {
719
+ custom: { text: "Yes", link: { label: "Buy", href: "/api/offerings/checkout/writing_monthly" } },
720
+ other: { text: "Ask", link: { label: "Ask", href: "/contact" } },
721
+ },
722
+ },
723
+ ],
724
+ },
725
+ ],
726
+ });
727
+ const data = dataOf(render([W4, pricingSection("p")]).placed, "w");
728
+ expect(data.addons?.map((a) => a.name)).toEqual(["Kept"]);
729
+ const values = data.comparisonGroups?.[0]?.rows[0]?.values ?? {};
730
+ expect(values["custom"]).toEqual({ text: "Yes" });
731
+ expect(values["other"]).toEqual({ text: "Ask", link: { label: "Ask", href: "/contact" } });
732
+ });
733
+
734
+ it("drops them through pricingSections for page plans: [] too", async () => {
735
+ const sections = await pricingSections([W2], { plans: [], plan: undefined, locale: "en" });
736
+ expect(fetchMock).not.toHaveBeenCalled();
737
+ expect(keysOf(sections, "w")).toEqual(["custom"]);
738
+ expect(dataOf(sections, "w")).not.toHaveProperty("extraTier");
739
+ });
740
+
741
+ it("gives way to the contact email with every other pricing section", () => {
742
+ expect(withContactFallback([HERO, W, pricingSection("p"), EXTRAS]).map((s) => s.id)).toEqual([
743
+ "hero",
744
+ "offerings-contact",
745
+ ]);
746
+ });
747
+
748
+ describe("through pricingSections", () => {
749
+ let now = Date.now();
750
+ beforeEach(() => {
751
+ now += 16_000;
752
+ jest.spyOn(Date, "now").mockReturnValue(now);
753
+ });
754
+ afterEach(() => jest.restoreAllMocks());
755
+
756
+ const answer = (data: unknown) =>
757
+ fetchMock.mockImplementation(async () => ({
758
+ ok: true,
759
+ status: 200,
760
+ json: async () => ({ ok: true, data }),
761
+ }));
762
+
763
+ it("takes the contact path when the only pricing left would be written", async () => {
764
+ answer({ status: "shown", shownSet: stripeSet() });
765
+ const sections = await pricingSections([HERO, W, pricingSection("p")], {
766
+ plans: ["absent"],
767
+ plan: undefined,
768
+ locale: "en",
769
+ });
770
+ expect(sections.map((s) => s.id)).toEqual(["hero", "offerings-contact"]);
771
+ });
772
+
773
+ it("takes the contact path on an empty shown set", async () => {
774
+ answer({ status: "empty" });
775
+ const sections = await pricingSections([HERO, W, pricingSection("p")], {
776
+ plans: undefined,
777
+ plan: undefined,
778
+ locale: "en",
779
+ });
780
+ expect(sections.map((s) => s.id)).toEqual(["hero", "offerings-contact"]);
781
+ });
782
+
783
+ it("reads no Offerings for a page whose every pricing section is written", async () => {
784
+ answer({ status: "shown", shownSet: stripeSet() });
785
+ const sections = await pricingSections([HERO, W], { plans: undefined, plan: undefined, locale: "en" });
786
+ expect(sections.map((s) => s.id)).toEqual(["hero", "w"]);
787
+ expect(sections[1]).toEqual(W);
788
+ expect(fetchMock).not.toHaveBeenCalled();
789
+ });
790
+
791
+ it("reads once when an unbound section sits beside it", async () => {
792
+ answer({ status: "shown", shownSet: stripeSet() });
793
+ const sections = await pricingSections([HERO, W, pricingSection("p")], {
794
+ plans: undefined,
795
+ plan: undefined,
796
+ locale: "en",
797
+ });
798
+ expect(fetchMock).toHaveBeenCalledTimes(1);
799
+ expect(sections.map((s) => s.id)).toEqual(["hero", "w", "p"]);
800
+ });
801
+ });
802
+ });
803
+
804
+ describe("the plan bar options survive the Stripe path (#12141 D9, AC-1)", () => {
805
+ const REC_GRID = { pickerLabel: "Plan", pinnedGroups: true, groupsOpen: "first" };
806
+
807
+ it.each([
808
+ ["an unbound plans slot", {}],
809
+ ["a bound section", { source: "offerings", variant: "with-comparison-table" }],
810
+ ])("%s keeps planBar and comparisonPlanBar over the Offerings cards, deep-equal", (_label, extra) => {
811
+ const { placed } = render([
812
+ pricingSection("p", { ...extra, planBar: {}, comparisonPlanBar: REC_GRID }),
813
+ ]);
814
+ expect(dataOf(placed, "p").planBar).toEqual({});
815
+ expect(dataOf(placed, "p").comparisonPlanBar).toEqual(REC_GRID);
816
+ });
817
+ });